< prev index next >

src/hotspot/share/runtime/continuation.cpp

Print this page

134   if (!is_vthread_safe_to_preempt(current, current->vthread())) {
135     return freeze_pinned_native;
136   }
137 
138   UnmountBeginMark ubm(current);
139   if (ubm.failed()) return freeze_pinned_native;
140   freeze_result res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(current, current->last_Java_sp());
141   log_trace(continuations, preempt)("try_preempt: %d", res);
142   ubm.set_result(res);
143 
144   if (current->has_pending_exception()) {
145     assert(res == freeze_exception, "expecting an exception result from freeze");
146     // We don't want to throw exceptions, especially when returning
147     // from monitorenter since the compiler does not expect one. We
148     // just ignore the exception and pin the vthread to the carrier.
149     current->clear_pending_exception();
150   }
151   return res;
152 }
153 
154 #ifndef PRODUCT
155 static jlong java_tid(JavaThread* thread) {
156   return java_lang_Thread::thread_id(thread->threadObj());
157 }
158 #endif
159 
160 ContinuationEntry* Continuation::get_continuation_entry_for_continuation(JavaThread* thread, oop continuation) {
161   if (thread == nullptr || continuation == nullptr) {
162     return nullptr;
163   }
164 
165   for (ContinuationEntry* entry = thread->last_continuation(); entry != nullptr; entry = entry->parent()) {
166     if (continuation == entry->cont_oop(thread)) {
167       return entry;
168     }
169   }
170   return nullptr;
171 }
172 
173 static bool is_on_stack(JavaThread* thread, const ContinuationEntry* entry) {
174   if (entry == nullptr) {
175     return false;
176   }
177 
178   assert(thread->is_in_full_stack((address)entry), "");
179   return true;

369   ContinuationEntry* ce = current->last_continuation();
370   if (ce == nullptr) {
371     return true; // no continuation mounted
372   }
373   return ce->pin();
374 }
375 
376 bool Continuation::unpin(JavaThread* current) {
377   ContinuationEntry* ce = current->last_continuation();
378   if (ce == nullptr) {
379     return true; // no continuation mounted
380   }
381   return ce->unpin();
382 }
383 
384 frame Continuation::continuation_bottom_sender(JavaThread* thread, const frame& callee, intptr_t* sender_sp) {
385   assert (thread != nullptr, "");
386   ContinuationEntry* ce = get_continuation_entry_for_sp(thread, callee.sp());
387   assert(ce != nullptr, "callee.sp(): " INTPTR_FORMAT, p2i(callee.sp()));
388 
389   log_develop_debug(continuations)("continuation_bottom_sender: [" JLONG_FORMAT "] [%d] callee: " INTPTR_FORMAT
390     " sender_sp: " INTPTR_FORMAT,
391     java_tid(thread), thread->osthread()->thread_id(), p2i(callee.sp()), p2i(sender_sp));
392 
393   frame entry = ce->to_frame();
394   if (callee.is_interpreted_frame()) {
395     entry.set_sp(sender_sp); // sp != unextended_sp
396   }
397   return entry;
398 }
399 
400 address Continuation::get_top_return_pc_post_barrier(JavaThread* thread, address pc) {
401   ContinuationEntry* ce;
402   if (thread != nullptr && is_return_barrier_entry(pc) && (ce = thread->last_continuation()) != nullptr) {
403     return ce->entry_pc();
404   }
405   return pc;
406 }
407 
408 void Continuation::set_cont_fastpath_thread_state(JavaThread* thread) {
409   assert(thread != nullptr, "");
410   bool fast = !thread->is_interp_only_mode();
411   thread->set_cont_fastpath_thread_state(fast);

134   if (!is_vthread_safe_to_preempt(current, current->vthread())) {
135     return freeze_pinned_native;
136   }
137 
138   UnmountBeginMark ubm(current);
139   if (ubm.failed()) return freeze_pinned_native;
140   freeze_result res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(current, current->last_Java_sp());
141   log_trace(continuations, preempt)("try_preempt: %d", res);
142   ubm.set_result(res);
143 
144   if (current->has_pending_exception()) {
145     assert(res == freeze_exception, "expecting an exception result from freeze");
146     // We don't want to throw exceptions, especially when returning
147     // from monitorenter since the compiler does not expect one. We
148     // just ignore the exception and pin the vthread to the carrier.
149     current->clear_pending_exception();
150   }
151   return res;
152 }
153 






154 ContinuationEntry* Continuation::get_continuation_entry_for_continuation(JavaThread* thread, oop continuation) {
155   if (thread == nullptr || continuation == nullptr) {
156     return nullptr;
157   }
158 
159   for (ContinuationEntry* entry = thread->last_continuation(); entry != nullptr; entry = entry->parent()) {
160     if (continuation == entry->cont_oop(thread)) {
161       return entry;
162     }
163   }
164   return nullptr;
165 }
166 
167 static bool is_on_stack(JavaThread* thread, const ContinuationEntry* entry) {
168   if (entry == nullptr) {
169     return false;
170   }
171 
172   assert(thread->is_in_full_stack((address)entry), "");
173   return true;

363   ContinuationEntry* ce = current->last_continuation();
364   if (ce == nullptr) {
365     return true; // no continuation mounted
366   }
367   return ce->pin();
368 }
369 
370 bool Continuation::unpin(JavaThread* current) {
371   ContinuationEntry* ce = current->last_continuation();
372   if (ce == nullptr) {
373     return true; // no continuation mounted
374   }
375   return ce->unpin();
376 }
377 
378 frame Continuation::continuation_bottom_sender(JavaThread* thread, const frame& callee, intptr_t* sender_sp) {
379   assert (thread != nullptr, "");
380   ContinuationEntry* ce = get_continuation_entry_for_sp(thread, callee.sp());
381   assert(ce != nullptr, "callee.sp(): " INTPTR_FORMAT, p2i(callee.sp()));
382 
383   log_develop_debug(continuations)("continuation_bottom_sender: [%d] callee: " INTPTR_FORMAT " sender_sp: " INTPTR_FORMAT,
384       thread->osthread()->thread_id(), p2i(callee.sp()), p2i(sender_sp));

385 
386   frame entry = ce->to_frame();
387   if (callee.is_interpreted_frame()) {
388     entry.set_sp(sender_sp); // sp != unextended_sp
389   }
390   return entry;
391 }
392 
393 address Continuation::get_top_return_pc_post_barrier(JavaThread* thread, address pc) {
394   ContinuationEntry* ce;
395   if (thread != nullptr && is_return_barrier_entry(pc) && (ce = thread->last_continuation()) != nullptr) {
396     return ce->entry_pc();
397   }
398   return pc;
399 }
400 
401 void Continuation::set_cont_fastpath_thread_state(JavaThread* thread) {
402   assert(thread != nullptr, "");
403   bool fast = !thread->is_interp_only_mode();
404   thread->set_cont_fastpath_thread_state(fast);
< prev index next >