src/hotspot/share/runtime/thread.cpp
changeset 58095 adc72cd1d1f2
parent 58084 cddef3bde924
child 58124 dc792fa77da0
child 58154 060d9d139109
equal deleted inserted replaced
58094:0f6c749acd15 58095:adc72cd1d1f2
   289   // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents
   289   // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents
   290   // we might instead use a stack of ParkEvents that we could provision on-demand.
   290   // we might instead use a stack of ParkEvents that we could provision on-demand.
   291   // The stack would act as a cache to avoid calls to ParkEvent::Allocate()
   291   // The stack would act as a cache to avoid calls to ParkEvent::Allocate()
   292   // and ::Release()
   292   // and ::Release()
   293   _ParkEvent   = ParkEvent::Allocate(this);
   293   _ParkEvent   = ParkEvent::Allocate(this);
   294   _SleepEvent  = ParkEvent::Allocate(this);
       
   295   _MuxEvent    = ParkEvent::Allocate(this);
   294   _MuxEvent    = ParkEvent::Allocate(this);
   296 
   295 
   297 #ifdef CHECK_UNHANDLED_OOPS
   296 #ifdef CHECK_UNHANDLED_OOPS
   298   if (CheckUnhandledOops) {
   297   if (CheckUnhandledOops) {
   299     _unhandled_oops = new UnhandledOops(this);
   298     _unhandled_oops = new UnhandledOops(this);
   454   assert(last_handle_mark() == NULL, "check we have reached the end");
   453   assert(last_handle_mark() == NULL, "check we have reached the end");
   455 
   454 
   456   // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads.
   455   // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads.
   457   // We NULL out the fields for good hygiene.
   456   // We NULL out the fields for good hygiene.
   458   ParkEvent::Release(_ParkEvent); _ParkEvent   = NULL;
   457   ParkEvent::Release(_ParkEvent); _ParkEvent   = NULL;
   459   ParkEvent::Release(_SleepEvent); _SleepEvent  = NULL;
       
   460   ParkEvent::Release(_MuxEvent); _MuxEvent    = NULL;
   458   ParkEvent::Release(_MuxEvent); _MuxEvent    = NULL;
   461 
   459 
   462   delete handle_area();
   460   delete handle_area();
   463   delete metadata_handles();
   461   delete metadata_handles();
   464 
   462 
  1694   _jni_active_critical = 0;
  1692   _jni_active_critical = 0;
  1695   _pending_jni_exception_check_fn = NULL;
  1693   _pending_jni_exception_check_fn = NULL;
  1696   _do_not_unlock_if_synchronized = false;
  1694   _do_not_unlock_if_synchronized = false;
  1697   _cached_monitor_info = NULL;
  1695   _cached_monitor_info = NULL;
  1698   _parker = Parker::Allocate(this);
  1696   _parker = Parker::Allocate(this);
  1699 
  1697   _SleepEvent = ParkEvent::Allocate(this);
  1700   // Setup safepoint state info for this thread
  1698   // Setup safepoint state info for this thread
  1701   ThreadSafepointState::create(this);
  1699   ThreadSafepointState::create(this);
  1702 
  1700 
  1703   debug_only(_java_call_counter = 0);
  1701   debug_only(_java_call_counter = 0);
  1704 
  1702 
  1805 JavaThread::~JavaThread() {
  1803 JavaThread::~JavaThread() {
  1806 
  1804 
  1807   // JSR166 -- return the parker to the free list
  1805   // JSR166 -- return the parker to the free list
  1808   Parker::Release(_parker);
  1806   Parker::Release(_parker);
  1809   _parker = NULL;
  1807   _parker = NULL;
       
  1808 
       
  1809   // Return the sleep event to the free list
       
  1810   ParkEvent::Release(_SleepEvent);
       
  1811   _SleepEvent = NULL;
  1810 
  1812 
  1811   // Free any remaining  previous UnrollBlock
  1813   // Free any remaining  previous UnrollBlock
  1812   vframeArray* old_array = vframe_array_last();
  1814   vframeArray* old_array = vframe_array_last();
  1813 
  1815 
  1814   if (old_array != NULL) {
  1816   if (old_array != NULL) {
  3335   vfst.security_get_caller_frame(depth);
  3337   vfst.security_get_caller_frame(depth);
  3336   if (!vfst.at_end()) {
  3338   if (!vfst.at_end()) {
  3337     return vfst.method()->method_holder();
  3339     return vfst.method()->method_holder();
  3338   }
  3340   }
  3339   return NULL;
  3341   return NULL;
       
  3342 }
       
  3343 
       
  3344 // java.lang.Thread.sleep support
       
  3345 // Returns true if sleep time elapsed as expected, and false
       
  3346 // if the thread was interrupted.
       
  3347 bool JavaThread::sleep(jlong millis) {
       
  3348   assert(this == Thread::current(),  "thread consistency check");
       
  3349 
       
  3350   ParkEvent * const slp = this->_SleepEvent;
       
  3351   // Because there can be races with thread interruption sending an unpark()
       
  3352   // to the event, we explicitly reset it here to avoid an immediate return.
       
  3353   // The actual interrupt state will be checked before we park().
       
  3354   slp->reset();
       
  3355   // Thread interruption establishes a happens-before ordering in the
       
  3356   // Java Memory Model, so we need to ensure we synchronize with the
       
  3357   // interrupt state.
       
  3358   OrderAccess::fence();
       
  3359 
       
  3360   jlong prevtime = os::javaTimeNanos();
       
  3361 
       
  3362   for (;;) {
       
  3363     // interruption has precedence over timing out
       
  3364     if (os::is_interrupted(this, true)) {
       
  3365       return false;
       
  3366     }
       
  3367 
       
  3368     if (millis <= 0) {
       
  3369       return true;
       
  3370     }
       
  3371 
       
  3372     {
       
  3373       ThreadBlockInVM tbivm(this);
       
  3374       OSThreadWaitState osts(this->osthread(), false /* not Object.wait() */);
       
  3375 
       
  3376       this->set_suspend_equivalent();
       
  3377       // cleared by handle_special_suspend_equivalent_condition() or
       
  3378       // java_suspend_self() via check_and_wait_while_suspended()
       
  3379 
       
  3380       slp->park(millis);
       
  3381 
       
  3382       // were we externally suspended while we were waiting?
       
  3383       this->check_and_wait_while_suspended();
       
  3384     }
       
  3385 
       
  3386     // Update elapsed time tracking
       
  3387     jlong newtime = os::javaTimeNanos();
       
  3388     if (newtime - prevtime < 0) {
       
  3389       // time moving backwards, should only happen if no monotonic clock
       
  3390       // not a guarantee() because JVM should not abort on kernel/glibc bugs
       
  3391       assert(!os::supports_monotonic_clock(),
       
  3392              "unexpected time moving backwards detected in os::sleep()");
       
  3393     } else {
       
  3394       millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
       
  3395     }
       
  3396     prevtime = newtime;
       
  3397   }
  3340 }
  3398 }
  3341 
  3399 
  3342 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  3400 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  3343   assert(thread->is_Compiler_thread(), "must be compiler thread");
  3401   assert(thread->is_Compiler_thread(), "must be compiler thread");
  3344   CompileBroker::compiler_thread_loop();
  3402   CompileBroker::compiler_thread_loop();