diff --git a/jdk/make/mapfiles/libinstrument/mapfile-vers b/jdk/make/mapfiles/libinstrument/mapfile-vers
index 748670139bd..c51a8af2dc7 100644
--- a/jdk/make/mapfiles/libinstrument/mapfile-vers
+++ b/jdk/make/mapfiles/libinstrument/mapfile-vers
@@ -39,6 +39,7 @@ SUNWprivate_1.1 {
Java_sun_instrument_InstrumentationImpl_getObjectSize0;
Java_sun_instrument_InstrumentationImpl_appendToClassLoaderSearch0;
Java_sun_instrument_InstrumentationImpl_setNativeMethodPrefixes;
+ Java_sun_instrument_InstrumentationImpl_loadAgent0;
local:
*;
};
diff --git a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
index 2f6af4de922..fb9660f6072 100644
--- a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
@@ -119,18 +119,24 @@ import sun.security.util.SecurityConstants;
* The Java run-time has the following built-in class loaders:
*
*
- * - Bootstrap class loader.
+ *
Bootstrap class loader.
* It is the virtual machine's built-in class loader, typically represented
* as {@code null}, and does not have a parent.
- * - {@linkplain #getPlatformClassLoader() Platform class loader}.
+ *
{@linkplain #getPlatformClassLoader() Platform class loader}.
* All platform classes are visible to the platform class loader
* that can be used as the parent of a {@code ClassLoader} instance.
* Platform classes include Java SE platform APIs, their implementation
* classes and JDK-specific run-time classes that are defined by the
- * platform class loader or its ancestors.
- * - {@linkplain #getSystemClassLoader() System class loader}.
- * It is also known as application class
- * loader and is distinct from the platform class loader.
+ * platform class loader or its ancestors.
+ *
To allow for upgrading/overriding of modules defined to the platform
+ * class loader, and where classes in the upgraded version link to
+ * classes in modules defined to the application class loader, the
+ * platform class loader may delegate to the application class loader.
+ * In other words, classes in named modules defined to the application
+ * class loader may be visible to the platform class loader.
+ * {@linkplain #getSystemClassLoader() System class loader}.
+ * It is also known as application class loader and is distinct
+ * from the platform class loader.
* The system class loader is typically used to define classes on the
* application class path, module path, and JDK-specific tools.
* The platform class loader is a parent or an ancestor of the system class
@@ -368,6 +374,10 @@ public abstract class ClassLoader {
* Creates a new class loader of the specified name and using the
* specified parent class loader for delegation.
*
+ * @apiNote If the parent is specified as {@code null} (for the
+ * bootstrap class loader) then there is no guarantee that all platform
+ * classes are visible.
+ *
* @param name class loader name; or {@code null} if not named
* @param parent the parent class loader
*
@@ -390,9 +400,12 @@ public abstract class ClassLoader {
* delegation.
*
*
If there is a security manager, its {@link
- * SecurityManager#checkCreateClassLoader()
- * checkCreateClassLoader} method is invoked. This may result in
- * a security exception.
+ * SecurityManager#checkCreateClassLoader() checkCreateClassLoader} method
+ * is invoked. This may result in a security exception.
+ *
+ * @apiNote If the parent is specified as {@code null} (for the
+ * bootstrap class loader) then there is no guarantee that all platform
+ * classes are visible.
*
* @param parent
* The parent class loader
@@ -2206,6 +2219,12 @@ public abstract class ClassLoader {
* this class loader are searched recursively (parent by parent)
* for a {@code Package} of the given name.
*
+ * @apiNote The {@link #getPlatformClassLoader() platform class loader}
+ * may delegate to the application class loader but the application class
+ * loader is not its ancestor. When invoked on the platform class loader,
+ * this method will not find packages defined to the application
+ * class loader.
+ *
* @param name
* The package name
*
@@ -2251,6 +2270,14 @@ public abstract class ClassLoader {
* {@code Package} object of the same package name, each defined by
* a different class loader in the class loader hierarchy.
*
+ * @apiNote The {@link #getPlatformClassLoader() platform class loader}
+ * may delegate to the application class loader. In other words,
+ * packages in modules defined to the application class loader may be
+ * visible to the platform class loader. On the other hand,
+ * the application class loader is not its ancestor and hence
+ * when invoked on the platform class loader, this method will not
+ * return any packages defined to the application class loader.
+ *
* @return The array of {@code Package} objects defined by this
* class loader and its ancestors
*
diff --git a/jdk/src/java.base/share/classes/java/lang/Module.java b/jdk/src/java.base/share/classes/java/lang/Module.java
index 26337d86beb..f6ab49b4519 100644
--- a/jdk/src/java.base/share/classes/java/lang/Module.java
+++ b/jdk/src/java.base/share/classes/java/lang/Module.java
@@ -57,6 +57,7 @@ import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.loader.BootLoader;
import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets;
+import jdk.internal.module.ModuleLoaderMap;
import jdk.internal.module.ServicesCatalog;
import jdk.internal.module.Resources;
import jdk.internal.org.objectweb.asm.AnnotationVisitor;
@@ -215,8 +216,8 @@ public final class Module implements AnnotatedElement {
}
/**
- * Returns the layer that contains this module or {@code null} if this
- * module is not in a layer.
+ * Returns the module layer that contains this module or {@code null} if
+ * this module is not in a module layer.
*
* A module layer contains named modules and therefore this method always
* returns {@code null} when invoked on an unnamed module.
@@ -691,6 +692,13 @@ public final class Module implements AnnotatedElement {
* This method has no effect if the package is already open
* to the given module.
*
+ * @apiNote This method can be used for cases where a consumer
+ * module uses a qualified opens to open a package to an API
+ * module but where the reflective access to the members of classes in
+ * the consumer module is delegated to code in another module. Code in the
+ * API module can use this method to open the package in the consumer module
+ * to the other module.
+ *
* @param pn
* The package name
* @param other
@@ -1077,7 +1085,7 @@ public final class Module implements AnnotatedElement {
if (loader != null) {
moduleToLoader.put(name, loader);
loaders.add(loader);
- } else if (!isBootLayer) {
+ } else if (!(clf instanceof ModuleLoaderMap.Mapper)) {
throw new IllegalArgumentException("loader can't be 'null'");
}
}
@@ -1458,11 +1466,11 @@ public final class Module implements AnnotatedElement {
* encapsulated.
*
* - A package name is derived from the resource name. If
- * the package name is a {@link #getPackages() package} in the module
- * then the resource can only be located by the caller of this method
- * when the package is {@link #isOpen(String,Module) open} to at least
- * the caller's module. If the resource is not in a package in the module
- * then the resource is not encapsulated.
+ * the package name is a {@linkplain #getPackages() package} in the
+ * module then the resource can only be located by the caller of this
+ * method when the package is {@linkplain #isOpen(String,Module) open}
+ * to at least the caller's module. If the resource is not in a
+ * package in the module then the resource is not encapsulated.
*
*
* In the above, the package name for a resource is derived
@@ -1521,8 +1529,7 @@ public final class Module implements AnnotatedElement {
}
// locate resource in module
- JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
- URL url = jla.findResource(loader, mn, name);
+ URL url = loader.findResource(mn, name);
if (url != null) {
try {
return url.openStream();
diff --git a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
index 098e8626525..b60d63e5f02 100644
--- a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
+++ b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
@@ -25,10 +25,10 @@
package java.lang;
-import java.lang.RuntimePermission;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
+import java.lang.module.ModuleReference;
import java.lang.reflect.Member;
import java.io.FileDescriptor;
import java.io.File;
@@ -42,12 +42,15 @@ import java.security.PrivilegedAction;
import java.security.Security;
import java.security.SecurityPermission;
import java.util.HashSet;
+import java.util.Map;
import java.util.Objects;
import java.util.PropertyPermission;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import jdk.internal.module.ModuleBootstrap;
+import jdk.internal.module.ModuleLoaderMap;
import jdk.internal.reflect.CallerSensitive;
import sun.security.util.SecurityConstants;
@@ -1431,30 +1434,30 @@ class SecurityManager {
return packages;
}
- // The non-exported packages of the modules in the boot layer that are
- // loaded by the platform class loader or its ancestors. A non-exported
- // package is a package that either is not exported at all by its containing
- // module or is exported in a qualified fashion by its containing module.
- private static final Set nonExportedPkgs;
-
+ // The non-exported packages in modules defined to the boot or platform
+ // class loaders. A non-exported package is a package that is not exported
+ // or is only exported to specific modules.
+ private static final Map nonExportedPkgs = new ConcurrentHashMap<>();
static {
- // Get the modules in the boot layer
- Stream bootLayerModules = ModuleLayer.boot().modules().stream();
-
- // Filter out the modules loaded by the boot or platform loader
- PrivilegedAction> pa = () ->
- bootLayerModules.filter(SecurityManager::isBootOrPlatformModule)
- .collect(Collectors.toSet());
- Set modules = AccessController.doPrivileged(pa);
-
- // Filter out the non-exported packages
- nonExportedPkgs = modules.stream()
- .map(Module::getDescriptor)
- .map(SecurityManager::nonExportedPkgs)
- .flatMap(Set::stream)
- .collect(Collectors.toSet());
+ addNonExportedPackages(ModuleLayer.boot());
}
+ /**
+ * Record the non-exported packages of the modules in the given layer
+ */
+ static void addNonExportedPackages(ModuleLayer layer) {
+ Set bootModules = ModuleLoaderMap.bootModules();
+ Set platformModules = ModuleLoaderMap.platformModules();
+ layer.modules().stream()
+ .map(Module::getDescriptor)
+ .filter(md -> bootModules.contains(md.name())
+ || platformModules.contains(md.name()))
+ .map(SecurityManager::nonExportedPkgs)
+ .flatMap(Set::stream)
+ .forEach(pn -> nonExportedPkgs.put(pn, Boolean.TRUE));
+ }
+
+
/**
* Called by java.security.Security
*/
@@ -1467,14 +1470,6 @@ class SecurityManager {
}
}
- /**
- * Returns true if the module's loader is the boot or platform loader.
- */
- private static boolean isBootOrPlatformModule(Module m) {
- return m.getClassLoader() == null ||
- m.getClassLoader() == ClassLoader.getPlatformClassLoader();
- }
-
/**
* Returns the non-exported packages of the specified module.
*/
@@ -1535,7 +1530,7 @@ class SecurityManager {
Objects.requireNonNull(pkg, "package name can't be null");
// check if pkg is not exported to all modules
- if (nonExportedPkgs.contains(pkg)) {
+ if (nonExportedPkgs.containsKey(pkg)) {
checkPermission(
new RuntimePermission("accessClassInPackage." + pkg));
return;
@@ -1634,7 +1629,7 @@ class SecurityManager {
Objects.requireNonNull(pkg, "package name can't be null");
// check if pkg is not exported to all modules
- if (nonExportedPkgs.contains(pkg)) {
+ if (nonExportedPkgs.containsKey(pkg)) {
checkPermission(
new RuntimePermission("defineClassInPackage." + pkg));
return;
diff --git a/jdk/src/java.base/share/classes/java/lang/System.java b/jdk/src/java.base/share/classes/java/lang/System.java
index edd5b553db1..630380e2d4b 100644
--- a/jdk/src/java.base/share/classes/java/lang/System.java
+++ b/jdk/src/java.base/share/classes/java/lang/System.java
@@ -41,7 +41,6 @@ import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
-import java.net.URL;
import java.security.AccessControlContext;
import java.security.ProtectionDomain;
import java.security.AccessController;
@@ -2111,9 +2110,6 @@ public final class System {
public Class> findBootstrapClassOrNull(ClassLoader cl, String name) {
return cl.findBootstrapClassOrNull(name);
}
- public URL findResource(ClassLoader cl, String mn, String name) throws IOException {
- return cl.findResource(mn, name);
- }
public Stream packages(ClassLoader cl) {
return cl.packages();
}
@@ -2123,6 +2119,9 @@ public final class System {
public String fastUUID(long lsb, long msb) {
return Long.fastUUID(lsb, msb);
}
+ public void addNonExportedPackages(ModuleLayer layer) {
+ SecurityManager.addNonExportedPackages(layer);
+ }
public void invalidatePackageAccessCache() {
SecurityManager.invalidatePackageAccessCache();
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
index eceba166e24..47e5aeacb65 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
@@ -876,9 +876,7 @@ public class MethodHandles {
* accessible to the class. The {@code PACKAGE} lookup mode serves to authenticate
* that the lookup object was created by a caller in the runtime package (or derived
* from a lookup originally created by suitably privileged code to a target class in
- * the runtime package). The lookup modes cannot include {@link #PRIVATE PRIVATE}
- * access. A lookup with {@code PRIVATE} access can be downgraded to drop this lookup
- * mode with the {@linkplain #dropLookupMode(int) dropLookupMode} method.
+ * the runtime package).
*
* The {@code bytes} parameter is the class bytes of a valid class file (as defined
* by the The Java Virtual Machine Specification) with a class name in the
@@ -896,7 +894,6 @@ public class MethodHandles {
* @throws IllegalArgumentException the bytes are for a class in a different package
* to the lookup class
* @throws IllegalAccessException if this lookup does not have {@code PACKAGE} access
- * @throws UnsupportedOperationException if the lookup class has {@code PRIVATE} access
* @throws LinkageError if the class is malformed ({@code ClassFormatError}), cannot be
* verified ({@code VerifyError}), is already defined, or another linkage error occurs
* @throws SecurityException if denied by the security manager
@@ -911,8 +908,6 @@ public class MethodHandles {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new RuntimePermission("defineClass"));
- if (hasPrivateAccess())
- throw new UnsupportedOperationException("PRIVATE access not supported");
if ((lookupModes() & PACKAGE) == 0)
throw new IllegalAccessException("Lookup does not have PACKAGE access");
assert (lookupModes() & (MODULE|PUBLIC)) != 0;
diff --git a/jdk/src/java.base/share/classes/java/lang/module/Configuration.java b/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
index d5fc16c1ef6..ef7e44a114d 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
@@ -109,20 +109,17 @@ public final class Configuration {
private final Set modules;
private final Map nameToModule;
- // module constraints on target
- private final String osName;
- private final String osArch;
+ // constraint on target platform
+ private final String targetPlatform;
- String osName() { return osName; }
- String osArch() { return osArch; }
+ String targetPlatform() { return targetPlatform; }
private Configuration() {
this.parents = Collections.emptyList();
this.graph = Collections.emptyMap();
this.modules = Collections.emptySet();
this.nameToModule = Collections.emptyMap();
- this.osName = null;
- this.osArch = null;
+ this.targetPlatform = null;
}
private Configuration(List parents,
@@ -147,8 +144,7 @@ public final class Configuration {
this.modules = Set.of(moduleArray);
this.nameToModule = Map.ofEntries(nameEntries);
- this.osName = resolver.osName();
- this.osArch = resolver.osArch();
+ this.targetPlatform = resolver.targetPlatform();
}
/**
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
index 01b4316fa20..20d198b46ee 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
@@ -99,6 +99,7 @@ public class ModuleDescriptor
*
* @see ModuleDescriptor#modifiers()
* @since 9
+ * @spec JPMS
*/
public static enum Modifier {
/**
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
index 0be9d8d9eff..e0e6d883550 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
@@ -286,8 +286,9 @@ public interface ModuleFinder {
* class names of provider classes.
*
* If the JAR file has a {@code Main-Class} attribute in its
- * main manifest then its value is the module {@link
- * ModuleDescriptor#mainClass() main class}.
+ * main manifest, its value is a legal class name, and its package is
+ * in the set of packages derived for the module, then the value is the
+ * module {@linkplain ModuleDescriptor#mainClass() main class}.
*
*
*
@@ -298,8 +299,7 @@ public interface ModuleFinder {
* file, where the JAR file contains a {@code .class} in the top-level
* directory of the JAR file, where an entry in a service configuration
* file is not a legal class name or its package name is not in the set of
- * packages derived for the module, or where the module main class is not
- * a legal class name or its package is not in the module.
+ * packages derived for the module.
*
* In addition to JAR files, an implementation may also support modules
* that are packaged in other implementation specific module formats. If
diff --git a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
index 6adf93f8317..a723e638abe 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
@@ -28,6 +28,7 @@ package java.lang.module;
import java.io.PrintStream;
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires.Modifier;
+import java.net.URI;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@@ -38,10 +39,8 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import java.util.StringJoiner;
import java.util.stream.Collectors;
import jdk.internal.module.ModuleHashes;
@@ -69,12 +68,10 @@ final class Resolver {
// true if all automatic modules have been found
private boolean haveAllAutomaticModules;
- // module constraints on target platform
- private String osName;
- private String osArch;
+ // constraint on target platform
+ private String targetPlatform;
- String osName() { return osName; }
- String osArch() { return osArch; }
+ String targetPlatform() { return targetPlatform; }
/**
* @throws IllegalArgumentException if there are more than one parent and
@@ -89,37 +86,23 @@ final class Resolver {
this.afterFinder = afterFinder;
this.traceOutput = traceOutput;
- // record constraints on target platform, checking that they don't conflict
+ // record constraint on target platform, checking for conflicts
for (Configuration parent : parents) {
- String value = parent.osName();
+ String value = parent.targetPlatform();
if (value != null) {
- if (osName == null) {
- osName = value;
+ if (targetPlatform == null) {
+ targetPlatform = value;
} else {
- if (!value.equals(osName)) {
- failParentConflict("Operating System", osName, value);
- }
- }
- }
- value = parent.osArch();
- if (value != null) {
- if (osArch == null) {
- osArch = value;
- } else {
- if (!value.equals(osArch)) {
- failParentConflict("OS architecture", osArch, value);
+ if (!value.equals(targetPlatform)) {
+ String msg = "Parents have conflicting constraints on target" +
+ " platform: " + targetPlatform + ", " + value;
+ throw new IllegalArgumentException(msg);
}
}
}
}
}
- private void failParentConflict(String constraint, String s1, String s2) {
- String msg = "Parents have conflicting constraints on target "
- + constraint + ": " + s1 + ", " + s2;
- throw new IllegalArgumentException(msg);
- }
-
/**
* Resolves the given named modules.
*
@@ -147,8 +130,7 @@ final class Resolver {
}
if (isTracing()) {
- trace("Root module %s located", root);
- mref.location().ifPresent(uri -> trace(" (%s)", uri));
+ trace("root %s", nameAndInfo(mref));
}
addFoundModule(mref);
@@ -180,9 +162,7 @@ final class Resolver {
ModuleDescriptor other = mref.descriptor();
q.offer(other);
if (isTracing()) {
- trace("Automatic module %s located, required by %s",
- other.name(), descriptor.name());
- mref.location().ifPresent(uri -> trace(" (%s)", uri));
+ trace("%s requires %s", descriptor.name(), nameAndInfo(mref));
}
});
haveAllAutomaticModules = true;
@@ -213,21 +193,13 @@ final class Resolver {
}
}
+ if (isTracing() && !dn.equals("java.base")) {
+ trace("%s requires %s", descriptor.name(), nameAndInfo(mref));
+ }
+
if (!nameToReference.containsKey(dn)) {
addFoundModule(mref);
q.offer(mref.descriptor());
-
- if (isTracing()) {
- String prefix;
- if (mref.descriptor().isAutomatic()) {
- prefix = "Automatic module";
- } else {
- prefix = "Module";
- }
- trace(prefix + " %s located, required by %s",
- dn, descriptor.name());
- mref.location().ifPresent(uri -> trace(" (%s)", uri));
- }
}
}
@@ -291,6 +263,13 @@ final class Resolver {
do {
for (ModuleDescriptor descriptor : candidateConsumers) {
if (!descriptor.uses().isEmpty()) {
+
+ // the modules that provide at least one service
+ Set modulesToBind = null;
+ if (isTracing()) {
+ modulesToBind = new HashSet<>();
+ }
+
for (String service : descriptor.uses()) {
Set mrefs = availableProviders.get(service);
if (mrefs != null) {
@@ -298,15 +277,13 @@ final class Resolver {
ModuleDescriptor provider = mref.descriptor();
if (!provider.equals(descriptor)) {
- trace("Module %s provides %s, used by %s",
- provider.name(), service, descriptor.name());
+ if (isTracing() && modulesToBind.add(provider)) {
+ trace("%s binds %s", descriptor.name(),
+ nameAndInfo(mref));
+ }
String pn = provider.name();
if (!nameToReference.containsKey(pn)) {
- if (isTracing()) {
- mref.location()
- .ifPresent(uri -> trace(" (%s)", uri));
- }
addFoundModule(mref);
q.push(provider);
}
@@ -349,59 +326,31 @@ final class Resolver {
if (mref instanceof ModuleReferenceImpl) {
ModuleTarget target = ((ModuleReferenceImpl)mref).moduleTarget();
if (target != null)
- checkTargetConstraints(mn, target);
+ checkTargetPlatform(mn, target);
}
nameToReference.put(mn, mref);
}
/**
- * Check that the module's constraints on the target platform do not
- * conflict with the constraints of other modules resolved so far or
- * modules in parent configurations.
+ * Check that the module's constraints on the target platform does
+ * conflict with the constraint of other modules resolved so far.
*/
- private void checkTargetConstraints(String mn, ModuleTarget target) {
- String value = target.osName();
+ private void checkTargetPlatform(String mn, ModuleTarget target) {
+ String value = target.targetPlatform();
if (value != null) {
- if (osName == null) {
- osName = value;
+ if (targetPlatform == null) {
+ targetPlatform = value;
} else {
- if (!value.equals(osName)) {
- failTargetConstraint(mn, target);
- }
- }
- }
- value = target.osArch();
- if (value != null) {
- if (osArch == null) {
- osArch = value;
- } else {
- if (!value.equals(osArch)) {
- failTargetConstraint(mn, target);
+ if (!value.equals(targetPlatform)) {
+ findFail("Module %s has constraints on target platform (%s)"
+ + " that conflict with other modules: %s", mn,
+ value, targetPlatform);
}
}
}
}
- private void failTargetConstraint(String mn, ModuleTarget target) {
- String s1 = targetAsString(osName, osArch);
- String s2 = targetAsString(target.osName(), target.osArch());
- findFail("Module %s has constraints on target platform (%s) that"
- + " conflict with other modules: %s", mn, s1, s2);
- }
-
- private String targetAsString(ModuleTarget target) {
- return targetAsString(target.osName(), target.osArch());
- }
-
- private String targetAsString(String osName, String osArch) {
- return new StringJoiner("-")
- .add(Objects.toString(osName, "*"))
- .add(Objects.toString(osArch, "*"))
- .toString();
- }
-
-
/**
* Execute post-resolution checks and returns the module graph of resolved
* modules as {@code Map}. The resolved modules will be in the given
@@ -412,12 +361,6 @@ final class Resolver {
Map> finish(Configuration cf,
boolean check)
{
- if (isTracing()) {
- trace("Result:");
- Set names = nameToReference.keySet();
- names.stream().sorted().forEach(name -> trace(" %s", name));
- }
-
if (check) {
detectCycles();
checkHashes();
@@ -520,9 +463,8 @@ final class Resolver {
findFail("Unable to compute the hash of module %s", dn);
}
- // skip checking the hash if the module has been patched
ModuleReferenceImpl other = (ModuleReferenceImpl)mref2;
- if (other != null && !other.isPatched()) {
+ if (other != null) {
byte[] recordedHash = hashes.hashFor(dn);
byte[] actualHash = other.computeHash(algorithm);
if (actualHash == null)
@@ -965,9 +907,17 @@ final class Resolver {
private void trace(String fmt, Object ... args) {
if (traceOutput != null) {
- traceOutput.format("[Resolver] " + fmt, args);
+ traceOutput.format(fmt, args);
traceOutput.println();
}
}
+ private String nameAndInfo(ModuleReference mref) {
+ ModuleDescriptor descriptor = mref.descriptor();
+ StringBuilder sb = new StringBuilder(descriptor.name());
+ mref.location().ifPresent(uri -> sb.append(" " + uri));
+ if (descriptor.isAutomatic())
+ sb.append(" automatic");
+ return sb.toString();
+ }
}
diff --git a/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java b/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java
index 08ff1f0d740..2754fa39c0a 100644
--- a/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java
+++ b/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. 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
@@ -36,6 +36,8 @@ import java.util.Map;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
+import jdk.internal.misc.VM;
+
/**
* Factory methods for file systems. This class defines the {@link #getDefault
* getDefault} method to get the default file system and factory methods to
@@ -120,8 +122,8 @@ public final class FileSystems {
// if the property java.nio.file.spi.DefaultFileSystemProvider is
// set then its value is the name of the default provider (or a list)
- String propValue = System
- .getProperty("java.nio.file.spi.DefaultFileSystemProvider");
+ String prop = "java.nio.file.spi.DefaultFileSystemProvider";
+ String propValue = System.getProperty(prop);
if (propValue != null) {
for (String cn: propValue.split(",")) {
try {
@@ -184,7 +186,7 @@ public final class FileSystems {
* @return the default file system
*/
public static FileSystem getDefault() {
- if (jdk.internal.misc.VM.isBooted()) {
+ if (VM.isModuleSystemInited()) {
return DefaultFileSystemHolder.defaultFileSystem;
} else {
return BuiltinFileSystemHolder.builtinFileSystem;
diff --git a/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java b/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
index ce3bb67e8dd..5d1c97c6d25 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
@@ -172,12 +172,10 @@ public class BuiltinClassLoader
}
/**
- * Register a module this this class loader. This has the effect of making
- * the types in the module visible.
+ * Register a module this class loader. This has the effect of making the
+ * types in the module visible.
*/
public void loadModule(ModuleReference mref) {
- assert !VM.isModuleSystemInited();
-
String mn = mref.descriptor().name();
if (nameToModule.putIfAbsent(mn, mref) != null) {
throw new InternalError(mn + " already defined to this loader");
@@ -191,6 +189,11 @@ public class BuiltinClassLoader
+ other.mref().descriptor().name());
}
}
+
+ // clear resources cache if VM is already initialized
+ if (VM.isModuleSystemInited() && resourceCache != null) {
+ resourceCache = null;
+ }
}
/**
@@ -355,7 +358,10 @@ public class BuiltinClassLoader
private List findMiscResource(String name) throws IOException {
SoftReference