153 if (!is_vthread_safe_to_preempt(current, current->vthread())) {
154 return freeze_pinned_native;
155 }
156
157 JVMTI_ONLY(JvmtiUnmountBeginMark jubm(current);)
158 JVMTI_ONLY(if (jubm.failed()) return freeze_pinned_native;)
159 freeze_result res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(current, current->last_Java_sp());
160 log_trace(continuations, preempt)("try_preempt: %d", res);
161 JVMTI_ONLY(jubm.set_result(res);)
162
163 if (current->has_pending_exception()) {
164 assert(res == freeze_exception, "expecting an exception result from freeze");
165 // We don't want to throw exceptions, especially when returning
166 // from monitorenter since the compiler does not expect one. We
167 // just ignore the exception and pin the vthread to the carrier.
168 current->clear_pending_exception();
169 }
170 return res;
171 }
172
173 #ifndef PRODUCT
174 static jlong java_tid(JavaThread* thread) {
175 return java_lang_Thread::thread_id(thread->threadObj());
176 }
177 #endif
178
179 ContinuationEntry* Continuation::get_continuation_entry_for_continuation(JavaThread* thread, oop continuation) {
180 if (thread == nullptr || continuation == nullptr) {
181 return nullptr;
182 }
183
184 for (ContinuationEntry* entry = thread->last_continuation(); entry != nullptr; entry = entry->parent()) {
185 if (continuation == entry->cont_oop(thread)) {
186 return entry;
187 }
188 }
189 return nullptr;
190 }
191
192 static bool is_on_stack(JavaThread* thread, const ContinuationEntry* entry) {
193 if (entry == nullptr) {
194 return false;
195 }
196
197 assert(thread->is_in_full_stack((address)entry), "");
198 return true;
388 ContinuationEntry* ce = current->last_continuation();
389 if (ce == nullptr) {
390 return true; // no continuation mounted
391 }
392 return ce->pin();
393 }
394
395 bool Continuation::unpin(JavaThread* current) {
396 ContinuationEntry* ce = current->last_continuation();
397 if (ce == nullptr) {
398 return true; // no continuation mounted
399 }
400 return ce->unpin();
401 }
402
403 frame Continuation::continuation_bottom_sender(JavaThread* thread, const frame& callee, intptr_t* sender_sp) {
404 assert (thread != nullptr, "");
405 ContinuationEntry* ce = get_continuation_entry_for_sp(thread, callee.sp());
406 assert(ce != nullptr, "callee.sp(): " INTPTR_FORMAT, p2i(callee.sp()));
407
408 log_develop_debug(continuations)("continuation_bottom_sender: [" JLONG_FORMAT "] [%d] callee: " INTPTR_FORMAT
409 " sender_sp: " INTPTR_FORMAT,
410 java_tid(thread), thread->osthread()->thread_id(), p2i(callee.sp()), p2i(sender_sp));
411
412 frame entry = ce->to_frame();
413 if (callee.is_interpreted_frame()) {
414 entry.set_sp(sender_sp); // sp != unextended_sp
415 }
416 return entry;
417 }
418
419 address Continuation::get_top_return_pc_post_barrier(JavaThread* thread, address pc) {
420 ContinuationEntry* ce;
421 if (thread != nullptr && is_return_barrier_entry(pc) && (ce = thread->last_continuation()) != nullptr) {
422 return ce->entry_pc();
423 }
424 return pc;
425 }
426
427 void Continuation::set_cont_fastpath_thread_state(JavaThread* thread) {
428 assert(thread != nullptr, "");
429 bool fast = !thread->is_interp_only_mode();
430 thread->set_cont_fastpath_thread_state(fast);
|
153 if (!is_vthread_safe_to_preempt(current, current->vthread())) {
154 return freeze_pinned_native;
155 }
156
157 JVMTI_ONLY(JvmtiUnmountBeginMark jubm(current);)
158 JVMTI_ONLY(if (jubm.failed()) return freeze_pinned_native;)
159 freeze_result res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(current, current->last_Java_sp());
160 log_trace(continuations, preempt)("try_preempt: %d", res);
161 JVMTI_ONLY(jubm.set_result(res);)
162
163 if (current->has_pending_exception()) {
164 assert(res == freeze_exception, "expecting an exception result from freeze");
165 // We don't want to throw exceptions, especially when returning
166 // from monitorenter since the compiler does not expect one. We
167 // just ignore the exception and pin the vthread to the carrier.
168 current->clear_pending_exception();
169 }
170 return res;
171 }
172
173 ContinuationEntry* Continuation::get_continuation_entry_for_continuation(JavaThread* thread, oop continuation) {
174 if (thread == nullptr || continuation == nullptr) {
175 return nullptr;
176 }
177
178 for (ContinuationEntry* entry = thread->last_continuation(); entry != nullptr; entry = entry->parent()) {
179 if (continuation == entry->cont_oop(thread)) {
180 return entry;
181 }
182 }
183 return nullptr;
184 }
185
186 static bool is_on_stack(JavaThread* thread, const ContinuationEntry* entry) {
187 if (entry == nullptr) {
188 return false;
189 }
190
191 assert(thread->is_in_full_stack((address)entry), "");
192 return true;
382 ContinuationEntry* ce = current->last_continuation();
383 if (ce == nullptr) {
384 return true; // no continuation mounted
385 }
386 return ce->pin();
387 }
388
389 bool Continuation::unpin(JavaThread* current) {
390 ContinuationEntry* ce = current->last_continuation();
391 if (ce == nullptr) {
392 return true; // no continuation mounted
393 }
394 return ce->unpin();
395 }
396
397 frame Continuation::continuation_bottom_sender(JavaThread* thread, const frame& callee, intptr_t* sender_sp) {
398 assert (thread != nullptr, "");
399 ContinuationEntry* ce = get_continuation_entry_for_sp(thread, callee.sp());
400 assert(ce != nullptr, "callee.sp(): " INTPTR_FORMAT, p2i(callee.sp()));
401
402 log_develop_debug(continuations)("continuation_bottom_sender: [%d] callee: " INTPTR_FORMAT " sender_sp: " INTPTR_FORMAT,
403 thread->osthread()->thread_id(), p2i(callee.sp()), p2i(sender_sp));
404
405 frame entry = ce->to_frame();
406 if (callee.is_interpreted_frame()) {
407 entry.set_sp(sender_sp); // sp != unextended_sp
408 }
409 return entry;
410 }
411
412 address Continuation::get_top_return_pc_post_barrier(JavaThread* thread, address pc) {
413 ContinuationEntry* ce;
414 if (thread != nullptr && is_return_barrier_entry(pc) && (ce = thread->last_continuation()) != nullptr) {
415 return ce->entry_pc();
416 }
417 return pc;
418 }
419
420 void Continuation::set_cont_fastpath_thread_state(JavaThread* thread) {
421 assert(thread != nullptr, "");
422 bool fast = !thread->is_interp_only_mode();
423 thread->set_cont_fastpath_thread_state(fast);
|