# HG changeset patch # User ccheung # Date 1531274653 25200 # Node ID dbe8aa90d4dd4f06bc13ef5dca4eb3c9337c58b6 # Parent 0d28f82ecac63f5b321854d4d62c11f221b694d6 8205946: JVM crash after call to ClassLoader::setup_bootstrap_search_path() Summary: exit vm if setting of boot class path fails. Reviewed-by: lfoltan, jiangli, dholmes diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/os/aix/os_aix.cpp --- a/src/hotspot/os/aix/os_aix.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/os/aix/os_aix.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -576,7 +576,9 @@ } } Arguments::set_java_home(buf); - set_boot_path('/', ':'); + if (!set_boot_path('/', ':')) { + vm_exit_during_initialization("Failed setting boot class path.", NULL); + } } // Where to look for native libraries. diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/os/bsd/os_bsd.cpp --- a/src/hotspot/os/bsd/os_bsd.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/os/bsd/os_bsd.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -372,7 +372,9 @@ } } Arguments::set_java_home(buf); - set_boot_path('/', ':'); + if (!set_boot_path('/', ':')) { + vm_exit_during_initialization("Failed setting boot class path.", NULL); + } } // Where to look for native libraries. diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/os/linux/os_linux.cpp --- a/src/hotspot/os/linux/os_linux.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/os/linux/os_linux.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -367,7 +367,9 @@ } } Arguments::set_java_home(buf); - set_boot_path('/', ':'); + if (!set_boot_path('/', ':')) { + vm_exit_during_initialization("Failed setting boot class path.", NULL); + } } // Where to look for native libraries. diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/os/solaris/os_solaris.cpp --- a/src/hotspot/os/solaris/os_solaris.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/os/solaris/os_solaris.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -580,7 +580,9 @@ } } Arguments::set_java_home(buf); - set_boot_path('/', ':'); + if (!set_boot_path('/', ':')) { + vm_exit_during_initialization("Failed setting boot class path.", NULL); + } } // Where to look for native libraries. diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/os/windows/os_windows.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -230,7 +230,7 @@ FREE_C_HEAP_ARRAY(char, dll_path); if (!set_boot_path('\\', ';')) { - return; + vm_exit_during_initialization("Failed setting boot class path.", NULL); } } diff -r 0d28f82ecac6 -r dbe8aa90d4dd src/hotspot/share/classfile/classLoader.cpp --- a/src/hotspot/share/classfile/classLoader.cpp Tue Jul 10 10:24:08 2018 -0700 +++ b/src/hotspot/share/classfile/classLoader.cpp Tue Jul 10 19:04:13 2018 -0700 @@ -549,6 +549,7 @@ void ClassLoader::setup_bootstrap_search_path() { const char* sys_class_path = Arguments::get_sysclasspath(); + assert(sys_class_path != NULL, "System boot class path must not be NULL"); if (PrintSharedArchiveAndExit) { // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily // the same as the bootcp of the shared archive. diff -r 0d28f82ecac6 -r dbe8aa90d4dd test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java --- a/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java Tue Jul 10 10:24:08 2018 -0700 +++ b/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java Tue Jul 10 19:04:13 2018 -0700 @@ -108,6 +108,16 @@ out.shouldNotContain("shared class paths mismatch"); out.shouldNotContain("BOOT classpath mismatch"); } + + // Test with no modules image in the /lib directory + renameModulesFile(java_home_dst); + { + ProcessBuilder pb = makeBuilder(java_home_dst + "/bin/java", + "-version"); + OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-missing-modules"); + out.shouldHaveExitValue(1); + out.shouldContain("Failed setting boot class path."); + } } // Do a cheap clone of the JDK. Most files can be sym-linked. However, $JAVA_HOME/bin/java and $JAVA_HOME/lib/.../libjvm.so" @@ -144,6 +154,24 @@ } } + static void renameModulesFile(String javaHome) throws Exception { + String modulesDir = javaHome + File.separator + "lib"; + File origModules = new File(modulesDir, "modules"); + if (!origModules.exists()) { + throw new RuntimeException("modules file not found"); + } + + File renamedModules = new File(modulesDir, "orig_modules"); + if (renamedModules.exists()) { + throw new RuntimeException("found orig_modules unexpectedly"); + } + + boolean success = origModules.renameTo(renamedModules); + if (!success) { + throw new RuntimeException("rename modules file failed"); + } + } + static ProcessBuilder makeBuilder(String... args) throws Exception { System.out.print("["); for (String s : args) {