< prev index next >

src/hotspot/os/solaris/os_solaris.cpp

Print this page




5046   assert(absTime->tv_sec >= 0, "tv_sec < 0");
5047   assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
5048   assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
5049   assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
5050 }
5051 
5052 void Parker::park(bool isAbsolute, jlong time) {
5053   // Ideally we'd do something useful while spinning, such
5054   // as calling unpackTime().
5055 
5056   // Optional fast-path check:
5057   // Return immediately if a permit is available.
5058   // We depend on Atomic::xchg() having full barrier semantics
5059   // since we are doing a lock-free update to _counter.
5060   if (Atomic::xchg(0, &_counter) > 0) return;
5061 
5062   // Optional fast-exit: Check interrupt before trying to wait
5063   Thread* thread = Thread::current();
5064   assert(thread->is_Java_thread(), "Must be JavaThread");
5065   JavaThread *jt = (JavaThread *)thread;
5066   if (Thread::is_interrupted(thread, false)) {
5067     return;
5068   }
5069 
5070   // First, demultiplex/decode time arguments
5071   timespec absTime;
5072   if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
5073     return;
5074   }
5075   if (time > 0) {
5076     // Warning: this code might be exposed to the old Solaris time
5077     // round-down bugs.  Grep "roundingFix" for details.
5078     unpackTime(&absTime, isAbsolute, time);
5079   }
5080 
5081   // Enter safepoint region
5082   // Beware of deadlocks such as 6317397.
5083   // The per-thread Parker:: _mutex is a classic leaf-lock.
5084   // In particular a thread must never block on the Threads_lock while
5085   // holding the Parker:: mutex.  If safepoints are pending both the
5086   // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
5087   ThreadBlockInVM tbivm(jt);
5088 
5089   // Don't wait if cannot get lock since interference arises from
5090   // unblocking.  Also. check interrupt before trying wait
5091   if (Thread::is_interrupted(thread, false) ||
5092       os::Solaris::mutex_trylock(_mutex) != 0) {
5093     return;
5094   }
5095 
5096   int status;
5097 
5098   if (_counter > 0)  { // no wait needed
5099     _counter = 0;
5100     status = os::Solaris::mutex_unlock(_mutex);
5101     assert(status == 0, "invariant");
5102     // Paranoia to ensure our locked and lock-free paths interact
5103     // correctly with each other and Java-level accesses.
5104     OrderAccess::fence();
5105     return;
5106   }
5107 
5108   OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
5109   jt->set_suspend_equivalent();
5110   // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
5111 




5046   assert(absTime->tv_sec >= 0, "tv_sec < 0");
5047   assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
5048   assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
5049   assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
5050 }
5051 
5052 void Parker::park(bool isAbsolute, jlong time) {
5053   // Ideally we'd do something useful while spinning, such
5054   // as calling unpackTime().
5055 
5056   // Optional fast-path check:
5057   // Return immediately if a permit is available.
5058   // We depend on Atomic::xchg() having full barrier semantics
5059   // since we are doing a lock-free update to _counter.
5060   if (Atomic::xchg(0, &_counter) > 0) return;
5061 
5062   // Optional fast-exit: Check interrupt before trying to wait
5063   Thread* thread = Thread::current();
5064   assert(thread->is_Java_thread(), "Must be JavaThread");
5065   JavaThread *jt = (JavaThread *)thread;
5066   if (jt->is_interrupted(false)) {
5067     return;
5068   }
5069 
5070   // First, demultiplex/decode time arguments
5071   timespec absTime;
5072   if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
5073     return;
5074   }
5075   if (time > 0) {
5076     // Warning: this code might be exposed to the old Solaris time
5077     // round-down bugs.  Grep "roundingFix" for details.
5078     unpackTime(&absTime, isAbsolute, time);
5079   }
5080 
5081   // Enter safepoint region
5082   // Beware of deadlocks such as 6317397.
5083   // The per-thread Parker:: _mutex is a classic leaf-lock.
5084   // In particular a thread must never block on the Threads_lock while
5085   // holding the Parker:: mutex.  If safepoints are pending both the
5086   // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
5087   ThreadBlockInVM tbivm(jt);
5088 
5089   // Don't wait if cannot get lock since interference arises from
5090   // unblocking.  Also. check interrupt before trying wait
5091   if (jt->is_interrupted(false) ||
5092       os::Solaris::mutex_trylock(_mutex) != 0) {
5093     return;
5094   }
5095 
5096   int status;
5097 
5098   if (_counter > 0)  { // no wait needed
5099     _counter = 0;
5100     status = os::Solaris::mutex_unlock(_mutex);
5101     assert(status == 0, "invariant");
5102     // Paranoia to ensure our locked and lock-free paths interact
5103     // correctly with each other and Java-level accesses.
5104     OrderAccess::fence();
5105     return;
5106   }
5107 
5108   OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
5109   jt->set_suspend_equivalent();
5110   // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
5111 


< prev index next >