duke@435: /* kamg@2511: * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "code/nmethod.hpp" stefank@2314: #include "code/pcDesc.hpp" stefank@2314: #include "code/scopeDesc.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "jvmtifiles/jvmtiEnv.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/objArrayOop.hpp" stefank@2314: #include "prims/jvmtiCodeBlobEvents.hpp" stefank@2314: #include "prims/jvmtiEventController.hpp" stefank@2314: #include "prims/jvmtiEventController.inline.hpp" stefank@2314: #include "prims/jvmtiExport.hpp" stefank@2314: #include "prims/jvmtiImpl.hpp" stefank@2314: #include "prims/jvmtiManageCapabilities.hpp" stefank@2314: #include "prims/jvmtiRawMonitor.hpp" stefank@2314: #include "prims/jvmtiTagMap.hpp" stefank@2314: #include "prims/jvmtiThreadState.inline.hpp" stefank@2314: #include "runtime/arguments.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/objectMonitor.hpp" stefank@2314: #include "runtime/objectMonitor.inline.hpp" stefank@2314: #include "runtime/thread.hpp" stefank@2314: #include "runtime/vframe.hpp" stefank@2314: #include "services/attachListener.hpp" stefank@2314: #include "services/serviceUtil.hpp" stefank@2314: #ifndef SERIALGC stefank@2314: #include "gc_implementation/parallelScavenge/psMarkSweep.hpp" stefank@2314: #endif duke@435: duke@435: #ifdef JVMTI_TRACE duke@435: #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; tty->print_cr out; } duke@435: #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; tty->print_cr out; } duke@435: #else duke@435: #define EVT_TRIG_TRACE(evt,out) duke@435: #define EVT_TRACE(evt,out) duke@435: #endif duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEventTransition duke@435: // duke@435: // TO DO -- duke@435: // more handle purging duke@435: duke@435: // Use this for JavaThreads and state is _thread_in_vm. duke@435: class JvmtiJavaThreadEventTransition : StackObj { duke@435: private: duke@435: ResourceMark _rm; duke@435: ThreadToNativeFromVM _transition; duke@435: HandleMark _hm; duke@435: duke@435: public: duke@435: JvmtiJavaThreadEventTransition(JavaThread *thread) : duke@435: _rm(), duke@435: _transition(thread), duke@435: _hm(thread) {}; duke@435: }; duke@435: duke@435: // For JavaThreads which are not in _thread_in_vm state duke@435: // and other system threads use this. duke@435: class JvmtiThreadEventTransition : StackObj { duke@435: private: duke@435: ResourceMark _rm; duke@435: HandleMark _hm; duke@435: JavaThreadState _saved_state; duke@435: JavaThread *_jthread; duke@435: duke@435: public: duke@435: JvmtiThreadEventTransition(Thread *thread) : _rm(), _hm() { duke@435: if (thread->is_Java_thread()) { duke@435: _jthread = (JavaThread *)thread; duke@435: _saved_state = _jthread->thread_state(); duke@435: if (_saved_state == _thread_in_Java) { duke@435: ThreadStateTransition::transition_from_java(_jthread, _thread_in_native); duke@435: } else { duke@435: ThreadStateTransition::transition(_jthread, _saved_state, _thread_in_native); duke@435: } duke@435: } else { duke@435: _jthread = NULL; duke@435: } duke@435: } duke@435: duke@435: ~JvmtiThreadEventTransition() { duke@435: if (_jthread != NULL) duke@435: ThreadStateTransition::transition_from_native(_jthread, _saved_state); duke@435: } duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEventMark duke@435: // duke@435: duke@435: class JvmtiEventMark : public StackObj { duke@435: private: duke@435: JavaThread *_thread; duke@435: JNIEnv* _jni_env; duke@435: bool _exception_detected; duke@435: bool _exception_caught; duke@435: #if 0 duke@435: JNIHandleBlock* _hblock; duke@435: #endif duke@435: duke@435: public: duke@435: JvmtiEventMark(JavaThread *thread) : _thread(thread), duke@435: _jni_env(thread->jni_environment()) { duke@435: #if 0 duke@435: _hblock = thread->active_handles(); duke@435: _hblock->clear_thoroughly(); // so we can be safe duke@435: #else duke@435: // we want to use the code above - but that needs the JNIHandle changes - later... duke@435: // for now, steal JNI push local frame code duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: // we are before an event. duke@435: // Save current jvmti thread exception state. duke@435: if (state != NULL) { duke@435: _exception_detected = state->is_exception_detected(); duke@435: _exception_caught = state->is_exception_caught(); duke@435: } else { duke@435: _exception_detected = false; duke@435: _exception_caught = false; duke@435: } duke@435: duke@435: JNIHandleBlock* old_handles = thread->active_handles(); duke@435: JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); duke@435: assert(new_handles != NULL, "should not be NULL"); duke@435: new_handles->set_pop_frame_link(old_handles); duke@435: thread->set_active_handles(new_handles); duke@435: #endif duke@435: assert(thread == JavaThread::current(), "thread must be current!"); duke@435: thread->frame_anchor()->make_walkable(thread); duke@435: }; duke@435: duke@435: ~JvmtiEventMark() { duke@435: #if 0 duke@435: _hblock->clear(); // for consistency with future correct behavior duke@435: #else duke@435: // we want to use the code above - but that needs the JNIHandle changes - later... duke@435: // for now, steal JNI pop local frame code duke@435: JNIHandleBlock* old_handles = _thread->active_handles(); duke@435: JNIHandleBlock* new_handles = old_handles->pop_frame_link(); duke@435: assert(new_handles != NULL, "should not be NULL"); duke@435: _thread->set_active_handles(new_handles); duke@435: // Note that we set the pop_frame_link to NULL explicitly, otherwise duke@435: // the release_block call will release the blocks. duke@435: old_handles->set_pop_frame_link(NULL); duke@435: JNIHandleBlock::release_block(old_handles, _thread); // may block duke@435: #endif duke@435: duke@435: JvmtiThreadState* state = _thread->jvmti_thread_state(); duke@435: // we are continuing after an event. duke@435: if (state != NULL) { duke@435: // Restore the jvmti thread exception state. duke@435: if (_exception_detected) { duke@435: state->set_exception_detected(); duke@435: } duke@435: if (_exception_caught) { duke@435: state->set_exception_caught(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: #if 0 duke@435: jobject to_jobject(oop obj) { return obj == NULL? NULL : _hblock->allocate_handle_fast(obj); } duke@435: #else duke@435: // we want to use the code above - but that needs the JNIHandle changes - later... duke@435: // for now, use regular make_local duke@435: jobject to_jobject(oop obj) { return JNIHandles::make_local(_thread,obj); } duke@435: #endif duke@435: duke@435: jclass to_jclass(klassOop klass) { return (klass == NULL ? NULL : (jclass)to_jobject(Klass::cast(klass)->java_mirror())); } duke@435: duke@435: jmethodID to_jmethodID(methodHandle method) { return method->jmethod_id(); } duke@435: duke@435: JNIEnv* jni_env() { return _jni_env; } duke@435: }; duke@435: duke@435: class JvmtiThreadEventMark : public JvmtiEventMark { duke@435: private: duke@435: jthread _jt; duke@435: duke@435: public: duke@435: JvmtiThreadEventMark(JavaThread *thread) : duke@435: JvmtiEventMark(thread) { duke@435: _jt = (jthread)(to_jobject(thread->threadObj())); duke@435: }; duke@435: jthread jni_thread() { return _jt; } duke@435: }; duke@435: duke@435: class JvmtiClassEventMark : public JvmtiThreadEventMark { duke@435: private: duke@435: jclass _jc; duke@435: duke@435: public: duke@435: JvmtiClassEventMark(JavaThread *thread, klassOop klass) : duke@435: JvmtiThreadEventMark(thread) { duke@435: _jc = to_jclass(klass); duke@435: }; duke@435: jclass jni_class() { return _jc; } duke@435: }; duke@435: duke@435: class JvmtiMethodEventMark : public JvmtiThreadEventMark { duke@435: private: duke@435: jmethodID _mid; duke@435: duke@435: public: duke@435: JvmtiMethodEventMark(JavaThread *thread, methodHandle method) : duke@435: JvmtiThreadEventMark(thread), duke@435: _mid(to_jmethodID(method)) {}; duke@435: jmethodID jni_methodID() { return _mid; } duke@435: }; duke@435: duke@435: class JvmtiLocationEventMark : public JvmtiMethodEventMark { duke@435: private: duke@435: jlocation _loc; duke@435: duke@435: public: duke@435: JvmtiLocationEventMark(JavaThread *thread, methodHandle method, address location) : duke@435: JvmtiMethodEventMark(thread, method), duke@435: _loc(location - method->code_base()) {}; duke@435: jlocation location() { return _loc; } duke@435: }; duke@435: duke@435: class JvmtiExceptionEventMark : public JvmtiLocationEventMark { duke@435: private: duke@435: jobject _exc; duke@435: duke@435: public: duke@435: JvmtiExceptionEventMark(JavaThread *thread, methodHandle method, address location, Handle exception) : duke@435: JvmtiLocationEventMark(thread, method, location), duke@435: _exc(to_jobject(exception())) {}; duke@435: jobject exception() { return _exc; } duke@435: }; duke@435: duke@435: class JvmtiClassFileLoadEventMark : public JvmtiThreadEventMark { duke@435: private: duke@435: const char *_class_name; duke@435: jobject _jloader; duke@435: jobject _protection_domain; duke@435: jclass _class_being_redefined; duke@435: duke@435: public: coleenp@2497: JvmtiClassFileLoadEventMark(JavaThread *thread, Symbol* name, duke@435: Handle class_loader, Handle prot_domain, KlassHandle *class_being_redefined) : JvmtiThreadEventMark(thread) { coleenp@2497: _class_name = name != NULL? name->as_utf8() : NULL; duke@435: _jloader = (jobject)to_jobject(class_loader()); duke@435: _protection_domain = (jobject)to_jobject(prot_domain()); duke@435: if (class_being_redefined == NULL) { duke@435: _class_being_redefined = NULL; duke@435: } else { duke@435: _class_being_redefined = (jclass)to_jclass((*class_being_redefined)()); duke@435: } duke@435: }; duke@435: const char *class_name() { duke@435: return _class_name; duke@435: } duke@435: jobject jloader() { duke@435: return _jloader; duke@435: } duke@435: jobject protection_domain() { duke@435: return _protection_domain; duke@435: } duke@435: jclass class_being_redefined() { duke@435: return _class_being_redefined; duke@435: } duke@435: }; duke@435: duke@435: ////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: int JvmtiExport::_field_access_count = 0; duke@435: int JvmtiExport::_field_modification_count = 0; duke@435: duke@435: bool JvmtiExport::_can_access_local_variables = false; duke@435: bool JvmtiExport::_can_hotswap_or_post_breakpoint = false; duke@435: bool JvmtiExport::_can_modify_any_class = false; duke@435: bool JvmtiExport::_can_walk_any_space = false; duke@435: duke@435: bool JvmtiExport::_has_redefined_a_class = false; duke@435: bool JvmtiExport::_all_dependencies_are_recorded = false; duke@435: duke@435: // duke@435: // field access management duke@435: // duke@435: duke@435: // interpreter generator needs the address of the counter duke@435: address JvmtiExport::get_field_access_count_addr() { duke@435: // We don't grab a lock because we don't want to duke@435: // serialize field access between all threads. This means that a duke@435: // thread on another processor can see the wrong count value and duke@435: // may either miss making a needed call into post_field_access() duke@435: // or will make an unneeded call into post_field_access(). We pay duke@435: // this price to avoid slowing down the VM when we aren't watching duke@435: // field accesses. duke@435: // Other access/mutation safe by virtue of being in VM state. duke@435: return (address)(&_field_access_count); duke@435: } duke@435: duke@435: // duke@435: // field modification management duke@435: // duke@435: duke@435: // interpreter generator needs the address of the counter duke@435: address JvmtiExport::get_field_modification_count_addr() { duke@435: // We don't grab a lock because we don't duke@435: // want to serialize field modification between all threads. This duke@435: // means that a thread on another processor can see the wrong duke@435: // count value and may either miss making a needed call into duke@435: // post_field_modification() or will make an unneeded call into duke@435: // post_field_modification(). We pay this price to avoid slowing duke@435: // down the VM when we aren't watching field modifications. duke@435: // Other access/mutation safe by virtue of being in VM state. duke@435: return (address)(&_field_modification_count); duke@435: } duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // Functions needed by java.lang.instrument for starting up javaagent. duke@435: /////////////////////////////////////////////////////////////// duke@435: duke@435: jint duke@435: JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { dcubed@1556: // The JVMTI_VERSION_INTERFACE_JVMTI part of the version number dcubed@1556: // has already been validated in JNI GetEnv(). dcubed@1556: int major, minor, micro; dcubed@1556: dcubed@1556: // micro version doesn't matter here (yet?) dcubed@1556: decode_version_values(version, &major, &minor, µ); dcubed@1556: switch (major) { kamg@2330: case 1: dcubed@1556: switch (minor) { kamg@2330: case 0: // version 1.0. is recognized kamg@2330: case 1: // version 1.1. is recognized kamg@2330: case 2: // version 1.2. is recognized dcubed@1556: break; dcubed@1556: kamg@2330: default: dcubed@1556: return JNI_EVERSION; // unsupported minor version number dcubed@1556: } dcubed@1556: break; kamg@2330: default: dcubed@1556: return JNI_EVERSION; // unsupported major version number dcubed@1556: } duke@435: duke@435: if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) { duke@435: JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread(); duke@435: // transition code: native to VM duke@435: ThreadInVMfromNative __tiv(current_thread); duke@435: __ENTRY(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread) duke@435: debug_only(VMNativeEntryWrapper __vew;) duke@435: dcubed@1556: JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version); duke@435: *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv* duke@435: return JNI_OK; duke@435: duke@435: } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) { duke@435: // not live, no thread to transition dcubed@1556: JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version); duke@435: *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv* duke@435: return JNI_OK; duke@435: duke@435: } else { duke@435: // Called at the wrong time duke@435: *penv = NULL; duke@435: return JNI_EDETACHED; duke@435: } duke@435: } duke@435: dcubed@1556: dcubed@1556: void dcubed@1556: JvmtiExport::decode_version_values(jint version, int * major, int * minor, dcubed@1556: int * micro) { dcubed@1556: *major = (version & JVMTI_VERSION_MASK_MAJOR) >> JVMTI_VERSION_SHIFT_MAJOR; dcubed@1556: *minor = (version & JVMTI_VERSION_MASK_MINOR) >> JVMTI_VERSION_SHIFT_MINOR; dcubed@1556: *micro = (version & JVMTI_VERSION_MASK_MICRO) >> JVMTI_VERSION_SHIFT_MICRO; dcubed@1556: } dcubed@1556: duke@435: void JvmtiExport::enter_primordial_phase() { duke@435: JvmtiEnvBase::set_phase(JVMTI_PHASE_PRIMORDIAL); duke@435: } duke@435: duke@435: void JvmtiExport::enter_start_phase() { duke@435: JvmtiManageCapabilities::recompute_always_capabilities(); duke@435: JvmtiEnvBase::set_phase(JVMTI_PHASE_START); duke@435: } duke@435: duke@435: void JvmtiExport::enter_onload_phase() { duke@435: JvmtiEnvBase::set_phase(JVMTI_PHASE_ONLOAD); duke@435: } duke@435: duke@435: void JvmtiExport::enter_live_phase() { duke@435: JvmtiEnvBase::set_phase(JVMTI_PHASE_LIVE); duke@435: } duke@435: duke@435: // duke@435: // JVMTI events that the VM posts to the debugger and also startup agent duke@435: // and call the agent's premain() for java.lang.instrument. duke@435: // duke@435: duke@435: void JvmtiExport::post_vm_start() { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Trg VM start event triggered" )); duke@435: duke@435: // can now enable some events duke@435: JvmtiEventController::vm_start(); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_VM_START)) { duke@435: EVT_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Evt VM start event sent" )); duke@435: duke@435: JavaThread *thread = JavaThread::current(); duke@435: JvmtiThreadEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventVMStart callback = env->callbacks()->VMStart; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_vm_initialized() { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Trg VM init event triggered" )); duke@435: duke@435: // can now enable events duke@435: JvmtiEventController::vm_init(); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_VM_INIT)) { duke@435: EVT_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Evt VM init event sent" )); duke@435: duke@435: JavaThread *thread = JavaThread::current(); duke@435: JvmtiThreadEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventVMInit callback = env->callbacks()->VMInit; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_vm_death() { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Trg VM death event triggered" )); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_VM_DEATH)) { duke@435: EVT_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Evt VM death event sent" )); duke@435: duke@435: JavaThread *thread = JavaThread::current(); duke@435: JvmtiEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventVMDeath callback = env->callbacks()->VMDeath; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: JvmtiEnvBase::set_phase(JVMTI_PHASE_DEAD); duke@435: JvmtiEventController::vm_death(); duke@435: } duke@435: duke@435: char** duke@435: JvmtiExport::get_all_native_method_prefixes(int* count_ptr) { duke@435: // Have to grab JVMTI thread state lock to be sure environment doesn't duke@435: // go away while we iterate them. No locks during VM bring-up. duke@435: if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) { duke@435: return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr); duke@435: } else { duke@435: MutexLocker mu(JvmtiThreadState_lock); duke@435: return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr); duke@435: } duke@435: } duke@435: duke@435: class JvmtiClassFileLoadHookPoster : public StackObj { duke@435: private: coleenp@2497: Symbol* _h_name; duke@435: Handle _class_loader; duke@435: Handle _h_protection_domain; duke@435: unsigned char ** _data_ptr; duke@435: unsigned char ** _end_ptr; duke@435: JavaThread * _thread; duke@435: jint _curr_len; duke@435: unsigned char * _curr_data; duke@435: JvmtiEnv * _curr_env; duke@435: jint * _cached_length_ptr; duke@435: unsigned char ** _cached_data_ptr; duke@435: JvmtiThreadState * _state; duke@435: KlassHandle * _h_class_being_redefined; duke@435: JvmtiClassLoadKind _load_kind; duke@435: duke@435: public: coleenp@2497: inline JvmtiClassFileLoadHookPoster(Symbol* h_name, Handle class_loader, duke@435: Handle h_protection_domain, duke@435: unsigned char **data_ptr, unsigned char **end_ptr, duke@435: unsigned char **cached_data_ptr, duke@435: jint *cached_length_ptr) { duke@435: _h_name = h_name; duke@435: _class_loader = class_loader; duke@435: _h_protection_domain = h_protection_domain; duke@435: _data_ptr = data_ptr; duke@435: _end_ptr = end_ptr; duke@435: _thread = JavaThread::current(); duke@435: _curr_len = *end_ptr - *data_ptr; duke@435: _curr_data = *data_ptr; duke@435: _curr_env = NULL; duke@435: _cached_length_ptr = cached_length_ptr; duke@435: _cached_data_ptr = cached_data_ptr; duke@435: *_cached_length_ptr = 0; duke@435: *_cached_data_ptr = NULL; duke@435: duke@435: _state = _thread->jvmti_thread_state(); duke@435: if (_state != NULL) { duke@435: _h_class_being_redefined = _state->get_class_being_redefined(); duke@435: _load_kind = _state->get_class_load_kind(); duke@435: // Clear class_being_redefined flag here. The action duke@435: // from agent handler could generate a new class file load duke@435: // hook event and if it is not cleared the new event generated duke@435: // from regular class file load could have this stale redefined duke@435: // class handle info. duke@435: _state->clear_class_being_redefined(); duke@435: } else { duke@435: // redefine and retransform will always set the thread state duke@435: _h_class_being_redefined = (KlassHandle *) NULL; duke@435: _load_kind = jvmti_class_load_kind_load; duke@435: } duke@435: } duke@435: duke@435: void post() { duke@435: // EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, duke@435: // ("JVMTI [%s] class file load hook event triggered", duke@435: // JvmtiTrace::safe_get_thread_name(_thread))); duke@435: post_all_envs(); duke@435: copy_modified_data(); duke@435: } duke@435: duke@435: private: duke@435: void post_all_envs() { duke@435: if (_load_kind != jvmti_class_load_kind_retransform) { duke@435: // for class load and redefine, duke@435: // call the non-retransformable agents duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (!env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) { duke@435: // non-retransformable agents cannot retransform back, duke@435: // so no need to cache the original class file bytes duke@435: post_to_env(env, false); duke@435: } duke@435: } duke@435: } duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: // retransformable agents get all events duke@435: if (env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) { duke@435: // retransformable agents need to cache the original class file duke@435: // bytes if changes are made via the ClassFileLoadHook duke@435: post_to_env(env, true); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void post_to_env(JvmtiEnv* env, bool caching_needed) { duke@435: unsigned char *new_data = NULL; duke@435: jint new_len = 0; duke@435: // EVT_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, duke@435: // ("JVMTI [%s] class file load hook event sent %s data_ptr = %d, data_len = %d", duke@435: // JvmtiTrace::safe_get_thread_name(_thread), coleenp@2497: // _h_name == NULL ? "NULL" : _h_name->as_utf8(), duke@435: // _curr_data, _curr_len )); duke@435: JvmtiClassFileLoadEventMark jem(_thread, _h_name, _class_loader, duke@435: _h_protection_domain, duke@435: _h_class_being_redefined); duke@435: JvmtiJavaThreadEventTransition jet(_thread); duke@435: JNIEnv* jni_env = (JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL)? duke@435: NULL : jem.jni_env(); duke@435: jvmtiEventClassFileLoadHook callback = env->callbacks()->ClassFileLoadHook; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jni_env, duke@435: jem.class_being_redefined(), duke@435: jem.jloader(), jem.class_name(), duke@435: jem.protection_domain(), duke@435: _curr_len, _curr_data, duke@435: &new_len, &new_data); duke@435: } duke@435: if (new_data != NULL) { duke@435: // this agent has modified class data. duke@435: if (caching_needed && *_cached_data_ptr == NULL) { duke@435: // data has been changed by the new retransformable agent duke@435: // and it hasn't already been cached, cache it duke@435: *_cached_data_ptr = (unsigned char *)os::malloc(_curr_len); duke@435: memcpy(*_cached_data_ptr, _curr_data, _curr_len); duke@435: *_cached_length_ptr = _curr_len; duke@435: } duke@435: duke@435: if (_curr_data != *_data_ptr) { duke@435: // curr_data is previous agent modified class data. duke@435: // And this has been changed by the new agent so duke@435: // we can delete it now. duke@435: _curr_env->Deallocate(_curr_data); duke@435: } duke@435: duke@435: // Class file data has changed by the current agent. duke@435: _curr_data = new_data; duke@435: _curr_len = new_len; duke@435: // Save the current agent env we need this to deallocate the duke@435: // memory allocated by this agent. duke@435: _curr_env = env; duke@435: } duke@435: } duke@435: duke@435: void copy_modified_data() { duke@435: // if one of the agent has modified class file data. duke@435: // Copy modified class data to new resources array. duke@435: if (_curr_data != *_data_ptr) { duke@435: *_data_ptr = NEW_RESOURCE_ARRAY(u1, _curr_len); duke@435: memcpy(*_data_ptr, _curr_data, _curr_len); duke@435: *_end_ptr = *_data_ptr + _curr_len; duke@435: _curr_env->Deallocate(_curr_data); duke@435: } duke@435: } duke@435: }; duke@435: duke@435: bool JvmtiExport::_should_post_class_file_load_hook = false; duke@435: duke@435: // this entry is for class file load hook on class load, redefine and retransform coleenp@2497: void JvmtiExport::post_class_file_load_hook(Symbol* h_name, duke@435: Handle class_loader, duke@435: Handle h_protection_domain, duke@435: unsigned char **data_ptr, duke@435: unsigned char **end_ptr, duke@435: unsigned char **cached_data_ptr, duke@435: jint *cached_length_ptr) { duke@435: JvmtiClassFileLoadHookPoster poster(h_name, class_loader, duke@435: h_protection_domain, duke@435: data_ptr, end_ptr, duke@435: cached_data_ptr, duke@435: cached_length_ptr); duke@435: poster.post(); duke@435: } duke@435: duke@435: void JvmtiExport::report_unsupported(bool on) { duke@435: // If any JVMTI service is turned on, we need to exit before native code duke@435: // tries to access nonexistant services. duke@435: if (on) { duke@435: vm_exit_during_initialization("Java Kernel does not support JVMTI."); duke@435: } duke@435: } duke@435: duke@435: duke@435: #ifndef JVMTI_KERNEL duke@435: static inline klassOop oop_to_klassOop(oop obj) { duke@435: klassOop k = obj->klass(); duke@435: duke@435: // if the object is a java.lang.Class then return the java mirror never@1577: if (k == SystemDictionary::Class_klass()) { duke@435: if (!java_lang_Class::is_primitive(obj)) { duke@435: k = java_lang_Class::as_klassOop(obj); duke@435: assert(k != NULL, "class for non-primitive mirror must exist"); duke@435: } duke@435: } duke@435: return k; duke@435: } duke@435: duke@435: class JvmtiVMObjectAllocEventMark : public JvmtiClassEventMark { duke@435: private: duke@435: jobject _jobj; duke@435: jlong _size; duke@435: public: duke@435: JvmtiVMObjectAllocEventMark(JavaThread *thread, oop obj) : JvmtiClassEventMark(thread, oop_to_klassOop(obj)) { duke@435: _jobj = (jobject)to_jobject(obj); duke@435: _size = obj->size() * wordSize; duke@435: }; duke@435: jobject jni_jobject() { return _jobj; } duke@435: jlong size() { return _size; } duke@435: }; duke@435: duke@435: class JvmtiCompiledMethodLoadEventMark : public JvmtiMethodEventMark { duke@435: private: duke@435: jint _code_size; duke@435: const void *_code_data; duke@435: jint _map_length; duke@435: jvmtiAddrLocationMap *_map; duke@435: const void *_compile_info; duke@435: public: dcubed@1619: JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = NULL) duke@435: : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) { twisti@2103: _code_data = nm->insts_begin(); twisti@2103: _code_size = nm->insts_size(); dcubed@1619: _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is NULL. duke@435: JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length); duke@435: } duke@435: ~JvmtiCompiledMethodLoadEventMark() { duke@435: FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, _map); duke@435: } duke@435: duke@435: jint code_size() { return _code_size; } duke@435: const void *code_data() { return _code_data; } duke@435: jint map_length() { return _map_length; } duke@435: const jvmtiAddrLocationMap* map() { return _map; } duke@435: const void *compile_info() { return _compile_info; } duke@435: }; duke@435: duke@435: duke@435: duke@435: class JvmtiMonitorEventMark : public JvmtiThreadEventMark { duke@435: private: duke@435: jobject _jobj; duke@435: public: duke@435: JvmtiMonitorEventMark(JavaThread *thread, oop object) duke@435: : JvmtiThreadEventMark(thread){ duke@435: _jobj = to_jobject(object); duke@435: } duke@435: jobject jni_object() { return _jobj; } duke@435: }; duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // pending CompiledMethodUnload support duke@435: // duke@435: kamg@2511: void JvmtiExport::post_compiled_method_unload( kamg@2511: jmethodID method, const void *code_begin) { kamg@2511: JavaThread* thread = JavaThread::current(); never@1932: EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, never@1932: ("JVMTI [%s] method compile unload event triggered", kamg@2511: JvmtiTrace::safe_get_thread_name(thread))); never@1932: never@1932: // post the event for each environment that has this event enabled. never@1932: JvmtiEnvIterator it; never@1932: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { never@1932: if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) { never@1932: never@1932: EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, never@1932: ("JVMTI [%s] class compile method unload event sent jmethodID " PTR_FORMAT, kamg@2511: JvmtiTrace::safe_get_thread_name(thread), method)); never@1932: kamg@2511: ResourceMark rm(thread); never@1932: kamg@2511: JvmtiEventMark jem(thread); kamg@2511: JvmtiJavaThreadEventTransition jet(thread); never@1932: jvmtiEventCompiledMethodUnload callback = env->callbacks()->CompiledMethodUnload; never@1932: if (callback != NULL) { never@1932: (*callback)(env->jvmti_external(), method, code_begin); never@1932: } never@1932: } never@1932: } never@1932: } never@1932: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiExport duke@435: // duke@435: duke@435: void JvmtiExport::post_raw_breakpoint(JavaThread *thread, methodOop method, address location) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Trg Breakpoint triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT); duke@435: if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) { duke@435: ThreadState old_os_state = thread->osthread()->get_state(); duke@435: thread->osthread()->set_state(BREAKPOINTED); duke@435: EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Evt Breakpoint sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiLocationEventMark jem(thread, mh, location); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location()); duke@435: } duke@435: duke@435: ets->set_breakpoint_posted(); duke@435: thread->osthread()->set_state(old_os_state); duke@435: } duke@435: } duke@435: } duke@435: duke@435: ////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: bool JvmtiExport::_can_get_source_debug_extension = false; duke@435: bool JvmtiExport::_can_maintain_original_method_order = false; duke@435: bool JvmtiExport::_can_post_interpreter_events = false; dcubed@1648: bool JvmtiExport::_can_post_on_exceptions = false; duke@435: bool JvmtiExport::_can_post_breakpoint = false; duke@435: bool JvmtiExport::_can_post_field_access = false; duke@435: bool JvmtiExport::_can_post_field_modification = false; duke@435: bool JvmtiExport::_can_post_method_entry = false; duke@435: bool JvmtiExport::_can_post_method_exit = false; duke@435: bool JvmtiExport::_can_pop_frame = false; duke@435: bool JvmtiExport::_can_force_early_return = false; duke@435: duke@435: bool JvmtiExport::_should_post_single_step = false; duke@435: bool JvmtiExport::_should_post_field_access = false; duke@435: bool JvmtiExport::_should_post_field_modification = false; duke@435: bool JvmtiExport::_should_post_class_load = false; duke@435: bool JvmtiExport::_should_post_class_prepare = false; duke@435: bool JvmtiExport::_should_post_class_unload = false; duke@435: bool JvmtiExport::_should_post_thread_life = false; duke@435: bool JvmtiExport::_should_clean_up_heap_objects = false; duke@435: bool JvmtiExport::_should_post_native_method_bind = false; duke@435: bool JvmtiExport::_should_post_dynamic_code_generated = false; duke@435: bool JvmtiExport::_should_post_data_dump = false; duke@435: bool JvmtiExport::_should_post_compiled_method_load = false; duke@435: bool JvmtiExport::_should_post_compiled_method_unload = false; duke@435: bool JvmtiExport::_should_post_monitor_contended_enter = false; duke@435: bool JvmtiExport::_should_post_monitor_contended_entered = false; duke@435: bool JvmtiExport::_should_post_monitor_wait = false; duke@435: bool JvmtiExport::_should_post_monitor_waited = false; duke@435: bool JvmtiExport::_should_post_garbage_collection_start = false; duke@435: bool JvmtiExport::_should_post_garbage_collection_finish = false; duke@435: bool JvmtiExport::_should_post_object_free = false; duke@435: bool JvmtiExport::_should_post_resource_exhausted = false; duke@435: bool JvmtiExport::_should_post_vm_object_alloc = false; dcubed@1648: bool JvmtiExport::_should_post_on_exceptions = false; duke@435: duke@435: //////////////////////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: duke@435: // duke@435: // JVMTI single step management duke@435: // duke@435: void JvmtiExport::at_single_stepping_point(JavaThread *thread, methodOop method, address location) { duke@435: assert(JvmtiExport::should_post_single_step(), "must be single stepping"); duke@435: duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: // update information about current location and post a step event duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Trg Single Step triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: if (!state->hide_single_stepping()) { duke@435: if (state->is_pending_step_for_popframe()) { duke@435: state->process_pending_step_for_popframe(); duke@435: } duke@435: if (state->is_pending_step_for_earlyret()) { duke@435: state->process_pending_step_for_earlyret(); duke@435: } duke@435: JvmtiExport::post_single_step(thread, mh(), location); duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::expose_single_stepping(JavaThread *thread) { duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state != NULL) { duke@435: state->clear_hide_single_stepping(); duke@435: } duke@435: } duke@435: duke@435: duke@435: bool JvmtiExport::hide_single_stepping(JavaThread *thread) { duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state != NULL && state->is_enabled(JVMTI_EVENT_SINGLE_STEP)) { duke@435: state->set_hide_single_stepping(); duke@435: return true; duke@435: } else { duke@435: return false; duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_class_load(JavaThread *thread, klassOop klass) { duke@435: HandleMark hm(thread); duke@435: KlassHandle kh(thread, klass); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Trg Class Load triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiThreadState* state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) { duke@435: EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Evt Class Load sent %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: kh()==NULL? "NULL" : Klass::cast(kh())->external_name() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiClassEventMark jem(thread, kh()); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventClassLoad callback = env->callbacks()->ClassLoad; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_class_prepare(JavaThread *thread, klassOop klass) { duke@435: HandleMark hm(thread); duke@435: KlassHandle kh(thread, klass); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Trg Class Prepare triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiThreadState* state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) { duke@435: EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Evt Class Prepare sent %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: kh()==NULL? "NULL" : Klass::cast(kh())->external_name() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiClassEventMark jem(thread, kh()); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_class_unload(klassOop klass) { duke@435: Thread *thread = Thread::current(); duke@435: HandleMark hm(thread); duke@435: KlassHandle kh(thread, klass); duke@435: duke@435: EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Trg Class Unload triggered" )); duke@435: if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { duke@435: assert(thread->is_VM_thread(), "wrong thread"); duke@435: duke@435: // get JavaThread for whom we are proxy duke@435: JavaThread *real_thread = duke@435: (JavaThread *)((VMThread *)thread)->vm_operation()->calling_thread(); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { duke@435: EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Evt Class Unload sent %s", duke@435: kh()==NULL? "NULL" : Klass::cast(kh())->external_name() )); duke@435: duke@435: // do everything manually, since this is a proxy - needs special care duke@435: JNIEnv* jni_env = real_thread->jni_environment(); duke@435: jthread jt = (jthread)JNIHandles::make_local(real_thread, real_thread->threadObj()); duke@435: jclass jk = (jclass)JNIHandles::make_local(real_thread, Klass::cast(kh())->java_mirror()); duke@435: duke@435: // Before we call the JVMTI agent, we have to set the state in the duke@435: // thread for which we are proxying. duke@435: JavaThreadState prev_state = real_thread->thread_state(); duke@435: assert(prev_state == _thread_blocked, "JavaThread should be at safepoint"); duke@435: real_thread->set_thread_state(_thread_in_native); duke@435: duke@435: jvmtiExtensionEvent callback = env->ext_callbacks()->ClassUnload; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jni_env, jt, jk); duke@435: } duke@435: duke@435: assert(real_thread->thread_state() == _thread_in_native, duke@435: "JavaThread should be in native"); duke@435: real_thread->set_thread_state(prev_state); duke@435: duke@435: JNIHandles::destroy_local(jk); duke@435: JNIHandles::destroy_local(jt); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_thread_start(JavaThread *thread) { duke@435: assert(thread->thread_state() == _thread_in_vm, "must be in vm state"); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Trg Thread Start event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: // do JVMTI thread initialization (if needed) duke@435: JvmtiEventController::thread_started(thread); duke@435: duke@435: // Do not post thread start event for hidden java thread. duke@435: if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) && duke@435: !thread->is_hidden_from_external_view()) { duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_THREAD_START)) { duke@435: EVT_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Evt Thread Start event sent", duke@435: JvmtiTrace::safe_get_thread_name(thread) )); duke@435: duke@435: JvmtiThreadEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventThreadStart callback = env->callbacks()->ThreadStart; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_thread_end(JavaThread *thread) { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Trg Thread End event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: // Do not post thread end event for hidden java thread. duke@435: if (state->is_enabled(JVMTI_EVENT_THREAD_END) && duke@435: !thread->is_hidden_from_external_view()) { duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) { duke@435: EVT_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Evt Thread End event sent", duke@435: JvmtiTrace::safe_get_thread_name(thread) )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiThreadEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) { duke@435: assert(SafepointSynchronize::is_at_safepoint(), "must be executed at safepoint"); duke@435: assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking"); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Trg Object Free triggered" )); duke@435: EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Evt Object Free sent")); duke@435: duke@435: jvmtiEventObjectFree callback = env->callbacks()->ObjectFree; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), tag); duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Trg resource exhausted event triggered" )); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_RESOURCE_EXHAUSTED)) { duke@435: EVT_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Evt resource exhausted event sent" )); duke@435: duke@435: JavaThread *thread = JavaThread::current(); duke@435: JvmtiThreadEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventResourceExhausted callback = env->callbacks()->ResourceExhausted; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), duke@435: resource_exhausted_flags, NULL, description); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_method_entry(JavaThread *thread, methodOop method, frame current_frame) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Trg Method Entry triggered %s.%s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() )); duke@435: duke@435: JvmtiThreadState* state = thread->jvmti_thread_state(); duke@435: if (state == NULL || !state->is_interp_only_mode()) { duke@435: // for any thread that actually wants method entry, interp_only_mode is set duke@435: return; duke@435: } duke@435: duke@435: state->incr_cur_stack_depth(); duke@435: duke@435: if (state->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) { duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) { duke@435: EVT_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Evt Method Entry sent %s.%s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiMethodEventMark jem(thread, mh); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventMethodEntry callback = env->callbacks()->MethodEntry; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_methodID()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_method_exit(JavaThread *thread, methodOop method, frame current_frame) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Trg Method Exit triggered %s.%s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() )); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL || !state->is_interp_only_mode()) { duke@435: // for any thread that actually wants method exit, interp_only_mode is set duke@435: return; duke@435: } duke@435: duke@435: // return a flag when a method terminates by throwing an exception duke@435: // i.e. if an exception is thrown and it's not caught by the current method duke@435: bool exception_exit = state->is_exception_detected() && !state->is_exception_caught(); duke@435: duke@435: duke@435: if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) { duke@435: Handle result; duke@435: jvalue value; duke@435: value.j = 0L; duke@435: duke@435: // if the method hasn't been popped because of an exception then we populate duke@435: // the return_value parameter for the callback. At this point we only have duke@435: // the address of a "raw result" and we just call into the interpreter to duke@435: // convert this into a jvalue. duke@435: if (!exception_exit) { duke@435: oop oop_result; duke@435: BasicType type = current_frame.interpreter_frame_result(&oop_result, &value); duke@435: if (type == T_OBJECT || type == T_ARRAY) { duke@435: result = Handle(thread, oop_result); duke@435: } duke@435: } duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_METHOD_EXIT)) { duke@435: EVT_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Evt Method Exit sent %s.%s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiMethodEventMark jem(thread, mh); duke@435: if (result.not_null()) { duke@435: value.l = JNIHandles::make_local(thread, result()); duke@435: } duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventMethodExit callback = env->callbacks()->MethodExit; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), exception_exit, value); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (state->is_enabled(JVMTI_EVENT_FRAME_POP)) { duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: int cur_frame_number = state->cur_stack_depth(); duke@435: duke@435: if (ets->is_frame_pop(cur_frame_number)) { duke@435: // we have a NotifyFramePop entry for this frame. duke@435: // now check that this env/thread wants this event duke@435: if (ets->is_enabled(JVMTI_EVENT_FRAME_POP)) { duke@435: EVT_TRACE(JVMTI_EVENT_FRAME_POP, ("JVMTI [%s] Evt Frame Pop sent %s.%s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() )); duke@435: duke@435: // we also need to issue a frame pop event for this frame duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiMethodEventMark jem(thread, mh); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventFramePop callback = env->callbacks()->FramePop; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), exception_exit); duke@435: } duke@435: } duke@435: // remove the frame's entry duke@435: ets->clear_frame_pop(cur_frame_number); duke@435: } duke@435: } duke@435: } duke@435: duke@435: state->decr_cur_stack_depth(); duke@435: } duke@435: duke@435: duke@435: // Todo: inline this for optimization duke@435: void JvmtiExport::post_single_step(JavaThread *thread, methodOop method, address location) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP); duke@435: if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) { duke@435: EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Evt Single Step sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiLocationEventMark jem(thread, mh, location); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventSingleStep callback = env->callbacks()->SingleStep; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location()); duke@435: } duke@435: duke@435: ets->set_single_stepping_posted(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_exception_throw(JavaThread *thread, methodOop method, address location, oop exception) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: Handle exception_handle(thread, exception); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("JVMTI [%s] Trg Exception thrown triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: if (!state->is_exception_detected()) { duke@435: state->set_exception_detected(); duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) { duke@435: duke@435: EVT_TRACE(JVMTI_EVENT_EXCEPTION, duke@435: ("JVMTI [%s] Evt Exception thrown sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiExceptionEventMark jem(thread, mh, location, exception_handle); duke@435: duke@435: // It's okay to clear these exceptions here because we duplicate duke@435: // this lookup in InterpreterRuntime::exception_handler_for_exception. duke@435: EXCEPTION_MARK; duke@435: duke@435: bool should_repeat; duke@435: vframeStream st(thread); duke@435: assert(!st.at_end(), "cannot be at end"); duke@435: methodOop current_method = NULL; duke@435: int current_bci = -1; duke@435: do { duke@435: current_method = st.method(); duke@435: current_bci = st.bci(); duke@435: do { duke@435: should_repeat = false; duke@435: KlassHandle eh_klass(thread, exception_handle()->klass()); duke@435: current_bci = current_method->fast_exception_handler_bci_for( duke@435: eh_klass, current_bci, THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: exception_handle = KlassHandle(thread, PENDING_EXCEPTION); duke@435: CLEAR_PENDING_EXCEPTION; duke@435: should_repeat = true; duke@435: } duke@435: } while (should_repeat && (current_bci != -1)); duke@435: st.next(); duke@435: } while ((current_bci < 0) && (!st.at_end())); duke@435: duke@435: jmethodID catch_jmethodID; duke@435: if (current_bci < 0) { duke@435: catch_jmethodID = 0; duke@435: current_bci = 0; duke@435: } else { duke@435: catch_jmethodID = jem.to_jmethodID( duke@435: methodHandle(thread, current_method)); duke@435: } duke@435: duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventException callback = env->callbacks()->Exception; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location(), duke@435: jem.exception(), duke@435: catch_jmethodID, current_bci); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // frames may get popped because of this throw, be safe - invalidate cached depth duke@435: state->invalidate_cur_stack_depth(); duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, methodOop method, address location, oop exception, bool in_handler_frame) { duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: Handle exception_handle(thread, exception); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION_CATCH, duke@435: ("JVMTI [%s] Trg unwind_due_to_exception triggered %s.%s @ %s%d - %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location==0? "no location:" : "", duke@435: location==0? 0 : location - mh()->code_base(), duke@435: in_handler_frame? "in handler frame" : "not handler frame" )); duke@435: duke@435: if (state->is_exception_detected()) { duke@435: duke@435: state->invalidate_cur_stack_depth(); duke@435: if (!in_handler_frame) { duke@435: // Not in exception handler. duke@435: if(state->is_interp_only_mode()) { duke@435: // method exit and frame pop events are posted only in interp mode. duke@435: // When these events are enabled code should be in running in interp mode. duke@435: JvmtiExport::post_method_exit(thread, method, thread->last_frame()); duke@435: // The cached cur_stack_depth might have changed from the duke@435: // operations of frame pop or method exit. We are not 100% sure duke@435: // the cached cur_stack_depth is still valid depth so invalidate duke@435: // it. duke@435: state->invalidate_cur_stack_depth(); duke@435: } duke@435: } else { duke@435: // In exception handler frame. Report exception catch. duke@435: assert(location != NULL, "must be a known location"); duke@435: // Update cur_stack_depth - the frames above the current frame duke@435: // have been unwound due to this exception: duke@435: assert(!state->is_exception_caught(), "exception must not be caught yet."); duke@435: state->set_exception_caught(); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_EXCEPTION_CATCH) && (exception_handle() != NULL)) { duke@435: EVT_TRACE(JVMTI_EVENT_EXCEPTION_CATCH, duke@435: ("JVMTI [%s] Evt ExceptionCatch sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiExceptionEventMark jem(thread, mh, location, exception_handle); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventExceptionCatch callback = env->callbacks()->ExceptionCatch; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location(), duke@435: jem.exception()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: oop JvmtiExport::jni_GetField_probe(JavaThread *thread, jobject jobj, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static) { duke@435: if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) { duke@435: // At least one field access watch is set so we have more work duke@435: // to do. This wrapper is used by entry points that allow us duke@435: // to create handles in post_field_access_by_jni(). duke@435: post_field_access_by_jni(thread, obj, klass, fieldID, is_static); duke@435: // event posting can block so refetch oop if we were passed a jobj duke@435: if (jobj != NULL) return JNIHandles::resolve_non_null(jobj); duke@435: } duke@435: return obj; duke@435: } duke@435: duke@435: oop JvmtiExport::jni_GetField_probe_nh(JavaThread *thread, jobject jobj, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static) { duke@435: if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) { duke@435: // At least one field access watch is set so we have more work duke@435: // to do. This wrapper is used by "quick" entry points that don't duke@435: // allow us to create handles in post_field_access_by_jni(). We duke@435: // override that with a ResetNoHandleMark. duke@435: ResetNoHandleMark rnhm; duke@435: post_field_access_by_jni(thread, obj, klass, fieldID, is_static); duke@435: // event posting can block so refetch oop if we were passed a jobj duke@435: if (jobj != NULL) return JNIHandles::resolve_non_null(jobj); duke@435: } duke@435: return obj; duke@435: } duke@435: duke@435: void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static) { duke@435: // We must be called with a Java context in order to provide reasonable duke@435: // values for the klazz, method, and location fields. The callers of this duke@435: // function don't make the call unless there is a Java context. duke@435: assert(thread->has_last_Java_frame(), "must be called with a Java context"); duke@435: duke@435: ResourceMark rm; duke@435: fieldDescriptor fd; duke@435: // if get_field_descriptor finds fieldID to be invalid, then we just bail duke@435: bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd); duke@435: assert(valid_fieldID == true,"post_field_access_by_jni called with invalid fieldID"); duke@435: if (!valid_fieldID) return; duke@435: // field accesses are not watched so bail duke@435: if (!fd.is_field_access_watched()) return; duke@435: duke@435: HandleMark hm(thread); duke@435: KlassHandle h_klass(thread, klass); duke@435: Handle h_obj; duke@435: if (!is_static) { duke@435: // non-static field accessors have an object, but we need a handle duke@435: assert(obj != NULL, "non-static needs an object"); duke@435: h_obj = Handle(thread, obj); duke@435: } duke@435: post_field_access(thread, duke@435: thread->last_frame().interpreter_frame_method(), duke@435: thread->last_frame().interpreter_frame_bcp(), duke@435: h_klass, h_obj, fieldID); duke@435: } duke@435: duke@435: void JvmtiExport::post_field_access(JavaThread *thread, methodOop method, duke@435: address location, KlassHandle field_klass, Handle object, jfieldID field) { duke@435: duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Trg Field Access event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) { duke@435: EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Evt Field Access event sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiLocationEventMark jem(thread, mh, location); duke@435: jclass field_jclass = jem.to_jclass(field_klass()); duke@435: jobject field_jobject = jem.to_jobject(object()); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location(), duke@435: field_jclass, field_jobject, field); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: oop JvmtiExport::jni_SetField_probe(JavaThread *thread, jobject jobj, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static, duke@435: char sig_type, jvalue *value) { duke@435: if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) { duke@435: // At least one field modification watch is set so we have more work duke@435: // to do. This wrapper is used by entry points that allow us duke@435: // to create handles in post_field_modification_by_jni(). duke@435: post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value); duke@435: // event posting can block so refetch oop if we were passed a jobj duke@435: if (jobj != NULL) return JNIHandles::resolve_non_null(jobj); duke@435: } duke@435: return obj; duke@435: } duke@435: duke@435: oop JvmtiExport::jni_SetField_probe_nh(JavaThread *thread, jobject jobj, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static, duke@435: char sig_type, jvalue *value) { duke@435: if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) { duke@435: // At least one field modification watch is set so we have more work duke@435: // to do. This wrapper is used by "quick" entry points that don't duke@435: // allow us to create handles in post_field_modification_by_jni(). We duke@435: // override that with a ResetNoHandleMark. duke@435: ResetNoHandleMark rnhm; duke@435: post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value); duke@435: // event posting can block so refetch oop if we were passed a jobj duke@435: if (jobj != NULL) return JNIHandles::resolve_non_null(jobj); duke@435: } duke@435: return obj; duke@435: } duke@435: duke@435: void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj, duke@435: klassOop klass, jfieldID fieldID, bool is_static, duke@435: char sig_type, jvalue *value) { duke@435: // We must be called with a Java context in order to provide reasonable duke@435: // values for the klazz, method, and location fields. The callers of this duke@435: // function don't make the call unless there is a Java context. duke@435: assert(thread->has_last_Java_frame(), "must be called with Java context"); duke@435: duke@435: ResourceMark rm; duke@435: fieldDescriptor fd; duke@435: // if get_field_descriptor finds fieldID to be invalid, then we just bail duke@435: bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd); duke@435: assert(valid_fieldID == true,"post_field_modification_by_jni called with invalid fieldID"); duke@435: if (!valid_fieldID) return; duke@435: // field modifications are not watched so bail duke@435: if (!fd.is_field_modification_watched()) return; duke@435: duke@435: HandleMark hm(thread); duke@435: duke@435: Handle h_obj; duke@435: if (!is_static) { duke@435: // non-static field accessors have an object, but we need a handle duke@435: assert(obj != NULL, "non-static needs an object"); duke@435: h_obj = Handle(thread, obj); duke@435: } duke@435: KlassHandle h_klass(thread, klass); duke@435: post_field_modification(thread, duke@435: thread->last_frame().interpreter_frame_method(), duke@435: thread->last_frame().interpreter_frame_bcp(), duke@435: h_klass, h_obj, fieldID, sig_type, value); duke@435: } duke@435: duke@435: void JvmtiExport::post_raw_field_modification(JavaThread *thread, methodOop method, duke@435: address location, KlassHandle field_klass, Handle object, jfieldID field, duke@435: char sig_type, jvalue *value) { duke@435: duke@435: if (sig_type == 'I' || sig_type == 'Z' || sig_type == 'C' || sig_type == 'S') { duke@435: // 'I' instructions are used for byte, char, short and int. duke@435: // determine which it really is, and convert duke@435: fieldDescriptor fd; duke@435: bool found = JvmtiEnv::get_field_descriptor(field_klass(), field, &fd); duke@435: // should be found (if not, leave as is) duke@435: if (found) { duke@435: jint ival = value->i; duke@435: // convert value from int to appropriate type duke@435: switch (fd.field_type()) { duke@435: case T_BOOLEAN: duke@435: sig_type = 'Z'; duke@435: value->i = 0; // clear it duke@435: value->z = (jboolean)ival; duke@435: break; duke@435: case T_BYTE: duke@435: sig_type = 'B'; duke@435: value->i = 0; // clear it duke@435: value->b = (jbyte)ival; duke@435: break; duke@435: case T_CHAR: duke@435: sig_type = 'C'; duke@435: value->i = 0; // clear it duke@435: value->c = (jchar)ival; duke@435: break; duke@435: case T_SHORT: duke@435: sig_type = 'S'; duke@435: value->i = 0; // clear it duke@435: value->s = (jshort)ival; duke@435: break; duke@435: case T_INT: duke@435: // nothing to do duke@435: break; duke@435: default: duke@435: // this is an integer instruction, should be one of above duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // convert oop to JNI handle. duke@435: if (sig_type == 'L' || sig_type == '[') { duke@435: value->l = (jobject)JNIHandles::make_local(thread, (oop)value->l); duke@435: } duke@435: duke@435: post_field_modification(thread, method, location, field_klass, object, field, sig_type, value); duke@435: duke@435: // Destroy the JNI handle allocated above. duke@435: if (sig_type == 'L') { duke@435: JNIHandles::destroy_local(value->l); duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_field_modification(JavaThread *thread, methodOop method, duke@435: address location, KlassHandle field_klass, Handle object, jfieldID field, duke@435: char sig_type, jvalue *value_ptr) { duke@435: duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION, duke@435: ("JVMTI [%s] Trg Field Modification event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) { duke@435: EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION, duke@435: ("JVMTI [%s] Evt Field Modification event sent %s.%s @ %d", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(), duke@435: (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(), duke@435: location - mh()->code_base() )); duke@435: duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiLocationEventMark jem(thread, mh, location); duke@435: jclass field_jclass = jem.to_jclass(field_klass()); duke@435: jobject field_jobject = jem.to_jobject(object()); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventFieldModification callback = env->callbacks()->FieldModification; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_methodID(), jem.location(), duke@435: field_jclass, field_jobject, field, sig_type, *value_ptr); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_native_method_bind(methodOop method, address* function_ptr) { duke@435: JavaThread* thread = JavaThread::current(); duke@435: assert(thread->thread_state() == _thread_in_vm, "must be in vm state"); duke@435: duke@435: HandleMark hm(thread); duke@435: methodHandle mh(thread, method); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Trg Native Method Bind event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) { duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) { duke@435: EVT_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Evt Native Method Bind event sent", duke@435: JvmtiTrace::safe_get_thread_name(thread) )); duke@435: duke@435: JvmtiMethodEventMark jem(thread, mh); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: JNIEnv* jni_env = JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL? NULL : jem.jni_env(); duke@435: jvmtiEventNativeMethodBind callback = env->callbacks()->NativeMethodBind; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jni_env, jem.jni_thread(), duke@435: jem.jni_methodID(), (void*)(*function_ptr), (void**)function_ptr); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: dcubed@1619: // Returns a record containing inlining information for the given nmethod dcubed@1619: jvmtiCompiledMethodLoadInlineRecord* create_inline_record(nmethod* nm) { dcubed@1619: jint numstackframes = 0; dcubed@1619: jvmtiCompiledMethodLoadInlineRecord* record = (jvmtiCompiledMethodLoadInlineRecord*)NEW_RESOURCE_OBJ(jvmtiCompiledMethodLoadInlineRecord); dcubed@1619: record->header.kind = JVMTI_CMLR_INLINE_INFO; dcubed@1619: record->header.next = NULL; dcubed@1619: record->header.majorinfoversion = JVMTI_CMLR_MAJOR_VERSION_1; dcubed@1619: record->header.minorinfoversion = JVMTI_CMLR_MINOR_VERSION_0; dcubed@1619: record->numpcs = 0; dcubed@1619: for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) { dcubed@1619: if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue; dcubed@1619: record->numpcs++; dcubed@1619: } dcubed@1619: record->pcinfo = (PCStackInfo*)(NEW_RESOURCE_ARRAY(PCStackInfo, record->numpcs)); dcubed@1619: int scope = 0; dcubed@1619: for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) { dcubed@1619: if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue; dcubed@1619: void* pc_address = (void*)p->real_pc(nm); dcubed@1619: assert(pc_address != NULL, "pc_address must be non-null"); dcubed@1619: record->pcinfo[scope].pc = pc_address; dcubed@1619: numstackframes=0; dcubed@1619: for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) { dcubed@1619: numstackframes++; dcubed@1619: } dcubed@1619: assert(numstackframes != 0, "numstackframes must be nonzero."); dcubed@1619: record->pcinfo[scope].methods = (jmethodID *)NEW_RESOURCE_ARRAY(jmethodID, numstackframes); dcubed@1619: record->pcinfo[scope].bcis = (jint *)NEW_RESOURCE_ARRAY(jint, numstackframes); dcubed@1619: record->pcinfo[scope].numstackframes = numstackframes; dcubed@1619: int stackframe = 0; dcubed@1619: for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) { dcubed@1619: // sd->method() can be NULL for stubs but not for nmethods. To be completely robust, include an assert that we should never see a null sd->method() dcubed@1619: assert(!sd->method().is_null(), "sd->method() cannot be null."); dcubed@1619: record->pcinfo[scope].methods[stackframe] = sd->method()->jmethod_id(); dcubed@1619: record->pcinfo[scope].bcis[stackframe] = sd->bci(); dcubed@1619: stackframe++; dcubed@1619: } dcubed@1619: scope++; dcubed@1619: } dcubed@1619: return record; dcubed@1619: } duke@435: duke@435: void JvmtiExport::post_compiled_method_load(nmethod *nm) { duke@435: JavaThread* thread = JavaThread::current(); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD, duke@435: ("JVMTI [%s] method compile load event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) { duke@435: duke@435: EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD, duke@435: ("JVMTI [%s] class compile method load event sent %s.%s ", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: (nm->method() == NULL) ? "NULL" : nm->method()->klass_name()->as_C_string(), duke@435: (nm->method() == NULL) ? "NULL" : nm->method()->name()->as_C_string())); duke@435: ResourceMark rm(thread); kamg@2511: HandleMark hm(thread); dcubed@1619: dcubed@1619: // Add inlining information dcubed@1619: jvmtiCompiledMethodLoadInlineRecord* inlinerecord = create_inline_record(nm); dcubed@1619: // Pass inlining information through the void pointer dcubed@1619: JvmtiCompiledMethodLoadEventMark jem(thread, nm, inlinerecord); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_methodID(), duke@435: jem.code_size(), jem.code_data(), jem.map_length(), duke@435: jem.map(), jem.compile_info()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // post a COMPILED_METHOD_LOAD event for a given environment duke@435: void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length, duke@435: const void *code_begin, const jint map_length, duke@435: const jvmtiAddrLocationMap* map) duke@435: { duke@435: JavaThread* thread = JavaThread::current(); duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD, duke@435: ("JVMTI [%s] method compile load event triggered (by GenerateEvents)", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) { duke@435: duke@435: EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD, duke@435: ("JVMTI [%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT, duke@435: JvmtiTrace::safe_get_thread_name(thread), method)); duke@435: duke@435: JvmtiEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), method, duke@435: length, code_begin, map_length, duke@435: map, NULL); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) { dcubed@2836: assert(name != NULL && name[0] != '\0', "sanity check"); dcubed@2836: duke@435: JavaThread* thread = JavaThread::current(); kamg@2583: // In theory everyone coming thru here is in_vm but we need to be certain kamg@2583: // because a callee will do a vm->native transition kamg@2583: ThreadInVMfromUnknown __tiv; kamg@2583: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED, duke@435: ("JVMTI [%s] method dynamic code generated event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) { duke@435: EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED, duke@435: ("JVMTI [%s] dynamic code generated event sent for %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), name)); duke@435: JvmtiEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char)); duke@435: jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), name, (void*)code_begin, length); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) { duke@435: jvmtiPhase phase = JvmtiEnv::get_phase(); duke@435: if (phase == JVMTI_PHASE_PRIMORDIAL || phase == JVMTI_PHASE_START) { duke@435: post_dynamic_code_generated_internal(name, code_begin, code_end); kamg@2583: } else { kamg@2583: // It may not be safe to post the event from this thread. Defer all kamg@2583: // postings to the service thread so that it can perform them in a safe kamg@2583: // context and in-order. kamg@2583: MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); kamg@2583: JvmtiDeferredEvent event = JvmtiDeferredEvent::dynamic_code_generated_event( kamg@2583: name, code_begin, code_end); kamg@2583: JvmtiDeferredEventQueue::enqueue(event); duke@435: } duke@435: } duke@435: duke@435: duke@435: // post a DYNAMIC_CODE_GENERATED event for a given environment duke@435: // used by GenerateEvents duke@435: void JvmtiExport::post_dynamic_code_generated(JvmtiEnv* env, const char *name, duke@435: const void *code_begin, const void *code_end) duke@435: { duke@435: JavaThread* thread = JavaThread::current(); duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED, duke@435: ("JVMTI [%s] dynamic code generated event triggered (by GenerateEvents)", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) { duke@435: EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED, duke@435: ("JVMTI [%s] dynamic code generated event sent for %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), name)); duke@435: JvmtiEventMark jem(thread); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char)); duke@435: jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), name, (void*)code_begin, length); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // post a DynamicCodeGenerated event while holding locks in the VM. duke@435: void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* name, duke@435: address code_begin, address code_end) duke@435: { duke@435: // register the stub with the current dynamic code event collector duke@435: JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current()); dcubed@1044: // state can only be NULL if the current thread is exiting which dcubed@1044: // should not happen since we're trying to post an event dcubed@1044: guarantee(state != NULL, "attempt to register stub via an exiting thread"); duke@435: JvmtiDynamicCodeEventCollector* collector = state->get_dynamic_code_event_collector(); duke@435: guarantee(collector != NULL, "attempt to register stub without event collector"); duke@435: collector->register_stub(name, code_begin, code_end); duke@435: } duke@435: duke@435: // Collect all the vm internally allocated objects which are visible to java world duke@435: void JvmtiExport::record_vm_internal_object_allocation(oop obj) { duke@435: Thread* thread = ThreadLocalStorage::thread(); duke@435: if (thread != NULL && thread->is_Java_thread()) { duke@435: // Can not take safepoint here. duke@435: No_Safepoint_Verifier no_sfpt; duke@435: // Can not take safepoint here so can not use state_for to get duke@435: // jvmti thread state. duke@435: JvmtiThreadState *state = ((JavaThread*)thread)->jvmti_thread_state(); duke@435: if (state != NULL ) { duke@435: // state is non NULL when VMObjectAllocEventCollector is enabled. duke@435: JvmtiVMObjectAllocEventCollector *collector; duke@435: collector = state->get_vm_object_alloc_event_collector(); duke@435: if (collector != NULL && collector->is_enabled()) { duke@435: // Don't record classes as these will be notified via the ClassLoad duke@435: // event. never@1577: if (obj->klass() != SystemDictionary::Class_klass()) { duke@435: collector->record_allocation(obj); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_garbage_collection_finish() { duke@435: Thread *thread = Thread::current(); // this event is posted from VM-Thread. duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, duke@435: ("JVMTI [%s] garbage collection finish event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)) { duke@435: EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, duke@435: ("JVMTI [%s] garbage collection finish event sent ", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: // JNIEnv is NULL here because this event is posted from VM Thread duke@435: jvmtiEventGarbageCollectionFinish callback = env->callbacks()->GarbageCollectionFinish; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_garbage_collection_start() { duke@435: Thread* thread = Thread::current(); // this event is posted from vm-thread. duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START, duke@435: ("JVMTI [%s] garbage collection start event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_START)) { duke@435: EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START, duke@435: ("JVMTI [%s] garbage collection start event sent ", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: // JNIEnv is NULL here because this event is posted from VM Thread duke@435: jvmtiEventGarbageCollectionStart callback = env->callbacks()->GarbageCollectionStart; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_data_dump() { duke@435: Thread *thread = Thread::current(); duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST, duke@435: ("JVMTI [%s] data dump request event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) { duke@435: EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST, duke@435: ("JVMTI [%s] data dump request event sent ", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: // JNIEnv is NULL here because this event is posted from VM Thread duke@435: jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) { duke@435: oop object = (oop)obj_mntr->object(); duke@435: if (!ServiceUtil::visible_oop(object)) { duke@435: // Ignore monitor contended enter for vm internal object. duke@435: return; duke@435: } duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: HandleMark hm(thread); duke@435: Handle h(thread, object); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, duke@435: ("JVMTI [%s] montior contended enter event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) { duke@435: EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, duke@435: ("JVMTI [%s] monitor contended enter event sent", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiMonitorEventMark jem(thread, h()); duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) { duke@435: oop object = (oop)obj_mntr->object(); duke@435: if (!ServiceUtil::visible_oop(object)) { duke@435: // Ignore monitor contended entered for vm internal object. duke@435: return; duke@435: } duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: HandleMark hm(thread); duke@435: Handle h(thread, object); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, duke@435: ("JVMTI [%s] montior contended entered event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) { duke@435: EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, duke@435: ("JVMTI [%s] monitor contended enter event sent", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiMonitorEventMark jem(thread, h()); duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: jvmtiEventMonitorContendedEntered callback = env->callbacks()->MonitorContendedEntered; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object, duke@435: jlong timeout) { duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: HandleMark hm(thread); duke@435: Handle h(thread, object); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAIT, duke@435: ("JVMTI [%s] montior wait event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) { duke@435: EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT, duke@435: ("JVMTI [%s] monitor wait event sent ", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiMonitorEventMark jem(thread, h()); duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_object(), timeout); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) { duke@435: oop object = (oop)obj_mntr->object(); duke@435: if (!ServiceUtil::visible_oop(object)) { duke@435: // Ignore monitor waited for vm internal object. duke@435: return; duke@435: } duke@435: JvmtiThreadState *state = thread->jvmti_thread_state(); duke@435: if (state == NULL) { duke@435: return; duke@435: } duke@435: duke@435: HandleMark hm(thread); duke@435: Handle h(thread, object); duke@435: duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED, duke@435: ("JVMTI [%s] montior waited event triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: duke@435: JvmtiEnvThreadStateIterator it(state); duke@435: for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { duke@435: if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) { duke@435: EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED, duke@435: ("JVMTI [%s] monitor waited event sent ", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: JvmtiMonitorEventMark jem(thread, h()); duke@435: JvmtiEnv *env = ets->get_env(); duke@435: JvmtiThreadEventTransition jet(thread); duke@435: jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_object(), timed_out); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) { duke@435: EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Trg vm object alloc triggered", duke@435: JvmtiTrace::safe_get_thread_name(thread))); duke@435: if (object == NULL) { duke@435: return; duke@435: } duke@435: HandleMark hm(thread); duke@435: Handle h(thread, object); duke@435: JvmtiEnvIterator it; duke@435: for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { duke@435: if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) { duke@435: EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Evt vmobject alloc sent %s", duke@435: JvmtiTrace::safe_get_thread_name(thread), duke@435: object==NULL? "NULL" : Klass::cast(java_lang_Class::as_klassOop(object))->external_name())); duke@435: duke@435: JvmtiVMObjectAllocEventMark jem(thread, h()); duke@435: JvmtiJavaThreadEventTransition jet(thread); duke@435: jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc; duke@435: if (callback != NULL) { duke@435: (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), duke@435: jem.jni_jobject(), jem.jni_class(), jem.size()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: //////////////////////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: void JvmtiExport::cleanup_thread(JavaThread* thread) { duke@435: assert(JavaThread::current() == thread, "thread is not current"); kamg@2446: MutexLocker mu(JvmtiThreadState_lock); duke@435: kamg@2446: if (thread->jvmti_thread_state() != NULL) { kamg@2446: // This has to happen after the thread state is removed, which is kamg@2446: // why it is not in post_thread_end_event like its complement kamg@2446: // Maybe both these functions should be rolled into the posts? kamg@2446: JvmtiEventController::thread_ended(thread); kamg@2446: } duke@435: } duke@435: duke@435: void JvmtiExport::oops_do(OopClosure* f) { duke@435: JvmtiCurrentBreakpoints::oops_do(f); duke@435: JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(f); duke@435: } duke@435: kamg@2467: void JvmtiExport::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) { kamg@2467: JvmtiTagMap::weak_oops_do(is_alive, f); kamg@2467: } kamg@2467: kamg@2467: void JvmtiExport::gc_epilogue() { kamg@2467: JvmtiCurrentBreakpoints::gc_epilogue(); kamg@2467: } kamg@2467: duke@435: // Onload raw monitor transition. duke@435: void JvmtiExport::transition_pending_onload_raw_monitors() { duke@435: JvmtiPendingMonitors::transition_raw_monitors(); duke@435: } duke@435: duke@435: //////////////////////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: // type for the Agent_OnAttach entry point duke@435: extern "C" { duke@435: typedef jint (JNICALL *OnAttachEntry_t)(JavaVM*, char *, void *); duke@435: } duke@435: duke@435: #ifndef SERVICES_KERNEL duke@435: jint JvmtiExport::load_agent_library(AttachOperation* op, outputStream* st) { duke@435: char ebuf[1024]; duke@435: char buffer[JVM_MAXPATHLEN]; duke@435: void* library; duke@435: jint result = JNI_ERR; duke@435: duke@435: // get agent name and options duke@435: const char* agent = op->arg(0); duke@435: const char* absParam = op->arg(1); duke@435: const char* options = op->arg(2); duke@435: duke@435: // The abs paramter should be "true" or "false" duke@435: bool is_absolute_path = (absParam != NULL) && (strcmp(absParam,"true")==0); duke@435: duke@435: duke@435: // If the path is absolute we attempt to load the library. Otherwise we try to duke@435: // load it from the standard dll directory. duke@435: duke@435: if (is_absolute_path) { ikrylov@2322: library = os::dll_load(agent, ebuf, sizeof ebuf); duke@435: } else { duke@435: // Try to load the agent from the standard dll directory ikrylov@2322: os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), agent); ikrylov@2322: library = os::dll_load(buffer, ebuf, sizeof ebuf); duke@435: if (library == NULL) { duke@435: // not found - try local path duke@435: char ns[1] = {0}; ikrylov@2322: os::dll_build_name(buffer, sizeof(buffer), ns, agent); ikrylov@2322: library = os::dll_load(buffer, ebuf, sizeof ebuf); duke@435: } duke@435: } duke@435: duke@435: // If the library was loaded then we attempt to invoke the Agent_OnAttach duke@435: // function duke@435: if (library != NULL) { duke@435: duke@435: // Lookup the Agent_OnAttach function duke@435: OnAttachEntry_t on_attach_entry = NULL; duke@435: const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS; duke@435: for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_attach_symbols); symbol_index++) { duke@435: on_attach_entry = ikrylov@2322: CAST_TO_FN_PTR(OnAttachEntry_t, os::dll_lookup(library, on_attach_symbols[symbol_index])); duke@435: if (on_attach_entry != NULL) break; duke@435: } duke@435: duke@435: if (on_attach_entry == NULL) { duke@435: // Agent_OnAttach missing - unload library ikrylov@2322: os::dll_unload(library); duke@435: } else { duke@435: // Invoke the Agent_OnAttach function duke@435: JavaThread* THREAD = JavaThread::current(); duke@435: { duke@435: extern struct JavaVM_ main_vm; duke@435: JvmtiThreadEventMark jem(THREAD); duke@435: JvmtiJavaThreadEventTransition jet(THREAD); duke@435: duke@435: result = (*on_attach_entry)(&main_vm, (char*)options, NULL); duke@435: } duke@435: duke@435: // Agent_OnAttach may have used JNI duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: } duke@435: duke@435: // If OnAttach returns JNI_OK then we add it to the list of duke@435: // agent libraries so that we can call Agent_OnUnload later. duke@435: if (result == JNI_OK) { duke@435: Arguments::add_loaded_agent(agent, (char*)options, is_absolute_path, library); duke@435: } duke@435: duke@435: // Agent_OnAttach executed so completion status is JNI_OK duke@435: st->print_cr("%d", result); duke@435: result = JNI_OK; duke@435: } duke@435: } duke@435: return result; duke@435: } duke@435: #endif // SERVICES_KERNEL duke@435: duke@435: //////////////////////////////////////////////////////////////////////////////////////////////// duke@435: duke@435: // Setup current current thread for event collection. duke@435: void JvmtiEventCollector::setup_jvmti_thread_state() { duke@435: // set this event collector to be the current one. duke@435: JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current()); dcubed@1044: // state can only be NULL if the current thread is exiting which dcubed@1044: // should not happen since we're trying to configure for event collection dcubed@1044: guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state"); duke@435: if (is_vm_object_alloc_event()) { duke@435: _prev = state->get_vm_object_alloc_event_collector(); duke@435: state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this); duke@435: } else if (is_dynamic_code_event()) { duke@435: _prev = state->get_dynamic_code_event_collector(); duke@435: state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this); duke@435: } duke@435: } duke@435: duke@435: // Unset current event collection in this thread and reset it with previous duke@435: // collector. duke@435: void JvmtiEventCollector::unset_jvmti_thread_state() { duke@435: JvmtiThreadState* state = JavaThread::current()->jvmti_thread_state(); duke@435: if (state != NULL) { duke@435: // restore the previous event collector (if any) duke@435: if (is_vm_object_alloc_event()) { duke@435: if (state->get_vm_object_alloc_event_collector() == this) { duke@435: state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)_prev); duke@435: } else { duke@435: // this thread's jvmti state was created during the scope of duke@435: // the event collector. duke@435: } duke@435: } else { duke@435: if (is_dynamic_code_event()) { duke@435: if (state->get_dynamic_code_event_collector() == this) { duke@435: state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)_prev); duke@435: } else { duke@435: // this thread's jvmti state was created during the scope of duke@435: // the event collector. duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // create the dynamic code event collector duke@435: JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(NULL) { duke@435: if (JvmtiExport::should_post_dynamic_code_generated()) { duke@435: setup_jvmti_thread_state(); duke@435: } duke@435: } duke@435: duke@435: // iterate over any code blob descriptors collected and post a duke@435: // DYNAMIC_CODE_GENERATED event to the profiler. duke@435: JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() { duke@435: assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events"); duke@435: // iterate over any code blob descriptors that we collected duke@435: if (_code_blobs != NULL) { duke@435: for (int i=0; i<_code_blobs->length(); i++) { duke@435: JvmtiCodeBlobDesc* blob = _code_blobs->at(i); duke@435: JvmtiExport::post_dynamic_code_generated(blob->name(), blob->code_begin(), blob->code_end()); duke@435: FreeHeap(blob); duke@435: } duke@435: delete _code_blobs; duke@435: } duke@435: unset_jvmti_thread_state(); duke@435: } duke@435: duke@435: // register a stub duke@435: void JvmtiDynamicCodeEventCollector::register_stub(const char* name, address start, address end) { duke@435: if (_code_blobs == NULL) { duke@435: _code_blobs = new (ResourceObj::C_HEAP) GrowableArray(1,true); duke@435: } duke@435: _code_blobs->append(new JvmtiCodeBlobDesc(name, start, end)); duke@435: } duke@435: duke@435: // Setup current thread to record vm allocated objects. duke@435: JvmtiVMObjectAllocEventCollector::JvmtiVMObjectAllocEventCollector() : _allocated(NULL) { duke@435: if (JvmtiExport::should_post_vm_object_alloc()) { duke@435: _enable = true; duke@435: setup_jvmti_thread_state(); duke@435: } else { duke@435: _enable = false; duke@435: } duke@435: } duke@435: duke@435: // Post vm_object_alloc event for vm allocated objects visible to java duke@435: // world. duke@435: JvmtiVMObjectAllocEventCollector::~JvmtiVMObjectAllocEventCollector() { duke@435: if (_allocated != NULL) { duke@435: set_enabled(false); duke@435: for (int i = 0; i < _allocated->length(); i++) { duke@435: oop obj = _allocated->at(i); duke@435: if (ServiceUtil::visible_oop(obj)) { duke@435: JvmtiExport::post_vm_object_alloc(JavaThread::current(), obj); duke@435: } duke@435: } duke@435: delete _allocated; duke@435: } duke@435: unset_jvmti_thread_state(); duke@435: } duke@435: duke@435: void JvmtiVMObjectAllocEventCollector::record_allocation(oop obj) { duke@435: assert(is_enabled(), "VM object alloc event collector is not enabled"); duke@435: if (_allocated == NULL) { duke@435: _allocated = new (ResourceObj::C_HEAP) GrowableArray(1, true); duke@435: } duke@435: _allocated->push(obj); duke@435: } duke@435: duke@435: // GC support. duke@435: void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) { duke@435: if (_allocated != NULL) { duke@435: for(int i=_allocated->length() - 1; i >= 0; i--) { duke@435: if (_allocated->at(i) != NULL) { duke@435: f->do_oop(_allocated->adr_at(i)); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(OopClosure* f) { duke@435: // no-op if jvmti not enabled duke@435: if (!JvmtiEnv::environments_might_exist()) { duke@435: return; duke@435: } duke@435: duke@435: // Runs at safepoint. So no need to acquire Threads_lock. duke@435: for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) { duke@435: JvmtiThreadState *state = jthr->jvmti_thread_state(); duke@435: if (state != NULL) { duke@435: JvmtiVMObjectAllocEventCollector *collector; duke@435: collector = state->get_vm_object_alloc_event_collector(); duke@435: while (collector != NULL) { duke@435: collector->oops_do(f); duke@435: collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev(); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Disable collection of VMObjectAlloc events duke@435: NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) { duke@435: // a no-op if VMObjectAlloc event is not enabled duke@435: if (!JvmtiExport::should_post_vm_object_alloc()) { duke@435: return; duke@435: } duke@435: Thread* thread = ThreadLocalStorage::thread(); duke@435: if (thread != NULL && thread->is_Java_thread()) { duke@435: JavaThread* current_thread = (JavaThread*)thread; duke@435: JvmtiThreadState *state = current_thread->jvmti_thread_state(); duke@435: if (state != NULL) { duke@435: JvmtiVMObjectAllocEventCollector *collector; duke@435: collector = state->get_vm_object_alloc_event_collector(); duke@435: if (collector != NULL && collector->is_enabled()) { duke@435: _collector = collector; duke@435: _collector->set_enabled(false); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Re-Enable collection of VMObjectAlloc events (if previously enabled) duke@435: NoJvmtiVMObjectAllocMark::~NoJvmtiVMObjectAllocMark() { duke@435: if (was_enabled()) { duke@435: _collector->set_enabled(true); duke@435: } duke@435: }; duke@435: kamg@2445: JvmtiGCMarker::JvmtiGCMarker() { duke@435: // if there aren't any JVMTI environments then nothing to do duke@435: if (!JvmtiEnv::environments_might_exist()) { duke@435: return; duke@435: } duke@435: duke@435: if (JvmtiExport::should_post_garbage_collection_start()) { duke@435: JvmtiExport::post_garbage_collection_start(); duke@435: } duke@435: kamg@2445: if (SafepointSynchronize::is_at_safepoint()) { kamg@2445: // Do clean up tasks that need to be done at a safepoint kamg@2445: JvmtiEnvBase::check_for_periodic_clean_up(); duke@435: } duke@435: } duke@435: duke@435: JvmtiGCMarker::~JvmtiGCMarker() { duke@435: // if there aren't any JVMTI environments then nothing to do duke@435: if (!JvmtiEnv::environments_might_exist()) { duke@435: return; duke@435: } duke@435: duke@435: // JVMTI notify gc finish duke@435: if (JvmtiExport::should_post_garbage_collection_finish()) { duke@435: JvmtiExport::post_garbage_collection_finish(); duke@435: } duke@435: } duke@435: #endif // JVMTI_KERNEL