< prev index next >
src/hotspot/share/runtime/os.cpp
Print this page
*** 1846,1904 ****
naked_short_sleep(limit);
millis -= limit;
}
naked_short_sleep(millis);
}
-
- int os::sleep(JavaThread* thread, jlong millis) {
- assert(thread == Thread::current(), "thread consistency check");
-
- ParkEvent * const slp = thread->_SleepEvent;
- // Because there can be races with thread interruption sending an unpark()
- // to the event, we explicitly reset it here to avoid an immediate return.
- // The actual interrupt state will be checked before we park().
- slp->reset();
- // Thread interruption establishes a happens-before ordering in the
- // Java Memory Model, so we need to ensure we synchronize with the
- // interrupt state.
- OrderAccess::fence();
-
- jlong prevtime = javaTimeNanos();
-
- for (;;) {
- // interruption has precedence over timing out
- if (os::is_interrupted(thread, true)) {
- return OS_INTRPT;
- }
-
- jlong newtime = javaTimeNanos();
-
- if (newtime - prevtime < 0) {
- // time moving backwards, should only happen if no monotonic clock
- // not a guarantee() because JVM should not abort on kernel/glibc bugs
- assert(!os::supports_monotonic_clock(),
- "unexpected time moving backwards detected in os::sleep()");
- } else {
- millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
- }
-
- if (millis <= 0) {
- return OS_OK;
- }
-
- prevtime = newtime;
-
- {
- ThreadBlockInVM tbivm(thread);
- OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
-
- thread->set_suspend_equivalent();
- // cleared by handle_special_suspend_equivalent_condition() or
- // java_suspend_self() via check_and_wait_while_suspended()
-
- slp->park(millis);
-
- // were we externally suspended while we were waiting?
- thread->check_and_wait_while_suspended();
- }
- }
- }
--- 1846,1850 ----
< prev index next >