--- old/src/hotspot/share/classfile/classLoader.cpp 2019-03-13 08:49:07.151245200 -0700 +++ new/src/hotspot/share/classfile/classLoader.cpp 2019-03-13 08:49:06.879241857 -0700 @@ -139,6 +139,7 @@ ClassPathEntry* ClassLoader::_jrt_entry = NULL; ClassPathEntry* ClassLoader::_first_append_entry = NULL; ClassPathEntry* ClassLoader::_last_append_entry = NULL; +const char* ClassLoader::_modules_image_identity = MODULES_IMAGE_NAME; #if INCLUDE_CDS ClassPathEntry* ClassLoader::_app_classpath_entries = NULL; ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL; @@ -736,6 +737,8 @@ // Check for a jimage if (Arguments::has_jimage()) { + _modules_image_identity = os::strdup(new_entry->name()); + assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice"); assert(new_entry != NULL && new_entry->is_modules_image(), "No java runtime image present"); _jrt_entry = new_entry; @@ -846,7 +849,7 @@ } } } - log_info(class, path)("opened: %s", path); + log_info(class, path)("opened: %s (real path: %s)", path, canonical_path); log_info(class, load)("opened: %s", path); } else { // Directory --- old/src/hotspot/share/classfile/classLoader.hpp 2019-03-13 08:49:07.823253459 -0700 +++ new/src/hotspot/share/classfile/classLoader.hpp 2019-03-13 08:49:07.523249772 -0700 @@ -26,6 +26,7 @@ #define SHARE_CLASSFILE_CLASSLOADER_HPP #include "jimage.hpp" +#include "runtime/arguments.hpp" #include "runtime/handles.hpp" #include "runtime/perfData.hpp" #include "utilities/exceptions.hpp" @@ -34,7 +35,12 @@ // The VM class loader. #include -// Name of boot "modules" image +// Name of boot "modules" image. This macro may be used with caution. +// +// For most of use cases, ClassLoader::modules_image_identity(), which gives the +// canonical path should be used. When dealing with the system boot path string +// that's set up by os::set_boot_path(), then the canonical name cannot be +// used and MODULES_IMAGE_NAME should be used directly. #define MODULES_IMAGE_NAME "modules" // Class path entry (directory or zip file) @@ -217,6 +223,9 @@ // Last entry in linked list of appended ClassPathEntry instances static ClassPathEntry* _last_append_entry; + // The modules image identity obtained from the canonical path. + static const char* _modules_image_identity; + // Info used by CDS CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;) @@ -439,7 +448,14 @@ // distinguish from a class_name with no package name, as both cases have a NULL return value static const char* package_from_name(const char* const class_name, bool* bad_class_name = NULL); - static bool is_modules_image(const char* name) { return string_ends_with(name, MODULES_IMAGE_NAME); } + static const char* modules_image_identity() { return _modules_image_identity; } + static bool is_modules_image(const char* name) { + if (Arguments::has_jimage()) { + assert(modules_image_identity() != NULL, "must be set"); + return strcmp(name, modules_image_identity()) == 0; + } + return false; + } // Debugging static void verify() PRODUCT_RETURN; --- /dev/null 2019-02-05 09:23:58.036870828 -0800 +++ new/test/hotspot/jtreg/runtime/modules/ModulesSymLink.java 2019-03-13 08:49:08.191257982 -0700 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019, Google Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary Test with symbolic linked lib/modules + * @bug 8220095 + * @requires (os.family == "solaris" | os.family == "linux" | os.family == "mac") + * @library /test/lib + * @modules java.management + * jdk.jlink + * @run driver ModulesSymLink + */ + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class ModulesSymLink { + static String java_home; + static String test_jdk; + + public static void main(String[] args) throws Throwable { + java_home = System.getProperty("java.home"); + test_jdk = System.getProperty("user.dir") + File.separator + + "modulessymlink_jdk" + Long.toString(System.currentTimeMillis()); + + constructTestJDK(); + + ProcessBuilder pb = new ProcessBuilder( + test_jdk + File.separator + "bin" + File.separator + "java", + "-version"); + OutputAnalyzer out = new OutputAnalyzer(pb.start()); + out.shouldHaveExitValue(0); + } + + // 1) Create a test JDK binary (jlink is used to help simplify the process, + // alternatively a test JDK could be copied from JAVA_HOME.) + // 2) Rename the test JDK's lib/modules to lib/0. + // 3) Then create a link to lib/0 as lib/modules. + static void constructTestJDK() throws Throwable { + Path jlink = Paths.get(java_home, "bin", "jlink"); + OutputAnalyzer out = ProcessTools.executeProcess(jlink.toString(), + "--output", test_jdk, + "--add-modules", "java.base"); + out.shouldHaveExitValue(0); + + Path modules = Paths.get(test_jdk, "lib", "modules"); + Path renamed_modules = Paths.get(test_jdk, "lib", "0"); + Files.move(modules, renamed_modules); + Files.createSymbolicLink(modules, renamed_modules); + } +}