41 #include "prims/jvmtiManageCapabilities.hpp"
42 #include "prims/jvmtiRawMonitor.hpp"
43 #include "prims/jvmtiRedefineClasses.hpp"
44 #include "prims/jvmtiTagMap.hpp"
45 #include "prims/jvmtiThreadState.inline.hpp"
46 #include "runtime/arguments.hpp"
47 #include "runtime/handles.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/objectMonitor.hpp"
50 #include "runtime/objectMonitor.inline.hpp"
51 #include "runtime/os.inline.hpp"
52 #include "runtime/thread.inline.hpp"
53 #include "runtime/vframe.hpp"
54 #include "services/attachListener.hpp"
55 #include "services/serviceUtil.hpp"
56 #include "utilities/macros.hpp"
57 #if INCLUDE_ALL_GCS
58 #include "gc/parallel/psMarkSweep.hpp"
59 #endif // INCLUDE_ALL_GCS
60
61 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
62
63 #ifdef JVMTI_TRACE
64 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; tty->print_cr out; }
65 #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; tty->print_cr out; }
66 #else
67 #define EVT_TRIG_TRACE(evt,out)
68 #define EVT_TRACE(evt,out)
69 #endif
70
71 ///////////////////////////////////////////////////////////////
72 //
73 // JvmtiEventTransition
74 //
75 // TO DO --
76 // more handle purging
77
78 // Use this for JavaThreads and state is _thread_in_vm.
79 class JvmtiJavaThreadEventTransition : StackObj {
80 private:
81 ResourceMark _rm;
82 ThreadToNativeFromVM _transition;
753
754 ///////////////////////////////////////////////////////////////
755 //
756 // pending CompiledMethodUnload support
757 //
758
759 void JvmtiExport::post_compiled_method_unload(
760 jmethodID method, const void *code_begin) {
761 JavaThread* thread = JavaThread::current();
762 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
763 ("JVMTI [%s] method compile unload event triggered",
764 JvmtiTrace::safe_get_thread_name(thread)));
765
766 // post the event for each environment that has this event enabled.
767 JvmtiEnvIterator it;
768 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
769 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) {
770
771 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
772 ("JVMTI [%s] class compile method unload event sent jmethodID " PTR_FORMAT,
773 JvmtiTrace::safe_get_thread_name(thread), method));
774
775 ResourceMark rm(thread);
776
777 JvmtiEventMark jem(thread);
778 JvmtiJavaThreadEventTransition jet(thread);
779 jvmtiEventCompiledMethodUnload callback = env->callbacks()->CompiledMethodUnload;
780 if (callback != NULL) {
781 (*callback)(env->jvmti_external(), method, code_begin);
782 }
783 }
784 }
785 }
786
787 ///////////////////////////////////////////////////////////////
788 //
789 // JvmtiExport
790 //
791
792 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, address location) {
793 HandleMark hm(thread);
794 methodHandle mh(thread, method);
795
796 JvmtiThreadState *state = thread->jvmti_thread_state();
797 if (state == NULL) {
798 return;
799 }
800 EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Trg Breakpoint triggered",
801 JvmtiTrace::safe_get_thread_name(thread)));
802 JvmtiEnvThreadStateIterator it(state);
803 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
804 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
805 if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
806 ThreadState old_os_state = thread->osthread()->get_state();
807 thread->osthread()->set_state(BREAKPOINTED);
808 EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Evt Breakpoint sent %s.%s @ %d",
809 JvmtiTrace::safe_get_thread_name(thread),
810 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
811 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
812 location - mh()->code_base() ));
813
814 JvmtiEnv *env = ets->get_env();
815 JvmtiLocationEventMark jem(thread, mh, location);
816 JvmtiJavaThreadEventTransition jet(thread);
817 jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
818 if (callback != NULL) {
819 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
820 jem.jni_methodID(), jem.location());
821 }
822
823 ets->set_breakpoint_posted();
824 thread->osthread()->set_state(old_os_state);
825 }
826 }
827 }
828
1241 }
1242 }
1243
1244 state->decr_cur_stack_depth();
1245 }
1246
1247
1248 // Todo: inline this for optimization
1249 void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address location) {
1250 HandleMark hm(thread);
1251 methodHandle mh(thread, method);
1252
1253 JvmtiThreadState *state = thread->jvmti_thread_state();
1254 if (state == NULL) {
1255 return;
1256 }
1257 JvmtiEnvThreadStateIterator it(state);
1258 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1259 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
1260 if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1261 EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Evt Single Step sent %s.%s @ %d",
1262 JvmtiTrace::safe_get_thread_name(thread),
1263 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1264 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1265 location - mh()->code_base() ));
1266
1267 JvmtiEnv *env = ets->get_env();
1268 JvmtiLocationEventMark jem(thread, mh, location);
1269 JvmtiJavaThreadEventTransition jet(thread);
1270 jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
1271 if (callback != NULL) {
1272 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1273 jem.jni_methodID(), jem.location());
1274 }
1275
1276 ets->set_single_stepping_posted();
1277 }
1278 }
1279 }
1280
1281
1282 void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, address location, oop exception) {
1283 HandleMark hm(thread);
1284 methodHandle mh(thread, method);
1285 Handle exception_handle(thread, exception);
1286
1287 JvmtiThreadState *state = thread->jvmti_thread_state();
1288 if (state == NULL) {
1289 return;
1290 }
1291
1292 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("JVMTI [%s] Trg Exception thrown triggered",
1293 JvmtiTrace::safe_get_thread_name(thread)));
1294 if (!state->is_exception_detected()) {
1295 state->set_exception_detected();
1296 JvmtiEnvThreadStateIterator it(state);
1297 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1298 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
1299
1300 EVT_TRACE(JVMTI_EVENT_EXCEPTION,
1301 ("JVMTI [%s] Evt Exception thrown sent %s.%s @ %d",
1302 JvmtiTrace::safe_get_thread_name(thread),
1303 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1304 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1305 location - mh()->code_base() ));
1306
1307 JvmtiEnv *env = ets->get_env();
1308 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
1309
1310 // It's okay to clear these exceptions here because we duplicate
1311 // this lookup in InterpreterRuntime::exception_handler_for_exception.
1312 EXCEPTION_MARK;
1313
1314 bool should_repeat;
1315 vframeStream st(thread);
1316 assert(!st.at_end(), "cannot be at end");
1317 Method* current_method = NULL;
1318 // A GC may occur during the Method::fast_exception_handler_bci_for()
1319 // call below if it needs to load the constraint class. Using a
1320 // methodHandle to keep the 'current_method' from being deallocated
1321 // if GC happens.
1357 }
1358 }
1359 }
1360 }
1361
1362 // frames may get popped because of this throw, be safe - invalidate cached depth
1363 state->invalidate_cur_stack_depth();
1364 }
1365
1366
1367 void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) {
1368 HandleMark hm(thread);
1369 methodHandle mh(thread, method);
1370 Handle exception_handle(thread, exception);
1371
1372 JvmtiThreadState *state = thread->jvmti_thread_state();
1373 if (state == NULL) {
1374 return;
1375 }
1376 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
1377 ("JVMTI [%s] Trg unwind_due_to_exception triggered %s.%s @ %s%d - %s",
1378 JvmtiTrace::safe_get_thread_name(thread),
1379 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1380 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1381 location==0? "no location:" : "",
1382 location==0? 0 : location - mh()->code_base(),
1383 in_handler_frame? "in handler frame" : "not handler frame" ));
1384
1385 if (state->is_exception_detected()) {
1386
1387 state->invalidate_cur_stack_depth();
1388 if (!in_handler_frame) {
1389 // Not in exception handler.
1390 if(state->is_interp_only_mode()) {
1391 // method exit and frame pop events are posted only in interp mode.
1392 // When these events are enabled code should be in running in interp mode.
1393 JvmtiExport::post_method_exit(thread, method, thread->last_frame());
1394 // The cached cur_stack_depth might have changed from the
1395 // operations of frame pop or method exit. We are not 100% sure
1396 // the cached cur_stack_depth is still valid depth so invalidate
1397 // it.
1398 state->invalidate_cur_stack_depth();
1399 }
1400 } else {
1401 // In exception handler frame. Report exception catch.
1402 assert(location != NULL, "must be a known location");
1403 // Update cur_stack_depth - the frames above the current frame
1404 // have been unwound due to this exception:
1405 assert(!state->is_exception_caught(), "exception must not be caught yet.");
1406 state->set_exception_caught();
1407
1408 JvmtiEnvThreadStateIterator it(state);
1409 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1410 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION_CATCH) && (exception_handle() != NULL)) {
1411 EVT_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
1412 ("JVMTI [%s] Evt ExceptionCatch sent %s.%s @ %d",
1413 JvmtiTrace::safe_get_thread_name(thread),
1414 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1415 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1416 location - mh()->code_base() ));
1417
1418 JvmtiEnv *env = ets->get_env();
1419 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
1420 JvmtiJavaThreadEventTransition jet(thread);
1421 jvmtiEventExceptionCatch callback = env->callbacks()->ExceptionCatch;
1422 if (callback != NULL) {
1423 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1424 jem.jni_methodID(), jem.location(),
1425 jem.exception());
1426 }
1427 }
1428 }
1429 }
1430 }
1431 }
1432
1486 thread->last_frame().interpreter_frame_method(),
1487 thread->last_frame().interpreter_frame_bcp(),
1488 h_klass, h_obj, fieldID);
1489 }
1490
1491 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
1492 address location, KlassHandle field_klass, Handle object, jfieldID field) {
1493
1494 HandleMark hm(thread);
1495 methodHandle mh(thread, method);
1496
1497 JvmtiThreadState *state = thread->jvmti_thread_state();
1498 if (state == NULL) {
1499 return;
1500 }
1501 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Trg Field Access event triggered",
1502 JvmtiTrace::safe_get_thread_name(thread)));
1503 JvmtiEnvThreadStateIterator it(state);
1504 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1505 if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
1506 EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Evt Field Access event sent %s.%s @ %d",
1507 JvmtiTrace::safe_get_thread_name(thread),
1508 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1509 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1510 location - mh()->code_base() ));
1511
1512 JvmtiEnv *env = ets->get_env();
1513 JvmtiLocationEventMark jem(thread, mh, location);
1514 jclass field_jclass = jem.to_jclass(field_klass());
1515 jobject field_jobject = jem.to_jobject(object());
1516 JvmtiJavaThreadEventTransition jet(thread);
1517 jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
1518 if (callback != NULL) {
1519 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1520 jem.jni_methodID(), jem.location(),
1521 field_jclass, field_jobject, field);
1522 }
1523 }
1524 }
1525 }
1526
1650
1651 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
1652 address location, KlassHandle field_klass, Handle object, jfieldID field,
1653 char sig_type, jvalue *value_ptr) {
1654
1655 HandleMark hm(thread);
1656 methodHandle mh(thread, method);
1657
1658 JvmtiThreadState *state = thread->jvmti_thread_state();
1659 if (state == NULL) {
1660 return;
1661 }
1662 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
1663 ("JVMTI [%s] Trg Field Modification event triggered",
1664 JvmtiTrace::safe_get_thread_name(thread)));
1665
1666 JvmtiEnvThreadStateIterator it(state);
1667 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1668 if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
1669 EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
1670 ("JVMTI [%s] Evt Field Modification event sent %s.%s @ %d",
1671 JvmtiTrace::safe_get_thread_name(thread),
1672 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1673 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1674 location - mh()->code_base() ));
1675
1676 JvmtiEnv *env = ets->get_env();
1677 JvmtiLocationEventMark jem(thread, mh, location);
1678 jclass field_jclass = jem.to_jclass(field_klass());
1679 jobject field_jobject = jem.to_jobject(object());
1680 JvmtiJavaThreadEventTransition jet(thread);
1681 jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
1682 if (callback != NULL) {
1683 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1684 jem.jni_methodID(), jem.location(),
1685 field_jclass, field_jobject, field, sig_type, *value_ptr);
1686 }
1687 }
1688 }
1689 }
1690
1790 jem.map(), jem.compile_info());
1791 }
1792 }
1793 }
1794 }
1795
1796
1797 // post a COMPILED_METHOD_LOAD event for a given environment
1798 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
1799 const void *code_begin, const jint map_length,
1800 const jvmtiAddrLocationMap* map)
1801 {
1802 JavaThread* thread = JavaThread::current();
1803 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
1804 ("JVMTI [%s] method compile load event triggered (by GenerateEvents)",
1805 JvmtiTrace::safe_get_thread_name(thread)));
1806 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
1807
1808 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
1809 ("JVMTI [%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT,
1810 JvmtiTrace::safe_get_thread_name(thread), method));
1811
1812 JvmtiEventMark jem(thread);
1813 JvmtiJavaThreadEventTransition jet(thread);
1814 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
1815 if (callback != NULL) {
1816 (*callback)(env->jvmti_external(), method,
1817 length, code_begin, map_length,
1818 map, NULL);
1819 }
1820 }
1821 }
1822
1823 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
1824 assert(name != NULL && name[0] != '\0', "sanity check");
1825
1826 JavaThread* thread = JavaThread::current();
1827 // In theory everyone coming thru here is in_vm but we need to be certain
1828 // because a callee will do a vm->native transition
1829 ThreadInVMfromUnknown __tiv;
1830
|
41 #include "prims/jvmtiManageCapabilities.hpp"
42 #include "prims/jvmtiRawMonitor.hpp"
43 #include "prims/jvmtiRedefineClasses.hpp"
44 #include "prims/jvmtiTagMap.hpp"
45 #include "prims/jvmtiThreadState.inline.hpp"
46 #include "runtime/arguments.hpp"
47 #include "runtime/handles.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/objectMonitor.hpp"
50 #include "runtime/objectMonitor.inline.hpp"
51 #include "runtime/os.inline.hpp"
52 #include "runtime/thread.inline.hpp"
53 #include "runtime/vframe.hpp"
54 #include "services/attachListener.hpp"
55 #include "services/serviceUtil.hpp"
56 #include "utilities/macros.hpp"
57 #if INCLUDE_ALL_GCS
58 #include "gc/parallel/psMarkSweep.hpp"
59 #endif // INCLUDE_ALL_GCS
60
61 #ifdef JVMTI_TRACE
62 #define EVT_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_SENT) != 0) { SafeResourceMark rm; tty->print_cr out; }
63 #define EVT_TRIG_TRACE(evt,out) if ((JvmtiTrace::event_trace_flags(evt) & JvmtiTrace::SHOW_EVENT_TRIGGER) != 0) { SafeResourceMark rm; tty->print_cr out; }
64 #else
65 #define EVT_TRIG_TRACE(evt,out)
66 #define EVT_TRACE(evt,out)
67 #endif
68
69 ///////////////////////////////////////////////////////////////
70 //
71 // JvmtiEventTransition
72 //
73 // TO DO --
74 // more handle purging
75
76 // Use this for JavaThreads and state is _thread_in_vm.
77 class JvmtiJavaThreadEventTransition : StackObj {
78 private:
79 ResourceMark _rm;
80 ThreadToNativeFromVM _transition;
751
752 ///////////////////////////////////////////////////////////////
753 //
754 // pending CompiledMethodUnload support
755 //
756
757 void JvmtiExport::post_compiled_method_unload(
758 jmethodID method, const void *code_begin) {
759 JavaThread* thread = JavaThread::current();
760 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
761 ("JVMTI [%s] method compile unload event triggered",
762 JvmtiTrace::safe_get_thread_name(thread)));
763
764 // post the event for each environment that has this event enabled.
765 JvmtiEnvIterator it;
766 for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
767 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) {
768
769 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_UNLOAD,
770 ("JVMTI [%s] class compile method unload event sent jmethodID " PTR_FORMAT,
771 JvmtiTrace::safe_get_thread_name(thread), p2i(method)));
772
773 ResourceMark rm(thread);
774
775 JvmtiEventMark jem(thread);
776 JvmtiJavaThreadEventTransition jet(thread);
777 jvmtiEventCompiledMethodUnload callback = env->callbacks()->CompiledMethodUnload;
778 if (callback != NULL) {
779 (*callback)(env->jvmti_external(), method, code_begin);
780 }
781 }
782 }
783 }
784
785 ///////////////////////////////////////////////////////////////
786 //
787 // JvmtiExport
788 //
789
790 void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, address location) {
791 HandleMark hm(thread);
792 methodHandle mh(thread, method);
793
794 JvmtiThreadState *state = thread->jvmti_thread_state();
795 if (state == NULL) {
796 return;
797 }
798 EVT_TRIG_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Trg Breakpoint triggered",
799 JvmtiTrace::safe_get_thread_name(thread)));
800 JvmtiEnvThreadStateIterator it(state);
801 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
802 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_BREAKPOINT);
803 if (!ets->breakpoint_posted() && ets->is_enabled(JVMTI_EVENT_BREAKPOINT)) {
804 ThreadState old_os_state = thread->osthread()->get_state();
805 thread->osthread()->set_state(BREAKPOINTED);
806 EVT_TRACE(JVMTI_EVENT_BREAKPOINT, ("JVMTI [%s] Evt Breakpoint sent %s.%s @ " INTX_FORMAT,
807 JvmtiTrace::safe_get_thread_name(thread),
808 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
809 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
810 location - mh()->code_base() ));
811
812 JvmtiEnv *env = ets->get_env();
813 JvmtiLocationEventMark jem(thread, mh, location);
814 JvmtiJavaThreadEventTransition jet(thread);
815 jvmtiEventBreakpoint callback = env->callbacks()->Breakpoint;
816 if (callback != NULL) {
817 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
818 jem.jni_methodID(), jem.location());
819 }
820
821 ets->set_breakpoint_posted();
822 thread->osthread()->set_state(old_os_state);
823 }
824 }
825 }
826
1239 }
1240 }
1241
1242 state->decr_cur_stack_depth();
1243 }
1244
1245
1246 // Todo: inline this for optimization
1247 void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address location) {
1248 HandleMark hm(thread);
1249 methodHandle mh(thread, method);
1250
1251 JvmtiThreadState *state = thread->jvmti_thread_state();
1252 if (state == NULL) {
1253 return;
1254 }
1255 JvmtiEnvThreadStateIterator it(state);
1256 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1257 ets->compare_and_set_current_location(mh(), location, JVMTI_EVENT_SINGLE_STEP);
1258 if (!ets->single_stepping_posted() && ets->is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
1259 EVT_TRACE(JVMTI_EVENT_SINGLE_STEP, ("JVMTI [%s] Evt Single Step sent %s.%s @ " INTX_FORMAT,
1260 JvmtiTrace::safe_get_thread_name(thread),
1261 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1262 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1263 location - mh()->code_base() ));
1264
1265 JvmtiEnv *env = ets->get_env();
1266 JvmtiLocationEventMark jem(thread, mh, location);
1267 JvmtiJavaThreadEventTransition jet(thread);
1268 jvmtiEventSingleStep callback = env->callbacks()->SingleStep;
1269 if (callback != NULL) {
1270 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1271 jem.jni_methodID(), jem.location());
1272 }
1273
1274 ets->set_single_stepping_posted();
1275 }
1276 }
1277 }
1278
1279
1280 void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, address location, oop exception) {
1281 HandleMark hm(thread);
1282 methodHandle mh(thread, method);
1283 Handle exception_handle(thread, exception);
1284
1285 JvmtiThreadState *state = thread->jvmti_thread_state();
1286 if (state == NULL) {
1287 return;
1288 }
1289
1290 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("JVMTI [%s] Trg Exception thrown triggered",
1291 JvmtiTrace::safe_get_thread_name(thread)));
1292 if (!state->is_exception_detected()) {
1293 state->set_exception_detected();
1294 JvmtiEnvThreadStateIterator it(state);
1295 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1296 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION) && (exception != NULL)) {
1297
1298 EVT_TRACE(JVMTI_EVENT_EXCEPTION,
1299 ("JVMTI [%s] Evt Exception thrown sent %s.%s @ " INTX_FORMAT,
1300 JvmtiTrace::safe_get_thread_name(thread),
1301 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1302 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1303 location - mh()->code_base() ));
1304
1305 JvmtiEnv *env = ets->get_env();
1306 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
1307
1308 // It's okay to clear these exceptions here because we duplicate
1309 // this lookup in InterpreterRuntime::exception_handler_for_exception.
1310 EXCEPTION_MARK;
1311
1312 bool should_repeat;
1313 vframeStream st(thread);
1314 assert(!st.at_end(), "cannot be at end");
1315 Method* current_method = NULL;
1316 // A GC may occur during the Method::fast_exception_handler_bci_for()
1317 // call below if it needs to load the constraint class. Using a
1318 // methodHandle to keep the 'current_method' from being deallocated
1319 // if GC happens.
1355 }
1356 }
1357 }
1358 }
1359
1360 // frames may get popped because of this throw, be safe - invalidate cached depth
1361 state->invalidate_cur_stack_depth();
1362 }
1363
1364
1365 void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* method, address location, oop exception, bool in_handler_frame) {
1366 HandleMark hm(thread);
1367 methodHandle mh(thread, method);
1368 Handle exception_handle(thread, exception);
1369
1370 JvmtiThreadState *state = thread->jvmti_thread_state();
1371 if (state == NULL) {
1372 return;
1373 }
1374 EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
1375 ("JVMTI [%s] Trg unwind_due_to_exception triggered %s.%s @ %s" INTX_FORMAT " - %s",
1376 JvmtiTrace::safe_get_thread_name(thread),
1377 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1378 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1379 location==0? "no location:" : "",
1380 location==0? 0 : location - mh()->code_base(),
1381 in_handler_frame? "in handler frame" : "not handler frame" ));
1382
1383 if (state->is_exception_detected()) {
1384
1385 state->invalidate_cur_stack_depth();
1386 if (!in_handler_frame) {
1387 // Not in exception handler.
1388 if(state->is_interp_only_mode()) {
1389 // method exit and frame pop events are posted only in interp mode.
1390 // When these events are enabled code should be in running in interp mode.
1391 JvmtiExport::post_method_exit(thread, method, thread->last_frame());
1392 // The cached cur_stack_depth might have changed from the
1393 // operations of frame pop or method exit. We are not 100% sure
1394 // the cached cur_stack_depth is still valid depth so invalidate
1395 // it.
1396 state->invalidate_cur_stack_depth();
1397 }
1398 } else {
1399 // In exception handler frame. Report exception catch.
1400 assert(location != NULL, "must be a known location");
1401 // Update cur_stack_depth - the frames above the current frame
1402 // have been unwound due to this exception:
1403 assert(!state->is_exception_caught(), "exception must not be caught yet.");
1404 state->set_exception_caught();
1405
1406 JvmtiEnvThreadStateIterator it(state);
1407 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1408 if (ets->is_enabled(JVMTI_EVENT_EXCEPTION_CATCH) && (exception_handle() != NULL)) {
1409 EVT_TRACE(JVMTI_EVENT_EXCEPTION_CATCH,
1410 ("JVMTI [%s] Evt ExceptionCatch sent %s.%s @ " INTX_FORMAT,
1411 JvmtiTrace::safe_get_thread_name(thread),
1412 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1413 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1414 location - mh()->code_base() ));
1415
1416 JvmtiEnv *env = ets->get_env();
1417 JvmtiExceptionEventMark jem(thread, mh, location, exception_handle);
1418 JvmtiJavaThreadEventTransition jet(thread);
1419 jvmtiEventExceptionCatch callback = env->callbacks()->ExceptionCatch;
1420 if (callback != NULL) {
1421 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1422 jem.jni_methodID(), jem.location(),
1423 jem.exception());
1424 }
1425 }
1426 }
1427 }
1428 }
1429 }
1430
1484 thread->last_frame().interpreter_frame_method(),
1485 thread->last_frame().interpreter_frame_bcp(),
1486 h_klass, h_obj, fieldID);
1487 }
1488
1489 void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
1490 address location, KlassHandle field_klass, Handle object, jfieldID field) {
1491
1492 HandleMark hm(thread);
1493 methodHandle mh(thread, method);
1494
1495 JvmtiThreadState *state = thread->jvmti_thread_state();
1496 if (state == NULL) {
1497 return;
1498 }
1499 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Trg Field Access event triggered",
1500 JvmtiTrace::safe_get_thread_name(thread)));
1501 JvmtiEnvThreadStateIterator it(state);
1502 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1503 if (ets->is_enabled(JVMTI_EVENT_FIELD_ACCESS)) {
1504 EVT_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("JVMTI [%s] Evt Field Access event sent %s.%s @ " INTX_FORMAT,
1505 JvmtiTrace::safe_get_thread_name(thread),
1506 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1507 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1508 location - mh()->code_base() ));
1509
1510 JvmtiEnv *env = ets->get_env();
1511 JvmtiLocationEventMark jem(thread, mh, location);
1512 jclass field_jclass = jem.to_jclass(field_klass());
1513 jobject field_jobject = jem.to_jobject(object());
1514 JvmtiJavaThreadEventTransition jet(thread);
1515 jvmtiEventFieldAccess callback = env->callbacks()->FieldAccess;
1516 if (callback != NULL) {
1517 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1518 jem.jni_methodID(), jem.location(),
1519 field_jclass, field_jobject, field);
1520 }
1521 }
1522 }
1523 }
1524
1648
1649 void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
1650 address location, KlassHandle field_klass, Handle object, jfieldID field,
1651 char sig_type, jvalue *value_ptr) {
1652
1653 HandleMark hm(thread);
1654 methodHandle mh(thread, method);
1655
1656 JvmtiThreadState *state = thread->jvmti_thread_state();
1657 if (state == NULL) {
1658 return;
1659 }
1660 EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
1661 ("JVMTI [%s] Trg Field Modification event triggered",
1662 JvmtiTrace::safe_get_thread_name(thread)));
1663
1664 JvmtiEnvThreadStateIterator it(state);
1665 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
1666 if (ets->is_enabled(JVMTI_EVENT_FIELD_MODIFICATION)) {
1667 EVT_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
1668 ("JVMTI [%s] Evt Field Modification event sent %s.%s @ " INTX_FORMAT,
1669 JvmtiTrace::safe_get_thread_name(thread),
1670 (mh() == NULL) ? "NULL" : mh()->klass_name()->as_C_string(),
1671 (mh() == NULL) ? "NULL" : mh()->name()->as_C_string(),
1672 location - mh()->code_base() ));
1673
1674 JvmtiEnv *env = ets->get_env();
1675 JvmtiLocationEventMark jem(thread, mh, location);
1676 jclass field_jclass = jem.to_jclass(field_klass());
1677 jobject field_jobject = jem.to_jobject(object());
1678 JvmtiJavaThreadEventTransition jet(thread);
1679 jvmtiEventFieldModification callback = env->callbacks()->FieldModification;
1680 if (callback != NULL) {
1681 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
1682 jem.jni_methodID(), jem.location(),
1683 field_jclass, field_jobject, field, sig_type, *value_ptr);
1684 }
1685 }
1686 }
1687 }
1688
1788 jem.map(), jem.compile_info());
1789 }
1790 }
1791 }
1792 }
1793
1794
1795 // post a COMPILED_METHOD_LOAD event for a given environment
1796 void JvmtiExport::post_compiled_method_load(JvmtiEnv* env, const jmethodID method, const jint length,
1797 const void *code_begin, const jint map_length,
1798 const jvmtiAddrLocationMap* map)
1799 {
1800 JavaThread* thread = JavaThread::current();
1801 EVT_TRIG_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
1802 ("JVMTI [%s] method compile load event triggered (by GenerateEvents)",
1803 JvmtiTrace::safe_get_thread_name(thread)));
1804 if (env->is_enabled(JVMTI_EVENT_COMPILED_METHOD_LOAD)) {
1805
1806 EVT_TRACE(JVMTI_EVENT_COMPILED_METHOD_LOAD,
1807 ("JVMTI [%s] class compile method load event sent (by GenerateEvents), jmethodID=" PTR_FORMAT,
1808 JvmtiTrace::safe_get_thread_name(thread), p2i(method)));
1809
1810 JvmtiEventMark jem(thread);
1811 JvmtiJavaThreadEventTransition jet(thread);
1812 jvmtiEventCompiledMethodLoad callback = env->callbacks()->CompiledMethodLoad;
1813 if (callback != NULL) {
1814 (*callback)(env->jvmti_external(), method,
1815 length, code_begin, map_length,
1816 map, NULL);
1817 }
1818 }
1819 }
1820
1821 void JvmtiExport::post_dynamic_code_generated_internal(const char *name, const void *code_begin, const void *code_end) {
1822 assert(name != NULL && name[0] != '\0', "sanity check");
1823
1824 JavaThread* thread = JavaThread::current();
1825 // In theory everyone coming thru here is in_vm but we need to be certain
1826 // because a callee will do a vm->native transition
1827 ThreadInVMfromUnknown __tiv;
1828
|