Skip to content

Commit b317d0e

Browse files
linzangslowhog
authored andcommitted
8241638: launcher time metrics always report 1 on Linux when _JAVA_LAUNCHER_DEBUG set
Reviewed-by: alanb, dholmes
1 parent e18d661 commit b317d0e

5 files changed

Lines changed: 35 additions & 14 deletions

File tree

make/launcher/LauncherCommon.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ define SetupBuildLauncherBody
144144
-DPROGNAME='"$1"' \
145145
$$($1_CFLAGS), \
146146
CFLAGS_linux := -fPIC, \
147-
CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \
147+
CFLAGS_solaris := -KPIC, \
148148
CFLAGS_windows := $$($1_CFLAGS_windows), \
149149
DISABLED_WARNINGS_gcc := unused-function, \
150150
LDFLAGS := $$(LDFLAGS_JDKEXE) \

src/java.base/macosx/native/libjli/java_md_macosx.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
641641
{
642642
struct timeval tv;
643643
gettimeofday(&tv, NULL);
644-
return (tv.tv_sec * 1000) + tv.tv_usec;
644+
return (tv.tv_sec * 1000000) + tv.tv_usec;
645645
}
646646

647647

src/java.base/share/native/libjli/java.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
241241
char *main_class = NULL;
242242
int ret;
243243
InvocationFunctions ifn;
244-
jlong start, end;
244+
jlong start = 0, end = 0;
245245
char jvmpath[MAXPATHLEN];
246246
char jrepath[MAXPATHLEN];
247247
char jvmcfg[MAXPATHLEN];
@@ -408,7 +408,7 @@ JavaMain(void* _args)
408408
jmethodID mainID;
409409
jobjectArray mainArgs;
410410
int ret = 0;
411-
jlong start, end;
411+
jlong start = 0, end = 0;
412412

413413
RegisterThread();
414414

@@ -1618,7 +1618,7 @@ LoadMainClass(JNIEnv *env, int mode, char *name)
16181618
jmethodID mid;
16191619
jstring str;
16201620
jobject result;
1621-
jlong start, end;
1621+
jlong start = 0, end = 0;
16221622
jclass cls = GetLauncherHelperClass(env);
16231623
NULL_CHECK0(cls);
16241624
if (JLI_IsTraceLauncher()) {
@@ -1633,7 +1633,7 @@ LoadMainClass(JNIEnv *env, int mode, char *name)
16331633
USE_STDERR, mode, str));
16341634

16351635
if (JLI_IsTraceLauncher()) {
1636-
end = CounterGet();
1636+
end = CounterGet();
16371637
printf("%ld micro seconds to load main class\n",
16381638
(long)(jint)Counter2Micros(end-start));
16391639
printf("----%s----\n", JLDEBUG_ENV_ENTRY);
@@ -2080,7 +2080,7 @@ ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
20802080
char line[MAXPATHLEN+20];
20812081
int cnt = 0;
20822082
int lineno = 0;
2083-
jlong start, end;
2083+
jlong start = 0, end = 0;
20842084
int vmType;
20852085
char *tmpPtr;
20862086
char *altVMName = NULL;
@@ -2172,7 +2172,7 @@ ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
21722172
knownVMsCount = cnt;
21732173

21742174
if (JLI_IsTraceLauncher()) {
2175-
end = CounterGet();
2175+
end = CounterGet();
21762176
printf("%ld micro seconds to parse jvm.cfg\n",
21772177
(long)(jint)Counter2Micros(end-start));
21782178
}

src/java.base/unix/native/libjli/java_md_solinux.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,3 +813,24 @@ ProcessPlatformOption(const char *arg)
813813
{
814814
return JNI_FALSE;
815815
}
816+
817+
#ifndef __solaris__
818+
819+
/*
820+
* Provide a CounterGet() implementation based on gettimeofday() which
821+
* is universally available, even though it may not be 'high resolution'
822+
* compared to platforms that provide gethrtime() (like Solaris). It is
823+
* also subject to time-of-day changes, but alternatives may not be
824+
* known to be available at either build time or run time.
825+
*/
826+
uint64_t CounterGet() {
827+
uint64_t result = 0;
828+
struct timeval tv;
829+
if (gettimeofday(&tv, NULL) != -1) {
830+
result = 1000000LL * (uint64_t)tv.tv_sec;
831+
result += (uint64_t)tv.tv_usec;
832+
}
833+
return result;
834+
}
835+
836+
#endif // !__solaris__

src/java.base/unix/native/libjli/java_md_solinux.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
#ifndef JAVA_MD_SOLINUX_H
2727
#define JAVA_MD_SOLINUX_H
2828

29-
#ifdef HAVE_GETHRTIME
29+
#include <sys/time.h>
30+
#ifdef __solaris__
3031
/*
3132
* Support for doing cheap, accurate interval timing.
3233
*/
33-
#include <sys/time.h>
3434
#define CounterGet() (gethrtime()/1000)
3535
#define Counter2Micros(counts) (counts)
36-
#else /* ! HAVE_GETHRTIME */
37-
#define CounterGet() (0)
38-
#define Counter2Micros(counts) (1)
39-
#endif /* HAVE_GETHRTIME */
36+
#else /* ! __solaris__ */
37+
uint64_t CounterGet(void);
38+
#define Counter2Micros(counts) (counts)
39+
#endif /* __solaris__ */
4040

4141
/* pointer to environment */
4242
extern char **environ;

0 commit comments

Comments
 (0)