aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_PRIMS_JVMTIEXPORT_HPP aoqi@0: #define SHARE_VM_PRIMS_JVMTIEXPORT_HPP aoqi@0: aoqi@0: #include "jvmtifiles/jvmti.h" aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "memory/iterator.hpp" aoqi@0: #include "oops/oop.hpp" aoqi@0: #include "oops/oopsHierarchy.hpp" aoqi@0: #include "runtime/frame.hpp" aoqi@0: #include "runtime/handles.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: #include "utilities/growableArray.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: aoqi@0: // Must be included after jvmti.h. aoqi@0: #include "code/jvmticmlr.h" aoqi@0: aoqi@0: // Forward declarations aoqi@0: aoqi@0: class JvmtiEventControllerPrivate; aoqi@0: class JvmtiManageCapabilities; aoqi@0: class JvmtiEnv; aoqi@0: class JvmtiThreadState; aoqi@0: class AttachOperation; aoqi@0: aoqi@0: #define JVMTI_SUPPORT_FLAG(key) \ aoqi@0: private: \ aoqi@0: static bool _##key; \ aoqi@0: public: \ aoqi@0: inline static void set_##key(bool on) { \ aoqi@0: JVMTI_ONLY(_##key = (on != 0)); \ aoqi@0: NOT_JVMTI(report_unsupported(on)); \ aoqi@0: } \ aoqi@0: inline static bool key() { \ aoqi@0: JVMTI_ONLY(return _##key); \ aoqi@0: NOT_JVMTI(return false); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // This class contains the JVMTI interface for the rest of hotspot. aoqi@0: // aoqi@0: class JvmtiExport : public AllStatic { aoqi@0: friend class VMStructs; aoqi@0: friend class CompileReplay; aoqi@0: aoqi@0: private: aoqi@0: aoqi@0: #if INCLUDE_JVMTI aoqi@0: static int _field_access_count; aoqi@0: static int _field_modification_count; aoqi@0: aoqi@0: static bool _can_access_local_variables; aoqi@0: static bool _can_hotswap_or_post_breakpoint; aoqi@0: static bool _can_modify_any_class; aoqi@0: static bool _can_walk_any_space; aoqi@0: #endif // INCLUDE_JVMTI aoqi@0: aoqi@0: JVMTI_SUPPORT_FLAG(can_get_source_debug_extension) aoqi@0: JVMTI_SUPPORT_FLAG(can_maintain_original_method_order) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_interpreter_events) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_on_exceptions) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_breakpoint) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_field_access) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_field_modification) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_method_entry) aoqi@0: JVMTI_SUPPORT_FLAG(can_post_method_exit) aoqi@0: JVMTI_SUPPORT_FLAG(can_pop_frame) aoqi@0: JVMTI_SUPPORT_FLAG(can_force_early_return) aoqi@0: aoqi@0: friend class JvmtiEventControllerPrivate; // should only modify these flags aoqi@0: JVMTI_SUPPORT_FLAG(should_post_single_step) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_field_access) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_field_modification) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_class_load) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_class_prepare) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_class_unload) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_native_method_bind) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_compiled_method_load) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_compiled_method_unload) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_dynamic_code_generated) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_monitor_contended_enter) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_monitor_contended_entered) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_monitor_wait) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_monitor_waited) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_data_dump) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_garbage_collection_start) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_garbage_collection_finish) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_on_exceptions) aoqi@0: aoqi@0: // ------ the below maybe don't have to be (but are for now) aoqi@0: // fixed conditions here ------------ aoqi@0: // any events can be enabled aoqi@0: JVMTI_SUPPORT_FLAG(should_post_thread_life) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_object_free) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_resource_exhausted) aoqi@0: aoqi@0: // we are holding objects on the heap - need to talk to GC - e.g. aoqi@0: // breakpoint info aoqi@0: JVMTI_SUPPORT_FLAG(should_clean_up_heap_objects) aoqi@0: JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc) aoqi@0: aoqi@0: // If flag cannot be implemented, give an error if on=true aoqi@0: static void report_unsupported(bool on); aoqi@0: aoqi@0: // these should only be called by the friend class aoqi@0: friend class JvmtiManageCapabilities; aoqi@0: inline static void set_can_modify_any_class(bool on) { aoqi@0: JVMTI_ONLY(_can_modify_any_class = (on != 0);) aoqi@0: } aoqi@0: inline static void set_can_access_local_variables(bool on) { aoqi@0: JVMTI_ONLY(_can_access_local_variables = (on != 0);) aoqi@0: } aoqi@0: inline static void set_can_hotswap_or_post_breakpoint(bool on) { aoqi@0: JVMTI_ONLY(_can_hotswap_or_post_breakpoint = (on != 0);) aoqi@0: } aoqi@0: inline static void set_can_walk_any_space(bool on) { aoqi@0: JVMTI_ONLY(_can_walk_any_space = (on != 0);) aoqi@0: } aoqi@0: aoqi@0: enum { aoqi@0: JVMTI_VERSION_MASK = 0x70000000, aoqi@0: JVMTI_VERSION_VALUE = 0x30000000, aoqi@0: JVMDI_VERSION_VALUE = 0x20000000 aoqi@0: }; aoqi@0: aoqi@0: static void post_field_modification(JavaThread *thread, Method* method, address location, aoqi@0: KlassHandle field_klass, Handle object, jfieldID field, aoqi@0: char sig_type, jvalue *value); aoqi@0: aoqi@0: aoqi@0: // posts a DynamicCodeGenerated event (internal/private implementation). aoqi@0: // The public post_dynamic_code_generated* functions make use of the aoqi@0: // internal implementation. Also called from JvmtiDeferredEvent::post() aoqi@0: static void post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: private: aoqi@0: aoqi@0: // GenerateEvents support to allow posting of CompiledMethodLoad and aoqi@0: // DynamicCodeGenerated events for a given environment. aoqi@0: friend class JvmtiCodeBlobEvents; aoqi@0: aoqi@0: static void post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length, aoqi@0: const void *code_begin, const jint map_length, aoqi@0: const jvmtiAddrLocationMap* map) NOT_JVMTI_RETURN; aoqi@0: static void post_dynamic_code_generated(JvmtiEnv* env, const char *name, const void *code_begin, aoqi@0: const void *code_end) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // The RedefineClasses() API breaks some invariants in the "regular" aoqi@0: // system. For example, there are sanity checks when GC'ing nmethods aoqi@0: // that require the containing class to be unloading. However, when a aoqi@0: // method is redefined, the old method and nmethod can become GC'able aoqi@0: // without the containing class unloading. The state of becoming aoqi@0: // GC'able can be asynchronous to the RedefineClasses() call since aoqi@0: // the old method may still be running and cannot be GC'ed until aoqi@0: // after all old invocations have finished. Additionally, a method aoqi@0: // that has not been redefined may have an nmethod that depends on aoqi@0: // the redefined method. The dependent nmethod will get deopted in aoqi@0: // this case and may also be GC'able without the containing class aoqi@0: // being unloaded. aoqi@0: // aoqi@0: // This flag indicates whether RedefineClasses() has ever redefined aoqi@0: // one or more classes during the lifetime of the VM. The flag should aoqi@0: // only be set by the friend class and can be queried by other sub aoqi@0: // systems as needed to relax invariant checks. aoqi@0: static bool _has_redefined_a_class; aoqi@0: friend class VM_RedefineClasses; aoqi@0: inline static void set_has_redefined_a_class() { aoqi@0: JVMTI_ONLY(_has_redefined_a_class = true;) aoqi@0: } aoqi@0: // Flag to indicate if the compiler has recorded all dependencies. When the aoqi@0: // can_redefine_classes capability is enabled in the OnLoad phase then the compiler aoqi@0: // records all dependencies from startup. However if the capability is first aoqi@0: // enabled some time later then the dependencies recorded by the compiler aoqi@0: // are incomplete. This flag is used by RedefineClasses to know if the aoqi@0: // dependency information is complete or not. aoqi@0: static bool _all_dependencies_are_recorded; aoqi@0: aoqi@0: public: aoqi@0: inline static bool has_redefined_a_class() { aoqi@0: JVMTI_ONLY(return _has_redefined_a_class); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: aoqi@0: inline static bool all_dependencies_are_recorded() { aoqi@0: return _all_dependencies_are_recorded; aoqi@0: } aoqi@0: aoqi@0: inline static void set_all_dependencies_are_recorded(bool on) { aoqi@0: _all_dependencies_are_recorded = (on != 0); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // let JVMTI know that the JVM_OnLoad code is running aoqi@0: static void enter_onload_phase() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // let JVMTI know that the VM isn't up yet (and JVM_OnLoad code isn't running) aoqi@0: static void enter_primordial_phase() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // let JVMTI know that the VM isn't up yet but JNI is live aoqi@0: static void enter_start_phase() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // let JVMTI know that the VM is fully up and running now aoqi@0: static void enter_live_phase() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // ------ can_* conditions (below) are set at OnLoad and never changed ------------ aoqi@0: inline static bool can_modify_any_class() { aoqi@0: JVMTI_ONLY(return _can_modify_any_class); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: inline static bool can_access_local_variables() { aoqi@0: JVMTI_ONLY(return _can_access_local_variables); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: inline static bool can_hotswap_or_post_breakpoint() { aoqi@0: JVMTI_ONLY(return _can_hotswap_or_post_breakpoint); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: inline static bool can_walk_any_space() { aoqi@0: JVMTI_ONLY(return _can_walk_any_space); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: aoqi@0: // field access management aoqi@0: static address get_field_access_count_addr() NOT_JVMTI_RETURN_(0); aoqi@0: aoqi@0: // field modification management aoqi@0: static address get_field_modification_count_addr() NOT_JVMTI_RETURN_(0); aoqi@0: aoqi@0: // ----------------- aoqi@0: aoqi@0: static bool is_jvmti_version(jint version) { aoqi@0: JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMTI_VERSION_VALUE); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: static bool is_jvmdi_version(jint version) { aoqi@0: JVMTI_ONLY(return (version & JVMTI_VERSION_MASK) == JVMDI_VERSION_VALUE); aoqi@0: NOT_JVMTI(return false); aoqi@0: } aoqi@0: static jint get_jvmti_interface(JavaVM *jvm, void **penv, jint version) NOT_JVMTI_RETURN_(0); aoqi@0: static void decode_version_values(jint version, int * major, int * minor, aoqi@0: int * micro) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // single stepping management methods aoqi@0: static void at_single_stepping_point(JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN; aoqi@0: static void expose_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN; aoqi@0: static bool hide_single_stepping(JavaThread *thread) NOT_JVMTI_RETURN_(false); aoqi@0: aoqi@0: // Methods that notify the debugger that something interesting has happened in the VM. aoqi@0: static void post_vm_start () NOT_JVMTI_RETURN; aoqi@0: static void post_vm_initialized () NOT_JVMTI_RETURN; aoqi@0: static void post_vm_death () NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_single_step (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN; aoqi@0: static void post_raw_breakpoint (JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_exception_throw (JavaThread *thread, Method* method, address location, oop exception) NOT_JVMTI_RETURN; aoqi@0: static void notice_unwind_due_to_exception (JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static oop jni_GetField_probe (JavaThread *thread, jobject jobj, aoqi@0: oop obj, Klass* klass, jfieldID fieldID, bool is_static) aoqi@0: NOT_JVMTI_RETURN_(NULL); aoqi@0: static oop jni_GetField_probe_nh (JavaThread *thread, jobject jobj, aoqi@0: oop obj, Klass* klass, jfieldID fieldID, bool is_static) aoqi@0: NOT_JVMTI_RETURN_(NULL); aoqi@0: static void post_field_access_by_jni (JavaThread *thread, oop obj, aoqi@0: Klass* klass, jfieldID fieldID, bool is_static) NOT_JVMTI_RETURN; aoqi@0: static void post_field_access (JavaThread *thread, Method* method, aoqi@0: address location, KlassHandle field_klass, Handle object, jfieldID field) NOT_JVMTI_RETURN; aoqi@0: static oop jni_SetField_probe (JavaThread *thread, jobject jobj, aoqi@0: oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type, aoqi@0: jvalue *value) NOT_JVMTI_RETURN_(NULL); aoqi@0: static oop jni_SetField_probe_nh (JavaThread *thread, jobject jobj, aoqi@0: oop obj, Klass* klass, jfieldID fieldID, bool is_static, char sig_type, aoqi@0: jvalue *value) NOT_JVMTI_RETURN_(NULL); aoqi@0: static void post_field_modification_by_jni(JavaThread *thread, oop obj, aoqi@0: Klass* klass, jfieldID fieldID, bool is_static, char sig_type, aoqi@0: jvalue *value); aoqi@0: static void post_raw_field_modification(JavaThread *thread, Method* method, aoqi@0: address location, KlassHandle field_klass, Handle object, jfieldID field, aoqi@0: char sig_type, jvalue *value) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_method_entry (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN; aoqi@0: static void post_method_exit (JavaThread *thread, Method* method, frame current_frame) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_class_load (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN; aoqi@0: static void post_class_unload (Klass* klass) NOT_JVMTI_RETURN; aoqi@0: static void post_class_prepare (JavaThread *thread, Klass* klass) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_thread_start (JavaThread *thread) NOT_JVMTI_RETURN; aoqi@0: static void post_thread_end (JavaThread *thread) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // Support for java.lang.instrument agent loading. aoqi@0: static bool _should_post_class_file_load_hook; aoqi@0: inline static void set_should_post_class_file_load_hook(bool on) { _should_post_class_file_load_hook = on; } aoqi@0: inline static bool should_post_class_file_load_hook() { aoqi@0: JVMTI_ONLY(return _should_post_class_file_load_hook); aoqi@0: NOT_JVMTI(return false;) aoqi@0: } aoqi@0: static void post_class_file_load_hook(Symbol* h_name, Handle class_loader, aoqi@0: Handle h_protection_domain, aoqi@0: unsigned char **data_ptr, unsigned char **end_ptr, aoqi@0: JvmtiCachedClassFileData **cache_ptr) NOT_JVMTI_RETURN; aoqi@0: static void post_native_method_bind(Method* method, address* function_ptr) NOT_JVMTI_RETURN; aoqi@0: static void post_compiled_method_load(nmethod *nm) NOT_JVMTI_RETURN; aoqi@0: static void post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // used to post a CompiledMethodUnload event aoqi@0: static void post_compiled_method_unload(jmethodID mid, const void *code_begin) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // similiar to post_dynamic_code_generated except that it can be used to aoqi@0: // post a DynamicCodeGenerated event while holding locks in the VM. Any event aoqi@0: // posted using this function is recorded by the enclosing event collector aoqi@0: // -- JvmtiDynamicCodeEventCollector. aoqi@0: static void post_dynamic_code_generated_while_holding_locks(const char* name, address code_begin, address code_end) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void post_garbage_collection_finish() NOT_JVMTI_RETURN; aoqi@0: static void post_garbage_collection_start() NOT_JVMTI_RETURN; aoqi@0: static void post_data_dump() NOT_JVMTI_RETURN; aoqi@0: static void post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN; aoqi@0: static void post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) NOT_JVMTI_RETURN; aoqi@0: static void post_monitor_wait(JavaThread *thread, oop obj, jlong timeout) NOT_JVMTI_RETURN; aoqi@0: static void post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) NOT_JVMTI_RETURN; aoqi@0: static void post_object_free(JvmtiEnv* env, jlong tag) NOT_JVMTI_RETURN; aoqi@0: static void post_resource_exhausted(jint resource_exhausted_flags, const char* detail) NOT_JVMTI_RETURN; aoqi@0: static void record_vm_internal_object_allocation(oop object) NOT_JVMTI_RETURN; aoqi@0: // Post objects collected by vm_object_alloc_event_collector. aoqi@0: static void post_vm_object_alloc(JavaThread *thread, oop object) NOT_JVMTI_RETURN; aoqi@0: // Collects vm internal objects for later event posting. aoqi@0: inline static void vm_object_alloc_event_collector(oop object) { aoqi@0: if (should_post_vm_object_alloc()) { aoqi@0: record_vm_internal_object_allocation(object); aoqi@0: } aoqi@0: } aoqi@0: inline static void post_array_size_exhausted() { aoqi@0: if (should_post_resource_exhausted()) { aoqi@0: post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, aoqi@0: "Requested array size exceeds VM limit"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static void cleanup_thread (JavaThread* thread) NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void oops_do(OopClosure* f) NOT_JVMTI_RETURN; aoqi@0: static void weak_oops_do(BoolObjectClosure* b, OopClosure* f) NOT_JVMTI_RETURN; aoqi@0: static void gc_epilogue() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: static void transition_pending_onload_raw_monitors() NOT_JVMTI_RETURN; aoqi@0: aoqi@0: // attach support aoqi@0: static jint load_agent_library(AttachOperation* op, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR); aoqi@0: aoqi@0: // SetNativeMethodPrefix support aoqi@0: static char** get_all_native_method_prefixes(int* count_ptr) NOT_JVMTI_RETURN_(NULL); aoqi@0: }; aoqi@0: aoqi@0: // Support class used by JvmtiDynamicCodeEventCollector and others. It aoqi@0: // describes a single code blob by name and address range. aoqi@0: class JvmtiCodeBlobDesc : public CHeapObj { aoqi@0: private: aoqi@0: char _name[64]; aoqi@0: address _code_begin; aoqi@0: address _code_end; aoqi@0: aoqi@0: public: aoqi@0: JvmtiCodeBlobDesc(const char *name, address code_begin, address code_end) { aoqi@0: assert(name != NULL, "all code blobs must be named"); aoqi@0: strncpy(_name, name, sizeof(_name)); aoqi@0: _name[sizeof(_name)-1] = '\0'; aoqi@0: _code_begin = code_begin; aoqi@0: _code_end = code_end; aoqi@0: } aoqi@0: char* name() { return _name; } aoqi@0: address code_begin() { return _code_begin; } aoqi@0: address code_end() { return _code_end; } aoqi@0: }; aoqi@0: aoqi@0: // JvmtiEventCollector is a helper class to setup thread for aoqi@0: // event collection. aoqi@0: class JvmtiEventCollector : public StackObj { aoqi@0: private: aoqi@0: JvmtiEventCollector* _prev; // Save previous one to support nested event collector. aoqi@0: aoqi@0: public: aoqi@0: void setup_jvmti_thread_state(); // Set this collector in current thread. aoqi@0: void unset_jvmti_thread_state(); // Reset previous collector in current thread. aoqi@0: virtual bool is_dynamic_code_event() { return false; } aoqi@0: virtual bool is_vm_object_alloc_event(){ return false; } aoqi@0: JvmtiEventCollector *get_prev() { return _prev; } aoqi@0: }; aoqi@0: aoqi@0: // A JvmtiDynamicCodeEventCollector is a helper class for the JvmtiExport aoqi@0: // interface. It collects "dynamic code generated" events that are posted aoqi@0: // while holding locks. When the event collector goes out of scope the aoqi@0: // events will be posted. aoqi@0: // aoqi@0: // Usage :- aoqi@0: // aoqi@0: // { aoqi@0: // JvmtiDynamicCodeEventCollector event_collector; aoqi@0: // : aoqi@0: // { MutexLocker ml(...) aoqi@0: // : aoqi@0: // JvmtiExport::post_dynamic_code_generated_while_holding_locks(...) aoqi@0: // } aoqi@0: // // event collector goes out of scope => post events to profiler. aoqi@0: // } aoqi@0: aoqi@0: class JvmtiDynamicCodeEventCollector : public JvmtiEventCollector { aoqi@0: private: aoqi@0: GrowableArray* _code_blobs; // collected code blob events aoqi@0: aoqi@0: friend class JvmtiExport; aoqi@0: void register_stub(const char* name, address start, address end); aoqi@0: aoqi@0: public: aoqi@0: JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN; aoqi@0: ~JvmtiDynamicCodeEventCollector() NOT_JVMTI_RETURN; aoqi@0: bool is_dynamic_code_event() { return true; } aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: // Used to record vm internally allocated object oops and post aoqi@0: // vm object alloc event for objects visible to java world. aoqi@0: // Constructor enables JvmtiThreadState flag and all vm allocated aoqi@0: // objects are recorded in a growable array. When destructor is aoqi@0: // called the vm object alloc event is posted for each objects aoqi@0: // visible to java world. aoqi@0: // See jvm.cpp file for its usage. aoqi@0: // aoqi@0: class JvmtiVMObjectAllocEventCollector : public JvmtiEventCollector { aoqi@0: private: aoqi@0: GrowableArray* _allocated; // field to record vm internally allocated object oop. aoqi@0: bool _enable; // This flag is enabled in constructor and disabled aoqi@0: // in destructor before posting event. To avoid aoqi@0: // collection of objects allocated while running java code inside aoqi@0: // agent post_vm_object_alloc() event handler. aoqi@0: aoqi@0: //GC support aoqi@0: void oops_do(OopClosure* f); aoqi@0: aoqi@0: friend class JvmtiExport; aoqi@0: // Record vm allocated object oop. aoqi@0: inline void record_allocation(oop obj); aoqi@0: aoqi@0: //GC support aoqi@0: static void oops_do_for_all_threads(OopClosure* f); aoqi@0: aoqi@0: public: aoqi@0: JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; aoqi@0: ~JvmtiVMObjectAllocEventCollector() NOT_JVMTI_RETURN; aoqi@0: bool is_vm_object_alloc_event() { return true; } aoqi@0: aoqi@0: bool is_enabled() { return _enable; } aoqi@0: void set_enabled(bool on) { _enable = on; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: aoqi@0: // Marker class to disable the posting of VMObjectAlloc events aoqi@0: // within its scope. aoqi@0: // aoqi@0: // Usage :- aoqi@0: // aoqi@0: // { aoqi@0: // NoJvmtiVMObjectAllocMark njm; aoqi@0: // : aoqi@0: // // VMObjAlloc event will not be posted aoqi@0: // JvmtiExport::vm_object_alloc_event_collector(obj); aoqi@0: // : aoqi@0: // } aoqi@0: aoqi@0: class NoJvmtiVMObjectAllocMark : public StackObj { aoqi@0: private: aoqi@0: // enclosing collector if enabled, NULL otherwise aoqi@0: JvmtiVMObjectAllocEventCollector *_collector; aoqi@0: aoqi@0: bool was_enabled() { return _collector != NULL; } aoqi@0: aoqi@0: public: aoqi@0: NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN; aoqi@0: ~NoJvmtiVMObjectAllocMark() NOT_JVMTI_RETURN; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Base class for reporting GC events to JVMTI. aoqi@0: class JvmtiGCMarker : public StackObj { aoqi@0: public: aoqi@0: JvmtiGCMarker() NOT_JVMTI_RETURN; aoqi@0: ~JvmtiGCMarker() NOT_JVMTI_RETURN; aoqi@0: }; aoqi@0: aoqi@0: // JvmtiHideSingleStepping is a helper class for hiding aoqi@0: // internal single step events. aoqi@0: class JvmtiHideSingleStepping : public StackObj { aoqi@0: private: aoqi@0: bool _single_step_hidden; aoqi@0: JavaThread * _thread; aoqi@0: aoqi@0: public: aoqi@0: JvmtiHideSingleStepping(JavaThread * thread) { aoqi@0: assert(thread != NULL, "sanity check"); aoqi@0: aoqi@0: _single_step_hidden = false; aoqi@0: _thread = thread; aoqi@0: if (JvmtiExport::should_post_single_step()) { aoqi@0: _single_step_hidden = JvmtiExport::hide_single_stepping(_thread); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: ~JvmtiHideSingleStepping() { aoqi@0: if (_single_step_hidden) { aoqi@0: JvmtiExport::expose_single_stepping(_thread); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_PRIMS_JVMTIEXPORT_HPP