addrs = ni.getInetAddresses();
+ while (addrs.hasMoreElements()) {
+ InetAddress addr = addrs.nextElement();
+ if (!addr.isAnyLocalAddress()) {
+ if (addr instanceof Inet4Address) {
+ ip4 = true;
+ } else if (addr instanceof Inet6Address) {
+ ip6 = true;
+ }
+ }
+ }
+
+ boolean isLoopback = ni.isLoopback();
+ boolean isPPP = ni.isPointToPoint();
+ if (!isLoopback && !isPPP) {
+ // found an interface that is not the loopback or a
+ // point-to-point interface
+ if (preferred == null) {
+ preferred = ni;
+ } else if (ip4 && ip6){
return ni;
}
- if (ppp == null && isPPP)
- ppp = ni;
- if (loopback == null && isLoopback)
- loopback = ni;
}
+ if (ppp == null && isPPP)
+ ppp = ni;
+ if (loopback == null && isLoopback)
+ loopback = ni;
+
} catch (IOException skip) { }
}
- return (ppp != null) ? ppp : loopback;
+ if (preferred != null) {
+ return preferred;
+ } else {
+ return (ppp != null) ? ppp : loopback;
+ }
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -149,6 +149,7 @@
* Ensures that the bytes of this key are
* set to zero when there are no more references to it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (this.key != null) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -150,6 +150,7 @@
* Ensures that the bytes of this key are
* set to zero when there are no more references to it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (this.key != null) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -145,6 +145,7 @@
* Ensures that the password bytes of this key are
* set to zero when there are no more references to it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (this.key != null) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -267,6 +267,7 @@
* Ensures that the password bytes of this key are
* erased when there are no more references to it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (this.passwd != null) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/io/BufferedReader.java
--- a/jdk/src/java.base/share/classes/java/io/BufferedReader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/io/BufferedReader.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -297,14 +297,15 @@
/**
* Reads a line of text. A line is considered to be terminated by any one
- * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
- * followed immediately by a linefeed.
+ * of a line feed ('\n'), a carriage return ('\r'), a carriage return
+ * followed immediately by a line feed, or by reaching the end-of-file
+ * (EOF).
*
* @param ignoreLF If true, the next '\n' will be skipped
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
- * stream has been reached
+ * stream has been reached without reading any characters
*
* @see java.io.LineNumberReader#readLine()
*
@@ -375,12 +376,13 @@
/**
* Reads a line of text. A line is considered to be terminated by any one
- * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
- * followed immediately by a linefeed.
+ * of a line feed ('\n'), a carriage return ('\r'), a carriage return
+ * followed immediately by a line feed, or by reaching the end-of-file
+ * (EOF).
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
- * stream has been reached
+ * stream has been reached without reading any characters
*
* @exception IOException If an I/O error occurs
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/io/FileInputStream.java
--- a/jdk/src/java.base/share/classes/java/io/FileInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/io/FileInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -413,9 +413,19 @@
* Ensures that the close
method of this file input stream is
* called when there are no more references to it.
*
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
+ *
* @exception IOException if an I/O error occurs.
* @see java.io.FileInputStream#close()
*/
+ @Deprecated(since="9")
protected void finalize() throws IOException {
if ((fd != null) && (fd != FileDescriptor.in)) {
/* if fd is shared, the references in FileDescriptor
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/io/FileOutputStream.java
--- a/jdk/src/java.base/share/classes/java/io/FileOutputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/io/FileOutputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -427,9 +427,18 @@
* close
method of this file output stream is
* called when there are no more references to this stream.
*
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
* @exception IOException if an I/O error occurs.
* @see java.io.FileInputStream#close()
*/
+ @Deprecated(since="9")
protected void finalize() throws IOException {
if (fd != null) {
if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/io/ObjectInputFilter.java
--- a/jdk/src/java.base/share/classes/java/io/ObjectInputFilter.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/io/ObjectInputFilter.java Wed Jul 05 23:13:02 2017 +0200
@@ -322,7 +322,7 @@
* Other patterns match or reject class or package name
* as returned from {@link Class#getName() Class.getName()} and
* 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,
* not the array type.
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Class.java
--- a/jdk/src/java.base/share/classes/java/lang/Class.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@@ -2561,21 +2560,16 @@
public InputStream getResourceAsStream(String name) {
name = resolveName(name);
- Module module = getModule();
- if (module.isNamed()) {
- if (Resources.canEncapsulate(name)) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != module) {
- Set packages = module.getDescriptor().packages();
- String pn = Resources.toPackageName(name);
- if (packages.contains(pn) && !module.isOpen(pn, caller)) {
- // resource is in package not open to caller
- return null;
- }
- }
+ Module thisModule = getModule();
+ if (thisModule.isNamed()) {
+ // check if resource can be located by caller
+ if (Resources.canEncapsulate(name)
+ && !isOpenToCaller(name, Reflection.getCallerClass())) {
+ return null;
}
- String mn = module.getName();
+ // resource not encapsulated or in package open to caller
+ String mn = thisModule.getName();
ClassLoader cl = getClassLoader0();
try {
@@ -2663,20 +2657,16 @@
public URL getResource(String name) {
name = resolveName(name);
- Module module = getModule();
- if (module.isNamed()) {
- if (Resources.canEncapsulate(name)) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != module) {
- Set packages = module.getDescriptor().packages();
- String pn = Resources.toPackageName(name);
- if (packages.contains(pn) && !module.isOpen(pn, caller)) {
- // resource is in package not open to caller
- return null;
- }
- }
+ Module thisModule = getModule();
+ if (thisModule.isNamed()) {
+ // check if resource can be located by caller
+ if (Resources.canEncapsulate(name)
+ && !isOpenToCaller(name, Reflection.getCallerClass())) {
+ return null;
}
- String mn = getModule().getName();
+
+ // resource not encapsulated or in package open to caller
+ String mn = thisModule.getName();
ClassLoader cl = getClassLoader0();
try {
if (cl == null) {
@@ -2698,10 +2688,36 @@
}
}
+ /**
+ * 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 */
private static java.security.ProtectionDomain allPermDomain;
-
/**
* Returns the {@code ProtectionDomain} of this class. If there is a
* security manager installed, this method first calls the security
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/ClassLoader.java
--- a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,7 +31,6 @@
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
-import java.lang.reflect.Module;
import java.net.URL;
import java.security.AccessController;
import java.security.AccessControlContext;
@@ -352,9 +351,7 @@
private ClassLoader(Void unused, String name, ClassLoader parent) {
this.name = name;
this.parent = parent;
- this.unnamedModule
- = SharedSecrets.getJavaLangReflectModuleAccess()
- .defineUnnamedModule(this);
+ this.unnamedModule = new Module(this);
if (ParallelLoaders.isRegistered(this.getClass())) {
parallelLockMap = new ConcurrentHashMap<>();
package2certs = new ConcurrentHashMap<>();
@@ -2348,6 +2345,7 @@
this.isBuiltin = isBuiltin;
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
synchronized (loadedLibraryNames) {
if (fromClass.getClassLoader() != null && loaded) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Comparable.java
--- a/jdk/src/java.base/share/classes/java/lang/Comparable.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Comparable.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -124,7 +124,7 @@
* {@code sgn(}expression {@code )} designates the mathematical
* signum function, which is defined to return one of {@code -1},
* {@code 0}, or {@code 1} according to whether the value of
- * expression is negative, zero or positive.
+ * expression is negative, zero, or positive, respectively.
*
* @param o the object to be compared.
* @return a negative integer, zero, or a positive integer as this object
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Enum.java
--- a/jdk/src/java.base/share/classes/java/lang/Enum.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Enum.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, 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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -243,6 +243,7 @@
/**
* enum classes cannot have finalize methods.
*/
+ @SuppressWarnings("deprecation")
protected final void finalize() { }
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/LayerInstantiationException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/LayerInstantiationException.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, 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;
+
+/**
+ * Thrown when creating a {@linkplain ModuleLayer module layer} fails.
+ *
+ * @see ModuleLayer
+ * @since 9
+ * @spec JPMS
+ */
+public class LayerInstantiationException extends RuntimeException {
+ private static final long serialVersionUID = -906239691613568347L;
+
+ /**
+ * Constructs a {@code LayerInstantiationException} with no detail message.
+ */
+ public LayerInstantiationException() {
+ }
+
+ /**
+ * Constructs a {@code LayerInstantiationException} with the given detail
+ * message.
+ *
+ * @param msg
+ * The detail message; can be {@code null}
+ */
+ public LayerInstantiationException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a {@code LayerInstantiationException} with the given cause.
+ *
+ * @param cause
+ * The cause; can be {@code null}
+ */
+ public LayerInstantiationException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a {@code FindException} with the given detail message
+ * and cause.
+ *
+ * @param msg
+ * The detail message; can be {@code null}
+ * @param cause
+ * The cause; can be {@code null}
+ */
+ public LayerInstantiationException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+}
+
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Module.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Module.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,1586 @@
+/*
+ * Copyright (c) 2014, 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.module.Configuration;
+import java.lang.module.ModuleReference;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Exports;
+import java.lang.module.ModuleDescriptor.Opens;
+import java.lang.module.ModuleDescriptor.Version;
+import java.lang.module.ResolvedModule;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URI;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import jdk.internal.loader.BuiltinClassLoader;
+import jdk.internal.loader.BootLoader;
+import jdk.internal.misc.JavaLangAccess;
+import jdk.internal.misc.SharedSecrets;
+import jdk.internal.module.ServicesCatalog;
+import jdk.internal.module.Resources;
+import jdk.internal.org.objectweb.asm.AnnotationVisitor;
+import jdk.internal.org.objectweb.asm.Attribute;
+import jdk.internal.org.objectweb.asm.ClassReader;
+import jdk.internal.org.objectweb.asm.ClassVisitor;
+import jdk.internal.org.objectweb.asm.ClassWriter;
+import jdk.internal.org.objectweb.asm.Opcodes;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+import sun.security.util.SecurityConstants;
+
+/**
+ * Represents a run-time module, either {@link #isNamed() named} or unnamed.
+ *
+ * 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
+ * machine to create a {@linkplain ModuleLayer module layer}.
+ *
+ * An unnamed module does not have a name. There is an unnamed module for
+ * each {@link ClassLoader ClassLoader}, obtained by invoking its {@link
+ * ClassLoader#getUnnamedModule() getUnnamedModule} method. All types that are
+ * not in a named module are members of their defining class loader's unnamed
+ * module.
+ *
+ * The package names that are parameters or returned by methods defined in
+ * this class are the fully-qualified names of the packages as defined in
+ * section 6.5.3 of The Java™ Language Specification , for
+ * example, {@code "java.lang"}.
+ *
+ * Unless otherwise specified, passing a {@code null} argument to a method
+ * in this class causes a {@link NullPointerException NullPointerException} to
+ * be thrown.
+ *
+ * @since 9
+ * @spec JPMS
+ * @see Class#getModule()
+ */
+
+public final class Module implements AnnotatedElement {
+
+ // the layer that contains this module, can be null
+ private final ModuleLayer layer;
+
+ // module name and loader, these fields are read by VM
+ private final String name;
+ private final ClassLoader loader;
+
+ // the module descriptor
+ private final ModuleDescriptor descriptor;
+
+
+ /**
+ * Creates a new named Module. The resulting Module will be defined to the
+ * VM but will not read any other modules, will not have any exports setup
+ * and will not be registered in the service catalog.
+ */
+ Module(ModuleLayer layer,
+ ClassLoader loader,
+ ModuleDescriptor descriptor,
+ URI uri)
+ {
+ this.layer = layer;
+ this.name = descriptor.name();
+ this.loader = loader;
+ this.descriptor = descriptor;
+
+ // define module to VM
+
+ boolean isOpen = descriptor.isOpen();
+ Version version = descriptor.version().orElse(null);
+ String vs = Objects.toString(version, null);
+ String loc = Objects.toString(uri, null);
+ String[] packages = descriptor.packages().toArray(new String[0]);
+ defineModule0(this, isOpen, vs, loc, packages);
+ }
+
+
+ /**
+ * Create the unnamed Module for the given ClassLoader.
+ *
+ * @see ClassLoader#getUnnamedModule
+ */
+ Module(ClassLoader loader) {
+ this.layer = null;
+ this.name = null;
+ this.loader = loader;
+ this.descriptor = null;
+ }
+
+
+ /**
+ * Creates a named module but without defining the module to the VM.
+ *
+ * @apiNote This constructor is for VM white-box testing.
+ */
+ Module(ClassLoader loader, ModuleDescriptor descriptor) {
+ this.layer = null;
+ this.name = descriptor.name();
+ this.loader = loader;
+ this.descriptor = descriptor;
+ }
+
+
+
+ /**
+ * Returns {@code true} if this module is a named module.
+ *
+ * @return {@code true} if this is a named module
+ *
+ * @see ClassLoader#getUnnamedModule()
+ */
+ public boolean isNamed() {
+ return name != null;
+ }
+
+ /**
+ * Returns the module name or {@code null} if this module is an unnamed
+ * module.
+ *
+ * @return The module name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the {@code ClassLoader} for this module.
+ *
+ * If there is a security manager then its {@code checkPermission}
+ * method if first called with a {@code RuntimePermission("getClassLoader")}
+ * permission to check that the caller is allowed to get access to the
+ * class loader.
+ *
+ * @return The class loader for this module
+ *
+ * @throws SecurityException
+ * If denied by the security manager
+ */
+ public ClassLoader getClassLoader() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
+ }
+ return loader;
+ }
+
+ /**
+ * Returns the module descriptor for this module or {@code null} if this
+ * module is an unnamed module.
+ *
+ * @return The module descriptor for this module
+ */
+ public ModuleDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ /**
+ * Returns the layer that contains this module or {@code null} if this
+ * module is not in a layer.
+ *
+ * A module layer contains named modules and therefore this method always
+ * returns {@code null} when invoked on an unnamed module.
+ *
+ * Dynamic modules are
+ * named modules that are generated at runtime. A dynamic module may or may
+ * not be in a module layer.
+ *
+ * @return The module layer that contains this module
+ *
+ * @see java.lang.reflect.Proxy
+ */
+ public ModuleLayer getLayer() {
+ if (isNamed()) {
+ ModuleLayer layer = this.layer;
+ if (layer != null)
+ return layer;
+
+ // special-case java.base as it is created before the boot layer
+ if (loader == null && name.equals("java.base")) {
+ return ModuleLayer.boot();
+ }
+ }
+ return null;
+ }
+
+
+ // --
+
+ // special Module to mean "all unnamed modules"
+ private static final Module ALL_UNNAMED_MODULE = new Module(null);
+
+ // special Module to mean "everyone"
+ private static final Module EVERYONE_MODULE = new Module(null);
+
+ // set contains EVERYONE_MODULE, used when a package is opened or
+ // exported unconditionally
+ private static final Set EVERYONE_SET = Set.of(EVERYONE_MODULE);
+
+
+ // -- readability --
+
+ // the modules that this module reads
+ private volatile Set reads;
+
+ // additional module (2nd key) that some module (1st key) reflectively reads
+ private static final WeakPairMap reflectivelyReads
+ = new WeakPairMap<>();
+
+
+ /**
+ * Indicates if this module reads the given module. This method returns
+ * {@code true} if invoked to test if this module reads itself. It also
+ * returns {@code true} if invoked on an unnamed module (as unnamed
+ * modules read all modules).
+ *
+ * @param other
+ * The other module
+ *
+ * @return {@code true} if this module reads {@code other}
+ *
+ * @see #addReads(Module)
+ */
+ public boolean canRead(Module other) {
+ Objects.requireNonNull(other);
+
+ // an unnamed module reads all modules
+ if (!this.isNamed())
+ return true;
+
+ // all modules read themselves
+ if (other == this)
+ return true;
+
+ // check if this module reads other
+ if (other.isNamed()) {
+ Set reads = this.reads; // volatile read
+ if (reads != null && reads.contains(other))
+ return true;
+ }
+
+ // check if this module reads the other module reflectively
+ if (reflectivelyReads.containsKeyPair(this, other))
+ return true;
+
+ // if other is an unnamed module then check if this module reads
+ // all unnamed modules
+ if (!other.isNamed()
+ && reflectivelyReads.containsKeyPair(this, ALL_UNNAMED_MODULE))
+ return true;
+
+ return false;
+ }
+
+ /**
+ * If the caller's module is this module then update this module to read
+ * the given module.
+ *
+ * This method is a no-op if {@code other} is this module (all modules read
+ * themselves), this module is an unnamed module (as unnamed modules read
+ * all modules), or this module already reads {@code other}.
+ *
+ * @implNote Read edges added by this method are weak and
+ * do not prevent {@code other} from being GC'ed when this module is
+ * strongly reachable.
+ *
+ * @param other
+ * The other module
+ *
+ * @return this module
+ *
+ * @throws IllegalCallerException
+ * If this is a named module and the caller's module is not this
+ * module
+ *
+ * @see #canRead
+ */
+ @CallerSensitive
+ public Module addReads(Module other) {
+ Objects.requireNonNull(other);
+ if (this.isNamed()) {
+ Module caller = getCallerModule(Reflection.getCallerClass());
+ if (caller != this) {
+ throw new IllegalCallerException(caller + " != " + this);
+ }
+ implAddReads(other, true);
+ }
+ return this;
+ }
+
+ /**
+ * Updates this module to read another module.
+ *
+ * @apiNote Used by the --add-reads command line option.
+ */
+ void implAddReads(Module other) {
+ 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.
+ *
+ * @apiNote This method is for VM white-box testing.
+ */
+ void implAddReadsNoSync(Module other) {
+ implAddReads(other, false);
+ }
+
+ /**
+ * Makes the given {@code Module} readable to this module.
+ *
+ * If {@code syncVM} is {@code true} then the VM is notified.
+ */
+ private void implAddReads(Module other, boolean syncVM) {
+ Objects.requireNonNull(other);
+ if (!canRead(other)) {
+ // update VM first, just in case it fails
+ if (syncVM) {
+ if (other == ALL_UNNAMED_MODULE) {
+ addReads0(this, null);
+ } else {
+ addReads0(this, other);
+ }
+ }
+
+ // add reflective read
+ reflectivelyReads.putIfAbsent(this, other, Boolean.TRUE);
+ }
+ }
+
+
+ // -- exported and open packages --
+
+ // the packages are open to other modules, can be null
+ // if the value contains EVERYONE_MODULE then the package is open to all
+ private volatile Map> openPackages;
+
+ // the packages that are exported, can be null
+ // if the value contains EVERYONE_MODULE then the package is exported to all
+ private volatile Map> exportedPackages;
+
+ // additional exports or opens added at run-time
+ // this module (1st key), other module (2nd key)
+ // (package name, open?) (value)
+ private static final WeakPairMap>
+ reflectivelyExports = new WeakPairMap<>();
+
+
+ /**
+ * Returns {@code true} if this module exports the given package to at
+ * least the given module.
+ *
+ * This method returns {@code true} if invoked to test if a package in
+ * this module is exported to itself. It always returns {@code true} when
+ * invoked on an unnamed module. A package that is {@link #isOpen open} to
+ * the given module is considered exported to that module at run-time and
+ * so this method returns {@code true} if the package is open to the given
+ * module.
+ *
+ * This method does not check if the given module reads this module.
+ *
+ * @param pn
+ * The package name
+ * @param other
+ * The other module
+ *
+ * @return {@code true} if this module exports the package to at least the
+ * given module
+ *
+ * @see ModuleDescriptor#exports()
+ * @see #addExports(String,Module)
+ */
+ public boolean isExported(String pn, Module other) {
+ Objects.requireNonNull(pn);
+ Objects.requireNonNull(other);
+ return implIsExportedOrOpen(pn, other, /*open*/false);
+ }
+
+ /**
+ * Returns {@code true} if this module has opened a package to at
+ * least the given module.
+ *
+ * This method returns {@code true} if invoked to test if a package in
+ * this module is open to itself. It returns {@code true} when invoked on an
+ * {@link ModuleDescriptor#isOpen open} module with a package in the module.
+ * It always returns {@code true} when invoked on an unnamed module.
+ *
+ * This method does not check if the given module reads this module.
+ *
+ * @param pn
+ * The package name
+ * @param other
+ * The other module
+ *
+ * @return {@code true} if this module has opened the package
+ * to at least the given module
+ *
+ * @see ModuleDescriptor#opens()
+ * @see #addOpens(String,Module)
+ * @see AccessibleObject#setAccessible(boolean)
+ * @see java.lang.invoke.MethodHandles#privateLookupIn
+ */
+ public boolean isOpen(String pn, Module other) {
+ Objects.requireNonNull(pn);
+ Objects.requireNonNull(other);
+ return implIsExportedOrOpen(pn, other, /*open*/true);
+ }
+
+ /**
+ * Returns {@code true} if this module exports the given package
+ * unconditionally.
+ *
+ * This method always returns {@code true} when invoked on an unnamed
+ * module. A package that is {@link #isOpen(String) opened} unconditionally
+ * is considered exported unconditionally at run-time and so this method
+ * returns {@code true} if the package is opened unconditionally.
+ *
+ * This method does not check if the given module reads this module.
+ *
+ * @param pn
+ * The package name
+ *
+ * @return {@code true} if this module exports the package unconditionally
+ *
+ * @see ModuleDescriptor#exports()
+ */
+ public boolean isExported(String pn) {
+ Objects.requireNonNull(pn);
+ return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/false);
+ }
+
+ /**
+ * Returns {@code true} if this module has opened a package
+ * unconditionally.
+ *
+ * This method always returns {@code true} when invoked on an unnamed
+ * module. Additionally, it always returns {@code true} when invoked on an
+ * {@link ModuleDescriptor#isOpen open} module with a package in the
+ * module.
+ *
+ * This method does not check if the given module reads this module.
+ *
+ * @param pn
+ * The package name
+ *
+ * @return {@code true} if this module has opened the package
+ * unconditionally
+ *
+ * @see ModuleDescriptor#opens()
+ */
+ public boolean isOpen(String pn) {
+ Objects.requireNonNull(pn);
+ return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/true);
+ }
+
+
+ /**
+ * Returns {@code true} if this module exports or opens the given package
+ * to the given module. If the other module is {@code EVERYONE_MODULE} then
+ * this method tests if the package is exported or opened unconditionally.
+ */
+ private boolean implIsExportedOrOpen(String pn, Module other, boolean open) {
+ // all packages in unnamed modules are open
+ if (!isNamed())
+ return true;
+
+ // all packages are exported/open to self
+ if (other == this && containsPackage(pn))
+ return true;
+
+ // all packages in open and automatic modules are open
+ if (descriptor.isOpen() || descriptor.isAutomatic())
+ return containsPackage(pn);
+
+ // exported/opened via module declaration/descriptor
+ if (isStaticallyExportedOrOpen(pn, other, open))
+ return true;
+
+ // exported via addExports/addOpens
+ if (isReflectivelyExportedOrOpen(pn, other, open))
+ return true;
+
+ // not exported or open to other
+ return false;
+ }
+
+ /**
+ * Returns {@code true} if this module exports or opens a package to
+ * the given module via its module declaration.
+ */
+ private boolean isStaticallyExportedOrOpen(String pn, Module other, boolean open) {
+ // package is open to everyone or
+ Map> openPackages = this.openPackages;
+ if (openPackages != null) {
+ Set targets = openPackages.get(pn);
+ if (targets != null) {
+ if (targets.contains(EVERYONE_MODULE))
+ return true;
+ if (other != EVERYONE_MODULE && targets.contains(other))
+ return true;
+ }
+ }
+
+ if (!open) {
+ // package is exported to everyone or
+ Map> exportedPackages = this.exportedPackages;
+ if (exportedPackages != null) {
+ Set targets = exportedPackages.get(pn);
+ if (targets != null) {
+ if (targets.contains(EVERYONE_MODULE))
+ return true;
+ if (other != EVERYONE_MODULE && targets.contains(other))
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Returns {@code true} if this module reflectively exports or opens given
+ * package package to the given module.
+ */
+ private boolean isReflectivelyExportedOrOpen(String pn, Module other, boolean open) {
+ // exported or open to all modules
+ Map exports = reflectivelyExports.get(this, EVERYONE_MODULE);
+ if (exports != null) {
+ Boolean b = exports.get(pn);
+ if (b != null) {
+ boolean isOpen = b.booleanValue();
+ if (!open || isOpen) return true;
+ }
+ }
+
+ if (other != EVERYONE_MODULE) {
+
+ // exported or open to other
+ exports = reflectivelyExports.get(this, other);
+ if (exports != null) {
+ Boolean b = exports.get(pn);
+ if (b != null) {
+ boolean isOpen = b.booleanValue();
+ if (!open || isOpen) return true;
+ }
+ }
+
+ // other is an unnamed module && exported or open to all unnamed
+ if (!other.isNamed()) {
+ exports = reflectivelyExports.get(this, ALL_UNNAMED_MODULE);
+ if (exports != null) {
+ Boolean b = exports.get(pn);
+ if (b != null) {
+ boolean isOpen = b.booleanValue();
+ if (!open || isOpen) return true;
+ }
+ }
+ }
+
+ }
+
+ return false;
+ }
+
+
+ /**
+ * If the caller's module is this module then update this module to export
+ * the given package to the given module.
+ *
+ * This method has no effect if the package is already exported (or
+ * open ) to the given module.
+ *
+ * @apiNote As specified in section 5.4.3 of the The Java™
+ * Virtual Machine Specification , if an attempt to resolve a
+ * symbolic reference fails because of a linkage error, then subsequent
+ * attempts to resolve the reference always fail with the same error that
+ * was thrown as a result of the initial resolution attempt.
+ *
+ * @param pn
+ * The package name
+ * @param other
+ * The module
+ *
+ * @return this module
+ *
+ * @throws IllegalArgumentException
+ * If {@code pn} is {@code null}, or this is a named module and the
+ * package {@code pn} is not a package in this module
+ * @throws IllegalCallerException
+ * If this is a named module and the caller's module is not this
+ * module
+ *
+ * @jvms 5.4.3 Resolution
+ * @see #isExported(String,Module)
+ */
+ @CallerSensitive
+ public Module addExports(String pn, Module other) {
+ if (pn == null)
+ throw new IllegalArgumentException("package is null");
+ Objects.requireNonNull(other);
+
+ if (isNamed()) {
+ Module caller = getCallerModule(Reflection.getCallerClass());
+ if (caller != this) {
+ throw new IllegalCallerException(caller + " != " + this);
+ }
+ implAddExportsOrOpens(pn, other, /*open*/false, /*syncVM*/true);
+ }
+
+ return this;
+ }
+
+ /**
+ * If this module has opened a package to at least the caller
+ * module then update this module to open the package to the given module.
+ * Opening a package with this method allows all types in the package,
+ * and all their members, not just public types and their public members,
+ * to be reflected on by the given module when using APIs that support
+ * private access or a way to bypass or suppress default Java language
+ * access control checks.
+ *
+ * This method has no effect if the package is already open
+ * to the given module.
+ *
+ * @param pn
+ * The package name
+ * @param other
+ * The module
+ *
+ * @return this module
+ *
+ * @throws IllegalArgumentException
+ * If {@code pn} is {@code null}, or this is a named module and the
+ * package {@code pn} is not a package in this module
+ * @throws IllegalCallerException
+ * If this is a named module and this module has not opened the
+ * package to at least the caller's module
+ *
+ * @see #isOpen(String,Module)
+ * @see AccessibleObject#setAccessible(boolean)
+ * @see java.lang.invoke.MethodHandles#privateLookupIn
+ */
+ @CallerSensitive
+ public Module addOpens(String pn, Module other) {
+ if (pn == null)
+ throw new IllegalArgumentException("package is null");
+ Objects.requireNonNull(other);
+
+ if (isNamed()) {
+ Module caller = getCallerModule(Reflection.getCallerClass());
+ if (caller != this && (caller == null || !isOpen(pn, caller)))
+ throw new IllegalCallerException(pn + " is not open to " + caller);
+ implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
+ }
+
+ return this;
+ }
+
+
+ /**
+ * Updates this module to export a package unconditionally.
+ *
+ * @apiNote This method is for JDK tests only.
+ */
+ void implAddExports(String pn) {
+ implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, false, true);
+ }
+
+ /**
+ * Updates this module to export a package to another module.
+ *
+ * @apiNote Used by Instrumentation::redefineModule and --add-exports
+ */
+ void implAddExports(String pn, Module other) {
+ implAddExportsOrOpens(pn, other, false, true);
+ }
+
+ /**
+ * Updates this module to export a package to all unnamed modules.
+ *
+ * @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) {
+ 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.
+ *
+ * If {@code syncVM} is {@code true} then the VM is notified.
+ */
+ private void implAddExportsOrOpens(String pn,
+ Module other,
+ boolean open,
+ boolean syncVM) {
+ Objects.requireNonNull(other);
+ Objects.requireNonNull(pn);
+
+ // all packages are open in unnamed, open, and automatic modules
+ if (!isNamed() || descriptor.isOpen() || descriptor.isAutomatic())
+ return;
+
+ // nothing to do if already exported/open to other
+ if (implIsExportedOrOpen(pn, other, open))
+ return;
+
+ // can only export a package in the module
+ if (!containsPackage(pn)) {
+ throw new IllegalArgumentException("package " + pn
+ + " not in contents");
+ }
+
+ // update VM first, just in case it fails
+ if (syncVM) {
+ if (other == EVERYONE_MODULE) {
+ addExportsToAll0(this, pn);
+ } else if (other == ALL_UNNAMED_MODULE) {
+ addExportsToAllUnnamed0(this, pn);
+ } else {
+ addExports0(this, pn, other);
+ }
+ }
+
+ // add package name to reflectivelyExports if absent
+ Map map = reflectivelyExports
+ .computeIfAbsent(this, other,
+ (m1, m2) -> new ConcurrentHashMap<>());
+
+ if (open) {
+ map.put(pn, Boolean.TRUE); // may need to promote from FALSE to TRUE
+ } else {
+ map.putIfAbsent(pn, Boolean.FALSE);
+ }
+ }
+
+
+ // -- services --
+
+ // additional service type (2nd key) that some module (1st key) uses
+ private static final WeakPairMap, Boolean> reflectivelyUses
+ = new WeakPairMap<>();
+
+ /**
+ * If the caller's module is this module then update this module to add a
+ * service dependence on the given service type. This method is intended
+ * for use by frameworks that invoke {@link java.util.ServiceLoader
+ * ServiceLoader} on behalf of other modules or where the framework is
+ * passed a reference to the service type by other code. This method is
+ * a no-op when invoked on an unnamed module or an automatic module.
+ *
+ * This method does not cause {@link Configuration#resolveAndBind
+ * resolveAndBind} to be re-run.
+ *
+ * @param service
+ * The service type
+ *
+ * @return this module
+ *
+ * @throws IllegalCallerException
+ * If this is a named module and the caller's module is not this
+ * module
+ *
+ * @see #canUse(Class)
+ * @see ModuleDescriptor#uses()
+ */
+ @CallerSensitive
+ public Module addUses(Class> service) {
+ Objects.requireNonNull(service);
+
+ if (isNamed() && !descriptor.isAutomatic()) {
+ Module caller = getCallerModule(Reflection.getCallerClass());
+ if (caller != this) {
+ throw new IllegalCallerException(caller + " != " + this);
+ }
+ implAddUses(service);
+ }
+
+ return this;
+ }
+
+ /**
+ * Update this module to add a service dependence on the given service
+ * type.
+ */
+ void implAddUses(Class> service) {
+ if (!canUse(service)) {
+ reflectivelyUses.putIfAbsent(this, service, Boolean.TRUE);
+ }
+ }
+
+
+ /**
+ * Indicates if this module has a service dependence on the given service
+ * type. This method always returns {@code true} when invoked on an unnamed
+ * module or an automatic module.
+ *
+ * @param service
+ * The service type
+ *
+ * @return {@code true} if this module uses service type {@code st}
+ *
+ * @see #addUses(Class)
+ */
+ public boolean canUse(Class> service) {
+ Objects.requireNonNull(service);
+
+ if (!isNamed())
+ return true;
+
+ if (descriptor.isAutomatic())
+ return true;
+
+ // uses was declared
+ if (descriptor.uses().contains(service.getName()))
+ return true;
+
+ // uses added via addUses
+ return reflectivelyUses.containsKeyPair(this, service);
+ }
+
+
+
+ // -- packages --
+
+ // Additional packages that are added to the module at run-time.
+ private volatile Map extraPackages;
+
+ private boolean containsPackage(String pn) {
+ if (descriptor.packages().contains(pn))
+ return true;
+ Map extraPackages = this.extraPackages;
+ if (extraPackages != null && extraPackages.containsKey(pn))
+ return true;
+ return false;
+ }
+
+
+ /**
+ * Returns the set of package names for the packages in this module.
+ *
+ * For named modules, the returned set contains an element for each
+ * package in the module.
+ *
+ * For unnamed modules, this method is the equivalent to invoking the
+ * {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of
+ * this module's class loader and returning the set of package names.
+ *
+ * @return the set of the package names of the packages in this module
+ */
+ public Set getPackages() {
+ if (isNamed()) {
+
+ Set packages = descriptor.packages();
+ Map extraPackages = this.extraPackages;
+ if (extraPackages == null) {
+ return packages;
+ } else {
+ return Stream.concat(packages.stream(),
+ extraPackages.keySet().stream())
+ .collect(Collectors.toSet());
+ }
+
+ } else {
+ // unnamed module
+ Stream packages;
+ if (loader == null) {
+ packages = BootLoader.packages();
+ } else {
+ packages = SharedSecrets.getJavaLangAccess().packages(loader);
+ }
+ return packages.map(Package::getName).collect(Collectors.toSet());
+ }
+ }
+
+ /**
+ * Add a package to this module without notifying the VM.
+ *
+ * @apiNote This method is VM white-box testing.
+ */
+ void implAddPackageNoSync(String pn) {
+ implAddPackage(pn.replace('/', '.'), false);
+ }
+
+ /**
+ * Add a package to this module.
+ *
+ * If {@code syncVM} is {@code true} then the VM is notified. This method is
+ * a no-op if this is an unnamed module or the module already contains the
+ * package.
+ *
+ * @throws IllegalArgumentException if the package name is not legal
+ * @throws IllegalStateException if the package is defined to another module
+ */
+ private void implAddPackage(String pn, boolean syncVM) {
+ // no-op if unnamed module
+ if (!isNamed())
+ return;
+
+ // no-op if module contains the package
+ if (containsPackage(pn))
+ return;
+
+ // check package name is legal for named modules
+ if (pn.isEmpty())
+ throw new IllegalArgumentException("Cannot add package");
+ for (int i=0; i extraPackages = this.extraPackages;
+ if (extraPackages == null) {
+ synchronized (this) {
+ extraPackages = this.extraPackages;
+ if (extraPackages == null)
+ this.extraPackages = extraPackages = new ConcurrentHashMap<>();
+ }
+ }
+
+ // update VM first in case it fails. This is a no-op if another thread
+ // beats us to add the package first
+ if (syncVM) {
+ // throws IllegalStateException if defined to another module
+ addPackage0(this, pn);
+ if (descriptor.isOpen() || descriptor.isAutomatic()) {
+ addExportsToAll0(this, pn);
+ }
+ }
+ extraPackages.putIfAbsent(pn, Boolean.TRUE);
+ }
+
+
+ // -- creating Module objects --
+
+ /**
+ * Defines all module in a configuration to the runtime.
+ *
+ * @return a map of module name to runtime {@code Module}
+ *
+ * @throws IllegalArgumentException
+ * If defining any of the modules to the VM fails
+ */
+ static Map defineModules(Configuration cf,
+ Function clf,
+ ModuleLayer layer)
+ {
+ Map nameToModule = new HashMap<>();
+ Map moduleToLoader = new HashMap<>();
+
+ boolean isBootLayer = (ModuleLayer.boot() == null);
+ Set loaders = new HashSet<>();
+
+ // map each module to a class loader
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ String name = resolvedModule.name();
+ ClassLoader loader = clf.apply(name);
+ if (loader != null) {
+ moduleToLoader.put(name, loader);
+ loaders.add(loader);
+ } else if (!isBootLayer) {
+ throw new IllegalArgumentException("loader can't be 'null'");
+ }
+ }
+
+ // define each module in the configuration to the VM
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ ModuleReference mref = resolvedModule.reference();
+ ModuleDescriptor descriptor = mref.descriptor();
+ String name = descriptor.name();
+ URI uri = mref.location().orElse(null);
+ ClassLoader loader = moduleToLoader.get(resolvedModule.name());
+ Module m;
+ if (loader == null && isBootLayer && name.equals("java.base")) {
+ // java.base is already defined to the VM
+ m = Object.class.getModule();
+ } else {
+ m = new Module(layer, loader, descriptor, uri);
+ }
+ nameToModule.put(name, m);
+ moduleToLoader.put(name, loader);
+ }
+
+ // setup readability and exports
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ ModuleReference mref = resolvedModule.reference();
+ ModuleDescriptor descriptor = mref.descriptor();
+
+ String mn = descriptor.name();
+ Module m = nameToModule.get(mn);
+ assert m != null;
+
+ // reads
+ Set reads = new HashSet<>();
+
+ // name -> source Module when in parent layer
+ Map nameToSource = Collections.emptyMap();
+
+ for (ResolvedModule other : resolvedModule.reads()) {
+ Module m2 = null;
+ if (other.configuration() == cf) {
+ // this configuration
+ m2 = nameToModule.get(other.name());
+ assert m2 != null;
+ } else {
+ // parent layer
+ for (ModuleLayer parent: layer.parents()) {
+ m2 = findModule(parent, other);
+ if (m2 != null)
+ break;
+ }
+ assert m2 != null;
+ if (nameToSource.isEmpty())
+ nameToSource = new HashMap<>();
+ nameToSource.put(other.name(), m2);
+ }
+ reads.add(m2);
+
+ // update VM view
+ addReads0(m, m2);
+ }
+ m.reads = reads;
+
+ // automatic modules read all unnamed modules
+ if (descriptor.isAutomatic()) {
+ m.implAddReads(ALL_UNNAMED_MODULE, true);
+ }
+
+ // exports and opens
+ initExportsAndOpens(m, nameToSource, nameToModule, layer.parents());
+ }
+
+ // register the modules in the boot layer
+ if (isBootLayer) {
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ ModuleReference mref = resolvedModule.reference();
+ ModuleDescriptor descriptor = mref.descriptor();
+ if (!descriptor.provides().isEmpty()) {
+ String name = descriptor.name();
+ Module m = nameToModule.get(name);
+ ClassLoader loader = moduleToLoader.get(name);
+ ServicesCatalog catalog;
+ if (loader == null) {
+ catalog = BootLoader.getServicesCatalog();
+ } else {
+ catalog = ServicesCatalog.getServicesCatalog(loader);
+ }
+ catalog.register(m);
+ }
+ }
+ }
+
+ // record that there is a layer with modules defined to the class loader
+ for (ClassLoader loader : loaders) {
+ layer.bindToLoader(loader);
+ }
+
+ return nameToModule;
+ }
+
+
+ /**
+ * Find the runtime Module corresponding to the given ResolvedModule
+ * in the given parent layer (or its parents).
+ */
+ private static Module findModule(ModuleLayer parent,
+ ResolvedModule resolvedModule) {
+ Configuration cf = resolvedModule.configuration();
+ String dn = resolvedModule.name();
+ return parent.layers()
+ .filter(l -> l.configuration() == cf)
+ .findAny()
+ .map(layer -> {
+ Optional om = layer.findModule(dn);
+ assert om.isPresent() : dn + " not found in layer";
+ Module m = om.get();
+ assert m.getLayer() == layer : m + " not in expected layer";
+ return m;
+ })
+ .orElse(null);
+ }
+
+
+ /**
+ * Initialize the maps of exported and open packages for module m.
+ */
+ private static void initExportsAndOpens(Module m,
+ Map nameToSource,
+ Map nameToModule,
+ List parents) {
+ // The VM doesn't special case open or automatic modules so need to
+ // export all packages
+ ModuleDescriptor descriptor = m.getDescriptor();
+ if (descriptor.isOpen() || descriptor.isAutomatic()) {
+ assert descriptor.opens().isEmpty();
+ for (String source : descriptor.packages()) {
+ addExportsToAll0(m, source);
+ }
+ return;
+ }
+
+ Map> openPackages = new HashMap<>();
+ Map> exportedPackages = new HashMap<>();
+
+ // process the open packages first
+ for (Opens opens : descriptor.opens()) {
+ String source = opens.source();
+
+ if (opens.isQualified()) {
+ // qualified opens
+ Set targets = new HashSet<>();
+ for (String target : opens.targets()) {
+ Module m2 = findModule(target, nameToSource, nameToModule, parents);
+ if (m2 != null) {
+ addExports0(m, source, m2);
+ targets.add(m2);
+ }
+ }
+ if (!targets.isEmpty()) {
+ openPackages.put(source, targets);
+ }
+ } else {
+ // unqualified opens
+ addExportsToAll0(m, source);
+ openPackages.put(source, EVERYONE_SET);
+ }
+ }
+
+ // next the exports, skipping exports when the package is open
+ for (Exports exports : descriptor.exports()) {
+ String source = exports.source();
+
+ // skip export if package is already open to everyone
+ Set openToTargets = openPackages.get(source);
+ if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE))
+ continue;
+
+ if (exports.isQualified()) {
+ // qualified exports
+ Set targets = new HashSet<>();
+ for (String target : exports.targets()) {
+ Module m2 = findModule(target, nameToSource, nameToModule, parents);
+ if (m2 != null) {
+ // skip qualified export if already open to m2
+ if (openToTargets == null || !openToTargets.contains(m2)) {
+ addExports0(m, source, m2);
+ targets.add(m2);
+ }
+ }
+ }
+ if (!targets.isEmpty()) {
+ exportedPackages.put(source, targets);
+ }
+
+ } else {
+ // unqualified exports
+ addExportsToAll0(m, source);
+ exportedPackages.put(source, EVERYONE_SET);
+ }
+ }
+
+ if (!openPackages.isEmpty())
+ m.openPackages = openPackages;
+ if (!exportedPackages.isEmpty())
+ m.exportedPackages = exportedPackages;
+ }
+
+ /**
+ * Find the runtime Module with the given name. The module name is the
+ * name of a target module in a qualified exports or opens directive.
+ *
+ * @param target The target module to find
+ * @param nameToSource The modules in parent layers that are read
+ * @param nameToModule The modules in the layer under construction
+ * @param parents The parent layers
+ */
+ private static Module findModule(String target,
+ Map nameToSource,
+ Map nameToModule,
+ List parents) {
+ Module m = nameToSource.get(target);
+ if (m == null) {
+ m = nameToModule.get(target);
+ if (m == null) {
+ for (ModuleLayer parent : parents) {
+ m = parent.findModule(target).orElse(null);
+ if (m != null) break;
+ }
+ }
+ }
+ return m;
+ }
+
+
+ // -- annotations --
+
+ /**
+ * {@inheritDoc}
+ * This method returns {@code null} when invoked on an unnamed module.
+ */
+ @Override
+ public T getAnnotation(Class annotationClass) {
+ return moduleInfoClass().getDeclaredAnnotation(annotationClass);
+ }
+
+ /**
+ * {@inheritDoc}
+ * This method returns an empty array when invoked on an unnamed module.
+ */
+ @Override
+ public Annotation[] getAnnotations() {
+ return moduleInfoClass().getAnnotations();
+ }
+
+ /**
+ * {@inheritDoc}
+ * This method returns an empty array when invoked on an unnamed module.
+ */
+ @Override
+ public Annotation[] getDeclaredAnnotations() {
+ return moduleInfoClass().getDeclaredAnnotations();
+ }
+
+ // cached class file with annotations
+ private volatile Class> moduleInfoClass;
+
+ private Class> moduleInfoClass() {
+ Class> clazz = this.moduleInfoClass;
+ if (clazz != null)
+ return clazz;
+
+ synchronized (this) {
+ clazz = this.moduleInfoClass;
+ if (clazz == null) {
+ if (isNamed()) {
+ PrivilegedAction> pa = this::loadModuleInfoClass;
+ clazz = AccessController.doPrivileged(pa);
+ }
+ if (clazz == null) {
+ class DummyModuleInfo { }
+ clazz = DummyModuleInfo.class;
+ }
+ this.moduleInfoClass = clazz;
+ }
+ return clazz;
+ }
+ }
+
+ private Class> loadModuleInfoClass() {
+ Class> clazz = null;
+ try (InputStream in = getResourceAsStream("module-info.class")) {
+ if (in != null)
+ clazz = loadModuleInfoClass(in);
+ } catch (Exception ignore) { }
+ return clazz;
+ }
+
+ /**
+ * Loads module-info.class as a package-private interface in a class loader
+ * that is a child of this module's class loader.
+ */
+ private Class> loadModuleInfoClass(InputStream in) throws IOException {
+ final String MODULE_INFO = "module-info";
+
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
+ + ClassWriter.COMPUTE_FRAMES);
+
+ ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, cw) {
+ @Override
+ public void visit(int version,
+ int access,
+ String name,
+ String signature,
+ String superName,
+ String[] interfaces) {
+ cw.visit(version,
+ Opcodes.ACC_INTERFACE
+ + Opcodes.ACC_ABSTRACT
+ + Opcodes.ACC_SYNTHETIC,
+ MODULE_INFO,
+ null,
+ "java/lang/Object",
+ null);
+ }
+ @Override
+ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+ // keep annotations
+ return super.visitAnnotation(desc, visible);
+ }
+ @Override
+ public void visitAttribute(Attribute attr) {
+ // drop non-annotation attributes
+ }
+ };
+
+ ClassReader cr = new ClassReader(in);
+ cr.accept(cv, 0);
+ byte[] bytes = cw.toByteArray();
+
+ ClassLoader cl = new ClassLoader(loader) {
+ @Override
+ protected Class> findClass(String cn)throws ClassNotFoundException {
+ if (cn.equals(MODULE_INFO)) {
+ return super.defineClass(cn, bytes, 0, bytes.length);
+ } else {
+ throw new ClassNotFoundException(cn);
+ }
+ }
+ };
+
+ try {
+ return cl.loadClass(MODULE_INFO);
+ } catch (ClassNotFoundException e) {
+ throw new InternalError(e);
+ }
+ }
+
+
+ // -- misc --
+
+
+ /**
+ * Returns an input stream for reading a resource in this module.
+ * The {@code name} parameter is a {@code '/'}-separated path name that
+ * identifies the resource. As with {@link Class#getResourceAsStream
+ * Class.getResourceAsStream}, this method delegates to the module's class
+ * loader {@link ClassLoader#findResource(String,String)
+ * findResource(String,String)} method, invoking it with the module name
+ * (or {@code null} when the module is unnamed) and the name of the
+ * resource. If the resource name has a leading slash then it is dropped
+ * before delegation.
+ *
+ * A resource in a named module may be encapsulated so that
+ * it cannot be located by code in other modules. Whether a resource can be
+ * located or not is determined as follows:
+ *
+ *
+ * If the resource name ends with "{@code .class}" then it is not
+ * encapsulated.
+ *
+ * A package name is derived from the resource name. If
+ * the package name is a {@link #getPackages() package} in the module
+ * then the resource can only be located by the caller of this method
+ * when the package is {@link #isOpen(String,Module) open} to at least
+ * the caller's module. If the resource is not in a package in the module
+ * then the resource is not encapsulated.
+ *
+ *
+ * In the above, the package name for a resource is derived
+ * from the subsequence of characters that precedes the last {@code '/'} in
+ * the name and then replacing each {@code '/'} character in the subsequence
+ * with {@code '.'}. A leading slash is ignored when deriving the package
+ * name. As an example, the package name derived for a resource named
+ * "{@code a/b/c/foo.properties}" is "{@code a.b.c}". A resource name
+ * with the name "{@code META-INF/MANIFEST.MF}" is never encapsulated
+ * because "{@code META-INF}" is not a legal package name.
+ *
+ * This method returns {@code null} if the resource is not in this
+ * module, the resource is encapsulated and cannot be located by the caller,
+ * or access to the resource is denied by the security manager.
+ *
+ * @param name
+ * The resource name
+ *
+ * @return An input stream for reading the resource or {@code null}
+ *
+ * @throws IOException
+ * If an I/O error occurs
+ *
+ * @see Class#getResourceAsStream(String)
+ */
+ @CallerSensitive
+ public InputStream getResourceAsStream(String name) throws IOException {
+ if (name.startsWith("/")) {
+ name = name.substring(1);
+ }
+
+ if (isNamed() && Resources.canEncapsulate(name)) {
+ Module caller = getCallerModule(Reflection.getCallerClass());
+ if (caller != this && caller != Object.class.getModule()) {
+ String pn = Resources.toPackageName(name);
+ if (getPackages().contains(pn)) {
+ if (caller == null && !isOpen(pn)) {
+ // no caller, package not open
+ return null;
+ }
+ if (!isOpen(pn, caller)) {
+ // package not open to caller
+ return null;
+ }
+ }
+ }
+ }
+
+ String mn = this.name;
+
+ // special-case built-in class loaders to avoid URL connection
+ if (loader == null) {
+ return BootLoader.findResourceAsStream(mn, name);
+ } else if (loader instanceof BuiltinClassLoader) {
+ return ((BuiltinClassLoader) loader).findResourceAsStream(mn, name);
+ }
+
+ // locate resource in module
+ JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
+ URL url = jla.findResource(loader, mn, name);
+ if (url != null) {
+ try {
+ return url.openStream();
+ } catch (SecurityException e) { }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the string representation of this module. For a named module,
+ * the representation is the string {@code "module"}, followed by a space,
+ * and then the module name. For an unnamed module, the representation is
+ * the string {@code "unnamed module"}, followed by a space, and then an
+ * implementation specific string that identifies the unnamed module.
+ *
+ * @return The string representation of this module
+ */
+ @Override
+ public String toString() {
+ if (isNamed()) {
+ return "module " + name;
+ } else {
+ String id = Integer.toHexString(System.identityHashCode(this));
+ return "unnamed module @" + id;
+ }
+ }
+
+ /**
+ * 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 --
+
+ // JVM_DefineModule
+ private static native void defineModule0(Module module,
+ boolean isOpen,
+ String version,
+ String location,
+ String[] pns);
+
+ // JVM_AddReadsModule
+ private static native void addReads0(Module from, Module to);
+
+ // JVM_AddModuleExports
+ private static native void addExports0(Module from, String pn, Module to);
+
+ // JVM_AddModuleExportsToAll
+ private static native void addExportsToAll0(Module from, String pn);
+
+ // JVM_AddModuleExportsToAllUnnamed
+ private static native void addExportsToAllUnnamed0(Module from, String pn);
+
+ // JVM_AddModulePackage
+ private static native void addPackage0(Module m, String pn);
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,944 @@
+/*
+ * Copyright (c) 2014, 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;
+
+import java.lang.module.Configuration;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ResolvedModule;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import jdk.internal.loader.ClassLoaderValue;
+import jdk.internal.loader.Loader;
+import jdk.internal.loader.LoaderPool;
+import jdk.internal.module.ServicesCatalog;
+import sun.security.util.SecurityConstants;
+
+
+/**
+ * A layer of modules in the Java virtual machine.
+ *
+ * A layer is created from a graph of modules in a {@link Configuration}
+ * and a function that maps each module to a {@link ClassLoader}.
+ * Creating a layer informs the Java virtual machine about the classes that
+ * may be loaded from the modules so that the Java virtual machine knows which
+ * module that each class is a member of.
+ *
+ * Creating a layer creates a {@link Module} object for each {@link
+ * ResolvedModule} in the configuration. For each resolved module that is
+ * {@link ResolvedModule#reads() read}, the {@code Module} {@link
+ * Module#canRead reads} the corresponding run-time {@code Module}, which may
+ * be in the same layer or a {@link #parents() parent} layer.
+ *
+ * The {@link #defineModulesWithOneLoader defineModulesWithOneLoader} and
+ * {@link #defineModulesWithManyLoaders defineModulesWithManyLoaders} methods
+ * 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
+ * class loader. The {@link #defineModules defineModules} method is for more
+ * 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
+ * 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
+ * there can be more than one parent layer or where a {@link
+ * ModuleLayer.Controller Controller} is needed to control modules in the layer
+ *
+ *
+ * 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
+ * started. The boot layer contains module {@code java.base} and is the only
+ * layer in the Java virtual machine with a module named "{@code java.base}".
+ * The modules in the boot layer are mapped to the bootstrap class loader and
+ * other class loaders that are
+ * built-in into the Java virtual machine. The boot layer will often be
+ * the {@link #parents() parent} when creating additional layers.
+ *
+ * Each {@code Module} in a layer is created so that it {@link
+ * Module#isExported(String) exports} and {@link Module#isOpen(String) opens}
+ * the packages described by its {@link ModuleDescriptor}. Qualified exports
+ * (where a package is exported to a set of target modules rather than all
+ * modules) are reified when creating the layer as follows:
+ *
+ * If module {@code X} exports a package to {@code Y}, and if the
+ * runtime {@code Module} {@code X} reads {@code Module} {@code Y}, then
+ * the package is exported to {@code Module} {@code Y} (which may be in
+ * the same layer as {@code X} or a parent layer).
+ *
+ * If module {@code X} exports a package to {@code Y}, and if the
+ * runtime {@code Module} {@code X} does not read {@code Y} then target
+ * {@code Y} is located as if by invoking {@link #findModule(String)
+ * findModule} to find the module in the layer or its parent layers. If
+ * {@code Y} is found then the package is exported to the instance of
+ * {@code Y} that was found. If {@code Y} is not found then the qualified
+ * export is ignored.
+ *
+ *
+ * Qualified opens are handled in same way as qualified exports.
+ *
+ * As when creating a {@code Configuration},
+ * {@link ModuleDescriptor#isAutomatic() automatic} modules receive special
+ * treatment when creating a layer. An automatic module is created in the
+ * Java virtual machine as a {@code Module} that reads every unnamed {@code
+ * Module} in the Java virtual machine.
+ *
+ * Unless otherwise specified, passing a {@code null} argument to a method
+ * in this class causes a {@link NullPointerException NullPointerException} to
+ * be thrown.
+ *
+ * Example usage:
+ *
+ * This example creates a configuration by resolving a module named
+ * "{@code myapp}" with the configuration for the boot layer as the parent. It
+ * then creates a new layer with the modules in this configuration. All modules
+ * are defined to the same class loader.
+ *
+ * {@code
+ * ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
+ *
+ * ModuleLayer parent = ModuleLayer.boot();
+ *
+ * Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
+ *
+ * ClassLoader scl = ClassLoader.getSystemClassLoader();
+ *
+ * ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
+ *
+ * Class> c = layer.findLoader("myapp").loadClass("app.Main");
+ * }
+ *
+ * @since 9
+ * @spec JPMS
+ * @see Module#getLayer()
+ */
+
+public final class ModuleLayer {
+
+ // the empty layer
+ private static final ModuleLayer EMPTY_LAYER
+ = new ModuleLayer(Configuration.empty(), List.of(), null);
+
+ // the configuration from which this ;ayer was created
+ private final Configuration cf;
+
+ // parent layers, empty in the case of the empty layer
+ private final List parents;
+
+ // maps module name to jlr.Module
+ private final Map nameToModule;
+
+ /**
+ * Creates a new module layer from the modules in the given configuration.
+ */
+ private ModuleLayer(Configuration cf,
+ List parents,
+ Function clf)
+ {
+ this.cf = cf;
+ this.parents = parents; // no need to do defensive copy
+
+ Map map;
+ if (parents.isEmpty()) {
+ map = Collections.emptyMap();
+ } else {
+ map = Module.defineModules(cf, clf, this);
+ }
+ this.nameToModule = map; // no need to do defensive copy
+ }
+
+ /**
+ * Controls a module layer. The static methods defined by {@link ModuleLayer}
+ * to create module layers return a {@code Controller} that can be used to
+ * control modules in the layer.
+ *
+ * Unless otherwise specified, passing a {@code null} argument to a
+ * method in this class causes a {@link NullPointerException
+ * NullPointerException} to be thrown.
+ *
+ * @apiNote Care should be taken with {@code Controller} objects, they
+ * should never be shared with untrusted code.
+ *
+ * @since 9
+ * @spec JPMS
+ */
+ public static final class Controller {
+ private final ModuleLayer layer;
+
+ Controller(ModuleLayer layer) {
+ this.layer = layer;
+ }
+
+ /**
+ * Returns the layer that this object controls.
+ *
+ * @return the module layer
+ */
+ public ModuleLayer layer() {
+ return layer;
+ }
+
+ private void ensureInLayer(Module source) {
+ if (source.getLayer() != layer)
+ throw new IllegalArgumentException(source + " not in layer");
+ }
+
+
+ /**
+ * Updates module {@code source} in the layer to read module
+ * {@code target}. This method is a no-op if {@code source} already
+ * reads {@code target}.
+ *
+ * @implNote Read edges added by this method are weak
+ * and do not prevent {@code target} from being GC'ed when {@code source}
+ * is strongly reachable.
+ *
+ * @param source
+ * The source module
+ * @param target
+ * The target module to read
+ *
+ * @return This controller
+ *
+ * @throws IllegalArgumentException
+ * If {@code source} is not in the module layer
+ *
+ * @see Module#addReads
+ */
+ public Controller addReads(Module source, Module target) {
+ ensureInLayer(source);
+ source.implAddReads(target);
+ return this;
+ }
+
+ /**
+ * Updates module {@code source} in the layer to open a package to
+ * module {@code target}. This method is a no-op if {@code source}
+ * already opens the package to at least {@code target}.
+ *
+ * @param source
+ * The source module
+ * @param pn
+ * The package name
+ * @param target
+ * The target module to read
+ *
+ * @return This controller
+ *
+ * @throws IllegalArgumentException
+ * If {@code source} is not in the module layer or the package
+ * is not in the source module
+ *
+ * @see Module#addOpens
+ */
+ public Controller addOpens(Module source, String pn, Module target) {
+ ensureInLayer(source);
+ source.implAddOpens(pn, target);
+ return this;
+ }
+ }
+
+
+ /**
+ * 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.
+ * This method creates one class loader and defines all modules to that
+ * class loader. The {@link ClassLoader#getParent() parent} of each class
+ * loader is the given parent class loader. This method works exactly as
+ * specified by the static {@link
+ * #defineModulesWithOneLoader(Configuration,List,ClassLoader)
+ * defineModulesWithOneLoader} method when invoked with this layer as the
+ * parent. In other words, if this layer is {@code thisLayer} then this
+ * method is equivalent to invoking:
+ * {@code
+ * ModuleLayer.defineModulesWithOneLoader(cf, List.of(thisLayer), parentLoader).layer();
+ * }
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param parentLoader
+ * The parent class loader for the class loader created by this
+ * method; may be {@code null} for the bootstrap class loader
+ *
+ * @return The newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent of the given configuration is not the configuration
+ * for this layer
+ * @throws LayerInstantiationException
+ * If the layer cannot be created for any of the reasons specified
+ * by the static {@code defineModulesWithOneLoader} method
+ * @throws SecurityException
+ * If {@code RuntimePermission("createClassLoader")} or
+ * {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ *
+ * @see #findLoader
+ */
+ public ModuleLayer defineModulesWithOneLoader(Configuration cf,
+ ClassLoader parentLoader) {
+ return defineModulesWithOneLoader(cf, List.of(this), parentLoader).layer();
+ }
+
+
+ /**
+ * 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.
+ * Each module is defined to its own {@link ClassLoader} created by this
+ * method. The {@link ClassLoader#getParent() parent} of each class loader
+ * is the given parent class loader. This method works exactly as specified
+ * by the static {@link
+ * #defineModulesWithManyLoaders(Configuration,List,ClassLoader)
+ * defineModulesWithManyLoaders} method when invoked with this layer as the
+ * parent. In other words, if this layer is {@code thisLayer} then this
+ * method is equivalent to invoking:
+ * {@code
+ * ModuleLayer.defineModulesWithManyLoaders(cf, List.of(thisLayer), parentLoader).layer();
+ * }
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param parentLoader
+ * The parent class loader for each of the class loaders created by
+ * this method; may be {@code null} for the bootstrap class loader
+ *
+ * @return The newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent of the given configuration is not the configuration
+ * for this layer
+ * @throws LayerInstantiationException
+ * If the layer cannot be created for any of the reasons specified
+ * by the static {@code defineModulesWithManyLoaders} method
+ * @throws SecurityException
+ * If {@code RuntimePermission("createClassLoader")} or
+ * {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ *
+ * @see #findLoader
+ */
+ public ModuleLayer defineModulesWithManyLoaders(Configuration cf,
+ ClassLoader parentLoader) {
+ return defineModulesWithManyLoaders(cf, List.of(this), parentLoader).layer();
+ }
+
+
+ /**
+ * 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.
+ * 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
+ * {@link #defineModules(Configuration,List,Function) defineModules}
+ * method when invoked with this layer as the parent. In other words, if
+ * this layer is {@code thisLayer} then this method is equivalent to
+ * invoking:
+ * {@code
+ * ModuleLayer.defineModules(cf, List.of(thisLayer), clf).layer();
+ * }
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param clf
+ * The function to map a module name to a class loader
+ *
+ * @return The newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent of the given configuration is not the configuration
+ * for this layer
+ * @throws LayerInstantiationException
+ * If the layer cannot be created for any of the reasons specified
+ * by the static {@code defineModules} method
+ * @throws SecurityException
+ * If {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ */
+ public ModuleLayer defineModules(Configuration cf,
+ Function clf) {
+ return defineModules(cf, List.of(this), clf).layer();
+ }
+
+ /**
+ * Creates a new module layer by defining the modules in the given {@code
+ * Configuration} to the Java virtual machine. This method creates one
+ * class loader and defines all modules to that class loader.
+ *
+ * The class loader created by this method implements direct
+ * delegation when loading types from modules. When its {@link
+ * ClassLoader#loadClass(String, boolean) loadClass} method is invoked to
+ * load a class then it uses the package name of the class to map it to a
+ * module. This may be a module in this layer and hence defined to the same
+ * class loader. It may be a package in a module in a parent layer that is
+ * exported to one or more of the modules in this layer. The class
+ * loader delegates to the class loader of the module, throwing {@code
+ * ClassNotFoundException} if not found by that class loader.
+ * When {@code loadClass} is invoked to load classes that do not map to a
+ * module then it delegates to the parent class loader.
+ *
+ * Attempting to create a layer with all modules defined to the same
+ * class loader can fail for the following reasons:
+ *
+ *
+ *
+ * Overlapping packages : Two or more modules in the
+ * configuration have the same package.
+ *
+ * Split delegation : The resulting class loader would
+ * need to delegate to more than one class loader in order to load types
+ * in a specific package.
+ *
+ *
+ *
+ * In addition, a layer cannot be created if the configuration contains
+ * a module named "{@code java.base}", or a module contains a package named
+ * "{@code java}" or a package with a name starting with "{@code java.}".
+ *
+ * If there is a security manager then the class loader created by
+ * this method will load classes and resources with privileges that are
+ * restricted by the calling context of this method.
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param parentLayers
+ * The list of parent layers in search order
+ * @param parentLoader
+ * The parent class loader for the class loader created by this
+ * method; may be {@code null} for the bootstrap class loader
+ *
+ * @return A controller that controls the newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent configurations do not match the configuration of
+ * the parent layers, including order
+ * @throws LayerInstantiationException
+ * If all modules cannot be defined to the same class loader for any
+ * of the reasons listed above
+ * @throws SecurityException
+ * If {@code RuntimePermission("createClassLoader")} or
+ * {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ *
+ * @see #findLoader
+ */
+ public static Controller defineModulesWithOneLoader(Configuration cf,
+ List parentLayers,
+ ClassLoader parentLoader)
+ {
+ List parents = new ArrayList<>(parentLayers);
+ checkConfiguration(cf, parents);
+
+ checkCreateClassLoaderPermission();
+ checkGetClassLoaderPermission();
+
+ try {
+ Loader loader = new Loader(cf.modules(), parentLoader);
+ loader.initRemotePackageMap(cf, parents);
+ ModuleLayer layer = new ModuleLayer(cf, parents, mn -> loader);
+ return new Controller(layer);
+ } catch (IllegalArgumentException | IllegalStateException e) {
+ throw new LayerInstantiationException(e.getMessage());
+ }
+ }
+
+ /**
+ * Creates a new module layer by defining the modules in the given {@code
+ * Configuration} to the Java virtual machine. Each module is defined to
+ * its own {@link ClassLoader} created by this method. The {@link
+ * ClassLoader#getParent() parent} of each class loader is the given parent
+ * class loader.
+ *
+ * The class loaders created by this method implement direct
+ * delegation when loading types from modules. When {@link
+ * ClassLoader#loadClass(String, boolean) loadClass} method is invoked to
+ * load a class then it uses the package name of the class to map it to a
+ * module. The package may be in the module defined to the class loader.
+ * The package may be exported by another module in this layer to the
+ * module defined to the class loader. It may be in a package exported by a
+ * module in a parent layer. The class loader delegates to the class loader
+ * of the module, throwing {@code ClassNotFoundException} if not found by
+ * that class loader.
+ * When {@code loadClass} is invoked to load classes that do not map to a
+ * module then it delegates to the parent class loader.
+ *
+ * If there is a security manager then the class loaders created by
+ * this method will load classes and resources with privileges that are
+ * restricted by the calling context of this method.
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param parentLayers
+ * The list of parent layers in search order
+ * @param parentLoader
+ * The parent class loader for each of the class loaders created by
+ * this method; may be {@code null} for the bootstrap class loader
+ *
+ * @return A controller that controls the newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent configurations do not match the configuration of
+ * the parent layers, including order
+ * @throws LayerInstantiationException
+ * If the layer cannot be created because the configuration contains
+ * a module named "{@code java.base}" or a module contains a package
+ * named "{@code java}" or a package with a name starting with
+ * "{@code java.}"
+ *
+ * @throws SecurityException
+ * If {@code RuntimePermission("createClassLoader")} or
+ * {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ *
+ * @see #findLoader
+ */
+ public static Controller defineModulesWithManyLoaders(Configuration cf,
+ List parentLayers,
+ ClassLoader parentLoader)
+ {
+ List parents = new ArrayList<>(parentLayers);
+ checkConfiguration(cf, parents);
+
+ checkCreateClassLoaderPermission();
+ checkGetClassLoaderPermission();
+
+ LoaderPool pool = new LoaderPool(cf, parents, parentLoader);
+ try {
+ ModuleLayer layer = new ModuleLayer(cf, parents, pool::loaderFor);
+ return new Controller(layer);
+ } catch (IllegalArgumentException | IllegalStateException e) {
+ throw new LayerInstantiationException(e.getMessage());
+ }
+ }
+
+ /**
+ * Creates a new module layer by defining the modules in the given {@code
+ * Configuration} to the Java virtual machine. The given function maps each
+ * module in the configuration, by name, to a class loader. Creating the
+ * layer informs the Java virtual machine about the classes that may be
+ * loaded so that the Java virtual machine knows which module that each
+ * class is a member of.
+ *
+ * The class loader delegation implemented by the class loaders must
+ * respect module readability. The class loaders should be
+ * {@link ClassLoader#registerAsParallelCapable parallel-capable} so as to
+ * avoid deadlocks during class loading. In addition, the entity creating
+ * a new layer with this method should arrange that the class loaders be
+ * ready to load from these modules before there are any attempts to load
+ * classes or resources.
+ *
+ * Creating a layer can fail for the following reasons:
+ *
+ *
+ *
+ * Two or more modules with the same package are mapped to the
+ * same class loader.
+ *
+ * A module is mapped to a class loader that already has a
+ * module of the same name defined to it.
+ *
+ * A module is mapped to a class loader that has already
+ * defined types in any of the packages in the module.
+ *
+ *
+ *
+ * In addition, a layer cannot be created if the configuration contains
+ * a module named "{@code java.base}", a configuration contains a module
+ * with a package named "{@code java}" or a package name starting with
+ * "{@code java.}" and the module is mapped to a class loader other than
+ * the {@link ClassLoader#getPlatformClassLoader() platform class loader},
+ * or the function to map a module name to a class loader returns
+ * {@code null}.
+ *
+ * If the function to map a module name to class loader throws an error
+ * or runtime exception then it is propagated to the caller of this method.
+ *
+ *
+ * @apiNote It is implementation specific as to whether creating a layer
+ * 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
+ * to the Java virtual machine.
+ *
+ * @param cf
+ * The configuration for the layer
+ * @param parentLayers
+ * The list of parent layers in search order
+ * @param clf
+ * The function to map a module name to a class loader
+ *
+ * @return A controller that controls the newly created layer
+ *
+ * @throws IllegalArgumentException
+ * If the parent configurations do not match the configuration of
+ * the parent layers, including order
+ * @throws LayerInstantiationException
+ * If creating the layer fails for any of the reasons listed above
+ * @throws SecurityException
+ * If {@code RuntimePermission("getClassLoader")} is denied by
+ * the security manager
+ */
+ public static Controller defineModules(Configuration cf,
+ List parentLayers,
+ Function clf)
+ {
+ List parents = new ArrayList<>(parentLayers);
+ checkConfiguration(cf, parents);
+ Objects.requireNonNull(clf);
+
+ checkGetClassLoaderPermission();
+
+ // The boot layer is checked during module system initialization
+ if (boot() != null) {
+ checkForDuplicatePkgs(cf, clf);
+ }
+
+ try {
+ ModuleLayer layer = new ModuleLayer(cf, parents, clf);
+ return new Controller(layer);
+ } catch (IllegalArgumentException | IllegalStateException e) {
+ throw new LayerInstantiationException(e.getMessage());
+ }
+ }
+
+
+ /**
+ * Checks that the parent configurations match the configuration of
+ * the parent layers.
+ */
+ private static void checkConfiguration(Configuration cf,
+ List parentLayers)
+ {
+ Objects.requireNonNull(cf);
+
+ List parentConfigurations = cf.parents();
+ if (parentLayers.size() != parentConfigurations.size())
+ throw new IllegalArgumentException("wrong number of parents");
+
+ int index = 0;
+ for (ModuleLayer parent : parentLayers) {
+ if (parent.configuration() != parentConfigurations.get(index)) {
+ throw new IllegalArgumentException(
+ "Parent of configuration != configuration of this Layer");
+ }
+ index++;
+ }
+ }
+
+ private static void checkCreateClassLoaderPermission() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
+ }
+
+ private static void checkGetClassLoaderPermission() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
+ }
+
+ /**
+ * Checks a configuration and the module-to-loader mapping to ensure that
+ * no two modules mapped to the same class loader have the same package.
+ * It also checks that no two automatic modules have the same package.
+ *
+ * @throws LayerInstantiationException
+ */
+ private static void checkForDuplicatePkgs(Configuration cf,
+ Function clf)
+ {
+ // HashMap allows null keys
+ Map> loaderToPackages = new HashMap<>();
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
+ ClassLoader loader = clf.apply(descriptor.name());
+
+ Set loaderPackages
+ = loaderToPackages.computeIfAbsent(loader, k -> new HashSet<>());
+
+ for (String pkg : descriptor.packages()) {
+ boolean added = loaderPackages.add(pkg);
+ if (!added) {
+ throw fail("More than one module with package %s mapped" +
+ " to the same class loader", pkg);
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates a LayerInstantiationException with the a message formatted from
+ * the given format string and arguments.
+ */
+ private static LayerInstantiationException fail(String fmt, Object ... args) {
+ String msg = String.format(fmt, args);
+ return new LayerInstantiationException(msg);
+ }
+
+
+ /**
+ * Returns the configuration for this layer.
+ *
+ * @return The configuration for this layer
+ */
+ public Configuration configuration() {
+ return cf;
+ }
+
+
+ /**
+ * Returns the list of this layer's parents unless this is the
+ * {@linkplain #empty empty layer}, which has no parents and so an
+ * empty list is returned.
+ *
+ * @return The list of this layer's parents
+ */
+ public List parents() {
+ return parents;
+ }
+
+
+ /**
+ * Returns an ordered stream of layers. The first element is is this layer,
+ * the remaining elements are the parent layers in DFS order.
+ *
+ * @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.
+ */
+ Stream layers() {
+ List allLayers = this.allLayers;
+ if (allLayers != null)
+ return allLayers.stream();
+
+ allLayers = new ArrayList<>();
+ Set visited = new HashSet<>();
+ Deque stack = new ArrayDeque<>();
+ visited.add(this);
+ stack.push(this);
+
+ while (!stack.isEmpty()) {
+ ModuleLayer layer = stack.pop();
+ allLayers.add(layer);
+
+ // push in reverse order
+ for (int i = layer.parents.size() - 1; i >= 0; i--) {
+ ModuleLayer parent = layer.parents.get(i);
+ if (!visited.contains(parent)) {
+ visited.add(parent);
+ stack.push(parent);
+ }
+ }
+ }
+
+ this.allLayers = allLayers = Collections.unmodifiableList(allLayers);
+ return allLayers.stream();
+ }
+
+ private volatile List allLayers;
+
+ /**
+ * Returns the set of the modules in this layer.
+ *
+ * @return A possibly-empty unmodifiable set of the modules in this layer
+ */
+ public Set modules() {
+ Set modules = this.modules;
+ if (modules == null) {
+ this.modules = modules =
+ Collections.unmodifiableSet(new HashSet<>(nameToModule.values()));
+ }
+ return modules;
+ }
+
+ private volatile Set modules;
+
+
+ /**
+ * Returns the module with the given name in this layer, or if not in this
+ * layer, the {@linkplain #parents parent} layers. Finding a module in
+ * parent layers is equivalent to invoking {@code findModule} on each
+ * parent, in search order, until the module is found or all parents have
+ * been searched. In a tree of layers then this is equivalent to
+ * a depth-first search.
+ *
+ * @param name
+ * The name of the module to find
+ *
+ * @return The module with the given name or an empty {@code Optional}
+ * if there isn't a module with this name in this layer or any
+ * parent layer
+ */
+ public Optional findModule(String name) {
+ Objects.requireNonNull(name);
+ if (this == EMPTY_LAYER)
+ return Optional.empty();
+ Module m = nameToModule.get(name);
+ if (m != null)
+ return Optional.of(m);
+
+ return layers()
+ .skip(1) // skip this layer
+ .map(l -> l.nameToModule)
+ .filter(map -> map.containsKey(name))
+ .map(map -> map.get(name))
+ .findAny();
+ }
+
+
+ /**
+ * Returns the {@code ClassLoader} for the module with the given name. If
+ * a module of the given name is not in this layer then the {@link #parents
+ * parent} layers are searched in the manner specified by {@link
+ * #findModule(String) findModule}.
+ *
+ * If there is a security manager then its {@code checkPermission}
+ * method is called with a {@code RuntimePermission("getClassLoader")}
+ * permission to check that the caller is allowed to get access to the
+ * class loader.
+ *
+ * @apiNote This method does not return an {@code Optional}
+ * because `null` must be used to represent the bootstrap class loader.
+ *
+ * @param name
+ * The name of the module to find
+ *
+ * @return The ClassLoader that the module is defined to
+ *
+ * @throws IllegalArgumentException if a module of the given name is not
+ * defined in this layer or any parent of this layer
+ *
+ * @throws SecurityException if denied by the security manager
+ */
+ public ClassLoader findLoader(String name) {
+ Optional om = findModule(name);
+
+ // can't use map(Module::getClassLoader) as class loader can be null
+ if (om.isPresent()) {
+ return om.get().getClassLoader();
+ } else {
+ throw new IllegalArgumentException("Module " + name
+ + " not known to this layer");
+ }
+ }
+
+ /**
+ * Returns a string describing this module layer.
+ *
+ * @return A possibly empty string describing this module layer
+ */
+ @Override
+ public String toString() {
+ return modules().stream()
+ .map(Module::getName)
+ .collect(Collectors.joining(", "));
+ }
+
+ /**
+ * Returns the empty layer. There are no modules in the empty
+ * layer. It has no parents.
+ *
+ * @return The empty layer
+ */
+ public static ModuleLayer empty() {
+ return EMPTY_LAYER;
+ }
+
+
+ /**
+ * Returns the boot layer. The boot layer contains at least one module,
+ * {@code java.base}. Its parent is the {@link #empty() empty} layer.
+ *
+ * @apiNote This method returns {@code null} during startup and before
+ * the boot layer is fully initialized.
+ *
+ * @return The boot layer
+ */
+ public static ModuleLayer boot() {
+ return System.bootLayer;
+ }
+
+ /**
+ * Returns the ServicesCatalog for this Layer, creating it if not
+ * already created.
+ */
+ ServicesCatalog getServicesCatalog() {
+ ServicesCatalog servicesCatalog = this.servicesCatalog;
+ if (servicesCatalog != null)
+ return servicesCatalog;
+
+ synchronized (this) {
+ servicesCatalog = this.servicesCatalog;
+ if (servicesCatalog == null) {
+ servicesCatalog = ServicesCatalog.create();
+ nameToModule.values().forEach(servicesCatalog::register);
+ this.servicesCatalog = servicesCatalog;
+ }
+ }
+
+ return servicesCatalog;
+ }
+
+ private volatile ServicesCatalog servicesCatalog;
+
+
+ /**
+ * Record that this layer has at least one module defined to the given
+ * class loader.
+ */
+ void bindToLoader(ClassLoader loader) {
+ // CLV.computeIfAbsent(loader, (cl, clv) -> new CopyOnWriteArrayList<>())
+ List list = CLV.get(loader);
+ if (list == null) {
+ list = new CopyOnWriteArrayList<>();
+ List previous = CLV.putIfAbsent(loader, list);
+ if (previous != null) list = previous;
+ }
+ list.add(this);
+ }
+
+ /**
+ * Returns a stream of the layers that have at least one module defined to
+ * the given class loader.
+ */
+ static Stream layers(ClassLoader loader) {
+ List list = CLV.get(loader);
+ if (list != null) {
+ return list.stream();
+ } else {
+ return Stream.empty();
+ }
+ }
+
+ // the list of layers with modules defined to a class loader
+ private static final ClassLoaderValue> CLV = new ClassLoaderValue<>();
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/NamedPackage.java
--- a/jdk/src/java.base/share/classes/java/lang/NamedPackage.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/NamedPackage.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleReference;
-import java.lang.reflect.Module;
import java.net.URI;
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Object.java
--- a/jdk/src/java.base/share/classes/java/lang/Object.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Object.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -561,10 +561,53 @@
* the finalization of this object to be halted, but is otherwise
* ignored.
*
+ * @apiNote
+ * Classes that embed non-heap resources have many options
+ * for cleanup of those resources. The class must ensure that the
+ * lifetime of each instance is longer than that of any resource it embeds.
+ * {@link java.lang.ref.Reference#reachabilityFence} can be used to ensure that
+ * objects remain reachable while resources embedded in the object are in use.
+ *
+ * A subclass should avoid overriding the {@code finalize} method
+ * unless the subclass embeds non-heap resources that must be cleaned up
+ * before the instance is collected.
+ * Finalizer invocations are not automatically chained, unlike constructors.
+ * If a subclass overrides {@code finalize} it must invoke the superclass
+ * finalizer explicitly.
+ * To guard against exceptions prematurely terminating the finalize chain,
+ * the subclass should use a {@code try-finally} block to ensure
+ * {@code super.finalize()} is always invoked. For example,
+ *
{@code @Override
+ * protected void finalize() throws Throwable {
+ * try {
+ * ... // cleanup subclass state
+ * } finally {
+ * super.finalize();
+ * }
+ * }
+ * }
+ *
+ * @deprecated The finalization mechanism is inherently problematic.
+ * Finalization can lead to performance issues, deadlocks, and hangs.
+ * Errors in finalizers can lead to resource leaks; there is no way to cancel
+ * finalization if it is no longer necessary; and no ordering is specified
+ * among calls to {@code finalize} methods of different objects.
+ * Furthermore, there are no guarantees regarding the timing of finalization.
+ * The {@code finalize} method might be called on a finalizable object
+ * only after an indefinite delay, if at all.
+ *
+ * Classes whose instances hold non-heap resources should provide a method
+ * to enable explicit release of those resources, and they should also
+ * implement {@link AutoCloseable} if appropriate.
+ * The {@link java.lang.ref.Cleaner} and {@link java.lang.ref.PhantomReference}
+ * provide more flexible and efficient ways to release resources when an object
+ * becomes unreachable.
+ *
* @throws Throwable the {@code Exception} raised by this method
* @see java.lang.ref.WeakReference
* @see java.lang.ref.PhantomReference
* @jls 12.6 Finalization of Class Instances
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable { }
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Package.java
--- a/jdk/src/java.base/share/classes/java/lang/Package.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Package.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,7 +27,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Module;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/SecurityManager.java
--- a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java Wed Jul 05 23:13:02 2017 +0200
@@ -29,9 +29,7 @@
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
-import java.lang.reflect.Layer;
import java.lang.reflect.Member;
-import java.lang.reflect.Module;
import java.io.FileDescriptor;
import java.io.File;
import java.io.FilePermission;
@@ -1441,7 +1439,7 @@
static {
// Get the modules in the boot layer
- Stream bootLayerModules = Layer.boot().modules().stream();
+ Stream bootLayerModules = ModuleLayer.boot().modules().stream();
// Filter out the modules loaded by the boot or platform loader
PrivilegedAction> pa = () ->
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/StackTraceElement.java
--- a/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,8 +33,6 @@
import java.lang.module.ModuleDescriptor.Version;
import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
@@ -191,7 +189,7 @@
* if the module name is not available.
* @since 9
* @spec JPMS
- * @see java.lang.reflect.Module#getName()
+ * @see Module#getName()
*/
public String getModuleName() {
return moduleName;
@@ -480,7 +478,7 @@
if (!VM.isModuleSystemInited())
return true;
- return Layer.boot() == m.getLayer() && HashedModules.contains(m);
+ return ModuleLayer.boot() == m.getLayer() && HashedModules.contains(m);
}
/*
@@ -492,7 +490,7 @@
static Set hashedModules() {
- Optional resolvedModule = Layer.boot()
+ Optional resolvedModule = ModuleLayer.boot()
.configuration()
.findModule("java.base");
assert resolvedModule.isPresent();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/System.java
--- a/jdk/src/java.base/share/classes/java/lang/System.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/System.java Wed Jul 05 23:13:02 2017 +0200
@@ -35,33 +35,32 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
+import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
+import java.net.URI;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.ProtectionDomain;
-import java.util.Properties;
-import java.util.PropertyPermission;
-import java.util.Map;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.nio.channels.Channel;
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.stream.Stream;
-import java.util.Objects;
-import java.util.ResourceBundle;
-import java.util.function.Supplier;
-import sun.nio.ch.Interruptible;
+import jdk.internal.module.ModuleBootstrap;
+import jdk.internal.module.ServicesCatalog;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
-import sun.security.util.SecurityConstants;
-import sun.reflect.annotation.AnnotationType;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.JavaLangAccess;;
import jdk.internal.misc.SharedSecrets;;
@@ -69,8 +68,9 @@
import jdk.internal.logger.LoggerFinderLoader;
import jdk.internal.logger.LazyLoggers;
import jdk.internal.logger.LocalizedLoggerWrapper;
-
-import jdk.internal.module.ModuleBootstrap;
+import sun.reflect.annotation.AnnotationType;
+import sun.nio.ch.Interruptible;
+import sun.security.util.SecurityConstants;
/**
* The System
class contains several useful class fields
@@ -1162,7 +1162,7 @@
* @param msg the string message (or a key in the message catalog, if
* this logger is a {@link
* 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}.
*
* @throws NullPointerException if {@code level} is {@code null}.
@@ -1230,7 +1230,7 @@
* @param msg the string message (or a key in the message catalog, if
* this logger is a {@link
* 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}.
* @param thrown a {@code Throwable} associated with the log message;
* can be {@code null}.
@@ -1279,7 +1279,7 @@
* java.text.MessageFormat} format, (or a key in the message
* catalog, if this logger is a {@link
* 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}.
* @param params an optional list of parameters to the message (may be
* none).
@@ -1484,7 +1484,7 @@
* message localization.
*
* @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
* logger in a {@link Logger} instance where all methods that do not
* take a {@link ResourceBundle} as parameter are redirected to one
@@ -1568,7 +1568,7 @@
* @implSpec
* Instances returned by this method route messages to loggers
* 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.
* 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
@@ -1581,7 +1581,7 @@
*
* @apiNote
* 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
* the logging backend, for instance, to allow loggers to be obtained during
* the system initialization time.
@@ -1614,7 +1614,7 @@
* @implSpec
* The returned logger will perform message localization as specified
* 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
* {@code module} is the caller's module.
* In cases where {@code System.getLogger} is called from a context where
@@ -1979,7 +1979,7 @@
}
// @see #initPhase2()
- private static Layer bootLayer;
+ static ModuleLayer bootLayer;
/*
* Invoked by VM. Phase 2 module system initialization.
@@ -2099,12 +2099,10 @@
public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) {
return new Thread(target, acc);
}
+ @SuppressWarnings("deprecation")
public void invokeFinalize(Object o) throws Throwable {
o.finalize();
}
- public Layer getBootLayer() {
- return bootLayer;
- }
public ConcurrentHashMap, ?> createOrGetClassLoaderValueMap(ClassLoader cl) {
return cl.createOrGetClassLoaderValueMap();
}
@@ -2129,6 +2127,44 @@
public void 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 layers(ModuleLayer layer) {
+ return layer.layers();
+ }
+ public Stream layers(ClassLoader loader) {
+ return ModuleLayer.layers(loader);
+ }
});
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/Thread.java
--- a/jdk/src/java.base/share/classes/java/lang/Thread.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Thread.java Wed Jul 05 23:13:02 2017 +0200
@@ -927,7 +927,7 @@
* for example), the interrupt
method should be used to
* interrupt the wait.
* For more information, see
- * Why
+ * Why
* are Thread.stop, Thread.suspend and Thread.resume Deprecated? .
*/
@Deprecated(since="1.2")
@@ -960,7 +960,7 @@
* could be used to generate exceptions that the target thread was
* not prepared to handle.
* For more information, see
- * Why
+ * Why
* are Thread.stop, Thread.suspend and Thread.resume Deprecated? .
* This method is subject to removal in a future version of Java SE.
*/
@@ -1082,7 +1082,7 @@
* If another thread ever attempted to lock this resource, deadlock
* would result. Such deadlocks typically manifest themselves as
* "frozen" processes. For more information, see
- *
+ *
* Why are Thread.stop, Thread.suspend and Thread.resume Deprecated? .
* This method is subject to removal in a future version of Java SE.
* @throws NoSuchMethodError always
@@ -1122,7 +1122,7 @@
* monitor prior to calling resume
, deadlock results. Such
* deadlocks typically manifest themselves as "frozen" processes.
* For more information, see
- * Why
+ * Why
* are Thread.stop, Thread.suspend and Thread.resume Deprecated? .
*/
@Deprecated(since="1.2")
@@ -1148,7 +1148,7 @@
* @deprecated This method exists solely for use with {@link #suspend},
* which has been deprecated because it is deadlock-prone.
* For more information, see
- * Why
+ * Why
* are Thread.stop, Thread.suspend and Thread.resume Deprecated? .
*/
@Deprecated(since="1.2")
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/WeakPairMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/WeakPairMap.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 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 java.lang;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BiFunction;
+
+/**
+ * A WeakHashMap-like data structure that uses a pair of weakly-referenced keys
+ * with identity equality semantics to associate a strongly-referenced value.
+ * Unlike WeakHashMap, this data structure is thread-safe.
+ *
+ * @param the type of 1st key in key pair
+ * @param the type of 2nd key in key pair
+ * @param the type of value
+ * @author Peter Levart
+ */
+final class WeakPairMap {
+
+ private final ConcurrentHashMap, V> map = new ConcurrentHashMap<>();
+ private final ReferenceQueue queue = new ReferenceQueue<>();
+
+ /**
+ * Tests if the specified pair of keys are associated with a value
+ * in the WeakPairMap.
+ *
+ * @param k1 the 1st of the pair of keys
+ * @param k2 the 2nd of the pair of keys
+ * @return true if and only if the specified key pair is in this WeakPairMap,
+ * as determined by the identity comparison; false otherwise
+ * @throws NullPointerException if any of the specified keys is null
+ */
+ public boolean containsKeyPair(K1 k1, K2 k2) {
+ expungeStaleAssociations();
+ return map.containsKey(Pair.lookup(k1, k2));
+ }
+
+ /**
+ * Returns the value to which the specified pair of keys is mapped, or null
+ * if this WeakPairMap contains no mapping for the key pair.
+ * More formally, if this WeakPairMap contains a mapping from a key pair
+ * {@code (_k1, _k2)} to a value {@code v} such that
+ * {@code k1 == _k1 && k2 == _k2}, then this method returns {@code v};
+ * otherwise it returns {@code null}.
+ * (There can be at most one such mapping.)
+ *
+ * @param k1 the 1st of the pair of keys for which the mapped value is to
+ * be returned
+ * @param k2 the 2nd of the pair of keys for which the mapped value is to
+ * be returned
+ * @return the value to which the specified key pair is mapped, or null if
+ * this map contains no mapping for the key pair
+ * @throws NullPointerException if any of the specified keys is null
+ */
+ public V get(K1 k1, K2 k2) {
+ expungeStaleAssociations();
+ return map.get(Pair.lookup(k1, k2));
+ }
+
+ /**
+ * Maps the specified key pair to the specified value in this WeakPairMap.
+ * Neither the keys nor the value can be null.
+ *
The value can be retrieved by calling the {@link #get} method
+ * with the the same keys (compared by identity).
+ *
+ * @param k1 the 1st of the pair of keys with which the specified value is to
+ * be associated
+ * @param k2 the 2nd of the pair of keys with which the specified value is to
+ * be associated
+ * @param v value to be associated with the specified key pair
+ * @return the previous value associated with key pair, or {@code null} if
+ * there was no mapping for key pair
+ * @throws NullPointerException if any of the specified keys or value is null
+ */
+ public V put(K1 k1, K2 k2, V v) {
+ expungeStaleAssociations();
+ return map.put(Pair.weak(k1, k2, queue), v);
+ }
+
+ /**
+ * If the specified key pair is not already associated with a value,
+ * associates it with the given value and returns {@code null}, else does
+ * nothing and returns the currently associated value.
+ *
+ * @param k1 the 1st of the pair of keys with which the specified value is to
+ * be associated
+ * @param k2 the 2nd of the pair of keys with which the specified value is to
+ * be associated
+ * @param v value to be associated with the specified key pair
+ * @return the previous value associated with key pair, or {@code null} if
+ * there was no mapping for key pair
+ * @throws NullPointerException if any of the specified keys or value is null
+ */
+ public V putIfAbsent(K1 k1, K2 k2, V v) {
+ expungeStaleAssociations();
+ return map.putIfAbsent(Pair.weak(k1, k2, queue), v);
+ }
+
+ /**
+ * If the specified key pair is not already associated with a value,
+ * attempts to compute its value using the given mapping function
+ * and enters it into this WeakPairMap unless {@code null}. The entire
+ * method invocation is performed atomically, so the function is
+ * applied at most once per key pair. Some attempted update operations
+ * on this WeakPairMap by other threads may be blocked while computation
+ * is in progress, so the computation should be short and simple,
+ * and must not attempt to update any other mappings of this WeakPairMap.
+ *
+ * @param k1 the 1st of the pair of keys with which the
+ * computed value is to be associated
+ * @param k2 the 2nd of the pair of keys with which the
+ * computed value is to be associated
+ * @param mappingFunction the function to compute a value
+ * @return the current (existing or computed) value associated with
+ * the specified key pair, or null if the computed value is null
+ * @throws NullPointerException if any of the specified keys or
+ * mappingFunction is null
+ * @throws IllegalStateException if the computation detectably
+ * attempts a recursive update to this map
+ * that would otherwise never complete
+ * @throws RuntimeException or Error if the mappingFunction does so, in
+ * which case the mapping is left unestablished
+ */
+ public V computeIfAbsent(K1 k1, K2 k2,
+ BiFunction super K1, ? super K2, ? extends V>
+ mappingFunction) {
+ expungeStaleAssociations();
+ try {
+ return map.computeIfAbsent(
+ Pair.weak(k1, k2, queue),
+ pair -> mappingFunction.apply(pair.first(), pair.second()));
+ } finally {
+ Reference.reachabilityFence(k1);
+ Reference.reachabilityFence(k2);
+ }
+ }
+
+ /**
+ * Returns a {@link Collection} view of the values contained in this
+ * WeakPairMap. The collection is backed by the WeakPairMap, so changes to
+ * the map are reflected in the collection, and vice-versa. The collection
+ * supports element removal, which removes the corresponding
+ * mapping from this map, via the {@code Iterator.remove},
+ * {@code Collection.remove}, {@code removeAll},
+ * {@code retainAll}, and {@code clear} operations. It does not
+ * support the {@code add} or {@code addAll} operations.
+ *
+ * @return the collection view
+ */
+ public Collection values() {
+ expungeStaleAssociations();
+ return map.values();
+ }
+
+ /**
+ * Removes associations from this WeakPairMap for which at least one of the
+ * keys in key pair has been found weakly-reachable and corresponding
+ * WeakRefPeer(s) enqueued. Called as part of each public operation.
+ */
+ private void expungeStaleAssociations() {
+ WeakRefPeer> peer;
+ while ((peer = (WeakRefPeer>) queue.poll()) != null) {
+ map.remove(peer.weakPair());
+ }
+ }
+
+ /**
+ * Common interface of both {@link Weak} and {@link Lookup} key pairs.
+ */
+ private interface Pair {
+
+ static Pair weak(K1 k1, K2 k2,
+ ReferenceQueue queue) {
+ return new Weak<>(k1, k2, queue);
+ }
+
+ static Pair lookup(K1 k1, K2 k2) {
+ return new Lookup<>(k1, k2);
+ }
+
+ /**
+ * @return The 1st of the pair of keys (may be null for {@link Weak}
+ * when it gets cleared)
+ */
+ K1 first();
+
+ /**
+ * @return The 2nd of the pair of keys (may be null for {@link Weak}
+ * when it gets cleared)
+ */
+ K2 second();
+
+ static int hashCode(Object first, Object second) {
+ // assert first != null && second != null;
+ return System.identityHashCode(first) ^
+ System.identityHashCode(second);
+ }
+
+ static boolean equals(Object first, Object second, Pair, ?> p) {
+ return first != null && second != null &&
+ first == p.first() && second == p.second();
+ }
+
+ /**
+ * A Pair where both keys are weakly-referenced.
+ * It is composed of two instances of {@link WeakRefPeer}s:
+ * {@code
+ *
+ * +-referent-> [K1] +-referent-> [K2]
+ * | |
+ * +----------------+ +----------------+
+ * | Pair.Weak <: |-----peer----->| (anonymous) <: |
+ * | WeakRefPeer, | | WeakRefPeer |
+ * | Pair |<--weakPair()--| |
+ * +----------------+ +----------------+
+ * | ^
+ * | |
+ * +-weakPair()-+
+ *
+ * }
+ *
+ * Pair.Weak is used for CHM keys. Both peers are associated with the
+ * same {@link ReferenceQueue} so when either of their referents
+ * becomes weakly-reachable, the corresponding entries can be
+ * {@link #expungeStaleAssociations() expunged} from the map.
+ */
+ final class Weak extends WeakRefPeer implements Pair {
+
+ // saved hash so it can be retrieved after the reference is cleared
+ private final int hash;
+ // link to peer
+ private final WeakRefPeer peer;
+
+ Weak(K1 k1, K2 k2, ReferenceQueue queue) {
+ super(k1, queue);
+ hash = Pair.hashCode(k1, k2);
+ peer = new WeakRefPeer<>(k2, queue) {
+ // link back to peer
+ @Override
+ Weak, ?> weakPair() { return Weak.this; }
+ };
+ }
+
+ @Override
+ Weak, ?> weakPair() {
+ return this;
+ }
+
+ @Override
+ public K1 first() {
+ return get();
+ }
+
+ @Override
+ public K2 second() {
+ return peer.get();
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return this == obj ||
+ (obj instanceof Pair &&
+ Pair.equals(first(), second(), (Pair, ?>) obj));
+ }
+ }
+
+ /**
+ * Optimized lookup Pair, used as lookup key in methods like
+ * {@link java.util.Map#get(Object)} or
+ * {@link java.util.Map#containsKey(Object)}) where
+ * there is a great chance its allocation is eliminated
+ * by escape analysis when such lookups are inlined by JIT.
+ * All its methods are purposely designed so that 'this' is never
+ * passed to any other method or used as identity.
+ */
+ final class Lookup implements Pair {
+ private final K1 k1;
+ private final K2 k2;
+
+ Lookup(K1 k1, K2 k2) {
+ this.k1 = Objects.requireNonNull(k1);
+ this.k2 = Objects.requireNonNull(k2);
+ }
+
+ @Override
+ public K1 first() {
+ return k1;
+ }
+
+ @Override
+ public K2 second() {
+ return k2;
+ }
+
+ @Override
+ public int hashCode() {
+ return Pair.hashCode(k1, k2);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof Pair &&
+ Pair.equals(k1, k2, (Pair, ?>) obj);
+ }
+ }
+ }
+
+ /**
+ * Common abstract supertype of a pair of WeakReference peers.
+ */
+ private static abstract class WeakRefPeer extends WeakReference {
+
+ WeakRefPeer(K k, ReferenceQueue queue) {
+ super(Objects.requireNonNull(k), queue);
+ }
+
+ /**
+ * @return the {@link Pair.Weak} side of the pair of peers.
+ */
+ abstract Pair.Weak, ?> weakPair();
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/annotation/ElementType.java
--- a/jdk/src/java.base/share/classes/java/lang/annotation/ElementType.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/annotation/ElementType.java Wed Jul 05 23:13:02 2017 +0200
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
/**
* The constants of this enumerated type provide a simple classification of the
* syntactic locations where annotations may appear in a Java program. These
- * constants are used in {@link Target java.lang.annotation.Target}
+ * constants are used in {@link java.lang.annotation.Target Target}
* meta-annotations to specify where it is legal to write annotations of a
* given type.
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/doc-files/threadPrimitiveDeprecation.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/doc-files/threadPrimitiveDeprecation.html Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,364 @@
+
+
+
+
+ Java Thread Primitive Deprecation
+
+
+
+Java Thread Primitive Deprecation
+
+Why is Thread.stop
deprecated?
+Because it is inherently unsafe. Stopping a thread causes it to
+unlock all the monitors that it has locked. (The monitors are
+unlocked as the ThreadDeath
exception propagates up
+the stack.) If any of the objects previously protected by these
+monitors were in an inconsistent state, other threads may now view
+these objects in an inconsistent state. Such objects are said to be
+damaged . When threads operate on damaged objects, arbitrary
+behavior can result. This behavior may be subtle and difficult to
+detect, or it may be pronounced. Unlike other unchecked exceptions,
+ThreadDeath
kills threads silently; thus, the user has
+no warning that his program may be corrupted. The corruption can
+manifest itself at any time after the actual damage occurs, even
+hours or days in the future.
+
+Couldn't I just catch the ThreadDeath
exception
+and fix the damaged object?
+In theory, perhaps, but it would vastly complicate the
+task of writing correct multithreaded code. The task would be
+nearly insurmountable for two reasons:
+
+A thread can throw a ThreadDeath
exception
+almost anywhere . All synchronized methods and blocks would
+have to be studied in great detail, with this in mind.
+A thread can throw a second ThreadDeath
exception
+while cleaning up from the first (in the catch
or
+finally
clause). Cleanup would have to be repeated till
+it succeeded. The code to ensure this would be quite complex.
+
+In sum, it just isn't practical.
+
+What about Thread.stop(Throwable)
?
+In addition to all of the problems noted above, this method may
+be used to generate exceptions that its target thread is unprepared
+to handle (including checked exceptions that the thread could not
+possibly throw, were it not for this method). For example, the
+following method is behaviorally identical to Java's
+throw
operation, but circumvents the compiler's
+attempts to guarantee that the calling method has declared all of
+the checked exceptions that it may throw:
+
+ static void sneakyThrow(Throwable t) {
+ Thread.currentThread().stop(t);
+ }
+
+
+What should I use instead of Thread.stop
?
+Most uses of stop
should be replaced by code that
+simply modifies some variable to indicate that the target thread
+should stop running. The target thread should check this variable
+regularly, and return from its run method in an orderly fashion if
+the variable indicates that it is to stop running. To ensure prompt
+communication of the stop-request, the variable must be
+volatile (or access to the variable must be
+synchronized).
+For example, suppose your applet contains the following
+start
, stop
and run
+methods:
+
+ private Thread blinker;
+
+ public void start() {
+ blinker = new Thread(this);
+ blinker.start();
+ }
+
+ public void stop() {
+ blinker.stop(); // UNSAFE!
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(interval);
+ } catch (InterruptedException e){
+ }
+ repaint();
+ }
+ }
+
+You can avoid the use of Thread.stop
by replacing the
+applet's stop
and run
methods with:
+
+ private volatile Thread blinker;
+
+ public void stop() {
+ blinker = null;
+ }
+
+ public void run() {
+ Thread thisThread = Thread.currentThread();
+ while (blinker == thisThread) {
+ try {
+ Thread.sleep(interval);
+ } catch (InterruptedException e){
+ }
+ repaint();
+ }
+ }
+
+
+How do I stop a thread that waits for long periods (e.g., for
+input)?
+That's what the Thread.interrupt
method is for. The
+same "state based" signaling mechanism shown above can be used, but
+the state change (blinker = null
, in the previous
+example) can be followed by a call to
+Thread.interrupt
, to interrupt the wait:
+
+ public void stop() {
+ Thread moribund = waiter;
+ waiter = null;
+ moribund.interrupt();
+ }
+
+For this technique to work, it's critical that any method that
+catches an interrupt exception and is not prepared to deal with it
+immediately reasserts the exception. We say reasserts
+rather than rethrows , because it is not always possible to
+rethrow the exception. If the method that catches the
+InterruptedException
is not declared to throw this
+(checked) exception, then it should "reinterrupt itself" with the
+following incantation:
+
+ Thread.currentThread().interrupt();
+
+This ensures that the Thread will reraise the
+InterruptedException
as soon as it is able.
+
+What if a thread doesn't respond to
+Thread.interrupt
?
+In some cases, you can use application specific tricks. For
+example, if a thread is waiting on a known socket, you can close
+the socket to cause the thread to return immediately.
+Unfortunately, there really isn't any technique that works in
+general. It should be noted that in all situations where a
+waiting thread doesn't respond to Thread.interrupt
, it
+wouldn't respond to Thread.stop
either. Such
+cases include deliberate denial-of-service attacks, and I/O
+operations for which thread.stop and thread.interrupt do not work
+properly.
+
+Why are Thread.suspend
and
+Thread.resume
deprecated?
+Thread.suspend
is inherently deadlock-prone. If the
+target thread holds a lock on the monitor protecting a critical
+system resource when it is suspended, no thread can access this
+resource until the target thread is resumed. If the thread that
+would resume the target thread attempts to lock this monitor prior
+to calling resume
, deadlock results. Such deadlocks
+typically manifest themselves as "frozen" processes.
+
+What should I use instead of Thread.suspend
and
+Thread.resume
?
+As with Thread.stop
, the prudent approach is to
+have the "target thread" poll a variable indicating the desired
+state of the thread (active or suspended). When the desired state
+is suspended, the thread waits using Object.wait
. When
+the thread is resumed, the target thread is notified using
+Object.notify
.
+For example, suppose your applet contains the following
+mousePressed event handler, which toggles the state of a thread
+called blinker
:
+
+ private boolean threadSuspended;
+
+ Public void mousePressed(MouseEvent e) {
+ e.consume();
+
+ if (threadSuspended)
+ blinker.resume();
+ else
+ blinker.suspend(); // DEADLOCK-PRONE!
+
+ threadSuspended = !threadSuspended;
+ }
+
+You can avoid the use of Thread.suspend
and
+Thread.resume
by replacing the event handler above
+with:
+
+ public synchronized void mousePressed(MouseEvent e) {
+ e.consume();
+
+ threadSuspended = !threadSuspended;
+
+ if (!threadSuspended)
+ notify();
+ }
+
+and adding the following code to the "run loop":
+
+ synchronized(this) {
+ while (threadSuspended)
+ wait();
+ }
+
+The wait
method throws the
+InterruptedException
, so it must be inside a try
+... catch
clause. It's fine to put it in the same clause as
+the sleep
. The check should follow (rather than
+precede) the sleep
so the window is immediately
+repainted when the thread is "resumed." The resulting
+run
method follows:
+
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(interval);
+
+ synchronized(this) {
+ while (threadSuspended)
+ wait();
+ }
+ } catch (InterruptedException e){
+ }
+ repaint();
+ }
+ }
+
+Note that the notify
in the mousePressed
+method and the wait
in the run
method are
+inside synchronized
blocks. This is required by the
+language, and ensures that wait
and
+notify
are properly serialized. In practical terms,
+this eliminates race conditions that could cause the "suspended"
+thread to miss a notify
and remain suspended
+indefinitely.
+While the cost of synchronization in Java is decreasing as the
+platform matures, it will never be free. A simple trick can be used
+to remove the synchronization that we've added to each iteration of
+the "run loop." The synchronized block that was added is replaced
+by a slightly more complex piece of code that enters a synchronized
+block only if the thread has actually been suspended:
+
+ if (threadSuspended) {
+ synchronized(this) {
+ while (threadSuspended)
+ wait();
+ }
+ }
+
+In the absence of explicit synchronization,
+threadSuspended must be made volatile to ensure
+prompt communication of the suspend-request.
+The resulting run
method is:
+
+ private volatile boolean threadSuspended;
+
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(interval);
+
+ if (threadSuspended) {
+ synchronized(this) {
+ while (threadSuspended)
+ wait();
+ }
+ }
+ } catch (InterruptedException e){
+ }
+ repaint();
+ }
+ }
+
+
+Can I combine the two techniques to produce a thread that may
+be safely "stopped" or "suspended"?
+Yes, it's reasonably straightforward. The one subtlety is that the
+target thread may already be suspended at the time that another
+thread tries to stop it. If the stop method merely sets
+the state variable (blinker ) to null, the target thread
+will remain suspended (waiting on the monitor), rather than exiting
+gracefully as it should. If the applet is restarted, multiple
+threads could end up waiting on the monitor at the same time,
+resulting in erratic behavior.
+To rectify this situation, the stop method must ensure
+that the target thread resumes immediately if it is suspended. Once
+the target thread resumes, it must recognize immediately that it
+has been stopped, and exit gracefully. Here's how the resulting
+run and stop methods look:
+
+ public void run() {
+ Thread thisThread = Thread.currentThread();
+ while (blinker == thisThread) {
+ try {
+ Thread.sleep(interval);
+
+ synchronized(this) {
+ while (threadSuspended && blinker==thisThread)
+ wait();
+ }
+ } catch (InterruptedException e){
+ }
+ repaint();
+ }
+ }
+
+ public synchronized void stop() {
+ blinker = null;
+ notify();
+ }
+
+If the stop method calls Thread.interrupt , as
+described above, it needn't call notify as well, but it
+still must be synchronized. This ensures that the target thread
+won't miss an interrupt due to a race condition.
+
+What about Thread.destroy
?
+Thread.destroy
was never implemented and has been
+deprecated. If it were implemented, it would be deadlock-prone in
+the manner of Thread.suspend
. (In fact, it is roughly
+equivalent to Thread.suspend
without the possibility
+of a subsequent Thread.resume
.)
+
+Why is Runtime.runFinalizersOnExit
+deprecated?
+Because it is inherently unsafe. It may result in finalizers being
+called on live objects while other threads are concurrently
+manipulating those objects, resulting in erratic behavior or
+deadlock. While this problem could be prevented if the class whose
+objects are being finalized were coded to "defend against" this
+call, most programmers do not defend against it. They assume
+that an object is dead at the time that its finalizer is called.
+Further, the call is not "thread-safe" in the sense that it sets
+a VM-global flag. This forces every class with a finalizer
+to defend against the finalization of live objects!
+
+
+
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Jul 05 23:13:02 2017 +0200
@@ -450,32 +450,29 @@
*/
static class Factory {
- static final String JLO_SIG = "Ljava/lang/Object;";
- static final String JLS_SIG = "Ljava/lang/String;";
- static final String JLC_SIG = "Ljava/lang/Class;";
- static final String MH = "java/lang/invoke/MethodHandle";
- static final String MH_SIG = "L"+MH+";";
- static final String BMH = "java/lang/invoke/BoundMethodHandle";
- static final String BMH_SIG = "L"+BMH+";";
- static final String SPECIES_DATA = "java/lang/invoke/BoundMethodHandle$SpeciesData";
- static final String SPECIES_DATA_SIG = "L"+SPECIES_DATA+";";
- static final String STABLE_SIG = "Ljdk/internal/vm/annotation/Stable;";
+ private static final String JLO_SIG = "Ljava/lang/Object;";
+ private static final String MH = "java/lang/invoke/MethodHandle";
+ private static final String MH_SIG = "L"+MH+";";
+ private static final String BMH = "java/lang/invoke/BoundMethodHandle";
+ private static final String BMH_NAME = "java.lang.invoke.BoundMethodHandle";
+ private static final String BMH_SIG = "L"+BMH+";";
+ private static final String SPECIES_DATA = "java/lang/invoke/BoundMethodHandle$SpeciesData";
+ private static final String SPECIES_DATA_SIG = "L"+SPECIES_DATA+";";
+ private static final String STABLE_SIG = "Ljdk/internal/vm/annotation/Stable;";
- static final String SPECIES_PREFIX_NAME = "Species_";
- static final String SPECIES_PREFIX_PATH = BMH + "$" + SPECIES_PREFIX_NAME;
- static final String SPECIES_CLASS_PREFIX = SPECIES_PREFIX_PATH.replace('/', '.');
+ private static final String SPECIES_PREFIX_NAME = "Species_";
+ private static final String SPECIES_PREFIX_PATH = BMH + "$" + SPECIES_PREFIX_NAME;
+ private static final String SPECIES_CLASS_PREFIX = BMH_NAME + "$" + SPECIES_PREFIX_NAME;
- static final String BMHSPECIES_DATA_EWI_SIG = "(B)" + SPECIES_DATA_SIG;
- static final String BMHSPECIES_DATA_GFC_SIG = "(" + JLS_SIG + JLC_SIG + ")" + SPECIES_DATA_SIG;
- static final String MYSPECIES_DATA_SIG = "()" + SPECIES_DATA_SIG;
- static final String VOID_SIG = "()V";
- static final String INT_SIG = "()I";
+ private static final String BMHSPECIES_DATA_EWI_SIG = "(B)" + SPECIES_DATA_SIG;
+ private static final String MYSPECIES_DATA_SIG = "()" + SPECIES_DATA_SIG;
+ private static final String INT_SIG = "()I";
- static final String SIG_INCIPIT = "(Ljava/lang/invoke/MethodType;Ljava/lang/invoke/LambdaForm;";
+ private static final String SIG_INCIPIT = "(Ljava/lang/invoke/MethodType;Ljava/lang/invoke/LambdaForm;";
- static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" };
+ private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" };
- static final ConcurrentMap> CLASS_CACHE = new ConcurrentHashMap<>();
+ private static final ConcurrentMap> CLASS_CACHE = new ConcurrentHashMap<>();
/**
* Get a concrete subclass of BMH for a given combination of bound types.
@@ -830,15 +827,27 @@
private static String makeSignature(String types, boolean ctor) {
StringBuilder buf = new StringBuilder(SIG_INCIPIT);
- for (char c : types.toCharArray()) {
- buf.append(typeSig(c));
+ int len = types.length();
+ for (int i = 0; i < len; i++) {
+ buf.append(typeSig(types.charAt(i)));
}
return buf.append(')').append(ctor ? "V" : BMH_SIG).toString();
}
+ private static MethodType makeConstructorType(String types) {
+ int length = types.length();
+ Class> ptypes[] = new Class>[length + 2];
+ ptypes[0] = MethodType.class;
+ ptypes[1] = LambdaForm.class;
+ for (int i = 0; i < length; i++) {
+ ptypes[i + 2] = BasicType.basicType(types.charAt(i)).basicTypeClass();
+ }
+ return MethodType.makeImpl(BoundMethodHandle.class, ptypes, true);
+ }
+
static MethodHandle makeCbmhCtor(Class extends BoundMethodHandle> cbmh, String types) {
try {
- return LOOKUP.findStatic(cbmh, "make", MethodType.fromDescriptor(makeSignature(types, false), null));
+ return LOOKUP.findStatic(cbmh, "make", makeConstructorType(types));
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
throw newInternalError(e);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java Wed Jul 05 23:13:02 2017 +0200
@@ -224,12 +224,12 @@
assert(names.length == nameCursor);
if (doesAlloc) {
// names = { argx,y,z,... new C, init method }
- names[NEW_OBJ] = new Name(NF_allocateInstance, names[DMH_THIS]);
- names[GET_MEMBER] = new Name(NF_constructorMethod, names[DMH_THIS]);
+ names[NEW_OBJ] = new Name(getFunction(NF_allocateInstance), names[DMH_THIS]);
+ names[GET_MEMBER] = new Name(getFunction(NF_constructorMethod), names[DMH_THIS]);
} else if (needsInit) {
- names[GET_MEMBER] = new Name(NF_internalMemberNameEnsureInit, names[DMH_THIS]);
+ names[GET_MEMBER] = new Name(getFunction(NF_internalMemberNameEnsureInit), names[DMH_THIS]);
} else {
- names[GET_MEMBER] = new Name(NF_internalMemberName, names[DMH_THIS]);
+ names[GET_MEMBER] = new Name(getFunction(NF_internalMemberName), names[DMH_THIS]);
}
assert(findDirectMethodHandle(names[GET_MEMBER]) == names[DMH_THIS]);
Object[] outArgs = Arrays.copyOfRange(names, ARG_BASE, GET_MEMBER+1, Object[].class);
@@ -249,10 +249,10 @@
return lform;
}
- static Object findDirectMethodHandle(Name name) {
- if (name.function == NF_internalMemberName ||
- name.function == NF_internalMemberNameEnsureInit ||
- name.function == NF_constructorMethod) {
+ /* assert */ static Object findDirectMethodHandle(Name name) {
+ if (name.function.equals(getFunction(NF_internalMemberName)) ||
+ name.function.equals(getFunction(NF_internalMemberNameEnsureInit)) ||
+ name.function.equals(getFunction(NF_constructorMethod))) {
assert(name.arguments.length == 1);
return name.arguments[0];
}
@@ -674,18 +674,18 @@
final int RESULT = nameCursor-1; // either the call or the cast
Name[] names = arguments(nameCursor - ARG_LIMIT, mtype.invokerType());
if (needsInit)
- names[INIT_BAR] = new Name(NF_ensureInitialized, names[DMH_THIS]);
+ names[INIT_BAR] = new Name(getFunction(NF_ensureInitialized), names[DMH_THIS]);
if (needsCast && !isGetter)
- names[PRE_CAST] = new Name(NF_checkCast, names[DMH_THIS], names[SET_VALUE]);
+ names[PRE_CAST] = new Name(getFunction(NF_checkCast), names[DMH_THIS], names[SET_VALUE]);
Object[] outArgs = new Object[1 + linkerType.parameterCount()];
assert(outArgs.length == (isGetter ? 3 : 4));
- outArgs[0] = names[U_HOLDER] = new Name(NF_UNSAFE);
+ outArgs[0] = names[U_HOLDER] = new Name(getFunction(NF_UNSAFE));
if (isStatic) {
- outArgs[1] = names[F_HOLDER] = new Name(NF_staticBase, names[DMH_THIS]);
- outArgs[2] = names[F_OFFSET] = new Name(NF_staticOffset, names[DMH_THIS]);
+ outArgs[1] = names[F_HOLDER] = new Name(getFunction(NF_staticBase), names[DMH_THIS]);
+ outArgs[2] = names[F_OFFSET] = new Name(getFunction(NF_staticOffset), names[DMH_THIS]);
} else {
- outArgs[1] = names[OBJ_CHECK] = new Name(NF_checkBase, names[OBJ_BASE]);
- outArgs[2] = names[F_OFFSET] = new Name(NF_fieldOffset, names[DMH_THIS]);
+ outArgs[1] = names[OBJ_CHECK] = new Name(getFunction(NF_checkBase), names[OBJ_BASE]);
+ outArgs[2] = names[F_OFFSET] = new Name(getFunction(NF_fieldOffset), names[DMH_THIS]);
}
if (!isGetter) {
outArgs[3] = (needsCast ? names[PRE_CAST] : names[SET_VALUE]);
@@ -693,7 +693,7 @@
for (Object a : outArgs) assert(a != null);
names[LINKER_CALL] = new Name(linker, outArgs);
if (needsCast && isGetter)
- names[POST_CAST] = new Name(NF_checkCast, names[DMH_THIS], names[LINKER_CALL]);
+ names[POST_CAST] = new Name(getFunction(NF_checkCast), names[DMH_THIS], names[LINKER_CALL]);
for (Name n : names) assert(n != null);
LambdaForm form;
@@ -726,48 +726,72 @@
/**
* Pre-initialized NamedFunctions for bootstrapping purposes.
- * Factored in an inner class to delay initialization until first usage.
*/
- static final NamedFunction
- NF_internalMemberName,
- NF_internalMemberNameEnsureInit,
- NF_ensureInitialized,
- NF_fieldOffset,
- NF_checkBase,
- NF_staticBase,
- NF_staticOffset,
- NF_checkCast,
- NF_allocateInstance,
- NF_constructorMethod,
- NF_UNSAFE;
- static {
+ static final byte NF_internalMemberName = 0,
+ NF_internalMemberNameEnsureInit = 1,
+ NF_ensureInitialized = 2,
+ NF_fieldOffset = 3,
+ NF_checkBase = 4,
+ NF_staticBase = 5,
+ NF_staticOffset = 6,
+ NF_checkCast = 7,
+ NF_allocateInstance = 8,
+ NF_constructorMethod = 9,
+ NF_UNSAFE = 10,
+ NF_LIMIT = 11;
+
+ private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
+
+ private static NamedFunction getFunction(byte func) {
+ NamedFunction nf = NFS[func];
+ if (nf != null) {
+ return nf;
+ }
+ // Each nf must be statically invocable or we get tied up in our bootstraps.
+ nf = NFS[func] = createFunction(func);
+ assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
+ return nf;
+ }
+
+ private static NamedFunction createFunction(byte func) {
try {
- NamedFunction nfs[] = {
- NF_internalMemberName = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("internalMemberName", Object.class)),
- NF_internalMemberNameEnsureInit = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("internalMemberNameEnsureInit", Object.class)),
- NF_ensureInitialized = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("ensureInitialized", Object.class)),
- NF_fieldOffset = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("fieldOffset", Object.class)),
- NF_checkBase = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("checkBase", Object.class)),
- NF_staticBase = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("staticBase", Object.class)),
- NF_staticOffset = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("staticOffset", Object.class)),
- NF_checkCast = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("checkCast", Object.class, Object.class)),
- NF_allocateInstance = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("allocateInstance", Object.class)),
- NF_constructorMethod = new NamedFunction(DirectMethodHandle.class
- .getDeclaredMethod("constructorMethod", Object.class)),
- NF_UNSAFE = new NamedFunction(new MemberName(MethodHandleStatics.class
- .getDeclaredField("UNSAFE")))
- };
- // Each nf must be statically invocable or we get tied up in our bootstraps.
- assert(InvokerBytecodeGenerator.isStaticallyInvocable(nfs));
+ switch (func) {
+ case NF_internalMemberName:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("internalMemberName", Object.class));
+ case NF_internalMemberNameEnsureInit:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("internalMemberNameEnsureInit", Object.class));
+ case NF_ensureInitialized:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("ensureInitialized", Object.class));
+ case NF_fieldOffset:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("fieldOffset", Object.class));
+ case NF_checkBase:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("checkBase", Object.class));
+ case NF_staticBase:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("staticBase", Object.class));
+ case NF_staticOffset:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("staticOffset", Object.class));
+ case NF_checkCast:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("checkCast", Object.class, Object.class));
+ case NF_allocateInstance:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("allocateInstance", Object.class));
+ case NF_constructorMethod:
+ return new NamedFunction(DirectMethodHandle.class
+ .getDeclaredMethod("constructorMethod", Object.class));
+ case NF_UNSAFE:
+ return new NamedFunction(new MemberName(MethodHandleStatics.class
+ .getDeclaredField("UNSAFE")));
+ default:
+ throw newInternalError("Unknown function: " + func);
+ }
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Wed Jul 05 23:13:02 2017 +0200
@@ -73,6 +73,7 @@
private static final String LL_SIG = "(L" + OBJ + ";)L" + OBJ + ";";
private static final String LLV_SIG = "(L" + OBJ + ";L" + OBJ + ";)V";
private static final String CLASS_PREFIX = LF + "$";
+ private static final String SOURCE_PREFIX = "LambdaForm$";
/** Name of its super class*/
static final String INVOKER_SUPER_NAME = OBJ;
@@ -80,9 +81,6 @@
/** Name of new class */
private final String className;
- /** Name of the source file (for stack trace printing). */
- private final String sourceFile;
-
private final LambdaForm lambdaForm;
private final String invokerName;
private final MethodType invokerType;
@@ -109,8 +107,7 @@
if (DUMP_CLASS_FILES) {
className = makeDumpableClassName(className);
}
- this.className = CLASS_PREFIX + className;
- this.sourceFile = "LambdaForm$" + className;
+ this.className = className;
this.lambdaForm = lambdaForm;
this.invokerName = invokerName;
this.invokerType = invokerType;
@@ -173,6 +170,13 @@
}
}
+ private void maybeDump(final byte[] classFile) {
+ if (DUMP_CLASS_FILES) {
+ maybeDump(CLASS_PREFIX + className, classFile);
+ }
+ }
+
+ // Also used from BoundMethodHandle
static void maybeDump(final String className, final byte[] classFile) {
if (DUMP_CLASS_FILES) {
java.security.AccessController.doPrivileged(
@@ -306,8 +310,9 @@
private ClassWriter classFilePrologue() {
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
- cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, INVOKER_SUPER_NAME, null);
- cw.visitSource(sourceFile, null);
+ cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
+ CLASS_PREFIX + className, null, INVOKER_SUPER_NAME, null);
+ cw.visitSource(SOURCE_PREFIX + className, null);
return cw;
}
@@ -617,12 +622,11 @@
return resolvedMember;
}
- private static MemberName lookupPregenerated(LambdaForm form) {
+ private static MemberName lookupPregenerated(LambdaForm form, MethodType invokerType) {
if (form.customized != null) {
// No pre-generated version for customized LF
return null;
}
- MethodType invokerType = form.methodType();
String name = form.kind.methodName;
switch (form.kind) {
case BOUND_REINVOKER: {
@@ -670,7 +674,7 @@
* Generate customized bytecode for a given LambdaForm.
*/
static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
- MemberName pregenerated = lookupPregenerated(form);
+ MemberName pregenerated = lookupPregenerated(form, invokerType);
if (pregenerated != null) return pregenerated; // pre-generated bytecode
InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("MH", form, invokerType);
@@ -720,7 +724,7 @@
bogusMethod(lambdaForm);
final byte[] classFile = toByteArray();
- maybeDump(className, classFile);
+ maybeDump(classFile);
return classFile;
}
@@ -908,7 +912,7 @@
//MethodHandle.class already covered
};
- static boolean isStaticallyInvocable(NamedFunction[] functions) {
+ static boolean isStaticallyInvocable(NamedFunction ... functions) {
for (NamedFunction nf : functions) {
if (!isStaticallyInvocable(nf.member())) {
return false;
@@ -1761,7 +1765,7 @@
bogusMethod(invokerType);
final byte[] classFile = cw.toByteArray();
- maybeDump(className, classFile);
+ maybeDump(classFile);
return classFile;
}
@@ -1829,7 +1833,7 @@
bogusMethod(dstType);
final byte[] classFile = cw.toByteArray();
- maybeDump(className, classFile);
+ maybeDump(classFile);
return classFile;
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java Wed Jul 05 23:13:02 2017 +0200
@@ -313,15 +313,15 @@
Object[] outArgs = Arrays.copyOfRange(names, CALL_MH, OUTARG_LIMIT, Object[].class);
Object mtypeArg = (customized ? mtype : names[MTYPE_ARG]);
if (!isGeneric) {
- names[CHECK_TYPE] = new Name(NF_checkExactType, names[CALL_MH], mtypeArg);
+ names[CHECK_TYPE] = new Name(getFunction(NF_checkExactType), names[CALL_MH], mtypeArg);
// mh.invokeExact(a*):R => checkExactType(mh, TYPEOF(a*:R)); mh.invokeBasic(a*)
} else {
- names[CHECK_TYPE] = new Name(NF_checkGenericType, names[CALL_MH], mtypeArg);
+ names[CHECK_TYPE] = new Name(getFunction(NF_checkGenericType), names[CALL_MH], mtypeArg);
// mh.invokeGeneric(a*):R => checkGenericType(mh, TYPEOF(a*:R)).invokeBasic(a*)
outArgs[0] = names[CHECK_TYPE];
}
if (CHECK_CUSTOM != -1) {
- names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]);
+ names[CHECK_CUSTOM] = new Name(getFunction(NF_checkCustomized), outArgs[0]);
}
names[LINKER_CALL] = new Name(outCallType, outArgs);
if (customized) {
@@ -368,7 +368,7 @@
}
names[VAD_ARG] = new Name(ARG_LIMIT, BasicType.basicType(Object.class));
- names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[THIS_VH], names[VAD_ARG]);
+ names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleGenericType), names[THIS_VH], names[VAD_ARG]);
Object[] outArgs = new Object[ARG_LIMIT + 1];
outArgs[0] = names[CHECK_TYPE];
@@ -377,7 +377,7 @@
}
if (CHECK_CUSTOM != -1) {
- names[CHECK_CUSTOM] = new Name(NF_checkCustomized, outArgs[0]);
+ names[CHECK_CUSTOM] = new Name(getFunction(NF_checkCustomized), outArgs[0]);
}
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
@@ -420,9 +420,9 @@
names[VAD_ARG] = new Name(getter, names[THIS_MH]);
if (isExact) {
- names[CHECK_TYPE] = new Name(NF_checkVarHandleExactType, names[CALL_VH], names[VAD_ARG]);
+ names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleExactType), names[CALL_VH], names[VAD_ARG]);
} else {
- names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[CALL_VH], names[VAD_ARG]);
+ names[CHECK_TYPE] = new Name(getFunction(NF_checkVarHandleGenericType), names[CALL_VH], names[VAD_ARG]);
}
Object[] outArgs = new Object[ARG_LIMIT];
outArgs[0] = names[CHECK_TYPE];
@@ -543,7 +543,7 @@
assert(names.length == nameCursor);
assert(names[APPENDIX_ARG] != null);
if (!skipCallSite)
- names[CALL_MH] = new Name(NF_getCallSiteTarget, names[CSITE_ARG]);
+ names[CALL_MH] = new Name(getFunction(NF_getCallSiteTarget), names[CSITE_ARG]);
// (site.)invokedynamic(a*):R => mh = site.getTarget(); mh.invokeBasic(a*)
final int PREPEND_MH = 0, PREPEND_COUNT = 1;
Object[] outArgs = Arrays.copyOfRange(names, ARG_BASE, OUTARG_LIMIT + PREPEND_COUNT, Object[].class);
@@ -586,31 +586,51 @@
}
// Local constant functions:
- private static final NamedFunction
- NF_checkExactType,
- NF_checkGenericType,
- NF_getCallSiteTarget,
- NF_checkCustomized,
- NF_checkVarHandleGenericType,
- NF_checkVarHandleExactType;
- static {
+ private static final byte NF_checkExactType = 0,
+ NF_checkGenericType = 1,
+ NF_getCallSiteTarget = 2,
+ NF_checkCustomized = 3,
+ NF_checkVarHandleGenericType = 4,
+ NF_checkVarHandleExactType = 5,
+ NF_LIMIT = 6;
+
+ private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
+
+ private static NamedFunction getFunction(byte func) {
+ NamedFunction nf = NFS[func];
+ if (nf != null) {
+ return nf;
+ }
+ NFS[func] = nf = createFunction(func);
+ // Each nf must be statically invocable or we get tied up in our bootstraps.
+ assert(InvokerBytecodeGenerator.isStaticallyInvocable(nf));
+ return nf;
+ }
+
+ private static NamedFunction createFunction(byte func) {
try {
- NamedFunction nfs[] = {
- NF_checkExactType = new NamedFunction(Invokers.class
- .getDeclaredMethod("checkExactType", MethodHandle.class, MethodType.class)),
- NF_checkGenericType = new NamedFunction(Invokers.class
- .getDeclaredMethod("checkGenericType", MethodHandle.class, MethodType.class)),
- NF_getCallSiteTarget = new NamedFunction(Invokers.class
- .getDeclaredMethod("getCallSiteTarget", CallSite.class)),
- NF_checkCustomized = new NamedFunction(Invokers.class
- .getDeclaredMethod("checkCustomized", MethodHandle.class)),
- NF_checkVarHandleGenericType = new NamedFunction(Invokers.class
- .getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class)),
- NF_checkVarHandleExactType = new NamedFunction(Invokers.class
- .getDeclaredMethod("checkVarHandleExactType", VarHandle.class, VarHandle.AccessDescriptor.class)),
- };
- // Each nf must be statically invocable or we get tied up in our bootstraps.
- assert(InvokerBytecodeGenerator.isStaticallyInvocable(nfs));
+ switch (func) {
+ case NF_checkExactType:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("checkExactType", MethodHandle.class, MethodType.class));
+ case NF_checkGenericType:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("checkGenericType", MethodHandle.class, MethodType.class));
+ case NF_getCallSiteTarget:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("getCallSiteTarget", CallSite.class));
+ case NF_checkCustomized:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("checkCustomized", MethodHandle.class));
+ case NF_checkVarHandleGenericType:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class));
+ case NF_checkVarHandleExactType:
+ return new NamedFunction(Invokers.class
+ .getDeclaredMethod("checkVarHandleExactType", VarHandle.class, VarHandle.AccessDescriptor.class));
+ default:
+ throw newInternalError("Unknown function: " + func);
+ }
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Wed Jul 05 23:13:02 2017 +0200
@@ -270,21 +270,21 @@
GENERIC("invoke"),
ZERO("zero"),
IDENTITY("identity"),
- BOUND_REINVOKER("BMH.reinvoke"),
- REINVOKER("MH.reinvoke"),
- DELEGATE("MH.delegate"),
- EXACT_LINKER("MH.invokeExact_MT"),
- EXACT_INVOKER("MH.exactInvoker"),
- GENERIC_LINKER("MH.invoke_MT"),
- GENERIC_INVOKER("MH.invoker"),
+ BOUND_REINVOKER("BMH.reinvoke", "reinvoke"),
+ REINVOKER("MH.reinvoke", "reinvoke"),
+ DELEGATE("MH.delegate", "delegate"),
+ EXACT_LINKER("MH.invokeExact_MT", "invokeExact_MT"),
+ EXACT_INVOKER("MH.exactInvoker", "exactInvoker"),
+ GENERIC_LINKER("MH.invoke_MT", "invoke_MT"),
+ GENERIC_INVOKER("MH.invoker", "invoker"),
LINK_TO_TARGET_METHOD("linkToTargetMethod"),
LINK_TO_CALL_SITE("linkToCallSite"),
- DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual"),
- DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial"),
- DIRECT_INVOKE_STATIC("DMH.invokeStatic"),
- DIRECT_NEW_INVOKE_SPECIAL("DMH.newInvokeSpecial"),
- DIRECT_INVOKE_INTERFACE("DMH.invokeInterface"),
- DIRECT_INVOKE_STATIC_INIT("DMH.invokeStaticInit"),
+ DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual", "invokeVirtual"),
+ DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial", "invokeSpecial"),
+ DIRECT_INVOKE_STATIC("DMH.invokeStatic", "invokeStatic"),
+ DIRECT_NEW_INVOKE_SPECIAL("DMH.newInvokeSpecial", "newInvokeSpecial"),
+ DIRECT_INVOKE_INTERFACE("DMH.invokeInterface", "invokeInterface"),
+ DIRECT_INVOKE_STATIC_INIT("DMH.invokeStaticInit", "invokeStaticInit"),
GET_OBJECT("getObject"),
PUT_OBJECT("putObject"),
GET_OBJECT_VOLATILE("getObjectVolatile"),
@@ -330,20 +330,19 @@
GUARD("guard"),
GUARD_WITH_CATCH("guardWithCatch"),
VARHANDLE_EXACT_INVOKER("VH.exactInvoker"),
- VARHANDLE_INVOKER("VH.invoker"),
- VARHANDLE_LINKER("VH.invoke_MT");
+ VARHANDLE_INVOKER("VH.invoker", "invoker"),
+ VARHANDLE_LINKER("VH.invoke_MT", "invoke_MT");
final String defaultLambdaName;
final String methodName;
private Kind(String defaultLambdaName) {
+ this(defaultLambdaName, defaultLambdaName);
+ }
+
+ private Kind(String defaultLambdaName, String methodName) {
this.defaultLambdaName = defaultLambdaName;
- int p = defaultLambdaName.indexOf('.');
- if (p > -1) {
- this.methodName = defaultLambdaName.substring(p + 1);
- } else {
- this.methodName = defaultLambdaName;
- }
+ this.methodName = methodName;
}
}
@@ -642,7 +641,7 @@
for (int i = 0; i < arity; ++i) {
ptypes[i] = parameterType(i).btClass;
}
- return MethodType.methodType(returnType().btClass, ptypes);
+ return MethodType.makeImpl(returnType().btClass, ptypes, true);
}
/** Return ABC_Z, where the ABC are parameter type characters, and Z is the return type character. */
@@ -678,7 +677,7 @@
for (int i = 0; i < ptypes.length; i++)
ptypes[i] = basicType(sig.charAt(i)).btClass;
Class> rtype = signatureReturn(sig).btClass;
- return MethodType.methodType(rtype, ptypes);
+ return MethodType.makeImpl(rtype, ptypes, true);
}
/**
@@ -848,6 +847,10 @@
if (vmentry != null && isCompiled) {
return; // already compiled somehow
}
+
+ // Obtain the invoker MethodType outside of the following try block.
+ // This ensures that an IllegalArgumentException is directly thrown if the
+ // type would have 256 or more parameters
MethodType invokerType = methodType();
assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType));
try {
@@ -902,10 +905,6 @@
}
return true;
}
- private static boolean returnTypesMatch(String sig, Object[] av, Object res) {
- MethodHandle mh = (MethodHandle) av[0];
- return valueMatches(signatureReturn(sig), mh.type().returnType(), res);
- }
private static boolean checkInt(Class> type, Object x) {
assert(x instanceof Integer);
if (type == int.class) return true;
@@ -1180,7 +1179,6 @@
// If we have a cached invoker, call it right away.
// NOTE: The invoker always returns a reference value.
if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments);
- assert(checkArgumentTypes(arguments, methodType()));
return invoker().invokeBasic(resolvedHandle(), arguments);
}
@@ -1198,7 +1196,6 @@
traceInterpreter("| resolve", this);
resolvedHandle();
}
- assert(checkArgumentTypes(arguments, methodType()));
rval = invoker().invokeBasic(resolvedHandle(), arguments);
} catch (Throwable ex) {
traceInterpreter("] throw =>", ex);
@@ -1214,23 +1211,6 @@
return invoker = computeInvoker(methodType().form());
}
- private static boolean checkArgumentTypes(Object[] arguments, MethodType methodType) {
- if (true) return true; // FIXME
- MethodType dstType = methodType.form().erasedType();
- MethodType srcType = dstType.basicType().wrap();
- Class>[] ptypes = new Class>[arguments.length];
- for (int i = 0; i < arguments.length; i++) {
- Object arg = arguments[i];
- Class> ptype = arg == null ? Object.class : arg.getClass();
- // If the dest. type is a primitive we keep the
- // argument type.
- ptypes[i] = dstType.parameterType(i).isPrimitive() ? ptype : Object.class;
- }
- MethodType argType = MethodType.methodType(srcType.returnType(), ptypes).wrap();
- assert(argType.isConvertibleTo(srcType)) : "wrong argument types: cannot convert " + argType + " to " + srcType;
- return true;
- }
-
MethodType methodType() {
if (resolvedHandle != null)
return resolvedHandle.type();
@@ -1726,7 +1706,7 @@
boolean isVoid = (type == V_TYPE);
Class> btClass = type.btClass;
MethodType zeType = MethodType.methodType(btClass);
- MethodType idType = (isVoid) ? zeType : zeType.appendParameterTypes(btClass);
+ MethodType idType = (isVoid) ? zeType : MethodType.methodType(btClass, btClass);
// Look up symbolic names. It might not be necessary to have these,
// but if we need to emit direct references to bytecodes, it helps.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java Wed Jul 05 23:13:02 2017 +0200
@@ -532,7 +532,8 @@
assert(pos > 0); // cannot spread the MH arg itself
Name spreadParam = new Name(L_TYPE);
- Name checkSpread = new Name(MethodHandleImpl.NF_checkSpreadArgument, spreadParam, arrayLength);
+ Name checkSpread = new Name(MethodHandleImpl.getFunction(MethodHandleImpl.NF_checkSpreadArgument),
+ spreadParam, arrayLength);
// insert the new expressions
int exprPos = lambdaForm.arity();
@@ -932,14 +933,14 @@
// replace the null entry in the MHImpl.loop invocation with localTypes
Name invokeLoop = lambdaForm.names[pos + 1];
- assert(invokeLoop.function == NF_loop);
+ assert(invokeLoop.function.equals(MethodHandleImpl.getFunction(NF_loop)));
Object[] args = Arrays.copyOf(invokeLoop.arguments, invokeLoop.arguments.length);
assert(args[0] == null);
args[0] = localTypes;
LambdaFormBuffer buf = buffer();
buf.startEdit();
- buf.changeName(pos + 1, new Name(NF_loop, args));
+ buf.changeName(pos + 1, new Name(MethodHandleImpl.getFunction(NF_loop), args));
form = buf.endEdit();
return putInCache(key, form);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -149,7 +148,7 @@
Object[] typeInfo = (Object[]) type;
Class>[] ptypes = (Class>[]) typeInfo[1];
Class> rtype = (Class>) typeInfo[0];
- MethodType res = MethodType.methodType(rtype, ptypes);
+ MethodType res = MethodType.makeImpl(rtype, ptypes, true);
type = res;
}
// Make sure type is a MethodType for racing threads.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -589,7 +589,7 @@
// Spread the array.
MethodHandle aload = MethodHandles.arrayElementGetter(spreadArgType);
Name array = names[argIndex];
- names[nameCursor++] = new Name(NF_checkSpreadArgument, array, spreadArgCount);
+ names[nameCursor++] = new Name(getFunction(NF_checkSpreadArgument), array, spreadArgCount);
for (int j = 0; j < spreadArgCount; i++, j++) {
indexes[i] = nameCursor;
names[nameCursor++] = new Name(aload, array, j);
@@ -934,7 +934,7 @@
// profile branch
if (PROFILE != -1) {
- names[PROFILE] = new Name(NF_profileBoolean, names[CALL_TEST], names[GET_COUNTERS]);
+ names[PROFILE] = new Name(getFunction(NF_profileBoolean), names[CALL_TEST], names[GET_COUNTERS]);
}
// call selectAlternative
names[SELECT_ALT] = new Name(getConstantHandle(MH_selectAlternative), names[TEST], names[GET_TARGET], names[GET_FALLBACK]);
@@ -1012,7 +1012,7 @@
// t_{i+1}:L=MethodHandleImpl.guardWithCatch(target:L,exType:L,catcher:L,t_{i}:L);
Object[] gwcArgs = new Object[] {names[GET_TARGET], names[GET_CLASS], names[GET_CATCHER], names[BOXED_ARGS]};
- names[TRY_CATCH] = new Name(NF_guardWithCatch, gwcArgs);
+ names[TRY_CATCH] = new Name(getFunction(NF_guardWithCatch), gwcArgs);
// t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L);
MethodHandle invokeBasicUnbox = MethodHandles.basicInvoker(MethodType.methodType(basicType.rtype(), Object.class));
@@ -1085,7 +1085,7 @@
mh = MethodHandles.dropArguments(mh, 1, Arrays.copyOfRange(type.parameterArray(), 1, arity));
return mh;
}
- return makePairwiseConvert(NF_throwException.resolvedHandle(), type, false, true);
+ return makePairwiseConvert(getFunction(NF_throwException).resolvedHandle(), type, false, true);
}
static Empty throwException(T t) throws T { throw t; }
@@ -1673,33 +1673,57 @@
}
// Local constant functions:
- /*non-public*/ static final NamedFunction
- NF_checkSpreadArgument,
- NF_guardWithCatch,
- NF_throwException,
- NF_tryFinally,
- NF_loop,
- NF_profileBoolean;
+
+ /* non-public */
+ static final byte NF_checkSpreadArgument = 0,
+ NF_guardWithCatch = 1,
+ NF_throwException = 2,
+ NF_tryFinally = 3,
+ NF_loop = 4,
+ NF_profileBoolean = 5,
+ NF_LIMIT = 6;
- static {
+ private static final @Stable NamedFunction[] NFS = new NamedFunction[NF_LIMIT];
+
+ static NamedFunction getFunction(byte func) {
+ NamedFunction nf = NFS[func];
+ if (nf != null) {
+ return nf;
+ }
+ return NFS[func] = createFunction(func);
+ }
+
+ private static NamedFunction createFunction(byte func) {
try {
- NF_checkSpreadArgument = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("checkSpreadArgument", Object.class, int.class));
- NF_guardWithCatch = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("guardWithCatch", MethodHandle.class, Class.class,
- MethodHandle.class, Object[].class));
- NF_tryFinally = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class));
- NF_loop = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class));
- NF_throwException = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("throwException", Throwable.class));
- NF_profileBoolean = new NamedFunction(MethodHandleImpl.class
- .getDeclaredMethod("profileBoolean", boolean.class, int[].class));
+ switch (func) {
+ case NF_checkSpreadArgument:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("checkSpreadArgument", Object.class, int.class));
+ case NF_guardWithCatch:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("guardWithCatch", MethodHandle.class, Class.class,
+ MethodHandle.class, Object[].class));
+ case NF_tryFinally:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class));
+ case NF_loop:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class));
+ case NF_throwException:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("throwException", Throwable.class));
+ case NF_profileBoolean:
+ return new NamedFunction(MethodHandleImpl.class
+ .getDeclaredMethod("profileBoolean", boolean.class, int[].class));
+ default:
+ throw new InternalError("Undefined function: " + func);
+ }
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
+ }
+ static {
SharedSecrets.setJavaLangInvokeAccess(new JavaLangInvokeAccess() {
@Override
public Object newMemberName() {
@@ -1878,7 +1902,7 @@
Object[] lArgs =
new Object[]{null, // placeholder for BasicType[] localTypes - will be added by LambdaFormEditor
names[GET_CLAUSE_DATA], names[BOXED_ARGS]};
- names[LOOP] = new Name(NF_loop, lArgs);
+ names[LOOP] = new Name(getFunction(NF_loop), lArgs);
// t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L);
MethodHandle invokeBasicUnbox = MethodHandles.basicInvoker(MethodType.methodType(basicType.rtype(), Object.class));
@@ -2113,7 +2137,7 @@
// t_{i+1}:L=MethodHandleImpl.tryFinally(target:L,exType:L,catcher:L,t_{i}:L);
Object[] tfArgs = new Object[] {names[GET_TARGET], names[GET_CLEANUP], names[BOXED_ARGS]};
- names[TRY_FINALLY] = new Name(NF_tryFinally, tfArgs);
+ names[TRY_FINALLY] = new Name(getFunction(NF_tryFinally), tfArgs);
// t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L);
MethodHandle invokeBasicUnbox = MethodHandles.basicInvoker(MethodType.methodType(basicType.rtype(), Object.class));
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.lang.reflect.ReflectPermission;
import java.nio.ByteOrder;
import java.security.AccessController;
@@ -668,11 +667,11 @@
* The value is {@code 0x20}, which does not correspond meaningfully to
* any particular {@linkplain java.lang.reflect.Modifier modifier bit}.
* 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}
* 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
- * java.lang.reflect.Module#isExported(String) exported unconditionally}.
+ * java.lang.Module#isExported(String) exported unconditionally}.
* @since 9
* @spec JPMS
* @see #publicLookup()
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java Wed Jul 05 23:13:02 2017 +0200
@@ -95,7 +95,7 @@
private static final long serialVersionUID = 292L; // {rtype, {ptype...}}
// The rtype and ptypes fields define the structural identity of the method type:
- private final Class> rtype;
+ private final @Stable Class> rtype;
private final @Stable Class>[] ptypes;
// The remaining fields are caches of various sorts:
@@ -117,7 +117,8 @@
/**
* Construct a temporary unchecked instance of MethodType for use only as a key to the intern table.
- * Does not check the given parameters for validity, and must be discarded after it is used as a searching key.
+ * Does not check the given parameters for validity, and must discarded (if untrusted) or checked
+ * (if trusted) after it has been used as a searching key.
* The parameters are reversed for this constructor, so that it is not accidentally used.
*/
private MethodType(Class>[] ptypes, Class> rtype) {
@@ -181,6 +182,7 @@
checkSlotCount(ptypes.length + slots);
return slots;
}
+
static {
// MAX_JVM_ARITY must be power of 2 minus 1 for following code trick to work:
assert((MAX_JVM_ARITY & (MAX_JVM_ARITY+1)) == 0);
@@ -303,18 +305,26 @@
*/
/*trusted*/ static
MethodType makeImpl(Class> rtype, Class>[] ptypes, boolean trusted) {
- MethodType mt = internTable.get(new MethodType(ptypes, rtype));
- if (mt != null)
- return mt;
if (ptypes.length == 0) {
ptypes = NO_PTYPES; trusted = true;
}
- mt = new MethodType(rtype, ptypes, trusted);
+ MethodType primordialMT = new MethodType(ptypes, rtype);
+ MethodType mt = internTable.get(primordialMT);
+ if (mt != null)
+ return mt;
+
// promote the object to the Real Thing, and reprobe
+ if (trusted) {
+ MethodType.checkRtype(rtype);
+ MethodType.checkPtypes(ptypes);
+ mt = primordialMT;
+ } else {
+ mt = new MethodType(rtype, ptypes, false);
+ }
mt.form = MethodTypeForm.findForm(mt);
return internTable.add(mt);
}
- private static final MethodType[] objectOnlyTypes = new MethodType[20];
+ private static final @Stable MethodType[] objectOnlyTypes = new MethodType[20];
/**
* Finds or creates a method type whose components are {@code Object} with an optional trailing {@code Object[]} array.
@@ -398,9 +408,14 @@
checkSlotCount(parameterSlotCount() + ptypesToInsert.length + ins);
int ilen = ptypesToInsert.length;
if (ilen == 0) return this;
- Class>[] nptypes = Arrays.copyOfRange(ptypes, 0, len+ilen);
- System.arraycopy(nptypes, num, nptypes, num+ilen, len-num);
+ Class>[] nptypes = new Class>[len + ilen];
+ if (num > 0) {
+ System.arraycopy(ptypes, 0, nptypes, 0, num);
+ }
System.arraycopy(ptypesToInsert, 0, nptypes, num, ilen);
+ if (num < len) {
+ System.arraycopy(ptypes, num, nptypes, num+ilen, len-num);
+ }
return makeImpl(rtype, nptypes, true);
}
@@ -636,11 +651,14 @@
return form.basicType();
}
+ private static final @Stable Class>[] METHOD_HANDLE_ARRAY
+ = new Class>[] { MethodHandle.class };
+
/**
* @return a version of the original type with MethodHandle prepended as the first argument
*/
/*non-public*/ MethodType invokerType() {
- return insertParameterTypes(0, MethodHandle.class);
+ return insertParameterTypes(0, METHOD_HANDLE_ARRAY);
}
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/module/Configuration.java
--- a/jdk/src/java.base/share/classes/java/lang/module/Configuration.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/Configuration.java Wed Jul 05 23:13:02 2017 +0200
@@ -64,11 +64,11 @@
* with the receiver as the parent configuration. The static methods are for
* more advanced cases where there can be more than one parent configuration.
*
- * Each {@link java.lang.reflect.Layer layer} of modules in the Java virtual
+ *
Each {@link java.lang.ModuleLayer layer} of modules in the Java virtual
* machine is created from a configuration. The configuration for the {@link
- * java.lang.reflect.Layer#boot() boot} layer is obtained by invoking {@code
- * Layer.boot().configuration()}. The configuration for the boot layer will
- * often be the parent when creating new configurations.
+ * java.lang.ModuleLayer#boot() boot} layer is obtained by invoking {@code
+ * ModuleLayer.boot().configuration()}. The configuration for the boot layer
+ * will often be the parent when creating new configurations.
*
* Example
*
@@ -81,7 +81,7 @@
* {@code
* 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"));
* cf.modules().forEach(m -> {
@@ -95,7 +95,7 @@
*
* @since 9
* @spec JPMS
- * @see java.lang.reflect.Layer
+ * @see java.lang.ModuleLayer
*/
public final class Configuration {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java Wed Jul 05 23:13:02 2017 +0200
@@ -60,7 +60,7 @@
* A module descriptor describes a named module and defines methods to
* obtain each of its components. The module descriptor for a named module
* 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
* {@link ModuleDescriptor.Builder} class or by reading the binary form of a
* module declaration ({@code module-info.class}) using the {@link
@@ -85,7 +85,7 @@
*
{@code ModuleDescriptor} objects are immutable and safe for use by
* multiple concurrent threads.
*
- * @see java.lang.reflect.Module
+ * @see java.lang.Module
* @since 9
* @spec JPMS
*/
@@ -2110,7 +2110,9 @@
/**
* 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
* The module main class
@@ -2134,8 +2136,8 @@
throw new IllegalArgumentException(mc + ": unnamed package");
}
}
+ packages.add(pn);
mainClass = mc;
- packages.add(pn);
return this;
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java Wed Jul 05 23:13:02 2017 +0200
@@ -228,14 +228,14 @@
* directory is treated as an exploded module rather than a directory of
* modules.
*
- * The module finder returned by this method supports modules that are
- * packaged as JAR files. A JAR file with a {@code module-info.class} in
- * the top-level directory of the JAR file (or overridden by a versioned
- * entry in a {@link java.util.jar.JarFile#isMultiRelease() multi-release}
- * JAR file) is a modular JAR and is an explicit module .
- * A JAR file that does not have a {@code module-info.class} in the
- * top-level directory is created as an automatic module. The components
- * for the automatic module are derived as follows:
+ *
The module finder returned by this method
+ * supports modules packaged as JAR files. A JAR file with a {@code
+ * module-info.class} in its top-level directory, or in a versioned entry
+ * in a {@linkplain java.util.jar.JarFile#isMultiRelease() multi-release}
+ * JAR file, is a modular JAR file and thus defines an explicit
+ * module. A JAR file that does not have a {@code module-info.class} in its
+ * top-level directory defines an automatic module , as follows:
+ *
*
*
*
@@ -254,16 +254,16 @@
* ModuleDescriptor.Version} and ignored if it cannot be parsed as
* a {@code Version}.
*
- * For the module name, then any trailing digits and dots
- * are removed, all non-alphanumeric characters ({@code [^A-Za-z0-9]})
- * are replaced with a dot ({@code "."}), all repeating dots are
- * replaced with one dot, and all leading and trailing dots are
- * removed.
+ * All non-alphanumeric characters ({@code [^A-Za-z0-9]})
+ * in the module name are replaced with a dot ({@code "."}), all
+ * repeating dots are replaced with one dot, and all leading and
+ * trailing dots are removed.
*
* 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
- * named {@code foo-1.2.3-SNAPSHOT.jar} will derive a module name
- * {@code foo} and {@code 1.2.3-SNAPSHOT} as the version.
+ * named {@code foo-bar-1.2.3-SNAPSHOT.jar} will derive a module
+ * name {@code foo.bar} and {@code 1.2.3-SNAPSHOT} as the version.
+ *
*
*
*
@@ -312,7 +312,9 @@
*
* As with automatic modules, the contents of a packaged or exploded
* module may need to be scanned 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
* assumed to be a class in the unnamed package and so {@code FindException}
* is thrown.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/module/Resolver.java
--- a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import java.io.PrintStream;
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires.Modifier;
-import java.lang.reflect.Layer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@@ -67,6 +66,9 @@
// maps module name to module reference
private final Map nameToReference = new HashMap<>();
+ // true if all automatic modules have been found
+ private boolean haveAllAutomaticModules;
+
// module constraints on target platform
private String osName;
private String osArch;
@@ -171,6 +173,21 @@
ModuleDescriptor descriptor = q.poll();
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
for (ModuleDescriptor.Requires requires : descriptor.requires()) {
@@ -199,10 +216,15 @@
if (!nameToReference.containsKey(dn)) {
addFoundModule(mref);
q.offer(mref.descriptor());
- resolved.add(mref.descriptor());
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());
mref.location().ifPresent(uri -> trace(" (%s)", uri));
}
@@ -250,7 +272,7 @@
// the initial set of modules that may use services
Set initialConsumers;
- if (Layer.boot() == null) {
+ if (ModuleLayer.boot() == null) {
initialConsumers = new HashSet<>();
} else {
initialConsumers = parents.stream()
@@ -301,6 +323,21 @@
return this;
}
+ /**
+ * Add all automatic modules that have not already been found to the
+ * nameToReference map.
+ */
+ private Set addFoundAutomaticModules() {
+ Set 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
@@ -534,7 +571,7 @@
// need "requires transitive" from the modules in parent configurations
// as there may be selected modules that have a dependency on modules in
// the parent configuration.
- if (Layer.boot() == null) {
+ if (ModuleLayer.boot() == null) {
g2 = new HashMap<>(capacity);
} else {
g2 = parents.stream()
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/module/package-info.java
--- a/jdk/src/java.base/share/classes/java/lang/module/package-info.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/package-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -70,7 +70,7 @@
* }
*
* 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
* its readability graph are:
*
{@code
@@ -92,10 +92,10 @@
*
* {@link java.lang.module.ModuleDescriptor#isAutomatic() Automatic} modules
* receive special treatment during resolution. Each automatic module is resolved
- * so that it reads all other modules in the configuration and all parent
- * configurations. Each automatic module is also resolved as if it
- * "{@code requires transitive}" all other automatic modules in the configuration
- * (and all automatic modules in parent configurations).
+ * as if it "{@code requires transitive}" all observable automatic modules and
+ * all automatic modules in the parent configurations. Each automatic module is
+ * resolved so that it reads all other modules in the resulting configuration and
+ * all modules in parent configurations.
*
*
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,949 +0,0 @@
-/*
- * Copyright (c) 2014, 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.reflect;
-
-import java.lang.module.Configuration;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ResolvedModule;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import jdk.internal.loader.ClassLoaderValue;
-import jdk.internal.loader.Loader;
-import jdk.internal.loader.LoaderPool;
-import jdk.internal.misc.SharedSecrets;
-import jdk.internal.module.Modules;
-import jdk.internal.module.ServicesCatalog;
-import sun.security.util.SecurityConstants;
-
-
-/**
- * A layer of modules in the Java virtual machine.
- *
- * A layer is created from a graph of modules in a {@link Configuration}
- * and a function that maps each module to a {@link ClassLoader}.
- * Creating a layer informs the Java virtual machine about the classes that
- * may be loaded from the modules so that the Java virtual machine knows which
- * module that each class is a member of.
- *
- * Creating a layer creates a {@link Module} object for each {@link
- * ResolvedModule} in the configuration. For each resolved module that is
- * {@link ResolvedModule#reads() read}, the {@code Module} {@link
- * Module#canRead reads} the corresponding run-time {@code Module}, which may
- * be in the same layer or a {@link #parents() parent} layer.
- *
- * The {@link #defineModulesWithOneLoader defineModulesWithOneLoader} and
- * {@link #defineModulesWithManyLoaders defineModulesWithManyLoaders} methods
- * provide convenient ways to create a {@code Layer} where all modules are
- * 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
- * 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
- * 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
- * there can be more than one parent layer or where a {@link Layer.Controller
- * Controller} is needed to control modules in the layer.
- *
- * 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
- * started. The boot layer contains module {@code java.base} and is the only
- * layer in the Java virtual machine with a module named "{@code java.base}".
- * The modules in the boot layer are mapped to the bootstrap class loader and
- * other class loaders that are
- * built-in into the Java virtual machine. The boot layer will often be
- * the {@link #parents() parent} when creating additional layers.
- *
- * Each {@code Module} in a layer is created so that it {@link
- * Module#isExported(String) exports} and {@link Module#isOpen(String) opens}
- * the packages described by its {@link ModuleDescriptor}. Qualified exports
- * (where a package is exported to a set of target modules rather than all
- * modules) are reified when creating the layer as follows:
- *
- * If module {@code X} exports a package to {@code Y}, and if the
- * runtime {@code Module} {@code X} reads {@code Module} {@code Y}, then
- * the package is exported to {@code Module} {@code Y} (which may be in
- * the same layer as {@code X} or a parent layer).
- *
- * If module {@code X} exports a package to {@code Y}, and if the
- * runtime {@code Module} {@code X} does not read {@code Y} then target
- * {@code Y} is located as if by invoking {@link #findModule(String)
- * findModule} to find the module in the layer or its parent layers. If
- * {@code Y} is found then the package is exported to the instance of
- * {@code Y} that was found. If {@code Y} is not found then the qualified
- * export is ignored.
- *
- *
- * Qualified opens are handled in same way as qualified exports.
- *
- * As when creating a {@code Configuration},
- * {@link ModuleDescriptor#isAutomatic() automatic} modules receive special
- * treatment when creating a layer. An automatic module is created in the
- * Java virtual machine as a {@code Module} that reads every unnamed {@code
- * Module} in the Java virtual machine.
- *
- * Unless otherwise specified, passing a {@code null} argument to a method
- * in this class causes a {@link NullPointerException NullPointerException} to
- * be thrown.
- *
- * Example usage:
- *
- * This example creates a configuration by resolving a module named
- * "{@code myapp}" with the configuration for the boot layer as the parent. It
- * then creates a new layer with the modules in this configuration. All modules
- * are defined to the same class loader.
- *
- * {@code
- * ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
- *
- * Layer parent = Layer.boot();
- *
- * Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
- *
- * ClassLoader scl = ClassLoader.getSystemClassLoader();
- *
- * Layer layer = parent.defineModulesWithOneLoader(cf, scl);
- *
- * Class> c = layer.findLoader("myapp").loadClass("app.Main");
- * }
- *
- * @since 9
- * @spec JPMS
- * @see Module#getLayer()
- */
-
-public final class Layer {
-
- // the empty Layer
- private static final Layer EMPTY_LAYER
- = new Layer(Configuration.empty(), List.of(), null);
-
- // the configuration from which this Layer was created
- private final Configuration cf;
-
- // parent layers, empty in the case of the empty layer
- private final List parents;
-
- // maps module name to jlr.Module
- private final Map nameToModule;
-
- /**
- * Creates a new Layer from the modules in the given configuration.
- */
- private Layer(Configuration cf,
- List parents,
- Function clf)
- {
- this.cf = cf;
- this.parents = parents; // no need to do defensive copy
-
- Map map;
- if (parents.isEmpty()) {
- map = Collections.emptyMap();
- } else {
- map = Module.defineModules(cf, clf, this);
- }
- this.nameToModule = map; // no need to do defensive copy
- }
-
- /**
- * Controls a layer. The static methods defined by {@link Layer} to create
- * module layers return a {@code Controller} that can be used to control
- * modules in the layer.
- *
- * Unless otherwise specified, passing a {@code null} argument to a
- * method in this class causes a {@link NullPointerException
- * NullPointerException} to be thrown.
- *
- * @apiNote Care should be taken with {@code Controller} objects, they
- * should never be shared with untrusted code.
- *
- * @since 9
- * @spec JPMS
- */
- public static final class Controller {
- private final Layer layer;
-
- Controller(Layer layer) {
- this.layer = layer;
- }
-
- /**
- * Returns the layer that this object controls.
- *
- * @return the layer
- */
- public Layer layer() {
- return layer;
- }
-
- private void ensureInLayer(Module source) {
- if (source.getLayer() != layer)
- throw new IllegalArgumentException(source + " not in layer");
- }
-
-
- /**
- * Updates module {@code source} in the layer to read module
- * {@code target}. This method is a no-op if {@code source} already
- * reads {@code target}.
- *
- * @implNote Read edges added by this method are weak
- * and do not prevent {@code target} from being GC'ed when {@code source}
- * is strongly reachable.
- *
- * @param source
- * The source module
- * @param target
- * The target module to read
- *
- * @return This controller
- *
- * @throws IllegalArgumentException
- * If {@code source} is not in the layer
- *
- * @see Module#addReads
- */
- public Controller addReads(Module source, Module target) {
- ensureInLayer(source);
- Objects.requireNonNull(target);
- Modules.addReads(source, target);
- return this;
- }
-
- /**
- * Updates module {@code source} in the layer to open a package to
- * module {@code target}. This method is a no-op if {@code source}
- * already opens the package to at least {@code target}.
- *
- * @param source
- * The source module
- * @param pn
- * The package name
- * @param target
- * The target module to read
- *
- * @return This controller
- *
- * @throws IllegalArgumentException
- * If {@code source} is not in the layer or the package is not
- * in the source module
- *
- * @see Module#addOpens
- */
- public Controller addOpens(Module source, String pn, Module target) {
- ensureInLayer(source);
- Objects.requireNonNull(pn);
- Objects.requireNonNull(target);
- Modules.addOpens(source, pn, target);
- return this;
- }
- }
-
-
- /**
- * Creates a new layer, with this layer as its parent, by defining the
- * modules in the given {@code Configuration} to the Java virtual machine.
- * This method creates one class loader and defines all modules to that
- * class loader. The {@link ClassLoader#getParent() parent} of each class
- * loader is the given parent class loader. This method works exactly as
- * specified by the static {@link
- * #defineModulesWithOneLoader(Configuration,List,ClassLoader)
- * defineModulesWithOneLoader} method when invoked with this layer as the
- * parent. In other words, if this layer is {@code thisLayer} then this
- * method is equivalent to invoking:
- * {@code
- * Layer.defineModulesWithOneLoader(cf, List.of(thisLayer), parentLoader).layer();
- * }
- *
- * @param cf
- * The configuration for the layer
- * @param parentLoader
- * The parent class loader for the class loader created by this
- * method; may be {@code null} for the bootstrap class loader
- *
- * @return The newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent of the given configuration is not the configuration
- * for this layer
- * @throws LayerInstantiationException
- * If the layer cannot be created for any of the reasons specified
- * by the static {@code defineModulesWithOneLoader} method
- * @throws SecurityException
- * If {@code RuntimePermission("createClassLoader")} or
- * {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- *
- * @see #findLoader
- */
- public Layer defineModulesWithOneLoader(Configuration cf,
- ClassLoader parentLoader) {
- return defineModulesWithOneLoader(cf, List.of(this), parentLoader).layer();
- }
-
-
- /**
- * Creates a new layer, with this layer as its parent, by defining the
- * modules in the given {@code Configuration} to the Java virtual machine.
- * Each module is defined to its own {@link ClassLoader} created by this
- * method. The {@link ClassLoader#getParent() parent} of each class loader
- * is the given parent class loader. This method works exactly as specified
- * by the static {@link
- * #defineModulesWithManyLoaders(Configuration,List,ClassLoader)
- * defineModulesWithManyLoaders} method when invoked with this layer as the
- * parent. In other words, if this layer is {@code thisLayer} then this
- * method is equivalent to invoking:
- * {@code
- * Layer.defineModulesWithManyLoaders(cf, List.of(thisLayer), parentLoader).layer();
- * }
- *
- * @param cf
- * The configuration for the layer
- * @param parentLoader
- * The parent class loader for each of the class loaders created by
- * this method; may be {@code null} for the bootstrap class loader
- *
- * @return The newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent of the given configuration is not the configuration
- * for this layer
- * @throws LayerInstantiationException
- * If the layer cannot be created for any of the reasons specified
- * by the static {@code defineModulesWithManyLoaders} method
- * @throws SecurityException
- * If {@code RuntimePermission("createClassLoader")} or
- * {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- *
- * @see #findLoader
- */
- public Layer defineModulesWithManyLoaders(Configuration cf,
- ClassLoader parentLoader) {
- return defineModulesWithManyLoaders(cf, List.of(this), parentLoader).layer();
- }
-
-
- /**
- * Creates a new layer, with this layer as its parent, by defining the
- * 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
- * given function. This method works exactly as specified by the static
- * {@link #defineModules(Configuration,List,Function) defineModules}
- * method when invoked with this layer as the parent. In other words, if
- * this layer is {@code thisLayer} then this method is equivalent to
- * invoking:
- * {@code
- * Layer.defineModules(cf, List.of(thisLayer), clf).layer();
- * }
- *
- * @param cf
- * The configuration for the layer
- * @param clf
- * The function to map a module name to a class loader
- *
- * @return The newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent of the given configuration is not the configuration
- * for this layer
- * @throws LayerInstantiationException
- * If the layer cannot be created for any of the reasons specified
- * by the static {@code defineModules} method
- * @throws SecurityException
- * If {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- */
- public Layer defineModules(Configuration cf,
- Function clf) {
- return defineModules(cf, List.of(this), clf).layer();
- }
-
- /**
- * Creates a new layer by defining the modules in the given {@code
- * Configuration} to the Java virtual machine. This method creates one
- * class loader and defines all modules to that class loader.
- *
- * The class loader created by this method implements direct
- * delegation when loading types from modules. When its {@link
- * ClassLoader#loadClass(String, boolean) loadClass} method is invoked to
- * load a class then it uses the package name of the class to map it to a
- * module. This may be a module in this layer and hence defined to the same
- * class loader. It may be a package in a module in a parent layer that is
- * exported to one or more of the modules in this layer. The class
- * loader delegates to the class loader of the module, throwing {@code
- * ClassNotFoundException} if not found by that class loader.
- * When {@code loadClass} is invoked to load classes that do not map to a
- * module then it delegates to the parent class loader.
- *
- * Attempting to create a layer with all modules defined to the same
- * class loader can fail for the following reasons:
- *
- *
- *
- * Overlapping packages : Two or more modules in the
- * configuration have the same package.
- *
- * Split delegation : The resulting class loader would
- * need to delegate to more than one class loader in order to load types
- * in a specific package.
- *
- *
- *
- * In addition, a layer cannot be created if the configuration contains
- * a module named "{@code java.base}", or a module contains a package named
- * "{@code java}" or a package with a name starting with "{@code java.}".
- *
- * If there is a security manager then the class loader created by
- * this method will load classes and resources with privileges that are
- * restricted by the calling context of this method.
- *
- * @param cf
- * The configuration for the layer
- * @param parentLayers
- * The list of parent layers in search order
- * @param parentLoader
- * The parent class loader for the class loader created by this
- * method; may be {@code null} for the bootstrap class loader
- *
- * @return A controller that controls the newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent configurations do not match the configuration of
- * the parent layers, including order
- * @throws LayerInstantiationException
- * If all modules cannot be defined to the same class loader for any
- * of the reasons listed above
- * @throws SecurityException
- * If {@code RuntimePermission("createClassLoader")} or
- * {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- *
- * @see #findLoader
- */
- public static Controller defineModulesWithOneLoader(Configuration cf,
- List parentLayers,
- ClassLoader parentLoader)
- {
- List parents = new ArrayList<>(parentLayers);
- checkConfiguration(cf, parents);
-
- checkCreateClassLoaderPermission();
- checkGetClassLoaderPermission();
-
- try {
- Loader loader = new Loader(cf.modules(), parentLoader);
- loader.initRemotePackageMap(cf, parents);
- Layer layer = new Layer(cf, parents, mn -> loader);
- return new Controller(layer);
- } catch (IllegalArgumentException | IllegalStateException e) {
- throw new LayerInstantiationException(e.getMessage());
- }
- }
-
- /**
- * Creates a new layer by defining the modules in the given {@code
- * Configuration} to the Java virtual machine. Each module is defined to
- * its own {@link ClassLoader} created by this method. The {@link
- * ClassLoader#getParent() parent} of each class loader is the given parent
- * class loader.
- *
- * The class loaders created by this method implement direct
- * delegation when loading types from modules. When {@link
- * ClassLoader#loadClass(String, boolean) loadClass} method is invoked to
- * load a class then it uses the package name of the class to map it to a
- * module. The package may be in the module defined to the class loader.
- * The package may be exported by another module in this layer to the
- * module defined to the class loader. It may be in a package exported by a
- * module in a parent layer. The class loader delegates to the class loader
- * of the module, throwing {@code ClassNotFoundException} if not found by
- * that class loader.
- * When {@code loadClass} is invoked to load classes that do not map to a
- * module then it delegates to the parent class loader.
- *
- * If there is a security manager then the class loaders created by
- * this method will load classes and resources with privileges that are
- * restricted by the calling context of this method.
- *
- * @param cf
- * The configuration for the layer
- * @param parentLayers
- * The list of parent layers in search order
- * @param parentLoader
- * The parent class loader for each of the class loaders created by
- * this method; may be {@code null} for the bootstrap class loader
- *
- * @return A controller that controls the newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent configurations do not match the configuration of
- * the parent layers, including order
- * @throws LayerInstantiationException
- * If the layer cannot be created because the configuration contains
- * a module named "{@code java.base}" or a module contains a package
- * named "{@code java}" or a package with a name starting with
- * "{@code java.}"
- *
- * @throws SecurityException
- * If {@code RuntimePermission("createClassLoader")} or
- * {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- *
- * @see #findLoader
- */
- public static Controller defineModulesWithManyLoaders(Configuration cf,
- List parentLayers,
- ClassLoader parentLoader)
- {
- List parents = new ArrayList<>(parentLayers);
- checkConfiguration(cf, parents);
-
- checkCreateClassLoaderPermission();
- checkGetClassLoaderPermission();
-
- LoaderPool pool = new LoaderPool(cf, parents, parentLoader);
- try {
- Layer layer = new Layer(cf, parents, pool::loaderFor);
- return new Controller(layer);
- } catch (IllegalArgumentException | IllegalStateException e) {
- throw new LayerInstantiationException(e.getMessage());
- }
- }
-
- /**
- * Creates a new layer by defining the modules in the given {@code
- * Configuration} to the Java virtual machine. The given function maps each
- * module in the configuration, by name, to a class loader. Creating the
- * layer informs the Java virtual machine about the classes that may be
- * loaded so that the Java virtual machine knows which module that each
- * class is a member of.
- *
- * The class loader delegation implemented by the class loaders must
- * respect module readability. The class loaders should be
- * {@link ClassLoader#registerAsParallelCapable parallel-capable} so as to
- * avoid deadlocks during class loading. In addition, the entity creating
- * a new layer with this method should arrange that the class loaders be
- * ready to load from these modules before there are any attempts to load
- * classes or resources.
- *
- * Creating a {@code Layer} can fail for the following reasons:
- *
- *
- *
- * Two or more modules with the same package are mapped to the
- * same class loader.
- *
- * A module is mapped to a class loader that already has a
- * module of the same name defined to it.
- *
- * A module is mapped to a class loader that has already
- * defined types in any of the packages in the module.
- *
- *
- *
- * In addition, a layer cannot be created if the configuration contains
- * a module named "{@code java.base}", a configuration contains a module
- * with a package named "{@code java}" or a package name starting with
- * "{@code java.}" and the module is mapped to a class loader other than
- * the {@link ClassLoader#getPlatformClassLoader() platform class loader},
- * or the function to map a module name to a class loader returns
- * {@code null}.
- *
- * If the function to map a module name to class loader throws an error
- * or runtime exception then it is propagated to the caller of this method.
- *
- *
- * @apiNote It is implementation specific as to whether creating a Layer
- * 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
- * to the Java virtual machine.
- *
- * @param cf
- * The configuration for the layer
- * @param parentLayers
- * The list of parent layers in search order
- * @param clf
- * The function to map a module name to a class loader
- *
- * @return A controller that controls the newly created layer
- *
- * @throws IllegalArgumentException
- * If the parent configurations do not match the configuration of
- * the parent layers, including order
- * @throws LayerInstantiationException
- * If creating the layer fails for any of the reasons listed above
- * @throws SecurityException
- * If {@code RuntimePermission("getClassLoader")} is denied by
- * the security manager
- */
- public static Controller defineModules(Configuration cf,
- List parentLayers,
- Function clf)
- {
- List parents = new ArrayList<>(parentLayers);
- checkConfiguration(cf, parents);
- Objects.requireNonNull(clf);
-
- checkGetClassLoaderPermission();
-
- // The boot layer is checked during module system initialization
- if (boot() != null) {
- checkForDuplicatePkgs(cf, clf);
- }
-
- try {
- Layer layer = new Layer(cf, parents, clf);
- return new Controller(layer);
- } catch (IllegalArgumentException | IllegalStateException e) {
- throw new LayerInstantiationException(e.getMessage());
- }
- }
-
-
- /**
- * Checks that the parent configurations match the configuration of
- * the parent layers.
- */
- private static void checkConfiguration(Configuration cf,
- List parentLayers)
- {
- Objects.requireNonNull(cf);
-
- List parentConfigurations = cf.parents();
- if (parentLayers.size() != parentConfigurations.size())
- throw new IllegalArgumentException("wrong number of parents");
-
- int index = 0;
- for (Layer parent : parentLayers) {
- if (parent.configuration() != parentConfigurations.get(index)) {
- throw new IllegalArgumentException(
- "Parent of configuration != configuration of this Layer");
- }
- index++;
- }
- }
-
- private static void checkCreateClassLoaderPermission() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
- }
-
- private static void checkGetClassLoaderPermission() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
- }
-
- /**
- * Checks a configuration and the module-to-loader mapping to ensure that
- * no two modules mapped to the same class loader have the same package.
- * It also checks that no two automatic modules have the same package.
- *
- * @throws LayerInstantiationException
- */
- private static void checkForDuplicatePkgs(Configuration cf,
- Function clf)
- {
- // HashMap allows null keys
- Map> loaderToPackages = new HashMap<>();
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
- ClassLoader loader = clf.apply(descriptor.name());
-
- Set loaderPackages
- = loaderToPackages.computeIfAbsent(loader, k -> new HashSet<>());
-
- for (String pkg : descriptor.packages()) {
- boolean added = loaderPackages.add(pkg);
- if (!added) {
- throw fail("More than one module with package %s mapped" +
- " to the same class loader", pkg);
- }
- }
- }
- }
-
- /**
- * Creates a LayerInstantiationException with the a message formatted from
- * the given format string and arguments.
- */
- private static LayerInstantiationException fail(String fmt, Object ... args) {
- String msg = String.format(fmt, args);
- return new LayerInstantiationException(msg);
- }
-
-
- /**
- * Returns the configuration for this layer.
- *
- * @return The configuration for this layer
- */
- public Configuration configuration() {
- return cf;
- }
-
-
- /**
- * Returns the list of this layer's parents unless this is the
- * {@linkplain #empty empty layer}, which has no parents and so an
- * empty list is returned.
- *
- * @return The list of this layer's parents
- */
- public List parents() {
- return parents;
- }
-
-
- /**
- * Returns an ordered stream of layers. The first element is is this layer,
- * the remaining elements are the parent layers in DFS order.
- *
- * @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.
- */
- Stream layers() {
- List allLayers = this.allLayers;
- if (allLayers != null)
- return allLayers.stream();
-
- allLayers = new ArrayList<>();
- Set visited = new HashSet<>();
- Deque stack = new ArrayDeque<>();
- visited.add(this);
- stack.push(this);
-
- while (!stack.isEmpty()) {
- Layer layer = stack.pop();
- allLayers.add(layer);
-
- // push in reverse order
- for (int i = layer.parents.size() - 1; i >= 0; i--) {
- Layer parent = layer.parents.get(i);
- if (!visited.contains(parent)) {
- visited.add(parent);
- stack.push(parent);
- }
- }
- }
-
- this.allLayers = allLayers = Collections.unmodifiableList(allLayers);
- return allLayers.stream();
- }
-
- private volatile List allLayers;
-
- /**
- * Returns the set of the modules in this layer.
- *
- * @return A possibly-empty unmodifiable set of the modules in this layer
- */
- public Set modules() {
- Set modules = this.modules;
- if (modules == null) {
- this.modules = modules =
- Collections.unmodifiableSet(new HashSet<>(nameToModule.values()));
- }
- return modules;
- }
-
- private volatile Set modules;
-
-
- /**
- * Returns the module with the given name in this layer, or if not in this
- * layer, the {@linkplain #parents parent} layers. Finding a module in
- * parent layers is equivalent to invoking {@code findModule} on each
- * parent, in search order, until the module is found or all parents have
- * been searched. In a tree of layers then this is equivalent to
- * a depth-first search.
- *
- * @param name
- * The name of the module to find
- *
- * @return The module with the given name or an empty {@code Optional}
- * if there isn't a module with this name in this layer or any
- * parent layer
- */
- public Optional findModule(String name) {
- Objects.requireNonNull(name);
- if (this == EMPTY_LAYER)
- return Optional.empty();
- Module m = nameToModule.get(name);
- if (m != null)
- return Optional.of(m);
-
- return layers()
- .skip(1) // skip this layer
- .map(l -> l.nameToModule)
- .filter(map -> map.containsKey(name))
- .map(map -> map.get(name))
- .findAny();
- }
-
-
- /**
- * Returns the {@code ClassLoader} for the module with the given name. If
- * a module of the given name is not in this layer then the {@link #parents
- * parent} layers are searched in the manner specified by {@link
- * #findModule(String) findModule}.
- *
- * If there is a security manager then its {@code checkPermission}
- * method is called with a {@code RuntimePermission("getClassLoader")}
- * permission to check that the caller is allowed to get access to the
- * class loader.
- *
- * @apiNote This method does not return an {@code Optional}
- * because `null` must be used to represent the bootstrap class loader.
- *
- * @param name
- * The name of the module to find
- *
- * @return The ClassLoader that the module is defined to
- *
- * @throws IllegalArgumentException if a module of the given name is not
- * defined in this layer or any parent of this layer
- *
- * @throws SecurityException if denied by the security manager
- */
- public ClassLoader findLoader(String name) {
- Optional om = findModule(name);
-
- // can't use map(Module::getClassLoader) as class loader can be null
- if (om.isPresent()) {
- return om.get().getClassLoader();
- } else {
- throw new IllegalArgumentException("Module " + name
- + " not known to this layer");
- }
- }
-
- /**
- * Returns a string describing this layer.
- *
- * @return A possibly empty string describing this layer
- */
- @Override
- public String toString() {
- return modules().stream()
- .map(Module::getName)
- .collect(Collectors.joining(", "));
- }
-
- /**
- * Returns the empty layer. There are no modules in the empty
- * layer. It has no parents.
- *
- * @return The empty layer
- */
- public static Layer empty() {
- return EMPTY_LAYER;
- }
-
-
- /**
- * Returns the boot layer. The boot layer contains at least one module,
- * {@code java.base}. Its parent is the {@link #empty() empty} layer.
- *
- * @apiNote This method returns {@code null} during startup and before
- * the boot layer is fully initialized.
- *
- * @return The boot layer
- */
- public static Layer boot() {
- return SharedSecrets.getJavaLangAccess().getBootLayer();
- }
-
-
- /**
- * Returns the ServicesCatalog for this Layer, creating it if not
- * already created.
- */
- ServicesCatalog getServicesCatalog() {
- ServicesCatalog servicesCatalog = this.servicesCatalog;
- if (servicesCatalog != null)
- return servicesCatalog;
-
- synchronized (this) {
- servicesCatalog = this.servicesCatalog;
- if (servicesCatalog == null) {
- servicesCatalog = ServicesCatalog.create();
- nameToModule.values().forEach(servicesCatalog::register);
- this.servicesCatalog = servicesCatalog;
- }
- }
-
- return servicesCatalog;
- }
-
- private volatile ServicesCatalog servicesCatalog;
-
-
- /**
- * Record that this layer has at least one module defined to the given
- * class loader.
- */
- void bindToLoader(ClassLoader loader) {
- // CLV.computeIfAbsent(loader, (cl, clv) -> new CopyOnWriteArrayList<>())
- List list = CLV.get(loader);
- if (list == null) {
- list = new CopyOnWriteArrayList<>();
- List previous = CLV.putIfAbsent(loader, list);
- if (previous != null) list = previous;
- }
- list.add(this);
- }
-
- /**
- * Returns a stream of the layers that have at least one module defined to
- * the given class loader.
- */
- static Stream layers(ClassLoader loader) {
- List list = CLV.get(loader);
- if (list != null) {
- return list.stream();
- } else {
- return Stream.empty();
- }
- }
-
- // the list of layers with modules defined to a class loader
- private static final ClassLoaderValue> CLV = new ClassLoaderValue<>();
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2015, 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 java.lang.reflect;
-
-/**
- * Thrown when creating a Layer fails.
- *
- * @see Layer
- *
- * @since 9
- * @spec JPMS
- */
-public class LayerInstantiationException extends RuntimeException {
- private static final long serialVersionUID = -906239691613568347L;
-
- /**
- * Constructs a {@code LayerInstantiationException} with no detail message.
- */
- public LayerInstantiationException() {
- }
-
- /**
- * Constructs a {@code LayerInstantiationException} with the given detail
- * message.
- *
- * @param msg
- * The detail message; can be {@code null}
- */
- public LayerInstantiationException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs a {@code LayerInstantiationException} with the given cause.
- *
- * @param cause
- * The cause; can be {@code null}
- */
- public LayerInstantiationException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructs a {@code FindException} with the given detail message
- * and cause.
- *
- * @param msg
- * The detail message; can be {@code null}
- * @param cause
- * The cause; can be {@code null}
- */
- public LayerInstantiationException(String msg, Throwable cause) {
- super(msg, cause);
- }
-
-}
-
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/Module.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Module.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1591 +0,0 @@
-/*
- * Copyright (c) 2014, 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.reflect;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.annotation.Annotation;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleReference;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleDescriptor.Exports;
-import java.lang.module.ModuleDescriptor.Opens;
-import java.lang.module.ModuleDescriptor.Version;
-import java.lang.module.ResolvedModule;
-import java.net.URI;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-import java.util.stream.Stream;
-
-import jdk.internal.loader.BuiltinClassLoader;
-import jdk.internal.loader.BootLoader;
-import jdk.internal.misc.JavaLangAccess;
-import jdk.internal.misc.JavaLangReflectModuleAccess;
-import jdk.internal.misc.SharedSecrets;
-import jdk.internal.module.ServicesCatalog;
-import jdk.internal.module.Resources;
-import jdk.internal.org.objectweb.asm.AnnotationVisitor;
-import jdk.internal.org.objectweb.asm.Attribute;
-import jdk.internal.org.objectweb.asm.ClassReader;
-import jdk.internal.org.objectweb.asm.ClassVisitor;
-import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.internal.org.objectweb.asm.Opcodes;
-import jdk.internal.reflect.CallerSensitive;
-import jdk.internal.reflect.Reflection;
-import sun.security.util.SecurityConstants;
-
-/**
- * Represents a run-time module, either {@link #isNamed() named} or unnamed.
- *
- * 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
- * machine to create a module {@link Layer Layer}.
- *
- * An unnamed module does not have a name. There is an unnamed module for
- * each {@link ClassLoader ClassLoader}, obtained by invoking its {@link
- * ClassLoader#getUnnamedModule() getUnnamedModule} method. All types that are
- * not in a named module are members of their defining class loader's unnamed
- * module.
- *
- * The package names that are parameters or returned by methods defined in
- * this class are the fully-qualified names of the packages as defined in
- * section 6.5.3 of The Java™ Language Specification , for
- * example, {@code "java.lang"}.
- *
- * Unless otherwise specified, passing a {@code null} argument to a method
- * in this class causes a {@link NullPointerException NullPointerException} to
- * be thrown.
- *
- * @since 9
- * @spec JPMS
- * @see java.lang.Class#getModule
- */
-
-public final class Module implements AnnotatedElement {
-
- // the layer that contains this module, can be null
- private final Layer layer;
-
- // module name and loader, these fields are read by VM
- private final String name;
- private final ClassLoader loader;
-
- // the module descriptor
- private final ModuleDescriptor descriptor;
-
-
- /**
- * Creates a new named Module. The resulting Module will be defined to the
- * VM but will not read any other modules, will not have any exports setup
- * and will not be registered in the service catalog.
- */
- private Module(Layer layer,
- ClassLoader loader,
- ModuleDescriptor descriptor,
- URI uri)
- {
- this.layer = layer;
- this.name = descriptor.name();
- this.loader = loader;
- this.descriptor = descriptor;
-
- // define module to VM
-
- boolean isOpen = descriptor.isOpen();
- Version version = descriptor.version().orElse(null);
- String vs = Objects.toString(version, null);
- String loc = Objects.toString(uri, null);
- String[] packages = descriptor.packages().toArray(new String[0]);
- defineModule0(this, isOpen, vs, loc, packages);
- }
-
-
- /**
- * Create the unnamed Module for the given ClassLoader.
- *
- * @see ClassLoader#getUnnamedModule
- */
- private Module(ClassLoader loader) {
- this.layer = null;
- this.name = null;
- this.loader = loader;
- this.descriptor = null;
- }
-
-
- /**
- * Creates a named module but without defining the module to the VM.
- *
- * @apiNote This constructor is for VM white-box testing.
- */
- Module(ClassLoader loader, ModuleDescriptor descriptor) {
- this.layer = null;
- this.name = descriptor.name();
- this.loader = loader;
- this.descriptor = descriptor;
- }
-
-
-
- /**
- * Returns {@code true} if this module is a named module.
- *
- * @return {@code true} if this is a named module
- *
- * @see ClassLoader#getUnnamedModule()
- */
- public boolean isNamed() {
- return name != null;
- }
-
- /**
- * Returns the module name or {@code null} if this module is an unnamed
- * module.
- *
- * @return The module name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the {@code ClassLoader} for this module.
- *
- * If there is a security manager then its {@code checkPermission}
- * method if first called with a {@code RuntimePermission("getClassLoader")}
- * permission to check that the caller is allowed to get access to the
- * class loader.
- *
- * @return The class loader for this module
- *
- * @throws SecurityException
- * If denied by the security manager
- */
- public ClassLoader getClassLoader() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
- }
- return loader;
- }
-
- /**
- * Returns the module descriptor for this module or {@code null} if this
- * module is an unnamed module.
- *
- * @return The module descriptor for this module
- */
- public ModuleDescriptor getDescriptor() {
- return descriptor;
- }
-
- /**
- * Returns the layer that contains this module or {@code null} if this
- * module is not in a layer.
- *
- * A module {@code Layer} contains named modules and therefore this
- * method always returns {@code null} when invoked on an unnamed module.
- *
- * Dynamic modules are named
- * modules that are generated at runtime. A dynamic module may or may
- * not be in a module Layer.
- *
- * @return The layer that contains this module
- *
- * @see Proxy
- */
- public Layer getLayer() {
- if (isNamed()) {
- Layer layer = this.layer;
- if (layer != null)
- return layer;
-
- // special-case java.base as it is created before the boot Layer
- if (loader == null && name.equals("java.base")) {
- return SharedSecrets.getJavaLangAccess().getBootLayer();
- }
- }
-
- return null;
- }
-
-
- // --
-
- // special Module to mean "all unnamed modules"
- private static final Module ALL_UNNAMED_MODULE = new Module(null);
-
- // special Module to mean "everyone"
- private static final Module EVERYONE_MODULE = new Module(null);
-
- // set contains EVERYONE_MODULE, used when a package is opened or
- // exported unconditionally
- private static final Set EVERYONE_SET = Set.of(EVERYONE_MODULE);
-
-
- // -- readability --
-
- // the modules that this module reads
- private volatile Set reads;
-
- // additional module (2nd key) that some module (1st key) reflectively reads
- private static final WeakPairMap reflectivelyReads
- = new WeakPairMap<>();
-
-
- /**
- * Indicates if this module reads the given module. This method returns
- * {@code true} if invoked to test if this module reads itself. It also
- * returns {@code true} if invoked on an unnamed module (as unnamed
- * modules read all modules).
- *
- * @param other
- * The other module
- *
- * @return {@code true} if this module reads {@code other}
- *
- * @see #addReads(Module)
- */
- public boolean canRead(Module other) {
- Objects.requireNonNull(other);
-
- // an unnamed module reads all modules
- if (!this.isNamed())
- return true;
-
- // all modules read themselves
- if (other == this)
- return true;
-
- // check if this module reads other
- if (other.isNamed()) {
- Set reads = this.reads; // volatile read
- if (reads != null && reads.contains(other))
- return true;
- }
-
- // check if this module reads the other module reflectively
- if (reflectivelyReads.containsKeyPair(this, other))
- return true;
-
- // if other is an unnamed module then check if this module reads
- // all unnamed modules
- if (!other.isNamed()
- && reflectivelyReads.containsKeyPair(this, ALL_UNNAMED_MODULE))
- return true;
-
- return false;
- }
-
- /**
- * If the caller's module is this module then update this module to read
- * the given module.
- *
- * This method is a no-op if {@code other} is this module (all modules read
- * themselves), this module is an unnamed module (as unnamed modules read
- * all modules), or this module already reads {@code other}.
- *
- * @implNote Read edges added by this method are weak and
- * do not prevent {@code other} from being GC'ed when this module is
- * strongly reachable.
- *
- * @param other
- * The other module
- *
- * @return this module
- *
- * @throws IllegalCallerException
- * If this is a named module and the caller's module is not this
- * module
- *
- * @see #canRead
- */
- @CallerSensitive
- public Module addReads(Module other) {
- Objects.requireNonNull(other);
- if (this.isNamed()) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != this) {
- throw new IllegalCallerException(caller + " != " + this);
- }
- implAddReads(other, true);
- }
- return this;
- }
-
- /**
- * Updates this module to read another module.
- *
- * @apiNote This method is for Proxy use and white-box testing.
- */
- void implAddReads(Module other) {
- implAddReads(other, true);
- }
-
- /**
- * Updates this module to read another module without notifying the VM.
- *
- * @apiNote This method is for VM white-box testing.
- */
- void implAddReadsNoSync(Module other) {
- implAddReads(other, false);
- }
-
- /**
- * Makes the given {@code Module} readable to this module.
- *
- * If {@code syncVM} is {@code true} then the VM is notified.
- */
- private void implAddReads(Module other, boolean syncVM) {
- if (!canRead(other)) {
- // update VM first, just in case it fails
- if (syncVM) {
- if (other == ALL_UNNAMED_MODULE) {
- addReads0(this, null);
- } else {
- addReads0(this, other);
- }
- }
-
- // add reflective read
- reflectivelyReads.putIfAbsent(this, other, Boolean.TRUE);
- }
- }
-
-
- // -- exported and open packages --
-
- // the packages are open to other modules, can be null
- // if the value contains EVERYONE_MODULE then the package is open to all
- private volatile Map> openPackages;
-
- // the packages that are exported, can be null
- // if the value contains EVERYONE_MODULE then the package is exported to all
- private volatile Map> exportedPackages;
-
- // additional exports or opens added at run-time
- // this module (1st key), other module (2nd key)
- // (package name, open?) (value)
- private static final WeakPairMap>
- reflectivelyExports = new WeakPairMap<>();
-
-
- /**
- * Returns {@code true} if this module exports the given package to at
- * least the given module.
- *
- * This method returns {@code true} if invoked to test if a package in
- * this module is exported to itself. It always returns {@code true} when
- * invoked on an unnamed module. A package that is {@link #isOpen open} to
- * the given module is considered exported to that module at run-time and
- * so this method returns {@code true} if the package is open to the given
- * module.
- *
- * This method does not check if the given module reads this module.
- *
- * @param pn
- * The package name
- * @param other
- * The other module
- *
- * @return {@code true} if this module exports the package to at least the
- * given module
- *
- * @see ModuleDescriptor#exports()
- * @see #addExports(String,Module)
- */
- public boolean isExported(String pn, Module other) {
- Objects.requireNonNull(pn);
- Objects.requireNonNull(other);
- return implIsExportedOrOpen(pn, other, /*open*/false);
- }
-
- /**
- * Returns {@code true} if this module has opened a package to at
- * least the given module.
- *
- * This method returns {@code true} if invoked to test if a package in
- * this module is open to itself. It returns {@code true} when invoked on an
- * {@link ModuleDescriptor#isOpen open} module with a package in the module.
- * It always returns {@code true} when invoked on an unnamed module.
- *
- * This method does not check if the given module reads this module.
- *
- * @param pn
- * The package name
- * @param other
- * The other module
- *
- * @return {@code true} if this module has opened the package
- * to at least the given module
- *
- * @see ModuleDescriptor#opens()
- * @see #addOpens(String,Module)
- * @see AccessibleObject#setAccessible(boolean)
- * @see java.lang.invoke.MethodHandles#privateLookupIn
- */
- public boolean isOpen(String pn, Module other) {
- Objects.requireNonNull(pn);
- Objects.requireNonNull(other);
- return implIsExportedOrOpen(pn, other, /*open*/true);
- }
-
- /**
- * Returns {@code true} if this module exports the given package
- * unconditionally.
- *
- * This method always returns {@code true} when invoked on an unnamed
- * module. A package that is {@link #isOpen(String) opened} unconditionally
- * is considered exported unconditionally at run-time and so this method
- * returns {@code true} if the package is opened unconditionally.
- *
- * This method does not check if the given module reads this module.
- *
- * @param pn
- * The package name
- *
- * @return {@code true} if this module exports the package unconditionally
- *
- * @see ModuleDescriptor#exports()
- */
- public boolean isExported(String pn) {
- Objects.requireNonNull(pn);
- return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/false);
- }
-
- /**
- * Returns {@code true} if this module has opened a package
- * unconditionally.
- *
- * This method always returns {@code true} when invoked on an unnamed
- * module. Additionally, it always returns {@code true} when invoked on an
- * {@link ModuleDescriptor#isOpen open} module with a package in the
- * module.
- *
- * This method does not check if the given module reads this module.
- *
- * @param pn
- * The package name
- *
- * @return {@code true} if this module has opened the package
- * unconditionally
- *
- * @see ModuleDescriptor#opens()
- */
- public boolean isOpen(String pn) {
- Objects.requireNonNull(pn);
- return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/true);
- }
-
-
- /**
- * Returns {@code true} if this module exports or opens the given package
- * to the given module. If the other module is {@code EVERYONE_MODULE} then
- * this method tests if the package is exported or opened unconditionally.
- */
- private boolean implIsExportedOrOpen(String pn, Module other, boolean open) {
- // all packages in unnamed modules are open
- if (!isNamed())
- return true;
-
- // all packages are exported/open to self
- if (other == this && containsPackage(pn))
- return true;
-
- // all packages in open and automatic modules are open
- if (descriptor.isOpen() || descriptor.isAutomatic())
- return containsPackage(pn);
-
- // exported/opened via module declaration/descriptor
- if (isStaticallyExportedOrOpen(pn, other, open))
- return true;
-
- // exported via addExports/addOpens
- if (isReflectivelyExportedOrOpen(pn, other, open))
- return true;
-
- // not exported or open to other
- return false;
- }
-
- /**
- * Returns {@code true} if this module exports or opens a package to
- * the given module via its module declaration.
- */
- private boolean isStaticallyExportedOrOpen(String pn, Module other, boolean open) {
- // package is open to everyone or
- Map> openPackages = this.openPackages;
- if (openPackages != null) {
- Set targets = openPackages.get(pn);
- if (targets != null) {
- if (targets.contains(EVERYONE_MODULE))
- return true;
- if (other != EVERYONE_MODULE && targets.contains(other))
- return true;
- }
- }
-
- if (!open) {
- // package is exported to everyone or
- Map> exportedPackages = this.exportedPackages;
- if (exportedPackages != null) {
- Set targets = exportedPackages.get(pn);
- if (targets != null) {
- if (targets.contains(EVERYONE_MODULE))
- return true;
- if (other != EVERYONE_MODULE && targets.contains(other))
- return true;
- }
- }
- }
-
- return false;
- }
-
-
- /**
- * Returns {@code true} if this module reflectively exports or opens given
- * package package to the given module.
- */
- private boolean isReflectivelyExportedOrOpen(String pn, Module other, boolean open) {
- // exported or open to all modules
- Map exports = reflectivelyExports.get(this, EVERYONE_MODULE);
- if (exports != null) {
- Boolean b = exports.get(pn);
- if (b != null) {
- boolean isOpen = b.booleanValue();
- if (!open || isOpen) return true;
- }
- }
-
- if (other != EVERYONE_MODULE) {
-
- // exported or open to other
- exports = reflectivelyExports.get(this, other);
- if (exports != null) {
- Boolean b = exports.get(pn);
- if (b != null) {
- boolean isOpen = b.booleanValue();
- if (!open || isOpen) return true;
- }
- }
-
- // other is an unnamed module && exported or open to all unnamed
- if (!other.isNamed()) {
- exports = reflectivelyExports.get(this, ALL_UNNAMED_MODULE);
- if (exports != null) {
- Boolean b = exports.get(pn);
- if (b != null) {
- boolean isOpen = b.booleanValue();
- if (!open || isOpen) return true;
- }
- }
- }
-
- }
-
- return false;
- }
-
-
- /**
- * If the caller's module is this module then update this module to export
- * the given package to the given module.
- *
- * This method has no effect if the package is already exported (or
- * open ) to the given module.
- *
- * @apiNote As specified in section 5.4.3 of the The Java™
- * Virtual Machine Specification , if an attempt to resolve a
- * symbolic reference fails because of a linkage error, then subsequent
- * attempts to resolve the reference always fail with the same error that
- * was thrown as a result of the initial resolution attempt.
- *
- * @param pn
- * The package name
- * @param other
- * The module
- *
- * @return this module
- *
- * @throws IllegalArgumentException
- * If {@code pn} is {@code null}, or this is a named module and the
- * package {@code pn} is not a package in this module
- * @throws IllegalCallerException
- * If this is a named module and the caller's module is not this
- * module
- *
- * @jvms 5.4.3 Resolution
- * @see #isExported(String,Module)
- */
- @CallerSensitive
- public Module addExports(String pn, Module other) {
- if (pn == null)
- throw new IllegalArgumentException("package is null");
- Objects.requireNonNull(other);
-
- if (isNamed()) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != this) {
- throw new IllegalCallerException(caller + " != " + this);
- }
- implAddExportsOrOpens(pn, other, /*open*/false, /*syncVM*/true);
- }
-
- return this;
- }
-
- /**
- * If this module has opened a package to at least the caller
- * module then update this module to open the package to the given module.
- * Opening a package with this method allows all types in the package,
- * and all their members, not just public types and their public members,
- * to be reflected on by the given module when using APIs that support
- * private access or a way to bypass or suppress default Java language
- * access control checks.
- *
- * This method has no effect if the package is already open
- * to the given module.
- *
- * @param pn
- * The package name
- * @param other
- * The module
- *
- * @return this module
- *
- * @throws IllegalArgumentException
- * If {@code pn} is {@code null}, or this is a named module and the
- * package {@code pn} is not a package in this module
- * @throws IllegalCallerException
- * If this is a named module and this module has not opened the
- * package to at least the caller's module
- *
- * @see #isOpen(String,Module)
- * @see AccessibleObject#setAccessible(boolean)
- * @see java.lang.invoke.MethodHandles#privateLookupIn
- */
- @CallerSensitive
- public Module addOpens(String pn, Module other) {
- if (pn == null)
- throw new IllegalArgumentException("package is null");
- Objects.requireNonNull(other);
-
- if (isNamed()) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != this && !isOpen(pn, caller))
- throw new IllegalCallerException(pn + " is not open to " + caller);
- implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
- }
-
- return this;
- }
-
-
- /**
- * Updates the exports so that package {@code pn} is exported to module
- * {@code other} but without notifying the VM.
- *
- * @apiNote This method is for VM white-box testing.
- */
- void implAddExportsNoSync(String pn, Module other) {
- if (other == null)
- other = EVERYONE_MODULE;
- implAddExportsOrOpens(pn.replace('/', '.'), other, false, false);
- }
-
- /**
- * Updates the exports so that package {@code pn} is exported to module
- * {@code other}.
- *
- * @apiNote This method is for white-box testing.
- */
- void implAddExports(String pn, Module other) {
- implAddExportsOrOpens(pn, other, false, true);
- }
-
- /**
- * Updates the module to open package {@code pn} to module {@code other}.
- *
- * @apiNote This method is for white-box tests and jtreg
- */
- void implAddOpens(String pn, Module other) {
- implAddExportsOrOpens(pn, other, true, true);
- }
-
- /**
- * Updates a module to export or open a module to another module.
- *
- * If {@code syncVM} is {@code true} then the VM is notified.
- */
- private void implAddExportsOrOpens(String pn,
- Module other,
- boolean open,
- boolean syncVM) {
- Objects.requireNonNull(other);
- Objects.requireNonNull(pn);
-
- // all packages are open in unnamed, open, and automatic modules
- if (!isNamed() || descriptor.isOpen() || descriptor.isAutomatic())
- return;
-
- // nothing to do if already exported/open to other
- if (implIsExportedOrOpen(pn, other, open))
- return;
-
- // can only export a package in the module
- if (!containsPackage(pn)) {
- throw new IllegalArgumentException("package " + pn
- + " not in contents");
- }
-
- // update VM first, just in case it fails
- if (syncVM) {
- if (other == EVERYONE_MODULE) {
- addExportsToAll0(this, pn);
- } else if (other == ALL_UNNAMED_MODULE) {
- addExportsToAllUnnamed0(this, pn);
- } else {
- addExports0(this, pn, other);
- }
- }
-
- // add package name to reflectivelyExports if absent
- Map map = reflectivelyExports
- .computeIfAbsent(this, other,
- (m1, m2) -> new ConcurrentHashMap<>());
-
- if (open) {
- map.put(pn, Boolean.TRUE); // may need to promote from FALSE to TRUE
- } else {
- map.putIfAbsent(pn, Boolean.FALSE);
- }
- }
-
-
- // -- services --
-
- // additional service type (2nd key) that some module (1st key) uses
- private static final WeakPairMap, Boolean> reflectivelyUses
- = new WeakPairMap<>();
-
- /**
- * If the caller's module is this module then update this module to add a
- * service dependence on the given service type. This method is intended
- * for use by frameworks that invoke {@link java.util.ServiceLoader
- * ServiceLoader} on behalf of other modules or where the framework is
- * passed a reference to the service type by other code. This method is
- * a no-op when invoked on an unnamed module or an automatic module.
- *
- * This method does not cause {@link Configuration#resolveAndBind
- * resolveAndBind} to be re-run.
- *
- * @param service
- * The service type
- *
- * @return this module
- *
- * @throws IllegalCallerException
- * If this is a named module and the caller's module is not this
- * module
- *
- * @see #canUse(Class)
- * @see ModuleDescriptor#uses()
- */
- @CallerSensitive
- public Module addUses(Class> service) {
- Objects.requireNonNull(service);
-
- if (isNamed() && !descriptor.isAutomatic()) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != this) {
- throw new IllegalCallerException(caller + " != " + this);
- }
- implAddUses(service);
- }
-
- return this;
- }
-
- /**
- * Update this module to add a service dependence on the given service
- * type.
- */
- void implAddUses(Class> service) {
- if (!canUse(service)) {
- reflectivelyUses.putIfAbsent(this, service, Boolean.TRUE);
- }
- }
-
-
- /**
- * Indicates if this module has a service dependence on the given service
- * type. This method always returns {@code true} when invoked on an unnamed
- * module or an automatic module.
- *
- * @param service
- * The service type
- *
- * @return {@code true} if this module uses service type {@code st}
- *
- * @see #addUses(Class)
- */
- public boolean canUse(Class> service) {
- Objects.requireNonNull(service);
-
- if (!isNamed())
- return true;
-
- if (descriptor.isAutomatic())
- return true;
-
- // uses was declared
- if (descriptor.uses().contains(service.getName()))
- return true;
-
- // uses added via addUses
- return reflectivelyUses.containsKeyPair(this, service);
- }
-
-
-
- // -- packages --
-
- // Additional packages that are added to the module at run-time.
- private volatile Map extraPackages;
-
- private boolean containsPackage(String pn) {
- if (descriptor.packages().contains(pn))
- return true;
- Map extraPackages = this.extraPackages;
- if (extraPackages != null && extraPackages.containsKey(pn))
- return true;
- return false;
- }
-
-
- /**
- * Returns an array of the package names of the packages in this module.
- *
- * For named modules, the returned array contains an element for each
- * package in the module.
- *
- * For unnamed modules, this method is the equivalent to invoking the
- * {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of
- * this module's class loader and returning the array of package names.
- *
- * A package name appears at most once in the returned array.
- *
- * @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() {
- if (isNamed()) {
-
- Set packages = descriptor.packages();
- Map extraPackages = this.extraPackages;
- if (extraPackages == null) {
- return packages.toArray(new String[0]);
- } else {
- return Stream.concat(packages.stream(),
- extraPackages.keySet().stream())
- .toArray(String[]::new);
- }
-
- } else {
- // unnamed module
- Stream packages;
- if (loader == null) {
- packages = BootLoader.packages();
- } else {
- packages = SharedSecrets.getJavaLangAccess().packages(loader);
- }
- return packages.map(Package::getName).toArray(String[]::new);
- }
- }
-
- /**
- * Add a package to this module without notifying the VM.
- *
- * @apiNote This method is VM white-box testing.
- */
- void implAddPackageNoSync(String pn) {
- implAddPackage(pn.replace('/', '.'), false);
- }
-
- /**
- * Add a package to this module.
- *
- * If {@code syncVM} is {@code true} then the VM is notified. This method is
- * a no-op if this is an unnamed module or the module already contains the
- * package.
- *
- * @throws IllegalArgumentException if the package name is not legal
- * @throws IllegalStateException if the package is defined to another module
- */
- private void implAddPackage(String pn, boolean syncVM) {
- // no-op if unnamed module
- if (!isNamed())
- return;
-
- // no-op if module contains the package
- if (containsPackage(pn))
- return;
-
- // check package name is legal for named modules
- if (pn.isEmpty())
- throw new IllegalArgumentException("Cannot add package");
- for (int i=0; i extraPackages = this.extraPackages;
- if (extraPackages == null) {
- synchronized (this) {
- extraPackages = this.extraPackages;
- if (extraPackages == null)
- this.extraPackages = extraPackages = new ConcurrentHashMap<>();
- }
- }
-
- // update VM first in case it fails. This is a no-op if another thread
- // beats us to add the package first
- if (syncVM) {
- // throws IllegalStateException if defined to another module
- addPackage0(this, pn);
- if (descriptor.isOpen() || descriptor.isAutomatic()) {
- addExportsToAll0(this, pn);
- }
- }
- extraPackages.putIfAbsent(pn, Boolean.TRUE);
- }
-
-
- // -- creating Module objects --
-
- /**
- * Defines all module in a configuration to the runtime.
- *
- * @return a map of module name to runtime {@code Module}
- *
- * @throws IllegalArgumentException
- * If defining any of the modules to the VM fails
- */
- static Map defineModules(Configuration cf,
- Function clf,
- Layer layer)
- {
- Map nameToModule = new HashMap<>();
- Map moduleToLoader = new HashMap<>();
-
- boolean isBootLayer = (Layer.boot() == null);
- Set loaders = new HashSet<>();
-
- // map each module to a class loader
- for (ResolvedModule resolvedModule : cf.modules()) {
- String name = resolvedModule.name();
- ClassLoader loader = clf.apply(name);
- if (loader != null) {
- moduleToLoader.put(name, loader);
- loaders.add(loader);
- } else if (!isBootLayer) {
- throw new IllegalArgumentException("loader can't be 'null'");
- }
- }
-
- // define each module in the configuration to the VM
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleReference mref = resolvedModule.reference();
- ModuleDescriptor descriptor = mref.descriptor();
- String name = descriptor.name();
- URI uri = mref.location().orElse(null);
- ClassLoader loader = moduleToLoader.get(resolvedModule.name());
- Module m;
- if (loader == null && isBootLayer && name.equals("java.base")) {
- // java.base is already defined to the VM
- m = Object.class.getModule();
- } else {
- m = new Module(layer, loader, descriptor, uri);
- }
- nameToModule.put(name, m);
- moduleToLoader.put(name, loader);
- }
-
- // setup readability and exports
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleReference mref = resolvedModule.reference();
- ModuleDescriptor descriptor = mref.descriptor();
-
- String mn = descriptor.name();
- Module m = nameToModule.get(mn);
- assert m != null;
-
- // reads
- Set reads = new HashSet<>();
-
- // name -> source Module when in parent layer
- Map nameToSource = Collections.emptyMap();
-
- for (ResolvedModule other : resolvedModule.reads()) {
- Module m2 = null;
- if (other.configuration() == cf) {
- // this configuration
- m2 = nameToModule.get(other.name());
- assert m2 != null;
- } else {
- // parent layer
- for (Layer parent: layer.parents()) {
- m2 = findModule(parent, other);
- if (m2 != null)
- break;
- }
- assert m2 != null;
- if (nameToSource.isEmpty())
- nameToSource = new HashMap<>();
- nameToSource.put(other.name(), m2);
- }
- reads.add(m2);
-
- // update VM view
- addReads0(m, m2);
- }
- m.reads = reads;
-
- // automatic modules read all unnamed modules
- if (descriptor.isAutomatic()) {
- m.implAddReads(ALL_UNNAMED_MODULE, true);
- }
-
- // exports and opens
- initExportsAndOpens(m, nameToSource, nameToModule, layer.parents());
- }
-
- // register the modules in the boot layer
- if (isBootLayer) {
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleReference mref = resolvedModule.reference();
- ModuleDescriptor descriptor = mref.descriptor();
- if (!descriptor.provides().isEmpty()) {
- String name = descriptor.name();
- Module m = nameToModule.get(name);
- ClassLoader loader = moduleToLoader.get(name);
- ServicesCatalog catalog;
- if (loader == null) {
- catalog = BootLoader.getServicesCatalog();
- } else {
- catalog = ServicesCatalog.getServicesCatalog(loader);
- }
- catalog.register(m);
- }
- }
- }
-
- // record that there is a layer with modules defined to the class loader
- for (ClassLoader loader : loaders) {
- layer.bindToLoader(loader);
- }
-
- return nameToModule;
- }
-
-
- /**
- * Find the runtime Module corresponding to the given ResolvedModule
- * in the given parent layer (or its parents).
- */
- private static Module findModule(Layer parent, ResolvedModule resolvedModule) {
- Configuration cf = resolvedModule.configuration();
- String dn = resolvedModule.name();
- return parent.layers()
- .filter(l -> l.configuration() == cf)
- .findAny()
- .map(layer -> {
- Optional om = layer.findModule(dn);
- assert om.isPresent() : dn + " not found in layer";
- Module m = om.get();
- assert m.getLayer() == layer : m + " not in expected layer";
- return m;
- })
- .orElse(null);
- }
-
-
- /**
- * Initialize the maps of exported and open packages for module m.
- */
- private static void initExportsAndOpens(Module m,
- Map nameToSource,
- Map nameToModule,
- List parents) {
- // The VM doesn't special case open or automatic modules so need to
- // export all packages
- ModuleDescriptor descriptor = m.getDescriptor();
- if (descriptor.isOpen() || descriptor.isAutomatic()) {
- assert descriptor.opens().isEmpty();
- for (String source : descriptor.packages()) {
- addExportsToAll0(m, source);
- }
- return;
- }
-
- Map> openPackages = new HashMap<>();
- Map> exportedPackages = new HashMap<>();
-
- // process the open packages first
- for (Opens opens : descriptor.opens()) {
- String source = opens.source();
-
- if (opens.isQualified()) {
- // qualified opens
- Set targets = new HashSet<>();
- for (String target : opens.targets()) {
- Module m2 = findModule(target, nameToSource, nameToModule, parents);
- if (m2 != null) {
- addExports0(m, source, m2);
- targets.add(m2);
- }
- }
- if (!targets.isEmpty()) {
- openPackages.put(source, targets);
- }
- } else {
- // unqualified opens
- addExportsToAll0(m, source);
- openPackages.put(source, EVERYONE_SET);
- }
- }
-
- // next the exports, skipping exports when the package is open
- for (Exports exports : descriptor.exports()) {
- String source = exports.source();
-
- // skip export if package is already open to everyone
- Set openToTargets = openPackages.get(source);
- if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE))
- continue;
-
- if (exports.isQualified()) {
- // qualified exports
- Set targets = new HashSet<>();
- for (String target : exports.targets()) {
- Module m2 = findModule(target, nameToSource, nameToModule, parents);
- if (m2 != null) {
- // skip qualified export if already open to m2
- if (openToTargets == null || !openToTargets.contains(m2)) {
- addExports0(m, source, m2);
- targets.add(m2);
- }
- }
- }
- if (!targets.isEmpty()) {
- exportedPackages.put(source, targets);
- }
-
- } else {
- // unqualified exports
- addExportsToAll0(m, source);
- exportedPackages.put(source, EVERYONE_SET);
- }
- }
-
- if (!openPackages.isEmpty())
- m.openPackages = openPackages;
- if (!exportedPackages.isEmpty())
- m.exportedPackages = exportedPackages;
- }
-
- /**
- * Find the runtime Module with the given name. The module name is the
- * name of a target module in a qualified exports or opens directive.
- *
- * @param target The target module to find
- * @param nameToSource The modules in parent layers that are read
- * @param nameToModule The modules in the layer under construction
- * @param parents The parent layers
- */
- private static Module findModule(String target,
- Map nameToSource,
- Map nameToModule,
- List parents) {
- Module m = nameToSource.get(target);
- if (m == null) {
- m = nameToModule.get(target);
- if (m == null) {
- for (Layer parent : parents) {
- m = parent.findModule(target).orElse(null);
- if (m != null) break;
- }
- }
- }
- return m;
- }
-
-
- // -- annotations --
-
- /**
- * {@inheritDoc}
- * This method returns {@code null} when invoked on an unnamed module.
- */
- @Override
- public T getAnnotation(Class annotationClass) {
- return moduleInfoClass().getDeclaredAnnotation(annotationClass);
- }
-
- /**
- * {@inheritDoc}
- * This method returns an empty array when invoked on an unnamed module.
- */
- @Override
- public Annotation[] getAnnotations() {
- return moduleInfoClass().getAnnotations();
- }
-
- /**
- * {@inheritDoc}
- * This method returns an empty array when invoked on an unnamed module.
- */
- @Override
- public Annotation[] getDeclaredAnnotations() {
- return moduleInfoClass().getDeclaredAnnotations();
- }
-
- // cached class file with annotations
- private volatile Class> moduleInfoClass;
-
- private Class> moduleInfoClass() {
- Class> clazz = this.moduleInfoClass;
- if (clazz != null)
- return clazz;
-
- synchronized (this) {
- clazz = this.moduleInfoClass;
- if (clazz == null) {
- if (isNamed()) {
- PrivilegedAction> pa = this::loadModuleInfoClass;
- clazz = AccessController.doPrivileged(pa);
- }
- if (clazz == null) {
- class DummyModuleInfo { }
- clazz = DummyModuleInfo.class;
- }
- this.moduleInfoClass = clazz;
- }
- return clazz;
- }
- }
-
- private Class> loadModuleInfoClass() {
- Class> clazz = null;
- try (InputStream in = getResourceAsStream("module-info.class")) {
- if (in != null)
- clazz = loadModuleInfoClass(in);
- } catch (Exception ignore) { }
- return clazz;
- }
-
- /**
- * Loads module-info.class as a package-private interface in a class loader
- * that is a child of this module's class loader.
- */
- private Class> loadModuleInfoClass(InputStream in) throws IOException {
- final String MODULE_INFO = "module-info";
-
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
- + ClassWriter.COMPUTE_FRAMES);
-
- ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, cw) {
- @Override
- public void visit(int version,
- int access,
- String name,
- String signature,
- String superName,
- String[] interfaces) {
- cw.visit(version,
- Opcodes.ACC_INTERFACE
- + Opcodes.ACC_ABSTRACT
- + Opcodes.ACC_SYNTHETIC,
- MODULE_INFO,
- null,
- "java/lang/Object",
- null);
- }
- @Override
- public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
- // keep annotations
- return super.visitAnnotation(desc, visible);
- }
- @Override
- public void visitAttribute(Attribute attr) {
- // drop non-annotation attributes
- }
- };
-
- ClassReader cr = new ClassReader(in);
- cr.accept(cv, 0);
- byte[] bytes = cw.toByteArray();
-
- ClassLoader cl = new ClassLoader(loader) {
- @Override
- protected Class> findClass(String cn)throws ClassNotFoundException {
- if (cn.equals(MODULE_INFO)) {
- return super.defineClass(cn, bytes, 0, bytes.length);
- } else {
- throw new ClassNotFoundException(cn);
- }
- }
- };
-
- try {
- return cl.loadClass(MODULE_INFO);
- } catch (ClassNotFoundException e) {
- throw new InternalError(e);
- }
- }
-
-
- // -- misc --
-
-
- /**
- * Returns an input stream for reading a resource in this module.
- * The {@code name} parameter is a {@code '/'}-separated path name that
- * identifies the resource. As with {@link Class#getResourceAsStream
- * Class.getResourceAsStream}, this method delegates to the module's class
- * loader {@link ClassLoader#findResource(String,String)
- * findResource(String,String)} method, invoking it with the module name
- * (or {@code null} when the module is unnamed) and the name of the
- * resource. If the resource name has a leading slash then it is dropped
- * before delegation.
- *
- * A resource in a named module may be encapsulated so that
- * it cannot be located by code in other modules. Whether a resource can be
- * located or not is determined as follows:
- *
- *
- * If the resource name ends with "{@code .class}" then it is not
- * encapsulated.
- *
- * A package name is derived from the resource name. If
- * the package name is a {@link #getPackages() package} in the module
- * then the resource can only be located by the caller of this method
- * when the package is {@link #isOpen(String,Module) open} to at least
- * the caller's module. If the resource is not in a package in the module
- * then the resource is not encapsulated.
- *
- *
- * In the above, the package name for a resource is derived
- * from the subsequence of characters that precedes the last {@code '/'} in
- * the name and then replacing each {@code '/'} character in the subsequence
- * with {@code '.'}. A leading slash is ignored when deriving the package
- * name. As an example, the package name derived for a resource named
- * "{@code a/b/c/foo.properties}" is "{@code a.b.c}". A resource name
- * with the name "{@code META-INF/MANIFEST.MF}" is never encapsulated
- * because "{@code META-INF}" is not a legal package name.
- *
- * This method returns {@code null} if the resource is not in this
- * module, the resource is encapsulated and cannot be located by the caller,
- * or access to the resource is denied by the security manager.
- *
- * @param name
- * The resource name
- *
- * @return An input stream for reading the resource or {@code null}
- *
- * @throws IOException
- * If an I/O error occurs
- *
- * @see Class#getResourceAsStream(String)
- */
- @CallerSensitive
- public InputStream getResourceAsStream(String name) throws IOException {
- if (name.startsWith("/")) {
- name = name.substring(1);
- }
-
- if (isNamed() && Resources.canEncapsulate(name)) {
- Module caller = Reflection.getCallerClass().getModule();
- if (caller != this && caller != Object.class.getModule()) {
- // ignore packages added for proxies via addPackage
- Set packages = getDescriptor().packages();
- String pn = Resources.toPackageName(name);
- if (packages.contains(pn) && !isOpen(pn, caller)) {
- // resource is in package not open to caller
- return null;
- }
- }
- }
-
- String mn = this.name;
-
- // special-case built-in class loaders to avoid URL connection
- if (loader == null) {
- return BootLoader.findResourceAsStream(mn, name);
- } else if (loader instanceof BuiltinClassLoader) {
- return ((BuiltinClassLoader) loader).findResourceAsStream(mn, name);
- }
-
- // locate resource in module
- JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
- URL url = jla.findResource(loader, mn, name);
- if (url != null) {
- try {
- return url.openStream();
- } catch (SecurityException e) { }
- }
-
- return null;
- }
-
- /**
- * Returns the string representation of this module. For a named module,
- * the representation is the string {@code "module"}, followed by a space,
- * and then the module name. For an unnamed module, the representation is
- * the string {@code "unnamed module"}, followed by a space, and then an
- * implementation specific string that identifies the unnamed module.
- *
- * @return The string representation of this module
- */
- @Override
- public String toString() {
- if (isNamed()) {
- return "module " + name;
- } else {
- String id = Integer.toHexString(System.identityHashCode(this));
- return "unnamed module @" + id;
- }
- }
-
-
- // -- native methods --
-
- // JVM_DefineModule
- private static native void defineModule0(Module module,
- boolean isOpen,
- String version,
- String location,
- String[] pns);
-
- // JVM_AddReadsModule
- private static native void addReads0(Module from, Module to);
-
- // JVM_AddModuleExports
- private static native void addExports0(Module from, String pn, Module to);
-
- // JVM_AddModuleExportsToAll
- private static native void addExportsToAll0(Module from, String pn);
-
- // JVM_AddModuleExportsToAllUnnamed
- private static native void addExportsToAllUnnamed0(Module from, String pn);
-
- // JVM_AddModulePackage
- 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 layers(Layer layer) {
- return layer.layers();
- }
- @Override
- public Stream layers(ClassLoader loader) {
- return Layer.layers(loader);
- }
- });
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java Wed Jul 05 23:13:02 2017 +0200
@@ -227,11 +227,11 @@
* {@code Proxy.newProxyInstance} method should be used instead.
*
*
- * A dynamic module can read the modules of all of the superinterfaces of a proxy class
- * and the modules of the types referenced by all public method signatures
+ * A dynamic module can read the modules of all of the superinterfaces of a proxy
+ * 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},
- * is in a non-exported package, the {@linkplain java.lang.reflect.Module module}
- * of {@code T} is updated to export the package of {@code T} to the dynamic module.
+ * is in a non-exported package, the {@linkplain Module module} of {@code T} is
+ * updated to export the package of {@code T} to the dynamic module.
*
*
Methods Duplicated in Multiple Proxy Interfaces
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/WeakPairMap.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/WeakPairMap.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,354 +0,0 @@
-/*
- * Copyright (c) 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 java.lang.reflect;
-
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.BiFunction;
-
-/**
- * A WeakHashMap-like data structure that uses a pair of weakly-referenced keys
- * with identity equality semantics to associate a strongly-referenced value.
- * Unlike WeakHashMap, this data structure is thread-safe.
- *
- * @param the type of 1st key in key pair
- * @param the type of 2nd key in key pair
- * @param the type of value
- * @author Peter Levart
- */
-final class WeakPairMap {
-
- private final ConcurrentHashMap, V> map = new ConcurrentHashMap<>();
- private final ReferenceQueue queue = new ReferenceQueue<>();
-
- /**
- * Tests if the specified pair of keys are associated with a value
- * in the WeakPairMap.
- *
- * @param k1 the 1st of the pair of keys
- * @param k2 the 2nd of the pair of keys
- * @return true if and only if the specified key pair is in this WeakPairMap,
- * as determined by the identity comparison; false otherwise
- * @throws NullPointerException if any of the specified keys is null
- */
- public boolean containsKeyPair(K1 k1, K2 k2) {
- expungeStaleAssociations();
- return map.containsKey(Pair.lookup(k1, k2));
- }
-
- /**
- * Returns the value to which the specified pair of keys is mapped, or null
- * if this WeakPairMap contains no mapping for the key pair.
- * More formally, if this WeakPairMap contains a mapping from a key pair
- * {@code (_k1, _k2)} to a value {@code v} such that
- * {@code k1 == _k1 && k2 == _k2}, then this method returns {@code v};
- * otherwise it returns {@code null}.
- * (There can be at most one such mapping.)
- *
- * @param k1 the 1st of the pair of keys for which the mapped value is to
- * be returned
- * @param k2 the 2nd of the pair of keys for which the mapped value is to
- * be returned
- * @return the value to which the specified key pair is mapped, or null if
- * this map contains no mapping for the key pair
- * @throws NullPointerException if any of the specified keys is null
- */
- public V get(K1 k1, K2 k2) {
- expungeStaleAssociations();
- return map.get(Pair.lookup(k1, k2));
- }
-
- /**
- * Maps the specified key pair to the specified value in this WeakPairMap.
- * Neither the keys nor the value can be null.
- *
The value can be retrieved by calling the {@link #get} method
- * with the the same keys (compared by identity).
- *
- * @param k1 the 1st of the pair of keys with which the specified value is to
- * be associated
- * @param k2 the 2nd of the pair of keys with which the specified value is to
- * be associated
- * @param v value to be associated with the specified key pair
- * @return the previous value associated with key pair, or {@code null} if
- * there was no mapping for key pair
- * @throws NullPointerException if any of the specified keys or value is null
- */
- public V put(K1 k1, K2 k2, V v) {
- expungeStaleAssociations();
- return map.put(Pair.weak(k1, k2, queue), v);
- }
-
- /**
- * If the specified key pair is not already associated with a value,
- * associates it with the given value and returns {@code null}, else does
- * nothing and returns the currently associated value.
- *
- * @param k1 the 1st of the pair of keys with which the specified value is to
- * be associated
- * @param k2 the 2nd of the pair of keys with which the specified value is to
- * be associated
- * @param v value to be associated with the specified key pair
- * @return the previous value associated with key pair, or {@code null} if
- * there was no mapping for key pair
- * @throws NullPointerException if any of the specified keys or value is null
- */
- public V putIfAbsent(K1 k1, K2 k2, V v) {
- expungeStaleAssociations();
- return map.putIfAbsent(Pair.weak(k1, k2, queue), v);
- }
-
- /**
- * If the specified key pair is not already associated with a value,
- * attempts to compute its value using the given mapping function
- * and enters it into this WeakPairMap unless {@code null}. The entire
- * method invocation is performed atomically, so the function is
- * applied at most once per key pair. Some attempted update operations
- * on this WeakPairMap by other threads may be blocked while computation
- * is in progress, so the computation should be short and simple,
- * and must not attempt to update any other mappings of this WeakPairMap.
- *
- * @param k1 the 1st of the pair of keys with which the
- * computed value is to be associated
- * @param k2 the 2nd of the pair of keys with which the
- * computed value is to be associated
- * @param mappingFunction the function to compute a value
- * @return the current (existing or computed) value associated with
- * the specified key pair, or null if the computed value is null
- * @throws NullPointerException if any of the specified keys or
- * mappingFunction is null
- * @throws IllegalStateException if the computation detectably
- * attempts a recursive update to this map
- * that would otherwise never complete
- * @throws RuntimeException or Error if the mappingFunction does so, in
- * which case the mapping is left unestablished
- */
- public V computeIfAbsent(K1 k1, K2 k2,
- BiFunction super K1, ? super K2, ? extends V>
- mappingFunction) {
- expungeStaleAssociations();
- try {
- return map.computeIfAbsent(
- Pair.weak(k1, k2, queue),
- pair -> mappingFunction.apply(pair.first(), pair.second()));
- } finally {
- Reference.reachabilityFence(k1);
- Reference.reachabilityFence(k2);
- }
- }
-
- /**
- * Returns a {@link Collection} view of the values contained in this
- * WeakPairMap. The collection is backed by the WeakPairMap, so changes to
- * the map are reflected in the collection, and vice-versa. The collection
- * supports element removal, which removes the corresponding
- * mapping from this map, via the {@code Iterator.remove},
- * {@code Collection.remove}, {@code removeAll},
- * {@code retainAll}, and {@code clear} operations. It does not
- * support the {@code add} or {@code addAll} operations.
- *
- * @return the collection view
- */
- public Collection values() {
- expungeStaleAssociations();
- return map.values();
- }
-
- /**
- * Removes associations from this WeakPairMap for which at least one of the
- * keys in key pair has been found weakly-reachable and corresponding
- * WeakRefPeer(s) enqueued. Called as part of each public operation.
- */
- private void expungeStaleAssociations() {
- WeakRefPeer> peer;
- while ((peer = (WeakRefPeer>) queue.poll()) != null) {
- map.remove(peer.weakPair());
- }
- }
-
- /**
- * Common interface of both {@link Weak} and {@link Lookup} key pairs.
- */
- private interface Pair {
-
- static Pair weak(K1 k1, K2 k2,
- ReferenceQueue queue) {
- return new Weak<>(k1, k2, queue);
- }
-
- static Pair lookup(K1 k1, K2 k2) {
- return new Lookup<>(k1, k2);
- }
-
- /**
- * @return The 1st of the pair of keys (may be null for {@link Weak}
- * when it gets cleared)
- */
- K1 first();
-
- /**
- * @return The 2nd of the pair of keys (may be null for {@link Weak}
- * when it gets cleared)
- */
- K2 second();
-
- static int hashCode(Object first, Object second) {
- // assert first != null && second != null;
- return System.identityHashCode(first) ^
- System.identityHashCode(second);
- }
-
- static boolean equals(Object first, Object second, Pair, ?> p) {
- return first != null && second != null &&
- first == p.first() && second == p.second();
- }
-
- /**
- * A Pair where both keys are weakly-referenced.
- * It is composed of two instances of {@link WeakRefPeer}s:
- * {@code
- *
- * +-referent-> [K1] +-referent-> [K2]
- * | |
- * +----------------+ +----------------+
- * | Pair.Weak <: |-----peer----->| (anonymous) <: |
- * | WeakRefPeer, | | WeakRefPeer |
- * | Pair |<--weakPair()--| |
- * +----------------+ +----------------+
- * | ^
- * | |
- * +-weakPair()-+
- *
- * }
- *
- * Pair.Weak is used for CHM keys. Both peers are associated with the
- * same {@link ReferenceQueue} so when either of their referents
- * becomes weakly-reachable, the corresponding entries can be
- * {@link #expungeStaleAssociations() expunged} from the map.
- */
- final class Weak extends WeakRefPeer implements Pair {
-
- // saved hash so it can be retrieved after the reference is cleared
- private final int hash;
- // link to peer
- private final WeakRefPeer peer;
-
- Weak(K1 k1, K2 k2, ReferenceQueue queue) {
- super(k1, queue);
- hash = Pair.hashCode(k1, k2);
- peer = new WeakRefPeer<>(k2, queue) {
- // link back to peer
- @Override
- Weak, ?> weakPair() { return Weak.this; }
- };
- }
-
- @Override
- Weak, ?> weakPair() {
- return this;
- }
-
- @Override
- public K1 first() {
- return get();
- }
-
- @Override
- public K2 second() {
- return peer.get();
- }
-
- @Override
- public int hashCode() {
- return hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- return this == obj ||
- (obj instanceof Pair &&
- Pair.equals(first(), second(), (Pair, ?>) obj));
- }
- }
-
- /**
- * Optimized lookup Pair, used as lookup key in methods like
- * {@link java.util.Map#get(Object)} or
- * {@link java.util.Map#containsKey(Object)}) where
- * there is a great chance its allocation is eliminated
- * by escape analysis when such lookups are inlined by JIT.
- * All its methods are purposely designed so that 'this' is never
- * passed to any other method or used as identity.
- */
- final class Lookup implements Pair {
- private final K1 k1;
- private final K2 k2;
-
- Lookup(K1 k1, K2 k2) {
- this.k1 = Objects.requireNonNull(k1);
- this.k2 = Objects.requireNonNull(k2);
- }
-
- @Override
- public K1 first() {
- return k1;
- }
-
- @Override
- public K2 second() {
- return k2;
- }
-
- @Override
- public int hashCode() {
- return Pair.hashCode(k1, k2);
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj instanceof Pair &&
- Pair.equals(k1, k2, (Pair, ?>) obj);
- }
- }
- }
-
- /**
- * Common abstract supertype of a pair of WeakReference peers.
- */
- private static abstract class WeakRefPeer extends WeakReference {
-
- WeakRefPeer(K k, ReferenceQueue queue) {
- super(Objects.requireNonNull(k), queue);
- }
-
- /**
- * @return the {@link Pair.Weak} side of the pair of peers.
- */
- abstract Pair.Weak, ?> weakPair();
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/lang/reflect/package-info.java
--- a/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -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.
*
* 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
- * modules, classes and objects. Reflection allows programmatic access to
- * information about modules and to the fields, methods and constructors of
- * loaded classes, and the use of reflected fields, methods, and constructors
- * to operate on their underlying counterparts, within encapsulation and
- * security restrictions.
+ * classes and objects. Reflection allows programmatic access to information
+ * about the fields, methods and constructors of loaded classes, and the use
+ * of reflected fields, methods, and constructors to operate on their underlying
+ * counterparts, within encapsulation and security restrictions.
*
* {@code AccessibleObject} allows suppression of access checks if
* the necessary {@code ReflectPermission} is available.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
--- a/jdk/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -275,6 +275,7 @@
return (fd == null) ? true : false;
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java
--- a/jdk/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -646,6 +646,7 @@
/**
* Cleans up if the user forgets to close it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/ContentHandler.java
--- a/jdk/src/java.base/share/classes/java/net/ContentHandler.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/ContentHandler.java Wed Jul 05 23:13:02 2017 +0200
@@ -37,10 +37,10 @@
* application calls the {@code getContent} method in class
* {@code URL} or in {@code URLConnection}.
* The application's content handler factory (an instance of a class that
- * implements the interface {@code ContentHandlerFactory} set
- * up by a call to {@code setContentHandler}) is
- * called with a {@code String} giving the MIME type of the
- * object being received on the socket. The factory returns an
+ * implements the interface {@code ContentHandlerFactory} set up by a call to
+ * {@link URLConnection#setContentHandlerFactory(ContentHandlerFactory)
+ * setContentHandlerFactory} is called with a {@code String} giving the
+ * MIME type of the object being received on the socket. The factory returns an
* instance of a subclass of {@code ContentHandler}, and its
* {@code getContent} method is called to create the object.
*
@@ -99,7 +99,8 @@
* representation of an object, this method reads that stream and
* creates an object that matches one of the types specified.
*
- * The default implementation of this method should call getContent()
+ * The default implementation of this method should call
+ * {@link #getContent(URLConnection)}
* and screen the return type for a match of the suggested types.
*
* @param urlc a URL connection.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/SocketInputStream.java
--- a/jdk/src/java.base/share/classes/java/net/SocketInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/SocketInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -283,6 +283,7 @@
/**
* Overrides finalize, the fd is closed by the Socket.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() {}
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/SocketOutputStream.java
--- a/jdk/src/java.base/share/classes/java/net/SocketOutputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/SocketOutputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -175,6 +175,7 @@
/**
* Overrides finalize, the fd is closed by the Socket.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() {}
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/net/URLConnection.java
--- a/jdk/src/java.base/share/classes/java/net/URLConnection.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/net/URLConnection.java Wed Jul 05 23:13:02 2017 +0200
@@ -876,7 +876,7 @@
* Sets the value of the {@code doInput} field for this
* {@code URLConnection} to the specified value.
*
- * A URL connection can be used for input and/or output. Set the DoInput
+ * A URL connection can be used for input and/or output. Set the doInput
* flag to true if you intend to use the URL connection for input,
* false if not. The default is true.
*
@@ -906,7 +906,7 @@
* Sets the value of the {@code doOutput} field for this
* {@code URLConnection} to the specified value.
*
- * A URL connection can be used for input and/or output. Set the DoOutput
+ * A URL connection can be used for input and/or output. Set the doOutput
* flag to true if you intend to use the URL connection for output,
* false if not. The default is false.
*
@@ -972,7 +972,7 @@
* Returns the default value of the {@code allowUserInteraction}
* field.
*
- * Ths default is "sticky", being a part of the static state of all
+ * This default is "sticky", being a part of the static state of all
* URLConnections. This flag applies to the next, and all following
* URLConnections that are created.
*
@@ -993,7 +993,7 @@
* "reload" button in a browser). If the UseCaches flag on a connection
* is true, the connection is allowed to use whatever caches it can.
* If false, caches are to be ignored.
- * The default value comes from DefaultUseCaches, which defaults to
+ * The default value comes from defaultUseCaches, which defaults to
* true. A default value can also be set per-protocol using
* {@link #setDefaultUseCaches(String,boolean)}.
*
@@ -1252,7 +1252,7 @@
* application. It can be called at most once by an application.
*
* The {@code ContentHandlerFactory} instance is used to
- * construct a content handler from a content type
+ * construct a content handler from a content type.
*
* If there is a security manager, this method first calls
* the security manager's {@code checkSetFactory} method
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/time/chrono/AbstractChronology.java
--- a/jdk/src/java.base/share/classes/java/time/chrono/AbstractChronology.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/time/chrono/AbstractChronology.java Wed Jul 05 23:13:02 2017 +0200
@@ -127,36 +127,6 @@
public abstract class AbstractChronology implements Chronology {
/**
- * ChronoLocalDate order constant.
- */
- static final Comparator DATE_ORDER =
- (Comparator & Serializable) (date1, date2) -> {
- return Long.compare(date1.toEpochDay(), date2.toEpochDay());
- };
- /**
- * ChronoLocalDateTime order constant.
- */
- static final Comparator> DATE_TIME_ORDER =
- (Comparator> & Serializable) (dateTime1, dateTime2) -> {
- int cmp = Long.compare(dateTime1.toLocalDate().toEpochDay(), dateTime2.toLocalDate().toEpochDay());
- if (cmp == 0) {
- cmp = Long.compare(dateTime1.toLocalTime().toNanoOfDay(), dateTime2.toLocalTime().toNanoOfDay());
- }
- return cmp;
- };
- /**
- * ChronoZonedDateTime order constant.
- */
- static final Comparator> INSTANT_ORDER =
- (Comparator> & Serializable) (dateTime1, dateTime2) -> {
- int cmp = Long.compare(dateTime1.toEpochSecond(), dateTime2.toEpochSecond());
- if (cmp == 0) {
- cmp = Long.compare(dateTime1.toLocalTime().getNano(), dateTime2.toLocalTime().getNano());
- }
- return cmp;
- };
-
- /**
* Map of available calendars by ID.
*/
private static final ConcurrentHashMap CHRONOS_BY_ID = new ConcurrentHashMap<>();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDate.java
--- a/jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDate.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDate.java Wed Jul 05 23:13:02 2017 +0200
@@ -66,6 +66,7 @@
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoUnit.DAYS;
+import java.io.Serializable;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalTime;
@@ -256,7 +257,9 @@
* @see #isEqual
*/
static Comparator timeLineOrder() {
- return AbstractChronology.DATE_ORDER;
+ return (Comparator & Serializable) (date1, date2) -> {
+ return Long.compare(date1.toEpochDay(), date2.toEpochDay());
+ };
}
//-----------------------------------------------------------------------
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java
--- a/jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java Wed Jul 05 23:13:02 2017 +0200
@@ -66,6 +66,7 @@
import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
+import java.io.Serializable;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -136,7 +137,13 @@
* @see #isEqual
*/
static Comparator> timeLineOrder() {
- return AbstractChronology.DATE_TIME_ORDER;
+ return (Comparator> & Serializable) (dateTime1, dateTime2) -> {
+ int cmp = Long.compare(dateTime1.toLocalDate().toEpochDay(), dateTime2.toLocalDate().toEpochDay());
+ if (cmp == 0) {
+ cmp = Long.compare(dateTime1.toLocalTime().toNanoOfDay(), dateTime2.toLocalTime().toNanoOfDay());
+ }
+ return cmp;
+ };
}
//-----------------------------------------------------------------------
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java
--- a/jdk/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java Wed Jul 05 23:13:02 2017 +0200
@@ -66,6 +66,7 @@
import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
+import java.io.Serializable;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalTime;
@@ -137,7 +138,13 @@
* @see #isEqual
*/
static Comparator> timeLineOrder() {
- return AbstractChronology.INSTANT_ORDER;
+ return (Comparator> & Serializable) (dateTime1, dateTime2) -> {
+ int cmp = Long.compare(dateTime1.toEpochSecond(), dateTime2.toEpochSecond());
+ if (cmp == 0) {
+ cmp = Long.compare(dateTime1.toLocalTime().getNano(), dateTime2.toLocalTime().getNano());
+ }
+ return cmp;
+ };
}
//-----------------------------------------------------------------------
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/Comparator.java
--- a/jdk/src/java.base/share/classes/java/util/Comparator.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/Comparator.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -112,12 +112,6 @@
* zero, or a positive integer as the first argument is less than, equal
* to, or greater than the second.
*
- * In the foregoing description, the notation
- * {@code sgn(}expression {@code )} designates the mathematical
- * signum function, which is defined to return one of {@code -1},
- * {@code 0}, or {@code 1} according to whether the value of
- * expression is negative, zero or positive.
- *
* The implementor must ensure that {@code sgn(compare(x, y)) ==
* -sgn(compare(y, x))} for all {@code x} and {@code y}. (This
* implies that {@code compare(x, y)} must throw an exception if and only
@@ -135,7 +129,13 @@
* {@code (compare(x, y)==0) == (x.equals(y))}. Generally speaking,
* any comparator that violates this condition should clearly indicate
* this fact. The recommended language is "Note: this comparator
- * imposes orderings that are inconsistent with equals."
+ * imposes orderings that are inconsistent with equals."
+ *
+ * In the foregoing description, the notation
+ * {@code sgn(}expression {@code )} designates the mathematical
+ * signum function, which is defined to return one of {@code -1},
+ * {@code 0}, or {@code 1} according to whether the value of
+ * expression is negative, zero, or positive, respectively.
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/ResourceBundle.java
--- a/jdk/src/java.base/share/classes/java/util/ResourceBundle.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/ResourceBundle.java Wed Jul 05 23:13:02 2017 +0200
@@ -50,7 +50,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
@@ -1836,7 +1835,7 @@
cacheKey.setFormat(format);
break;
}
- } catch (Exception e) {
+ } catch (LinkageError|Exception e) {
cacheKey.setCause(e);
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/ServiceLoader.java
--- a/jdk/src/java.base/share/classes/java/util/ServiceLoader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/ServiceLoader.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,10 +31,8 @@
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessControlContext;
@@ -50,7 +48,6 @@
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.JavaLangAccess;
-import jdk.internal.misc.JavaLangReflectModuleAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.VM;
import jdk.internal.module.ServicesCatalog;
@@ -160,7 +157,7 @@
*
Locating providers
*
* 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 using a module layer then only providers in named modules in
* the layer (or parent layers) are located.
@@ -168,11 +165,11 @@
*
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
* 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
* 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
- * Layer#defineModulesWithManyLoaders defineModulesWithManyLoaders}). If the
+ * ModuleLayer#defineModulesWithManyLoaders defineModulesWithManyLoaders}). If the
* {@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
* layer, irrespective of their defining class loader.
@@ -198,7 +195,7 @@
* 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
* 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
* loader. The ordering of modules defined to the same class loader, or the
* ordering of modules in a layer, is not defined.
@@ -216,11 +213,11 @@
* method finds the service configuration files.
*
*
- * Service loaders created to locate providers in a module {@link Layer}
- * will first locate providers in the layer, before locating providers in
- * parent layers. Traversal of parent layers is depth-first with each layer
- * visited at most once. For example, suppose L0 is the boot layer, L1 and
- * L2 are custom layers with L0 as their parent. Now suppose that L3 is
+ *
Service loaders created to locate providers in a {@linkplain ModuleLayer
+ * module layer} will first locate providers in the layer, before locating
+ * providers in parent layers. Traversal of parent layers is depth-first with
+ * each layer visited at most once. For example, suppose L0 is the boot layer,
+ * 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
* 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
@@ -352,12 +349,12 @@
// The class of the service type
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
- private final Layer layer;
+ private final ModuleLayer layer;
// 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;
// The access control context taken when the ServiceLoader is created
@@ -376,10 +373,8 @@
private int reloadCount;
private static JavaLangAccess LANG_ACCESS;
- private static JavaLangReflectModuleAccess JLRM_ACCESS;
static {
LANG_ACCESS = SharedSecrets.getJavaLangAccess();
- JLRM_ACCESS = SharedSecrets.getJavaLangReflectModuleAccess();
}
/**
@@ -425,13 +420,13 @@
/**
* Initializes a new instance of this class for locating service providers
- * in a module Layer.
+ * in a module layer.
*
* @throws ServiceConfigurationError
* If {@code svc} is not accessible to {@code caller} or the caller
* module does not use the service type.
*/
- private ServiceLoader(Class> caller, Layer layer, Class svc) {
+ private ServiceLoader(Class> caller, ModuleLayer layer, Class svc) {
Objects.requireNonNull(caller);
Objects.requireNonNull(layer);
Objects.requireNonNull(svc);
@@ -512,12 +507,15 @@
/**
* 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) {
- Module callerModule = caller.getModule();
+ if (caller == null) {
+ fail(svc, "no caller to check if it declares `uses`");
+ }
// Check access to the service type
+ Module callerModule = caller.getModule();
int mods = svc.getModifiers();
if (!Reflection.verifyMemberAccess(caller, svc, null, mods)) {
fail(svc, "service type not accessible to " + callerModule);
@@ -826,13 +824,13 @@
/**
* 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
implements Iterator>
{
- Deque stack = new ArrayDeque<>();
- Set visited = new HashSet<>();
+ Deque stack = new ArrayDeque<>();
+ Set visited = new HashSet<>();
Iterator iterator;
ServiceProvider next; // next provider to load
@@ -841,8 +839,8 @@
stack.push(layer);
}
- private Iterator providers(Layer layer) {
- ServicesCatalog catalog = JLRM_ACCESS.getServicesCatalog(layer);
+ private Iterator providers(ModuleLayer layer) {
+ ServicesCatalog catalog = LANG_ACCESS.getServicesCatalog(layer);
return catalog.findServices(serviceName).iterator();
}
@@ -864,10 +862,10 @@
if (stack.isEmpty())
return false;
- Layer layer = stack.pop();
- List parents = layer.parents();
+ ModuleLayer layer = stack.pop();
+ List parents = layer.parents();
for (int i = parents.size() - 1; i >= 0; i--) {
- Layer parent = parents.get(i);
+ ModuleLayer parent = parents.get(i);
if (!visited.contains(parent)) {
visited.add(parent);
stack.push(parent);
@@ -915,8 +913,8 @@
* Returns iterator to iterate over the implementations of {@code
* service} in the given layer.
*/
- private List providers(Layer layer) {
- ServicesCatalog catalog = JLRM_ACCESS.getServicesCatalog(layer);
+ private List providers(ModuleLayer layer) {
+ ServicesCatalog catalog = LANG_ACCESS.getServicesCatalog(layer);
return catalog.findServices(serviceName);
}
@@ -946,10 +944,10 @@
return providers.iterator();
} else {
List allProviders = new ArrayList<>(providers);
- Layer bootLayer = Layer.boot();
- Iterator iterator = JLRM_ACCESS.layers(loader).iterator();
+ ModuleLayer bootLayer = ModuleLayer.boot();
+ Iterator iterator = LANG_ACCESS.layers(loader).iterator();
while (iterator.hasNext()) {
- Layer layer = iterator.next();
+ ModuleLayer layer = iterator.next();
if (layer != bootLayer) {
allProviders.addAll(providers(layer));
}
@@ -1535,7 +1533,7 @@
/**
* 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.
*
* @apiNote Unlike the other load methods defined here, the service type
@@ -1545,7 +1543,7 @@
* @param the class of the service type
*
* @param layer
- * The module Layer
+ * The module layer
*
* @param service
* The interface or abstract class representing the service
@@ -1561,7 +1559,7 @@
* @spec JPMS
*/
@CallerSensitive
- public static ServiceLoader load(Layer layer, Class service) {
+ public static ServiceLoader load(ModuleLayer layer, Class service) {
return new ServiceLoader<>(Reflection.getCallerClass(), layer, service);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/Timer.java
--- a/jdk/src/java.base/share/classes/java/util/Timer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/Timer.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -108,6 +108,7 @@
* finalizer forgetting to call it.
*/
private final Object threadReaper = new Object() {
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
synchronized(queue) {
thread.newTasksMayBeScheduled = false;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java Wed Jul 05 23:13:02 2017 +0200
@@ -1032,9 +1032,10 @@
}
else if ((fh = f.hash) == MOVED)
tab = helpTransfer(tab, f);
- else if (onlyIfAbsent && fh == hash && // check first node
- ((fk = f.key) == key || fk != null && key.equals(fk)) &&
- (fv = f.val) != null)
+ else if (onlyIfAbsent // check first node without acquiring lock
+ && fh == hash
+ && ((fk = f.key) == key || (fk != null && key.equals(fk)))
+ && (fv = f.val) != null)
return fv;
else {
V oldVal = null;
@@ -1728,9 +1729,9 @@
}
else if ((fh = f.hash) == MOVED)
tab = helpTransfer(tab, f);
- else if (fh == h && // check first node
- ((fk = f.key) == key || fk != null && key.equals(fk)) &&
- (fv = f.val) != null)
+ else if (fh == h // check first node without acquiring lock
+ && ((fk = f.key) == key || (fk != null && key.equals(fk)))
+ && (fv = f.val) != null)
return fv;
else {
boolean added = false;
@@ -3468,9 +3469,9 @@
static final class KeyIterator extends BaseIterator
implements Iterator, Enumeration {
- KeyIterator(Node[] tab, int index, int size, int limit,
+ KeyIterator(Node[] tab, int size, int index, int limit,
ConcurrentHashMap map) {
- super(tab, index, size, limit, map);
+ super(tab, size, index, limit, map);
}
public final K next() {
@@ -3488,9 +3489,9 @@
static final class ValueIterator extends BaseIterator
implements Iterator, Enumeration {
- ValueIterator(Node[] tab, int index, int size, int limit,
+ ValueIterator(Node[] tab, int size, int index, int limit,
ConcurrentHashMap map) {
- super(tab, index, size, limit, map);
+ super(tab, size, index, limit, map);
}
public final V next() {
@@ -3508,9 +3509,9 @@
static final class EntryIterator extends BaseIterator
implements Iterator> {
- EntryIterator(Node[] tab, int index, int size, int limit,
+ EntryIterator(Node[] tab, int size, int index, int limit,
ConcurrentHashMap map) {
- super(tab, index, size, limit, map);
+ super(tab, size, index, limit, map);
}
public final Map.Entry next() {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Wed Jul 05 23:13:02 2017 +0200
@@ -48,7 +48,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.Set;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
-import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/Executors.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/Executors.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/Executors.java Wed Jul 05 23:13:02 2017 +0200
@@ -713,6 +713,7 @@
FinalizableDelegatedExecutorService(ExecutorService executor) {
super(executor);
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
super.shutdown();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Wed Jul 05 23:13:02 2017 +0200
@@ -2354,7 +2354,7 @@
checkPermission();
}
- private Object newInstanceFromSystemProperty(String property)
+ private static Object newInstanceFromSystemProperty(String property)
throws ReflectiveOperationException {
String className = System.getProperty(property);
return (className == null)
@@ -2524,15 +2524,13 @@
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
*/
+ @SuppressWarnings("unchecked")
public ForkJoinTask> submit(Runnable task) {
if (task == null)
throw new NullPointerException();
- ForkJoinTask> job;
- if (task instanceof ForkJoinTask>) // avoid re-wrap
- job = (ForkJoinTask>) task;
- else
- job = new ForkJoinTask.AdaptedRunnableAction(task);
- return externalSubmit(job);
+ return externalSubmit((task instanceof ForkJoinTask>)
+ ? (ForkJoinTask) task // avoid re-wrap
+ : new ForkJoinTask.AdaptedRunnableAction(task));
}
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java Wed Jul 05 23:13:02 2017 +0200
@@ -203,21 +203,19 @@
static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
/** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
private static final ThreadGroup innocuousThreadGroup =
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<>() {
- public ThreadGroup run() {
- ThreadGroup group = Thread.currentThread().getThreadGroup();
- for (ThreadGroup p; (p = group.getParent()) != null; )
- group = p;
- return new ThreadGroup(group, "InnocuousForkJoinWorkerThreadGroup");
- }});
+ AccessController.doPrivileged(new PrivilegedAction<>() {
+ public ThreadGroup run() {
+ ThreadGroup group = Thread.currentThread().getThreadGroup();
+ for (ThreadGroup p; (p = group.getParent()) != null; )
+ group = p;
+ return new ThreadGroup(
+ group, "InnocuousForkJoinWorkerThreadGroup");
+ }});
/** An AccessControlContext supporting no privileges */
private static final AccessControlContext INNOCUOUS_ACC =
new AccessControlContext(
- new ProtectionDomain[] {
- new ProtectionDomain(null, null)
- });
+ new ProtectionDomain[] { new ProtectionDomain(null, null) });
InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
super(pool,
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java Wed Jul 05 23:13:02 2017 +0200
@@ -1490,7 +1490,17 @@
/**
* Invokes {@code shutdown} when this executor is no longer
* referenced and it has no threads.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() {
shutdown();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java
--- a/jdk/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java Wed Jul 05 23:13:02 2017 +0200
@@ -444,7 +444,7 @@
}
}
- private IllegalMonitorStateException unmatchedUnlockException() {
+ private static IllegalMonitorStateException unmatchedUnlockException() {
return new IllegalMonitorStateException(
"attempt to unlock read lock, not locked by current thread");
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java
--- a/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,7 +31,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/zip/Deflater.java
--- a/jdk/src/java.base/share/classes/java/util/zip/Deflater.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/zip/Deflater.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -551,7 +551,17 @@
/**
* Closes the compressor when garbage is collected.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() {
end();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/zip/Inflater.java
--- a/jdk/src/java.base/share/classes/java/util/zip/Inflater.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/zip/Inflater.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -378,7 +378,17 @@
/**
* Closes the decompressor when garbage is collected.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() {
end();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java Wed Jul 05 23:13:02 2017 +0200
@@ -420,6 +420,7 @@
Integer.MAX_VALUE : (int) avail);
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
close();
}
@@ -641,9 +642,18 @@
* This will prevent holding up system resources for an undetermined
* length of time.
*
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
* @throws IOException if an I/O error has occurred
* @see java.util.zip.ZipFile#close()
*/
+ @Deprecated(since="9")
protected void finalize() throws IOException {
close();
}
@@ -813,6 +823,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/javax/crypto/JceSecurityManager.java
--- a/jdk/src/java.base/share/classes/javax/crypto/JceSecurityManager.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/javax/crypto/JceSecurityManager.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package javax.crypto;
-import java.lang.reflect.Module;
import java.security.*;
import java.net.*;
import java.util.*;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -106,6 +106,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
cleanup();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/loader/BootLoader.java
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/BootLoader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/BootLoader.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,8 +27,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.module.ModuleReference;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -62,8 +60,7 @@
private static final String JAVA_HOME = System.getProperty("java.home");
static {
- UNNAMED_MODULE
- = SharedSecrets.getJavaLangReflectModuleAccess().defineUnnamedModule(null);
+ UNNAMED_MODULE = SharedSecrets.getJavaLangAccess().defineUnnamedModule(null);
setBootLoaderUnnamedModule0(UNNAMED_MODULE);
}
@@ -255,7 +252,7 @@
if (mn != null) {
// named module from runtime image or exploded module
- Optional om = Layer.boot().findModule(mn);
+ Optional om = ModuleLayer.boot().findModule(mn);
if (!om.isPresent())
throw new InternalError(mn + " not in boot layer");
return om.get();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,7 +27,6 @@
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Module;
import java.net.URL;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/loader/Loader.java
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/Loader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/Loader.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -80,8 +79,8 @@
* loader. This allows automatic modules (for example) to link to types in the
* unnamed module of the parent class loader.
*
- * @see Layer#defineModulesWithOneLoader
- * @see Layer#defineModulesWithManyLoaders
+ * @see ModuleModuleLayer#defineModulesWithOneLoader
+ * @see ModuleModuleLayer#defineModulesWithManyLoaders
*/
public final class Loader extends SecureClassLoader {
@@ -207,10 +206,10 @@
* @param cf the Configuration containing at least modules to be defined to
* this class loader
*
- * @param parentLayers the parent Layers
+ * @param parentModuleLayers the parent ModuleLayers
*/
public Loader initRemotePackageMap(Configuration cf,
- List parentLayers)
+ List parentModuleLayers)
{
for (String name : nameToModule.keySet()) {
ResolvedModule resolvedModule = cf.findModule(name).get();
@@ -236,8 +235,8 @@
} else {
// find the layer for the target module
- Layer layer = parentLayers.stream()
- .map(parent -> findLayer(parent, other.configuration()))
+ ModuleLayer layer = parentModuleLayers.stream()
+ .map(parent -> findModuleLayer(parent, other.configuration()))
.flatMap(Optional::stream)
.findAny()
.orElseThrow(() ->
@@ -286,8 +285,8 @@
* Find the layer corresponding to the given configuration in the tree
* of layers rooted at the given parent.
*/
- private Optional findLayer(Layer parent, Configuration cf) {
- return SharedSecrets.getJavaLangReflectModuleAccess().layers(parent)
+ private Optional findModuleLayer(ModuleLayer parent, Configuration cf) {
+ return SharedSecrets.getJavaLangAccess().layers(parent)
.filter(l -> l.configuration() == cf)
.findAny();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,7 +27,6 @@
import java.lang.module.Configuration;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -36,7 +35,7 @@
/**
* A pool of class loaders.
*
- * @see Layer#defineModulesWithManyLoaders
+ * @see ModuleLayer#defineModulesWithManyLoaders
*/
public final class LoaderPool {
@@ -51,7 +50,7 @@
* created with the given parent class loader as its parent.
*/
public LoaderPool(Configuration cf,
- List parentLayers,
+ List parentLayers,
ClassLoader parentLoader)
{
Map loaders = new HashMap<>();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java
--- a/jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java Wed Jul 05 23:13:02 2017 +0200
@@ -34,7 +34,6 @@
import java.lang.System.LoggerFinder;
import java.lang.System.Logger;
import java.lang.ref.ReferenceQueue;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java
--- a/jdk/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/logger/LazyLoggers.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,7 +31,6 @@
import java.lang.System.LoggerFinder;
import java.lang.System.Logger;
import java.lang.ref.WeakReference;
-import java.lang.reflect.Module;
import java.util.Objects;
import jdk.internal.misc.VM;
import sun.util.logging.PlatformLogger;
@@ -402,10 +401,10 @@
* @param module The module on behalf of which the logger is created.
* If the module is not loaded from the Boot ClassLoader,
* 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.
* 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.
*
* @return a (possibly lazy) Logger instance.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,10 +27,10 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
+import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Executable;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
+import java.net.URI;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.ProtectionDomain;
@@ -38,6 +38,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
+import jdk.internal.module.ServicesCatalog;
import jdk.internal.reflect.ConstantPool;
import sun.reflect.annotation.AnnotationType;
import sun.nio.ch.Interruptible;
@@ -140,11 +141,6 @@
void invokeFinalize(Object o) throws Throwable;
/**
- * Returns the boot Layer
- */
- Layer getBootLayer();
-
- /**
* Returns the ConcurrentHashMap used as a storage for ClassLoaderValue(s)
* associated with the given class loader, creating it if it doesn't already exist.
*/
@@ -185,4 +181,74 @@
* Invalidate package access cache
*/
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 layers(ModuleLayer layer);
+
+ /**
+ * Returns a stream of the layers that have modules defined to the
+ * given class loader.
+ */
+ Stream layers(ClassLoader loader);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangReflectModuleAccess.java
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangReflectModuleAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 layers(Layer layer);
-
- /**
- * Returns a stream of the layers that have modules defined to the
- * given class loader.
- */
- Stream layers(ClassLoader loader);
-}
\ No newline at end of file
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/misc/JavaUtilResourceBundleAccess.java
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaUtilResourceBundleAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaUtilResourceBundleAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package jdk.internal.misc;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java Wed Jul 05 23:13:02 2017 +0200
@@ -50,7 +50,6 @@
private static JavaUtilJarAccess javaUtilJarAccess;
private static JavaLangAccess javaLangAccess;
private static JavaLangModuleAccess javaLangModuleAccess;
- private static JavaLangReflectModuleAccess javaLangReflectModuleAccess;
private static JavaLangInvokeAccess javaLangInvokeAccess;
private static JavaLangRefAccess javaLangRefAccess;
private static JavaIOAccess javaIOAccess;
@@ -119,16 +118,6 @@
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) {
javaLangRefAccess = jlra;
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,7 +27,6 @@
import java.io.PrintStream;
import java.lang.invoke.MethodHandles;
-import java.lang.reflect.Module;
import java.net.URL;
import java.security.AccessController;
import java.security.CodeSource;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java Wed Jul 05 23:13:02 2017 +0200
@@ -32,9 +32,6 @@
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
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.nio.file.Path;
import java.nio.file.Paths;
@@ -61,7 +58,7 @@
* 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
* 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.
*/
@@ -106,11 +103,11 @@
}
/**
- * Initialize the module system, returning the boot Layer.
+ * Initialize the module system, returning the boot layer.
*
* @see java.lang.System#initPhase2()
*/
- public static Layer boot() {
+ public static ModuleLayer boot() {
long t0 = System.nanoTime();
@@ -237,7 +234,6 @@
ModuleFinder f = finder; // observable modules
systemModules.findAll()
.stream()
- .filter(mref -> !ModuleResolution.doNotResolveByDefault(mref))
.map(ModuleReference::descriptor)
.map(ModuleDescriptor::name)
.filter(mn -> f.find(mn).isPresent()) // observable
@@ -321,8 +317,7 @@
if (SystemModules.hasSplitPackages() || needPostResolutionChecks) {
Map packageToModule = new HashMap<>();
for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleDescriptor descriptor =
- resolvedModule.reference().descriptor();
+ ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
String name = descriptor.name();
for (String p : descriptor.packages()) {
String other = packageToModule.putIfAbsent(p, name);
@@ -338,7 +333,7 @@
long t4 = System.nanoTime();
// define modules to VM/runtime
- Layer bootLayer = Layer.empty().defineModules(cf, clf);
+ ModuleLayer bootLayer = ModuleLayer.empty().defineModules(cf, clf);
PerfCounters.layerCreateTime.addElapsedTimeFrom(t4);
@@ -476,7 +471,7 @@
* Process the --add-reads options to add any additional read edges that
* are specified on the command-line.
*/
- private static void addExtraReads(Layer bootLayer) {
+ private static void addExtraReads(ModuleLayer bootLayer) {
// decode the command line options
Map> map = decode("jdk.module.addreads.");
@@ -514,7 +509,7 @@
* Process the --add-exports and --add-opens options to export/open
* additional packages specified on the command-line.
*/
- private static void addExtraExportsAndOpens(Layer bootLayer) {
+ private static void addExtraExportsAndOpens(ModuleLayer bootLayer) {
// --add-exports
String prefix = "jdk.module.addexports.";
Map> extraExports = decode(prefix);
@@ -548,7 +543,7 @@
}
}
- private static void addExtraExportsOrOpens(Layer bootLayer,
+ private static void addExtraExportsOrOpens(ModuleLayer bootLayer,
Map> map,
boolean opens)
{
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java Wed Jul 05 23:13:02 2017 +0200
@@ -135,8 +135,9 @@
Path top = file;
Files.find(top, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile()))
- .filter(path -> !isAutomatic
+ .filter(path -> (!isAutomatic
|| path.toString().endsWith(".class"))
+ && !isHidden(path))
.map(path -> toPackageName(top, path))
.filter(Checks::isPackageName)
.forEach(packages::add);
@@ -177,11 +178,13 @@
ModuleTarget target = null;
ModuleHashes recordedHashes = null;
+ ModuleHashes.HashSupplier hasher = null;
ModuleResolution mres = null;
if (mref instanceof ModuleReferenceImpl) {
ModuleReferenceImpl impl = (ModuleReferenceImpl)mref;
target = impl.moduleTarget();
recordedHashes = impl.recordedHashes();
+ hasher = impl.hasher();
mres = impl.moduleResolution();
}
@@ -191,7 +194,7 @@
this,
target,
recordedHashes,
- null,
+ hasher,
mres);
}
@@ -556,7 +559,7 @@
/**
- * 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) {
Path entry = top.relativize(file);
@@ -569,6 +572,17 @@
}
/**
+ * 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.
*/
private static String toPackageName(Path file, JarEntry entry) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java Wed Jul 05 23:13:02 2017 +0200
@@ -547,7 +547,6 @@
*/
private static class Patterns {
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 REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
@@ -558,9 +557,6 @@
* Clean up candidate module name derived from a JAR file name.
*/
private static String cleanModuleName(String mn) {
- // drop trailing version from name
- mn = Patterns.TRAILING_VERSION.matcher(mn).replaceAll("");
-
// replace non-alphanumeric
mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
@@ -630,7 +626,7 @@
private Set explodedPackages(Path dir) {
try {
return Files.find(dir, Integer.MAX_VALUE,
- ((path, attrs) -> attrs.isRegularFile()))
+ ((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
.map(path -> dir.relativize(path))
.map(this::toPackageName)
.flatMap(Optional::stream)
@@ -726,6 +722,17 @@
}
}
+ /**
+ * 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
= PerfCounter.newPerfCounter("jdk.module.finder.modulepath.scanTime");
private static final PerfCounter moduleCount
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/Modules.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,15 +26,13 @@
package jdk.internal.module;
import java.lang.module.ModuleDescriptor;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
-import jdk.internal.misc.JavaLangReflectModuleAccess;
+import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets;
/**
@@ -51,8 +49,7 @@
public class Modules {
private Modules() { }
- private static final JavaLangReflectModuleAccess JLRMA
- = SharedSecrets.getJavaLangReflectModuleAccess();
+ private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
/**
* Creates a new Module. The module has the given ModuleDescriptor and
@@ -67,7 +64,7 @@
ModuleDescriptor descriptor,
URI uri)
{
- return JLRMA.defineModule(loader, descriptor, uri);
+ return JLA.defineModule(loader, descriptor, uri);
}
/**
@@ -75,23 +72,14 @@
* Same as m1.addReads(m2) but without a caller check.
*/
public static void addReads(Module m1, Module m2) {
- JLRMA.addReads(m1, m2);
+ JLA.addReads(m1, m2);
}
/**
* Update module m to read all unnamed modules.
*/
public static void addReadsAllUnnamed(Module m) {
- JLRMA.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);
+ JLA.addReadsAllUnnamed(m);
}
/**
@@ -99,23 +87,14 @@
* Same as m1.addExports(pn, m2) but without a caller check
*/
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.
*/
public static void addExportsToAllUnnamed(Module m, String pn) {
- JLRMA.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);
+ JLA.addExportsToAllUnnamed(m, pn);
}
/**
@@ -123,14 +102,14 @@
* Same as m1.addOpens(pn, m2) but without a caller check.
*/
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.
*/
public static void addOpensToAllUnnamed(Module m, String pn) {
- JLRMA.addOpensToAllUnnamed(m, pn);
+ JLA.addOpensToAllUnnamed(m, pn);
}
/**
@@ -138,16 +117,16 @@
* Same as m2.addUses(service) but without a caller check.
*/
public static void addUses(Module m, Class> service) {
- JLRMA.addUses(m, service);
+ JLA.addUses(m, service);
}
/**
* Updates module m to provide a service
*/
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
PrivilegedAction pa = m::getClassLoader;
ClassLoader loader = AccessController.doPrivileged(pa);
@@ -162,9 +141,7 @@
if (layer != null) {
// update Layer catalog
- SharedSecrets.getJavaLangReflectModuleAccess()
- .getServicesCatalog(layer)
- .addProvider(m, service, impl);
+ JLA.getServicesCatalog(layer).addProvider(m, service, impl);
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/jdk/internal/module/ServicesCatalog.java
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ServicesCatalog.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ServicesCatalog.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package jdk.internal.module;
-import java.lang.reflect.Module;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Provides;
import java.util.ArrayList;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
--- a/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,7 +27,6 @@
import java.lang.reflect.Modifier;
import static java.lang.reflect.Modifier.*;
-import java.lang.reflect.Module;
import java.util.Objects;
import jdk.internal.reflect.Reflection;
@@ -297,10 +296,13 @@
* @param refc the class attempting to make the reference
*/
public static boolean isTypeVisible(java.lang.invoke.MethodType type, Class> refc) {
- for (int n = -1, max = type.parameterCount(); n < max; n++) {
- Class> ptype = (n < 0 ? type.returnType() : type.parameterType(n));
- if (!isTypeVisible(ptype, refc))
+ if (!isTypeVisible(type.returnType(), refc)) {
+ return false;
+ }
+ for (int n = 0, max = type.parameterCount(); n < max; n++) {
+ if (!isTypeVisible(type.parameterType(n), refc)) {
return false;
+ }
}
return true;
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/invoke/util/Wrapper.java
--- a/jdk/src/java.base/share/classes/sun/invoke/util/Wrapper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/invoke/util/Wrapper.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,20 +26,20 @@
package sun.invoke.util;
public enum Wrapper {
- // wrapperType primitiveType char emptyArray format
- BOOLEAN( Boolean.class, boolean.class, 'Z', new boolean[0], Format.unsigned( 1)),
+ // wrapperType simple primitiveType simple char emptyArray format
+ BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1)),
// These must be in the order defined for widening primitive conversions in JLS 5.1.2
// Avoid boxing integral types here to defer initialization of internal caches
- BYTE ( Byte.class, byte.class, 'B', new byte[0], Format.signed( 8)),
- SHORT ( Short.class, short.class, 'S', new short[0], Format.signed( 16)),
- CHAR (Character.class, char.class, 'C', new char[0], Format.unsigned(16)),
- INT ( Integer.class, int.class, 'I', new int[0], Format.signed( 32)),
- LONG ( Long.class, long.class, 'J', new long[0], Format.signed( 64)),
- FLOAT ( Float.class, float.class, 'F', new float[0], Format.floating(32)),
- DOUBLE ( Double.class, double.class, 'D', new double[0], Format.floating(64)),
- OBJECT ( Object.class, Object.class, 'L', new Object[0], Format.other( 1)),
+ BYTE ( Byte.class, "Byte", byte.class, "byte", 'B', new byte[0], Format.signed( 8)),
+ SHORT ( Short.class, "Short", short.class, "short", 'S', new short[0], Format.signed( 16)),
+ CHAR (Character.class, "Character", char.class, "char", 'C', new char[0], Format.unsigned(16)),
+ INT ( Integer.class, "Integer", int.class, "int", 'I', new int[0], Format.signed( 32)),
+ LONG ( Long.class, "Long", long.class, "long", 'J', new long[0], Format.signed( 64)),
+ FLOAT ( Float.class, "Float", float.class, "float", 'F', new float[0], Format.floating(32)),
+ DOUBLE ( Double.class, "Double", double.class, "double", 'D', new double[0], Format.floating(64)),
+ OBJECT ( Object.class, "Object", Object.class, "Object", 'L', new Object[0], Format.other( 1)),
// VOID must be the last type, since it is "assignable" from any other type:
- VOID ( Void.class, void.class, 'V', null, Format.other( 0)),
+ VOID ( Void.class, "Void", void.class, "void", 'V', null, Format.other( 0)),
;
public static final int COUNT = 10;
@@ -52,14 +52,14 @@
private final String wrapperSimpleName;
private final String primitiveSimpleName;
- private Wrapper(Class> wtype, Class> ptype, char tchar, Object emptyArray, int format) {
+ private Wrapper(Class> wtype, String wtypeName, Class> ptype, String ptypeName, char tchar, Object emptyArray, int format) {
this.wrapperType = wtype;
this.primitiveType = ptype;
this.basicTypeChar = tchar;
this.emptyArray = emptyArray;
this.format = format;
- this.wrapperSimpleName = wtype.getSimpleName();
- this.primitiveSimpleName = ptype.getSimpleName();
+ this.wrapperSimpleName = wtypeName;
+ this.primitiveSimpleName = ptypeName;
}
/** For debugging, give the details of this wrapper. */
@@ -518,12 +518,6 @@
* If the target type is a primitive, change it to a wrapper.
*/
static Class forceType(Class> type, Class exampleType) {
- boolean z = (type == exampleType ||
- type.isPrimitive() && forPrimitiveType(type) == findWrapperType(exampleType) ||
- exampleType.isPrimitive() && forPrimitiveType(exampleType) == findWrapperType(type) ||
- type == Object.class && !exampleType.isPrimitive());
- if (!z)
- System.out.println(type+" <= "+exampleType);
assert(type == exampleType ||
type.isPrimitive() && forPrimitiveType(type) == findWrapperType(exampleType) ||
exampleType.isPrimitive() && forPrimitiveType(exampleType) == findWrapperType(type) ||
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java
--- a/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java Wed Jul 05 23:13:02 2017 +0200
@@ -50,10 +50,8 @@
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
import java.lang.module.ModuleDescriptor.Provides;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
@@ -467,7 +465,7 @@
String mn = s[0];
String pn = s[1];
- Layer.boot().findModule(mn).ifPresent(m -> {
+ ModuleLayer.boot().findModule(mn).ifPresent(m -> {
if (m.getDescriptor().packages().contains(pn)) {
if (open) {
Modules.addOpensToAllUnnamed(m, pn);
@@ -564,7 +562,7 @@
}
// main module is in the boot layer
- Layer layer = Layer.boot();
+ ModuleLayer layer = ModuleLayer.boot();
Optional om = layer.findModule(mainModule);
if (!om.isPresent()) {
// should not happen
@@ -854,7 +852,7 @@
private static void setFXLaunchParameters(String what, int mode) {
// find the module with the FX launcher
- Optional om = Layer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);
+ Optional om = ModuleLayer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);
if (!om.isPresent()) {
abort(null, "java.launcher.cls.error5");
}
@@ -938,8 +936,7 @@
* Called by the launcher to list the observable modules.
* 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
- * names of the modules to list (-listmods:java.base,java.desktop for
- * example).
+ * names of the modules to list (e.g. --list-modules java.base,java.desktop)
*/
static void listModules(boolean printToStderr, String optionFlag)
throws IOException, ClassNotFoundException
@@ -947,89 +944,97 @@
initOutput(printToStderr);
ModuleFinder finder = jdk.internal.module.ModuleBootstrap.finder();
-
int colon = optionFlag.indexOf('=');
if (colon == -1) {
finder.findAll().stream()
- .sorted(Comparator.comparing(ModuleReference::descriptor))
- .forEach(md -> {
- ostream.println(midAndLocation(md.descriptor(),
- md.location()));
- });
+ .sorted(Comparator.comparing(ModuleReference::descriptor))
+ .forEach(mref -> describeModule(finder, mref, false));
} else {
String[] names = optionFlag.substring(colon+1).split(",");
for (String name: names) {
ModuleReference mref = finder.find(name).orElse(null);
if (mref == null) {
- System.err.format("%s not observable!%n", name);
+ System.err.format("%s not found%n", name);
continue;
}
-
- 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 = 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 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));
+ describeModule(finder, mref, true);
}
}
}
+ /**
+ * 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 = 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 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 String toString(Set s) {
return toStringStream(s).collect(Collectors.joining(" "));
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties
--- a/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties Wed Jul 05 23:13:02 2017 +0200
@@ -39,7 +39,8 @@
java.launcher.opt.hotspot =\ {0}\t is a synonym for the "{1}" VM [deprecated]\n
# Translators please note do not translate the options themselves
-java.launcher.opt.footer =\ -cp \n\
+java.launcher.opt.footer = \
+\ -cp \n\
\ -classpath \n\
\ --class-path \n\
\ A {0} separated list of directories, JAR archives,\n\
@@ -101,8 +102,11 @@
\ should always be passed as the argument to the -splash option.\n\
\ The most appropriate scaled image provided will be picked up\n\
\ automatically.\n\
-\ See the SplashScreen API documentation for more information.\n\
-\ @ read options from the specified file\n\n\
+\ See the SplashScreen API documentation for more information\n\
+\ @argument files\n\
+\ one or more argument files containing options\n\
+\ -disable-@files\n\
+\ prevent further argument file expansion\n\
\To specify an argument for a long option, you can use --= or\n\
\-- .\n
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/net/www/MeteredStream.java
--- a/jdk/src/java.base/share/classes/sun/net/www/MeteredStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/net/www/MeteredStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -203,6 +203,7 @@
return super.markSupported();
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
close();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/net/www/protocol/https/DelegateHttpsURLConnection.java
--- a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/DelegateHttpsURLConnection.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/DelegateHttpsURLConnection.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -77,6 +77,7 @@
* Called by layered delegator's finalize() method to handle closing
* the underlying object.
*/
+ @SuppressWarnings("deprecation")
protected void dispose() throws Throwable {
super.finalize();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java
--- a/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -478,6 +478,7 @@
* sun.net.www.protocol.http.HttpURLConnection's finalize()
* would have to be made public.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
delegate.dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java
--- a/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -1034,6 +1034,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws IOException {
// fd is null if constructor threw exception
if (fd != null)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/reflect/misc/MethodUtil.java
--- a/jdk/src/java.base/share/classes/sun/reflect/misc/MethodUtil.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/reflect/misc/MethodUtil.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package sun.reflect.misc;
-import java.lang.reflect.Module;
import java.io.EOFException;
import java.security.AllPermission;
import java.security.AccessController;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/security/provider/KeyProtector.java
--- a/jdk/src/java.base/share/classes/sun/security/provider/KeyProtector.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/provider/KeyProtector.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -147,6 +147,7 @@
* Ensures that the password bytes of this key protector are
* set to zero when there are no more references to it.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() {
if (passwdBytes != null) {
Arrays.fill(passwdBytes, (byte)0x00);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/security/ssl/BaseSSLSocketImpl.java
--- a/jdk/src/java.base/share/classes/sun/security/ssl/BaseSSLSocketImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/BaseSSLSocketImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -265,6 +265,7 @@
* the penalty of prematurly killing SSL sessions.
*/
@Override
+ @SuppressWarnings("deprecation")
protected final void finalize() throws Throwable {
try {
close();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
--- a/jdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -247,6 +247,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected final void finalize() throws Throwable {
// empty
super.finalize();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java
--- a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -485,7 +485,9 @@
if (c != null) {
command = c;
- } else if (collator.compare(flags, "-help") == 0) {
+ } else if (collator.compare(flags, "-help") == 0 ||
+ collator.compare(flags, "-h") == 0 ||
+ collator.compare(flags, "-?") == 0) {
help = true;
} else if (collator.compare(flags, "-conf") == 0) {
i++;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.base/share/native/libjava/Module.c
--- a/jdk/src/java.base/share/native/libjava/Module.c Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.base/share/native/libjava/Module.c Wed Jul 05 23:13:02 2017 +0200
@@ -29,12 +29,12 @@
#include "jni_util.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
* 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*
GetInternalPackageName(JNIEnv *env, jstring pkg, char* buf, jsize buf_size)
@@ -68,7 +68,7 @@
}
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,
jstring location, jobjectArray packages)
{
@@ -109,14 +109,14 @@
}
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);
}
JNIEXPORT void JNICALL
-Java_java_lang_reflect_Module_addExports0(JNIEnv *env, jclass cls, jobject from,
- jstring pkg, jobject to)
+Java_java_lang_Module_addExports0(JNIEnv *env, jclass cls, jobject from,
+ jstring pkg, jobject to)
{
char buf[128];
char* pkg_name;
@@ -136,8 +136,8 @@
}
JNIEXPORT void JNICALL
-Java_java_lang_reflect_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject from,
- jstring pkg)
+Java_java_lang_Module_addExportsToAll0(JNIEnv *env, jclass cls, jobject from,
+ jstring pkg)
{
char buf[128];
char* pkg_name;
@@ -157,8 +157,8 @@
}
JNIEXPORT void JNICALL
-Java_java_lang_reflect_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls,
- jobject from, jstring pkg)
+Java_java_lang_Module_addExportsToAllUnnamed0(JNIEnv *env, jclass cls,
+ jobject from, jstring pkg)
{
char buf[128];
char* pkg_name;
@@ -178,7 +178,7 @@
}
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* pkg_name;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java
--- a/jdk/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -114,6 +114,7 @@
changes.putAll(other.changes);
}
+ @SuppressWarnings("deprecation")
protected synchronized void finalize() throws Throwable {
if (cfDictionaryPtr == 0) return;
disposeCFDictionary(cfDictionaryPtr);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java
--- a/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java Wed Jul 05 23:13:02 2017 +0200
@@ -124,6 +124,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
super.finalize();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/sun/font/CFont.java
--- a/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFont.java Wed Jul 05 23:13:02 2017 +0200
@@ -250,6 +250,7 @@
return compFont;
}
+ @SuppressWarnings("deprecation")
protected synchronized void finalize() {
if (nativeFontPtr != 0) {
disposeNativeFont(nativeFontPtr);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/sun/font/CStrike.java
--- a/jdk/src/java.desktop/macosx/classes/sun/font/CStrike.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/sun/font/CStrike.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -127,6 +127,7 @@
return nativeStrikePtr;
}
+ @SuppressWarnings("deprecation")
protected synchronized void finalize() throws Throwable {
if (nativeStrikePtr != 0) {
disposeNativeStrikePtr(nativeStrikePtr);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -135,6 +135,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected final void finalize() throws Throwable {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -556,6 +556,7 @@
// The following methods are CPrinterJob specific.
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() {
synchronized (fNSPrintInfoLock) {
if (fNSPrintInfo != -1) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/SubImageInputStream.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/SubImageInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/SubImageInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -72,6 +72,7 @@
streamPos = pos;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call
// super.finalize() in this case)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -143,6 +143,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call
// super.finalize() in this case)
@@ -279,6 +280,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call
// super.finalize() in this case)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFBaseJPEGCompressor.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFBaseJPEGCompressor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFBaseJPEGCompressor.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -435,6 +435,7 @@
return compDataLength;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
if(JPEGWriter != null) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFJPEGDecompressor.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFJPEGDecompressor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFJPEGDecompressor.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -139,6 +139,7 @@
JPEGReader.read(0, JPEGParam);
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
JPEGReader.dispose();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFOldJPEGDecompressor.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFOldJPEGDecompressor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFOldJPEGDecompressor.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -610,6 +610,7 @@
JPEGReader.read(0, JPEGParam);
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
JPEGReader.dispose();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamFinalizer.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamFinalizer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/stream/StreamFinalizer.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -60,6 +60,7 @@
this.stream = stream;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
stream.close();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDevice.java
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDevice.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDevice.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -444,6 +444,7 @@
* close this device if discarded by the garbage collector.
*/
@Override
+ @SuppressWarnings("deprecation")
protected final void finalize() {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/java/awt/Graphics.java
--- a/jdk/src/java.desktop/share/classes/java/awt/Graphics.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/java/awt/Graphics.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -1159,8 +1159,18 @@
/**
* Disposes of this graphics context once it is no longer referenced.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
* @see #dispose
*/
+ @Deprecated(since="9")
public void finalize() {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/java/awt/PrintJob.java
--- a/jdk/src/java.desktop/share/classes/java/awt/PrintJob.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/java/awt/PrintJob.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -79,8 +79,18 @@
/**
* Ends this print job once it is no longer referenced.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
* @see #end
*/
+ @Deprecated(since="9")
public void finalize() {
end();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java
--- a/jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -751,7 +751,17 @@
/**
* Frees the resources associated with an ICC_Profile object.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize () {
if (cmmProfile != null) {
CMSManager.getModule().freeProfile(cmmProfile);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/java/awt/image/ColorModel.java
--- a/jdk/src/java.desktop/share/classes/java/awt/image/ColorModel.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/java/awt/image/ColorModel.java Wed Jul 05 23:13:02 2017 +0200
@@ -1620,7 +1620,17 @@
* Disposes of system resources associated with this
* {@code ColorModel} once this {@code ColorModel} is no
* longer referenced.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
public void finalize() {
}
@@ -1952,4 +1962,4 @@
return lg16Toog16LUT;
}
-}
\ No newline at end of file
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java
--- a/jdk/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/java/awt/image/IndexColorModel.java Wed Jul 05 23:13:02 2017 +0200
@@ -1514,7 +1514,17 @@
* Disposes of system resources associated with this
* {@code ColorModel} once this {@code ColorModel} is no
* longer referenced.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
public void finalize() {
}
@@ -1630,4 +1640,4 @@
}
return result;
}
-}
\ No newline at end of file
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import org.w3c.dom.Node;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -706,7 +706,17 @@
*
* @exception Throwable if an error occurs during superclass
* finalization.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
public void finalize() throws Throwable {
deregisterAll();
super.finalize();
@@ -846,6 +856,7 @@
poset.clear();
}
+ @SuppressWarnings("deprecation")
public synchronized void finalize() {
clear();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/stream/FileCacheImageInputStream.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -260,7 +260,17 @@
/**
* {@inheritDoc}
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageInputStream.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -155,7 +155,17 @@
/**
* {@inheritDoc}
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageOutputStream.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageOutputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/FileImageOutputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -163,7 +163,17 @@
/**
* {@inheritDoc}
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/ImageInputStreamImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -867,7 +867,17 @@
*
* @exception Throwable if an error occurs during superclass
* finalization.
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable {
if (!isClosed) {
try {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/imageio/stream/MemoryCacheImageInputStream.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/stream/MemoryCacheImageInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/stream/MemoryCacheImageInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -178,7 +178,17 @@
/**
* {@inheritDoc}
+ *
+ * @deprecated The {@code finalize} method has been deprecated.
+ * Subclasses that override {@code finalize} in order to perform cleanup
+ * should be modified to use alternative cleanup mechanisms and
+ * to remove the overriding {@code finalize} method.
+ * When overriding the {@code finalize} method, its implementation must explicitly
+ * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
+ * See the specification for {@link Object#finalize()} for further
+ * information about migration options.
*/
+ @Deprecated(since="9")
protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/swing/text/PlainView.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/PlainView.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/PlainView.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,7 +31,6 @@
import java.security.PrivilegedAction;
import java.util.Objects;
import javax.swing.event.*;
-import java.lang.reflect.Module;
import java.lang.ref.SoftReference;
import java.util.HashMap;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/javax/swing/text/StringContent.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/StringContent.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/StringContent.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -351,6 +351,7 @@
return rec.offset;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
// schedule the record to be removed later
// on another thread.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java
--- a/jdk/src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -472,6 +472,7 @@
this.pData = pData;
}
+ @SuppressWarnings("deprecation")
public void finalize() {
if (pData != 0L) {
BufImgSurfaceData.freeNativeICMData(pData);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java
--- a/jdk/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -3633,6 +3633,7 @@
* enough to know that if our override is empty then it should not
* mark us as finalizeable.
*/
+ @SuppressWarnings("deprecation")
public void finalize() {
// DO NOT REMOVE THIS METHOD
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/java2d/pipe/RegionClipSpanIterator.java
--- a/jdk/src/java.desktop/share/classes/sun/java2d/pipe/RegionClipSpanIterator.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/java2d/pipe/RegionClipSpanIterator.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -383,6 +383,7 @@
*/
//public native void dispose();
+ @SuppressWarnings("deprecation")
protected void finalize() {
//dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/print/PeekGraphics.java
--- a/jdk/src/java.desktop/share/classes/sun/print/PeekGraphics.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/print/PeekGraphics.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2006, 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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1336,6 +1336,7 @@
/**
* Empty finalizer as no clean up needed here.
*/
+ @SuppressWarnings("deprecation")
public void finalize() {
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java
--- a/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/print/PrintJob2D.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -942,6 +942,7 @@
* Ends this print job once it is no longer referenced.
* @see #end
*/
+ @SuppressWarnings("deprecation")
public void finalize() {
end();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics.java
--- a/jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -1099,6 +1099,7 @@
/**
* Empty finalizer as no clean up needed here.
*/
+ @SuppressWarnings("deprecation")
public void finalize() {
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics2D.java
--- a/jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics2D.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/print/ProxyGraphics2D.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2006, 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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1264,6 +1264,7 @@
/**
* Empty finalizer as no clean up needed here.
*/
+ @SuppressWarnings("deprecation")
public void finalize() {
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/share/legal/jpeg.md
--- a/jdk/src/java.desktop/share/legal/jpeg.md Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/share/legal/jpeg.md Wed Jul 05 23:13:02 2017 +0200
@@ -1,4 +1,4 @@
-## JPEG release 6b
+## Independent JPEG Group: JPEG release 6b
### JPEG License
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -181,6 +181,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
dispose();
super.finalize();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WInputMethod.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -132,6 +132,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable
{
// Release the resources used by the native input context.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java
--- a/jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package java.lang.instrument;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java
--- a/jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package java.lang.instrument;
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.Map;
@@ -346,7 +345,7 @@
/**
- * Determines whether a class is modifiable by
+ * Tests whether a class is modifiable by
* {@linkplain #retransformClasses retransformation}
* or {@linkplain #redefineClasses redefinition}.
* If a class is modifiable then this method returns true
.
@@ -711,8 +710,11 @@
* {@code extraProvides} map contains a service provider type that
* is not a member of the module or an implementation of the service;
* 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
* any of the Sets or Maps contains a {@code null} key or value
+ *
+ * @see #isModifiableModule(Module)
* @since 9
* @spec JPMS
*/
@@ -722,4 +724,19 @@
Map> extraOpens,
Set> extraUses,
Map, List>> 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);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/classes/java/lang/instrument/UnmodifiableModuleException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.instrument/share/classes/java/lang/instrument/UnmodifiableModuleException.java Wed Jul 05 23:13:02 2017 +0200
@@ -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);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java
--- a/jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,11 +23,10 @@
* questions.
*/
-
package sun.instrument;
+import java.lang.instrument.UnmodifiableModuleException;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
import java.lang.reflect.AccessibleObject;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.ClassDefinition;
@@ -132,6 +131,13 @@
return isModifiableClass0(mNativeAgent, theClass);
}
+ public boolean isModifiableModule(Module module) {
+ if (module == null) {
+ throw new NullPointerException("'module' is null");
+ }
+ return true;
+ }
+
public boolean
isRetransformClassesSupported() {
// ask lazily since there is some overhead
@@ -243,6 +249,9 @@
if (!module.isNamed())
return;
+ if (!isModifiableModule(module))
+ throw new UnmodifiableModuleException(module.getName());
+
// copy and check reads
extraReads = new HashSet<>(extraReads);
if (extraReads.contains(null))
@@ -312,7 +321,7 @@
return Collections.emptyMap();
Map> result = new HashMap<>();
- Set packages = Set.of(module.getPackages());
+ Set packages = module.getPackages();
for (Map.Entry> e : map.entrySet()) {
String pkg = e.getKey();
if (pkg == null)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java
--- a/jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,10 +25,8 @@
package sun.instrument;
-
import java.lang.instrument.Instrumentation;
import java.lang.instrument.ClassFileTransformer;
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
/*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h
--- a/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h Wed Jul 05 23:13:02 2017 +0200
@@ -66,7 +66,7 @@
#define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V"
#define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODNAME "transform"
#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"
/*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.logging/share/classes/java/util/logging/Level.java
--- a/jdk/src/java.logging/share/classes/java/util/logging/Level.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.logging/share/classes/java/util/logging/Level.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,10 +24,10 @@
*/
package java.util.logging;
+
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.logging/share/classes/java/util/logging/LogManager.java
--- a/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
* questions.
*/
-
package java.util.logging;
import java.io.*;
@@ -43,7 +42,6 @@
import jdk.internal.misc.JavaAWTAccess;
import jdk.internal.misc.SharedSecrets;
import sun.util.logging.internal.LoggingProviderImpl;
-import java.lang.reflect.Module;
import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.logging/share/classes/java/util/logging/Logger.java
--- a/jdk/src/java.logging/share/classes/java/util/logging/Logger.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.logging/share/classes/java/util/logging/Logger.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,11 +23,9 @@
* questions.
*/
-
package java.util.logging;
import java.lang.ref.WeakReference;
-import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
@@ -664,7 +662,7 @@
* a new logger is created.
*
* If a new logger is created its log level will be configured
- * based on the LogManager configuration and it will configured
+ * based on the LogManager configuration and it will be configured
* to also send logging output to its parent's Handlers. It will
* be registered in the LogManager global namespace.
*
@@ -726,7 +724,7 @@
*
*
* If a new logger is created its log level will be configured
- * based on the LogManager and it will configured to also send logging
+ * based on the LogManager and it will be configured to also send logging
* output to its parent's Handlers. It will be registered in
* the LogManager global namespace.
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.logging/share/classes/sun/util/logging/internal/LoggingProviderImpl.java
--- a/jdk/src/java.logging/share/classes/sun/util/logging/internal/LoggingProviderImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.logging/share/classes/sun/util/logging/internal/LoggingProviderImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -32,7 +32,6 @@
import java.util.function.Supplier;
import java.lang.System.LoggerFinder;
import java.lang.System.Logger;
-import java.lang.reflect.Module;
import java.util.Objects;
import java.util.logging.LogManager;
import jdk.internal.logger.DefaultLoggerFinder;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
--- a/jdk/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Module;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.rmi.MarshalledObject;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.management/share/classes/java/lang/management/LockInfo.java
--- a/jdk/src/java.management/share/classes/java/lang/management/LockInfo.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.management/share/classes/java/lang/management/LockInfo.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -38,8 +38,8 @@
* a synchronizer that may be exclusively owned by a thread and uses
* {@link AbstractOwnableSynchronizer AbstractOwnableSynchronizer}
* (or its subclass) to implement its synchronization property.
- * {@link ReentrantLock ReentrantLock} and
- * {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
+ * {@link ReentrantLock ReentrantLock} and the write-lock (but not
+ * the read-lock) of {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
* two examples of ownable synchronizers provided by the platform.
*
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java
--- a/jdk/src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import com.sun.jmx.mbeanserver.Util;
import java.io.IOException;
import java.io.UncheckedIOException;
-import java.lang.reflect.Module;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.HashMap;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.management/share/classes/sun/management/ManagementFactoryHelper.java
--- a/jdk/src/java.management/share/classes/sun/management/ManagementFactoryHelper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.management/share/classes/sun/management/ManagementFactoryHelper.java Wed Jul 05 23:13:02 2017 +0200
@@ -45,7 +45,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.lang.reflect.Module;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.PrivilegedAction;
import java.util.Collections;
@@ -181,8 +180,7 @@
return AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Class> run() {
- Optional logging = java.lang.reflect.Layer.boot()
- .findModule("java.logging");
+ Optional logging = ModuleLayer.boot().findModule("java.logging");
if (logging.isPresent()) {
return Class.forName(logging.get(), className);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.naming/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java
--- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -382,6 +382,7 @@
listArg = ne.listArg;
}
+ @SuppressWarnings("deprecation")
protected final void finalize() {
cleanup();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java
--- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -474,6 +474,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
if (debug > 0) System.err.println("LdapClient: finalize " + this);
forceClose(pooled);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java
--- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -2609,6 +2609,7 @@
// ----------------- Connection ---------------------
+ @SuppressWarnings("deprecation")
protected void finalize() {
try {
close();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java
--- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -129,6 +129,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
clearPassword();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.naming/share/classes/com/sun/naming/internal/VersionHelper.java
--- a/jdk/src/java.naming/share/classes/com/sun/naming/internal/VersionHelper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.naming/share/classes/com/sun/naming/internal/VersionHelper.java Wed Jul 05 23:13:02 2017 +0200
@@ -176,7 +176,7 @@
InputStream getResourceAsStream(Class> c, String name) {
PrivilegedAction act = () -> {
try {
- java.lang.reflect.Module m = c.getModule();
+ Module m = c.getModule();
return c.getModule().getResourceAsStream(resolveName(c,name));
} catch (IOException x) {
return null;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.rmi/share/classes/java/rmi/activation/ActivationInstantiator.java
--- a/jdk/src/java.rmi/share/classes/java/rmi/activation/ActivationInstantiator.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.rmi/share/classes/java/rmi/activation/ActivationInstantiator.java Wed Jul 05 23:13:02 2017 +0200
@@ -67,11 +67,11 @@
*
* The class to be activated and the special activation constructor are both public,
* 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
*
* 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.
*
*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.rmi/share/classes/java/rmi/server/UnicastRemoteObject.java
--- a/jdk/src/java.rmi/share/classes/java/rmi/server/UnicastRemoteObject.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.rmi/share/classes/java/rmi/server/UnicastRemoteObject.java Wed Jul 05 23:13:02 2017 +0200
@@ -135,9 +135,9 @@
* remote object's class.
*
* 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
- * {@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.
*
* The proxy's invocation handler is a {@link
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.rmi/share/classes/sun/rmi/log/LogInputStream.java
--- a/jdk/src/java.rmi/share/classes/sun/rmi/log/LogInputStream.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.rmi/share/classes/sun/rmi/log/LogInputStream.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -128,6 +128,7 @@
/**
* Closes the stream when garbage is collected.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.rmi/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java
--- a/jdk/src/java.rmi/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.rmi/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -440,6 +440,7 @@
/**
* Shut down connection upon finalization.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable
{
super.finalize();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSCredElement.java
--- a/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSCredElement.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSCredElement.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -130,6 +130,7 @@
return "N/A";
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSNameElement.java
--- a/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSNameElement.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSNameElement.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -289,6 +289,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/NativeGSSContext.java
--- a/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/NativeGSSContext.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/NativeGSSContext.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -618,6 +618,7 @@
return isInitiator;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Base.java
--- a/jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Base.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/CramMD5Base.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, 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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -136,6 +136,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
clearPassword();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/PlainClient.java
--- a/jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/PlainClient.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.security.sasl/share/classes/com/sun/security/sasl/PlainClient.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -199,6 +199,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
clearPassword();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.smartcardio/share/classes/sun/security/smartcardio/CardImpl.java
--- a/jdk/src/java.smartcardio/share/classes/sun/security/smartcardio/CardImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.smartcardio/share/classes/sun/security/smartcardio/CardImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -274,6 +274,7 @@
+ ", protocol " + getProtocol() + ", state " + state;
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (state == State.OK) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/java.sql/share/classes/java/sql/Connection.java
--- a/jdk/src/java.sql/share/classes/java/sql/Connection.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/java.sql/share/classes/java/sql/Connection.java Wed Jul 05 23:13:02 2017 +0200
@@ -1535,8 +1535,9 @@
* The connection pool caches {@code PooledConnection} objects
* Returns a logical connection handle when {@code getConnection} is
* called by the application
- * The pool manager calls {@code Connection.close} on the logical connection handle
- * prior to returning the {@code PooledConnection} back to the cache
+ * The logical {@code Connection} is closed by calling
+ * {@code Connection.close} prior to returning the {@code PooledConnection}
+ * to the cache.
*
* @throws SQLException if an error occurs
* @since 9
@@ -1577,8 +1578,9 @@
* The connection pool caches {@code PooledConnection} objects
* Returns a logical connection handle when {@code getConnection} is
* called by the application
- * The pool manager calls {@code Connection.close} on the logical connection handle
- * prior to returning the {@code PooledConnection} back to the cache
+ * The logical {@code Connection} is closed by calling
+ * {@code Connection.close} prior to returning the {@code PooledConnection}
+ * to the cache.
*
* @throws SQLException if an error occurs
* @since 9
@@ -1590,7 +1592,10 @@
}
/**
- * Sets and validates the sharding keys for this connection.
+ * Sets and validates the sharding keys for this connection. A {@code null}
+ * value may be specified for the sharding Key. The validity
+ * of a {@code null} sharding key is vendor-specific. Consult your vendor's
+ * documentation for additional information.
* @implSpec
* The default implementation will throw a
* {@code SQLFeatureNotSupportedException}.
@@ -1600,7 +1605,8 @@
* {@code Connection}. The timeout value indicates how long the driver
* should wait for the {@code Connection} to verify that the sharding key
* is valid before {@code setShardingKeyIfValid} returns false.
- * @param shardingKey the sharding key to be validated against this connection
+ * @param shardingKey the sharding key to be validated against this connection.
+ * The sharding key may be {@code null}
* @param superShardingKey the super sharding key to be validated against this
* connection. The super sharding key may be {@code null}.
* @param timeout time in seconds before which the validation process is expected to
@@ -1610,10 +1616,10 @@
* and set on this connection; false if the sharding keys are not valid or
* the timeout period expires before the operation completes.
* @throws SQLException if an error occurs while performing this validation;
- * the {@code shardingkey} is {@code null}; a {@code superSharedingKey} is specified
+ * a {@code superSharedingKey} is specified
* without a {@code shardingKey};
* this method is called on a closed {@code connection}; or
- * the {@code timeout} value is less than 0.
+ * the {@code timeout} value is negative.
* @throws SQLFeatureNotSupportedException if the driver does not support sharding
* @since 9
* @see ShardingKey
@@ -1626,7 +1632,10 @@
}
/**
- * Sets and validates the sharding key for this connection.
+ * Sets and validates the sharding key for this connection. A {@code null}
+ * value may be specified for the sharding Key. The validity
+ * of a {@code null} sharding key is vendor-specific. Consult your vendor's
+ * documentation for additional information.
* @implSpec
* The default implementation will throw a
* {@code SQLFeatureNotSupportedException}.
@@ -1635,7 +1644,8 @@
* {@code Connection}. The timeout value indicates how long the driver
* should wait for the {@code Connection} to verify that the sharding key
* is valid before {@code setShardingKeyIfValid} returns false.
- * @param shardingKey the sharding key to be validated against this connection
+ * @param shardingKey the sharding key to be validated against this connection.
+ * The sharding key may be {@code null}
* @param timeout time in seconds before which the validation process is expected to
* be completed,else the validation process is aborted. A value of 0 indicates
* the validation process will not time out.
@@ -1643,8 +1653,8 @@
* set on this connection; false if the sharding key is not valid or
* the timeout period expires before the operation completes.
* @throws SQLException if there is an error while performing this validation;
- * this method is called on a closed {@code connection}; the {@code shardingkey}
- * is {@code null}; or the {@code timeout} value is less than 0.
+ * this method is called on a closed {@code connection};
+ * or the {@code timeout} value is negative.
* @throws SQLFeatureNotSupportedException if the driver does not support sharding
* @since 9
* @see ShardingKey
@@ -1664,12 +1674,12 @@
* This method sets the specified sharding keys but does not require a
* round trip to the database to validate that the sharding keys are valid
* for the {@code Connection}.
- * @param shardingKey the sharding key to set on this connection.
+ * @param shardingKey the sharding key to set on this connection. The sharding
+ * key may be {@code null}
* @param superShardingKey the super sharding key to set on this connection.
* The super sharding key may be {@code null}
* @throws SQLException if an error occurs setting the sharding keys;
- * this method is called on a closed {@code connection};
- * the {@code shardingkey} is {@code null}; or
+ * this method is called on a closed {@code connection}; or
* a {@code superSharedingKey} is specified without a {@code shardingKey}
* @throws SQLFeatureNotSupportedException if the driver does not support sharding
* @since 9
@@ -1690,10 +1700,10 @@
* This method sets the specified sharding key but does not require a
* round trip to the database to validate that the sharding key is valid
* for the {@code Connection}.
- * @param shardingKey the sharding key to set on this connection.
- * @throws SQLException if an error occurs setting the sharding key;
- * this method is called on a closed {@code connection}; or the
- * {@code shardkingKey} is {@code null}
+ * @param shardingKey the sharding key to set on this connection. The sharding
+ * key may be {@code null}
+ * @throws SQLException if an error occurs setting the sharding key; or
+ * this method is called on a closed {@code connection}
* @throws SQLFeatureNotSupportedException if the driver does not support sharding
* @since 9
* @see ShardingKey
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.accessibility/share/classes/module-info.java
--- a/jdk/src/jdk.accessibility/share/classes/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.accessibility/share/classes/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,6 +26,7 @@
/**
* Defines JDK utility classes used by implementors of Assistive Technologies.
*
+ * @moduleGraph
* @since 9
*/
module jdk.accessibility {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java
--- a/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, 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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -241,6 +241,7 @@
pc.setPassword(password); // this clones the password if not null
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
if (password != null) {
Arrays.fill(password, ' ');
@@ -1022,7 +1023,7 @@
("trusted certificates may only be set by " +
"token initialization application"));
}
- Module module = token.provider.nssModule;
+ Secmod.Module module = token.provider.nssModule;
if ((module.type != ModuleType.KEYSTORE) && (module.type != ModuleType.FIPS)) {
// XXX allow TRUSTANCHOR module
throw new KeyStoreException("Trusted certificates can only be "
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
--- a/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java Wed Jul 05 23:13:02 2017 +0200
@@ -77,7 +77,7 @@
final boolean removable;
- final Module nssModule;
+ final Secmod.Module nssModule;
final boolean nssUseSecmodTrust;
@@ -148,7 +148,7 @@
boolean useSecmod = config.getNssUseSecmod();
boolean nssUseSecmodTrust = config.getNssUseSecmodTrust();
- Module nssModule = null;
+ Secmod.Module nssModule = null;
//
// Initialization via Secmod. The way this works is as follows:
@@ -217,7 +217,7 @@
// XXX which exception to throw
throw new ProviderException("Could not initialize NSS", e);
}
- List modules = secmod.getModules();
+ List modules = secmod.getModules();
if (config.getShowInfo()) {
System.out.println("NSS modules: " + modules);
}
@@ -258,7 +258,7 @@
("Invalid external module: " + moduleName);
}
int k = 0;
- for (Module module : modules) {
+ for (Secmod.Module module : modules) {
if (module.getType() == ModuleType.EXTERNAL) {
if (++k == moduleIndex) {
nssModule = module;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java
--- a/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -1531,6 +1531,7 @@
*
* @exception Throwable If finalization fails.
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
disconnect();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.crypto.ec/share/legal/ecc.md
--- a/jdk/src/jdk.crypto.ec/share/legal/ecc.md Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.crypto.ec/share/legal/ecc.md Wed Jul 05 23:13:02 2017 +0200
@@ -6,7 +6,8 @@
This notice is provided with respect to Elliptic Curve Cryptography,
which is included with JRE, JDK, and OpenJDK.
-You are receiving a copy of the Elliptic Curve Cryptography library in source
+You are receiving a [copy](http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/jdk.crypto.ec/share/native/libsunec/impl)
+of the Elliptic Curve Cryptography library in source
form with the JDK and OpenJDK source distributions, and as object code in
the JRE & JDK runtimes.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/Key.java
--- a/jdk/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/Key.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/Key.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -52,6 +52,7 @@
/**
* Finalization method
*/
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable
{
try {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.editpad/share/classes/module-info.java
--- a/jdk/src/jdk.editpad/share/classes/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.editpad/share/classes/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,6 +26,7 @@
/**
* Implementation of the edit pad service.
*
+ * @moduleGraph
* @since 9
*/
module jdk.editpad {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.incubator.httpclient/share/classes/module-info.java
--- a/jdk/src/jdk.incubator.httpclient/share/classes/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.incubator.httpclient/share/classes/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,6 +27,7 @@
* Defines the high-level HTTP and WebSocket API.
* {@Incubating}
*
+ * @moduleGraph
* @since 9
*/
module jdk.incubator.httpclient {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/console/ConsoleReader.java
--- a/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/console/ConsoleReader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/console/ConsoleReader.java Wed Jul 05 23:13:02 2017 +0200
@@ -306,6 +306,7 @@
* Shuts down the ConsoleReader if the JVM attempts to clean it up.
*/
@Override
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
shutdown();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java
--- a/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Wed Jul 05 23:13:02 2017 +0200
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -74,7 +74,7 @@
//in.resetPromptLine(in.getPrompt(), in.getHistory().current().toString(), -1);
//but that would mean more re-writing on the screen, (and prints an additional
//empty line), so using setBuffer directly:
- Method setBuffer = in.getClass().getDeclaredMethod("setBuffer", String.class);
+ Method setBuffer = ConsoleReader.class.getDeclaredMethod("setBuffer", String.class);
setBuffer.setAccessible(true);
setBuffer.invoke(in, in.getHistory().current().toString());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java
--- a/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -444,6 +444,7 @@
} else if (collator.compare(flags, "-strict") ==0) {
strict = true;
} else if (collator.compare(flags, "-h") == 0 ||
+ collator.compare(flags, "-?") == 0 ||
collator.compare(flags, "-help") == 0) {
fullusage();
} else {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
package sun.tools.common;
-import java.lang.reflect.Module;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jdwp.agent/share/native/libjdwp/ModuleReferenceImpl.c
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/ModuleReferenceImpl.c Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/ModuleReferenceImpl.c Wed Jul 05 23:13:02 2017 +0200
@@ -29,8 +29,8 @@
#include "ModuleReferenceImpl.h"
-static jclass jlrM(JNIEnv *env) {
- return findClass(env, "Ljava/lang/reflect/Module;");
+static jclass jlM(JNIEnv *env) {
+ return findClass(env, "Ljava/lang/Module;");
}
static jboolean
@@ -43,7 +43,7 @@
jobject module;
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);
if (inStream_error(in)) {
@@ -71,7 +71,7 @@
jobject module;
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);
if (inStream_error(in)) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.nio.ByteOrder;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -55,10 +54,10 @@
* @return A new plugin or null if plugin is unknown.
*/
public static Plugin newPlugin(String name,
- Map configuration, Layer pluginsLayer) {
+ Map configuration, ModuleLayer pluginsLayer) {
Objects.requireNonNull(name);
Objects.requireNonNull(configuration);
- pluginsLayer = pluginsLayer == null ? Layer.boot() : pluginsLayer;
+ pluginsLayer = pluginsLayer == null ? ModuleLayer.boot() : pluginsLayer;
return PluginRepository.newPlugin(configuration, name, pluginsLayer);
}
@@ -330,7 +329,7 @@
private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) {
List plugins = new ArrayList<>(pluginsConfig.getPlugins());
- List bootPlugins = PluginRepository.getPlugins(Layer.boot());
+ List bootPlugins = PluginRepository.getPlugins(ModuleLayer.boot());
for (Plugin bp : bootPlugins) {
if (Utils.isAutoEnabled(bp)) {
try {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginRepository.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
*/
package jdk.tools.jlink.internal;
-import java.lang.reflect.Layer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -56,7 +55,7 @@
* @return A provider or null if not found.
*/
public static Plugin getPlugin(String name,
- Layer pluginsLayer) {
+ ModuleLayer pluginsLayer) {
return getPlugin(Plugin.class, name, pluginsLayer);
}
@@ -69,7 +68,7 @@
* @return A plugin or null if no plugin found.
*/
public static Plugin newPlugin(Map config, String name,
- Layer pluginsLayer) {
+ ModuleLayer pluginsLayer) {
Objects.requireNonNull(name);
Objects.requireNonNull(pluginsLayer);
Plugin plugin = getPlugin(name, pluginsLayer);
@@ -107,12 +106,12 @@
registeredPlugins.remove(name);
}
- public static List getPlugins(Layer pluginsLayer) {
+ public static List getPlugins(ModuleLayer pluginsLayer) {
return getPlugins(Plugin.class, pluginsLayer);
}
private static T getPlugin(Class clazz, String name,
- Layer pluginsLayer) {
+ ModuleLayer pluginsLayer) {
Objects.requireNonNull(name);
Objects.requireNonNull(pluginsLayer);
@SuppressWarnings("unchecked")
@@ -136,7 +135,7 @@
* @param pluginsLayer
* @return The list of plugins.
*/
- private static List getPlugins(Class clazz, Layer pluginsLayer) {
+ private static List getPlugins(Class clazz, ModuleLayer pluginsLayer) {
Objects.requireNonNull(pluginsLayer);
List factories = new ArrayList<>();
try {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Wed Jul 05 23:13:02 2017 +0200
@@ -29,7 +29,6 @@
import java.io.PrintWriter;
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -211,7 +210,7 @@
private final class PluginsHelper {
- private Layer pluginsLayer = Layer.boot();
+ private ModuleLayer pluginsLayer = ModuleLayer.boot();
private final List plugins;
private String lastSorter;
private boolean listPlugins;
@@ -655,7 +654,7 @@
return defaults;
}
- public Layer getPluginsLayer() {
+ public ModuleLayer getPluginsLayer() {
return pluginOptions.pluginsLayer;
}
}
@@ -725,18 +724,18 @@
return System.getProperty("java.version");
}
- static Layer createPluginsLayer(List paths) {
+ static ModuleLayer createPluginsLayer(List paths) {
Path[] dirs = paths.toArray(new Path[0]);
ModuleFinder finder = ModulePath.of(Runtime.version(), true, dirs);
- Configuration bootConfiguration = Layer.boot().configuration();
+ Configuration bootConfiguration = ModuleLayer.boot().configuration();
try {
Configuration cf = bootConfiguration
.resolveAndBind(ModuleFinder.of(),
finder,
Collections.emptySet());
ClassLoader scl = ClassLoader.getSystemClassLoader();
- return Layer.boot().defineModulesWithOneLoader(cf, scl);
+ return ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
} catch (Exception ex) {
// Malformed plugin modules (e.g.: same package in multiple modules).
throw new PluginException("Invalid modules in the plugins path: " + ex);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
*/
package jdk.tools.jlink.internal;
-import java.lang.reflect.Module;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.lang.module.ModuleDescriptor;
import java.util.EnumSet;
@@ -43,8 +44,6 @@
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
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;
/**
@@ -101,9 +100,9 @@
// --release-info add:build_type=fastdebug,source=openjdk,java_version=9
// and put whatever value that was passed in command line.
- config.keySet().stream().
- filter(s -> !NAME.equals(s)).
- forEach(s -> release.put(s, config.get(s)));
+ config.keySet().stream()
+ .filter(s -> !NAME.equals(s))
+ .forEach(s -> release.put(s, config.get(s)));
}
break;
@@ -148,8 +147,8 @@
// put topological sorted module names separated by space
release.put("MODULES", new ModuleSorter(in.moduleView())
- .sorted().map(ResourcePoolModule::name)
- .collect(Collectors.joining(" ", "\"", "\"")));
+ .sorted().map(ResourcePoolModule::name)
+ .collect(Collectors.joining(" ", "\"", "\"")));
// create a TOP level ResourcePoolEntry for "release" file.
out.add(ResourcePoolEntry.create("/java.base/release",
@@ -160,11 +159,11 @@
// Parse version string and return a string that includes only version part
// leaving "pre", "build" information. See also: java.lang.Runtime.Version.
private static String parseVersion(String str) {
- return Runtime.Version.parse(str).
- version().
- stream().
- map(Object::toString).
- collect(Collectors.joining("."));
+ return Runtime.Version.parse(str)
+ .version()
+ .stream()
+ .map(Object::toString)
+ .collect(Collectors.joining("."));
}
private static String quote(String str) {
@@ -172,14 +171,12 @@
}
private byte[] releaseFileContent() {
- Properties props = new Properties();
- props.putAll(release);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- props.store(baos, "");
- return baos.toByteArray();
- } catch (IOException ex) {
- throw new UncheckedIOException(ex);
+ try (PrintWriter pw = new PrintWriter(baos)) {
+ release.entrySet().stream()
+ .sorted(Map.Entry.comparingByKey())
+ .forEach(e -> pw.format("%s=%s%n", e.getKey(), e.getValue()));
}
+ return baos.toByteArray();
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsClient.java
--- a/jdk/src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsClient.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsClient.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -142,6 +142,7 @@
resps = Collections.synchronizedMap(new HashMap());
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java
--- a/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -119,6 +119,7 @@
reference = ctx.reference;
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
close();
}
@@ -593,6 +594,7 @@
nextName = 0;
}
+ @SuppressWarnings("deprecation")
protected void finalize() {
ctx.close();
}
@@ -633,6 +635,7 @@
}
}
+ @SuppressWarnings("deprecation")
public void close () {
finalize();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Base.java
--- a/jdk/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Base.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Base.java Wed Jul 05 23:13:02 2017 +0200
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -158,6 +158,7 @@
}
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
dispose();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
--- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java Wed Jul 05 23:13:02 2017 +0200
@@ -936,6 +936,7 @@
return zc.toString(name);
}
+ @SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/ProblemList.txt
--- a/jdk/test/ProblemList.txt Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/ProblemList.txt Wed Jul 05 23:13:02 2017 +0200
@@ -289,8 +289,6 @@
java/util/BitSet/BitSetStreamTest.java 8079538 generic-all
-jdk/internal/util/jar/TestVersionedStream.java 8177640 windows-all
-
############################################################################
# jdk_instrument
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/TEST.ROOT
--- a/jdk/test/TEST.ROOT Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/TEST.ROOT Wed Jul 05 23:13:02 2017 +0200
@@ -26,8 +26,8 @@
# Allow querying of various System properties in @requires clauses
requires.properties=sun.arch.data.model java.runtime.name
-# Tests using jtreg 4.2 b05 features
-requiredVersion=4.2 b05
+# Tests using jtreg 4.2 b07 features
+requiredVersion=4.2 b07
# Path to libraries in the topmost test directory. This is needed so @library
# does not need ../../ notation to reach them
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/ArgumentValuesTest.java
--- a/jdk/test/com/sun/jdi/ArgumentValuesTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/ArgumentValuesTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,13 +1,38 @@
-/** hard coded linenumbers in other tests - DO NOT CHANGE
- * @test/nodynamiccopyright/
- * @bug 4490824
- * @summary JDI: provide arguments when no debug attributes present
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
*
- * @author jjh
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4490824
+ * @summary JDI: provide arguments when no debug attributes present
*
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile ArgumentValuesTest.java
- * @run driver ArgumentValuesTest
+ * @author jjh
+ *
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile ArgumentValuesTest.java
+ * @run driver ArgumentValuesTest
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
@@ -35,26 +60,26 @@
static List intList;
public static void noArgs() {
- int index = 0; // line 38
+ int index = 0; // line NO_ARGS_LINE_1
}
public static void allArgs(char p_char, byte p_byte, short p_short,
int p_int, long p_long, float p_float,
double p_double, int p_iarray[], int p_marray[][],
String p_sarray1[], String p_string) {
- int index = 0; // line 45
+ int index = 0; // line ALL_ARGS_LINE_1
}
public static void varArgs(String ... p1) {
- int index = 0; // line 49
+ int index = 0; // line VAR_ARGS_LINE_1
}
public static void genericArgs(List p1) {
- int index = 0; // line 53
+ int index = 0; // line GENERIC_ARGS_LINE_1
}
public void instanceMethod(char p_char, byte p_byte) {
- int index = 0; // line 57
+ int index = 0; // line INSTANCE_METHOD_LINE_1
}
public static void main(String[] args) {
@@ -81,6 +106,12 @@
/********** test program **********/
public class ArgumentValuesTest extends TestScaffold {
+ static final int NO_ARGS_LINE_1 = 63;
+ static final int ALL_ARGS_LINE_1 = 70;
+ static final int VAR_ARGS_LINE_1 = 74;
+ static final int GENERIC_ARGS_LINE_1 = 78;
+ static final int INSTANCE_METHOD_LINE_1 = 82;
+
// Must be in same order as args to allArgs(....)
String fieldNames[] = {"s_char1", "s_byte1", "s_short1", "s_int1",
"s_long1", "s_float1", "s_double1", "s_iarray1",
@@ -118,7 +149,7 @@
{
System.out.println("----- Testing each type of arg");
- bpe = resumeTo("ArgumentValuesTarg", 45);
+ bpe = resumeTo("ArgumentValuesTarg", ALL_ARGS_LINE_1);
StackFrame frame = bpe.thread().frame(0);
Method mmm = frame.location().method();
@@ -147,7 +178,7 @@
// a method with no params
{
System.out.println("----- Testing no args");
- bpe = resumeTo("ArgumentValuesTarg", 38);
+ bpe = resumeTo("ArgumentValuesTarg", NO_ARGS_LINE_1);
StackFrame frame = bpe.thread().frame(0);
Method mmm = frame.location().method();
@@ -165,7 +196,7 @@
// as a String[3] in the method.
{
System.out.println("----- Testing var args");
- bpe = resumeTo("ArgumentValuesTarg", 49);
+ bpe = resumeTo("ArgumentValuesTarg", VAR_ARGS_LINE_1);
StackFrame frame = bpe.thread().frame(0);
Method mmm = frame.location().method();
@@ -199,7 +230,7 @@
// a method with with one generic param
{
System.out.println("----- Testing generic args");
- bpe = resumeTo("ArgumentValuesTarg", 53);
+ bpe = resumeTo("ArgumentValuesTarg", GENERIC_ARGS_LINE_1);
StackFrame frame = bpe.thread().frame(0);
Method mmm = frame.location().method();
@@ -224,7 +255,7 @@
// test instance method call
{
System.out.println("----- Testing instance method call");
- bpe = resumeTo("ArgumentValuesTarg", 57);
+ bpe = resumeTo("ArgumentValuesTarg", INSTANCE_METHOD_LINE_1);
StackFrame frame = bpe.thread().frame(0);
Method mmm = frame.location().method();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/BreakpointTest.java
--- a/jdk/test/com/sun/jdi/BreakpointTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/BreakpointTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -21,19 +21,20 @@
* questions.
*/
+// THIS TEST IS LINE NUMBER SENSITIVE
+
/**
- * @test
- * @bug 6496524
- * @summary Setting breakpoint in jdb crashes Hotspot JVM
- *
- * @author jjh
+ * @test
+ * @bug 6496524
+ * @key intermittent
+ * @summary Setting breakpoint in jdb crashes Hotspot JVM
+ * @author jjh
*
- * @key intermittent
- * @modules jdk.jdi
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g BreakpointTest.java
- * @run driver BreakpointTest
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g BreakpointTest.java
+ * @run driver BreakpointTest
*/
+
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
@@ -47,7 +48,6 @@
class BreakpointTarg {
public final static int BKPT_LINE = 56;
- // LINE NUMBER SENSITIVE
public static long count;
static void doit() {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/FetchLocals.java
--- a/jdk/test/com/sun/jdi/FetchLocals.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/FetchLocals.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,13 +1,37 @@
-/** hard coded linenumbers in test - DO NOT CHANGE
- * @test/nodynamiccopyright/
- * @bug 4386002 4429245
- * @summary Test fix for: Incorrect values reported for some locals of type long
+/*
+ * Copyright (c) 2013, 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.
+ *
+ * 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).
*
- * @author Tim Bell
+ * 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.
*
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g FetchLocals.java
- * @run driver FetchLocals
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4386002 4429245
+ * @summary Test fix for: Incorrect values reported for some locals of type long
+ * @author Tim Bell
+ *
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g FetchLocals.java
+ * @run driver FetchLocals
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
@@ -59,7 +83,7 @@
System.out.println(f);
System.out.print("d is: ");
System.out.println(d);
- System.out.println(); // Thie is Line 63...
+ System.out.println(); // This is FetchLocals::LINE
if (w == 0xde00ad00be00ef00L) {
System.out.print ("The debugger was here. w modified to: 0x");
System.out.println(Long.toHexString(w));
@@ -87,6 +111,7 @@
}
public class FetchLocals extends TestScaffold {
+ static final int LINE = 86;
FetchLocals (String args[]) {
super(args);
@@ -355,7 +380,7 @@
* Get to the bottom of testMethod():
*/
try {
- BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", 63);
+ BreakpointEvent bpe = resumeTo("FetchLocalsDebugee", LINE);
/*
* Fetch values from fields; what did we get?
*/
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/GetLocalVariables.java
--- a/jdk/test/com/sun/jdi/GetLocalVariables.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/GetLocalVariables.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,14 +1,39 @@
-/** hard coded linenumbers in this test - DO NOT CHANGE
- * @test/nodynamiccopyright/
- * @bug 4359312 4450091
- * @summary Test PTR 1421 JVM exceptions making a call to LocalVariable.type().name()
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
*
- * @author Tim Bell (based on the PTR 1421 report submitted by IBM).
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4359312 4450091
+ * @summary Test PTR 1421 JVM exceptions making a call to LocalVariable.type().name()
+ * @author Tim Bell (based on the PTR 1421 report submitted by IBM).
*
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g GetLocalVariables.java
- * @run driver GetLocalVariables
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g GetLocalVariables.java
+ * @run driver GetLocalVariables
*/
+
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
@@ -194,7 +219,7 @@
l_long, l_float, l_double, l_iarray,
l_marray, l_string);
- e1.test_1(); // <-- this is line 197
+ e1.test_1(); // RESUME_TO_LINE
e3.test_1();
e4.test_1();
e5.test_1();
@@ -231,6 +256,7 @@
/********** test program **********/
public class GetLocalVariables extends TestScaffold {
+ static final int RESUME_TO_LINE = 222;
ReferenceType targetClass;
ThreadReference mainThread;
@@ -257,7 +283,7 @@
mainThread = bpe.thread();
EventRequestManager erm = vm().eventRequestManager();
- bpe = resumeTo("GetLocalVariablesTarg", 197);
+ bpe = resumeTo("GetLocalVariablesTarg", RESUME_TO_LINE);
/*
* We've arrived. Look around at some variables.
*/
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/GetSetLocalTest.java
--- a/jdk/test/com/sun/jdi/GetSetLocalTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/GetSetLocalTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,13 +1,37 @@
-/** hard coded linenumbers in other tests - DO NOT CHANGE
- * @test/nodynamiccopyright/
- * @bug 4300412
- * @summary Test GetLocal* and SetLocal* functions
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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).
*
- * @author Serguei Spitsyn
+ * 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.
*
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g GetSetLocalTest.java
- * @run driver GetSetLocalTest
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4300412
+ * @summary Test GetLocal* and SetLocal* functions
+ * @author Serguei Spitsyn
+ *
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g GetSetLocalTest.java
+ * @run driver GetSetLocalTest
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
@@ -35,7 +59,7 @@
int result;
{
{ boolean bool_1 = false;
- intArg++;
+ intArg++; // START_LINE
}
boolean bool_2 = true;
@@ -111,7 +135,7 @@
}
Object obj_2 = new Object();
- intArg++; // <-- Last stop is at this point.
+ intArg++; // STOP_LINE. Last stop is at this point.
// Only obj_2 and intArg are valid
// Note: even result is not valid here!
}
@@ -125,6 +149,8 @@
/********** test program **********/
public class GetSetLocalTest extends TestScaffold {
+ static final int START_LINE = 62;
+ static final int STOP_LINE = 138;
ReferenceType targetClass;
ThreadReference mainThread;
@@ -635,7 +661,7 @@
println("EventRequestManager");
StackFrame frame = null;
- for (int line = 38; line < 118; line += 4) {
+ for (int line = START_LINE; line <= STOP_LINE; line += 4) {
println("\n resumeTo(GetSetLocalTarg, " + line + ")");
bpe = resumeTo("GetSetLocalTarg", line);
frame = bpe.thread().frame(0);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/LambdaBreakpointTest.java
--- a/jdk/test/com/sun/jdi/LambdaBreakpointTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/LambdaBreakpointTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -21,19 +21,18 @@
* questions.
*/
-/********** LINE NUMBER SENSITIVE! *****************************************************************/
+// THIS TEST IS LINE NUMBER SENSITIVE
/**
- * @test
- * @summary Test setting breakpoints on lambda calls
- *
- * @author Staffan Larsen
+ * @test
+ * @summary Test setting breakpoints on lambda calls
+ * @author Staffan Larsen
*
- * @modules jdk.jdi
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g LambdaBreakpointTest.java
- * @run driver LambdaBreakpointTest
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g LambdaBreakpointTest.java
+ * @run driver LambdaBreakpointTest
*/
+
import java.util.List;
import com.sun.jdi.LocalVariable;
@@ -50,22 +49,17 @@
/********** target program **********/
class LambdaBreakpointTestTarg {
-
- static int[] breakpointLines = {
- 63, 67, 64, 65, 66, 68
- };
-
public static void main(String[] args) {
test();
}
private static void test() {
- Runnable r = () -> { // B1: L62
- String from = "lambda"; // B3: L63
- System.out.println("Hello from " + from); // B4: L64
- }; // B5: L65
- r.run(); // B2: L66
- System.out.println("Goodbye."); // B6: L67
+ Runnable r = () -> { // LambdaBreakpointTest::TEST_LINE_1, BKPT_LINES[0]
+ String from = "lambda"; // LambdaBreakpointTest::TEST_LINE_2, BKPT_LINES[2]
+ System.out.println("Hello from " + from); // LambdaBreakpointTest::TEST_LINE_3, BKPT_LINES[3]
+ }; // LambdaBreakpointTest::TEST_LINE_4, BKPT_LINES[4]
+ r.run(); // LambdaBreakpointTest::TEST_LINE_5, BKPT_LINES[1]
+ System.out.println("Goodbye."); // LambdaBreakpointTest::TEST_LINE_6, BKPT_LINES[5]
}
}
@@ -73,6 +67,21 @@
/********** test program **********/
public class LambdaBreakpointTest extends TestScaffold {
+ private static final int TEST_LINE_1 = 57;
+ private static final int TEST_LINE_2 = TEST_LINE_1 + 1;
+ private static final int TEST_LINE_3 = TEST_LINE_1 + 2;
+ private static final int TEST_LINE_4 = TEST_LINE_1 + 3;
+ private static final int TEST_LINE_5 = TEST_LINE_1 + 4;
+ private static final int TEST_LINE_6 = TEST_LINE_1 + 5;
+
+ private static final int[] BKPT_LINES = {
+ TEST_LINE_1,
+ TEST_LINE_5,
+ TEST_LINE_2,
+ TEST_LINE_3,
+ TEST_LINE_4,
+ TEST_LINE_6,
+ };
LambdaBreakpointTest (String args[]) {
super(args);
@@ -92,7 +101,7 @@
startToMain("LambdaBreakpointTestTarg");
// Put a breakpoint on each location in the order they should happen
- for (int line : LambdaBreakpointTestTarg.breakpointLines) {
+ for (int line : BKPT_LINES) {
System.out.println("Running to line: " + line);
BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line);
int stoppedAt = be.location().lineNumber();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/LineNumberOnBraceTest.java
--- a/jdk/test/com/sun/jdi/LineNumberOnBraceTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/LineNumberOnBraceTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,13 +1,37 @@
-/**
- * @test/nodynamiccopyright/
- * @bug 4952629 4870514
- * @summary REGRESSION: javac generates a spurious line number entry on } else {
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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).
*
- * @author jjh
+ * 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.
*
- * @run build VMConnection TargetListener TargetAdapter
- * @run compile -g LineNumberOnBraceTest.java
- * @run driver LineNumberOnBraceTest
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4952629 4870514
+ * @summary REGRESSION: javac generates a spurious line number entry on } else {
+ * @author jjh
+ *
+ * @run build VMConnection TargetListener TargetAdapter
+ * @run compile -g LineNumberOnBraceTest.java
+ * @run driver LineNumberOnBraceTest
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
@@ -15,29 +39,27 @@
import java.util.*;
- /********** LINE NUMBER SENSITIVE! *****************************************************************/
class LineNumberOnBraceTarg {
- public final static int stopLine = 29; // THIS MUST BE THE LINE NUMBER OF THE // stopline LINE
- public final static int stopLine2 = 35; // THIS MUST BE THE LINE NUMBER OF THE // stopline2 LINE
-
+ public final static int STOP_LINE = 50; // THIS MUST BE THE LINE NUMBER OF // STOP_LINE LINE
+ public final static int STOP_LINE_2 = 56; // THIS MUST BE THE LINE NUMBER OF // STOP_LINE_2 LINE
public static void main(String[] args){
System.out.println("Howdy!");
if (args.length == 0) {
- System.out.println("No args to debuggee"); // stopLine
+ System.out.println("No args to debuggee"); // STOP_LINE
} else {
System.out.println("Some args to debuggee");
}
- if (args.length == 0) {
+ if (args.length == 0) { // STOP_LINE + 4
boolean b1 = false;
- if (b1) { // stopLine2
+ if (b1) { // STOP_LINE_2
System.out.println("In 2nd else"); // bug 4870514 is that we stop here.
}
} else {
System.out.println("In 2nd else");
}
- System.out.println("Goodbye from LineNumberOnBraceTarg!"); // stopLine2 + 6
+ System.out.println("Goodbye from LineNumberOnBraceTarg!");
}
// This isn't part of the test; it is just here
@@ -78,7 +100,7 @@
targetClass = bpe.location().declaringType();
mainThread = bpe.thread();
- resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.stopLine);
+ resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.STOP_LINE);
StepEvent stepev = stepOverLine(mainThread); // step to 2nd if (args.length
// Bug 4952629 is that javac outputs a line number
@@ -87,24 +109,23 @@
int ln = stepev.location().lineNumber();
System.out.println("Debuggee is stopped at line " + ln);
- if (ln != LineNumberOnBraceTarg.stopLine + 4) {
+ if (ln != LineNumberOnBraceTarg.STOP_LINE + 4) {
failure("FAIL: Bug 4952629: Should be at line " +
- (LineNumberOnBraceTarg.stopLine + 4) +
+ (LineNumberOnBraceTarg.STOP_LINE + 4) +
", am at " + ln);
} else {
System.out.println("Passed test for 4952629");
}
// Test for bug 4870514
- System.out.println("Resuming to " + LineNumberOnBraceTarg.stopLine2);
- resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.stopLine2);
- System.out.println("Stopped at " + LineNumberOnBraceTarg.stopLine2);
+ System.out.println("Resuming to " + LineNumberOnBraceTarg.STOP_LINE_2);
+ resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.STOP_LINE_2);
+ System.out.println("Stopped at " + LineNumberOnBraceTarg.STOP_LINE_2);
stepev = stepOverLine(mainThread);
ln = stepev.location().lineNumber();
System.out.println("Debuggee is stopped at line " + ln);
- if (ln == LineNumberOnBraceTarg.stopLine2 + 1) {
- failure("FAIL: bug 4870514: Incorrectly stopped at " +
- (LineNumberOnBraceTarg.stopLine2 + 1));
+ if (ln <= LineNumberOnBraceTarg.STOP_LINE_2 + 1) {
+ failure("FAIL: bug 4870514: Incorrectly stopped at " + ln);
} else {
System.out.println("Passed test for 4870514");
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/com/sun/jdi/PopAndStepTest.java
--- a/jdk/test/com/sun/jdi/PopAndStepTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/com/sun/jdi/PopAndStepTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,17 +1,39 @@
-/* /nodynamiccopyright/ */ // DO NOT DELETE ANY LINES!!!!
-// THIS TEST IS LINE NUMBER SENSITIVE
-/**
- * @test
- * @bug 4530424
- * @summary Hin says that doing a step over after a popframe acts like a resume.
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
*
- * @author jjh
+ * 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.
+ */
+
+// THIS TEST IS LINE NUMBER SENSITIVE
+
+/**
+ * @test
+ * @bug 4530424
+ * @summary Hin says that doing a step over after a popframe acts like a resume.
+ * @author jjh
*
- * @library ..
- * @modules jdk.jdi
- * @run build TestScaffold VMConnection TargetListener TargetAdapter
- * @run compile -g PopAndStepTest.java
- * @run driver PopAndStepTest
+ * @library ..
+ *
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g PopAndStepTest.java
+ * @run driver PopAndStepTest
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
@@ -19,25 +41,23 @@
import java.util.*;
- /********** LINE NUMBER SENSITIVE! *****************************************************************/
-
class PopAndStepTarg {
public void B() {
- System.out.println("debuggee: in B");
- System.out.println("debuggee: in B, back to A"); // add line breakpoint here line 27 !!!
+ System.out.println("debuggee: in B"); // B_LINE_1
+ System.out.println("debuggee: in B, back to A"); // B_LINE_2
}
public void A() {
- System.out.println("debuggee: in A, about to call B"); // line 31
- B();
- System.out.println("debuggee: in A, back from B"); // line 33
- throw new RuntimeException("debuggee: Got to line 34");
+ System.out.println("debuggee: in A, about to call B"); // A_LINE_1
+ B(); // A_LINE_2
+ System.out.println("debuggee: in A, back from B"); // A_LINE_3
+ throw new RuntimeException("debuggee: Got to line A_LINE_4:" + PopAndStepTest.A_LINE_4); // A_LINE_4
}
public static void main(String[] args) {
- System.out.println("debuggee: Howdy!"); // line 38
- PopAndStepTarg xxx = new PopAndStepTarg(); // line 40
- xxx.A(); // line 41
+ System.out.println("debuggee: Howdy!"); // MAIN_LINE_1
+ PopAndStepTarg xxx = new PopAndStepTarg(); // MAIN_LINE_2
+ xxx.A(); // MAIN_LINE_3
System.out.println("debugee: Goodbye from PopAndStepTarg!");
}
}
@@ -46,6 +66,18 @@
/********** test program **********/
public class PopAndStepTest extends TestScaffold {
+ static final int B_LINE_1 = 46;
+ static final int B_LINE_2 = B_LINE_1 + 1;
+
+ static final int A_LINE_1 = 51;
+ static final int A_LINE_2 = A_LINE_1 + 1;
+ static final int A_LINE_3 = A_LINE_1 + 2;
+ static final int A_LINE_4 = A_LINE_1 + 3;
+
+ static final int MAIN_LINE_1 = 58;
+ static final int MAIN_LINE_2 = MAIN_LINE_1 + 1;
+ static final int MAIN_LINE_3 = MAIN_LINE_1 + 2;
+
ReferenceType targetClass;
ThreadReference mainThread;
@@ -116,10 +148,10 @@
BreakpointEvent bpe = startToMain("PopAndStepTarg");
targetClass = bpe.location().declaringType();
mainThread = bpe.thread();
- getDebuggeeLineNum(38);
+ getDebuggeeLineNum(MAIN_LINE_1);
- println("Resuming to line 27");
- bpe = resumeTo("PopAndStepTarg", 27); getDebuggeeLineNum(27);
+ println("Resuming to line B_LINE_2 : " + B_LINE_2);
+ bpe = resumeTo("PopAndStepTarg", B_LINE_2); getDebuggeeLineNum(B_LINE_2);
// The failure is this:
// create step request
@@ -141,21 +173,21 @@
srInto.enable(); // This fails
mainThread.popFrames(frameFor("A"));
//srInto.enable(); // if the enable is moved here, it passes
- println("Popped back to line 41 in main, the call to A()");
- println("Stepping into line 31");
- waitForRequestedEvent(srInto); // println
+ println("Popped back to line MAIN_LINE_3(" + MAIN_LINE_3 + ") in main, the call to A()");
+ println("Stepping into line A_LINE_1:" + A_LINE_1);
+ waitForRequestedEvent(srInto); // println
srInto.disable();
- getDebuggeeLineNum(31);
+ getDebuggeeLineNum(A_LINE_1);
// The failure occurs here.
- println("Stepping over to line 32");
- stepOverLine(mainThread); // println
- getDebuggeeLineNum(32);
+ println("Stepping over to line A_LINE_2:" + A_LINE_2);
+ stepOverLine(mainThread); // println
+ getDebuggeeLineNum(A_LINE_2);
- println("Stepping over to line 33");
- stepOverLine(mainThread); // call to B()
- getDebuggeeLineNum(33);
+ println("Stepping over to line A_LINE_3:" + A_LINE_3);
+ stepOverLine(mainThread); // call to B()
+ getDebuggeeLineNum(A_LINE_3);
vm().exit(0);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/awt/TrayIcon/SystemTrayIconHelper.java
--- a/jdk/test/java/awt/TrayIcon/SystemTrayIconHelper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/awt/TrayIcon/SystemTrayIconHelper.java Wed Jul 05 23:13:02 2017 +0200
@@ -81,7 +81,7 @@
try {
// sun.lwawt.macosx.CTrayIcon
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());
@@ -105,7 +105,7 @@
} else {
try {
// 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());
Field f_peer = getField(java.awt.TrayIcon.class, "peer");
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/awt/patchlib/java.desktop/java/awt/Helper.java
--- a/jdk/test/java/awt/patchlib/java.desktop/java/awt/Helper.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/awt/patchlib/java.desktop/java/awt/Helper.java Wed Jul 05 23:13:02 2017 +0200
@@ -22,7 +22,6 @@
*/
package java.awt;
-import java.lang.reflect.Module;
public class Helper {
private Helper() { }
public static void addExports(String pn, Module target) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/awt/regtesthelpers/Util.java
--- a/jdk/test/java/awt/regtesthelpers/Util.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/awt/regtesthelpers/Util.java Wed Jul 05 23:13:02 2017 +0200
@@ -445,7 +445,7 @@
try {
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.
// 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());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/GetModuleTest.java
--- a/jdk/test/java/lang/Class/GetModuleTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/GetModuleTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -31,7 +31,6 @@
*/
import java.awt.Component;
-import java.lang.reflect.Module;
import jdk.internal.org.objectweb.asm.ClassWriter;
import static jdk.internal.org.objectweb.asm.Opcodes.*;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/forName/modules/TestLayer.java
--- a/jdk/test/java/lang/Class/forName/modules/TestLayer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/forName/modules/TestLayer.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,9 +23,7 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
@@ -45,13 +43,13 @@
ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolveAndBind(ModuleFinder.of(),
finder,
modules);
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 m2 = layer.findModule("m2").get();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/forName/modules/TestMain.java
--- a/jdk/test/java/lang/Class/forName/modules/TestMain.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/forName/modules/TestMain.java Wed Jul 05 23:13:02 2017 +0200
@@ -21,13 +21,11 @@
* questions.
*/
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
public class TestMain {
public static void main(String[] args) throws Exception {
- Layer boot = Layer.boot();
+ ModuleLayer boot = ModuleLayer.boot();
Module m1 = boot.findModule("m1").get();
Module m2 = boot.findModule("m2").get();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/forName/modules/src/m2/p2/test/Main.java
--- a/jdk/test/java/lang/Class/forName/modules/src/m2/p2/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/forName/modules/src/m2/p2/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,12 +23,9 @@
package p2.test;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-
public class Main {
public static void main(String... args) throws Exception {
- Layer boot = Layer.boot();
+ ModuleLayer boot = ModuleLayer.boot();
Module m1 = boot.findModule("m1").get();
Module m2 = Main.class.getModule();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoAccess.java
--- a/jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,8 +26,6 @@
import java.io.FilePermission;
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessControlException;
@@ -47,7 +45,7 @@
ModuleFinder finder = ModuleFinder.of(Paths.get("mods1"), Paths.get("mods2"));
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration parent = bootLayer.configuration();
Configuration cf = parent.resolveAndBind(finder,
@@ -55,7 +53,7 @@
Set.of("m1", "m2"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithManyLoaders(cf, scl);
+ ModuleLayer layer = bootLayer.defineModulesWithManyLoaders(cf, scl);
if (sm != null) {
System.setSecurityManager(sm);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoGetClassLoaderAccess.java
--- a/jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoGetClassLoaderAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/forName/modules/src/m3/p3/NoGetClassLoaderAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,8 +23,6 @@
package p3;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.security.AccessControlException;
import java.security.Permission;
@@ -37,7 +35,7 @@
private static final Permission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader");
public static void main(String[] args) throws Exception {
- Layer boot = Layer.boot();
+ ModuleLayer boot = ModuleLayer.boot();
System.setSecurityManager(new SecurityManager());
Module m1 = boot.findModule("m1").get();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java
--- a/jdk/test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,10 +26,8 @@
import java.io.UncheckedIOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
-import java.lang.reflect.Module;
import java.lang.reflect.Modifier;
import java.lang.reflect.InaccessibleObjectException;
-import java.lang.reflect.Layer;
import java.lang.reflect.ReflectPermission;
import java.net.URI;
import java.nio.file.FileSystem;
@@ -269,7 +267,7 @@
try {
return Files.walk(root)
.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.toString())
.filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class"))
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/Class/getResource/Main.java
--- a/jdk/test/java/lang/Class/getResource/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/Class/getResource/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
import java.lang.module.Configuration;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -256,7 +255,7 @@
* Returns the directory for the given module (by name).
*/
static Path directoryFor(String name) {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule resolvedModule = cf.findModule(name).orElse(null);
if (resolvedModule == null)
throw new RuntimeException("not found: " + name);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ClassLoader/getResource/automaticmodules/Main.java
--- a/jdk/test/java/lang/ClassLoader/getResource/automaticmodules/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/ClassLoader/getResource/automaticmodules/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.net.URL;
import java.util.Enumeration;
@@ -74,7 +73,7 @@
public static void main(String[] args) throws Exception {
String mn = args[0];
- ModuleReference mref = Layer.boot()
+ ModuleReference mref = ModuleLayer.boot()
.configuration()
.findModule(mn)
.map(ResolvedModule::reference)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ClassLoader/getResource/modules/Main.java
--- a/jdk/test/java/lang/ClassLoader/getResource/modules/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/ClassLoader/getResource/modules/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
import java.io.InputStream;
import java.lang.module.Configuration;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
@@ -309,7 +308,7 @@
* Returns the directory for the given module (by name).
*/
static Path directoryFor(String mn) {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule resolvedModule = cf.findModule(mn).orElse(null);
if (resolvedModule == null)
throw new RuntimeException("not found: " + mn);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/BasicLayerTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/BasicLayerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,1213 @@
+/*
+ * Copyright (c) 2014, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library /lib/testlibrary
+ * @modules java.base/jdk.internal.misc
+ * @build BasicLayerTest ModuleUtils
+ * @compile layertest/Test.java
+ * @run testng BasicLayerTest
+ * @summary Basic tests for java.lang.ModuleLayer
+ */
+
+import java.lang.module.Configuration;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Requires;
+import java.lang.module.ModuleFinder;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import jdk.internal.misc.SharedSecrets;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+@Test
+public class BasicLayerTest {
+
+ /**
+ * Creates a "non-strict" builder for building a module. This allows the
+ * test the create ModuleDescriptor objects that do not require java.base.
+ */
+ private static ModuleDescriptor.Builder newBuilder(String mn) {
+ return SharedSecrets.getJavaLangModuleAccess()
+ .newModuleBuilder(mn, false, Set.of());
+ }
+
+ /**
+ * Exercise ModuleLayer.empty()
+ */
+ public void testEmpty() {
+ ModuleLayer emptyLayer = ModuleLayer.empty();
+
+ assertTrue(emptyLayer.parents().isEmpty());
+
+ assertTrue(emptyLayer.configuration() == Configuration.empty());
+
+ assertTrue(emptyLayer.modules().isEmpty());
+
+ assertFalse(emptyLayer.findModule("java.base").isPresent());
+
+ try {
+ emptyLayer.findLoader("java.base");
+ assertTrue(false);
+ } catch (IllegalArgumentException expected) { }
+ }
+
+
+ /**
+ * Exercise ModuleLayer.boot()
+ */
+ public void testBoot() {
+ ModuleLayer bootLayer = ModuleLayer.boot();
+
+ // configuration
+ Configuration cf = bootLayer.configuration();
+ assertTrue(cf.findModule("java.base").get()
+ .reference()
+ .descriptor()
+ .exports()
+ .stream().anyMatch(e -> (e.source().equals("java.lang")
+ && !e.isQualified())));
+
+ // modules
+ Set modules = bootLayer.modules();
+ assertTrue(modules.contains(Object.class.getModule()));
+ int count = (int) modules.stream().map(Module::getName).count();
+ assertEquals(count, modules.size()); // module names are unique
+
+ // findModule
+ Module base = Object.class.getModule();
+ assertTrue(bootLayer.findModule("java.base").get() == base);
+ assertTrue(base.getLayer() == bootLayer);
+
+ // findLoader
+ assertTrue(bootLayer.findLoader("java.base") == null);
+
+ // parents
+ assertTrue(bootLayer.parents().size() == 1);
+ assertTrue(bootLayer.parents().get(0) == ModuleLayer.empty());
+ }
+
+
+ /**
+ * Exercise defineModules, created with empty layer as parent
+ */
+ public void testLayerOnEmpty() {
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .requires("m2")
+ .exports("p1")
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires("m3")
+ .build();
+
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .build();
+
+ ModuleFinder finder
+ = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);
+
+ Configuration cf = resolve(finder, "m1");
+
+ // map each module to its own class loader for this test
+ ClassLoader loader1 = new ClassLoader() { };
+ ClassLoader loader2 = new ClassLoader() { };
+ ClassLoader loader3 = new ClassLoader() { };
+ Map map = new HashMap<>();
+ map.put("m1", loader1);
+ map.put("m2", loader2);
+ map.put("m3", loader3);
+
+ ModuleLayer layer = ModuleLayer.empty().defineModules(cf, map::get);
+
+ // configuration
+ assertTrue(layer.configuration() == cf);
+ assertTrue(layer.configuration().modules().size() == 3);
+
+ // modules
+ Set modules = layer.modules();
+ assertTrue(modules.size() == 3);
+ Set names = modules.stream()
+ .map(Module::getName)
+ .collect(Collectors.toSet());
+ assertTrue(names.contains("m1"));
+ assertTrue(names.contains("m2"));
+ assertTrue(names.contains("m3"));
+
+ // findModule
+ Module m1 = layer.findModule("m1").get();
+ Module m2 = layer.findModule("m2").get();
+ Module m3 = layer.findModule("m3").get();
+ assertEquals(m1.getName(), "m1");
+ assertEquals(m2.getName(), "m2");
+ assertEquals(m3.getName(), "m3");
+ assertTrue(m1.getDescriptor() == descriptor1);
+ assertTrue(m2.getDescriptor() == descriptor2);
+ assertTrue(m3.getDescriptor() == descriptor3);
+ assertTrue(m1.getLayer() == layer);
+ assertTrue(m2.getLayer() == layer);
+ assertTrue(m3.getLayer() == layer);
+ assertTrue(modules.contains(m1));
+ assertTrue(modules.contains(m2));
+ assertTrue(modules.contains(m3));
+ assertFalse(layer.findModule("godot").isPresent());
+
+ // findLoader
+ assertTrue(layer.findLoader("m1") == loader1);
+ assertTrue(layer.findLoader("m2") == loader2);
+ assertTrue(layer.findLoader("m3") == loader3);
+ try {
+ ClassLoader loader = layer.findLoader("godot");
+ assertTrue(false);
+ } catch (IllegalArgumentException ignore) { }
+
+ // parents
+ assertTrue(layer.parents().size() == 1);
+ assertTrue(layer.parents().get(0) == ModuleLayer.empty());
+ }
+
+
+ /**
+ * Exercise defineModules, created with boot layer as parent
+ */
+ public void testLayerOnBoot() {
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .requires("m2")
+ .requires("java.base")
+ .exports("p1")
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires("java.base")
+ .build();
+
+ ModuleFinder finder
+ = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = resolve(parent, finder, "m1");
+
+ ClassLoader loader = new ClassLoader() { };
+
+ ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
+
+ // configuration
+ assertTrue(layer.configuration() == cf);
+ assertTrue(layer.configuration().modules().size() == 2);
+
+ // modules
+ Set modules = layer.modules();
+ assertTrue(modules.size() == 2);
+ Set names = modules.stream()
+ .map(Module::getName)
+ .collect(Collectors.toSet());
+ assertTrue(names.contains("m1"));
+ assertTrue(names.contains("m2"));
+
+ // findModule
+ Module m1 = layer.findModule("m1").get();
+ Module m2 = layer.findModule("m2").get();
+ assertEquals(m1.getName(), "m1");
+ assertEquals(m2.getName(), "m2");
+ assertTrue(m1.getDescriptor() == descriptor1);
+ assertTrue(m2.getDescriptor() == descriptor2);
+ assertTrue(m1.getLayer() == layer);
+ assertTrue(m2.getLayer() == layer);
+ assertTrue(modules.contains(m1));
+ assertTrue(modules.contains(m2));
+ assertTrue(layer.findModule("java.base").get() == Object.class.getModule());
+ assertFalse(layer.findModule("godot").isPresent());
+
+ // findLoader
+ assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m2") == loader);
+ assertTrue(layer.findLoader("java.base") == null);
+
+ // parents
+ assertTrue(layer.parents().size() == 1);
+ assertTrue(layer.parents().get(0) == ModuleLayer.boot());
+ }
+
+
+ /**
+ * Exercise defineModules with a configuration of two modules that
+ * have the same module-private package.
+ */
+ public void testPackageContainedInSelfAndOther() {
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .requires("m2")
+ .packages(Set.of("p"))
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .packages(Set.of("p"))
+ .build();
+
+ ModuleFinder finder
+ = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf = resolve(finder, "m1");
+ assertTrue(cf.modules().size() == 2);
+
+ // one loader per module, should be okay
+ ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
+
+ // same class loader
+ try {
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer.empty().defineModules(cf, mn -> loader);
+ assertTrue(false);
+ } catch (LayerInstantiationException expected) { }
+ }
+
+
+ /**
+ * Exercise defineModules with a configuration that is a partitioned
+ * graph. The same package is exported in both partitions.
+ */
+ public void testSameExportInPartitionedGraph() {
+
+ // m1 reads m2, m2 exports p to m1
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .requires("m2")
+ .build();
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .exports("p", Set.of("m1"))
+ .build();
+
+ // m3 reads m4, m4 exports p to m3
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires("m4")
+ .build();
+ ModuleDescriptor descriptor4 = newBuilder("m4")
+ .exports("p", Set.of("m3"))
+ .build();
+
+ ModuleFinder finder
+ = ModuleUtils.finderOf(descriptor1,
+ descriptor2,
+ descriptor3,
+ descriptor4);
+
+ Configuration cf = resolve(finder, "m1", "m3");
+ assertTrue(cf.modules().size() == 4);
+
+ // one loader per module
+ ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
+
+ // m1 & m2 in one loader, m3 & m4 in another loader
+ ClassLoader loader1 = new ClassLoader() { };
+ ClassLoader loader2 = new ClassLoader() { };
+ Map map = new HashMap<>();
+ map.put("m1", loader1);
+ map.put("m2", loader1);
+ map.put("m3", loader2);
+ map.put("m4", loader2);
+ ModuleLayer.empty().defineModules(cf, map::get);
+
+ // same loader
+ try {
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer.empty().defineModules(cf, mn -> loader);
+ assertTrue(false);
+ } catch (LayerInstantiationException expected) { }
+ }
+
+
+ /**
+ * Exercise defineModules with a configuration with a module that
+ * contains a package that is the same name as a non-exported package in
+ * a parent layer.
+ */
+ public void testContainsSamePackageAsBootLayer() {
+
+ // check assumption that java.base contains sun.launcher
+ ModuleDescriptor base = Object.class.getModule().getDescriptor();
+ assertTrue(base.packages().contains("sun.launcher"));
+
+ ModuleDescriptor descriptor = newBuilder("m1")
+ .requires("java.base")
+ .packages(Set.of("sun.launcher"))
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
+ assertTrue(cf.modules().size() == 1);
+
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
+ assertTrue(layer.modules().size() == 1);
+ }
+
+
+ /**
+ * Test layers with implied readability.
+ *
+ * The test consists of three configurations:
+ * - Configuration/layer1: m1, m2 requires transitive m1
+ * - Configuration/layer2: m3 requires m1
+ */
+ public void testImpliedReadabilityWithLayers1() {
+
+ // cf1: m1 and m2, m2 requires transitive m1
+
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
+ .build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf1 = resolve(finder1, "m2");
+
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+
+
+ // cf2: m3, m3 requires m2
+
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires("m2")
+ .build();
+
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3);
+
+ Configuration cf2 = resolve(cf1, finder2, "m3");
+
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+
+ assertTrue(layer1.parents().size() == 1);
+ assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
+
+ assertTrue(layer2.parents().size() == 1);
+ assertTrue(layer2.parents().get(0) == layer1);
+
+ Module m1 = layer2.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+ Module m3 = layer2.findModule("m3").get();
+
+ assertTrue(m1.getLayer() == layer1);
+ assertTrue(m2.getLayer() == layer1);
+ assertTrue(m3.getLayer() == layer2);
+
+ assertTrue(m1.getClassLoader() == cl1);
+ assertTrue(m2.getClassLoader() == cl1);
+ assertTrue(m3.getClassLoader() == cl2);
+
+ assertTrue(m1.canRead(m1));
+ assertFalse(m1.canRead(m2));
+ assertFalse(m1.canRead(m3));
+
+ assertTrue(m2.canRead(m1));
+ assertTrue(m2.canRead(m2));
+ assertFalse(m2.canRead(m3));
+
+ assertTrue(m3.canRead(m1));
+ assertTrue(m3.canRead(m2));
+ assertTrue(m3.canRead(m3));
+ }
+
+
+ /**
+ * Test layers with implied readability.
+ *
+ * The test consists of three configurations:
+ * - Configuration/layer1: m1
+ * - Configuration/layer2: m2 requires transitive m3, m3 requires m2
+ */
+ public void testImpliedReadabilityWithLayers2() {
+
+ // cf1: m1
+
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+
+ Configuration cf1 = resolve(finder1, "m1");
+
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+
+
+ // cf2: m2, m3: m2 requires transitive m1, m3 requires m2
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
+ .build();
+
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires("m2")
+ .build();
+
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2, descriptor3);
+
+ Configuration cf2 = resolve(cf1, finder2, "m3");
+
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+
+ assertTrue(layer1.parents().size() == 1);
+ assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
+
+ assertTrue(layer2.parents().size() == 1);
+ assertTrue(layer2.parents().get(0) == layer1);
+
+ Module m1 = layer2.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+ Module m3 = layer2.findModule("m3").get();
+
+ assertTrue(m1.getLayer() == layer1);
+ assertTrue(m2.getLayer() == layer2);
+ assertTrue(m3.getLayer() == layer2);
+
+ assertTrue(m1.canRead(m1));
+ assertFalse(m1.canRead(m2));
+ assertFalse(m1.canRead(m3));
+
+ assertTrue(m2.canRead(m1));
+ assertTrue(m2.canRead(m2));
+ assertFalse(m2.canRead(m3));
+
+ assertTrue(m3.canRead(m1));
+ assertTrue(m3.canRead(m2));
+ assertTrue(m3.canRead(m3));
+ }
+
+
+ /**
+ * Test layers with implied readability.
+ *
+ * The test consists of three configurations:
+ * - Configuration/layer1: m1
+ * - Configuration/layer2: m2 requires transitive m1
+ * - Configuration/layer3: m3 requires m1
+ */
+ public void testImpliedReadabilityWithLayers3() {
+
+ // cf1: m1
+
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+
+ Configuration cf1 = resolve(finder1, "m1");
+
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+
+
+ // cf2: m2 requires transitive m1
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
+ .build();
+
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
+
+ Configuration cf2 = resolve(cf1, finder2, "m2");
+
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+
+
+ // cf3: m3 requires m2
+
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires("m2")
+ .build();
+
+ ModuleFinder finder3 = ModuleUtils.finderOf(descriptor3);
+
+ Configuration cf3 = resolve(cf2, finder3, "m3");
+
+ ClassLoader cl3 = new ClassLoader() { };
+ ModuleLayer layer3 = layer2.defineModules(cf3, mn -> cl3);
+
+ assertTrue(layer1.parents().size() == 1);
+ assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
+
+ assertTrue(layer2.parents().size() == 1);
+ assertTrue(layer2.parents().get(0) == layer1);
+
+ assertTrue(layer3.parents().size() == 1);
+ assertTrue(layer3.parents().get(0) == layer2);
+
+ Module m1 = layer3.findModule("m1").get();
+ Module m2 = layer3.findModule("m2").get();
+ Module m3 = layer3.findModule("m3").get();
+
+ assertTrue(m1.getLayer() == layer1);
+ assertTrue(m2.getLayer() == layer2);
+ assertTrue(m3.getLayer() == layer3);
+
+ assertTrue(m1.canRead(m1));
+ assertFalse(m1.canRead(m2));
+ assertFalse(m1.canRead(m3));
+
+ assertTrue(m2.canRead(m1));
+ assertTrue(m2.canRead(m2));
+ assertFalse(m2.canRead(m3));
+
+ assertTrue(m3.canRead(m1));
+ assertTrue(m3.canRead(m2));
+ assertTrue(m3.canRead(m3));
+ }
+
+
+ /**
+ * Test layers with implied readability.
+ *
+ * The test consists of two configurations:
+ * - Configuration/layer1: m1, m2 requires transitive m1
+ * - Configuration/layer2: m3 requires transitive m2, m4 requires m3
+ */
+ public void testImpliedReadabilityWithLayers4() {
+
+ // cf1: m1, m2 requires transitive m1
+
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
+ .build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf1 = resolve(finder1, "m2");
+
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+
+
+ // cf2: m3 requires transitive m2, m4 requires m3
+
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m2")
+ .build();
+
+ ModuleDescriptor descriptor4 = newBuilder("m4")
+ .requires("m3")
+ .build();
+
+
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4);
+
+ Configuration cf2 = resolve(cf1, finder2, "m3", "m4");
+
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+
+ assertTrue(layer1.parents().size() == 1);
+ assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
+
+ assertTrue(layer2.parents().size() == 1);
+ assertTrue(layer2.parents().get(0) == layer1);
+
+ Module m1 = layer2.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+ Module m3 = layer2.findModule("m3").get();
+ Module m4 = layer2.findModule("m4").get();
+
+ assertTrue(m1.getLayer() == layer1);
+ assertTrue(m2.getLayer() == layer1);
+ assertTrue(m3.getLayer() == layer2);
+ assertTrue(m4.getLayer() == layer2);
+
+ assertTrue(m1.canRead(m1));
+ assertFalse(m1.canRead(m2));
+ assertFalse(m1.canRead(m3));
+ assertFalse(m1.canRead(m4));
+
+ assertTrue(m2.canRead(m1));
+ assertTrue(m2.canRead(m2));
+ assertFalse(m1.canRead(m3));
+ assertFalse(m1.canRead(m4));
+
+ assertTrue(m3.canRead(m1));
+ assertTrue(m3.canRead(m2));
+ assertTrue(m3.canRead(m3));
+ assertFalse(m3.canRead(m4));
+
+ assertTrue(m4.canRead(m1));
+ assertTrue(m4.canRead(m2));
+ assertTrue(m4.canRead(m3));
+ assertTrue(m4.canRead(m4));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * does not read the target module.
+ *
+ * m1 { exports p to m2 }
+ * m2 { }
+ */
+ public void testQualifiedExports1() {
+ ModuleDescriptor descriptor1 = newBuilder("m1").
+ exports("p", Set.of("m2"))
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf = resolve(finder1, "m1", "m2");
+
+ ClassLoader cl = new ClassLoader() { };
+ ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
+ assertTrue(layer.modules().size() == 2);
+
+ Module m1 = layer.findModule("m1").get();
+ Module m2 = layer.findModule("m2").get();
+
+ // check m1 exports p to m2
+ assertFalse(m1.isExported("p"));
+ assertTrue(m1.isExported("p", m2));
+ assertFalse(m1.isOpen("p", m2));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * reads the target module.
+ *
+ * m1 { exports p to m2; }
+ * m2 { requires m1; }
+ */
+ public void testQualifiedExports2() {
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .exports("p", Set.of("m2"))
+ .build();
+
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires("m1")
+ .build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf = resolve(finder1, "m2");
+ ClassLoader cl = new ClassLoader() { };
+ ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
+ assertTrue(layer.modules().size() == 2);
+
+ Module m1 = layer.findModule("m1").get();
+ Module m2 = layer.findModule("m2").get();
+
+ // check m1 exports p to m2
+ assertFalse(m1.isExported("p"));
+ assertTrue(m1.isExported("p", m2));
+ assertFalse(m1.isOpen("p", m2));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * does not read the target module in the parent layer.
+ *
+ * - Configuration/layer1: m1 { }
+ * - Configuration/layer2: m2 { exports p to m1; }
+ */
+ public void testQualifiedExports3() {
+ // create layer1 with m1
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ Configuration cf1 = resolve(finder1, "m1");
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+ assertTrue(layer1.modules().size() == 1);
+
+ // create layer2 with m2
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .exports("p", Set.of("m1"))
+ .build();
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
+ Configuration cf2 = resolve(cf1, finder2, "m2");
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+ assertTrue(layer2.modules().size() == 1);
+
+ Module m1 = layer1.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+
+ // check m2 exports p to layer1/m1
+ assertFalse(m2.isExported("p"));
+ assertTrue(m2.isExported("p", m1));
+ assertFalse(m2.isOpen("p", m1));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * reads the target module in the parent layer.
+ *
+ * - Configuration/layer1: m1 { }
+ * - Configuration/layer2: m2 { requires m1; exports p to m1; }
+ */
+ public void testQualifiedExports4() {
+ // create layer1 with m1
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ Configuration cf1 = resolve(finder1, "m1");
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+ assertTrue(layer1.modules().size() == 1);
+
+ // create layer2 with m2
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires("m1")
+ .exports("p", Set.of("m1"))
+ .build();
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
+ Configuration cf2 = resolve(cf1, finder2, "m2");
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+ assertTrue(layer2.modules().size() == 1);
+
+ Module m1 = layer1.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+
+ // check m2 exports p to layer1/m1
+ assertFalse(m2.isExported("p"));
+ assertTrue(m2.isExported("p", m1));
+ assertFalse(m2.isOpen("p", m1));
+ }
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * does not read the target module.
+ *
+ * - Configuration/layer1: m1
+ * - Configuration/layer2: m1, m2 { exports p to m1; }
+ */
+ public void testQualifiedExports5() {
+ // create layer1 with m1
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ Configuration cf1 = resolve(finder1, "m1");
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+ assertTrue(layer1.modules().size() == 1);
+
+ // create layer2 with m1 and m2
+ ModuleDescriptor descriptor2 = newBuilder("m2").exports("p", Set.of("m1")).build();
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor2);
+ Configuration cf2 = resolve(cf1, finder2, "m1", "m2");
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+ assertTrue(layer2.modules().size() == 2);
+
+ Module m1_v1 = layer1.findModule("m1").get();
+ Module m1_v2 = layer2.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+
+ // check m2 exports p to layer2/m2
+ assertFalse(m2.isExported("p"));
+ assertTrue(m2.isExported("p", m1_v2));
+ assertFalse(m2.isExported("p", m1_v1));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The module exporting the package
+ * reads the target module in the parent layer (due to requires transitive).
+ *
+ * - Configuration/layer1: m1, m2 { requires transitive m1; }
+ * - Configuration/layer2: m1, m3 { requires m2; exports p to m1; }
+ */
+ public void testQualifiedExports6() {
+ // create layer1 with m1 and m2
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
+ .build();
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+ Configuration cf1 = resolve(finder1, "m2");
+ ClassLoader loader1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> loader1);
+ assertTrue(layer1.modules().size() == 2);
+
+ // create layer2 with m1 and m3
+ ModuleDescriptor descriptor3 = newBuilder("m3")
+ .requires("m2")
+ .exports("p", Set.of("m1"))
+ .build();
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3);
+ Configuration cf2 = resolve(cf1, finder2, "m1", "m3");
+ ClassLoader loader2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> loader2);
+ assertTrue(layer2.modules().size() == 2);
+
+ Module m1_v1 = layer1.findModule("m1").get();
+ Module m2 = layer1.findModule("m2").get();
+
+ Module m1_v2 = layer2.findModule("m1").get();
+ Module m3 = layer2.findModule("m3").get();
+
+ assertTrue(m3.canRead(m1_v1));
+ assertFalse(m3.canRead(m1_v2));
+
+ assertFalse(m3.isExported("p"));
+ assertTrue(m3.isExported("p", m1_v1));
+ assertFalse(m3.isExported("p", m1_v2));
+ assertFalse(m3.isExported("p", m2));
+ }
+
+
+ /**
+ * Test layers with a qualified export. The target module is not in any layer.
+ *
+ * - Configuration/layer1: m1 { }
+ * - Configuration/layer2: m2 { exports p to m3; }
+ */
+ public void testQualifiedExports7() {
+ // create layer1 with m1
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ Configuration cf1 = resolve(finder1, "m1");
+ ClassLoader cl1 = new ClassLoader() { };
+ ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
+ assertTrue(layer1.modules().size() == 1);
+
+ // create layer2 with m2
+ ModuleDescriptor descriptor2 = newBuilder("m2")
+ .exports("p", Set.of("m3"))
+ .build();
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
+ Configuration cf2 = resolve(cf1, finder2, "m2");
+ ClassLoader cl2 = new ClassLoader() { };
+ ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
+ assertTrue(layer2.modules().size() == 1);
+
+ Module m1 = layer1.findModule("m1").get();
+ Module m2 = layer2.findModule("m2").get();
+
+ // check m2 does not export p to anyone
+ assertFalse(m2.isExported("p"));
+ assertFalse(m2.isExported("p", m1));
+ }
+
+ /**
+ * Attempt to use defineModules to create a layer with a module defined
+ * to a class loader that already has a module of the same name defined
+ * to the class loader.
+ */
+ @Test(expectedExceptions = { LayerInstantiationException.class })
+ public void testModuleAlreadyDefinedToLoader() {
+
+ ModuleDescriptor md = newBuilder("m")
+ .requires("java.base")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(md);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+
+ Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
+
+ ClassLoader loader = new ClassLoader() { };
+
+ ModuleLayer.boot().defineModules(cf, mn -> loader);
+
+ // should throw LayerInstantiationException as m1 already defined to loader
+ ModuleLayer.boot().defineModules(cf, mn -> loader);
+
+ }
+
+
+ /**
+ * Attempt to use defineModules to create a layer with a module containing
+ * package {@code p} where the class loader already has a module defined
+ * to it containing package {@code p}.
+ */
+ @Test(expectedExceptions = { LayerInstantiationException.class })
+ public void testPackageAlreadyInNamedModule() {
+
+ ModuleDescriptor md1 = newBuilder("m1")
+ .packages(Set.of("p"))
+ .requires("java.base")
+ .build();
+
+ ModuleDescriptor md2 = newBuilder("m2")
+ .packages(Set.of("p"))
+ .requires("java.base")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(md1, md2);
+
+ ClassLoader loader = new ClassLoader() { };
+
+ // define m1 containing package p to class loader
+
+ Configuration parent = ModuleLayer.boot().configuration();
+
+ Configuration cf1 = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModules(cf1, mn -> loader);
+
+ // attempt to define m2 containing package p to class loader
+
+ Configuration cf2 = parent.resolve(finder, ModuleFinder.of(), Set.of("m2"));
+
+ // should throw exception because p already in m1
+ ModuleLayer layer2 = ModuleLayer.boot().defineModules(cf2, mn -> loader);
+
+ }
+
+
+ /**
+ * Attempt to use defineModules to create a layer with a module
+ * containing a package in which a type is already loaded by the class
+ * loader.
+ */
+ @Test(expectedExceptions = { LayerInstantiationException.class })
+ public void testPackageAlreadyInUnnamedModule() throws Exception {
+
+ Class> c = layertest.Test.class;
+ assertFalse(c.getModule().isNamed()); // in unnamed module
+
+ ModuleDescriptor md = newBuilder("m")
+ .packages(Set.of(c.getPackageName()))
+ .requires("java.base")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(md);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
+
+ ModuleLayer.boot().defineModules(cf, mn -> c.getClassLoader());
+ }
+
+
+ /**
+ * Attempt to create a layer with a module named "java.base".
+ */
+ public void testLayerWithJavaBase() {
+ ModuleDescriptor descriptor = newBuilder("java.base")
+ .exports("java.lang")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor);
+
+ Configuration cf = ModuleLayer.boot()
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of("java.base"));
+ assertTrue(cf.modules().size() == 1);
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ try {
+ ModuleLayer.boot().defineModules(cf, mn -> new ClassLoader() { });
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+
+ try {
+ ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+
+ try {
+ ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+ }
+
+
+ @DataProvider(name = "javaPackages")
+ public Object[][] javaPackages() {
+ return new Object[][] { { "m1", "java" }, { "m2", "java.x" } };
+ }
+
+ /**
+ * 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
+ * class loader.
+ */
+ @Test(dataProvider = "javaPackages")
+ public void testLayerWithJavaPackage(String mn, String pn) {
+ ModuleDescriptor descriptor = newBuilder(mn).packages(Set.of(pn)).build();
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor);
+
+ Configuration cf = ModuleLayer.boot()
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of(mn));
+ assertTrue(cf.modules().size() == 1);
+
+ ClassLoader pcl = ClassLoader.getPlatformClassLoader();
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ try {
+ ModuleLayer.boot().defineModules(cf, _mn -> new ClassLoader() { });
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+
+ try {
+ ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+
+ try {
+ ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
+ assertTrue(false);
+ } catch (LayerInstantiationException e) { }
+
+ // create layer with module defined to platform class loader
+ ModuleLayer layer = ModuleLayer.boot().defineModules(cf, _mn -> pcl);
+ Optional om = layer.findModule(mn);
+ assertTrue(om.isPresent());
+ Module foo = om.get();
+ assertTrue(foo.getClassLoader() == pcl);
+ assertTrue(foo.getPackages().size() == 1);
+ assertTrue(foo.getPackages().iterator().next().equals(pn));
+ }
+
+
+ /**
+ * Attempt to create a layer with a module defined to the boot loader
+ */
+ @Test(expectedExceptions = { LayerInstantiationException.class })
+ public void testLayerWithBootLoader() {
+ ModuleDescriptor descriptor = newBuilder("m1")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor);
+
+ Configuration cf = ModuleLayer.boot()
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of("m1"));
+ assertTrue(cf.modules().size() == 1);
+
+ ModuleLayer.boot().defineModules(cf, mn -> null );
+ }
+
+
+ /**
+ * Parent of configuration != configuration of parent layer
+ */
+ @Test(expectedExceptions = { IllegalArgumentException.class })
+ public void testIncorrectParent1() {
+ ModuleDescriptor descriptor1 = newBuilder("m1")
+ .requires("java.base")
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
+
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer.empty().defineModules(cf, mn -> loader);
+ }
+
+
+ /**
+ * Parent of configuration != configuration of parent layer
+ */
+ @Test(expectedExceptions = { IllegalArgumentException.class })
+ public void testIncorrectParent2() {
+ ModuleDescriptor descriptor1 = newBuilder("m1").build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
+
+ Configuration cf = resolve(finder, "m1");
+
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer.boot().defineModules(cf, mn -> loader);
+ }
+
+
+ // null handling
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testCreateWithNull1() {
+ ClassLoader loader = new ClassLoader() { };
+ ModuleLayer.empty().defineModules(null, mn -> loader);
+ }
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testCreateWithNull2() {
+ Configuration cf = resolve(ModuleLayer.boot().configuration(), ModuleFinder.of());
+ ModuleLayer.boot().defineModules(cf, null);
+ }
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testCreateWithNull3() {
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ModuleLayer.empty().defineModulesWithOneLoader(null, scl);
+ }
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testCreateWithNull4() {
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ModuleLayer.empty().defineModulesWithManyLoaders(null, scl);
+ }
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testFindModuleWithNull() {
+ ModuleLayer.boot().findModule(null);
+ }
+
+ @Test(expectedExceptions = { NullPointerException.class })
+ public void testFindLoaderWithNull() {
+ ModuleLayer.boot().findLoader(null);
+ }
+
+
+ // immutable sets
+
+ @Test(expectedExceptions = { UnsupportedOperationException.class })
+ public void testImmutableSet() {
+ Module base = Object.class.getModule();
+ ModuleLayer.boot().modules().add(base);
+ }
+
+
+ /**
+ * Resolve the given modules, by name, and returns the resulting
+ * Configuration.
+ */
+ private static Configuration resolve(Configuration cf,
+ ModuleFinder finder,
+ String... roots) {
+ return cf.resolve(finder, ModuleFinder.of(), Set.of(roots));
+ }
+
+ private static Configuration resolve(ModuleFinder finder,
+ String... roots) {
+ return resolve(Configuration.empty(), finder, roots);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/LayerAndLoadersTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/LayerAndLoadersTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,721 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library /lib/testlibrary
+ * @modules jdk.compiler
+ * @build LayerAndLoadersTest CompilerUtils ModuleUtils
+ * @run testng LayerAndLoadersTest
+ * @summary Tests for java.lang.ModuleLayer@defineModulesWithXXX methods
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.module.Configuration;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+@Test
+public class LayerAndLoadersTest {
+
+ private static final String TEST_SRC = System.getProperty("test.src");
+
+ private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
+ private static final Path MODS_DIR = Paths.get("mods");
+
+ @BeforeTest
+ public void setup() throws Exception {
+
+ // javac -d mods --module-source-path src src/**
+ assertTrue(CompilerUtils.compile(SRC_DIR, MODS_DIR,
+ "--module-source-path", SRC_DIR.toString()));
+ }
+
+
+ /**
+ * Basic test of ModuleLayer.defineModulesWithOneLoader
+ *
+ * Test scenario:
+ * m1 requires m2 and m3
+ */
+ public void testWithOneLoader() throws Exception {
+
+ Configuration cf = resolve("m1");
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
+
+ checkLayer(layer, "m1", "m2", "m3");
+
+ ClassLoader cl1 = layer.findLoader("m1");
+ ClassLoader cl2 = layer.findLoader("m2");
+ ClassLoader cl3 = layer.findLoader("m3");
+
+ assertTrue(cl1.getParent() == scl);
+ assertTrue(cl2 == cl1);
+ assertTrue(cl3 == cl1);
+
+ invoke(layer, "m1", "p.Main");
+
+ }
+
+
+ /**
+ * Basic test of ModuleLayer.defineModulesWithManyLoaders
+ *
+ * Test scenario:
+ * m1 requires m2 and m3
+ */
+ public void testWithManyLoaders() throws Exception {
+
+ Configuration cf = resolve("m1");
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
+
+ checkLayer(layer, "m1", "m2", "m3");
+
+ ClassLoader cl1 = layer.findLoader("m1");
+ ClassLoader cl2 = layer.findLoader("m2");
+ ClassLoader cl3 = layer.findLoader("m3");
+
+ assertTrue(cl1.getParent() == scl);
+ assertTrue(cl2.getParent() == scl);
+ assertTrue(cl3.getParent() == scl);
+ assertTrue(cl2 != cl1);
+ assertTrue(cl3 != cl1);
+ assertTrue(cl3 != cl2);
+
+ invoke(layer, "m1", "p.Main");
+
+ }
+
+
+ /**
+ * Basic test of ModuleLayer.defineModulesWithOneLoader where one of the
+ * modules is a service provider module.
+ *
+ * Test scenario:
+ * m1 requires m2 and m3
+ * m1 uses S
+ * m4 provides S with ...
+ */
+ public void testServicesWithOneLoader() throws Exception {
+
+ Configuration cf = resolveAndBind("m1");
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
+
+ checkLayer(layer, "m1", "m2", "m3", "m4");
+
+ ClassLoader cl1 = layer.findLoader("m1");
+ ClassLoader cl2 = layer.findLoader("m2");
+ ClassLoader cl3 = layer.findLoader("m3");
+ ClassLoader cl4 = layer.findLoader("m4");
+
+ assertTrue(cl1.getParent() == scl);
+ assertTrue(cl2 == cl1);
+ assertTrue(cl3 == cl1);
+ assertTrue(cl4 == cl1);
+
+ Class> serviceType = cl1.loadClass("p.Service");
+ assertTrue(serviceType.getClassLoader() == cl1);
+
+ Iterator> iter = ServiceLoader.load(serviceType, cl1).iterator();
+ Object provider = iter.next();
+ assertTrue(serviceType.isInstance(provider));
+ assertTrue(provider.getClass().getClassLoader() == cl1);
+ assertFalse(iter.hasNext());
+
+ }
+
+
+ /**
+ * Basic test of ModuleLayer.defineModulesWithManyLoaders where one of the
+ * modules is a service provider module.
+ *
+ * Test scenario:
+ * m1 requires m2 and m3
+ * m1 uses S
+ * m4 provides S with ...
+ */
+ public void testServicesWithManyLoaders() throws Exception {
+
+ Configuration cf = resolveAndBind("m1");
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
+
+ checkLayer(layer, "m1", "m2", "m3", "m4");
+
+ ClassLoader cl1 = layer.findLoader("m1");
+ ClassLoader cl2 = layer.findLoader("m2");
+ ClassLoader cl3 = layer.findLoader("m3");
+ ClassLoader cl4 = layer.findLoader("m4");
+
+ assertTrue(cl1.getParent() == scl);
+ assertTrue(cl2.getParent() == scl);
+ assertTrue(cl3.getParent() == scl);
+ assertTrue(cl4.getParent() == scl);
+ assertTrue(cl2 != cl1);
+ assertTrue(cl3 != cl1);
+ assertTrue(cl3 != cl2);
+ assertTrue(cl4 != cl1);
+ assertTrue(cl4 != cl2);
+ assertTrue(cl4 != cl3);
+
+ Class> serviceType = cl1.loadClass("p.Service");
+ assertTrue(serviceType.getClassLoader() == cl1);
+
+ // Test that the service provider can be located via any of
+ // the class loaders in the layer
+ for (Module m : layer.modules()) {
+ ClassLoader loader = m.getClassLoader();
+ Iterator> iter = ServiceLoader.load(serviceType, loader).iterator();
+ Object provider = iter.next();
+ assertTrue(serviceType.isInstance(provider));
+ assertTrue(provider.getClass().getClassLoader() == cl4);
+ assertFalse(iter.hasNext());
+ }
+
+ }
+
+
+ /**
+ * Tests that the class loaders created by defineModulesWithXXX delegate
+ * to the given parent class loader.
+ */
+ public void testDelegationToParent() throws Exception {
+
+ Configuration cf = resolve("m1");
+
+ ClassLoader parent = this.getClass().getClassLoader();
+ String cn = this.getClass().getName();
+
+ // one loader
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, parent);
+ testLoad(layer, cn);
+
+ // one loader with boot loader as parent
+ layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, null);
+ testLoadFail(layer, cn);
+
+ // many loaders
+ layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, parent);
+ testLoad(layer, cn);
+
+ // many loader with boot loader as parent
+ layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, null);
+ testLoadFail(layer, cn);
+
+ }
+
+
+ /**
+ * Test defineModulesWithXXX when modules that have overlapping packages.
+ *
+ * Test scenario:
+ * m1 exports p
+ * m2 exports p
+ */
+ public void testOverlappingPackages() {
+
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1").exports("p").build();
+
+ ModuleDescriptor descriptor2
+ = ModuleDescriptor.newModule("m2").exports("p").build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf = ModuleLayer.boot()
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
+
+ // cannot define both module m1 and m2 to the same class loader
+ try {
+ ModuleLayer.boot().defineModulesWithOneLoader(cf, null);
+ assertTrue(false);
+ } catch (LayerInstantiationException expected) { }
+
+ // should be okay to have one module per class loader
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, null);
+ checkLayer(layer, "m1", "m2");
+
+ }
+
+
+ /**
+ * Test ModuleLayer.defineModulesWithXXX with split delegation.
+ *
+ * Test scenario:
+ * layer1: m1 exports p, m2 exports p
+ * layer2: m3 reads m1, m4 reads m2
+ */
+ public void testSplitDelegation() {
+
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1").exports("p").build();
+
+ ModuleDescriptor descriptor2
+ = ModuleDescriptor.newModule("m2").exports("p").build();
+
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+
+ Configuration cf1 = ModuleLayer.boot()
+ .configuration()
+ .resolve(finder1, ModuleFinder.of(), Set.of("m1", "m2"));
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
+ checkLayer(layer1, "m1", "m2");
+
+ ModuleDescriptor descriptor3
+ = ModuleDescriptor.newModule("m3").requires("m1").build();
+
+ ModuleDescriptor descriptor4
+ = ModuleDescriptor.newModule("m4").requires("m2").build();
+
+ ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4);
+
+ Configuration cf2 = cf1.resolve(finder2, ModuleFinder.of(),
+ Set.of("m3", "m4"));
+
+ // package p cannot be supplied by two class loaders
+ try {
+ layer1.defineModulesWithOneLoader(cf2, null);
+ assertTrue(false);
+ } catch (LayerInstantiationException expected) { }
+
+ // no split delegation when modules have their own class loader
+ ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
+ checkLayer(layer2, "m3", "m4");
+
+ }
+
+
+ /**
+ * Test ModuleLayer.defineModulesWithXXX when the modules that override same
+ * named modules in the parent layer.
+ *
+ * Test scenario:
+ * layer1: m1, m2, m3 => same loader
+ * layer2: m1, m2, m4 => same loader
+ */
+ public void testOverriding1() throws Exception {
+
+ Configuration cf1 = resolve("m1");
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithOneLoader(cf1, null);
+ checkLayer(layer1, "m1", "m2", "m3");
+
+ ModuleFinder finder = ModuleFinder.of(MODS_DIR);
+ Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
+ Set.of("m1"));
+
+ ModuleLayer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
+ checkLayer(layer2, "m1", "m2", "m3");
+ invoke(layer1, "m1", "p.Main");
+
+ ClassLoader loader1 = layer1.findLoader("m1");
+ ClassLoader loader2 = layer1.findLoader("m2");
+ ClassLoader loader3 = layer1.findLoader("m3");
+
+ ClassLoader loader4 = layer2.findLoader("m1");
+ ClassLoader loader5 = layer2.findLoader("m2");
+ ClassLoader loader6 = layer2.findLoader("m3");
+
+ assertTrue(loader1 == loader2);
+ assertTrue(loader1 == loader3);
+
+ assertTrue(loader4 == loader5);
+ assertTrue(loader4 == loader6);
+ assertTrue(loader4 != loader1);
+
+ assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader1);
+
+ assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
+ assertTrue(loader4.loadClass("q.Hello").getClassLoader() == loader4);
+ assertTrue(loader4.loadClass("w.Hello").getClassLoader() == loader4);
+
+ }
+
+
+ /**
+ * Test Layer defineModulesWithXXX when the modules that override same
+ * named modules in the parent layer.
+ *
+ * Test scenario:
+ * layer1: m1, m2, m3 => loader pool
+ * layer2: m1, m2, m3 => loader pool
+ */
+ public void testOverriding2() throws Exception {
+
+ Configuration cf1 = resolve("m1");
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
+ checkLayer(layer1, "m1", "m2", "m3");
+
+ ModuleFinder finder = ModuleFinder.of(MODS_DIR);
+ Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
+ Set.of("m1"));
+
+ ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
+ checkLayer(layer2, "m1", "m2", "m3");
+ invoke(layer1, "m1", "p.Main");
+
+ ClassLoader loader1 = layer1.findLoader("m1");
+ ClassLoader loader2 = layer1.findLoader("m2");
+ ClassLoader loader3 = layer1.findLoader("m3");
+
+ ClassLoader loader4 = layer2.findLoader("m1");
+ ClassLoader loader5 = layer2.findLoader("m2");
+ ClassLoader loader6 = layer2.findLoader("m3");
+
+ assertTrue(loader4 != loader1);
+ assertTrue(loader5 != loader2);
+ assertTrue(loader6 != loader3);
+
+ assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader2);
+ assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader3);
+
+ // p.Main is not visible via loader2
+ try {
+ loader2.loadClass("p.Main");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // w.Hello is not visible via loader2
+ try {
+ loader2.loadClass("w.Hello");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // p.Main is not visible via loader3
+ try {
+ loader3.loadClass("p.Main");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // q.Hello is not visible via loader3
+ try {
+ loader3.loadClass("q.Hello");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+
+ assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
+ assertTrue(loader5.loadClass("q.Hello").getClassLoader() == loader5);
+ assertTrue(loader6.loadClass("w.Hello").getClassLoader() == loader6);
+
+ // p.Main is not visible via loader5
+ try {
+ loader5.loadClass("p.Main");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // w.Hello is not visible via loader5
+ try {
+ loader5.loadClass("w.Hello");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // p.Main is not visible via loader6
+ try {
+ loader6.loadClass("p.Main");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ // q.Hello is not visible via loader6
+ try {
+ loader6.loadClass("q.Hello");
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+
+ }
+
+
+ /**
+ * Test ModuleLayer.defineModulesWithXXX when the modules that override same
+ * named modules in the parent layer.
+ *
+ * layer1: m1, m2, m3 => same loader
+ * layer2: m1, m3 => same loader
+ */
+ public void testOverriding3() throws Exception {
+
+ Configuration cf1 = resolve("m1");
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithOneLoader(cf1, null);
+ checkLayer(layer1, "m1", "m2", "m3");
+
+ ModuleFinder finder = finderFor("m1", "m3");
+
+ Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
+ Set.of("m1"));
+
+ ModuleLayer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
+ checkLayer(layer2, "m1", "m3");
+ invoke(layer1, "m1", "p.Main");
+
+ ClassLoader loader1 = layer1.findLoader("m1");
+ ClassLoader loader2 = layer2.findLoader("m1");
+
+ assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader1);
+
+ assertTrue(loader2.loadClass("p.Main").getClassLoader() == loader2);
+ assertTrue(loader2.loadClass("q.Hello").getClassLoader() == loader1);
+ assertTrue(loader2.loadClass("w.Hello").getClassLoader() == loader2);
+
+ }
+
+
+ /**
+ * Test Layer defineModulesWithXXX when the modules that override same
+ * named modules in the parent layer.
+ *
+ * layer1: m1, m2, m3 => loader pool
+ * layer2: m1, m3 => loader pool
+ */
+ public void testOverriding4() throws Exception {
+
+ Configuration cf1 = resolve("m1");
+
+ ModuleLayer layer1 = ModuleLayer.boot().defineModulesWithManyLoaders(cf1, null);
+ checkLayer(layer1, "m1", "m2", "m3");
+
+ ModuleFinder finder = finderFor("m1", "m3");
+
+ Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
+ Set.of("m1"));
+
+ ModuleLayer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
+ checkLayer(layer2, "m1", "m3");
+ invoke(layer1, "m1", "p.Main");
+
+ ClassLoader loader1 = layer1.findLoader("m1");
+ ClassLoader loader2 = layer1.findLoader("m2");
+ ClassLoader loader3 = layer1.findLoader("m3");
+
+ ClassLoader loader4 = layer2.findLoader("m1");
+ ClassLoader loader5 = layer2.findLoader("m2");
+ ClassLoader loader6 = layer2.findLoader("m3");
+
+ assertTrue(loader4 != loader1);
+ assertTrue(loader5 == loader2); // m2 not overridden
+ assertTrue(loader6 != loader3);
+
+ assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
+ assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader2);
+ assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader3);
+
+ assertTrue(loader2.loadClass("q.Hello").getClassLoader() == loader2);
+
+ assertTrue(loader3.loadClass("w.Hello").getClassLoader() == loader3);
+
+ assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
+ assertTrue(loader4.loadClass("q.Hello").getClassLoader() == loader2);
+ assertTrue(loader4.loadClass("w.Hello").getClassLoader() == loader6);
+
+ assertTrue(loader6.loadClass("w.Hello").getClassLoader() == loader6);
+
+ }
+
+
+ /**
+ * Basic test of resource loading with a class loader created by
+ * Layer.defineModulesWithOneLoader.
+ */
+ public void testResourcesOneLoader() throws Exception {
+ Configuration cf = resolve("m1");
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
+ ClassLoader loader = layer.findLoader("m1");
+ testResourceLoading(loader, "p/Main.class");
+ }
+
+ /**
+ * Basic test of resource loading with a class loader created by
+ * Layer.defineModulesWithOneLoader.
+ */
+ public void testResourcesManyLoaders() throws Exception {
+ Configuration cf = resolve("m1");
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
+ ClassLoader loader = layer.findLoader("m1");
+ testResourceLoading(loader, "p/Main.class");
+ }
+
+ /**
+ * Test that a resource is located by a class loader.
+ */
+ private void testResourceLoading(ClassLoader loader, String name)
+ throws IOException
+ {
+ URL url = loader.getResource(name);
+ assertNotNull(url);
+
+ try (InputStream in = loader.getResourceAsStream(name)) {
+ assertNotNull(in);
+ }
+
+ Enumeration urls = loader.getResources(name);
+ assertTrue(urls.hasMoreElements());
+ }
+
+
+ // -- supporting methods --
+
+
+ /**
+ * Resolve the given modules, by name, and returns the resulting
+ * Configuration.
+ */
+ private static Configuration resolve(String... roots) {
+ ModuleFinder finder = ModuleFinder.of(MODS_DIR);
+ return ModuleLayer.boot()
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of(roots));
+ }
+
+ /**
+ * Resolve the given modules, by name, and returns the resulting
+ * Configuration.
+ */
+ private static Configuration resolveAndBind(String... roots) {
+ ModuleFinder finder = ModuleFinder.of(MODS_DIR);
+ return ModuleLayer.boot()
+ .configuration()
+ .resolveAndBind(finder, ModuleFinder.of(), Set.of(roots));
+ }
+
+
+ /**
+ * Invokes the static void main(String[]) method on the given class
+ * in the given module.
+ */
+ private static void invoke(ModuleLayer layer, String mn, String mc) throws Exception {
+ ClassLoader loader = layer.findLoader(mn);
+ Class> c = loader.loadClass(mc);
+ Method mainMethod = c.getMethod("main", String[].class);
+ mainMethod.invoke(null, (Object)new String[0]);
+ }
+
+
+ /**
+ * Checks that the given layer contains exactly the expected modules
+ * (by name).
+ */
+ private void checkLayer(ModuleLayer layer, String ... expected) {
+ Set names = layer.modules().stream()
+ .map(Module::getName)
+ .collect(Collectors.toSet());
+ assertTrue(names.size() == expected.length);
+ for (String name : expected) {
+ assertTrue(names.contains(name));
+ }
+ }
+
+
+ /**
+ * Test that a class can be loaded via the class loader of all modules
+ * in the given layer.
+ */
+ static void testLoad(ModuleLayer layer, String cn) throws Exception {
+ for (Module m : layer.modules()) {
+ ClassLoader l = m.getClassLoader();
+ l.loadClass(cn);
+ }
+ }
+
+
+ /**
+ * Test that a class cannot be loaded via any of the class loaders of
+ * the modules in the given layer.
+ */
+ static void testLoadFail(ModuleLayer layer, String cn) throws Exception {
+ for (Module m : layer.modules()) {
+ ClassLoader l = m.getClassLoader();
+ try {
+ l.loadClass(cn);
+ assertTrue(false);
+ } catch (ClassNotFoundException expected) { }
+ }
+ }
+
+
+ /**
+ * Returns a ModuleFinder that only finds the given test modules
+ */
+ static ModuleFinder finderFor(String... names) {
+
+ ModuleFinder finder = ModuleFinder.of(MODS_DIR);
+
+ Map mrefs = new HashMap<>();
+ for (String name : names) {
+ Optional omref = finder.find(name);
+ assert omref.isPresent();
+ mrefs.put(name, omref.get());
+ }
+
+ return new ModuleFinder() {
+ @Override
+ public Optional find(String name) {
+ ModuleReference mref = mrefs.get(name);
+ return Optional.ofNullable(mref);
+ }
+ @Override
+ public Set findAll() {
+ return mrefs.values().stream().collect(Collectors.toSet());
+ }
+ };
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/LayerControllerTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/LayerControllerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library /lib/testlibrary
+ * @build LayerControllerTest ModuleUtils
+ * @run testng LayerControllerTest
+ * @summary Basic tests for java.lang.ModuleLayer.Controller
+ */
+
+import java.lang.module.Configuration;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleFinder;
+import java.util.List;
+import java.util.Set;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+@Test
+public class LayerControllerTest {
+
+ /**
+ * Creates a Controller for a module layer containing modules m1 and m2.
+ * 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
+ */
+ private ModuleLayer.Controller createTestLayer() {
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1")
+ .packages(Set.of("p1"))
+ .requires("java.base")
+ .build();
+
+ ModuleDescriptor descriptor2
+ = ModuleDescriptor.newModule("m2")
+ .requires("java.base")
+ .packages(Set.of("p2"))
+ .build();
+
+ ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
+ ModuleLayer bootLayer = ModuleLayer.boot();
+
+ Configuration cf = bootLayer.configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+
+ ModuleLayer.Controller controller
+ = ModuleLayer.defineModulesWithOneLoader(cf, List.of(bootLayer), scl);
+
+ ModuleLayer layer = controller.layer();
+
+ assertTrue(layer.modules().size() == 2);
+ assertTrue(layer.findModule("m1").isPresent());
+ assertTrue(layer.findModule("m2").isPresent());
+
+ return controller;
+ }
+
+ /**
+ * Basic test of Controller to update modules m1 and m2 to read and
+ * open packages to each other.
+ */
+ public void testBasic() {
+ ModuleLayer.Controller controller = createTestLayer();
+ ModuleLayer layer = controller.layer();
+ Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
+ Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
+
+ assertFalse(m1.canRead(m2));
+ assertFalse(m1.isExported("p1"));
+ assertFalse(m1.isOpen("p1"));
+ assertFalse(m1.isExported("p1", m2));
+ assertFalse(m1.isOpen("p1", m2));
+
+ assertFalse(m2.canRead(m1));
+ assertFalse(m2.isExported("p2"));
+ assertFalse(m2.isOpen("p2"));
+ assertFalse(m2.isExported("p2", m1));
+ assertFalse(m2.isOpen("p2", m1));
+
+ // update m1 to read m2
+ assertTrue(controller.addReads(m1, m2) == controller);
+ assertTrue(m1.canRead(m2));
+ assertFalse(m2.canRead(m1));
+
+ // update m2 to read m1
+ assertTrue(controller.addReads(m2, m1) == controller);
+ assertTrue(m1.canRead(m2));
+ assertTrue(m1.canRead(m1));
+
+ // update m1 to open p1 to m2
+ assertTrue(controller.addOpens(m1, "p1", m2) == controller);
+ assertTrue(m1.isExported("p1", m2));
+ assertTrue(m1.isOpen("p1", m2));
+ assertFalse(m1.isExported("p1"));
+ assertFalse(m1.isOpen("p1"));
+
+ // update m2 to open p2 to m1
+ assertTrue(controller.addOpens(m2, "p2", m1) == controller);
+ assertTrue(m2.isExported("p2", m1));
+ assertTrue(m2.isOpen("p2", m1));
+ assertFalse(m2.isExported("p2"));
+ assertFalse(m2.isOpen("p2"));
+ }
+
+ /**
+ * Test invalid argument handling
+ */
+ public void testBadArguments() {
+ ModuleLayer.Controller controller = createTestLayer();
+ ModuleLayer layer = controller.layer();
+ Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
+ Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
+ Module base = Object.class.getModule();
+
+ // java.base is not in layer
+ try {
+ controller.addReads(base, m2);
+ assertTrue(false);
+ } catch (IllegalArgumentException expected) { }
+
+ // java.base is not in layer
+ try {
+ controller.addOpens(base, "java.lang", m2);
+ assertTrue(false);
+ } catch (IllegalArgumentException expected) { }
+
+ // m1 does not contain java.lang
+ try {
+ controller.addOpens(m1, "java.lang", m2);
+ assertTrue(false);
+ } catch (IllegalArgumentException expected) { }
+ }
+
+ /**
+ * Test null handling
+ */
+ public void testNulls() {
+ ModuleLayer.Controller controller = createTestLayer();
+ ModuleLayer layer = controller.layer();
+ Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
+ Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
+ assertTrue(m1 != null);
+ assertTrue(m2 != null);
+
+ try {
+ controller.addReads(null, m2);
+ assertTrue(false);
+ } catch (NullPointerException expected) { }
+
+ try {
+ controller.addReads(m1, null);
+ assertTrue(false);
+ } catch (NullPointerException expected) { }
+
+ try {
+ controller.addOpens(null, "p1", m2);
+ assertTrue(false);
+ } catch (NullPointerException expected) { }
+
+ try {
+ controller.addOpens(m1, null, m2);
+ assertTrue(false);
+ } catch (NullPointerException expected) { }
+
+ try {
+ controller.addOpens(m1, "p1", null);
+ assertTrue(false);
+ } catch (NullPointerException expected) { }
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/layertest/Test.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/layertest/Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+/**
+ * Supporting class for tests of java.lang.ModuleLayer.
+ */
+
+package layertest;
+
+public class Test { }
+
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m1/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m1/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module m1 {
+ requires m2;
+ requires m3;
+ exports p;
+ uses p.Service;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m1/p/Main.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m1/p/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 p;
+
+import java.net.URL;
+
+public class Main {
+ public static void main(String[] args) {
+
+ URL url1 = Main.class.getResource("Main.class");
+ if (url1 == null) throw new RuntimeException();
+ URL url2 = Main.class.getResource("/p/Main.class");
+ if (url2 == null) throw new RuntimeException();
+
+ q.Hello.hello();
+ w.Hello.hello();
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m1/p/Service.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m1/p/Service.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 p;
+
+public interface Service { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m2/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m2/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module m2 {
+ exports q;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m2/q/Hello.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m2/q/Hello.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 q;
+
+import java.net.URL;
+
+public class Hello {
+
+ public static void hello() {
+
+ URL url1 = Hello.class.getResource("Hello.class");
+ if (url1 == null) throw new RuntimeException();
+ URL url2 = Hello.class.getResource("/q/Hello.class");
+ if (url2 == null) throw new RuntimeException();
+
+ System.out.println("Hello!");
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m3/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m3/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module m3 {
+ // qualified export
+ exports w to m1;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m3/w/Hello.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m3/w/Hello.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 w;
+
+import java.net.URL;
+
+public class Hello {
+
+ public static void hello() {
+
+ URL url1 = Hello.class.getResource("Hello.class");
+ if (url1 == null) throw new RuntimeException();
+ URL url2 = Hello.class.getResource("/w/Hello.class");
+ if (url2 == null) throw new RuntimeException();
+
+ System.out.println("Hello!");
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m4/impl/ServiceImpl.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m4/impl/ServiceImpl.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 impl;
+
+public class ServiceImpl implements p.Service {
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleLayer/src/m4/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleLayer/src/m4/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module m4 {
+ requires m1;
+ provides p.Service with impl.ServiceImpl;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/AddExportsTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/AddExportsTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @modules java.base/jdk.internal.misc
+ * java.desktop
+ * @run main/othervm --add-exports=java.desktop/sun.awt=java.base AddExportsTest
+ * @run main/othervm --add-exports=java.desktop/sun.awt=ALL-UNNAMED AddExportsTest
+ * @summary Test Module isExported methods with exports changed by -AddExportsTest
+ */
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import jdk.internal.misc.VM;
+
+public class AddExportsTest {
+ /*
+ * jtreg sets -Dtest.modules system property to the internal APIs
+ * specified at @modules tag. The test will exclude --add-exports set
+ * for @modules.
+ */
+ private static final String TEST_MODULES = System.getProperty("test.modules");
+
+ public static void main(String[] args) {
+
+ Optional oaddExports = Stream.of(VM.getRuntimeArguments())
+ .filter(arg -> arg.startsWith("--add-exports="))
+ .filter(arg -> !arg.equals("--add-exports=" + TEST_MODULES + "=ALL-UNNAMED"))
+ .map(arg -> arg.substring("--add-exports=".length(), arg.length()))
+ .findFirst();
+
+ assertTrue(oaddExports.isPresent());
+
+ ModuleLayer bootLayer = ModuleLayer.boot();
+
+ Module unnamedModule = AddExportsTest.class.getModule();
+ assertFalse(unnamedModule.isNamed());
+
+ for (String expr : oaddExports.get().split(",")) {
+
+ String[] s = expr.split("=");
+ assertTrue(s.length == 2);
+
+ // $MODULE/$PACKAGE
+ String[] moduleAndPackage = s[0].split("/");
+ assertTrue(moduleAndPackage.length == 2);
+
+ String mn = moduleAndPackage[0];
+ String pn = moduleAndPackage[1];
+
+ // source module
+ Module source;
+ Optional om = bootLayer.findModule(mn);
+ assertTrue(om.isPresent(), mn + " not in boot layer");
+ source = om.get();
+
+ // package should not be exported unconditionally
+ assertFalse(source.isExported(pn),
+ pn + " should not be exported unconditionally");
+
+ // $TARGET
+ String tn = s[1];
+ if ("ALL-UNNAMED".equals(tn)) {
+
+ // package is exported to all unnamed modules
+ assertTrue(source.isExported(pn, unnamedModule),
+ pn + " should be exported to all unnamed modules");
+
+ } else {
+
+ om = bootLayer.findModule(tn);
+ assertTrue(om.isPresent());
+ Module target = om.get();
+
+ // package should be exported to target module
+ assertTrue(source.isExported(pn, target),
+ pn + " should be exported to " + target);
+
+ // package should not be exported to unnamed modules
+ assertFalse(source.isExported(pn, unnamedModule),
+ pn + " should not be exported to unnamed modules");
+
+ }
+
+ }
+ }
+
+ static void assertTrue(boolean cond) {
+ if (!cond) throw new RuntimeException();
+ }
+
+ static void assertTrue(boolean cond, String msg) {
+ if (!cond) throw new RuntimeException(msg);
+ }
+
+ static void assertFalse(boolean cond) {
+ if (cond) throw new RuntimeException();
+ }
+
+ static void assertFalse(boolean cond, String msg) {
+ if (cond) throw new RuntimeException(msg);
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/AnnotationsTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/AnnotationsTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.module.Configuration;
+import java.lang.module.ModuleFinder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import jdk.internal.module.ClassFileAttributes;
+import jdk.internal.org.objectweb.asm.AnnotationVisitor;
+import jdk.internal.org.objectweb.asm.Attribute;
+import jdk.internal.org.objectweb.asm.ClassReader;
+import jdk.internal.org.objectweb.asm.ClassVisitor;
+import jdk.internal.org.objectweb.asm.ClassWriter;
+import jdk.internal.org.objectweb.asm.Opcodes;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * @test
+ * @modules java.base/jdk.internal.org.objectweb.asm
+ * java.base/jdk.internal.module
+ * java.xml
+ * @run testng AnnotationsTest
+ * @summary Basic test of annotations on modules
+ */
+
+public class AnnotationsTest {
+
+ /**
+ * Test that there are no annotations on an unnamed module.
+ */
+ @Test
+ public void testUnnamedModule() {
+ Module module = this.getClass().getModule();
+ assertTrue(module.getAnnotations().length == 0);
+ }
+
+ /**
+ * Test loading a module with a RuntimeVisibleAnnotation attribute.
+ * The test copies the module-info.class for java.xml, adds the attribute,
+ * and then loads the updated module.
+ */
+ @Test
+ public void testNamedModule() throws IOException {
+
+ // "deprecate" java.xml
+ Path dir = Files.createTempDirectory("mods");
+ deprecateModule("java.xml", true, "9", dir);
+
+ // "load" the cloned java.xml
+ Module module = loadModule(dir, "java.xml");
+
+ // check the annotation is present
+ assertTrue(module.isAnnotationPresent(Deprecated.class));
+ Deprecated d = module.getAnnotation(Deprecated.class);
+ assertNotNull(d, "@Deprecated not found");
+ assertTrue(d.forRemoval());
+ assertEquals(d.since(), "9");
+ Annotation[] a = module.getAnnotations();
+ assertTrue(a.length == 1);
+ assertTrue(a[0] instanceof Deprecated);
+ }
+
+
+ /**
+ * Copy the module-info.class for the given module, add the
+ * Deprecated annotation, and write the updated module-info.class
+ * to a directory.
+ */
+ static void deprecateModule(String name,
+ boolean forRemoval,
+ String since,
+ Path output) throws IOException {
+ Module module = ModuleLayer.boot().findModule(name).orElse(null);
+ assertNotNull(module, name + " not found");
+
+ InputStream in = module.getResourceAsStream("module-info.class");
+ assertNotNull(in, "No module-info.class for " + name);
+
+ try (in) {
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
+ + ClassWriter.COMPUTE_FRAMES);
+
+ ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, cw) { };
+
+ ClassReader cr = new ClassReader(in);
+
+ List attrs = new ArrayList<>();
+ attrs.add(new ClassFileAttributes.ModuleAttribute());
+ attrs.add(new ClassFileAttributes.ModulePackagesAttribute());
+ attrs.add(new ClassFileAttributes.ModuleTargetAttribute());
+ cr.accept(cv, attrs.toArray(new Attribute[0]), 0);
+
+ AnnotationVisitor annotationVisitor
+ = cv.visitAnnotation("Ljava/lang/Deprecated;", true);
+ annotationVisitor.visit("forRemoval", forRemoval);
+ annotationVisitor.visit("since", since);
+ annotationVisitor.visitEnd();
+
+ byte[] bytes = cw.toByteArray();
+ Path mi = output.resolve("module-info.class");
+ Files.write(mi, bytes);
+ }
+ }
+
+ /**
+ * Load the module of the given name in the given directory into a
+ * child layer.
+ */
+ static Module loadModule(Path dir, String name) throws IOException {
+ ModuleFinder finder = ModuleFinder.of(dir);
+
+ ModuleLayer bootLayer = ModuleLayer.boot();
+
+ Configuration cf = bootLayer.configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of(name));
+
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+
+ Module module = layer.findModule(name).orElse(null);
+ assertNotNull(module, name + " not loaded");
+ return module;
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/BasicModuleTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/BasicModuleTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 2014, 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.
+ *
+ * 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.
+ */
+
+import java.lang.module.ModuleDescriptor.Exports;
+import java.lang.module.ResolvedModule;
+import java.nio.file.spi.FileSystemProvider; // service type in java.base
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import javax.print.PrintServiceLookup; // service type in java.desktop
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/*
+ * @test
+ * @summary Basic test of java.lang.Module
+ * @modules java.desktop java.xml
+ * @run testng BasicModuleTest
+ */
+
+public class BasicModuleTest {
+
+ /**
+ * Tests that the given module reads all modules in the boot layer.
+ */
+ private void testReadsAllBootModules(Module m) {
+ ModuleLayer bootLayer = ModuleLayer.boot();
+ bootLayer.configuration()
+ .modules()
+ .stream()
+ .map(ResolvedModule::name)
+ .map(bootLayer::findModule)
+ .forEach(target -> assertTrue(m.canRead(target.get())));
+ }
+
+ /**
+ * Returns a {@code Predicate} to test if a package is exported.
+ */
+ private Predicate doesExport(String pn) {
+ return e -> (e.source().equals(pn) && !e.isQualified());
+ }
+
+
+
+ @Test
+ public void testThisModule() {
+ Module thisModule = BasicModuleTest.class.getModule();
+ Module baseModule = Object.class.getModule();
+
+ assertFalse(thisModule.isNamed());
+ assertTrue(thisModule.getName() == null);
+ assertTrue(thisModule.getDescriptor() == null);
+ assertTrue(thisModule.getLayer() == null);
+ assertTrue(thisModule.toString().startsWith("unnamed module "));
+
+ ClassLoader thisLoader = BasicModuleTest.class.getClassLoader();
+ assertTrue(thisLoader == thisModule.getClassLoader());
+ assertTrue(thisLoader.getUnnamedModule() == thisModule);
+
+ // unnamed modules read all other modules
+ ClassLoader cl;
+ cl = ClassLoader.getPlatformClassLoader();
+ assertTrue(thisModule.canRead(cl.getUnnamedModule()));
+ cl = ClassLoader.getSystemClassLoader();
+ assertTrue(thisModule.canRead(cl.getUnnamedModule()));
+ testReadsAllBootModules(thisModule);
+
+ // unnamed modules export all packages
+ assertTrue(thisModule.isExported(""));
+ assertTrue(thisModule.isExported("", thisModule));
+ assertTrue(thisModule.isExported("", baseModule));
+ assertTrue(thisModule.isExported("p"));
+ assertTrue(thisModule.isExported("p", thisModule));
+ assertTrue(thisModule.isExported("p", baseModule));
+
+ // this test is in the unnamed package
+ assertTrue(thisModule.getPackages().contains(""));
+ }
+
+
+ @Test
+ public void testUnnamedModules() {
+ Module thisModule = BasicModuleTest.class.getModule();
+ Module baseModule = Object.class.getModule();
+
+ ClassLoader loader1 = ClassLoader.getSystemClassLoader();
+ ClassLoader loader2 = loader1.getParent();
+
+ Module m1 = loader1.getUnnamedModule();
+ Module m2 = loader2.getUnnamedModule();
+
+ assertTrue(m1 != m2);
+
+ assertFalse(m1.isNamed());
+ assertFalse(m2.isNamed());
+
+ assertTrue(m1.getLayer() == null);
+ assertTrue(m2.getLayer() == null);
+
+ assertTrue(m1.toString().startsWith("unnamed module "));
+ assertTrue(m2.toString().startsWith("unnamed module "));
+
+ // unnamed module reads all modules
+ assertTrue(m1.canRead(m2));
+ assertTrue(m2.canRead(m1));
+
+ testReadsAllBootModules(m1);
+ testReadsAllBootModules(m2);
+
+ assertTrue(m1.isExported(""));
+ assertTrue(m1.isExported("", thisModule));
+ assertTrue(m1.isExported("", baseModule));
+ assertTrue(m1.isExported("p"));
+ assertTrue(m1.isExported("p", thisModule));
+ assertTrue(m1.isExported("p", baseModule));
+ }
+
+
+
+ @Test
+ public void testBaseModule() {
+ Module base = Object.class.getModule();
+ Module thisModule = BasicModuleTest.class.getModule();
+
+ // getName
+ assertTrue(base.getName().equals("java.base"));
+
+ // getDescriptor
+ assertTrue(base.getDescriptor().exports().stream()
+ .anyMatch(doesExport("java.lang")));
+
+ // getClassLoader
+ assertTrue(base.getClassLoader() == null);
+
+ // getLayer
+ assertTrue(base.getLayer() == ModuleLayer.boot());
+
+ // toString
+ assertEquals(base.toString(), "module java.base");
+
+ // getPackages
+ assertTrue(base.getPackages().contains("java.lang"));
+
+ // canRead
+ assertTrue(base.canRead(base));
+ assertFalse(base.canRead(thisModule));
+
+ // addReads
+ try {
+ base.addReads(thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(base.canRead(thisModule));
+
+ // isExported
+ assertTrue(base.isExported("java.lang"));
+ assertTrue(base.isExported("java.lang", thisModule));
+ assertTrue(base.isExported("java.lang", base));
+ assertFalse(base.isExported("jdk.internal.misc"));
+ assertFalse(base.isExported("jdk.internal.misc", thisModule));
+ assertTrue(base.isExported("jdk.internal.misc", base));
+ assertFalse(base.isExported("java.wombat"));
+ assertFalse(base.isExported("java.wombat", thisModule));
+ assertFalse(base.isExported("java.wombat", base));
+
+ // addExports
+ try {
+ base.addExports("java.lang", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ try {
+ base.addExports("jdk.internal.misc", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(base.isExported("jdk.internal.misc"));
+ assertFalse(base.isExported("jdk.internal.misc", thisModule));
+
+ // isOpen
+ assertFalse(base.isOpen("java.lang"));
+ assertFalse(base.isOpen("java.lang", thisModule));
+ assertTrue(base.isOpen("java.lang", base));
+ assertFalse(base.isOpen("jdk.internal.misc"));
+ assertFalse(base.isOpen("jdk.internal.misc", thisModule));
+ assertTrue(base.isOpen("jdk.internal.misc", base));
+ assertFalse(base.isOpen("java.wombat"));
+ assertFalse(base.isOpen("java.wombat", thisModule));
+ assertFalse(base.isOpen("java.wombat", base));
+
+ // addOpens
+ try {
+ base.addOpens("jdk.internal.misc", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(base.isOpen("jdk.internal.misc"));
+ assertFalse(base.isOpen("jdk.internal.misc", thisModule));
+
+ // canUse
+ assertTrue(base.canUse(FileSystemProvider.class));
+ assertFalse(base.canUse(Thread.class));
+
+ // addUses
+ try {
+ base.addUses(FileSystemProvider.class);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ try {
+ base.addUses(Thread.class);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(base.canUse(Thread.class));
+ }
+
+
+ @Test
+ public void testDesktopModule() {
+ Module desktop = java.awt.Component.class.getModule();
+ Module base = Object.class.getModule();
+ Module xml = javax.xml.XMLConstants.class.getModule();
+ Module thisModule = BasicModuleTest.class.getModule();
+
+ // name
+ assertTrue(desktop.getName().equals("java.desktop"));
+
+ // descriptor
+ assertTrue(desktop.getDescriptor().exports().stream()
+ .anyMatch(doesExport("java.awt")));
+
+ // getClassLoader
+ assertTrue(desktop.getClassLoader() == null);
+
+ // getLayer
+ assertTrue(desktop.getLayer() == ModuleLayer.boot());
+
+ // toString
+ assertEquals(desktop.toString(), "module java.desktop");
+
+ // getPackages
+ assertTrue(desktop.getPackages().contains("java.awt"));
+ assertTrue(desktop.getPackages().contains("sun.awt"));
+
+ // canRead
+ assertTrue(desktop.canRead(base));
+ assertTrue(desktop.canRead(xml));
+
+ // addReads
+ try {
+ desktop.addReads(thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(desktop.canRead(thisModule));
+
+ // isExported
+ assertTrue(desktop.isExported("java.awt"));
+ assertTrue(desktop.isExported("java.awt", thisModule));
+ assertFalse(desktop.isExported("sun.awt"));
+ assertFalse(desktop.isExported("sun.awt", thisModule));
+ assertTrue(desktop.isExported("sun.awt", desktop));
+ assertFalse(desktop.isExported("java.wombat"));
+ assertFalse(desktop.isExported("java.wombat", thisModule));
+ assertFalse(desktop.isExported("java.wombat", base));
+
+ // addExports
+ try {
+ desktop.addExports("java.awt", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ try {
+ desktop.addExports("sun.awt", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(desktop.isExported("sun.awt"));
+ assertFalse(desktop.isExported("sun.awt", thisModule));
+
+ // isOpen
+ assertFalse(desktop.isOpen("java.awt"));
+ assertFalse(desktop.isOpen("java.awt", thisModule));
+ assertTrue(desktop.isOpen("java.awt", desktop));
+ assertFalse(desktop.isOpen("sun.awt"));
+ assertFalse(desktop.isOpen("sun.awt", thisModule));
+ assertTrue(desktop.isOpen("sun.awt", desktop));
+ assertFalse(desktop.isOpen("java.wombat"));
+ assertFalse(desktop.isOpen("java.wombat", thisModule));
+ assertFalse(desktop.isOpen("java.wombat", desktop));
+
+ // addOpens
+ try {
+ base.addOpens("sun.awt", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(desktop.isOpen("sun.awt"));
+ assertFalse(desktop.isOpen("sun.awt", thisModule));
+
+ // canUse
+ assertTrue(base.canUse(FileSystemProvider.class));
+ assertFalse(base.canUse(Thread.class));
+
+ // addUses
+ try {
+ desktop.addUses(PrintServiceLookup.class);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ try {
+ desktop.addUses(Thread.class);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ assertFalse(desktop.canUse(Thread.class));
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/WithSecurityManager.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/WithSecurityManager.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @modules jdk.compiler
+ * @summary Test java.lang.Module methods that specify permission checks
+ * @run main/othervm -Djava.security.policy=${test.src}/allow.policy WithSecurityManager allow
+ * @run main/othervm WithSecurityManager deny
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.module.Configuration;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Test java.lang.Module methods that specify permission checks.
+ */
+
+public class WithSecurityManager {
+
+ // a module that will be loaded into a child layer
+ static final String ANOTHER_MODULE = "jdk.compiler";
+ static final String ANOTHER_MODULE_RESOURCE = "com/sun/tools/javac/Main.class";
+
+ public static void main(String[] args) throws IOException {
+ boolean allow = args[0].equals("allow");
+
+ // base module, in the boot layer
+ Module base = Object.class.getModule();
+
+ // another module, in a child layer
+ Module other = loadModuleInChildLayer(ANOTHER_MODULE);
+ assertTrue(other.getLayer() != ModuleLayer.boot());
+
+ System.setSecurityManager(new SecurityManager());
+
+ test(base, "java/lang/Object.class", allow);
+ test(other, ANOTHER_MODULE_RESOURCE, allow);
+ }
+
+ /**
+ * Test the permission checks by invoking methods on the given module.
+ *
+ * If {@code allow} is {@code true} then the permission checks should succeed.
+ */
+ static void test(Module m, String name, boolean allow) throws IOException {
+
+ // test Module::getClassLoader
+ System.out.format("Test getClassLoader on %s ...%n", m);
+ try {
+ ClassLoader cl = m.getClassLoader();
+ System.out.println(cl);
+ if (!allow)
+ assertTrue("getClassLoader should have failed", false);
+ } catch (SecurityException e) {
+ System.out.println(e + " thrown");
+ if (allow)
+ throw e;
+ }
+
+ // test Module::getResourceAsStream
+ System.out.format("Test getResourceAsStream(\"%s\") on %s ...%n", name, m);
+ try (InputStream in = m.getResourceAsStream(name)) {
+ System.out.println(in);
+ if (allow && (in == null))
+ assertTrue(name + " not found", false);
+ if (!allow && (in != null))
+ assertTrue(name + " should not be found", false);
+ }
+
+ }
+
+ /**
+ * Create a module layer that contains the given system module.
+ */
+ static Module loadModuleInChildLayer(String mn) {
+ Optional omref = ModuleFinder.ofSystem().find(mn);
+ assertTrue("module " + mn + " not a system module", omref.isPresent());
+
+ // create a ModuleFinder that only finds this module
+ ModuleReference mref = omref.get();
+ ModuleFinder finder = new ModuleFinder() {
+ @Override
+ public Optional find(String name) {
+ if (name.equals(mn))
+ return Optional.of(mref);
+ else
+ return Optional.empty();
+ }
+
+ @Override
+ public Set findAll() {
+ return Collections.singleton(mref);
+ }
+ };
+
+ // create a child configuration and layer with this module
+ ModuleLayer bootLayer = ModuleLayer.boot();
+ Configuration cf = bootLayer
+ .configuration()
+ .resolve(finder, ModuleFinder.of(), Set.of(ANOTHER_MODULE));
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, null);
+
+ Optional om = layer.findModule(mn);
+ assertTrue("module " + mn + " not in child layer", om.isPresent());
+ return om.get();
+ }
+
+ static void assertTrue(String msg, boolean e) {
+ if (!e)
+ throw new RuntimeException(msg);
+ }
+
+ static void assertTrue(boolean e) {
+ if (!e)
+ throw new RuntimeException();
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/AccessTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/AccessTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+
+import static jdk.testlibrary.ProcessTools.executeTestJava;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * @test
+ * @library /lib/testlibrary
+ * @modules jdk.compiler
+ * @build AccessTest CompilerUtils jdk.testlibrary.*
+ * @run testng AccessTest
+ * @summary Driver for test that checks access to access to types in
+ * exported and non-exported packages.
+ */
+
+@Test
+public class AccessTest {
+
+ private static final String TEST_SRC = System.getProperty("test.src");
+
+ private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
+ private static final Path MODS_DIR = Paths.get("mods");
+
+
+ // the names of the modules in this test
+ private static List modules = Arrays.asList("test", "target");
+
+
+ /**
+ * Compiles all modules used by the test
+ */
+ @BeforeTest
+ public void compileAll() throws Exception {
+ for (String mn : modules) {
+ Path src = SRC_DIR.resolve(mn);
+ Path mods = MODS_DIR.resolve(mn);
+ assertTrue(CompilerUtils.compile(src, mods));
+ }
+ }
+
+ /**
+ * Run the test
+ */
+ public void runTest() throws Exception {
+ int exitValue
+ = executeTestJava("--module-path", MODS_DIR.toString(),
+ "--add-modules", "target",
+ "-Dsun.reflect.enableStrictMode=true",
+ "-m", "test/test.Main")
+ .outputTo(System.out)
+ .errorTo(System.out)
+ .getExitValue();
+
+ assertTrue(exitValue == 0);
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module target {
+ exports p1;
+ exports p2;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/p1/Helper.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/p1/Helper.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 p1;
+
+/**
+ * Helper class in target module to allow test invoke addExports[Private]
+ */
+
+public class Helper {
+ Helper() { }
+
+ public static void addExports(String pn, Module who) {
+ Helper.class.getModule().addExports(pn, who);
+ }
+
+ public static void addOpens(String pn, Module who) {
+ Helper.class.getModule().addOpens(pn, who);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/p1/Public.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/p1/Public.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 p1;
+
+public class Public {
+
+ // public constructor
+ public Public() { }
+
+ // non-public constructor
+ private Public(Void ignore) { }
+
+ // public field
+ public static Object f1;
+
+ // non-public field
+ private static Object f2;
+
+ // public method
+ public static void foo() { }
+
+ // non-public method
+ private static void bar() { }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/p2/NonPublic.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/p2/NonPublic.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 p2;
+
+class NonPublic {
+
+ // public constructor
+ public NonPublic() { }
+
+ // non-public constructor
+ private NonPublic(Void ignore) { }
+
+ // public field
+ public static Object f1;
+
+ // non-public field
+ private static Object f2;
+
+ // public method
+ public static void foo() { }
+
+ // non-public method
+ private static void bar() { }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/q1/Public.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/q1/Public.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 q1;
+
+public class Public {
+
+ // public constructor
+ public Public() { }
+
+ // non-public constructor
+ private Public(Void ignore) { }
+
+ // public field
+ public static Object f1;
+
+ // non-public field
+ private static Object f2;
+
+ // public method
+ public static void foo() { }
+
+ // non-public method
+ private static void bar() { }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/target/q2/NonPublic.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/target/q2/NonPublic.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 q2;
+
+class NonPublic {
+
+ // public constructor
+ public NonPublic() { }
+
+ // non-public constructor
+ private NonPublic(Void ignore) { }
+
+ // public field
+ public static Object f1;
+
+ // non-public field
+ private static Object f2;
+
+ // public method
+ public static void foo() { }
+
+ // non-public method
+ private static void bar() { }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/test/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/test/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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.
+ */
+
+module test { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/access/src/test/test/Main.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/access/src/test/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,377 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * 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 test;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Test access to public/non-public members of public/non-public classes in
+ * exported and non-exported packages.
+ */
+
+public class Main {
+
+ public static void main(String[] args) throws Exception {
+ testPublicClassInExportedPackage();
+ testNonPublicClassInExportedPackage();
+ testPublicClassInNonExportedPackage();
+ testNonPublicClassInNonExportedPackage();
+ }
+
+ static void testPublicClassInExportedPackage() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module targetModule = getTargetModule();
+
+ assertTrue(targetModule.isExported("p1"));
+ assertTrue(targetModule.isExported("p1", thisModule));
+ assertTrue(targetModule.isExported("p1", targetModule));
+
+ assertFalse(targetModule.isOpen("p1"));
+ assertFalse(targetModule.isOpen("p1", thisModule));
+ assertTrue(targetModule.isOpen("p1", targetModule));
+
+ Class> clazz = Class.forName("p1.Public");
+ Constructor> ctor1 = clazz.getConstructor(); // public
+ Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
+
+ Field f1 = clazz.getField("f1"); // public
+ Field f2 = clazz.getDeclaredField("f2"); // non-public
+
+ Method m1 = clazz.getMethod("foo"); // public
+ Method m2 = clazz.getDeclaredMethod("bar"); // non-public
+
+ tryAccessConstructor(ctor1, true);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, true);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, true);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, false);
+
+ targetAddOpens("p1", thisModule);
+
+ tryAccessConstructor(ctor1, true);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, true);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, true);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(ctor2, true);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, true);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, true);
+ }
+
+ static void testNonPublicClassInExportedPackage() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module targetModule = getTargetModule();
+
+ assertTrue(targetModule.isExported("p2"));
+ assertTrue(targetModule.isExported("p2", thisModule));
+ assertTrue(targetModule.isExported("p2", targetModule));
+
+ assertFalse(targetModule.isOpen("p2"));
+ assertFalse(targetModule.isOpen("p2", thisModule));
+ assertTrue(targetModule.isOpen("p1", targetModule));
+
+ Class> clazz = Class.forName("p2.NonPublic");
+ Constructor> ctor1 = clazz.getConstructor();
+ Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class);
+
+ Field f1 = clazz.getField("f1"); // public
+ Field f2 = clazz.getDeclaredField("f2"); // non-public
+
+ Method m1 = clazz.getMethod("foo"); // public
+ Method m2 = clazz.getDeclaredMethod("bar"); // non-public
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, false);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, false);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, false);
+ trySetAccessible(f2, false);
+
+ targetAddExports("p2", thisModule);
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, false);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, false);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, false);
+ trySetAccessible(f2, false);
+
+ targetAddOpens("p2", thisModule);
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(ctor2, true);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, true);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, true);
+ }
+
+ static void testPublicClassInNonExportedPackage() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module targetModule = getTargetModule();
+
+ assertFalse(targetModule.isExported("q1"));
+ assertFalse(targetModule.isExported("q1", thisModule));
+ assertTrue(targetModule.isExported("q1", targetModule));
+
+ assertFalse(targetModule.isOpen("q1"));
+ assertFalse(targetModule.isOpen("q1", thisModule));
+ assertTrue(targetModule.isOpen("q1", targetModule));
+
+ Class> clazz = Class.forName("q1.Public");
+ Constructor> ctor1 = clazz.getConstructor(); // public
+ Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
+
+ Field f1 = clazz.getField("f1"); // public
+ Field f2 = clazz.getDeclaredField("f2"); // non-public
+
+ Method m1 = clazz.getMethod("foo"); // public
+ Method m2 = clazz.getDeclaredMethod("bar"); // non-public
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, false);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, false);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, false);
+ trySetAccessible(f2, false);
+
+ targetAddExports("q1", thisModule);
+
+ tryAccessConstructor(ctor1, true);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, true);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, true);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, false);
+
+ targetAddOpens("q1", thisModule);
+
+ tryAccessConstructor(ctor1, true);
+ tryAccessConstructor(ctor1, false);
+ tryAccessMethod(m1, true);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, true);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(ctor2, true);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, true);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, true);
+ }
+
+ static void testNonPublicClassInNonExportedPackage() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module targetModule = getTargetModule();
+
+ assertFalse(targetModule.isExported("q2"));
+ assertFalse(targetModule.isExported("q2", thisModule));
+ assertTrue(targetModule.isExported("q2", targetModule));
+
+ assertFalse(targetModule.isOpen("q2"));
+ assertFalse(targetModule.isOpen("q2", thisModule));
+ assertTrue(targetModule.isOpen("q2", targetModule));
+
+ Class> clazz = Class.forName("q2.NonPublic");
+ Constructor> ctor1 = clazz.getConstructor(); // public
+ Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
+
+ Field f1 = clazz.getField("f1"); // public
+ Field f2 = clazz.getDeclaredField("f2"); // non-public
+
+ Method m1 = clazz.getMethod("foo"); // public
+ Method m2 = clazz.getDeclaredMethod("bar"); // non-public
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, false);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, false);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, false);
+ trySetAccessible(f2, false);
+
+ targetAddExports("q2", thisModule);
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, false);
+ trySetAccessible(ctor2, false);
+ trySetAccessible(m1, false);
+ trySetAccessible(m2, false);
+ trySetAccessible(f1, false);
+ trySetAccessible(f2, false);
+
+ targetAddOpens("q2", thisModule);
+
+ tryAccessConstructor(ctor1, false);
+ tryAccessConstructor(ctor2, false);
+ tryAccessMethod(m1, false);
+ tryAccessMethod(m2, false);
+ tryAccessObjectField(f1, false);
+ tryAccessObjectField(f2, false);
+
+ trySetAccessible(ctor1, true);
+ trySetAccessible(m1, true);
+ trySetAccessible(m2, true);
+ trySetAccessible(f1, true);
+ trySetAccessible(f2, true);
+ }
+
+
+ static Module getTargetModule() {
+ return ModuleLayer.boot().findModule("target").get();
+ }
+
+ static void tryAccessConstructor(Constructor> ctor, boolean shouldSucceed) {
+ try {
+ ctor.newInstance();
+ assertTrue(shouldSucceed);
+ } catch (Exception e) {
+ assertFalse(shouldSucceed);
+ }
+ }
+
+ static void tryAccessMethod(Method method, boolean shouldSucceed) {
+ try {
+ method.invoke(null);
+ assertTrue(shouldSucceed);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertFalse(shouldSucceed);
+ }
+ }
+
+ static void tryAccessObjectField(Field f, boolean shouldSucceed) {
+ try {
+ f.get(null);
+ assertTrue(shouldSucceed);
+ } catch (Exception e) {
+ assertFalse(shouldSucceed);
+ }
+ try {
+ f.set(null, new Object());
+ assertTrue(shouldSucceed);
+ } catch (Exception e) {
+ assertFalse(shouldSucceed);
+ }
+ }
+
+ static void trySetAccessible(AccessibleObject ao, boolean shouldSucceed) {
+ try {
+ ao.setAccessible(true);
+ assertTrue(shouldSucceed);
+ } catch (Exception e) {
+ assertFalse(shouldSucceed);
+ }
+ }
+
+ /**
+ * Update target module to export a package to the given module.
+ */
+ static void targetAddExports(String pn, Module who) throws Exception {
+ Class> helper = Class.forName("p1.Helper");
+ Method m = helper.getMethod("addExports", String.class, Module.class);
+ m.invoke(null, pn, who);
+ }
+
+ /**
+ * Update target module to open a package to the given module.
+ */
+ static void targetAddOpens(String pn, Module who) throws Exception {
+ Class> helper = Class.forName("p1.Helper");
+ Method m = helper.getMethod("addOpens", String.class, Module.class);
+ m.invoke(null, pn, who);
+ }
+
+ static void assertTrue(boolean expr) {
+ if (!expr) throw new RuntimeException();
+ }
+
+ static void assertFalse(boolean expr) {
+ assertTrue(!expr);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/Driver.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/Driver.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @build test/* m1/* m2/* m3/* m4/*
+ * @run testng/othervm test/test.Main
+ * @summary Basic test case for Module::addXXX methods
+ */
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m1/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m1/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+module m1 {
+ exports p1;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m1/p1/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m1/p1/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ *
+ * 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 p1;
+
+public class C {
+ public C() { }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m2/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m2/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+module m2 {
+ exports p2;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m2/p2/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m2/p2/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ *
+ * 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 p2;
+
+public class C {
+
+ public static void export(String pn, Module m) {
+ C.class.getModule().addExports(pn, m);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m2/p2/internal/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m2/p2/internal/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ *
+ * 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 p2.internal;
+
+public class C {
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m3/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m3/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+module m3 {
+ exports p3 to test;
+ opens p3 to test;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m3/p3/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m3/p3/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ *
+ * 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 p3;
+
+public class C {
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m4/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m4/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+module m4 {
+ exports p4;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/m4/p4/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/m4/p4/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ *
+ * 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 p4;
+
+import java.lang.reflect.Constructor;
+
+public class C {
+ public static Object tryNewInstance(Class> clazz) throws Exception {
+ Constructor> ctor = clazz.getDeclaredConstructor();
+ return ctor.newInstance();
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/test/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/test/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+module test {
+ exports test to testng;
+
+ requires m2;
+ requires m3;
+ requires m4;
+ requires testng;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/test/test/C.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/test/test/C.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ *
+ * 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 test;
+
+public class C { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/test/test/Main.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/test/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ *
+ * 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 test;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.util.ServiceConfigurationError;
+import java.util.ServiceLoader;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * Basic test case for Module::addXXXX methods
+ */
+
+@Test
+public class Main {
+
+ /**
+ * Test Module::addReads
+ *
+ * module test { }
+ *
+ * module m1 {
+ * exports p1;
+ * }
+ */
+ public void testAddReads() throws Throwable {
+ Module thisModule = Main.class.getModule();
+ Class> clazz = Class.forName("p1.C");
+ Module m1 = clazz.getModule();
+
+ // test does not read m1
+ assertFalse(thisModule.canRead(m1));
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodType mt = MethodType.methodType(void.class);
+ try {
+ lookup.findConstructor(clazz, mt);
+ assertTrue(false);
+ } catch (IllegalAccessException expected) { }
+
+ // update test to read m1
+ Module result = thisModule.addReads(m1);
+ assertTrue(result== thisModule);
+ assertTrue(thisModule.canRead(m1));
+ MethodHandle mh = lookup.findConstructor(clazz, mt);
+ Object obj = mh.invoke();
+
+ // attempt to update m1 to read test
+ try {
+ m1.addReads(thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ }
+
+
+ /**
+ * Test Module::addExports
+ *
+ * module test {
+ * requires m2;
+ * }
+ * module m2 {
+ * exports p2;
+ * contains package p2.internal;
+ * }
+ */
+ public void testAddExports() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module m2 = p2.C.class.getModule();
+ Class> targetClass = Class.forName("p2.internal.C");
+ String p2Internal = targetClass.getPackageName();
+ assertTrue(targetClass.getModule() == m2);
+
+ // m2 does not export p2.internal to test
+ assertFalse(m2.isExported(p2Internal, thisModule));
+ Constructor> ctor = targetClass.getDeclaredConstructor();
+ try {
+ ctor.newInstance();
+ assertTrue(false);
+ } catch (IllegalAccessException expected) { }
+
+ // update m2 to export p2.internal to test
+ p2.C.export(p2Internal, thisModule);
+ assertTrue(m2.isExported(p2Internal, thisModule));
+ ctor.newInstance(); // should succeed
+
+ // attempt to update m2 to export a package to test
+ try {
+ m2.addExports("p2.other", thisModule);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ }
+
+ /**
+ * Test Module::addOpens
+ *
+ * module test {
+ * requires m3;
+ * requires m4;
+ * }
+ *
+ * module m3 {
+ * exports p3 to test;
+ * opens p3 to test;
+ * }
+ *
+ * module m4 {
+ * exports p4;
+ * }
+ */
+ public void testAddOpens() throws Exception {
+ Module thisModule = Main.class.getModule();
+ Module m3 = p3.C.class.getModule();
+ Module m4 = p4.C.class.getModule();
+
+ // test does not open package test to m4
+ assertFalse(thisModule.isOpen("test", m4));
+ try {
+ p4.C.tryNewInstance(test.C.class);
+ assertTrue(false);
+ } catch (IllegalAccessException expected) { }
+
+ // open test to m4
+ thisModule.addOpens("test", m4);
+ p4.C.tryNewInstance(test.C.class); // should succeed
+
+
+ // m3 does not open p3 to m4
+ assertFalse(m3.isOpen("p3", m4));
+ try {
+ p4.C.tryNewInstance(p3.C.class);
+ assertTrue(false);
+ } catch (IllegalAccessException expected) { }
+
+
+ // m3 opens p3 to test => test allowed to open m3/p3 to m4
+ assertTrue(m3.isOpen("p3", thisModule));
+ m3.addOpens("p3", m4);
+ assertTrue(m3.isOpen("p3", m4));
+ p4.C.tryNewInstance(p3.C.class); // should succeed
+
+
+ // attempt to update m4 to open package to m3
+ try {
+ m4.addOpens("p4", m3);
+ assertTrue(false);
+ } catch (IllegalCallerException expected) { }
+ }
+
+
+ /**
+ * Test Module::addUses
+ */
+ public void testAddUses() {
+ Module thisModule = Main.class.getModule();
+
+ assertFalse(thisModule.canUse(Service.class));
+ try {
+ ServiceLoader.load(Service.class);
+ assertTrue(false);
+ } catch (ServiceConfigurationError expected) { }
+
+ Module result = thisModule.addUses(Service.class);
+ assertTrue(result== thisModule);
+
+ assertTrue(thisModule.canUse(Service.class));
+ ServiceLoader.load(Service.class); // no exception
+ }
+
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/addXXX/test/test/Service.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/addXXX/test/test/Service.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ *
+ * 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 test;
+
+/**
+ * Simple service type
+ */
+public interface Service { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/allow.policy
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/allow.policy Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, 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.
+ *
+ * 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.
+ */
+
+grant {
+ permission java.lang.RuntimePermission "getClassLoader";
+ permission java.lang.RuntimePermission "accessSystemModules";
+ permission java.io.FilePermission "${java.home}/modules/-", "read"; // exploded build
+};
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/annotation/Basic.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/annotation/Basic.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library src
+ * @build m/* Basic
+ * @run testng/othervm Basic
+ * @summary Basic test for annotations on modules
+ */
+
+import java.util.Arrays;
+
+import p.annotation.Foo;
+import p.annotation.Bar;
+import p.annotation.Baz;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+public class Basic {
+
+ final Module module = Foo.class.getModule();
+
+ /**
+ * {@code @Foo} does not have RUNTIME retention policy.
+ */
+ @Test
+ public void testInvisibleAnnotation() {
+ assertFalse(module.isAnnotationPresent(Foo.class));
+ assertNull(module.getAnnotation(Foo.class));
+ }
+
+ /**
+ * {@code @Bar} has RUNTIME retention policy and value "bar"
+ */
+ @Test
+ public void testBarAnnotation() {
+ assertTrue(module.isAnnotationPresent(Bar.class));
+ Bar bar = module.getAnnotation(Bar.class);
+ assertNotNull(bar);
+ assertEquals(bar.value(), "bar");
+ }
+
+ /**
+ * {@code @Baz} has RUNTIME retention policy has a repeating value
+ */
+ @Test
+ public void testBazAnnotation() {
+ assertTrue(module.isAnnotationPresent(Baz.class));
+ Baz baz = module.getAnnotation(Baz.class);
+ assertNotNull(baz);
+ String[] expected = { "one", "two", "three" };
+ assertTrue(Arrays.equals(baz.value(), expected));
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/annotation/src/m/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/annotation/src/m/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.
+ */
+
+import p.annotation.*;
+
+@Foo
+@Bar("bar")
+@Baz({"one", "two", "three"})
+module m {
+ exports p.annotation;
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Bar.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Bar.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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 p.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.MODULE;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value={MODULE})
+public @interface Bar {
+ String value();
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Baz.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Baz.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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 p.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.MODULE;
+
+@Target(value={MODULE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Baz {
+ String[] value();
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Foo.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ModuleTests/annotation/src/m/p/annotation/Foo.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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 p.annotation;
+
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.MODULE;
+
+@Target(value={MODULE})
+public @interface Foo {}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/SecurityManager/CheckPackageAccess.java
--- a/jdk/test/java/lang/SecurityManager/CheckPackageAccess.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/SecurityManager/CheckPackageAccess.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
-import java.lang.reflect.Layer;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@@ -82,7 +81,7 @@
void test() {
final boolean isModulePresent =
- Layer.boot().findModule(moduleName).isPresent();
+ ModuleLayer.boot().findModule(moduleName).isPresent();
System.out.format("Testing module: %1$s. Module is%2$s present.\n",
moduleName, isModulePresent ? "" : " NOT");
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java
--- a/jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
* @run main/othervm CheckSecurityProvider
*/
-import java.lang.reflect.Layer;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
@@ -45,7 +44,7 @@
*/
public class CheckSecurityProvider {
public static void main(String[] args) throws Exception {
- Layer layer = Layer.boot();
+ ModuleLayer layer = ModuleLayer.boot();
System.setSecurityManager(new SecurityManager());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/SecurityManager/modules/Test.java
--- a/jdk/test/java/lang/SecurityManager/modules/Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/SecurityManager/modules/Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -21,8 +21,6 @@
* questions.
*/
-import java.lang.reflect.Module;
-
public class Test {
public static void main(String... args) {
SecurityManager sm = System.getSecurityManager();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/StackTraceElement/PublicConstructor.java
--- a/jdk/test/java/lang/StackTraceElement/PublicConstructor.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/StackTraceElement/PublicConstructor.java Wed Jul 05 23:13:02 2017 +0200
@@ -29,7 +29,6 @@
*/
import java.lang.module.ModuleDescriptor;
-import java.lang.reflect.Module;
public class PublicConstructor {
public static void main(String... args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/StackTraceElement/lib/m1/com/app/Utils.java
--- a/jdk/test/java/lang/StackTraceElement/lib/m1/com/app/Utils.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/StackTraceElement/lib/m1/com/app/Utils.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
import java.lang.StackWalker.StackFrame;
import java.lang.module.ModuleDescriptor;
-import java.lang.reflect.Module;
import java.util.Objects;
public class Utils {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/Logger/custom/CustomLoggerTest.java
--- a/jdk/test/java/lang/System/Logger/custom/CustomLoggerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/Logger/custom/CustomLoggerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -46,7 +46,6 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.stream.Stream;
-import java.lang.reflect.Module;
import java.security.AllPermission;
/**
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/BaseLoggerFinder.java
--- a/jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/BaseLoggerFinder.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/BaseLoggerFinder.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
import java.security.PrivilegedAction;
import java.lang.System.LoggerFinder;
import java.lang.System.Logger;
-import java.lang.reflect.Module;
public class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/TestLoggerFinder.java
--- a/jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/TestLoggerFinder.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/BaseLoggerFinderTest/TestLoggerFinder.java Wed Jul 05 23:13:02 2017 +0200
@@ -30,7 +30,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import java.lang.System.Logger;
-import java.lang.reflect.Module;
/**
* What our test provider needs to implement.
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/LoggerFinderAPI/LoggerFinderAPI.java
--- a/jdk/test/java/lang/System/LoggerFinder/LoggerFinderAPI/LoggerFinderAPI.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/LoggerFinderAPI/LoggerFinderAPI.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.System.LoggerFinder;
-import java.lang.reflect.Module;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Objects;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/BaseDefaultLoggerFinderTest/BaseDefaultLoggerFinderTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/BaseDefaultLoggerFinderTest/BaseDefaultLoggerFinderTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/BaseDefaultLoggerFinderTest/BaseDefaultLoggerFinderTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -55,7 +55,6 @@
import jdk.internal.logger.DefaultLoggerFinder;
import jdk.internal.logger.SimpleConsoleLogger;
import sun.util.logging.PlatformLogger;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/BaseLoggerBridgeTest/BaseLoggerBridgeTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/BaseLoggerBridgeTest/BaseLoggerBridgeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/BaseLoggerBridgeTest/BaseLoggerBridgeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -47,7 +47,6 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.stream.Stream;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/BasePlatformLoggerTest/BasePlatformLoggerTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/BasePlatformLoggerTest/BasePlatformLoggerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/BasePlatformLoggerTest/BasePlatformLoggerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -47,7 +47,6 @@
import java.security.AccessControlException;
import java.util.stream.Stream;
import sun.util.logging.PlatformLogger;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -30,7 +30,6 @@
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
-import java.lang.reflect.Module;
import jdk.internal.logger.BootstrapLogger;
import jdk.internal.logger.LazyLoggers;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.util.stream.Stream;
import jdk.internal.logger.BootstrapLogger;
import jdk.internal.logger.LazyLoggers;
-import java.lang.reflect.Module;
/*
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/LoggerBridgeTest/LoggerBridgeTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/LoggerBridgeTest/LoggerBridgeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/LoggerBridgeTest/LoggerBridgeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -51,7 +51,6 @@
import java.lang.System.Logger.Level;
import java.util.stream.Stream;
import sun.util.logging.PlatformLogger;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/LoggerFinderLoaderTest/LoggerFinderLoaderTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/LoggerFinderLoaderTest/LoggerFinderLoaderTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/LoggerFinderLoaderTest/LoggerFinderLoaderTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -53,7 +53,6 @@
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicReference;
import jdk.internal.logger.SimpleConsoleLogger;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -49,7 +49,6 @@
import java.lang.System.Logger.Level;
import java.util.stream.Stream;
import sun.util.logging.PlatformLogger;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Layer;
import java.lang.reflect.Method;
/*
@@ -106,7 +105,7 @@
}
Class> platformLoggerType = platformLogger.getClass();
System.out.println("platformLogger: " + platformLoggerType);
- boolean simpleConsoleOnly = !Layer.boot().findModule("java.logging").isPresent();
+ boolean simpleConsoleOnly = !ModuleLayer.boot().findModule("java.logging").isPresent();
if (simpleConsoleOnly) {
/* Happens if the test is called with custom JDK without java.logging module
or in case usage commandline option --limit-modules java.base */
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/internal/backend/LoggerFinderBackendTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/internal/backend/LoggerFinderBackendTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/internal/backend/LoggerFinderBackendTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -78,7 +78,6 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import sun.util.logging.internal.LoggingProviderImpl;
-import java.lang.reflect.Module;
/**
* @author danielfuchs
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/System/LoggerFinder/jdk/DefaultLoggerBridgeTest/DefaultLoggerBridgeTest.java
--- a/jdk/test/java/lang/System/LoggerFinder/jdk/DefaultLoggerBridgeTest/DefaultLoggerBridgeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/System/LoggerFinder/jdk/DefaultLoggerBridgeTest/DefaultLoggerBridgeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -48,7 +48,6 @@
import java.lang.System.Logger;
import java.util.stream.Stream;
import sun.util.logging.internal.LoggingProviderImpl;
-import java.lang.reflect.Module;
/**
* @test
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/WeakPairMap/Driver.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/WeakPairMap/Driver.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8888888
+ * @summary Functional test for WeakPairMap
+ * @build java.base/java.lang.WeakPairMapTest
+ * @run main Driver
+ */
+public class Driver {
+ public static void main(String[] args) {
+ java.lang.WeakPairMapTest.main(args);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/WeakPairMap/java.base/java/lang/WeakPairMapTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/WeakPairMap/java.base/java/lang/WeakPairMapTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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;
+
+import java.lang.ref.Reference;
+import java.util.Objects;
+
+/**
+ * Functional test for WeakPairMap
+ *
+ * @author Peter Levart
+ */
+public class WeakPairMapTest {
+ public static void main(String[] args) {
+ WeakPairMap pm = new WeakPairMap<>();
+ Object key1 = new Object();
+ Object key2 = new Object();
+
+ // check for emptiness
+ assertEquals(pm.containsKeyPair(key1, key2), false);
+ assertEquals(pm.get(key1, key2), null);
+
+ // check for NPE(s)
+ for (Object k1 : new Object[]{null, key1}) {
+ for (Object k2 : new Object[]{null, key2}) {
+ for (String v : new String[]{null, "abc"}) {
+
+ if (k1 != null && k2 != null && v != null) {
+ // skip non-null args
+ continue;
+ }
+
+ try {
+ pm.put(k1, k2, v);
+ throw new AssertionError("Unexpected code path, k1=" +
+ k1 + ", k2=" + k2 + ", v=" + v);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ pm.putIfAbsent(k1, k2, v);
+ throw new AssertionError("Unexpected code path, k1=" +
+ k1 + ", k2=" + k2 + ", v=" + v);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ if (k1 != null && k2 != null) {
+ // skip non-null args
+ continue;
+ }
+
+ try {
+ pm.computeIfAbsent(k1, k2, (_k1, _k2) -> v);
+ throw new AssertionError("Unexpected code path, k1=" +
+ k1 + ", k2=" + k2 + ", v=" + v);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ pm.containsKeyPair(k1, k2);
+ throw new AssertionError("Unexpected code path, k1=" +
+ k1 + ", k2=" + k2);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ pm.get(k1, k2);
+ throw new AssertionError("Unexpected code path, k1=" +
+ k1 + ", k2=" + k2);
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+ }
+ }
+
+ // how much to wait when it is expected for entry to be retained
+ final long retentionTimeout = 500L;
+ // how much to wait when it is expected for entry to be removed
+ final long cleanupTimeout = 30_000L;
+
+ // check insertion
+ assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check retention while both keys are still reachable
+ assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check cleanup when both keys are unreachable
+ key1 = null;
+ key2 = null;
+ assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
+
+ // new insertion
+ key1 = new Object();
+ key2 = new Object();
+ assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check retention while both keys are still reachable
+ assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check cleanup when 1st key is unreachable
+ key1 = null;
+ assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
+ Reference.reachabilityFence(key2);
+
+ // new insertion
+ key1 = new Object();
+ key2 = new Object();
+ assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check retention while both keys are still reachable
+ assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
+ assertEquals(pm.get(key1, key2), "abc");
+
+ // check cleanup when 2nd key is unreachable
+ key2 = null;
+ assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
+ Reference.reachabilityFence(key1);
+ }
+
+ /**
+ * Trigger GC and wait for at most {@code millis} ms for given value to
+ * be removed from given WeakPairMap.
+ *
+ * @return true if element has been removed or false if not
+ */
+ static boolean gcAndWaitRemoved(WeakPairMap, ?, V> pm, V value,
+ long millis) {
+ System.gc();
+ for (int i = 0; i < (millis + 99) / 100 && pm.values().contains(value); i++) {
+ try {
+ Thread.sleep(100L);
+ } catch (InterruptedException e) {
+ throw new AssertionError("Interrupted");
+ }
+ }
+ return !pm.values().contains(value);
+ }
+
+ static void assertEquals(Object actual, Object expected) {
+ if (!Objects.equals(actual, expected)) {
+ throw new AssertionError("Expected: " + expected + ", actual: " + actual);
+ }
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/ATransformerManagementTestCase.java
--- a/jdk/test/java/lang/instrument/ATransformerManagementTestCase.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/ATransformerManagementTestCase.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,8 +24,6 @@
import java.io.*;
import java.lang.instrument.*;
-
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
import java.util.*;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/BootstrapClassPathAgent.java
--- a/jdk/test/java/lang/instrument/BootstrapClassPathAgent.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/BootstrapClassPathAgent.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.io.*;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
public class BootstrapClassPathAgent {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/BootstrapClassPathTest.java
--- a/jdk/test/java/lang/instrument/BootstrapClassPathTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/BootstrapClassPathTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.io.*;
import java.lang.instrument.*;
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
public class BootstrapClassPathTest {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/RedefineClassWithNativeMethodAgent.java
--- a/jdk/test/java/lang/instrument/RedefineClassWithNativeMethodAgent.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/RedefineClassWithNativeMethodAgent.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
import java.io.InputStream;
import java.lang.instrument.ClassDefinition;
import java.lang.instrument.Instrumentation;
-import java.lang.reflect.Module;
import java.util.Timer;
import java.util.TimerTask;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/RedefineModuleAgent.java
--- a/jdk/test/java/lang/instrument/RedefineModuleAgent.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/RedefineModuleAgent.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -22,7 +22,6 @@
*/
import java.lang.instrument.Instrumentation;
-import java.lang.reflect.Module;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -47,4 +46,8 @@
Map, List>> extraProvides) {
inst.redefineModule(module, extraReads, extraExports, extraOpens, extraUses, extraProvides);
}
+
+ static boolean isModifiableModule(Module module) {
+ return inst.isModifiableModule(module);
+ }
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/RedefineModuleTest.java
--- a/jdk/test/java/lang/instrument/RedefineModuleTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/RedefineModuleTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -34,8 +34,6 @@
import java.lang.TestProvider;
import java.lang.instrument.Instrumentation;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.net.URLStreamHandler;
import java.net.spi.URLStreamHandlerProvider;
import java.nio.file.FileSystems;
@@ -68,6 +66,10 @@
extraProvides);
}
+ static boolean isModifiableModule(Module module) {
+ return RedefineModuleAgent.isModifiableModule(module);
+ }
+
/**
* Use redefineModule to update java.base to read java.instrument
@@ -138,13 +140,13 @@
// pre-conditions
assertFalse(baseModule.canUse(service));
assertTrue(collect(ServiceLoader.load(service)).isEmpty());
- assertTrue(collect(ServiceLoader.load(Layer.boot(), service)).isEmpty());
+ assertTrue(collect(ServiceLoader.load(ModuleLayer.boot(), service)).isEmpty());
// update java.base to use TestProvider
redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(service), Map.of());
assertTrue(baseModule.canUse(service));
assertTrue(collect(ServiceLoader.load(service)).isEmpty());
- assertTrue(collect(ServiceLoader.load(Layer.boot(), service)).isEmpty());
+ assertTrue(collect(ServiceLoader.load(ModuleLayer.boot(), service)).isEmpty());
// update java.base to provide an implementation of TestProvider
Class> type1 = Class.forName("jdk.internal.test.TestProviderImpl1");
@@ -162,7 +164,7 @@
assertTrue(containsInstanceOf(collect(providers), type1));
// use ServiceLoader to load implementations in the boot layer
- providers = collect(ServiceLoader.load(Layer.boot(), service));
+ providers = collect(ServiceLoader.load(ModuleLayer.boot(), service));
assertTrue(collect(providers).size() == 1);
assertTrue(containsInstanceOf(collect(providers), type1));
@@ -184,7 +186,7 @@
assertTrue(containsInstanceOf(providers, type2));
// use ServiceLoader to load implementations in the boot layer
- providers = collect(ServiceLoader.load(Layer.boot(), service));
+ providers = collect(ServiceLoader.load(ModuleLayer.boot(), service));
assertTrue(collect(providers).size() == 2);
assertTrue(containsInstanceOf(providers, type1));
assertTrue(containsInstanceOf(providers, type2));
@@ -279,6 +281,19 @@
}
/**
+ * Exercise IsModifiableModule
+ */
+ @Test
+ public void testIsModifiableModule() {
+ ClassLoader pcl = ClassLoader.getPlatformClassLoader();
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ assertTrue(isModifiableModule(pcl.getUnnamedModule()));
+ assertTrue(isModifiableModule(scl.getUnnamedModule()));
+ assertTrue(isModifiableModule(RedefineModuleTest.class.getModule()));
+ assertTrue(isModifiableModule(Object.class.getModule()));
+ }
+
+ /**
* Test redefineClass with null
*/
public void testNulls() {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/RetransformAgent.java
--- a/jdk/test/java/lang/instrument/RetransformAgent.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/RetransformAgent.java Wed Jul 05 23:13:02 2017 +0200
@@ -34,7 +34,6 @@
*/
import java.lang.instrument.*;
-import java.lang.reflect.Module;
import java.security.ProtectionDomain;
import java.io.*;
import asmlib.*;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/instrument/SimpleIdentityTransformer.java
--- a/jdk/test/java/lang/instrument/SimpleIdentityTransformer.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/instrument/SimpleIdentityTransformer.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
import java.lang.instrument.Instrumentation;
import java.lang.instrument.ClassFileTransformer;
-import java.lang.reflect.Module;
import java.security.*;
/*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java
--- a/jdk/test/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Module;
import static java.lang.invoke.MethodHandles.Lookup.*;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/invoke/modules/m1/p1/Main.java
--- a/jdk/test/java/lang/invoke/modules/m1/p1/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/invoke/modules/m1/p1/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -27,8 +27,6 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import static java.lang.invoke.MethodHandles.Lookup.*;
@@ -64,14 +62,14 @@
}
// check setup
- Module m1 = Layer.boot().findModule("m1").orElse(null);
+ Module m1 = ModuleLayer.boot().findModule("m1").orElse(null);
assertNotNull(m1);
assertTrue(p1_Type1.getModule() == m1);
assertTrue(p2_Type2.getModule() == m1);
assertTrue(m1.isExported("p1"));
assertFalse(m1.isExported("p2"));
- Module m2 = Layer.boot().findModule("m2").orElse(null);
+ Module m2 = ModuleLayer.boot().findModule("m2").orElse(null);
assertNotNull(m2);
assertTrue(q1_Type1.getModule() == m2);
assertTrue(q2_Type2.getModule() == m2);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/module/AutomaticModulesTest.java
--- a/jdk/test/java/lang/module/AutomaticModulesTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/module/AutomaticModulesTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -38,8 +38,6 @@
import java.lang.module.ModuleReference;
import java.lang.module.ResolutionException;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -69,13 +67,8 @@
{ "foo.jar", "foo" },
{ "foo4j.jar", "foo4j", },
- { "foo1.jar", "foo" },
- { "foo1.2.jar", "foo" },
- { "foo1.2.3.jar", "foo" },
-
- { "foo10.jar", "foo" },
- { "foo10.20.jar", "foo" },
- { "foo10.20.30.jar", "foo" },
+ { "foo1.jar", "foo1" },
+ { "foo10.jar", "foo10" },
{ "foo-1.jar", "foo/1" },
{ "foo-1.2.jar", "foo/1.2" },
@@ -93,6 +86,9 @@
{ "foo-bar-10.jar", "foo.bar/10" },
{ "foo-bar-10.20.jar", "foo.bar/10.20" },
+ { "foo.bar1.jar", "foo.bar1" },
+ { "foo.bar10.jar", "foo.bar10" },
+
{ "foo-1.2-SNAPSHOT.jar", "foo/1.2-SNAPSHOT" },
{ "foo-bar-1.2-SNAPSHOT.jar", "foo.bar/1.2-SNAPSHOT" },
@@ -108,8 +104,12 @@
public Object[][] createBadNames() {
return new Object[][]{
- { ".jar", null },
- { "_.jar", null }
+ { ".jar", null },
+ { "_.jar", null },
+
+ { "foo.1.jar", null },
+ { "1foo.jar", null },
+ { "foo.1bar.jar", null },
};
}
@@ -389,7 +389,7 @@
ModuleFinder finder = ModuleFinder.of(dir);
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "m");
ModuleDescriptor descriptor = findDescriptor(cf, "m");
@@ -469,11 +469,11 @@
createDummyJarFile(dir.resolve("c.jar"), "q/T.class");
// module finder locates a and the modules in the directory
- ModuleFinder finder
- = ModuleFinder.compose(ModuleUtils.finderOf(descriptor1),
- ModuleFinder.of(dir));
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "a");
assertTrue(cf.modules().size() == 3);
@@ -482,7 +482,7 @@
assertTrue(cf.findModule("c").isPresent());
ResolvedModule base = cf.findModule("java.base").get();
- assertTrue(base.configuration() == Layer.boot().configuration());
+ assertTrue(base.configuration() == ModuleLayer.boot().configuration());
ResolvedModule a = cf.findModule("a").get();
ResolvedModule b = cf.findModule("b").get();
ResolvedModule c = cf.findModule("c").get();
@@ -534,11 +534,11 @@
createDummyJarFile(dir.resolve("d.jar"), "q/T.class");
// module finder locates a and the modules in the directory
- ModuleFinder finder
- = ModuleFinder.compose(ModuleUtils.finderOf(descriptor1, descriptor2),
- ModuleFinder.of(dir));
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "a", "d");
assertTrue(cf.modules().size() == 4);
@@ -554,7 +554,7 @@
// readability
ResolvedModule base = cf.findModule("java.base").get();
- assertTrue(base.configuration() == Layer.boot().configuration());
+ assertTrue(base.configuration() == ModuleLayer.boot().configuration());
ResolvedModule a = cf.findModule("a").get();
ResolvedModule b = cf.findModule("b").get();
ResolvedModule c = cf.findModule("c").get();
@@ -607,11 +607,11 @@
createDummyJarFile(dir.resolve("d.jar"), "q/T.class");
// module finder locates a and the modules in the directory
- ModuleFinder finder
- = ModuleFinder.compose(ModuleUtils.finderOf(descriptor1, descriptor2),
- ModuleFinder.of(dir));
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "a", "d");
assertTrue(cf.modules().size() == 4);
@@ -621,7 +621,7 @@
assertTrue(cf.findModule("d").isPresent());
ResolvedModule base = cf.findModule("java.base").get();
- assertTrue(base.configuration() == Layer.boot().configuration());
+ assertTrue(base.configuration() == ModuleLayer.boot().configuration());
ResolvedModule a = cf.findModule("a").get();
ResolvedModule b = cf.findModule("b").get();
ResolvedModule c = cf.findModule("c").get();
@@ -661,6 +661,189 @@
/**
+ * Basic test to ensure that no automatic modules are resolved when
+ * an automatic module is not a root or required by other modules.
+ */
+ public void testInConfiguration4() throws IOException {
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1")
+ .requires("java.base")
+ .build();
+
+ // automatic modules
+ Path dir = Files.createTempDirectory(USER_DIR, "mods");
+ createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class");
+ createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class");
+ createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class");
+
+ // module finder locates m1 and the modules in the directory
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = resolve(parent, finder, "m1");
+
+ // ensure that no automatic module is resolved
+ assertTrue(cf.modules().size() == 1);
+ assertTrue(cf.findModule("m1").isPresent());
+ }
+
+
+ /**
+ * Basic test to ensure that if an automatic module is resolved then
+ * all observable automatic modules are resolved.
+ */
+ public void testInConfiguration5() throws IOException {
+ // m1 requires m2
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1")
+ .requires("m2").build();
+
+ // m2 requires automatic module
+ ModuleDescriptor descriptor2
+ = ModuleDescriptor.newModule("m2")
+ .requires("auto1")
+ .build();
+
+ // automatic modules
+ Path dir = Files.createTempDirectory(USER_DIR, "mods");
+ createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class");
+ createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class");
+ createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class");
+
+ // module finder locates m1, m2, and the modules in the directory
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf = resolve(parent, finder, "m1");
+
+ // all automatic modules should be resolved
+ assertTrue(cf.modules().size() == 5);
+ assertTrue(cf.findModule("m1").isPresent());
+ assertTrue(cf.findModule("m2").isPresent());
+ assertTrue(cf.findModule("auto1").isPresent());
+ assertTrue(cf.findModule("auto2").isPresent());
+ assertTrue(cf.findModule("auto3").isPresent());
+
+ ResolvedModule base = parent.findModule("java.base")
+ .orElseThrow(() -> new RuntimeException());
+ ResolvedModule m1 = cf.findModule("m1").get();
+ ResolvedModule m2 = cf.findModule("m2").get();
+ ResolvedModule auto1 = cf.findModule("auto1").get();
+ ResolvedModule auto2 = cf.findModule("auto2").get();
+ ResolvedModule auto3 = cf.findModule("auto3").get();
+
+ // m1 does not read the automatic modules
+ assertTrue(m1.reads().size() == 2);
+ assertTrue(m1.reads().contains(m2));
+ assertTrue(m1.reads().contains(base));
+
+ // m2 should read all the automatic modules
+ assertTrue(m2.reads().size() == 4);
+ assertTrue(m2.reads().contains(auto1));
+ assertTrue(m2.reads().contains(auto2));
+ assertTrue(m2.reads().contains(auto3));
+ assertTrue(m2.reads().contains(base));
+
+ assertTrue(auto1.reads().contains(m1));
+ assertTrue(auto1.reads().contains(m2));
+ assertTrue(auto1.reads().contains(auto2));
+ assertTrue(auto1.reads().contains(auto3));
+ assertTrue(auto1.reads().contains(base));
+
+ assertTrue(auto2.reads().contains(m1));
+ assertTrue(auto2.reads().contains(m2));
+ assertTrue(auto2.reads().contains(auto1));
+ assertTrue(auto2.reads().contains(auto3));
+ assertTrue(auto2.reads().contains(base));
+
+ assertTrue(auto3.reads().contains(m1));
+ assertTrue(auto3.reads().contains(m2));
+ assertTrue(auto3.reads().contains(auto1));
+ assertTrue(auto3.reads().contains(auto2));
+ assertTrue(auto3.reads().contains(base));
+ }
+
+
+ /**
+ * Basic test of automatic modules in a child configuration. All automatic
+ * modules that are found with the before finder should be resolved. The
+ * automatic modules that are found by the after finder and not shadowed
+ * by the before finder, or parent configurations, should also be resolved.
+ */
+ public void testInConfiguration6() throws IOException {
+ // m1 requires auto1
+ ModuleDescriptor descriptor1
+ = ModuleDescriptor.newModule("m1")
+ .requires("auto1")
+ .build();
+
+ Path dir = Files.createTempDirectory(USER_DIR, "mods");
+ createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class");
+
+ // module finder locates m1 and auto1
+ ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
+ ModuleFinder finder2 = ModuleFinder.of(dir);
+ ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
+
+ Configuration parent = ModuleLayer.boot().configuration();
+ Configuration cf1 = resolve(parent, finder, "m1");
+
+ assertTrue(cf1.modules().size() == 2);
+ assertTrue(cf1.findModule("m1").isPresent());
+ assertTrue(cf1.findModule("auto1").isPresent());
+
+ ResolvedModule base = parent.findModule("java.base")
+ .orElseThrow(() -> new RuntimeException());
+ ResolvedModule m1 = cf1.findModule("m1").get();
+ ResolvedModule auto1 = cf1.findModule("auto1").get();
+
+ assertTrue(m1.reads().size() == 2);
+ assertTrue(m1.reads().contains(auto1));
+ assertTrue(m1.reads().contains(base));
+
+ assertTrue(auto1.reads().contains(m1));
+ assertTrue(auto1.reads().contains(base));
+
+
+ // create child configuration - the after finder locates auto1
+
+ dir = Files.createTempDirectory(USER_DIR, "mods");
+ createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class");
+ ModuleFinder beforeFinder = ModuleFinder.of(dir);
+
+ dir = Files.createTempDirectory(USER_DIR, "mods");
+ createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class");
+ createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class");
+ createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class");
+ ModuleFinder afterFinder = ModuleFinder.of(dir);
+
+ Configuration cf2 = cf1.resolve(beforeFinder, afterFinder, Set.of("auto2"));
+
+ // auto1 should be found in parent and should not be in cf2
+ assertTrue(cf2.modules().size() == 2);
+ assertTrue(cf2.findModule("auto2").isPresent());
+ assertTrue(cf2.findModule("auto3").isPresent());
+
+ ResolvedModule auto2 = cf2.findModule("auto2").get();
+ ResolvedModule auto3 = cf2.findModule("auto3").get();
+
+ assertTrue(auto2.reads().contains(m1));
+ assertTrue(auto2.reads().contains(auto1));
+ assertTrue(auto2.reads().contains(auto3));
+ assertTrue(auto2.reads().contains(base));
+
+ assertTrue(auto3.reads().contains(m1));
+ assertTrue(auto3.reads().contains(auto1));
+ assertTrue(auto3.reads().contains(auto2));
+ assertTrue(auto3.reads().contains(base));
+ }
+
+
+ /**
* Basic test of a configuration created with automatic modules
* a requires b* and c*
* b* contains p
@@ -684,7 +867,7 @@
= ModuleFinder.compose(ModuleUtils.finderOf(descriptor),
ModuleFinder.of(dir));
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
resolve(parent, finder, "a");
}
@@ -711,13 +894,13 @@
= ModuleFinder.compose(ModuleUtils.finderOf(descriptor),
ModuleFinder.of(dir));
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
resolve(parent, finder, "a");
}
/**
- * Basic test of Layer containing automatic modules
+ * Basic test of layer containing automatic modules
*/
public void testInLayer() throws IOException {
ModuleDescriptor descriptor
@@ -736,12 +919,12 @@
= ModuleFinder.compose(ModuleUtils.finderOf(descriptor),
ModuleFinder.of(dir));
- Configuration parent = Layer.boot().configuration();
+ Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "a");
assertTrue(cf.modules().size() == 3);
// each module gets its own loader
- Layer layer = Layer.boot().defineModules(cf, mn -> new ClassLoader() { });
+ ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> new ClassLoader() { });
// an unnamed module
Module unnamed = (new ClassLoader() { }).getUnnamedModule();
@@ -804,7 +987,7 @@
*/
static void testReadAllBootModules(Configuration cf, String mn) {
- Set bootModules = Layer.boot().modules().stream()
+ Set bootModules = ModuleLayer.boot().modules().stream()
.map(Module::getName)
.collect(Collectors.toSet());
@@ -813,10 +996,10 @@
}
/**
- * Test that the given Module reads all module in the given Layer
- * and its parent Layers.
+ * Test that the given Module reads all module in the given layer
+ * and its parent layers.
*/
- static void testsReadsAll(Module m, Layer layer) {
+ static void testsReadsAll(Module m, ModuleLayer layer) {
// check that m reads all modules in the layer
layer.configuration().modules().stream()
.map(ResolvedModule::name)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/module/ConfigurationTest.java
--- a/jdk/test/java/lang/module/ConfigurationTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/module/ConfigurationTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -40,7 +40,6 @@
import java.lang.module.ModuleFinder;
import java.lang.module.ResolutionException;
import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
@@ -1708,7 +1707,7 @@
ModuleFinder finder = ModuleUtils.finderOf(descriptor);
- Configuration bootConfiguration = Layer.boot().configuration();
+ Configuration bootConfiguration = ModuleLayer.boot().configuration();
// m1 contains package java.lang, java.base exports package java.lang to m1
resolve(bootConfiguration, finder, "m1");
@@ -1989,14 +1988,14 @@
@Test(expectedExceptions = { NullPointerException.class })
public void testResolveRequiresWithNull5() {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
Configuration.resolve(ModuleFinder.of(), List.of(cf), null, Set.of());
}
@Test(expectedExceptions = { NullPointerException.class })
public void testResolveRequiresWithNull6() {
ModuleFinder empty = ModuleFinder.of();
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
Configuration.resolve(empty, List.of(cf), empty, null);
}
@@ -2024,14 +2023,14 @@
@Test(expectedExceptions = { NullPointerException.class })
public void testResolveRequiresAndUsesWithNull5() {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
Configuration.resolveAndBind(ModuleFinder.of(), List.of(cf), null, Set.of());
}
@Test(expectedExceptions = { NullPointerException.class })
public void testResolveRequiresAndUsesWithNull6() {
ModuleFinder empty = ModuleFinder.of();
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
Configuration.resolveAndBind(empty, List.of(cf), empty, null);
}
@@ -2044,14 +2043,14 @@
@Test(expectedExceptions = { UnsupportedOperationException.class })
public void testImmutableSet1() {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule base = cf.findModule("java.base").get();
cf.modules().add(base);
}
@Test(expectedExceptions = { UnsupportedOperationException.class })
public void testImmutableSet2() {
- Configuration cf = Layer.boot().configuration();
+ Configuration cf = ModuleLayer.boot().configuration();
ResolvedModule base = cf.findModule("java.base").get();
base.reads().add(base);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/module/ModuleDescriptorTest.java
--- a/jdk/test/java/lang/module/ModuleDescriptorTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/module/ModuleDescriptorTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -41,7 +41,6 @@
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires.Modifier;
import java.lang.module.ModuleDescriptor.Version;
-import java.lang.reflect.Module;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/module/ModuleFinderTest.java
--- a/jdk/test/java/lang/module/ModuleFinderTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/module/ModuleFinderTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -529,6 +529,30 @@
/**
+ * Test ModuleFinder.of with a directory containing hidden files
+ */
+ public void testOfWithHiddenFiles() throws Exception {
+ Path dir = Files.createTempDirectory(USER_DIR, "mods");
+ createExplodedModule(dir.resolve("m"), "m",
+ "com/.ignore",
+ "com/foo/.ignore",
+ "com/foo/foo.properties");
+
+ ModuleFinder finder = ModuleFinder.of(dir);
+ ModuleReference mref = finder.find("m").orElse(null);
+ assertNotNull(mref);
+
+ Set expectedPackages;
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ expectedPackages = Set.of("com", "com.foo");
+ } else {
+ expectedPackages = Set.of("com.foo");
+ }
+ assertEquals(mref.descriptor().packages(), expectedPackages);
+ }
+
+
+ /**
* Test ModuleFinder.of with a truncated module-info.class
*/
public void testOfWithTruncatedModuleInfo() throws Exception {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/module/ModuleReader/ModuleReaderTest.java
--- a/jdk/test/java/lang/module/ModuleReader/ModuleReaderTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/module/ModuleReader/ModuleReaderTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -37,7 +37,6 @@
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
-import java.lang.reflect.Module;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java
--- a/jdk/test/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -36,7 +36,6 @@
import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Module;
import jdk.internal.misc.Unsafe;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/BasicLayerTest.java
--- a/jdk/test/java/lang/reflect/Layer/BasicLayerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1219 +0,0 @@
-/*
- * Copyright (c) 2014, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @library /lib/testlibrary
- * @modules java.base/jdk.internal.misc
- * @build BasicLayerTest ModuleUtils
- * @compile layertest/Test.java
- * @run testng BasicLayerTest
- * @summary Basic tests for java.lang.reflect.Layer
- */
-
-import java.lang.module.Configuration;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleDescriptor.Requires;
-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.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import jdk.internal.misc.SharedSecrets;
-
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-@Test
-public class BasicLayerTest {
-
- /**
- * Creates a "non-strict" builder for building a module. This allows the
- * test the create ModuleDescriptor objects that do not require java.base.
- */
- private static ModuleDescriptor.Builder newBuilder(String mn) {
- return SharedSecrets.getJavaLangModuleAccess()
- .newModuleBuilder(mn, false, Set.of());
- }
-
- /**
- * Exercise Layer.empty()
- */
- public void testEmpty() {
- Layer emptyLayer = Layer.empty();
-
- assertTrue(emptyLayer.parents().isEmpty());
-
- assertTrue(emptyLayer.configuration() == Configuration.empty());
-
- assertTrue(emptyLayer.modules().isEmpty());
-
- assertFalse(emptyLayer.findModule("java.base").isPresent());
-
- try {
- emptyLayer.findLoader("java.base");
- assertTrue(false);
- } catch (IllegalArgumentException expected) { }
- }
-
-
- /**
- * Exercise Layer.boot()
- */
- public void testBoot() {
- Layer bootLayer = Layer.boot();
-
- // configuration
- Configuration cf = bootLayer.configuration();
- assertTrue(cf.findModule("java.base").get()
- .reference()
- .descriptor()
- .exports()
- .stream().anyMatch(e -> (e.source().equals("java.lang")
- && !e.isQualified())));
-
- // modules
- Set modules = bootLayer.modules();
- assertTrue(modules.contains(Object.class.getModule()));
- int count = (int) modules.stream().map(Module::getName).count();
- assertEquals(count, modules.size()); // module names are unique
-
- // findModule
- Module base = Object.class.getModule();
- assertTrue(bootLayer.findModule("java.base").get() == base);
- assertTrue(base.getLayer() == bootLayer);
-
- // findLoader
- assertTrue(bootLayer.findLoader("java.base") == null);
-
- // parents
- assertTrue(bootLayer.parents().size() == 1);
- assertTrue(bootLayer.parents().get(0) == Layer.empty());
- }
-
-
- /**
- * Exercise Layer defineModules, created with empty layer as parent
- */
- public void testLayerOnEmpty() {
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .requires("m2")
- .exports("p1")
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires("m3")
- .build();
-
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .build();
-
- ModuleFinder finder
- = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);
-
- Configuration cf = resolve(finder, "m1");
-
- // map each module to its own class loader for this test
- ClassLoader loader1 = new ClassLoader() { };
- ClassLoader loader2 = new ClassLoader() { };
- ClassLoader loader3 = new ClassLoader() { };
- Map map = new HashMap<>();
- map.put("m1", loader1);
- map.put("m2", loader2);
- map.put("m3", loader3);
-
- Layer layer = Layer.empty().defineModules(cf, map::get);
-
- // configuration
- assertTrue(layer.configuration() == cf);
- assertTrue(layer.configuration().modules().size() == 3);
-
- // modules
- Set modules = layer.modules();
- assertTrue(modules.size() == 3);
- Set names = modules.stream()
- .map(Module::getName)
- .collect(Collectors.toSet());
- assertTrue(names.contains("m1"));
- assertTrue(names.contains("m2"));
- assertTrue(names.contains("m3"));
-
- // findModule
- Module m1 = layer.findModule("m1").get();
- Module m2 = layer.findModule("m2").get();
- Module m3 = layer.findModule("m3").get();
- assertEquals(m1.getName(), "m1");
- assertEquals(m2.getName(), "m2");
- assertEquals(m3.getName(), "m3");
- assertTrue(m1.getDescriptor() == descriptor1);
- assertTrue(m2.getDescriptor() == descriptor2);
- assertTrue(m3.getDescriptor() == descriptor3);
- assertTrue(m1.getLayer() == layer);
- assertTrue(m2.getLayer() == layer);
- assertTrue(m3.getLayer() == layer);
- assertTrue(modules.contains(m1));
- assertTrue(modules.contains(m2));
- assertTrue(modules.contains(m3));
- assertFalse(layer.findModule("godot").isPresent());
-
- // findLoader
- assertTrue(layer.findLoader("m1") == loader1);
- assertTrue(layer.findLoader("m2") == loader2);
- assertTrue(layer.findLoader("m3") == loader3);
- try {
- ClassLoader loader = layer.findLoader("godot");
- assertTrue(false);
- } catch (IllegalArgumentException ignore) { }
-
- // parents
- assertTrue(layer.parents().size() == 1);
- assertTrue(layer.parents().get(0) == Layer.empty());
- }
-
-
- /**
- * Exercise Layer defineModules, created with boot layer as parent
- */
- public void testLayerOnBoot() {
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .requires("m2")
- .requires("java.base")
- .exports("p1")
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires("java.base")
- .build();
-
- ModuleFinder finder
- = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration parent = Layer.boot().configuration();
- Configuration cf = resolve(parent, finder, "m1");
-
- ClassLoader loader = new ClassLoader() { };
-
- Layer layer = Layer.boot().defineModules(cf, mn -> loader);
-
- // configuration
- assertTrue(layer.configuration() == cf);
- assertTrue(layer.configuration().modules().size() == 2);
-
- // modules
- Set modules = layer.modules();
- assertTrue(modules.size() == 2);
- Set names = modules.stream()
- .map(Module::getName)
- .collect(Collectors.toSet());
- assertTrue(names.contains("m1"));
- assertTrue(names.contains("m2"));
-
- // findModule
- Module m1 = layer.findModule("m1").get();
- Module m2 = layer.findModule("m2").get();
- assertEquals(m1.getName(), "m1");
- assertEquals(m2.getName(), "m2");
- assertTrue(m1.getDescriptor() == descriptor1);
- assertTrue(m2.getDescriptor() == descriptor2);
- assertTrue(m1.getLayer() == layer);
- assertTrue(m2.getLayer() == layer);
- assertTrue(modules.contains(m1));
- assertTrue(modules.contains(m2));
- assertTrue(layer.findModule("java.base").get() == Object.class.getModule());
- assertFalse(layer.findModule("godot").isPresent());
-
- // findLoader
- assertTrue(layer.findLoader("m1") == loader);
- assertTrue(layer.findLoader("m2") == loader);
- assertTrue(layer.findLoader("java.base") == null);
-
- // parents
- assertTrue(layer.parents().size() == 1);
- assertTrue(layer.parents().get(0) == Layer.boot());
- }
-
-
- /**
- * Exercise Layer defineModules with a configuration of two modules that
- * have the same module-private package.
- */
- public void testPackageContainedInSelfAndOther() {
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .requires("m2")
- .packages(Set.of("p"))
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .packages(Set.of("p"))
- .build();
-
- ModuleFinder finder
- = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf = resolve(finder, "m1");
- assertTrue(cf.modules().size() == 2);
-
- // one loader per module, should be okay
- Layer.empty().defineModules(cf, mn -> new ClassLoader() { });
-
- // same class loader
- try {
- ClassLoader loader = new ClassLoader() { };
- Layer.empty().defineModules(cf, mn -> loader);
- assertTrue(false);
- } catch (LayerInstantiationException expected) { }
- }
-
-
- /**
- * Exercise Layer defineModules with a configuration that is a partitioned
- * graph. The same package is exported in both partitions.
- */
- public void testSameExportInPartitionedGraph() {
-
- // m1 reads m2, m2 exports p to m1
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .requires("m2")
- .build();
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .exports("p", Set.of("m1"))
- .build();
-
- // m3 reads m4, m4 exports p to m3
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires("m4")
- .build();
- ModuleDescriptor descriptor4 = newBuilder("m4")
- .exports("p", Set.of("m3"))
- .build();
-
- ModuleFinder finder
- = ModuleUtils.finderOf(descriptor1,
- descriptor2,
- descriptor3,
- descriptor4);
-
- Configuration cf = resolve(finder, "m1", "m3");
- assertTrue(cf.modules().size() == 4);
-
- // one loader per module
- Layer.empty().defineModules(cf, mn -> new ClassLoader() { });
-
- // m1 & m2 in one loader, m3 & m4 in another loader
- ClassLoader loader1 = new ClassLoader() { };
- ClassLoader loader2 = new ClassLoader() { };
- Map map = new HashMap<>();
- map.put("m1", loader1);
- map.put("m2", loader1);
- map.put("m3", loader2);
- map.put("m4", loader2);
- Layer.empty().defineModules(cf, map::get);
-
- // same loader
- try {
- ClassLoader loader = new ClassLoader() { };
- Layer.empty().defineModules(cf, mn -> loader);
- assertTrue(false);
- } catch (LayerInstantiationException expected) { }
- }
-
-
- /**
- * Exercise Layer defineModules with a configuration with a module that
- * contains a package that is the same name as a non-exported package in
- * a parent layer.
- */
- public void testContainsSamePackageAsBootLayer() {
-
- // check assumption that java.base contains sun.launcher
- ModuleDescriptor base = Object.class.getModule().getDescriptor();
- assertTrue(base.packages().contains("sun.launcher"));
-
- ModuleDescriptor descriptor = newBuilder("m1")
- .requires("java.base")
- .packages(Set.of("sun.launcher"))
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor);
-
- Configuration parent = Layer.boot().configuration();
- Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
- assertTrue(cf.modules().size() == 1);
-
- ClassLoader loader = new ClassLoader() { };
- Layer layer = Layer.boot().defineModules(cf, mn -> loader);
- assertTrue(layer.modules().size() == 1);
- }
-
-
- /**
- * Test layers with implied readability.
- *
- * The test consists of three configurations:
- * - Configuration/layer1: m1, m2 requires transitive m1
- * - Configuration/layer2: m3 requires m1
- */
- public void testImpliedReadabilityWithLayers1() {
-
- // cf1: m1 and m2, m2 requires transitive m1
-
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
- .build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf1 = resolve(finder1, "m2");
-
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
-
-
- // cf2: m3, m3 requires m2
-
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires("m2")
- .build();
-
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3);
-
- Configuration cf2 = resolve(cf1, finder2, "m3");
-
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
-
- assertTrue(layer1.parents().size() == 1);
- assertTrue(layer1.parents().get(0) == Layer.empty());
-
- assertTrue(layer2.parents().size() == 1);
- assertTrue(layer2.parents().get(0) == layer1);
-
- Module m1 = layer2.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
- Module m3 = layer2.findModule("m3").get();
-
- assertTrue(m1.getLayer() == layer1);
- assertTrue(m2.getLayer() == layer1);
- assertTrue(m3.getLayer() == layer2);
-
- assertTrue(m1.getClassLoader() == cl1);
- assertTrue(m2.getClassLoader() == cl1);
- assertTrue(m3.getClassLoader() == cl2);
-
- assertTrue(m1.canRead(m1));
- assertFalse(m1.canRead(m2));
- assertFalse(m1.canRead(m3));
-
- assertTrue(m2.canRead(m1));
- assertTrue(m2.canRead(m2));
- assertFalse(m2.canRead(m3));
-
- assertTrue(m3.canRead(m1));
- assertTrue(m3.canRead(m2));
- assertTrue(m3.canRead(m3));
- }
-
-
- /**
- * Test layers with implied readability.
- *
- * The test consists of three configurations:
- * - Configuration/layer1: m1
- * - Configuration/layer2: m2 requires transitive m3, m3 requires m2
- */
- public void testImpliedReadabilityWithLayers2() {
-
- // cf1: m1
-
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
-
- Configuration cf1 = resolve(finder1, "m1");
-
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
-
-
- // cf2: m2, m3: m2 requires transitive m1, m3 requires m2
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
- .build();
-
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires("m2")
- .build();
-
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2, descriptor3);
-
- Configuration cf2 = resolve(cf1, finder2, "m3");
-
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
-
- assertTrue(layer1.parents().size() == 1);
- assertTrue(layer1.parents().get(0) == Layer.empty());
-
- assertTrue(layer2.parents().size() == 1);
- assertTrue(layer2.parents().get(0) == layer1);
-
- Module m1 = layer2.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
- Module m3 = layer2.findModule("m3").get();
-
- assertTrue(m1.getLayer() == layer1);
- assertTrue(m2.getLayer() == layer2);
- assertTrue(m3.getLayer() == layer2);
-
- assertTrue(m1.canRead(m1));
- assertFalse(m1.canRead(m2));
- assertFalse(m1.canRead(m3));
-
- assertTrue(m2.canRead(m1));
- assertTrue(m2.canRead(m2));
- assertFalse(m2.canRead(m3));
-
- assertTrue(m3.canRead(m1));
- assertTrue(m3.canRead(m2));
- assertTrue(m3.canRead(m3));
- }
-
-
- /**
- * Test layers with implied readability.
- *
- * The test consists of three configurations:
- * - Configuration/layer1: m1
- * - Configuration/layer2: m2 requires transitive m1
- * - Configuration/layer3: m3 requires m1
- */
- public void testImpliedReadabilityWithLayers3() {
-
- // cf1: m1
-
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
-
- Configuration cf1 = resolve(finder1, "m1");
-
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
-
-
- // cf2: m2 requires transitive m1
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
- .build();
-
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
-
- Configuration cf2 = resolve(cf1, finder2, "m2");
-
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
-
-
- // cf3: m3 requires m2
-
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires("m2")
- .build();
-
- ModuleFinder finder3 = ModuleUtils.finderOf(descriptor3);
-
- Configuration cf3 = resolve(cf2, finder3, "m3");
-
- ClassLoader cl3 = new ClassLoader() { };
- Layer layer3 = layer2.defineModules(cf3, mn -> cl3);
-
- assertTrue(layer1.parents().size() == 1);
- assertTrue(layer1.parents().get(0) == Layer.empty());
-
- assertTrue(layer2.parents().size() == 1);
- assertTrue(layer2.parents().get(0) == layer1);
-
- assertTrue(layer3.parents().size() == 1);
- assertTrue(layer3.parents().get(0) == layer2);
-
- Module m1 = layer3.findModule("m1").get();
- Module m2 = layer3.findModule("m2").get();
- Module m3 = layer3.findModule("m3").get();
-
- assertTrue(m1.getLayer() == layer1);
- assertTrue(m2.getLayer() == layer2);
- assertTrue(m3.getLayer() == layer3);
-
- assertTrue(m1.canRead(m1));
- assertFalse(m1.canRead(m2));
- assertFalse(m1.canRead(m3));
-
- assertTrue(m2.canRead(m1));
- assertTrue(m2.canRead(m2));
- assertFalse(m2.canRead(m3));
-
- assertTrue(m3.canRead(m1));
- assertTrue(m3.canRead(m2));
- assertTrue(m3.canRead(m3));
- }
-
-
- /**
- * Test layers with implied readability.
- *
- * The test consists of two configurations:
- * - Configuration/layer1: m1, m2 requires transitive m1
- * - Configuration/layer2: m3 requires transitive m2, m4 requires m3
- */
- public void testImpliedReadabilityWithLayers4() {
-
- // cf1: m1, m2 requires transitive m1
-
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
- .build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf1 = resolve(finder1, "m2");
-
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
-
-
- // cf2: m3 requires transitive m2, m4 requires m3
-
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m2")
- .build();
-
- ModuleDescriptor descriptor4 = newBuilder("m4")
- .requires("m3")
- .build();
-
-
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4);
-
- Configuration cf2 = resolve(cf1, finder2, "m3", "m4");
-
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
-
- assertTrue(layer1.parents().size() == 1);
- assertTrue(layer1.parents().get(0) == Layer.empty());
-
- assertTrue(layer2.parents().size() == 1);
- assertTrue(layer2.parents().get(0) == layer1);
-
- Module m1 = layer2.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
- Module m3 = layer2.findModule("m3").get();
- Module m4 = layer2.findModule("m4").get();
-
- assertTrue(m1.getLayer() == layer1);
- assertTrue(m2.getLayer() == layer1);
- assertTrue(m3.getLayer() == layer2);
- assertTrue(m4.getLayer() == layer2);
-
- assertTrue(m1.canRead(m1));
- assertFalse(m1.canRead(m2));
- assertFalse(m1.canRead(m3));
- assertFalse(m1.canRead(m4));
-
- assertTrue(m2.canRead(m1));
- assertTrue(m2.canRead(m2));
- assertFalse(m1.canRead(m3));
- assertFalse(m1.canRead(m4));
-
- assertTrue(m3.canRead(m1));
- assertTrue(m3.canRead(m2));
- assertTrue(m3.canRead(m3));
- assertFalse(m3.canRead(m4));
-
- assertTrue(m4.canRead(m1));
- assertTrue(m4.canRead(m2));
- assertTrue(m4.canRead(m3));
- assertTrue(m4.canRead(m4));
- }
-
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * does not read the target module.
- *
- * m1 { exports p to m2 }
- * m2 { }
- */
- public void testQualifiedExports1() {
- ModuleDescriptor descriptor1 = newBuilder("m1").
- exports("p", Set.of("m2"))
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf = resolve(finder1, "m1", "m2");
-
- ClassLoader cl = new ClassLoader() { };
- Layer layer = Layer.empty().defineModules(cf, mn -> cl);
- assertTrue(layer.modules().size() == 2);
-
- Module m1 = layer.findModule("m1").get();
- Module m2 = layer.findModule("m2").get();
-
- // check m1 exports p to m2
- assertFalse(m1.isExported("p"));
- assertTrue(m1.isExported("p", m2));
- assertFalse(m1.isOpen("p", m2));
- }
-
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * reads the target module.
- *
- * m1 { exports p to m2; }
- * m2 { requires m1; }
- */
- public void testQualifiedExports2() {
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .exports("p", Set.of("m2"))
- .build();
-
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires("m1")
- .build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf = resolve(finder1, "m2");
- ClassLoader cl = new ClassLoader() { };
- Layer layer = Layer.empty().defineModules(cf, mn -> cl);
- assertTrue(layer.modules().size() == 2);
-
- Module m1 = layer.findModule("m1").get();
- Module m2 = layer.findModule("m2").get();
-
- // check m1 exports p to m2
- assertFalse(m1.isExported("p"));
- assertTrue(m1.isExported("p", m2));
- assertFalse(m1.isOpen("p", m2));
- }
-
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * does not read the target module in the parent layer.
- *
- * - Configuration/layer1: m1 { }
- * - Configuration/layer2: m2 { exports p to m1; }
- */
- public void testQualifiedExports3() {
- // create layer1 with m1
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
- Configuration cf1 = resolve(finder1, "m1");
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
- assertTrue(layer1.modules().size() == 1);
-
- // create layer2 with m2
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .exports("p", Set.of("m1"))
- .build();
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
- Configuration cf2 = resolve(cf1, finder2, "m2");
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
- assertTrue(layer2.modules().size() == 1);
-
- Module m1 = layer1.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
-
- // check m2 exports p to layer1/m1
- assertFalse(m2.isExported("p"));
- assertTrue(m2.isExported("p", m1));
- assertFalse(m2.isOpen("p", m1));
- }
-
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * reads the target module in the parent layer.
- *
- * - Configuration/layer1: m1 { }
- * - Configuration/layer2: m2 { requires m1; exports p to m1; }
- */
- public void testQualifiedExports4() {
- // create layer1 with m1
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
- Configuration cf1 = resolve(finder1, "m1");
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
- assertTrue(layer1.modules().size() == 1);
-
- // create layer2 with m2
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires("m1")
- .exports("p", Set.of("m1"))
- .build();
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
- Configuration cf2 = resolve(cf1, finder2, "m2");
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
- assertTrue(layer2.modules().size() == 1);
-
- Module m1 = layer1.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
-
- // check m2 exports p to layer1/m1
- assertFalse(m2.isExported("p"));
- assertTrue(m2.isExported("p", m1));
- assertFalse(m2.isOpen("p", m1));
- }
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * does not read the target module.
- *
- * - Configuration/layer1: m1
- * - Configuration/layer2: m1, m2 { exports p to m1; }
- */
- public void testQualifiedExports5() {
- // create layer1 with m1
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
- Configuration cf1 = resolve(finder1, "m1");
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
- assertTrue(layer1.modules().size() == 1);
-
- // create layer2 with m1 and m2
- ModuleDescriptor descriptor2 = newBuilder("m2").exports("p", Set.of("m1")).build();
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor2);
- Configuration cf2 = resolve(cf1, finder2, "m1", "m2");
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
- assertTrue(layer2.modules().size() == 2);
-
- Module m1_v1 = layer1.findModule("m1").get();
- Module m1_v2 = layer2.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
-
- // check m2 exports p to layer2/m2
- assertFalse(m2.isExported("p"));
- assertTrue(m2.isExported("p", m1_v2));
- assertFalse(m2.isExported("p", m1_v1));
- }
-
-
- /**
- * Test layers with a qualified export. The module exporting the package
- * reads the target module in the parent layer (due to requires transitive).
- *
- * - Configuration/layer1: m1, m2 { requires transitive m1; }
- * - Configuration/layer2: m1, m3 { requires m2; exports p to m1; }
- */
- public void testQualifiedExports6() {
- // create layer1 with m1 and m2
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
- .build();
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
- Configuration cf1 = resolve(finder1, "m2");
- ClassLoader loader1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> loader1);
- assertTrue(layer1.modules().size() == 2);
-
- // create layer2 with m1 and m3
- ModuleDescriptor descriptor3 = newBuilder("m3")
- .requires("m2")
- .exports("p", Set.of("m1"))
- .build();
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3);
- Configuration cf2 = resolve(cf1, finder2, "m1", "m3");
- ClassLoader loader2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> loader2);
- assertTrue(layer2.modules().size() == 2);
-
- Module m1_v1 = layer1.findModule("m1").get();
- Module m2 = layer1.findModule("m2").get();
-
- Module m1_v2 = layer2.findModule("m1").get();
- Module m3 = layer2.findModule("m3").get();
-
- assertTrue(m3.canRead(m1_v1));
- assertFalse(m3.canRead(m1_v2));
-
- assertFalse(m3.isExported("p"));
- assertTrue(m3.isExported("p", m1_v1));
- assertFalse(m3.isExported("p", m1_v2));
- assertFalse(m3.isExported("p", m2));
- }
-
-
- /**
- * Test layers with a qualified export. The target module is not in any layer.
- *
- * - Configuration/layer1: m1 { }
- * - Configuration/layer2: m2 { exports p to m3; }
- */
- public void testQualifiedExports7() {
- // create layer1 with m1
- ModuleDescriptor descriptor1 = newBuilder("m1").build();
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
- Configuration cf1 = resolve(finder1, "m1");
- ClassLoader cl1 = new ClassLoader() { };
- Layer layer1 = Layer.empty().defineModules(cf1, mn -> cl1);
- assertTrue(layer1.modules().size() == 1);
-
- // create layer2 with m2
- ModuleDescriptor descriptor2 = newBuilder("m2")
- .exports("p", Set.of("m3"))
- .build();
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
- Configuration cf2 = resolve(cf1, finder2, "m2");
- ClassLoader cl2 = new ClassLoader() { };
- Layer layer2 = layer1.defineModules(cf2, mn -> cl2);
- assertTrue(layer2.modules().size() == 1);
-
- Module m1 = layer1.findModule("m1").get();
- Module m2 = layer2.findModule("m2").get();
-
- // check m2 does not export p to anyone
- assertFalse(m2.isExported("p"));
- assertFalse(m2.isExported("p", m1));
- }
-
- /**
- * Attempt to use Layer defineModules to create a layer with a module
- * defined to a class loader that already has a module of the same name
- * defined to the class loader.
- */
- @Test(expectedExceptions = { LayerInstantiationException.class })
- public void testModuleAlreadyDefinedToLoader() {
-
- ModuleDescriptor md = newBuilder("m")
- .requires("java.base")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(md);
-
- Configuration parent = Layer.boot().configuration();
-
- Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
-
- ClassLoader loader = new ClassLoader() { };
-
- Layer.boot().defineModules(cf, mn -> loader);
-
- // should throw LayerInstantiationException as m1 already defined to loader
- Layer.boot().defineModules(cf, mn -> loader);
-
- }
-
-
- /**
- * Attempt to use Layer defineModules to create a Layer with a module
- * containing package {@code p} where the class loader already has a module
- * defined to it containing package {@code p}.
- */
- @Test(expectedExceptions = { LayerInstantiationException.class })
- public void testPackageAlreadyInNamedModule() {
-
- ModuleDescriptor md1 = newBuilder("m1")
- .packages(Set.of("p"))
- .requires("java.base")
- .build();
-
- ModuleDescriptor md2 = newBuilder("m2")
- .packages(Set.of("p"))
- .requires("java.base")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(md1, md2);
-
- ClassLoader loader = new ClassLoader() { };
-
- // define m1 containing package p to class loader
-
- Configuration parent = Layer.boot().configuration();
-
- Configuration cf1 = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
-
- Layer layer1 = Layer.boot().defineModules(cf1, mn -> loader);
-
- // attempt to define m2 containing package p to class loader
-
- Configuration cf2 = parent.resolve(finder, ModuleFinder.of(), Set.of("m2"));
-
- // should throw exception because p already in m1
- Layer layer2 = Layer.boot().defineModules(cf2, mn -> loader);
-
- }
-
-
- /**
- * Attempt to use Layer defineModules to create a Layer with a module
- * containing a package in which a type is already loaded by the class
- * loader.
- */
- @Test(expectedExceptions = { LayerInstantiationException.class })
- public void testPackageAlreadyInUnnamedModule() throws Exception {
-
- Class> c = layertest.Test.class;
- assertFalse(c.getModule().isNamed()); // in unnamed module
-
- ModuleDescriptor md = newBuilder("m")
- .packages(Set.of(c.getPackageName()))
- .requires("java.base")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(md);
-
- Configuration parent = Layer.boot().configuration();
- Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
-
- Layer.boot().defineModules(cf, mn -> c.getClassLoader());
- }
-
-
- /**
- * Attempt to create a Layer with a module named "java.base".
- */
- public void testLayerWithJavaBase() {
- ModuleDescriptor descriptor = newBuilder("java.base")
- .exports("java.lang")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor);
-
- Configuration cf = Layer.boot()
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of("java.base"));
- assertTrue(cf.modules().size() == 1);
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- try {
- Layer.boot().defineModules(cf, mn -> new ClassLoader() { });
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
-
- try {
- Layer.boot().defineModulesWithOneLoader(cf, scl);
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
-
- try {
- Layer.boot().defineModulesWithManyLoaders(cf, scl);
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
- }
-
-
- @DataProvider(name = "javaPackages")
- public Object[][] javaPackages() {
- return new Object[][] { { "m1", "java" }, { "m2", "java.x" } };
- }
-
- /**
- * 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
- * class loader.
- */
- @Test(dataProvider = "javaPackages")
- public void testLayerWithJavaPackage(String mn, String pn) {
- ModuleDescriptor descriptor = newBuilder(mn).packages(Set.of(pn)).build();
- ModuleFinder finder = ModuleUtils.finderOf(descriptor);
-
- Configuration cf = Layer.boot()
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of(mn));
- assertTrue(cf.modules().size() == 1);
-
- ClassLoader pcl = ClassLoader.getPlatformClassLoader();
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- try {
- Layer.boot().defineModules(cf, _mn -> new ClassLoader() { });
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
-
- try {
- Layer.boot().defineModulesWithOneLoader(cf, scl);
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
-
- try {
- Layer.boot().defineModulesWithManyLoaders(cf, scl);
- assertTrue(false);
- } catch (LayerInstantiationException e) { }
-
- // create layer with module defined to platform class loader
- Layer layer = Layer.boot().defineModules(cf, _mn -> pcl);
- Optional om = layer.findModule(mn);
- assertTrue(om.isPresent());
- Module foo = om.get();
- assertTrue(foo.getClassLoader() == pcl);
- assertTrue(foo.getPackages().length == 1);
- assertTrue(foo.getPackages()[0].equals(pn));
- }
-
-
- /**
- * Attempt to create a Layer with a module defined to the boot loader
- */
- @Test(expectedExceptions = { LayerInstantiationException.class })
- public void testLayerWithBootLoader() {
- ModuleDescriptor descriptor = newBuilder("m1")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor);
-
- Configuration cf = Layer.boot()
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of("m1"));
- assertTrue(cf.modules().size() == 1);
-
- Layer.boot().defineModules(cf, mn -> null );
- }
-
-
- /**
- * Parent of configuration != configuration of parent Layer
- */
- @Test(expectedExceptions = { IllegalArgumentException.class })
- public void testIncorrectParent1() {
-
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .requires("java.base")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
-
- Configuration parent = Layer.boot().configuration();
- Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
-
- ClassLoader loader = new ClassLoader() { };
- Layer.empty().defineModules(cf, mn -> loader);
- }
-
-
- /**
- * Parent of configuration != configuration of parent Layer
- */
- @Test(expectedExceptions = { IllegalArgumentException.class })
- public void testIncorrectParent2() {
-
- ModuleDescriptor descriptor1 = newBuilder("m1")
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
-
- Configuration cf = resolve(finder, "m1");
-
- ClassLoader loader = new ClassLoader() { };
- Layer.boot().defineModules(cf, mn -> loader);
- }
-
-
- // null handling
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testCreateWithNull1() {
- ClassLoader loader = new ClassLoader() { };
- Layer.empty().defineModules(null, mn -> loader);
- }
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testCreateWithNull2() {
- Configuration cf = resolve(Layer.boot().configuration(), ModuleFinder.of());
- Layer.boot().defineModules(cf, null);
- }
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testCreateWithNull3() {
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer.empty().defineModulesWithOneLoader(null, scl);
- }
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testCreateWithNull4() {
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer.empty().defineModulesWithManyLoaders(null, scl);
- }
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testFindModuleWithNull() {
- Layer.boot().findModule(null);
- }
-
- @Test(expectedExceptions = { NullPointerException.class })
- public void testFindLoaderWithNull() {
- Layer.boot().findLoader(null);
- }
-
-
- // immutable sets
-
- @Test(expectedExceptions = { UnsupportedOperationException.class })
- public void testImmutableSet() {
- Module base = Object.class.getModule();
- Layer.boot().modules().add(base);
- }
-
-
- /**
- * Resolve the given modules, by name, and returns the resulting
- * Configuration.
- */
- private static Configuration resolve(Configuration cf,
- ModuleFinder finder,
- String... roots) {
- return cf.resolve(finder, ModuleFinder.of(), Set.of(roots));
- }
-
- private static Configuration resolve(ModuleFinder finder,
- String... roots) {
- return resolve(Configuration.empty(), finder, roots);
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/LayerAndLoadersTest.java
--- a/jdk/test/java/lang/reflect/Layer/LayerAndLoadersTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,724 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @library /lib/testlibrary
- * @modules jdk.compiler
- * @build LayerAndLoadersTest CompilerUtils ModuleUtils
- * @run testng LayerAndLoadersTest
- * @summary Tests for java.lang.reflect.Layer@createWithXXX methods
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReference;
-import java.lang.reflect.Layer;
-import java.lang.reflect.LayerInstantiationException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Module;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Optional;
-import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-@Test
-public class LayerAndLoadersTest {
-
- private static final String TEST_SRC = System.getProperty("test.src");
-
- private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
- private static final Path MODS_DIR = Paths.get("mods");
-
- @BeforeTest
- public void setup() throws Exception {
-
- // javac -d mods --module-source-path src src/**
- assertTrue(CompilerUtils.compile(SRC_DIR, MODS_DIR,
- "--module-source-path", SRC_DIR.toString()));
- }
-
-
- /**
- * Basic test of Layer defineModulesWithOneLoader
- *
- * Test scenario:
- * m1 requires m2 and m3
- */
- public void testWithOneLoader() throws Exception {
-
- Configuration cf = resolve("m1");
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl);
-
- checkLayer(layer, "m1", "m2", "m3");
-
- ClassLoader cl1 = layer.findLoader("m1");
- ClassLoader cl2 = layer.findLoader("m2");
- ClassLoader cl3 = layer.findLoader("m3");
-
- assertTrue(cl1.getParent() == scl);
- assertTrue(cl2 == cl1);
- assertTrue(cl3 == cl1);
-
- invoke(layer, "m1", "p.Main");
-
- }
-
-
- /**
- * Basic test of Layer defineModulesWithManyLoaders
- *
- * Test scenario:
- * m1 requires m2 and m3
- */
- public void testWithManyLoaders() throws Exception {
-
- Configuration cf = resolve("m1");
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
-
- checkLayer(layer, "m1", "m2", "m3");
-
- ClassLoader cl1 = layer.findLoader("m1");
- ClassLoader cl2 = layer.findLoader("m2");
- ClassLoader cl3 = layer.findLoader("m3");
-
- assertTrue(cl1.getParent() == scl);
- assertTrue(cl2.getParent() == scl);
- assertTrue(cl3.getParent() == scl);
- assertTrue(cl2 != cl1);
- assertTrue(cl3 != cl1);
- assertTrue(cl3 != cl2);
-
- invoke(layer, "m1", "p.Main");
-
- }
-
-
- /**
- * Basic test of Layer defineModulesWithOneLoader where one of the modules
- * is a service provider module.
- *
- * Test scenario:
- * m1 requires m2 and m3
- * m1 uses S
- * m4 provides S with ...
- */
- public void testServicesWithOneLoader() throws Exception {
-
- Configuration cf = resolveAndBind("m1");
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl);
-
- checkLayer(layer, "m1", "m2", "m3", "m4");
-
- ClassLoader cl1 = layer.findLoader("m1");
- ClassLoader cl2 = layer.findLoader("m2");
- ClassLoader cl3 = layer.findLoader("m3");
- ClassLoader cl4 = layer.findLoader("m4");
-
- assertTrue(cl1.getParent() == scl);
- assertTrue(cl2 == cl1);
- assertTrue(cl3 == cl1);
- assertTrue(cl4 == cl1);
-
- Class> serviceType = cl1.loadClass("p.Service");
- assertTrue(serviceType.getClassLoader() == cl1);
-
- Iterator> iter = ServiceLoader.load(serviceType, cl1).iterator();
- Object provider = iter.next();
- assertTrue(serviceType.isInstance(provider));
- assertTrue(provider.getClass().getClassLoader() == cl1);
- assertFalse(iter.hasNext());
-
- }
-
-
- /**
- * Basic test of Layer defineModulesWithManyLoaders where one of the
- * modules is a service provider module.
- *
- * Test scenario:
- * m1 requires m2 and m3
- * m1 uses S
- * m4 provides S with ...
- */
- public void testServicesWithManyLoaders() throws Exception {
-
- Configuration cf = resolveAndBind("m1");
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
-
- checkLayer(layer, "m1", "m2", "m3", "m4");
-
- ClassLoader cl1 = layer.findLoader("m1");
- ClassLoader cl2 = layer.findLoader("m2");
- ClassLoader cl3 = layer.findLoader("m3");
- ClassLoader cl4 = layer.findLoader("m4");
-
- assertTrue(cl1.getParent() == scl);
- assertTrue(cl2.getParent() == scl);
- assertTrue(cl3.getParent() == scl);
- assertTrue(cl4.getParent() == scl);
- assertTrue(cl2 != cl1);
- assertTrue(cl3 != cl1);
- assertTrue(cl3 != cl2);
- assertTrue(cl4 != cl1);
- assertTrue(cl4 != cl2);
- assertTrue(cl4 != cl3);
-
- Class> serviceType = cl1.loadClass("p.Service");
- assertTrue(serviceType.getClassLoader() == cl1);
-
- // Test that the service provider can be located via any of
- // the class loaders in the layer
- for (Module m : layer.modules()) {
- ClassLoader loader = m.getClassLoader();
- Iterator> iter = ServiceLoader.load(serviceType, loader).iterator();
- Object provider = iter.next();
- assertTrue(serviceType.isInstance(provider));
- assertTrue(provider.getClass().getClassLoader() == cl4);
- assertFalse(iter.hasNext());
- }
-
- }
-
-
- /**
- * Tests that the class loaders created by defineModulesWithXXX delegate
- * to the given parent class loader.
- */
- public void testDelegationToParent() throws Exception {
-
- Configuration cf = resolve("m1");
-
- ClassLoader parent = this.getClass().getClassLoader();
- String cn = this.getClass().getName();
-
- // one loader
- Layer layer = Layer.boot().defineModulesWithOneLoader(cf, parent);
- testLoad(layer, cn);
-
- // one loader with boot loader as parent
- layer = Layer.boot().defineModulesWithOneLoader(cf, null);
- testLoadFail(layer, cn);
-
- // many loaders
- layer = Layer.boot().defineModulesWithManyLoaders(cf, parent);
- testLoad(layer, cn);
-
- // many loader with boot loader as parent
- layer = Layer.boot().defineModulesWithManyLoaders(cf, null);
- testLoadFail(layer, cn);
-
- }
-
-
- /**
- * Test defineModulesWithXXX when modules that have overlapping packages.
- *
- * Test scenario:
- * m1 exports p
- * m2 exports p
- */
- public void testOverlappingPackages() {
-
- ModuleDescriptor descriptor1
- = ModuleDescriptor.newModule("m1").exports("p").build();
-
- ModuleDescriptor descriptor2
- = ModuleDescriptor.newModule("m2").exports("p").build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf = Layer.boot()
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
-
- // cannot define both module m1 and m2 to the same class loader
- try {
- Layer.boot().defineModulesWithOneLoader(cf, null);
- assertTrue(false);
- } catch (LayerInstantiationException expected) { }
-
- // should be okay to have one module per class loader
- Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, null);
- checkLayer(layer, "m1", "m2");
-
- }
-
-
- /**
- * Test Layer defineModulesWithXXX with split delegation.
- *
- * Test scenario:
- * layer1: m1 exports p, m2 exports p
- * layer2: m3 reads m1, m4 reads m2
- */
- public void testSplitDelegation() {
-
- ModuleDescriptor descriptor1
- = ModuleDescriptor.newModule("m1").exports("p").build();
-
- ModuleDescriptor descriptor2
- = ModuleDescriptor.newModule("m2").exports("p").build();
-
- ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
-
- Configuration cf1 = Layer.boot()
- .configuration()
- .resolve(finder1, ModuleFinder.of(), Set.of("m1", "m2"));
-
- Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null);
- checkLayer(layer1, "m1", "m2");
-
- ModuleDescriptor descriptor3
- = ModuleDescriptor.newModule("m3").requires("m1").build();
-
- ModuleDescriptor descriptor4
- = ModuleDescriptor.newModule("m4").requires("m2").build();
-
- ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4);
-
- Configuration cf2 = cf1.resolve(finder2, ModuleFinder.of(),
- Set.of("m3", "m4"));
-
- // package p cannot be supplied by two class loaders
- try {
- layer1.defineModulesWithOneLoader(cf2, null);
- assertTrue(false);
- } catch (LayerInstantiationException expected) { }
-
- // no split delegation when modules have their own class loader
- Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
- checkLayer(layer2, "m3", "m4");
-
- }
-
-
- /**
- * Test Layer defineModulesWithXXX when the modules that override same
- * named modules in the parent layer.
- *
- * Test scenario:
- * layer1: m1, m2, m3 => same loader
- * layer2: m1, m2, m4 => same loader
- */
- public void testOverriding1() throws Exception {
-
- Configuration cf1 = resolve("m1");
-
- Layer layer1 = Layer.boot().defineModulesWithOneLoader(cf1, null);
- checkLayer(layer1, "m1", "m2", "m3");
-
- ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
- Set.of("m1"));
-
- Layer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
- checkLayer(layer2, "m1", "m2", "m3");
- invoke(layer1, "m1", "p.Main");
-
- ClassLoader loader1 = layer1.findLoader("m1");
- ClassLoader loader2 = layer1.findLoader("m2");
- ClassLoader loader3 = layer1.findLoader("m3");
-
- ClassLoader loader4 = layer2.findLoader("m1");
- ClassLoader loader5 = layer2.findLoader("m2");
- ClassLoader loader6 = layer2.findLoader("m3");
-
- assertTrue(loader1 == loader2);
- assertTrue(loader1 == loader3);
-
- assertTrue(loader4 == loader5);
- assertTrue(loader4 == loader6);
- assertTrue(loader4 != loader1);
-
- assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader1);
-
- assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
- assertTrue(loader4.loadClass("q.Hello").getClassLoader() == loader4);
- assertTrue(loader4.loadClass("w.Hello").getClassLoader() == loader4);
-
- }
-
-
- /**
- * Test Layer defineModulesWithXXX when the modules that override same
- * named modules in the parent layer.
- *
- * Test scenario:
- * layer1: m1, m2, m3 => loader pool
- * layer2: m1, m2, m3 => loader pool
- */
- public void testOverriding2() throws Exception {
-
- Configuration cf1 = resolve("m1");
-
- Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null);
- checkLayer(layer1, "m1", "m2", "m3");
-
- ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
- Set.of("m1"));
-
- Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
- checkLayer(layer2, "m1", "m2", "m3");
- invoke(layer1, "m1", "p.Main");
-
- ClassLoader loader1 = layer1.findLoader("m1");
- ClassLoader loader2 = layer1.findLoader("m2");
- ClassLoader loader3 = layer1.findLoader("m3");
-
- ClassLoader loader4 = layer2.findLoader("m1");
- ClassLoader loader5 = layer2.findLoader("m2");
- ClassLoader loader6 = layer2.findLoader("m3");
-
- assertTrue(loader4 != loader1);
- assertTrue(loader5 != loader2);
- assertTrue(loader6 != loader3);
-
- assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader2);
- assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader3);
-
- // p.Main is not visible via loader2
- try {
- loader2.loadClass("p.Main");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // w.Hello is not visible via loader2
- try {
- loader2.loadClass("w.Hello");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // p.Main is not visible via loader3
- try {
- loader3.loadClass("p.Main");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // q.Hello is not visible via loader3
- try {
- loader3.loadClass("q.Hello");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
-
- assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
- assertTrue(loader5.loadClass("q.Hello").getClassLoader() == loader5);
- assertTrue(loader6.loadClass("w.Hello").getClassLoader() == loader6);
-
- // p.Main is not visible via loader5
- try {
- loader5.loadClass("p.Main");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // w.Hello is not visible via loader5
- try {
- loader5.loadClass("w.Hello");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // p.Main is not visible via loader6
- try {
- loader6.loadClass("p.Main");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- // q.Hello is not visible via loader6
- try {
- loader6.loadClass("q.Hello");
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
-
- }
-
-
- /**
- * Test Layer defineModulesWithXXX when the modules that override same
- * named modules in the parent layer.
- *
- * layer1: m1, m2, m3 => same loader
- * layer2: m1, m3 => same loader
- */
- public void testOverriding3() throws Exception {
-
- Configuration cf1 = resolve("m1");
-
- Layer layer1 = Layer.boot().defineModulesWithOneLoader(cf1, null);
- checkLayer(layer1, "m1", "m2", "m3");
-
- ModuleFinder finder = finderFor("m1", "m3");
-
- Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
- Set.of("m1"));
-
- Layer layer2 = layer1.defineModulesWithOneLoader(cf2, null);
- checkLayer(layer2, "m1", "m3");
- invoke(layer1, "m1", "p.Main");
-
- ClassLoader loader1 = layer1.findLoader("m1");
- ClassLoader loader2 = layer2.findLoader("m1");
-
- assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader1);
-
- assertTrue(loader2.loadClass("p.Main").getClassLoader() == loader2);
- assertTrue(loader2.loadClass("q.Hello").getClassLoader() == loader1);
- assertTrue(loader2.loadClass("w.Hello").getClassLoader() == loader2);
-
- }
-
-
- /**
- * Test Layer defineModulesWithXXX when the modules that override same
- * named modules in the parent layer.
- *
- * layer1: m1, m2, m3 => loader pool
- * layer2: m1, m3 => loader pool
- */
- public void testOverriding4() throws Exception {
-
- Configuration cf1 = resolve("m1");
-
- Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, null);
- checkLayer(layer1, "m1", "m2", "m3");
-
- ModuleFinder finder = finderFor("m1", "m3");
-
- Configuration cf2 = cf1.resolve(finder, ModuleFinder.of(),
- Set.of("m1"));
-
- Layer layer2 = layer1.defineModulesWithManyLoaders(cf2, null);
- checkLayer(layer2, "m1", "m3");
- invoke(layer1, "m1", "p.Main");
-
- ClassLoader loader1 = layer1.findLoader("m1");
- ClassLoader loader2 = layer1.findLoader("m2");
- ClassLoader loader3 = layer1.findLoader("m3");
-
- ClassLoader loader4 = layer2.findLoader("m1");
- ClassLoader loader5 = layer2.findLoader("m2");
- ClassLoader loader6 = layer2.findLoader("m3");
-
- assertTrue(loader4 != loader1);
- assertTrue(loader5 == loader2); // m2 not overridden
- assertTrue(loader6 != loader3);
-
- assertTrue(loader1.loadClass("p.Main").getClassLoader() == loader1);
- assertTrue(loader1.loadClass("q.Hello").getClassLoader() == loader2);
- assertTrue(loader1.loadClass("w.Hello").getClassLoader() == loader3);
-
- assertTrue(loader2.loadClass("q.Hello").getClassLoader() == loader2);
-
- assertTrue(loader3.loadClass("w.Hello").getClassLoader() == loader3);
-
- assertTrue(loader4.loadClass("p.Main").getClassLoader() == loader4);
- assertTrue(loader4.loadClass("q.Hello").getClassLoader() == loader2);
- assertTrue(loader4.loadClass("w.Hello").getClassLoader() == loader6);
-
- assertTrue(loader6.loadClass("w.Hello").getClassLoader() == loader6);
-
- }
-
-
- /**
- * Basic test of resource loading with a class loader created by
- * Layer.defineModulesWithOneLoader.
- */
- public void testResourcesOneLoader() throws Exception {
- Configuration cf = resolve("m1");
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl);
- ClassLoader loader = layer.findLoader("m1");
- testResourceLoading(loader, "p/Main.class");
- }
-
- /**
- * Basic test of resource loading with a class loader created by
- * Layer.defineModulesWithOneLoader.
- */
- public void testResourcesManyLoaders() throws Exception {
- Configuration cf = resolve("m1");
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
- ClassLoader loader = layer.findLoader("m1");
- testResourceLoading(loader, "p/Main.class");
- }
-
- /**
- * Test that a resource is located by a class loader.
- */
- private void testResourceLoading(ClassLoader loader, String name)
- throws IOException
- {
- URL url = loader.getResource(name);
- assertNotNull(url);
-
- try (InputStream in = loader.getResourceAsStream(name)) {
- assertNotNull(in);
- }
-
- Enumeration urls = loader.getResources(name);
- assertTrue(urls.hasMoreElements());
- }
-
-
- // -- supporting methods --
-
-
- /**
- * Resolve the given modules, by name, and returns the resulting
- * Configuration.
- */
- private static Configuration resolve(String... roots) {
- ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- return Layer.boot()
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of(roots));
- }
-
- /**
- * Resolve the given modules, by name, and returns the resulting
- * Configuration.
- */
- private static Configuration resolveAndBind(String... roots) {
- ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- return Layer.boot()
- .configuration()
- .resolveAndBind(finder, ModuleFinder.of(), Set.of(roots));
- }
-
-
- /**
- * Invokes the static void main(String[]) method on the given class
- * in the given module.
- */
- private static void invoke(Layer layer, String mn, String mc) throws Exception {
- ClassLoader loader = layer.findLoader(mn);
- Class> c = loader.loadClass(mc);
- Method mainMethod = c.getMethod("main", String[].class);
- mainMethod.invoke(null, (Object)new String[0]);
- }
-
-
- /**
- * Checks that the given layer contains exactly the expected modules
- * (by name).
- */
- private void checkLayer(Layer layer, String ... expected) {
- Set names = layer.modules().stream()
- .map(Module::getName)
- .collect(Collectors.toSet());
- assertTrue(names.size() == expected.length);
- for (String name : expected) {
- assertTrue(names.contains(name));
- }
- }
-
-
- /**
- * Test that a class can be loaded via the class loader of all modules
- * in the given layer.
- */
- static void testLoad(Layer layer, String cn) throws Exception {
- for (Module m : layer.modules()) {
- ClassLoader l = m.getClassLoader();
- l.loadClass(cn);
- }
- }
-
-
- /**
- * Test that a class cannot be loaded via any of the class loaders of
- * the modules in the given layer.
- */
- static void testLoadFail(Layer layer, String cn) throws Exception {
- for (Module m : layer.modules()) {
- ClassLoader l = m.getClassLoader();
- try {
- l.loadClass(cn);
- assertTrue(false);
- } catch (ClassNotFoundException expected) { }
- }
- }
-
-
- /**
- * Returns a ModuleFinder that only finds the given test modules
- */
- static ModuleFinder finderFor(String... names) {
-
- ModuleFinder finder = ModuleFinder.of(MODS_DIR);
-
- Map mrefs = new HashMap<>();
- for (String name : names) {
- Optional omref = finder.find(name);
- assert omref.isPresent();
- mrefs.put(name, omref.get());
- }
-
- return new ModuleFinder() {
- @Override
- public Optional find(String name) {
- ModuleReference mref = mrefs.get(name);
- return Optional.ofNullable(mref);
- }
- @Override
- public Set findAll() {
- return mrefs.values().stream().collect(Collectors.toSet());
- }
- };
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/LayerControllerTest.java
--- a/jdk/test/java/lang/reflect/Layer/LayerControllerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @library /lib/testlibrary
- * @build LayerControllerTest ModuleUtils
- * @run testng LayerControllerTest
- * @summary Basic tests for java.lang.reflect.Layer.Controller
- */
-
-import java.lang.module.Configuration;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.util.List;
-import java.util.Set;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-@Test
-public class LayerControllerTest {
-
- /**
- * Creates a Controller for a module layer containing modules m1 and m2.
- * 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
- */
- private Layer.Controller createTestLayer() {
- ModuleDescriptor descriptor1
- = ModuleDescriptor.newModule("m1")
- .packages(Set.of("p1"))
- .requires("java.base")
- .build();
-
- ModuleDescriptor descriptor2
- = ModuleDescriptor.newModule("m2")
- .requires("java.base")
- .packages(Set.of("p2"))
- .build();
-
- ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);
- Layer bootLayer = Layer.boot();
-
- Configuration cf = bootLayer.configuration()
- .resolve(finder, ModuleFinder.of(), Set.of("m1", "m2"));
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
-
- Layer.Controller controller
- = Layer.defineModulesWithOneLoader(cf, List.of(bootLayer), scl);
-
- Layer layer = controller.layer();
-
- assertTrue(layer.modules().size() == 2);
- assertTrue(layer.findModule("m1").isPresent());
- assertTrue(layer.findModule("m2").isPresent());
-
- return controller;
- }
-
- /**
- * Basic test of Layer.Controller to update modules m1 and m2 to read and
- * open packages to each other.
- */
- public void testBasic() {
- Layer.Controller controller = createTestLayer();
- Layer layer = controller.layer();
- Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
- Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
-
- assertFalse(m1.canRead(m2));
- assertFalse(m1.isExported("p1"));
- assertFalse(m1.isOpen("p1"));
- assertFalse(m1.isExported("p1", m2));
- assertFalse(m1.isOpen("p1", m2));
-
- assertFalse(m2.canRead(m1));
- assertFalse(m2.isExported("p2"));
- assertFalse(m2.isOpen("p2"));
- assertFalse(m2.isExported("p2", m1));
- assertFalse(m2.isOpen("p2", m1));
-
- // update m1 to read m2
- assertTrue(controller.addReads(m1, m2) == controller);
- assertTrue(m1.canRead(m2));
- assertFalse(m2.canRead(m1));
-
- // update m2 to read m1
- assertTrue(controller.addReads(m2, m1) == controller);
- assertTrue(m1.canRead(m2));
- assertTrue(m1.canRead(m1));
-
- // update m1 to open p1 to m2
- assertTrue(controller.addOpens(m1, "p1", m2) == controller);
- assertTrue(m1.isExported("p1", m2));
- assertTrue(m1.isOpen("p1", m2));
- assertFalse(m1.isExported("p1"));
- assertFalse(m1.isOpen("p1"));
-
- // update m2 to open p2 to m1
- assertTrue(controller.addOpens(m2, "p2", m1) == controller);
- assertTrue(m2.isExported("p2", m1));
- assertTrue(m2.isOpen("p2", m1));
- assertFalse(m2.isExported("p2"));
- assertFalse(m2.isOpen("p2"));
- }
-
- /**
- * Test invalid argument handling
- */
- public void testBadArguments() {
- Layer.Controller controller = createTestLayer();
- Layer layer = controller.layer();
- Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
- Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
- Module base = Object.class.getModule();
-
- // java.base is not in layer
- try {
- controller.addReads(base, m2);
- assertTrue(false);
- } catch (IllegalArgumentException expected) { }
-
- // java.base is not in layer
- try {
- controller.addOpens(base, "java.lang", m2);
- assertTrue(false);
- } catch (IllegalArgumentException expected) { }
-
- // m1 does not contain java.lang
- try {
- controller.addOpens(m1, "java.lang", m2);
- assertTrue(false);
- } catch (IllegalArgumentException expected) { }
- }
-
- /**
- * Test null handling
- */
- public void testNulls() {
- Layer.Controller controller = createTestLayer();
- Layer layer = controller.layer();
- Module m1 = layer.findModule("m1").orElseThrow(RuntimeException::new);
- Module m2 = layer.findModule("m2").orElseThrow(RuntimeException::new);
- assertTrue(m1 != null);
- assertTrue(m2 != null);
-
- try {
- controller.addReads(null, m2);
- assertTrue(false);
- } catch (NullPointerException expected) { }
-
- try {
- controller.addReads(m1, null);
- assertTrue(false);
- } catch (NullPointerException expected) { }
-
- try {
- controller.addOpens(null, "p1", m2);
- assertTrue(false);
- } catch (NullPointerException expected) { }
-
- try {
- controller.addOpens(m1, null, m2);
- assertTrue(false);
- } catch (NullPointerException expected) { }
-
- try {
- controller.addOpens(m1, "p1", null);
- assertTrue(false);
- } catch (NullPointerException expected) { }
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/layertest/Test.java
--- a/jdk/test/java/lang/reflect/Layer/layertest/Test.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-/**
- * Supporting class for tests of java.lang.reflect.Layer.
- */
-
-package layertest;
-
-public class Test { }
-
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m1/module-info.java
--- a/jdk/test/java/lang/reflect/Layer/src/m1/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module m1 {
- requires m2;
- requires m3;
- exports p;
- uses p.Service;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m1/p/Main.java
--- a/jdk/test/java/lang/reflect/Layer/src/m1/p/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 p;
-
-import java.net.URL;
-
-public class Main {
- public static void main(String[] args) {
-
- URL url1 = Main.class.getResource("Main.class");
- if (url1 == null) throw new RuntimeException();
- URL url2 = Main.class.getResource("/p/Main.class");
- if (url2 == null) throw new RuntimeException();
-
- q.Hello.hello();
- w.Hello.hello();
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m1/p/Service.java
--- a/jdk/test/java/lang/reflect/Layer/src/m1/p/Service.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 p;
-
-public interface Service { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m2/module-info.java
--- a/jdk/test/java/lang/reflect/Layer/src/m2/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module m2 {
- exports q;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m2/q/Hello.java
--- a/jdk/test/java/lang/reflect/Layer/src/m2/q/Hello.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 q;
-
-import java.net.URL;
-
-public class Hello {
-
- public static void hello() {
-
- URL url1 = Hello.class.getResource("Hello.class");
- if (url1 == null) throw new RuntimeException();
- URL url2 = Hello.class.getResource("/q/Hello.class");
- if (url2 == null) throw new RuntimeException();
-
- System.out.println("Hello!");
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m3/module-info.java
--- a/jdk/test/java/lang/reflect/Layer/src/m3/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module m3 {
- // qualified export
- exports w to m1;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m3/w/Hello.java
--- a/jdk/test/java/lang/reflect/Layer/src/m3/w/Hello.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 w;
-
-import java.net.URL;
-
-public class Hello {
-
- public static void hello() {
-
- URL url1 = Hello.class.getResource("Hello.class");
- if (url1 == null) throw new RuntimeException();
- URL url2 = Hello.class.getResource("/w/Hello.class");
- if (url2 == null) throw new RuntimeException();
-
- System.out.println("Hello!");
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m4/impl/ServiceImpl.java
--- a/jdk/test/java/lang/reflect/Layer/src/m4/impl/ServiceImpl.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 impl;
-
-public class ServiceImpl implements p.Service {
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Layer/src/m4/module-info.java
--- a/jdk/test/java/lang/reflect/Layer/src/m4/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module m4 {
- requires m1;
- provides p.Service with impl.ServiceImpl;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/AddExportsTest.java
--- a/jdk/test/java/lang/reflect/Module/AddExportsTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @modules java.base/jdk.internal.misc
- * java.desktop
- * @run main/othervm --add-exports=java.desktop/sun.awt=java.base AddExportsTest
- * @run main/othervm --add-exports=java.desktop/sun.awt=ALL-UNNAMED AddExportsTest
- * @summary Test Module isExported methods with exports changed by -AddExportsTest
- */
-
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import jdk.internal.misc.VM;
-
-public class AddExportsTest {
- /*
- * jtreg sets -Dtest.modules system property to the internal APIs
- * specified at @modules tag. The test will exclude --add-exports set
- * for @modules.
- */
- private static final String TEST_MODULES = System.getProperty("test.modules");
-
- public static void main(String[] args) {
-
- Optional oaddExports = Stream.of(VM.getRuntimeArguments())
- .filter(arg -> arg.startsWith("--add-exports="))
- .filter(arg -> !arg.equals("--add-exports=" + TEST_MODULES + "=ALL-UNNAMED"))
- .map(arg -> arg.substring("--add-exports=".length(), arg.length()))
- .findFirst();
-
- assertTrue(oaddExports.isPresent());
-
- Layer bootLayer = Layer.boot();
-
- Module unnamedModule = AddExportsTest.class.getModule();
- assertFalse(unnamedModule.isNamed());
-
- for (String expr : oaddExports.get().split(",")) {
-
- String[] s = expr.split("=");
- assertTrue(s.length == 2);
-
- // $MODULE/$PACKAGE
- String[] moduleAndPackage = s[0].split("/");
- assertTrue(moduleAndPackage.length == 2);
-
- String mn = moduleAndPackage[0];
- String pn = moduleAndPackage[1];
-
- // source module
- Module source;
- Optional om = bootLayer.findModule(mn);
- assertTrue(om.isPresent(), mn + " not in boot layer");
- source = om.get();
-
- // package should not be exported unconditionally
- assertFalse(source.isExported(pn),
- pn + " should not be exported unconditionally");
-
- // $TARGET
- String tn = s[1];
- if ("ALL-UNNAMED".equals(tn)) {
-
- // package is exported to all unnamed modules
- assertTrue(source.isExported(pn, unnamedModule),
- pn + " should be exported to all unnamed modules");
-
- } else {
-
- om = bootLayer.findModule(tn);
- assertTrue(om.isPresent());
- Module target = om.get();
-
- // package should be exported to target module
- assertTrue(source.isExported(pn, target),
- pn + " should be exported to " + target);
-
- // package should not be exported to unnamed modules
- assertFalse(source.isExported(pn, unnamedModule),
- pn + " should not be exported to unnamed modules");
-
- }
-
- }
- }
-
- static void assertTrue(boolean cond) {
- if (!cond) throw new RuntimeException();
- }
-
- static void assertTrue(boolean cond, String msg) {
- if (!cond) throw new RuntimeException(msg);
- }
-
- static void assertFalse(boolean cond) {
- if (cond) throw new RuntimeException();
- }
-
- static void assertFalse(boolean cond, String msg) {
- if (cond) throw new RuntimeException(msg);
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/AnnotationsTest.java
--- a/jdk/test/java/lang/reflect/Module/AnnotationsTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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.
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.annotation.Annotation;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import jdk.internal.module.ClassFileAttributes;
-import jdk.internal.org.objectweb.asm.AnnotationVisitor;
-import jdk.internal.org.objectweb.asm.Attribute;
-import jdk.internal.org.objectweb.asm.ClassReader;
-import jdk.internal.org.objectweb.asm.ClassVisitor;
-import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.internal.org.objectweb.asm.Opcodes;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/**
- * @test
- * @modules java.base/jdk.internal.org.objectweb.asm
- * java.base/jdk.internal.module
- * java.xml
- * @run testng AnnotationsTest
- * @summary Basic test of annotations on modules
- */
-
-public class AnnotationsTest {
-
- /**
- * Test that there are no annotations on an unnamed module.
- */
- @Test
- public void testUnnamedModule() {
- Module module = this.getClass().getModule();
- assertTrue(module.getAnnotations().length == 0);
- }
-
- /**
- * Test loading a module with a RuntimeVisibleAnnotation attribute.
- * The test copies the module-info.class for java.xml, adds the attribute,
- * and then loads the updated module.
- */
- @Test
- public void testNamedModule() throws IOException {
-
- // "deprecate" java.xml
- Path dir = Files.createTempDirectory("mods");
- deprecateModule("java.xml", true, "9", dir);
-
- // "load" the cloned java.xml
- Module module = loadModule(dir, "java.xml");
-
- // check the annotation is present
- assertTrue(module.isAnnotationPresent(Deprecated.class));
- Deprecated d = module.getAnnotation(Deprecated.class);
- assertNotNull(d, "@Deprecated not found");
- assertTrue(d.forRemoval());
- assertEquals(d.since(), "9");
- Annotation[] a = module.getAnnotations();
- assertTrue(a.length == 1);
- assertTrue(a[0] instanceof Deprecated);
- }
-
-
- /**
- * Copy the module-info.class for the given module, add the
- * Deprecated annotation, and write the updated module-info.class
- * to a directory.
- */
- static void deprecateModule(String name,
- boolean forRemoval,
- String since,
- Path output) throws IOException {
- Module module = Layer.boot().findModule(name).orElse(null);
- assertNotNull(module, name + " not found");
-
- InputStream in = module.getResourceAsStream("module-info.class");
- assertNotNull(in, "No module-info.class for " + name);
-
- try (in) {
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
- + ClassWriter.COMPUTE_FRAMES);
-
- ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, cw) { };
-
- ClassReader cr = new ClassReader(in);
-
- List attrs = new ArrayList<>();
- attrs.add(new ClassFileAttributes.ModuleAttribute());
- attrs.add(new ClassFileAttributes.ModulePackagesAttribute());
- attrs.add(new ClassFileAttributes.ModuleTargetAttribute());
- cr.accept(cv, attrs.toArray(new Attribute[0]), 0);
-
- AnnotationVisitor annotationVisitor
- = cv.visitAnnotation("Ljava/lang/Deprecated;", true);
- annotationVisitor.visit("forRemoval", forRemoval);
- annotationVisitor.visit("since", since);
- annotationVisitor.visitEnd();
-
- byte[] bytes = cw.toByteArray();
- Path mi = output.resolve("module-info.class");
- Files.write(mi, bytes);
- }
- }
-
- /**
- * Load the module of the given name in the given directory into a
- * child layer.
- */
- static Module loadModule(Path dir, String name) throws IOException {
- ModuleFinder finder = ModuleFinder.of(dir);
-
- Layer bootLayer = Layer.boot();
-
- Configuration cf = bootLayer.configuration()
- .resolve(finder, ModuleFinder.of(), Set.of(name));
-
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
-
- Module module = layer.findModule(name).orElse(null);
- assertNotNull(module, name + " not loaded");
- return module;
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/BasicModuleTest.java
--- a/jdk/test/java/lang/reflect/Module/BasicModuleTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,338 +0,0 @@
-/*
- * Copyright (c) 2014, 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.
- *
- * 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.
- */
-
-import java.lang.module.ModuleDescriptor.Exports;
-import java.lang.module.ResolvedModule;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.nio.file.spi.FileSystemProvider; // service type in java.base
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-import javax.print.PrintServiceLookup; // service type in java.desktop
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/*
- * @test
- * @summary Basic test of java.lang.reflect.Module
- * @modules java.desktop java.xml
- * @run testng BasicModuleTest
- */
-
-public class BasicModuleTest {
-
- /**
- * Tests that the given module reads all modules in the boot Layer.
- */
- private void testReadsAllBootModules(Module m) {
- Layer bootLayer = Layer.boot();
- bootLayer.configuration()
- .modules()
- .stream()
- .map(ResolvedModule::name)
- .map(bootLayer::findModule)
- .forEach(target -> assertTrue(m.canRead(target.get())));
- }
-
- /**
- * Returns {@code true} if the array contains the given object.
- */
- private boolean contains(T[] array, T obj) {
- return Stream.of(array).anyMatch(obj::equals);
- }
-
- /**
- * Returns a {@code Predicate} to test if a package is exported.
- */
- private Predicate doesExport(String pn) {
- return e -> (e.source().equals(pn) && !e.isQualified());
- }
-
-
-
- @Test
- public void testThisModule() {
- Module thisModule = BasicModuleTest.class.getModule();
- Module baseModule = Object.class.getModule();
-
- assertFalse(thisModule.isNamed());
- assertTrue(thisModule.getName() == null);
- assertTrue(thisModule.getDescriptor() == null);
- assertTrue(thisModule.getLayer() == null);
- assertTrue(thisModule.toString().startsWith("unnamed module "));
-
- ClassLoader thisLoader = BasicModuleTest.class.getClassLoader();
- assertTrue(thisLoader == thisModule.getClassLoader());
- assertTrue(thisLoader.getUnnamedModule() == thisModule);
-
- // unnamed modules read all other modules
- ClassLoader cl;
- cl = ClassLoader.getPlatformClassLoader();
- assertTrue(thisModule.canRead(cl.getUnnamedModule()));
- cl = ClassLoader.getSystemClassLoader();
- assertTrue(thisModule.canRead(cl.getUnnamedModule()));
- testReadsAllBootModules(thisModule);
-
- // unnamed modules export all packages
- assertTrue(thisModule.isExported(""));
- assertTrue(thisModule.isExported("", thisModule));
- assertTrue(thisModule.isExported("", baseModule));
- assertTrue(thisModule.isExported("p"));
- assertTrue(thisModule.isExported("p", thisModule));
- assertTrue(thisModule.isExported("p", baseModule));
-
- // this test is in the unnamed package
- assertTrue(contains(thisModule.getPackages(), ""));
- }
-
-
- @Test
- public void testUnnamedModules() {
- Module thisModule = BasicModuleTest.class.getModule();
- Module baseModule = Object.class.getModule();
-
- ClassLoader loader1 = ClassLoader.getSystemClassLoader();
- ClassLoader loader2 = loader1.getParent();
-
- Module m1 = loader1.getUnnamedModule();
- Module m2 = loader2.getUnnamedModule();
-
- assertTrue(m1 != m2);
-
- assertFalse(m1.isNamed());
- assertFalse(m2.isNamed());
-
- assertTrue(m1.getLayer() == null);
- assertTrue(m2.getLayer() == null);
-
- assertTrue(m1.toString().startsWith("unnamed module "));
- assertTrue(m2.toString().startsWith("unnamed module "));
-
- // unnamed module reads all modules
- assertTrue(m1.canRead(m2));
- assertTrue(m2.canRead(m1));
-
- testReadsAllBootModules(m1);
- testReadsAllBootModules(m2);
-
- assertTrue(m1.isExported(""));
- assertTrue(m1.isExported("", thisModule));
- assertTrue(m1.isExported("", baseModule));
- assertTrue(m1.isExported("p"));
- assertTrue(m1.isExported("p", thisModule));
- assertTrue(m1.isExported("p", baseModule));
- }
-
-
-
- @Test
- public void testBaseModule() {
- Module base = Object.class.getModule();
- Module thisModule = BasicModuleTest.class.getModule();
-
- // getName
- assertTrue(base.getName().equals("java.base"));
-
- // getDescriptor
- assertTrue(base.getDescriptor().exports().stream()
- .anyMatch(doesExport("java.lang")));
-
- // getClassLoader
- assertTrue(base.getClassLoader() == null);
-
- // getLayer
- assertTrue(base.getLayer() == Layer.boot());
-
- // toString
- assertEquals(base.toString(), "module java.base");
-
- // getPackages
- assertTrue(contains(base.getPackages(), "java.lang"));
-
- // canRead
- assertTrue(base.canRead(base));
- assertFalse(base.canRead(thisModule));
-
- // addReads
- try {
- base.addReads(thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(base.canRead(thisModule));
-
- // isExported
- assertTrue(base.isExported("java.lang"));
- assertTrue(base.isExported("java.lang", thisModule));
- assertTrue(base.isExported("java.lang", base));
- assertFalse(base.isExported("jdk.internal.misc"));
- assertFalse(base.isExported("jdk.internal.misc", thisModule));
- assertTrue(base.isExported("jdk.internal.misc", base));
- assertFalse(base.isExported("java.wombat"));
- assertFalse(base.isExported("java.wombat", thisModule));
- assertFalse(base.isExported("java.wombat", base));
-
- // addExports
- try {
- base.addExports("java.lang", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- try {
- base.addExports("jdk.internal.misc", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(base.isExported("jdk.internal.misc"));
- assertFalse(base.isExported("jdk.internal.misc", thisModule));
-
- // isOpen
- assertFalse(base.isOpen("java.lang"));
- assertFalse(base.isOpen("java.lang", thisModule));
- assertTrue(base.isOpen("java.lang", base));
- assertFalse(base.isOpen("jdk.internal.misc"));
- assertFalse(base.isOpen("jdk.internal.misc", thisModule));
- assertTrue(base.isOpen("jdk.internal.misc", base));
- assertFalse(base.isOpen("java.wombat"));
- assertFalse(base.isOpen("java.wombat", thisModule));
- assertFalse(base.isOpen("java.wombat", base));
-
- // addOpens
- try {
- base.addOpens("jdk.internal.misc", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(base.isOpen("jdk.internal.misc"));
- assertFalse(base.isOpen("jdk.internal.misc", thisModule));
-
- // canUse
- assertTrue(base.canUse(FileSystemProvider.class));
- assertFalse(base.canUse(Thread.class));
-
- // addUses
- try {
- base.addUses(FileSystemProvider.class);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- try {
- base.addUses(Thread.class);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(base.canUse(Thread.class));
- }
-
-
- @Test
- public void testDesktopModule() {
- Module desktop = java.awt.Component.class.getModule();
- Module base = Object.class.getModule();
- Module xml = javax.xml.XMLConstants.class.getModule();
- Module thisModule = BasicModuleTest.class.getModule();
-
- // name
- assertTrue(desktop.getName().equals("java.desktop"));
-
- // descriptor
- assertTrue(desktop.getDescriptor().exports().stream()
- .anyMatch(doesExport("java.awt")));
-
- // getClassLoader
- assertTrue(desktop.getClassLoader() == null);
-
- // getLayer
- assertTrue(desktop.getLayer() == Layer.boot());
-
- // toString
- assertEquals(desktop.toString(), "module java.desktop");
-
- // getPackages
- assertTrue(contains(desktop.getPackages(), "java.awt"));
- assertTrue(contains(desktop.getPackages(), "sun.awt"));
-
- // canRead
- assertTrue(desktop.canRead(base));
- assertTrue(desktop.canRead(xml));
-
- // addReads
- try {
- desktop.addReads(thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(desktop.canRead(thisModule));
-
- // isExported
- assertTrue(desktop.isExported("java.awt"));
- assertTrue(desktop.isExported("java.awt", thisModule));
- assertFalse(desktop.isExported("sun.awt"));
- assertFalse(desktop.isExported("sun.awt", thisModule));
- assertTrue(desktop.isExported("sun.awt", desktop));
- assertFalse(desktop.isExported("java.wombat"));
- assertFalse(desktop.isExported("java.wombat", thisModule));
- assertFalse(desktop.isExported("java.wombat", base));
-
- // addExports
- try {
- desktop.addExports("java.awt", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- try {
- desktop.addExports("sun.awt", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(desktop.isExported("sun.awt"));
- assertFalse(desktop.isExported("sun.awt", thisModule));
-
- // isOpen
- assertFalse(desktop.isOpen("java.awt"));
- assertFalse(desktop.isOpen("java.awt", thisModule));
- assertTrue(desktop.isOpen("java.awt", desktop));
- assertFalse(desktop.isOpen("sun.awt"));
- assertFalse(desktop.isOpen("sun.awt", thisModule));
- assertTrue(desktop.isOpen("sun.awt", desktop));
- assertFalse(desktop.isOpen("java.wombat"));
- assertFalse(desktop.isOpen("java.wombat", thisModule));
- assertFalse(desktop.isOpen("java.wombat", desktop));
-
- // addOpens
- try {
- base.addOpens("sun.awt", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(desktop.isOpen("sun.awt"));
- assertFalse(desktop.isOpen("sun.awt", thisModule));
-
- // canUse
- assertTrue(base.canUse(FileSystemProvider.class));
- assertFalse(base.canUse(Thread.class));
-
- // addUses
- try {
- desktop.addUses(PrintServiceLookup.class);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- try {
- desktop.addUses(Thread.class);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- assertFalse(desktop.canUse(Thread.class));
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/WithSecurityManager.java
--- a/jdk/test/java/lang/reflect/Module/WithSecurityManager.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @modules jdk.compiler
- * @summary Test java.lang.reflect.Module methods that specify permission checks
- * @run main/othervm -Djava.security.policy=${test.src}/allow.policy WithSecurityManager allow
- * @run main/othervm WithSecurityManager deny
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReference;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.Set;
-
-/**
- * Test java.lang.reflect.Module methods that specify permission checks.
- */
-
-public class WithSecurityManager {
-
- // a module that will be loaded into a child layer
- static final String ANOTHER_MODULE = "jdk.compiler";
- static final String ANOTHER_MODULE_RESOURCE = "com/sun/tools/javac/Main.class";
-
- public static void main(String[] args) throws IOException {
- boolean allow = args[0].equals("allow");
-
- // base module, in the boot layer
- Module base = Object.class.getModule();
-
- // another module, in a child layer
- Module other = loadModuleInChildLayer(ANOTHER_MODULE);
- assertTrue(other.getLayer() != Layer.boot());
-
- System.setSecurityManager(new SecurityManager());
-
- test(base, "java/lang/Object.class", allow);
- test(other, ANOTHER_MODULE_RESOURCE, allow);
- }
-
- /**
- * Test the permission checks by invoking methods on the given module.
- *
- * If {@code allow} is {@code true} then the permission checks should succeed.
- */
- static void test(Module m, String name, boolean allow) throws IOException {
-
- // test Module::getClassLoader
- System.out.format("Test getClassLoader on %s ...%n", m);
- try {
- ClassLoader cl = m.getClassLoader();
- System.out.println(cl);
- if (!allow)
- assertTrue("getClassLoader should have failed", false);
- } catch (SecurityException e) {
- System.out.println(e + " thrown");
- if (allow)
- throw e;
- }
-
- // test Module::getResourceAsStream
- System.out.format("Test getResourceAsStream(\"%s\") on %s ...%n", name, m);
- try (InputStream in = m.getResourceAsStream(name)) {
- System.out.println(in);
- if (allow && (in == null))
- assertTrue(name + " not found", false);
- if (!allow && (in != null))
- assertTrue(name + " should not be found", false);
- }
-
- }
-
- /**
- * Create a module layer that contains the given system module.
- */
- static Module loadModuleInChildLayer(String mn) {
- Optional omref = ModuleFinder.ofSystem().find(mn);
- assertTrue("module " + mn + " not a system module", omref.isPresent());
-
- // create a ModuleFinder that only finds this module
- ModuleReference mref = omref.get();
- ModuleFinder finder = new ModuleFinder() {
- @Override
- public Optional find(String name) {
- if (name.equals(mn))
- return Optional.of(mref);
- else
- return Optional.empty();
- }
-
- @Override
- public Set findAll() {
- return Collections.singleton(mref);
- }
- };
-
- // create a child configuration and layer with this module
- Layer bootLayer = Layer.boot();
- Configuration cf = bootLayer
- .configuration()
- .resolve(finder, ModuleFinder.of(), Set.of(ANOTHER_MODULE));
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, null);
-
- Optional om = layer.findModule(mn);
- assertTrue("module " + mn + " not in child layer", om.isPresent());
- return om.get();
- }
-
- static void assertTrue(String msg, boolean e) {
- if (!e)
- throw new RuntimeException(msg);
- }
-
- static void assertTrue(boolean e) {
- if (!e)
- throw new RuntimeException();
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/AccessTest.java
--- a/jdk/test/java/lang/reflect/Module/access/AccessTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.List;
-
-import static jdk.testlibrary.ProcessTools.executeTestJava;
-
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/**
- * @test
- * @library /lib/testlibrary
- * @modules jdk.compiler
- * @build AccessTest CompilerUtils jdk.testlibrary.*
- * @run testng AccessTest
- * @summary Driver for test that checks access to access to types in
- * exported and non-exported packages.
- */
-
-@Test
-public class AccessTest {
-
- private static final String TEST_SRC = System.getProperty("test.src");
-
- private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
- private static final Path MODS_DIR = Paths.get("mods");
-
-
- // the names of the modules in this test
- private static List modules = Arrays.asList("test", "target");
-
-
- /**
- * Compiles all modules used by the test
- */
- @BeforeTest
- public void compileAll() throws Exception {
- for (String mn : modules) {
- Path src = SRC_DIR.resolve(mn);
- Path mods = MODS_DIR.resolve(mn);
- assertTrue(CompilerUtils.compile(src, mods));
- }
- }
-
- /**
- * Run the test
- */
- public void runTest() throws Exception {
- int exitValue
- = executeTestJava("--module-path", MODS_DIR.toString(),
- "--add-modules", "target",
- "-Dsun.reflect.enableStrictMode=true",
- "-m", "test/test.Main")
- .outputTo(System.out)
- .errorTo(System.out)
- .getExitValue();
-
- assertTrue(exitValue == 0);
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/module-info.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module target {
- exports p1;
- exports p2;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/p1/Helper.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/p1/Helper.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 p1;
-
-import java.lang.reflect.Module;
-
-/**
- * Helper class in target module to allow test invoke addExports[Private]
- */
-
-public class Helper {
- Helper() { }
-
- public static void addExports(String pn, Module who) {
- Helper.class.getModule().addExports(pn, who);
- }
-
- public static void addOpens(String pn, Module who) {
- Helper.class.getModule().addOpens(pn, who);
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/p1/Public.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/p1/Public.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 p1;
-
-public class Public {
-
- // public constructor
- public Public() { }
-
- // non-public constructor
- private Public(Void ignore) { }
-
- // public field
- public static Object f1;
-
- // non-public field
- private static Object f2;
-
- // public method
- public static void foo() { }
-
- // non-public method
- private static void bar() { }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/p2/NonPublic.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/p2/NonPublic.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 p2;
-
-class NonPublic {
-
- // public constructor
- public NonPublic() { }
-
- // non-public constructor
- private NonPublic(Void ignore) { }
-
- // public field
- public static Object f1;
-
- // non-public field
- private static Object f2;
-
- // public method
- public static void foo() { }
-
- // non-public method
- private static void bar() { }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/q1/Public.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/q1/Public.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 q1;
-
-public class Public {
-
- // public constructor
- public Public() { }
-
- // non-public constructor
- private Public(Void ignore) { }
-
- // public field
- public static Object f1;
-
- // non-public field
- private static Object f2;
-
- // public method
- public static void foo() { }
-
- // non-public method
- private static void bar() { }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/target/q2/NonPublic.java
--- a/jdk/test/java/lang/reflect/Module/access/src/target/q2/NonPublic.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 q2;
-
-class NonPublic {
-
- // public constructor
- public NonPublic() { }
-
- // non-public constructor
- private NonPublic(Void ignore) { }
-
- // public field
- public static Object f1;
-
- // non-public field
- private static Object f2;
-
- // public method
- public static void foo() { }
-
- // non-public method
- private static void bar() { }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/test/module-info.java
--- a/jdk/test/java/lang/reflect/Module/access/src/test/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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.
- */
-
-module test { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/access/src/test/test/Main.java
--- a/jdk/test/java/lang/reflect/Module/access/src/test/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,379 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * 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 test;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Method;
-import java.lang.reflect.Module;
-
-/**
- * Test access to public/non-public members of public/non-public classes in
- * exported and non-exported packages.
- */
-
-public class Main {
-
- public static void main(String[] args) throws Exception {
- testPublicClassInExportedPackage();
- testNonPublicClassInExportedPackage();
- testPublicClassInNonExportedPackage();
- testNonPublicClassInNonExportedPackage();
- }
-
- static void testPublicClassInExportedPackage() throws Exception {
- Module thisModule = Main.class.getModule();
- Module targetModule = getTargetModule();
-
- assertTrue(targetModule.isExported("p1"));
- assertTrue(targetModule.isExported("p1", thisModule));
- assertTrue(targetModule.isExported("p1", targetModule));
-
- assertFalse(targetModule.isOpen("p1"));
- assertFalse(targetModule.isOpen("p1", thisModule));
- assertTrue(targetModule.isOpen("p1", targetModule));
-
- Class> clazz = Class.forName("p1.Public");
- Constructor> ctor1 = clazz.getConstructor(); // public
- Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
-
- Field f1 = clazz.getField("f1"); // public
- Field f2 = clazz.getDeclaredField("f2"); // non-public
-
- Method m1 = clazz.getMethod("foo"); // public
- Method m2 = clazz.getDeclaredMethod("bar"); // non-public
-
- tryAccessConstructor(ctor1, true);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, true);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, true);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, true);
- trySetAccessible(m2, false);
- trySetAccessible(f1, true);
- trySetAccessible(f2, false);
-
- targetAddOpens("p1", thisModule);
-
- tryAccessConstructor(ctor1, true);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, true);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, true);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(ctor2, true);
- trySetAccessible(m1, true);
- trySetAccessible(m2, true);
- trySetAccessible(f1, true);
- trySetAccessible(f2, true);
- }
-
- static void testNonPublicClassInExportedPackage() throws Exception {
- Module thisModule = Main.class.getModule();
- Module targetModule = getTargetModule();
-
- assertTrue(targetModule.isExported("p2"));
- assertTrue(targetModule.isExported("p2", thisModule));
- assertTrue(targetModule.isExported("p2", targetModule));
-
- assertFalse(targetModule.isOpen("p2"));
- assertFalse(targetModule.isOpen("p2", thisModule));
- assertTrue(targetModule.isOpen("p1", targetModule));
-
- Class> clazz = Class.forName("p2.NonPublic");
- Constructor> ctor1 = clazz.getConstructor();
- Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class);
-
- Field f1 = clazz.getField("f1"); // public
- Field f2 = clazz.getDeclaredField("f2"); // non-public
-
- Method m1 = clazz.getMethod("foo"); // public
- Method m2 = clazz.getDeclaredMethod("bar"); // non-public
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, false);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, false);
- trySetAccessible(m2, false);
- trySetAccessible(f1, false);
- trySetAccessible(f2, false);
-
- targetAddExports("p2", thisModule);
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, false);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, false);
- trySetAccessible(m2, false);
- trySetAccessible(f1, false);
- trySetAccessible(f2, false);
-
- targetAddOpens("p2", thisModule);
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(ctor2, true);
- trySetAccessible(m1, true);
- trySetAccessible(m2, true);
- trySetAccessible(f1, true);
- trySetAccessible(f2, true);
- }
-
- static void testPublicClassInNonExportedPackage() throws Exception {
- Module thisModule = Main.class.getModule();
- Module targetModule = getTargetModule();
-
- assertFalse(targetModule.isExported("q1"));
- assertFalse(targetModule.isExported("q1", thisModule));
- assertTrue(targetModule.isExported("q1", targetModule));
-
- assertFalse(targetModule.isOpen("q1"));
- assertFalse(targetModule.isOpen("q1", thisModule));
- assertTrue(targetModule.isOpen("q1", targetModule));
-
- Class> clazz = Class.forName("q1.Public");
- Constructor> ctor1 = clazz.getConstructor(); // public
- Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
-
- Field f1 = clazz.getField("f1"); // public
- Field f2 = clazz.getDeclaredField("f2"); // non-public
-
- Method m1 = clazz.getMethod("foo"); // public
- Method m2 = clazz.getDeclaredMethod("bar"); // non-public
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, false);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, false);
- trySetAccessible(m2, false);
- trySetAccessible(f1, false);
- trySetAccessible(f2, false);
-
- targetAddExports("q1", thisModule);
-
- tryAccessConstructor(ctor1, true);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, true);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, true);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, true);
- trySetAccessible(m2, false);
- trySetAccessible(f1, true);
- trySetAccessible(f2, false);
-
- targetAddOpens("q1", thisModule);
-
- tryAccessConstructor(ctor1, true);
- tryAccessConstructor(ctor1, false);
- tryAccessMethod(m1, true);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, true);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(ctor2, true);
- trySetAccessible(m1, true);
- trySetAccessible(m2, true);
- trySetAccessible(f1, true);
- trySetAccessible(f2, true);
- }
-
- static void testNonPublicClassInNonExportedPackage() throws Exception {
- Module thisModule = Main.class.getModule();
- Module targetModule = getTargetModule();
-
- assertFalse(targetModule.isExported("q2"));
- assertFalse(targetModule.isExported("q2", thisModule));
- assertTrue(targetModule.isExported("q2", targetModule));
-
- assertFalse(targetModule.isOpen("q2"));
- assertFalse(targetModule.isOpen("q2", thisModule));
- assertTrue(targetModule.isOpen("q2", targetModule));
-
- Class> clazz = Class.forName("q2.NonPublic");
- Constructor> ctor1 = clazz.getConstructor(); // public
- Constructor> ctor2 = clazz.getDeclaredConstructor(Void.class); // non-public
-
- Field f1 = clazz.getField("f1"); // public
- Field f2 = clazz.getDeclaredField("f2"); // non-public
-
- Method m1 = clazz.getMethod("foo"); // public
- Method m2 = clazz.getDeclaredMethod("bar"); // non-public
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, false);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, false);
- trySetAccessible(m2, false);
- trySetAccessible(f1, false);
- trySetAccessible(f2, false);
-
- targetAddExports("q2", thisModule);
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, false);
- trySetAccessible(ctor2, false);
- trySetAccessible(m1, false);
- trySetAccessible(m2, false);
- trySetAccessible(f1, false);
- trySetAccessible(f2, false);
-
- targetAddOpens("q2", thisModule);
-
- tryAccessConstructor(ctor1, false);
- tryAccessConstructor(ctor2, false);
- tryAccessMethod(m1, false);
- tryAccessMethod(m2, false);
- tryAccessObjectField(f1, false);
- tryAccessObjectField(f2, false);
-
- trySetAccessible(ctor1, true);
- trySetAccessible(m1, true);
- trySetAccessible(m2, true);
- trySetAccessible(f1, true);
- trySetAccessible(f2, true);
- }
-
-
- static Module getTargetModule() {
- return Layer.boot().findModule("target").get();
- }
-
- static void tryAccessConstructor(Constructor> ctor, boolean shouldSucceed) {
- try {
- ctor.newInstance();
- assertTrue(shouldSucceed);
- } catch (Exception e) {
- assertFalse(shouldSucceed);
- }
- }
-
- static void tryAccessMethod(Method method, boolean shouldSucceed) {
- try {
- method.invoke(null);
- assertTrue(shouldSucceed);
- } catch (Exception e) {
- e.printStackTrace();
- assertFalse(shouldSucceed);
- }
- }
-
- static void tryAccessObjectField(Field f, boolean shouldSucceed) {
- try {
- f.get(null);
- assertTrue(shouldSucceed);
- } catch (Exception e) {
- assertFalse(shouldSucceed);
- }
- try {
- f.set(null, new Object());
- assertTrue(shouldSucceed);
- } catch (Exception e) {
- assertFalse(shouldSucceed);
- }
- }
-
- static void trySetAccessible(AccessibleObject ao, boolean shouldSucceed) {
- try {
- ao.setAccessible(true);
- assertTrue(shouldSucceed);
- } catch (Exception e) {
- assertFalse(shouldSucceed);
- }
- }
-
- /**
- * Update target module to export a package to the given module.
- */
- static void targetAddExports(String pn, Module who) throws Exception {
- Class> helper = Class.forName("p1.Helper");
- Method m = helper.getMethod("addExports", String.class, Module.class);
- m.invoke(null, pn, who);
- }
-
- /**
- * Update target module to open a package to the given module.
- */
- static void targetAddOpens(String pn, Module who) throws Exception {
- Class> helper = Class.forName("p1.Helper");
- Method m = helper.getMethod("addOpens", String.class, Module.class);
- m.invoke(null, pn, who);
- }
-
- static void assertTrue(boolean expr) {
- if (!expr) throw new RuntimeException();
- }
-
- static void assertFalse(boolean expr) {
- assertTrue(!expr);
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/Driver.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/Driver.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @build test/* m1/* m2/* m3/* m4/*
- * @run testng/othervm test/test.Main
- * @summary Basic test case for Module::addXXX methods
- */
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m1/module-info.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m1/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-module m1 {
- exports p1;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m1/p1/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m1/p1/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * 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.
- *
- * 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 p1;
-
-public class C {
- public C() { }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m2/module-info.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m2/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-module m2 {
- exports p2;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m2/p2/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m2/p2/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * 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.
- *
- * 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 p2;
-
-import java.lang.reflect.Module;
-
-public class C {
-
- public static void export(String pn, Module m) {
- C.class.getModule().addExports(pn, m);
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m2/p2/internal/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m2/p2/internal/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * 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.
- *
- * 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 p2.internal;
-
-public class C {
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m3/module-info.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m3/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-module m3 {
- exports p3 to test;
- opens p3 to test;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m3/p3/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m3/p3/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * 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.
- *
- * 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 p3;
-
-public class C {
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m4/module-info.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m4/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-module m4 {
- exports p4;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/m4/p4/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/m4/p4/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * 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.
- *
- * 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 p4;
-
-import java.lang.reflect.Constructor;
-
-public class C {
- public static Object tryNewInstance(Class> clazz) throws Exception {
- Constructor> ctor = clazz.getDeclaredConstructor();
- return ctor.newInstance();
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/test/module-info.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/test/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-module test {
- exports test to testng;
-
- requires m2;
- requires m3;
- requires m4;
- requires testng;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/test/test/C.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/test/test/C.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * 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.
- *
- * 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 test;
-
-public class C { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/test/test/Main.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/test/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,196 +0,0 @@
-/*
- * 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.
- *
- * 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 test;
-
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Module;
-import java.util.ServiceConfigurationError;
-import java.util.ServiceLoader;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/**
- * Basic test case for Module::addXXXX methods
- */
-
-@Test
-public class Main {
-
- /**
- * Test Module::addReads
- *
- * module test { }
- *
- * module m1 {
- * exports p1;
- * }
- */
- public void testAddReads() throws Throwable {
- Module thisModule = Main.class.getModule();
- Class> clazz = Class.forName("p1.C");
- Module m1 = clazz.getModule();
-
- // test does not read m1
- assertFalse(thisModule.canRead(m1));
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- MethodType mt = MethodType.methodType(void.class);
- try {
- lookup.findConstructor(clazz, mt);
- assertTrue(false);
- } catch (IllegalAccessException expected) { }
-
- // update test to read m1
- Module result = thisModule.addReads(m1);
- assertTrue(result== thisModule);
- assertTrue(thisModule.canRead(m1));
- MethodHandle mh = lookup.findConstructor(clazz, mt);
- Object obj = mh.invoke();
-
- // attempt to update m1 to read test
- try {
- m1.addReads(thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- }
-
-
- /**
- * Test Module::addExports
- *
- * module test {
- * requires m2;
- * }
- * module m2 {
- * exports p2;
- * contains package p2.internal;
- * }
- */
- public void testAddExports() throws Exception {
- Module thisModule = Main.class.getModule();
- Module m2 = p2.C.class.getModule();
- Class> targetClass = Class.forName("p2.internal.C");
- String p2Internal = targetClass.getPackageName();
- assertTrue(targetClass.getModule() == m2);
-
- // m2 does not export p2.internal to test
- assertFalse(m2.isExported(p2Internal, thisModule));
- Constructor> ctor = targetClass.getDeclaredConstructor();
- try {
- ctor.newInstance();
- assertTrue(false);
- } catch (IllegalAccessException expected) { }
-
- // update m2 to export p2.internal to test
- p2.C.export(p2Internal, thisModule);
- assertTrue(m2.isExported(p2Internal, thisModule));
- ctor.newInstance(); // should succeed
-
- // attempt to update m2 to export a package to test
- try {
- m2.addExports("p2.other", thisModule);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- }
-
- /**
- * Test Module::addOpens
- *
- * module test {
- * requires m3;
- * requires m4;
- * }
- *
- * module m3 {
- * exports p3 to test;
- * opens p3 to test;
- * }
- *
- * module m4 {
- * exports p4;
- * }
- */
- public void testAddOpens() throws Exception {
- Module thisModule = Main.class.getModule();
- Module m3 = p3.C.class.getModule();
- Module m4 = p4.C.class.getModule();
-
- // test does not open package test to m4
- assertFalse(thisModule.isOpen("test", m4));
- try {
- p4.C.tryNewInstance(test.C.class);
- assertTrue(false);
- } catch (IllegalAccessException expected) { }
-
- // open test to m4
- thisModule.addOpens("test", m4);
- p4.C.tryNewInstance(test.C.class); // should succeed
-
-
- // m3 does not open p3 to m4
- assertFalse(m3.isOpen("p3", m4));
- try {
- p4.C.tryNewInstance(p3.C.class);
- assertTrue(false);
- } catch (IllegalAccessException expected) { }
-
-
- // m3 opens p3 to test => test allowed to open m3/p3 to m4
- assertTrue(m3.isOpen("p3", thisModule));
- m3.addOpens("p3", m4);
- assertTrue(m3.isOpen("p3", m4));
- p4.C.tryNewInstance(p3.C.class); // should succeed
-
-
- // attempt to update m4 to open package to m3
- try {
- m4.addOpens("p4", m3);
- assertTrue(false);
- } catch (IllegalCallerException expected) { }
- }
-
-
- /**
- * Test Module::addUses
- */
- public void testAddUses() {
- Module thisModule = Main.class.getModule();
-
- assertFalse(thisModule.canUse(Service.class));
- try {
- ServiceLoader.load(Service.class);
- assertTrue(false);
- } catch (ServiceConfigurationError expected) { }
-
- Module result = thisModule.addUses(Service.class);
- assertTrue(result== thisModule);
-
- assertTrue(thisModule.canUse(Service.class));
- ServiceLoader.load(Service.class); // no exception
- }
-
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/addXXX/test/test/Service.java
--- a/jdk/test/java/lang/reflect/Module/addXXX/test/test/Service.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * 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.
- *
- * 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 test;
-
-/**
- * Simple service type
- */
-public interface Service { }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/allow.policy
--- a/jdk/test/java/lang/reflect/Module/allow.policy Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2016, 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.
- *
- * 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.
- */
-
-grant {
- permission java.lang.RuntimePermission "getClassLoader";
- permission java.lang.RuntimePermission "accessSystemModules";
- permission java.io.FilePermission "${java.home}/modules/-", "read"; // exploded build
-};
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/annotation/Basic.java
--- a/jdk/test/java/lang/reflect/Module/annotation/Basic.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @library src
- * @build m/* Basic
- * @run testng/othervm Basic
- * @summary Basic test for annotations on modules
- */
-
-import java.lang.reflect.Module;
-import java.util.Arrays;
-
-import p.annotation.Foo;
-import p.annotation.Bar;
-import p.annotation.Baz;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-public class Basic {
-
- final Module module = Foo.class.getModule();
-
- /**
- * {@code @Foo} does not have RUNTIME retention policy.
- */
- @Test
- public void testInvisibleAnnotation() {
- assertFalse(module.isAnnotationPresent(Foo.class));
- assertNull(module.getAnnotation(Foo.class));
- }
-
- /**
- * {@code @Bar} has RUNTIME retention policy and value "bar"
- */
- @Test
- public void testBarAnnotation() {
- assertTrue(module.isAnnotationPresent(Bar.class));
- Bar bar = module.getAnnotation(Bar.class);
- assertNotNull(bar);
- assertEquals(bar.value(), "bar");
- }
-
- /**
- * {@code @Baz} has RUNTIME retention policy has a repeating value
- */
- @Test
- public void testBazAnnotation() {
- assertTrue(module.isAnnotationPresent(Baz.class));
- Baz baz = module.getAnnotation(Baz.class);
- assertNotNull(baz);
- String[] expected = { "one", "two", "three" };
- assertTrue(Arrays.equals(baz.value(), expected));
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/annotation/src/m/module-info.java
--- a/jdk/test/java/lang/reflect/Module/annotation/src/m/module-info.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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.
- */
-
-import p.annotation.*;
-
-@Foo
-@Bar("bar")
-@Baz({"one", "two", "three"})
-module m {
- exports p.annotation;
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Bar.java
--- a/jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Bar.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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 p.annotation;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import static java.lang.annotation.ElementType.MODULE;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value={MODULE})
-public @interface Bar {
- String value();
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Baz.java
--- a/jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Baz.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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 p.annotation;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import static java.lang.annotation.ElementType.MODULE;
-
-@Target(value={MODULE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Baz {
- String[] value();
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Foo.java
--- a/jdk/test/java/lang/reflect/Module/annotation/src/m/p/annotation/Foo.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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 p.annotation;
-
-import java.lang.annotation.Target;
-import static java.lang.annotation.ElementType.MODULE;
-
-@Target(value={MODULE})
-public @interface Foo {}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/ProxyClassAccessTest.java
--- a/jdk/test/java/lang/reflect/Proxy/ProxyClassAccessTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/ProxyClassAccessTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.lang.reflect.Proxy;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -88,12 +87,12 @@
@Test
public void testNoReadAccess() throws Exception {
ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer
.configuration()
.resolveAndBind(ModuleFinder.of(), finder, modules);
ClassLoader parentLoader = this.getClass().getClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, parentLoader);
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, parentLoader);
ClassLoader loader = layer.findLoader("m1");
Class>[] interfaces = new Class>[] {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/ProxyForMethodHandle.java
--- a/jdk/test/java/lang/reflect/Proxy/ProxyForMethodHandle.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/ProxyForMethodHandle.java Wed Jul 05 23:13:02 2017 +0200
@@ -28,7 +28,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Module;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/ProxyLayerTest.java
--- a/jdk/test/java/lang/reflect/Proxy/ProxyLayerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/ProxyLayerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Layer;
import java.lang.reflect.Proxy;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -70,18 +69,18 @@
}
/**
- * Test proxy implementing interfaces in a Layer defined in
+ * Test proxy implementing interfaces in a layer defined in
* an unnamed module
*/
@Test
public void testProxyInUnnamed() throws Exception {
ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer
.configuration()
.resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules));
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader("m1");
@@ -110,12 +109,12 @@
@Test
public void testProxyInDynamicModule() throws Exception {
ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer
.configuration()
.resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules));
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader("m1");
@@ -140,12 +139,12 @@
@Test
public void testNoReadAccess() throws Exception {
ModuleFinder finder = ModuleFinder.of(MODS_DIR);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer
.configuration()
.resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules));
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader("m1");
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/ProxyModuleMapping.java
--- a/jdk/test/java/lang/reflect/Proxy/ProxyModuleMapping.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/ProxyModuleMapping.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Module;
import java.lang.reflect.Proxy;
/*
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/Main.java
--- a/jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -25,7 +25,6 @@
import java.net.URL;
import java.net.URLClassLoader;
-import java.lang.reflect.Module;
import static jdk.test.ProxyTest.*;
public class Main {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/ProxyTest.java
--- a/jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/ProxyTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/lang/reflect/Proxy/src/test/jdk/test/ProxyTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,7 +26,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Module;
import java.lang.reflect.Proxy;
import java.util.Arrays;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/WeakPairMap/Driver.java
--- a/jdk/test/java/lang/reflect/WeakPairMap/Driver.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @bug 8888888
- * @summary Functional test for WeakPairMap
- * @build java.base/java.lang.reflect.WeakPairMapTest
- * @run main Driver
- */
-public class Driver {
- public static void main(String[] args) {
- java.lang.reflect.WeakPairMapTest.main(args);
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/lang/reflect/WeakPairMap/java.base/java/lang/reflect/WeakPairMapTest.java
--- a/jdk/test/java/lang/reflect/WeakPairMap/java.base/java/lang/reflect/WeakPairMapTest.java Thu Apr 13 20:35:38 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 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.
- *
- * 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.reflect;
-
-import java.lang.ref.Reference;
-import java.util.Objects;
-
-/**
- * Functional test for WeakPairMap
- *
- * @author Peter Levart
- */
-public class WeakPairMapTest {
- public static void main(String[] args) {
- WeakPairMap pm = new WeakPairMap<>();
- Object key1 = new Object();
- Object key2 = new Object();
-
- // check for emptiness
- assertEquals(pm.containsKeyPair(key1, key2), false);
- assertEquals(pm.get(key1, key2), null);
-
- // check for NPE(s)
- for (Object k1 : new Object[]{null, key1}) {
- for (Object k2 : new Object[]{null, key2}) {
- for (String v : new String[]{null, "abc"}) {
-
- if (k1 != null && k2 != null && v != null) {
- // skip non-null args
- continue;
- }
-
- try {
- pm.put(k1, k2, v);
- throw new AssertionError("Unexpected code path, k1=" +
- k1 + ", k2=" + k2 + ", v=" + v);
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- pm.putIfAbsent(k1, k2, v);
- throw new AssertionError("Unexpected code path, k1=" +
- k1 + ", k2=" + k2 + ", v=" + v);
- } catch (NullPointerException e) {
- // expected
- }
-
- if (k1 != null && k2 != null) {
- // skip non-null args
- continue;
- }
-
- try {
- pm.computeIfAbsent(k1, k2, (_k1, _k2) -> v);
- throw new AssertionError("Unexpected code path, k1=" +
- k1 + ", k2=" + k2 + ", v=" + v);
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- pm.containsKeyPair(k1, k2);
- throw new AssertionError("Unexpected code path, k1=" +
- k1 + ", k2=" + k2);
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- pm.get(k1, k2);
- throw new AssertionError("Unexpected code path, k1=" +
- k1 + ", k2=" + k2);
- } catch (NullPointerException e) {
- // expected
- }
- }
- }
- }
-
- // how much to wait when it is expected for entry to be retained
- final long retentionTimeout = 500L;
- // how much to wait when it is expected for entry to be removed
- final long cleanupTimeout = 30_000L;
-
- // check insertion
- assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check retention while both keys are still reachable
- assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check cleanup when both keys are unreachable
- key1 = null;
- key2 = null;
- assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
-
- // new insertion
- key1 = new Object();
- key2 = new Object();
- assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check retention while both keys are still reachable
- assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check cleanup when 1st key is unreachable
- key1 = null;
- assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
- Reference.reachabilityFence(key2);
-
- // new insertion
- key1 = new Object();
- key2 = new Object();
- assertEquals(pm.putIfAbsent(key1, key2, "abc"), null);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check retention while both keys are still reachable
- assertEquals(gcAndWaitRemoved(pm, "abc", retentionTimeout), false);
- assertEquals(pm.get(key1, key2), "abc");
-
- // check cleanup when 2nd key is unreachable
- key2 = null;
- assertEquals(gcAndWaitRemoved(pm, "abc", cleanupTimeout), true);
- Reference.reachabilityFence(key1);
- }
-
- /**
- * Trigger GC and wait for at most {@code millis} ms for given value to
- * be removed from given WeakPairMap.
- *
- * @return true if element has been removed or false if not
- */
- static boolean gcAndWaitRemoved(WeakPairMap, ?, V> pm, V value,
- long millis) {
- System.gc();
- for (int i = 0; i < (millis + 99) / 100 && pm.values().contains(value); i++) {
- try {
- Thread.sleep(100L);
- } catch (InterruptedException e) {
- throw new AssertionError("Interrupted");
- }
- }
- return !pm.values().contains(value);
- }
-
- static void assertEquals(Object actual, Object expected) {
- if (!Objects.equals(actual, expected)) {
- throw new AssertionError("Expected: " + expected + ", actual: " + actual);
- }
- }
-}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/nio/channels/SocketChannel/VectorIO.java
--- a/jdk/test/java/nio/channels/SocketChannel/VectorIO.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/nio/channels/SocketChannel/VectorIO.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -22,8 +22,10 @@
*/
/* @test
- * @summary Test socketchannel vector IO
- * @library ..
+ * @summary Test socketchannel vector IO (use -Dseed=X to set PRNG seed)
+ * @library .. /lib/testlibrary/
+ * @build jdk.testlibrary.RandomFactory
+ * @run main VectorIO
* @key randomness
*/
@@ -32,11 +34,11 @@
import java.nio.*;
import java.nio.channels.*;
import java.util.*;
-
+import jdk.testlibrary.RandomFactory;
public class VectorIO {
- static Random generator = new Random();
+ private static Random generator = RandomFactory.getRandom();
static int testSize;
@@ -100,8 +102,6 @@
static class Server
extends TestThread
{
- static Random generator = new Random();
-
final int testSize;
final ServerSocketChannel ssc;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/nio/channels/etc/AdaptorCloseAndInterrupt.java
--- a/jdk/test/java/nio/channels/etc/AdaptorCloseAndInterrupt.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/nio/channels/etc/AdaptorCloseAndInterrupt.java Wed Jul 05 23:13:02 2017 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.Random;
@@ -46,6 +47,9 @@
final DatagramChannel peer;
final int port;
+ final AtomicBoolean isClosed = new AtomicBoolean();
+ final AtomicBoolean isInterrupted = new AtomicBoolean();
+
public AdaptorCloseAndInterrupt() {
listener = null;
peer = null;
@@ -96,6 +100,7 @@
try {
sc.socket().getInputStream().read(new byte[100]);
+ System.err.format("close() was invoked: %s%n", isClosed.get());
throw new RuntimeException("read should not have completed");
} catch (ClosedChannelException expected) {}
@@ -119,7 +124,10 @@
sc.socket().getInputStream().read(new byte[100]);
throw new RuntimeException("read should not have completed");
} catch (ClosedByInterruptException expected) {
- Thread.currentThread().interrupted();
+ System.out.format("interrupt() was invoked: %s%n",
+ isInterrupted.get());
+ System.out.format("scReadAsyncInterrupt was interrupted: %s%n",
+ Thread.currentThread().interrupted());
}
if (!sc.socket().isClosed())
@@ -140,6 +148,7 @@
try {
dc.socket().receive(new DatagramPacket(new byte[100], 100));
+ System.err.format("close() was invoked: %s%n", isClosed.get());
throw new RuntimeException("receive should not have completed");
} catch (ClosedChannelException expected) {}
@@ -159,7 +168,16 @@
dc.socket().receive(new DatagramPacket(new byte[100], 100));
throw new RuntimeException("receive should not have completed");
} catch (ClosedByInterruptException expected) {
- Thread.currentThread().interrupted();
+ System.out.format("interrupt() was invoked: %s%n",
+ isInterrupted.get());
+ System.out.format("dcReceiveAsyncInterrupt was interrupted: %s%n",
+ Thread.currentThread().interrupted());
+ } catch (SocketTimeoutException unexpected) {
+ System.err.format("Receive thread interrupt invoked: %s%n",
+ isInterrupted.get());
+ System.err.format("Receive thread was interrupted: %s%n",
+ Thread.currentThread().isInterrupted());
+ throw unexpected;
}
if (!dc.socket().isClosed())
@@ -175,6 +193,7 @@
try {
ssc.socket().accept();
+ System.err.format("close() was invoked: %s%n", isClosed.get());
throw new RuntimeException("accept should not have completed");
} catch (ClosedChannelException expected) {}
@@ -193,7 +212,10 @@
ssc.socket().accept();
throw new RuntimeException("accept should not have completed");
} catch (ClosedByInterruptException expected) {
- Thread.currentThread().interrupted();
+ System.out.format("interrupt() was invoked: %s%n",
+ isInterrupted.get());
+ System.out.format("ssAcceptAsyncInterrupt was interrupted: %s%n",
+ Thread.currentThread().interrupted());
}
if (!ssc.socket().isClosed())
@@ -204,6 +226,7 @@
AdaptorCloseAndInterrupt.pool.schedule(new Callable() {
public Void call() throws Exception {
sc.close();
+ isClosed.set(true);
return null;
}
}, new Random().nextInt(1000), TimeUnit.MILLISECONDS);
@@ -214,6 +237,7 @@
AdaptorCloseAndInterrupt.pool.schedule(new Callable() {
public Void call() throws Exception {
current.interrupt();
+ isInterrupted.set(true);
return null;
}
}, new Random().nextInt(1000), TimeUnit.MILLISECONDS);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/security/Provider/DefaultProviderList.java
--- a/jdk/test/java/security/Provider/DefaultProviderList.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/security/Provider/DefaultProviderList.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.ServiceLoader;
-import java.lang.reflect.Module;
public class DefaultProviderList {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/cache/src/test/jdk/test/Main.java
--- a/jdk/test/java/util/ResourceBundle/modules/cache/src/test/jdk/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/cache/src/test/jdk/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.test;
-import java.lang.reflect.Module;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -56,4 +55,4 @@
jdk.test.util.Bundles.getBundle();
}
}
-}
\ No newline at end of file
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/casesensitive/CaseInsensitiveNameClash.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/casesensitive/CaseInsensitiveNameClash.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8177980
+ * @library /lib/testlibrary
+ * @modules jdk.compiler
+ * @build CompilerUtils jdk.testlibrary.ProcessTools CaseInsensitiveNameClash
+ * @run testng CaseInsensitiveNameClash
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import jdk.testlibrary.ProcessTools;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+public class CaseInsensitiveNameClash {
+
+ private static final String TEST_SRC = System.getProperty("test.src");
+
+ private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
+ private static final Path MODS_DIR = Paths.get("mods");
+
+ private static final String MODULE = "resbundle";
+ private static final String MAIN_CLASS = MODULE + "/jdk.test.Main";
+
+ /**
+ * Compiles the module used by the test
+ */
+ @BeforeTest
+ public void compileAll() throws Exception {
+ Path msrc = SRC_DIR.resolve(MODULE);
+ assertTrue(CompilerUtils.compile(msrc, MODS_DIR,
+ "--module-source-path", SRC_DIR.toString()));
+ Path propsFile = Paths.get("jdk", "test", "main.properties");
+ Files.copy(msrc.resolve(propsFile), MODS_DIR.resolve(MODULE).resolve(propsFile));
+ }
+
+ @Test
+ public void test() throws Exception {
+ assertTrue(ProcessTools.executeTestJava("--module-path", MODS_DIR.toString(),
+ "-m", MAIN_CLASS)
+ .outputTo(System.out)
+ .errorTo(System.out)
+ .getExitValue() == 0);
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/jdk/test/Main.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/jdk/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ *
+ * 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.test;
+
+import java.util.ResourceBundle;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ ResourceBundle bundle = ResourceBundle.getBundle("jdk.test.main");
+ if (!bundle.getString("key").equals("value")) {
+ throw new RuntimeException("Expected: value but get " + bundle.getString("key"));
+ }
+ }
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/jdk/test/main.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/jdk/test/main.properties Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,1 @@
+key=value
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/module-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/casesensitive/src/resbundle/module-info.java Wed Jul 05 23:13:02 2017 +0200
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+module resbundle {
+}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/security/src/test/jdk/test/Main.java
--- a/jdk/test/java/util/ResourceBundle/modules/security/src/test/jdk/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/security/src/test/jdk/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -24,7 +24,6 @@
package jdk.test;
import p1.Bundle;
-import java.lang.reflect.Module;
import java.util.ResourceBundle;
public class Main {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithNoModuleArg.java
--- a/jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithNoModuleArg.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithNoModuleArg.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.embargo;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithUnnamedModuleArg.java
--- a/jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithUnnamedModuleArg.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/visibility/src/embargo/jdk/embargo/TestWithUnnamedModuleArg.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.embargo;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/visibility/src/pkg/jdk/pkg/test/Main.java
--- a/jdk/test/java/util/ResourceBundle/modules/visibility/src/pkg/jdk/pkg/test/Main.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/visibility/src/pkg/jdk/pkg/test/Main.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.pkg.test;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithNoModuleArg.java
--- a/jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithNoModuleArg.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithNoModuleArg.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.test;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithUnnamedModuleArg.java
--- a/jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithUnnamedModuleArg.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ResourceBundle/modules/visibility/src/test/jdk/test/TestWithUnnamedModuleArg.java Wed Jul 05 23:13:02 2017 +0200
@@ -23,7 +23,6 @@
package jdk.test;
-import java.lang.reflect.Module;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ServiceLoader/modules/BadProvidersTest.java
--- a/jdk/test/java/util/ServiceLoader/modules/BadProvidersTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ServiceLoader/modules/BadProvidersTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,7 +33,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -87,14 +86,14 @@
private List loadProviders(Path mp, String moduleName) throws Exception {
ModuleFinder finder = ModuleFinder.of(mp);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf = bootLayer.configuration()
.resolveAndBind(finder, ModuleFinder.of(), Set.of(moduleName));
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl);
+ ModuleLayer layer = ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
Class> service = layer.findLoader(moduleName).loadClass(TEST_SERVICE);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/ServiceLoader/modules/Basic.java
--- a/jdk/test/java/util/ServiceLoader/modules/Basic.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/ServiceLoader/modules/Basic.java Wed Jul 05 23:13:02 2017 +0200
@@ -34,7 +34,6 @@
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -229,7 +228,7 @@
*/
@Test
public void testWithCustomLayer1() {
- Layer layer = createCustomLayer("bananascript");
+ ModuleLayer layer = createCustomLayer("bananascript");
ClassLoader loader = layer.findLoader("bananascript");
List providers
@@ -258,7 +257,7 @@
*/
@Test
public void testWithCustomLayer2() {
- Layer layer = createCustomLayer("bananascript");
+ ModuleLayer layer = createCustomLayer("bananascript");
List factories
= collectAll(ServiceLoader.load(layer, ScriptEngineFactory.class));
@@ -293,7 +292,7 @@
*/
@Test
public void testWithCustomLayer3() {
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration cf0 = bootLayer.configuration();
// boot layer should contain "bananascript"
@@ -313,12 +312,12 @@
// layer1
Configuration cf1 = cf0.resolveAndBind(finder, ModuleFinder.of(), Set.of());
- Layer layer1 = bootLayer.defineModulesWithOneLoader(cf1, scl);
+ ModuleLayer layer1 = bootLayer.defineModulesWithOneLoader(cf1, scl);
assertTrue(layer1.modules().size() == 1);
// layer2
Configuration cf2 = cf0.resolveAndBind(finder, ModuleFinder.of(), Set.of());
- Layer layer2 = bootLayer.defineModulesWithOneLoader(cf2, scl);
+ ModuleLayer layer2 = bootLayer.defineModulesWithOneLoader(cf2, scl);
assertTrue(layer2.modules().size() == 1);
// layer3 with layer1 and layer2 as parents
@@ -326,7 +325,8 @@
List.of(cf1, cf2),
ModuleFinder.of(),
Set.of());
- Layer layer3 = Layer.defineModulesWithOneLoader(cf3, List.of(layer1, layer2), scl).layer();
+ ModuleLayer layer3
+ = ModuleLayer.defineModulesWithOneLoader(cf3, List.of(layer1, layer2), scl).layer();
assertTrue(layer3.modules().size() == 1);
@@ -390,12 +390,12 @@
@Test(expectedExceptions = { NullPointerException.class })
public void testLoadNull3() {
class S { }
- ServiceLoader.load((Layer) null, S.class);
+ ServiceLoader.load((ModuleLayer) null, S.class);
}
@Test(expectedExceptions = { NullPointerException.class })
public void testLoadNull4() {
- ServiceLoader.load(Layer.empty(), null);
+ ServiceLoader.load(ModuleLayer.empty(), null);
}
@Test(expectedExceptions = { NullPointerException.class })
@@ -404,19 +404,19 @@
}
/**
- * Create a custom Layer by resolving the given module names. The modules
+ * Create a custom layer by resolving the given module names. The modules
* are located in the {@code ${test.classes}/modules} directory.
*/
- private Layer createCustomLayer(String... modules) {
+ private ModuleLayer createCustomLayer(String... modules) {
Path dir = Paths.get(System.getProperty("test.classes", "."), "modules");
ModuleFinder finder = ModuleFinder.of(dir);
Set roots = new HashSet<>();
Collections.addAll(roots, modules);
- Layer bootLayer = Layer.boot();
+ ModuleLayer bootLayer = ModuleLayer.boot();
Configuration parent = bootLayer.configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), roots);
ClassLoader scl = ClassLoader.getSystemClassLoader();
- Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+ ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
assertTrue(layer.modules().size() == 1);
return layer;
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ArrayDeque8Test.java
--- a/jdk/test/java/util/concurrent/tck/ArrayDeque8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ArrayDeque8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -37,7 +37,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayDeque8Test extends JSR166TestCase {
public static void main(String[] args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ArrayDequeTest.java
--- a/jdk/test/java/util/concurrent/tck/ArrayDequeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ArrayDequeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -35,7 +35,6 @@
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -44,7 +43,6 @@
import java.util.concurrent.ThreadLocalRandom;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayDequeTest extends JSR166TestCase {
public static void main(String[] args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ArrayListTest.java
--- a/jdk/test/java/util/concurrent/tck/ArrayListTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ArrayListTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -33,11 +33,9 @@
*/
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ArrayListTest extends JSR166TestCase {
public static void main(String[] args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/AtomicReferenceFieldUpdaterTest.java
--- a/jdk/test/java/util/concurrent/tck/AtomicReferenceFieldUpdaterTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/AtomicReferenceFieldUpdaterTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -75,7 +75,7 @@
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
- assertFalse(seven == a.get(this));
+ assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}
@@ -208,7 +208,7 @@
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
- assertFalse(seven == a.get(this));
+ assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/AtomicReferenceTest.java
--- a/jdk/test/java/util/concurrent/tck/AtomicReferenceTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/AtomicReferenceTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -153,7 +153,7 @@
AtomicReference z = serialClone(x);
assertNotSame(y, z);
assertEquals(one, x.get());
- assertEquals(null, y.get());
+ assertNull(y.get());
assertEquals(one, z.get());
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/CompletableFutureTest.java
--- a/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -2589,28 +2589,28 @@
// unspecified behavior - both source completions available
try {
- assertEquals(null, h0.join());
+ assertNull(h0.join());
rs[0].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
- assertEquals(null, h1.join());
+ assertNull(h1.join());
rs[1].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
- assertEquals(null, h2.join());
+ assertNull(h2.join());
rs[2].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
- assertEquals(null, h3.join());
+ assertNull(h3.join());
rs[3].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);
@@ -2849,28 +2849,28 @@
// unspecified behavior - both source completions available
try {
- assertEquals(null, h0.join());
+ assertNull(h0.join());
rs[0].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
- assertEquals(null, h1.join());
+ assertNull(h1.join());
rs[1].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
- assertEquals(null, h2.join());
+ assertNull(h2.join());
rs[2].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
- assertEquals(null, h3.join());
+ assertNull(h3.join());
rs[3].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -237,8 +237,8 @@
Set set1 = map.keySet();
Set set2 = map.keySet(true);
set2.add(six);
- assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
- assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
+ assertSame(map, ((ConcurrentHashMap.KeySetView)set2).getMap());
+ assertSame(map, ((ConcurrentHashMap.KeySetView)set1).getMap());
assertEquals(set2.size(), map.size());
assertEquals(set1.size(), map.size());
assertTrue((Boolean)map.get(six));
@@ -332,10 +332,10 @@
assertFalse(set.add(one));
assertTrue(set.add(six));
assertTrue(set.add(seven));
- assertTrue(set.getMappedValue() == one);
- assertTrue(map.get(one) != one);
- assertTrue(map.get(six) == one);
- assertTrue(map.get(seven) == one);
+ assertSame(one, set.getMappedValue());
+ assertNotSame(one, map.get(one));
+ assertSame(one, map.get(six));
+ assertSame(one, map.get(seven));
}
void checkSpliteratorCharacteristics(Spliterator> sp,
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentHashMapTest.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentHashMapTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentHashMapTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,8 +43,6 @@
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -148,7 +146,7 @@
ConcurrentHashMap m =
new ConcurrentHashMap();
for (int i = 0; i < size; i++) {
- assertTrue(m.put(new CI(i), true) == null);
+ assertNull(m.put(new CI(i), true));
}
for (int i = 0; i < size; i++) {
assertTrue(m.containsKey(new CI(i)));
@@ -169,7 +167,7 @@
BS bs = new BS(String.valueOf(i));
LexicographicList bis = new LexicographicList(bi);
LexicographicList bss = new LexicographicList(bs);
- assertTrue(m.putIfAbsent(bis, true) == null);
+ assertNull(m.putIfAbsent(bis, true));
assertTrue(m.containsKey(bis));
if (m.putIfAbsent(bss, true) == null)
assertTrue(m.containsKey(bss));
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -43,7 +43,6 @@
import java.util.concurrent.ConcurrentLinkedDeque;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ConcurrentLinkedDequeTest extends JSR166TestCase {
@@ -67,7 +66,7 @@
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentLinkedDeque populatedDeque(int n) {
+ private static ConcurrentLinkedDeque populatedDeque(int n) {
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -41,7 +41,6 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class ConcurrentLinkedQueueTest extends JSR166TestCase {
@@ -65,7 +64,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentLinkedQueue populatedQueue(int n) {
+ private static ConcurrentLinkedQueue populatedQueue(int n) {
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -64,7 +64,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private ConcurrentSkipListSet populatedSet(int n) {
+ private static ConcurrentSkipListSet populatedSet(int n) {
ConcurrentSkipListSet q =
new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
@@ -80,7 +80,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private ConcurrentSkipListSet set5() {
+ private static ConcurrentSkipListSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@@ -229,7 +229,7 @@
} catch (ClassCastException success) {
assertTrue(q.size() < 2);
for (int i = 0, size = q.size(); i < size; i++)
- assertTrue(q.pollFirst().getClass() == Object.class);
+ assertSame(Object.class, q.pollFirst().getClass());
assertNull(q.pollFirst());
assertTrue(q.isEmpty());
assertEquals(0, q.size());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java
--- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -59,7 +59,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private NavigableSet populatedSet(int n) {
+ private static NavigableSet populatedSet(int n) {
ConcurrentSkipListSet q =
new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
@@ -79,7 +79,7 @@
/**
* Returns a new set of first 5 ints.
*/
- private NavigableSet set5() {
+ private static NavigableSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@@ -97,7 +97,7 @@
/**
* Returns a new set of first 5 negative ints.
*/
- private NavigableSet dset5() {
+ private static NavigableSet dset5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(m1);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java
--- a/jdk/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -44,7 +44,6 @@
import java.util.concurrent.CopyOnWriteArrayList;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class CopyOnWriteArrayListTest extends JSR166TestCase {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/CountedCompleter8Test.java
--- a/jdk/test/java/util/concurrent/tck/CountedCompleter8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/CountedCompleter8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -32,9 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
import java.util.concurrent.CountedCompleter;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/CountedCompleterTest.java
--- a/jdk/test/java/util/concurrent/tck/CountedCompleterTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/CountedCompleterTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -40,7 +40,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
-import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ExchangerTest.java
--- a/jdk/test/java/util/concurrent/tck/ExchangerTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ExchangerTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -160,12 +160,12 @@
public void realRun() throws InterruptedException {
assertSame(one, e.exchange(two));
exchanged.countDown();
- interrupted.await();
+ await(interrupted);
assertSame(three, e.exchange(one));
}});
Thread t3 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
- interrupted.await();
+ await(interrupted);
assertSame(one, e.exchange(three));
}});
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ExecutorCompletionService9Test.java
--- a/jdk/test/java/util/concurrent/tck/ExecutorCompletionService9Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ExecutorCompletionService9Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -37,7 +37,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ExecutorCompletionServiceTest.java
--- a/jdk/test/java/util/concurrent/tck/ExecutorCompletionServiceTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ExecutorCompletionServiceTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -172,7 +172,7 @@
CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
final CountDownLatch proceed = new CountDownLatch(1);
cs.submit(new Callable() { public String call() throws Exception {
- proceed.await();
+ await(proceed);
return TEST_STRING;
}});
assertNull(cs.poll());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ExecutorsTest.java
--- a/jdk/test/java/util/concurrent/tck/ExecutorsTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ExecutorsTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -333,16 +333,12 @@
public void realRun() {
try {
Thread current = Thread.currentThread();
- assertTrue(!current.isDaemon());
+ assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
- ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
- if (s != null)
- assertTrue(g == s.getThreadGroup());
- else
- assertTrue(g == egroup);
- String name = current.getName();
- assertTrue(name.endsWith("thread-1"));
+ assertSame(current.getThreadGroup(),
+ (s == null) ? egroup : s.getThreadGroup());
+ assertTrue(current.getName().endsWith("thread-1"));
} catch (SecurityException ok) {
// Also pass if not allowed to change setting
}
@@ -370,16 +366,12 @@
Runnable r = new CheckedRunnable() {
public void realRun() {
Thread current = Thread.currentThread();
- assertTrue(!current.isDaemon());
+ assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
- ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
- if (s != null)
- assertTrue(g == s.getThreadGroup());
- else
- assertTrue(g == egroup);
- String name = current.getName();
- assertTrue(name.endsWith("thread-1"));
+ assertSame(current.getThreadGroup(),
+ (s == null) ? egroup : s.getThreadGroup());
+ assertTrue(current.getName().endsWith("thread-1"));
assertSame(thisccl, current.getContextClassLoader());
assertEquals(thisacc, AccessController.getContext());
done.countDown();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ForkJoinPool8Test.java
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPool8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPool8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -206,7 +206,7 @@
public FJException(Throwable cause) { super(cause); }
}
- // A simple recursive action for testing
+ /** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@@ -224,7 +224,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;
@@ -932,7 +932,7 @@
}
}
- // Version of CCF with forced failure in left completions
+ /** Version of CCF with forced failure in left completions. */
abstract static class FailingCCF extends CountedCompleter {
int number;
int rnumber;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ForkJoinPool9Test.java
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPool9Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPool9Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -32,8 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.CountDownLatch;
@@ -93,7 +91,7 @@
Future> f = ForkJoinPool.commonPool().submit(runInCommonPool);
// Ensure runInCommonPool is truly running in the common pool,
// by giving this thread no opportunity to "help" on get().
- assertTrue(taskStarted.await(LONG_DELAY_MS, MILLISECONDS));
+ await(taskStarted);
assertNull(f.get());
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java
--- a/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -244,7 +244,7 @@
taskStarted.countDown();
assertEquals(1, p.getPoolSize());
assertEquals(1, p.getActiveThreadCount());
- done.await();
+ await(done);
}};
Future> future = p.submit(task);
await(taskStarted);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ForkJoinTask8Test.java
--- a/jdk/test/java/util/concurrent/tck/ForkJoinTask8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ForkJoinTask8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -127,7 +127,8 @@
assertNull(a.getException());
assertNull(a.getRawResult());
if (a instanceof BinaryAsyncAction)
- assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == INITIAL_STATE);
+ assertEquals(INITIAL_STATE,
+ ((BinaryAsyncAction)a).getForkJoinTaskTag());
try {
a.get(0L, SECONDS);
@@ -148,7 +149,8 @@
assertNull(a.getException());
assertSame(expected, a.getRawResult());
if (a instanceof BinaryAsyncAction)
- assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == COMPLETE_STATE);
+ assertEquals(COMPLETE_STATE,
+ ((BinaryAsyncAction)a).getForkJoinTaskTag());
{
Thread.currentThread().interrupt();
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/JSR166TestCase.java
--- a/jdk/test/java/util/concurrent/tck/JSR166TestCase.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/JSR166TestCase.java Wed Jul 05 23:13:02 2017 +0200
@@ -26,8 +26,9 @@
* However, the following notice accompanied the original version of this
* file:
*
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group and released to the public domain, as explained at
+ * Written by Doug Lea and Martin Buchholz with assistance from
+ * members of JCP JSR-166 Expert Group and released to the public
+ * domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
* Other contributors include Andrew Wright, Jeffrey Hayes,
* Pat Fisher, Mike Judd.
@@ -35,32 +36,33 @@
/*
* @test
- * @summary JSR-166 tck tests (conformance testing mode)
+ * @summary JSR-166 tck tests, in a number of variations.
+ * The first is the conformance testing variant,
+ * while others also test implementation details.
* @build *
* @modules java.management
* @run junit/othervm/timeout=1000 JSR166TestCase
- */
-
-/*
- * @test
- * @summary JSR-166 tck tests (whitebox tests allowed)
- * @build *
- * @modules java.base/java.util.concurrent:open
- * java.base/java.lang:open
- * java.management
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0
* JSR166TestCase
* @run junit/othervm/timeout=1000
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1
* -Djava.util.secureRandomSeed=true
* JSR166TestCase
* @run junit/othervm/timeout=1000/policy=tck.policy
+ * --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ * --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
*/
@@ -79,8 +81,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
@@ -118,7 +118,6 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.AssertionFailedError;
@@ -328,9 +327,11 @@
// public static String cpuModel() {
// try {
-// Matcher matcher = Pattern.compile("model name\\s*: (.*)")
+// java.util.regex.Matcher matcher
+// = Pattern.compile("model name\\s*: (.*)")
// .matcher(new String(
-// Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
+// java.nio.file.Files.readAllBytes(
+// java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8"));
// matcher.find();
// return matcher.group(1);
// } catch (Exception ex) { return null; }
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedBlockingDeque8Test.java
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingDeque8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingDeque8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -36,7 +36,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedBlockingDeque8Test extends JSR166TestCase {
public static void main(String[] args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -85,7 +85,7 @@
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedBlockingDeque populatedDeque(int n) {
+ private static LinkedBlockingDeque populatedDeque(int n) {
LinkedBlockingDeque q =
new LinkedBlockingDeque(n);
assertTrue(q.isEmpty());
@@ -801,7 +801,7 @@
}
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingQueue8Test.java Wed Jul 05 23:13:02 2017 +0200
@@ -36,7 +36,6 @@
import java.util.Spliterator;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedBlockingQueue8Test extends JSR166TestCase {
public static void main(String[] args) {
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -85,7 +85,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedBlockingQueue populatedQueue(int n) {
+ private static LinkedBlockingQueue populatedQueue(int n) {
LinkedBlockingQueue q =
new LinkedBlockingQueue(n);
assertTrue(q.isEmpty());
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedListTest.java
--- a/jdk/test/java/util/concurrent/tck/LinkedListTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedListTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -40,7 +40,6 @@
import java.util.NoSuchElementException;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class LinkedListTest extends JSR166TestCase {
public static void main(String[] args) {
@@ -70,7 +69,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private LinkedList populatedQueue(int n) {
+ private static LinkedList populatedQueue(int n) {
LinkedList q = new LinkedList<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/LinkedTransferQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/LinkedTransferQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/LinkedTransferQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -321,7 +321,7 @@
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
@@ -826,7 +826,7 @@
Thread first = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.transfer(four);
- assertTrue(!q.contains(four));
+ assertFalse(q.contains(four));
assertEquals(1, q.size());
}});
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -93,7 +93,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private PriorityBlockingQueue populatedQueue(int n) {
+ private static PriorityBlockingQueue populatedQueue(int n) {
PriorityBlockingQueue q =
new PriorityBlockingQueue(n);
assertTrue(q.isEmpty());
@@ -445,7 +445,7 @@
}
}});
- aboutToWait.await();
+ await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/PriorityQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/PriorityQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/PriorityQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -42,7 +42,6 @@
import java.util.Queue;
import junit.framework.Test;
-import junit.framework.TestSuite;
public class PriorityQueueTest extends JSR166TestCase {
public static void main(String[] args) {
@@ -70,7 +69,7 @@
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private PriorityQueue populatedQueue(int n) {
+ private static PriorityQueue populatedQueue(int n) {
PriorityQueue q = new PriorityQueue<>(n);
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/RecursiveActionTest.java
--- a/jdk/test/java/util/concurrent/tck/RecursiveActionTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/RecursiveActionTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -195,7 +195,7 @@
public FJException(Throwable cause) { super(cause); }
}
- // A simple recursive action for testing
+ /** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@@ -213,7 +213,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/RecursiveTaskTest.java
--- a/jdk/test/java/util/concurrent/tck/RecursiveTaskTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/RecursiveTaskTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -210,10 +210,10 @@
public FJException() { super(); }
}
- // An invalid return value for Fib
+ /** An invalid return value for Fib. */
static final Integer NoResult = Integer.valueOf(-17);
- // A simple recursive task for testing
+ /** A simple recursive task for testing. */
final class FibTask extends CheckedRecursiveTask {
final int number;
FibTask(int n) { number = n; }
@@ -231,7 +231,7 @@
}
}
- // A recursive action failing in base case
+ /** A recursive action failing in base case. */
final class FailingFibTask extends RecursiveTask {
final int number;
int result;
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/StampedLockTest.java
--- a/jdk/test/java/util/concurrent/tck/StampedLockTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/StampedLockTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -518,7 +518,7 @@
lock.unlockWrite(s);
}});
- aboutToLock.await();
+ await(aboutToLock);
waitForThreadToEnterWaitState(t);
assertFalse(lock.isWriteLocked());
assertTrue(lock.isReadLocked());
@@ -777,7 +777,7 @@
lock.writeLockInterruptibly();
}});
- locked.await();
+ await(locked);
assertFalse(lock.validate(p));
assertEquals(0L, lock.tryOptimisticRead());
waitForThreadToEnterWaitState(t);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java
--- a/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/SubmissionPublisherTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -519,7 +519,7 @@
s1.request = false;
p.subscribe(s1);
s1.awaitSubscribe();
- assertTrue(p.estimateMinimumDemand() == 0);
+ assertEquals(0, p.estimateMinimumDemand());
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s2);
p.submit(1);
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/SynchronousQueueTest.java
--- a/jdk/test/java/util/concurrent/tck/SynchronousQueueTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/SynchronousQueueTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -596,7 +596,7 @@
fail("timed out");
Thread.yield();
}
- assertTrue(l.size() == 1);
+ assertEquals(1, l.size());
assertSame(one, l.get(0));
awaitTermination(t);
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java
--- a/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -265,7 +265,7 @@
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -359,13 +359,13 @@
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
- threadProceed.await();
+ await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
- threadDone.await();
+ await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@@ -1953,7 +1953,7 @@
public void realRun() {
done.countDown();
}});
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ThreadPoolExecutorTest.java
--- a/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ThreadPoolExecutorTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -45,7 +45,6 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
@@ -118,7 +117,7 @@
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -212,13 +211,13 @@
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
- threadProceed.await();
+ await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
- threadDone.await();
+ await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@@ -302,6 +301,20 @@
}
/**
+ * The default rejected execution handler is AbortPolicy.
+ */
+ public void testDefaultRejectedExecutionHandler() {
+ final ThreadPoolExecutor p =
+ new ThreadPoolExecutor(1, 2,
+ LONG_DELAY_MS, MILLISECONDS,
+ new ArrayBlockingQueue(10));
+ try (PoolCleaner cleaner = cleaner(p)) {
+ assertTrue(p.getRejectedExecutionHandler()
+ instanceof ThreadPoolExecutor.AbortPolicy);
+ }
+ }
+
+ /**
* getRejectedExecutionHandler returns handler in constructor if not set
*/
public void testGetRejectedExecutionHandler() {
@@ -1139,7 +1152,7 @@
await(done);
}};
for (int i = 0; i < 2; ++i)
- p.submit(Executors.callable(task));
+ p.execute(task);
for (int i = 0; i < 2; ++i) {
try {
p.execute(task);
@@ -1955,7 +1968,7 @@
public void realRun() {
done.countDown();
}});
- assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
+ await(done);
}
}
@@ -2048,7 +2061,7 @@
}
}
// enough time to run all tasks
- assertTrue(done.await(nTasks * SHORT_DELAY_MS, MILLISECONDS));
+ await(done, nTasks * SHORT_DELAY_MS);
}
}
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/ThreadTest.java
--- a/jdk/test/java/util/concurrent/tck/ThreadTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/ThreadTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -76,7 +76,7 @@
* setDefaultUncaughtExceptionHandler.
*/
public void testGetAndSetDefaultUncaughtExceptionHandler() {
- assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
+ assertNull(Thread.getDefaultUncaughtExceptionHandler());
// failure due to SecurityException is OK.
// Would be nice to explicitly test both ways, but cannot yet.
Thread.UncaughtExceptionHandler defaultHandler
diff -r 49a5ced535f6 -r a34001e206f9 jdk/test/java/util/concurrent/tck/TreeSetTest.java
--- a/jdk/test/java/util/concurrent/tck/TreeSetTest.java Thu Apr 13 20:35:38 2017 +0000
+++ b/jdk/test/java/util/concurrent/tck/TreeSetTest.java Wed Jul 05 23:13:02 2017 +0200
@@ -69,7 +69,7 @@
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
- private TreeSet populatedSet(int n) {
+ private static TreeSet