Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/prims/jvmtiExport.hpp
32285 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_PRIMS_JVMTIEXPORT_HPP25#define SHARE_VM_PRIMS_JVMTIEXPORT_HPP2627#include "jvmtifiles/jvmti.h"28#include "memory/allocation.hpp"29#include "memory/iterator.hpp"30#include "oops/oop.hpp"31#include "oops/oopsHierarchy.hpp"32#include "runtime/frame.hpp"33#include "runtime/handles.hpp"34#include "utilities/globalDefinitions.hpp"35#include "utilities/growableArray.hpp"36#include "utilities/macros.hpp"3738// Must be included after jvmti.h.39#include "code/jvmticmlr.h"4041// Forward declarations4243class JvmtiEventControllerPrivate;44class JvmtiManageCapabilities;45class JvmtiEnv;46class JvmtiThreadState;47class AttachOperation;4849#define JVMTI_SUPPORT_FLAG(key) \50private: \51static bool _##key; \52public: \53inline static void set_##key(bool on) { \54JVMTI_ONLY(_##key = (on != 0)); \55NOT_JVMTI(report_unsupported(on)); \56} \57inline static bool key() { \58JVMTI_ONLY(return _##key); \59NOT_JVMTI(return false); \60}616263// This class contains the JVMTI interface for the rest of hotspot.64//65class JvmtiExport : public AllStatic {66friend class VMStructs;67friend class CompileReplay;6869private:7071#if INCLUDE_JVMTI72static int _field_access_count;73static int _field_modification_count;7475static bool _can_access_local_variables;76static bool _can_hotswap_or_post_breakpoint;77static bool _can_modify_any_class;78static bool _can_walk_any_space;79#endif // INCLUDE_JVMTI8081JVMTI_SUPPORT_FLAG(can_get_source_debug_extension)82JVMTI_SUPPORT_FLAG(can_maintain_original_method_order)83JVMTI_SUPPORT_FLAG(can_post_interpreter_events)84JVMTI_SUPPORT_FLAG(can_post_on_exceptions)85JVMTI_SUPPORT_FLAG(can_post_breakpoint)86JVMTI_SUPPORT_FLAG(can_post_field_access)87JVMTI_SUPPORT_FLAG(can_post_field_modification)88JVMTI_SUPPORT_FLAG(can_post_method_entry)89JVMTI_SUPPORT_FLAG(can_post_method_exit)90JVMTI_SUPPORT_FLAG(can_pop_frame)91JVMTI_SUPPORT_FLAG(can_force_early_return)9293friend class JvmtiEventControllerPrivate; // should only modify these flags94JVMTI_SUPPORT_FLAG(should_post_single_step)95JVMTI_SUPPORT_FLAG(should_post_field_access)96JVMTI_SUPPORT_FLAG(should_post_field_modification)97JVMTI_SUPPORT_FLAG(should_post_class_load)98JVMTI_SUPPORT_FLAG(should_post_class_prepare)99JVMTI_SUPPORT_FLAG(should_post_class_unload)100JVMTI_SUPPORT_FLAG(should_post_native_method_bind)101JVMTI_SUPPORT_FLAG(should_post_compiled_method_load)102JVMTI_SUPPORT_FLAG(should_post_compiled_method_unload)103JVMTI_SUPPORT_FLAG(should_post_dynamic_code_generated)104JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter)105JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered)106JVMTI_SUPPORT_FLAG(should_post_monitor_wait)107JVMTI_SUPPORT_FLAG(should_post_monitor_waited)108JVMTI_SUPPORT_FLAG(should_post_data_dump)109JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start)110JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish)111JVMTI_SUPPORT_FLAG(should_post_on_exceptions)112113// ------ the below maybe don't have to be (but are for now)114// fixed conditions here ------------115// any events can be enabled116JVMTI_SUPPORT_FLAG(should_post_thread_life)117JVMTI_SUPPORT_FLAG(should_post_object_free)118JVMTI_SUPPORT_FLAG(should_post_resource_exhausted)119120// we are holding objects on the heap - need to talk to GC - e.g.121// breakpoint info122JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects)123JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)124125// If flag cannot be implemented, give an error if on=true126static void report_unsupported(bool on);127128// these should only be called by the friend class129friend class JvmtiManageCapabilities;130inline static void set_can_modify_any_class(bool on) {131JVMTI_ONLY(_can_modify_any_class = (on != 0);)132}133inline static void set_can_access_local_variables(bool on) {134JVMTI_ONLY(_can_access_local_variables = (on != 0);)135}136inline static void set_can_hotswap_or_post_breakpoint(bool on) {137JVMTI_ONLY(_can_hotswap_or_post_breakpoint = (on != 0);)138}139inline static void set_can_walk_any_space(bool on) {140JVMTI_ONLY(_can_walk_any_space = (on != 0);)141}142143enum {144JVMTI_VERSION_MASK = 0x70000000,145JVMTI_VERSION_VALUE = 0x30000000,146JVMDI_VERSION_VALUE = 0x20000000147};148149static void post_field_modification(JavaThread *thread, Method* method, address location,150KlassHandle field_klass, Handle object, jfieldID field,151char sig_type, jvalue *value);152153154// posts a DynamicCodeGenerated event (internal/private implementation).155// The public post_dynamic_code_generated* functions make use of the156// internal implementation. Also called from JvmtiDeferredEvent::post()157static void post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN;158159private:160161// GenerateEvents support to allow posting of CompiledMethodLoad and162// DynamicCodeGenerated events for a given environment.163friend class JvmtiCodeBlobEvents;164165static void post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,166const void *code_begin, const jint map_length,167const jvmtiAddrLocationMap* map) NOT_JVMTI_RETURN;168static void post_dynamic_code_generated(JvmtiEnv* env, const char *name, const void *code_begin,169const void *code_end) NOT_JVMTI_RETURN;170171// The RedefineClasses() API breaks some invariants in the "regular"172// system. For example, there are sanity checks when GC'ing nmethods173// that require the containing class to be unloading. However, when a174// method is redefined, the old method and nmethod can become GC'able175// without the containing class unloading. The state of becoming176// GC'able can be asynchronous to the RedefineClasses() call since177// the old method may still be running and cannot be GC'ed until178// after all old invocations have finished. Additionally, a method179// that has not been redefined may have an nmethod that depends on180// the redefined method. The dependent nmethod will get deopted in181// this case and may also be GC'able without the containing class182// being unloaded.183//184// This flag indicates whether RedefineClasses() has ever redefined185// one or more classes during the lifetime of the VM. The flag should186// only be set by the friend class and can be queried by other sub187// systems as needed to relax invariant checks.188static bool _has_redefined_a_class;189friend class VM_RedefineClasses;190inline static void set_has_redefined_a_class() {191JVMTI_ONLY(_has_redefined_a_class = true;)192}193// Flag to indicate if the compiler has recorded all dependencies. When the194// can_redefine_classes capability is enabled in the OnLoad phase then the compiler195// records all dependencies from startup. However if the capability is first196// enabled some time later then the dependencies recorded by the compiler197// are incomplete. This flag is used by RedefineClasses to know if the198// dependency information is complete or not.199static bool _all_dependencies_are_recorded;200201public:202inline static bool has_redefined_a_class() {203JVMTI_ONLY(return _has_redefined_a_class);204NOT_JVMTI(return false);205}206207inline static bool all_dependencies_are_recorded() {208return _all_dependencies_are_recorded;209}210211inline static void set_all_dependencies_are_recorded(bool on) {212_all_dependencies_are_recorded = (on != 0);213}214215216// let JVMTI know that the JVM_OnLoad code is running217static void enter_onload_phase() NOT_JVMTI_RETURN;218219// let JVMTI know that the VM isn't up yet (and JVM_OnLoad code isn't running)220static void enter_primordial_phase() NOT_JVMTI_RETURN;221222// let JVMTI know that the VM isn't up yet but JNI is live223static void enter_start_phase() NOT_JVMTI_RETURN;224225// let JVMTI know that the VM is fully up and running now226static void enter_live_phase() NOT_JVMTI_RETURN;227228// ------ can_* conditions (below) are set at OnLoad and never changed ------------229inline static bool can_modify_any_class() {230JVMTI_ONLY(return _can_modify_any_class);231NOT_JVMTI(return false);232}233inline static bool can_access_local_variables() {234JVMTI_ONLY(return _can_access_local_variables);235NOT_JVMTI(return false);236}237inline static bool can_hotswap_or_post_breakpoint() {238JVMTI_ONLY(return _can_hotswap_or_post_breakpoint);239NOT_JVMTI(return false);240}241inline static bool can_walk_any_space() {242JVMTI_ONLY(return _can_walk_any_space);243NOT_JVMTI(return false);244}245246// field access management247static address get_field_access_count_addr() NOT_JVMTI_RETURN_(0);248249// field modification management250static address get_field_modification_count_addr() NOT_JVMTI_RETURN_(0);251252// -----------------253254static bool is_jvmti_version(jint version) {255JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMTI_VERSION_VALUE);256NOT_JVMTI(return false);257}258static bool is_jvmdi_version(jint version) {259JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMDI_VERSION_VALUE);260NOT_JVMTI(return false);261}262static jint get_jvmti_interface(JavaVM *jvm, void **penv, jint version) NOT_JVMTI_RETURN_(0);263static void decode_version_values(jint version, int * major, int * minor,264int * micro) NOT_JVMTI_RETURN;265266// single stepping management methods267static void at_single_stepping_point(JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;268static void expose_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN;269static bool hide_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN_(false);270271// Methods that notify the debugger that something interesting has happened in the VM.272static void post_vm_start () NOT_JVMTI_RETURN;273static void post_vm_initialized () NOT_JVMTI_RETURN;274static void post_vm_death () NOT_JVMTI_RETURN;275276static void post_single_step (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;277static void post_raw_breakpoint (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;278279static void post_exception_throw (JavaThread *thread, Method* method, address location, oop exception) NOT_JVMTI_RETURN;280static void notice_unwind_due_to_exception (JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) NOT_JVMTI_RETURN;281282static oop jni_GetField_probe (JavaThread *thread, jobject jobj,283oop obj, Klass* klass, jfieldID fieldID, bool is_static)284NOT_JVMTI_RETURN_(NULL);285static oop jni_GetField_probe_nh (JavaThread *thread, jobject jobj,286oop obj, Klass* klass, jfieldID fieldID, bool is_static)287NOT_JVMTI_RETURN_(NULL);288static void post_field_access_by_jni (JavaThread *thread, oop obj,289Klass* klass, jfieldID fieldID, bool is_static) NOT_JVMTI_RETURN;290static void post_field_access (JavaThread *thread, Method* method,291address location, KlassHandle field_klass, Handle object, jfieldID field) NOT_JVMTI_RETURN;292static oop jni_SetField_probe (JavaThread *thread, jobject jobj,293oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type,294jvalue *value) NOT_JVMTI_RETURN_(NULL);295static oop jni_SetField_probe_nh (JavaThread *thread, jobject jobj,296oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type,297jvalue *value) NOT_JVMTI_RETURN_(NULL);298static void post_field_modification_by_jni(JavaThread *thread, oop obj,299Klass* klass, jfieldID fieldID, bool is_static, char sig_type,300jvalue *value);301static void post_raw_field_modification(JavaThread *thread, Method* method,302address location, KlassHandle field_klass, Handle object, jfieldID field,303char sig_type, jvalue *value) NOT_JVMTI_RETURN;304305static void post_method_entry (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN;306static void post_method_exit (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN;307308static void post_class_load (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN;309static void post_class_unload (Klass* klass) NOT_JVMTI_RETURN;310static void post_class_prepare (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN;311312static void post_thread_start (JavaThread *thread) NOT_JVMTI_RETURN;313static void post_thread_end (JavaThread *thread) NOT_JVMTI_RETURN;314315// Support for java.lang.instrument agent loading.316static bool _should_post_class_file_load_hook;317inline static void set_should_post_class_file_load_hook(bool on) { _should_post_class_file_load_hook = on; }318inline static bool should_post_class_file_load_hook() {319JVMTI_ONLY(return _should_post_class_file_load_hook);320NOT_JVMTI(return false;)321}322static void post_class_file_load_hook(Symbol* h_name, Handle class_loader,323Handle h_protection_domain,324unsigned char **data_ptr, unsigned char **end_ptr,325JvmtiCachedClassFileData **cache_ptr) NOT_JVMTI_RETURN;326static void post_native_method_bind(Method* method, address* function_ptr) NOT_JVMTI_RETURN;327static void post_compiled_method_load(nmethod *nm) NOT_JVMTI_RETURN;328static void post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN;329330// used to post a CompiledMethodUnload event331static void post_compiled_method_unload(jmethodID mid, const void *code_begin) NOT_JVMTI_RETURN;332333// similiar to post_dynamic_code_generated except that it can be used to334// post a DynamicCodeGenerated event while holding locks in the VM. Any event335// posted using this function is recorded by the enclosing event collector336// -- JvmtiDynamicCodeEventCollector.337static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN;338339static void post_garbage_collection_finish() NOT_JVMTI_RETURN;340static void post_garbage_collection_start() NOT_JVMTI_RETURN;341static void post_data_dump() NOT_JVMTI_RETURN;342static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;343static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN;344static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN;345static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN;346static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN;347static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN;348static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN;349// Post objects collected by vm_object_alloc_event_collector.350static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN;351// Collects vm internal objects for later event posting.352inline static void vm_object_alloc_event_collector(oop object) {353if (should_post_vm_object_alloc()) {354record_vm_internal_object_allocation(object);355}356}357inline static void post_array_size_exhausted() {358if (should_post_resource_exhausted()) {359post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,360"Requested array size exceeds VM limit");361}362}363364static void cleanup_thread (JavaThread* thread) NOT_JVMTI_RETURN;365static void clear_detected_exception (JavaThread* thread) NOT_JVMTI_RETURN;366367static void oops_do(OopClosure* f) NOT_JVMTI_RETURN;368static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN;369static void gc_epilogue() NOT_JVMTI_RETURN;370371static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN;372373// attach support374static jint load_agent_library(AttachOperation* op, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);375376// SetNativeMethodPrefix support377static char** get_all_native_method_prefixes(int* count_ptr) NOT_JVMTI_RETURN_(NULL);378};379380// Support class used by JvmtiDynamicCodeEventCollector and others. It381// describes a single code blob by name and address range.382class JvmtiCodeBlobDesc : public CHeapObj<mtInternal> {383private:384char _name[64];385address _code_begin;386address _code_end;387388public:389JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) {390assert(name != NULL, "all code blobs must be named");391strncpy(_name, name, sizeof(_name) - 1);392_name[sizeof(_name)-1] = '\0';393_code_begin = code_begin;394_code_end = code_end;395}396char* name() { return _name; }397address code_begin() { return _code_begin; }398address code_end() { return _code_end; }399};400401// JvmtiEventCollector is a helper class to setup thread for402// event collection.403class JvmtiEventCollector : public StackObj {404private:405JvmtiEventCollector* _prev; // Save previous one to support nested event collector.406407public:408void setup_jvmti_thread_state(); // Set this collector in current thread.409void unset_jvmti_thread_state(); // Reset previous collector in current thread.410virtual bool is_dynamic_code_event() { return false; }411virtual bool is_vm_object_alloc_event(){ return false; }412JvmtiEventCollector *get_prev() { return _prev; }413};414415// A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport416// interface. It collects "dynamic code generated" events that are posted417// while holding locks. When the event collector goes out of scope the418// events will be posted.419//420// Usage :-421//422// {423// JvmtiDynamicCodeEventCollector event_collector;424// :425// { MutexLocker ml(...)426// :427// JvmtiExport::post_dynamic_code_generated_while_holding_locks(...)428// }429// // event collector goes out of scope => post events to profiler.430// }431432class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector {433private:434GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs; // collected code blob events435436friend class JvmtiExport;437void register_stub(const char* name, address start, address end);438439public:440JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;441~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN;442bool is_dynamic_code_event() { return true; }443444};445446// Used to record vm internally allocated object oops and post447// vm object alloc event for objects visible to java world.448// Constructor enables JvmtiThreadState flag and all vm allocated449// objects are recorded in a growable array. When destructor is450// called the vm object alloc event is posted for each objects451// visible to java world.452// See jvm.cpp file for its usage.453//454class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector {455private:456GrowableArray<oop>* _allocated; // field to record vm internally allocated object oop.457bool _enable; // This flag is enabled in constructor and disabled458// in destructor before posting event. To avoid459// collection of objects allocated while running java code inside460// agent post_vm_object_alloc() event handler.461462//GC support463void oops_do(OopClosure* f);464465friend class JvmtiExport;466// Record vm allocated object oop.467inline void record_allocation(oop obj);468469//GC support470static void oops_do_for_all_threads(OopClosure* f);471472public:473JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;474~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN;475bool is_vm_object_alloc_event() { return true; }476477bool is_enabled() { return _enable; }478void set_enabled(bool on) { _enable = on; }479};480481482483// Marker class to disable the posting of VMObjectAlloc events484// within its scope.485//486// Usage :-487//488// {489// NoJvmtiVMObjectAllocMark njm;490// :491// // VMObjAlloc event will not be posted492// JvmtiExport::vm_object_alloc_event_collector(obj);493// :494// }495496class NoJvmtiVMObjectAllocMark : public StackObj {497private:498// enclosing collector if enabled, NULL otherwise499JvmtiVMObjectAllocEventCollector *_collector;500501bool was_enabled() { return _collector != NULL; }502503public:504NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN;505~NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN;506};507508509// Base class for reporting GC events to JVMTI.510class JvmtiGCMarker : public StackObj {511public:512JvmtiGCMarker() NOT_JVMTI_RETURN;513~JvmtiGCMarker() NOT_JVMTI_RETURN;514};515516// JvmtiHideSingleStepping is a helper class for hiding517// internal single step events.518class JvmtiHideSingleStepping : public StackObj {519private:520bool _single_step_hidden;521JavaThread * _thread;522523public:524JvmtiHideSingleStepping(JavaThread * thread) {525assert(thread != NULL, "sanity check");526527_single_step_hidden = false;528_thread = thread;529if (JvmtiExport::should_post_single_step()) {530_single_step_hidden = JvmtiExport::hide_single_stepping(_thread);531}532}533534~JvmtiHideSingleStepping() {535if (_single_step_hidden) {536JvmtiExport::expose_single_stepping(_thread);537}538}539};540541#endif // SHARE_VM_PRIMS_JVMTIEXPORT_HPP542543544