Skip to content

Commit

Permalink
8241638: launcher time metrics always report 1 on Linux when _JAVA_LA…
Browse files Browse the repository at this point in the history
…UNCHER_DEBUG set

Reviewed-by: alanb, dholmes
  • Loading branch information
linzang authored and slowhog committed Apr 7, 2020
1 parent e18d661 commit b317d0e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion make/launcher/LauncherCommon.gmk
Expand Up @@ -144,7 +144,7 @@ define SetupBuildLauncherBody
-DPROGNAME='"$1"' \
$$($1_CFLAGS), \
CFLAGS_linux := -fPIC, \
CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \
CFLAGS_solaris := -KPIC, \
CFLAGS_windows := $$($1_CFLAGS_windows), \
DISABLED_WARNINGS_gcc := unused-function, \
LDFLAGS := $$(LDFLAGS_JDKEXE) \
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/macosx/native/libjli/java_md_macosx.m
Expand Up @@ -641,7 +641,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000) + tv.tv_usec;
return (tv.tv_sec * 1000000) + tv.tv_usec;
}


Expand Down
12 changes: 6 additions & 6 deletions src/java.base/share/native/libjli/java.c
Expand Up @@ -241,7 +241,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
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];
Expand Down Expand Up @@ -408,7 +408,7 @@ JavaMain(void* _args)
jmethodID mainID;
jobjectArray mainArgs;
int ret = 0;
jlong start, end;
jlong start = 0, end = 0;

RegisterThread();

Expand Down Expand Up @@ -1618,7 +1618,7 @@ LoadMainClass(JNIEnv *env, int mode, char *name)
jmethodID mid;
jstring str;
jobject result;
jlong start, end;
jlong start = 0, end = 0;
jclass cls = GetLauncherHelperClass(env);
NULL_CHECK0(cls);
if (JLI_IsTraceLauncher()) {
Expand All @@ -1633,7 +1633,7 @@ LoadMainClass(JNIEnv *env, int mode, char *name)
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);
Expand Down Expand Up @@ -2080,7 +2080,7 @@ ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
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;
Expand Down Expand Up @@ -2172,7 +2172,7 @@ ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
knownVMsCount = cnt;

if (JLI_IsTraceLauncher()) {
end = CounterGet();
end = CounterGet();
printf("%ld micro seconds to parse jvm.cfg\n",
(long)(jint)Counter2Micros(end-start));
}
Expand Down
21 changes: 21 additions & 0 deletions src/java.base/unix/native/libjli/java_md_solinux.c
Expand Up @@ -813,3 +813,24 @@ ProcessPlatformOption(const char *arg)
{
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__
12 changes: 6 additions & 6 deletions src/java.base/unix/native/libjli/java_md_solinux.h
Expand Up @@ -26,17 +26,17 @@
#ifndef JAVA_MD_SOLINUX_H
#define JAVA_MD_SOLINUX_H

#ifdef HAVE_GETHRTIME
#include <sys/time.h>
#ifdef __solaris__
/*
* Support for doing cheap, accurate interval timing.
*/
#include <sys/time.h>
#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;
Expand Down

0 comments on commit b317d0e

Please sign in to comment.