8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
authorccheung
Thu, 24 May 2018 09:15:09 -0700
changeset 50254 61657d4a99e5
parent 50253 7a7285477153
child 50256 c29627b3ba73
8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message Summary: Converting the assert in ClassLoader::update_module_path_entry_list() to a meaningful error message before aborting the CDS dump. Reviewed-by: stuefe, iklam
src/hotspot/share/classfile/classLoader.cpp
test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java
--- a/src/hotspot/share/classfile/classLoader.cpp	Thu May 24 20:34:17 2018 +0530
+++ b/src/hotspot/share/classfile/classLoader.cpp	Thu May 24 09:15:09 2018 -0700
@@ -711,8 +711,11 @@
 void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
   assert(DumpSharedSpaces, "dump time only");
   struct stat st;
-  int ret = os::stat(path, &st);
-  assert(ret == 0, "module path must exist");
+  if (os::stat(path, &st) != 0) {
+    tty->print_cr("os::stat error %d (%s). CDS dump aborted (path was \"%s\").",
+      errno, os::errno_name(errno), path);
+    vm_exit_during_initialization();
+  }
   // File or directory found
   ClassPathEntry* new_entry = NULL;
   new_entry = create_class_path_entry(path, &st, true /* throw_exception */,
--- a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java	Thu May 24 20:34:17 2018 +0530
+++ b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java	Thu May 24 09:15:09 2018 -0700
@@ -37,8 +37,10 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Arrays;
 
 import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Platform;
 import jdk.testlibrary.ProcessTools;
 
 public class MainModuleOnly {
@@ -177,10 +179,54 @@
         // The dumping process will exit with an error due to non-empty directory
         // in the --module-path.
         output = TestCommon.createArchive(destJar.toString(), appClasses,
-                                          "-Xlog:class+load=trace",
                                           "--module-path", MODS_DIR.toString(),
                                           "-m", TEST_MODULE1);
         output.shouldHaveExitValue(1)
               .shouldMatch("Error: non-empty directory.*com.simple");
+
+        // test module path with very long length
+        //
+        // This test can't be run on the windows platform due to an existing
+        // issue in ClassLoader::get_canonical_path() (JDK-8190737).
+        if (Platform.isWindows()) {
+            System.out.println("Long module path test cannot be tested on the Windows platform.");
+            return;
+        }
+        Path longDir = USER_DIR;
+        int pathLen = longDir.toString().length();
+        int PATH_LEN = 2034;
+        int MAX_DIR_LEN = 250;
+        while (pathLen < PATH_LEN) {
+            int remaining = PATH_LEN - pathLen;
+            int subPathLen = remaining > MAX_DIR_LEN ? MAX_DIR_LEN : remaining;
+            char[] chars = new char[subPathLen];
+            Arrays.fill(chars, 'x');
+            String subPath = new String(chars);
+            longDir = Paths.get(longDir.toString(), subPath);
+            pathLen = longDir.toString().length();
+        }
+        File longDirFile = new File(longDir.toString());
+        try {
+            longDirFile.mkdirs();
+        } catch (Exception e) {
+            throw e;
+        }
+        Path longDirJar = longDir.resolve(TEST_MODULE1 + ".jar");
+        // IOException results from the Files.copy() call on platform
+        // such as MacOS X. Test can't be proceeded further with the
+        // exception.
+        try {
+            Files.copy(destJar, longDirJar);
+        } catch (java.io.IOException ioe) {
+            System.out.println("Caught IOException from Files.copy(). Cannot continue.");
+            return;
+        }
+        output = TestCommon.createArchive(destJar.toString(), appClasses,
+                                          "-Xlog:exceptions=trace",
+                                          "--module-path", longDirJar.toString(),
+                                          "-m", TEST_MODULE1);
+        if (output.getExitValue() != 0) {
+            output.shouldMatch("os::stat error.*CDS dump aborted");
+        }
     }
 }