@@ -417,6 +417,15 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) {
417
417
}
418
418
}
419
419
420
+ JvmtiThreadState*
421
+ JvmtiExport::get_jvmti_thread_state (JavaThread *thread) {
422
+ assert (thread == JavaThread::current (), " must be current thread" );
423
+ if (thread->is_vthread_mounted () && thread->jvmti_thread_state () == nullptr ) {
424
+ JvmtiEventController::thread_started (thread);
425
+ }
426
+ return thread->jvmti_thread_state ();
427
+ }
428
+
420
429
void
421
430
JvmtiExport::add_default_read_edges (Handle h_module, TRAPS) {
422
431
if (!Universe::is_module_initialized ()) {
@@ -920,7 +929,7 @@ class JvmtiClassFileLoadHookPoster : public StackObj {
920
929
_has_been_modified = false ;
921
930
922
931
assert (!_thread->is_in_any_VTMS_transition (), " CFLH events are not allowed in any VTMS transition" );
923
- _state = _thread-> jvmti_thread_state ( );
932
+ _state = JvmtiExport::get_jvmti_thread_state (_thread );
924
933
if (_state != nullptr ) {
925
934
_class_being_redefined = _state->get_class_being_redefined ();
926
935
_load_kind = _state->get_class_load_kind ();
@@ -1212,7 +1221,7 @@ void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, addres
1212
1221
HandleMark hm (thread);
1213
1222
methodHandle mh (thread, method);
1214
1223
1215
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1224
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1216
1225
if (state == nullptr ) {
1217
1226
return ;
1218
1227
}
@@ -1310,7 +1319,7 @@ void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, a
1310
1319
methodHandle mh (thread, method);
1311
1320
1312
1321
// update information about current location and post a step event
1313
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1322
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1314
1323
if (state == nullptr ) {
1315
1324
return ;
1316
1325
}
@@ -1329,15 +1338,15 @@ void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, a
1329
1338
1330
1339
1331
1340
void JvmtiExport::expose_single_stepping (JavaThread *thread) {
1332
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1341
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1333
1342
if (state != nullptr ) {
1334
1343
state->clear_hide_single_stepping ();
1335
1344
}
1336
1345
}
1337
1346
1338
1347
1339
1348
bool JvmtiExport::hide_single_stepping (JavaThread *thread) {
1340
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1349
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1341
1350
if (state != nullptr && state->is_enabled (JVMTI_EVENT_SINGLE_STEP)) {
1342
1351
state->set_hide_single_stepping ();
1343
1352
return true ;
@@ -1352,7 +1361,7 @@ void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
1352
1361
}
1353
1362
HandleMark hm (thread);
1354
1363
1355
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1364
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1356
1365
if (state == nullptr ) {
1357
1366
return ;
1358
1367
}
@@ -1390,7 +1399,7 @@ void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
1390
1399
}
1391
1400
HandleMark hm (thread);
1392
1401
1393
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1402
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1394
1403
if (state == nullptr ) {
1395
1404
return ;
1396
1405
}
@@ -1519,7 +1528,7 @@ void JvmtiExport::post_thread_end(JavaThread *thread) {
1519
1528
EVT_TRIG_TRACE (JVMTI_EVENT_THREAD_END, (" [%s] Trg Thread End event triggered" ,
1520
1529
JvmtiTrace::safe_get_thread_name (thread)));
1521
1530
1522
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1531
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1523
1532
if (state == nullptr ) {
1524
1533
return ;
1525
1534
}
@@ -1567,7 +1576,7 @@ void JvmtiExport::post_vthread_start(jobject vthread) {
1567
1576
EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_START, (" [%p] Trg Virtual Thread Start event triggered" , vthread));
1568
1577
1569
1578
JavaThread *cur_thread = JavaThread::current ();
1570
- JvmtiThreadState *state = cur_thread-> jvmti_thread_state ( );
1579
+ JvmtiThreadState *state = get_jvmti_thread_state (cur_thread );
1571
1580
if (state == nullptr ) {
1572
1581
return ;
1573
1582
}
@@ -1601,7 +1610,7 @@ void JvmtiExport::post_vthread_end(jobject vthread) {
1601
1610
EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_END, (" [%p] Trg Virtual Thread End event triggered" , vthread));
1602
1611
1603
1612
JavaThread *cur_thread = JavaThread::current ();
1604
- JvmtiThreadState *state = cur_thread-> jvmti_thread_state ( );
1613
+ JvmtiThreadState *state = get_jvmti_thread_state (cur_thread );
1605
1614
if (state == nullptr ) {
1606
1615
return ;
1607
1616
}
@@ -1636,7 +1645,7 @@ void JvmtiExport::post_vthread_mount(jobject vthread) {
1636
1645
HandleMark hm (thread);
1637
1646
EVT_TRIG_TRACE (EXT_EVENT_VIRTUAL_THREAD_MOUNT, (" [%p] Trg Virtual Thread Mount event triggered" , vthread));
1638
1647
1639
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1648
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1640
1649
if (state == nullptr ) {
1641
1650
return ;
1642
1651
}
@@ -1671,7 +1680,7 @@ void JvmtiExport::post_vthread_unmount(jobject vthread) {
1671
1680
HandleMark hm (thread);
1672
1681
EVT_TRIG_TRACE (EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, (" [%p] Trg Virtual Thread Unmount event triggered" , vthread));
1673
1682
1674
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1683
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1675
1684
if (state == nullptr ) {
1676
1685
return ;
1677
1686
}
@@ -1704,7 +1713,7 @@ void JvmtiExport::continuation_yield_cleanup(JavaThread* thread, jint continuati
1704
1713
}
1705
1714
1706
1715
assert (thread == JavaThread::current (), " must be" );
1707
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1716
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1708
1717
if (state == nullptr ) {
1709
1718
return ;
1710
1719
}
@@ -1798,7 +1807,7 @@ void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame cu
1798
1807
HandleMark hm (thread);
1799
1808
methodHandle mh (thread, method);
1800
1809
1801
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1810
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1802
1811
if (state == nullptr || !state->is_interp_only_mode ()) {
1803
1812
// for any thread that actually wants method entry, interp_only_mode is set
1804
1813
return ;
@@ -1838,7 +1847,7 @@ void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame cur
1838
1847
HandleMark hm (thread);
1839
1848
methodHandle mh (thread, method);
1840
1849
1841
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1850
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1842
1851
1843
1852
if (state == nullptr || !state->is_interp_only_mode ()) {
1844
1853
// for any thread that actually wants method exit, interp_only_mode is set
@@ -1959,7 +1968,7 @@ void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address l
1959
1968
HandleMark hm (thread);
1960
1969
methodHandle mh (thread, method);
1961
1970
1962
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1971
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1963
1972
if (state == nullptr ) {
1964
1973
return ;
1965
1974
}
@@ -2001,7 +2010,7 @@ void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, addre
2001
2010
// ensure the stack is sufficiently processed.
2002
2011
KeepStackGCProcessedMark ksgcpm (thread);
2003
2012
2004
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2013
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2005
2014
if (state == nullptr ) {
2006
2015
return ;
2007
2016
}
@@ -2089,7 +2098,7 @@ void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* met
2089
2098
methodHandle mh (thread, method);
2090
2099
Handle exception_handle (thread, exception );
2091
2100
2092
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2101
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2093
2102
if (state == nullptr ) {
2094
2103
return ;
2095
2104
}
@@ -2205,7 +2214,7 @@ void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
2205
2214
HandleMark hm (thread);
2206
2215
methodHandle mh (thread, method);
2207
2216
2208
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2217
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2209
2218
if (state == nullptr ) {
2210
2219
return ;
2211
2220
}
@@ -2361,7 +2370,7 @@ void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
2361
2370
HandleMark hm (thread);
2362
2371
methodHandle mh (thread, method);
2363
2372
2364
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2373
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2365
2374
if (state == nullptr ) {
2366
2375
return ;
2367
2376
}
@@ -2603,7 +2612,7 @@ void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* na
2603
2612
// jvmti thread state.
2604
2613
// The collector and/or state might be null if JvmtiDynamicCodeEventCollector
2605
2614
// has been initialized while JVMTI_EVENT_DYNAMIC_CODE_GENERATED was disabled.
2606
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
2615
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
2607
2616
if (state != nullptr ) {
2608
2617
JvmtiDynamicCodeEventCollector *collector = state->get_dynamic_code_event_collector ();
2609
2618
if (collector != nullptr ) {
@@ -2722,17 +2731,17 @@ void JvmtiExport::post_data_dump() {
2722
2731
2723
2732
void JvmtiExport::post_monitor_contended_enter (JavaThread *thread, ObjectMonitor *obj_mntr) {
2724
2733
oop object = obj_mntr->object ();
2725
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2734
+ HandleMark hm (thread);
2735
+ Handle h (thread, object);
2736
+
2737
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2726
2738
if (state == nullptr ) {
2727
2739
return ;
2728
2740
}
2729
2741
if (thread->is_in_any_VTMS_transition ()) {
2730
2742
return ; // no events should be posted if thread is in any VTMS transition
2731
2743
}
2732
2744
2733
- HandleMark hm (thread);
2734
- Handle h (thread, object);
2735
-
2736
2745
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2737
2746
(" [%s] monitor contended enter event triggered" ,
2738
2747
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2755,17 +2764,17 @@ void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor
2755
2764
2756
2765
void JvmtiExport::post_monitor_contended_entered (JavaThread *thread, ObjectMonitor *obj_mntr) {
2757
2766
oop object = obj_mntr->object ();
2758
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2767
+ HandleMark hm (thread);
2768
+ Handle h (thread, object);
2769
+
2770
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2759
2771
if (state == nullptr ) {
2760
2772
return ;
2761
2773
}
2762
2774
if (thread->is_in_any_VTMS_transition ()) {
2763
2775
return ; // no events should be posted if thread is in any VTMS transition
2764
2776
}
2765
2777
2766
- HandleMark hm (thread);
2767
- Handle h (thread, object);
2768
-
2769
2778
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2770
2779
(" [%s] monitor contended entered event triggered" ,
2771
2780
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2789,17 +2798,17 @@ void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonit
2789
2798
2790
2799
void JvmtiExport::post_monitor_wait (JavaThread *thread, oop object,
2791
2800
jlong timeout) {
2792
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2801
+ HandleMark hm (thread);
2802
+ Handle h (thread, object);
2803
+
2804
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2793
2805
if (state == nullptr ) {
2794
2806
return ;
2795
2807
}
2796
2808
if (thread->is_in_any_VTMS_transition ()) {
2797
2809
return ; // no events should be posted if thread is in any VTMS transition
2798
2810
}
2799
2811
2800
- HandleMark hm (thread);
2801
- Handle h (thread, object);
2802
-
2803
2812
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_WAIT,
2804
2813
(" [%s] monitor wait event triggered" ,
2805
2814
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2823,17 +2832,17 @@ void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
2823
2832
2824
2833
void JvmtiExport::post_monitor_waited (JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2825
2834
oop object = obj_mntr->object ();
2826
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2835
+ HandleMark hm (thread);
2836
+ Handle h (thread, object);
2837
+
2838
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2827
2839
if (state == nullptr ) {
2828
2840
return ;
2829
2841
}
2830
2842
if (thread->is_in_any_VTMS_transition ()) {
2831
2843
return ; // no events should be posted if thread is in any VTMS transition
2832
2844
}
2833
2845
2834
- HandleMark hm (thread);
2835
- Handle h (thread, object);
2836
-
2837
2846
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_WAITED,
2838
2847
(" [%s] monitor waited event triggered" ,
2839
2848
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2886,7 +2895,10 @@ void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2886
2895
}
2887
2896
2888
2897
void JvmtiExport::post_sampled_object_alloc (JavaThread *thread, oop object) {
2889
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2898
+ HandleMark hm (thread);
2899
+ Handle h (thread, object);
2900
+
2901
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2890
2902
if (state == nullptr ) {
2891
2903
return ;
2892
2904
}
@@ -2896,8 +2908,6 @@ void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
2896
2908
if (thread->is_in_any_VTMS_transition ()) {
2897
2909
return ; // no events should be posted if thread is in any VTMS transition
2898
2910
}
2899
- HandleMark hm (thread);
2900
- Handle h (thread, object);
2901
2911
2902
2912
EVT_TRIG_TRACE (JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2903
2913
(" [%s] Trg sampled object alloc triggered" ,
0 commit comments