< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page

 206 
 207   jclass to_jclass(Klass* klass) { return (klass == NULL ? NULL : (jclass)to_jobject(klass->java_mirror())); }
 208 
 209   jmethodID to_jmethodID(const methodHandle& method) { return method->jmethod_id(); }
 210 
 211   JNIEnv* jni_env() { return _jni_env; }
 212 };
 213 
 214 class JvmtiThreadEventMark : public JvmtiEventMark {
 215 private:
 216   jthread _jt;
 217 
 218 public:
 219   JvmtiThreadEventMark(JavaThread *thread) :
 220     JvmtiEventMark(thread) {
 221     _jt = (jthread)(to_jobject(thread->threadObj()));
 222   };
 223  jthread jni_thread() { return _jt; }
 224 };
 225 
 226 class JvmtiClassEventMark : public JvmtiThreadEventMark {

















 227 private:
 228   jclass _jc;
 229 
 230 public:
 231   JvmtiClassEventMark(JavaThread *thread, Klass* klass) :
 232     JvmtiThreadEventMark(thread) {
 233     _jc = to_jclass(klass);
 234   };
 235   jclass jni_class() { return _jc; }
 236 };
 237 
 238 class JvmtiMethodEventMark : public JvmtiThreadEventMark {
 239 private:
 240   jmethodID _mid;
 241 
 242 public:
 243   JvmtiMethodEventMark(JavaThread *thread, const methodHandle& method) :
 244     JvmtiThreadEventMark(thread),
 245     _mid(to_jmethodID(method)) {};
 246   jmethodID jni_methodID() { return _mid; }
 247 };
 248 
 249 class JvmtiLocationEventMark : public JvmtiMethodEventMark {
 250 private:
 251   jlocation _loc;
 252 
 253 public:
 254   JvmtiLocationEventMark(JavaThread *thread, const methodHandle& method, address location) :
 255     JvmtiMethodEventMark(thread, method),
 256     _loc(location - method->code_base()) {};
 257   jlocation location() { return _loc; }
 258 };
 259 
 260 class JvmtiExceptionEventMark : public JvmtiLocationEventMark {
 261 private:
 262   jobject _exc;
 263 
 264 public:

 783   if (thread_oop == NULL) {
 784     // NULL jthread, GC'ed jthread or a bad JNI handle.
 785     return JVMTI_ERROR_INVALID_THREAD;
 786   }
 787   // Looks like an oop at this point.
 788 
 789   if (!thread_oop->is_a(vmClasses::Thread_klass())) {
 790     // The oop is not a java.lang.Thread.
 791     return JVMTI_ERROR_INVALID_THREAD;
 792   }
 793   // Looks like a java.lang.Thread oop at this point.
 794 
 795   if (thread_oop_p != NULL) {
 796     // Return the oop to the caller; the caller may still want
 797     // the oop even if this function returns an error.
 798     *thread_oop_p = thread_oop;
 799   }
 800 
 801   JavaThread * java_thread = java_lang_Thread::thread(thread_oop);
 802   if (java_thread == NULL) {



 803     // The java.lang.Thread does not contain a JavaThread * so it has
 804     // not yet run or it has died.
 805     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 806   }
 807   // Looks like a live JavaThread at this point.
 808 
 809   // We do not check the EnableThreadSMRExtraValidityChecks option
 810   // for this includes() call because JVM/TI's spec is tighter.
 811   if (!t_list->includes(java_thread)) {
 812     // Not on the JavaThreads list so it is not alive.
 813     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 814   }
 815 
 816   // Return a live JavaThread that is "protected" by the
 817   // ThreadsListHandle in the caller.
 818   *jt_pp = java_thread;
 819 
 820   return JVMTI_ERROR_NONE;
 821 }
 822 

1108   JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = NULL)
1109           : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
1110     _code_data = nm->code_begin();
1111     _code_size = nm->code_size();
1112     _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is NULL.
1113     JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
1114   }
1115   ~JvmtiCompiledMethodLoadEventMark() {
1116      FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, _map);
1117   }
1118 
1119   jint code_size() { return _code_size; }
1120   const void *code_data() { return _code_data; }
1121   jint map_length() { return _map_length; }
1122   const jvmtiAddrLocationMap* map() { return _map; }
1123   const void *compile_info() { return _compile_info; }
1124 };
1125 
1126 
1127 
1128 class JvmtiMonitorEventMark : public JvmtiThreadEventMark {
1129 private:
1130   jobject _jobj;
1131 public:
1132   JvmtiMonitorEventMark(JavaThread *thread, oop object)
1133           : JvmtiThreadEventMark(thread){
1134      _jobj = to_jobject(object);
1135   }
1136   jobject jni_object() { return _jobj; }
1137 };
1138 
1139 ///////////////////////////////////////////////////////////////
1140 //
1141 // pending CompiledMethodUnload support
1142 //
1143 
1144 void JvmtiExport::post_compiled_method_unload(
1145        jmethodID method, const void *code_begin) {
1146   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1147     return;
1148   }
1149   JavaThread* thread = JavaThread::current();
1150   EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
1151                  ("[%s] method compile unload event triggered",
1152                   JvmtiTrace::safe_get_thread_name(thread)));
1153 

1170       if (callback != NULL) {
1171         (*callback)(env->jvmti_external(), method, code_begin);
1172       }
1173     }
1174   }
1175 }
1176 
1177 ///////////////////////////////////////////////////////////////
1178 //
1179 // JvmtiExport
1180 //
1181 
1182 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, address location) {
1183   HandleMark hm(thread);
1184   methodHandle mh(thread, method);
1185 
1186   JvmtiThreadState *state = thread->jvmti_thread_state();
1187   if (state == NULL) {
1188     return;
1189   }




1190   EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("[%s] Trg Breakpoint triggered",
1191                       JvmtiTrace::safe_get_thread_name(thread)));
1192   JvmtiEnvThreadStateIterator it(state);
1193   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1194     ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
1195     if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
1196       ThreadState old_os_state = thread->osthread()->get_state();
1197       thread->osthread()->set_state(BREAKPOINTED);
1198       EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("[%s] Evt Breakpoint sent %s.%s @ " INTX_FORMAT,
1199                      JvmtiTrace::safe_get_thread_name(thread),
1200                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1201                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1202                      location - mh()->code_base() ));
1203 
1204       JvmtiEnv *env = ets->get_env();
1205       JvmtiLocationEventMark jem(thread, mh, location);
1206       JvmtiJavaThreadEventTransition jet(thread);
1207       jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
1208       if (callback != NULL) {
1209         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1210                     jem.jni_methodID(), jem.location());
1211       }
1212 
1213       ets->set_breakpoint_posted();
1214       thread->osthread()->set_state(old_os_state);
1215     }
1216   }
1217 }
1218 
1219 //////////////////////////////////////////////////////////////////////////////
1220 
1221 bool              JvmtiExport::_can_get_source_debug_extension            = false;
1222 bool              JvmtiExport::_can_maintain_original_method_order        = false;
1223 bool              JvmtiExport::_can_post_interpreter_events               = false;
1224 bool              JvmtiExport::_can_post_on_exceptions                    = false;
1225 bool              JvmtiExport::_can_post_breakpoint                       = false;
1226 bool              JvmtiExport::_can_post_field_access                     = false;
1227 bool              JvmtiExport::_can_post_field_modification               = false;
1228 bool              JvmtiExport::_can_post_method_entry                     = false;
1229 bool              JvmtiExport::_can_post_method_exit                      = false;

1230 bool              JvmtiExport::_can_pop_frame                             = false;
1231 bool              JvmtiExport::_can_force_early_return                    = false;

1232 bool              JvmtiExport::_can_get_owned_monitor_info                = false;
1233 
1234 bool              JvmtiExport::_early_vmstart_recorded                    = false;
1235 
1236 bool              JvmtiExport::_should_post_single_step                   = false;
1237 bool              JvmtiExport::_should_post_field_access                  = false;
1238 bool              JvmtiExport::_should_post_field_modification            = false;
1239 bool              JvmtiExport::_should_post_class_load                    = false;
1240 bool              JvmtiExport::_should_post_class_prepare                 = false;
1241 bool              JvmtiExport::_should_post_class_unload                  = false;
1242 bool              JvmtiExport::_should_post_thread_life                   = false;
1243 bool              JvmtiExport::_should_clean_up_heap_objects              = false;
1244 bool              JvmtiExport::_should_post_native_method_bind            = false;
1245 bool              JvmtiExport::_should_post_dynamic_code_generated        = false;
1246 bool              JvmtiExport::_should_post_data_dump                     = false;
1247 bool              JvmtiExport::_should_post_compiled_method_load          = false;
1248 bool              JvmtiExport::_should_post_compiled_method_unload        = false;
1249 bool              JvmtiExport::_should_post_monitor_contended_enter       = false;
1250 bool              JvmtiExport::_should_post_monitor_contended_entered     = false;
1251 bool              JvmtiExport::_should_post_monitor_wait                  = false;
1252 bool              JvmtiExport::_should_post_monitor_waited                = false;
1253 bool              JvmtiExport::_should_post_garbage_collection_start      = false;
1254 bool              JvmtiExport::_should_post_garbage_collection_finish     = false;
1255 bool              JvmtiExport::_should_post_object_free                   = false;
1256 bool              JvmtiExport::_should_post_resource_exhausted            = false;
1257 bool              JvmtiExport::_should_post_vm_object_alloc               = false;
1258 bool              JvmtiExport::_should_post_sampled_object_alloc          = false;
1259 bool              JvmtiExport::_should_post_on_exceptions                 = false;




1260 
1261 ////////////////////////////////////////////////////////////////////////////////////////////////
1262 
1263 





























1264 //
1265 // JVMTI single step management
1266 //
1267 void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, address location) {
1268   assert(JvmtiExport::should_post_single_step(), "must be single stepping");
1269 
1270   HandleMark hm(thread);
1271   methodHandle mh(thread, method);
1272 
1273   // update information about current location and post a step event
1274   JvmtiThreadState *state = thread->jvmti_thread_state();
1275   if (state == NULL) {
1276     return;
1277   }
1278   EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Trg Single Step triggered",
1279                       JvmtiTrace::safe_get_thread_name(thread)));
1280   if (!state->hide_single_stepping()) {
1281     if (state->is_pending_step_for_popframe()) {
1282       state->process_pending_step_for_popframe();
1283     }

1302   if (state != NULL && state->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1303     state->set_hide_single_stepping();
1304     return true;
1305   } else {
1306     return false;
1307   }
1308 }
1309 
1310 void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
1311   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1312     return;
1313   }
1314   HandleMark hm(thread);
1315 
1316   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Trg Class Load triggered",
1317                       JvmtiTrace::safe_get_thread_name(thread)));
1318   JvmtiThreadState* state = thread->jvmti_thread_state();
1319   if (state == NULL) {
1320     return;
1321   }



1322   JvmtiEnvThreadStateIterator it(state);
1323   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1324     if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) {
1325       JvmtiEnv *env = ets->get_env();
1326       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1327         continue;
1328       }
1329       EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Evt Class Load sent %s",
1330                                          JvmtiTrace::safe_get_thread_name(thread),
1331                                          klass==NULL? "NULL" : klass->external_name() ));
1332       JvmtiClassEventMark jem(thread, klass);
1333       JvmtiJavaThreadEventTransition jet(thread);
1334       jvmtiEventClassLoad callback = env->callbacks()->ClassLoad;
1335       if (callback != NULL) {
1336         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
1337       }
1338     }
1339   }
1340 }
1341 
1342 
1343 void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
1344   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1345     return;
1346   }
1347   HandleMark hm(thread);
1348 
1349   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Trg Class Prepare triggered",
1350                       JvmtiTrace::safe_get_thread_name(thread)));
1351   JvmtiThreadState* state = thread->jvmti_thread_state();
1352   if (state == NULL) {
1353     return;
1354   }



1355   JvmtiEnvThreadStateIterator it(state);
1356   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1357     if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) {
1358       JvmtiEnv *env = ets->get_env();
1359       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1360         continue;
1361       }
1362       EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Evt Class Prepare sent %s",
1363                                             JvmtiTrace::safe_get_thread_name(thread),
1364                                             klass==NULL? "NULL" : klass->external_name() ));
1365       JvmtiClassEventMark jem(thread, klass);
1366       JvmtiJavaThreadEventTransition jet(thread);
1367       jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare;
1368       if (callback != NULL) {
1369         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
1370       }
1371     }
1372   }
1373 }
1374 

1424   assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
1425 
1426   EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Trg Thread Start event triggered",
1427                       JvmtiTrace::safe_get_thread_name(thread)));
1428 
1429   // do JVMTI thread initialization (if needed)
1430   JvmtiEventController::thread_started(thread);
1431 
1432   // Do not post thread start event for hidden java thread.
1433   if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) &&
1434       !thread->is_hidden_from_external_view()) {
1435     JvmtiEnvIterator it;
1436     for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
1437       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1438         continue;
1439       }
1440       if (env->is_enabled(JVMTI_EVENT_THREAD_START)) {
1441         EVT_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Evt Thread Start event sent",
1442                      JvmtiTrace::safe_get_thread_name(thread) ));
1443 
1444         JvmtiThreadEventMark jem(thread);
1445         JvmtiJavaThreadEventTransition jet(thread);
1446         jvmtiEventThreadStart callback = env->callbacks()->ThreadStart;
1447         if (callback != NULL) {
1448           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1449         }
1450       }
1451     }
1452   }
1453 }
1454 
1455 
1456 void JvmtiExport::post_thread_end(JavaThread *thread) {
1457   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1458     return;
1459   }
1460   EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Trg Thread End event triggered",
1461                       JvmtiTrace::safe_get_thread_name(thread)));
1462 
1463   JvmtiThreadState *state = thread->jvmti_thread_state();
1464   if (state == NULL) {
1465     return;
1466   }
1467 
1468   // Do not post thread end event for hidden java thread.
1469   if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
1470       !thread->is_hidden_from_external_view()) {
1471 
1472     JvmtiEnvThreadStateIterator it(state);
1473     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1474       if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
1475         JvmtiEnv *env = ets->get_env();
1476         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1477           continue;
1478         }
1479         EVT_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Evt Thread End event sent",
1480                      JvmtiTrace::safe_get_thread_name(thread) ));
1481 
1482         JvmtiThreadEventMark jem(thread);
1483         JvmtiJavaThreadEventTransition jet(thread);
1484         jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
1485         if (callback != NULL) {
1486           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1487         }
1488       }
1489     }
1490   }
1491 }
1492 













































































































































































1493 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
1494   assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
1495 
1496   EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Trg Object Free triggered" ));
1497   EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Evt Object Free sent"));
1498 
1499   jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
1500   if (callback != NULL) {
1501     (*callback)(env->jvmti_external(), tag);
1502   }
1503 }
1504 
1505 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
1506 
1507   JavaThread *thread  = JavaThread::current();
1508 
1509   log_error(jvmti)("Posting Resource Exhausted event: %s",
1510                    description != nullptr ? description : "unknown");
1511 
1512   // JDK-8213834: handlers of ResourceExhausted may attempt some analysis

1533                     resource_exhausted_flags, NULL, description);
1534       }
1535     }
1536   }
1537 }
1538 
1539 void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame current_frame) {
1540   HandleMark hm(thread);
1541   methodHandle mh(thread, method);
1542 
1543   EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("[%s] Trg Method Entry triggered %s.%s",
1544                      JvmtiTrace::safe_get_thread_name(thread),
1545                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1546                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
1547 
1548   JvmtiThreadState* state = thread->jvmti_thread_state();
1549   if (state == NULL || !state->is_interp_only_mode()) {
1550     // for any thread that actually wants method entry, interp_only_mode is set
1551     return;
1552   }



1553 
1554   state->incr_cur_stack_depth();
1555 
1556   if (state->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
1557     JvmtiEnvThreadStateIterator it(state);
1558     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1559       if (ets->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
1560         EVT_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("[%s] Evt Method Entry sent %s.%s",
1561                                              JvmtiTrace::safe_get_thread_name(thread),
1562                                              (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1563                                              (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
1564 
1565         JvmtiEnv *env = ets->get_env();
1566         JvmtiMethodEventMark jem(thread, mh);
1567         JvmtiJavaThreadEventTransition jet(thread);
1568         jvmtiEventMethodEntry callback = env->callbacks()->MethodEntry;
1569         if (callback != NULL) {
1570           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_methodID());
1571         }
1572       }
1573     }
1574   }
1575 }
1576 
1577 void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame current_frame) {
1578   HandleMark hm(thread);
1579   methodHandle mh(thread, method);
1580 
1581   JvmtiThreadState *state = thread->jvmti_thread_state();
1582 
1583   if (state == NULL || !state->is_interp_only_mode()) {
1584     // for any thread that actually wants method exit, interp_only_mode is set
1585     return;
1586   }



1587 
1588   // return a flag when a method terminates by throwing an exception
1589   // i.e. if an exception is thrown and it's not caught by the current method
1590   bool exception_exit = state->is_exception_detected() && !state->is_exception_caught();
1591   Handle result;
1592   jvalue value;
1593   value.j = 0L;
1594 
1595   if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
1596     // if the method hasn't been popped because of an exception then we populate
1597     // the return_value parameter for the callback. At this point we only have
1598     // the address of a "raw result" and we just call into the interpreter to
1599     // convert this into a jvalue.
1600     if (!exception_exit) {
1601       oop oop_result;
1602       BasicType type = current_frame.interpreter_frame_result(&oop_result, &value);
1603       if (is_reference_type(type)) {
1604         result = Handle(thread, oop_result);
1605         value.l = JNIHandles::make_local(thread, result());
1606       }

1670           // we also need to issue a frame pop event for this frame
1671           JvmtiEnv *env = ets->get_env();
1672           JvmtiMethodEventMark jem(thread, mh);
1673           JvmtiJavaThreadEventTransition jet(thread);
1674           jvmtiEventFramePop callback = env->callbacks()->FramePop;
1675           if (callback != NULL) {
1676             (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1677                         jem.jni_methodID(), exception_exit);
1678           }
1679         }
1680         // remove the frame's entry
1681         {
1682           MutexLocker mu(JvmtiThreadState_lock);
1683           ets->clear_frame_pop(cur_frame_number);
1684         }
1685       }
1686     }
1687   }
1688 
1689   state->decr_cur_stack_depth();

1690 }
1691 
1692 
1693 // Todo: inline this for optimization
1694 void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address location) {
1695   HandleMark hm(thread);
1696   methodHandle mh(thread, method);
1697 
1698   JvmtiThreadState *state = thread->jvmti_thread_state();
1699   if (state == NULL) {
1700     return;
1701   }




1702   JvmtiEnvThreadStateIterator it(state);
1703   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1704     ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
1705     if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1706       EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Evt Single Step sent %s.%s @ " INTX_FORMAT,
1707                     JvmtiTrace::safe_get_thread_name(thread),
1708                     (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1709                     (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1710                     location - mh()->code_base() ));
1711 
1712       JvmtiEnv *env = ets->get_env();
1713       JvmtiLocationEventMark jem(thread, mh, location);
1714       JvmtiJavaThreadEventTransition jet(thread);
1715       jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
1716       if (callback != NULL) {
1717         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1718                     jem.jni_methodID(), jem.location());
1719       }
1720 
1721       ets->set_single_stepping_posted();
1722     }
1723   }
1724 }
1725 
1726 void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, address location, oop exception) {
1727   HandleMark hm(thread);
1728   methodHandle mh(thread, method);
1729   Handle exception_handle(thread, exception);
1730 
1731   JvmtiThreadState *state = thread->jvmti_thread_state();
1732   if (state == NULL) {
1733     return;
1734   }



1735 
1736   EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("[%s] Trg Exception thrown triggered",
1737                       JvmtiTrace::safe_get_thread_name(thread)));
1738   if (!state->is_exception_detected()) {
1739     state->set_exception_detected();
1740     JvmtiEnvThreadStateIterator it(state);
1741     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1742       if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
1743 
1744         EVT_TRACE(JVMTI_EVENT_EXCEPTION,
1745                      ("[%s] Evt Exception thrown sent %s.%s @ " INTX_FORMAT,
1746                       JvmtiTrace::safe_get_thread_name(thread),
1747                       (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1748                       (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1749                       location - mh()->code_base() ));
1750 
1751         JvmtiEnv *env = ets->get_env();
1752         JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
1753 
1754         // It's okay to clear these exceptions here because we duplicate

1877 }
1878 
1879 oop JvmtiExport::jni_GetField_probe(JavaThread *thread, jobject jobj, oop obj,
1880                                     Klass* klass, jfieldID fieldID, bool is_static) {
1881   if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
1882     // At least one field access watch is set so we have more work to do.
1883     post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
1884     // event posting can block so refetch oop if we were passed a jobj
1885     if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
1886   }
1887   return obj;
1888 }
1889 
1890 void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj,
1891                                            Klass* klass, jfieldID fieldID, bool is_static) {
1892   // We must be called with a Java context in order to provide reasonable
1893   // values for the klazz, method, and location fields. The callers of this
1894   // function don't make the call unless there is a Java context.
1895   assert(thread->has_last_Java_frame(), "must be called with a Java context");
1896 




1897   ResourceMark rm;
1898   fieldDescriptor fd;
1899   // if get_field_descriptor finds fieldID to be invalid, then we just bail
1900   bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
1901   assert(valid_fieldID == true,"post_field_access_by_jni called with invalid fieldID");
1902   if (!valid_fieldID) return;
1903   // field accesses are not watched so bail
1904   if (!fd.is_field_access_watched()) return;
1905 
1906   HandleMark hm(thread);
1907   Handle h_obj;
1908   if (!is_static) {
1909     // non-static field accessors have an object, but we need a handle
1910     assert(obj != NULL, "non-static needs an object");
1911     h_obj = Handle(thread, obj);
1912   }
1913   post_field_access(thread,
1914                     thread->last_frame().interpreter_frame_method(),
1915                     thread->last_frame().interpreter_frame_bcp(),
1916                     klass, h_obj, fieldID);
1917 }
1918 
1919 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
1920   address location, Klass* field_klass, Handle object, jfieldID field) {
1921 
1922   HandleMark hm(thread);
1923   methodHandle mh(thread, method);
1924 
1925   JvmtiThreadState *state = thread->jvmti_thread_state();
1926   if (state == NULL) {
1927     return;
1928   }




1929   EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("[%s] Trg Field Access event triggered",
1930                       JvmtiTrace::safe_get_thread_name(thread)));
1931   JvmtiEnvThreadStateIterator it(state);
1932   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1933     if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
1934       EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("[%s] Evt Field Access event sent %s.%s @ " INTX_FORMAT,
1935                      JvmtiTrace::safe_get_thread_name(thread),
1936                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1937                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1938                      location - mh()->code_base() ));
1939 
1940       JvmtiEnv *env = ets->get_env();
1941       JvmtiLocationEventMark jem(thread, mh, location);
1942       jclass field_jclass = jem.to_jclass(field_klass);
1943       jobject field_jobject = jem.to_jobject(object());
1944       JvmtiJavaThreadEventTransition jet(thread);
1945       jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
1946       if (callback != NULL) {
1947         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1948                     jem.jni_methodID(), jem.location(),

1955 oop JvmtiExport::jni_SetField_probe(JavaThread *thread, jobject jobj, oop obj,
1956                                     Klass* klass, jfieldID fieldID, bool is_static,
1957                                     char sig_type, jvalue *value) {
1958   if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
1959     // At least one field modification watch is set so we have more work to do.
1960     post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
1961     // event posting can block so refetch oop if we were passed a jobj
1962     if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
1963   }
1964   return obj;
1965 }
1966 
1967 void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj,
1968                                                  Klass* klass, jfieldID fieldID, bool is_static,
1969                                                  char sig_type, jvalue *value) {
1970   // We must be called with a Java context in order to provide reasonable
1971   // values for the klazz, method, and location fields. The callers of this
1972   // function don't make the call unless there is a Java context.
1973   assert(thread->has_last_Java_frame(), "must be called with Java context");
1974 




1975   ResourceMark rm;
1976   fieldDescriptor fd;
1977   // if get_field_descriptor finds fieldID to be invalid, then we just bail
1978   bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
1979   assert(valid_fieldID == true,"post_field_modification_by_jni called with invalid fieldID");
1980   if (!valid_fieldID) return;
1981   // field modifications are not watched so bail
1982   if (!fd.is_field_modification_watched()) return;
1983 
1984   HandleMark hm(thread);
1985 
1986   Handle h_obj;
1987   if (!is_static) {
1988     // non-static field accessors have an object, but we need a handle
1989     assert(obj != NULL, "non-static needs an object");
1990     h_obj = Handle(thread, obj);
1991   }
1992   post_field_modification(thread,
1993                           thread->last_frame().interpreter_frame_method(),
1994                           thread->last_frame().interpreter_frame_bcp(),
1995                           klass, h_obj, fieldID, sig_type, value);
1996 }
1997 
1998 void JvmtiExport::post_raw_field_modification(JavaThread *thread, Method* method,
1999   address location, Klass* field_klass, Handle object, jfieldID field,
2000   char sig_type, jvalue *value) {
2001 




2002   if (sig_type == JVM_SIGNATURE_INT || sig_type == JVM_SIGNATURE_BOOLEAN ||
2003       sig_type == JVM_SIGNATURE_BYTE || sig_type == JVM_SIGNATURE_CHAR ||
2004       sig_type == JVM_SIGNATURE_SHORT) {
2005     // 'I' instructions are used for byte, char, short and int.
2006     // determine which it really is, and convert
2007     fieldDescriptor fd;
2008     bool found = JvmtiEnv::get_field_descriptor(field_klass, field, &fd);
2009     // should be found (if not, leave as is)
2010     if (found) {
2011       jint ival = value->i;
2012       // convert value from int to appropriate type
2013       switch (fd.field_type()) {
2014       case T_BOOLEAN:
2015         sig_type = JVM_SIGNATURE_BOOLEAN;
2016         value->i = 0; // clear it
2017         value->z = (jboolean)ival;
2018         break;
2019       case T_BYTE:
2020         sig_type = JVM_SIGNATURE_BYTE;
2021         value->i = 0; // clear it

2053 
2054   post_field_modification(thread, method, location, field_klass, object, field, sig_type, value);
2055 
2056   // Destroy the JNI handle allocated above.
2057   if (handle_created) {
2058     JNIHandles::destroy_local(value->l);
2059   }
2060 }
2061 
2062 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
2063   address location, Klass* field_klass, Handle object, jfieldID field,
2064   char sig_type, jvalue *value_ptr) {
2065 
2066   HandleMark hm(thread);
2067   methodHandle mh(thread, method);
2068 
2069   JvmtiThreadState *state = thread->jvmti_thread_state();
2070   if (state == NULL) {
2071     return;
2072   }




2073   EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
2074                      ("[%s] Trg Field Modification event triggered",
2075                       JvmtiTrace::safe_get_thread_name(thread)));
2076 
2077   JvmtiEnvThreadStateIterator it(state);
2078   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2079     if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
2080       EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
2081                    ("[%s] Evt Field Modification event sent %s.%s @ " INTX_FORMAT,
2082                     JvmtiTrace::safe_get_thread_name(thread),
2083                     (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
2084                     (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
2085                     location - mh()->code_base() ));
2086 
2087       JvmtiEnv *env = ets->get_env();
2088       JvmtiLocationEventMark jem(thread, mh, location);
2089       jclass field_jclass = jem.to_jclass(field_klass);
2090       jobject field_jobject = jem.to_jobject(object());
2091       JvmtiJavaThreadEventTransition jet(thread);
2092       jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
2093       if (callback != NULL) {
2094         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2095                     jem.jni_methodID(), jem.location(),
2096                     field_jclass, field_jobject, field, sig_type, *value_ptr);
2097       }
2098     }
2099   }
2100 }
2101 
2102 void JvmtiExport::post_native_method_bind(Method* method, address* function_ptr) {
2103   JavaThread* thread = JavaThread::current();
2104   assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
2105 
2106   HandleMark hm(thread);
2107   methodHandle mh(thread, method);
2108 
2109   EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("[%s] Trg Native Method Bind event triggered",
2110                       JvmtiTrace::safe_get_thread_name(thread)));
2111 




2112   if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
2113     JvmtiEnvIterator it;
2114     for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2115       if (env->is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
2116         EVT_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("[%s] Evt Native Method Bind event sent",
2117                      JvmtiTrace::safe_get_thread_name(thread) ));
2118 
2119         JvmtiMethodEventMark jem(thread, mh);
2120         JvmtiJavaThreadEventTransition jet(thread);
2121         JNIEnv* jni_env = (env->phase() == JVMTI_PHASE_PRIMORDIAL) ? NULL : jem.jni_env();
2122         jvmtiEventNativeMethodBind callback = env->callbacks()->NativeMethodBind;
2123         if (callback != NULL) {
2124           (*callback)(env->jvmti_external(), jni_env, jem.jni_thread(),
2125                       jem.jni_methodID(), (void*)(*function_ptr), (void**)function_ptr);
2126         }
2127       }
2128     }
2129   }
2130 }
2131 

2398     if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
2399       EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
2400                 ("[%s] data dump request event sent",
2401                  JvmtiTrace::safe_get_thread_name(thread)));
2402      JvmtiThreadEventTransition jet(thread);
2403      // JNIEnv is NULL here because this event is posted from VM Thread
2404      jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
2405      if (callback != NULL) {
2406        (*callback)(env->jvmti_external());
2407      }
2408     }
2409   }
2410 }
2411 
2412 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
2413   oop object = obj_mntr->object();
2414   JvmtiThreadState *state = thread->jvmti_thread_state();
2415   if (state == NULL) {
2416     return;
2417   }



2418 
2419   HandleMark hm(thread);
2420   Handle h(thread, object);
2421 
2422   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2423                      ("[%s] monitor contended enter event triggered",
2424                       JvmtiTrace::safe_get_thread_name(thread)));
2425 
2426   JvmtiEnvThreadStateIterator it(state);
2427   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2428     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
2429       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2430                    ("[%s] monitor contended enter event sent",
2431                     JvmtiTrace::safe_get_thread_name(thread)));
2432       JvmtiMonitorEventMark  jem(thread, h());
2433       JvmtiEnv *env = ets->get_env();
2434       JvmtiThreadEventTransition jet(thread);
2435       jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
2436       if (callback != NULL) {
2437         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2438       }
2439     }
2440   }
2441 }
2442 
2443 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
2444   oop object = obj_mntr->object();
2445   JvmtiThreadState *state = thread->jvmti_thread_state();
2446   if (state == NULL) {
2447     return;
2448   }



2449 
2450   HandleMark hm(thread);
2451   Handle h(thread, object);
2452 
2453   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2454                      ("[%s] monitor contended entered event triggered",
2455                       JvmtiTrace::safe_get_thread_name(thread)));
2456 
2457   JvmtiEnvThreadStateIterator it(state);
2458   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2459     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
2460       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2461                    ("[%s] monitor contended enter event sent",
2462                     JvmtiTrace::safe_get_thread_name(thread)));
2463       JvmtiMonitorEventMark  jem(thread, h());
2464       JvmtiEnv *env = ets->get_env();
2465       JvmtiThreadEventTransition jet(thread);
2466       jvmtiEventMonitorContendedEntered callback = env->callbacks()->MonitorContendedEntered;
2467       if (callback != NULL) {
2468         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2469       }
2470     }
2471   }
2472 }
2473 
2474 void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
2475                                           jlong timeout) {
2476   JvmtiThreadState *state = thread->jvmti_thread_state();
2477   if (state == NULL) {
2478     return;
2479   }



2480 
2481   HandleMark hm(thread);
2482   Handle h(thread, object);
2483 
2484   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2485                      ("[%s] monitor wait event triggered",
2486                       JvmtiTrace::safe_get_thread_name(thread)));
2487 
2488   JvmtiEnvThreadStateIterator it(state);
2489   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2490     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
2491       EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2492                    ("[%s] monitor wait event sent",
2493                     JvmtiTrace::safe_get_thread_name(thread)));
2494       JvmtiMonitorEventMark  jem(thread, h());
2495       JvmtiEnv *env = ets->get_env();
2496       JvmtiThreadEventTransition jet(thread);
2497       jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
2498       if (callback != NULL) {
2499         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2500                     jem.jni_object(), timeout);
2501       }
2502     }
2503   }
2504 }
2505 
2506 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2507   oop object = obj_mntr->object();
2508   JvmtiThreadState *state = thread->jvmti_thread_state();
2509   if (state == NULL) {
2510     return;
2511   }



2512 
2513   HandleMark hm(thread);
2514   Handle h(thread, object);
2515 
2516   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2517                      ("[%s] monitor waited event triggered",
2518                       JvmtiTrace::safe_get_thread_name(thread)));
2519 
2520   JvmtiEnvThreadStateIterator it(state);
2521   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2522     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2523       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2524                    ("[%s] monitor waited event sent",
2525                     JvmtiTrace::safe_get_thread_name(thread)));
2526       JvmtiMonitorEventMark  jem(thread, h());
2527       JvmtiEnv *env = ets->get_env();
2528       JvmtiThreadEventTransition jet(thread);
2529       jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
2530       if (callback != NULL) {
2531         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2532                     jem.jni_object(), timed_out);
2533       }
2534     }
2535   }
2536 }
2537 
2538 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2539   EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2540                       JvmtiTrace::safe_get_thread_name(thread)));
2541   if (object == NULL) {
2542     return;
2543   }



2544   HandleMark hm(thread);
2545   Handle h(thread, object);
2546   JvmtiEnvIterator it;
2547   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2548     if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
2549       EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2550                                          JvmtiTrace::safe_get_thread_name(thread),
2551                                          object==NULL? "NULL" : object->klass()->external_name()));
2552 
2553       JvmtiObjectAllocEventMark jem(thread, h());
2554       JvmtiJavaThreadEventTransition jet(thread);
2555       jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
2556       if (callback != NULL) {
2557         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2558                     jem.jni_jobject(), jem.jni_class(), jem.size());
2559       }
2560     }
2561   }
2562 }
2563 
2564 void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
2565   JvmtiThreadState *state = thread->jvmti_thread_state();
2566   if (state == NULL) {
2567     return;
2568   }
2569 
2570   EVT_TRIG_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2571                  ("[%s] Trg sampled object alloc triggered",
2572                   JvmtiTrace::safe_get_thread_name(thread)));
2573   if (object == NULL) {
2574     return;
2575   }



2576   HandleMark hm(thread);
2577   Handle h(thread, object);
2578 
2579   JvmtiEnvThreadStateIterator it(state);
2580   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2581     if (ets->is_enabled(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC)) {
2582       EVT_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2583                 ("[%s] Evt sampled object alloc sent %s",
2584                  JvmtiTrace::safe_get_thread_name(thread),
2585                  object == NULL ? "NULL" : object->klass()->external_name()));
2586 
2587       JvmtiEnv *env = ets->get_env();
2588       JvmtiObjectAllocEventMark jem(thread, h());
2589       JvmtiJavaThreadEventTransition jet(thread);
2590       jvmtiEventSampledObjectAlloc callback = env->callbacks()->SampledObjectAlloc;
2591       if (callback != NULL) {
2592         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2593                     jem.jni_jobject(), jem.jni_class(), jem.size());
2594       }
2595     }

 206 
 207   jclass to_jclass(Klass* klass) { return (klass == NULL ? NULL : (jclass)to_jobject(klass->java_mirror())); }
 208 
 209   jmethodID to_jmethodID(const methodHandle& method) { return method->jmethod_id(); }
 210 
 211   JNIEnv* jni_env() { return _jni_env; }
 212 };
 213 
 214 class JvmtiThreadEventMark : public JvmtiEventMark {
 215 private:
 216   jthread _jt;
 217 
 218 public:
 219   JvmtiThreadEventMark(JavaThread *thread) :
 220     JvmtiEventMark(thread) {
 221     _jt = (jthread)(to_jobject(thread->threadObj()));
 222   };
 223  jthread jni_thread() { return _jt; }
 224 };
 225 
 226 class JvmtiVirtualThreadEventMark : public JvmtiEventMark {
 227 private:
 228   jthread _jt;
 229 
 230 public:
 231   JvmtiVirtualThreadEventMark(JavaThread *thread) :
 232     JvmtiEventMark(thread) {
 233     JvmtiThreadState* state = thread->jvmti_thread_state();
 234     if (state != NULL && state->is_virtual()) {
 235       _jt = (jthread)(to_jobject(thread->vthread()));
 236     } else {
 237       _jt = (jthread)(to_jobject(thread->threadObj()));
 238     }
 239   };
 240   jthread jni_thread() { return _jt; }
 241 };
 242 
 243 class JvmtiClassEventMark : public JvmtiVirtualThreadEventMark {
 244 private:
 245   jclass _jc;
 246 
 247 public:
 248   JvmtiClassEventMark(JavaThread *thread, Klass* klass) :
 249     JvmtiVirtualThreadEventMark(thread) {
 250     _jc = to_jclass(klass);
 251   };
 252   jclass jni_class() { return _jc; }
 253 };
 254 
 255 class JvmtiMethodEventMark : public JvmtiVirtualThreadEventMark {
 256 private:
 257   jmethodID _mid;
 258 
 259 public:
 260   JvmtiMethodEventMark(JavaThread *thread, const methodHandle& method) :
 261     JvmtiVirtualThreadEventMark(thread),
 262     _mid(to_jmethodID(method)) {};
 263   jmethodID jni_methodID() { return _mid; }
 264 };
 265 
 266 class JvmtiLocationEventMark : public JvmtiMethodEventMark {
 267 private:
 268   jlocation _loc;
 269 
 270 public:
 271   JvmtiLocationEventMark(JavaThread *thread, const methodHandle& method, address location) :
 272     JvmtiMethodEventMark(thread, method),
 273     _loc(location - method->code_base()) {};
 274   jlocation location() { return _loc; }
 275 };
 276 
 277 class JvmtiExceptionEventMark : public JvmtiLocationEventMark {
 278 private:
 279   jobject _exc;
 280 
 281 public:

 800   if (thread_oop == NULL) {
 801     // NULL jthread, GC'ed jthread or a bad JNI handle.
 802     return JVMTI_ERROR_INVALID_THREAD;
 803   }
 804   // Looks like an oop at this point.
 805 
 806   if (!thread_oop->is_a(vmClasses::Thread_klass())) {
 807     // The oop is not a java.lang.Thread.
 808     return JVMTI_ERROR_INVALID_THREAD;
 809   }
 810   // Looks like a java.lang.Thread oop at this point.
 811 
 812   if (thread_oop_p != NULL) {
 813     // Return the oop to the caller; the caller may still want
 814     // the oop even if this function returns an error.
 815     *thread_oop_p = thread_oop;
 816   }
 817 
 818   JavaThread * java_thread = java_lang_Thread::thread(thread_oop);
 819   if (java_thread == NULL) {
 820     if (java_lang_VirtualThread::is_instance(thread_oop)) {
 821       return JVMTI_ERROR_INVALID_THREAD;
 822     }
 823     // The java.lang.Thread does not contain a JavaThread * so it has
 824     // not yet run or it has died.
 825     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 826   }
 827   // Looks like a live JavaThread at this point.
 828 
 829   // We do not check the EnableThreadSMRExtraValidityChecks option
 830   // for this includes() call because JVM/TI's spec is tighter.
 831   if (!t_list->includes(java_thread)) {
 832     // Not on the JavaThreads list so it is not alive.
 833     return JVMTI_ERROR_THREAD_NOT_ALIVE;
 834   }
 835 
 836   // Return a live JavaThread that is "protected" by the
 837   // ThreadsListHandle in the caller.
 838   *jt_pp = java_thread;
 839 
 840   return JVMTI_ERROR_NONE;
 841 }
 842 

1128   JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = NULL)
1129           : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
1130     _code_data = nm->code_begin();
1131     _code_size = nm->code_size();
1132     _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is NULL.
1133     JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
1134   }
1135   ~JvmtiCompiledMethodLoadEventMark() {
1136      FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, _map);
1137   }
1138 
1139   jint code_size() { return _code_size; }
1140   const void *code_data() { return _code_data; }
1141   jint map_length() { return _map_length; }
1142   const jvmtiAddrLocationMap* map() { return _map; }
1143   const void *compile_info() { return _compile_info; }
1144 };
1145 
1146 
1147 
1148 class JvmtiMonitorEventMark : public JvmtiVirtualThreadEventMark {
1149 private:
1150   jobject _jobj;
1151 public:
1152   JvmtiMonitorEventMark(JavaThread *thread, oop object)
1153           : JvmtiVirtualThreadEventMark(thread){
1154      _jobj = to_jobject(object);
1155   }
1156   jobject jni_object() { return _jobj; }
1157 };
1158 
1159 ///////////////////////////////////////////////////////////////
1160 //
1161 // pending CompiledMethodUnload support
1162 //
1163 
1164 void JvmtiExport::post_compiled_method_unload(
1165        jmethodID method, const void *code_begin) {
1166   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1167     return;
1168   }
1169   JavaThread* thread = JavaThread::current();
1170   EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
1171                  ("[%s] method compile unload event triggered",
1172                   JvmtiTrace::safe_get_thread_name(thread)));
1173 

1190       if (callback != NULL) {
1191         (*callback)(env->jvmti_external(), method, code_begin);
1192       }
1193     }
1194   }
1195 }
1196 
1197 ///////////////////////////////////////////////////////////////
1198 //
1199 // JvmtiExport
1200 //
1201 
1202 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, address location) {
1203   HandleMark hm(thread);
1204   methodHandle mh(thread, method);
1205 
1206   JvmtiThreadState *state = thread->jvmti_thread_state();
1207   if (state == NULL) {
1208     return;
1209   }
1210   if (thread->is_in_VTMT()) {
1211     return; // no events should be posted if thread is in a VTMT transition
1212   }
1213 
1214   EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("[%s] Trg Breakpoint triggered",
1215                       JvmtiTrace::safe_get_thread_name(thread)));
1216   JvmtiEnvThreadStateIterator it(state);
1217   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1218     ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
1219     if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
1220       ThreadState old_os_state = thread->osthread()->get_state();
1221       thread->osthread()->set_state(BREAKPOINTED);
1222       EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("[%s] Evt Breakpoint sent %s.%s @ " INTX_FORMAT,
1223                      JvmtiTrace::safe_get_thread_name(thread),
1224                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1225                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1226                      location - mh()->code_base() ));
1227 
1228       JvmtiEnv *env = ets->get_env();
1229       JvmtiLocationEventMark jem(thread, mh, location);
1230       JvmtiJavaThreadEventTransition jet(thread);
1231       jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
1232       if (callback != NULL) {
1233         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1234                     jem.jni_methodID(), jem.location());
1235       }
1236 
1237       ets->set_breakpoint_posted();
1238       thread->osthread()->set_state(old_os_state);
1239     }
1240   }
1241 }
1242 
1243 //////////////////////////////////////////////////////////////////////////////
1244 
1245 bool              JvmtiExport::_can_get_source_debug_extension            = false;
1246 bool              JvmtiExport::_can_maintain_original_method_order        = false;
1247 bool              JvmtiExport::_can_post_interpreter_events               = false;
1248 bool              JvmtiExport::_can_post_on_exceptions                    = false;
1249 bool              JvmtiExport::_can_post_breakpoint                       = false;
1250 bool              JvmtiExport::_can_post_field_access                     = false;
1251 bool              JvmtiExport::_can_post_field_modification               = false;
1252 bool              JvmtiExport::_can_post_method_entry                     = false;
1253 bool              JvmtiExport::_can_post_method_exit                      = false;
1254 bool              JvmtiExport::_can_post_frame_pop                        = false;
1255 bool              JvmtiExport::_can_pop_frame                             = false;
1256 bool              JvmtiExport::_can_force_early_return                    = false;
1257 bool              JvmtiExport::_can_support_virtual_threads               = false;
1258 bool              JvmtiExport::_can_get_owned_monitor_info                = false;
1259 
1260 bool              JvmtiExport::_early_vmstart_recorded                    = false;
1261 
1262 bool              JvmtiExport::_should_post_single_step                   = false;
1263 bool              JvmtiExport::_should_post_field_access                  = false;
1264 bool              JvmtiExport::_should_post_field_modification            = false;
1265 bool              JvmtiExport::_should_post_class_load                    = false;
1266 bool              JvmtiExport::_should_post_class_prepare                 = false;
1267 bool              JvmtiExport::_should_post_class_unload                  = false;
1268 bool              JvmtiExport::_should_post_thread_life                   = false;
1269 bool              JvmtiExport::_should_clean_up_heap_objects              = false;
1270 bool              JvmtiExport::_should_post_native_method_bind            = false;
1271 bool              JvmtiExport::_should_post_dynamic_code_generated        = false;
1272 bool              JvmtiExport::_should_post_data_dump                     = false;
1273 bool              JvmtiExport::_should_post_compiled_method_load          = false;
1274 bool              JvmtiExport::_should_post_compiled_method_unload        = false;
1275 bool              JvmtiExport::_should_post_monitor_contended_enter       = false;
1276 bool              JvmtiExport::_should_post_monitor_contended_entered     = false;
1277 bool              JvmtiExport::_should_post_monitor_wait                  = false;
1278 bool              JvmtiExport::_should_post_monitor_waited                = false;
1279 bool              JvmtiExport::_should_post_garbage_collection_start      = false;
1280 bool              JvmtiExport::_should_post_garbage_collection_finish     = false;
1281 bool              JvmtiExport::_should_post_object_free                   = false;
1282 bool              JvmtiExport::_should_post_resource_exhausted            = false;
1283 bool              JvmtiExport::_should_post_vm_object_alloc               = false;
1284 bool              JvmtiExport::_should_post_sampled_object_alloc          = false;
1285 bool              JvmtiExport::_should_post_on_exceptions                 = false;
1286 bool              JvmtiExport::_should_post_vthread_start                 = false;
1287 bool              JvmtiExport::_should_post_vthread_end                   = false;
1288 bool              JvmtiExport::_should_post_vthread_mount                 = false;
1289 bool              JvmtiExport::_should_post_vthread_unmount               = false;
1290 
1291 ////////////////////////////////////////////////////////////////////////////////////////////////
1292 
1293 
1294 void JvmtiExport::check_suspend_at_safepoint(JavaThread *thread) {
1295   oop vt = thread->mounted_vthread();
1296 
1297   if (vt != NULL && java_lang_VirtualThread::is_instance(vt)) {
1298     HandleMark hm(thread);
1299     Handle vth = Handle(thread, vt);
1300 
1301     ThreadBlockInVM tbivm(thread);
1302     MonitorLocker ml(JvmtiVTMT_lock, Mutex::_no_safepoint_check_flag);
1303 
1304 #ifdef DBG // TMP
1305     JvmtiThreadState* state = thread->jvmti_thread_state();
1306 
1307     if (state != NULL) {
1308       printf("DBG: JvmtiExport::check_suspend_at_safepoint: state: %p virt: %d jt: %p vt-susp: %d ct-susp: %d\n",
1309              (void*)state, state->is_virtual(), (void*)thread,
1310              JvmtiVTSuspender::is_vthread_suspended(vt),
1311              thread->is_thread_suspended()
1312             );
1313       fflush(0);
1314     }
1315 #endif
1316     // block while vthread is externally suspended
1317     while (JvmtiVTSuspender::is_vthread_suspended(vth())) {
1318       ml.wait();
1319     }
1320   }
1321 }
1322 
1323 //
1324 // JVMTI single step management
1325 //
1326 void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, address location) {
1327   assert(JvmtiExport::should_post_single_step(), "must be single stepping");
1328 
1329   HandleMark hm(thread);
1330   methodHandle mh(thread, method);
1331 
1332   // update information about current location and post a step event
1333   JvmtiThreadState *state = thread->jvmti_thread_state();
1334   if (state == NULL) {
1335     return;
1336   }
1337   EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Trg Single Step triggered",
1338                       JvmtiTrace::safe_get_thread_name(thread)));
1339   if (!state->hide_single_stepping()) {
1340     if (state->is_pending_step_for_popframe()) {
1341       state->process_pending_step_for_popframe();
1342     }

1361   if (state != NULL && state->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1362     state->set_hide_single_stepping();
1363     return true;
1364   } else {
1365     return false;
1366   }
1367 }
1368 
1369 void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
1370   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1371     return;
1372   }
1373   HandleMark hm(thread);
1374 
1375   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Trg Class Load triggered",
1376                       JvmtiTrace::safe_get_thread_name(thread)));
1377   JvmtiThreadState* state = thread->jvmti_thread_state();
1378   if (state == NULL) {
1379     return;
1380   }
1381   if (thread->is_in_VTMT()) {
1382     return; // no events should be posted if thread is in a VTMT transition
1383   }
1384   JvmtiEnvThreadStateIterator it(state);
1385   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1386     if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) {
1387       JvmtiEnv *env = ets->get_env();
1388       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1389         continue;
1390       }
1391       EVT_TRACE(JVMTI_EVENT_CLASS_LOAD, ("[%s] Evt Class Load sent %s",
1392                                          JvmtiTrace::safe_get_thread_name(thread),
1393                                          klass==NULL? "NULL" : klass->external_name() ));
1394       JvmtiClassEventMark jem(thread, klass);
1395       JvmtiJavaThreadEventTransition jet(thread);
1396       jvmtiEventClassLoad callback = env->callbacks()->ClassLoad;
1397       if (callback != NULL) {
1398         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
1399       }
1400     }
1401   }
1402 }
1403 
1404 
1405 void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
1406   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1407     return;
1408   }
1409   HandleMark hm(thread);
1410 
1411   EVT_TRIG_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Trg Class Prepare triggered",
1412                       JvmtiTrace::safe_get_thread_name(thread)));
1413   JvmtiThreadState* state = thread->jvmti_thread_state();
1414   if (state == NULL) {
1415     return;
1416   }
1417   if (thread->is_in_VTMT()) {
1418     return; // no events should be posted if thread is in a VTMT transition
1419   }
1420   JvmtiEnvThreadStateIterator it(state);
1421   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1422     if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) {
1423       JvmtiEnv *env = ets->get_env();
1424       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1425         continue;
1426       }
1427       EVT_TRACE(JVMTI_EVENT_CLASS_PREPARE, ("[%s] Evt Class Prepare sent %s",
1428                                             JvmtiTrace::safe_get_thread_name(thread),
1429                                             klass==NULL? "NULL" : klass->external_name() ));
1430       JvmtiClassEventMark jem(thread, klass);
1431       JvmtiJavaThreadEventTransition jet(thread);
1432       jvmtiEventClassPrepare callback = env->callbacks()->ClassPrepare;
1433       if (callback != NULL) {
1434         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_class());
1435       }
1436     }
1437   }
1438 }
1439 

1489   assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
1490 
1491   EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Trg Thread Start event triggered",
1492                       JvmtiTrace::safe_get_thread_name(thread)));
1493 
1494   // do JVMTI thread initialization (if needed)
1495   JvmtiEventController::thread_started(thread);
1496 
1497   // Do not post thread start event for hidden java thread.
1498   if (JvmtiEventController::is_enabled(JVMTI_EVENT_THREAD_START) &&
1499       !thread->is_hidden_from_external_view()) {
1500     JvmtiEnvIterator it;
1501     for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
1502       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1503         continue;
1504       }
1505       if (env->is_enabled(JVMTI_EVENT_THREAD_START)) {
1506         EVT_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Evt Thread Start event sent",
1507                      JvmtiTrace::safe_get_thread_name(thread) ));
1508 
1509         JvmtiVirtualThreadEventMark jem(thread);
1510         JvmtiJavaThreadEventTransition jet(thread);
1511         jvmtiEventThreadStart callback = env->callbacks()->ThreadStart;
1512         if (callback != NULL) {
1513           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1514         }
1515       }
1516     }
1517   }
1518 }
1519 
1520 
1521 void JvmtiExport::post_thread_end(JavaThread *thread) {
1522   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1523     return;
1524   }
1525   EVT_TRIG_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Trg Thread End event triggered",
1526                       JvmtiTrace::safe_get_thread_name(thread)));
1527 
1528   JvmtiThreadState *state = thread->jvmti_thread_state();
1529   if (state == NULL) {
1530     return;
1531   }
1532 
1533   // Do not post thread end event for hidden java thread.
1534   if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
1535       !thread->is_hidden_from_external_view()) {
1536 
1537     JvmtiEnvThreadStateIterator it(state);
1538     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1539       if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
1540         JvmtiEnv *env = ets->get_env();
1541         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1542           continue;
1543         }
1544         EVT_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Evt Thread End event sent",
1545                      JvmtiTrace::safe_get_thread_name(thread) ));
1546 
1547         JvmtiVirtualThreadEventMark jem(thread);
1548         JvmtiJavaThreadEventTransition jet(thread);
1549         jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
1550         if (callback != NULL) {
1551           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1552         }
1553       }
1554     }
1555   }
1556 }
1557 
1558 
1559 void JvmtiExport::post_vthread_start(jobject vthread) {
1560   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1561     return;
1562   }
1563   EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_START, ("[%p] Trg Virtual Thread Start event triggered", vthread));
1564 
1565   JavaThread *cur_thread = JavaThread::current();
1566   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1567   if (state == NULL) {
1568     return;
1569   }
1570 
1571   if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_START)) {
1572     JvmtiEnvThreadStateIterator it(state);
1573 
1574     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1575       JvmtiEnv *env = ets->get_env();
1576       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1577         continue;
1578       }
1579       if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_START)) {
1580         EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_START, ("[%p] Evt Virtual Thread Start event sent", vthread));
1581 
1582         JvmtiVirtualThreadEventMark jem(cur_thread);
1583         JvmtiJavaThreadEventTransition jet(cur_thread);
1584         jvmtiEventVirtualThreadStart callback = env->callbacks()->VirtualThreadStart;
1585         if (callback != NULL) {
1586           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1587         }
1588       }
1589     }
1590   }
1591 }
1592 
1593 void JvmtiExport::post_vthread_end(jobject vthread) {
1594   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1595     return;
1596   }
1597   EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_END, ("[%p] Trg Virtual Thread End event triggered", vthread));
1598 
1599   JavaThread *cur_thread = JavaThread::current();
1600   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1601   if (state == NULL) {
1602     return;
1603   }
1604 
1605   if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_END)) {
1606     JvmtiEnvThreadStateIterator it(state);
1607 
1608     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1609       JvmtiEnv *env = ets->get_env();
1610       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1611         continue;
1612       }
1613       if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_END)) {
1614         EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_END, ("[%p] Evt Virtual Thread End event sent", vthread));
1615 
1616         JvmtiVirtualThreadEventMark jem(cur_thread);
1617         JvmtiJavaThreadEventTransition jet(cur_thread);
1618         jvmtiEventVirtualThreadEnd callback = env->callbacks()->VirtualThreadEnd;
1619         if (callback != NULL) {
1620           (*callback)(env->jvmti_external(), jem.jni_env(), vthread);
1621         }
1622       }
1623     }
1624   }
1625 }
1626 
1627 void JvmtiExport::post_vthread_mount(jobject vthread) {
1628   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1629     return;
1630   }
1631   JavaThread *thread = JavaThread::current();
1632   HandleMark hm(thread);
1633   EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_MOUNT, ("[%p] Trg Virtual Thread Mount event triggered", vthread));
1634 
1635   JvmtiThreadState *state = thread->jvmti_thread_state();
1636   if (state == NULL) {
1637     return;
1638   }
1639 
1640   if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_MOUNT)) {
1641     JvmtiEnvThreadStateIterator it(state);
1642 
1643     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1644       JvmtiEnv *env = ets->get_env();
1645       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1646         continue;
1647       }
1648       if (ets->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_MOUNT)) {
1649         EVT_TRACE(EXT_EVENT_VIRTUAL_THREAD_MOUNT, ("[%p] Evt Virtual Thread Mount event sent", vthread));
1650 
1651         JvmtiVirtualThreadEventMark jem(thread);
1652         JvmtiJavaThreadEventTransition jet(thread);
1653         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadMount;
1654         if (callback != NULL) {
1655           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1656         }
1657       }
1658     }
1659   }
1660 }
1661 
1662 void JvmtiExport::post_vthread_unmount(jobject vthread) {
1663   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1664     return;
1665   }
1666   JavaThread *thread = JavaThread::current();
1667   HandleMark hm(thread);
1668   EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Trg Virtual Thread Unmount event triggered", vthread));
1669 
1670   JvmtiThreadState *state = thread->jvmti_thread_state();
1671   if (state == NULL) {
1672     return;
1673   }
1674 
1675   if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1676     JvmtiEnvThreadStateIterator it(state);
1677 
1678     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1679       JvmtiEnv *env = ets->get_env();
1680       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1681         continue;
1682       }
1683       if (ets->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1684         EVT_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Evt Virtual Thread Unmount event sent", vthread));
1685 
1686         JvmtiVirtualThreadEventMark jem(thread);
1687         JvmtiJavaThreadEventTransition jet(thread);
1688         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadUnmount;
1689         if (callback != NULL) {
1690           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1691         }
1692       }
1693     }
1694   }
1695 }
1696 
1697 void JvmtiExport::continuation_yield_cleanup(JavaThread* thread, jint continuation_frame_count) {
1698   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1699     return;
1700   }
1701 
1702   assert (thread == JavaThread::current(), "must be");
1703   JvmtiThreadState *state = thread->jvmti_thread_state();
1704   if (state == NULL) {
1705     return;
1706   }
1707   state->invalidate_cur_stack_depth();
1708 
1709   // Clear frame_pop requests in frames popped by yield
1710   if (can_post_frame_pop()) {
1711     JvmtiEnvThreadStateIterator it(state);
1712     int top_frame_num = state->cur_stack_depth() + continuation_frame_count;
1713 
1714     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1715       if (!ets->has_frame_pops()) {
1716         continue;
1717       }
1718       for (int frame_idx = 0; frame_idx < continuation_frame_count; frame_idx++) {
1719         int frame_num = top_frame_num - frame_idx;
1720 
1721         if (!state->is_virtual() && ets->is_frame_pop(frame_num)) {
1722           // remove the frame's entry
1723           MutexLocker mu(JvmtiThreadState_lock);
1724           ets->clear_frame_pop(frame_num);
1725         }
1726       } 
1727     }
1728   }
1729 }
1730 
1731 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
1732   assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
1733 
1734   EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Trg Object Free triggered" ));
1735   EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Evt Object Free sent"));
1736 
1737   jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
1738   if (callback != NULL) {
1739     (*callback)(env->jvmti_external(), tag);
1740   }
1741 }
1742 
1743 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
1744 
1745   JavaThread *thread  = JavaThread::current();
1746 
1747   log_error(jvmti)("Posting Resource Exhausted event: %s",
1748                    description != nullptr ? description : "unknown");
1749 
1750   // JDK-8213834: handlers of ResourceExhausted may attempt some analysis

1771                     resource_exhausted_flags, NULL, description);
1772       }
1773     }
1774   }
1775 }
1776 
1777 void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame current_frame) {
1778   HandleMark hm(thread);
1779   methodHandle mh(thread, method);
1780 
1781   EVT_TRIG_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("[%s] Trg Method Entry triggered %s.%s",
1782                      JvmtiTrace::safe_get_thread_name(thread),
1783                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1784                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
1785 
1786   JvmtiThreadState* state = thread->jvmti_thread_state();
1787   if (state == NULL || !state->is_interp_only_mode()) {
1788     // for any thread that actually wants method entry, interp_only_mode is set
1789     return;
1790   }
1791   if (mh->jvmti_mount_transition() || thread->is_in_VTMT()) {
1792     return; // no events should be posted if thread is in a VTMT transition
1793   }
1794 
1795   state->incr_cur_stack_depth();
1796 
1797   if (state->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
1798     JvmtiEnvThreadStateIterator it(state);
1799     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1800       if (ets->is_enabled(JVMTI_EVENT_METHOD_ENTRY)) {
1801         EVT_TRACE(JVMTI_EVENT_METHOD_ENTRY, ("[%s] Evt Method Entry sent %s.%s",
1802                                              JvmtiTrace::safe_get_thread_name(thread),
1803                                              (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1804                                              (mh() == NULL) ? "NULL" : mh()->name()->as_C_string() ));
1805 
1806         JvmtiEnv *env = ets->get_env();
1807         JvmtiMethodEventMark jem(thread, mh);
1808         JvmtiJavaThreadEventTransition jet(thread);
1809         jvmtiEventMethodEntry callback = env->callbacks()->MethodEntry;
1810         if (callback != NULL) {
1811           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_methodID());
1812         }
1813       }
1814     }
1815   }
1816 }
1817 
1818 void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame current_frame) {
1819   HandleMark hm(thread);
1820   methodHandle mh(thread, method);
1821 
1822   JvmtiThreadState *state = thread->jvmti_thread_state();
1823 
1824   if (state == NULL || !state->is_interp_only_mode()) {
1825     // for any thread that actually wants method exit, interp_only_mode is set
1826     return;
1827   }
1828   if (mh->jvmti_mount_transition() || thread->is_in_VTMT()) {
1829     return; // no events should be posted if thread is in a VTMT transition
1830   }
1831 
1832   // return a flag when a method terminates by throwing an exception
1833   // i.e. if an exception is thrown and it's not caught by the current method
1834   bool exception_exit = state->is_exception_detected() && !state->is_exception_caught();
1835   Handle result;
1836   jvalue value;
1837   value.j = 0L;
1838 
1839   if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) {
1840     // if the method hasn't been popped because of an exception then we populate
1841     // the return_value parameter for the callback. At this point we only have
1842     // the address of a "raw result" and we just call into the interpreter to
1843     // convert this into a jvalue.
1844     if (!exception_exit) {
1845       oop oop_result;
1846       BasicType type = current_frame.interpreter_frame_result(&oop_result, &value);
1847       if (is_reference_type(type)) {
1848         result = Handle(thread, oop_result);
1849         value.l = JNIHandles::make_local(thread, result());
1850       }

1914           // we also need to issue a frame pop event for this frame
1915           JvmtiEnv *env = ets->get_env();
1916           JvmtiMethodEventMark jem(thread, mh);
1917           JvmtiJavaThreadEventTransition jet(thread);
1918           jvmtiEventFramePop callback = env->callbacks()->FramePop;
1919           if (callback != NULL) {
1920             (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1921                         jem.jni_methodID(), exception_exit);
1922           }
1923         }
1924         // remove the frame's entry
1925         {
1926           MutexLocker mu(JvmtiThreadState_lock);
1927           ets->clear_frame_pop(cur_frame_number);
1928         }
1929       }
1930     }
1931   }
1932 
1933   state->decr_cur_stack_depth();
1934 
1935 }
1936 
1937 
1938 // Todo: inline this for optimization
1939 void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address location) {
1940   HandleMark hm(thread);
1941   methodHandle mh(thread, method);
1942 
1943   JvmtiThreadState *state = thread->jvmti_thread_state();
1944   if (state == NULL) {
1945     return;
1946   }
1947   if (mh->jvmti_mount_transition() || thread->is_in_VTMT()) {
1948     return; // no events should be posted if thread is in a VTMT transition
1949   }
1950 
1951   JvmtiEnvThreadStateIterator it(state);
1952   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1953     ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
1954     if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1955       EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Evt Single Step sent %s.%s @ " INTX_FORMAT,
1956                     JvmtiTrace::safe_get_thread_name(thread),
1957                     (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1958                     (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1959                     location - mh()->code_base() ));
1960 
1961       JvmtiEnv *env = ets->get_env();
1962       JvmtiLocationEventMark jem(thread, mh, location);
1963       JvmtiJavaThreadEventTransition jet(thread);
1964       jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
1965       if (callback != NULL) {
1966         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1967                     jem.jni_methodID(), jem.location());
1968       }
1969 
1970       ets->set_single_stepping_posted();
1971     }
1972   }
1973 }
1974 
1975 void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, address location, oop exception) {
1976   HandleMark hm(thread);
1977   methodHandle mh(thread, method);
1978   Handle exception_handle(thread, exception);
1979 
1980   JvmtiThreadState *state = thread->jvmti_thread_state();
1981   if (state == NULL) {
1982     return;
1983   }
1984   if (thread->is_in_VTMT()) {
1985     return; // no events should be posted if thread is in a VTMT transition
1986   }
1987 
1988   EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("[%s] Trg Exception thrown triggered",
1989                       JvmtiTrace::safe_get_thread_name(thread)));
1990   if (!state->is_exception_detected()) {
1991     state->set_exception_detected();
1992     JvmtiEnvThreadStateIterator it(state);
1993     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1994       if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
1995 
1996         EVT_TRACE(JVMTI_EVENT_EXCEPTION,
1997                      ("[%s] Evt Exception thrown sent %s.%s @ " INTX_FORMAT,
1998                       JvmtiTrace::safe_get_thread_name(thread),
1999                       (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
2000                       (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
2001                       location - mh()->code_base() ));
2002 
2003         JvmtiEnv *env = ets->get_env();
2004         JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
2005 
2006         // It's okay to clear these exceptions here because we duplicate

2129 }
2130 
2131 oop JvmtiExport::jni_GetField_probe(JavaThread *thread, jobject jobj, oop obj,
2132                                     Klass* klass, jfieldID fieldID, bool is_static) {
2133   if (*((int *)get_field_access_count_addr()) > 0 && thread->has_last_Java_frame()) {
2134     // At least one field access watch is set so we have more work to do.
2135     post_field_access_by_jni(thread, obj, klass, fieldID, is_static);
2136     // event posting can block so refetch oop if we were passed a jobj
2137     if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
2138   }
2139   return obj;
2140 }
2141 
2142 void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj,
2143                                            Klass* klass, jfieldID fieldID, bool is_static) {
2144   // We must be called with a Java context in order to provide reasonable
2145   // values for the klazz, method, and location fields. The callers of this
2146   // function don't make the call unless there is a Java context.
2147   assert(thread->has_last_Java_frame(), "must be called with a Java context");
2148 
2149   if (thread->is_in_VTMT()) {
2150     return; // no events should be posted if thread is in a VTMT transition
2151   }
2152 
2153   ResourceMark rm;
2154   fieldDescriptor fd;
2155   // if get_field_descriptor finds fieldID to be invalid, then we just bail
2156   bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
2157   assert(valid_fieldID == true,"post_field_access_by_jni called with invalid fieldID");
2158   if (!valid_fieldID) return;
2159   // field accesses are not watched so bail
2160   if (!fd.is_field_access_watched()) return;
2161 
2162   HandleMark hm(thread);
2163   Handle h_obj;
2164   if (!is_static) {
2165     // non-static field accessors have an object, but we need a handle
2166     assert(obj != NULL, "non-static needs an object");
2167     h_obj = Handle(thread, obj);
2168   }
2169   post_field_access(thread,
2170                     thread->last_frame().interpreter_frame_method(),
2171                     thread->last_frame().interpreter_frame_bcp(),
2172                     klass, h_obj, fieldID);
2173 }
2174 
2175 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
2176   address location, Klass* field_klass, Handle object, jfieldID field) {
2177 
2178   HandleMark hm(thread);
2179   methodHandle mh(thread, method);
2180 
2181   JvmtiThreadState *state = thread->jvmti_thread_state();
2182   if (state == NULL) {
2183     return;
2184   }
2185   if (thread->is_in_VTMT()) {
2186     return; // no events should be posted if thread is in a VTMT transition
2187   }
2188 
2189   EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("[%s] Trg Field Access event triggered",
2190                       JvmtiTrace::safe_get_thread_name(thread)));
2191   JvmtiEnvThreadStateIterator it(state);
2192   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2193     if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
2194       EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("[%s] Evt Field Access event sent %s.%s @ " INTX_FORMAT,
2195                      JvmtiTrace::safe_get_thread_name(thread),
2196                      (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
2197                      (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
2198                      location - mh()->code_base() ));
2199 
2200       JvmtiEnv *env = ets->get_env();
2201       JvmtiLocationEventMark jem(thread, mh, location);
2202       jclass field_jclass = jem.to_jclass(field_klass);
2203       jobject field_jobject = jem.to_jobject(object());
2204       JvmtiJavaThreadEventTransition jet(thread);
2205       jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
2206       if (callback != NULL) {
2207         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2208                     jem.jni_methodID(), jem.location(),

2215 oop JvmtiExport::jni_SetField_probe(JavaThread *thread, jobject jobj, oop obj,
2216                                     Klass* klass, jfieldID fieldID, bool is_static,
2217                                     char sig_type, jvalue *value) {
2218   if (*((int *)get_field_modification_count_addr()) > 0 && thread->has_last_Java_frame()) {
2219     // At least one field modification watch is set so we have more work to do.
2220     post_field_modification_by_jni(thread, obj, klass, fieldID, is_static, sig_type, value);
2221     // event posting can block so refetch oop if we were passed a jobj
2222     if (jobj != NULL) return JNIHandles::resolve_non_null(jobj);
2223   }
2224   return obj;
2225 }
2226 
2227 void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj,
2228                                                  Klass* klass, jfieldID fieldID, bool is_static,
2229                                                  char sig_type, jvalue *value) {
2230   // We must be called with a Java context in order to provide reasonable
2231   // values for the klazz, method, and location fields. The callers of this
2232   // function don't make the call unless there is a Java context.
2233   assert(thread->has_last_Java_frame(), "must be called with Java context");
2234 
2235   if (thread->is_in_VTMT()) {
2236     return; // no events should be posted if thread is in a VTMT transition
2237   }                   
2238 
2239   ResourceMark rm;
2240   fieldDescriptor fd;
2241   // if get_field_descriptor finds fieldID to be invalid, then we just bail
2242   bool valid_fieldID = JvmtiEnv::get_field_descriptor(klass, fieldID, &fd);
2243   assert(valid_fieldID == true,"post_field_modification_by_jni called with invalid fieldID");
2244   if (!valid_fieldID) return;
2245   // field modifications are not watched so bail
2246   if (!fd.is_field_modification_watched()) return;
2247 
2248   HandleMark hm(thread);
2249 
2250   Handle h_obj;
2251   if (!is_static) {
2252     // non-static field accessors have an object, but we need a handle
2253     assert(obj != NULL, "non-static needs an object");
2254     h_obj = Handle(thread, obj);
2255   }
2256   post_field_modification(thread,
2257                           thread->last_frame().interpreter_frame_method(),
2258                           thread->last_frame().interpreter_frame_bcp(),
2259                           klass, h_obj, fieldID, sig_type, value);
2260 }
2261 
2262 void JvmtiExport::post_raw_field_modification(JavaThread *thread, Method* method,
2263   address location, Klass* field_klass, Handle object, jfieldID field,
2264   char sig_type, jvalue *value) {
2265 
2266   if (thread->is_in_VTMT()) {
2267     return; // no events should be posted if thread is in a VTMT transition
2268   }
2269 
2270   if (sig_type == JVM_SIGNATURE_INT || sig_type == JVM_SIGNATURE_BOOLEAN ||
2271       sig_type == JVM_SIGNATURE_BYTE || sig_type == JVM_SIGNATURE_CHAR ||
2272       sig_type == JVM_SIGNATURE_SHORT) {
2273     // 'I' instructions are used for byte, char, short and int.
2274     // determine which it really is, and convert
2275     fieldDescriptor fd;
2276     bool found = JvmtiEnv::get_field_descriptor(field_klass, field, &fd);
2277     // should be found (if not, leave as is)
2278     if (found) {
2279       jint ival = value->i;
2280       // convert value from int to appropriate type
2281       switch (fd.field_type()) {
2282       case T_BOOLEAN:
2283         sig_type = JVM_SIGNATURE_BOOLEAN;
2284         value->i = 0; // clear it
2285         value->z = (jboolean)ival;
2286         break;
2287       case T_BYTE:
2288         sig_type = JVM_SIGNATURE_BYTE;
2289         value->i = 0; // clear it

2321 
2322   post_field_modification(thread, method, location, field_klass, object, field, sig_type, value);
2323 
2324   // Destroy the JNI handle allocated above.
2325   if (handle_created) {
2326     JNIHandles::destroy_local(value->l);
2327   }
2328 }
2329 
2330 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
2331   address location, Klass* field_klass, Handle object, jfieldID field,
2332   char sig_type, jvalue *value_ptr) {
2333 
2334   HandleMark hm(thread);
2335   methodHandle mh(thread, method);
2336 
2337   JvmtiThreadState *state = thread->jvmti_thread_state();
2338   if (state == NULL) {
2339     return;
2340   }
2341   if (thread->is_in_VTMT()) {
2342     return; // no events should be posted if thread is in a VTMT transition
2343   }
2344 
2345   EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
2346                      ("[%s] Trg Field Modification event triggered",
2347                       JvmtiTrace::safe_get_thread_name(thread)));
2348 
2349   JvmtiEnvThreadStateIterator it(state);
2350   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2351     if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
2352       EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
2353                    ("[%s] Evt Field Modification event sent %s.%s @ " INTX_FORMAT,
2354                     JvmtiTrace::safe_get_thread_name(thread),
2355                     (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
2356                     (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
2357                     location - mh()->code_base() ));
2358 
2359       JvmtiEnv *env = ets->get_env();
2360       JvmtiLocationEventMark jem(thread, mh, location);
2361       jclass field_jclass = jem.to_jclass(field_klass);
2362       jobject field_jobject = jem.to_jobject(object());
2363       JvmtiJavaThreadEventTransition jet(thread);
2364       jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
2365       if (callback != NULL) {
2366         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2367                     jem.jni_methodID(), jem.location(),
2368                     field_jclass, field_jobject, field, sig_type, *value_ptr);
2369       }
2370     }
2371   }
2372 }
2373 
2374 void JvmtiExport::post_native_method_bind(Method* method, address* function_ptr) {
2375   JavaThread* thread = JavaThread::current();
2376   assert(thread->thread_state() == _thread_in_vm, "must be in vm state");
2377 
2378   HandleMark hm(thread);
2379   methodHandle mh(thread, method);
2380 
2381   EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("[%s] Trg Native Method Bind event triggered",
2382                       JvmtiTrace::safe_get_thread_name(thread)));
2383 
2384   if (thread->is_in_VTMT()) {
2385     return; // no events should be posted if thread is in a VTMT transition
2386   }
2387 
2388   if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
2389     JvmtiEnvIterator it;
2390     for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2391       if (env->is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
2392         EVT_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("[%s] Evt Native Method Bind event sent",
2393                      JvmtiTrace::safe_get_thread_name(thread) ));
2394 
2395         JvmtiMethodEventMark jem(thread, mh);
2396         JvmtiJavaThreadEventTransition jet(thread);
2397         JNIEnv* jni_env = (env->phase() == JVMTI_PHASE_PRIMORDIAL) ? NULL : jem.jni_env();
2398         jvmtiEventNativeMethodBind callback = env->callbacks()->NativeMethodBind;
2399         if (callback != NULL) {
2400           (*callback)(env->jvmti_external(), jni_env, jem.jni_thread(),
2401                       jem.jni_methodID(), (void*)(*function_ptr), (void**)function_ptr);
2402         }
2403       }
2404     }
2405   }
2406 }
2407 

2674     if (env->is_enabled(JVMTI_EVENT_DATA_DUMP_REQUEST)) {
2675       EVT_TRACE(JVMTI_EVENT_DATA_DUMP_REQUEST,
2676                 ("[%s] data dump request event sent",
2677                  JvmtiTrace::safe_get_thread_name(thread)));
2678      JvmtiThreadEventTransition jet(thread);
2679      // JNIEnv is NULL here because this event is posted from VM Thread
2680      jvmtiEventDataDumpRequest callback = env->callbacks()->DataDumpRequest;
2681      if (callback != NULL) {
2682        (*callback)(env->jvmti_external());
2683      }
2684     }
2685   }
2686 }
2687 
2688 void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor *obj_mntr) {
2689   oop object = obj_mntr->object();
2690   JvmtiThreadState *state = thread->jvmti_thread_state();
2691   if (state == NULL) {
2692     return;
2693   }
2694   if (thread->is_in_VTMT()) {
2695     return; // no events should be posted if thread is in a VTMT transition
2696   }
2697 
2698   HandleMark hm(thread);
2699   Handle h(thread, object);
2700 
2701   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2702                      ("[%s] monitor contended enter event triggered",
2703                       JvmtiTrace::safe_get_thread_name(thread)));
2704 
2705   JvmtiEnvThreadStateIterator it(state);
2706   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2707     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTER)) {
2708       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2709                    ("[%s] monitor contended enter event sent",
2710                     JvmtiTrace::safe_get_thread_name(thread)));
2711       JvmtiMonitorEventMark  jem(thread, h());
2712       JvmtiEnv *env = ets->get_env();
2713       JvmtiThreadEventTransition jet(thread);
2714       jvmtiEventMonitorContendedEnter callback = env->callbacks()->MonitorContendedEnter;
2715       if (callback != NULL) {
2716         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2717       }
2718     }
2719   }
2720 }
2721 
2722 void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonitor *obj_mntr) {
2723   oop object = obj_mntr->object();
2724   JvmtiThreadState *state = thread->jvmti_thread_state();
2725   if (state == NULL) {
2726     return;
2727   }
2728   if (thread->is_in_VTMT()) {
2729     return; // no events should be posted if thread is in a VTMT transition
2730   }
2731 
2732   HandleMark hm(thread);
2733   Handle h(thread, object);
2734 
2735   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2736                      ("[%s] monitor contended entered event triggered",
2737                       JvmtiTrace::safe_get_thread_name(thread)));
2738 
2739   JvmtiEnvThreadStateIterator it(state);
2740   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2741     if (ets->is_enabled(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED)) {
2742       EVT_TRACE(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2743                    ("[%s] monitor contended enter event sent",
2744                     JvmtiTrace::safe_get_thread_name(thread)));
2745       JvmtiMonitorEventMark  jem(thread, h());
2746       JvmtiEnv *env = ets->get_env();
2747       JvmtiThreadEventTransition jet(thread);
2748       jvmtiEventMonitorContendedEntered callback = env->callbacks()->MonitorContendedEntered;
2749       if (callback != NULL) {
2750         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), jem.jni_object());
2751       }
2752     }
2753   }
2754 }
2755 
2756 void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
2757                                           jlong timeout) {
2758   JvmtiThreadState *state = thread->jvmti_thread_state();
2759   if (state == NULL) {
2760     return;
2761   }
2762   if (thread->is_in_VTMT()) {
2763     return; // no events should be posted if thread is in a VTMT transition
2764   }
2765 
2766   HandleMark hm(thread);
2767   Handle h(thread, object);
2768 
2769   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2770                      ("[%s] monitor wait event triggered",
2771                       JvmtiTrace::safe_get_thread_name(thread)));
2772 
2773   JvmtiEnvThreadStateIterator it(state);
2774   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2775     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAIT)) {
2776       EVT_TRACE(JVMTI_EVENT_MONITOR_WAIT,
2777                    ("[%s] monitor wait event sent",
2778                     JvmtiTrace::safe_get_thread_name(thread)));
2779       JvmtiMonitorEventMark  jem(thread, h());
2780       JvmtiEnv *env = ets->get_env();
2781       JvmtiThreadEventTransition jet(thread);
2782       jvmtiEventMonitorWait callback = env->callbacks()->MonitorWait;
2783       if (callback != NULL) {
2784         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2785                     jem.jni_object(), timeout);
2786       }
2787     }
2788   }
2789 }
2790 
2791 void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2792   oop object = obj_mntr->object();
2793   JvmtiThreadState *state = thread->jvmti_thread_state();
2794   if (state == NULL) {
2795     return;
2796   }
2797   if (thread->is_in_VTMT()) {
2798     return; // no events should be posted if thread is in a VTMT transition
2799   }
2800 
2801   HandleMark hm(thread);
2802   Handle h(thread, object);
2803 
2804   EVT_TRIG_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2805                      ("[%s] monitor waited event triggered",
2806                       JvmtiTrace::safe_get_thread_name(thread)));
2807 
2808   JvmtiEnvThreadStateIterator it(state);
2809   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2810     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2811       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2812                    ("[%s] monitor waited event sent",
2813                     JvmtiTrace::safe_get_thread_name(thread)));
2814       JvmtiMonitorEventMark  jem(thread, h());
2815       JvmtiEnv *env = ets->get_env();
2816       JvmtiThreadEventTransition jet(thread);
2817       jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
2818       if (callback != NULL) {
2819         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2820                     jem.jni_object(), timed_out);
2821       }
2822     }
2823   }
2824 }
2825 
2826 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2827   EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2828                       JvmtiTrace::safe_get_thread_name(thread)));
2829   if (object == NULL) {
2830     return;
2831   }
2832   if (thread->is_in_VTMT()) {
2833     return; // no events should be posted if thread is in a VTMT transition
2834   }
2835   HandleMark hm(thread);
2836   Handle h(thread, object);
2837   JvmtiEnvIterator it;
2838   for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
2839     if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
2840       EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2841                                          JvmtiTrace::safe_get_thread_name(thread),
2842                                          object==NULL? "NULL" : object->klass()->external_name()));
2843 
2844       JvmtiObjectAllocEventMark jem(thread, h());
2845       JvmtiJavaThreadEventTransition jet(thread);
2846       jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
2847       if (callback != NULL) {
2848         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2849                     jem.jni_jobject(), jem.jni_class(), jem.size());
2850       }
2851     }
2852   }
2853 }
2854 
2855 void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
2856   JvmtiThreadState *state = thread->jvmti_thread_state();
2857   if (state == NULL) {
2858     return;
2859   }
2860 
2861   EVT_TRIG_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2862                  ("[%s] Trg sampled object alloc triggered",
2863                   JvmtiTrace::safe_get_thread_name(thread)));
2864   if (object == NULL) {
2865     return;
2866   }
2867   if (thread->is_in_VTMT()) {
2868     return; // no events should be posted if thread is in a VTMT transition
2869   }
2870   HandleMark hm(thread);
2871   Handle h(thread, object);
2872 
2873   JvmtiEnvThreadStateIterator it(state);
2874   for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
2875     if (ets->is_enabled(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC)) {
2876       EVT_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2877                 ("[%s] Evt sampled object alloc sent %s",
2878                  JvmtiTrace::safe_get_thread_name(thread),
2879                  object == NULL ? "NULL" : object->klass()->external_name()));
2880 
2881       JvmtiEnv *env = ets->get_env();
2882       JvmtiObjectAllocEventMark jem(thread, h());
2883       JvmtiJavaThreadEventTransition jet(thread);
2884       jvmtiEventSampledObjectAlloc callback = env->callbacks()->SampledObjectAlloc;
2885       if (callback != NULL) {
2886         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2887                     jem.jni_jobject(), jem.jni_class(), jem.size());
2888       }
2889     }
< prev index next >