diff -r dd5d7ba5b539 -r 33b8f6f4cdf5 src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp Thu Dec 20 02:51:01 2018 +0100 +++ b/src/hotspot/os/windows/os_windows.cpp Thu Dec 20 10:05:19 2018 +0100 @@ -3512,6 +3512,43 @@ Sleep(ms); } +void os::naked_short_nanosleep(jlong ns) { + assert(ns > -1 && ns < NANOUNITS, "Un-interruptable sleep, short time use only"); + LARGE_INTEGER hundreds_nanos = { 0 }; + HANDLE wait_timer = ::CreateWaitableTimer(NULL /* attributes*/, + true /* manual reset */, + NULL /* name */ ); + if (wait_timer == NULL) { + log_warning(os)("Failed to CreateWaitableTimer: %u", GetLastError()); + return; + } + + // We need a minimum of one hundred nanos. + ns = ns > 100 ? ns : 100; + + // Round ns to the nearst hundred of nanos. + // Negative values indicate relative time. + hundreds_nanos.QuadPart = -((ns + 50) / 100); + + if (::SetWaitableTimer(wait_timer /* handle */, + &hundreds_nanos /* due time */, + 0 /* period */, + NULL /* comp func */, + NULL /* comp func args */, + FALSE /* resume */)) { + DWORD res = ::WaitForSingleObject(wait_timer /* handle */, INFINITE /* timeout */); + if (res != WAIT_OBJECT_0) { + if (res == WAIT_FAILED) { + log_warning(os)("Failed to WaitForSingleObject: %u", GetLastError()); + } else { + log_warning(os)("Unexpected return from WaitForSingleObject: %s", + res == WAIT_ABANDONED ? "WAIT_ABANDONED" : "WAIT_TIMEOUT"); + } + } + } + ::CloseHandle(wait_timer /* handle */); +} + // Sleep forever; naked call to OS-specific sleep; use with CAUTION void os::infinite_sleep() { while (true) { // sleep forever ...