312 ThreadBlockInVMWithDeadlockCheck(JavaThread* thread, Monitor** in_flight_monitor_adr) |
312 ThreadBlockInVMWithDeadlockCheck(JavaThread* thread, Monitor** in_flight_monitor_adr) |
313 : ThreadStateTransition(thread), _in_flight_monitor_adr(in_flight_monitor_adr) { |
313 : ThreadStateTransition(thread), _in_flight_monitor_adr(in_flight_monitor_adr) { |
314 // Once we are blocked vm expects stack to be walkable |
314 // Once we are blocked vm expects stack to be walkable |
315 thread->frame_anchor()->make_walkable(thread); |
315 thread->frame_anchor()->make_walkable(thread); |
316 |
316 |
317 thread->set_thread_state((JavaThreadState)(_thread_in_vm + 1)); |
317 // All unsafe states are treated the same by the VMThread |
318 InterfaceSupport::serialize_thread_state_with_handler(thread); |
318 // so we can skip the _thread_in_vm_trans state here. Since |
319 |
319 // we don't read poll, it's enough to order the stores. |
320 SafepointMechanism::callback_if_safepoint(thread); |
320 OrderAccess::storestore(); |
321 |
321 |
322 thread->set_thread_state(_thread_blocked); |
322 thread->set_thread_state(_thread_blocked); |
323 |
323 |
324 CHECK_UNHANDLED_OOPS_ONLY(_thread->clear_unhandled_oops();) |
324 CHECK_UNHANDLED_OOPS_ONLY(_thread->clear_unhandled_oops();) |
325 } |
325 } |
326 ~ThreadBlockInVMWithDeadlockCheck() { |
326 ~ThreadBlockInVMWithDeadlockCheck() { |
327 // Change to transition state |
327 // Change to transition state |
328 _thread->set_thread_state((JavaThreadState)(_thread_blocked + 1)); |
328 _thread->set_thread_state((JavaThreadState)(_thread_blocked_trans)); |
329 |
329 |
330 InterfaceSupport::serialize_thread_state_with_handler(_thread); |
330 InterfaceSupport::serialize_thread_state_with_handler(_thread); |
331 |
331 |
332 if (SafepointMechanism::should_block(_thread)) { |
332 if (SafepointMechanism::should_block(_thread)) { |
333 release_monitor(); |
333 release_monitor(); |
334 SafepointMechanism::callback_if_safepoint(_thread); |
334 SafepointMechanism::block_if_requested(_thread); |
335 // The VMThread might have read that we were in a _thread_blocked state |
|
336 // and proceeded to process a handshake for us. If that's the case then |
|
337 // we need to block. |
|
338 // By doing this we are also making the current thread process its own |
|
339 // handshake if there is one pending and the VMThread didn't try to process |
|
340 // it yet. This is more of a side-effect and not really necessary; the |
|
341 // handshake could be processed later on. |
|
342 if (_thread->has_handshake()) { |
|
343 _thread->handshake_process_by_self(); |
|
344 } |
|
345 } |
335 } |
346 |
336 |
347 _thread->set_thread_state(_thread_in_vm); |
337 _thread->set_thread_state(_thread_in_vm); |
348 CHECK_UNHANDLED_OOPS_ONLY(_thread->clear_unhandled_oops();) |
338 CHECK_UNHANDLED_OOPS_ONLY(_thread->clear_unhandled_oops();) |
349 } |
339 } |