hotspot/src/share/vm/memory/filemap.cpp
changeset 40013 943cf01a6b82
parent 38207 2ed792c9481d
child 40244 b3055c216762
--- a/hotspot/src/share/vm/memory/filemap.cpp	Tue Jul 26 11:04:20 2016 +0200
+++ b/hotspot/src/share/vm/memory/filemap.cpp	Tue Jul 26 10:29:27 2016 -0400
@@ -199,11 +199,45 @@
   size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
 
   for (int pass=0; pass<2; pass++) {
-    ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
 
-    for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
+    // Process the modular java runtime image first
+    ClassPathEntry* jrt_entry = ClassLoader::get_jrt_entry();
+    assert(jrt_entry != NULL,
+           "No modular java runtime image present when allocating the CDS classpath entry table");
+    const char *name = jrt_entry->name();
+    int name_bytes = (int)(strlen(name) + 1);
+    if (pass == 0) {
+      count++;
+      bytes += (int)entry_size;
+      bytes += name_bytes;
+      log_info(class, path)("add main shared path for modular java runtime image %s", name);
+    } else {
+      // The java runtime image is always in slot 0 on the shared class path.
+      SharedClassPathEntry* ent = shared_classpath(0);
+      struct stat st;
+      if (os::stat(name, &st) == 0) {
+        ent->_timestamp = st.st_mtime;
+        ent->_filesize = st.st_size;
+      }
+      if (ent->_filesize == 0) {
+        // unknown
+        ent->_filesize = -2;
+      }
+      ent->_name = strptr;
+      assert(strptr + name_bytes <= strptr_max, "miscalculated buffer size");
+      strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0.
+      strptr += name_bytes;
+    }
+
+    // Walk the appended entries, which includes the entries added for the classpath.
+    ClassPathEntry *cpe = ClassLoader::classpath_entry(1);
+
+    // Since the java runtime image is always in slot 0 on the shared class path, the
+    // appended entries are started at slot 1 immediately after.
+    for (int cur_entry = 1 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
       const char *name = cpe->name();
       int name_bytes = (int)(strlen(name) + 1);
+      assert(!cpe->is_jrt(), "A modular java runtime image is present on the list of appended entries");
 
       if (pass == 0) {
         count ++;
@@ -228,11 +262,7 @@
         } else {
           struct stat st;
           if (os::stat(name, &st) == 0) {
-            if (cpe->is_jrt()) {
-              // it's the "modules" jimage
-              ent->_timestamp = st.st_mtime;
-              ent->_filesize = st.st_size;
-            } else if ((st.st_mode & S_IFDIR) == S_IFDIR) {
+            if ((st.st_mode & S_IFDIR) == S_IFDIR) {
               if (!os::dir_is_empty(name)) {
                 ClassLoader::exit_with_path_failure(
                   "Cannot have non-empty directory in archived classpaths", name);
@@ -886,6 +916,11 @@
     return false;
   }
 
+  if (!Arguments::has_jimage()) {
+    FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
+    return false;
+  }
+
   if (_version != current_version()) {
     FileMapInfo::fail_continue("The shared archive file is the wrong version.");
     return false;