8177530: Module system implementation refresh (4/2017)

Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Reviewed-by: mchung, alanb
This commit is contained in:
Alan Bateman 2017-04-07 08:05:54 +00:00
parent b204ee7e06
commit 02cfdc2061
222 changed files with 1364 additions and 1233 deletions

View File

@ -273,12 +273,12 @@ SUNWprivate_1.1 {
Java_jdk_internal_misc_VM_getRuntimeArguments; Java_jdk_internal_misc_VM_getRuntimeArguments;
Java_jdk_internal_misc_VM_initialize; Java_jdk_internal_misc_VM_initialize;
Java_java_lang_reflect_Module_defineModule0; Java_java_lang_Module_defineModule0;
Java_java_lang_reflect_Module_addReads0; Java_java_lang_Module_addReads0;
Java_java_lang_reflect_Module_addExports0; Java_java_lang_Module_addExports0;
Java_java_lang_reflect_Module_addExportsToAll0; Java_java_lang_Module_addExportsToAll0;
Java_java_lang_reflect_Module_addExportsToAllUnnamed0; Java_java_lang_Module_addExportsToAllUnnamed0;
Java_java_lang_reflect_Module_addPackage0; Java_java_lang_Module_addPackage0;
Java_jdk_internal_loader_BootLoader_getSystemPackageLocation; Java_jdk_internal_loader_BootLoader_getSystemPackageLocation;
Java_jdk_internal_loader_BootLoader_getSystemPackageNames; Java_jdk_internal_loader_BootLoader_getSystemPackageNames;

View File

@ -322,7 +322,7 @@ public interface ObjectInputFilter {
* Other patterns match or reject class or package name * Other patterns match or reject class or package name
* as returned from {@link Class#getName() Class.getName()} and * as returned from {@link Class#getName() Class.getName()} and
* if an optional module name is present * if an optional module name is present
* {@link java.lang.reflect.Module#getName() class.getModule().getName()}. * {@link Module#getName() class.getModule().getName()}.
* Note that for arrays the element type is used in the pattern, * Note that for arrays the element type is used in the pattern,
* not the array type. * not the array type.
* <ul> * <ul>

View File

@ -43,7 +43,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
@ -2561,21 +2560,16 @@ public final class Class<T> implements java.io.Serializable,
public InputStream getResourceAsStream(String name) { public InputStream getResourceAsStream(String name) {
name = resolveName(name); name = resolveName(name);
Module module = getModule(); Module thisModule = getModule();
if (module.isNamed()) { if (thisModule.isNamed()) {
if (Resources.canEncapsulate(name)) { // check if resource can be located by caller
Module caller = Reflection.getCallerClass().getModule(); if (Resources.canEncapsulate(name)
if (caller != module) { && !isOpenToCaller(name, Reflection.getCallerClass())) {
Set<String> packages = module.getDescriptor().packages(); return null;
String pn = Resources.toPackageName(name);
if (packages.contains(pn) && !module.isOpen(pn, caller)) {
// resource is in package not open to caller
return null;
}
}
} }
String mn = module.getName(); // resource not encapsulated or in package open to caller
String mn = thisModule.getName();
ClassLoader cl = getClassLoader0(); ClassLoader cl = getClassLoader0();
try { try {
@ -2663,20 +2657,16 @@ public final class Class<T> implements java.io.Serializable,
public URL getResource(String name) { public URL getResource(String name) {
name = resolveName(name); name = resolveName(name);
Module module = getModule(); Module thisModule = getModule();
if (module.isNamed()) { if (thisModule.isNamed()) {
if (Resources.canEncapsulate(name)) { // check if resource can be located by caller
Module caller = Reflection.getCallerClass().getModule(); if (Resources.canEncapsulate(name)
if (caller != module) { && !isOpenToCaller(name, Reflection.getCallerClass())) {
Set<String> packages = module.getDescriptor().packages(); return null;
String pn = Resources.toPackageName(name);
if (packages.contains(pn) && !module.isOpen(pn, caller)) {
// resource is in package not open to caller
return null;
}
}
} }
String mn = getModule().getName();
// resource not encapsulated or in package open to caller
String mn = thisModule.getName();
ClassLoader cl = getClassLoader0(); ClassLoader cl = getClassLoader0();
try { try {
if (cl == null) { if (cl == null) {
@ -2698,10 +2688,36 @@ public final class Class<T> implements java.io.Serializable,
} }
} }
/**
* Returns true if a resource with the given name can be located by the
* given caller. All resources in a module can be located by code in
* the module. For other callers, then the package needs to be open to
* the caller.
*/
private boolean isOpenToCaller(String name, Class<?> caller) {
// assert getModule().isNamed();
Module thisModule = getModule();
Module callerModule = (caller != null) ? caller.getModule() : null;
if (callerModule != thisModule) {
String pn = Resources.toPackageName(name);
if (thisModule.getDescriptor().packages().contains(pn)) {
if (callerModule == null && !thisModule.isOpen(pn)) {
// no caller, package not open
return false;
}
if (!thisModule.isOpen(pn, callerModule)) {
// package not open to caller
return false;
}
}
}
return true;
}
/** protection domain returned when the internal domain is null */ /** protection domain returned when the internal domain is null */
private static java.security.ProtectionDomain allPermDomain; private static java.security.ProtectionDomain allPermDomain;
/** /**
* Returns the {@code ProtectionDomain} of this class. If there is a * Returns the {@code ProtectionDomain} of this class. If there is a
* security manager installed, this method first calls the security * security manager installed, this method first calls the security

View File

@ -31,7 +31,6 @@ import java.io.UncheckedIOException;
import java.io.File; import java.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.security.AccessController; import java.security.AccessController;
import java.security.AccessControlContext; import java.security.AccessControlContext;
@ -352,9 +351,7 @@ public abstract class ClassLoader {
private ClassLoader(Void unused, String name, ClassLoader parent) { private ClassLoader(Void unused, String name, ClassLoader parent) {
this.name = name; this.name = name;
this.parent = parent; this.parent = parent;
this.unnamedModule this.unnamedModule = new Module(this);
= SharedSecrets.getJavaLangReflectModuleAccess()
.defineUnnamedModule(this);
if (ParallelLoaders.isRegistered(this.getClass())) { if (ParallelLoaders.isRegistered(this.getClass())) {
parallelLockMap = new ConcurrentHashMap<>(); parallelLockMap = new ConcurrentHashMap<>();
package2certs = new ConcurrentHashMap<>(); package2certs = new ConcurrentHashMap<>();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,13 +23,12 @@
* questions. * questions.
*/ */
package java.lang.reflect; package java.lang;
/** /**
* Thrown when creating a Layer fails. * Thrown when creating a {@linkplain ModuleLayer module layer} fails.
*
* @see Layer
* *
* @see ModuleLayer
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
*/ */

View File

@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package java.lang.reflect; package java.lang;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -35,6 +35,7 @@ import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens; import java.lang.module.ModuleDescriptor.Opens;
import java.lang.module.ModuleDescriptor.Version; import java.lang.module.ModuleDescriptor.Version;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.AnnotatedElement;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.security.AccessController; import java.security.AccessController;
@ -49,12 +50,12 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.internal.loader.BuiltinClassLoader; import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.loader.BootLoader; import jdk.internal.loader.BootLoader;
import jdk.internal.misc.JavaLangAccess; import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.JavaLangReflectModuleAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.ServicesCatalog; import jdk.internal.module.ServicesCatalog;
import jdk.internal.module.Resources; import jdk.internal.module.Resources;
@ -73,7 +74,7 @@ import sun.security.util.SecurityConstants;
* *
* <p> Named modules have a {@link #getName() name} and are constructed by the * <p> Named modules have a {@link #getName() name} and are constructed by the
* Java Virtual Machine when a graph of modules is defined to the Java virtual * Java Virtual Machine when a graph of modules is defined to the Java virtual
* machine to create a module {@link Layer Layer}. </p> * machine to create a {@linkplain ModuleLayer module layer}. </p>
* *
* <p> An unnamed module does not have a name. There is an unnamed module for * <p> An unnamed module does not have a name. There is an unnamed module for
* each {@link ClassLoader ClassLoader}, obtained by invoking its {@link * each {@link ClassLoader ClassLoader}, obtained by invoking its {@link
@ -92,13 +93,13 @@ import sun.security.util.SecurityConstants;
* *
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
* @see java.lang.Class#getModule * @see Class#getModule()
*/ */
public final class Module implements AnnotatedElement { public final class Module implements AnnotatedElement {
// the layer that contains this module, can be null // the layer that contains this module, can be null
private final Layer layer; private final ModuleLayer layer;
// module name and loader, these fields are read by VM // module name and loader, these fields are read by VM
private final String name; private final String name;
@ -113,10 +114,10 @@ public final class Module implements AnnotatedElement {
* VM but will not read any other modules, will not have any exports setup * VM but will not read any other modules, will not have any exports setup
* and will not be registered in the service catalog. * and will not be registered in the service catalog.
*/ */
private Module(Layer layer, Module(ModuleLayer layer,
ClassLoader loader, ClassLoader loader,
ModuleDescriptor descriptor, ModuleDescriptor descriptor,
URI uri) URI uri)
{ {
this.layer = layer; this.layer = layer;
this.name = descriptor.name(); this.name = descriptor.name();
@ -139,7 +140,7 @@ public final class Module implements AnnotatedElement {
* *
* @see ClassLoader#getUnnamedModule * @see ClassLoader#getUnnamedModule
*/ */
private Module(ClassLoader loader) { Module(ClassLoader loader) {
this.layer = null; this.layer = null;
this.name = null; this.name = null;
this.loader = loader; this.loader = loader;
@ -217,29 +218,28 @@ public final class Module implements AnnotatedElement {
* Returns the layer that contains this module or {@code null} if this * Returns the layer that contains this module or {@code null} if this
* module is not in a layer. * module is not in a layer.
* *
* A module {@code Layer} contains named modules and therefore this * A module layer contains named modules and therefore this method always
* method always returns {@code null} when invoked on an unnamed module. * returns {@code null} when invoked on an unnamed module.
* *
* <p> <a href="Proxy.html#dynamicmodule">Dynamic modules</a> are named * <p> <a href="reflect/Proxy.html#dynamicmodule">Dynamic modules</a> are
* modules that are generated at runtime. A dynamic module may or may * named modules that are generated at runtime. A dynamic module may or may
* not be in a module Layer. </p> * not be in a module layer. </p>
* *
* @return The layer that contains this module * @return The module layer that contains this module
* *
* @see Proxy * @see java.lang.reflect.Proxy
*/ */
public Layer getLayer() { public ModuleLayer getLayer() {
if (isNamed()) { if (isNamed()) {
Layer layer = this.layer; ModuleLayer layer = this.layer;
if (layer != null) if (layer != null)
return layer; return layer;
// special-case java.base as it is created before the boot Layer // special-case java.base as it is created before the boot layer
if (loader == null && name.equals("java.base")) { if (loader == null && name.equals("java.base")) {
return SharedSecrets.getJavaLangAccess().getBootLayer(); return ModuleLayer.boot();
} }
} }
return null; return null;
} }
@ -338,7 +338,7 @@ public final class Module implements AnnotatedElement {
public Module addReads(Module other) { public Module addReads(Module other) {
Objects.requireNonNull(other); Objects.requireNonNull(other);
if (this.isNamed()) { if (this.isNamed()) {
Module caller = Reflection.getCallerClass().getModule(); Module caller = getCallerModule(Reflection.getCallerClass());
if (caller != this) { if (caller != this) {
throw new IllegalCallerException(caller + " != " + this); throw new IllegalCallerException(caller + " != " + this);
} }
@ -350,12 +350,21 @@ public final class Module implements AnnotatedElement {
/** /**
* Updates this module to read another module. * Updates this module to read another module.
* *
* @apiNote This method is for Proxy use and white-box testing. * @apiNote Used by the --add-reads command line option.
*/ */
void implAddReads(Module other) { void implAddReads(Module other) {
implAddReads(other, true); implAddReads(other, true);
} }
/**
* Updates this module to read all unnamed modules.
*
* @apiNote Used by the --add-reads command line option.
*/
void implAddReadsAllUnnamed() {
implAddReads(Module.ALL_UNNAMED_MODULE, true);
}
/** /**
* Updates this module to read another module without notifying the VM. * Updates this module to read another module without notifying the VM.
* *
@ -371,6 +380,7 @@ public final class Module implements AnnotatedElement {
* If {@code syncVM} is {@code true} then the VM is notified. * If {@code syncVM} is {@code true} then the VM is notified.
*/ */
private void implAddReads(Module other, boolean syncVM) { private void implAddReads(Module other, boolean syncVM) {
Objects.requireNonNull(other);
if (!canRead(other)) { if (!canRead(other)) {
// update VM first, just in case it fails // update VM first, just in case it fails
if (syncVM) { if (syncVM) {
@ -659,7 +669,7 @@ public final class Module implements AnnotatedElement {
Objects.requireNonNull(other); Objects.requireNonNull(other);
if (isNamed()) { if (isNamed()) {
Module caller = Reflection.getCallerClass().getModule(); Module caller = getCallerModule(Reflection.getCallerClass());
if (caller != this) { if (caller != this) {
throw new IllegalCallerException(caller + " != " + this); throw new IllegalCallerException(caller + " != " + this);
} }
@ -706,8 +716,8 @@ public final class Module implements AnnotatedElement {
Objects.requireNonNull(other); Objects.requireNonNull(other);
if (isNamed()) { if (isNamed()) {
Module caller = Reflection.getCallerClass().getModule(); Module caller = getCallerModule(Reflection.getCallerClass());
if (caller != this && !isOpen(pn, caller)) if (caller != this && (caller == null || !isOpen(pn, caller)))
throw new IllegalCallerException(pn + " is not open to " + caller); throw new IllegalCallerException(pn + " is not open to " + caller);
implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true); implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
} }
@ -717,36 +727,80 @@ public final class Module implements AnnotatedElement {
/** /**
* Updates the exports so that package {@code pn} is exported to module * Updates this module to export a package unconditionally.
* {@code other} but without notifying the VM.
* *
* @apiNote This method is for VM white-box testing. * @apiNote This method is for JDK tests only.
*/ */
void implAddExportsNoSync(String pn, Module other) { void implAddExports(String pn) {
if (other == null) implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, false, true);
other = EVERYONE_MODULE;
implAddExportsOrOpens(pn.replace('/', '.'), other, false, false);
} }
/** /**
* Updates the exports so that package {@code pn} is exported to module * Updates this module to export a package to another module.
* {@code other}.
* *
* @apiNote This method is for white-box testing. * @apiNote Used by Instrumentation::redefineModule and --add-exports
*/ */
void implAddExports(String pn, Module other) { void implAddExports(String pn, Module other) {
implAddExportsOrOpens(pn, other, false, true); implAddExportsOrOpens(pn, other, false, true);
} }
/** /**
* Updates the module to open package {@code pn} to module {@code other}. * Updates this module to export a package to all unnamed modules.
* *
* @apiNote This method is for white-box tests and jtreg * @apiNote Used by the --add-exports command line option.
*/
void implAddExportsToAllUnnamed(String pn) {
implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, false, true);
}
/**
* Updates this export to export a package unconditionally without
* notifying the VM.
*
* @apiNote This method is for VM white-box testing.
*/
void implAddExportsNoSync(String pn) {
implAddExportsOrOpens(pn.replace('/', '.'), Module.EVERYONE_MODULE, false, false);
}
/**
* Updates a module to export a package to another module without
* notifying the VM.
*
* @apiNote This method is for VM white-box testing.
*/
void implAddExportsNoSync(String pn, Module other) {
implAddExportsOrOpens(pn.replace('/', '.'), other, false, false);
}
/**
* Updates this module to open a package unconditionally.
*
* @apiNote This method is for JDK tests only.
*/
void implAddOpens(String pn) {
implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, true, true);
}
/**
* Updates this module to open a package to another module.
*
* @apiNote Used by Instrumentation::redefineModule and --add-opens
*/ */
void implAddOpens(String pn, Module other) { void implAddOpens(String pn, Module other) {
implAddExportsOrOpens(pn, other, true, true); implAddExportsOrOpens(pn, other, true, true);
} }
/**
* Updates this module to export a package to all unnamed modules.
*
* @apiNote Used by the --add-opens command line option.
*/
void implAddOpensToAllUnnamed(String pn) {
implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, true, true);
}
/** /**
* Updates a module to export or open a module to another module. * Updates a module to export or open a module to another module.
* *
@ -831,7 +885,7 @@ public final class Module implements AnnotatedElement {
Objects.requireNonNull(service); Objects.requireNonNull(service);
if (isNamed() && !descriptor.isAutomatic()) { if (isNamed() && !descriptor.isAutomatic()) {
Module caller = Reflection.getCallerClass().getModule(); Module caller = getCallerModule(Reflection.getCallerClass());
if (caller != this) { if (caller != this) {
throw new IllegalCallerException(caller + " != " + this); throw new IllegalCallerException(caller + " != " + this);
} }
@ -899,33 +953,28 @@ public final class Module implements AnnotatedElement {
/** /**
* Returns an array of the package names of the packages in this module. * Returns the set of package names for the packages in this module.
* *
* <p> For named modules, the returned array contains an element for each * <p> For named modules, the returned set contains an element for each
* package in the module. </p> * package in the module. </p>
* *
* <p> For unnamed modules, this method is the equivalent to invoking the * <p> For unnamed modules, this method is the equivalent to invoking the
* {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of * {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of
* this module's class loader and returning the array of package names. </p> * this module's class loader and returning the set of package names. </p>
* *
* <p> A package name appears at most once in the returned array. </p> * @return the set of the package names of the packages in this module
*
* @apiNote This method returns an array rather than a {@code Set} for
* consistency with other {@code java.lang.reflect} types.
*
* @return an array of the package names of the packages in this module
*/ */
public String[] getPackages() { public Set<String> getPackages() {
if (isNamed()) { if (isNamed()) {
Set<String> packages = descriptor.packages(); Set<String> packages = descriptor.packages();
Map<String, Boolean> extraPackages = this.extraPackages; Map<String, Boolean> extraPackages = this.extraPackages;
if (extraPackages == null) { if (extraPackages == null) {
return packages.toArray(new String[0]); return packages;
} else { } else {
return Stream.concat(packages.stream(), return Stream.concat(packages.stream(),
extraPackages.keySet().stream()) extraPackages.keySet().stream())
.toArray(String[]::new); .collect(Collectors.toSet());
} }
} else { } else {
@ -936,7 +985,7 @@ public final class Module implements AnnotatedElement {
} else { } else {
packages = SharedSecrets.getJavaLangAccess().packages(loader); packages = SharedSecrets.getJavaLangAccess().packages(loader);
} }
return packages.map(Package::getName).toArray(String[]::new); return packages.map(Package::getName).collect(Collectors.toSet());
} }
} }
@ -1013,12 +1062,12 @@ public final class Module implements AnnotatedElement {
*/ */
static Map<String, Module> defineModules(Configuration cf, static Map<String, Module> defineModules(Configuration cf,
Function<String, ClassLoader> clf, Function<String, ClassLoader> clf,
Layer layer) ModuleLayer layer)
{ {
Map<String, Module> nameToModule = new HashMap<>(); Map<String, Module> nameToModule = new HashMap<>();
Map<String, ClassLoader> moduleToLoader = new HashMap<>(); Map<String, ClassLoader> moduleToLoader = new HashMap<>();
boolean isBootLayer = (Layer.boot() == null); boolean isBootLayer = (ModuleLayer.boot() == null);
Set<ClassLoader> loaders = new HashSet<>(); Set<ClassLoader> loaders = new HashSet<>();
// map each module to a class loader // map each module to a class loader
@ -1074,7 +1123,7 @@ public final class Module implements AnnotatedElement {
assert m2 != null; assert m2 != null;
} else { } else {
// parent layer // parent layer
for (Layer parent: layer.parents()) { for (ModuleLayer parent: layer.parents()) {
m2 = findModule(parent, other); m2 = findModule(parent, other);
if (m2 != null) if (m2 != null)
break; break;
@ -1133,7 +1182,8 @@ public final class Module implements AnnotatedElement {
* Find the runtime Module corresponding to the given ResolvedModule * Find the runtime Module corresponding to the given ResolvedModule
* in the given parent layer (or its parents). * in the given parent layer (or its parents).
*/ */
private static Module findModule(Layer parent, ResolvedModule resolvedModule) { private static Module findModule(ModuleLayer parent,
ResolvedModule resolvedModule) {
Configuration cf = resolvedModule.configuration(); Configuration cf = resolvedModule.configuration();
String dn = resolvedModule.name(); String dn = resolvedModule.name();
return parent.layers() return parent.layers()
@ -1156,7 +1206,7 @@ public final class Module implements AnnotatedElement {
private static void initExportsAndOpens(Module m, private static void initExportsAndOpens(Module m,
Map<String, Module> nameToSource, Map<String, Module> nameToSource,
Map<String, Module> nameToModule, Map<String, Module> nameToModule,
List<Layer> parents) { List<ModuleLayer> parents) {
// The VM doesn't special case open or automatic modules so need to // The VM doesn't special case open or automatic modules so need to
// export all packages // export all packages
ModuleDescriptor descriptor = m.getDescriptor(); ModuleDescriptor descriptor = m.getDescriptor();
@ -1246,12 +1296,12 @@ public final class Module implements AnnotatedElement {
private static Module findModule(String target, private static Module findModule(String target,
Map<String, Module> nameToSource, Map<String, Module> nameToSource,
Map<String, Module> nameToModule, Map<String, Module> nameToModule,
List<Layer> parents) { List<ModuleLayer> parents) {
Module m = nameToSource.get(target); Module m = nameToSource.get(target);
if (m == null) { if (m == null) {
m = nameToModule.get(target); m = nameToModule.get(target);
if (m == null) { if (m == null) {
for (Layer parent : parents) { for (ModuleLayer parent : parents) {
m = parent.findModule(target).orElse(null); m = parent.findModule(target).orElse(null);
if (m != null) break; if (m != null) break;
} }
@ -1445,14 +1495,18 @@ public final class Module implements AnnotatedElement {
} }
if (isNamed() && Resources.canEncapsulate(name)) { if (isNamed() && Resources.canEncapsulate(name)) {
Module caller = Reflection.getCallerClass().getModule(); Module caller = getCallerModule(Reflection.getCallerClass());
if (caller != this && caller != Object.class.getModule()) { if (caller != this && caller != Object.class.getModule()) {
// ignore packages added for proxies via addPackage
Set<String> packages = getDescriptor().packages();
String pn = Resources.toPackageName(name); String pn = Resources.toPackageName(name);
if (packages.contains(pn) && !isOpen(pn, caller)) { if (getPackages().contains(pn)) {
// resource is in package not open to caller if (caller == null && !isOpen(pn)) {
return null; // no caller, package not open
return null;
}
if (!isOpen(pn, caller)) {
// package not open to caller
return null;
}
} }
} }
} }
@ -1497,6 +1551,14 @@ public final class Module implements AnnotatedElement {
} }
} }
/**
* Returns the module that a given caller class is a member of. Returns
* {@code null} if the caller is {@code null}.
*/
private Module getCallerModule(Class<?> caller) {
return (caller != null) ? caller.getModule() : null;
}
// -- native methods -- // -- native methods --
@ -1521,71 +1583,4 @@ public final class Module implements AnnotatedElement {
// JVM_AddModulePackage // JVM_AddModulePackage
private static native void addPackage0(Module m, String pn); private static native void addPackage0(Module m, String pn);
/**
* Register shared secret to provide access to package-private methods
*/
static {
SharedSecrets.setJavaLangReflectModuleAccess(
new JavaLangReflectModuleAccess() {
@Override
public Module defineUnnamedModule(ClassLoader loader) {
return new Module(loader);
}
@Override
public Module defineModule(ClassLoader loader,
ModuleDescriptor descriptor,
URI uri) {
return new Module(null, loader, descriptor, uri);
}
@Override
public void addReads(Module m1, Module m2) {
m1.implAddReads(m2, true);
}
@Override
public void addReadsAllUnnamed(Module m) {
m.implAddReads(Module.ALL_UNNAMED_MODULE);
}
@Override
public void addExports(Module m, String pn) {
m.implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, false, true);
}
@Override
public void addExports(Module m, String pn, Module other) {
m.implAddExportsOrOpens(pn, other, false, true);
}
@Override
public void addExportsToAllUnnamed(Module m, String pn) {
m.implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, false, true);
}
@Override
public void addOpens(Module m, String pn) {
m.implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, true, true);
}
@Override
public void addOpens(Module m, String pn, Module other) {
m.implAddExportsOrOpens(pn, other, true, true);
}
@Override
public void addOpensToAllUnnamed(Module m, String pn) {
m.implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, true, true);
}
@Override
public void addUses(Module m, Class<?> service) {
m.implAddUses(service);
}
@Override
public ServicesCatalog getServicesCatalog(Layer layer) {
return layer.getServicesCatalog();
}
@Override
public Stream<Layer> layers(Layer layer) {
return layer.layers();
}
@Override
public Stream<Layer> layers(ClassLoader loader) {
return Layer.layers(loader);
}
});
}
} }

View File

@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package java.lang.reflect; package java.lang;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
@ -47,8 +47,6 @@ import java.util.stream.Stream;
import jdk.internal.loader.ClassLoaderValue; import jdk.internal.loader.ClassLoaderValue;
import jdk.internal.loader.Loader; import jdk.internal.loader.Loader;
import jdk.internal.loader.LoaderPool; import jdk.internal.loader.LoaderPool;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.Modules;
import jdk.internal.module.ServicesCatalog; import jdk.internal.module.ServicesCatalog;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
@ -70,15 +68,16 @@ import sun.security.util.SecurityConstants;
* *
* <p> The {@link #defineModulesWithOneLoader defineModulesWithOneLoader} and * <p> The {@link #defineModulesWithOneLoader defineModulesWithOneLoader} and
* {@link #defineModulesWithManyLoaders defineModulesWithManyLoaders} methods * {@link #defineModulesWithManyLoaders defineModulesWithManyLoaders} methods
* provide convenient ways to create a {@code Layer} where all modules are * provide convenient ways to create a module layer where all modules are
* mapped to a single class loader or where each module is mapped to its own * mapped to a single class loader or where each module is mapped to its own
* class loader. The {@link #defineModules defineModules} method is for more * class loader. The {@link #defineModules defineModules} method is for more
* advanced cases where modules are mapped to custom class loaders by means of * advanced cases where modules are mapped to custom class loaders by means of
* a function specified to the method. Each of these methods has an instance * a function specified to the method. Each of these methods has an instance
* and static variant. The instance methods create a layer with the receiver * and static variant. The instance methods create a layer with the receiver
* as the parent layer. The static methods are for more advanced cases where * as the parent layer. The static methods are for more advanced cases where
* there can be more than one parent layer or where a {@link Layer.Controller * there can be more than one parent layer or where a {@link
* Controller} is needed to control modules in the layer. </p> * ModuleLayer.Controller Controller} is needed to control modules in the layer
* </p>
* *
* <p> A Java virtual machine has at least one non-empty layer, the {@link * <p> A Java virtual machine has at least one non-empty layer, the {@link
* #boot() boot} layer, that is created when the Java virtual machine is * #boot() boot} layer, that is created when the Java virtual machine is
@ -131,13 +130,13 @@ import sun.security.util.SecurityConstants;
* <pre>{@code * <pre>{@code
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); * ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
* *
* Layer parent = Layer.boot(); * ModuleLayer parent = ModuleLayer.boot();
* *
* Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp")); * Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
* *
* ClassLoader scl = ClassLoader.getSystemClassLoader(); * ClassLoader scl = ClassLoader.getSystemClassLoader();
* *
* Layer layer = parent.defineModulesWithOneLoader(cf, scl); * ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
* *
* Class<?> c = layer.findLoader("myapp").loadClass("app.Main"); * Class<?> c = layer.findLoader("myapp").loadClass("app.Main");
* }</pre> * }</pre>
@ -147,27 +146,27 @@ import sun.security.util.SecurityConstants;
* @see Module#getLayer() * @see Module#getLayer()
*/ */
public final class Layer { public final class ModuleLayer {
// the empty Layer // the empty layer
private static final Layer EMPTY_LAYER private static final ModuleLayer EMPTY_LAYER
= new Layer(Configuration.empty(), List.of(), null); = new ModuleLayer(Configuration.empty(), List.of(), null);
// the configuration from which this Layer was created // the configuration from which this ;ayer was created
private final Configuration cf; private final Configuration cf;
// parent layers, empty in the case of the empty layer // parent layers, empty in the case of the empty layer
private final List<Layer> parents; private final List<ModuleLayer> parents;
// maps module name to jlr.Module // maps module name to jlr.Module
private final Map<String, Module> nameToModule; private final Map<String, Module> nameToModule;
/** /**
* Creates a new Layer from the modules in the given configuration. * Creates a new module layer from the modules in the given configuration.
*/ */
private Layer(Configuration cf, private ModuleLayer(Configuration cf,
List<Layer> parents, List<ModuleLayer> parents,
Function<String, ClassLoader> clf) Function<String, ClassLoader> clf)
{ {
this.cf = cf; this.cf = cf;
this.parents = parents; // no need to do defensive copy this.parents = parents; // no need to do defensive copy
@ -182,9 +181,9 @@ public final class Layer {
} }
/** /**
* Controls a layer. The static methods defined by {@link Layer} to create * Controls a module layer. The static methods defined by {@link ModuleLayer}
* module layers return a {@code Controller} that can be used to control * to create module layers return a {@code Controller} that can be used to
* modules in the layer. * control modules in the layer.
* *
* <p> Unless otherwise specified, passing a {@code null} argument to a * <p> Unless otherwise specified, passing a {@code null} argument to a
* method in this class causes a {@link NullPointerException * method in this class causes a {@link NullPointerException
@ -197,18 +196,18 @@ public final class Layer {
* @spec JPMS * @spec JPMS
*/ */
public static final class Controller { public static final class Controller {
private final Layer layer; private final ModuleLayer layer;
Controller(Layer layer) { Controller(ModuleLayer layer) {
this.layer = layer; this.layer = layer;
} }
/** /**
* Returns the layer that this object controls. * Returns the layer that this object controls.
* *
* @return the layer * @return the module layer
*/ */
public Layer layer() { public ModuleLayer layer() {
return layer; return layer;
} }
@ -235,14 +234,13 @@ public final class Layer {
* @return This controller * @return This controller
* *
* @throws IllegalArgumentException * @throws IllegalArgumentException
* If {@code source} is not in the layer * If {@code source} is not in the module layer
* *
* @see Module#addReads * @see Module#addReads
*/ */
public Controller addReads(Module source, Module target) { public Controller addReads(Module source, Module target) {
ensureInLayer(source); ensureInLayer(source);
Objects.requireNonNull(target); source.implAddReads(target);
Modules.addReads(source, target);
return this; return this;
} }
@ -261,23 +259,21 @@ public final class Layer {
* @return This controller * @return This controller
* *
* @throws IllegalArgumentException * @throws IllegalArgumentException
* If {@code source} is not in the layer or the package is not * If {@code source} is not in the module layer or the package
* in the source module * is not in the source module
* *
* @see Module#addOpens * @see Module#addOpens
*/ */
public Controller addOpens(Module source, String pn, Module target) { public Controller addOpens(Module source, String pn, Module target) {
ensureInLayer(source); ensureInLayer(source);
Objects.requireNonNull(pn); source.implAddOpens(pn, target);
Objects.requireNonNull(target);
Modules.addOpens(source, pn, target);
return this; return this;
} }
} }
/** /**
* Creates a new layer, with this layer as its parent, by defining the * Creates a new module layer, with this layer as its parent, by defining the
* modules in the given {@code Configuration} to the Java virtual machine. * modules in the given {@code Configuration} to the Java virtual machine.
* This method creates one class loader and defines all modules to that * This method creates one class loader and defines all modules to that
* class loader. The {@link ClassLoader#getParent() parent} of each class * class loader. The {@link ClassLoader#getParent() parent} of each class
@ -288,7 +284,7 @@ public final class Layer {
* parent. In other words, if this layer is {@code thisLayer} then this * parent. In other words, if this layer is {@code thisLayer} then this
* method is equivalent to invoking: * method is equivalent to invoking:
* <pre> {@code * <pre> {@code
* Layer.defineModulesWithOneLoader(cf, List.of(thisLayer), parentLoader).layer(); * ModuleLayer.defineModulesWithOneLoader(cf, List.of(thisLayer), parentLoader).layer();
* }</pre> * }</pre>
* *
* @param cf * @param cf
@ -312,14 +308,14 @@ public final class Layer {
* *
* @see #findLoader * @see #findLoader
*/ */
public Layer defineModulesWithOneLoader(Configuration cf, public ModuleLayer defineModulesWithOneLoader(Configuration cf,
ClassLoader parentLoader) { ClassLoader parentLoader) {
return defineModulesWithOneLoader(cf, List.of(this), parentLoader).layer(); return defineModulesWithOneLoader(cf, List.of(this), parentLoader).layer();
} }
/** /**
* Creates a new layer, with this layer as its parent, by defining the * Creates a new module layer, with this layer as its parent, by defining the
* modules in the given {@code Configuration} to the Java virtual machine. * modules in the given {@code Configuration} to the Java virtual machine.
* Each module is defined to its own {@link ClassLoader} created by this * Each module is defined to its own {@link ClassLoader} created by this
* method. The {@link ClassLoader#getParent() parent} of each class loader * method. The {@link ClassLoader#getParent() parent} of each class loader
@ -330,7 +326,7 @@ public final class Layer {
* parent. In other words, if this layer is {@code thisLayer} then this * parent. In other words, if this layer is {@code thisLayer} then this
* method is equivalent to invoking: * method is equivalent to invoking:
* <pre> {@code * <pre> {@code
* Layer.defineModulesWithManyLoaders(cf, List.of(thisLayer), parentLoader).layer(); * ModuleLayer.defineModulesWithManyLoaders(cf, List.of(thisLayer), parentLoader).layer();
* }</pre> * }</pre>
* *
* @param cf * @param cf
@ -354,14 +350,14 @@ public final class Layer {
* *
* @see #findLoader * @see #findLoader
*/ */
public Layer defineModulesWithManyLoaders(Configuration cf, public ModuleLayer defineModulesWithManyLoaders(Configuration cf,
ClassLoader parentLoader) { ClassLoader parentLoader) {
return defineModulesWithManyLoaders(cf, List.of(this), parentLoader).layer(); return defineModulesWithManyLoaders(cf, List.of(this), parentLoader).layer();
} }
/** /**
* Creates a new layer, with this layer as its parent, by defining the * Creates a new module layer, with this layer as its parent, by defining the
* modules in the given {@code Configuration} to the Java virtual machine. * modules in the given {@code Configuration} to the Java virtual machine.
* Each module is mapped, by name, to its class loader by means of the * Each module is mapped, by name, to its class loader by means of the
* given function. This method works exactly as specified by the static * given function. This method works exactly as specified by the static
@ -370,7 +366,7 @@ public final class Layer {
* this layer is {@code thisLayer} then this method is equivalent to * this layer is {@code thisLayer} then this method is equivalent to
* invoking: * invoking:
* <pre> {@code * <pre> {@code
* Layer.defineModules(cf, List.of(thisLayer), clf).layer(); * ModuleLayer.defineModules(cf, List.of(thisLayer), clf).layer();
* }</pre> * }</pre>
* *
* @param cf * @param cf
@ -390,13 +386,13 @@ public final class Layer {
* If {@code RuntimePermission("getClassLoader")} is denied by * If {@code RuntimePermission("getClassLoader")} is denied by
* the security manager * the security manager
*/ */
public Layer defineModules(Configuration cf, public ModuleLayer defineModules(Configuration cf,
Function<String, ClassLoader> clf) { Function<String, ClassLoader> clf) {
return defineModules(cf, List.of(this), clf).layer(); return defineModules(cf, List.of(this), clf).layer();
} }
/** /**
* Creates a new layer by defining the modules in the given {@code * Creates a new module layer by defining the modules in the given {@code
* Configuration} to the Java virtual machine. This method creates one * Configuration} to the Java virtual machine. This method creates one
* class loader and defines all modules to that class loader. * class loader and defines all modules to that class loader.
* *
@ -458,10 +454,10 @@ public final class Layer {
* @see #findLoader * @see #findLoader
*/ */
public static Controller defineModulesWithOneLoader(Configuration cf, public static Controller defineModulesWithOneLoader(Configuration cf,
List<Layer> parentLayers, List<ModuleLayer> parentLayers,
ClassLoader parentLoader) ClassLoader parentLoader)
{ {
List<Layer> parents = new ArrayList<>(parentLayers); List<ModuleLayer> parents = new ArrayList<>(parentLayers);
checkConfiguration(cf, parents); checkConfiguration(cf, parents);
checkCreateClassLoaderPermission(); checkCreateClassLoaderPermission();
@ -470,7 +466,7 @@ public final class Layer {
try { try {
Loader loader = new Loader(cf.modules(), parentLoader); Loader loader = new Loader(cf.modules(), parentLoader);
loader.initRemotePackageMap(cf, parents); loader.initRemotePackageMap(cf, parents);
Layer layer = new Layer(cf, parents, mn -> loader); ModuleLayer layer = new ModuleLayer(cf, parents, mn -> loader);
return new Controller(layer); return new Controller(layer);
} catch (IllegalArgumentException | IllegalStateException e) { } catch (IllegalArgumentException | IllegalStateException e) {
throw new LayerInstantiationException(e.getMessage()); throw new LayerInstantiationException(e.getMessage());
@ -478,7 +474,7 @@ public final class Layer {
} }
/** /**
* Creates a new layer by defining the modules in the given {@code * Creates a new module layer by defining the modules in the given {@code
* Configuration} to the Java virtual machine. Each module is defined to * Configuration} to the Java virtual machine. Each module is defined to
* its own {@link ClassLoader} created by this method. The {@link * its own {@link ClassLoader} created by this method. The {@link
* ClassLoader#getParent() parent} of each class loader is the given parent * ClassLoader#getParent() parent} of each class loader is the given parent
@ -528,10 +524,10 @@ public final class Layer {
* @see #findLoader * @see #findLoader
*/ */
public static Controller defineModulesWithManyLoaders(Configuration cf, public static Controller defineModulesWithManyLoaders(Configuration cf,
List<Layer> parentLayers, List<ModuleLayer> parentLayers,
ClassLoader parentLoader) ClassLoader parentLoader)
{ {
List<Layer> parents = new ArrayList<>(parentLayers); List<ModuleLayer> parents = new ArrayList<>(parentLayers);
checkConfiguration(cf, parents); checkConfiguration(cf, parents);
checkCreateClassLoaderPermission(); checkCreateClassLoaderPermission();
@ -539,7 +535,7 @@ public final class Layer {
LoaderPool pool = new LoaderPool(cf, parents, parentLoader); LoaderPool pool = new LoaderPool(cf, parents, parentLoader);
try { try {
Layer layer = new Layer(cf, parents, pool::loaderFor); ModuleLayer layer = new ModuleLayer(cf, parents, pool::loaderFor);
return new Controller(layer); return new Controller(layer);
} catch (IllegalArgumentException | IllegalStateException e) { } catch (IllegalArgumentException | IllegalStateException e) {
throw new LayerInstantiationException(e.getMessage()); throw new LayerInstantiationException(e.getMessage());
@ -547,7 +543,7 @@ public final class Layer {
} }
/** /**
* Creates a new layer by defining the modules in the given {@code * Creates a new module layer by defining the modules in the given {@code
* Configuration} to the Java virtual machine. The given function maps each * Configuration} to the Java virtual machine. The given function maps each
* module in the configuration, by name, to a class loader. Creating the * module in the configuration, by name, to a class loader. Creating the
* layer informs the Java virtual machine about the classes that may be * layer informs the Java virtual machine about the classes that may be
@ -562,7 +558,7 @@ public final class Layer {
* ready to load from these modules before there are any attempts to load * ready to load from these modules before there are any attempts to load
* classes or resources. </p> * classes or resources. </p>
* *
* <p> Creating a {@code Layer} can fail for the following reasons: </p> * <p> Creating a layer can fail for the following reasons: </p>
* *
* <ul> * <ul>
* *
@ -589,7 +585,7 @@ public final class Layer {
* or runtime exception then it is propagated to the caller of this method. * or runtime exception then it is propagated to the caller of this method.
* </p> * </p>
* *
* @apiNote It is implementation specific as to whether creating a Layer * @apiNote It is implementation specific as to whether creating a layer
* with this method is an atomic operation or not. Consequentially it is * with this method is an atomic operation or not. Consequentially it is
* possible for this method to fail with some modules, but not all, defined * possible for this method to fail with some modules, but not all, defined
* to the Java virtual machine. * to the Java virtual machine.
@ -613,10 +609,10 @@ public final class Layer {
* the security manager * the security manager
*/ */
public static Controller defineModules(Configuration cf, public static Controller defineModules(Configuration cf,
List<Layer> parentLayers, List<ModuleLayer> parentLayers,
Function<String, ClassLoader> clf) Function<String, ClassLoader> clf)
{ {
List<Layer> parents = new ArrayList<>(parentLayers); List<ModuleLayer> parents = new ArrayList<>(parentLayers);
checkConfiguration(cf, parents); checkConfiguration(cf, parents);
Objects.requireNonNull(clf); Objects.requireNonNull(clf);
@ -628,7 +624,7 @@ public final class Layer {
} }
try { try {
Layer layer = new Layer(cf, parents, clf); ModuleLayer layer = new ModuleLayer(cf, parents, clf);
return new Controller(layer); return new Controller(layer);
} catch (IllegalArgumentException | IllegalStateException e) { } catch (IllegalArgumentException | IllegalStateException e) {
throw new LayerInstantiationException(e.getMessage()); throw new LayerInstantiationException(e.getMessage());
@ -641,7 +637,7 @@ public final class Layer {
* the parent layers. * the parent layers.
*/ */
private static void checkConfiguration(Configuration cf, private static void checkConfiguration(Configuration cf,
List<Layer> parentLayers) List<ModuleLayer> parentLayers)
{ {
Objects.requireNonNull(cf); Objects.requireNonNull(cf);
@ -650,7 +646,7 @@ public final class Layer {
throw new IllegalArgumentException("wrong number of parents"); throw new IllegalArgumentException("wrong number of parents");
int index = 0; int index = 0;
for (Layer parent : parentLayers) { for (ModuleLayer parent : parentLayers) {
if (parent.configuration() != parentConfigurations.get(index)) { if (parent.configuration() != parentConfigurations.get(index)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Parent of configuration != configuration of this Layer"); "Parent of configuration != configuration of this Layer");
@ -727,7 +723,7 @@ public final class Layer {
* *
* @return The list of this layer's parents * @return The list of this layer's parents
*/ */
public List<Layer> parents() { public List<ModuleLayer> parents() {
return parents; return parents;
} }
@ -739,24 +735,24 @@ public final class Layer {
* @implNote For now, the assumption is that the number of elements will * @implNote For now, the assumption is that the number of elements will
* be very low and so this method does not use a specialized spliterator. * be very low and so this method does not use a specialized spliterator.
*/ */
Stream<Layer> layers() { Stream<ModuleLayer> layers() {
List<Layer> allLayers = this.allLayers; List<ModuleLayer> allLayers = this.allLayers;
if (allLayers != null) if (allLayers != null)
return allLayers.stream(); return allLayers.stream();
allLayers = new ArrayList<>(); allLayers = new ArrayList<>();
Set<Layer> visited = new HashSet<>(); Set<ModuleLayer> visited = new HashSet<>();
Deque<Layer> stack = new ArrayDeque<>(); Deque<ModuleLayer> stack = new ArrayDeque<>();
visited.add(this); visited.add(this);
stack.push(this); stack.push(this);
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
Layer layer = stack.pop(); ModuleLayer layer = stack.pop();
allLayers.add(layer); allLayers.add(layer);
// push in reverse order // push in reverse order
for (int i = layer.parents.size() - 1; i >= 0; i--) { for (int i = layer.parents.size() - 1; i >= 0; i--) {
Layer parent = layer.parents.get(i); ModuleLayer parent = layer.parents.get(i);
if (!visited.contains(parent)) { if (!visited.contains(parent)) {
visited.add(parent); visited.add(parent);
stack.push(parent); stack.push(parent);
@ -768,7 +764,7 @@ public final class Layer {
return allLayers.stream(); return allLayers.stream();
} }
private volatile List<Layer> allLayers; private volatile List<ModuleLayer> allLayers;
/** /**
* Returns the set of the modules in this layer. * Returns the set of the modules in this layer.
@ -856,9 +852,9 @@ public final class Layer {
} }
/** /**
* Returns a string describing this layer. * Returns a string describing this module layer.
* *
* @return A possibly empty string describing this layer * @return A possibly empty string describing this module layer
*/ */
@Override @Override
public String toString() { public String toString() {
@ -873,7 +869,7 @@ public final class Layer {
* *
* @return The empty layer * @return The empty layer
*/ */
public static Layer empty() { public static ModuleLayer empty() {
return EMPTY_LAYER; return EMPTY_LAYER;
} }
@ -887,11 +883,10 @@ public final class Layer {
* *
* @return The boot layer * @return The boot layer
*/ */
public static Layer boot() { public static ModuleLayer boot() {
return SharedSecrets.getJavaLangAccess().getBootLayer(); return System.bootLayer;
} }
/** /**
* Returns the ServicesCatalog for this Layer, creating it if not * Returns the ServicesCatalog for this Layer, creating it if not
* already created. * already created.
@ -922,10 +917,10 @@ public final class Layer {
*/ */
void bindToLoader(ClassLoader loader) { void bindToLoader(ClassLoader loader) {
// CLV.computeIfAbsent(loader, (cl, clv) -> new CopyOnWriteArrayList<>()) // CLV.computeIfAbsent(loader, (cl, clv) -> new CopyOnWriteArrayList<>())
List<Layer> list = CLV.get(loader); List<ModuleLayer> list = CLV.get(loader);
if (list == null) { if (list == null) {
list = new CopyOnWriteArrayList<>(); list = new CopyOnWriteArrayList<>();
List<Layer> previous = CLV.putIfAbsent(loader, list); List<ModuleLayer> previous = CLV.putIfAbsent(loader, list);
if (previous != null) list = previous; if (previous != null) list = previous;
} }
list.add(this); list.add(this);
@ -935,8 +930,8 @@ public final class Layer {
* Returns a stream of the layers that have at least one module defined to * Returns a stream of the layers that have at least one module defined to
* the given class loader. * the given class loader.
*/ */
static Stream<Layer> layers(ClassLoader loader) { static Stream<ModuleLayer> layers(ClassLoader loader) {
List<Layer> list = CLV.get(loader); List<ModuleLayer> list = CLV.get(loader);
if (list != null) { if (list != null) {
return list.stream(); return list.stream();
} else { } else {
@ -945,5 +940,5 @@ public final class Layer {
} }
// the list of layers with modules defined to a class loader // the list of layers with modules defined to a class loader
private static final ClassLoaderValue<List<Layer>> CLV = new ClassLoaderValue<>(); private static final ClassLoaderValue<List<ModuleLayer>> CLV = new ClassLoaderValue<>();
} }

View File

@ -26,7 +26,6 @@ package java.lang;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.reflect.Module;
import java.net.URI; import java.net.URI;
/** /**

View File

@ -27,7 +27,6 @@ package java.lang;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Module;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;

View File

@ -29,9 +29,7 @@ import java.lang.RuntimePermission;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Exports; import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens; import java.lang.module.ModuleDescriptor.Opens;
import java.lang.reflect.Layer;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Module;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.File; import java.io.File;
import java.io.FilePermission; import java.io.FilePermission;
@ -1441,7 +1439,7 @@ class SecurityManager {
static { static {
// Get the modules in the boot layer // Get the modules in the boot layer
Stream<Module> bootLayerModules = Layer.boot().modules().stream(); Stream<Module> bootLayerModules = ModuleLayer.boot().modules().stream();
// Filter out the modules loaded by the boot or platform loader // Filter out the modules loaded by the boot or platform loader
PrivilegedAction<Set<Module>> pa = () -> PrivilegedAction<Set<Module>> pa = () ->

View File

@ -33,8 +33,6 @@ import jdk.internal.module.ModuleReferenceImpl;
import java.lang.module.ModuleDescriptor.Version; import java.lang.module.ModuleDescriptor.Version;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@ -191,7 +189,7 @@ public final class StackTraceElement implements java.io.Serializable {
* if the module name is not available. * if the module name is not available.
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
* @see java.lang.reflect.Module#getName() * @see Module#getName()
*/ */
public String getModuleName() { public String getModuleName() {
return moduleName; return moduleName;
@ -480,7 +478,7 @@ public final class StackTraceElement implements java.io.Serializable {
if (!VM.isModuleSystemInited()) if (!VM.isModuleSystemInited())
return true; return true;
return Layer.boot() == m.getLayer() && HashedModules.contains(m); return ModuleLayer.boot() == m.getLayer() && HashedModules.contains(m);
} }
/* /*
@ -492,7 +490,7 @@ public final class StackTraceElement implements java.io.Serializable {
static Set<String> hashedModules() { static Set<String> hashedModules() {
Optional<ResolvedModule> resolvedModule = Layer.boot() Optional<ResolvedModule> resolvedModule = ModuleLayer.boot()
.configuration() .configuration()
.findModule("java.base"); .findModule("java.base");
assert resolvedModule.isPresent(); assert resolvedModule.isPresent();

View File

@ -35,33 +35,32 @@ import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Executable; import java.lang.reflect.Executable;
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.Properties;
import java.util.PropertyPermission;
import java.util.Map;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.nio.channels.Channel; import java.nio.channels.Channel;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.PropertyPermission;
import java.util.ResourceBundle;
import java.util.function.Supplier;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.Objects; import jdk.internal.module.ModuleBootstrap;
import java.util.ResourceBundle; import jdk.internal.module.ServicesCatalog;
import java.util.function.Supplier;
import sun.nio.ch.Interruptible;
import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection; import jdk.internal.reflect.Reflection;
import sun.security.util.SecurityConstants;
import sun.reflect.annotation.AnnotationType;
import jdk.internal.HotSpotIntrinsicCandidate; import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.JavaLangAccess;; import jdk.internal.misc.JavaLangAccess;;
import jdk.internal.misc.SharedSecrets;; import jdk.internal.misc.SharedSecrets;;
@ -69,8 +68,9 @@ import jdk.internal.misc.VM;
import jdk.internal.logger.LoggerFinderLoader; import jdk.internal.logger.LoggerFinderLoader;
import jdk.internal.logger.LazyLoggers; import jdk.internal.logger.LazyLoggers;
import jdk.internal.logger.LocalizedLoggerWrapper; import jdk.internal.logger.LocalizedLoggerWrapper;
import sun.reflect.annotation.AnnotationType;
import jdk.internal.module.ModuleBootstrap; import sun.nio.ch.Interruptible;
import sun.security.util.SecurityConstants;
/** /**
* The <code>System</code> class contains several useful class fields * The <code>System</code> class contains several useful class fields
@ -1160,7 +1160,7 @@ public final class System {
* @param msg the string message (or a key in the message catalog, if * @param msg the string message (or a key in the message catalog, if
* this logger is a {@link * this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, * LoggerFinder#getLocalizedLogger(java.lang.String,
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); * java.util.ResourceBundle, java.lang.Module) localized logger});
* can be {@code null}. * can be {@code null}.
* *
* @throws NullPointerException if {@code level} is {@code null}. * @throws NullPointerException if {@code level} is {@code null}.
@ -1228,7 +1228,7 @@ public final class System {
* @param msg the string message (or a key in the message catalog, if * @param msg the string message (or a key in the message catalog, if
* this logger is a {@link * this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, * LoggerFinder#getLocalizedLogger(java.lang.String,
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); * java.util.ResourceBundle, java.lang.Module) localized logger});
* can be {@code null}. * can be {@code null}.
* @param thrown a {@code Throwable} associated with the log message; * @param thrown a {@code Throwable} associated with the log message;
* can be {@code null}. * can be {@code null}.
@ -1277,7 +1277,7 @@ public final class System {
* java.text.MessageFormat} format, (or a key in the message * java.text.MessageFormat} format, (or a key in the message
* catalog, if this logger is a {@link * catalog, if this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, * LoggerFinder#getLocalizedLogger(java.lang.String,
* java.util.ResourceBundle, java.lang.reflect.Module) localized logger}); * java.util.ResourceBundle, java.lang.Module) localized logger});
* can be {@code null}. * can be {@code null}.
* @param params an optional list of parameters to the message (may be * @param params an optional list of parameters to the message (may be
* none). * none).
@ -1482,7 +1482,7 @@ public final class System {
* message localization. * message localization.
* *
* @implSpec By default, this method calls {@link * @implSpec By default, this method calls {@link
* #getLogger(java.lang.String, java.lang.reflect.Module) * #getLogger(java.lang.String, java.lang.Module)
* this.getLogger(name, module)} to obtain a logger, then wraps that * this.getLogger(name, module)} to obtain a logger, then wraps that
* logger in a {@link Logger} instance where all methods that do not * logger in a {@link Logger} instance where all methods that do not
* take a {@link ResourceBundle} as parameter are redirected to one * take a {@link ResourceBundle} as parameter are redirected to one
@ -1566,7 +1566,7 @@ public final class System {
* @implSpec * @implSpec
* Instances returned by this method route messages to loggers * Instances returned by this method route messages to loggers
* obtained by calling {@link LoggerFinder#getLogger(java.lang.String, * obtained by calling {@link LoggerFinder#getLogger(java.lang.String,
* java.lang.reflect.Module) LoggerFinder.getLogger(name, module)}, where * java.lang.Module) LoggerFinder.getLogger(name, module)}, where
* {@code module} is the caller's module. * {@code module} is the caller's module.
* In cases where {@code System.getLogger} is called from a context where * In cases where {@code System.getLogger} is called from a context where
* there is no caller frame on the stack (e.g when called directly * there is no caller frame on the stack (e.g when called directly
@ -1579,7 +1579,7 @@ public final class System {
* *
* @apiNote * @apiNote
* This method may defer calling the {@link * This method may defer calling the {@link
* LoggerFinder#getLogger(java.lang.String, java.lang.reflect.Module) * LoggerFinder#getLogger(java.lang.String, java.lang.Module)
* LoggerFinder.getLogger} method to create an actual logger supplied by * LoggerFinder.getLogger} method to create an actual logger supplied by
* the logging backend, for instance, to allow loggers to be obtained during * the logging backend, for instance, to allow loggers to be obtained during
* the system initialization time. * the system initialization time.
@ -1612,7 +1612,7 @@ public final class System {
* @implSpec * @implSpec
* The returned logger will perform message localization as specified * The returned logger will perform message localization as specified
* by {@link LoggerFinder#getLocalizedLogger(java.lang.String, * by {@link LoggerFinder#getLocalizedLogger(java.lang.String,
* java.util.ResourceBundle, java.lang.reflect.Module) * java.util.ResourceBundle, java.lang.Module)
* LoggerFinder.getLocalizedLogger(name, bundle, module)}, where * LoggerFinder.getLocalizedLogger(name, bundle, module)}, where
* {@code module} is the caller's module. * {@code module} is the caller's module.
* In cases where {@code System.getLogger} is called from a context where * In cases where {@code System.getLogger} is called from a context where
@ -1977,7 +1977,7 @@ public final class System {
} }
// @see #initPhase2() // @see #initPhase2()
private static Layer bootLayer; static ModuleLayer bootLayer;
/* /*
* Invoked by VM. Phase 2 module system initialization. * Invoked by VM. Phase 2 module system initialization.
@ -2100,9 +2100,6 @@ public final class System {
public void invokeFinalize(Object o) throws Throwable { public void invokeFinalize(Object o) throws Throwable {
o.finalize(); o.finalize();
} }
public Layer getBootLayer() {
return bootLayer;
}
public ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap(ClassLoader cl) { public ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap(ClassLoader cl) {
return cl.createOrGetClassLoaderValueMap(); return cl.createOrGetClassLoaderValueMap();
} }
@ -2127,6 +2124,44 @@ public final class System {
public void invalidatePackageAccessCache() { public void invalidatePackageAccessCache() {
SecurityManager.invalidatePackageAccessCache(); SecurityManager.invalidatePackageAccessCache();
} }
public Module defineModule(ClassLoader loader,
ModuleDescriptor descriptor,
URI uri) {
return new Module(null, loader, descriptor, uri);
}
public Module defineUnnamedModule(ClassLoader loader) {
return new Module(loader);
}
public void addReads(Module m1, Module m2) {
m1.implAddReads(m2);
}
public void addReadsAllUnnamed(Module m) {
m.implAddReadsAllUnnamed();
}
public void addExports(Module m, String pn, Module other) {
m.implAddExports(pn, other);
}
public void addExportsToAllUnnamed(Module m, String pn) {
m.implAddExportsToAllUnnamed(pn);
}
public void addOpens(Module m, String pn, Module other) {
m.implAddOpens(pn, other);
}
public void addOpensToAllUnnamed(Module m, String pn) {
m.implAddOpensToAllUnnamed(pn);
}
public void addUses(Module m, Class<?> service) {
m.implAddUses(service);
}
public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
return layer.getServicesCatalog();
}
public Stream<ModuleLayer> layers(ModuleLayer layer) {
return layer.layers();
}
public Stream<ModuleLayer> layers(ClassLoader loader) {
return ModuleLayer.layers(loader);
}
}); });
} }
} }

View File

@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package java.lang.reflect; package java.lang;
import java.lang.ref.Reference; import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;

View File

@ -33,7 +33,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;

View File

@ -43,7 +43,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.lang.reflect.ReflectPermission; import java.lang.reflect.ReflectPermission;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.security.AccessController; import java.security.AccessController;
@ -668,11 +667,11 @@ public class MethodHandles {
* The value is {@code 0x20}, which does not correspond meaningfully to * The value is {@code 0x20}, which does not correspond meaningfully to
* any particular {@linkplain java.lang.reflect.Modifier modifier bit}. * any particular {@linkplain java.lang.reflect.Modifier modifier bit}.
* A {@code Lookup} with this lookup mode assumes {@linkplain * A {@code Lookup} with this lookup mode assumes {@linkplain
* java.lang.reflect.Module#canRead(java.lang.reflect.Module) readability}. * java.lang.Module#canRead(java.lang.Module) readability}.
* In conjunction with the {@code PUBLIC} modifier bit, a {@code Lookup} * In conjunction with the {@code PUBLIC} modifier bit, a {@code Lookup}
* with this lookup mode can access all public members of public types * with this lookup mode can access all public members of public types
* of all modules where the type is in a package that is {@link * of all modules where the type is in a package that is {@link
* java.lang.reflect.Module#isExported(String) exported unconditionally}. * java.lang.Module#isExported(String) exported unconditionally}.
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
* @see #publicLookup() * @see #publicLookup()

View File

@ -64,11 +64,11 @@ import java.util.stream.Stream;
* with the receiver as the parent configuration. The static methods are for * with the receiver as the parent configuration. The static methods are for
* more advanced cases where there can be more than one parent configuration. </p> * more advanced cases where there can be more than one parent configuration. </p>
* *
* <p> Each {@link java.lang.reflect.Layer layer} of modules in the Java virtual * <p> Each {@link java.lang.ModuleLayer layer} of modules in the Java virtual
* machine is created from a configuration. The configuration for the {@link * machine is created from a configuration. The configuration for the {@link
* java.lang.reflect.Layer#boot() boot} layer is obtained by invoking {@code * java.lang.ModuleLayer#boot() boot} layer is obtained by invoking {@code
* Layer.boot().configuration()}. The configuration for the boot layer will * ModuleLayer.boot().configuration()}. The configuration for the boot layer
* often be the parent when creating new configurations. </p> * will often be the parent when creating new configurations. </p>
* *
* <h3> Example </h3> * <h3> Example </h3>
* *
@ -81,7 +81,7 @@ import java.util.stream.Stream;
* <pre>{@code * <pre>{@code
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); * ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
* *
* Configuration parent = Layer.boot().configuration(); * Configuration parent = ModuleLayer.boot().configuration();
* *
* Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp")); * Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
* cf.modules().forEach(m -> { * cf.modules().forEach(m -> {
@ -95,7 +95,7 @@ import java.util.stream.Stream;
* *
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
* @see java.lang.reflect.Layer * @see java.lang.ModuleLayer
*/ */
public final class Configuration { public final class Configuration {

View File

@ -60,7 +60,7 @@ import jdk.internal.module.ModuleInfo;
* <p> A module descriptor describes a named module and defines methods to * <p> A module descriptor describes a named module and defines methods to
* obtain each of its components. The module descriptor for a named module * obtain each of its components. The module descriptor for a named module
* in the Java virtual machine is obtained by invoking the {@link * in the Java virtual machine is obtained by invoking the {@link
* java.lang.reflect.Module Module}'s {@link java.lang.reflect.Module#getDescriptor * java.lang.Module Module}'s {@link java.lang.Module#getDescriptor
* getDescriptor} method. Module descriptors can also be created using the * getDescriptor} method. Module descriptors can also be created using the
* {@link ModuleDescriptor.Builder} class or by reading the binary form of a * {@link ModuleDescriptor.Builder} class or by reading the binary form of a
* module declaration ({@code module-info.class}) using the {@link * module declaration ({@code module-info.class}) using the {@link
@ -85,7 +85,7 @@ import jdk.internal.module.ModuleInfo;
* <p> {@code ModuleDescriptor} objects are immutable and safe for use by * <p> {@code ModuleDescriptor} objects are immutable and safe for use by
* multiple concurrent threads.</p> * multiple concurrent threads.</p>
* *
* @see java.lang.reflect.Module * @see java.lang.Module
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
*/ */
@ -2110,7 +2110,9 @@ public class ModuleDescriptor
/** /**
* Sets the module main class. The package for the main class is added * Sets the module main class. The package for the main class is added
* to the module if not already added. * to the module if not already added. In other words, this method is
* equivalent to first invoking this builder's {@link #packages(Set)
* packages} method to add the package name of the main class.
* *
* @param mc * @param mc
* The module main class * The module main class
@ -2134,8 +2136,8 @@ public class ModuleDescriptor
throw new IllegalArgumentException(mc + ": unnamed package"); throw new IllegalArgumentException(mc + ": unnamed package");
} }
} }
mainClass = mc;
packages.add(pn); packages.add(pn);
mainClass = mc;
return this; return this;
} }

View File

@ -228,14 +228,14 @@ public interface ModuleFinder {
* directory is treated as an exploded module rather than a directory of * directory is treated as an exploded module rather than a directory of
* modules. </p> * modules. </p>
* *
* <p> The module finder returned by this method supports modules that are * <p id="automatic-modules"> The module finder returned by this method
* packaged as JAR files. A JAR file with a {@code module-info.class} in * supports modules packaged as JAR files. A JAR file with a {@code
* the top-level directory of the JAR file (or overridden by a versioned * module-info.class} in its top-level directory, or in a versioned entry
* entry in a {@link java.util.jar.JarFile#isMultiRelease() multi-release} * in a {@linkplain java.util.jar.JarFile#isMultiRelease() multi-release}
* JAR file) is a modular JAR and is an <em>explicit module</em>. * JAR file, is a modular JAR file and thus defines an <em>explicit</em>
* A JAR file that does not have a {@code module-info.class} in the * module. A JAR file that does not have a {@code module-info.class} in its
* top-level directory is created as an automatic module. The components * top-level directory defines an <em>automatic module</em>, as follows:
* for the automatic module are derived as follows: * </p>
* *
* <ul> * <ul>
* *
@ -254,16 +254,16 @@ public interface ModuleFinder {
* ModuleDescriptor.Version} and ignored if it cannot be parsed as * ModuleDescriptor.Version} and ignored if it cannot be parsed as
* a {@code Version}. </p></li> * a {@code Version}. </p></li>
* *
* <li><p> For the module name, then any trailing digits and dots * <li><p> All non-alphanumeric characters ({@code [^A-Za-z0-9]})
* are removed, all non-alphanumeric characters ({@code [^A-Za-z0-9]}) * in the module name are replaced with a dot ({@code "."}), all
* are replaced with a dot ({@code "."}), all repeating dots are * repeating dots are replaced with one dot, and all leading and
* replaced with one dot, and all leading and trailing dots are * trailing dots are removed. </p></li>
* removed. </p></li>
* *
* <li><p> As an example, a JAR file named {@code foo-bar.jar} will * <li><p> As an example, a JAR file named {@code foo-bar.jar} will
* derive a module name {@code foo.bar} and no version. A JAR file * derive a module name {@code foo.bar} and no version. A JAR file
* named {@code foo-1.2.3-SNAPSHOT.jar} will derive a module name * named {@code foo-bar-1.2.3-SNAPSHOT.jar} will derive a module
* {@code foo} and {@code 1.2.3-SNAPSHOT} as the version. </p></li> * name {@code foo.bar} and {@code 1.2.3-SNAPSHOT} as the version.
* </p></li>
* *
* </ul></li> * </ul></li>
* *
@ -312,7 +312,9 @@ public interface ModuleFinder {
* *
* <p> As with automatic modules, the contents of a packaged or exploded * <p> As with automatic modules, the contents of a packaged or exploded
* module may need to be <em>scanned</em> in order to determine the packages * module may need to be <em>scanned</em> in order to determine the packages
* in the module. If a {@code .class} file (other than {@code * in the module. Whether {@linkplain java.nio.file.Files#isHidden(Path)
* hidden files} are ignored or not is implementation specific and therefore
* not specified. If a {@code .class} file (other than {@code
* module-info.class}) is found in the top-level directory then it is * module-info.class}) is found in the top-level directory then it is
* assumed to be a class in the unnamed package and so {@code FindException} * assumed to be a class in the unnamed package and so {@code FindException}
* is thrown. </p> * is thrown. </p>

View File

@ -28,7 +28,6 @@ package java.lang.module;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.module.ModuleDescriptor.Provides; import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires.Modifier; import java.lang.module.ModuleDescriptor.Requires.Modifier;
import java.lang.reflect.Layer;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -67,6 +66,9 @@ final class Resolver {
// maps module name to module reference // maps module name to module reference
private final Map<String, ModuleReference> nameToReference = new HashMap<>(); private final Map<String, ModuleReference> nameToReference = new HashMap<>();
// true if all automatic modules have been found
private boolean haveAllAutomaticModules;
// module constraints on target platform // module constraints on target platform
private String osName; private String osName;
private String osArch; private String osArch;
@ -171,6 +173,21 @@ final class Resolver {
ModuleDescriptor descriptor = q.poll(); ModuleDescriptor descriptor = q.poll();
assert nameToReference.containsKey(descriptor.name()); assert nameToReference.containsKey(descriptor.name());
// if the module is an automatic module then all automatic
// modules need to be resolved
if (descriptor.isAutomatic() && !haveAllAutomaticModules) {
addFoundAutomaticModules().forEach(mref -> {
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));
}
});
haveAllAutomaticModules = true;
}
// process dependences // process dependences
for (ModuleDescriptor.Requires requires : descriptor.requires()) { for (ModuleDescriptor.Requires requires : descriptor.requires()) {
@ -199,10 +216,15 @@ final class Resolver {
if (!nameToReference.containsKey(dn)) { if (!nameToReference.containsKey(dn)) {
addFoundModule(mref); addFoundModule(mref);
q.offer(mref.descriptor()); q.offer(mref.descriptor());
resolved.add(mref.descriptor());
if (isTracing()) { if (isTracing()) {
trace("Module %s located, required by %s", String prefix;
if (mref.descriptor().isAutomatic()) {
prefix = "Automatic module";
} else {
prefix = "Module";
}
trace(prefix + " %s located, required by %s",
dn, descriptor.name()); dn, descriptor.name());
mref.location().ifPresent(uri -> trace(" (%s)", uri)); mref.location().ifPresent(uri -> trace(" (%s)", uri));
} }
@ -250,7 +272,7 @@ final class Resolver {
// the initial set of modules that may use services // the initial set of modules that may use services
Set<ModuleDescriptor> initialConsumers; Set<ModuleDescriptor> initialConsumers;
if (Layer.boot() == null) { if (ModuleLayer.boot() == null) {
initialConsumers = new HashSet<>(); initialConsumers = new HashSet<>();
} else { } else {
initialConsumers = parents.stream() initialConsumers = parents.stream()
@ -301,6 +323,21 @@ final class Resolver {
return this; return this;
} }
/**
* Add all automatic modules that have not already been found to the
* nameToReference map.
*/
private Set<ModuleReference> addFoundAutomaticModules() {
Set<ModuleReference> result = new HashSet<>();
findAll().forEach(mref -> {
String mn = mref.descriptor().name();
if (mref.descriptor().isAutomatic() && !nameToReference.containsKey(mn)) {
addFoundModule(mref);
result.add(mref);
}
});
return result;
}
/** /**
* Add the module to the nameToReference map. Also check any constraints on * Add the module to the nameToReference map. Also check any constraints on
@ -534,7 +571,7 @@ final class Resolver {
// need "requires transitive" from the modules in parent configurations // need "requires transitive" from the modules in parent configurations
// as there may be selected modules that have a dependency on modules in // as there may be selected modules that have a dependency on modules in
// the parent configuration. // the parent configuration.
if (Layer.boot() == null) { if (ModuleLayer.boot() == null) {
g2 = new HashMap<>(capacity); g2 = new HashMap<>(capacity);
} else { } else {
g2 = parents.stream() g2 = parents.stream()

View File

@ -70,7 +70,7 @@
* } </pre> * } </pre>
* *
* <p> If module {@code m1} is resolved with the configuration for the {@link * <p> If module {@code m1} is resolved with the configuration for the {@link
* java.lang.reflect.Layer#boot() boot} layer as the parent then the resulting * java.lang.ModuleLayer#boot() boot} layer as the parent then the resulting
* configuration contains two modules ({@code m1}, {@code m2}). The edges in * configuration contains two modules ({@code m1}, {@code m2}). The edges in
* its readability graph are: * its readability graph are:
* <pre> {@code * <pre> {@code
@ -92,10 +92,10 @@
* *
* <p> {@link java.lang.module.ModuleDescriptor#isAutomatic() Automatic} modules * <p> {@link java.lang.module.ModuleDescriptor#isAutomatic() Automatic} modules
* receive special treatment during resolution. Each automatic module is resolved * receive special treatment during resolution. Each automatic module is resolved
* so that it reads all other modules in the configuration and all parent * as if it "{@code requires transitive}" all observable automatic modules and
* configurations. Each automatic module is also resolved as if it * all automatic modules in the parent configurations. Each automatic module is
* "{@code requires transitive}" all other automatic modules in the configuration * resolved so that it reads all other modules in the resulting configuration and
* (and all automatic modules in parent configurations). </p> * all modules in parent configurations. </p>
* *
* <h2><a name="servicebinding">Service binding</a></h2> * <h2><a name="servicebinding">Service binding</a></h2>
* *

View File

@ -227,11 +227,11 @@ import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC;
* {@code Proxy.newProxyInstance} method should be used instead. * {@code Proxy.newProxyInstance} method should be used instead.
* *
* <p> * <p>
* A dynamic module can read the modules of all of the superinterfaces of a proxy class * A dynamic module can read the modules of all of the superinterfaces of a proxy
* and the modules of the types referenced by all public method signatures * class and the modules of the types referenced by all public method signatures
* of a proxy class. If a superinterface or a referenced type, say {@code T}, * of a proxy class. If a superinterface or a referenced type, say {@code T},
* is in a non-exported package, the {@linkplain java.lang.reflect.Module module} * is in a non-exported package, the {@linkplain Module module} of {@code T} is
* of {@code T} is updated to export the package of {@code T} to the dynamic module. * updated to export the package of {@code T} to the dynamic module.
* *
* <h3>Methods Duplicated in Multiple Proxy Interfaces</h3> * <h3>Methods Duplicated in Multiple Proxy Interfaces</h3>
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,10 @@
/** /**
* Provides classes and interfaces for obtaining reflective information about * Provides classes and interfaces for obtaining reflective information about
* modules, classes and objects. Reflection allows programmatic access to * classes and objects. Reflection allows programmatic access to information
* information about modules and to the fields, methods and constructors of * about the fields, methods and constructors of loaded classes, and the use
* loaded classes, and the use of reflected fields, methods, and constructors * of reflected fields, methods, and constructors to operate on their underlying
* to operate on their underlying counterparts, within encapsulation and * counterparts, within encapsulation and security restrictions.
* security restrictions.
* *
* <p>{@code AccessibleObject} allows suppression of access checks if * <p>{@code AccessibleObject} allows suppression of access checks if
* the necessary {@code ReflectPermission} is available. * the necessary {@code ReflectPermission} is available.

View File

@ -50,7 +50,6 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.net.JarURLConnection; import java.net.JarURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;

View File

@ -31,10 +31,8 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.security.AccessControlContext; import java.security.AccessControlContext;
@ -50,7 +48,6 @@ import java.util.stream.StreamSupport;
import jdk.internal.loader.BootLoader; import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders; import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.JavaLangAccess; import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.JavaLangReflectModuleAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.VM; import jdk.internal.misc.VM;
import jdk.internal.module.ServicesCatalog; import jdk.internal.module.ServicesCatalog;
@ -160,7 +157,7 @@ import jdk.internal.reflect.Reflection;
* <h2> Locating providers </h2> * <h2> Locating providers </h2>
* *
* <p> The {@code load} methods locate providers using a class loader or module * <p> The {@code load} methods locate providers using a class loader or module
* {@link Layer layer}. When locating providers using a class loader then * {@link ModuleLayer layer}. When locating providers using a class loader then
* providers in both named and unnamed modules may be located. When locating * providers in both named and unnamed modules may be located. When locating
* providers using a module layer then only providers in named modules in * providers using a module layer then only providers in named modules in
* the layer (or parent layers) are located. * the layer (or parent layers) are located.
@ -168,11 +165,11 @@ import jdk.internal.reflect.Reflection;
* <p> When locating providers using a class loader then any providers in named * <p> When locating providers using a class loader then any providers in named
* modules defined to the class loader, or any class loader that is reachable * modules defined to the class loader, or any class loader that is reachable
* via parent delegation, are located. Additionally, providers in module layers * via parent delegation, are located. Additionally, providers in module layers
* other than the {@link Layer#boot() boot} layer, where the module layer * other than the {@link ModuleLayer#boot() boot} layer, where the module layer
* contains modules defined to the class loader, or any class loader reachable * contains modules defined to the class loader, or any class loader reachable
* via parent delegation, are also located. For example, suppose there is a * via parent delegation, are also located. For example, suppose there is a
* module layer where each module is defined to its own class loader (see {@link * module layer where each module is defined to its own class loader (see {@link
* Layer#defineModulesWithManyLoaders defineModulesWithManyLoaders}). If the * ModuleLayer#defineModulesWithManyLoaders defineModulesWithManyLoaders}). If the
* {@code load} method is invoked to locate providers using any of these class * {@code load} method is invoked to locate providers using any of these class
* loaders for this layer then it will locate all of the providers in that * loaders for this layer then it will locate all of the providers in that
* layer, irrespective of their defining class loader. * layer, irrespective of their defining class loader.
@ -198,7 +195,7 @@ import jdk.internal.reflect.Reflection;
* will locate providers in modules defined to the class loader, then its * will locate providers in modules defined to the class loader, then its
* parent class loader, its parent parent, and so on to the bootstrap class * parent class loader, its parent parent, and so on to the bootstrap class
* loader. If a {@code ClassLoader}, or any class loader in the parent * loader. If a {@code ClassLoader}, or any class loader in the parent
* delegation chain, defines modules in a custom module {@link Layer} then * delegation chain, defines modules in a custom module {@link ModuleLayer} then
* all providers in that layer are located, irrespective of their class * all providers in that layer are located, irrespective of their class
* loader. The ordering of modules defined to the same class loader, or the * loader. The ordering of modules defined to the same class loader, or the
* ordering of modules in a layer, is not defined. </li> * ordering of modules in a layer, is not defined. </li>
@ -216,11 +213,11 @@ import jdk.internal.reflect.Reflection;
* method finds the service configuration files. </li> * method finds the service configuration files. </li>
* </ul> * </ul>
* *
* <p> Service loaders created to locate providers in a module {@link Layer} * <p> Service loaders created to locate providers in a {@linkplain ModuleLayer
* will first locate providers in the layer, before locating providers in * module layer} will first locate providers in the layer, before locating
* parent layers. Traversal of parent layers is depth-first with each layer * providers in parent layers. Traversal of parent layers is depth-first with
* visited at most once. For example, suppose L0 is the boot layer, L1 and * each layer visited at most once. For example, suppose L0 is the boot layer,
* L2 are custom layers with L0 as their parent. Now suppose that L3 is * L1 and L2 are custom layers with L0 as their parent. Now suppose that L3 is
* created with L1 and L2 as the parents (in that order). Using a service * created with L1 and L2 as the parents (in that order). Using a service
* loader to locate providers with L3 as the content will locate providers * loader to locate providers with L3 as the content will locate providers
* in the following order: L3, L1, L0, L2. The ordering of modules in a layer * in the following order: L3, L1, L0, L2. The ordering of modules in a layer
@ -352,12 +349,12 @@ public final class ServiceLoader<S>
// The class of the service type // The class of the service type
private final String serviceName; private final String serviceName;
// The module Layer used to locate providers; null when locating // The module layer used to locate providers; null when locating
// providers using a class loader // providers using a class loader
private final Layer layer; private final ModuleLayer layer;
// The class loader used to locate, load, and instantiate providers; // The class loader used to locate, load, and instantiate providers;
// null when locating provider using a module Layer // null when locating provider using a module layer
private final ClassLoader loader; private final ClassLoader loader;
// The access control context taken when the ServiceLoader is created // The access control context taken when the ServiceLoader is created
@ -376,10 +373,8 @@ public final class ServiceLoader<S>
private int reloadCount; private int reloadCount;
private static JavaLangAccess LANG_ACCESS; private static JavaLangAccess LANG_ACCESS;
private static JavaLangReflectModuleAccess JLRM_ACCESS;
static { static {
LANG_ACCESS = SharedSecrets.getJavaLangAccess(); LANG_ACCESS = SharedSecrets.getJavaLangAccess();
JLRM_ACCESS = SharedSecrets.getJavaLangReflectModuleAccess();
} }
/** /**
@ -425,13 +420,13 @@ public final class ServiceLoader<S>
/** /**
* Initializes a new instance of this class for locating service providers * Initializes a new instance of this class for locating service providers
* in a module Layer. * in a module layer.
* *
* @throws ServiceConfigurationError * @throws ServiceConfigurationError
* If {@code svc} is not accessible to {@code caller} or the caller * If {@code svc} is not accessible to {@code caller} or the caller
* module does not use the service type. * module does not use the service type.
*/ */
private ServiceLoader(Class<?> caller, Layer layer, Class<S> svc) { private ServiceLoader(Class<?> caller, ModuleLayer layer, Class<S> svc) {
Objects.requireNonNull(caller); Objects.requireNonNull(caller);
Objects.requireNonNull(layer); Objects.requireNonNull(layer);
Objects.requireNonNull(svc); Objects.requireNonNull(svc);
@ -512,12 +507,15 @@ public final class ServiceLoader<S>
/** /**
* Checks that the given service type is accessible to types in the given * Checks that the given service type is accessible to types in the given
* module, and check that the module declare that it uses the service type. ?? * module, and check that the module declares that it uses the service type.
*/ */
private static void checkCaller(Class<?> caller, Class<?> svc) { private static void checkCaller(Class<?> caller, Class<?> svc) {
Module callerModule = caller.getModule(); if (caller == null) {
fail(svc, "no caller to check if it declares `uses`");
}
// Check access to the service type // Check access to the service type
Module callerModule = caller.getModule();
int mods = svc.getModifiers(); int mods = svc.getModifiers();
if (!Reflection.verifyMemberAccess(caller, svc, null, mods)) { if (!Reflection.verifyMemberAccess(caller, svc, null, mods)) {
fail(svc, "service type not accessible to " + callerModule); fail(svc, "service type not accessible to " + callerModule);
@ -826,13 +824,13 @@ public final class ServiceLoader<S>
/** /**
* Implements lazy service provider lookup of service providers that * Implements lazy service provider lookup of service providers that
* are provided by modules in a module Layer (or parent layers) * are provided by modules in a module layer (or parent layers)
*/ */
private final class LayerLookupIterator<T> private final class LayerLookupIterator<T>
implements Iterator<Provider<T>> implements Iterator<Provider<T>>
{ {
Deque<Layer> stack = new ArrayDeque<>(); Deque<ModuleLayer> stack = new ArrayDeque<>();
Set<Layer> visited = new HashSet<>(); Set<ModuleLayer> visited = new HashSet<>();
Iterator<ServiceProvider> iterator; Iterator<ServiceProvider> iterator;
ServiceProvider next; // next provider to load ServiceProvider next; // next provider to load
@ -841,8 +839,8 @@ public final class ServiceLoader<S>
stack.push(layer); stack.push(layer);
} }
private Iterator<ServiceProvider> providers(Layer layer) { private Iterator<ServiceProvider> providers(ModuleLayer layer) {
ServicesCatalog catalog = JLRM_ACCESS.getServicesCatalog(layer); ServicesCatalog catalog = LANG_ACCESS.getServicesCatalog(layer);
return catalog.findServices(serviceName).iterator(); return catalog.findServices(serviceName).iterator();
} }
@ -864,10 +862,10 @@ public final class ServiceLoader<S>
if (stack.isEmpty()) if (stack.isEmpty())
return false; return false;
Layer layer = stack.pop(); ModuleLayer layer = stack.pop();
List<Layer> parents = layer.parents(); List<ModuleLayer> parents = layer.parents();
for (int i = parents.size() - 1; i >= 0; i--) { for (int i = parents.size() - 1; i >= 0; i--) {
Layer parent = parents.get(i); ModuleLayer parent = parents.get(i);
if (!visited.contains(parent)) { if (!visited.contains(parent)) {
visited.add(parent); visited.add(parent);
stack.push(parent); stack.push(parent);
@ -915,8 +913,8 @@ public final class ServiceLoader<S>
* Returns iterator to iterate over the implementations of {@code * Returns iterator to iterate over the implementations of {@code
* service} in the given layer. * service} in the given layer.
*/ */
private List<ServiceProvider> providers(Layer layer) { private List<ServiceProvider> providers(ModuleLayer layer) {
ServicesCatalog catalog = JLRM_ACCESS.getServicesCatalog(layer); ServicesCatalog catalog = LANG_ACCESS.getServicesCatalog(layer);
return catalog.findServices(serviceName); return catalog.findServices(serviceName);
} }
@ -946,10 +944,10 @@ public final class ServiceLoader<S>
return providers.iterator(); return providers.iterator();
} else { } else {
List<ServiceProvider> allProviders = new ArrayList<>(providers); List<ServiceProvider> allProviders = new ArrayList<>(providers);
Layer bootLayer = Layer.boot(); ModuleLayer bootLayer = ModuleLayer.boot();
Iterator<Layer> iterator = JLRM_ACCESS.layers(loader).iterator(); Iterator<ModuleLayer> iterator = LANG_ACCESS.layers(loader).iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Layer layer = iterator.next(); ModuleLayer layer = iterator.next();
if (layer != bootLayer) { if (layer != bootLayer) {
allProviders.addAll(providers(layer)); allProviders.addAll(providers(layer));
} }
@ -1535,7 +1533,7 @@ public final class ServiceLoader<S>
/** /**
* Creates a new service loader for the given service type that loads * Creates a new service loader for the given service type that loads
* service providers from modules in the given {@code Layer} and its * service providers from modules in the given {@code ModuleLayer} and its
* ancestors. * ancestors.
* *
* @apiNote Unlike the other load methods defined here, the service type * @apiNote Unlike the other load methods defined here, the service type
@ -1545,7 +1543,7 @@ public final class ServiceLoader<S>
* @param <S> the class of the service type * @param <S> the class of the service type
* *
* @param layer * @param layer
* The module Layer * The module layer
* *
* @param service * @param service
* The interface or abstract class representing the service * The interface or abstract class representing the service
@ -1561,7 +1559,7 @@ public final class ServiceLoader<S>
* @spec JPMS * @spec JPMS
*/ */
@CallerSensitive @CallerSensitive
public static <S> ServiceLoader<S> load(Layer layer, Class<S> service) { public static <S> ServiceLoader<S> load(ModuleLayer layer, Class<S> service) {
return new ServiceLoader<>(Reflection.getCallerClass(), layer, service); return new ServiceLoader<>(Reflection.getCallerClass(), layer, service);
} }

View File

@ -31,7 +31,6 @@ import jdk.internal.misc.SharedSecrets;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Locale; import java.util.Locale;

View File

@ -25,7 +25,6 @@
package javax.crypto; package javax.crypto;
import java.lang.reflect.Module;
import java.security.*; import java.security.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;

View File

@ -27,8 +27,6 @@ package jdk.internal.loader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -62,8 +60,7 @@ public class BootLoader {
private static final String JAVA_HOME = System.getProperty("java.home"); private static final String JAVA_HOME = System.getProperty("java.home");
static { static {
UNNAMED_MODULE UNNAMED_MODULE = SharedSecrets.getJavaLangAccess().defineUnnamedModule(null);
= SharedSecrets.getJavaLangReflectModuleAccess().defineUnnamedModule(null);
setBootLoaderUnnamedModule0(UNNAMED_MODULE); setBootLoaderUnnamedModule0(UNNAMED_MODULE);
} }
@ -255,7 +252,7 @@ public class BootLoader {
if (mn != null) { if (mn != null) {
// named module from runtime image or exploded module // named module from runtime image or exploded module
Optional<Module> om = Layer.boot().findModule(mn); Optional<Module> om = ModuleLayer.boot().findModule(mn);
if (!om.isPresent()) if (!om.isPresent())
throw new InternalError(mn + " not in boot layer"); throw new InternalError(mn + " not in boot layer");
return om.get(); return om.get();

View File

@ -27,7 +27,6 @@ package jdk.internal.loader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Paths; import java.nio.file.Paths;

View File

@ -33,7 +33,6 @@ import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleReader; import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -80,8 +79,8 @@ import jdk.internal.module.Resources;
* loader. This allows automatic modules (for example) to link to types in the * loader. This allows automatic modules (for example) to link to types in the
* unnamed module of the parent class loader. * unnamed module of the parent class loader.
* *
* @see Layer#defineModulesWithOneLoader * @see ModuleModuleLayer#defineModulesWithOneLoader
* @see Layer#defineModulesWithManyLoaders * @see ModuleModuleLayer#defineModulesWithManyLoaders
*/ */
public final class Loader extends SecureClassLoader { public final class Loader extends SecureClassLoader {
@ -207,10 +206,10 @@ public final class Loader extends SecureClassLoader {
* @param cf the Configuration containing at least modules to be defined to * @param cf the Configuration containing at least modules to be defined to
* this class loader * this class loader
* *
* @param parentLayers the parent Layers * @param parentModuleLayers the parent ModuleLayers
*/ */
public Loader initRemotePackageMap(Configuration cf, public Loader initRemotePackageMap(Configuration cf,
List<Layer> parentLayers) List<ModuleLayer> parentModuleLayers)
{ {
for (String name : nameToModule.keySet()) { for (String name : nameToModule.keySet()) {
ResolvedModule resolvedModule = cf.findModule(name).get(); ResolvedModule resolvedModule = cf.findModule(name).get();
@ -236,8 +235,8 @@ public final class Loader extends SecureClassLoader {
} else { } else {
// find the layer for the target module // find the layer for the target module
Layer layer = parentLayers.stream() ModuleLayer layer = parentModuleLayers.stream()
.map(parent -> findLayer(parent, other.configuration())) .map(parent -> findModuleLayer(parent, other.configuration()))
.flatMap(Optional::stream) .flatMap(Optional::stream)
.findAny() .findAny()
.orElseThrow(() -> .orElseThrow(() ->
@ -286,8 +285,8 @@ public final class Loader extends SecureClassLoader {
* Find the layer corresponding to the given configuration in the tree * Find the layer corresponding to the given configuration in the tree
* of layers rooted at the given parent. * of layers rooted at the given parent.
*/ */
private Optional<Layer> findLayer(Layer parent, Configuration cf) { private Optional<ModuleLayer> findModuleLayer(ModuleLayer parent, Configuration cf) {
return SharedSecrets.getJavaLangReflectModuleAccess().layers(parent) return SharedSecrets.getJavaLangAccess().layers(parent)
.filter(l -> l.configuration() == cf) .filter(l -> l.configuration() == cf)
.findAny(); .findAny();
} }

View File

@ -27,7 +27,6 @@ package jdk.internal.loader;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -36,7 +35,7 @@ import java.util.stream.Stream;
/** /**
* A pool of class loaders. * A pool of class loaders.
* *
* @see Layer#defineModulesWithManyLoaders * @see ModuleLayer#defineModulesWithManyLoaders
*/ */
public final class LoaderPool { public final class LoaderPool {
@ -51,7 +50,7 @@ public final class LoaderPool {
* created with the given parent class loader as its parent. * created with the given parent class loader as its parent.
*/ */
public LoaderPool(Configuration cf, public LoaderPool(Configuration cf,
List<Layer> parentLayers, List<ModuleLayer> parentLayers,
ClassLoader parentLoader) ClassLoader parentLoader)
{ {
Map<String, Loader> loaders = new HashMap<>(); Map<String, Loader> loaders = new HashMap<>();

View File

@ -34,7 +34,6 @@ import java.util.Objects;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Collection; import java.util.Collection;

View File

@ -31,7 +31,6 @@ import java.util.function.BiFunction;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Module;
import java.util.Objects; import java.util.Objects;
import jdk.internal.misc.VM; import jdk.internal.misc.VM;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -402,10 +401,10 @@ public final class LazyLoggers {
* @param module The module on behalf of which the logger is created. * @param module The module on behalf of which the logger is created.
* If the module is not loaded from the Boot ClassLoader, * If the module is not loaded from the Boot ClassLoader,
* the LoggerFinder is accessed and the logger returned * the LoggerFinder is accessed and the logger returned
* by {@link LoggerFinder#getLogger(java.lang.String, java.lang.reflect.Module)} * by {@link LoggerFinder#getLogger(java.lang.String, java.lang.Module)}
* is returned to the caller directly. * is returned to the caller directly.
* Otherwise, the logger returned by * Otherwise, the logger returned by
* {@link #getLazyLogger(java.lang.String, java.lang.reflect.Module)} * {@link #getLazyLogger(java.lang.String, java.lang.Module)}
* is returned to the caller. * is returned to the caller.
* *
* @return a (possibly lazy) Logger instance. * @return a (possibly lazy) Logger instance.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,10 +27,10 @@ package jdk.internal.misc;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Executable; import java.lang.reflect.Executable;
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
@ -38,6 +38,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.internal.module.ServicesCatalog;
import jdk.internal.reflect.ConstantPool; import jdk.internal.reflect.ConstantPool;
import sun.reflect.annotation.AnnotationType; import sun.reflect.annotation.AnnotationType;
import sun.nio.ch.Interruptible; import sun.nio.ch.Interruptible;
@ -139,11 +140,6 @@ public interface JavaLangAccess {
*/ */
void invokeFinalize(Object o) throws Throwable; void invokeFinalize(Object o) throws Throwable;
/**
* Returns the boot Layer
*/
Layer getBootLayer();
/** /**
* Returns the ConcurrentHashMap used as a storage for ClassLoaderValue(s) * Returns the ConcurrentHashMap used as a storage for ClassLoaderValue(s)
* associated with the given class loader, creating it if it doesn't already exist. * associated with the given class loader, creating it if it doesn't already exist.
@ -185,4 +181,74 @@ public interface JavaLangAccess {
* Invalidate package access cache * Invalidate package access cache
*/ */
void invalidatePackageAccessCache(); void invalidatePackageAccessCache();
/**
* Defines a new module to the Java virtual machine. The module
* is defined to the given class loader.
*
* The URI is for information purposes only, it can be {@code null}.
*/
Module defineModule(ClassLoader loader, ModuleDescriptor descriptor, URI uri);
/**
* Defines the unnamed module for the given class loader.
*/
Module defineUnnamedModule(ClassLoader loader);
/**
* Updates the readability so that module m1 reads m2. The new read edge
* does not result in a strong reference to m2 (m2 can be GC'ed).
*
* This method is the same as m1.addReads(m2) but without a permission check.
*/
void addReads(Module m1, Module m2);
/**
* Updates module m to read all unnamed modules.
*/
void addReadsAllUnnamed(Module m);
/**
* Updates module m1 to export a package to module m2. The export does
* not result in a strong reference to m2 (m2 can be GC'ed).
*/
void addExports(Module m1, String pkg, Module m2);
/**
* Updates a module m to export a package to all unnamed modules.
*/
void addExportsToAllUnnamed(Module m, String pkg);
/**
* Updates module m1 to open a package to module m2. Opening the
* package does not result in a strong reference to m2 (m2 can be GC'ed).
*/
void addOpens(Module m1, String pkg, Module m2);
/**
* Updates a module m to open a package to all unnamed modules.
*/
void addOpensToAllUnnamed(Module m, String pkg);
/**
* Updates a module m to use a service.
*/
void addUses(Module m, Class<?> service);
/**
* Returns the ServicesCatalog for the given Layer.
*/
ServicesCatalog getServicesCatalog(ModuleLayer layer);
/**
* Returns an ordered stream of layers. The first element is is the
* given layer, the remaining elements are its parents, in DFS order.
*/
Stream<ModuleLayer> layers(ModuleLayer layer);
/**
* Returns a stream of the layers that have modules defined to the
* given class loader.
*/
Stream<ModuleLayer> layers(ClassLoader loader);
} }

View File

@ -1,121 +0,0 @@
/*
* Copyright (c) 2014, 2016, 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
* 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.
*/
package jdk.internal.misc;
import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.net.URI;
import java.util.stream.Stream;
import jdk.internal.module.ServicesCatalog;
/**
* Provides access to non-public methods in java.lang.reflect.Module
*/
public interface JavaLangReflectModuleAccess {
/**
* Defines the unnamed module for the given class loader.
*/
Module defineUnnamedModule(ClassLoader loader);
/**
* Defines a new module to the Java virtual machine. The module
* is defined to the given class loader.
*
* The URI is for information purposes only, it can be {@code null}.
*/
Module defineModule(ClassLoader loader, ModuleDescriptor descriptor, URI uri);
/**
* Updates the readability so that module m1 reads m2. The new read edge
* does not result in a strong reference to m2 (m2 can be GC'ed).
*
* This method is the same as m1.addReads(m2) but without a permission check.
*/
void addReads(Module m1, Module m2);
/**
* Updates module m to read all unnamed modules.
*/
void addReadsAllUnnamed(Module m);
/**
* Update module m to export a package to all modules.
*/
void addExports(Module m, String pn);
/**
* Updates module m1 to export a package to module m2. The export does
* not result in a strong reference to m2 (m2 can be GC'ed).
*/
void addExports(Module m1, String pkg, Module m2);
/**
* Updates a module m to export a package to all unnamed modules.
*/
void addExportsToAllUnnamed(Module m, String pkg);
/**
* Updates a module m to open a package to all modules.
*/
void addOpens(Module m, String pkg);
/**
* Updates module m1 to open a package to module m2. Opening the
* package does not result in a strong reference to m2 (m2 can be GC'ed).
*/
void addOpens(Module m1, String pkg, Module m2);
/**
* Updates a module m to open a package to all unnamed modules.
*/
void addOpensToAllUnnamed(Module m, String pkg);
/**
* Updates a module m to use a service.
*/
void addUses(Module m, Class<?> service);
/**
* Returns the ServicesCatalog for the given Layer.
*/
ServicesCatalog getServicesCatalog(Layer layer);
/**
* Returns an ordered stream of layers. The first element is is the
* given layer, the remaining elements are its parents, in DFS order.
*/
Stream<Layer> layers(Layer layer);
/**
* Returns a stream of the layers that have modules defined to the
* given class loader.
*/
Stream<Layer> layers(ClassLoader loader);
}

View File

@ -25,7 +25,6 @@
package jdk.internal.misc; package jdk.internal.misc;
import java.lang.reflect.Module;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;

View File

@ -50,7 +50,6 @@ public class SharedSecrets {
private static JavaUtilJarAccess javaUtilJarAccess; private static JavaUtilJarAccess javaUtilJarAccess;
private static JavaLangAccess javaLangAccess; private static JavaLangAccess javaLangAccess;
private static JavaLangModuleAccess javaLangModuleAccess; private static JavaLangModuleAccess javaLangModuleAccess;
private static JavaLangReflectModuleAccess javaLangReflectModuleAccess;
private static JavaLangInvokeAccess javaLangInvokeAccess; private static JavaLangInvokeAccess javaLangInvokeAccess;
private static JavaLangRefAccess javaLangRefAccess; private static JavaLangRefAccess javaLangRefAccess;
private static JavaIOAccess javaIOAccess; private static JavaIOAccess javaIOAccess;
@ -119,16 +118,6 @@ public class SharedSecrets {
return javaLangModuleAccess; return javaLangModuleAccess;
} }
public static void setJavaLangReflectModuleAccess(JavaLangReflectModuleAccess jlrma) {
javaLangReflectModuleAccess = jlrma;
}
public static JavaLangReflectModuleAccess getJavaLangReflectModuleAccess() {
if (javaLangReflectModuleAccess == null)
unsafe.ensureClassInitialized(java.lang.reflect.Module.class);
return javaLangReflectModuleAccess;
}
public static void setJavaLangRefAccess(JavaLangRefAccess jlra) { public static void setJavaLangRefAccess(JavaLangRefAccess jlra) {
javaLangRefAccess = jlra; javaLangRefAccess = jlra;
} }

View File

@ -27,7 +27,6 @@ package jdk.internal.module;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.security.AccessController; import java.security.AccessController;
import java.security.CodeSource; import java.security.CodeSource;

View File

@ -32,9 +32,6 @@ import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.lang.reflect.LayerInstantiationException;
import java.lang.reflect.Module;
import java.net.URI; import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -61,7 +58,7 @@ import jdk.internal.perf.PerfCounter;
* resolving a set of module names specified via the launcher (or equivalent) * resolving a set of module names specified via the launcher (or equivalent)
* -m and --add-modules options. The modules are located on a module path that * -m and --add-modules options. The modules are located on a module path that
* is constructed from the upgrade module path, system modules, and application * is constructed from the upgrade module path, system modules, and application
* module path. The Configuration is instantiated as the boot Layer with each * module path. The Configuration is instantiated as the boot layer with each
* module in the the configuration defined to one of the built-in class loaders. * module in the the configuration defined to one of the built-in class loaders.
*/ */
@ -106,11 +103,11 @@ public final class ModuleBootstrap {
} }
/** /**
* Initialize the module system, returning the boot Layer. * Initialize the module system, returning the boot layer.
* *
* @see java.lang.System#initPhase2() * @see java.lang.System#initPhase2()
*/ */
public static Layer boot() { public static ModuleLayer boot() {
long t0 = System.nanoTime(); long t0 = System.nanoTime();
@ -237,7 +234,6 @@ public final class ModuleBootstrap {
ModuleFinder f = finder; // observable modules ModuleFinder f = finder; // observable modules
systemModules.findAll() systemModules.findAll()
.stream() .stream()
.filter(mref -> !ModuleResolution.doNotResolveByDefault(mref))
.map(ModuleReference::descriptor) .map(ModuleReference::descriptor)
.map(ModuleDescriptor::name) .map(ModuleDescriptor::name)
.filter(mn -> f.find(mn).isPresent()) // observable .filter(mn -> f.find(mn).isPresent()) // observable
@ -321,8 +317,7 @@ public final class ModuleBootstrap {
if (SystemModules.hasSplitPackages() || needPostResolutionChecks) { if (SystemModules.hasSplitPackages() || needPostResolutionChecks) {
Map<String, String> packageToModule = new HashMap<>(); Map<String, String> packageToModule = new HashMap<>();
for (ResolvedModule resolvedModule : cf.modules()) { for (ResolvedModule resolvedModule : cf.modules()) {
ModuleDescriptor descriptor = ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
resolvedModule.reference().descriptor();
String name = descriptor.name(); String name = descriptor.name();
for (String p : descriptor.packages()) { for (String p : descriptor.packages()) {
String other = packageToModule.putIfAbsent(p, name); String other = packageToModule.putIfAbsent(p, name);
@ -338,7 +333,7 @@ public final class ModuleBootstrap {
long t4 = System.nanoTime(); long t4 = System.nanoTime();
// define modules to VM/runtime // define modules to VM/runtime
Layer bootLayer = Layer.empty().defineModules(cf, clf); ModuleLayer bootLayer = ModuleLayer.empty().defineModules(cf, clf);
PerfCounters.layerCreateTime.addElapsedTimeFrom(t4); PerfCounters.layerCreateTime.addElapsedTimeFrom(t4);
@ -476,7 +471,7 @@ public final class ModuleBootstrap {
* Process the --add-reads options to add any additional read edges that * Process the --add-reads options to add any additional read edges that
* are specified on the command-line. * are specified on the command-line.
*/ */
private static void addExtraReads(Layer bootLayer) { private static void addExtraReads(ModuleLayer bootLayer) {
// decode the command line options // decode the command line options
Map<String, List<String>> map = decode("jdk.module.addreads."); Map<String, List<String>> map = decode("jdk.module.addreads.");
@ -514,7 +509,7 @@ public final class ModuleBootstrap {
* Process the --add-exports and --add-opens options to export/open * Process the --add-exports and --add-opens options to export/open
* additional packages specified on the command-line. * additional packages specified on the command-line.
*/ */
private static void addExtraExportsAndOpens(Layer bootLayer) { private static void addExtraExportsAndOpens(ModuleLayer bootLayer) {
// --add-exports // --add-exports
String prefix = "jdk.module.addexports."; String prefix = "jdk.module.addexports.";
Map<String, List<String>> extraExports = decode(prefix); Map<String, List<String>> extraExports = decode(prefix);
@ -548,7 +543,7 @@ public final class ModuleBootstrap {
} }
} }
private static void addExtraExportsOrOpens(Layer bootLayer, private static void addExtraExportsOrOpens(ModuleLayer bootLayer,
Map<String, List<String>> map, Map<String, List<String>> map,
boolean opens) boolean opens)
{ {

View File

@ -135,8 +135,9 @@ public final class ModulePatcher {
Path top = file; Path top = file;
Files.find(top, Integer.MAX_VALUE, Files.find(top, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile())) ((path, attrs) -> attrs.isRegularFile()))
.filter(path -> !isAutomatic .filter(path -> (!isAutomatic
|| path.toString().endsWith(".class")) || path.toString().endsWith(".class"))
&& !isHidden(path))
.map(path -> toPackageName(top, path)) .map(path -> toPackageName(top, path))
.filter(Checks::isPackageName) .filter(Checks::isPackageName)
.forEach(packages::add); .forEach(packages::add);
@ -177,11 +178,13 @@ public final class ModulePatcher {
ModuleTarget target = null; ModuleTarget target = null;
ModuleHashes recordedHashes = null; ModuleHashes recordedHashes = null;
ModuleHashes.HashSupplier hasher = null;
ModuleResolution mres = null; ModuleResolution mres = null;
if (mref instanceof ModuleReferenceImpl) { if (mref instanceof ModuleReferenceImpl) {
ModuleReferenceImpl impl = (ModuleReferenceImpl)mref; ModuleReferenceImpl impl = (ModuleReferenceImpl)mref;
target = impl.moduleTarget(); target = impl.moduleTarget();
recordedHashes = impl.recordedHashes(); recordedHashes = impl.recordedHashes();
hasher = impl.hasher();
mres = impl.moduleResolution(); mres = impl.moduleResolution();
} }
@ -191,7 +194,7 @@ public final class ModulePatcher {
this, this,
target, target,
recordedHashes, recordedHashes,
null, hasher,
mres); mres);
} }
@ -556,7 +559,7 @@ public final class ModulePatcher {
/** /**
* Derives a package name from a file path to a .class file. * Derives a package name from the file path of an entry in an exploded patch
*/ */
private static String toPackageName(Path top, Path file) { private static String toPackageName(Path top, Path file) {
Path entry = top.relativize(file); Path entry = top.relativize(file);
@ -568,6 +571,17 @@ public final class ModulePatcher {
} }
} }
/**
* Returns true if the given file exists and is a hidden file
*/
private boolean isHidden(Path file) {
try {
return Files.isHidden(file);
} catch (IOException ioe) {
return false;
}
}
/** /**
* Derives a package name from the name of an entry in a JAR file. * Derives a package name from the name of an entry in a JAR file.
*/ */

View File

@ -547,7 +547,6 @@ public class ModulePath implements ModuleFinder {
*/ */
private static class Patterns { private static class Patterns {
static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))"); static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
static final Pattern TRAILING_VERSION = Pattern.compile("(\\.|\\d)*$");
static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]"); static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+"); static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
static final Pattern LEADING_DOTS = Pattern.compile("^\\."); static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
@ -558,9 +557,6 @@ public class ModulePath implements ModuleFinder {
* Clean up candidate module name derived from a JAR file name. * Clean up candidate module name derived from a JAR file name.
*/ */
private static String cleanModuleName(String mn) { private static String cleanModuleName(String mn) {
// drop trailing version from name
mn = Patterns.TRAILING_VERSION.matcher(mn).replaceAll("");
// replace non-alphanumeric // replace non-alphanumeric
mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll("."); mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
@ -630,7 +626,7 @@ public class ModulePath implements ModuleFinder {
private Set<String> explodedPackages(Path dir) { private Set<String> explodedPackages(Path dir) {
try { try {
return Files.find(dir, Integer.MAX_VALUE, return Files.find(dir, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile())) ((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
.map(path -> dir.relativize(path)) .map(path -> dir.relativize(path))
.map(this::toPackageName) .map(this::toPackageName)
.flatMap(Optional::stream) .flatMap(Optional::stream)
@ -726,6 +722,17 @@ public class ModulePath implements ModuleFinder {
} }
} }
/**
* Returns true if the given file exists and is a hidden file
*/
private boolean isHidden(Path file) {
try {
return Files.isHidden(file);
} catch (IOException ioe) {
return false;
}
}
private static final PerfCounter scanTime private static final PerfCounter scanTime
= PerfCounter.newPerfCounter("jdk.module.finder.modulepath.scanTime"); = PerfCounter.newPerfCounter("jdk.module.finder.modulepath.scanTime");
private static final PerfCounter moduleCount private static final PerfCounter moduleCount

View File

@ -26,15 +26,13 @@
package jdk.internal.module; package jdk.internal.module;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.net.URI; import java.net.URI;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import jdk.internal.loader.BootLoader; import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders; import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.JavaLangReflectModuleAccess; import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
/** /**
@ -51,8 +49,7 @@ import jdk.internal.misc.SharedSecrets;
public class Modules { public class Modules {
private Modules() { } private Modules() { }
private static final JavaLangReflectModuleAccess JLRMA private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
= SharedSecrets.getJavaLangReflectModuleAccess();
/** /**
* Creates a new Module. The module has the given ModuleDescriptor and * Creates a new Module. The module has the given ModuleDescriptor and
@ -67,7 +64,7 @@ public class Modules {
ModuleDescriptor descriptor, ModuleDescriptor descriptor,
URI uri) URI uri)
{ {
return JLRMA.defineModule(loader, descriptor, uri); return JLA.defineModule(loader, descriptor, uri);
} }
/** /**
@ -75,23 +72,14 @@ public class Modules {
* Same as m1.addReads(m2) but without a caller check. * Same as m1.addReads(m2) but without a caller check.
*/ */
public static void addReads(Module m1, Module m2) { public static void addReads(Module m1, Module m2) {
JLRMA.addReads(m1, m2); JLA.addReads(m1, m2);
} }
/** /**
* Update module m to read all unnamed modules. * Update module m to read all unnamed modules.
*/ */
public static void addReadsAllUnnamed(Module m) { public static void addReadsAllUnnamed(Module m) {
JLRMA.addReadsAllUnnamed(m); JLA.addReadsAllUnnamed(m);
}
/**
* Update module m to export a package to all modules.
*
* This method is for intended for use by tests only.
*/
public static void addExports(Module m, String pn) {
JLRMA.addExports(m, pn);
} }
/** /**
@ -99,23 +87,14 @@ public class Modules {
* Same as m1.addExports(pn, m2) but without a caller check * Same as m1.addExports(pn, m2) but without a caller check
*/ */
public static void addExports(Module m1, String pn, Module m2) { public static void addExports(Module m1, String pn, Module m2) {
JLRMA.addExports(m1, pn, m2); JLA.addExports(m1, pn, m2);
} }
/** /**
* Updates module m to export a package to all unnamed modules. * Updates module m to export a package to all unnamed modules.
*/ */
public static void addExportsToAllUnnamed(Module m, String pn) { public static void addExportsToAllUnnamed(Module m, String pn) {
JLRMA.addExportsToAllUnnamed(m, pn); JLA.addExportsToAllUnnamed(m, pn);
}
/**
* Update module m to open a package to all modules.
*
* This method is for intended for use by tests only.
*/
public static void addOpens(Module m, String pn) {
JLRMA.addOpens(m, pn);
} }
/** /**
@ -123,14 +102,14 @@ public class Modules {
* Same as m1.addOpens(pn, m2) but without a caller check. * Same as m1.addOpens(pn, m2) but without a caller check.
*/ */
public static void addOpens(Module m1, String pn, Module m2) { public static void addOpens(Module m1, String pn, Module m2) {
JLRMA.addOpens(m1, pn, m2); JLA.addOpens(m1, pn, m2);
} }
/** /**
* Updates module m to open a package to all unnamed modules. * Updates module m to open a package to all unnamed modules.
*/ */
public static void addOpensToAllUnnamed(Module m, String pn) { public static void addOpensToAllUnnamed(Module m, String pn) {
JLRMA.addOpensToAllUnnamed(m, pn); JLA.addOpensToAllUnnamed(m, pn);
} }
/** /**
@ -138,16 +117,16 @@ public class Modules {
* Same as m2.addUses(service) but without a caller check. * Same as m2.addUses(service) but without a caller check.
*/ */
public static void addUses(Module m, Class<?> service) { public static void addUses(Module m, Class<?> service) {
JLRMA.addUses(m, service); JLA.addUses(m, service);
} }
/** /**
* Updates module m to provide a service * Updates module m to provide a service
*/ */
public static void addProvides(Module m, Class<?> service, Class<?> impl) { public static void addProvides(Module m, Class<?> service, Class<?> impl) {
Layer layer = m.getLayer(); ModuleLayer layer = m.getLayer();
if (layer == null || layer == Layer.boot()) { if (layer == null || layer == ModuleLayer.boot()) {
// update ClassLoader catalog // update ClassLoader catalog
PrivilegedAction<ClassLoader> pa = m::getClassLoader; PrivilegedAction<ClassLoader> pa = m::getClassLoader;
ClassLoader loader = AccessController.doPrivileged(pa); ClassLoader loader = AccessController.doPrivileged(pa);
@ -162,9 +141,7 @@ public class Modules {
if (layer != null) { if (layer != null) {
// update Layer catalog // update Layer catalog
SharedSecrets.getJavaLangReflectModuleAccess() JLA.getServicesCatalog(layer).addProvider(m, service, impl);
.getServicesCatalog(layer)
.addProvider(m, service, impl);
} }
} }

View File

@ -25,7 +25,6 @@
package jdk.internal.module; package jdk.internal.module;
import java.lang.reflect.Module;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Provides; import java.lang.module.ModuleDescriptor.Provides;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -27,7 +27,6 @@ package sun.invoke.util;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import static java.lang.reflect.Modifier.*; import static java.lang.reflect.Modifier.*;
import java.lang.reflect.Module;
import java.util.Objects; import java.util.Objects;
import jdk.internal.reflect.Reflection; import jdk.internal.reflect.Reflection;

View File

@ -50,10 +50,8 @@ import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleDescriptor.Exports; import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens; import java.lang.module.ModuleDescriptor.Opens;
import java.lang.module.ModuleDescriptor.Provides; import java.lang.module.ModuleDescriptor.Provides;
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Module;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.net.URI; import java.net.URI;
@ -467,7 +465,7 @@ public final class LauncherHelper {
String mn = s[0]; String mn = s[0];
String pn = s[1]; String pn = s[1];
Layer.boot().findModule(mn).ifPresent(m -> { ModuleLayer.boot().findModule(mn).ifPresent(m -> {
if (m.getDescriptor().packages().contains(pn)) { if (m.getDescriptor().packages().contains(pn)) {
if (open) { if (open) {
Modules.addOpensToAllUnnamed(m, pn); Modules.addOpensToAllUnnamed(m, pn);
@ -564,7 +562,7 @@ public final class LauncherHelper {
} }
// main module is in the boot layer // main module is in the boot layer
Layer layer = Layer.boot(); ModuleLayer layer = ModuleLayer.boot();
Optional<Module> om = layer.findModule(mainModule); Optional<Module> om = layer.findModule(mainModule);
if (!om.isPresent()) { if (!om.isPresent()) {
// should not happen // should not happen
@ -854,7 +852,7 @@ public final class LauncherHelper {
private static void setFXLaunchParameters(String what, int mode) { private static void setFXLaunchParameters(String what, int mode) {
// find the module with the FX launcher // find the module with the FX launcher
Optional<Module> om = Layer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME); Optional<Module> om = ModuleLayer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);
if (!om.isPresent()) { if (!om.isPresent()) {
abort(null, "java.launcher.cls.error5"); abort(null, "java.launcher.cls.error5");
} }
@ -938,8 +936,7 @@ public final class LauncherHelper {
* Called by the launcher to list the observable modules. * Called by the launcher to list the observable modules.
* If called without any sub-options then the output is a simple list of * If called without any sub-options then the output is a simple list of
* the modules. If called with sub-options then the sub-options are the * the modules. If called with sub-options then the sub-options are the
* names of the modules to list (-listmods:java.base,java.desktop for * names of the modules to list (e.g. --list-modules java.base,java.desktop)
* example).
*/ */
static void listModules(boolean printToStderr, String optionFlag) static void listModules(boolean printToStderr, String optionFlag)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
@ -947,89 +944,97 @@ public final class LauncherHelper {
initOutput(printToStderr); initOutput(printToStderr);
ModuleFinder finder = jdk.internal.module.ModuleBootstrap.finder(); ModuleFinder finder = jdk.internal.module.ModuleBootstrap.finder();
int colon = optionFlag.indexOf('='); int colon = optionFlag.indexOf('=');
if (colon == -1) { if (colon == -1) {
finder.findAll().stream() finder.findAll().stream()
.sorted(Comparator.comparing(ModuleReference::descriptor)) .sorted(Comparator.comparing(ModuleReference::descriptor))
.forEach(md -> { .forEach(mref -> describeModule(finder, mref, false));
ostream.println(midAndLocation(md.descriptor(),
md.location()));
});
} else { } else {
String[] names = optionFlag.substring(colon+1).split(","); String[] names = optionFlag.substring(colon+1).split(",");
for (String name: names) { for (String name: names) {
ModuleReference mref = finder.find(name).orElse(null); ModuleReference mref = finder.find(name).orElse(null);
if (mref == null) { if (mref == null) {
System.err.format("%s not observable!%n", name); System.err.format("%s not found%n", name);
continue; continue;
} }
describeModule(finder, mref, true);
ModuleDescriptor md = mref.descriptor();
if (md.isOpen())
ostream.print("open ");
if (md.isAutomatic())
ostream.print("automatic ");
if (md.modifiers().contains(ModuleDescriptor.Modifier.SYNTHETIC))
ostream.print("synthetic ");
if (md.modifiers().contains(ModuleDescriptor.Modifier.MANDATED))
ostream.print("mandated ");
ostream.println("module " + midAndLocation(md, mref.location()));
// unqualified exports (sorted by package)
Set<Exports> exports = new TreeSet<>(Comparator.comparing(Exports::source));
md.exports().stream().filter(e -> !e.isQualified()).forEach(exports::add);
for (Exports e : exports) {
String modsAndSource = Stream.concat(toStringStream(e.modifiers()),
Stream.of(e.source()))
.collect(Collectors.joining(" "));
ostream.format(" exports %s%n", modsAndSource);
}
for (Requires d : md.requires()) {
ostream.format(" requires %s%n", d);
}
for (String s : md.uses()) {
ostream.format(" uses %s%n", s);
}
for (Provides ps : md.provides()) {
ostream.format(" provides %s with %s%n", ps.service(),
ps.providers().stream().collect(Collectors.joining(", ")));
}
// qualified exports
for (Exports e : md.exports()) {
if (e.isQualified()) {
String modsAndSource = Stream.concat(toStringStream(e.modifiers()),
Stream.of(e.source()))
.collect(Collectors.joining(" "));
ostream.format(" exports %s", modsAndSource);
formatCommaList(ostream, " to", e.targets());
}
}
// open packages
for (Opens obj: md.opens()) {
String modsAndSource = Stream.concat(toStringStream(obj.modifiers()),
Stream.of(obj.source()))
.collect(Collectors.joining(" "));
ostream.format(" opens %s", modsAndSource);
if (obj.isQualified())
formatCommaList(ostream, " to", obj.targets());
else
ostream.println();
}
// non-exported/non-open packages
Set<String> concealed = new TreeSet<>(md.packages());
md.exports().stream().map(Exports::source).forEach(concealed::remove);
md.opens().stream().map(Opens::source).forEach(concealed::remove);
concealed.forEach(p -> ostream.format(" contains %s%n", p));
} }
} }
} }
/**
* Describes the given module.
*/
static void describeModule(ModuleFinder finder,
ModuleReference mref,
boolean verbose)
{
ModuleDescriptor md = mref.descriptor();
ostream.print("module " + midAndLocation(md, mref.location()));
if (md.isAutomatic())
ostream.print(" automatic");
ostream.println();
if (!verbose)
return;
// unqualified exports (sorted by package)
Set<Exports> exports = new TreeSet<>(Comparator.comparing(Exports::source));
md.exports().stream().filter(e -> !e.isQualified()).forEach(exports::add);
for (Exports e : exports) {
String modsAndSource = Stream.concat(toStringStream(e.modifiers()),
Stream.of(e.source()))
.collect(Collectors.joining(" "));
ostream.format(" exports %s%n", modsAndSource);
}
for (Requires d : md.requires()) {
ostream.format(" requires %s", d);
String suffix = finder.find(d.name())
.map(ModuleReference::descriptor)
.map(any -> any.isAutomatic() ? " automatic" : "")
.orElse(" not found");
ostream.println(suffix);
}
for (String s : md.uses()) {
ostream.format(" uses %s%n", s);
}
for (Provides ps : md.provides()) {
ostream.format(" provides %s with %s%n", ps.service(),
ps.providers().stream().collect(Collectors.joining(", ")));
}
// qualified exports
for (Exports e : md.exports()) {
if (e.isQualified()) {
String modsAndSource = Stream.concat(toStringStream(e.modifiers()),
Stream.of(e.source()))
.collect(Collectors.joining(" "));
ostream.format(" exports %s", modsAndSource);
formatCommaList(ostream, " to", e.targets());
}
}
// open packages
for (Opens obj: md.opens()) {
String modsAndSource = Stream.concat(toStringStream(obj.modifiers()),
Stream.of(obj.source()))
.collect(Collectors.joining(" "));
ostream.format(" opens %s", modsAndSource);
if (obj.isQualified())
formatCommaList(ostream, " to", obj.targets());
else
ostream.println();
}
// non-exported/non-open packages
Set<String> concealed = new TreeSet<>(md.packages());
md.exports().stream().map(Exports::source).forEach(concealed::remove);
md.opens().stream().map(Opens::source).forEach(concealed::remove);
concealed.forEach(p -> ostream.format(" contains %s%n", p));
}
static <T> String toString(Set<T> s) { static <T> String toString(Set<T> s) {
return toStringStream(s).collect(Collectors.joining(" ")); return toStringStream(s).collect(Collectors.joining(" "));
} }

View File

@ -25,7 +25,6 @@
package sun.reflect.misc; package sun.reflect.misc;
import java.lang.reflect.Module;
import java.io.EOFException; import java.io.EOFException;
import java.security.AllPermission; import java.security.AllPermission;
import java.security.AccessController; import java.security.AccessController;

View File

@ -29,12 +29,12 @@
#include "jni_util.h" #include "jni_util.h"
#include "jvm.h" #include "jvm.h"
#include "java_lang_reflect_Module.h" #include "java_lang_Module.h"
/* /*
* Gets the UTF-8 chars for the string and translates '.' to '/'. Does no * Gets the UTF-8 chars for the string and translates '.' to '/'. Does no
* further validation, assumption being that both calling code in * further validation, assumption being that both calling code in
* java.lang.reflect.Module and VM will do deeper validation. * java.lang.Module and VM will do deeper validation.
*/ */
static char* static char*
GetInternalPackageName(JNIEnv *env, jstring pkg, char* buf, jsize buf_size) GetInternalPackageName(JNIEnv *env, jstring pkg, char* buf, jsize buf_size)
@ -68,7 +68,7 @@ GetInternalPackageName(JNIEnv *env, jstring pkg, char* buf, jsize buf_size)
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_defineModule0(JNIEnv *env, jclass cls, jobject module, Java_java_lang_Module_defineModule0(JNIEnv *env, jclass cls, jobject module,
jboolean is_open, jstring version, jboolean is_open, jstring version,
jstring location, jobjectArray packages) jstring location, jobjectArray packages)
{ {
@ -109,14 +109,14 @@ Java_java_lang_reflect_Module_defineModule0(JNIEnv *env, jclass cls, jobject mod
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_addReads0(JNIEnv *env, jclass cls, jobject from, jobject to) Java_java_lang_Module_addReads0(JNIEnv *env, jclass cls, jobject from, jobject to)
{ {
JVM_AddReadsModule(env, from, to); JVM_AddReadsModule(env, from, to);
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_addExports0(JNIEnv *env, jclass cls, jobject from, Java_java_lang_Module_addExports0(JNIEnv *env, jclass cls, jobject from,
jstring pkg, jobject to) jstring pkg, jobject to)
{ {
char buf[128]; char buf[128];
char* pkg_name; char* pkg_name;
@ -136,8 +136,8 @@ Java_java_lang_reflect_Module_addExports0(JNIEnv *env, jclass cls, jobject from,
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject from, Java_java_lang_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject from,
jstring pkg) jstring pkg)
{ {
char buf[128]; char buf[128];
char* pkg_name; char* pkg_name;
@ -157,8 +157,8 @@ Java_java_lang_reflect_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls, Java_java_lang_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls,
jobject from, jstring pkg) jobject from, jstring pkg)
{ {
char buf[128]; char buf[128];
char* pkg_name; char* pkg_name;
@ -178,7 +178,7 @@ Java_java_lang_reflect_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls,
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_java_lang_reflect_Module_addPackage0(JNIEnv *env, jclass cls, jobject m, jstring pkg) Java_java_lang_Module_addPackage0(JNIEnv *env, jclass cls, jobject m, jstring pkg)
{ {
char buf[128]; char buf[128];
char* pkg_name; char* pkg_name;

View File

@ -28,7 +28,6 @@ package javax.imageio.metadata;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;

View File

@ -28,7 +28,6 @@ package javax.imageio.spi;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Arrays; import java.util.Arrays;

View File

@ -31,7 +31,6 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Objects; import java.util.Objects;
import javax.swing.event.*; import javax.swing.event.*;
import java.lang.reflect.Module;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.util.HashMap; import java.util.HashMap;

View File

@ -25,7 +25,6 @@
package java.lang.instrument; package java.lang.instrument;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;

View File

@ -25,7 +25,6 @@
package java.lang.instrument; package java.lang.instrument;
import java.lang.reflect.Module;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -346,7 +345,7 @@ public interface Instrumentation {
/** /**
* Determines whether a class is modifiable by * Tests whether a class is modifiable by
* {@linkplain #retransformClasses retransformation} * {@linkplain #retransformClasses retransformation}
* or {@linkplain #redefineClasses redefinition}. * or {@linkplain #redefineClasses redefinition}.
* If a class is modifiable then this method returns <code>true</code>. * If a class is modifiable then this method returns <code>true</code>.
@ -711,8 +710,11 @@ public interface Instrumentation {
* {@code extraProvides} map contains a service provider type that * {@code extraProvides} map contains a service provider type that
* is not a member of the module or an implementation of the service; * is not a member of the module or an implementation of the service;
* or {@code extraProvides} maps a key to an empty list * or {@code extraProvides} maps a key to an empty list
* @throws UnmodifiableModuleException if the module cannot be modified
* @throws NullPointerException if any of the arguments are {@code null} or * @throws NullPointerException if any of the arguments are {@code null} or
* any of the Sets or Maps contains a {@code null} key or value * any of the Sets or Maps contains a {@code null} key or value
*
* @see #isModifiableModule(Module)
* @since 9 * @since 9
* @spec JPMS * @spec JPMS
*/ */
@ -722,4 +724,19 @@ public interface Instrumentation {
Map<String, Set<Module>> extraOpens, Map<String, Set<Module>> extraOpens,
Set<Class<?>> extraUses, Set<Class<?>> extraUses,
Map<Class<?>, List<Class<?>>> extraProvides); Map<Class<?>, List<Class<?>>> extraProvides);
/**
* Tests whether a module can be modified with {@link #redefineModule
* redefineModule}. If a module is modifiable then this method returns
* {@code true}. If a module is not modifiable then this method returns
* {@code false}.
*
* @param module the module to test if it can be modified
* @return {@code true} if the module is modifiable, otherwise {@code false}
* @throws NullPointerException if the module is {@code null}
*
* @since 9
* @spec JPMS
*/
boolean isModifiableModule(Module module);
} }

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 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
* 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.
*/
package java.lang.instrument;
/**
* Thrown to indicate that a module cannot be modified.
*
* @see Instrumentation#redefineModule
* @since 9
* @spec JPMS
*/
public class UnmodifiableModuleException extends RuntimeException {
private static final long serialVersionUID = 6912511912351080644L;
/**
* Constructs an {@code UnmodifiableModuleException} with no
* detail message.
*/
public UnmodifiableModuleException() {
super();
}
/**
* Constructs an {@code UnmodifiableModuleException} with the
* specified detail message.
*
* @param msg the detail message.
*/
public UnmodifiableModuleException(String msg) {
super(msg);
}
}

View File

@ -23,11 +23,10 @@
* questions. * questions.
*/ */
package sun.instrument; package sun.instrument;
import java.lang.instrument.UnmodifiableModuleException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
import java.lang.reflect.AccessibleObject; import java.lang.reflect.AccessibleObject;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.ClassDefinition; import java.lang.instrument.ClassDefinition;
@ -132,6 +131,13 @@ public class InstrumentationImpl implements Instrumentation {
return isModifiableClass0(mNativeAgent, theClass); return isModifiableClass0(mNativeAgent, theClass);
} }
public boolean isModifiableModule(Module module) {
if (module == null) {
throw new NullPointerException("'module' is null");
}
return true;
}
public boolean public boolean
isRetransformClassesSupported() { isRetransformClassesSupported() {
// ask lazily since there is some overhead // ask lazily since there is some overhead
@ -243,6 +249,9 @@ public class InstrumentationImpl implements Instrumentation {
if (!module.isNamed()) if (!module.isNamed())
return; return;
if (!isModifiableModule(module))
throw new UnmodifiableModuleException(module.getName());
// copy and check reads // copy and check reads
extraReads = new HashSet<>(extraReads); extraReads = new HashSet<>(extraReads);
if (extraReads.contains(null)) if (extraReads.contains(null))
@ -312,7 +321,7 @@ public class InstrumentationImpl implements Instrumentation {
return Collections.emptyMap(); return Collections.emptyMap();
Map<String, Set<Module>> result = new HashMap<>(); Map<String, Set<Module>> result = new HashMap<>();
Set<String> packages = Set.of(module.getPackages()); Set<String> packages = module.getPackages();
for (Map.Entry<String, Set<Module>> e : map.entrySet()) { for (Map.Entry<String, Set<Module>> e : map.entrySet()) {
String pkg = e.getKey(); String pkg = e.getKey();
if (pkg == null) if (pkg == null)

View File

@ -25,10 +25,8 @@
package sun.instrument; package sun.instrument;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
import java.lang.reflect.Module;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
/* /*

View File

@ -66,7 +66,7 @@ typedef struct _JPLISEnvironment JPLISEnvironment;
#define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V" #define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
#define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODNAME "transform" #define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODNAME "transform"
#define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODSIGNATURE \ #define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODSIGNATURE \
"(Ljava/lang/reflect/Module;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/Class;Ljava/security/ProtectionDomain;[BZ)[B" "(Ljava/lang/Module;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/Class;Ljava/security/ProtectionDomain;[BZ)[B"
/* /*

View File

@ -24,10 +24,10 @@
*/ */
package java.util.logging; package java.util.logging;
import java.lang.ref.Reference; import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -23,7 +23,6 @@
* questions. * questions.
*/ */
package java.util.logging; package java.util.logging;
import java.io.*; import java.io.*;
@ -43,7 +42,6 @@ import java.util.stream.Stream;
import jdk.internal.misc.JavaAWTAccess; import jdk.internal.misc.JavaAWTAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import sun.util.logging.internal.LoggingProviderImpl; import sun.util.logging.internal.LoggingProviderImpl;
import java.lang.reflect.Module;
import static jdk.internal.logger.DefaultLoggerFinder.isSystem; import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
/** /**

View File

@ -23,11 +23,9 @@
* questions. * questions.
*/ */
package java.util.logging; package java.util.logging;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Module;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -32,7 +32,6 @@ import java.util.ResourceBundle;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.reflect.Module;
import java.util.Objects; import java.util.Objects;
import java.util.logging.LogManager; import java.util.logging.LogManager;
import jdk.internal.logger.DefaultLoggerFinder; import jdk.internal.logger.DefaultLoggerFinder;

View File

@ -43,7 +43,6 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Module;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.rmi.MarshalledObject; import java.rmi.MarshalledObject;

View File

@ -28,7 +28,6 @@ package javax.management.remote;
import com.sun.jmx.mbeanserver.Util; import com.sun.jmx.mbeanserver.Util;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.reflect.Module;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -45,7 +45,6 @@ import jdk.internal.misc.SharedSecrets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.lang.reflect.Module;
import java.lang.reflect.UndeclaredThrowableException; import java.lang.reflect.UndeclaredThrowableException;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Collections; import java.util.Collections;
@ -181,8 +180,7 @@ public class ManagementFactoryHelper {
return AccessController.doPrivileged(new PrivilegedAction<>() { return AccessController.doPrivileged(new PrivilegedAction<>() {
@Override @Override
public Class<?> run() { public Class<?> run() {
Optional<Module> logging = java.lang.reflect.Layer.boot() Optional<Module> logging = ModuleLayer.boot().findModule("java.logging");
.findModule("java.logging");
if (logging.isPresent()) { if (logging.isPresent()) {
return Class.forName(logging.get(), className); return Class.forName(logging.get(), className);
} }

View File

@ -176,7 +176,7 @@ public final class VersionHelper {
InputStream getResourceAsStream(Class<?> c, String name) { InputStream getResourceAsStream(Class<?> c, String name) {
PrivilegedAction<InputStream> act = () -> { PrivilegedAction<InputStream> act = () -> {
try { try {
java.lang.reflect.Module m = c.getModule(); Module m = c.getModule();
return c.getModule().getResourceAsStream(resolveName(c,name)); return c.getModule().getResourceAsStream(resolveName(c,name));
} catch (IOException x) { } catch (IOException x) {
return null; return null;

View File

@ -67,11 +67,11 @@ public interface ActivationInstantiator extends Remote {
* *
* <ul><li>The class to be activated and the special activation constructor are both public, * <ul><li>The class to be activated and the special activation constructor are both public,
* and the class resides in a package that is * and the class resides in a package that is
* {@linkplain java.lang.reflect.Module#isExported(String,java.lang.reflect.Module) exported} * {@linkplain Module#isExported(String,Module) exported}
* to at least the {@code java.rmi} module; or * to at least the {@code java.rmi} module; or
* *
* <li>The class to be activated resides in a package that is * <li>The class to be activated resides in a package that is
* {@linkplain java.lang.reflect.Module#isOpen(String,java.lang.reflect.Module) open} * {@linkplain Module#isOpen(String,Module) open}
* to at least the {@code java.rmi} module. * to at least the {@code java.rmi} module.
* </ul> * </ul>
* *

View File

@ -135,9 +135,9 @@ import sun.rmi.transport.LiveRef;
* remote object's class. * remote object's class.
* *
* <li>Each remote interface must either be public and reside in a package that is * <li>Each remote interface must either be public and reside in a package that is
* {@linkplain java.lang.reflect.Module#isExported(String,java.lang.reflect.Module) exported} * {@linkplain Module#isExported(String,Module) exported}
* to at least the {@code java.rmi} module, or it must reside in a package that is * to at least the {@code java.rmi} module, or it must reside in a package that is
* {@linkplain java.lang.reflect.Module#isOpen(String,java.lang.reflect.Module) open} * {@linkplain Module#isOpen(String,Module) open}
* to at least the {@code java.rmi} module. * to at least the {@code java.rmi} module.
* *
* <li>The proxy's invocation handler is a {@link * <li>The proxy's invocation handler is a {@link

View File

@ -1022,7 +1022,7 @@ final class P11KeyStore extends KeyStoreSpi {
("trusted certificates may only be set by " + ("trusted certificates may only be set by " +
"token initialization application")); "token initialization application"));
} }
Module module = token.provider.nssModule; Secmod.Module module = token.provider.nssModule;
if ((module.type != ModuleType.KEYSTORE) && (module.type != ModuleType.FIPS)) { if ((module.type != ModuleType.KEYSTORE) && (module.type != ModuleType.FIPS)) {
// XXX allow TRUSTANCHOR module // XXX allow TRUSTANCHOR module
throw new KeyStoreException("Trusted certificates can only be " throw new KeyStoreException("Trusted certificates can only be "

View File

@ -77,7 +77,7 @@ public final class SunPKCS11 extends AuthProvider {
final boolean removable; final boolean removable;
final Module nssModule; final Secmod.Module nssModule;
final boolean nssUseSecmodTrust; final boolean nssUseSecmodTrust;
@ -148,7 +148,7 @@ public final class SunPKCS11 extends AuthProvider {
boolean useSecmod = config.getNssUseSecmod(); boolean useSecmod = config.getNssUseSecmod();
boolean nssUseSecmodTrust = config.getNssUseSecmodTrust(); boolean nssUseSecmodTrust = config.getNssUseSecmodTrust();
Module nssModule = null; Secmod.Module nssModule = null;
// //
// Initialization via Secmod. The way this works is as follows: // Initialization via Secmod. The way this works is as follows:
@ -217,7 +217,7 @@ public final class SunPKCS11 extends AuthProvider {
// XXX which exception to throw // XXX which exception to throw
throw new ProviderException("Could not initialize NSS", e); throw new ProviderException("Could not initialize NSS", e);
} }
List<Module> modules = secmod.getModules(); List<Secmod.Module> modules = secmod.getModules();
if (config.getShowInfo()) { if (config.getShowInfo()) {
System.out.println("NSS modules: " + modules); System.out.println("NSS modules: " + modules);
} }
@ -258,7 +258,7 @@ public final class SunPKCS11 extends AuthProvider {
("Invalid external module: " + moduleName); ("Invalid external module: " + moduleName);
} }
int k = 0; int k = 0;
for (Module module : modules) { for (Secmod.Module module : modules) {
if (module.getType() == ModuleType.EXTERNAL) { if (module.getType() == ModuleType.EXTERNAL) {
if (++k == moduleIndex) { if (++k == moduleIndex) {
nssModule = module; nssModule = module;

View File

@ -25,7 +25,6 @@
package sun.tools.common; package sun.tools.common;
import java.lang.reflect.Module;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -29,8 +29,8 @@
#include "ModuleReferenceImpl.h" #include "ModuleReferenceImpl.h"
static jclass jlrM(JNIEnv *env) { static jclass jlM(JNIEnv *env) {
return findClass(env, "Ljava/lang/reflect/Module;"); return findClass(env, "Ljava/lang/Module;");
} }
static jboolean static jboolean
@ -43,7 +43,7 @@ getName(PacketInputStream *in, PacketOutputStream *out)
jobject module; jobject module;
if (method == NULL) { if (method == NULL) {
method = getMethod(env, jlrM(env), "getName", "()Ljava/lang/String;"); method = getMethod(env, jlM(env), "getName", "()Ljava/lang/String;");
} }
module = inStream_readModuleRef(getEnv(), in); module = inStream_readModuleRef(getEnv(), in);
if (inStream_error(in)) { if (inStream_error(in)) {
@ -71,7 +71,7 @@ getClassLoader(PacketInputStream *in, PacketOutputStream *out)
jobject module; jobject module;
if (method == NULL) { if (method == NULL) {
method = getMethod(env, jlrM(env), "getClassLoader", "()Ljava/lang/ClassLoader;"); method = getMethod(env, jlM(env), "getClassLoader", "()Ljava/lang/ClassLoader;");
} }
module = inStream_readModuleRef(env, in); module = inStream_readModuleRef(env, in);
if (inStream_error(in)) { if (inStream_error(in)) {

View File

@ -26,7 +26,6 @@ package jdk.tools.jlink.internal;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -55,10 +54,10 @@ public final class Jlink {
* @return A new plugin or null if plugin is unknown. * @return A new plugin or null if plugin is unknown.
*/ */
public static Plugin newPlugin(String name, public static Plugin newPlugin(String name,
Map<String, String> configuration, Layer pluginsLayer) { Map<String, String> configuration, ModuleLayer pluginsLayer) {
Objects.requireNonNull(name); Objects.requireNonNull(name);
Objects.requireNonNull(configuration); Objects.requireNonNull(configuration);
pluginsLayer = pluginsLayer == null ? Layer.boot() : pluginsLayer; pluginsLayer = pluginsLayer == null ? ModuleLayer.boot() : pluginsLayer;
return PluginRepository.newPlugin(configuration, name, pluginsLayer); return PluginRepository.newPlugin(configuration, name, pluginsLayer);
} }
@ -330,7 +329,7 @@ public final class Jlink {
private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) { private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) {
List<Plugin> plugins = new ArrayList<>(pluginsConfig.getPlugins()); List<Plugin> plugins = new ArrayList<>(pluginsConfig.getPlugins());
List<Plugin> bootPlugins = PluginRepository.getPlugins(Layer.boot()); List<Plugin> bootPlugins = PluginRepository.getPlugins(ModuleLayer.boot());
for (Plugin bp : bootPlugins) { for (Plugin bp : bootPlugins) {
if (Utils.isAutoEnabled(bp)) { if (Utils.isAutoEnabled(bp)) {
try { try {

View File

@ -24,7 +24,6 @@
*/ */
package jdk.tools.jlink.internal; package jdk.tools.jlink.internal;
import java.lang.reflect.Layer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -56,7 +55,7 @@ public final class PluginRepository {
* @return A provider or null if not found. * @return A provider or null if not found.
*/ */
public static Plugin getPlugin(String name, public static Plugin getPlugin(String name,
Layer pluginsLayer) { ModuleLayer pluginsLayer) {
return getPlugin(Plugin.class, name, pluginsLayer); return getPlugin(Plugin.class, name, pluginsLayer);
} }
@ -69,7 +68,7 @@ public final class PluginRepository {
* @return A plugin or null if no plugin found. * @return A plugin or null if no plugin found.
*/ */
public static Plugin newPlugin(Map<String, String> config, String name, public static Plugin newPlugin(Map<String, String> config, String name,
Layer pluginsLayer) { ModuleLayer pluginsLayer) {
Objects.requireNonNull(name); Objects.requireNonNull(name);
Objects.requireNonNull(pluginsLayer); Objects.requireNonNull(pluginsLayer);
Plugin plugin = getPlugin(name, pluginsLayer); Plugin plugin = getPlugin(name, pluginsLayer);
@ -107,12 +106,12 @@ public final class PluginRepository {
registeredPlugins.remove(name); registeredPlugins.remove(name);
} }
public static List<Plugin> getPlugins(Layer pluginsLayer) { public static List<Plugin> getPlugins(ModuleLayer pluginsLayer) {
return getPlugins(Plugin.class, pluginsLayer); return getPlugins(Plugin.class, pluginsLayer);
} }
private static <T extends Plugin> T getPlugin(Class<T> clazz, String name, private static <T extends Plugin> T getPlugin(Class<T> clazz, String name,
Layer pluginsLayer) { ModuleLayer pluginsLayer) {
Objects.requireNonNull(name); Objects.requireNonNull(name);
Objects.requireNonNull(pluginsLayer); Objects.requireNonNull(pluginsLayer);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -136,7 +135,7 @@ public final class PluginRepository {
* @param pluginsLayer * @param pluginsLayer
* @return The list of plugins. * @return The list of plugins.
*/ */
private static <T extends Plugin> List<T> getPlugins(Class<T> clazz, Layer pluginsLayer) { private static <T extends Plugin> List<T> getPlugins(Class<T> clazz, ModuleLayer pluginsLayer) {
Objects.requireNonNull(pluginsLayer); Objects.requireNonNull(pluginsLayer);
List<T> factories = new ArrayList<>(); List<T> factories = new ArrayList<>();
try { try {

View File

@ -29,7 +29,6 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -211,7 +210,7 @@ public final class TaskHelper {
private final class PluginsHelper { private final class PluginsHelper {
private Layer pluginsLayer = Layer.boot(); private ModuleLayer pluginsLayer = ModuleLayer.boot();
private final List<Plugin> plugins; private final List<Plugin> plugins;
private String lastSorter; private String lastSorter;
private boolean listPlugins; private boolean listPlugins;
@ -655,7 +654,7 @@ public final class TaskHelper {
return defaults; return defaults;
} }
public Layer getPluginsLayer() { public ModuleLayer getPluginsLayer() {
return pluginOptions.pluginsLayer; return pluginOptions.pluginsLayer;
} }
} }
@ -725,18 +724,18 @@ public final class TaskHelper {
return System.getProperty("java.version"); return System.getProperty("java.version");
} }
static Layer createPluginsLayer(List<Path> paths) { static ModuleLayer createPluginsLayer(List<Path> paths) {
Path[] dirs = paths.toArray(new Path[0]); Path[] dirs = paths.toArray(new Path[0]);
ModuleFinder finder = ModulePath.of(Runtime.version(), true, dirs); ModuleFinder finder = ModulePath.of(Runtime.version(), true, dirs);
Configuration bootConfiguration = Layer.boot().configuration(); Configuration bootConfiguration = ModuleLayer.boot().configuration();
try { try {
Configuration cf = bootConfiguration Configuration cf = bootConfiguration
.resolveAndBind(ModuleFinder.of(), .resolveAndBind(ModuleFinder.of(),
finder, finder,
Collections.emptySet()); Collections.emptySet());
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
return Layer.boot().defineModulesWithOneLoader(cf, scl); return ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
} catch (Exception ex) { } catch (Exception ex) {
// Malformed plugin modules (e.g.: same package in multiple modules). // Malformed plugin modules (e.g.: same package in multiple modules).
throw new PluginException("Invalid modules in the plugins path: " + ex); throw new PluginException("Invalid modules in the plugins path: " + ex);

View File

@ -24,7 +24,6 @@
*/ */
package jdk.tools.jlink.internal; package jdk.tools.jlink.internal;
import java.lang.reflect.Module;
import java.net.URI; import java.net.URI;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;

View File

@ -27,6 +27,7 @@ package jdk.tools.jlink.internal.plugins;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.util.EnumSet; import java.util.EnumSet;
@ -43,8 +44,6 @@ import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry; import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.ResourcePoolModule; import jdk.tools.jlink.plugin.ResourcePoolModule;
import jdk.tools.jlink.plugin.Plugin.Category;
import jdk.tools.jlink.plugin.Plugin.State;
import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.Plugin;
/** /**
@ -101,9 +100,9 @@ public final class ReleaseInfoPlugin implements Plugin {
// --release-info add:build_type=fastdebug,source=openjdk,java_version=9 // --release-info add:build_type=fastdebug,source=openjdk,java_version=9
// and put whatever value that was passed in command line. // and put whatever value that was passed in command line.
config.keySet().stream(). config.keySet().stream()
filter(s -> !NAME.equals(s)). .filter(s -> !NAME.equals(s))
forEach(s -> release.put(s, config.get(s))); .forEach(s -> release.put(s, config.get(s)));
} }
break; break;
@ -148,8 +147,8 @@ public final class ReleaseInfoPlugin implements Plugin {
// put topological sorted module names separated by space // put topological sorted module names separated by space
release.put("MODULES", new ModuleSorter(in.moduleView()) release.put("MODULES", new ModuleSorter(in.moduleView())
.sorted().map(ResourcePoolModule::name) .sorted().map(ResourcePoolModule::name)
.collect(Collectors.joining(" ", "\"", "\""))); .collect(Collectors.joining(" ", "\"", "\"")));
// create a TOP level ResourcePoolEntry for "release" file. // create a TOP level ResourcePoolEntry for "release" file.
out.add(ResourcePoolEntry.create("/java.base/release", out.add(ResourcePoolEntry.create("/java.base/release",
@ -160,11 +159,11 @@ public final class ReleaseInfoPlugin implements Plugin {
// Parse version string and return a string that includes only version part // Parse version string and return a string that includes only version part
// leaving "pre", "build" information. See also: java.lang.Runtime.Version. // leaving "pre", "build" information. See also: java.lang.Runtime.Version.
private static String parseVersion(String str) { private static String parseVersion(String str) {
return Runtime.Version.parse(str). return Runtime.Version.parse(str)
version(). .version()
stream(). .stream()
map(Object::toString). .map(Object::toString)
collect(Collectors.joining(".")); .collect(Collectors.joining("."));
} }
private static String quote(String str) { private static String quote(String str) {
@ -172,14 +171,12 @@ public final class ReleaseInfoPlugin implements Plugin {
} }
private byte[] releaseFileContent() { private byte[] releaseFileContent() {
Properties props = new Properties();
props.putAll(release);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
try { try (PrintWriter pw = new PrintWriter(baos)) {
props.store(baos, ""); release.entrySet().stream()
return baos.toByteArray(); .sorted(Map.Entry.comparingByKey())
} catch (IOException ex) { .forEach(e -> pw.format("%s=%s%n", e.getKey(), e.getValue()));
throw new UncheckedIOException(ex);
} }
return baos.toByteArray();
} }
} }

View File

@ -26,8 +26,8 @@ groups=TEST.groups [closed/TEST.groups]
# Allow querying of various System properties in @requires clauses # Allow querying of various System properties in @requires clauses
requires.properties=sun.arch.data.model java.runtime.name requires.properties=sun.arch.data.model java.runtime.name
# Tests using jtreg 4.2 b05 features # Tests using jtreg 4.2 b07 features
requiredVersion=4.2 b05 requiredVersion=4.2 b07
# Path to libraries in the topmost test directory. This is needed so @library # Path to libraries in the topmost test directory. This is needed so @library
# does not need ../../ notation to reach them # does not need ../../ notation to reach them

View File

@ -81,7 +81,7 @@ public class SystemTrayIconHelper {
try { try {
// sun.lwawt.macosx.CTrayIcon // sun.lwawt.macosx.CTrayIcon
Field f_peer = getField( java.awt.TrayIcon.class, "peer"); Field f_peer = getField( java.awt.TrayIcon.class, "peer");
Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.reflect.Module.class); Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
m_addExports.invoke(null, "sun.lwawt.macosx", robot.getClass().getModule()); m_addExports.invoke(null, "sun.lwawt.macosx", robot.getClass().getModule());
@ -105,7 +105,7 @@ public class SystemTrayIconHelper {
} else { } else {
try { try {
// sun.awt.X11.XTrayIconPeer // sun.awt.X11.XTrayIconPeer
Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.reflect.Module.class); Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
m_addExports.invoke(null, "sun.awt.X11", robot.getClass().getModule()); m_addExports.invoke(null, "sun.awt.X11", robot.getClass().getModule());
Field f_peer = getField(java.awt.TrayIcon.class, "peer"); Field f_peer = getField(java.awt.TrayIcon.class, "peer");

View File

@ -22,7 +22,6 @@
*/ */
package java.awt; package java.awt;
import java.lang.reflect.Module;
public class Helper { public class Helper {
private Helper() { } private Helper() { }
public static void addExports(String pn, Module target) { public static void addExports(String pn, Module target) {

View File

@ -445,7 +445,7 @@ public final class Util {
try { try {
final Class _clazz = clazz; final Class _clazz = clazz;
Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.reflect.Module.class); Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
// No MToolkit anymore: nothing to do about it. // No MToolkit anymore: nothing to do about it.
// We may be called from non-X11 system, and this permission cannot be delegated to a test. // We may be called from non-X11 system, and this permission cannot be delegated to a test.
m_addExports.invoke(null, "sun.awt.X11", Util.class.getModule()); m_addExports.invoke(null, "sun.awt.X11", Util.class.getModule());

View File

@ -31,7 +31,6 @@
*/ */
import java.awt.Component; import java.awt.Component;
import java.lang.reflect.Module;
import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.ClassWriter;
import static jdk.internal.org.objectweb.asm.Opcodes.*; import static jdk.internal.org.objectweb.asm.Opcodes.*;

View File

@ -23,9 +23,7 @@
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.nio.file.Path; import java.nio.file.Path;
@ -45,13 +43,13 @@ public class TestLayer {
ModuleFinder finder = ModuleFinder.of(MODS_DIR); ModuleFinder finder = ModuleFinder.of(MODS_DIR);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolveAndBind(ModuleFinder.of(), Configuration cf = parent.resolveAndBind(ModuleFinder.of(),
finder, finder,
modules); modules);
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
Module m1 = layer.findModule("m1").get(); Module m1 = layer.findModule("m1").get();
Module m2 = layer.findModule("m2").get(); Module m2 = layer.findModule("m2").get();

View File

@ -21,13 +21,11 @@
* questions. * questions.
*/ */
import java.lang.reflect.Layer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
public class TestMain { public class TestMain {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Layer boot = Layer.boot(); ModuleLayer boot = ModuleLayer.boot();
Module m1 = boot.findModule("m1").get(); Module m1 = boot.findModule("m1").get();
Module m2 = boot.findModule("m2").get(); Module m2 = boot.findModule("m2").get();

View File

@ -23,12 +23,9 @@
package p2.test; package p2.test;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
public class Main { public class Main {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Layer boot = Layer.boot(); ModuleLayer boot = ModuleLayer.boot();
Module m1 = boot.findModule("m1").get(); Module m1 = boot.findModule("m1").get();
Module m2 = Main.class.getModule(); Module m2 = Main.class.getModule();

View File

@ -26,8 +26,6 @@ package p3;
import java.io.FilePermission; import java.io.FilePermission;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.AccessControlException; import java.security.AccessControlException;
@ -47,7 +45,7 @@ public class NoAccess {
ModuleFinder finder = ModuleFinder.of(Paths.get("mods1"), Paths.get("mods2")); ModuleFinder finder = ModuleFinder.of(Paths.get("mods1"), Paths.get("mods2"));
Layer bootLayer = Layer.boot(); ModuleLayer bootLayer = ModuleLayer.boot();
Configuration parent = bootLayer.configuration(); Configuration parent = bootLayer.configuration();
Configuration cf = parent.resolveAndBind(finder, Configuration cf = parent.resolveAndBind(finder,
@ -55,7 +53,7 @@ public class NoAccess {
Set.of("m1", "m2")); Set.of("m1", "m2"));
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = bootLayer.defineModulesWithManyLoaders(cf, scl); ModuleLayer layer = bootLayer.defineModulesWithManyLoaders(cf, scl);
if (sm != null) { if (sm != null) {
System.setSecurityManager(sm); System.setSecurityManager(sm);

View File

@ -23,8 +23,6 @@
package p3; package p3;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.security.Permission; import java.security.Permission;
@ -37,7 +35,7 @@ public class NoGetClassLoaderAccess {
private static final Permission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader"); private static final Permission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader");
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Layer boot = Layer.boot(); ModuleLayer boot = ModuleLayer.boot();
System.setSecurityManager(new SecurityManager()); System.setSecurityManager(new SecurityManager());
Module m1 = boot.findModule("m1").get(); Module m1 = boot.findModule("m1").get();

View File

@ -26,10 +26,8 @@ import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.reflect.AccessibleObject; import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Module;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.Layer;
import java.lang.reflect.ReflectPermission; import java.lang.reflect.ReflectPermission;
import java.net.URI; import java.net.URI;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
@ -269,7 +267,7 @@ public class FieldSetAccessibleTest {
try { try {
return Files.walk(root) return Files.walk(root)
.filter(p -> p.getNameCount() > 2) .filter(p -> p.getNameCount() > 2)
.filter(p -> Layer.boot().findModule(p.getName(1).toString()).isPresent()) .filter(p -> ModuleLayer.boot().findModule(p.getName(1).toString()).isPresent())
.map(p -> p.subpath(2, p.getNameCount())) .map(p -> p.subpath(2, p.getNameCount()))
.map(p -> p.toString()) .map(p -> p.toString())
.filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class")) .filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class"))

View File

@ -23,7 +23,6 @@
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
@ -256,7 +255,7 @@ public class Main {
* Returns the directory for the given module (by name). * Returns the directory for the given module (by name).
*/ */
static Path directoryFor(String name) { static Path directoryFor(String name) {
Configuration cf = Layer.boot().configuration(); Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule resolvedModule = cf.findModule(name).orElse(null); ResolvedModule resolvedModule = cf.findModule(name).orElse(null);
if (resolvedModule == null) if (resolvedModule == null)
throw new RuntimeException("not found: " + name); throw new RuntimeException("not found: " + name);

View File

@ -26,7 +26,6 @@ import java.io.InputStream;
import java.lang.module.ModuleReader; import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.net.URL; import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
@ -74,7 +73,7 @@ public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String mn = args[0]; String mn = args[0];
ModuleReference mref = Layer.boot() ModuleReference mref = ModuleLayer.boot()
.configuration() .configuration()
.findModule(mn) .findModule(mn)
.map(ResolvedModule::reference) .map(ResolvedModule::reference)

View File

@ -24,7 +24,6 @@
import java.io.InputStream; import java.io.InputStream;
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.lang.reflect.Layer;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
@ -309,7 +308,7 @@ public class Main {
* Returns the directory for the given module (by name). * Returns the directory for the given module (by name).
*/ */
static Path directoryFor(String mn) { static Path directoryFor(String mn) {
Configuration cf = Layer.boot().configuration(); Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule resolvedModule = cf.findModule(mn).orElse(null); ResolvedModule resolvedModule = cf.findModule(mn).orElse(null);
if (resolvedModule == null) if (resolvedModule == null)
throw new RuntimeException("not found: " + mn); throw new RuntimeException("not found: " + mn);

View File

@ -28,16 +28,13 @@
* @build BasicLayerTest ModuleUtils * @build BasicLayerTest ModuleUtils
* @compile layertest/Test.java * @compile layertest/Test.java
* @run testng BasicLayerTest * @run testng BasicLayerTest
* @summary Basic tests for java.lang.reflect.Layer * @summary Basic tests for java.lang.ModuleLayer
*/ */
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.lang.reflect.LayerInstantiationException;
import java.lang.reflect.Module;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -63,10 +60,10 @@ public class BasicLayerTest {
} }
/** /**
* Exercise Layer.empty() * Exercise ModuleLayer.empty()
*/ */
public void testEmpty() { public void testEmpty() {
Layer emptyLayer = Layer.empty(); ModuleLayer emptyLayer = ModuleLayer.empty();
assertTrue(emptyLayer.parents().isEmpty()); assertTrue(emptyLayer.parents().isEmpty());
@ -84,10 +81,10 @@ public class BasicLayerTest {
/** /**
* Exercise Layer.boot() * Exercise ModuleLayer.boot()
*/ */
public void testBoot() { public void testBoot() {
Layer bootLayer = Layer.boot(); ModuleLayer bootLayer = ModuleLayer.boot();
// configuration // configuration
Configuration cf = bootLayer.configuration(); Configuration cf = bootLayer.configuration();
@ -114,12 +111,12 @@ public class BasicLayerTest {
// parents // parents
assertTrue(bootLayer.parents().size() == 1); assertTrue(bootLayer.parents().size() == 1);
assertTrue(bootLayer.parents().get(0) == Layer.empty()); assertTrue(bootLayer.parents().get(0) == ModuleLayer.empty());
} }
/** /**
* Exercise Layer defineModules, created with empty layer as parent * Exercise defineModules, created with empty layer as parent
*/ */
public void testLayerOnEmpty() { public void testLayerOnEmpty() {
ModuleDescriptor descriptor1 = newBuilder("m1") ModuleDescriptor descriptor1 = newBuilder("m1")
@ -148,7 +145,7 @@ public class BasicLayerTest {
map.put("m2", loader2); map.put("m2", loader2);
map.put("m3", loader3); map.put("m3", loader3);
Layer layer = Layer.empty().defineModules(cf, map::get); ModuleLayer layer = ModuleLayer.empty().defineModules(cf, map::get);
// configuration // configuration
assertTrue(layer.configuration() == cf); assertTrue(layer.configuration() == cf);
@ -193,12 +190,12 @@ public class BasicLayerTest {
// parents // parents
assertTrue(layer.parents().size() == 1); assertTrue(layer.parents().size() == 1);
assertTrue(layer.parents().get(0) == Layer.empty()); assertTrue(layer.parents().get(0) == ModuleLayer.empty());
} }
/** /**
* Exercise Layer defineModules, created with boot layer as parent * Exercise defineModules, created with boot layer as parent
*/ */
public void testLayerOnBoot() { public void testLayerOnBoot() {
ModuleDescriptor descriptor1 = newBuilder("m1") ModuleDescriptor descriptor1 = newBuilder("m1")
@ -214,12 +211,12 @@ public class BasicLayerTest {
ModuleFinder finder ModuleFinder finder
= ModuleUtils.finderOf(descriptor1, descriptor2); = ModuleUtils.finderOf(descriptor1, descriptor2);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "m1"); Configuration cf = resolve(parent, finder, "m1");
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer layer = Layer.boot().defineModules(cf, mn -> loader); ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
// configuration // configuration
assertTrue(layer.configuration() == cf); assertTrue(layer.configuration() == cf);
@ -255,12 +252,12 @@ public class BasicLayerTest {
// parents // parents
assertTrue(layer.parents().size() == 1); assertTrue(layer.parents().size() == 1);
assertTrue(layer.parents().get(0) == Layer.boot()); assertTrue(layer.parents().get(0) == ModuleLayer.boot());
} }
/** /**
* Exercise Layer defineModules with a configuration of two modules that * Exercise defineModules with a configuration of two modules that
* have the same module-private package. * have the same module-private package.
*/ */
public void testPackageContainedInSelfAndOther() { public void testPackageContainedInSelfAndOther() {
@ -280,19 +277,19 @@ public class BasicLayerTest {
assertTrue(cf.modules().size() == 2); assertTrue(cf.modules().size() == 2);
// one loader per module, should be okay // one loader per module, should be okay
Layer.empty().defineModules(cf, mn -> new ClassLoader() { }); ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
// same class loader // same class loader
try { try {
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.empty().defineModules(cf, mn -> loader); ModuleLayer.empty().defineModules(cf, mn -> loader);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException expected) { } } catch (LayerInstantiationException expected) { }
} }
/** /**
* Exercise Layer defineModules with a configuration that is a partitioned * Exercise defineModules with a configuration that is a partitioned
* graph. The same package is exported in both partitions. * graph. The same package is exported in both partitions.
*/ */
public void testSameExportInPartitionedGraph() { public void testSameExportInPartitionedGraph() {
@ -323,7 +320,7 @@ public class BasicLayerTest {
assertTrue(cf.modules().size() == 4); assertTrue(cf.modules().size() == 4);
// one loader per module // one loader per module
Layer.empty().defineModules(cf, mn -> new ClassLoader() { }); ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
// m1 & m2 in one loader, m3 & m4 in another loader // m1 & m2 in one loader, m3 & m4 in another loader
ClassLoader loader1 = new ClassLoader() { }; ClassLoader loader1 = new ClassLoader() { };
@ -333,19 +330,19 @@ public class BasicLayerTest {
map.put("m2", loader1); map.put("m2", loader1);
map.put("m3", loader2); map.put("m3", loader2);
map.put("m4", loader2); map.put("m4", loader2);
Layer.empty().defineModules(cf, map::get); ModuleLayer.empty().defineModules(cf, map::get);
// same loader // same loader
try { try {
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.empty().defineModules(cf, mn -> loader); ModuleLayer.empty().defineModules(cf, mn -> loader);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException expected) { } } catch (LayerInstantiationException expected) { }
} }
/** /**
* Exercise Layer defineModules with a configuration with a module that * Exercise defineModules with a configuration with a module that
* contains a package that is the same name as a non-exported package in * contains a package that is the same name as a non-exported package in
* a parent layer. * a parent layer.
*/ */
@ -362,12 +359,12 @@ public class BasicLayerTest {
ModuleFinder finder = ModuleUtils.finderOf(descriptor); ModuleFinder finder = ModuleUtils.finderOf(descriptor);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1")); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
assertTrue(cf.modules().size() == 1); assertTrue(cf.modules().size() == 1);
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer layer = Layer.boot().defineModules(cf, mn -> loader); ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
assertTrue(layer.modules().size() == 1); assertTrue(layer.modules().size() == 1);
} }
@ -395,7 +392,7 @@ public class BasicLayerTest {
Configuration cf1 = resolve(finder1, "m2"); Configuration cf1 = resolve(finder1, "m2");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
// cf2: m3, m3 requires m2 // cf2: m3, m3 requires m2
@ -409,10 +406,10 @@ public class BasicLayerTest {
Configuration cf2 = resolve(cf1, finder2, "m3"); Configuration cf2 = resolve(cf1, finder2, "m3");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer1.parents().size() == 1); assertTrue(layer1.parents().size() == 1);
assertTrue(layer1.parents().get(0) == Layer.empty()); assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
assertTrue(layer2.parents().size() == 1); assertTrue(layer2.parents().size() == 1);
assertTrue(layer2.parents().get(0) == layer1); assertTrue(layer2.parents().get(0) == layer1);
@ -461,7 +458,7 @@ public class BasicLayerTest {
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
// cf2: m2, m3: m2 requires transitive m1, m3 requires m2 // cf2: m2, m3: m2 requires transitive m1, m3 requires m2
@ -479,10 +476,10 @@ public class BasicLayerTest {
Configuration cf2 = resolve(cf1, finder2, "m3"); Configuration cf2 = resolve(cf1, finder2, "m3");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer1.parents().size() == 1); assertTrue(layer1.parents().size() == 1);
assertTrue(layer1.parents().get(0) == Layer.empty()); assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
assertTrue(layer2.parents().size() == 1); assertTrue(layer2.parents().size() == 1);
assertTrue(layer2.parents().get(0) == layer1); assertTrue(layer2.parents().get(0) == layer1);
@ -528,7 +525,7 @@ public class BasicLayerTest {
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
// cf2: m2 requires transitive m1 // cf2: m2 requires transitive m1
@ -542,7 +539,7 @@ public class BasicLayerTest {
Configuration cf2 = resolve(cf1, finder2, "m2"); Configuration cf2 = resolve(cf1, finder2, "m2");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
// cf3: m3 requires m2 // cf3: m3 requires m2
@ -556,10 +553,10 @@ public class BasicLayerTest {
Configuration cf3 = resolve(cf2, finder3, "m3"); Configuration cf3 = resolve(cf2, finder3, "m3");
ClassLoader cl3 = new ClassLoader() { }; ClassLoader cl3 = new ClassLoader() { };
Layer layer3 = layer2.defineModules(cf3, mn -> cl3); ModuleLayer layer3 = layer2.defineModules(cf3, mn -> cl3);
assertTrue(layer1.parents().size() == 1); assertTrue(layer1.parents().size() == 1);
assertTrue(layer1.parents().get(0) == Layer.empty()); assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
assertTrue(layer2.parents().size() == 1); assertTrue(layer2.parents().size() == 1);
assertTrue(layer2.parents().get(0) == layer1); assertTrue(layer2.parents().get(0) == layer1);
@ -612,7 +609,7 @@ public class BasicLayerTest {
Configuration cf1 = resolve(finder1, "m2"); Configuration cf1 = resolve(finder1, "m2");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
// cf2: m3 requires transitive m2, m4 requires m3 // cf2: m3 requires transitive m2, m4 requires m3
@ -631,10 +628,10 @@ public class BasicLayerTest {
Configuration cf2 = resolve(cf1, finder2, "m3", "m4"); Configuration cf2 = resolve(cf1, finder2, "m3", "m4");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer1.parents().size() == 1); assertTrue(layer1.parents().size() == 1);
assertTrue(layer1.parents().get(0) == Layer.empty()); assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
assertTrue(layer2.parents().size() == 1); assertTrue(layer2.parents().size() == 1);
assertTrue(layer2.parents().get(0) == layer1); assertTrue(layer2.parents().get(0) == layer1);
@ -691,7 +688,7 @@ public class BasicLayerTest {
Configuration cf = resolve(finder1, "m1", "m2"); Configuration cf = resolve(finder1, "m1", "m2");
ClassLoader cl = new ClassLoader() { }; ClassLoader cl = new ClassLoader() { };
Layer layer = Layer.empty().defineModules(cf, mn -> cl); ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
assertTrue(layer.modules().size() == 2); assertTrue(layer.modules().size() == 2);
Module m1 = layer.findModule("m1").get(); Module m1 = layer.findModule("m1").get();
@ -724,7 +721,7 @@ public class BasicLayerTest {
Configuration cf = resolve(finder1, "m2"); Configuration cf = resolve(finder1, "m2");
ClassLoader cl = new ClassLoader() { }; ClassLoader cl = new ClassLoader() { };
Layer layer = Layer.empty().defineModules(cf, mn -> cl); ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
assertTrue(layer.modules().size() == 2); assertTrue(layer.modules().size() == 2);
Module m1 = layer.findModule("m1").get(); Module m1 = layer.findModule("m1").get();
@ -750,7 +747,7 @@ public class BasicLayerTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
assertTrue(layer1.modules().size() == 1); assertTrue(layer1.modules().size() == 1);
// create layer2 with m2 // create layer2 with m2
@ -760,7 +757,7 @@ public class BasicLayerTest {
ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
Configuration cf2 = resolve(cf1, finder2, "m2"); Configuration cf2 = resolve(cf1, finder2, "m2");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer2.modules().size() == 1); assertTrue(layer2.modules().size() == 1);
Module m1 = layer1.findModule("m1").get(); Module m1 = layer1.findModule("m1").get();
@ -786,7 +783,7 @@ public class BasicLayerTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
assertTrue(layer1.modules().size() == 1); assertTrue(layer1.modules().size() == 1);
// create layer2 with m2 // create layer2 with m2
@ -797,7 +794,7 @@ public class BasicLayerTest {
ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
Configuration cf2 = resolve(cf1, finder2, "m2"); Configuration cf2 = resolve(cf1, finder2, "m2");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer2.modules().size() == 1); assertTrue(layer2.modules().size() == 1);
Module m1 = layer1.findModule("m1").get(); Module m1 = layer1.findModule("m1").get();
@ -822,7 +819,7 @@ public class BasicLayerTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
assertTrue(layer1.modules().size() == 1); assertTrue(layer1.modules().size() == 1);
// create layer2 with m1 and m2 // create layer2 with m1 and m2
@ -830,7 +827,7 @@ public class BasicLayerTest {
ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor2);
Configuration cf2 = resolve(cf1, finder2, "m1", "m2"); Configuration cf2 = resolve(cf1, finder2, "m1", "m2");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer2.modules().size() == 2); assertTrue(layer2.modules().size() == 2);
Module m1_v1 = layer1.findModule("m1").get(); Module m1_v1 = layer1.findModule("m1").get();
@ -860,7 +857,7 @@ public class BasicLayerTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
Configuration cf1 = resolve(finder1, "m2"); Configuration cf1 = resolve(finder1, "m2");
ClassLoader loader1 = new ClassLoader() { }; ClassLoader loader1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> loader1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> loader1);
assertTrue(layer1.modules().size() == 2); assertTrue(layer1.modules().size() == 2);
// create layer2 with m1 and m3 // create layer2 with m1 and m3
@ -871,7 +868,7 @@ public class BasicLayerTest {
ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3);
Configuration cf2 = resolve(cf1, finder2, "m1", "m3"); Configuration cf2 = resolve(cf1, finder2, "m1", "m3");
ClassLoader loader2 = new ClassLoader() { }; ClassLoader loader2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> loader2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> loader2);
assertTrue(layer2.modules().size() == 2); assertTrue(layer2.modules().size() == 2);
Module m1_v1 = layer1.findModule("m1").get(); Module m1_v1 = layer1.findModule("m1").get();
@ -902,7 +899,7 @@ public class BasicLayerTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
Configuration cf1 = resolve(finder1, "m1"); Configuration cf1 = resolve(finder1, "m1");
ClassLoader cl1 = new ClassLoader() { }; ClassLoader cl1 = new ClassLoader() { };
Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1); ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
assertTrue(layer1.modules().size() == 1); assertTrue(layer1.modules().size() == 1);
// create layer2 with m2 // create layer2 with m2
@ -912,7 +909,7 @@ public class BasicLayerTest {
ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
Configuration cf2 = resolve(cf1, finder2, "m2"); Configuration cf2 = resolve(cf1, finder2, "m2");
ClassLoader cl2 = new ClassLoader() { }; ClassLoader cl2 = new ClassLoader() { };
Layer layer2 = layer1.defineModules(cf2, mn -> cl2); ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
assertTrue(layer2.modules().size() == 1); assertTrue(layer2.modules().size() == 1);
Module m1 = layer1.findModule("m1").get(); Module m1 = layer1.findModule("m1").get();
@ -924,9 +921,9 @@ public class BasicLayerTest {
} }
/** /**
* Attempt to use Layer defineModules to create a layer with a module * Attempt to use defineModules to create a layer with a module defined
* defined to a class loader that already has a module of the same name * to a class loader that already has a module of the same name defined
* defined to the class loader. * to the class loader.
*/ */
@Test(expectedExceptions = { LayerInstantiationException.class }) @Test(expectedExceptions = { LayerInstantiationException.class })
public void testModuleAlreadyDefinedToLoader() { public void testModuleAlreadyDefinedToLoader() {
@ -937,24 +934,24 @@ public class BasicLayerTest {
ModuleFinder finder = ModuleUtils.finderOf(md); ModuleFinder finder = ModuleUtils.finderOf(md);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m")); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.boot().defineModules(cf, mn -> loader); ModuleLayer.boot().defineModules(cf, mn -> loader);
// should throw LayerInstantiationException as m1 already defined to loader // should throw LayerInstantiationException as m1 already defined to loader
Layer.boot().defineModules(cf, mn -> loader); ModuleLayer.boot().defineModules(cf, mn -> loader);
} }
/** /**
* Attempt to use Layer defineModules to create a Layer with a module * Attempt to use defineModules to create a layer with a module containing
* containing package {@code p} where the class loader already has a module * package {@code p} where the class loader already has a module defined
* defined to it containing package {@code p}. * to it containing package {@code p}.
*/ */
@Test(expectedExceptions = { LayerInstantiationException.class }) @Test(expectedExceptions = { LayerInstantiationException.class })
public void testPackageAlreadyInNamedModule() { public void testPackageAlreadyInNamedModule() {
@ -975,24 +972,24 @@ public class BasicLayerTest {
// define m1 containing package p to class loader // define m1 containing package p to class loader
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf1 = parent.resolve(finder, ModuleFinder.of(), Set.of("m1")); Configuration cf1 = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
Layer layer1 = Layer.boot().defineModules(cf1, mn -> loader); ModuleLayer layer1 = ModuleLayer.boot().defineModules(cf1, mn -> loader);
// attempt to define m2 containing package p to class loader // attempt to define m2 containing package p to class loader
Configuration cf2 = parent.resolve(finder, ModuleFinder.of(), Set.of("m2")); Configuration cf2 = parent.resolve(finder, ModuleFinder.of(), Set.of("m2"));
// should throw exception because p already in m1 // should throw exception because p already in m1
Layer layer2 = Layer.boot().defineModules(cf2, mn -> loader); ModuleLayer layer2 = ModuleLayer.boot().defineModules(cf2, mn -> loader);
} }
/** /**
* Attempt to use Layer defineModules to create a Layer with a module * Attempt to use defineModules to create a layer with a module
* containing a package in which a type is already loaded by the class * containing a package in which a type is already loaded by the class
* loader. * loader.
*/ */
@ -1009,15 +1006,15 @@ public class BasicLayerTest {
ModuleFinder finder = ModuleUtils.finderOf(md); ModuleFinder finder = ModuleUtils.finderOf(md);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m")); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
Layer.boot().defineModules(cf, mn -> c.getClassLoader()); ModuleLayer.boot().defineModules(cf, mn -> c.getClassLoader());
} }
/** /**
* Attempt to create a Layer with a module named "java.base". * Attempt to create a layer with a module named "java.base".
*/ */
public void testLayerWithJavaBase() { public void testLayerWithJavaBase() {
ModuleDescriptor descriptor = newBuilder("java.base") ModuleDescriptor descriptor = newBuilder("java.base")
@ -1026,7 +1023,7 @@ public class BasicLayerTest {
ModuleFinder finder = ModuleUtils.finderOf(descriptor); ModuleFinder finder = ModuleUtils.finderOf(descriptor);
Configuration cf = Layer.boot() Configuration cf = ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder, ModuleFinder.of(), Set.of("java.base")); .resolve(finder, ModuleFinder.of(), Set.of("java.base"));
assertTrue(cf.modules().size() == 1); assertTrue(cf.modules().size() == 1);
@ -1034,17 +1031,17 @@ public class BasicLayerTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
try { try {
Layer.boot().defineModules(cf, mn -> new ClassLoader() { }); ModuleLayer.boot().defineModules(cf, mn -> new ClassLoader() { });
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
try { try {
Layer.boot().defineModulesWithOneLoader(cf, scl); ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
try { try {
Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
} }
@ -1056,7 +1053,7 @@ public class BasicLayerTest {
} }
/** /**
* Attempt to create a Layer with a module containing a "java" package. * Attempt to create a layer with a module containing a "java" package.
* This should only be allowed when the module is defined to the platform * This should only be allowed when the module is defined to the platform
* class loader. * class loader.
*/ */
@ -1065,7 +1062,7 @@ public class BasicLayerTest {
ModuleDescriptor descriptor = newBuilder(mn).packages(Set.of(pn)).build(); ModuleDescriptor descriptor = newBuilder(mn).packages(Set.of(pn)).build();
ModuleFinder finder = ModuleUtils.finderOf(descriptor); ModuleFinder finder = ModuleUtils.finderOf(descriptor);
Configuration cf = Layer.boot() Configuration cf = ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder, ModuleFinder.of(), Set.of(mn)); .resolve(finder, ModuleFinder.of(), Set.of(mn));
assertTrue(cf.modules().size() == 1); assertTrue(cf.modules().size() == 1);
@ -1074,33 +1071,33 @@ public class BasicLayerTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
try { try {
Layer.boot().defineModules(cf, _mn -> new ClassLoader() { }); ModuleLayer.boot().defineModules(cf, _mn -> new ClassLoader() { });
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
try { try {
Layer.boot().defineModulesWithOneLoader(cf, scl); ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
try { try {
Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException e) { } } catch (LayerInstantiationException e) { }
// create layer with module defined to platform class loader // create layer with module defined to platform class loader
Layer layer = Layer.boot().defineModules(cf, _mn -> pcl); ModuleLayer layer = ModuleLayer.boot().defineModules(cf, _mn -> pcl);
Optional<Module> om = layer.findModule(mn); Optional<Module> om = layer.findModule(mn);
assertTrue(om.isPresent()); assertTrue(om.isPresent());
Module foo = om.get(); Module foo = om.get();
assertTrue(foo.getClassLoader() == pcl); assertTrue(foo.getClassLoader() == pcl);
assertTrue(foo.getPackages().length == 1); assertTrue(foo.getPackages().size() == 1);
assertTrue(foo.getPackages()[0].equals(pn)); assertTrue(foo.getPackages().iterator().next().equals(pn));
} }
/** /**
* Attempt to create a Layer with a module defined to the boot loader * Attempt to create a layer with a module defined to the boot loader
*/ */
@Test(expectedExceptions = { LayerInstantiationException.class }) @Test(expectedExceptions = { LayerInstantiationException.class })
public void testLayerWithBootLoader() { public void testLayerWithBootLoader() {
@ -1109,50 +1106,47 @@ public class BasicLayerTest {
ModuleFinder finder = ModuleUtils.finderOf(descriptor); ModuleFinder finder = ModuleUtils.finderOf(descriptor);
Configuration cf = Layer.boot() Configuration cf = ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder, ModuleFinder.of(), Set.of("m1")); .resolve(finder, ModuleFinder.of(), Set.of("m1"));
assertTrue(cf.modules().size() == 1); assertTrue(cf.modules().size() == 1);
Layer.boot().defineModules(cf, mn -> null ); ModuleLayer.boot().defineModules(cf, mn -> null );
} }
/** /**
* Parent of configuration != configuration of parent Layer * Parent of configuration != configuration of parent layer
*/ */
@Test(expectedExceptions = { IllegalArgumentException.class }) @Test(expectedExceptions = { IllegalArgumentException.class })
public void testIncorrectParent1() { public void testIncorrectParent1() {
ModuleDescriptor descriptor1 = newBuilder("m1") ModuleDescriptor descriptor1 = newBuilder("m1")
.requires("java.base") .requires("java.base")
.build(); .build();
ModuleFinder finder = ModuleUtils.finderOf(descriptor1); ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
Configuration parent = Layer.boot().configuration(); Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1")); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.empty().defineModules(cf, mn -> loader); ModuleLayer.empty().defineModules(cf, mn -> loader);
} }
/** /**
* Parent of configuration != configuration of parent Layer * Parent of configuration != configuration of parent layer
*/ */
@Test(expectedExceptions = { IllegalArgumentException.class }) @Test(expectedExceptions = { IllegalArgumentException.class })
public void testIncorrectParent2() { public void testIncorrectParent2() {
ModuleDescriptor descriptor1 = newBuilder("m1").build();
ModuleDescriptor descriptor1 = newBuilder("m1")
.build();
ModuleFinder finder = ModuleUtils.finderOf(descriptor1); ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
Configuration cf = resolve(finder, "m1"); Configuration cf = resolve(finder, "m1");
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.boot().defineModules(cf, mn -> loader); ModuleLayer.boot().defineModules(cf, mn -> loader);
} }
@ -1161,35 +1155,35 @@ public class BasicLayerTest {
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testCreateWithNull1() { public void testCreateWithNull1() {
ClassLoader loader = new ClassLoader() { }; ClassLoader loader = new ClassLoader() { };
Layer.empty().defineModules(null, mn -> loader); ModuleLayer.empty().defineModules(null, mn -> loader);
} }
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testCreateWithNull2() { public void testCreateWithNull2() {
Configuration cf = resolve(Layer.boot().configuration(), ModuleFinder.of()); Configuration cf = resolve(ModuleLayer.boot().configuration(), ModuleFinder.of());
Layer.boot().defineModules(cf, null); ModuleLayer.boot().defineModules(cf, null);
} }
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testCreateWithNull3() { public void testCreateWithNull3() {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer.empty().defineModulesWithOneLoader(null, scl); ModuleLayer.empty().defineModulesWithOneLoader(null, scl);
} }
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testCreateWithNull4() { public void testCreateWithNull4() {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer.empty().defineModulesWithManyLoaders(null, scl); ModuleLayer.empty().defineModulesWithManyLoaders(null, scl);
} }
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testFindModuleWithNull() { public void testFindModuleWithNull() {
Layer.boot().findModule(null); ModuleLayer.boot().findModule(null);
} }
@Test(expectedExceptions = { NullPointerException.class }) @Test(expectedExceptions = { NullPointerException.class })
public void testFindLoaderWithNull() { public void testFindLoaderWithNull() {
Layer.boot().findLoader(null); ModuleLayer.boot().findLoader(null);
} }
@ -1198,7 +1192,7 @@ public class BasicLayerTest {
@Test(expectedExceptions = { UnsupportedOperationException.class }) @Test(expectedExceptions = { UnsupportedOperationException.class })
public void testImmutableSet() { public void testImmutableSet() {
Module base = Object.class.getModule(); Module base = Object.class.getModule();
Layer.boot().modules().add(base); ModuleLayer.boot().modules().add(base);
} }

View File

@ -27,7 +27,7 @@
* @modules jdk.compiler * @modules jdk.compiler
* @build LayerAndLoadersTest CompilerUtils ModuleUtils * @build LayerAndLoadersTest CompilerUtils ModuleUtils
* @run testng LayerAndLoadersTest * @run testng LayerAndLoadersTest
* @summary Tests for java.lang.reflect.Layer@createWithXXX methods * @summary Tests for java.lang.ModuleLayer@defineModulesWithXXX methods
*/ */
import java.io.IOException; import java.io.IOException;
@ -36,10 +36,7 @@ import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference; import java.lang.module.ModuleReference;
import java.lang.reflect.Layer;
import java.lang.reflect.LayerInstantiationException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Module;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -74,7 +71,7 @@ public class LayerAndLoadersTest {
/** /**
* Basic test of Layer defineModulesWithOneLoader * Basic test of ModuleLayer.defineModulesWithOneLoader
* *
* Test scenario: * Test scenario:
* m1 requires m2 and m3 * m1 requires m2 and m3
@ -85,7 +82,7 @@ public class LayerAndLoadersTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
checkLayer(layer, "m1", "m2", "m3"); checkLayer(layer, "m1", "m2", "m3");
@ -103,7 +100,7 @@ public class LayerAndLoadersTest {
/** /**
* Basic test of Layer defineModulesWithManyLoaders * Basic test of ModuleLayer.defineModulesWithManyLoaders
* *
* Test scenario: * Test scenario:
* m1 requires m2 and m3 * m1 requires m2 and m3
@ -114,7 +111,7 @@ public class LayerAndLoadersTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
checkLayer(layer, "m1", "m2", "m3"); checkLayer(layer, "m1", "m2", "m3");
@ -135,8 +132,8 @@ public class LayerAndLoadersTest {
/** /**
* Basic test of Layer defineModulesWithOneLoader where one of the modules * Basic test of ModuleLayer.defineModulesWithOneLoader where one of the
* is a service provider module. * modules is a service provider module.
* *
* Test scenario: * Test scenario:
* m1 requires m2 and m3 * m1 requires m2 and m3
@ -149,7 +146,7 @@ public class LayerAndLoadersTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
checkLayer(layer, "m1", "m2", "m3", "m4"); checkLayer(layer, "m1", "m2", "m3", "m4");
@ -176,7 +173,7 @@ public class LayerAndLoadersTest {
/** /**
* Basic test of Layer defineModulesWithManyLoaders where one of the * Basic test of ModuleLayer.defineModulesWithManyLoaders where one of the
* modules is a service provider module. * modules is a service provider module.
* *
* Test scenario: * Test scenario:
@ -190,7 +187,7 @@ public class LayerAndLoadersTest {
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
checkLayer(layer, "m1", "m2", "m3", "m4"); checkLayer(layer, "m1", "m2", "m3", "m4");
@ -239,19 +236,19 @@ public class LayerAndLoadersTest {
String cn = this.getClass().getName(); String cn = this.getClass().getName();
// one loader // one loader
Layer layer = Layer.boot().defineModulesWithOneLoader(cf, parent); ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, parent);
testLoad(layer, cn); testLoad(layer, cn);
// one loader with boot loader as parent // one loader with boot loader as parent
layer = Layer.boot().defineModulesWithOneLoader(cf, null); layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, null);
testLoadFail(layer, cn); testLoadFail(layer, cn);
// many loaders // many loaders
layer = Layer.boot().defineModulesWithManyLoaders(cf, parent); layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, parent);
testLoad(layer, cn); testLoad(layer, cn);
// many loader with boot loader as parent // many loader with boot loader as parent
layer = Layer.boot().defineModulesWithManyLoaders(cf, null); layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, null);
testLoadFail(layer, cn); testLoadFail(layer, cn);
} }
@ -274,25 +271,25 @@ public class LayerAndLoadersTest {
ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
Configuration cf = Layer.boot() Configuration cf = ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder, ModuleFinder.of(), Set.of("m1", "m2")); .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
// cannot define both module m1 and m2 to the same class loader // cannot define both module m1 and m2 to the same class loader
try { try {
Layer.boot().defineModulesWithOneLoader(cf, null); ModuleLayer.boot().defineModulesWithOneLoader(cf, null);
assertTrue(false); assertTrue(false);
} catch (LayerInstantiationException expected) { } } catch (LayerInstantiationException expected) { }
// should be okay to have one module per class loader // should be okay to have one module per class loader
Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, null); ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, null);
checkLayer(layer, "m1", "m2"); checkLayer(layer, "m1", "m2");
} }
/** /**
* Test Layer defineModulesWithXXX with split delegation. * Test ModuleLayer.defineModulesWithXXX with split delegation.
* *
* Test scenario: * Test scenario:
* layer1: m1 exports p, m2 exports p * layer1: m1 exports p, m2 exports p
@ -308,11 +305,11 @@ public class LayerAndLoadersTest {
ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
Configuration cf1 = Layer.boot() Configuration cf1 = ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder1, ModuleFinder.of(), Set.of("m1", "m2")); .resolve(finder1, ModuleFinder.of(), Set.of("m1", "m2"));
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null); ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
checkLayer(layer1, "m1", "m2"); checkLayer(layer1, "m1", "m2");
ModuleDescriptor descriptor3 ModuleDescriptor descriptor3
@ -333,14 +330,14 @@ public class LayerAndLoadersTest {
} catch (LayerInstantiationException expected) { } } catch (LayerInstantiationException expected) { }
// no split delegation when modules have their own class loader // no split delegation when modules have their own class loader
Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null); ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
checkLayer(layer2, "m3", "m4"); checkLayer(layer2, "m3", "m4");
} }
/** /**
* Test Layer defineModulesWithXXX when the modules that override same * Test ModuleLayer.defineModulesWithXXX when the modules that override same
* named modules in the parent layer. * named modules in the parent layer.
* *
* Test scenario: * Test scenario:
@ -351,14 +348,14 @@ public class LayerAndLoadersTest {
Configuration cf1 = resolve("m1"); Configuration cf1 = resolve("m1");
Layer layer1 = Layer.boot().defineModulesWithOneLoader(cf1, null); ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithOneLoader(cf1, null);
checkLayer(layer1, "m1", "m2", "m3"); checkLayer(layer1, "m1", "m2", "m3");
ModuleFinder finder = ModuleFinder.of(MODS_DIR); ModuleFinder finder = ModuleFinder.of(MODS_DIR);
Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(), Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
Set.of("m1")); Set.of("m1"));
Layer layer2 = layer1.defineModulesWithOneLoader(cf2, null); ModuleLayer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
checkLayer(layer2, "m1", "m2", "m3"); checkLayer(layer2, "m1", "m2", "m3");
invoke(layer1, "m1", "p.Main"); invoke(layer1, "m1", "p.Main");
@ -400,14 +397,14 @@ public class LayerAndLoadersTest {
Configuration cf1 = resolve("m1"); Configuration cf1 = resolve("m1");
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null); ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
checkLayer(layer1, "m1", "m2", "m3"); checkLayer(layer1, "m1", "m2", "m3");
ModuleFinder finder = ModuleFinder.of(MODS_DIR); ModuleFinder finder = ModuleFinder.of(MODS_DIR);
Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(), Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
Set.of("m1")); Set.of("m1"));
Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null); ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
checkLayer(layer2, "m1", "m2", "m3"); checkLayer(layer2, "m1", "m2", "m3");
invoke(layer1, "m1", "p.Main"); invoke(layer1, "m1", "p.Main");
@ -484,7 +481,7 @@ public class LayerAndLoadersTest {
/** /**
* Test Layer defineModulesWithXXX when the modules that override same * Test ModuleLayer.defineModulesWithXXX when the modules that override same
* named modules in the parent layer. * named modules in the parent layer.
* *
* layer1: m1, m2, m3 => same loader * layer1: m1, m2, m3 => same loader
@ -494,7 +491,7 @@ public class LayerAndLoadersTest {
Configuration cf1 = resolve("m1"); Configuration cf1 = resolve("m1");
Layer layer1 = Layer.boot().defineModulesWithOneLoader(cf1, null); ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithOneLoader(cf1, null);
checkLayer(layer1, "m1", "m2", "m3"); checkLayer(layer1, "m1", "m2", "m3");
ModuleFinder finder = finderFor("m1", "m3"); ModuleFinder finder = finderFor("m1", "m3");
@ -502,7 +499,7 @@ public class LayerAndLoadersTest {
Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(), Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
Set.of("m1")); Set.of("m1"));
Layer layer2 = layer1.defineModulesWithOneLoader(cf2, null); ModuleLayer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
checkLayer(layer2, "m1", "m3"); checkLayer(layer2, "m1", "m3");
invoke(layer1, "m1", "p.Main"); invoke(layer1, "m1", "p.Main");
@ -531,7 +528,7 @@ public class LayerAndLoadersTest {
Configuration cf1 = resolve("m1"); Configuration cf1 = resolve("m1");
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null); ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
checkLayer(layer1, "m1", "m2", "m3"); checkLayer(layer1, "m1", "m2", "m3");
ModuleFinder finder = finderFor("m1", "m3"); ModuleFinder finder = finderFor("m1", "m3");
@ -539,7 +536,7 @@ public class LayerAndLoadersTest {
Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(), Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
Set.of("m1")); Set.of("m1"));
Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null); ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
checkLayer(layer2, "m1", "m3"); checkLayer(layer2, "m1", "m3");
invoke(layer1, "m1", "p.Main"); invoke(layer1, "m1", "p.Main");
@ -579,7 +576,7 @@ public class LayerAndLoadersTest {
public void testResourcesOneLoader() throws Exception { public void testResourcesOneLoader() throws Exception {
Configuration cf = resolve("m1"); Configuration cf = resolve("m1");
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader("m1"); ClassLoader loader = layer.findLoader("m1");
testResourceLoading(loader, "p/Main.class"); testResourceLoading(loader, "p/Main.class");
} }
@ -591,7 +588,7 @@ public class LayerAndLoadersTest {
public void testResourcesManyLoaders() throws Exception { public void testResourcesManyLoaders() throws Exception {
Configuration cf = resolve("m1"); Configuration cf = resolve("m1");
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl); ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
ClassLoader loader = layer.findLoader("m1"); ClassLoader loader = layer.findLoader("m1");
testResourceLoading(loader, "p/Main.class"); testResourceLoading(loader, "p/Main.class");
} }
@ -623,7 +620,7 @@ public class LayerAndLoadersTest {
*/ */
private static Configuration resolve(String... roots) { private static Configuration resolve(String... roots) {
ModuleFinder finder = ModuleFinder.of(MODS_DIR); ModuleFinder finder = ModuleFinder.of(MODS_DIR);
return Layer.boot() return ModuleLayer.boot()
.configuration() .configuration()
.resolve(finder, ModuleFinder.of(), Set.of(roots)); .resolve(finder, ModuleFinder.of(), Set.of(roots));
} }
@ -634,7 +631,7 @@ public class LayerAndLoadersTest {
*/ */
private static Configuration resolveAndBind(String... roots) { private static Configuration resolveAndBind(String... roots) {
ModuleFinder finder = ModuleFinder.of(MODS_DIR); ModuleFinder finder = ModuleFinder.of(MODS_DIR);
return Layer.boot() return ModuleLayer.boot()
.configuration() .configuration()
.resolveAndBind(finder, ModuleFinder.of(), Set.of(roots)); .resolveAndBind(finder, ModuleFinder.of(), Set.of(roots));
} }
@ -644,7 +641,7 @@ public class LayerAndLoadersTest {
* Invokes the static void main(String[]) method on the given class * Invokes the static void main(String[]) method on the given class
* in the given module. * in the given module.
*/ */
private static void invoke(Layer layer, String mn, String mc) throws Exception { private static void invoke(ModuleLayer layer, String mn, String mc) throws Exception {
ClassLoader loader = layer.findLoader(mn); ClassLoader loader = layer.findLoader(mn);
Class<?> c = loader.loadClass(mc); Class<?> c = loader.loadClass(mc);
Method mainMethod = c.getMethod("main", String[].class); Method mainMethod = c.getMethod("main", String[].class);
@ -656,7 +653,7 @@ public class LayerAndLoadersTest {
* Checks that the given layer contains exactly the expected modules * Checks that the given layer contains exactly the expected modules
* (by name). * (by name).
*/ */
private void checkLayer(Layer layer, String ... expected) { private void checkLayer(ModuleLayer layer, String ... expected) {
Set<String> names = layer.modules().stream() Set<String> names = layer.modules().stream()
.map(Module::getName) .map(Module::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
@ -671,7 +668,7 @@ public class LayerAndLoadersTest {
* Test that a class can be loaded via the class loader of all modules * Test that a class can be loaded via the class loader of all modules
* in the given layer. * in the given layer.
*/ */
static void testLoad(Layer layer, String cn) throws Exception { static void testLoad(ModuleLayer layer, String cn) throws Exception {
for (Module m : layer.modules()) { for (Module m : layer.modules()) {
ClassLoader l = m.getClassLoader(); ClassLoader l = m.getClassLoader();
l.loadClass(cn); l.loadClass(cn);
@ -683,7 +680,7 @@ public class LayerAndLoadersTest {
* Test that a class cannot be loaded via any of the class loaders of * Test that a class cannot be loaded via any of the class loaders of
* the modules in the given layer. * the modules in the given layer.
*/ */
static void testLoadFail(Layer layer, String cn) throws Exception { static void testLoadFail(ModuleLayer layer, String cn) throws Exception {
for (Module m : layer.modules()) { for (Module m : layer.modules()) {
ClassLoader l = m.getClassLoader(); ClassLoader l = m.getClassLoader();
try { try {

View File

@ -26,14 +26,12 @@
* @library /lib/testlibrary * @library /lib/testlibrary
* @build LayerControllerTest ModuleUtils * @build LayerControllerTest ModuleUtils
* @run testng LayerControllerTest * @run testng LayerControllerTest
* @summary Basic tests for java.lang.reflect.Layer.Controller * @summary Basic tests for java.lang.ModuleLayer.Controller
*/ */
import java.lang.module.Configuration; import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder; import java.lang.module.ModuleFinder;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -48,7 +46,7 @@ public class LayerControllerTest {
* Module m1 contains p1, reads java.base, does not export/open any package * Module m1 contains p1, reads java.base, does not export/open any package
* Module m2 contains p2, reads java.base, does not export/open any package * Module m2 contains p2, reads java.base, does not export/open any package
*/ */
private Layer.Controller createTestLayer() { private ModuleLayer.Controller createTestLayer() {
ModuleDescriptor descriptor1 ModuleDescriptor descriptor1
= ModuleDescriptor.newModule("m1") = ModuleDescriptor.newModule("m1")
.packages(Set.of("p1")) .packages(Set.of("p1"))
@ -62,17 +60,17 @@ public class LayerControllerTest {
.build(); .build();
ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
Layer bootLayer = Layer.boot(); ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer.configuration() Configuration cf = bootLayer.configuration()
.resolve(finder, ModuleFinder.of(), Set.of("m1", "m2")); .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
ClassLoader scl = ClassLoader.getSystemClassLoader(); ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer.Controller controller ModuleLayer.Controller controller
= Layer.defineModulesWithOneLoader(cf, List.of(bootLayer), scl); = ModuleLayer.defineModulesWithOneLoader(cf, List.of(bootLayer), scl);
Layer layer = controller.layer(); ModuleLayer layer = controller.layer();
assertTrue(layer.modules().size() == 2); assertTrue(layer.modules().size() == 2);
assertTrue(layer.findModule("m1").isPresent()); assertTrue(layer.findModule("m1").isPresent());
@ -82,12 +80,12 @@ public class LayerControllerTest {
} }
/** /**
* Basic test of Layer.Controller to update modules m1 and m2 to read and * Basic test of Controller to update modules m1 and m2 to read and
* open packages to each other. * open packages to each other.
*/ */
public void testBasic() { public void testBasic() {
Layer.Controller controller = createTestLayer(); ModuleLayer.Controller controller = createTestLayer();
Layer layer = controller.layer(); ModuleLayer layer = controller.layer();
Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new); Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new); Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
@ -132,8 +130,8 @@ public class LayerControllerTest {
* Test invalid argument handling * Test invalid argument handling
*/ */
public void testBadArguments() { public void testBadArguments() {
Layer.Controller controller = createTestLayer(); ModuleLayer.Controller controller = createTestLayer();
Layer layer = controller.layer(); ModuleLayer layer = controller.layer();
Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new); Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new); Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
Module base = Object.class.getModule(); Module base = Object.class.getModule();
@ -161,8 +159,8 @@ public class LayerControllerTest {
* Test null handling * Test null handling
*/ */
public void testNulls() { public void testNulls() {
Layer.Controller controller = createTestLayer(); ModuleLayer.Controller controller = createTestLayer();
Layer layer = controller.layer(); ModuleLayer layer = controller.layer();
Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new); Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new); Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
assertTrue(m1 != null); assertTrue(m1 != null);

View File

@ -22,7 +22,7 @@
*/ */
/** /**
* Supporting class for tests of java.lang.reflect.Layer. * Supporting class for tests of java.lang.ModuleLayer.
*/ */
package layertest; package layertest;

Some files were not shown because too many files have changed in this diff Show More