@@ -60,41 +60,41 @@ JVM_END
6060#if INCLUDE_JVMTI
6161class JvmtiUnmountBeginMark : public StackObj {
6262 Handle _vthread;
63- JavaThread* _target ;
63+ JavaThread* _current ;
6464 freeze_result _result;
6565 bool _failed;
6666
6767 public:
6868 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" );
7171
7272 if (JvmtiVTMSTransitionDisabler::VTMS_notify_jvmti_events ()) {
7373 JvmtiVTMSTransitionDisabler::VTMS_vthread_unmount ((jthread)_vthread.raw_value (), true );
7474
7575 // Don't preempt if there is a pending popframe or earlyret operation. This can
7676 // be installed in start_VTMS_transition() so we need to check it here.
7777 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 ())) {
8080 _failed = true ;
8181 }
8282 }
8383
8484 // Don't preempt in case there is an async exception installed since
8585 // 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 ()) {
8787 _failed = true ;
8888 }
8989 } else {
90- _target ->set_is_in_VTMS_transition (true );
90+ _current ->set_is_in_VTMS_transition (true );
9191 java_lang_Thread::set_is_in_VTMS_transition (_vthread (), true );
9292 }
9393 }
9494 ~JvmtiUnmountBeginMark () {
95- assert (!_target ->is_suspended (), " must be" );
95+ assert (!_current ->is_suspended (), " must be" );
9696
97- assert (_target ->is_in_VTMS_transition (), " must be" );
97+ assert (_current ->is_in_VTMS_transition (), " must be" );
9898 assert (java_lang_Thread::is_in_VTMS_transition (_vthread ()), " must be" );
9999
100100 // Read it again since for late binding agents the flag could have
@@ -106,7 +106,7 @@ class JvmtiUnmountBeginMark : public StackObj {
106106 if (jvmti_present) {
107107 JvmtiVTMSTransitionDisabler::VTMS_vthread_mount ((jthread)_vthread.raw_value (), false );
108108 } else {
109- _target ->set_is_in_VTMS_transition (false );
109+ _current ->set_is_in_VTMS_transition (false );
110110 java_lang_Thread::set_is_in_VTMS_transition (_vthread (), false );
111111 }
112112 }
@@ -115,51 +115,59 @@ class JvmtiUnmountBeginMark : public StackObj {
115115 bool failed () { return _failed; }
116116};
117117
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.
121121 return false ;
122122 }
123123 return true ;
124124}
125125#endif // INCLUDE_JVMTI
126126
127- static bool is_vthread_safe_to_preempt (JavaThread* target , oop vthread) {
127+ static bool is_vthread_safe_to_preempt (JavaThread* current , oop vthread) {
128128 assert (java_lang_VirtualThread::is_instance (vthread), " " );
129129 if (java_lang_VirtualThread::state (vthread) != java_lang_VirtualThread::RUNNING) { // inside transition
130130 return false ;
131131 }
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 );
133133}
134134
135135typedef freeze_result (*FreezeContFnT)(JavaThread*, intptr_t *);
136136
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, " " );
143143 assert (Continuation::continuation_scope (continuation) == java_lang_VirtualThread::vthread_scope (), " " );
144- assert (!target ->has_pending_exception (), " " );
144+ assert (!current ->has_pending_exception (), " " );
145145}
146146
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);
149149
150150 if (LockingMode == LM_LEGACY) {
151151 return freeze_unsupported;
152152 }
153153
154- if (!is_vthread_safe_to_preempt (target, target ->vthread ())) {
154+ if (!is_vthread_safe_to_preempt (current, current ->vthread ())) {
155155 return freeze_pinned_native;
156156 }
157157
158- JVMTI_ONLY (JvmtiUnmountBeginMark jubm (target );)
158+ JVMTI_ONLY (JvmtiUnmountBeginMark jubm (current );)
159159 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 ());
161161 log_trace (continuations, preempt)(" try_preempt: %d" , res);
162162 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+ }
163171 return res;
164172}
165173
0 commit comments