@@ -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 ();
@@ -1209,7 +1218,7 @@ void JvmtiExport::post_raw_breakpoint(JavaThread *thread, Method* method, addres
1209
1218
HandleMark hm (thread);
1210
1219
methodHandle mh (thread, method);
1211
1220
1212
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1221
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1213
1222
if (state == nullptr ) {
1214
1223
return ;
1215
1224
}
@@ -1307,7 +1316,7 @@ void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, a
1307
1316
methodHandle mh (thread, method);
1308
1317
1309
1318
// update information about current location and post a step event
1310
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1319
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1311
1320
if (state == nullptr ) {
1312
1321
return ;
1313
1322
}
@@ -1326,15 +1335,15 @@ void JvmtiExport::at_single_stepping_point(JavaThread *thread, Method* method, a
1326
1335
1327
1336
1328
1337
void JvmtiExport::expose_single_stepping (JavaThread *thread) {
1329
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1338
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1330
1339
if (state != nullptr ) {
1331
1340
state->clear_hide_single_stepping ();
1332
1341
}
1333
1342
}
1334
1343
1335
1344
1336
1345
bool JvmtiExport::hide_single_stepping (JavaThread *thread) {
1337
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1346
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1338
1347
if (state != nullptr && state->is_enabled (JVMTI_EVENT_SINGLE_STEP)) {
1339
1348
state->set_hide_single_stepping ();
1340
1349
return true ;
@@ -1349,7 +1358,7 @@ void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
1349
1358
}
1350
1359
HandleMark hm (thread);
1351
1360
1352
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1361
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1353
1362
if (state == nullptr ) {
1354
1363
return ;
1355
1364
}
@@ -1387,7 +1396,7 @@ void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
1387
1396
}
1388
1397
HandleMark hm (thread);
1389
1398
1390
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1399
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1391
1400
if (state == nullptr ) {
1392
1401
return ;
1393
1402
}
@@ -1516,7 +1525,7 @@ void JvmtiExport::post_thread_end(JavaThread *thread) {
1516
1525
EVT_TRIG_TRACE (JVMTI_EVENT_THREAD_END, (" [%s] Trg Thread End event triggered" ,
1517
1526
JvmtiTrace::safe_get_thread_name (thread)));
1518
1527
1519
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1528
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1520
1529
if (state == nullptr ) {
1521
1530
return ;
1522
1531
}
@@ -1564,7 +1573,7 @@ void JvmtiExport::post_vthread_start(jobject vthread) {
1564
1573
EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_START, (" [%p] Trg Virtual Thread Start event triggered" , vthread));
1565
1574
1566
1575
JavaThread *cur_thread = JavaThread::current ();
1567
- JvmtiThreadState *state = cur_thread-> jvmti_thread_state ( );
1576
+ JvmtiThreadState *state = get_jvmti_thread_state (cur_thread );
1568
1577
if (state == nullptr ) {
1569
1578
return ;
1570
1579
}
@@ -1598,7 +1607,7 @@ void JvmtiExport::post_vthread_end(jobject vthread) {
1598
1607
EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_END, (" [%p] Trg Virtual Thread End event triggered" , vthread));
1599
1608
1600
1609
JavaThread *cur_thread = JavaThread::current ();
1601
- JvmtiThreadState *state = cur_thread-> jvmti_thread_state ( );
1610
+ JvmtiThreadState *state = get_jvmti_thread_state (cur_thread );
1602
1611
if (state == nullptr ) {
1603
1612
return ;
1604
1613
}
@@ -1633,7 +1642,7 @@ void JvmtiExport::post_vthread_mount(jobject vthread) {
1633
1642
HandleMark hm (thread);
1634
1643
EVT_TRIG_TRACE (EXT_EVENT_VIRTUAL_THREAD_MOUNT, (" [%p] Trg Virtual Thread Mount event triggered" , vthread));
1635
1644
1636
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1645
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1637
1646
if (state == nullptr ) {
1638
1647
return ;
1639
1648
}
@@ -1668,7 +1677,7 @@ void JvmtiExport::post_vthread_unmount(jobject vthread) {
1668
1677
HandleMark hm (thread);
1669
1678
EVT_TRIG_TRACE (EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, (" [%p] Trg Virtual Thread Unmount event triggered" , vthread));
1670
1679
1671
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1680
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1672
1681
if (state == nullptr ) {
1673
1682
return ;
1674
1683
}
@@ -1701,7 +1710,7 @@ void JvmtiExport::continuation_yield_cleanup(JavaThread* thread, jint continuati
1701
1710
}
1702
1711
1703
1712
assert (thread == JavaThread::current (), " must be" );
1704
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1713
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1705
1714
if (state == nullptr ) {
1706
1715
return ;
1707
1716
}
@@ -1795,7 +1804,7 @@ void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame cu
1795
1804
HandleMark hm (thread);
1796
1805
methodHandle mh (thread, method);
1797
1806
1798
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
1807
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
1799
1808
if (state == nullptr || !state->is_interp_only_mode ()) {
1800
1809
// for any thread that actually wants method entry, interp_only_mode is set
1801
1810
return ;
@@ -1835,7 +1844,7 @@ void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame cur
1835
1844
HandleMark hm (thread);
1836
1845
methodHandle mh (thread, method);
1837
1846
1838
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1847
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1839
1848
1840
1849
if (state == nullptr || !state->is_interp_only_mode ()) {
1841
1850
// for any thread that actually wants method exit, interp_only_mode is set
@@ -1956,7 +1965,7 @@ void JvmtiExport::post_single_step(JavaThread *thread, Method* method, address l
1956
1965
HandleMark hm (thread);
1957
1966
methodHandle mh (thread, method);
1958
1967
1959
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
1968
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
1960
1969
if (state == nullptr ) {
1961
1970
return ;
1962
1971
}
@@ -1998,7 +2007,7 @@ void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, addre
1998
2007
// ensure the stack is sufficiently processed.
1999
2008
KeepStackGCProcessedMark ksgcpm (thread);
2000
2009
2001
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2010
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2002
2011
if (state == nullptr ) {
2003
2012
return ;
2004
2013
}
@@ -2086,7 +2095,7 @@ void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* met
2086
2095
methodHandle mh (thread, method);
2087
2096
Handle exception_handle (thread, exception );
2088
2097
2089
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2098
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2090
2099
if (state == nullptr ) {
2091
2100
return ;
2092
2101
}
@@ -2202,7 +2211,7 @@ void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
2202
2211
HandleMark hm (thread);
2203
2212
methodHandle mh (thread, method);
2204
2213
2205
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2214
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2206
2215
if (state == nullptr ) {
2207
2216
return ;
2208
2217
}
@@ -2358,7 +2367,7 @@ void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
2358
2367
HandleMark hm (thread);
2359
2368
methodHandle mh (thread, method);
2360
2369
2361
- JvmtiThreadState *state = thread-> jvmti_thread_state ( );
2370
+ JvmtiThreadState *state = get_jvmti_thread_state (thread );
2362
2371
if (state == nullptr ) {
2363
2372
return ;
2364
2373
}
@@ -2600,7 +2609,7 @@ void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* na
2600
2609
// jvmti thread state.
2601
2610
// The collector and/or state might be null if JvmtiDynamicCodeEventCollector
2602
2611
// has been initialized while JVMTI_EVENT_DYNAMIC_CODE_GENERATED was disabled.
2603
- JvmtiThreadState* state = thread-> jvmti_thread_state ( );
2612
+ JvmtiThreadState * state = get_jvmti_thread_state (thread );
2604
2613
if (state != nullptr ) {
2605
2614
JvmtiDynamicCodeEventCollector *collector = state->get_dynamic_code_event_collector ();
2606
2615
if (collector != nullptr ) {
@@ -2719,17 +2728,17 @@ void JvmtiExport::post_data_dump() {
2719
2728
2720
2729
void JvmtiExport::post_monitor_contended_enter (JavaThread *thread, ObjectMonitor *obj_mntr) {
2721
2730
oop object = obj_mntr->object ();
2722
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2731
+ HandleMark hm (thread);
2732
+ Handle h (thread, object);
2733
+
2734
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2723
2735
if (state == nullptr ) {
2724
2736
return ;
2725
2737
}
2726
2738
if (thread->is_in_any_VTMS_transition ()) {
2727
2739
return ; // no events should be posted if thread is in any VTMS transition
2728
2740
}
2729
2741
2730
- HandleMark hm (thread);
2731
- Handle h (thread, object);
2732
-
2733
2742
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_CONTENDED_ENTER,
2734
2743
(" [%s] monitor contended enter event triggered" ,
2735
2744
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2752,17 +2761,17 @@ void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor
2752
2761
2753
2762
void JvmtiExport::post_monitor_contended_entered (JavaThread *thread, ObjectMonitor *obj_mntr) {
2754
2763
oop object = obj_mntr->object ();
2755
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2764
+ HandleMark hm (thread);
2765
+ Handle h (thread, object);
2766
+
2767
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2756
2768
if (state == nullptr ) {
2757
2769
return ;
2758
2770
}
2759
2771
if (thread->is_in_any_VTMS_transition ()) {
2760
2772
return ; // no events should be posted if thread is in any VTMS transition
2761
2773
}
2762
2774
2763
- HandleMark hm (thread);
2764
- Handle h (thread, object);
2765
-
2766
2775
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,
2767
2776
(" [%s] monitor contended entered event triggered" ,
2768
2777
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2786,17 +2795,17 @@ void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonit
2786
2795
2787
2796
void JvmtiExport::post_monitor_wait (JavaThread *thread, oop object,
2788
2797
jlong timeout) {
2789
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2798
+ HandleMark hm (thread);
2799
+ Handle h (thread, object);
2800
+
2801
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2790
2802
if (state == nullptr ) {
2791
2803
return ;
2792
2804
}
2793
2805
if (thread->is_in_any_VTMS_transition ()) {
2794
2806
return ; // no events should be posted if thread is in any VTMS transition
2795
2807
}
2796
2808
2797
- HandleMark hm (thread);
2798
- Handle h (thread, object);
2799
-
2800
2809
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_WAIT,
2801
2810
(" [%s] monitor wait event triggered" ,
2802
2811
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2820,17 +2829,17 @@ void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
2820
2829
2821
2830
void JvmtiExport::post_monitor_waited (JavaThread *thread, ObjectMonitor *obj_mntr, jboolean timed_out) {
2822
2831
oop object = obj_mntr->object ();
2823
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2832
+ HandleMark hm (thread);
2833
+ Handle h (thread, object);
2834
+
2835
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2824
2836
if (state == nullptr ) {
2825
2837
return ;
2826
2838
}
2827
2839
if (thread->is_in_any_VTMS_transition ()) {
2828
2840
return ; // no events should be posted if thread is in any VTMS transition
2829
2841
}
2830
2842
2831
- HandleMark hm (thread);
2832
- Handle h (thread, object);
2833
-
2834
2843
EVT_TRIG_TRACE (JVMTI_EVENT_MONITOR_WAITED,
2835
2844
(" [%s] monitor waited event triggered" ,
2836
2845
JvmtiTrace::safe_get_thread_name (thread)));
@@ -2883,7 +2892,10 @@ void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2883
2892
}
2884
2893
2885
2894
void JvmtiExport::post_sampled_object_alloc (JavaThread *thread, oop object) {
2886
- JvmtiThreadState *state = thread->jvmti_thread_state ();
2895
+ HandleMark hm (thread);
2896
+ Handle h (thread, object);
2897
+
2898
+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
2887
2899
if (state == nullptr ) {
2888
2900
return ;
2889
2901
}
@@ -2893,8 +2905,6 @@ void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
2893
2905
if (thread->is_in_any_VTMS_transition ()) {
2894
2906
return ; // no events should be posted if thread is in any VTMS transition
2895
2907
}
2896
- HandleMark hm (thread);
2897
- Handle h (thread, object);
2898
2908
2899
2909
EVT_TRIG_TRACE (JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
2900
2910
(" [%s] Trg sampled object alloc triggered" ,
0 commit comments