Skip to content

Commit

Permalink
8343040: Clean up references to JRE in the launcher code
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, darcy
  • Loading branch information
jaikiran committed Oct 30, 2024
1 parent 9003524 commit 0fe15d6
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 160 deletions.
58 changes: 29 additions & 29 deletions src/java.base/macosx/native/libjli/java_md_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
/*
* Exports the JNI interface from libjli
*
* This allows client code to link against the .jre/.jdk bundles,
* This allows client code to link against the JDK bundles,
* and not worry about trying to pick a HotSpot to link against.
*
* Switching architectures is unsupported, since client code has
Expand All @@ -162,10 +162,10 @@
static InvocationFunctions *GetExportedJNIFunctions() {
if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions;

char jrePath[PATH_MAX];
jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), JNI_FALSE);
if (!gotJREPath) {
JLI_ReportErrorMessage("Failed to GetJREPath()");
char jdkRoot[PATH_MAX];
jboolean got = GetJDKInstallRoot(jdkRoot, sizeof(jdkRoot), JNI_FALSE);
if (!got) {
JLI_ReportErrorMessage("Failed to determine JDK installation root");
return NULL;
}

Expand All @@ -183,7 +183,7 @@
}

char jvmPath[PATH_MAX];
jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath));
jboolean gotJVMPath = GetJVMPath(jdkRoot, preferredJVM, jvmPath, sizeof(jvmPath));
if (!gotJVMPath) {
JLI_ReportErrorMessage("Failed to GetJVMPath()");
return NULL;
Expand Down Expand Up @@ -326,23 +326,23 @@ static void MacOSXStartup(int argc, char *argv[]) {

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) {
char jvmcfg[], jint so_jvmcfg) {
/* Compute/set the name of the executable */
SetExecname(*pargv);

char * jvmtype = NULL;
int argc = *pargc;
char **argv = *pargv;

/* 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);
Expand All @@ -356,7 +356,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
exit(4);
}

if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
if (!GetJVMPath(jdkroot, jvmtype, jvmpath, so_jvmpath)) {
JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
exit(4);
}
Expand All @@ -378,7 +378,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
* VM choosing is done by the launcher (java.c).
*/
static jboolean
GetJVMPath(const char *jrepath, const char *jvmtype,
GetJVMPath(const char *jdkroot, const char *jvmtype,
char *jvmpath, jint jvmpathsize)
{
struct stat s;
Expand All @@ -390,7 +390,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
* macosx client library is built thin, i386 only.
* 64 bit client requests must load server library
*/
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);
Expand All @@ -408,15 +408,15 @@ static void MacOSXStartup(int argc, char *argv[]) {
}

/*
* 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];

if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
/* Is the JDK co-located with the application? */
if (JLI_IsStaticallyLinked()) {
char jvm_cfg[MAXPATHLEN];
JLI_Snprintf(jvm_cfg, sizeof(jvm_cfg), "%s/lib/jvm.cfg", path);
Expand Down Expand Up @@ -445,7 +445,7 @@ static void MacOSXStartup(int argc, char *argv[]) {

/* try to find ourselves instead */
Dl_info selfInfo;
dladdr(&GetJREPath, &selfInfo);
dladdr(&GetJDKInstallRoot, &selfInfo);

if (JLI_IsStaticallyLinked()) {
char jvm_cfg[MAXPATHLEN];
Expand Down Expand Up @@ -488,8 +488,8 @@ static void MacOSXStartup(int argc, char *argv[]) {
return JNI_TRUE;
}

// If libjli.dylib is loaded from a macos bundle MacOS dir, find the JRE dir
// in ../Home.
// If libjli.dylib is loaded from a macos bundle MacOS dir, find the JDK
// install root at ../Home.
const char altLastPathComponent[] = "/MacOS/libjli.dylib";
size_t sizeOfAltLastPathComponent = sizeof(altLastPathComponent) - 1;
if (pathLen < sizeOfLastPathComponent) {
Expand All @@ -505,7 +505,7 @@ static void MacOSXStartup(int argc, char *argv[]) {
}

if (!speculative)
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
JLI_ReportErrorMessage(LAUNCHER_ERROR2 JAVA_DLL);
return JNI_FALSE;
}

Expand Down Expand Up @@ -642,27 +642,27 @@ static void MacOSXStartup(int argc, char *argv[]) {

void* SplashProcAddress(const char* name) {
if (!hSplashLib) {
char jrePath[PATH_MAX];
if (!GetJREPath(jrePath, sizeof(jrePath), JNI_FALSE)) {
JLI_ReportErrorMessage(JRE_ERROR1);
char jdkRoot[PATH_MAX];
if (!GetJDKInstallRoot(jdkRoot, sizeof(jdkRoot), JNI_FALSE)) {
JLI_ReportErrorMessage(LAUNCHER_ERROR1);
return NULL;
}

char splashPath[PATH_MAX];
const int ret = JLI_Snprintf(splashPath, sizeof(splashPath),
"%s/lib/%s", jrePath, SPLASHSCREEN_SO);
"%s/lib/%s", 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);
// It's OK if dlopen() fails. The splash screen library binary file
// might have been stripped out from the JRE image to reduce its size
// might have been stripped out from the JDK image to reduce its size
// (e.g. on embedded platforms).

if (hSplashLib) {
Expand Down
41 changes: 7 additions & 34 deletions src/java.base/share/native/libjli/emessages.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
Expand Down Expand Up @@ -62,60 +62,33 @@
#define JVM_ERROR1 "Error: Could not create the Java Virtual Machine.\n" GEN_ERROR
#define JVM_ERROR2 "Error: Could not detach main thread.\n" JNI_ERROR

#define JAR_ERROR1 "Error: Failed to load Main-Class manifest attribute from\n%s\n%s"
#define JAR_ERROR2 "Error: Unable to access jarfile %s"
#define JAR_ERROR3 "Error: Invalid or corrupt jarfile %s"

#define CLS_ERROR1 "Error: Could not find the main class %s.\n" JNI_ERROR
#define CLS_ERROR2 "Error: Failed to load Main Class: %s\n%s"
#define CLS_ERROR3 "Error: No main method found in specified class.\n" GEN_ERROR
#define CLS_ERROR4 "Error: Main method not public\n" GEN_ERROR
#define CLS_ERROR5 "Error: main-class: attribute exceeds system limits of %d bytes\n" GEN_ERROR

#define CFG_WARN1 "Warning: %s VM not supported; %s VM will be used"
#define CFG_WARN2 "Warning: No leading - on line %d of `%s'"
#define CFG_WARN3 "Warning: Missing VM type on line %d of `%s'"
#define CFG_WARN4 "Warning: Missing server class VM on line %d of `%s'"
#define CFG_WARN5 "Warning: Unknown VM type on line %d of `%s'"

#define CFG_ERROR1 "Error: Corrupt jvm.cfg file; cycle in alias list."
#define CFG_ERROR2 "Error: Unable to resolve VM alias %s"
#define CFG_ERROR3 "Error: %s VM not supported"
#define CFG_ERROR4 "Error: Unable to locate JRE meeting specification \"%s\""
#define CFG_ERROR5 "Error: Could not determine application home."
#define CFG_ERROR6 "Error: could not open `%s'"
#define CFG_ERROR7 "Error: no known VMs. (check for corrupt jvm.cfg file)"
#define CFG_ERROR8 "Error: missing `%s' JVM at `%s'.\nPlease install or use the JRE or JDK that contains these missing components."
#define CFG_ERROR8 "Error: missing `%s' JVM at `%s'.\nPlease install a JDK that contains these missing components."
#define CFG_ERROR9 "Error: could not determine JVM type."
#define CFG_ERROR10 "Error: Argument file size should not be larger than %lu."

#define JRE_ERROR1 "Error: Could not find Java SE Runtime Environment."
#define JRE_ERROR2 "Error: This Java instance does not support a %d-bit JVM.\nPlease install the desired version."
#define JRE_ERROR3 "Error: Improper value at line %d."
#define JRE_ERROR4 "Error: trying to exec %s.\nCheck if file exists and permissions are set correctly."
#define JRE_ERROR5 "Error: Failed to start a %d-bit JVM process from a %d-bit JVM."
#define JRE_ERROR6 "Error: Verify all necessary Java SE components have been installed."
#define JRE_ERROR7 "Error: Either 64-bit processes are not supported by this platform\nor the 64-bit components have not been installed."
#define JRE_ERROR8 "Error: could not find "
#define JRE_ERROR9 "Error: Unable to resolve %s"
#define JRE_ERROR10 "Error: Unable to resolve current executable"
#define JRE_ERROR11 "Error: Path length exceeds maximum length (PATH_MAX)"
#define JRE_ERROR12 "Error: Exec of %s failed"
#define JRE_ERROR13 "Error: String processing operation failed"
#define LAUNCHER_ERROR1 "Error: Could not find Java SE Runtime Environment."
#define LAUNCHER_ERROR2 "Error: could not find "
#define LAUNCHER_ERROR3 "Error: Path length exceeds maximum length (PATH_MAX)"
#define LAUNCHER_ERROR4 "Error: trying to exec %s.\nCheck if file exists and permissions are set correctly."
#define LAUNCHER_ERROR5 "Error: String processing operation failed"

#define DLL_ERROR1 "Error: dl failure on line %d"
#define DLL_ERROR2 "Error: failed %s, because %s"
#define DLL_ERROR3 "Error: could not find executable %s"
#define DLL_ERROR4 "Error: Failed to load %s"

#define REG_ERROR1 "Error: opening registry key '%s'"
#define REG_ERROR2 "Error: Failed reading value of registry key:\n\t%s\\CurrentVersion"
#define REG_ERROR3 "Error: Registry key '%s'\\CurrentVersion'\nhas value '%s', but '%s' is required."
#define REG_ERROR4 "Failed reading value of registry key:\n\t%s\\%s\\JavaHome"

#define SYS_ERROR1 "Error: CreateProcess(%s, ...) failed:"
#define SYS_ERROR2 "Error: WaitForSingleObject() failed."



#endif /* _EMESSAGES_H */
8 changes: 4 additions & 4 deletions src/java.base/share/native/libjli/java.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
InvocationFunctions ifn;
jlong start = 0, end = 0;
char jvmpath[MAXPATHLEN];
char jrepath[MAXPATHLEN];
char jdkroot[MAXPATHLEN];
char jvmcfg[MAXPATHLEN];

_fVersion = fullversion;
Expand Down Expand Up @@ -265,9 +265,9 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
}

CreateExecutionEnvironment(&argc, &argv,
jrepath, sizeof(jrepath),
jdkroot, sizeof(jdkroot),
jvmpath, sizeof(jvmpath),
jvmcfg, sizeof(jvmcfg));
jvmcfg, sizeof(jvmcfg));

ifn.CreateJavaVM = 0;
ifn.GetDefaultJavaVMInitArgs = 0;
Expand Down Expand Up @@ -2023,7 +2023,7 @@ PrintUsage(JNIEnv* env, jboolean doXUsage)
* JVM on the command line.
*
* The intent of the jvm.cfg file is to allow several JVM libraries to
* be installed in different subdirectories of a single JRE installation,
* be installed in different subdirectories of a single JDK installation,
* for space-savings and convenience in testing.
* The intent is explicitly not to provide a full aliasing or predicate
* mechanism.
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/native/libjli/java.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ GetApplicationHomeFromDll(char *buf, jint bufsize);
* Different platforms will implement this, here
* pargc is a pointer to the original argc,
* pargv is a pointer to the original argv,
* jrepath is an accessible path to the jre as determined by the call
* so_jrepath is the length of the buffer jrepath
* jdkroot is an accessible path to the JDK installation root as determined by the call
* so_jdkroot is the length of the buffer jdkroot
* jvmpath is an accessible path to the jvm as determined by the call
* so_jvmpath is the length of the buffer jvmpath
*/
void CreateExecutionEnvironment(int *argc, char ***argv,
char *jrepath, jint so_jrepath,
char *jdkroot, jint so_jdkroot,
char *jvmpath, jint so_jvmpath,
char *jvmcfg, jint so_jvmcfg);
char *jvmcfg, jint so_jvmcfg);

/* Reports an error message to stderr or a window as appropriate. */
JNIEXPORT void JNICALL
Expand Down
Loading

0 comments on commit 0fe15d6

Please sign in to comment.