8343040: Clean up references to JRE in the launcher code

Reviewed-by: alanb, darcy
This commit is contained in:
Jaikiran Pai 2024-10-30 10:39:05 +00:00
parent 9003524c8b
commit 0fe15d6836
8 changed files with 134 additions and 160 deletions

View file

@ -253,8 +253,8 @@ RequiresSetenv(const char *jvmpath) {
/*
* Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
* previous versions of the JRE, thus it is the only path that matters here.
* So we check to see if the desired JRE is set.
* previous versions of the JDK, thus it is the only path that matters here.
* So we check to see if the desired JDK is set.
*/
JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
p = JLI_StrRChr(jpath, '/');
@ -273,7 +273,7 @@ RequiresSetenv(const char *jvmpath) {
void
CreateExecutionEnvironment(int *pargc, char ***pargv,
char jrepath[], jint so_jrepath,
char jdkroot[], jint so_jdkroot,
char jvmpath[], jint so_jvmpath,
char jvmcfg[], jint so_jvmcfg) {
@ -294,13 +294,13 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
SetExecname(*pargv);
/* Check to see if the jvmpath exists */
/* Find out where the JRE is that we will be using. */
if (!GetJREPath(jrepath, so_jrepath, JNI_FALSE)) {
JLI_ReportErrorMessage(JRE_ERROR1);
/* Find out where the JDK is that we will be using. */
if (!GetJDKInstallRoot(jdkroot, so_jdkroot, JNI_FALSE)) {
JLI_ReportErrorMessage(LAUNCHER_ERROR1);
exit(2);
}
JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%sjvm.cfg",
jrepath, FILESEP, FILESEP);
jdkroot, FILESEP, FILESEP);
/* Find the specified JVM type */
if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
JLI_ReportErrorMessage(CFG_ERROR7);
@ -314,7 +314,7 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
exit(4);
}
if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
if (!GetJVMPath(jdkroot, jvmtype, jvmpath, so_jvmpath)) {
JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
exit(4);
}
@ -339,8 +339,8 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
* We will set the LD_LIBRARY_PATH as follows:
*
* o $JVMPATH (directory portion only)
* o $JRE/lib
* o $JRE/../lib
* o $JDK/lib
* o $JDK/../lib
*
* followed by the user's previous effective LD_LIBRARY_PATH, if
* any.
@ -352,7 +352,7 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
{ /* New scope to declare local variable */
char *new_jvmpath = JLI_StringDup(jvmpath);
new_runpath_size = ((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
2 * JLI_StrLen(jrepath) +
2 * JLI_StrLen(jdkroot) +
JLI_StrLen(new_jvmpath) + 52;
new_runpath = JLI_MemAlloc(new_runpath_size);
newpath = new_runpath + JLI_StrLen(LD_LIBRARY_PATH "=");
@ -372,8 +372,8 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
"%s/lib:"
"%s/../lib",
new_jvmpath,
jrepath,
jrepath
jdkroot,
jdkroot
);
JLI_MemFree(new_jvmpath);
@ -402,7 +402,7 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
if (runpath != 0) {
/* ensure storage for runpath + colon + NULL */
if ((JLI_StrLen(runpath) + 1 + 1) > new_runpath_size) {
JLI_ReportErrorMessageSys(JRE_ERROR11);
JLI_ReportErrorMessageSys(LAUNCHER_ERROR3);
exit(1);
}
JLI_StrCat(new_runpath, ":");
@ -437,14 +437,14 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
#else /* !SETENV_REQUIRED */
execv(newexec, argv);
#endif /* SETENV_REQUIRED */
JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
JLI_ReportErrorMessageSys(LAUNCHER_ERROR4, newexec);
}
exit(1);
}
static jboolean
GetJVMPath(const char *jrepath, const char *jvmtype,
GetJVMPath(const char *jdkroot, const char *jvmtype,
char *jvmpath, jint jvmpathsize)
{
struct stat s;
@ -452,7 +452,7 @@ GetJVMPath(const char *jrepath, const char *jvmtype,
if (JLI_StrChr(jvmtype, '/')) {
JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
} else {
JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jrepath, jvmtype);
JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jdkroot, jvmtype);
}
JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
@ -467,31 +467,31 @@ GetJVMPath(const char *jrepath, const char *jvmtype,
}
/*
* Find path to JRE based on .exe's location or registry settings.
* Find path to the JDK installation root
*/
static jboolean
GetJREPath(char *path, jint pathsize, jboolean speculative)
GetJDKInstallRoot(char *path, jint pathsize, jboolean speculative)
{
char libjava[MAXPATHLEN];
struct stat s;
JLI_TraceLauncher("Attempt to get JRE path from launcher executable path\n");
JLI_TraceLauncher("Attempt to get JDK installation root from launcher executable path\n");
if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
/* Is JDK co-located with the application? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
JLI_TraceLauncher("JRE path is %s\n", path);
JLI_TraceLauncher("JDK installation root path is %s\n", path);
return JNI_TRUE;
}
}
JLI_TraceLauncher("Attempt to get JRE path from shared lib of the image\n");
JLI_TraceLauncher("Attempt to get JDK installation root 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) {
JLI_TraceLauncher("JRE path is %s\n", path);
JLI_TraceLauncher("JDK installation root path is %s\n", path);
return JNI_TRUE;
}
}
@ -501,14 +501,14 @@ GetJREPath(char *path, jint pathsize, jboolean speculative)
if (GetApplicationHomeFromLibpath(path, pathsize)) {
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (stat(libjava, &s) == 0) {
JLI_TraceLauncher("JRE path is %s\n", path);
JLI_TraceLauncher("JDK installation root path is %s\n", path);
return JNI_TRUE;
}
}
#endif
if (!speculative)
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
JLI_ReportErrorMessage(LAUNCHER_ERROR2 JAVA_DLL);
return JNI_FALSE;
}
@ -597,22 +597,22 @@ static void* hSplashLib = NULL;
void* SplashProcAddress(const char* name) {
if (!hSplashLib) {
int ret;
char jrePath[MAXPATHLEN];
char jdkRoot[MAXPATHLEN];
char splashPath[MAXPATHLEN];
if (!GetJREPath(jrePath, sizeof(jrePath), JNI_FALSE)) {
JLI_ReportErrorMessage(JRE_ERROR1);
if (!GetJDKInstallRoot(jdkRoot, sizeof(jdkRoot), JNI_FALSE)) {
JLI_ReportErrorMessage(LAUNCHER_ERROR1);
return NULL;
}
ret = JLI_Snprintf(splashPath, sizeof(splashPath), "%s/lib/%s",
jrePath, SPLASHSCREEN_SO);
jdkRoot, SPLASHSCREEN_SO);
if (ret >= (int) sizeof(splashPath)) {
JLI_ReportErrorMessage(JRE_ERROR11);
JLI_ReportErrorMessage(LAUNCHER_ERROR3);
return NULL;
}
if (ret < 0) {
JLI_ReportErrorMessage(JRE_ERROR13);
JLI_ReportErrorMessage(LAUNCHER_ERROR5);
return NULL;
}
hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL);

View file

@ -55,9 +55,9 @@ int UnsetEnv(char *name);
char *FindExecName(char *program);
const char *SetExecname(char **argv);
const char *GetExecName();
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
static jboolean GetJVMPath(const char *jdkroot, const char *jvmtype,
char *jvmpath, jint jvmpathsize);
static jboolean GetJREPath(char *path, jint pathsize, jboolean speculative);
static jboolean GetJDKInstallRoot(char *path, jint pathsize, jboolean speculative);
#if defined(_AIX)
jboolean GetApplicationHomeFromLibpath(char *buf, jint bufsize);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -76,7 +76,7 @@ TruncatePath(char *buf, jboolean pathisdll)
}
/*
* Retrieves the path to the JRE home by locating the executable file
* Retrieves the path to the JDK home by locating the executable file
* of the current process and then truncating the path to the executable
*/
jboolean
@ -93,7 +93,7 @@ GetApplicationHome(char *buf, jint bufsize)
}
/*
* Retrieves the path to the JRE home by locating the
* Retrieves the path to the JDK home by locating the
* shared library and then truncating the path to it.
*/
jboolean
@ -124,7 +124,7 @@ LibjavaExists(const char *path)
}
/*
* Retrieves the path to the JRE home by locating libjava.so in
* Retrieves the path to the JDK home by locating libjava.so in
* LIBPATH and then truncating the path to it.
*/
jboolean
@ -262,7 +262,7 @@ JLI_ReportExceptionDescription(JNIEnv * env) {
/*
* Since using the file system as a registry is a bit risky, perform
* additional sanity checks on the identified directory to validate
* it as a valid jre/sdk.
* it as a valid JDK.
*
* Return 0 if the tests fail; otherwise return non-zero (true).
*