@@ -60,41 +60,41 @@ JVM_END
60
60
#if INCLUDE_JVMTI
61
61
class JvmtiUnmountBeginMark : public StackObj {
62
62
Handle _vthread;
63
- JavaThread* _target ;
63
+ JavaThread* _current ;
64
64
freeze_result _result;
65
65
bool _failed;
66
66
67
67
public:
68
68
JvmtiUnmountBeginMark (JavaThread* t) :
69
- _vthread (t, t->vthread ()), _target (t), _result(freeze_pinned_native), _failed(false ) {
70
- assert (!_target ->is_in_VTMS_transition (), " must be" );
69
+ _vthread (t, t->vthread ()), _current (t), _result(freeze_pinned_native), _failed(false ) {
70
+ assert (!_current ->is_in_VTMS_transition (), " must be" );
71
71
72
72
if (JvmtiVTMSTransitionDisabler::VTMS_notify_jvmti_events ()) {
73
73
JvmtiVTMSTransitionDisabler::VTMS_vthread_unmount ((jthread)_vthread.raw_value (), true );
74
74
75
75
// Don't preempt if there is a pending popframe or earlyret operation. This can
76
76
// be installed in start_VTMS_transition() so we need to check it here.
77
77
if (JvmtiExport::can_pop_frame () || JvmtiExport::can_force_early_return ()) {
78
- JvmtiThreadState* state = _target ->jvmti_thread_state ();
79
- if (_target ->has_pending_popframe () || (state != nullptr && state->is_earlyret_pending ())) {
78
+ JvmtiThreadState* state = _current ->jvmti_thread_state ();
79
+ if (_current ->has_pending_popframe () || (state != nullptr && state->is_earlyret_pending ())) {
80
80
_failed = true ;
81
81
}
82
82
}
83
83
84
84
// Don't preempt in case there is an async exception installed since
85
85
// we would incorrectly throw it during the unmount logic in the carrier.
86
- if (_target ->has_async_exception_condition ()) {
86
+ if (_current ->has_async_exception_condition ()) {
87
87
_failed = true ;
88
88
}
89
89
} else {
90
- _target ->set_is_in_VTMS_transition (true );
90
+ _current ->set_is_in_VTMS_transition (true );
91
91
java_lang_Thread::set_is_in_VTMS_transition (_vthread (), true );
92
92
}
93
93
}
94
94
~JvmtiUnmountBeginMark () {
95
- assert (!_target ->is_suspended (), " must be" );
95
+ assert (!_current ->is_suspended (), " must be" );
96
96
97
- assert (_target ->is_in_VTMS_transition (), " must be" );
97
+ assert (_current ->is_in_VTMS_transition (), " must be" );
98
98
assert (java_lang_Thread::is_in_VTMS_transition (_vthread ()), " must be" );
99
99
100
100
// Read it again since for late binding agents the flag could have
@@ -106,7 +106,7 @@ class JvmtiUnmountBeginMark : public StackObj {
106
106
if (jvmti_present) {
107
107
JvmtiVTMSTransitionDisabler::VTMS_vthread_mount ((jthread)_vthread.raw_value (), false );
108
108
} else {
109
- _target ->set_is_in_VTMS_transition (false );
109
+ _current ->set_is_in_VTMS_transition (false );
110
110
java_lang_Thread::set_is_in_VTMS_transition (_vthread (), false );
111
111
}
112
112
}
@@ -115,51 +115,59 @@ class JvmtiUnmountBeginMark : public StackObj {
115
115
bool failed () { return _failed; }
116
116
};
117
117
118
- static bool is_vthread_safe_to_preempt_for_jvmti (JavaThread* target ) {
119
- if (target ->is_in_VTMS_transition ()) {
120
- // We caught target at the end of a mount transition.
118
+ static bool is_vthread_safe_to_preempt_for_jvmti (JavaThread* current ) {
119
+ if (current ->is_in_VTMS_transition ()) {
120
+ // We are at the end of a mount transition.
121
121
return false ;
122
122
}
123
123
return true ;
124
124
}
125
125
#endif // INCLUDE_JVMTI
126
126
127
- static bool is_vthread_safe_to_preempt (JavaThread* target , oop vthread) {
127
+ static bool is_vthread_safe_to_preempt (JavaThread* current , oop vthread) {
128
128
assert (java_lang_VirtualThread::is_instance (vthread), " " );
129
129
if (java_lang_VirtualThread::state (vthread) != java_lang_VirtualThread::RUNNING) { // inside transition
130
130
return false ;
131
131
}
132
- return JVMTI_ONLY (is_vthread_safe_to_preempt_for_jvmti (target )) NOT_JVMTI (true );
132
+ return JVMTI_ONLY (is_vthread_safe_to_preempt_for_jvmti (current )) NOT_JVMTI (true );
133
133
}
134
134
135
135
typedef freeze_result (*FreezeContFnT)(JavaThread*, intptr_t *);
136
136
137
- static void verify_preempt_preconditions (JavaThread* target , oop continuation) {
138
- assert (target == JavaThread::current (), " no support for external preemption" );
139
- assert (target ->has_last_Java_frame (), " " );
140
- assert (!target ->preempting (), " " );
141
- assert (target ->last_continuation () != nullptr , " " );
142
- assert (target ->last_continuation ()->cont_oop (target ) == continuation, " " );
137
+ static void verify_preempt_preconditions (JavaThread* current , oop continuation) {
138
+ assert (current == JavaThread::current (), " no support for external preemption" );
139
+ assert (current ->has_last_Java_frame (), " " );
140
+ assert (!current ->preempting (), " " );
141
+ assert (current ->last_continuation () != nullptr , " " );
142
+ assert (current ->last_continuation ()->cont_oop (current ) == continuation, " " );
143
143
assert (Continuation::continuation_scope (continuation) == java_lang_VirtualThread::vthread_scope (), " " );
144
- assert (!target ->has_pending_exception (), " " );
144
+ assert (!current ->has_pending_exception (), " " );
145
145
}
146
146
147
- freeze_result Continuation::try_preempt (JavaThread* target , oop continuation) {
148
- verify_preempt_preconditions (target , continuation);
147
+ freeze_result Continuation::try_preempt (JavaThread* current , oop continuation) {
148
+ verify_preempt_preconditions (current , continuation);
149
149
150
150
if (LockingMode == LM_LEGACY) {
151
151
return freeze_unsupported;
152
152
}
153
153
154
- if (!is_vthread_safe_to_preempt (target, target ->vthread ())) {
154
+ if (!is_vthread_safe_to_preempt (current, current ->vthread ())) {
155
155
return freeze_pinned_native;
156
156
}
157
157
158
- JVMTI_ONLY (JvmtiUnmountBeginMark jubm (target );)
158
+ JVMTI_ONLY (JvmtiUnmountBeginMark jubm (current );)
159
159
JVMTI_ONLY (if (jubm.failed ()) return freeze_pinned_native;)
160
- freeze_result res = CAST_TO_FN_PTR (FreezeContFnT, freeze_preempt_entry ())(target, target ->last_Java_sp ());
160
+ freeze_result res = CAST_TO_FN_PTR (FreezeContFnT, freeze_preempt_entry ())(current, current ->last_Java_sp ());
161
161
log_trace (continuations, preempt)(" try_preempt: %d" , res);
162
162
JVMTI_ONLY (jubm.set_result (res);)
163
+
164
+ if (current->has_pending_exception ()) {
165
+ assert (res == freeze_exception, " expecting an exception result from freeze" );
166
+ // We don't want to throw exceptions, especially when returning
167
+ // from monitorenter since the compiler does not expect one. We
168
+ // just ignore the exception and pin the vthread to the carrier.
169
+ current->clear_pending_exception ();
170
+ }
163
171
return res;
164
172
}
165
173
0 commit comments