< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page




1183                     jem.jni_methodID(), jem.location());
1184       }
1185 
1186       ets->set_breakpoint_posted();
1187       thread->osthread()->set_state(old_os_state);
1188     }
1189   }
1190 }
1191 
1192 //////////////////////////////////////////////////////////////////////////////
1193 
1194 bool              JvmtiExport::_can_get_source_debug_extension            = false;
1195 bool              JvmtiExport::_can_maintain_original_method_order        = false;
1196 bool              JvmtiExport::_can_post_interpreter_events               = false;
1197 bool              JvmtiExport::_can_post_on_exceptions                    = false;
1198 bool              JvmtiExport::_can_post_breakpoint                       = false;
1199 bool              JvmtiExport::_can_post_field_access                     = false;
1200 bool              JvmtiExport::_can_post_field_modification               = false;
1201 bool              JvmtiExport::_can_post_method_entry                     = false;
1202 bool              JvmtiExport::_can_post_method_exit                      = false;

1203 bool              JvmtiExport::_can_pop_frame                             = false;
1204 bool              JvmtiExport::_can_force_early_return                    = false;


1205 
1206 bool              JvmtiExport::_early_vmstart_recorded                    = false;
1207 
1208 bool              JvmtiExport::_should_post_single_step                   = false;
1209 bool              JvmtiExport::_should_post_field_access                  = false;
1210 bool              JvmtiExport::_should_post_field_modification            = false;
1211 bool              JvmtiExport::_should_post_class_load                    = false;
1212 bool              JvmtiExport::_should_post_class_prepare                 = false;
1213 bool              JvmtiExport::_should_post_class_unload                  = false;
1214 bool              JvmtiExport::_should_post_thread_life                   = false;
1215 bool              JvmtiExport::_should_clean_up_heap_objects              = false;
1216 bool              JvmtiExport::_should_post_native_method_bind            = false;
1217 bool              JvmtiExport::_should_post_dynamic_code_generated        = false;
1218 bool              JvmtiExport::_should_post_data_dump                     = false;
1219 bool              JvmtiExport::_should_post_compiled_method_load          = false;
1220 bool              JvmtiExport::_should_post_compiled_method_unload        = false;
1221 bool              JvmtiExport::_should_post_monitor_contended_enter       = false;
1222 bool              JvmtiExport::_should_post_monitor_contended_entered     = false;
1223 bool              JvmtiExport::_should_post_monitor_wait                  = false;
1224 bool              JvmtiExport::_should_post_monitor_waited                = false;
1225 bool              JvmtiExport::_should_post_garbage_collection_start      = false;
1226 bool              JvmtiExport::_should_post_garbage_collection_finish     = false;
1227 bool              JvmtiExport::_should_post_object_free                   = false;
1228 bool              JvmtiExport::_should_post_resource_exhausted            = false;
1229 bool              JvmtiExport::_should_post_vm_object_alloc               = false;
1230 bool              JvmtiExport::_should_post_sampled_object_alloc          = false;
1231 bool              JvmtiExport::_should_post_on_exceptions                 = false;






1232 
1233 ////////////////////////////////////////////////////////////////////////////////////////////////
1234 
1235 
1236 //
1237 // JVMTI single step management
1238 //
1239 void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, address location) {
1240   assert(JvmtiExport::should_post_single_step(), "must be single stepping");
1241 
1242   HandleMark hm(thread);
1243   methodHandle mh(thread, method);
1244 
1245   // update information about current location and post a step event
1246   JvmtiThreadState *state = thread->jvmti_thread_state();
1247   if (state == NULL) {
1248     return;
1249   }
1250   EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Trg Single Step triggered",
1251                       JvmtiTrace::safe_get_thread_name(thread)));


1454   if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
1455       !thread->is_hidden_from_external_view()) {
1456 
1457     JvmtiEnvThreadStateIterator it(state);
1458     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1459       if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
1460         JvmtiEnv *env = ets->get_env();
1461         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1462           continue;
1463         }
1464         EVT_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Evt Thread End event sent",
1465                      JvmtiTrace::safe_get_thread_name(thread) ));
1466 
1467         JvmtiThreadEventMark jem(thread);
1468         JvmtiJavaThreadEventTransition jet(thread);
1469         jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
1470         if (callback != NULL) {
1471           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1472         }
1473       }



































































































































































































































1474     }
1475   }
1476 }
1477 
1478 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
1479   assert(SafepointSynchronize::is_at_safepoint(), "must be executed at safepoint");
1480   assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
1481 
1482   EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Trg Object Free triggered" ));
1483   EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Evt Object Free sent"));
1484 
1485   jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
1486   if (callback != NULL) {
1487     (*callback)(env->jvmti_external(), tag);
1488   }
1489 }
1490 
1491 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
1492 
1493   JavaThread *thread  = JavaThread::current();




1183                     jem.jni_methodID(), jem.location());
1184       }
1185 
1186       ets->set_breakpoint_posted();
1187       thread->osthread()->set_state(old_os_state);
1188     }
1189   }
1190 }
1191 
1192 //////////////////////////////////////////////////////////////////////////////
1193 
1194 bool              JvmtiExport::_can_get_source_debug_extension            = false;
1195 bool              JvmtiExport::_can_maintain_original_method_order        = false;
1196 bool              JvmtiExport::_can_post_interpreter_events               = false;
1197 bool              JvmtiExport::_can_post_on_exceptions                    = false;
1198 bool              JvmtiExport::_can_post_breakpoint                       = false;
1199 bool              JvmtiExport::_can_post_field_access                     = false;
1200 bool              JvmtiExport::_can_post_field_modification               = false;
1201 bool              JvmtiExport::_can_post_method_entry                     = false;
1202 bool              JvmtiExport::_can_post_method_exit                      = false;
1203 bool              JvmtiExport::_can_post_frame_pop                        = false;
1204 bool              JvmtiExport::_can_pop_frame                             = false;
1205 bool              JvmtiExport::_can_force_early_return                    = false;
1206 bool              JvmtiExport::_can_support_fibers                        = false;
1207 bool              JvmtiExport::_can_support_continuations                 = false;
1208 
1209 bool              JvmtiExport::_early_vmstart_recorded                    = false;
1210 
1211 bool              JvmtiExport::_should_post_single_step                   = false;
1212 bool              JvmtiExport::_should_post_field_access                  = false;
1213 bool              JvmtiExport::_should_post_field_modification            = false;
1214 bool              JvmtiExport::_should_post_class_load                    = false;
1215 bool              JvmtiExport::_should_post_class_prepare                 = false;
1216 bool              JvmtiExport::_should_post_class_unload                  = false;
1217 bool              JvmtiExport::_should_post_thread_life                   = false;
1218 bool              JvmtiExport::_should_clean_up_heap_objects              = false;
1219 bool              JvmtiExport::_should_post_native_method_bind            = false;
1220 bool              JvmtiExport::_should_post_dynamic_code_generated        = false;
1221 bool              JvmtiExport::_should_post_data_dump                     = false;
1222 bool              JvmtiExport::_should_post_compiled_method_load          = false;
1223 bool              JvmtiExport::_should_post_compiled_method_unload        = false;
1224 bool              JvmtiExport::_should_post_monitor_contended_enter       = false;
1225 bool              JvmtiExport::_should_post_monitor_contended_entered     = false;
1226 bool              JvmtiExport::_should_post_monitor_wait                  = false;
1227 bool              JvmtiExport::_should_post_monitor_waited                = false;
1228 bool              JvmtiExport::_should_post_garbage_collection_start      = false;
1229 bool              JvmtiExport::_should_post_garbage_collection_finish     = false;
1230 bool              JvmtiExport::_should_post_object_free                   = false;
1231 bool              JvmtiExport::_should_post_resource_exhausted            = false;
1232 bool              JvmtiExport::_should_post_vm_object_alloc               = false;
1233 bool              JvmtiExport::_should_post_sampled_object_alloc          = false;
1234 bool              JvmtiExport::_should_post_on_exceptions                 = false;
1235 bool              JvmtiExport::_should_post_continuation_run              = false;
1236 bool              JvmtiExport::_should_post_continuation_yield            = false;
1237 bool              JvmtiExport::_should_post_fiber_scheduled               = false;
1238 bool              JvmtiExport::_should_post_fiber_terminated              = false;
1239 bool              JvmtiExport::_should_post_fiber_mount                   = false;
1240 bool              JvmtiExport::_should_post_fiber_unmount                 = false;
1241 
1242 ////////////////////////////////////////////////////////////////////////////////////////////////
1243 
1244 
1245 //
1246 // JVMTI single step management
1247 //
1248 void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, address location) {
1249   assert(JvmtiExport::should_post_single_step(), "must be single stepping");
1250 
1251   HandleMark hm(thread);
1252   methodHandle mh(thread, method);
1253 
1254   // update information about current location and post a step event
1255   JvmtiThreadState *state = thread->jvmti_thread_state();
1256   if (state == NULL) {
1257     return;
1258   }
1259   EVT_TRIG_TRACE(JVMTI_EVENT_SINGLE_STEP, ("[%s] Trg Single Step triggered",
1260                       JvmtiTrace::safe_get_thread_name(thread)));


1463   if (state->is_enabled(JVMTI_EVENT_THREAD_END) &&
1464       !thread->is_hidden_from_external_view()) {
1465 
1466     JvmtiEnvThreadStateIterator it(state);
1467     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1468       if (ets->is_enabled(JVMTI_EVENT_THREAD_END)) {
1469         JvmtiEnv *env = ets->get_env();
1470         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1471           continue;
1472         }
1473         EVT_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Evt Thread End event sent",
1474                      JvmtiTrace::safe_get_thread_name(thread) ));
1475 
1476         JvmtiThreadEventMark jem(thread);
1477         JvmtiJavaThreadEventTransition jet(thread);
1478         jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
1479         if (callback != NULL) {
1480           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1481         }
1482       }
1483     }
1484   }
1485 }
1486 
1487 
1488 void JvmtiExport::post_fiber_scheduled(jthread thread, jobject fiber) {
1489   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1490     return;
1491   }
1492   EVT_TRIG_TRACE(JVMTI_EVENT_FIBER_SCHEDULED, ("[%p] Trg Fiber Scheduled event triggered", fiber));
1493 
1494   JavaThread *cur_thread = JavaThread::current();
1495   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1496   if (state == NULL) {
1497     return;
1498   }
1499 
1500   if (state->is_enabled(JVMTI_EVENT_FIBER_SCHEDULED)) {
1501     JvmtiEnvThreadStateIterator it(state);
1502 
1503     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1504       if (ets->is_enabled(JVMTI_EVENT_FIBER_SCHEDULED)) {
1505         JvmtiEnv *env = ets->get_env();
1506         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1507           continue;
1508         }
1509         EVT_TRACE(JVMTI_EVENT_FIBER_SCHEDULED, ("[%p] Evt Fiber Scheduled event sent", fiber));
1510 
1511         JvmtiThreadEventMark jem(cur_thread);
1512         JvmtiJavaThreadEventTransition jet(cur_thread);
1513         jvmtiEventFiberScheduled callback = env->callbacks()->FiberScheduled;
1514         if (callback != NULL) {
1515           (*callback)(env->jvmti_external(), jem.jni_env(), thread, fiber);
1516         }
1517       }
1518     }
1519   }
1520 }
1521 
1522 void JvmtiExport::post_fiber_terminated(jthread thread, jobject fiber) {
1523   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1524     return;
1525   }
1526   EVT_TRIG_TRACE(JVMTI_EVENT_FIBER_TERMINATED, ("[%p] Trg Fiber Terminated event triggered", fiber));
1527 
1528   JavaThread *cur_thread = JavaThread::current();
1529   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1530   if (state == NULL) {
1531     return;
1532   }
1533 
1534   if (state->is_enabled(JVMTI_EVENT_FIBER_TERMINATED)) {
1535     JvmtiEnvThreadStateIterator it(state);
1536 
1537     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1538       if (ets->is_enabled(JVMTI_EVENT_FIBER_TERMINATED)) {
1539         JvmtiEnv *env = ets->get_env();
1540         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1541           continue;
1542         }
1543         EVT_TRACE(JVMTI_EVENT_FIBER_TERMINATED, ("[%p] Evt Fiber Terminated event sent", fiber));
1544 
1545         JvmtiThreadEventMark jem(cur_thread);
1546         JvmtiJavaThreadEventTransition jet(cur_thread);
1547         jvmtiEventFiberTerminated callback = env->callbacks()->FiberTerminated;
1548         if (callback != NULL) {
1549           (*callback)(env->jvmti_external(), jem.jni_env(), thread, fiber);
1550         }
1551       }
1552     }
1553   }
1554 }
1555 
1556 void JvmtiExport::post_fiber_mount(jthread thread, jobject fiber) {
1557   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1558     return;
1559   }
1560   EVT_TRIG_TRACE(JVMTI_EVENT_FIBER_MOUNT, ("[%p] Trg Fiber Mount event triggered", fiber));
1561 
1562   JavaThread *cur_thread = JavaThread::current();
1563   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1564   if (state == NULL) {
1565     return;
1566   }
1567 
1568   if (state->is_enabled(JVMTI_EVENT_FIBER_MOUNT)) {
1569     JvmtiEnvThreadStateIterator it(state);
1570 
1571     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1572       if (ets->is_enabled(JVMTI_EVENT_FIBER_MOUNT)) {
1573         JvmtiEnv *env = ets->get_env();
1574         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1575           continue;
1576         }
1577         EVT_TRACE(JVMTI_EVENT_FIBER_MOUNT, ("[%p] Evt Fiber Mount event sent", fiber));
1578 
1579         JvmtiThreadEventMark jem(cur_thread);
1580         JvmtiJavaThreadEventTransition jet(cur_thread);
1581         jvmtiEventFiberMount callback = env->callbacks()->FiberMount;
1582         if (callback != NULL) {
1583           (*callback)(env->jvmti_external(), jem.jni_env(), thread, fiber);
1584         }
1585       }
1586     }
1587   }
1588 }
1589 
1590 void JvmtiExport::post_fiber_unmount(jthread thread, jobject fiber) {
1591   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1592     return;
1593   }
1594   EVT_TRIG_TRACE(JVMTI_EVENT_FIBER_UNMOUNT, ("[%p] Trg Fiber Unmount event triggered", fiber));
1595 
1596   JavaThread *cur_thread = JavaThread::current();
1597   JvmtiThreadState *state = cur_thread->jvmti_thread_state();
1598   if (state == NULL) {
1599     return;
1600   }
1601 
1602   if (state->is_enabled(JVMTI_EVENT_FIBER_UNMOUNT)) {
1603     JvmtiEnvThreadStateIterator it(state);
1604 
1605     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1606       if (ets->is_enabled(JVMTI_EVENT_FIBER_UNMOUNT)) {
1607         JvmtiEnv *env = ets->get_env();
1608         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1609           continue;
1610         }
1611         EVT_TRACE(JVMTI_EVENT_FIBER_UNMOUNT, ("[%p] Evt Fiber Unmount event sent", fiber));
1612 
1613         JvmtiThreadEventMark jem(cur_thread);
1614         JvmtiJavaThreadEventTransition jet(cur_thread);
1615         jvmtiEventFiberUnmount callback = env->callbacks()->FiberUnmount;
1616         if (callback != NULL) {
1617           (*callback)(env->jvmti_external(), jem.jni_env(), thread, fiber);
1618         }
1619       }
1620     }
1621   }
1622 }
1623 
1624 void JvmtiExport::post_continuation_run(JavaThread* thread, jint continuation_frame_count) {
1625   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1626     return;
1627   }
1628   EVT_TRIG_TRACE(JVMTI_EVENT_CONTINUATION_RUN, ("Trg Continuation Run event triggered"));
1629 
1630   assert (thread == JavaThread::current(), "must be");
1631   JvmtiThreadState *state = thread->jvmti_thread_state();
1632   if (state == NULL) {
1633     return;
1634   }
1635   state->invalidate_cur_stack_depth();
1636 
1637   if (state->is_enabled(JVMTI_EVENT_CONTINUATION_RUN)) {
1638     JvmtiEnvThreadStateIterator it(state);
1639 
1640     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1641       if (ets->is_enabled(JVMTI_EVENT_CONTINUATION_RUN)) {
1642         JvmtiEnv *env = ets->get_env();
1643         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1644           continue;
1645         }
1646         EVT_TRACE(JVMTI_EVENT_CONTINUATION_RUN, ("Evt Continuation Run event sent"));
1647 
1648         JvmtiThreadEventMark jem(thread);
1649         JvmtiJavaThreadEventTransition jet(thread);
1650         jvmtiEventContinuationRun callback = env->callbacks()->ContinuationRun;
1651         if (callback != NULL) {
1652           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), continuation_frame_count);
1653         }
1654       }
1655     }
1656   }
1657 }
1658 
1659 void JvmtiExport::post_continuation_yield(JavaThread* thread, jint continuation_frame_count) {
1660   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1661     return;
1662   }
1663   EVT_TRIG_TRACE(JVMTI_EVENT_CONTINUATION_YIELD, ("Trg Continuation Yield event triggered"));
1664 
1665   assert (thread == JavaThread::current(), "must be");
1666   JvmtiThreadState *state = thread->jvmti_thread_state();
1667   if (state == NULL) {
1668     return;
1669   }
1670   state->invalidate_cur_stack_depth();
1671 
1672   if (state->is_enabled(JVMTI_EVENT_CONTINUATION_YIELD)) {
1673     JvmtiEnvThreadStateIterator it(state);
1674 
1675     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1676       if (ets->is_enabled(JVMTI_EVENT_CONTINUATION_YIELD)) {
1677         JvmtiEnv *env = ets->get_env();
1678         if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1679           continue;
1680         }
1681         EVT_TRACE(JVMTI_EVENT_CONTINUATION_RUN, ("Evt Continuation Run event sent"));
1682 
1683         JvmtiThreadEventMark jem(thread);
1684         JvmtiJavaThreadEventTransition jet(thread);
1685         jvmtiEventContinuationYield callback = env->callbacks()->ContinuationYield;
1686         if (callback != NULL) {
1687           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(), continuation_frame_count);
1688         }
1689       }
1690     }
1691   }
1692 
1693   // Clear frame_pop requests in frames popped by yield
1694   if (can_post_frame_pop()) {
1695     JvmtiEnvThreadStateIterator it(state);
1696     int top_frame_num = state->cur_stack_depth() + continuation_frame_count;
1697 
1698     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1699       if (!ets->has_frame_pops()) {
1700         continue;
1701       }
1702       for (int frame_idx = 0; frame_idx < continuation_frame_count; frame_idx++) {
1703         int frame_num = top_frame_num - frame_idx;
1704 
1705         if (ets->is_frame_pop(frame_num)) {
1706           // remove the frame's entry
1707           ets->clear_frame_pop(frame_num);
1708         }
1709       } 
1710     }
1711   }
1712 }
1713 
1714 void JvmtiExport::post_object_free(JvmtiEnv* env, jlong tag) {
1715   assert(SafepointSynchronize::is_at_safepoint(), "must be executed at safepoint");
1716   assert(env->is_enabled(JVMTI_EVENT_OBJECT_FREE), "checking");
1717 
1718   EVT_TRIG_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Trg Object Free triggered" ));
1719   EVT_TRACE(JVMTI_EVENT_OBJECT_FREE, ("[?] Evt Object Free sent"));
1720 
1721   jvmtiEventObjectFree callback = env->callbacks()->ObjectFree;
1722   if (callback != NULL) {
1723     (*callback)(env->jvmti_external(), tag);
1724   }
1725 }
1726 
1727 void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) {
1728 
1729   JavaThread *thread  = JavaThread::current();


< prev index next >