< prev index next >

src/hotspot/share/runtime/handshake.cpp

Print this page
rev 52283 : [mq]: 8212933
rev 52284 : 8212933: Thread-SMR: requesting a VM operation whilst holding a ThreadsListHandle can cause deadlocks
Reviewed-by: eosterlund, dcubed, sspitsyn


 340     return true;
 341 
 342   default:
 343     return false;
 344   }
 345 }
 346 
 347 bool HandshakeState::claim_handshake_for_vmthread() {
 348   if (!_semaphore.trywait()) {
 349     return false;
 350   }
 351   if (has_operation()) {
 352     return true;
 353   }
 354   _semaphore.signal();
 355   return false;
 356 }
 357 
 358 void HandshakeState::process_by_vmthread(JavaThread* target) {
 359   assert(Thread::current()->is_VM_thread(), "should call from vm thread");


 360 
 361   if (!has_operation()) {
 362     // JT has already cleared its handshake
 363     return;
 364   }
 365 
 366   if (!possibly_vmthread_can_process_handshake(target)) {
 367     // JT is observed in an unsafe state, it must notice the handshake itself
 368     return;
 369   }
 370 
 371   // Claim the semaphore if there still an operation to be executed.
 372   if (!claim_handshake_for_vmthread()) {
 373     return;
 374   }
 375 
 376   // If we own the semaphore at this point and while owning the semaphore
 377   // can observe a safe state the thread cannot possibly continue without
 378   // getting caught by the semaphore.
 379   if (vmthread_can_process_handshake(target)) {


 340     return true;
 341 
 342   default:
 343     return false;
 344   }
 345 }
 346 
 347 bool HandshakeState::claim_handshake_for_vmthread() {
 348   if (!_semaphore.trywait()) {
 349     return false;
 350   }
 351   if (has_operation()) {
 352     return true;
 353   }
 354   _semaphore.signal();
 355   return false;
 356 }
 357 
 358 void HandshakeState::process_by_vmthread(JavaThread* target) {
 359   assert(Thread::current()->is_VM_thread(), "should call from vm thread");
 360   // Threads_lock must be held here, but that is assert()ed in
 361   // possibly_vmthread_can_process_handshake().
 362 
 363   if (!has_operation()) {
 364     // JT has already cleared its handshake
 365     return;
 366   }
 367 
 368   if (!possibly_vmthread_can_process_handshake(target)) {
 369     // JT is observed in an unsafe state, it must notice the handshake itself
 370     return;
 371   }
 372 
 373   // Claim the semaphore if there still an operation to be executed.
 374   if (!claim_handshake_for_vmthread()) {
 375     return;
 376   }
 377 
 378   // If we own the semaphore at this point and while owning the semaphore
 379   // can observe a safe state the thread cannot possibly continue without
 380   // getting caught by the semaphore.
 381   if (vmthread_can_process_handshake(target)) {
< prev index next >