Skip to content

Commit 7680f70

Browse files
committed
8171508: Remove -Dsun.java.launcher.is_altjvm option
Reviewed-by: dholmes, stuefe
1 parent 3131dd1 commit 7680f70

File tree

7 files changed

+109
-194
lines changed

7 files changed

+109
-194
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,60 +1306,39 @@ void os::jvm_path(char *buf, jint buflen) {
13061306
char* rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen);
13071307
assert(rp != nullptr, "error in realpath(): maybe the 'path' argument is too long?");
13081308

1309-
if (Arguments::sun_java_launcher_is_altjvm()) {
1310-
// Support for the java launcher's '-XXaltjvm=<path>' option. Typical
1311-
// value for buf is "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.so".
1312-
// If "/jre/lib/" appears at the right place in the string, then
1313-
// assume we are installed in a JDK and we're done. Otherwise, check
1314-
// for a JAVA_HOME environment variable and fix up the path so it
1315-
// looks like libjvm.so is installed there (append a fake suffix
1316-
// hotspot/libjvm.so).
1317-
const char *p = buf + strlen(buf) - 1;
1318-
for (int count = 0; p > buf && count < 4; ++count) {
1319-
for (--p; p > buf && *p != '/'; --p)
1320-
/* empty */ ;
1321-
}
1309+
// If executing unit tests we require JAVA_HOME to point to the real JDK.
1310+
if (Arguments::executing_unit_tests()) {
1311+
// Look for JAVA_HOME in the environment.
1312+
char* java_home_var = ::getenv("JAVA_HOME");
1313+
if (java_home_var != nullptr && java_home_var[0] != 0) {
1314+
1315+
// Check the current module name "libjvm.so".
1316+
const char* p = strrchr(buf, '/');
1317+
if (p == nullptr) {
1318+
return;
1319+
}
1320+
assert(strstr(p, "/libjvm") == p, "invalid library name");
13221321

1323-
if (strncmp(p, "/jre/lib/", 9) != 0) {
1324-
// Look for JAVA_HOME in the environment.
1325-
char* java_home_var = ::getenv("JAVA_HOME");
1326-
if (java_home_var != nullptr && java_home_var[0] != 0) {
1327-
char* jrelib_p;
1328-
int len;
1322+
stringStream ss(buf, buflen);
1323+
rp = os::realpath(java_home_var, buf, buflen);
1324+
if (rp == nullptr) {
1325+
return;
1326+
}
13291327

1330-
// Check the current module name "libjvm.so".
1331-
p = strrchr(buf, '/');
1332-
if (p == nullptr) {
1333-
return;
1334-
}
1335-
assert(strstr(p, "/libjvm") == p, "invalid library name");
1328+
assert((int)strlen(buf) < buflen, "Ran out of buffer room");
1329+
ss.print("%s/lib", buf);
13361330

1337-
rp = os::realpath(java_home_var, buf, buflen);
1331+
if (0 == access(buf, F_OK)) {
1332+
// Use current module name "libjvm.so"
1333+
ss.print("/%s/libjvm%s", Abstract_VM_Version::vm_variant(), JNI_LIB_SUFFIX);
1334+
assert(strcmp(buf + strlen(buf) - strlen(JNI_LIB_SUFFIX), JNI_LIB_SUFFIX) == 0,
1335+
"buf has been truncated");
1336+
} else {
1337+
// Go back to path of .so
1338+
rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen);
13381339
if (rp == nullptr) {
13391340
return;
13401341
}
1341-
1342-
// determine if this is a legacy image or modules image
1343-
// modules image doesn't have "jre" subdirectory
1344-
len = strlen(buf);
1345-
assert(len < buflen, "Ran out of buffer room");
1346-
jrelib_p = buf + len;
1347-
snprintf(jrelib_p, buflen-len, "/jre/lib");
1348-
if (0 != access(buf, F_OK)) {
1349-
snprintf(jrelib_p, buflen-len, "/lib");
1350-
}
1351-
1352-
if (0 == access(buf, F_OK)) {
1353-
// Use current module name "libjvm.so"
1354-
len = strlen(buf);
1355-
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
1356-
} else {
1357-
// Go back to path of .so
1358-
rp = os::realpath((char *)dlinfo.dli_fname, buf, buflen);
1359-
if (rp == nullptr) {
1360-
return;
1361-
}
1362-
}
13631342
}
13641343
}
13651344
}

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,71 +1502,45 @@ void os::jvm_path(char *buf, jint buflen) {
15021502
return;
15031503
}
15041504

1505-
if (Arguments::sun_java_launcher_is_altjvm()) {
1506-
// Support for the java launcher's '-XXaltjvm=<path>' option. Typical
1507-
// value for buf is "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so"
1508-
// or "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.dylib". If "/jre/lib/"
1509-
// appears at the right place in the string, then assume we are
1510-
// installed in a JDK and we're done. Otherwise, check for a
1511-
// JAVA_HOME environment variable and construct a path to the JVM
1512-
// being overridden.
1513-
1514-
const char *p = buf + strlen(buf) - 1;
1515-
for (int count = 0; p > buf && count < 5; ++count) {
1516-
for (--p; p > buf && *p != '/'; --p)
1517-
/* empty */ ;
1518-
}
1505+
// If executing unit tests we require JAVA_HOME to point to the real JDK.
1506+
if (Arguments::executing_unit_tests()) {
1507+
// Look for JAVA_HOME in the environment.
1508+
char* java_home_var = ::getenv("JAVA_HOME");
1509+
if (java_home_var != nullptr && java_home_var[0] != 0) {
1510+
1511+
// Check the current module name "libjvm"
1512+
const char* p = strrchr(buf, '/');
1513+
assert(strstr(p, "/libjvm") == p, "invalid library name");
1514+
1515+
stringStream ss(buf, buflen);
1516+
rp = os::realpath(java_home_var, buf, buflen);
1517+
if (rp == nullptr) {
1518+
return;
1519+
}
15191520

1520-
if (strncmp(p, "/jre/lib/", 9) != 0) {
1521-
// Look for JAVA_HOME in the environment.
1522-
char* java_home_var = ::getenv("JAVA_HOME");
1523-
if (java_home_var != nullptr && java_home_var[0] != 0) {
1524-
char* jrelib_p;
1525-
int len;
1521+
assert((int)strlen(buf) < buflen, "Ran out of buffer space");
1522+
// Add the appropriate library and JVM variant subdirs
1523+
ss.print("%s/lib/%s", buf, Abstract_VM_Version::vm_variant());
15261524

1527-
// Check the current module name "libjvm"
1528-
p = strrchr(buf, '/');
1529-
assert(strstr(p, "/libjvm") == p, "invalid library name");
1525+
if (0 != access(buf, F_OK)) {
1526+
ss.reset();
1527+
ss.print("%s/lib", buf);
1528+
}
15301529

1531-
rp = os::realpath(java_home_var, buf, buflen);
1530+
// If the path exists within JAVA_HOME, add the JVM library name
1531+
// to complete the path to JVM being overridden. Otherwise fallback
1532+
// to the path to the current library.
1533+
if (0 == access(buf, F_OK)) {
1534+
// Use current module name "libjvm"
1535+
ss.print("/libjvm%s", JNI_LIB_SUFFIX);
1536+
assert(strcmp(buf + strlen(buf) - strlen(JNI_LIB_SUFFIX), JNI_LIB_SUFFIX) == 0,
1537+
"buf has been truncated");
1538+
} else {
1539+
// Fall back to path of current library
1540+
rp = os::realpath(dli_fname, buf, buflen);
15321541
if (rp == nullptr) {
15331542
return;
15341543
}
1535-
1536-
// determine if this is a legacy image or modules image
1537-
// modules image doesn't have "jre" subdirectory
1538-
len = strlen(buf);
1539-
assert(len < buflen, "Ran out of buffer space");
1540-
jrelib_p = buf + len;
1541-
1542-
// Add the appropriate library subdir
1543-
snprintf(jrelib_p, buflen-len, "/jre/lib");
1544-
if (0 != access(buf, F_OK)) {
1545-
snprintf(jrelib_p, buflen-len, "/lib");
1546-
}
1547-
1548-
// Add the appropriate JVM variant subdir
1549-
len = strlen(buf);
1550-
jrelib_p = buf + len;
1551-
snprintf(jrelib_p, buflen-len, "/%s", Abstract_VM_Version::vm_variant());
1552-
if (0 != access(buf, F_OK)) {
1553-
snprintf(jrelib_p, buflen-len, "%s", "");
1554-
}
1555-
1556-
// If the path exists within JAVA_HOME, add the JVM library name
1557-
// to complete the path to JVM being overridden. Otherwise fallback
1558-
// to the path to the current library.
1559-
if (0 == access(buf, F_OK)) {
1560-
// Use current module name "libjvm"
1561-
len = strlen(buf);
1562-
snprintf(buf + len, buflen-len, "/libjvm%s", JNI_LIB_SUFFIX);
1563-
} else {
1564-
// Fall back to path of current library
1565-
rp = os::realpath(dli_fname, buf, buflen);
1566-
if (rp == nullptr) {
1567-
return;
1568-
}
1569-
}
15701544
}
15711545
}
15721546
}

src/hotspot/os/linux/os_linux.cpp

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,60 +2772,39 @@ void os::jvm_path(char *buf, jint buflen) {
27722772
return;
27732773
}
27742774

2775-
if (Arguments::sun_java_launcher_is_altjvm()) {
2776-
// Support for the java launcher's '-XXaltjvm=<path>' option. Typical
2777-
// value for buf is "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.so".
2778-
// If "/jre/lib/" appears at the right place in the string, then
2779-
// assume we are installed in a JDK and we're done. Otherwise, check
2780-
// for a JAVA_HOME environment variable and fix up the path so it
2781-
// looks like libjvm.so is installed there (append a fake suffix
2782-
// hotspot/libjvm.so).
2783-
const char *p = buf + strlen(buf) - 1;
2784-
for (int count = 0; p > buf && count < 5; ++count) {
2785-
for (--p; p > buf && *p != '/'; --p)
2786-
/* empty */ ;
2787-
}
2775+
// If executing unit tests we require JAVA_HOME to point to the real JDK.
2776+
if (Arguments::executing_unit_tests()) {
2777+
// Look for JAVA_HOME in the environment.
2778+
char* java_home_var = ::getenv("JAVA_HOME");
2779+
if (java_home_var != nullptr && java_home_var[0] != 0) {
2780+
2781+
// Check the current module name "libjvm.so".
2782+
const char* p = strrchr(buf, '/');
2783+
if (p == nullptr) {
2784+
return;
2785+
}
2786+
assert(strstr(p, "/libjvm") == p, "invalid library name");
27882787

2789-
if (strncmp(p, "/jre/lib/", 9) != 0) {
2790-
// Look for JAVA_HOME in the environment.
2791-
char* java_home_var = ::getenv("JAVA_HOME");
2792-
if (java_home_var != nullptr && java_home_var[0] != 0) {
2793-
char* jrelib_p;
2794-
int len;
2788+
stringStream ss(buf, buflen);
2789+
rp = os::realpath(java_home_var, buf, buflen);
2790+
if (rp == nullptr) {
2791+
return;
2792+
}
27952793

2796-
// Check the current module name "libjvm.so".
2797-
p = strrchr(buf, '/');
2798-
if (p == nullptr) {
2799-
return;
2800-
}
2801-
assert(strstr(p, "/libjvm") == p, "invalid library name");
2794+
assert((int)strlen(buf) < buflen, "Ran out of buffer room");
2795+
ss.print("%s/lib", buf);
28022796

2803-
rp = os::realpath(java_home_var, buf, buflen);
2797+
if (0 == access(buf, F_OK)) {
2798+
// Use current module name "libjvm.so"
2799+
ss.print("/%s/libjvm%s", Abstract_VM_Version::vm_variant(), JNI_LIB_SUFFIX);
2800+
assert(strcmp(buf + strlen(buf) - strlen(JNI_LIB_SUFFIX), JNI_LIB_SUFFIX) == 0,
2801+
"buf has been truncated");
2802+
} else {
2803+
// Go back to path of .so
2804+
rp = os::realpath(dli_fname, buf, buflen);
28042805
if (rp == nullptr) {
28052806
return;
28062807
}
2807-
2808-
// determine if this is a legacy image or modules image
2809-
// modules image doesn't have "jre" subdirectory
2810-
len = checked_cast<int>(strlen(buf));
2811-
assert(len < buflen, "Ran out of buffer room");
2812-
jrelib_p = buf + len;
2813-
snprintf(jrelib_p, buflen-len, "/jre/lib");
2814-
if (0 != access(buf, F_OK)) {
2815-
snprintf(jrelib_p, buflen-len, "/lib");
2816-
}
2817-
2818-
if (0 == access(buf, F_OK)) {
2819-
// Use current module name "libjvm.so"
2820-
len = (int)strlen(buf);
2821-
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
2822-
} else {
2823-
// Go back to path of .so
2824-
rp = os::realpath(dli_fname, buf, buflen);
2825-
if (rp == nullptr) {
2826-
return;
2827-
}
2828-
}
28292808
}
28302809
}
28312810
}

src/hotspot/os/windows/os_windows.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,26 +2206,16 @@ void os::jvm_path(char *buf, jint buflen) {
22062206
}
22072207

22082208
buf[0] = '\0';
2209-
if (Arguments::sun_java_launcher_is_altjvm()) {
2210-
// Support for the java launcher's '-XXaltjvm=<path>' option. Check
2211-
// for a JAVA_HOME environment variable and fix up the path so it
2212-
// looks like jvm.dll is installed there (append a fake suffix
2213-
// hotspot/jvm.dll).
2209+
// If executing unit tests we require JAVA_HOME to point to the real JDK.
2210+
if (Arguments::executing_unit_tests()) {
22142211
char* java_home_var = ::getenv("JAVA_HOME");
22152212
if (java_home_var != nullptr && java_home_var[0] != 0 &&
22162213
strlen(java_home_var) < (size_t)buflen) {
2217-
strncpy(buf, java_home_var, buflen);
2218-
2219-
// determine if this is a legacy image or modules image
2220-
// modules image doesn't have "jre" subdirectory
2221-
size_t len = strlen(buf);
2222-
char* jrebin_p = buf + len;
2223-
jio_snprintf(jrebin_p, buflen-len, "\\jre\\bin\\");
2224-
if (0 != _access(buf, 0)) {
2225-
jio_snprintf(jrebin_p, buflen-len, "\\bin\\");
2226-
}
2227-
len = strlen(buf);
2228-
jio_snprintf(buf + len, buflen-len, "hotspot\\jvm.dll");
2214+
stringStream ss(buf, buflen);
2215+
ss.print("%s\\bin\\%s\\jvm%s",
2216+
java_home_var, Abstract_VM_Version::vm_variant(), JNI_LIB_SUFFIX);
2217+
assert(strcmp(buf + strlen(buf) - strlen(JNI_LIB_SUFFIX), JNI_LIB_SUFFIX) == 0,
2218+
"buf has been truncated");
22292219
}
22302220
}
22312221

src/hotspot/share/runtime/arguments.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ size_t Arguments::_conservative_max_heap_alignment = 0;
9191
Arguments::Mode Arguments::_mode = _mixed;
9292
const char* Arguments::_java_vendor_url_bug = nullptr;
9393
const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
94-
bool Arguments::_sun_java_launcher_is_altjvm = false;
94+
bool Arguments::_executing_unit_tests = false;
9595

9696
// These parameters are reset in method parse_vm_init_args()
9797
bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
@@ -355,7 +355,7 @@ bool Arguments::internal_module_property_helper(const char* property, bool check
355355

356356
// Process java launcher properties.
357357
void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
358-
// See if sun.java.launcher or sun.java.launcher.is_altjvm is defined.
358+
// See if sun.java.launcher is defined.
359359
// Must do this before setting up other system properties,
360360
// as some of them may depend on launcher type.
361361
for (int index = 0; index < args->nOptions; index++) {
@@ -366,10 +366,8 @@ void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
366366
process_java_launcher_argument(tail, option->extraInfo);
367367
continue;
368368
}
369-
if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) {
370-
if (strcmp(tail, "true") == 0) {
371-
_sun_java_launcher_is_altjvm = true;
372-
}
369+
if (match_option(option, "-XX:+ExecutingUnitTests")) {
370+
_executing_unit_tests = true;
373371
continue;
374372
}
375373
}
@@ -1271,10 +1269,6 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
12711269
} else {
12721270
warning("The java.compiler system property is obsolete and no longer supported.");
12731271
}
1274-
} else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0) {
1275-
// sun.java.launcher.is_altjvm property is
1276-
// private and is processed in process_sun_java_launcher_properties();
1277-
// the sun.java.launcher property is passed on to the java application
12781272
} else if (strcmp(key, "sun.boot.library.path") == 0) {
12791273
// append is true, writable is true, internal is false
12801274
PropertyList_unique_add(&_system_properties, key, value, AppendProperty,
@@ -1763,8 +1757,8 @@ bool Arguments::created_by_java_launcher() {
17631757
return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
17641758
}
17651759

1766-
bool Arguments::sun_java_launcher_is_altjvm() {
1767-
return _sun_java_launcher_is_altjvm;
1760+
bool Arguments::executing_unit_tests() {
1761+
return _executing_unit_tests;
17681762
}
17691763

17701764
//===========================================================================================================

src/hotspot/share/runtime/arguments.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ class Arguments : AllStatic {
238238
// java launcher
239239
static const char* _sun_java_launcher;
240240

241-
// was this VM created via the -XXaltjvm=<path> option
242-
static bool _sun_java_launcher_is_altjvm;
241+
// was this VM created with the -XX:+ExecutingUnitTests option
242+
static bool _executing_unit_tests;
243243

244244
// for legacy gc options (-verbose:gc and -Xloggc:)
245245
static LegacyGCLogging _legacyGCLogging;
@@ -429,8 +429,8 @@ class Arguments : AllStatic {
429429
static const char* sun_java_launcher() { return _sun_java_launcher; }
430430
// Was VM created by a Java launcher?
431431
static bool created_by_java_launcher();
432-
// -Dsun.java.launcher.is_altjvm
433-
static bool sun_java_launcher_is_altjvm();
432+
// -XX:+ExecutingUnitTests
433+
static bool executing_unit_tests();
434434

435435
// abort, exit, vfprintf hooks
436436
static abort_hook_t abort_hook() { return _abort_hook; }

0 commit comments

Comments
 (0)