--- old/src/java.base/share/native/libjli/java.c 2020-03-26 14:02:35.011837437 +0800 +++ new/src/java.base/share/native/libjli/java.c 2020-03-26 14:02:34.835838060 +0800 @@ -241,7 +241,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, end = 0; RegisterThread(); @@ -1618,7 +1618,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()) { @@ -1633,7 +1633,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); @@ -2080,7 +2080,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; @@ -2172,7 +2172,7 @@ knownVMsCount = cnt; if (JLI_IsTraceLauncher()) { - end = CounterGet(); + end = CounterGet(); printf("%ld micro seconds to parse jvm.cfg\n", (long)(jint)Counter2Micros(end-start)); } --- old/src/java.base/unix/native/libjli/java_md_solinux.h 2020-03-26 14:02:35.659835143 +0800 +++ new/src/java.base/unix/native/libjli/java_md_solinux.h 2020-03-26 14:02:35.471835809 +0800 @@ -34,8 +34,22 @@ #define CounterGet() (gethrtime()/1000) #define Counter2Micros(counts) (counts) #else /* ! HAVE_GETHRTIME */ -#define CounterGet() (0) -#define Counter2Micros(counts) (1) +/* + * * Add gethrtime() implementation for launch time debug on Linux. + * */ +#include +inline uint64_t gethrtime() { + 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; +} + +#define CounterGet() (gethrtime()) +#define Counter2Micros(counts) (counts) #endif /* HAVE_GETHRTIME */ /* pointer to environment */