Skip to content

Commit 3934127

Browse files
committed
8318709: Improve System.nanoTime performance on Windows
Reviewed-by: ccleary, dholmes
1 parent 83eb206 commit 3934127

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/hotspot/os/windows/os_windows.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -801,20 +801,12 @@ void os::free_thread(OSThread* osthread) {
801801
static jlong first_filetime;
802802
static jlong initial_performance_count;
803803
static jlong performance_frequency;
804-
805-
806-
jlong as_long(LARGE_INTEGER x) {
807-
jlong result = 0; // initialization to avoid warning
808-
set_high(&result, x.HighPart);
809-
set_low(&result, x.LowPart);
810-
return result;
811-
}
812-
804+
static double nanos_per_count; // NANOSECS_PER_SEC / performance_frequency
813805

814806
jlong os::elapsed_counter() {
815807
LARGE_INTEGER count;
816808
QueryPerformanceCounter(&count);
817-
return as_long(count) - initial_performance_count;
809+
return count.QuadPart - initial_performance_count;
818810
}
819811

820812

@@ -978,9 +970,10 @@ void os::set_native_thread_name(const char *name) {
978970
void os::win32::initialize_performance_counter() {
979971
LARGE_INTEGER count;
980972
QueryPerformanceFrequency(&count);
981-
performance_frequency = as_long(count);
973+
performance_frequency = count.QuadPart;
974+
nanos_per_count = NANOSECS_PER_SEC / (double)performance_frequency;
982975
QueryPerformanceCounter(&count);
983-
initial_performance_count = as_long(count);
976+
initial_performance_count = count.QuadPart;
984977
}
985978

986979

@@ -1082,9 +1075,8 @@ void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
10821075
jlong os::javaTimeNanos() {
10831076
LARGE_INTEGER current_count;
10841077
QueryPerformanceCounter(&current_count);
1085-
double current = as_long(current_count);
1086-
double freq = performance_frequency;
1087-
jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC);
1078+
double current = current_count.QuadPart;
1079+
jlong time = (jlong)(current * nanos_per_count);
10881080
return time;
10891081
}
10901082

0 commit comments

Comments
 (0)