# HG changeset patch # User henryjen # Date 1586229911 0 # Tue Apr 07 03:25:11 2020 +0000 # Node ID 8e94c549c49b72a00d5d472e275996297654327c # Parent ff051338cae0778e3912ad8d9b371d40fd6a3ca2 8241638: launcher time metrics always report 1 on Linux when _JAVA_LAUNCHER_DEBUG set Reviewed-by: alanb, dholmes Contributed-by: linzang@tencent.com diff --git a/make/launcher/LauncherCommon.gmk b/make/launcher/LauncherCommon.gmk --- a/make/launcher/LauncherCommon.gmk +++ b/make/launcher/LauncherCommon.gmk @@ -143,7 +143,7 @@ -DLAUNCHER_NAME='"$$(LAUNCHER_NAME)"' \ -DPROGNAME='"$1"' \ $$($1_CFLAGS), \ - CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \ + CFLAGS_solaris := -KPIC, \ CFLAGS_windows := $$($1_CFLAGS_windows), \ DISABLED_WARNINGS_gcc := unused-function, \ LDFLAGS := $$(LDFLAGS_JDKEXE) \ diff --git a/src/java.base/macosx/native/libjli/java_md_macosx.m b/src/java.base/macosx/native/libjli/java_md_macosx.m --- a/src/java.base/macosx/native/libjli/java_md_macosx.m +++ b/src/java.base/macosx/native/libjli/java_md_macosx.m @@ -641,7 +641,7 @@ { struct timeval tv; gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + tv.tv_usec; + return (tv.tv_sec * 1000000) + tv.tv_usec; } diff --git a/src/java.base/share/native/libjli/java.c b/src/java.base/share/native/libjli/java.c --- a/src/java.base/share/native/libjli/java.c +++ b/src/java.base/share/native/libjli/java.c @@ -238,7 +238,7 @@ char *main_class = NULL; int ret; InvocationFunctions ifn; - jlong start, end; + jlong start = 0, end = 0; char jvmpath[MAXPATHLEN]; char jrepath[MAXPATHLEN]; char jvmcfg[MAXPATHLEN]; @@ -408,7 +408,7 @@ jmethodID mainID; jobjectArray mainArgs; int ret = 0; - jlong start, end; + jlong start = 0, end = 0; RegisterThread(); @@ -1619,7 +1619,7 @@ jmethodID mid; jstring str; jobject result; - jlong start, end; + jlong start = 0, end = 0; jclass cls = GetLauncherHelperClass(env); NULL_CHECK0(cls); if (JLI_IsTraceLauncher()) { @@ -1634,7 +1634,7 @@ USE_STDERR, mode, str)); if (JLI_IsTraceLauncher()) { - end = CounterGet(); + end = CounterGet(); printf("%ld micro seconds to load main class\n", (long)(jint)Counter2Micros(end-start)); printf("----%s----\n", JLDEBUG_ENV_ENTRY); @@ -2082,7 +2082,7 @@ char line[MAXPATHLEN+20]; int cnt = 0; int lineno = 0; - jlong start, end; + jlong start = 0, end = 0; int vmType; char *tmpPtr; char *altVMName = NULL; @@ -2174,7 +2174,7 @@ knownVMsCount = cnt; if (JLI_IsTraceLauncher()) { - end = CounterGet(); + end = CounterGet(); printf("%ld micro seconds to parse jvm.cfg\n", (long)(jint)Counter2Micros(end-start)); } diff --git a/src/java.base/unix/native/libjli/java_md_solinux.c b/src/java.base/unix/native/libjli/java_md_solinux.c --- a/src/java.base/unix/native/libjli/java_md_solinux.c +++ b/src/java.base/unix/native/libjli/java_md_solinux.c @@ -830,3 +830,24 @@ { return JNI_FALSE; } + +#ifndef __solaris__ + +/* + * Provide a CounterGet() implementation based on gettimeofday() which + * is universally available, even though it may not be 'high resolution' + * compared to platforms that provide gethrtime() (like Solaris). It is + * also subject to time-of-day changes, but alternatives may not be + * known to be available at either build time or run time. + */ +uint64_t CounterGet() { + uint64_t result = 0; + struct timeval tv; + if (gettimeofday(&tv, NULL) != -1) { + result = 1000000LL * (uint64_t)tv.tv_sec; + result += (uint64_t)tv.tv_usec; + } + return result; +} + +#endif // !__solaris__ diff --git a/src/java.base/unix/native/libjli/java_md_solinux.h b/src/java.base/unix/native/libjli/java_md_solinux.h --- a/src/java.base/unix/native/libjli/java_md_solinux.h +++ b/src/java.base/unix/native/libjli/java_md_solinux.h @@ -26,17 +26,17 @@ #ifndef JAVA_MD_SOLINUX_H #define JAVA_MD_SOLINUX_H -#ifdef HAVE_GETHRTIME +#include +#ifdef __solaris__ /* * Support for doing cheap, accurate interval timing. */ -#include #define CounterGet() (gethrtime()/1000) #define Counter2Micros(counts) (counts) -#else /* ! HAVE_GETHRTIME */ -#define CounterGet() (0) -#define Counter2Micros(counts) (1) -#endif /* HAVE_GETHRTIME */ +#else /* ! __solaris__ */ +uint64_t CounterGet(void); +#define Counter2Micros(counts) (counts) +#endif /* __solaris__ */ /* pointer to environment */ extern char **environ;