1332 if (env->phase() == JVMTI_PHASE_PRIMORDIAL) { 1333 continue; 1334 } 1335 EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Evt Class Prepare sent %s", 1336 JvmtiTrace::safe_get_thread_name(thread), 1337 klass==NULL? "NULL" : klass->external_name() )); 1338 JvmtiClassEventMark jem(thread, klass); 1339 JvmtiJavaThreadEventTransition jet(thread); 1340 jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare; 1341 if (callback != NULL) { 1342 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class()); 1343 } 1344 } 1345 } 1346 } 1347 1348 void JvmtiExport::post_class_unload(Klass* klass) { 1349 if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) { 1350 return; 1351 } 1352 Thread *thread = Thread::current(); 1353 HandleMark hm(thread); 1354 1355 EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Trg Class Unload triggered" )); 1356 if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { 1357 assert(thread->is_VM_thread(), "wrong thread"); 1358 1359 // get JavaThread for whom we are proxy 1360 Thread *calling_thread = ((VMThread *)thread)->vm_operation()->calling_thread(); 1361 if (!calling_thread->is_Java_thread()) { 1362 // cannot post an event to a non-JavaThread 1363 return; 1364 } 1365 JavaThread *real_thread = (JavaThread *)calling_thread; 1366 1367 JvmtiEnvIterator it; 1368 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { 1369 if (env->phase() == JVMTI_PHASE_PRIMORDIAL) { 1370 continue; 1371 } 1372 if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { 1373 EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Evt Class Unload sent %s", 1374 klass==NULL? "NULL" : klass->external_name() )); 1375 1376 // do everything manually, since this is a proxy - needs special care 1377 JNIEnv* jni_env = real_thread->jni_environment(); 1378 jthread jt = (jthread)JNIHandles::make_local(real_thread, real_thread->threadObj()); 1379 jclass jk = (jclass)JNIHandles::make_local(real_thread, klass->java_mirror()); 1380 1381 // Before we call the JVMTI agent, we have to set the state in the 1382 // thread for which we are proxying. 1383 JavaThreadState prev_state = real_thread->thread_state(); 1384 assert(((Thread *)real_thread)->is_ConcurrentGC_thread() || 1385 (real_thread->is_Java_thread() && prev_state == _thread_blocked), 1386 "should be ConcurrentGCThread or JavaThread at safepoint"); 1387 real_thread->set_thread_state(_thread_in_native); 1388 1389 jvmtiExtensionEvent callback = env->ext_callbacks()->ClassUnload; 1390 if (callback != NULL) { 1391 (*callback)(env->jvmti_external(), jni_env, jt, jk); 1392 } 1393 1394 assert(real_thread->thread_state() == _thread_in_native, 1395 "JavaThread should be in native"); 1396 real_thread->set_thread_state(prev_state); 1397 1398 JNIHandles::destroy_local(jk); 1399 JNIHandles::destroy_local(jt); 1400 } 1401 } 1402 } 1403 } 1404 1405 1406 void JvmtiExport::post_thread_start(JavaThread *thread) { 1407 if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) { 1408 return; 1409 } 1410 assert(thread->thread_state() == _thread_in_vm, "must be in vm state"); 1411 1412 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Trg Thread Start event triggered", 1413 JvmtiTrace::safe_get_thread_name(thread))); 1414 1415 // do JVMTI thread initialization (if needed) 1416 JvmtiEventController::thread_started(thread); 1417 1418 // Do not post thread start event for hidden java thread. 1419 if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) && | 1332 if (env->phase() == JVMTI_PHASE_PRIMORDIAL) { 1333 continue; 1334 } 1335 EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Evt Class Prepare sent %s", 1336 JvmtiTrace::safe_get_thread_name(thread), 1337 klass==NULL? "NULL" : klass->external_name() )); 1338 JvmtiClassEventMark jem(thread, klass); 1339 JvmtiJavaThreadEventTransition jet(thread); 1340 jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare; 1341 if (callback != NULL) { 1342 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class()); 1343 } 1344 } 1345 } 1346 } 1347 1348 void JvmtiExport::post_class_unload(Klass* klass) { 1349 if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) { 1350 return; 1351 } 1352 1353 // postings to the service thread so that it can perform them in a safe 1354 // context and in-order. 1355 MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag); 1356 ResourceMark rm; 1357 // JvmtiDeferredEvent copies the string. 1358 JvmtiDeferredEvent event = JvmtiDeferredEvent::class_unload_event(klass->name()->as_C_string()); 1359 JvmtiDeferredEventQueue::enqueue(event); 1360 } 1361 1362 1363 void JvmtiExport::post_class_unload_internal(const char* name) { 1364 if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) { 1365 return; 1366 } 1367 assert(Thread::current()->is_Java_thread(), "must be called from ServiceThread"); 1368 JavaThread *thread = JavaThread::current(); 1369 HandleMark hm(thread); 1370 1371 EVT_TRIG_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Trg Class Unload triggered" )); 1372 if (JvmtiEventController::is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { 1373 1374 JvmtiEnvIterator it; 1375 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) { 1376 if (env->phase() == JVMTI_PHASE_PRIMORDIAL) { 1377 continue; 1378 } 1379 if (env->is_enabled((jvmtiEvent)EXT_EVENT_CLASS_UNLOAD)) { 1380 EVT_TRACE(EXT_EVENT_CLASS_UNLOAD, ("[?] Evt Class Unload sent %s", name)); 1381 1382 JvmtiEventMark jem(thread); 1383 JvmtiJavaThreadEventTransition jet(thread); 1384 jvmtiExtensionEvent callback = env->ext_callbacks()->ClassUnload; 1385 if (callback != NULL) { 1386 (*callback)(env->jvmti_external(), jem.jni_env(), name); 1387 } 1388 } 1389 } 1390 } 1391 } 1392 1393 1394 void JvmtiExport::post_thread_start(JavaThread *thread) { 1395 if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) { 1396 return; 1397 } 1398 assert(thread->thread_state() == _thread_in_vm, "must be in vm state"); 1399 1400 EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Trg Thread Start event triggered", 1401 JvmtiTrace::safe_get_thread_name(thread))); 1402 1403 // do JVMTI thread initialization (if needed) 1404 JvmtiEventController::thread_started(thread); 1405 1406 // Do not post thread start event for hidden java thread. 1407 if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) && |