src/hotspot/share/runtime/thread.cpp
changeset 54323 846bc643f4ef
parent 54291 e6c86f6012bf
child 54329 ddd60ad787d4
equal deleted inserted replaced
54322:cf75ea6af695 54323:846bc643f4ef
  1834   this->cache_global_variables();
  1834   this->cache_global_variables();
  1835 
  1835 
  1836   // Thread is now sufficiently initialized to be handled by the safepoint code as being
  1836   // Thread is now sufficiently initialized to be handled by the safepoint code as being
  1837   // in the VM. Change thread state from _thread_new to _thread_in_vm
  1837   // in the VM. Change thread state from _thread_new to _thread_in_vm
  1838   ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  1838   ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
       
  1839   // Before a thread is on the threads list it is always safe, so after leaving the
       
  1840   // _thread_new we should emit a instruction barrier. The distance to modified code
       
  1841   // from here is probably far enough, but this is consistent and safe.
       
  1842   OrderAccess::cross_modify_fence();
  1839 
  1843 
  1840   assert(JavaThread::current() == this, "sanity check");
  1844   assert(JavaThread::current() == this, "sanity check");
  1841   assert(!Thread::current()->owns_locks(), "sanity check");
  1845   assert(!Thread::current()->owns_locks(), "sanity check");
  1842 
  1846 
  1843   DTRACE_THREAD_PROBE(start, this);
  1847   DTRACE_THREAD_PROBE(start, this);
  2437     // _ext_suspended flag is cleared by java_resume()
  2441     // _ext_suspended flag is cleared by java_resume()
  2438     while (is_ext_suspended()) {
  2442     while (is_ext_suspended()) {
  2439       this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
  2443       this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
  2440     }
  2444     }
  2441   }
  2445   }
  2442 
       
  2443   return ret;
  2446   return ret;
  2444 }
  2447 }
  2445 
  2448 
  2446 // Helper routine to set up the correct thread state before calling java_suspend_self.
  2449 // Helper routine to set up the correct thread state before calling java_suspend_self.
  2447 // This is called when regular thread-state transition helpers can't be used because
  2450 // This is called when regular thread-state transition helpers can't be used because
  2465   assert(this == Thread::current(), "invariant");
  2468   assert(this == Thread::current(), "invariant");
  2466   JavaThreadState state = thread_state();
  2469   JavaThreadState state = thread_state();
  2467   set_thread_state(_thread_blocked);
  2470   set_thread_state(_thread_blocked);
  2468   java_suspend_self();
  2471   java_suspend_self();
  2469   set_thread_state(state);
  2472   set_thread_state(state);
       
  2473   // Since we are not using a regular thread-state transition helper here,
       
  2474   // we must manually emit the instruction barrier after leaving a safe state.
       
  2475   OrderAccess::cross_modify_fence();
  2470   InterfaceSupport::serialize_thread_state_with_handler(this);
  2476   InterfaceSupport::serialize_thread_state_with_handler(this);
  2471   if (state != _thread_in_native) {
  2477   if (state != _thread_in_native) {
  2472     SafepointMechanism::block_if_requested(this);
  2478     SafepointMechanism::block_if_requested(this);
  2473   }
  2479   }
  2474 }
  2480 }