8329862: libjli GetApplicationHome cleanups and enhance jli tracing

Reviewed-by: clanger, stuefe
This commit is contained in:
Matthias Baesken 2024-04-26 08:12:09 +00:00
parent 006f090f98
commit 377f2e538a
2 changed files with 10 additions and 38 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -495,6 +495,8 @@ GetJREPath(char *path, jint pathsize, jboolean speculative)
char libjava[MAXPATHLEN];
struct stat s;
JLI_TraceLauncher("Attempt to get JRE path from launcher executable path\n");
if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
@ -502,20 +504,10 @@ GetJREPath(char *path, jint pathsize, jboolean speculative)
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
/* ensure storage for path + /jre + NULL */
if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
JLI_TraceLauncher("Insufficient space to store JRE path\n");
return JNI_FALSE;
}
/* Does the app ship a private JRE in <apphome>/jre directory? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
JLI_StrCat(path, "/jre");
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
}
JLI_TraceLauncher("Attempt to get JRE path from shared lib of the image\n");
if (GetApplicationHomeFromDll(path, pathsize)) {
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (stat(libjava, &s) == 0) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -49,10 +49,6 @@ static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
char *jvmpath, jint jvmpathsize);
static jboolean GetJREPath(char *path, jint pathsize);
#ifdef USE_REGISTRY_LOOKUP
jboolean GetPublicJREHome(char *buf, jint bufsize);
#endif
/* We supports warmup for UI stack that is performed in parallel
* to VM initialization.
* This helps to improve startup of UI application as warmup phase
@ -300,6 +296,8 @@ GetJREPath(char *path, jint pathsize)
char javadll[MAXPATHLEN];
struct stat s;
JLI_TraceLauncher("Attempt to get JRE path from launcher executable path\n");
if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
@ -307,20 +305,10 @@ GetJREPath(char *path, jint pathsize)
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
/* ensure storage for path + \jre + NULL */
if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
JLI_TraceLauncher("Insufficient space to store JRE path\n");
return JNI_FALSE;
}
/* Does this app ship a private JRE in <apphome>\jre directory? */
JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
if (stat(javadll, &s) == 0) {
JLI_StrCat(path, "\\jre");
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
}
JLI_TraceLauncher("Attempt to get JRE path from shared lib of the image\n");
/* Try getting path to JRE from path to JLI.DLL */
if (GetApplicationHomeFromDll(path, pathsize)) {
JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
@ -330,14 +318,6 @@ GetJREPath(char *path, jint pathsize)
}
}
#ifdef USE_REGISTRY_LOOKUP
/* Lookup public JRE using Windows registry. */
if (GetPublicJREHome(path, pathsize)) {
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
#endif
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
return JNI_FALSE;
}