changeset 50962:dbe8aa90d4dd

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
author ccheung
date Tue, 10 Jul 2018 19:04:13 -0700
parents 0d28f82ecac6
children 69b438908512
files src/hotspot/os/aix/os_aix.cpp src/hotspot/os/bsd/os_bsd.cpp src/hotspot/os/linux/os_linux.cpp src/hotspot/os/solaris/os_solaris.cpp src/hotspot/os/windows/os_windows.cpp src/hotspot/share/classfile/classLoader.cpp test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java
diffstat 7 files changed, 42 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- 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.
--- 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.
--- 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.
--- 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);
     }
   }
 
--- 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.
--- 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 <java home>/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) {