src/share/vm/prims/jvmtiExport.cpp

Wed, 02 Jun 2010 14:23:23 -0700

author
never
date
Wed, 02 Jun 2010 14:23:23 -0700
changeset 1932
852d0157c696
parent 1832
b4776199210f
child 1934
e9ff18c4ace7
permissions
-rw-r--r--

6956931: assert(SafepointSynchronize::is_at_safepoint()) failed: must be executed at a safepoint
Reviewed-by: kvn, dcubed

duke@435 1 /*
dcubed@1619 2 * Copyright 2003-2010 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_jvmtiExport.cpp.incl"
duke@435 27
duke@435 28 #ifdef JVMTI_TRACE
duke@435 29 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; tty->print_cr out; }
duke@435 30 #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 31 #else
duke@435 32 #define EVT_TRIG_TRACE(evt,out)
duke@435 33 #define EVT_TRACE(evt,out)
duke@435 34 #endif
duke@435 35
duke@435 36 ///////////////////////////////////////////////////////////////
duke@435 37 //
duke@435 38 // JvmtiEventTransition
duke@435 39 //
duke@435 40 // TO DO --
duke@435 41 // more handle purging
duke@435 42
duke@435 43 // Use this for JavaThreads and state is _thread_in_vm.
duke@435 44 class JvmtiJavaThreadEventTransition : StackObj {
duke@435 45 private:
duke@435 46 ResourceMark _rm;
duke@435 47 ThreadToNativeFromVM _transition;
duke@435 48 HandleMark _hm;
duke@435 49
duke@435 50 public:
duke@435 51 JvmtiJavaThreadEventTransition(JavaThread *thread) :
duke@435 52 _rm(),
duke@435 53 _transition(thread),
duke@435 54 _hm(thread) {};
duke@435 55 };
duke@435 56
duke@435 57 // For JavaThreads which are not in _thread_in_vm state
duke@435 58 // and other system threads use this.
duke@435 59 class JvmtiThreadEventTransition : StackObj {
duke@435 60 private:
duke@435 61 ResourceMark _rm;
duke@435 62 HandleMark _hm;
duke@435 63 JavaThreadState _saved_state;
duke@435 64 JavaThread *_jthread;
duke@435 65
duke@435 66 public:
duke@435 67 JvmtiThreadEventTransition(Thread *thread) : _rm(), _hm() {
duke@435 68 if (thread->is_Java_thread()) {
duke@435 69 _jthread = (JavaThread *)thread;
duke@435 70 _saved_state = _jthread->thread_state();
duke@435 71 if (_saved_state == _thread_in_Java) {
duke@435 72 ThreadStateTransition::transition_from_java(_jthread, _thread_in_native);
duke@435 73 } else {
duke@435 74 ThreadStateTransition::transition(_jthread, _saved_state, _thread_in_native);
duke@435 75 }
duke@435 76 } else {
duke@435 77 _jthread = NULL;
duke@435 78 }
duke@435 79 }
duke@435 80
duke@435 81 ~JvmtiThreadEventTransition() {
duke@435 82 if (_jthread != NULL)
duke@435 83 ThreadStateTransition::transition_from_native(_jthread, _saved_state);
duke@435 84 }
duke@435 85 };
duke@435 86
duke@435 87
duke@435 88 ///////////////////////////////////////////////////////////////
duke@435 89 //
duke@435 90 // JvmtiEventMark
duke@435 91 //
duke@435 92
duke@435 93 class JvmtiEventMark : public StackObj {
duke@435 94 private:
duke@435 95 JavaThread *_thread;
duke@435 96 JNIEnv* _jni_env;
duke@435 97 bool _exception_detected;
duke@435 98 bool _exception_caught;
duke@435 99 #if 0
duke@435 100 JNIHandleBlock* _hblock;
duke@435 101 #endif
duke@435 102
duke@435 103 public:
duke@435 104 JvmtiEventMark(JavaThread *thread) : _thread(thread),
duke@435 105 _jni_env(thread->jni_environment()) {
duke@435 106 #if 0
duke@435 107 _hblock = thread->active_handles();
duke@435 108 _hblock->clear_thoroughly(); // so we can be safe
duke@435 109 #else
duke@435 110 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 111 // for now, steal JNI push local frame code
duke@435 112 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 113 // we are before an event.
duke@435 114 // Save current jvmti thread exception state.
duke@435 115 if (state != NULL) {
duke@435 116 _exception_detected = state->is_exception_detected();
duke@435 117 _exception_caught = state->is_exception_caught();
duke@435 118 } else {
duke@435 119 _exception_detected = false;
duke@435 120 _exception_caught = false;
duke@435 121 }
duke@435 122
duke@435 123 JNIHandleBlock* old_handles = thread->active_handles();
duke@435 124 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
duke@435 125 assert(new_handles != NULL, "should not be NULL");
duke@435 126 new_handles->set_pop_frame_link(old_handles);
duke@435 127 thread->set_active_handles(new_handles);
duke@435 128 #endif
duke@435 129 assert(thread == JavaThread::current(), "thread must be current!");
duke@435 130 thread->frame_anchor()->make_walkable(thread);
duke@435 131 };
duke@435 132
duke@435 133 ~JvmtiEventMark() {
duke@435 134 #if 0
duke@435 135 _hblock->clear(); // for consistency with future correct behavior
duke@435 136 #else
duke@435 137 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 138 // for now, steal JNI pop local frame code
duke@435 139 JNIHandleBlock* old_handles = _thread->active_handles();
duke@435 140 JNIHandleBlock* new_handles = old_handles->pop_frame_link();
duke@435 141 assert(new_handles != NULL, "should not be NULL");
duke@435 142 _thread->set_active_handles(new_handles);
duke@435 143 // Note that we set the pop_frame_link to NULL explicitly, otherwise
duke@435 144 // the release_block call will release the blocks.
duke@435 145 old_handles->set_pop_frame_link(NULL);
duke@435 146 JNIHandleBlock::release_block(old_handles, _thread); // may block
duke@435 147 #endif
duke@435 148
duke@435 149 JvmtiThreadState* state = _thread->jvmti_thread_state();
duke@435 150 // we are continuing after an event.
duke@435 151 if (state != NULL) {
duke@435 152 // Restore the jvmti thread exception state.
duke@435 153 if (_exception_detected) {
duke@435 154 state->set_exception_detected();
duke@435 155 }
duke@435 156 if (_exception_caught) {
duke@435 157 state->set_exception_caught();
duke@435 158 }
duke@435 159 }
duke@435 160 }
duke@435 161
duke@435 162 #if 0
duke@435 163 jobject to_jobject(oop obj) { return obj == NULL? NULL : _hblock->allocate_handle_fast(obj); }
duke@435 164 #else
duke@435 165 // we want to use the code above - but that needs the JNIHandle changes - later...
duke@435 166 // for now, use regular make_local
duke@435 167 jobject to_jobject(oop obj) { return JNIHandles::make_local(_thread,obj); }
duke@435 168 #endif
duke@435 169
duke@435 170 jclass to_jclass(klassOop klass) { return (klass == NULL ? NULL : (jclass)to_jobject(Klass::cast(klass)->java_mirror())); }
duke@435 171
duke@435 172 jmethodID to_jmethodID(methodHandle method) { return method->jmethod_id(); }
duke@435 173
duke@435 174 JNIEnv* jni_env() { return _jni_env; }
duke@435 175 };
duke@435 176
duke@435 177 class JvmtiThreadEventMark : public JvmtiEventMark {
duke@435 178 private:
duke@435 179 jthread _jt;
duke@435 180
duke@435 181 public:
duke@435 182 JvmtiThreadEventMark(JavaThread *thread) :
duke@435 183 JvmtiEventMark(thread) {
duke@435 184 _jt = (jthread)(to_jobject(thread->threadObj()));
duke@435 185 };
duke@435 186 jthread jni_thread() { return _jt; }
duke@435 187 };
duke@435 188
duke@435 189 class JvmtiClassEventMark : public JvmtiThreadEventMark {
duke@435 190 private:
duke@435 191 jclass _jc;
duke@435 192
duke@435 193 public:
duke@435 194 JvmtiClassEventMark(JavaThread *thread, klassOop klass) :
duke@435 195 JvmtiThreadEventMark(thread) {
duke@435 196 _jc = to_jclass(klass);
duke@435 197 };
duke@435 198 jclass jni_class() { return _jc; }
duke@435 199 };
duke@435 200
duke@435 201 class JvmtiMethodEventMark : public JvmtiThreadEventMark {
duke@435 202 private:
duke@435 203 jmethodID _mid;
duke@435 204
duke@435 205 public:
duke@435 206 JvmtiMethodEventMark(JavaThread *thread, methodHandle method) :
duke@435 207 JvmtiThreadEventMark(thread),
duke@435 208 _mid(to_jmethodID(method)) {};
duke@435 209 jmethodID jni_methodID() { return _mid; }
duke@435 210 };
duke@435 211
duke@435 212 class JvmtiLocationEventMark : public JvmtiMethodEventMark {
duke@435 213 private:
duke@435 214 jlocation _loc;
duke@435 215
duke@435 216 public:
duke@435 217 JvmtiLocationEventMark(JavaThread *thread, methodHandle method, address location) :
duke@435 218 JvmtiMethodEventMark(thread, method),
duke@435 219 _loc(location - method->code_base()) {};
duke@435 220 jlocation location() { return _loc; }
duke@435 221 };
duke@435 222
duke@435 223 class JvmtiExceptionEventMark : public JvmtiLocationEventMark {
duke@435 224 private:
duke@435 225 jobject _exc;
duke@435 226
duke@435 227 public:
duke@435 228 JvmtiExceptionEventMark(JavaThread *thread, methodHandle method, address location, Handle exception) :
duke@435 229 JvmtiLocationEventMark(thread, method, location),
duke@435 230 _exc(to_jobject(exception())) {};
duke@435 231 jobject exception() { return _exc; }
duke@435 232 };
duke@435 233
duke@435 234 class JvmtiClassFileLoadEventMark : public JvmtiThreadEventMark {
duke@435 235 private:
duke@435 236 const char *_class_name;
duke@435 237 jobject _jloader;
duke@435 238 jobject _protection_domain;
duke@435 239 jclass _class_being_redefined;
duke@435 240
duke@435 241 public:
duke@435 242 JvmtiClassFileLoadEventMark(JavaThread *thread, symbolHandle name,
duke@435 243 Handle class_loader, Handle prot_domain, KlassHandle *class_being_redefined) : JvmtiThreadEventMark(thread) {
duke@435 244 _class_name = name() != NULL? name->as_utf8() : NULL;
duke@435 245 _jloader = (jobject)to_jobject(class_loader());
duke@435 246 _protection_domain = (jobject)to_jobject(prot_domain());
duke@435 247 if (class_being_redefined == NULL) {
duke@435 248 _class_being_redefined = NULL;
duke@435 249 } else {
duke@435 250 _class_being_redefined = (jclass)to_jclass((*class_being_redefined)());
duke@435 251 }
duke@435 252 };
duke@435 253 const char *class_name() {
duke@435 254 return _class_name;
duke@435 255 }
duke@435 256 jobject jloader() {
duke@435 257 return _jloader;
duke@435 258 }
duke@435 259 jobject protection_domain() {
duke@435 260 return _protection_domain;
duke@435 261 }
duke@435 262 jclass class_being_redefined() {
duke@435 263 return _class_being_redefined;
duke@435 264 }
duke@435 265 };
duke@435 266
duke@435 267 //////////////////////////////////////////////////////////////////////////////
duke@435 268
duke@435 269 int JvmtiExport::_field_access_count = 0;
duke@435 270 int JvmtiExport::_field_modification_count = 0;
duke@435 271
duke@435 272 bool JvmtiExport::_can_access_local_variables = false;
duke@435 273 bool JvmtiExport::_can_hotswap_or_post_breakpoint = false;
duke@435 274 bool JvmtiExport::_can_modify_any_class = false;
duke@435 275 bool JvmtiExport::_can_walk_any_space = false;
duke@435 276
duke@435 277 bool JvmtiExport::_has_redefined_a_class = false;
duke@435 278 bool JvmtiExport::_all_dependencies_are_recorded = false;
duke@435 279
duke@435 280 //
duke@435 281 // field access management
duke@435 282 //
duke@435 283
duke@435 284 // interpreter generator needs the address of the counter
duke@435 285 address JvmtiExport::get_field_access_count_addr() {
duke@435 286 // We don't grab a lock because we don't want to
duke@435 287 // serialize field access between all threads. This means that a
duke@435 288 // thread on another processor can see the wrong count value and
duke@435 289 // may either miss making a needed call into post_field_access()
duke@435 290 // or will make an unneeded call into post_field_access(). We pay
duke@435 291 // this price to avoid slowing down the VM when we aren't watching
duke@435 292 // field accesses.
duke@435 293 // Other access/mutation safe by virtue of being in VM state.
duke@435 294 return (address)(&_field_access_count);
duke@435 295 }
duke@435 296
duke@435 297 //
duke@435 298 // field modification management
duke@435 299 //
duke@435 300
duke@435 301 // interpreter generator needs the address of the counter
duke@435 302 address JvmtiExport::get_field_modification_count_addr() {
duke@435 303 // We don't grab a lock because we don't
duke@435 304 // want to serialize field modification between all threads. This
duke@435 305 // means that a thread on another processor can see the wrong
duke@435 306 // count value and may either miss making a needed call into
duke@435 307 // post_field_modification() or will make an unneeded call into
duke@435 308 // post_field_modification(). We pay this price to avoid slowing
duke@435 309 // down the VM when we aren't watching field modifications.
duke@435 310 // Other access/mutation safe by virtue of being in VM state.
duke@435 311 return (address)(&_field_modification_count);
duke@435 312 }
duke@435 313
duke@435 314
duke@435 315 ///////////////////////////////////////////////////////////////
duke@435 316 // Functions needed by java.lang.instrument for starting up javaagent.
duke@435 317 ///////////////////////////////////////////////////////////////
duke@435 318
duke@435 319 jint
duke@435 320 JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) {
dcubed@1556 321 // The JVMTI_VERSION_INTERFACE_JVMTI part of the version number
dcubed@1556 322 // has already been validated in JNI GetEnv().
dcubed@1556 323 int major, minor, micro;
dcubed@1556 324
dcubed@1556 325 // micro version doesn't matter here (yet?)
dcubed@1556 326 decode_version_values(version, &major, &minor, &micro);
dcubed@1556 327 switch (major) {
dcubed@1556 328 case 1:
dcubed@1556 329 switch (minor) {
dcubed@1556 330 case 0: // version 1.0.<micro> is recognized
dcubed@1556 331 case 1: // version 1.1.<micro> is recognized
dcubed@1556 332 break;
dcubed@1556 333
dcubed@1556 334 default:
dcubed@1556 335 return JNI_EVERSION; // unsupported minor version number
dcubed@1556 336 }
dcubed@1556 337 break;
dcubed@1556 338
dcubed@1556 339 default:
dcubed@1556 340 return JNI_EVERSION; // unsupported major version number
dcubed@1556 341 }
duke@435 342
duke@435 343 if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) {
duke@435 344 JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread();
duke@435 345 // transition code: native to VM
duke@435 346 ThreadInVMfromNative __tiv(current_thread);
duke@435 347 __ENTRY(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread)
duke@435 348 debug_only(VMNativeEntryWrapper __vew;)
duke@435 349
dcubed@1556 350 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
duke@435 351 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
duke@435 352 return JNI_OK;
duke@435 353
duke@435 354 } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
duke@435 355 // not live, no thread to transition
dcubed@1556 356 JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version);
duke@435 357 *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv*
duke@435 358 return JNI_OK;
duke@435 359
duke@435 360 } else {
duke@435 361 // Called at the wrong time
duke@435 362 *penv = NULL;
duke@435 363 return JNI_EDETACHED;
duke@435 364 }
duke@435 365 }
duke@435 366
dcubed@1556 367
dcubed@1556 368 void
dcubed@1556 369 JvmtiExport::decode_version_values(jint version, int * major, int * minor,
dcubed@1556 370 int * micro) {
dcubed@1556 371 *major = (version & JVMTI_VERSION_MASK_MAJOR) >> JVMTI_VERSION_SHIFT_MAJOR;
dcubed@1556 372 *minor = (version & JVMTI_VERSION_MASK_MINOR) >> JVMTI_VERSION_SHIFT_MINOR;
dcubed@1556 373 *micro = (version & JVMTI_VERSION_MASK_MICRO) >> JVMTI_VERSION_SHIFT_MICRO;
dcubed@1556 374 }
dcubed@1556 375
duke@435 376 void JvmtiExport::enter_primordial_phase() {
duke@435 377 JvmtiEnvBase::set_phase(JVMTI_PHASE_PRIMORDIAL);
duke@435 378 }
duke@435 379
duke@435 380 void JvmtiExport::enter_start_phase() {
duke@435 381 JvmtiManageCapabilities::recompute_always_capabilities();
duke@435 382 JvmtiEnvBase::set_phase(JVMTI_PHASE_START);
duke@435 383 }
duke@435 384
duke@435 385 void JvmtiExport::enter_onload_phase() {
duke@435 386 JvmtiEnvBase::set_phase(JVMTI_PHASE_ONLOAD);
duke@435 387 }
duke@435 388
duke@435 389 void JvmtiExport::enter_live_phase() {
duke@435 390 JvmtiEnvBase::set_phase(JVMTI_PHASE_LIVE);
duke@435 391 }
duke@435 392
duke@435 393 //
duke@435 394 // JVMTI events that the VM posts to the debugger and also startup agent
duke@435 395 // and call the agent's premain() for java.lang.instrument.
duke@435 396 //
duke@435 397
duke@435 398 void JvmtiExport::post_vm_start() {
duke@435 399 EVT_TRIG_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Trg VM start event triggered" ));
duke@435 400
duke@435 401 // can now enable some events
duke@435 402 JvmtiEventController::vm_start();
duke@435 403
duke@435 404 JvmtiEnvIterator it;
duke@435 405 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 406 if (env->is_enabled(JVMTI_EVENT_VM_START)) {
duke@435 407 EVT_TRACE(JVMTI_EVENT_VM_START, ("JVMTI Evt VM start event sent" ));
duke@435 408
duke@435 409 JavaThread *thread = JavaThread::current();
duke@435 410 JvmtiThreadEventMark jem(thread);
duke@435 411 JvmtiJavaThreadEventTransition jet(thread);
duke@435 412 jvmtiEventVMStart callback = env->callbacks()->VMStart;
duke@435 413 if (callback != NULL) {
duke@435 414 (*callback)(env->jvmti_external(), jem.jni_env());
duke@435 415 }
duke@435 416 }
duke@435 417 }
duke@435 418 }
duke@435 419
duke@435 420
duke@435 421 void JvmtiExport::post_vm_initialized() {
duke@435 422 EVT_TRIG_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Trg VM init event triggered" ));
duke@435 423
duke@435 424 // can now enable events
duke@435 425 JvmtiEventController::vm_init();
duke@435 426
duke@435 427 JvmtiEnvIterator it;
duke@435 428 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 429 if (env->is_enabled(JVMTI_EVENT_VM_INIT)) {
duke@435 430 EVT_TRACE(JVMTI_EVENT_VM_INIT, ("JVMTI Evt VM init event sent" ));
duke@435 431
duke@435 432 JavaThread *thread = JavaThread::current();
duke@435 433 JvmtiThreadEventMark jem(thread);
duke@435 434 JvmtiJavaThreadEventTransition jet(thread);
duke@435 435 jvmtiEventVMInit callback = env->callbacks()->VMInit;
duke@435 436 if (callback != NULL) {
duke@435 437 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 438 }
duke@435 439 }
duke@435 440 }
duke@435 441 }
duke@435 442
duke@435 443
duke@435 444 void JvmtiExport::post_vm_death() {
duke@435 445 EVT_TRIG_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Trg VM death event triggered" ));
duke@435 446
duke@435 447 JvmtiEnvIterator it;
duke@435 448 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 449 if (env->is_enabled(JVMTI_EVENT_VM_DEATH)) {
duke@435 450 EVT_TRACE(JVMTI_EVENT_VM_DEATH, ("JVMTI Evt VM death event sent" ));
duke@435 451
duke@435 452 JavaThread *thread = JavaThread::current();
duke@435 453 JvmtiEventMark jem(thread);
duke@435 454 JvmtiJavaThreadEventTransition jet(thread);
duke@435 455 jvmtiEventVMDeath callback = env->callbacks()->VMDeath;
duke@435 456 if (callback != NULL) {
duke@435 457 (*callback)(env->jvmti_external(), jem.jni_env());
duke@435 458 }
duke@435 459 }
duke@435 460 }
duke@435 461
duke@435 462 JvmtiEnvBase::set_phase(JVMTI_PHASE_DEAD);
duke@435 463 JvmtiEventController::vm_death();
duke@435 464 }
duke@435 465
duke@435 466 char**
duke@435 467 JvmtiExport::get_all_native_method_prefixes(int* count_ptr) {
duke@435 468 // Have to grab JVMTI thread state lock to be sure environment doesn't
duke@435 469 // go away while we iterate them. No locks during VM bring-up.
duke@435 470 if (Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint()) {
duke@435 471 return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
duke@435 472 } else {
duke@435 473 MutexLocker mu(JvmtiThreadState_lock);
duke@435 474 return JvmtiEnvBase::get_all_native_method_prefixes(count_ptr);
duke@435 475 }
duke@435 476 }
duke@435 477
duke@435 478 class JvmtiClassFileLoadHookPoster : public StackObj {
duke@435 479 private:
duke@435 480 symbolHandle _h_name;
duke@435 481 Handle _class_loader;
duke@435 482 Handle _h_protection_domain;
duke@435 483 unsigned char ** _data_ptr;
duke@435 484 unsigned char ** _end_ptr;
duke@435 485 JavaThread * _thread;
duke@435 486 jint _curr_len;
duke@435 487 unsigned char * _curr_data;
duke@435 488 JvmtiEnv * _curr_env;
duke@435 489 jint * _cached_length_ptr;
duke@435 490 unsigned char ** _cached_data_ptr;
duke@435 491 JvmtiThreadState * _state;
duke@435 492 KlassHandle * _h_class_being_redefined;
duke@435 493 JvmtiClassLoadKind _load_kind;
duke@435 494
duke@435 495 public:
duke@435 496 inline JvmtiClassFileLoadHookPoster(symbolHandle h_name, Handle class_loader,
duke@435 497 Handle h_protection_domain,
duke@435 498 unsigned char **data_ptr, unsigned char **end_ptr,
duke@435 499 unsigned char **cached_data_ptr,
duke@435 500 jint *cached_length_ptr) {
duke@435 501 _h_name = h_name;
duke@435 502 _class_loader = class_loader;
duke@435 503 _h_protection_domain = h_protection_domain;
duke@435 504 _data_ptr = data_ptr;
duke@435 505 _end_ptr = end_ptr;
duke@435 506 _thread = JavaThread::current();
duke@435 507 _curr_len = *end_ptr - *data_ptr;
duke@435 508 _curr_data = *data_ptr;
duke@435 509 _curr_env = NULL;
duke@435 510 _cached_length_ptr = cached_length_ptr;
duke@435 511 _cached_data_ptr = cached_data_ptr;
duke@435 512 *_cached_length_ptr = 0;
duke@435 513 *_cached_data_ptr = NULL;
duke@435 514
duke@435 515 _state = _thread->jvmti_thread_state();
duke@435 516 if (_state != NULL) {
duke@435 517 _h_class_being_redefined = _state->get_class_being_redefined();
duke@435 518 _load_kind = _state->get_class_load_kind();
duke@435 519 // Clear class_being_redefined flag here. The action
duke@435 520 // from agent handler could generate a new class file load
duke@435 521 // hook event and if it is not cleared the new event generated
duke@435 522 // from regular class file load could have this stale redefined
duke@435 523 // class handle info.
duke@435 524 _state->clear_class_being_redefined();
duke@435 525 } else {
duke@435 526 // redefine and retransform will always set the thread state
duke@435 527 _h_class_being_redefined = (KlassHandle *) NULL;
duke@435 528 _load_kind = jvmti_class_load_kind_load;
duke@435 529 }
duke@435 530 }
duke@435 531
duke@435 532 void post() {
duke@435 533 // EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
duke@435 534 // ("JVMTI [%s] class file load hook event triggered",
duke@435 535 // JvmtiTrace::safe_get_thread_name(_thread)));
duke@435 536 post_all_envs();
duke@435 537 copy_modified_data();
duke@435 538 }
duke@435 539
duke@435 540 private:
duke@435 541 void post_all_envs() {
duke@435 542 if (_load_kind != jvmti_class_load_kind_retransform) {
duke@435 543 // for class load and redefine,
duke@435 544 // call the non-retransformable agents
duke@435 545 JvmtiEnvIterator it;
duke@435 546 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 547 if (!env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) {
duke@435 548 // non-retransformable agents cannot retransform back,
duke@435 549 // so no need to cache the original class file bytes
duke@435 550 post_to_env(env, false);
duke@435 551 }
duke@435 552 }
duke@435 553 }
duke@435 554 JvmtiEnvIterator it;
duke@435 555 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 556 // retransformable agents get all events
duke@435 557 if (env->is_retransformable() && env->is_enabled(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK)) {
duke@435 558 // retransformable agents need to cache the original class file
duke@435 559 // bytes if changes are made via the ClassFileLoadHook
duke@435 560 post_to_env(env, true);
duke@435 561 }
duke@435 562 }
duke@435 563 }
duke@435 564
duke@435 565 void post_to_env(JvmtiEnv* env, bool caching_needed) {
duke@435 566 unsigned char *new_data = NULL;
duke@435 567 jint new_len = 0;
duke@435 568 // EVT_TRACE(JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
duke@435 569 // ("JVMTI [%s] class file load hook event sent %s data_ptr = %d, data_len = %d",
duke@435 570 // JvmtiTrace::safe_get_thread_name(_thread),
duke@435 571 // _h_name.is_null() ? "NULL" : _h_name->as_utf8(),
duke@435 572 // _curr_data, _curr_len ));
duke@435 573 JvmtiClassFileLoadEventMark jem(_thread, _h_name, _class_loader,
duke@435 574 _h_protection_domain,
duke@435 575 _h_class_being_redefined);
duke@435 576 JvmtiJavaThreadEventTransition jet(_thread);
duke@435 577 JNIEnv* jni_env = (JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL)?
duke@435 578 NULL : jem.jni_env();
duke@435 579 jvmtiEventClassFileLoadHook callback = env->callbacks()->ClassFileLoadHook;
duke@435 580 if (callback != NULL) {
duke@435 581 (*callback)(env->jvmti_external(), jni_env,
duke@435 582 jem.class_being_redefined(),
duke@435 583 jem.jloader(), jem.class_name(),
duke@435 584 jem.protection_domain(),
duke@435 585 _curr_len, _curr_data,
duke@435 586 &new_len, &new_data);
duke@435 587 }
duke@435 588 if (new_data != NULL) {
duke@435 589 // this agent has modified class data.
duke@435 590 if (caching_needed && *_cached_data_ptr == NULL) {
duke@435 591 // data has been changed by the new retransformable agent
duke@435 592 // and it hasn't already been cached, cache it
duke@435 593 *_cached_data_ptr = (unsigned char *)os::malloc(_curr_len);
duke@435 594 memcpy(*_cached_data_ptr, _curr_data, _curr_len);
duke@435 595 *_cached_length_ptr = _curr_len;
duke@435 596 }
duke@435 597
duke@435 598 if (_curr_data != *_data_ptr) {
duke@435 599 // curr_data is previous agent modified class data.
duke@435 600 // And this has been changed by the new agent so
duke@435 601 // we can delete it now.
duke@435 602 _curr_env->Deallocate(_curr_data);
duke@435 603 }
duke@435 604
duke@435 605 // Class file data has changed by the current agent.
duke@435 606 _curr_data = new_data;
duke@435 607 _curr_len = new_len;
duke@435 608 // Save the current agent env we need this to deallocate the
duke@435 609 // memory allocated by this agent.
duke@435 610 _curr_env = env;
duke@435 611 }
duke@435 612 }
duke@435 613
duke@435 614 void copy_modified_data() {
duke@435 615 // if one of the agent has modified class file data.
duke@435 616 // Copy modified class data to new resources array.
duke@435 617 if (_curr_data != *_data_ptr) {
duke@435 618 *_data_ptr = NEW_RESOURCE_ARRAY(u1, _curr_len);
duke@435 619 memcpy(*_data_ptr, _curr_data, _curr_len);
duke@435 620 *_end_ptr = *_data_ptr + _curr_len;
duke@435 621 _curr_env->Deallocate(_curr_data);
duke@435 622 }
duke@435 623 }
duke@435 624 };
duke@435 625
duke@435 626 bool JvmtiExport::_should_post_class_file_load_hook = false;
duke@435 627
duke@435 628 // this entry is for class file load hook on class load, redefine and retransform
duke@435 629 void JvmtiExport::post_class_file_load_hook(symbolHandle h_name,
duke@435 630 Handle class_loader,
duke@435 631 Handle h_protection_domain,
duke@435 632 unsigned char **data_ptr,
duke@435 633 unsigned char **end_ptr,
duke@435 634 unsigned char **cached_data_ptr,
duke@435 635 jint *cached_length_ptr) {
duke@435 636 JvmtiClassFileLoadHookPoster poster(h_name, class_loader,
duke@435 637 h_protection_domain,
duke@435 638 data_ptr, end_ptr,
duke@435 639 cached_data_ptr,
duke@435 640 cached_length_ptr);
duke@435 641 poster.post();
duke@435 642 }
duke@435 643
duke@435 644 void JvmtiExport::report_unsupported(bool on) {
duke@435 645 // If any JVMTI service is turned on, we need to exit before native code
duke@435 646 // tries to access nonexistant services.
duke@435 647 if (on) {
duke@435 648 vm_exit_during_initialization("Java Kernel does not support JVMTI.");
duke@435 649 }
duke@435 650 }
duke@435 651
duke@435 652
duke@435 653 #ifndef JVMTI_KERNEL
duke@435 654 static inline klassOop oop_to_klassOop(oop obj) {
duke@435 655 klassOop k = obj->klass();
duke@435 656
duke@435 657 // if the object is a java.lang.Class then return the java mirror
never@1577 658 if (k == SystemDictionary::Class_klass()) {
duke@435 659 if (!java_lang_Class::is_primitive(obj)) {
duke@435 660 k = java_lang_Class::as_klassOop(obj);
duke@435 661 assert(k != NULL, "class for non-primitive mirror must exist");
duke@435 662 }
duke@435 663 }
duke@435 664 return k;
duke@435 665 }
duke@435 666
duke@435 667 class JvmtiVMObjectAllocEventMark : public JvmtiClassEventMark {
duke@435 668 private:
duke@435 669 jobject _jobj;
duke@435 670 jlong _size;
duke@435 671 public:
duke@435 672 JvmtiVMObjectAllocEventMark(JavaThread *thread, oop obj) : JvmtiClassEventMark(thread, oop_to_klassOop(obj)) {
duke@435 673 _jobj = (jobject)to_jobject(obj);
duke@435 674 _size = obj->size() * wordSize;
duke@435 675 };
duke@435 676 jobject jni_jobject() { return _jobj; }
duke@435 677 jlong size() { return _size; }
duke@435 678 };
duke@435 679
duke@435 680 class JvmtiCompiledMethodLoadEventMark : public JvmtiMethodEventMark {
duke@435 681 private:
duke@435 682 jint _code_size;
duke@435 683 const void *_code_data;
duke@435 684 jint _map_length;
duke@435 685 jvmtiAddrLocationMap *_map;
duke@435 686 const void *_compile_info;
duke@435 687 public:
dcubed@1619 688 JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = NULL)
duke@435 689 : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
duke@435 690 _code_data = nm->code_begin();
duke@435 691 _code_size = nm->code_size();
dcubed@1619 692 _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is NULL.
duke@435 693 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
duke@435 694 }
duke@435 695 ~JvmtiCompiledMethodLoadEventMark() {
duke@435 696 FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, _map);
duke@435 697 }
duke@435 698
duke@435 699 jint code_size() { return _code_size; }
duke@435 700 const void *code_data() { return _code_data; }
duke@435 701 jint map_length() { return _map_length; }
duke@435 702 const jvmtiAddrLocationMap* map() { return _map; }
duke@435 703 const void *compile_info() { return _compile_info; }
duke@435 704 };
duke@435 705
duke@435 706
duke@435 707
duke@435 708 class JvmtiMonitorEventMark : public JvmtiThreadEventMark {
duke@435 709 private:
duke@435 710 jobject _jobj;
duke@435 711 public:
duke@435 712 JvmtiMonitorEventMark(JavaThread *thread, oop object)
duke@435 713 : JvmtiThreadEventMark(thread){
duke@435 714 _jobj = to_jobject(object);
duke@435 715 }
duke@435 716 jobject jni_object() { return _jobj; }
duke@435 717 };
duke@435 718
duke@435 719 ///////////////////////////////////////////////////////////////
duke@435 720 //
duke@435 721 // pending CompiledMethodUnload support
duke@435 722 //
duke@435 723
duke@435 724 bool JvmtiExport::_have_pending_compiled_method_unload_events;
duke@435 725 GrowableArray<jmethodID>* JvmtiExport::_pending_compiled_method_unload_method_ids;
duke@435 726 GrowableArray<const void *>* JvmtiExport::_pending_compiled_method_unload_code_begins;
duke@435 727 JavaThread* JvmtiExport::_current_poster;
duke@435 728
never@1932 729 void JvmtiExport::post_compiled_method_unload_internal(JavaThread* self, jmethodID method, const void *code_begin) {
never@1932 730 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
never@1932 731 ("JVMTI [%s] method compile unload event triggered",
never@1932 732 JvmtiTrace::safe_get_thread_name(self)));
never@1932 733
never@1932 734 // post the event for each environment that has this event enabled.
never@1932 735 JvmtiEnvIterator it;
never@1932 736 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
never@1932 737 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) {
never@1932 738
never@1932 739 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
never@1932 740 ("JVMTI [%s] class compile method unload event sent jmethodID " PTR_FORMAT,
never@1932 741 JvmtiTrace::safe_get_thread_name(self), method));
never@1932 742
never@1932 743 ResourceMark rm(self);
never@1932 744
never@1932 745 JvmtiEventMark jem(self);
never@1932 746 JvmtiJavaThreadEventTransition jet(self);
never@1932 747 jvmtiEventCompiledMethodUnload callback = env->callbacks()->CompiledMethodUnload;
never@1932 748 if (callback != NULL) {
never@1932 749 (*callback)(env->jvmti_external(), method, code_begin);
never@1932 750 }
never@1932 751 }
never@1932 752 }
never@1932 753 }
never@1932 754
duke@435 755 // post any pending CompiledMethodUnload events
duke@435 756
duke@435 757 void JvmtiExport::post_pending_compiled_method_unload_events() {
duke@435 758 JavaThread* self = JavaThread::current();
duke@435 759 assert(!self->owns_locks(), "can't hold locks");
duke@435 760
duke@435 761 // Indicates if this is the first activiation of this function.
duke@435 762 // In theory the profiler's callback could call back into VM and provoke
duke@435 763 // another CompiledMethodLoad event to be posted from this thread. As the
duke@435 764 // stack rewinds we need to ensure that the original activation does the
duke@435 765 // completion and notifies any waiters.
duke@435 766 bool first_activation = false;
duke@435 767
duke@435 768 // the jmethodID (may not be valid) to be used for a single event
duke@435 769 jmethodID method;
duke@435 770 const void *code_begin;
duke@435 771
duke@435 772 // grab the monitor and check if another thread is already posting
duke@435 773 // events. If there is another thread posting events then we wait
duke@435 774 // until it completes. (In theory we could check the pending events to
duke@435 775 // see if any of the addresses overlap with the event that we want to
duke@435 776 // post but as it will happen so rarely we just block any thread waiting
duke@435 777 // to post a CompiledMethodLoad or DynamicCodeGenerated event until all
duke@435 778 // pending CompiledMethodUnload events have been posted).
duke@435 779 //
duke@435 780 // If another thread isn't posting we examine the list of pending jmethodIDs.
duke@435 781 // If the list is empty then we are done. If it's not empty then this thread
duke@435 782 // (self) becomes the pending event poster and we remove the top (last)
duke@435 783 // event from the list. Note that this means we remove the newest event first
duke@435 784 // but as they are all CompiledMethodUnload events the order doesn't matter.
duke@435 785 // Once we have removed a jmethodID then we exit the monitor. Any other thread
duke@435 786 // wanting to post a CompiledMethodLoad or DynamicCodeGenerated event will
duke@435 787 // be forced to wait on the monitor.
duke@435 788 {
duke@435 789 MutexLocker mu(JvmtiPendingEvent_lock);
duke@435 790 if (_current_poster != self) {
duke@435 791 while (_current_poster != NULL) {
duke@435 792 JvmtiPendingEvent_lock->wait();
duke@435 793 }
duke@435 794 }
duke@435 795 if ((_pending_compiled_method_unload_method_ids == NULL) ||
duke@435 796 (_pending_compiled_method_unload_method_ids->length() == 0)) {
duke@435 797 return;
duke@435 798 }
duke@435 799 if (_current_poster == NULL) {
duke@435 800 _current_poster = self;
duke@435 801 first_activation = true;
duke@435 802 } else {
duke@435 803 // re-entrant
duke@435 804 guarantee(_current_poster == self, "checking");
duke@435 805 }
duke@435 806 method = _pending_compiled_method_unload_method_ids->pop();
duke@435 807 code_begin = _pending_compiled_method_unload_code_begins->pop();
duke@435 808 }
duke@435 809
duke@435 810 // This thread is the pending event poster so it first posts the CompiledMethodUnload
duke@435 811 // event for the jmethodID that has been removed from the list. Once posted it
duke@435 812 // re-grabs the monitor and checks the list again. If the list is empty then and this
duke@435 813 // is the first activation of the function then we reset the _have_pending_events
duke@435 814 // flag, cleanup _current_poster to indicate that no thread is now servicing the
duke@435 815 // pending events list, and finally notify any thread that might be waiting.
duke@435 816 for (;;) {
never@1932 817 post_compiled_method_unload_internal(self, method, code_begin);
duke@435 818
duke@435 819 // event posted, now re-grab monitor and get the next event
duke@435 820 // If there's no next event then we are done. If this is the first
duke@435 821 // activiation of this function by this thread notify any waiters
duke@435 822 // so that they can post.
duke@435 823 {
duke@435 824 MutexLocker ml(JvmtiPendingEvent_lock);
duke@435 825 if (_pending_compiled_method_unload_method_ids->length() == 0) {
duke@435 826 if (first_activation) {
duke@435 827 _have_pending_compiled_method_unload_events = false;
duke@435 828 _current_poster = NULL;
duke@435 829 JvmtiPendingEvent_lock->notify_all();
duke@435 830 }
duke@435 831 return;
duke@435 832 }
duke@435 833 method = _pending_compiled_method_unload_method_ids->pop();
duke@435 834 code_begin = _pending_compiled_method_unload_code_begins->pop();
duke@435 835 }
duke@435 836 }
duke@435 837 }
duke@435 838
duke@435 839 ///////////////////////////////////////////////////////////////
duke@435 840 //
duke@435 841 // JvmtiExport
duke@435 842 //
duke@435 843
duke@435 844 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, methodOop method, address location) {
duke@435 845 HandleMark hm(thread);
duke@435 846 methodHandle mh(thread, method);
duke@435 847
duke@435 848 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 849 if (state == NULL) {
duke@435 850 return;
duke@435 851 }
duke@435 852 EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Trg Breakpoint triggered",
duke@435 853 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 854 JvmtiEnvThreadStateIterator it(state);
duke@435 855 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 856 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
duke@435 857 if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
duke@435 858 ThreadState old_os_state = thread->osthread()->get_state();
duke@435 859 thread->osthread()->set_state(BREAKPOINTED);
duke@435 860 EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Evt Breakpoint sent %s.%s @ %d",
duke@435 861 JvmtiTrace::safe_get_thread_name(thread),
duke@435 862 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 863 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 864 location - mh()->code_base() ));
duke@435 865
duke@435 866 JvmtiEnv *env = ets->get_env();
duke@435 867 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 868 JvmtiJavaThreadEventTransition jet(thread);
duke@435 869 jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
duke@435 870 if (callback != NULL) {
duke@435 871 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 872 jem.jni_methodID(), jem.location());
duke@435 873 }
duke@435 874
duke@435 875 ets->set_breakpoint_posted();
duke@435 876 thread->osthread()->set_state(old_os_state);
duke@435 877 }
duke@435 878 }
duke@435 879 }
duke@435 880
duke@435 881 //////////////////////////////////////////////////////////////////////////////
duke@435 882
duke@435 883 bool JvmtiExport::_can_get_source_debug_extension = false;
duke@435 884 bool JvmtiExport::_can_maintain_original_method_order = false;
duke@435 885 bool JvmtiExport::_can_post_interpreter_events = false;
dcubed@1648 886 bool JvmtiExport::_can_post_on_exceptions = false;
duke@435 887 bool JvmtiExport::_can_post_breakpoint = false;
duke@435 888 bool JvmtiExport::_can_post_field_access = false;
duke@435 889 bool JvmtiExport::_can_post_field_modification = false;
duke@435 890 bool JvmtiExport::_can_post_method_entry = false;
duke@435 891 bool JvmtiExport::_can_post_method_exit = false;
duke@435 892 bool JvmtiExport::_can_pop_frame = false;
duke@435 893 bool JvmtiExport::_can_force_early_return = false;
duke@435 894
duke@435 895 bool JvmtiExport::_should_post_single_step = false;
duke@435 896 bool JvmtiExport::_should_post_field_access = false;
duke@435 897 bool JvmtiExport::_should_post_field_modification = false;
duke@435 898 bool JvmtiExport::_should_post_class_load = false;
duke@435 899 bool JvmtiExport::_should_post_class_prepare = false;
duke@435 900 bool JvmtiExport::_should_post_class_unload = false;
duke@435 901 bool JvmtiExport::_should_post_thread_life = false;
duke@435 902 bool JvmtiExport::_should_clean_up_heap_objects = false;
duke@435 903 bool JvmtiExport::_should_post_native_method_bind = false;
duke@435 904 bool JvmtiExport::_should_post_dynamic_code_generated = false;
duke@435 905 bool JvmtiExport::_should_post_data_dump = false;
duke@435 906 bool JvmtiExport::_should_post_compiled_method_load = false;
duke@435 907 bool JvmtiExport::_should_post_compiled_method_unload = false;
duke@435 908 bool JvmtiExport::_should_post_monitor_contended_enter = false;
duke@435 909 bool JvmtiExport::_should_post_monitor_contended_entered = false;
duke@435 910 bool JvmtiExport::_should_post_monitor_wait = false;
duke@435 911 bool JvmtiExport::_should_post_monitor_waited = false;
duke@435 912 bool JvmtiExport::_should_post_garbage_collection_start = false;
duke@435 913 bool JvmtiExport::_should_post_garbage_collection_finish = false;
duke@435 914 bool JvmtiExport::_should_post_object_free = false;
duke@435 915 bool JvmtiExport::_should_post_resource_exhausted = false;
duke@435 916 bool JvmtiExport::_should_post_vm_object_alloc = false;
dcubed@1648 917 bool JvmtiExport::_should_post_on_exceptions = false;
duke@435 918
duke@435 919 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 920
duke@435 921
duke@435 922 //
duke@435 923 // JVMTI single step management
duke@435 924 //
duke@435 925 void JvmtiExport::at_single_stepping_point(JavaThread *thread, methodOop method, address location) {
duke@435 926 assert(JvmtiExport::should_post_single_step(), "must be single stepping");
duke@435 927
duke@435 928 HandleMark hm(thread);
duke@435 929 methodHandle mh(thread, method);
duke@435 930
duke@435 931 // update information about current location and post a step event
duke@435 932 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 933 if (state == NULL) {
duke@435 934 return;
duke@435 935 }
duke@435 936 EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Trg Single Step triggered",
duke@435 937 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 938 if (!state->hide_single_stepping()) {
duke@435 939 if (state->is_pending_step_for_popframe()) {
duke@435 940 state->process_pending_step_for_popframe();
duke@435 941 }
duke@435 942 if (state->is_pending_step_for_earlyret()) {
duke@435 943 state->process_pending_step_for_earlyret();
duke@435 944 }
duke@435 945 JvmtiExport::post_single_step(thread, mh(), location);
duke@435 946 }
duke@435 947 }
duke@435 948
duke@435 949
duke@435 950 void JvmtiExport::expose_single_stepping(JavaThread *thread) {
duke@435 951 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 952 if (state != NULL) {
duke@435 953 state->clear_hide_single_stepping();
duke@435 954 }
duke@435 955 }
duke@435 956
duke@435 957
duke@435 958 bool JvmtiExport::hide_single_stepping(JavaThread *thread) {
duke@435 959 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 960 if (state != NULL && state->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
duke@435 961 state->set_hide_single_stepping();
duke@435 962 return true;
duke@435 963 } else {
duke@435 964 return false;
duke@435 965 }
duke@435 966 }
duke@435 967
duke@435 968 void JvmtiExport::post_class_load(JavaThread *thread, klassOop klass) {
duke@435 969 HandleMark hm(thread);
duke@435 970 KlassHandle kh(thread, klass);
duke@435 971
duke@435 972 EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Trg Class Load triggered",
duke@435 973 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 974 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 975 if (state == NULL) {
duke@435 976 return;
duke@435 977 }
duke@435 978 JvmtiEnvThreadStateIterator it(state);
duke@435 979 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 980 if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) {
duke@435 981 EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("JVMTI [%s] Evt Class Load sent %s",
duke@435 982 JvmtiTrace::safe_get_thread_name(thread),
duke@435 983 kh()==NULL? "NULL" : Klass::cast(kh())->external_name() ));
duke@435 984
duke@435 985 JvmtiEnv *env = ets->get_env();
duke@435 986 JvmtiClassEventMark jem(thread, kh());
duke@435 987 JvmtiJavaThreadEventTransition jet(thread);
duke@435 988 jvmtiEventClassLoad callback = env->callbacks()->ClassLoad;
duke@435 989 if (callback != NULL) {
duke@435 990 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
duke@435 991 }
duke@435 992 }
duke@435 993 }
duke@435 994 }
duke@435 995
duke@435 996
duke@435 997 void JvmtiExport::post_class_prepare(JavaThread *thread, klassOop klass) {
duke@435 998 HandleMark hm(thread);
duke@435 999 KlassHandle kh(thread, klass);
duke@435 1000
duke@435 1001 EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Trg Class Prepare triggered",
duke@435 1002 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1003 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 1004 if (state == NULL) {
duke@435 1005 return;
duke@435 1006 }
duke@435 1007 JvmtiEnvThreadStateIterator it(state);
duke@435 1008 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1009 if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) {
duke@435 1010 EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("JVMTI [%s] Evt Class Prepare sent %s",
duke@435 1011 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1012 kh()==NULL? "NULL" : Klass::cast(kh())->external_name() ));
duke@435 1013
duke@435 1014 JvmtiEnv *env = ets->get_env();
duke@435 1015 JvmtiClassEventMark jem(thread, kh());
duke@435 1016 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1017 jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare;
duke@435 1018 if (callback != NULL) {
duke@435 1019 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
duke@435 1020 }
duke@435 1021 }
duke@435 1022 }
duke@435 1023 }
duke@435 1024
duke@435 1025 void JvmtiExport::post_class_unload(klassOop klass) {
duke@435 1026 Thread *thread = Thread::current();
duke@435 1027 HandleMark hm(thread);
duke@435 1028 KlassHandle kh(thread, klass);
duke@435 1029
duke@435 1030 EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Trg Class Unload triggered" ));
duke@435 1031 if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
duke@435 1032 assert(thread->is_VM_thread(), "wrong thread");
duke@435 1033
duke@435 1034 // get JavaThread for whom we are proxy
duke@435 1035 JavaThread *real_thread =
duke@435 1036 (JavaThread *)((VMThread *)thread)->vm_operation()->calling_thread();
duke@435 1037
duke@435 1038 JvmtiEnvIterator it;
duke@435 1039 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1040 if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) {
duke@435 1041 EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("JVMTI [?] Evt Class Unload sent %s",
duke@435 1042 kh()==NULL? "NULL" : Klass::cast(kh())->external_name() ));
duke@435 1043
duke@435 1044 // do everything manually, since this is a proxy - needs special care
duke@435 1045 JNIEnv* jni_env = real_thread->jni_environment();
duke@435 1046 jthread jt = (jthread)JNIHandles::make_local(real_thread, real_thread->threadObj());
duke@435 1047 jclass jk = (jclass)JNIHandles::make_local(real_thread, Klass::cast(kh())->java_mirror());
duke@435 1048
duke@435 1049 // Before we call the JVMTI agent, we have to set the state in the
duke@435 1050 // thread for which we are proxying.
duke@435 1051 JavaThreadState prev_state = real_thread->thread_state();
duke@435 1052 assert(prev_state == _thread_blocked, "JavaThread should be at safepoint");
duke@435 1053 real_thread->set_thread_state(_thread_in_native);
duke@435 1054
duke@435 1055 jvmtiExtensionEvent callback = env->ext_callbacks()->ClassUnload;
duke@435 1056 if (callback != NULL) {
duke@435 1057 (*callback)(env->jvmti_external(), jni_env, jt, jk);
duke@435 1058 }
duke@435 1059
duke@435 1060 assert(real_thread->thread_state() == _thread_in_native,
duke@435 1061 "JavaThread should be in native");
duke@435 1062 real_thread->set_thread_state(prev_state);
duke@435 1063
duke@435 1064 JNIHandles::destroy_local(jk);
duke@435 1065 JNIHandles::destroy_local(jt);
duke@435 1066 }
duke@435 1067 }
duke@435 1068 }
duke@435 1069 }
duke@435 1070
duke@435 1071
duke@435 1072 void JvmtiExport::post_thread_start(JavaThread *thread) {
duke@435 1073 assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
duke@435 1074
duke@435 1075 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Trg Thread Start event triggered",
duke@435 1076 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1077
duke@435 1078 // do JVMTI thread initialization (if needed)
duke@435 1079 JvmtiEventController::thread_started(thread);
duke@435 1080
duke@435 1081 // Do not post thread start event for hidden java thread.
duke@435 1082 if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) &&
duke@435 1083 !thread->is_hidden_from_external_view()) {
duke@435 1084 JvmtiEnvIterator it;
duke@435 1085 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1086 if (env->is_enabled(JVMTI_EVENT_THREAD_START)) {
duke@435 1087 EVT_TRACE(JVMTI_EVENT_THREAD_START, ("JVMTI [%s] Evt Thread Start event sent",
duke@435 1088 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1089
duke@435 1090 JvmtiThreadEventMark jem(thread);
duke@435 1091 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1092 jvmtiEventThreadStart callback = env->callbacks()->ThreadStart;
duke@435 1093 if (callback != NULL) {
duke@435 1094 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 1095 }
duke@435 1096 }
duke@435 1097 }
duke@435 1098 }
duke@435 1099 }
duke@435 1100
duke@435 1101
duke@435 1102 void JvmtiExport::post_thread_end(JavaThread *thread) {
duke@435 1103 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Trg Thread End event triggered",
duke@435 1104 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1105
duke@435 1106 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1107 if (state == NULL) {
duke@435 1108 return;
duke@435 1109 }
duke@435 1110
duke@435 1111 // Do not post thread end event for hidden java thread.
duke@435 1112 if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
duke@435 1113 !thread->is_hidden_from_external_view()) {
duke@435 1114
duke@435 1115 JvmtiEnvThreadStateIterator it(state);
duke@435 1116 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1117 if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
duke@435 1118 EVT_TRACE(JVMTI_EVENT_THREAD_END, ("JVMTI [%s] Evt Thread End event sent",
duke@435 1119 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1120
duke@435 1121 JvmtiEnv *env = ets->get_env();
duke@435 1122 JvmtiThreadEventMark jem(thread);
duke@435 1123 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1124 jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
duke@435 1125 if (callback != NULL) {
duke@435 1126 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
duke@435 1127 }
duke@435 1128 }
duke@435 1129 }
duke@435 1130 }
duke@435 1131 }
duke@435 1132
duke@435 1133 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
duke@435 1134 assert(SafepointSynchronize::is_at_safepoint(), "must be executed at safepoint");
duke@435 1135 assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
duke@435 1136
duke@435 1137 EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Trg Object Free triggered" ));
duke@435 1138 EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("JVMTI [?] Evt Object Free sent"));
duke@435 1139
duke@435 1140 jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
duke@435 1141 if (callback != NULL) {
duke@435 1142 (*callback)(env->jvmti_external(), tag);
duke@435 1143 }
duke@435 1144 }
duke@435 1145
duke@435 1146 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
duke@435 1147 EVT_TRIG_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Trg resource exhausted event triggered" ));
duke@435 1148
duke@435 1149 JvmtiEnvIterator it;
duke@435 1150 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1151 if (env->is_enabled(JVMTI_EVENT_RESOURCE_EXHAUSTED)) {
duke@435 1152 EVT_TRACE(JVMTI_EVENT_RESOURCE_EXHAUSTED, ("JVMTI Evt resource exhausted event sent" ));
duke@435 1153
duke@435 1154 JavaThread *thread = JavaThread::current();
duke@435 1155 JvmtiThreadEventMark jem(thread);
duke@435 1156 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1157 jvmtiEventResourceExhausted callback = env->callbacks()->ResourceExhausted;
duke@435 1158 if (callback != NULL) {
duke@435 1159 (*callback)(env->jvmti_external(), jem.jni_env(),
duke@435 1160 resource_exhausted_flags, NULL, description);
duke@435 1161 }
duke@435 1162 }
duke@435 1163 }
duke@435 1164 }
duke@435 1165
duke@435 1166 void JvmtiExport::post_method_entry(JavaThread *thread, methodOop method, frame current_frame) {
duke@435 1167 HandleMark hm(thread);
duke@435 1168 methodHandle mh(thread, method);
duke@435 1169
duke@435 1170 EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Trg Method Entry triggered %s.%s",
duke@435 1171 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1172 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1173 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1174
duke@435 1175 JvmtiThreadState* state = thread->jvmti_thread_state();
duke@435 1176 if (state == NULL || !state->is_interp_only_mode()) {
duke@435 1177 // for any thread that actually wants method entry, interp_only_mode is set
duke@435 1178 return;
duke@435 1179 }
duke@435 1180
duke@435 1181 state->incr_cur_stack_depth();
duke@435 1182
duke@435 1183 if (state->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
duke@435 1184 JvmtiEnvThreadStateIterator it(state);
duke@435 1185 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1186 if (ets->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
duke@435 1187 EVT_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("JVMTI [%s] Evt Method Entry sent %s.%s",
duke@435 1188 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1189 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1190 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1191
duke@435 1192 JvmtiEnv *env = ets->get_env();
duke@435 1193 JvmtiMethodEventMark jem(thread, mh);
duke@435 1194 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1195 jvmtiEventMethodEntry callback = env->callbacks()->MethodEntry;
duke@435 1196 if (callback != NULL) {
duke@435 1197 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_methodID());
duke@435 1198 }
duke@435 1199 }
duke@435 1200 }
duke@435 1201 }
duke@435 1202 }
duke@435 1203
duke@435 1204 void JvmtiExport::post_method_exit(JavaThread *thread, methodOop method, frame current_frame) {
duke@435 1205 HandleMark hm(thread);
duke@435 1206 methodHandle mh(thread, method);
duke@435 1207
duke@435 1208 EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Trg Method Exit triggered %s.%s",
duke@435 1209 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1210 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1211 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1212
duke@435 1213 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1214 if (state == NULL || !state->is_interp_only_mode()) {
duke@435 1215 // for any thread that actually wants method exit, interp_only_mode is set
duke@435 1216 return;
duke@435 1217 }
duke@435 1218
duke@435 1219 // return a flag when a method terminates by throwing an exception
duke@435 1220 // i.e. if an exception is thrown and it's not caught by the current method
duke@435 1221 bool exception_exit = state->is_exception_detected() && !state->is_exception_caught();
duke@435 1222
duke@435 1223
duke@435 1224 if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
duke@435 1225 Handle result;
duke@435 1226 jvalue value;
duke@435 1227 value.j = 0L;
duke@435 1228
duke@435 1229 // if the method hasn't been popped because of an exception then we populate
duke@435 1230 // the return_value parameter for the callback. At this point we only have
duke@435 1231 // the address of a "raw result" and we just call into the interpreter to
duke@435 1232 // convert this into a jvalue.
duke@435 1233 if (!exception_exit) {
duke@435 1234 oop oop_result;
duke@435 1235 BasicType type = current_frame.interpreter_frame_result(&oop_result, &value);
duke@435 1236 if (type == T_OBJECT || type == T_ARRAY) {
duke@435 1237 result = Handle(thread, oop_result);
duke@435 1238 }
duke@435 1239 }
duke@435 1240
duke@435 1241 JvmtiEnvThreadStateIterator it(state);
duke@435 1242 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1243 if (ets->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
duke@435 1244 EVT_TRACE(JVMTI_EVENT_METHOD_EXIT, ("JVMTI [%s] Evt Method Exit sent %s.%s",
duke@435 1245 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1246 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1247 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1248
duke@435 1249 JvmtiEnv *env = ets->get_env();
duke@435 1250 JvmtiMethodEventMark jem(thread, mh);
duke@435 1251 if (result.not_null()) {
duke@435 1252 value.l = JNIHandles::make_local(thread, result());
duke@435 1253 }
duke@435 1254 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1255 jvmtiEventMethodExit callback = env->callbacks()->MethodExit;
duke@435 1256 if (callback != NULL) {
duke@435 1257 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1258 jem.jni_methodID(), exception_exit, value);
duke@435 1259 }
duke@435 1260 }
duke@435 1261 }
duke@435 1262 }
duke@435 1263
duke@435 1264 if (state->is_enabled(JVMTI_EVENT_FRAME_POP)) {
duke@435 1265 JvmtiEnvThreadStateIterator it(state);
duke@435 1266 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1267 int cur_frame_number = state->cur_stack_depth();
duke@435 1268
duke@435 1269 if (ets->is_frame_pop(cur_frame_number)) {
duke@435 1270 // we have a NotifyFramePop entry for this frame.
duke@435 1271 // now check that this env/thread wants this event
duke@435 1272 if (ets->is_enabled(JVMTI_EVENT_FRAME_POP)) {
duke@435 1273 EVT_TRACE(JVMTI_EVENT_FRAME_POP, ("JVMTI [%s] Evt Frame Pop sent %s.%s",
duke@435 1274 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1275 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1276 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
duke@435 1277
duke@435 1278 // we also need to issue a frame pop event for this frame
duke@435 1279 JvmtiEnv *env = ets->get_env();
duke@435 1280 JvmtiMethodEventMark jem(thread, mh);
duke@435 1281 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1282 jvmtiEventFramePop callback = env->callbacks()->FramePop;
duke@435 1283 if (callback != NULL) {
duke@435 1284 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1285 jem.jni_methodID(), exception_exit);
duke@435 1286 }
duke@435 1287 }
duke@435 1288 // remove the frame's entry
duke@435 1289 ets->clear_frame_pop(cur_frame_number);
duke@435 1290 }
duke@435 1291 }
duke@435 1292 }
duke@435 1293
duke@435 1294 state->decr_cur_stack_depth();
duke@435 1295 }
duke@435 1296
duke@435 1297
duke@435 1298 // Todo: inline this for optimization
duke@435 1299 void JvmtiExport::post_single_step(JavaThread *thread, methodOop method, address location) {
duke@435 1300 HandleMark hm(thread);
duke@435 1301 methodHandle mh(thread, method);
duke@435 1302
duke@435 1303 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1304 if (state == NULL) {
duke@435 1305 return;
duke@435 1306 }
duke@435 1307 JvmtiEnvThreadStateIterator it(state);
duke@435 1308 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1309 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
duke@435 1310 if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
duke@435 1311 EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Evt Single Step sent %s.%s @ %d",
duke@435 1312 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1313 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1314 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1315 location - mh()->code_base() ));
duke@435 1316
duke@435 1317 JvmtiEnv *env = ets->get_env();
duke@435 1318 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1319 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1320 jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
duke@435 1321 if (callback != NULL) {
duke@435 1322 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1323 jem.jni_methodID(), jem.location());
duke@435 1324 }
duke@435 1325
duke@435 1326 ets->set_single_stepping_posted();
duke@435 1327 }
duke@435 1328 }
duke@435 1329 }
duke@435 1330
duke@435 1331
duke@435 1332 void JvmtiExport::post_exception_throw(JavaThread *thread, methodOop method, address location, oop exception) {
duke@435 1333 HandleMark hm(thread);
duke@435 1334 methodHandle mh(thread, method);
duke@435 1335 Handle exception_handle(thread, exception);
duke@435 1336
duke@435 1337 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1338 if (state == NULL) {
duke@435 1339 return;
duke@435 1340 }
duke@435 1341
duke@435 1342 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("JVMTI [%s] Trg Exception thrown triggered",
duke@435 1343 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1344 if (!state->is_exception_detected()) {
duke@435 1345 state->set_exception_detected();
duke@435 1346 JvmtiEnvThreadStateIterator it(state);
duke@435 1347 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1348 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
duke@435 1349
duke@435 1350 EVT_TRACE(JVMTI_EVENT_EXCEPTION,
duke@435 1351 ("JVMTI [%s] Evt Exception thrown sent %s.%s @ %d",
duke@435 1352 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1353 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1354 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1355 location - mh()->code_base() ));
duke@435 1356
duke@435 1357 JvmtiEnv *env = ets->get_env();
duke@435 1358 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
duke@435 1359
duke@435 1360 // It's okay to clear these exceptions here because we duplicate
duke@435 1361 // this lookup in InterpreterRuntime::exception_handler_for_exception.
duke@435 1362 EXCEPTION_MARK;
duke@435 1363
duke@435 1364 bool should_repeat;
duke@435 1365 vframeStream st(thread);
duke@435 1366 assert(!st.at_end(), "cannot be at end");
duke@435 1367 methodOop current_method = NULL;
duke@435 1368 int current_bci = -1;
duke@435 1369 do {
duke@435 1370 current_method = st.method();
duke@435 1371 current_bci = st.bci();
duke@435 1372 do {
duke@435 1373 should_repeat = false;
duke@435 1374 KlassHandle eh_klass(thread, exception_handle()->klass());
duke@435 1375 current_bci = current_method->fast_exception_handler_bci_for(
duke@435 1376 eh_klass, current_bci, THREAD);
duke@435 1377 if (HAS_PENDING_EXCEPTION) {
duke@435 1378 exception_handle = KlassHandle(thread, PENDING_EXCEPTION);
duke@435 1379 CLEAR_PENDING_EXCEPTION;
duke@435 1380 should_repeat = true;
duke@435 1381 }
duke@435 1382 } while (should_repeat && (current_bci != -1));
duke@435 1383 st.next();
duke@435 1384 } while ((current_bci < 0) && (!st.at_end()));
duke@435 1385
duke@435 1386 jmethodID catch_jmethodID;
duke@435 1387 if (current_bci < 0) {
duke@435 1388 catch_jmethodID = 0;
duke@435 1389 current_bci = 0;
duke@435 1390 } else {
duke@435 1391 catch_jmethodID = jem.to_jmethodID(
duke@435 1392 methodHandle(thread, current_method));
duke@435 1393 }
duke@435 1394
duke@435 1395 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1396 jvmtiEventException callback = env->callbacks()->Exception;
duke@435 1397 if (callback != NULL) {
duke@435 1398 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1399 jem.jni_methodID(), jem.location(),
duke@435 1400 jem.exception(),
duke@435 1401 catch_jmethodID, current_bci);
duke@435 1402 }
duke@435 1403 }
duke@435 1404 }
duke@435 1405 }
duke@435 1406
duke@435 1407 // frames may get popped because of this throw, be safe - invalidate cached depth
duke@435 1408 state->invalidate_cur_stack_depth();
duke@435 1409 }
duke@435 1410
duke@435 1411
duke@435 1412 void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, methodOop method, address location, oop exception, bool in_handler_frame) {
duke@435 1413 HandleMark hm(thread);
duke@435 1414 methodHandle mh(thread, method);
duke@435 1415 Handle exception_handle(thread, exception);
duke@435 1416
duke@435 1417 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1418 if (state == NULL) {
duke@435 1419 return;
duke@435 1420 }
duke@435 1421 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
duke@435 1422 ("JVMTI [%s] Trg unwind_due_to_exception triggered %s.%s @ %s%d - %s",
duke@435 1423 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1424 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1425 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1426 location==0? "no location:" : "",
duke@435 1427 location==0? 0 : location - mh()->code_base(),
duke@435 1428 in_handler_frame? "in handler frame" : "not handler frame" ));
duke@435 1429
duke@435 1430 if (state->is_exception_detected()) {
duke@435 1431
duke@435 1432 state->invalidate_cur_stack_depth();
duke@435 1433 if (!in_handler_frame) {
duke@435 1434 // Not in exception handler.
duke@435 1435 if(state->is_interp_only_mode()) {
duke@435 1436 // method exit and frame pop events are posted only in interp mode.
duke@435 1437 // When these events are enabled code should be in running in interp mode.
duke@435 1438 JvmtiExport::post_method_exit(thread, method, thread->last_frame());
duke@435 1439 // The cached cur_stack_depth might have changed from the
duke@435 1440 // operations of frame pop or method exit. We are not 100% sure
duke@435 1441 // the cached cur_stack_depth is still valid depth so invalidate
duke@435 1442 // it.
duke@435 1443 state->invalidate_cur_stack_depth();
duke@435 1444 }
duke@435 1445 } else {
duke@435 1446 // In exception handler frame. Report exception catch.
duke@435 1447 assert(location != NULL, "must be a known location");
duke@435 1448 // Update cur_stack_depth - the frames above the current frame
duke@435 1449 // have been unwound due to this exception:
duke@435 1450 assert(!state->is_exception_caught(), "exception must not be caught yet.");
duke@435 1451 state->set_exception_caught();
duke@435 1452
duke@435 1453 JvmtiEnvThreadStateIterator it(state);
duke@435 1454 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1455 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION_CATCH) && (exception_handle() != NULL)) {
duke@435 1456 EVT_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
duke@435 1457 ("JVMTI [%s] Evt ExceptionCatch sent %s.%s @ %d",
duke@435 1458 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1459 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1460 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1461 location - mh()->code_base() ));
duke@435 1462
duke@435 1463 JvmtiEnv *env = ets->get_env();
duke@435 1464 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
duke@435 1465 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1466 jvmtiEventExceptionCatch callback = env->callbacks()->ExceptionCatch;
duke@435 1467 if (callback != NULL) {
duke@435 1468 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1469 jem.jni_methodID(), jem.location(),
duke@435 1470 jem.exception());
duke@435 1471 }
duke@435 1472 }
duke@435 1473 }
duke@435 1474 }
duke@435 1475 }
duke@435 1476 }
duke@435 1477
duke@435 1478 oop JvmtiExport::jni_GetField_probe(JavaThread *thread, jobject jobj, oop obj,
duke@435 1479 klassOop klass, jfieldID fieldID, bool is_static) {
duke@435 1480 if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1481 // At least one field access watch is set so we have more work
duke@435 1482 // to do. This wrapper is used by entry points that allow us
duke@435 1483 // to create handles in post_field_access_by_jni().
duke@435 1484 post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
duke@435 1485 // event posting can block so refetch oop if we were passed a jobj
duke@435 1486 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1487 }
duke@435 1488 return obj;
duke@435 1489 }
duke@435 1490
duke@435 1491 oop JvmtiExport::jni_GetField_probe_nh(JavaThread *thread, jobject jobj, oop obj,
duke@435 1492 klassOop klass, jfieldID fieldID, bool is_static) {
duke@435 1493 if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1494 // At least one field access watch is set so we have more work
duke@435 1495 // to do. This wrapper is used by "quick" entry points that don't
duke@435 1496 // allow us to create handles in post_field_access_by_jni(). We
duke@435 1497 // override that with a ResetNoHandleMark.
duke@435 1498 ResetNoHandleMark rnhm;
duke@435 1499 post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
duke@435 1500 // event posting can block so refetch oop if we were passed a jobj
duke@435 1501 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1502 }
duke@435 1503 return obj;
duke@435 1504 }
duke@435 1505
duke@435 1506 void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj,
duke@435 1507 klassOop klass, jfieldID fieldID, bool is_static) {
duke@435 1508 // We must be called with a Java context in order to provide reasonable
duke@435 1509 // values for the klazz, method, and location fields. The callers of this
duke@435 1510 // function don't make the call unless there is a Java context.
duke@435 1511 assert(thread->has_last_Java_frame(), "must be called with a Java context");
duke@435 1512
duke@435 1513 ResourceMark rm;
duke@435 1514 fieldDescriptor fd;
duke@435 1515 // if get_field_descriptor finds fieldID to be invalid, then we just bail
duke@435 1516 bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
duke@435 1517 assert(valid_fieldID == true,"post_field_access_by_jni called with invalid fieldID");
duke@435 1518 if (!valid_fieldID) return;
duke@435 1519 // field accesses are not watched so bail
duke@435 1520 if (!fd.is_field_access_watched()) return;
duke@435 1521
duke@435 1522 HandleMark hm(thread);
duke@435 1523 KlassHandle h_klass(thread, klass);
duke@435 1524 Handle h_obj;
duke@435 1525 if (!is_static) {
duke@435 1526 // non-static field accessors have an object, but we need a handle
duke@435 1527 assert(obj != NULL, "non-static needs an object");
duke@435 1528 h_obj = Handle(thread, obj);
duke@435 1529 }
duke@435 1530 post_field_access(thread,
duke@435 1531 thread->last_frame().interpreter_frame_method(),
duke@435 1532 thread->last_frame().interpreter_frame_bcp(),
duke@435 1533 h_klass, h_obj, fieldID);
duke@435 1534 }
duke@435 1535
duke@435 1536 void JvmtiExport::post_field_access(JavaThread *thread, methodOop method,
duke@435 1537 address location, KlassHandle field_klass, Handle object, jfieldID field) {
duke@435 1538
duke@435 1539 HandleMark hm(thread);
duke@435 1540 methodHandle mh(thread, method);
duke@435 1541
duke@435 1542 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1543 if (state == NULL) {
duke@435 1544 return;
duke@435 1545 }
duke@435 1546 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Trg Field Access event triggered",
duke@435 1547 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1548 JvmtiEnvThreadStateIterator it(state);
duke@435 1549 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1550 if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
duke@435 1551 EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Evt Field Access event sent %s.%s @ %d",
duke@435 1552 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1553 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1554 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1555 location - mh()->code_base() ));
duke@435 1556
duke@435 1557 JvmtiEnv *env = ets->get_env();
duke@435 1558 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1559 jclass field_jclass = jem.to_jclass(field_klass());
duke@435 1560 jobject field_jobject = jem.to_jobject(object());
duke@435 1561 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1562 jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
duke@435 1563 if (callback != NULL) {
duke@435 1564 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1565 jem.jni_methodID(), jem.location(),
duke@435 1566 field_jclass, field_jobject, field);
duke@435 1567 }
duke@435 1568 }
duke@435 1569 }
duke@435 1570 }
duke@435 1571
duke@435 1572 oop JvmtiExport::jni_SetField_probe(JavaThread *thread, jobject jobj, oop obj,
duke@435 1573 klassOop klass, jfieldID fieldID, bool is_static,
duke@435 1574 char sig_type, jvalue *value) {
duke@435 1575 if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1576 // At least one field modification watch is set so we have more work
duke@435 1577 // to do. This wrapper is used by entry points that allow us
duke@435 1578 // to create handles in post_field_modification_by_jni().
duke@435 1579 post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
duke@435 1580 // event posting can block so refetch oop if we were passed a jobj
duke@435 1581 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1582 }
duke@435 1583 return obj;
duke@435 1584 }
duke@435 1585
duke@435 1586 oop JvmtiExport::jni_SetField_probe_nh(JavaThread *thread, jobject jobj, oop obj,
duke@435 1587 klassOop klass, jfieldID fieldID, bool is_static,
duke@435 1588 char sig_type, jvalue *value) {
duke@435 1589 if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
duke@435 1590 // At least one field modification watch is set so we have more work
duke@435 1591 // to do. This wrapper is used by "quick" entry points that don't
duke@435 1592 // allow us to create handles in post_field_modification_by_jni(). We
duke@435 1593 // override that with a ResetNoHandleMark.
duke@435 1594 ResetNoHandleMark rnhm;
duke@435 1595 post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
duke@435 1596 // event posting can block so refetch oop if we were passed a jobj
duke@435 1597 if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
duke@435 1598 }
duke@435 1599 return obj;
duke@435 1600 }
duke@435 1601
duke@435 1602 void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj,
duke@435 1603 klassOop klass, jfieldID fieldID, bool is_static,
duke@435 1604 char sig_type, jvalue *value) {
duke@435 1605 // We must be called with a Java context in order to provide reasonable
duke@435 1606 // values for the klazz, method, and location fields. The callers of this
duke@435 1607 // function don't make the call unless there is a Java context.
duke@435 1608 assert(thread->has_last_Java_frame(), "must be called with Java context");
duke@435 1609
duke@435 1610 ResourceMark rm;
duke@435 1611 fieldDescriptor fd;
duke@435 1612 // if get_field_descriptor finds fieldID to be invalid, then we just bail
duke@435 1613 bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
duke@435 1614 assert(valid_fieldID == true,"post_field_modification_by_jni called with invalid fieldID");
duke@435 1615 if (!valid_fieldID) return;
duke@435 1616 // field modifications are not watched so bail
duke@435 1617 if (!fd.is_field_modification_watched()) return;
duke@435 1618
duke@435 1619 HandleMark hm(thread);
duke@435 1620
duke@435 1621 Handle h_obj;
duke@435 1622 if (!is_static) {
duke@435 1623 // non-static field accessors have an object, but we need a handle
duke@435 1624 assert(obj != NULL, "non-static needs an object");
duke@435 1625 h_obj = Handle(thread, obj);
duke@435 1626 }
duke@435 1627 KlassHandle h_klass(thread, klass);
duke@435 1628 post_field_modification(thread,
duke@435 1629 thread->last_frame().interpreter_frame_method(),
duke@435 1630 thread->last_frame().interpreter_frame_bcp(),
duke@435 1631 h_klass, h_obj, fieldID, sig_type, value);
duke@435 1632 }
duke@435 1633
duke@435 1634 void JvmtiExport::post_raw_field_modification(JavaThread *thread, methodOop method,
duke@435 1635 address location, KlassHandle field_klass, Handle object, jfieldID field,
duke@435 1636 char sig_type, jvalue *value) {
duke@435 1637
duke@435 1638 if (sig_type == 'I' || sig_type == 'Z' || sig_type == 'C' || sig_type == 'S') {
duke@435 1639 // 'I' instructions are used for byte, char, short and int.
duke@435 1640 // determine which it really is, and convert
duke@435 1641 fieldDescriptor fd;
duke@435 1642 bool found = JvmtiEnv::get_field_descriptor(field_klass(), field, &fd);
duke@435 1643 // should be found (if not, leave as is)
duke@435 1644 if (found) {
duke@435 1645 jint ival = value->i;
duke@435 1646 // convert value from int to appropriate type
duke@435 1647 switch (fd.field_type()) {
duke@435 1648 case T_BOOLEAN:
duke@435 1649 sig_type = 'Z';
duke@435 1650 value->i = 0; // clear it
duke@435 1651 value->z = (jboolean)ival;
duke@435 1652 break;
duke@435 1653 case T_BYTE:
duke@435 1654 sig_type = 'B';
duke@435 1655 value->i = 0; // clear it
duke@435 1656 value->b = (jbyte)ival;
duke@435 1657 break;
duke@435 1658 case T_CHAR:
duke@435 1659 sig_type = 'C';
duke@435 1660 value->i = 0; // clear it
duke@435 1661 value->c = (jchar)ival;
duke@435 1662 break;
duke@435 1663 case T_SHORT:
duke@435 1664 sig_type = 'S';
duke@435 1665 value->i = 0; // clear it
duke@435 1666 value->s = (jshort)ival;
duke@435 1667 break;
duke@435 1668 case T_INT:
duke@435 1669 // nothing to do
duke@435 1670 break;
duke@435 1671 default:
duke@435 1672 // this is an integer instruction, should be one of above
duke@435 1673 ShouldNotReachHere();
duke@435 1674 break;
duke@435 1675 }
duke@435 1676 }
duke@435 1677 }
duke@435 1678
duke@435 1679 // convert oop to JNI handle.
duke@435 1680 if (sig_type == 'L' || sig_type == '[') {
duke@435 1681 value->l = (jobject)JNIHandles::make_local(thread, (oop)value->l);
duke@435 1682 }
duke@435 1683
duke@435 1684 post_field_modification(thread, method, location, field_klass, object, field, sig_type, value);
duke@435 1685
duke@435 1686 // Destroy the JNI handle allocated above.
duke@435 1687 if (sig_type == 'L') {
duke@435 1688 JNIHandles::destroy_local(value->l);
duke@435 1689 }
duke@435 1690 }
duke@435 1691
duke@435 1692 void JvmtiExport::post_field_modification(JavaThread *thread, methodOop method,
duke@435 1693 address location, KlassHandle field_klass, Handle object, jfieldID field,
duke@435 1694 char sig_type, jvalue *value_ptr) {
duke@435 1695
duke@435 1696 HandleMark hm(thread);
duke@435 1697 methodHandle mh(thread, method);
duke@435 1698
duke@435 1699 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 1700 if (state == NULL) {
duke@435 1701 return;
duke@435 1702 }
duke@435 1703 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
duke@435 1704 ("JVMTI [%s] Trg Field Modification event triggered",
duke@435 1705 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1706
duke@435 1707 JvmtiEnvThreadStateIterator it(state);
duke@435 1708 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 1709 if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
duke@435 1710 EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
duke@435 1711 ("JVMTI [%s] Evt Field Modification event sent %s.%s @ %d",
duke@435 1712 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1713 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
duke@435 1714 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
duke@435 1715 location - mh()->code_base() ));
duke@435 1716
duke@435 1717 JvmtiEnv *env = ets->get_env();
duke@435 1718 JvmtiLocationEventMark jem(thread, mh, location);
duke@435 1719 jclass field_jclass = jem.to_jclass(field_klass());
duke@435 1720 jobject field_jobject = jem.to_jobject(object());
duke@435 1721 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1722 jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
duke@435 1723 if (callback != NULL) {
duke@435 1724 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 1725 jem.jni_methodID(), jem.location(),
duke@435 1726 field_jclass, field_jobject, field, sig_type, *value_ptr);
duke@435 1727 }
duke@435 1728 }
duke@435 1729 }
duke@435 1730 }
duke@435 1731
duke@435 1732 void JvmtiExport::post_native_method_bind(methodOop method, address* function_ptr) {
duke@435 1733 JavaThread* thread = JavaThread::current();
duke@435 1734 assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
duke@435 1735
duke@435 1736 HandleMark hm(thread);
duke@435 1737 methodHandle mh(thread, method);
duke@435 1738
duke@435 1739 EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Trg Native Method Bind event triggered",
duke@435 1740 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1741
duke@435 1742 if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
duke@435 1743 JvmtiEnvIterator it;
duke@435 1744 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1745 if (env->is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
duke@435 1746 EVT_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("JVMTI [%s] Evt Native Method Bind event sent",
duke@435 1747 JvmtiTrace::safe_get_thread_name(thread) ));
duke@435 1748
duke@435 1749 JvmtiMethodEventMark jem(thread, mh);
duke@435 1750 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1751 JNIEnv* jni_env = JvmtiEnv::get_phase() == JVMTI_PHASE_PRIMORDIAL? NULL : jem.jni_env();
duke@435 1752 jvmtiEventNativeMethodBind callback = env->callbacks()->NativeMethodBind;
duke@435 1753 if (callback != NULL) {
duke@435 1754 (*callback)(env->jvmti_external(), jni_env, jem.jni_thread(),
duke@435 1755 jem.jni_methodID(), (void*)(*function_ptr), (void**)function_ptr);
duke@435 1756 }
duke@435 1757 }
duke@435 1758 }
duke@435 1759 }
duke@435 1760 }
duke@435 1761
dcubed@1619 1762 // Returns a record containing inlining information for the given nmethod
dcubed@1619 1763 jvmtiCompiledMethodLoadInlineRecord* create_inline_record(nmethod* nm) {
dcubed@1619 1764 jint numstackframes = 0;
dcubed@1619 1765 jvmtiCompiledMethodLoadInlineRecord* record = (jvmtiCompiledMethodLoadInlineRecord*)NEW_RESOURCE_OBJ(jvmtiCompiledMethodLoadInlineRecord);
dcubed@1619 1766 record->header.kind = JVMTI_CMLR_INLINE_INFO;
dcubed@1619 1767 record->header.next = NULL;
dcubed@1619 1768 record->header.majorinfoversion = JVMTI_CMLR_MAJOR_VERSION_1;
dcubed@1619 1769 record->header.minorinfoversion = JVMTI_CMLR_MINOR_VERSION_0;
dcubed@1619 1770 record->numpcs = 0;
dcubed@1619 1771 for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) {
dcubed@1619 1772 if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue;
dcubed@1619 1773 record->numpcs++;
dcubed@1619 1774 }
dcubed@1619 1775 record->pcinfo = (PCStackInfo*)(NEW_RESOURCE_ARRAY(PCStackInfo, record->numpcs));
dcubed@1619 1776 int scope = 0;
dcubed@1619 1777 for(PcDesc* p = nm->scopes_pcs_begin(); p < nm->scopes_pcs_end(); p++) {
dcubed@1619 1778 if(p->scope_decode_offset() == DebugInformationRecorder::serialized_null) continue;
dcubed@1619 1779 void* pc_address = (void*)p->real_pc(nm);
dcubed@1619 1780 assert(pc_address != NULL, "pc_address must be non-null");
dcubed@1619 1781 record->pcinfo[scope].pc = pc_address;
dcubed@1619 1782 numstackframes=0;
dcubed@1619 1783 for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) {
dcubed@1619 1784 numstackframes++;
dcubed@1619 1785 }
dcubed@1619 1786 assert(numstackframes != 0, "numstackframes must be nonzero.");
dcubed@1619 1787 record->pcinfo[scope].methods = (jmethodID *)NEW_RESOURCE_ARRAY(jmethodID, numstackframes);
dcubed@1619 1788 record->pcinfo[scope].bcis = (jint *)NEW_RESOURCE_ARRAY(jint, numstackframes);
dcubed@1619 1789 record->pcinfo[scope].numstackframes = numstackframes;
dcubed@1619 1790 int stackframe = 0;
dcubed@1619 1791 for(ScopeDesc* sd = nm->scope_desc_at(p->real_pc(nm));sd != NULL;sd = sd->sender()) {
dcubed@1619 1792 // 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 1793 assert(!sd->method().is_null(), "sd->method() cannot be null.");
dcubed@1619 1794 record->pcinfo[scope].methods[stackframe] = sd->method()->jmethod_id();
dcubed@1619 1795 record->pcinfo[scope].bcis[stackframe] = sd->bci();
dcubed@1619 1796 stackframe++;
dcubed@1619 1797 }
dcubed@1619 1798 scope++;
dcubed@1619 1799 }
dcubed@1619 1800 return record;
dcubed@1619 1801 }
duke@435 1802
duke@435 1803 void JvmtiExport::post_compiled_method_load(nmethod *nm) {
duke@435 1804 // If there are pending CompiledMethodUnload events then these are
duke@435 1805 // posted before this CompiledMethodLoad event. We "lock" the nmethod and
duke@435 1806 // maintain a handle to the methodOop to ensure that the nmethod isn't
duke@435 1807 // flushed or unloaded while posting the events.
duke@435 1808 JavaThread* thread = JavaThread::current();
duke@435 1809 if (have_pending_compiled_method_unload_events()) {
duke@435 1810 methodHandle mh(thread, nm->method());
duke@435 1811 nmethodLocker nml(nm);
duke@435 1812 post_pending_compiled_method_unload_events();
duke@435 1813 }
duke@435 1814
duke@435 1815 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1816 ("JVMTI [%s] method compile load event triggered",
duke@435 1817 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1818
duke@435 1819 JvmtiEnvIterator it;
duke@435 1820 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1821 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
duke@435 1822
duke@435 1823 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1824 ("JVMTI [%s] class compile method load event sent %s.%s ",
duke@435 1825 JvmtiTrace::safe_get_thread_name(thread),
duke@435 1826 (nm->method() == NULL) ? "NULL" : nm->method()->klass_name()->as_C_string(),
duke@435 1827 (nm->method() == NULL) ? "NULL" : nm->method()->name()->as_C_string()));
duke@435 1828
duke@435 1829 ResourceMark rm(thread);
dcubed@1619 1830
dcubed@1619 1831 // Add inlining information
dcubed@1619 1832 jvmtiCompiledMethodLoadInlineRecord* inlinerecord = create_inline_record(nm);
dcubed@1619 1833 // Pass inlining information through the void pointer
dcubed@1619 1834 JvmtiCompiledMethodLoadEventMark jem(thread, nm, inlinerecord);
duke@435 1835 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1836 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
duke@435 1837 if (callback != NULL) {
duke@435 1838 (*callback)(env->jvmti_external(), jem.jni_methodID(),
duke@435 1839 jem.code_size(), jem.code_data(), jem.map_length(),
duke@435 1840 jem.map(), jem.compile_info());
duke@435 1841 }
duke@435 1842 }
duke@435 1843 }
duke@435 1844 }
duke@435 1845
duke@435 1846
duke@435 1847 // post a COMPILED_METHOD_LOAD event for a given environment
duke@435 1848 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
duke@435 1849 const void *code_begin, const jint map_length,
duke@435 1850 const jvmtiAddrLocationMap* map)
duke@435 1851 {
duke@435 1852 JavaThread* thread = JavaThread::current();
duke@435 1853 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1854 ("JVMTI [%s] method compile load event triggered (by GenerateEvents)",
duke@435 1855 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1856 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
duke@435 1857
duke@435 1858 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
duke@435 1859 ("JVMTI [%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT,
duke@435 1860 JvmtiTrace::safe_get_thread_name(thread), method));
duke@435 1861
duke@435 1862 JvmtiEventMark jem(thread);
duke@435 1863 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1864 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
duke@435 1865 if (callback != NULL) {
duke@435 1866 (*callback)(env->jvmti_external(), method,
duke@435 1867 length, code_begin, map_length,
duke@435 1868 map, NULL);
duke@435 1869 }
duke@435 1870 }
duke@435 1871 }
duke@435 1872
duke@435 1873 // used at a safepoint to post a CompiledMethodUnload event
never@1932 1874 void JvmtiExport::post_compiled_method_unload(jmethodID mid, const void *code_begin) {
never@1932 1875 if (SafepointSynchronize::is_at_safepoint()) {
never@1932 1876 // Class unloading can cause nmethod unloading which is reported
never@1932 1877 // by the VMThread. These must be batched to be processed later.
never@1932 1878 if (_pending_compiled_method_unload_method_ids == NULL) {
never@1932 1879 // create list lazily
never@1932 1880 _pending_compiled_method_unload_method_ids = new (ResourceObj::C_HEAP) GrowableArray<jmethodID>(10,true);
never@1932 1881 _pending_compiled_method_unload_code_begins = new (ResourceObj::C_HEAP) GrowableArray<const void *>(10,true);
never@1932 1882 }
never@1932 1883 _pending_compiled_method_unload_method_ids->append(mid);
never@1932 1884 _pending_compiled_method_unload_code_begins->append(code_begin);
never@1932 1885 _have_pending_compiled_method_unload_events = true;
never@1932 1886 } else {
never@1932 1887 // Unloading caused by the sweeper can be reported synchronously.
never@1932 1888 if (have_pending_compiled_method_unload_events()) {
never@1932 1889 post_pending_compiled_method_unload_events();
never@1932 1890 }
never@1932 1891 post_compiled_method_unload_internal(JavaThread::current(), mid, code_begin);
duke@435 1892 }
duke@435 1893 }
duke@435 1894
duke@435 1895 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
duke@435 1896 JavaThread* thread = JavaThread::current();
duke@435 1897 EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1898 ("JVMTI [%s] method dynamic code generated event triggered",
duke@435 1899 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1900 JvmtiEnvIterator it;
duke@435 1901 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 1902 if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
duke@435 1903 EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1904 ("JVMTI [%s] dynamic code generated event sent for %s",
duke@435 1905 JvmtiTrace::safe_get_thread_name(thread), name));
duke@435 1906 JvmtiEventMark jem(thread);
duke@435 1907 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1908 jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
duke@435 1909 jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
duke@435 1910 if (callback != NULL) {
duke@435 1911 (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
duke@435 1912 }
duke@435 1913 }
duke@435 1914 }
duke@435 1915 }
duke@435 1916
duke@435 1917 void JvmtiExport::post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) {
duke@435 1918 // In theory everyone coming thru here is in_vm but we need to be certain
duke@435 1919 // because a callee will do a vm->native transition
duke@435 1920 ThreadInVMfromUnknown __tiv;
duke@435 1921 jvmtiPhase phase = JvmtiEnv::get_phase();
duke@435 1922 if (phase == JVMTI_PHASE_PRIMORDIAL || phase == JVMTI_PHASE_START) {
duke@435 1923 post_dynamic_code_generated_internal(name, code_begin, code_end);
duke@435 1924 return;
duke@435 1925 }
duke@435 1926
duke@435 1927 if (have_pending_compiled_method_unload_events()) {
duke@435 1928 post_pending_compiled_method_unload_events();
duke@435 1929 }
duke@435 1930 post_dynamic_code_generated_internal(name, code_begin, code_end);
duke@435 1931 }
duke@435 1932
duke@435 1933
duke@435 1934 // post a DYNAMIC_CODE_GENERATED event for a given environment
duke@435 1935 // used by GenerateEvents
duke@435 1936 void JvmtiExport::post_dynamic_code_generated(JvmtiEnv* env, const char *name,
duke@435 1937 const void *code_begin, const void *code_end)
duke@435 1938 {
duke@435 1939 JavaThread* thread = JavaThread::current();
duke@435 1940 EVT_TRIG_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1941 ("JVMTI [%s] dynamic code generated event triggered (by GenerateEvents)",
duke@435 1942 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 1943 if (env->is_enabled(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)) {
duke@435 1944 EVT_TRACE(JVMTI_EVENT_DYNAMIC_CODE_GENERATED,
duke@435 1945 ("JVMTI [%s] dynamic code generated event sent for %s",
duke@435 1946 JvmtiTrace::safe_get_thread_name(thread), name));
duke@435 1947 JvmtiEventMark jem(thread);
duke@435 1948 JvmtiJavaThreadEventTransition jet(thread);
duke@435 1949 jint length = (jint)pointer_delta(code_end, code_begin, sizeof(char));
duke@435 1950 jvmtiEventDynamicCodeGenerated callback = env->callbacks()->DynamicCodeGenerated;
duke@435 1951 if (callback != NULL) {
duke@435 1952 (*callback)(env->jvmti_external(), name, (void*)code_begin, length);
duke@435 1953 }
duke@435 1954 }
duke@435 1955 }
duke@435 1956
duke@435 1957 // post a DynamicCodeGenerated event while holding locks in the VM.
duke@435 1958 void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* name,
duke@435 1959 address code_begin, address code_end)
duke@435 1960 {
duke@435 1961 // register the stub with the current dynamic code event collector
duke@435 1962 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
dcubed@1044 1963 // state can only be NULL if the current thread is exiting which
dcubed@1044 1964 // should not happen since we're trying to post an event
dcubed@1044 1965 guarantee(state != NULL, "attempt to register stub via an exiting thread");
duke@435 1966 JvmtiDynamicCodeEventCollector* collector = state->get_dynamic_code_event_collector();
duke@435 1967 guarantee(collector != NULL, "attempt to register stub without event collector");
duke@435 1968 collector->register_stub(name, code_begin, code_end);
duke@435 1969 }
duke@435 1970
duke@435 1971 // Collect all the vm internally allocated objects which are visible to java world
duke@435 1972 void JvmtiExport::record_vm_internal_object_allocation(oop obj) {
duke@435 1973 Thread* thread = ThreadLocalStorage::thread();
duke@435 1974 if (thread != NULL && thread->is_Java_thread()) {
duke@435 1975 // Can not take safepoint here.
duke@435 1976 No_Safepoint_Verifier no_sfpt;
duke@435 1977 // Can not take safepoint here so can not use state_for to get
duke@435 1978 // jvmti thread state.
duke@435 1979 JvmtiThreadState *state = ((JavaThread*)thread)->jvmti_thread_state();
duke@435 1980 if (state != NULL ) {
duke@435 1981 // state is non NULL when VMObjectAllocEventCollector is enabled.
duke@435 1982 JvmtiVMObjectAllocEventCollector *collector;
duke@435 1983 collector = state->get_vm_object_alloc_event_collector();
duke@435 1984 if (collector != NULL && collector->is_enabled()) {
duke@435 1985 // Don't record classes as these will be notified via the ClassLoad
duke@435 1986 // event.
never@1577 1987 if (obj->klass() != SystemDictionary::Class_klass()) {
duke@435 1988 collector->record_allocation(obj);
duke@435 1989 }
duke@435 1990 }
duke@435 1991 }
duke@435 1992 }
duke@435 1993 }
duke@435 1994
duke@435 1995 void JvmtiExport::post_garbage_collection_finish() {
duke@435 1996 Thread *thread = Thread::current(); // this event is posted from VM-Thread.
duke@435 1997 EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,
duke@435 1998 ("JVMTI [%s] garbage collection finish event triggered",
duke@435 1999 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2000 JvmtiEnvIterator it;
duke@435 2001 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 2002 if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH)) {
duke@435 2003 EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH,
duke@435 2004 ("JVMTI [%s] garbage collection finish event sent ",
duke@435 2005 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2006 JvmtiThreadEventTransition jet(thread);
duke@435 2007 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 2008 jvmtiEventGarbageCollectionFinish callback = env->callbacks()->GarbageCollectionFinish;
duke@435 2009 if (callback != NULL) {
duke@435 2010 (*callback)(env->jvmti_external());
duke@435 2011 }
duke@435 2012 }
duke@435 2013 }
duke@435 2014 }
duke@435 2015
duke@435 2016 void JvmtiExport::post_garbage_collection_start() {
duke@435 2017 Thread* thread = Thread::current(); // this event is posted from vm-thread.
duke@435 2018 EVT_TRIG_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START,
duke@435 2019 ("JVMTI [%s] garbage collection start event triggered",
duke@435 2020 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2021 JvmtiEnvIterator it;
duke@435 2022 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 2023 if (env->is_enabled(JVMTI_EVENT_GARBAGE_COLLECTION_START)) {
duke@435 2024 EVT_TRACE(JVMTI_EVENT_GARBAGE_COLLECTION_START,
duke@435 2025 ("JVMTI [%s] garbage collection start event sent ",
duke@435 2026 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2027 JvmtiThreadEventTransition jet(thread);
duke@435 2028 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 2029 jvmtiEventGarbageCollectionStart callback = env->callbacks()->GarbageCollectionStart;
duke@435 2030 if (callback != NULL) {
duke@435 2031 (*callback)(env->jvmti_external());
duke@435 2032 }
duke@435 2033 }
duke@435 2034 }
duke@435 2035 }
duke@435 2036
duke@435 2037 void JvmtiExport::post_data_dump() {
duke@435 2038 Thread *thread = Thread::current();
duke@435 2039 EVT_TRIG_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
duke@435 2040 ("JVMTI [%s] data dump request event triggered",
duke@435 2041 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2042 JvmtiEnvIterator it;
duke@435 2043 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 2044 if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
duke@435 2045 EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
duke@435 2046 ("JVMTI [%s] data dump request event sent ",
duke@435 2047 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2048 JvmtiThreadEventTransition jet(thread);
duke@435 2049 // JNIEnv is NULL here because this event is posted from VM Thread
duke@435 2050 jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
duke@435 2051 if (callback != NULL) {
duke@435 2052 (*callback)(env->jvmti_external());
duke@435 2053 }
duke@435 2054 }
duke@435 2055 }
duke@435 2056 }
duke@435 2057
duke@435 2058 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
duke@435 2059 oop object = (oop)obj_mntr->object();
duke@435 2060 if (!ServiceUtil::visible_oop(object)) {
duke@435 2061 // Ignore monitor contended enter for vm internal object.
duke@435 2062 return;
duke@435 2063 }
duke@435 2064 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2065 if (state == NULL) {
duke@435 2066 return;
duke@435 2067 }
duke@435 2068
duke@435 2069 HandleMark hm(thread);
duke@435 2070 Handle h(thread, object);
duke@435 2071
duke@435 2072 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
duke@435 2073 ("JVMTI [%s] montior contended enter event triggered",
duke@435 2074 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2075
duke@435 2076 JvmtiEnvThreadStateIterator it(state);
duke@435 2077 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2078 if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
duke@435 2079 EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
duke@435 2080 ("JVMTI [%s] monitor contended enter event sent",
duke@435 2081 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2082 JvmtiMonitorEventMark jem(thread, h());
duke@435 2083 JvmtiEnv *env = ets->get_env();
duke@435 2084 JvmtiThreadEventTransition jet(thread);
duke@435 2085 jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
duke@435 2086 if (callback != NULL) {
duke@435 2087 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
duke@435 2088 }
duke@435 2089 }
duke@435 2090 }
duke@435 2091 }
duke@435 2092
duke@435 2093 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
duke@435 2094 oop object = (oop)obj_mntr->object();
duke@435 2095 if (!ServiceUtil::visible_oop(object)) {
duke@435 2096 // Ignore monitor contended entered for vm internal object.
duke@435 2097 return;
duke@435 2098 }
duke@435 2099 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2100 if (state == NULL) {
duke@435 2101 return;
duke@435 2102 }
duke@435 2103
duke@435 2104 HandleMark hm(thread);
duke@435 2105 Handle h(thread, object);
duke@435 2106
duke@435 2107 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
duke@435 2108 ("JVMTI [%s] montior contended entered event triggered",
duke@435 2109 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2110
duke@435 2111 JvmtiEnvThreadStateIterator it(state);
duke@435 2112 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2113 if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
duke@435 2114 EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
duke@435 2115 ("JVMTI [%s] monitor contended enter event sent",
duke@435 2116 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2117 JvmtiMonitorEventMark jem(thread, h());
duke@435 2118 JvmtiEnv *env = ets->get_env();
duke@435 2119 JvmtiThreadEventTransition jet(thread);
duke@435 2120 jvmtiEventMonitorContendedEntered callback = env->callbacks()->MonitorContendedEntered;
duke@435 2121 if (callback != NULL) {
duke@435 2122 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
duke@435 2123 }
duke@435 2124 }
duke@435 2125 }
duke@435 2126 }
duke@435 2127
duke@435 2128 void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
duke@435 2129 jlong timeout) {
duke@435 2130 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2131 if (state == NULL) {
duke@435 2132 return;
duke@435 2133 }
duke@435 2134
duke@435 2135 HandleMark hm(thread);
duke@435 2136 Handle h(thread, object);
duke@435 2137
duke@435 2138 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAIT,
duke@435 2139 ("JVMTI [%s] montior wait event triggered",
duke@435 2140 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2141
duke@435 2142 JvmtiEnvThreadStateIterator it(state);
duke@435 2143 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2144 if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
duke@435 2145 EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
duke@435 2146 ("JVMTI [%s] monitor wait event sent ",
duke@435 2147 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2148 JvmtiMonitorEventMark jem(thread, h());
duke@435 2149 JvmtiEnv *env = ets->get_env();
duke@435 2150 JvmtiThreadEventTransition jet(thread);
duke@435 2151 jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
duke@435 2152 if (callback != NULL) {
duke@435 2153 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2154 jem.jni_object(), timeout);
duke@435 2155 }
duke@435 2156 }
duke@435 2157 }
duke@435 2158 }
duke@435 2159
duke@435 2160 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
duke@435 2161 oop object = (oop)obj_mntr->object();
duke@435 2162 if (!ServiceUtil::visible_oop(object)) {
duke@435 2163 // Ignore monitor waited for vm internal object.
duke@435 2164 return;
duke@435 2165 }
duke@435 2166 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 2167 if (state == NULL) {
duke@435 2168 return;
duke@435 2169 }
duke@435 2170
duke@435 2171 HandleMark hm(thread);
duke@435 2172 Handle h(thread, object);
duke@435 2173
duke@435 2174 EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
duke@435 2175 ("JVMTI [%s] montior waited event triggered",
duke@435 2176 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2177
duke@435 2178 JvmtiEnvThreadStateIterator it(state);
duke@435 2179 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 2180 if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
duke@435 2181 EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
duke@435 2182 ("JVMTI [%s] monitor waited event sent ",
duke@435 2183 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2184 JvmtiMonitorEventMark jem(thread, h());
duke@435 2185 JvmtiEnv *env = ets->get_env();
duke@435 2186 JvmtiThreadEventTransition jet(thread);
duke@435 2187 jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
duke@435 2188 if (callback != NULL) {
duke@435 2189 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2190 jem.jni_object(), timed_out);
duke@435 2191 }
duke@435 2192 }
duke@435 2193 }
duke@435 2194 }
duke@435 2195
duke@435 2196
duke@435 2197 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
duke@435 2198 EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Trg vm object alloc triggered",
duke@435 2199 JvmtiTrace::safe_get_thread_name(thread)));
duke@435 2200 if (object == NULL) {
duke@435 2201 return;
duke@435 2202 }
duke@435 2203 HandleMark hm(thread);
duke@435 2204 Handle h(thread, object);
duke@435 2205 JvmtiEnvIterator it;
duke@435 2206 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 2207 if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
duke@435 2208 EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("JVMTI [%s] Evt vmobject alloc sent %s",
duke@435 2209 JvmtiTrace::safe_get_thread_name(thread),
duke@435 2210 object==NULL? "NULL" : Klass::cast(java_lang_Class::as_klassOop(object))->external_name()));
duke@435 2211
duke@435 2212 JvmtiVMObjectAllocEventMark jem(thread, h());
duke@435 2213 JvmtiJavaThreadEventTransition jet(thread);
duke@435 2214 jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
duke@435 2215 if (callback != NULL) {
duke@435 2216 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
duke@435 2217 jem.jni_jobject(), jem.jni_class(), jem.size());
duke@435 2218 }
duke@435 2219 }
duke@435 2220 }
duke@435 2221 }
duke@435 2222
duke@435 2223 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2224
duke@435 2225 void JvmtiExport::cleanup_thread(JavaThread* thread) {
duke@435 2226 assert(JavaThread::current() == thread, "thread is not current");
duke@435 2227
duke@435 2228
duke@435 2229 // This has to happen after the thread state is removed, which is
duke@435 2230 // why it is not in post_thread_end_event like its complement
duke@435 2231 // Maybe both these functions should be rolled into the posts?
duke@435 2232 JvmtiEventController::thread_ended(thread);
duke@435 2233 }
duke@435 2234
duke@435 2235 void JvmtiExport::oops_do(OopClosure* f) {
duke@435 2236 JvmtiCurrentBreakpoints::oops_do(f);
duke@435 2237 JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(f);
duke@435 2238 }
duke@435 2239
duke@435 2240 // Onload raw monitor transition.
duke@435 2241 void JvmtiExport::transition_pending_onload_raw_monitors() {
duke@435 2242 JvmtiPendingMonitors::transition_raw_monitors();
duke@435 2243 }
duke@435 2244
duke@435 2245 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2246
duke@435 2247 // type for the Agent_OnAttach entry point
duke@435 2248 extern "C" {
duke@435 2249 typedef jint (JNICALL *OnAttachEntry_t)(JavaVM*, char *, void *);
duke@435 2250 }
duke@435 2251
duke@435 2252 #ifndef SERVICES_KERNEL
duke@435 2253 jint JvmtiExport::load_agent_library(AttachOperation* op, outputStream* st) {
duke@435 2254 char ebuf[1024];
duke@435 2255 char buffer[JVM_MAXPATHLEN];
duke@435 2256 void* library;
duke@435 2257 jint result = JNI_ERR;
duke@435 2258
duke@435 2259 // get agent name and options
duke@435 2260 const char* agent = op->arg(0);
duke@435 2261 const char* absParam = op->arg(1);
duke@435 2262 const char* options = op->arg(2);
duke@435 2263
duke@435 2264 // The abs paramter should be "true" or "false"
duke@435 2265 bool is_absolute_path = (absParam != NULL) && (strcmp(absParam,"true")==0);
duke@435 2266
duke@435 2267
duke@435 2268 // If the path is absolute we attempt to load the library. Otherwise we try to
duke@435 2269 // load it from the standard dll directory.
duke@435 2270
duke@435 2271 if (is_absolute_path) {
duke@435 2272 library = hpi::dll_load(agent, ebuf, sizeof ebuf);
duke@435 2273 } else {
duke@435 2274 // Try to load the agent from the standard dll directory
duke@435 2275 hpi::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), agent);
duke@435 2276 library = hpi::dll_load(buffer, ebuf, sizeof ebuf);
duke@435 2277 if (library == NULL) {
duke@435 2278 // not found - try local path
duke@435 2279 char ns[1] = {0};
duke@435 2280 hpi::dll_build_name(buffer, sizeof(buffer), ns, agent);
duke@435 2281 library = hpi::dll_load(buffer, ebuf, sizeof ebuf);
duke@435 2282 }
duke@435 2283 }
duke@435 2284
duke@435 2285 // If the library was loaded then we attempt to invoke the Agent_OnAttach
duke@435 2286 // function
duke@435 2287 if (library != NULL) {
duke@435 2288
duke@435 2289 // Lookup the Agent_OnAttach function
duke@435 2290 OnAttachEntry_t on_attach_entry = NULL;
duke@435 2291 const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS;
duke@435 2292 for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_attach_symbols); symbol_index++) {
duke@435 2293 on_attach_entry =
duke@435 2294 CAST_TO_FN_PTR(OnAttachEntry_t, hpi::dll_lookup(library, on_attach_symbols[symbol_index]));
duke@435 2295 if (on_attach_entry != NULL) break;
duke@435 2296 }
duke@435 2297
duke@435 2298 if (on_attach_entry == NULL) {
duke@435 2299 // Agent_OnAttach missing - unload library
duke@435 2300 hpi::dll_unload(library);
duke@435 2301 } else {
duke@435 2302 // Invoke the Agent_OnAttach function
duke@435 2303 JavaThread* THREAD = JavaThread::current();
duke@435 2304 {
duke@435 2305 extern struct JavaVM_ main_vm;
duke@435 2306 JvmtiThreadEventMark jem(THREAD);
duke@435 2307 JvmtiJavaThreadEventTransition jet(THREAD);
duke@435 2308
duke@435 2309 result = (*on_attach_entry)(&main_vm, (char*)options, NULL);
duke@435 2310 }
duke@435 2311
duke@435 2312 // Agent_OnAttach may have used JNI
duke@435 2313 if (HAS_PENDING_EXCEPTION) {
duke@435 2314 CLEAR_PENDING_EXCEPTION;
duke@435 2315 }
duke@435 2316
duke@435 2317 // If OnAttach returns JNI_OK then we add it to the list of
duke@435 2318 // agent libraries so that we can call Agent_OnUnload later.
duke@435 2319 if (result == JNI_OK) {
duke@435 2320 Arguments::add_loaded_agent(agent, (char*)options, is_absolute_path, library);
duke@435 2321 }
duke@435 2322
duke@435 2323 // Agent_OnAttach executed so completion status is JNI_OK
duke@435 2324 st->print_cr("%d", result);
duke@435 2325 result = JNI_OK;
duke@435 2326 }
duke@435 2327 }
duke@435 2328 return result;
duke@435 2329 }
duke@435 2330 #endif // SERVICES_KERNEL
duke@435 2331
duke@435 2332 // CMS has completed referencing processing so may need to update
duke@435 2333 // tag maps.
duke@435 2334 void JvmtiExport::cms_ref_processing_epilogue() {
duke@435 2335 if (JvmtiEnv::environments_might_exist()) {
duke@435 2336 JvmtiTagMap::cms_ref_processing_epilogue();
duke@435 2337 }
duke@435 2338 }
duke@435 2339
duke@435 2340
duke@435 2341 ////////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2342
duke@435 2343 // Setup current current thread for event collection.
duke@435 2344 void JvmtiEventCollector::setup_jvmti_thread_state() {
duke@435 2345 // set this event collector to be the current one.
duke@435 2346 JvmtiThreadState* state = JvmtiThreadState::state_for(JavaThread::current());
dcubed@1044 2347 // state can only be NULL if the current thread is exiting which
dcubed@1044 2348 // should not happen since we're trying to configure for event collection
dcubed@1044 2349 guarantee(state != NULL, "exiting thread called setup_jvmti_thread_state");
duke@435 2350 if (is_vm_object_alloc_event()) {
duke@435 2351 _prev = state->get_vm_object_alloc_event_collector();
duke@435 2352 state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)this);
duke@435 2353 } else if (is_dynamic_code_event()) {
duke@435 2354 _prev = state->get_dynamic_code_event_collector();
duke@435 2355 state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)this);
duke@435 2356 }
duke@435 2357 }
duke@435 2358
duke@435 2359 // Unset current event collection in this thread and reset it with previous
duke@435 2360 // collector.
duke@435 2361 void JvmtiEventCollector::unset_jvmti_thread_state() {
duke@435 2362 JvmtiThreadState* state = JavaThread::current()->jvmti_thread_state();
duke@435 2363 if (state != NULL) {
duke@435 2364 // restore the previous event collector (if any)
duke@435 2365 if (is_vm_object_alloc_event()) {
duke@435 2366 if (state->get_vm_object_alloc_event_collector() == this) {
duke@435 2367 state->set_vm_object_alloc_event_collector((JvmtiVMObjectAllocEventCollector *)_prev);
duke@435 2368 } else {
duke@435 2369 // this thread's jvmti state was created during the scope of
duke@435 2370 // the event collector.
duke@435 2371 }
duke@435 2372 } else {
duke@435 2373 if (is_dynamic_code_event()) {
duke@435 2374 if (state->get_dynamic_code_event_collector() == this) {
duke@435 2375 state->set_dynamic_code_event_collector((JvmtiDynamicCodeEventCollector *)_prev);
duke@435 2376 } else {
duke@435 2377 // this thread's jvmti state was created during the scope of
duke@435 2378 // the event collector.
duke@435 2379 }
duke@435 2380 }
duke@435 2381 }
duke@435 2382 }
duke@435 2383 }
duke@435 2384
duke@435 2385 // create the dynamic code event collector
duke@435 2386 JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(NULL) {
duke@435 2387 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 2388 setup_jvmti_thread_state();
duke@435 2389 }
duke@435 2390 }
duke@435 2391
duke@435 2392 // iterate over any code blob descriptors collected and post a
duke@435 2393 // DYNAMIC_CODE_GENERATED event to the profiler.
duke@435 2394 JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
duke@435 2395 assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
duke@435 2396 // iterate over any code blob descriptors that we collected
duke@435 2397 if (_code_blobs != NULL) {
duke@435 2398 for (int i=0; i<_code_blobs->length(); i++) {
duke@435 2399 JvmtiCodeBlobDesc* blob = _code_blobs->at(i);
duke@435 2400 JvmtiExport::post_dynamic_code_generated(blob->name(), blob->code_begin(), blob->code_end());
duke@435 2401 FreeHeap(blob);
duke@435 2402 }
duke@435 2403 delete _code_blobs;
duke@435 2404 }
duke@435 2405 unset_jvmti_thread_state();
duke@435 2406 }
duke@435 2407
duke@435 2408 // register a stub
duke@435 2409 void JvmtiDynamicCodeEventCollector::register_stub(const char* name, address start, address end) {
duke@435 2410 if (_code_blobs == NULL) {
duke@435 2411 _code_blobs = new (ResourceObj::C_HEAP) GrowableArray<JvmtiCodeBlobDesc*>(1,true);
duke@435 2412 }
duke@435 2413 _code_blobs->append(new JvmtiCodeBlobDesc(name, start, end));
duke@435 2414 }
duke@435 2415
duke@435 2416 // Setup current thread to record vm allocated objects.
duke@435 2417 JvmtiVMObjectAllocEventCollector::JvmtiVMObjectAllocEventCollector() : _allocated(NULL) {
duke@435 2418 if (JvmtiExport::should_post_vm_object_alloc()) {
duke@435 2419 _enable = true;
duke@435 2420 setup_jvmti_thread_state();
duke@435 2421 } else {
duke@435 2422 _enable = false;
duke@435 2423 }
duke@435 2424 }
duke@435 2425
duke@435 2426 // Post vm_object_alloc event for vm allocated objects visible to java
duke@435 2427 // world.
duke@435 2428 JvmtiVMObjectAllocEventCollector::~JvmtiVMObjectAllocEventCollector() {
duke@435 2429 if (_allocated != NULL) {
duke@435 2430 set_enabled(false);
duke@435 2431 for (int i = 0; i < _allocated->length(); i++) {
duke@435 2432 oop obj = _allocated->at(i);
duke@435 2433 if (ServiceUtil::visible_oop(obj)) {
duke@435 2434 JvmtiExport::post_vm_object_alloc(JavaThread::current(), obj);
duke@435 2435 }
duke@435 2436 }
duke@435 2437 delete _allocated;
duke@435 2438 }
duke@435 2439 unset_jvmti_thread_state();
duke@435 2440 }
duke@435 2441
duke@435 2442 void JvmtiVMObjectAllocEventCollector::record_allocation(oop obj) {
duke@435 2443 assert(is_enabled(), "VM object alloc event collector is not enabled");
duke@435 2444 if (_allocated == NULL) {
duke@435 2445 _allocated = new (ResourceObj::C_HEAP) GrowableArray<oop>(1, true);
duke@435 2446 }
duke@435 2447 _allocated->push(obj);
duke@435 2448 }
duke@435 2449
duke@435 2450 // GC support.
duke@435 2451 void JvmtiVMObjectAllocEventCollector::oops_do(OopClosure* f) {
duke@435 2452 if (_allocated != NULL) {
duke@435 2453 for(int i=_allocated->length() - 1; i >= 0; i--) {
duke@435 2454 if (_allocated->at(i) != NULL) {
duke@435 2455 f->do_oop(_allocated->adr_at(i));
duke@435 2456 }
duke@435 2457 }
duke@435 2458 }
duke@435 2459 }
duke@435 2460
duke@435 2461 void JvmtiVMObjectAllocEventCollector::oops_do_for_all_threads(OopClosure* f) {
duke@435 2462 // no-op if jvmti not enabled
duke@435 2463 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2464 return;
duke@435 2465 }
duke@435 2466
duke@435 2467 // Runs at safepoint. So no need to acquire Threads_lock.
duke@435 2468 for (JavaThread *jthr = Threads::first(); jthr != NULL; jthr = jthr->next()) {
duke@435 2469 JvmtiThreadState *state = jthr->jvmti_thread_state();
duke@435 2470 if (state != NULL) {
duke@435 2471 JvmtiVMObjectAllocEventCollector *collector;
duke@435 2472 collector = state->get_vm_object_alloc_event_collector();
duke@435 2473 while (collector != NULL) {
duke@435 2474 collector->oops_do(f);
duke@435 2475 collector = (JvmtiVMObjectAllocEventCollector *)collector->get_prev();
duke@435 2476 }
duke@435 2477 }
duke@435 2478 }
duke@435 2479 }
duke@435 2480
duke@435 2481
duke@435 2482 // Disable collection of VMObjectAlloc events
duke@435 2483 NoJvmtiVMObjectAllocMark::NoJvmtiVMObjectAllocMark() : _collector(NULL) {
duke@435 2484 // a no-op if VMObjectAlloc event is not enabled
duke@435 2485 if (!JvmtiExport::should_post_vm_object_alloc()) {
duke@435 2486 return;
duke@435 2487 }
duke@435 2488 Thread* thread = ThreadLocalStorage::thread();
duke@435 2489 if (thread != NULL && thread->is_Java_thread()) {
duke@435 2490 JavaThread* current_thread = (JavaThread*)thread;
duke@435 2491 JvmtiThreadState *state = current_thread->jvmti_thread_state();
duke@435 2492 if (state != NULL) {
duke@435 2493 JvmtiVMObjectAllocEventCollector *collector;
duke@435 2494 collector = state->get_vm_object_alloc_event_collector();
duke@435 2495 if (collector != NULL && collector->is_enabled()) {
duke@435 2496 _collector = collector;
duke@435 2497 _collector->set_enabled(false);
duke@435 2498 }
duke@435 2499 }
duke@435 2500 }
duke@435 2501 }
duke@435 2502
duke@435 2503 // Re-Enable collection of VMObjectAlloc events (if previously enabled)
duke@435 2504 NoJvmtiVMObjectAllocMark::~NoJvmtiVMObjectAllocMark() {
duke@435 2505 if (was_enabled()) {
duke@435 2506 _collector->set_enabled(true);
duke@435 2507 }
duke@435 2508 };
duke@435 2509
duke@435 2510 JvmtiGCMarker::JvmtiGCMarker(bool full) : _full(full), _invocation_count(0) {
duke@435 2511 assert(Thread::current()->is_VM_thread(), "wrong thread");
duke@435 2512
duke@435 2513 // if there aren't any JVMTI environments then nothing to do
duke@435 2514 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2515 return;
duke@435 2516 }
duke@435 2517
dcubed@1315 2518 if (ForceFullGCJVMTIEpilogues) {
dcubed@1315 2519 // force 'Full GC' was done semantics for JVMTI GC epilogues
dcubed@1315 2520 _full = true;
dcubed@1315 2521 }
dcubed@1315 2522
duke@435 2523 // GarbageCollectionStart event posted from VM thread - okay because
duke@435 2524 // JVMTI is clear that the "world is stopped" and callback shouldn't
duke@435 2525 // try to call into the VM.
duke@435 2526 if (JvmtiExport::should_post_garbage_collection_start()) {
duke@435 2527 JvmtiExport::post_garbage_collection_start();
duke@435 2528 }
duke@435 2529
duke@435 2530 // if "full" is false it probably means this is a scavenge of the young
duke@435 2531 // generation. However it could turn out that a "full" GC is required
duke@435 2532 // so we record the number of collections so that it can be checked in
duke@435 2533 // the destructor.
duke@435 2534 if (!_full) {
ysr@777 2535 _invocation_count = Universe::heap()->total_full_collections();
duke@435 2536 }
duke@435 2537
duke@435 2538 // Do clean up tasks that need to be done at a safepoint
duke@435 2539 JvmtiEnvBase::check_for_periodic_clean_up();
duke@435 2540 }
duke@435 2541
duke@435 2542 JvmtiGCMarker::~JvmtiGCMarker() {
duke@435 2543 // if there aren't any JVMTI environments then nothing to do
duke@435 2544 if (!JvmtiEnv::environments_might_exist()) {
duke@435 2545 return;
duke@435 2546 }
duke@435 2547
duke@435 2548 // JVMTI notify gc finish
duke@435 2549 if (JvmtiExport::should_post_garbage_collection_finish()) {
duke@435 2550 JvmtiExport::post_garbage_collection_finish();
duke@435 2551 }
duke@435 2552
duke@435 2553 // we might have initially started out doing a scavenge of the young
duke@435 2554 // generation but could have ended up doing a "full" GC - check the
duke@435 2555 // GC count to see.
duke@435 2556 if (!_full) {
ysr@777 2557 _full = (_invocation_count != Universe::heap()->total_full_collections());
duke@435 2558 }
duke@435 2559
duke@435 2560 // Full collection probably means the perm generation has been GC'ed
duke@435 2561 // so we clear the breakpoint cache.
duke@435 2562 if (_full) {
duke@435 2563 JvmtiCurrentBreakpoints::gc_epilogue();
duke@435 2564 }
duke@435 2565
duke@435 2566 // Notify heap/object tagging support
duke@435 2567 JvmtiTagMap::gc_epilogue(_full);
duke@435 2568 }
duke@435 2569 #endif // JVMTI_KERNEL

mercurial