check in the orb.properties file located in the user.home
- * directory (if any)
+ * directory, if any
*
- *
check in the orb.properties file located in the java.home/lib
- * directory (if any)
+ *
check in the orb.properties file located in the run-time image,
+ * if any
*
*
fall back on a hardcoded default behavior (use the Java IDL
* implementation)
@@ -170,9 +170,15 @@ import java.security.PrivilegedAction;
* Thus, where appropriate, it is necessary that
* the classes for this alternative ORBSingleton are available on the application's class path.
* It should be noted that the singleton ORB is system wide.
- *
+ *
* When a per-application ORB is created via the 2-arg init methods,
* then it will be located using the thread context class loader.
+ *
+ * The IDL to Java Language OMG specification documents the ${java.home}/lib directory as the location,
+ * in the Java run-time image, to search for orb.properties.
+ * This location is not intended for user editable configuration files.
+ * Therefore, the implementation first checks the ${java.home}/conf directory for orb.properties,
+ * and thereafter the ${java.home}/lib directory.
*
* @since JDK1.2
*/
@@ -271,14 +277,25 @@ abstract public class ORB {
}
String javaHome = System.getProperty("java.home");
- fileName = javaHome + File.separator
- + "lib" + File.separator + "orb.properties";
- props = getFileProperties( fileName ) ;
+
+ fileName = javaHome + File.separator + "conf"
+ + File.separator + "orb.properties";
+ props = getFileProperties(fileName);
+
+ if (props != null) {
+ String value = props.getProperty(name);
+ if (value != null)
+ return value;
+ }
+
+ fileName = javaHome + File.separator + "lib"
+ + File.separator + "orb.properties";
+ props = getFileProperties(fileName);
if (props == null)
- return null ;
+ return null;
else
- return props.getProperty( name ) ;
+ return props.getProperty(name);
}
}
);
diff --git a/hotspot/.hgtags b/hotspot/.hgtags
index 66afb5ed54b..2391406c10b 100644
--- a/hotspot/.hgtags
+++ b/hotspot/.hgtags
@@ -556,5 +556,9 @@ a82cb5350cad96a0b4de496afebe3ded89f27efa jdk-9+146
2a2ac7d9f52c8cb2b80077e515b5840b947e640c jdk-9+151
31f1d26c60df7b2e516a4f84160d76ba017d4e09 jdk-9+152
217ba81b9a4ce8698200370175aa2db86a39f66c jdk-9+153
+fc7e94cb748507366b839e859f865f724467446a jdk-10+0
a9fdfd55835ef9dccb7f317b07249bd66653b874 jdk-9+154
f3b3d77a1751897413aae43ac340a130b6fa2ae1 jdk-9+155
+43139c588ea48b6504e52b6c3dec530b17b1fdb4 jdk-9+156
+b2d0a906afd73dcf27f572217eb1be0f196ec16c jdk-9+157
+4e78f30935229f13ce7c43089621cf7169f5abac jdk-9+158
diff --git a/hotspot/.jcheck/conf b/hotspot/.jcheck/conf
index 5c6f62dc12c..b2581358014 100644
--- a/hotspot/.jcheck/conf
+++ b/hotspot/.jcheck/conf
@@ -1 +1 @@
-project=jdk9
+project=jdk10
diff --git a/hotspot/src/cpu/aarch64/vm/c1_LIRAssembler_aarch64.cpp b/hotspot/src/cpu/aarch64/vm/c1_LIRAssembler_aarch64.cpp
index b139a44f9a1..0016aa9ba6a 100644
--- a/hotspot/src/cpu/aarch64/vm/c1_LIRAssembler_aarch64.cpp
+++ b/hotspot/src/cpu/aarch64/vm/c1_LIRAssembler_aarch64.cpp
@@ -1922,12 +1922,17 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
}
if (opr2->is_constant()) {
+ bool is_32bit = false; // width of register operand
jlong imm;
+
switch(opr2->type()) {
+ case T_INT:
+ imm = opr2->as_constant_ptr()->as_jint();
+ is_32bit = true;
+ break;
case T_LONG:
imm = opr2->as_constant_ptr()->as_jlong();
break;
- case T_INT:
case T_ADDRESS:
imm = opr2->as_constant_ptr()->as_jint();
break;
@@ -1942,14 +1947,14 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
}
if (Assembler::operand_valid_for_add_sub_immediate(imm)) {
- if (type2aelembytes(opr1->type()) <= 4)
+ if (is_32bit)
__ cmpw(reg1, imm);
else
__ cmp(reg1, imm);
return;
} else {
__ mov(rscratch1, imm);
- if (type2aelembytes(opr1->type()) <= 4)
+ if (is_32bit)
__ cmpw(reg1, rscratch1);
else
__ cmp(reg1, rscratch1);
diff --git a/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp
index 71d7819561e..3177a8980b9 100644
--- a/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp
+++ b/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp
@@ -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.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -45,10 +45,8 @@ define_pd_global(bool, TieredCompilation, false);
// We compile very aggressively with the builtin simulator because
// doing so greatly reduces run times and tests more code.
define_pd_global(intx, CompileThreshold, 150 );
-define_pd_global(intx, BackEdgeThreshold, 500);
#else
define_pd_global(intx, CompileThreshold, 1500 );
-define_pd_global(intx, BackEdgeThreshold, 100000);
#endif
define_pd_global(intx, OnStackReplacePercentage, 933 );
@@ -76,6 +74,4 @@ define_pd_global(bool, OptimizeSinglePrecision, true );
define_pd_global(bool, CSEArrayLength, false);
define_pd_global(bool, TwoOperandLIRForm, false );
-define_pd_global(intx, SafepointPollOffset, 0 );
-
#endif // CPU_AARCH64_VM_C1_GLOBALS_AARCH64_HPP
diff --git a/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp
index 9a16dd76967..5a5d8ac4f95 100644
--- a/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp
+++ b/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp
@@ -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.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -43,7 +43,6 @@ define_pd_global(bool, UseOnStackReplacement, true);
define_pd_global(bool, ProfileInterpreter, true);
define_pd_global(bool, TieredCompilation, trueInTiered);
define_pd_global(intx, CompileThreshold, 10000);
-define_pd_global(intx, BackEdgeThreshold, 100000);
define_pd_global(intx, OnStackReplacePercentage, 140);
define_pd_global(intx, ConditionalMoveLimit, 3);
diff --git a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTStub.java b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTStub.java
index b7ba5e87e72..1eabbdc3a78 100644
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTStub.java
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTStub.java
@@ -25,6 +25,7 @@ package jdk.tools.jaotc;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.core.target.Backend;
+import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
import org.graalvm.compiler.hotspot.stubs.Stub;
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
@@ -48,7 +49,7 @@ public class AOTStub implements JavaMethodInfo {
}
public HotSpotCompiledCode compiledCode(CompilationResult result) {
- return stub.getCompiledCode(backend);
+ return HotSpotCompiledCodeBuilder.createCompiledCode(null, null, result);
}
}
diff --git a/hotspot/src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c b/hotspot/src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
index c12f82d1bf6..3e3758b0cf6 100644
--- a/hotspot/src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
+++ b/hotspot/src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
@@ -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
@@ -50,7 +50,7 @@ int pathmap_open(const char* name) {
}
- if (strlen(alt_root) + strlen(name) < PATH_MAX) {
+ if (strlen(alt_root) + strlen(name) > PATH_MAX) {
// Buffer too small.
return -1;
}
diff --git a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
index 643109bc1e9..09a382f9439 100644
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
@@ -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
@@ -150,13 +150,7 @@ public class HeapSummary extends Tool {
// Helper methods
private void printGCAlgorithm(Map flagMap) {
- // print about new generation
- long l = getFlagValue("UseParNewGC", flagMap);
- if (l == 1L) {
- System.out.println("using parallel threads in the new generation.");
- }
-
- l = getFlagValue("UseTLAB", flagMap);
+ long l = getFlagValue("UseTLAB", flagMap);
if (l == 1L) {
System.out.println("using thread-local object allocation.");
}
diff --git a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
index 5dbf8984158..eb3aad9495a 100644
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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,8 @@ public abstract class AbstractHeapGraphWriter implements HeapGraphWriter {
}
});
+ writeHeapRecordPrologue();
+
// write JavaThreads
writeJavaThreads();
diff --git a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
index 9da43745388..5d23da01d51 100644
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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
@@ -45,8 +45,8 @@ import sun.jvm.hotspot.classfile.*;
* WARNING: This format is still under development, and is subject to
* change without notice.
*
- * header "JAVA PROFILE 1.0.1" or "JAVA PROFILE 1.0.2" (0-terminated)
- * u4 size of identifiers. Identifiers are used to represent
+ * header "JAVA PROFILE 1.0.2" (0-terminated)
+ * u4 size of identifiers. Identifiers are used to represent
* UTF8 strings, objects, stack traces, etc. They usually
* have the same size as host pointers. For example, on
* Solaris and Win32, the size is 4.
@@ -294,10 +294,9 @@ import sun.jvm.hotspot.classfile.*;
* u2 stack trace depth
*
*
- * When the header is "JAVA PROFILE 1.0.2" a heap dump can optionally
- * be generated as a sequence of heap dump segments. This sequence is
- * terminated by an end record. The additional tags allowed by format
- * "JAVA PROFILE 1.0.2" are:
+ * A heap dump can optionally be generated as a sequence of heap dump
+ * segments. This sequence is terminated by an end record. The additional
+ * tags allowed by format "JAVA PROFILE 1.0.2" are:
*
* HPROF_HEAP_DUMP_SEGMENT denote a heap dump segment
*
@@ -310,8 +309,6 @@ import sun.jvm.hotspot.classfile.*;
public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
- // The heap size threshold used to determine if segmented format
- // ("JAVA PROFILE 1.0.2") should be used.
private static final long HPROF_SEGMENTED_HEAP_DUMP_THRESHOLD = 2L * 0x40000000;
// The approximate size of a heap segment. Used to calculate when to create
@@ -319,7 +316,6 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static final long HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE = 1L * 0x40000000;
// hprof binary file header
- private static final String HPROF_HEADER_1_0_1 = "JAVA PROFILE 1.0.1";
private static final String HPROF_HEADER_1_0_2 = "JAVA PROFILE 1.0.2";
// constants in enum HprofTag
@@ -380,6 +376,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static final int JVM_SIGNATURE_ARRAY = '[';
private static final int JVM_SIGNATURE_CLASS = 'L';
+ private static final long MAX_U4_VALUE = 0xFFFFFFFFL;
int serialNum = 1;
public synchronized void write(String fileName) throws IOException {
@@ -469,7 +466,6 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// length later - hprof format requires length.
out.flush();
currentSegmentStart = fos.getChannel().position();
-
// write dummy length of 0 and we'll fix it later.
out.writeInt(0);
}
@@ -479,7 +475,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
protected void writeHeapRecordEpilogue() throws IOException {
if (useSegmentedHeapDump) {
out.flush();
- if ((fos.getChannel().position() - currentSegmentStart - 4) >= HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE) {
+ if ((fos.getChannel().position() - currentSegmentStart - 4L) >= HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE) {
fillInHeapRecordLength();
currentSegmentStart = 0;
}
@@ -488,14 +484,14 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private void fillInHeapRecordLength() throws IOException {
- // now get current position to calculate length
+ // now get the current position to calculate length
long dumpEnd = fos.getChannel().position();
- // calculate length of heap data
+ // calculate the length of heap data
long dumpLenLong = (dumpEnd - currentSegmentStart - 4L);
// Check length boundary, overflow could happen but is _very_ unlikely
- if(dumpLenLong >= (4L * 0x40000000)){
+ if (dumpLenLong >= (4L * 0x40000000)) {
throw new RuntimeException("Heap segment size overflow.");
}
@@ -517,6 +513,71 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
fos.getChannel().position(currentPosition);
}
+ // get the size in bytes for the requested type
+ private long getSizeForType(int type) throws IOException {
+ switch (type) {
+ case TypeArrayKlass.T_BOOLEAN:
+ return BOOLEAN_SIZE;
+ case TypeArrayKlass.T_INT:
+ return INT_SIZE;
+ case TypeArrayKlass.T_CHAR:
+ return CHAR_SIZE;
+ case TypeArrayKlass.T_SHORT:
+ return SHORT_SIZE;
+ case TypeArrayKlass.T_BYTE:
+ return BYTE_SIZE;
+ case TypeArrayKlass.T_LONG:
+ return LONG_SIZE;
+ case TypeArrayKlass.T_FLOAT:
+ return FLOAT_SIZE;
+ case TypeArrayKlass.T_DOUBLE:
+ return DOUBLE_SIZE;
+ default:
+ throw new RuntimeException(
+ "Should not reach here: Unknown type: " + type);
+ }
+ }
+
+ private int getArrayHeaderSize(boolean isObjectAarray) {
+ return isObjectAarray?
+ ((int) BYTE_SIZE + 2 * (int) INT_SIZE + 2 * (int) OBJ_ID_SIZE):
+ (2 * (int) BYTE_SIZE + 2 * (int) INT_SIZE + (int) OBJ_ID_SIZE);
+ }
+
+ // Check if we need to truncate an array
+ private int calculateArrayMaxLength(long originalArrayLength,
+ int headerSize,
+ long typeSize,
+ String typeName) throws IOException {
+
+ long length = originalArrayLength;
+
+ // now get the current position to calculate length
+ long dumpEnd = fos.getChannel().position();
+ long originalLengthInBytes = originalArrayLength * typeSize;
+
+ // calculate the length of heap data
+ long currentRecordLength = (dumpEnd - currentSegmentStart - 4L);
+ if (currentRecordLength > 0 &&
+ (currentRecordLength + headerSize + originalLengthInBytes) > MAX_U4_VALUE) {
+ fillInHeapRecordLength();
+ currentSegmentStart = 0;
+ writeHeapRecordPrologue();
+ currentRecordLength = 0;
+ }
+
+ // Calculate the max bytes we can use.
+ long maxBytes = (MAX_U4_VALUE - (headerSize + currentRecordLength));
+
+ if (originalLengthInBytes > maxBytes) {
+ length = maxBytes/typeSize;
+ System.err.println("WARNING: Cannot dump array of type " + typeName
+ + " with length " + originalArrayLength
+ + "; truncating to length " + length);
+ }
+ return (int) length;
+ }
+
private void writeClassDumpRecords() throws IOException {
SystemDictionary sysDict = VM.getVM().getSystemDictionary();
ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph();
@@ -694,12 +755,16 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
}
protected void writeObjectArray(ObjArray array) throws IOException {
+ int headerSize = getArrayHeaderSize(true);
+ final int length = calculateArrayMaxLength(array.getLength(),
+ headerSize,
+ OBJ_ID_SIZE,
+ "Object");
out.writeByte((byte) HPROF_GC_OBJ_ARRAY_DUMP);
writeObjectID(array);
out.writeInt(DUMMY_STACK_TRACE_ID);
- out.writeInt((int) array.getLength());
+ out.writeInt(length);
writeObjectID(array.getKlass().getJavaMirror());
- final int length = (int) array.getLength();
for (int index = 0; index < length; index++) {
OopHandle handle = array.getOopHandleAt(index);
writeObjectID(getAddressValue(handle));
@@ -707,101 +772,101 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
}
protected void writePrimitiveArray(TypeArray array) throws IOException {
+ int headerSize = getArrayHeaderSize(false);
+ TypeArrayKlass tak = (TypeArrayKlass) array.getKlass();
+ final int type = (int) tak.getElementType();
+ final String typeName = tak.getElementTypeName();
+ final long typeSize = getSizeForType(type);
+ final int length = calculateArrayMaxLength(array.getLength(),
+ headerSize,
+ typeSize,
+ typeName);
out.writeByte((byte) HPROF_GC_PRIM_ARRAY_DUMP);
writeObjectID(array);
out.writeInt(DUMMY_STACK_TRACE_ID);
- out.writeInt((int) array.getLength());
- TypeArrayKlass tak = (TypeArrayKlass) array.getKlass();
- final int type = (int) tak.getElementType();
+ out.writeInt(length);
out.writeByte((byte) type);
switch (type) {
case TypeArrayKlass.T_BOOLEAN:
- writeBooleanArray(array);
+ writeBooleanArray(array, length);
break;
case TypeArrayKlass.T_CHAR:
- writeCharArray(array);
+ writeCharArray(array, length);
break;
case TypeArrayKlass.T_FLOAT:
- writeFloatArray(array);
+ writeFloatArray(array, length);
break;
case TypeArrayKlass.T_DOUBLE:
- writeDoubleArray(array);
+ writeDoubleArray(array, length);
break;
case TypeArrayKlass.T_BYTE:
- writeByteArray(array);
+ writeByteArray(array, length);
break;
case TypeArrayKlass.T_SHORT:
- writeShortArray(array);
+ writeShortArray(array, length);
break;
case TypeArrayKlass.T_INT:
- writeIntArray(array);
+ writeIntArray(array, length);
break;
case TypeArrayKlass.T_LONG:
- writeLongArray(array);
+ writeLongArray(array, length);
break;
default:
- throw new RuntimeException("should not reach here");
+ throw new RuntimeException(
+ "Should not reach here: Unknown type: " + type);
}
}
- private void writeBooleanArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeBooleanArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE;
out.writeBoolean(array.getHandle().getJBooleanAt(offset));
}
}
- private void writeByteArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeByteArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = BYTE_BASE_OFFSET + index * BYTE_SIZE;
out.writeByte(array.getHandle().getJByteAt(offset));
}
}
- private void writeShortArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeShortArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = SHORT_BASE_OFFSET + index * SHORT_SIZE;
out.writeShort(array.getHandle().getJShortAt(offset));
}
}
- private void writeIntArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeIntArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = INT_BASE_OFFSET + index * INT_SIZE;
out.writeInt(array.getHandle().getJIntAt(offset));
}
}
- private void writeLongArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeLongArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = LONG_BASE_OFFSET + index * LONG_SIZE;
out.writeLong(array.getHandle().getJLongAt(offset));
}
}
- private void writeCharArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeCharArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = CHAR_BASE_OFFSET + index * CHAR_SIZE;
out.writeChar(array.getHandle().getJCharAt(offset));
}
}
- private void writeFloatArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeFloatArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = FLOAT_BASE_OFFSET + index * FLOAT_SIZE;
out.writeFloat(array.getHandle().getJFloatAt(offset));
}
}
- private void writeDoubleArray(TypeArray array) throws IOException {
- final int length = (int) array.getLength();
+ private void writeDoubleArray(TypeArray array, int length) throws IOException {
for (int index = 0; index < length; index++) {
long offset = DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE;
out.writeDouble(array.getHandle().getJDoubleAt(offset));
@@ -996,12 +1061,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// writes hprof binary file header
private void writeFileHeader() throws IOException {
// version string
- if(useSegmentedHeapDump) {
- out.writeBytes(HPROF_HEADER_1_0_2);
- }
- else {
- out.writeBytes(HPROF_HEADER_1_0_1);
- }
+ out.writeBytes(HPROF_HEADER_1_0_2);
out.writeByte((byte)'\0');
// write identifier size. we use pointers as identifiers.
diff --git a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java
index 529a561eb5e..cf5ef10ccf2 100644
--- a/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java
+++ b/hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java
@@ -27,8 +27,6 @@ import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaType;
@@ -147,21 +145,34 @@ public class HotSpotJVMCIMetaAccessContext {
}
}
- private final Map, WeakReference> typeMap = new WeakHashMap<>();
+ private final ClassValue> resolvedJavaType = new ClassValue>() {
+ @Override
+ protected WeakReference computeValue(Class> type) {
+ return new WeakReference<>(createClass(type));
+ }
+ };
/**
* Gets the JVMCI mirror for a {@link Class} object.
*
* @return the {@link ResolvedJavaType} corresponding to {@code javaClass}
*/
- public synchronized ResolvedJavaType fromClass(Class> javaClass) {
- WeakReference typeRef = typeMap.get(javaClass);
- ResolvedJavaType type = typeRef != null ? typeRef.get() : null;
- if (type == null) {
- type = createClass(javaClass);
- typeMap.put(javaClass, new WeakReference<>(type));
+ public ResolvedJavaType fromClass(Class> javaClass) {
+ ResolvedJavaType javaType = null;
+ while (javaType == null) {
+ WeakReference type = resolvedJavaType.get(javaClass);
+ javaType = type.get();
+ if (javaType == null) {
+ /*
+ * If the referent has become null, clear out the current value
+ * and let computeValue above create a new value. Reload the
+ * value in a loop because in theory the WeakReference referent
+ * can be reclaimed at any point.
+ */
+ resolvedJavaType.remove(javaClass);
+ }
}
- return type;
+ return javaType;
}
/**
diff --git a/hotspot/src/jdk.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java b/hotspot/src/jdk.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java
index 5d2eb3ee74b..8857bd417a6 100644
--- a/hotspot/src/jdk.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java
+++ b/hotspot/src/jdk.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java
@@ -89,18 +89,11 @@ public abstract class Stub {
*/
protected InstalledCode code;
- /**
- * Compilation result from which {@link #code} was created.
- */
- protected CompilationResult compResult;
-
/**
* The registers destroyed by this stub (from the caller's perspective).
*/
private Set destroyedCallerRegisters;
- private HotSpotCompiledCode compiledCode;
-
public void initDestroyedCallerRegisters(Set registers) {
assert registers != null;
assert destroyedCallerRegisters == null || registers.equals(destroyedCallerRegisters) : "cannot redefine";
@@ -184,35 +177,13 @@ public abstract class Stub {
public synchronized InstalledCode getCode(final Backend backend) {
if (code == null) {
try (Scope d = Debug.sandbox("CompilingStub", DebugScope.getConfig(), providers.getCodeCache(), debugScopeContext())) {
- final StructuredGraph graph = getGraph(getStubCompilationId());
-
- // Stubs cannot be recompiled so they cannot be compiled with assumptions
- assert graph.getAssumptions() == null;
-
- if (!(graph.start() instanceof StubStartNode)) {
- StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
- newStart.setStateAfter(graph.start().stateAfter());
- graph.replaceFixed(graph.start(), newStart);
- }
-
CodeCacheProvider codeCache = providers.getCodeCache();
-
- compResult = new CompilationResult(toString(), GeneratePIC.getValue());
- try (Scope s0 = Debug.scope("StubCompilation", graph, providers.getCodeCache())) {
- Suites suites = createSuites();
- emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
- LIRSuites lirSuites = createLIRSuites();
- emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
- assert checkStubInvariants();
- } catch (Throwable e) {
- throw Debug.handle(e);
- }
-
- assert destroyedCallerRegisters != null;
+ CompilationResult compResult = buildCompilationResult(backend);
try (Scope s = Debug.scope("CodeInstall", compResult)) {
+ assert destroyedCallerRegisters != null;
// Add a GeneratePIC check here later, we don't want to install
// code if we don't have a corresponding VM global symbol.
- compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(null, null, compResult);
+ HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(null, null, compResult);
code = codeCache.installCode(null, compiledCode, null, null, false);
} catch (Throwable e) {
throw Debug.handle(e);
@@ -226,6 +197,44 @@ public abstract class Stub {
return code;
}
+ @SuppressWarnings("try")
+ private CompilationResult buildCompilationResult(final Backend backend) {
+ CompilationResult compResult = new CompilationResult(toString(), GeneratePIC.getValue());
+ final StructuredGraph graph = getGraph(getStubCompilationId());
+
+ // Stubs cannot be recompiled so they cannot be compiled with assumptions
+ assert graph.getAssumptions() == null;
+
+ if (!(graph.start() instanceof StubStartNode)) {
+ StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
+ newStart.setStateAfter(graph.start().stateAfter());
+ graph.replaceFixed(graph.start(), newStart);
+ }
+
+ try (Scope s0 = Debug.scope("StubCompilation", graph, providers.getCodeCache())) {
+ Suites suites = createSuites();
+ emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
+ LIRSuites lirSuites = createLIRSuites();
+ emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
+ assert checkStubInvariants(compResult);
+ } catch (Throwable e) {
+ throw Debug.handle(e);
+ }
+ return compResult;
+ }
+
+ /**
+ * Gets a {@link CompilationResult} that can be used for code generation. Required for AOT.
+ */
+ @SuppressWarnings("try")
+ public CompilationResult getCompilationResult(final Backend backend) {
+ try (Scope d = Debug.sandbox("CompilingStub", DebugScope.getConfig(), providers.getCodeCache(), debugScopeContext())) {
+ return buildCompilationResult(backend);
+ } catch (Throwable e) {
+ throw Debug.handle(e);
+ }
+ }
+
public CompilationIdentifier getStubCompilationId() {
return new StubCompilationIdentifier(this);
}
@@ -233,7 +242,7 @@ public abstract class Stub {
/**
* Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
*/
- private boolean checkStubInvariants() {
+ private boolean checkStubInvariants(CompilationResult compResult) {
assert compResult.getExceptionHandlers().isEmpty() : this;
// Stubs cannot be recompiled so they cannot be compiled with
@@ -278,24 +287,4 @@ public abstract class Stub {
}
return lirSuites;
}
-
- /**
- * Gets the HotSpotCompiledCode that was created during installation.
- */
- public synchronized HotSpotCompiledCode getCompiledCode(final Backend backend) {
- getCompilationResult(backend);
- assert compiledCode != null;
- return compiledCode;
- }
-
- /**
- * Gets the compilation result for this stub, compiling it first if necessary, and installing it
- * in code.
- */
- public synchronized CompilationResult getCompilationResult(final Backend backend) {
- if (code == null) {
- getCode(backend);
- }
- return compResult;
- }
}
diff --git a/hotspot/src/os/solaris/vm/os_solaris.cpp b/hotspot/src/os/solaris/vm/os_solaris.cpp
index 527246dcc3d..adbec4e459e 100644
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -3050,15 +3050,12 @@ void os::naked_yield() {
thr_yield();
}
-// Interface for setting lwp priorities. If we are using T2 libthread,
-// which forces the use of BoundThreads or we manually set UseBoundThreads,
-// all of our threads will be assigned to real lwp's. Using the thr_setprio
-// function is meaningless in this mode so we must adjust the real lwp's priority
+// Interface for setting lwp priorities. We are using T2 libthread,
+// which forces the use of bound threads, so all of our threads will
+// be assigned to real lwp's. Using the thr_setprio function is
+// meaningless in this mode so we must adjust the real lwp's priority.
// The routines below implement the getting and setting of lwp priorities.
//
-// Note: T2 is now the only supported libthread. UseBoundThreads flag is
-// being deprecated and all threads are now BoundThreads
-//
// Note: There are three priority scales used on Solaris. Java priotities
// which range from 1 to 10, libthread "thr_setprio" scale which range
// from 0 to 127, and the current scheduling class of the process we
diff --git a/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp b/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp
index e3a7af67742..095ac876292 100644
--- a/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp
+++ b/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp
@@ -248,7 +248,9 @@ void Canonicalizer::do_ArrayLength (ArrayLength* x) {
} else if ((lf = x->array()->as_LoadField()) != NULL) {
ciField* field = lf->field();
if (field->is_static_constant()) {
- assert(PatchALot || ScavengeRootsInCode < 2, "Constant field loads are folded during parsing");
+ // Constant field loads are usually folded during parsing.
+ // But it doesn't happen with PatchALot, ScavengeRootsInCode < 2, or when
+ // holder class is being initialized during parsing (for static fields).
ciObject* c = field->constant_value().as_object();
if (!c->is_null_object()) {
set_constant(c->as_array()->length());
diff --git a/hotspot/src/share/vm/c1/c1_LIR.cpp b/hotspot/src/share/vm/c1/c1_LIR.cpp
index 05f39476849..e6cdb5e7c03 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.cpp
@@ -1413,6 +1413,17 @@ void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr
append(c);
}
+void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
+ if (deoptimize_on_null) {
+ // Emit an explicit null check and deoptimize if opr is null
+ CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
+ cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(NULL));
+ branch(lir_cond_equal, T_OBJECT, deopt);
+ } else {
+ // Emit an implicit null check
+ append(new LIR_Op1(lir_null_check, opr, info));
+ }
+}
void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
diff --git a/hotspot/src/share/vm/c1/c1_LIR.hpp b/hotspot/src/share/vm/c1/c1_LIR.hpp
index 79d298d4cdf..5046a76b13f 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.hpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.hpp
@@ -2113,7 +2113,7 @@ class LIR_List: public CompilationResourceObj {
void pack64(LIR_Opr src, LIR_Opr dst) { append(new LIR_Op1(lir_pack64, src, dst, T_LONG, lir_patch_none, NULL)); }
void unpack64(LIR_Opr src, LIR_Opr dst) { append(new LIR_Op1(lir_unpack64, src, dst, T_LONG, lir_patch_none, NULL)); }
- void null_check(LIR_Opr opr, CodeEmitInfo* info) { append(new LIR_Op1(lir_null_check, opr, info)); }
+ void null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null = false);
void throw_exception(LIR_Opr exceptionPC, LIR_Opr exceptionOop, CodeEmitInfo* info) {
append(new LIR_Op2(lir_throw, exceptionPC, exceptionOop, LIR_OprFact::illegalOpr, info));
}
diff --git a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
index 0c10e864e3f..47c2b79fa89 100644
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
@@ -1752,8 +1752,10 @@ void LIRGenerator::do_StoreField(StoreField* x) {
if (x->needs_null_check() &&
(needs_patching ||
MacroAssembler::needs_explicit_null_check(x->offset()))) {
- // emit an explicit null check because the offset is too large
- __ null_check(object.result(), new CodeEmitInfo(info));
+ // Emit an explicit null check because the offset is too large.
+ // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
+ // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
+ __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);
}
LIR_Address* address;
@@ -1838,8 +1840,10 @@ void LIRGenerator::do_LoadField(LoadField* x) {
obj = new_register(T_OBJECT);
__ move(LIR_OprFact::oopConst(NULL), obj);
}
- // emit an explicit null check because the offset is too large
- __ null_check(obj, new CodeEmitInfo(info));
+ // Emit an explicit null check because the offset is too large.
+ // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
+ // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
+ __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);
}
LIR_Opr reg = rlock_result(x, field_type);
diff --git a/hotspot/src/share/vm/ci/ciEnv.cpp b/hotspot/src/share/vm/ci/ciEnv.cpp
index 024909b1cbc..e8587cf9646 100644
--- a/hotspot/src/share/vm/ci/ciEnv.cpp
+++ b/hotspot/src/share/vm/ci/ciEnv.cpp
@@ -101,6 +101,7 @@ ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter)
_debug_info = NULL;
_dependencies = NULL;
_failure_reason = NULL;
+ _inc_decompile_count_on_failure = true;
_compilable = MethodCompilable;
_break_at_compile = false;
_compiler_data = NULL;
@@ -161,6 +162,7 @@ ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) {
_debug_info = NULL;
_dependencies = NULL;
_failure_reason = NULL;
+ _inc_decompile_count_on_failure = true;
_compilable = MethodCompilable_never;
_break_at_compile = false;
_compiler_data = NULL;
@@ -902,7 +904,12 @@ void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
if (deps.is_klass_type()) continue; // skip klass dependencies
Klass* witness = deps.check_dependency();
if (witness != NULL) {
- record_failure("invalid non-klass dependency");
+ if (deps.type() == Dependencies::call_site_target_value) {
+ _inc_decompile_count_on_failure = false;
+ record_failure("call site target change");
+ } else {
+ record_failure("invalid non-klass dependency");
+ }
return;
}
}
@@ -1017,7 +1024,7 @@ void ciEnv::register_method(ciMethod* target,
if (failing()) {
// While not a true deoptimization, it is a preemptive decompile.
MethodData* mdo = method()->method_data();
- if (mdo != NULL) {
+ if (mdo != NULL && _inc_decompile_count_on_failure) {
mdo->inc_decompile_count();
}
diff --git a/hotspot/src/share/vm/ci/ciEnv.hpp b/hotspot/src/share/vm/ci/ciEnv.hpp
index e5a99e1a96a..36934010ef8 100644
--- a/hotspot/src/share/vm/ci/ciEnv.hpp
+++ b/hotspot/src/share/vm/ci/ciEnv.hpp
@@ -55,6 +55,7 @@ private:
DebugInformationRecorder* _debug_info;
Dependencies* _dependencies;
const char* _failure_reason;
+ bool _inc_decompile_count_on_failure;
int _compilable;
bool _break_at_compile;
int _num_inlined_bytecodes;
diff --git a/hotspot/src/share/vm/classfile/javaClasses.cpp b/hotspot/src/share/vm/classfile/javaClasses.cpp
index b7fe590eee1..84e618a4a50 100644
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp
@@ -2269,6 +2269,7 @@ void java_lang_LiveStackFrameInfo::compute_offsets() {
compute_offset(_monitors_offset, k, vmSymbols::monitors_name(), vmSymbols::object_array_signature());
compute_offset(_locals_offset, k, vmSymbols::locals_name(), vmSymbols::object_array_signature());
compute_offset(_operands_offset, k, vmSymbols::operands_name(), vmSymbols::object_array_signature());
+ compute_offset(_mode_offset, k, vmSymbols::mode_name(), vmSymbols::int_signature());
}
void java_lang_reflect_AccessibleObject::compute_offsets() {
@@ -3658,6 +3659,7 @@ int java_lang_StackFrameInfo::_version_offset;
int java_lang_LiveStackFrameInfo::_monitors_offset;
int java_lang_LiveStackFrameInfo::_locals_offset;
int java_lang_LiveStackFrameInfo::_operands_offset;
+int java_lang_LiveStackFrameInfo::_mode_offset;
int java_lang_AssertionStatusDirectives::classes_offset;
int java_lang_AssertionStatusDirectives::classEnabled_offset;
int java_lang_AssertionStatusDirectives::packages_offset;
@@ -3728,6 +3730,10 @@ void java_lang_LiveStackFrameInfo::set_operands(oop element, oop value) {
element->obj_field_put(_operands_offset, value);
}
+void java_lang_LiveStackFrameInfo::set_mode(oop element, int value) {
+ element->int_field_put(_mode_offset, value);
+}
+
// Support for java Assertions - java_lang_AssertionStatusDirectives.
void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) {
diff --git a/hotspot/src/share/vm/classfile/javaClasses.hpp b/hotspot/src/share/vm/classfile/javaClasses.hpp
index f05db4c79b7..52dfe4590ab 100644
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp
@@ -1380,11 +1380,13 @@ class java_lang_LiveStackFrameInfo: AllStatic {
static int _monitors_offset;
static int _locals_offset;
static int _operands_offset;
+ static int _mode_offset;
public:
static void set_monitors(oop info, oop value);
static void set_locals(oop info, oop value);
static void set_operands(oop info, oop value);
+ static void set_mode(oop info, int value);
static void compute_offsets();
diff --git a/hotspot/src/share/vm/classfile/vmSymbols.hpp b/hotspot/src/share/vm/classfile/vmSymbols.hpp
index 0ef86447c4e..f9f5a63cbd8 100644
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp
@@ -325,14 +325,8 @@
template(java_lang_StackStreamFactory_AbstractStackWalker, "java/lang/StackStreamFactory$AbstractStackWalker") \
template(doStackWalk_signature, "(JIIII)Ljava/lang/Object;") \
template(asPrimitive_name, "asPrimitive") \
- template(asPrimitive_int_signature, "(I)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_long_signature, "(J)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_short_signature, "(S)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_byte_signature, "(B)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_char_signature, "(C)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_float_signature, "(F)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_double_signature, "(D)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
- template(asPrimitive_boolean_signature, "(Z)Ljava/lang/LiveStackFrame$PrimitiveValue;") \
+ template(asPrimitive_int_signature, "(I)Ljava/lang/LiveStackFrame$PrimitiveSlot;") \
+ template(asPrimitive_long_signature, "(J)Ljava/lang/LiveStackFrame$PrimitiveSlot;") \
\
/* common method and field names */ \
template(object_initializer_name, "") \
@@ -444,6 +438,7 @@
template(monitors_name, "monitors") \
template(locals_name, "locals") \
template(operands_name, "operands") \
+ template(mode_name, "mode") \
template(oop_size_name, "oop_size") \
template(static_oop_field_count_name, "static_oop_field_count") \
template(protection_domain_name, "protection_domain") \
diff --git a/hotspot/src/share/vm/code/codeCache.cpp b/hotspot/src/share/vm/code/codeCache.cpp
index bfe643ab683..e1a2f6392b0 100644
--- a/hotspot/src/share/vm/code/codeCache.cpp
+++ b/hotspot/src/share/vm/code/codeCache.cpp
@@ -1211,7 +1211,7 @@ void CodeCache::make_marked_nmethods_not_entrant() {
CompiledMethodIterator iter;
while(iter.next_alive()) {
CompiledMethod* nm = iter.method();
- if (nm->is_marked_for_deoptimization()) {
+ if (nm->is_marked_for_deoptimization() && !nm->is_not_entrant()) {
nm->make_not_entrant();
}
}
diff --git a/hotspot/src/share/vm/code/nmethod.cpp b/hotspot/src/share/vm/code/nmethod.cpp
index 71420040970..f82872baf1c 100644
--- a/hotspot/src/share/vm/code/nmethod.cpp
+++ b/hotspot/src/share/vm/code/nmethod.cpp
@@ -1146,6 +1146,14 @@ bool nmethod::make_not_entrant_or_zombie(unsigned int state) {
assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
assert(!is_zombie(), "should not already be a zombie");
+ if (_state == state) {
+ // Avoid taking the lock if already in required state.
+ // This is safe from races because the state is an end-state,
+ // which the nmethod cannot back out of once entered.
+ // No need for fencing either.
+ return false;
+ }
+
// Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
nmethodLocker nml(this);
methodHandle the_method(method());
diff --git a/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
index 1cc6a5ea1e9..4effbf42d11 100644
--- a/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
+++ b/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
@@ -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
@@ -488,9 +488,6 @@ CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen,
_gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()),
_cms_start_registered(false)
{
- if (ExplicitGCInvokesConcurrentAndUnloadsClasses) {
- ExplicitGCInvokesConcurrent = true;
- }
// Now expand the span and allocate the collection support structures
// (MUT, marking bit map etc.) to cover both generations subject to
// collection.
@@ -2559,10 +2556,8 @@ void CMSCollector::verify_overflow_empty() const {
// Decide if we want to enable class unloading as part of the
// ensuing concurrent GC cycle. We will collect and
// unload classes if it's the case that:
-// (1) an explicit gc request has been made and the flag
-// ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR
-// (2) (a) class unloading is enabled at the command line, and
-// (b) old gen is getting really full
+// (a) class unloading is enabled at the command line, and
+// (b) old gen is getting really full
// NOTE: Provided there is no change in the state of the heap between
// calls to this method, it should have idempotent results. Moreover,
// its results should be monotonically increasing (i.e. going from 0 to 1,
@@ -2575,11 +2570,7 @@ void CMSCollector::verify_overflow_empty() const {
// below.
void CMSCollector::update_should_unload_classes() {
_should_unload_classes = false;
- // Condition 1 above
- if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) {
- _should_unload_classes = true;
- } else if (CMSClassUnloadingEnabled) { // Condition 2.a above
- // Disjuncts 2.b.(i,ii,iii) above
+ if (CMSClassUnloadingEnabled) {
_should_unload_classes = (concurrent_cycles_since_last_unload() >=
CMSClassUnloadingMaxInterval)
|| _cmsGen->is_too_full();
diff --git a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp
index 7967d6cf001..6015b16c3e2 100644
--- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp
+++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp
@@ -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
@@ -711,29 +711,6 @@ void HeapRegionRemSet::setup_remset_size() {
guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity");
}
-#ifndef PRODUCT
-void HeapRegionRemSet::print() {
- HeapRegionRemSetIterator iter(this);
- size_t card_index;
- while (iter.has_next(card_index)) {
- HeapWord* card_start = _bot->address_for_index(card_index);
- tty->print_cr(" Card " PTR_FORMAT, p2i(card_start));
- }
- if (iter.n_yielded() != occupied()) {
- tty->print_cr("Yielded disagrees with occupied:");
- tty->print_cr(" " SIZE_FORMAT_W(6) " yielded (" SIZE_FORMAT_W(6)
- " coarse, " SIZE_FORMAT_W(6) " fine).",
- iter.n_yielded(),
- iter.n_yielded_coarse(), iter.n_yielded_fine());
- tty->print_cr(" " SIZE_FORMAT_W(6) " occ (" SIZE_FORMAT_W(6)
- " coarse, " SIZE_FORMAT_W(6) " fine).",
- occupied(), occ_coarse(), occ_fine());
- }
- guarantee(iter.n_yielded() == occupied(),
- "We should have yielded all the represented cards.");
-}
-#endif
-
void HeapRegionRemSet::cleanup() {
SparsePRT::cleanup_all();
}
@@ -917,10 +894,6 @@ bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
// Otherwise...
break;
}
- assert(ParallelGCThreads > 1 ||
- n_yielded() == _hrrs->occupied(),
- "Should have yielded all the cards in the rem set "
- "(in the non-par case).");
return false;
}
diff --git a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp
index 7f740b692c8..97c7e0643ea 100644
--- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp
+++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp
@@ -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
@@ -290,8 +290,6 @@ public:
// consumed by the strong code roots.
size_t strong_code_roots_mem_size();
- void print() PRODUCT_RETURN;
-
// Called during a stop-world phase to perform any deferred cleanups.
static void cleanup();
diff --git a/hotspot/src/share/vm/oops/method.cpp b/hotspot/src/share/vm/oops/method.cpp
index f37278edd13..beed68bed8e 100644
--- a/hotspot/src/share/vm/oops/method.cpp
+++ b/hotspot/src/share/vm/oops/method.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -2199,7 +2199,6 @@ void Method::print_on(outputStream* st) const {
ResourceMark rm;
assert(is_method(), "must be method");
st->print_cr("%s", internal_name());
- // get the effect of PrintOopAddress, always, for methods:
st->print_cr(" - this oop: " INTPTR_FORMAT, p2i(this));
st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr();
st->print (" - constants: " INTPTR_FORMAT " ", p2i(constants()));
diff --git a/hotspot/src/share/vm/opto/type.cpp b/hotspot/src/share/vm/opto/type.cpp
index a8c68006020..6411307c517 100644
--- a/hotspot/src/share/vm/opto/type.cpp
+++ b/hotspot/src/share/vm/opto/type.cpp
@@ -373,7 +373,7 @@ const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
if (con_type != NULL && field->is_call_site_target()) {
ciCallSite* call_site = holder->as_call_site();
if (!call_site->is_constant_call_site()) {
- ciMethodHandle* target = call_site->get_target();
+ ciMethodHandle* target = con.as_object()->as_method_handle();
Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
}
}
diff --git a/hotspot/src/share/vm/prims/jvm.cpp b/hotspot/src/share/vm/prims/jvm.cpp
index 2955463852e..a5569e766c2 100644
--- a/hotspot/src/share/vm/prims/jvm.cpp
+++ b/hotspot/src/share/vm/prims/jvm.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -2967,14 +2967,7 @@ JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
JVMWrapper("JVM_Yield");
if (os::dont_yield()) return;
HOTSPOT_THREAD_YIELD();
-
- // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
- // Critical for similar threading behaviour
- if (ConvertYieldToSleep) {
- os::sleep(thread, MinSleepInterval, false);
- } else {
- os::naked_yield();
- }
+ os::naked_yield();
JVM_END
@@ -2998,18 +2991,7 @@ JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
EventThreadSleep event;
if (millis == 0) {
- // When ConvertSleepToYield is on, this matches the classic VM implementation of
- // JVM_Sleep. Critical for similar threading behaviour (Win32)
- // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
- // for SOLARIS
- if (ConvertSleepToYield) {
- os::naked_yield();
- } else {
- ThreadState old_state = thread->osthread()->get_state();
- thread->osthread()->set_state(SLEEPING);
- os::sleep(thread, MinSleepInterval, false);
- thread->osthread()->set_state(old_state);
- }
+ os::naked_yield();
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);
diff --git a/hotspot/src/share/vm/prims/jvmtiExport.cpp b/hotspot/src/share/vm/prims/jvmtiExport.cpp
index 52350da0cde..ad7984c4a8f 100644
--- a/hotspot/src/share/vm/prims/jvmtiExport.cpp
+++ b/hotspot/src/share/vm/prims/jvmtiExport.cpp
@@ -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.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1230,8 +1230,12 @@ void JvmtiExport::post_class_unload(Klass* klass) {
assert(thread->is_VM_thread(), "wrong thread");
// get JavaThread for whom we are proxy
- JavaThread *real_thread =
- (JavaThread *)((VMThread *)thread)->vm_operation()->calling_thread();
+ Thread *calling_thread = ((VMThread *)thread)->vm_operation()->calling_thread();
+ if (!calling_thread->is_Java_thread()) {
+ // cannot post an event to a non-JavaThread
+ return;
+ }
+ JavaThread *real_thread = (JavaThread *)calling_thread;
JvmtiEnvIterator it;
for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
diff --git a/hotspot/src/share/vm/prims/methodHandles.cpp b/hotspot/src/share/vm/prims/methodHandles.cpp
index 717c1fe00ad..abde0dd02ed 100644
--- a/hotspot/src/share/vm/prims/methodHandles.cpp
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -1208,9 +1208,10 @@ JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh,
if (reference_klass != NULL && reference_klass->is_instance_klass()) {
// Emulate LinkResolver::check_klass_accessability.
Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
- if (Reflection::verify_class_access(caller,
- reference_klass,
- true) != Reflection::ACCESS_OK) {
+ if (caller != SystemDictionary::Object_klass()
+ && Reflection::verify_class_access(caller,
+ reference_klass,
+ true) != Reflection::ACCESS_OK) {
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
}
}
diff --git a/hotspot/src/share/vm/prims/stackwalk.cpp b/hotspot/src/share/vm/prims/stackwalk.cpp
index e130127318a..9e3fc9a8464 100644
--- a/hotspot/src/share/vm/prims/stackwalk.cpp
+++ b/hotspot/src/share/vm/prims/stackwalk.cpp
@@ -173,7 +173,11 @@ void JavaFrameStream::fill_frame(int index, objArrayHandle frames_array,
}
}
-oop LiveFrameStream::create_primitive_value_instance(StackValueCollection* values, int i, TRAPS) {
+// Create and return a LiveStackFrame.PrimitiveSlot (if needed) for the
+// StackValue at the given index. 'type' is expected to be T_INT, T_LONG,
+// T_OBJECT, or T_CONFLICT.
+oop LiveFrameStream::create_primitive_slot_instance(StackValueCollection* values,
+ int i, BasicType type, TRAPS) {
Klass* k = SystemDictionary::resolve_or_null(vmSymbols::java_lang_LiveStackFrameInfo(), CHECK_NULL);
instanceKlassHandle ik (THREAD, k);
@@ -182,8 +186,8 @@ oop LiveFrameStream::create_primitive_value_instance(StackValueCollection* value
Symbol* signature = NULL;
// ## TODO: type is only available in LocalVariable table, if present.
- // ## StackValue type is T_INT or T_OBJECT.
- switch (values->at(i)->type()) {
+ // ## StackValue type is T_INT or T_OBJECT (or converted to T_LONG on 64-bit)
+ switch (type) {
case T_INT:
args.push_int(values->int_at(i));
signature = vmSymbols::asPrimitive_int_signature();
@@ -195,42 +199,26 @@ oop LiveFrameStream::create_primitive_value_instance(StackValueCollection* value
break;
case T_FLOAT:
- args.push_float(values->float_at(i));
- signature = vmSymbols::asPrimitive_float_signature();
- break;
-
case T_DOUBLE:
- args.push_double(values->double_at(i));
- signature = vmSymbols::asPrimitive_double_signature();
- break;
-
case T_BYTE:
- args.push_int(values->int_at(i));
- signature = vmSymbols::asPrimitive_byte_signature();
- break;
-
case T_SHORT:
- args.push_int(values->int_at(i));
- signature = vmSymbols::asPrimitive_short_signature();
- break;
-
case T_CHAR:
- args.push_int(values->int_at(i));
- signature = vmSymbols::asPrimitive_char_signature();
- break;
-
case T_BOOLEAN:
- args.push_int(values->int_at(i));
- signature = vmSymbols::asPrimitive_boolean_signature();
- break;
+ THROW_MSG_(vmSymbols::java_lang_InternalError(), "Unexpected StackValue type", NULL);
case T_OBJECT:
return values->obj_at(i)();
case T_CONFLICT:
// put a non-null slot
- args.push_int(0);
- signature = vmSymbols::asPrimitive_int_signature();
+ #ifdef _LP64
+ args.push_long(0);
+ signature = vmSymbols::asPrimitive_long_signature();
+ #else
+ args.push_int(0);
+ signature = vmSymbols::asPrimitive_int_signature();
+ #endif
+
break;
default: ShouldNotReachHere();
@@ -252,9 +240,19 @@ objArrayHandle LiveFrameStream::values_to_object_array(StackValueCollection* val
objArrayHandle array_h(THREAD, array_oop);
for (int i = 0; i < values->size(); i++) {
StackValue* st = values->at(i);
- oop obj = create_primitive_value_instance(values, i, CHECK_(empty));
- if (obj != NULL)
+ BasicType type = st->type();
+ int index = i;
+#ifdef _LP64
+ if (type != T_OBJECT && type != T_CONFLICT) {
+ intptr_t ret = st->get_int(); // read full 64-bit slot
+ type = T_LONG; // treat as long
+ index--; // undo +1 in StackValueCollection::long_at
+ }
+#endif
+ oop obj = create_primitive_slot_instance(values, index, type, CHECK_(empty));
+ if (obj != NULL) {
array_h->obj_at_put(i, obj);
+ }
}
return array_h;
}
@@ -286,6 +284,13 @@ void LiveFrameStream::fill_live_stackframe(Handle stackFrame,
StackValueCollection* expressions = _jvf->expressions();
GrowableArray* monitors = _jvf->monitors();
+ int mode = 0;
+ if (_jvf->is_interpreted_frame()) {
+ mode = MODE_INTERPRETED;
+ } else if (_jvf->is_compiled_frame()) {
+ mode = MODE_COMPILED;
+ }
+
if (!locals->is_empty()) {
objArrayHandle locals_h = values_to_object_array(locals, CHECK);
java_lang_LiveStackFrameInfo::set_locals(stackFrame(), locals_h());
@@ -298,6 +303,7 @@ void LiveFrameStream::fill_live_stackframe(Handle stackFrame,
objArrayHandle monitors_h = monitors_to_object_array(monitors, CHECK);
java_lang_LiveStackFrameInfo::set_monitors(stackFrame(), monitors_h());
}
+ java_lang_LiveStackFrameInfo::set_mode(stackFrame(), mode);
}
}
diff --git a/hotspot/src/share/vm/prims/stackwalk.hpp b/hotspot/src/share/vm/prims/stackwalk.hpp
index 161a74599c3..a0c4bede64a 100644
--- a/hotspot/src/share/vm/prims/stackwalk.hpp
+++ b/hotspot/src/share/vm/prims/stackwalk.hpp
@@ -92,11 +92,16 @@ public:
class LiveFrameStream : public BaseFrameStream {
private:
+ enum {
+ MODE_INTERPRETED = 0x01,
+ MODE_COMPILED = 0x02
+ };
+
javaVFrame* _jvf;
void fill_live_stackframe(Handle stackFrame, const methodHandle& method, TRAPS);
- static oop create_primitive_value_instance(StackValueCollection* values,
- int i, TRAPS);
+ static oop create_primitive_slot_instance(StackValueCollection* values,
+ int i, BasicType type, TRAPS);
static objArrayHandle monitors_to_object_array(GrowableArray* monitors,
TRAPS);
static objArrayHandle values_to_object_array(StackValueCollection* values, TRAPS);
diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp
index b57cb96839f..4ae0e3b1ee1 100644
--- a/hotspot/src/share/vm/runtime/arguments.cpp
+++ b/hotspot/src/share/vm/runtime/arguments.cpp
@@ -375,53 +375,17 @@ static SpecialFlag const special_jvm_flags[] = {
// -------------- Deprecated Flags --------------
// --- Non-alias flags - sorted by obsolete_in then expired_in:
{ "MaxGCMinorPauseMillis", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
- { "AutoGCSelectPauseMillis", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "UseAutoGCSelectPolicy", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "UseParNewGC", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "ExplicitGCInvokesConcurrentAndUnloadsClasses", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "ConvertSleepToYield", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
- { "ConvertYieldToSleep", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
// --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
{ "DefaultMaxRAMFraction", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
{ "CreateMinidumpOnCrash", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
- { "CMSMarkStackSizeMax", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "CMSMarkStackSize", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "G1MarkStackSize", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "ParallelMarkingThreads", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
- { "ParallelCMSThreads", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
// -------------- Obsolete Flags - sorted by expired_in --------------
- { "UseOldInlining", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "SafepointPollOffset", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "UseBoundThreads", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "DefaultThreadPriority", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "NoYieldsInMicrolock", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "BackEdgeThreshold", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "UseNewReflection", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "ReflectionWrapResolutionErrors",JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "VerifyReflectionBytecodes", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "AutoShutdownNMT", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "NmethodSweepFraction", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "NmethodSweepCheckInterval", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "CodeCacheMinimumFreeSpace", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
-#ifndef ZERO
- { "UseFastAccessorMethods", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "UseFastEmptyMethods", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
-#endif // ZERO
- { "UseCompilerSafepoints", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "AdaptiveSizePausePolicy", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "ParallelGCRetainPLAB", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "ThreadSafetyMargin", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "LazyBootClassLoader", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "StarvationMonitorInterval", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "PreInflateSpin", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "JNIDetachReleasesMonitors", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "UseAltSigs", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "SegmentedHeapDumpThreshold", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "PrintOopAddress", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
- { "PermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::jdk(10) },
- { "MaxPermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::jdk(10) },
+ { "ConvertSleepToYield", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
+ { "ConvertYieldToSleep", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
+ { "MinSleepInterval", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
+ { "PermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::undefined() },
+ { "MaxPermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::undefined() },
#ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS
{ "dep > obs", JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() },
@@ -444,11 +408,6 @@ typedef struct {
static AliasedFlag const aliased_jvm_flags[] = {
{ "DefaultMaxRAMFraction", "MaxRAMFraction" },
- { "CMSMarkStackSizeMax", "MarkStackSizeMax" },
- { "CMSMarkStackSize", "MarkStackSize" },
- { "G1MarkStackSize", "MarkStackSize" },
- { "ParallelMarkingThreads", "ConcGCThreads" },
- { "ParallelCMSThreads", "ConcGCThreads" },
{ "CreateMinidumpOnCrash", "CreateCoredumpOnCrash" },
{ NULL, NULL}
};
@@ -1547,7 +1506,6 @@ void Arguments::set_parnew_gc_flags() {
assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
"control point invariant");
assert(UseConcMarkSweepGC, "CMS is expected to be on here");
- assert(UseParNewGC, "ParNew should always be used with CMS");
if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
@@ -1588,7 +1546,6 @@ void Arguments::set_parnew_gc_flags() {
void Arguments::set_cms_and_parnew_gc_flags() {
assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
assert(UseConcMarkSweepGC, "CMS is expected to be on here");
- assert(UseParNewGC, "ParNew should always be used with CMS");
// Turn off AdaptiveSizePolicy by default for cms until it is complete.
disable_adaptive_size_policy("UseConcMarkSweepGC");
@@ -1728,16 +1685,6 @@ size_t Arguments::max_heap_for_compressed_oops() {
NOT_LP64(ShouldNotReachHere(); return 0);
}
-bool Arguments::should_auto_select_low_pause_collector() {
- if (UseAutoGCSelectPolicy &&
- !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
- (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
- log_trace(gc)("Automatic selection of the low pause collector based on pause goal of %d (ms)", (int) MaxGCPauseMillis);
- return true;
- }
- return false;
-}
-
void Arguments::set_use_compressed_oops() {
#ifndef ZERO
#ifdef _LP64
@@ -1841,16 +1788,7 @@ void Arguments::select_compilation_mode_ergonomically() {
void Arguments::select_gc_ergonomically() {
#if INCLUDE_ALL_GCS
if (os::is_server_class_machine()) {
- if (!UseAutoGCSelectPolicy) {
- FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
- } else {
- if (should_auto_select_low_pause_collector()) {
- FLAG_SET_ERGO_IF_DEFAULT(bool, UseConcMarkSweepGC, true);
- FLAG_SET_ERGO_IF_DEFAULT(bool, UseParNewGC, true);
- } else {
- FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
- }
- }
+ FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
} else {
FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
}
@@ -1859,7 +1797,6 @@ void Arguments::select_gc_ergonomically() {
UNSUPPORTED_OPTION(UseParallelGC);
UNSUPPORTED_OPTION(UseParallelOldGC);
UNSUPPORTED_OPTION(UseConcMarkSweepGC);
- UNSUPPORTED_OPTION(UseParNewGC);
FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
#endif // INCLUDE_ALL_GCS
}
@@ -2073,7 +2010,6 @@ void Arguments::set_gc_specific_flags() {
if (!ClassUnloading) {
FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false);
- FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);
}
#endif // INCLUDE_ALL_GCS
}
@@ -2428,18 +2364,6 @@ bool Arguments::check_gc_consistency() {
return false;
}
- if (UseConcMarkSweepGC && !UseParNewGC) {
- jio_fprintf(defaultStream::error_stream(),
- "It is not possible to combine the DefNew young collector with the CMS collector.\n");
- return false;
- }
-
- if (UseParNewGC && !UseConcMarkSweepGC) {
- jio_fprintf(defaultStream::error_stream(),
- "It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
- return false;
- }
-
return true;
}
@@ -3726,11 +3650,6 @@ jint Arguments::finalize_vm_init_args() {
}
}
- if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
- // CMS can only be used with ParNew
- FLAG_SET_ERGO(bool, UseParNewGC, true);
- }
-
if (!check_vm_args_consistency()) {
return JNI_ERR;
}
diff --git a/hotspot/src/share/vm/runtime/arguments.hpp b/hotspot/src/share/vm/runtime/arguments.hpp
index daa91c22bd7..ad2178d7d20 100644
--- a/hotspot/src/share/vm/runtime/arguments.hpp
+++ b/hotspot/src/share/vm/runtime/arguments.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -480,9 +480,6 @@ class Arguments : AllStatic {
static julong limit_by_allocatable_memory(julong size);
// Setup heap size
static void set_heap_size();
- // Based on automatic selection criteria, should the
- // low pause collector be used.
- static bool should_auto_select_low_pause_collector();
// Bytecode rewriting
static void set_bytecode_flags();
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index 90b274e58a2..a6c23d02542 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -1159,13 +1159,6 @@ public:
product_pd(bool, DontYieldALot, \
"Throw away obvious excess yield calls") \
\
- product(bool, ConvertSleepToYield, true, \
- "Convert sleep(0) to thread yield ") \
- \
- product(bool, ConvertYieldToSleep, false, \
- "Convert yield to a sleep of MinSleepInterval to simulate Win32 " \
- "behavior") \
- \
develop(bool, UseDetachedThreads, true, \
"Use detached threads that are recycled upon termination " \
"(for Solaris only)") \
@@ -1479,11 +1472,6 @@ public:
"A System.gc() request invokes a concurrent collection; " \
"(effective only when using concurrent collectors)") \
\
- product(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false, \
- "A System.gc() request invokes a concurrent collection and " \
- "also unloads classes during such a concurrent gc cycle " \
- "(effective only when UseConcMarkSweepGC)") \
- \
product(bool, GCLockerInvokesConcurrent, false, \
"The exit of a JNI critical section necessitating a scavenge, " \
"also kicks off a background concurrent collection") \
@@ -1501,9 +1489,6 @@ public:
product(bool, UseCMSBestFit, true, \
"Use CMS best fit allocation strategy") \
\
- product(bool, UseParNewGC, false, \
- "Use parallel threads in the new generation") \
- \
product(uintx, ParallelGCBufferWastePct, 10, \
"Wasted fraction of parallel allocation buffer") \
range(0, 100) \
@@ -2059,13 +2044,6 @@ public:
"Maximum fraction (1/n) of virtual memory used for ergonomically "\
"determining maximum heap size") \
\
- product(bool, UseAutoGCSelectPolicy, false, \
- "Use automatic collection selection policy") \
- \
- product(uintx, AutoGCSelectPauseMillis, 5000, \
- "Automatic GC selection pause threshold in milliseconds") \
- range(0, max_uintx) \
- \
product(bool, UseAdaptiveSizePolicy, true, \
"Use adaptive generation sizing policies") \
\
@@ -3003,10 +2981,6 @@ public:
develop(intx, DontYieldALotInterval, 10, \
"Interval between which yields will be dropped (milliseconds)") \
\
- develop(intx, MinSleepInterval, 1, \
- "Minimum sleep() interval (milliseconds) when " \
- "ConvertSleepToYield is off (used for Solaris)") \
- \
develop(intx, ProfilerPCTickThreshold, 15, \
"Number of ticks in a PC buckets to be a hotspot") \
\
diff --git a/hotspot/test/ProblemList.txt b/hotspot/test/ProblemList.txt
index bf6811efb15..31e5703c376 100644
--- a/hotspot/test/ProblemList.txt
+++ b/hotspot/test/ProblemList.txt
@@ -73,6 +73,7 @@ runtime/SharedArchiveFile/DefaultUseWithClient.java 8154204 generic-all
serviceability/jdwp/AllModulesCommandTest.java 8168478 generic-all
serviceability/sa/sadebugd/SADebugDTest.java 8163805 generic-all
+serviceability/jvmti/ModuleAwareAgents/ClassFileLoadHook/MAAClassFileLoadHook.java 8173936 generic-all
#############################################################################
diff --git a/hotspot/test/TEST.groups b/hotspot/test/TEST.groups
index c50c741f44d..8953467a9b2 100644
--- a/hotspot/test/TEST.groups
+++ b/hotspot/test/TEST.groups
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2013, 2016, 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
@@ -209,11 +209,8 @@ needs_full_vm_compact1 = \
gc/g1/TestShrinkToOneRegion.java \
gc/metaspace/G1AddMetaspaceDependency.java \
gc/startup_warnings/TestCMS.java \
- gc/startup_warnings/TestDefNewCMS.java \
gc/startup_warnings/TestParallelGC.java \
gc/startup_warnings/TestParallelScavengeSerialOld.java \
- gc/startup_warnings/TestParNewCMS.java \
- gc/startup_warnings/TestParNewSerialOld.java \
runtime/SharedArchiveFile/SharedArchiveFile.java
# Minimal VM on Compact 2 adds in some compact2 tests
diff --git a/hotspot/test/compiler/c1/TestUnresolvedField.jasm b/hotspot/test/compiler/c1/TestUnresolvedField.jasm
new file mode 100644
index 00000000000..e6c2ae4de2b
--- /dev/null
+++ b/hotspot/test/compiler/c1/TestUnresolvedField.jasm
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ *
+ */
+
+public class compiler/c1/TestUnresolvedField version 52:0 {
+ public static Method testGetField:"()V" stack 1 locals 1 {
+ aconst_null;
+ getfield Field T.f:I; // T does not exist
+ return;
+ }
+
+ public static Method testPutField:"()V" stack 2 locals 1 {
+ aconst_null;
+ iconst_0;
+ putfield Field T.f:I; // T does not exist
+ return;
+ }
+}
diff --git a/jdk/test/sun/security/krb5/auto/BadKdc4.java b/hotspot/test/compiler/c1/TestUnresolvedFieldMain.java
similarity index 57%
rename from jdk/test/sun/security/krb5/auto/BadKdc4.java
rename to hotspot/test/compiler/c1/TestUnresolvedFieldMain.java
index 8d64db2faca..040f1b17be6 100644
--- a/jdk/test/sun/security/krb5/auto/BadKdc4.java
+++ b/hotspot/test/compiler/c1/TestUnresolvedFieldMain.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -23,28 +23,26 @@
/*
* @test
- * @bug 6843127
- * @run main/othervm/timeout=300 BadKdc4
- * @summary krb5 should not try to access unavailable kdc too often
+ * @bug 8173373
+ * @compile TestUnresolvedField.jasm
+ * @run main/othervm -XX:TieredStopAtLevel=1 -Xcomp
+ * -XX:CompileCommand=compileonly,compiler.c1.TestUnresolvedField::test*
+ * compiler.c1.TestUnresolvedFieldMain
*/
-import java.io.*;
-import java.security.Security;
+package compiler.c1;
-public class BadKdc4 {
-
- public static void main(String[] args)
- throws Exception {
- Security.setProperty("krb5.kdc.bad.policy", "");
- BadKdc.go(
- "121212222222(32){1,3}121212222222(32){1,3}",
- "121212222222(32){1,3}121212222222(32){1,3}",
- // refresh
- "121212222222(32){1,3}121212222222(32){1,3}",
- // k3 off k2 on
- "121212(22){1,3}121212(22){1,3}",
- // k1 on
- "(12){2,4}"
- );
+public class TestUnresolvedFieldMain {
+ public static void main(String[] args) {
+ try {
+ TestUnresolvedField.testGetField();
+ } catch (java.lang.NoClassDefFoundError error) {
+ // Expected
+ }
+ try {
+ TestUnresolvedField.testPutField();
+ } catch (java.lang.NoClassDefFoundError error) {
+ // Expected
+ }
}
}
diff --git a/hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java b/hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java
index d9f2ddb1721..7fdd282033d 100644
--- a/hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java
+++ b/hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java
@@ -23,7 +23,6 @@
/**
* @test
- * @modules java.base/jdk.internal.misc
* @library /test/lib /
*
* @run driver compiler.jsr292.ContinuousCallSiteTargetChange
@@ -31,6 +30,7 @@
package compiler.jsr292;
+import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
@@ -39,15 +39,26 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
public class ContinuousCallSiteTargetChange {
- static void testServer() throws Exception {
+ static final int ITERATIONS = Integer.parseInt(System.getProperty("iterations", "50"));
+
+ static void runTest(Class> test, String... extraArgs) throws Exception {
+ List argsList = new ArrayList<>(
+ List.of("-XX:+IgnoreUnrecognizedVMOptions",
+ "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
+ "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining"));
+
+ argsList.addAll(Arrays.asList(extraArgs));
+
+ argsList.add(test.getName());
+ argsList.add(Integer.toString(ITERATIONS));
+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "-XX:+IgnoreUnrecognizedVMOptions",
- "-server", "-XX:-TieredCompilation", "-Xbatch",
- "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
- "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
- Test.class.getName(), "100");
+ argsList.toArray(new String[argsList.size()]));
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
@@ -55,30 +66,42 @@ public class ContinuousCallSiteTargetChange {
analyzer.shouldNotContain("made not compilable");
analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
+
}
- static void testClient() throws Exception {
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "-XX:+IgnoreUnrecognizedVMOptions",
- "-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1", "-Xbatch",
- "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
- "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
- Test.class.getName(), "100");
+ static void testServer(Class> test, String... args) throws Exception {
+ List extraArgsList = new ArrayList<>(
+ List.of("-server", "-XX:-TieredCompilation"));
+ extraArgsList.addAll(Arrays.asList(args));
- OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
+ runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
+ }
- analyzer.shouldHaveExitValue(0);
+ static void testClient(Class> test, String... args) throws Exception {
+ List extraArgsList = new ArrayList<>(
+ List.of("-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1"));
+ extraArgsList.addAll(Arrays.asList(args));
- analyzer.shouldNotContain("made not compilable");
- analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
+ runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
}
public static void main(String[] args) throws Exception {
- testServer();
- testClient();
+ testServer(RecompilationTest.class, "-Xbatch");
+ testClient(RecompilationTest.class, "-Xbatch");
+
+ testServer(PingPongTest.class);
+ testClient(PingPongTest.class);
}
- static class Test {
+ static MethodHandle findStatic(Class> cls, String name, MethodType mt) {
+ try {
+ return MethodHandles.lookup().findStatic(cls, name, mt);
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ static class RecompilationTest {
static final MethodType mt = MethodType.methodType(void.class);
static final CallSite cs = new MutableCallSite(mt);
@@ -96,7 +119,7 @@ public class ContinuousCallSiteTargetChange {
}
static void iteration() throws Throwable {
- MethodHandle mh1 = MethodHandles.lookup().findStatic(ContinuousCallSiteTargetChange.Test.class, "f", mt);
+ MethodHandle mh1 = findStatic(RecompilationTest.class, "f", mt);
cs.setTarget(mh1);
for (int i = 0; i < 20_000; i++) {
test1();
@@ -111,4 +134,38 @@ public class ContinuousCallSiteTargetChange {
}
}
}
+
+ static class PingPongTest {
+ static final MethodType mt = MethodType.methodType(void.class);
+ static final CallSite cs = new MutableCallSite(mt);
+
+ static final MethodHandle mh = cs.dynamicInvoker();
+
+ static final MethodHandle ping = findStatic(PingPongTest.class, "ping", mt);
+ static final MethodHandle pong = findStatic(PingPongTest.class, "pong", mt);
+
+ static void ping() {
+ Asserts.assertEQ(cs.getTarget(), ping, "wrong call site target");
+ cs.setTarget(pong);
+ }
+
+ static void pong() {
+ Asserts.assertEQ(cs.getTarget(), pong, "wrong call site target");
+ cs.setTarget(ping);
+ }
+
+ static void iteration() throws Throwable {
+ cs.setTarget(ping);
+ for (int i = 0; i < 20_000; i++) {
+ mh.invokeExact();
+ }
+ }
+
+ public static void main(String[] args) throws Throwable {
+ int iterations = Integer.parseInt(args[0]);
+ for (int i = 0; i < iterations; i++) {
+ iteration();
+ }
+ }
+ }
}
diff --git a/hotspot/test/compiler/jsr292/patches/java.base/java/lang/invoke/MethodHandleHelper.java b/hotspot/test/compiler/jsr292/patches/java.base/java/lang/invoke/MethodHandleHelper.java
index a4732624a3a..ad0d29278c2 100644
--- a/hotspot/test/compiler/jsr292/patches/java.base/java/lang/invoke/MethodHandleHelper.java
+++ b/hotspot/test/compiler/jsr292/patches/java.base/java/lang/invoke/MethodHandleHelper.java
@@ -84,7 +84,7 @@ public class MethodHandleHelper {
public static MethodHandle make(MethodHandle target) {
LambdaForm lform = DelegatingMethodHandle.makeReinvokerForm(
- target, -1, DelegatingMethodHandle.class, "reinvoker.dontInline",
+ target, -1, DelegatingMethodHandle.class,
/*forceInline=*/false, DelegatingMethodHandle.NF_getTarget, null);
return new NonInlinedReinvoker(target, lform);
}
diff --git a/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java b/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java
index dee13cfef8d..ec463e11890 100644
--- a/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java
+++ b/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java
@@ -44,6 +44,8 @@
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:CompileCommand=exclude,*::check
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
+ * -XX:CompileCommand=dontinline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,testFrame
+ * -XX:CompileCommand=inline,compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest,recurse
* -Xbatch
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
@@ -119,14 +121,25 @@ public class MaterializeVirtualObjectTest {
}
Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
+ "Method unexpectedly not compiled");
+ Asserts.assertTrue(WB.getMethodCompilationLevel(METHOD) == 4, getName()
+ + "Method not compiled at level 4");
testFrame("someString", COMPILE_THRESHOLD);
}
private void testFrame(String str, int iteration) {
Helper helper = new Helper(str);
- check(iteration);
+ recurse(2, iteration);
Asserts.assertTrue((helper.string != null) && (this != null)
- && (helper != null), getName() + " : some locals are null");
+ && (helper != null), String.format("%s : some locals are null", getName()));
+ }
+ private void recurse(int depth, int iteration) {
+ if (depth == 0) {
+ check(iteration);
+ } else {
+ Integer s = new Integer(depth);
+ recurse(depth - 1, iteration);
+ Asserts.assertEQ(s.intValue(), depth, String.format("different values: %s != %s", s.intValue(), depth));
+ }
}
private void check(int iteration) {
diff --git a/hotspot/test/gc/arguments/TestExplicitGCInvokesConcurrentAndUnloadsClasses.java b/hotspot/test/gc/arguments/TestExplicitGCInvokesConcurrentAndUnloadsClasses.java
deleted file mode 100644
index 83f075760d6..00000000000
--- a/hotspot/test/gc/arguments/TestExplicitGCInvokesConcurrentAndUnloadsClasses.java
+++ /dev/null
@@ -1,48 +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 TestExplicitGCInvokesConcurrentAndUnloadsClasses
- * @summary Test that the flag ExplicitGCInvokesConcurrentAndUnloadsClasses is deprecated
- * @bug 8170388
- * @key gc
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * @run driver TestExplicitGCInvokesConcurrentAndUnloadsClasses
- */
-
-import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
-
-public class TestExplicitGCInvokesConcurrentAndUnloadsClasses {
- public static void main(String[] args) throws Exception {
- ProcessBuilder pb =
- ProcessTools.createJavaProcessBuilder("-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses",
- "-Xlog:gc",
- "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("ExplicitGCInvokesConcurrentAndUnloadsClasses was deprecated");
- output.shouldHaveExitValue(0);
- }
-}
diff --git a/hotspot/test/gc/arguments/TestSelectDefaultGC.java b/hotspot/test/gc/arguments/TestSelectDefaultGC.java
index de770b283b8..084ee04a86b 100644
--- a/hotspot/test/gc/arguments/TestSelectDefaultGC.java
+++ b/hotspot/test/gc/arguments/TestSelectDefaultGC.java
@@ -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
@@ -66,7 +66,6 @@ public class TestSelectDefaultGC {
assertVMOption(output, "UseSerialGC", !isServer);
// CMS is never default
assertVMOption(output, "UseConcMarkSweepGC", false);
- assertVMOption(output, "UseParNewGC", false);
}
public static void main(String[] args) throws Exception {
diff --git a/hotspot/test/gc/startup_warnings/TestDefNewCMS.java b/hotspot/test/gc/startup_warnings/TestDefNewCMS.java
deleted file mode 100644
index f8780679733..00000000000
--- a/hotspot/test/gc/startup_warnings/TestDefNewCMS.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2013, 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 TestDefNewCMS
-* @key gc
-* @bug 8065972
-* @summary Test that the unsupported DefNew+CMS combination does not start
-* @library /test/lib
-* @modules java.base/jdk.internal.misc
-* java.management
-*/
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-public class TestDefNewCMS {
-
- public static void main(String args[]) throws Exception {
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:-UseParNewGC", "-XX:+UseConcMarkSweepGC", "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("It is not possible to combine the DefNew young collector with the CMS collector.");
- output.shouldContain("Error");
- output.shouldHaveExitValue(1);
- }
-
-}
diff --git a/hotspot/test/gc/startup_warnings/TestParNewCMS.java b/hotspot/test/gc/startup_warnings/TestParNewCMS.java
deleted file mode 100644
index 75dbe4bf7b3..00000000000
--- a/hotspot/test/gc/startup_warnings/TestParNewCMS.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2013, 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 TestParNewCMS
-* @key gc
-* @bug 8065972
-* @summary Test that specifying -XX:+UseParNewGC on the command line logs a warning message
-* @library /test/lib
-* @modules java.base/jdk.internal.misc
-* java.management
-*/
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-
-public class TestParNewCMS {
-
- public static void main(String args[]) throws Exception {
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-XX:+UseConcMarkSweepGC", "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("warning: Option UseParNewGC was deprecated in version");
- output.shouldNotContain("error");
- output.shouldHaveExitValue(0);
- }
-
-}
diff --git a/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java b/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java
deleted file mode 100644
index a4c8d5c31e1..00000000000
--- a/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2013, 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 TestParNewSerialOld
-* @key gc
-* @bug 8065972
-* @summary Test that the unsupported ParNew+SerialOld combination does not start
-* @library /test/lib
-* @modules java.base/jdk.internal.misc
-* java.management
-*/
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-
-public class TestParNewSerialOld {
-
- public static void main(String args[]) throws Exception {
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("It is not possible to combine the ParNew young collector with any collector other than CMS.");
- output.shouldContain("Error");
- output.shouldHaveExitValue(1);
- }
-
-}
diff --git a/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java b/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java
index 31d8b47a2ba..59d245548a5 100644
--- a/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java
+++ b/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java
@@ -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
@@ -37,18 +37,18 @@ public class ObsoleteFlagErrorMessage {
// Case 1: Newly obsolete flags with extra junk appended should not be treated as newly obsolete (8060449)
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "-XX:UseOldInliningPlusJunk", "-version");
+ "-XX:ConvertSleepToYieldPlusJunk", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("Unrecognized VM option 'UseOldInliningPlusJunk'"); // Must identify bad option.
+ output.shouldContain("Unrecognized VM option 'ConvertSleepToYieldPlusJunk'"); // Must identify bad option.
output.shouldHaveExitValue(1);
- // Case 2: Newly obsolete integer-valued flags should be recognized as newly obsolete (8073989)
+ // Case 2: Newly obsolete flags should be recognized as newly obsolete (8073989)
ProcessBuilder pb2 = ProcessTools.createJavaProcessBuilder(
- "-XX:NmethodSweepFraction=10", "-version");
+ "-XX:+ConvertSleepToYield", "-version");
OutputAnalyzer output2 = new OutputAnalyzer(pb2.start());
output2.shouldContain("Ignoring option").shouldContain("support was removed");
- output2.shouldContain("NmethodSweepFraction");
+ output2.shouldContain("ConvertSleepToYield");
}
}
diff --git a/hotspot/test/runtime/CommandLine/VMAliasOptions.java b/hotspot/test/runtime/CommandLine/VMAliasOptions.java
index eae37477c08..d82b4ae2274 100644
--- a/hotspot/test/runtime/CommandLine/VMAliasOptions.java
+++ b/hotspot/test/runtime/CommandLine/VMAliasOptions.java
@@ -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
@@ -40,11 +40,6 @@ public class VMAliasOptions {
*/
public static final String[][] ALIAS_OPTIONS = {
{"DefaultMaxRAMFraction", "MaxRAMFraction", "1032"},
- {"CMSMarkStackSizeMax", "MarkStackSizeMax", "1032"},
- {"CMSMarkStackSize", "MarkStackSize", "1032"},
- {"G1MarkStackSize", "MarkStackSize", "1032"},
- {"ParallelMarkingThreads", "ConcGCThreads", "2"},
- {"ParallelCMSThreads", "ConcGCThreads", "2"},
{"CreateMinidumpOnCrash", "CreateCoredumpOnCrash", "false" },
};
diff --git a/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java b/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java
index 06f73568460..bbd2ea5c49f 100644
--- a/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java
+++ b/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java
@@ -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
@@ -41,17 +41,9 @@ public class VMDeprecatedOptions {
public static final String[][] DEPRECATED_OPTIONS = {
// deprecated non-alias flags:
{"MaxGCMinorPauseMillis", "1032"},
- {"UseParNewGC", "false"},
- {"ConvertSleepToYield", "false" },
- {"ConvertYieldToSleep", "false" },
// deprecated alias flags (see also aliased_jvm_flags):
{"DefaultMaxRAMFraction", "4"},
- {"CMSMarkStackSizeMax", "1032"},
- {"CMSMarkStackSize", "1032"},
- {"G1MarkStackSize", "1032"},
- {"ParallelMarkingThreads", "2"},
- {"ParallelCMSThreads", "2"},
{"CreateMinidumpOnCrash", "false"}
};
diff --git a/hotspot/test/runtime/LocalLong/LocalLongHelper.java b/hotspot/test/runtime/LocalLong/LocalLongHelper.java
index 2134aee069e..065d7d8cbcb 100644
--- a/hotspot/test/runtime/LocalLong/LocalLongHelper.java
+++ b/hotspot/test/runtime/LocalLong/LocalLongHelper.java
@@ -30,10 +30,10 @@ import java.lang.StackWalker.StackFrame;
public class LocalLongHelper {
static StackWalker sw;
- static Method intValue;
+ static Method longValue;
static Method getLocals;
static Class> primitiveValueClass;
- static Method primitiveType;
+ static Method primitiveSize;
static Method getMethodType;
static Field memberName;
static Field offset;
@@ -43,27 +43,29 @@ public class LocalLongHelper {
new LocalLongHelper().longArg(0xC0FFEE, 0x1234567890ABCDEFL);
}
- // locals[2] contains the high byte of the long argument.
+ // locals[2] contains the unused slot of the long argument.
public long longArg(int i, long l) throws Throwable {
List frames = sw.walk(s -> s.collect(Collectors.toList()));
Object[] locals = (Object[]) getLocals.invoke(frames.get(0));
- int locals_2 = (int) intValue.invoke(locals[2]);
- if (locals_2 != 0){
- throw new RuntimeException("Expected locals_2 == 0");
+ if (8 == (int) primitiveSize.invoke(locals[2])) { // Only test 64-bit
+ long locals_2 = (long) longValue.invoke(locals[2]);
+ if (locals_2 != 0){
+ throw new RuntimeException("Expected locals_2 == 0");
+ }
}
return l; // Don't want l to become a dead var
}
private static void setupReflectionStatics() throws Throwable {
Class> liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
- primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveValue");
+ primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveSlot");
getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
getLocals.setAccessible(true);
- intValue = primitiveValueClass.getDeclaredMethod("intValue");
- intValue.setAccessible(true);
+ longValue = primitiveValueClass.getDeclaredMethod("longValue");
+ longValue.setAccessible(true);
Class> stackFrameInfoClass = Class.forName("java.lang.StackFrameInfo");
memberName = stackFrameInfoClass.getDeclaredField("memberName");
@@ -80,20 +82,8 @@ public class LocalLongHelper {
f.setAccessible(true);
Object localsAndOperandsOption = f.get(null);
- primitiveType = primitiveValueClass.getDeclaredMethod("type");
- primitiveType.setAccessible(true);
-
+ primitiveSize = primitiveValueClass.getDeclaredMethod("size");
+ primitiveSize.setAccessible(true);
sw = (StackWalker) ewsNI.invoke(null, java.util.Collections.emptySet(), localsAndOperandsOption);
}
-
- private static String type(Object o) throws Throwable {
- if (primitiveValueClass.isInstance(o)) {
- final char c = (char) primitiveType.invoke(o);
- return String.valueOf(c);
- } else if (o != null) {
- return o.getClass().getName();
- } else {
- return "null";
- }
- }
}
diff --git a/hotspot/test/runtime/NMT/AutoshutdownNMT.java b/hotspot/test/runtime/NMT/AutoshutdownNMT.java
deleted file mode 100644
index d07103e810c..00000000000
--- a/hotspot/test/runtime/NMT/AutoshutdownNMT.java
+++ /dev/null
@@ -1,47 +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.
- *
- * 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
- * @key nmt
- * @summary Test for deprecated message if -XX:-AutoShutdownNMT is specified
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- */
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-public class AutoshutdownNMT {
-
- public static void main(String args[]) throws Exception {
-
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "-XX:NativeMemoryTracking=detail",
- "-XX:-AutoShutdownNMT",
- "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("Ignoring option AutoShutdownNMT");
- }
-}
diff --git a/hotspot/test/runtime/modules/AccessCheck/AccessExportTwice.java b/hotspot/test/runtime/modules/AccessCheck/AccessExportTwice.java
index a1eb2cce85d..5f9d716892f 100644
--- a/hotspot/test/runtime/modules/AccessCheck/AccessExportTwice.java
+++ b/hotspot/test/runtime/modules/AccessCheck/AccessExportTwice.java
@@ -68,7 +68,7 @@ public class AccessExportTwice {
// Packages: none
// Packages exported: none
ModuleDescriptor descriptor_first_mod =
- ModuleDescriptor.module("first_mod")
+ ModuleDescriptor.newModule("first_mod")
.requires("java.base")
.requires("second_mod")
.build();
@@ -78,7 +78,7 @@ public class AccessExportTwice {
// Packages: p2
// Packages exported: p2 is exported to first_mod
ModuleDescriptor descriptor_second_mod =
- ModuleDescriptor.module("second_mod")
+ ModuleDescriptor.newModule("second_mod")
.requires("java.base")
.exports("p2", Set.of("first_mod"))
.build();
@@ -89,7 +89,7 @@ public class AccessExportTwice {
// Resolves "first_mod"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("first_mod"));
+ .resolve(finder, ModuleFinder.of(), Set.of("first_mod"));
// Map each module to the same class loader
Map map = new HashMap<>();
diff --git a/hotspot/test/runtime/modules/AccessCheck/AccessReadTwice.java b/hotspot/test/runtime/modules/AccessCheck/AccessReadTwice.java
index 5d1a690a740..5e21a9335fc 100644
--- a/hotspot/test/runtime/modules/AccessCheck/AccessReadTwice.java
+++ b/hotspot/test/runtime/modules/AccessCheck/AccessReadTwice.java
@@ -66,9 +66,9 @@ public class AccessReadTwice {
// Packages: p1, p4
// Packages exported: none
ModuleDescriptor descriptor_first_mod =
- ModuleDescriptor.module("first_mod")
+ ModuleDescriptor.newModule("first_mod")
.requires("java.base")
- .contains(Set.of("p1", "p4"))
+ .packages(Set.of("p1", "p4"))
.build();
// Define module: second_mod
@@ -76,7 +76,7 @@ public class AccessReadTwice {
// Packages: p2
// Packages exported: p2 is exported to first_mod
ModuleDescriptor descriptor_second_mod =
- ModuleDescriptor.module("second_mod")
+ ModuleDescriptor.newModule("second_mod")
.requires("java.base")
.exports("p2", Set.of("first_mod"))
.build();
@@ -87,7 +87,7 @@ public class AccessReadTwice {
// Resolves "first_mod" and "second_mod"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod"));
+ .resolve(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod"));
// Map each module to this class loader
Map map = new HashMap<>();
diff --git a/hotspot/test/runtime/modules/AccessCheck/CheckRead.java b/hotspot/test/runtime/modules/AccessCheck/CheckRead.java
index 6143f0b94b0..0d507cb7f16 100644
--- a/hotspot/test/runtime/modules/AccessCheck/CheckRead.java
+++ b/hotspot/test/runtime/modules/AccessCheck/CheckRead.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can not read module m2, then class p1.c1
- * in module m1 can not access p2.c2 in module m2.
+ * @summary Test that if module m1x can not read module m2x, then class p1.c1
+ * in module m1x can not access p2.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// defines m2 --> packages p2
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> packages p1
+// defines m2x --> packages p2
+// defines m3x --> packages p3
//
-// m1 can not read m2
-// package p2 in m2 is exported to m1
+// m1x can not read m2x
+// package p2 in m2x is exported to m1x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
-// Access denied since m1 can not read m2.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
+// Access denied since m1x can not read m2x.
//
public class CheckRead {
@@ -64,65 +64,65 @@ public class CheckRead {
// publicly defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m3
+ // Define module: m1x
+ // Can read: java.base, m3x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m3")
+ .requires("m3x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: p2 is exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
- // Define module: m3
- // Can read: java.base, m2
+ // Define module: m3x
+ // Can read: java.base, m2x
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
- .requires("m2")
- .contains("p3")
+ .requires("m2x")
+ .packages(Set.of("p3"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
- map.put("m3", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
+ map.put("m3x", MySameClassLoader.loader1);
- // Create Layer that contains m1, m2 and m3
+ // Create Layer that contains m1x, m2x and m3x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1 but m2 is not readable from m1)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x but m2x is not readable from m1x)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("cannot access")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java
index b0b64a46d95..d02959fd06f 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_CheckRead.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can not read module m2, then class p1.c1
- * in module m1 can not access p2.c2 in module m2.
+ * @summary Test that if module m1x can not read module m2x, then class p1.c1
+ * in module m1x can not access p2.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
+// defines m3x --> packages p3
//
-// m1 can not read m2
-// package p2 in m2 is exported to m1
+// m1x can not read m2x
+// package p2 in m2x is exported to m1x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
-// Access denied since m1 can not read m2.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
+// Access denied since m1x can not read m2x.
//
public class DiffCL_CheckRead {
@@ -64,65 +64,65 @@ public class DiffCL_CheckRead {
// publicly defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m3
+ // Define module: m1x
+ // Can read: java.base, m3x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m3")
+ .requires("m3x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: p2 is exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
- // Define module: m3
- // Can read: java.base, m2
+ // Define module: m3x
+ // Can read: java.base, m2x
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
- .requires("m2")
- .contains("p3")
+ .requires("m2x")
+ .packages(Set.of("p3"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
- map.put("m3", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
+ map.put("m3x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1, m2 and m3
+ // Create Layer that contains m1x, m2x and m3x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
- assertTrue(layer.findLoader("m3") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m3x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1 but m2 is not readable from m1)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x but m2x is not readable from m1x)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("cannot access")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java
index b7088553bad..3ffb591ff57 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualOther.java
@@ -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
@@ -25,9 +25,9 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, but package p2 in m2
- * is exported specifically to module m3, then class p1.c1 in m1 can not
- * access p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, but package p2 in m2x
+ * is exported specifically to module m3x, then class p1.c1 in m1x can not
+ * access p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -48,15 +48,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
+// defines m3x --> packages p3
//
-// m1 can read m2
-// package p2 in m2 is exported to m3
+// m1x can read m2x
+// package p2 in m2x is exported to m3x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access denied since although m1 can read m2, p2 is exported only to m3.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access denied since although m1x can read m2x, p2 is exported only to m3x.
//
public class DiffCL_ExpQualOther {
@@ -65,66 +65,66 @@ public class DiffCL_ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2, m3
+ // Define module: m1x
+ // Can read: java.base, m2x, m3x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
- .requires("m3")
+ .requires("m2x")
+ .requires("m3x")
.exports("p1")
.build();
- // Define module: m2
- // Can read: java.base, m3
+ // Define module: m2x
+ // Can read: java.base, m3x
// Packages: p2
- // Packages exported: p2 is exported to m3
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported to m3x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m3"))
+ .exports("p2", Set.of("m3x"))
.build();
- // Define module: m3
- // Can read: java.base, m2
+ // Define module: m3x
+ // Can read: java.base, m2x
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
- .requires("m2")
- .contains("p3")
+ .requires("m2x")
+ .packages(Set.of("p3"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
- map.put("m3", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
+ map.put("m3x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
- assertTrue(layer.findLoader("m3") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m3x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x not to m1x)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java
index 8ca888b312f..1a86434be85 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpQualToM1.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
- * Access allowed since m1 can read m2 and package p2 is exported to m1.
+ * @summary class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
+ * Access allowed since m1x can read m2x and package p2 is exported to m1x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,14 +47,14 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported to m1
+// m1x can read m2x
+// package p2 in m2x is exported to m1x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access allowed since m1 can read m2 and package p2 is exported to m1.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access allowed since m1x can read m2x and package p2 is exported to m1x.
//
public class DiffCL_ExpQualToM1 {
@@ -63,45 +63,45 @@ public class DiffCL_ExpQualToM1 {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported to unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: package p2 is exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: package p2 is exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -109,7 +109,7 @@ public class DiffCL_ExpQualToM1 {
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
+ throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java
index e38d54166ed..cb8c3f2b682 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_ExpUnqual.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, and package p2 in m2 is
- * exported unqualifiedly, then class p1.c1 in m1 can read p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, and package p2 in m2x is
+ * exported unqualifiedly, then class p1.c1 in m1x can read p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,14 +47,14 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported to m1
+// m1x can read m2x
+// package p2 in m2x is exported to m1x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access allowed since m1 can read m2 and package p2 is exported
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access allowed since m1x can read m2x and package p2 is exported
// unqualifiedly.
//
public class DiffCL_ExpUnqual {
@@ -64,45 +64,45 @@ public class DiffCL_ExpUnqual {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: package p2 is exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: package p2 is exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
.exports("p2")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -110,7 +110,7 @@ public class DiffCL_ExpUnqual {
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
+ throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java
index 0cc88f7a69b..5b18038a16d 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_PkgNotExp.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, but package p2 in m2 is not
- * exported, then class p1.c1 in m1 can not read p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, but package p2 in m2x is not
+ * exported, then class p1.c1 in m1x can not read p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,13 +47,13 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is not exported
+// m1x can read m2x
+// package p2 in m2x is not exported
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
// Access denied since p2 is not exported.
//
public class DiffCL_PkgNotExp {
@@ -63,52 +63,52 @@ public class DiffCL_PkgNotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p2")
+ .packages(Set.of("p2"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_Umod.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_Umod.java
index 2a5c723c76f..8b3d098e815 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_Umod.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_Umod.java
@@ -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
@@ -25,7 +25,7 @@
/*
* @test
- * @summary class p1.c1 defined in m1 tries to access p2.c2 defined in unnamed module.
+ * @summary class p1.c1 defined in m1x tries to access p2.c2 defined in unnamed module.
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.module
@@ -50,10 +50,10 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// package p1 in m1 is exported unqualifiedly
+// ClassLoader1 --> defines m1x --> packages p1
+// package p1 in m1x is exported unqualifiedly
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in
+// class p1.c1 defined in m1x tries to access p2.c2 defined in
// in unnamed module.
//
// Three access attempts occur in this test:
@@ -62,7 +62,7 @@ import myloaders.MyDiffClassLoader;
// 2. In this scenario a strict module establishes readability
// to the particular unnamed module it is trying to access.
// Access is allowed.
-// 3. Module m1 in the test_looseModuleLayer() method
+// 3. Module m1x in the test_looseModuleLayer() method
// is transitioned to a loose module, access
// to all unnamed modules is allowed.
//
@@ -71,41 +71,41 @@ public class DiffCL_Umod {
// Create Layers over the boot layer to test different
// accessing scenarios of a named module to an unnamed module.
- // Module m1 is a strict module and has not established
+ // Module m1x is a strict module and has not established
// readability to an unnamed module that p2.c2 is defined in.
public void test_strictModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader2
// to achieve differing class loaders.
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
+ map.put("m1x", MyDiffClassLoader.loader1);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -114,109 +114,109 @@ public class DiffCL_Umod {
// Attempt access
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Test Failed, strict module m1 should not be able " +
+ throw new RuntimeException("Test Failed, strict module m1x should not be able " +
"to access public type p2.c2 defined in unnamed module");
} catch (IllegalAccessError e) {
}
}
- // Module m1 is a strict module and has established
+ // Module m1x is a strict module and has established
// readability to an unnamed module that p2.c2 is defined in.
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader2
// to achieve differing class loaders.
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
+ map.put("m1x", MyDiffClassLoader.loader1);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1ReadEdgeDiffLoader
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1ReadEdgeDiffLoader");
try {
- // Read edge between m1 and the unnamed module that loads p2.c2 is established in
+ // Read edge between m1x and the unnamed module that loads p2.c2 is established in
// c1ReadEdgeDiffLoader's ctor before attempting access.
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, module m1 has established readability to p2/c2 loader's " +
+ throw new RuntimeException("Test Failed, module m1x has established readability to p2/c2 loader's " +
"unnamed module, access should be allowed: " + e.getMessage());
}
}
- // Module m1 is a loose module and thus can read all unnamed modules.
+ // Module m1x is a loose module and thus can read all unnamed modules.
public void test_looseModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader2
// to achieve differing class loaders.
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
+ map.put("m1x", MyDiffClassLoader.loader1);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1Loose
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1Loose");
- // change m1 to read all unnamed modules
- Module m1 = layer.findModule("m1").get();
- jdk.internal.module.Modules.addReadsAllUnnamed(m1);
+ // change m1x to read all unnamed modules
+ Module m1x = layer.findModule("m1x").get();
+ jdk.internal.module.Modules.addReadsAllUnnamed(m1x);
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, loose module m1 should be able to access " +
+ throw new RuntimeException("Test Failed, loose module m1x should be able to access " +
"public type p2.c2 defined in unnamed module: " + e.getMessage());
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java b/hotspot/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java
index b8420c2e5c6..8b3c600ca0a 100644
--- a/hotspot/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java
+++ b/hotspot/test/runtime/modules/AccessCheck/DiffCL_UmodUpkg.java
@@ -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
@@ -25,7 +25,7 @@
/*
* @test
- * @summary class p3.c3 defined in module m1 tries to access c4 defined in an unnamed package
+ * @summary class p3.c3 defined in module m1x tries to access c4 defined in an unnamed package
* and an unnamed module.
* @modules java.base/jdk.internal.misc
* @library /test/lib
@@ -48,10 +48,10 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p3
-// package p3 in m1 is exported unqualifiedly
+// ClassLoader1 --> defines m1x --> packages p3
+// package p3 in m1x is exported unqualifiedly
//
-// class p3.c3 defined in m1 tries to access c4 defined in
+// class p3.c3 defined in m1x tries to access c4 defined in
// in unnamed module.
//
// Two access attempts occur in this test:
@@ -66,41 +66,41 @@ public class DiffCL_UmodUpkg {
// Create Layers over the boot layer to test different
// accessing scenarios of a named module to an unnamed module.
- // Module m1 is a strict module and has not established
+ // Module m1x is a strict module and has not established
// readability to an unnamed module that c4 is defined in.
public void test_strictModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p3
// Packages exported: p3 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p3")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader2
// to achieve differing class loaders.
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
+ map.put("m1x", MyDiffClassLoader.loader1);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p3.c3
@@ -109,58 +109,58 @@ public class DiffCL_UmodUpkg {
// Attempt access
try {
p3_c3_class.newInstance();
- throw new RuntimeException("Test Failed, strict module m1 should not be able to access " +
+ throw new RuntimeException("Test Failed, strict module m1x should not be able to access " +
"public type c4 defined in unnamed module");
} catch (IllegalAccessError e) {
}
}
- // Module m1 is a strict module and has established
+ // Module m1x is a strict module and has established
// readability to an unnamed module that c4 is defined in.
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p3
// Packages exported: p3 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p3")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader2
// to achieve differing class loaders.
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
+ map.put("m1x", MyDiffClassLoader.loader1);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p3.c3ReadEdgeDiffLoader
Class p3_c3_class = MyDiffClassLoader.loader1.loadClass("p3.c3ReadEdgeDiffLoader");
try {
- // Read edge between m1 and the unnamed module that loads c4 is established in
+ // Read edge between m1x and the unnamed module that loads c4 is established in
// C3ReadEdgeDiffLoader's ctor before attempting access.
p3_c3_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, module m1 has established readability to " +
+ throw new RuntimeException("Test Failed, module m1x has established readability to " +
"c4 loader's unnamed module, access should be allowed: " + e.getMessage());
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/ExpQualOther.java
index 330d7239f3a..14da2aac213 100644
--- a/hotspot/test/runtime/modules/AccessCheck/ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/ExpQualOther.java
@@ -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
@@ -25,9 +25,9 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, but package p2 in m2
- * is exported specifically to module m3, then class p1.c1 in m1 can not
- * access p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, but package p2 in m2x
+ * is exported specifically to module m3x, then class p1.c1 in m1x can not
+ * access p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -48,15 +48,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// defines m2 --> packages p2
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> packages p1
+// defines m2x --> packages p2
+// defines m3x --> packages p3
//
-// m1 can read m2
-// package p2 in m2 is exported to m3
+// m1x can read m2x
+// package p2 in m2x is exported to m3x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access denied since although m1 can read m2, p2 is exported only to m3.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access denied since although m1x can read m2x, p2 is exported only to m3x.
//
public class ExpQualOther {
@@ -65,66 +65,66 @@ public class ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2, m3
+ // Define module: m1x
+ // Can read: java.base, m2x, m3x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
- .requires("m3")
+ .requires("m2x")
+ .requires("m3x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: p2 is exported to m3
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported to m3x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m3"))
+ .exports("p2", Set.of("m3x"))
.build();
- // Define module: m3
- // Can read: java.base, m2
+ // Define module: m3x
+ // Can read: java.base, m2x
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
- .requires("m2")
- .contains("p3")
+ .requires("m2x")
+ .packages(Set.of("p3"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
- map.put("m3", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
+ map.put("m3x", MySameClassLoader.loader1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x not to m1x)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/ExpQualToM1.java b/hotspot/test/runtime/modules/AccessCheck/ExpQualToM1.java
index 31de4576d90..ede47809f7a 100644
--- a/hotspot/test/runtime/modules/AccessCheck/ExpQualToM1.java
+++ b/hotspot/test/runtime/modules/AccessCheck/ExpQualToM1.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, AND package p2 in m2 is
- * exported qualifiedly to m1, then class p1.c1 in m1 can read p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, AND package p2 in m2x is
+ * exported qualifiedly to m1x, then class p1.c1 in m1x can read p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -53,52 +53,52 @@ public class ExpQualToM1 {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: p2 is exported qualifiedly to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported qualifiedly to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
+ throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/ExpUnqual.java b/hotspot/test/runtime/modules/AccessCheck/ExpUnqual.java
index 03a377027de..0ded845e90d 100644
--- a/hotspot/test/runtime/modules/AccessCheck/ExpUnqual.java
+++ b/hotspot/test/runtime/modules/AccessCheck/ExpUnqual.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, AND package p2 in module2 is
- * exported unqualifiedly, then class p1.c1 in m1 can read p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, AND package p2 in module_two is
+ * exported unqualifiedly, then class p1.c1 in m1x can read p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -53,45 +53,45 @@ public class ExpUnqual {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: p2 is exported unqualifiedly
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
.exports("p2")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
diff --git a/hotspot/test/runtime/modules/AccessCheck/ExportAllUnnamed.java b/hotspot/test/runtime/modules/AccessCheck/ExportAllUnnamed.java
index c9a89c8ba9f..35857f695cc 100644
--- a/hotspot/test/runtime/modules/AccessCheck/ExportAllUnnamed.java
+++ b/hotspot/test/runtime/modules/AccessCheck/ExportAllUnnamed.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test if package p2 in module m2 is exported to all unnamed,
- * then class p1.c1 in an unnamed module can read p2.c2 in module m2.
+ * @summary Test if package p2 in module m2x is exported to all unnamed,
+ * then class p1.c1 in an unnamed module can read p2.c2 in module m2x.
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.module
@@ -49,15 +49,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported unqualifiedly
+// m1x can read m2x
+// package p2 in m2x is exported unqualifiedly
//
-// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
// Access allowed, an unnamed module can read all modules and p2 in module
-// m2 is exported to all unnamed modules.
+// m2x is exported to all unnamed modules.
public class ExportAllUnnamed {
@@ -66,51 +66,51 @@ public class ExportAllUnnamed {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: p2 is exported unqualifiedly
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
Class p2_c2_class = MySameClassLoader.loader1.loadClass("p2.c2");
- Module m2 = p2_c2_class.getModule();
+ Module m2x = p2_c2_class.getModule();
- // Export m2/p2 to all unnamed modules.
- jdk.internal.module.Modules.addExportsToAllUnnamed(m2, "p2");
+ // Export m2x/p2 to all unnamed modules.
+ jdk.internal.module.Modules.addExportsToAllUnnamed(m2x, "p2");
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
diff --git a/hotspot/test/runtime/modules/AccessCheck/PkgNotExp.java b/hotspot/test/runtime/modules/AccessCheck/PkgNotExp.java
index 4f592a19002..990d08cc8b8 100644
--- a/hotspot/test/runtime/modules/AccessCheck/PkgNotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/PkgNotExp.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if module m1 can read module m2, but package p2 in m2 is not
- * exported, then class p1.c1 in m1 can not read p2.c2 in m2.
+ * @summary Test that if module m1x can read module m2x, but package p2 in m2x is not
+ * exported, then class p1.c1 in m1x can not read p2.c2 in m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -47,13 +47,13 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> packages p1
+// defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is not exported
+// m1x can read m2x
+// package p2 in m2x is not exported
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
// Access denied since p2 is not exported.
//
public class PkgNotExp {
@@ -63,51 +63,51 @@ public class PkgNotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p2")
+ .packages(Set.of("p2"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 and m2
+ // Create Layer that contains m1x and m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/Umod.java b/hotspot/test/runtime/modules/AccessCheck/Umod.java
index 255950c7f37..edce6ac4a3f 100644
--- a/hotspot/test/runtime/modules/AccessCheck/Umod.java
+++ b/hotspot/test/runtime/modules/AccessCheck/Umod.java
@@ -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
@@ -25,7 +25,7 @@
/*
* @test
- * @summary class p1.c1 defined in m1 tries to access p2.c2 defined in unnamed module.
+ * @summary class p1.c1 defined in m1x tries to access p2.c2 defined in unnamed module.
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.module
@@ -50,10 +50,10 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// package p1 in m1 is exported unqualifiedly
+// ClassLoader1 --> defines m1x --> packages p1
+// package p1 in m1x is exported unqualifiedly
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in
+// class p1.c1 defined in m1x tries to access p2.c2 defined in
// in unnamed module.
//
// Three access attempts occur in this test:
@@ -62,7 +62,7 @@ import myloaders.MySameClassLoader;
// 2. In this scenario a strict module establishes readability
// to the particular unnamed module it is trying to access.
// Access is allowed.
-// 3. Module m1 in the test_looseModuleLayer() method
+// 3. Module m1x in the test_looseModuleLayer() method
// is transitioned to a loose module, access
// to all unnamed modules is allowed.
//
@@ -71,38 +71,38 @@ public class Umod {
// Create Layers over the boot layer to test different
// accessing scenarios of a named module to an unnamed module.
- // Module m1 is a strict module and has not established
+ // Module m1x is a strict module and has not established
// readability to an unnamed module that p2.c2 is defined in.
public void test_strictModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader.
MySameClassLoader loader = new MySameClassLoader();
Map map = new HashMap<>();
- map.put("m1", loader);
+ map.put("m1x", loader);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m1x") == loader);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -111,103 +111,103 @@ public class Umod {
// Attempt access
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Test Failed, strict module m1, type p1.c1, should not be able " +
+ throw new RuntimeException("Test Failed, strict module m1x, type p1.c1, should not be able " +
"to access public type p2.c2 defined in unnamed module");
} catch (IllegalAccessError e) {
}
}
- // Module m1 is a strict module and has established
+ // Module m1x is a strict module and has established
// readability to an unnamed module that p2.c2 is defined in.
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MySameClassLoader loader = new MySameClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader.
Map map = new HashMap<>();
- map.put("m1", loader);
+ map.put("m1x", loader);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m1x") == loader);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1ReadEdge
Class p1_c1_class = loader.loadClass("p1.c1ReadEdge");
try {
- // Read edge between m1 and the unnamed module that loads p2.c2 is established in
+ // Read edge between m1x and the unnamed module that loads p2.c2 is established in
// c1ReadEdge's ctor before attempting access.
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, strict module m1, type p1.c1ReadEdge, should be able to acccess public type " +
+ throw new RuntimeException("Test Failed, strict module m1x, type p1.c1ReadEdge, should be able to acccess public type " +
"p2.c2 defined in unnamed module: " + e.getMessage());
}
}
- // Module m1 is a loose module and thus can read all unnamed modules.
+ // Module m1x is a loose module and thus can read all unnamed modules.
public void test_looseModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p1
// Packages exported: p1 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p1")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MySameClassLoader loader = new MySameClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c2 will be loaded in an unnamed module/loader.
Map map = new HashMap<>();
- map.put("m1", loader);
+ map.put("m1x", loader);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m1x") == loader);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1Loose
Class p1_c1_class = loader.loadClass("p1.c1Loose");
- // change m1 to read all unnamed modules
- Module m1 = layer.findModule("m1").get();
- jdk.internal.module.Modules.addReadsAllUnnamed(m1);
+ // change m1x to read all unnamed modules
+ Module m1x = layer.findModule("m1x").get();
+ jdk.internal.module.Modules.addReadsAllUnnamed(m1x);
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, strict module m1, type p1.c1Loose, should be able to acccess public type " +
+ throw new RuntimeException("Test Failed, strict module m1x, type p1.c1Loose, should be able to acccess public type " +
"p2.c2 defined in unnamed module: " + e.getMessage());
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java
index 5fcc629096c..ecdda73f41c 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpQualOther.java
@@ -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
@@ -25,9 +25,9 @@
/*
* @test
- * @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2.
+ * @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x.
* Access is denied, since an unnamed module can read all modules but p2 in module
- * m2 is exported specifically to module m1, not to all modules.
+ * m2x is exported specifically to module m1x, not to all modules.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -48,15 +48,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is not exported
+// m1x can read m2x
+// package p2 in m2x is not exported
//
-// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
// Access denied, an unnamed module can read all modules but p2 in module
-// m2 is exported specifically to module m1 not to all modules.
+// m2x is exported specifically to module m1x not to all modules.
//
public class UmodDiffCL_ExpQualOther {
@@ -65,53 +65,53 @@ public class UmodDiffCL_ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
- // NOTE: module m1 does not define a package named p1.
+ // NOTE: module m1x does not define a package named p1.
// p1 will be loaded in an unnamed module.
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1, not unqualifiedly");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x, not unqualifiedly");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java
index ade483acd46..c05fccc1a1c 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_ExpUnqual.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2.
- * Access allowed, an unnamed module can read all modules and p2 in module m2
+ * @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x.
+ * Access allowed, an unnamed module can read all modules and p2 in module m2x
* which is exported unqualifiedly.
* @modules java.base/jdk.internal.misc
* @library /test/lib
@@ -48,15 +48,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported unqualifiedly.
+// m1x can read m2x
+// package p2 in m2x is exported unqualifiedly.
//
-// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
// Access allowed, an unnamed module can read all modules and p2 in module
-// m2 which is exported unqualifiedly.
+// m2x which is exported unqualifiedly.
//
public class UmodDiffCL_ExpUnqual {
@@ -65,53 +65,53 @@ public class UmodDiffCL_ExpUnqual {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
.exports("p2")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
- // NOTE: module m1 does not define a package named p1.
+ // NOTE: module m1x does not define a package named p1.
// p1 will be loaded in an unnamed module.
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, p1.c1 defined in unnamed module can access p2.c2 in module m2");
+ throw new RuntimeException("Test Failed, p1.c1 defined in unnamed module can access p2.c2 in module m2x");
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java
index b5ec6c6a6b0..67732ac89bc 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodDiffCL_PkgNotExp.java
@@ -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
@@ -25,9 +25,9 @@
/*
* @test
- * @summary class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2.
+ * @summary class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2x.
* Access is denied since even though unnamed module can read all modules, p2
- * in module m2 is not exported at all.
+ * in module m2x is not exported at all.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// ClassLoader2 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// ClassLoader2 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is not exported
+// m1x can read m2x
+// package p2 in m2x is not exported
//
-// class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2x
// Access denied since even though unnamed module can read all modules, p2
-// in module m2 is not exported at all.
+// in module m2x is not exported at all.
//
public class UmodDiffCL_PkgNotExp {
@@ -64,53 +64,53 @@ public class UmodDiffCL_PkgNotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p2")
+ .packages(Set.of("p2"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
- // NOTE: module m1 does not define a package named p1.
+ // NOTE: module m1x does not define a package named p1.
// p1 will be loaded in an unnamed module.
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to an unnamed module)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported to an unnamed module)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodUPkg.java b/hotspot/test/runtime/modules/AccessCheck/UmodUPkg.java
index 7cfcdabe42b..fed0ad4382c 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodUPkg.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodUPkg.java
@@ -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
@@ -25,7 +25,7 @@
/*
* @test
- * @summary class p3.c3 defined in module m1 tries to access c4 defined in unnamed module.
+ * @summary class p3.c3 defined in module m1x tries to access c4 defined in unnamed module.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -48,10 +48,10 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> packages p3
-// package p3 in m1 is exported unqualifiedly
+// ClassLoader1 --> defines m1x --> packages p3
+// package p3 in m1x is exported unqualifiedly
//
-// class p3.c3 defined in m1 tries to access c4 defined in
+// class p3.c3 defined in m1x tries to access c4 defined in
// in unnamed module.
//
// Two access attempts occur in this test:
@@ -66,38 +66,38 @@ public class UmodUPkg {
// Create Layers over the boot layer to test different
// accessing scenarios of a named module to an unnamed module.
- // Module m1 is a strict module and has not established
+ // Module m1x is a strict module and has not established
// readability to an unnamed module that c4 is defined in.
public void test_strictModuleLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p3
// Packages exported: p3 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p3")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c4 will be loaded in an unnamed module/loader.
MySameClassLoader loader = new MySameClassLoader();
Map map = new HashMap<>();
- map.put("m1", loader);
+ map.put("m1x", loader);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m1x") == loader);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p3.c3
@@ -106,55 +106,55 @@ public class UmodUPkg {
// Attempt access
try {
p3_c3_class.newInstance();
- throw new RuntimeException("Test Failed, strict module m1, type p3.c3, should not be able to access " +
+ throw new RuntimeException("Test Failed, strict module m1x, type p3.c3, should not be able to access " +
"public type c4 defined in unnamed module");
} catch (IllegalAccessError e) {
}
}
- // Module m1 is a strict module and has established
+ // Module m1x is a strict module and has established
// readability to an unnamed module that c4 is defined in.
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
- // Define module: m1
+ // Define module: m1x
// Can read: java.base
// Packages: p3
// Packages exported: p3 is exported unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
.exports("p3")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
MySameClassLoader loader = new MySameClassLoader();
- // map module m1 to class loader.
+ // map module m1x to class loader.
// class c4 will be loaded in an unnamed module/loader.
Map map = new HashMap<>();
- map.put("m1", loader);
+ map.put("m1x", loader);
- // Create Layer that contains m1
+ // Create Layer that contains m1x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == loader);
+ assertTrue(layer.findLoader("m1x") == loader);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p3.c3ReadEdge
Class p3_c3_class = loader.loadClass("p3.c3ReadEdge");
try {
- // Read edge between m1 and the unnamed module that loads c4 is established in
+ // Read edge between m1x and the unnamed module that loads c4 is established in
// c3ReadEdge's ctor before attempting access.
p3_c3_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, module m1, type p3.c3ReadEdge, has established readability to " +
+ throw new RuntimeException("Test Failed, module m1x, type p3.c3ReadEdge, has established readability to " +
"c4 loader's unnamed module, access should be allowed: " + e.getMessage());
}
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java
index 01ec39aa1a5..b8c48da4b4a 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_ExpQualOther.java
@@ -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
@@ -25,9 +25,9 @@
/*
* @test
- * @summary class c5 defined in an unnamed module tries to access p6.c6 defined in m2.
+ * @summary class c5 defined in an unnamed module tries to access p6.c6 defined in m2x.
* Access is denied, since an unnamed module can read all modules but p6 in module
- * m2 is exported specifically to module m1, not to all modules.
+ * m2x is exported specifically to module m1x, not to all modules.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -48,15 +48,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// ClassLoader2 --> defines m2 --> packages p6
+// ClassLoader1 --> defines m1x --> no packages
+// ClassLoader2 --> defines m2x --> packages p6
//
-// m1 can read m2
-// package p6 in m2 is not exported
+// m1x can read m2x
+// package p6 in m2x is not exported
//
-// class c5 defined in an unnamed module tries to access p6.c6 defined in m2
+// class c5 defined in an unnamed module tries to access p6.c6 defined in m2x
// Access denied, an unnamed module can read all modules but p6 in module
-// m2 is exported specifically to module m1 not to all modules.
+// m2x is exported specifically to module m1x not to all modules.
//
public class UmodUpkgDiffCL_ExpQualOther {
@@ -65,51 +65,51 @@ public class UmodUpkgDiffCL_ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p6
- // Packages exported: p6 exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p6 exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p6", Set.of("m1"))
+ .exports("p6", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class c5
Class c5_class = MyDiffClassLoader.loader1.loadClass("c5");
try {
c5_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m1, not unqualifiedly");
+ throw new RuntimeException("Failed to get IAE (p6 in m2x is exported to m1x, not unqualifiedly");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java b/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java
index 68dd3778b5c..134a9d64e91 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_NotExp.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary class c5 in an unnamed module can read module m2, but package p6 in module m2 is not exported.
- * Access denied since even though unnamed module can read all modules, p6 in module m2 is not exported at all.
+ * @summary class c5 in an unnamed module can read module m2x, but package p6 in module m2x is not exported.
+ * Access denied since even though unnamed module can read all modules, p6 in module m2x is not exported at all.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MyDiffClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MyDiffClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// ClassLoader2 --> defines m2 --> packages p6
+// ClassLoader1 --> defines m1x --> no packages
+// ClassLoader2 --> defines m2x --> packages p6
//
-// m1 can read m2
-// package p6 in m2 is not exported
+// m1x can read m2x
+// package p6 in m2x is not exported
//
-// class c5 defined in unnamed module tries to access p6.c6 defined in m2
+// class c5 defined in unnamed module tries to access p6.c6 defined in m2x
// Access denied since even though unnamed module can read all modules, p6
-// in module m2 is not exported at all.
+// in module m2x is not exported at all.
//
public class UmodUpkgDiffCL_NotExp {
@@ -64,53 +64,53 @@ public class UmodUpkgDiffCL_NotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p6
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p6")
+ .packages(Set.of("p6"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MyDiffClassLoader.loader1);
- map.put("m2", MyDiffClassLoader.loader2);
+ map.put("m1x", MyDiffClassLoader.loader1);
+ map.put("m2x", MyDiffClassLoader.loader2);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
+ assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class c5
- // NOTE: module m1 does not define any packages.
+ // NOTE: module m1x does not define any packages.
// c5 will be loaded in an unnamed module.
Class c5_class = MyDiffClassLoader.loader1.loadClass("c5");
try {
c5_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p6 in m2 is not exported to " +
+ throw new RuntimeException("Failed to get IAE (p6 in m2x is not exported to " +
"an unnamed module that c5 is defined within)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java
index 68abe56b7a1..c6f2dd8be4a 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_ExpQualOther.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if class c5 in an unnamed module can read package p6 in module m2, but package p6 in module m2 is
- * exported qualifiedly to module m3, then class c5 in an unnamed module can not read p6.c6 in module m2.
+ * @summary Test that if class c5 in an unnamed module can read package p6 in module m2x, but package p6 in module m2x is
+ * exported qualifiedly to module m3x, then class c5 in an unnamed module can not read p6.c6 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p6
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p6
+// defines m3x --> packages p3
//
-// m1 can read m2
-// package p6 in m2 is exported to m3
+// m1x can read m2x
+// package p6 in m2x is exported to m3x
//
-// class c5 defined in m1 tries to access p6.c6 defined in m2
-// Access denied since although m1 can read m2, p6 is exported only to m3.
+// class c5 defined in m1x tries to access p6.c6 defined in m2x
+// Access denied since although m1x can read m2x, p6 is exported only to m3x.
//
public class UmodUpkg_ExpQualOther {
@@ -64,63 +64,63 @@ public class UmodUpkg_ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1 (need to define m1 to establish the Layer successfully)
- // Can read: java.base, m2, m3
+ // Define module: m1x (need to define m1x to establish the Layer successfully)
+ // Can read: java.base, m2x, m3x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
- .requires("m3")
+ .requires("m2x")
+ .requires("m3x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p6
- // Packages exported: p6 is exported to m3
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p6 is exported to m3x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p6", Set.of("m3"))
+ .exports("p6", Set.of("m3x"))
.build();
- // Define module: m3
+ // Define module: m3x
// Can read: java.base
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
- map.put("m3", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
+ map.put("m3x", MySameClassLoader.loader1);
- // Create Layer that contains m1, m2 and m3
+ // Create Layer that contains m1x, m2x and m3x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class c5
Class c5_class = MySameClassLoader.loader1.loadClass("c5");
try {
c5_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m3, not unqualifiedly to everyone)");
+ throw new RuntimeException("Failed to get IAE (p6 in m2x is exported to m3x, not unqualifiedly to everyone)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java b/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java
index da69805e580..69a768a8a07 100644
--- a/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/UmodUpkg_NotExp.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test if package p6 in module m2 is not exported, then class c5
- * in an unnamed module can not access p6.c2 in module m2.
+ * @summary Test if package p6 in module m2x is not exported, then class c5
+ * in an unnamed module can not access p6.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -46,13 +46,13 @@ import java.util.Map;
import java.util.Set;
import myloaders.MySameClassLoader;
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p6
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p6
//
-// m1 can read m2
-// package p6 in m2 is not exported
+// m1x can read m2x
+// package p6 in m2x is not exported
//
-// class c5 defined in an unnamed module tries to access p6.c2 defined in m2
+// class c5 defined in an unnamed module tries to access p6.c2 defined in m2x
// Access denied since p6 is not exported.
//
public class UmodUpkg_NotExp {
@@ -62,51 +62,51 @@ public class UmodUpkg_NotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p6
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p6")
+ .packages(Set.of("p6"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 and m2
+ // Create Layer that contains m1x and m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class c5
Class c5_class = MySameClassLoader.loader1.loadClass("c5");
try {
c5_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p6 in m2 is not exported)");
+ throw new RuntimeException("Failed to get IAE (p6 in m2x is not exported)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java b/hotspot/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java
index 0f5aaf21585..4ca29861c69 100644
--- a/hotspot/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java
+++ b/hotspot/test/runtime/modules/AccessCheck/Umod_ExpQualOther.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test that if package p2 in module m2 is exported to module m3,
- * then class p1.c1 in an unnamed module can not read p2.c2 in module m2.
+ * @summary Test that if package p2 in module m2x is exported to module m3x,
+ * then class p1.c1 in an unnamed module can not read p2.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p2
-// defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p2
+// defines m3x --> packages p3
//
-// m1 can read m2
-// package p2 in m2 is exported to m3
+// m1x can read m2x
+// package p2 in m2x is exported to m3x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access denied since although m1 can read m2, p2 is exported only to m3.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access denied since although m1x can read m2x, p2 is exported only to m3x.
//
public class Umod_ExpQualOther {
@@ -64,63 +64,63 @@ public class Umod_ExpQualOther {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1 (need to define m1 to establish the Layer successfully)
- // Can read: java.base, m2, m3
+ // Define module: m1x (need to define m1x to establish the Layer successfully)
+ // Can read: java.base, m2x, m3x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
- .requires("m3")
+ .requires("m2x")
+ .requires("m3x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: p2 is exported to m3
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: p2 is exported to m3x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m3"))
+ .exports("p2", Set.of("m3x"))
.build();
- // Define module: m3
+ // Define module: m3x
// Can read: java.base
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
- map.put("m3", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
+ map.put("m3x", MySameClassLoader.loader1);
- // Create Layer that contains m1, m2 and m3
+ // Create Layer that contains m1x, m2x and m3x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3, not unqualifiedly to everyone)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x, not unqualifiedly to everyone)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java b/hotspot/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java
index db90a08bd44..4430341308f 100644
--- a/hotspot/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java
+++ b/hotspot/test/runtime/modules/AccessCheck/Umod_ExpUnqual.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test if package p2 in module m2 is exported unqualifiedly,
- * then class p1.c1 in an unnamed module can read p2.c2 in module m2.
+ * @summary Test if package p2 in module m2x is exported unqualifiedly,
+ * then class p1.c1 in an unnamed module can read p2.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -47,15 +47,15 @@ import java.util.Set;
import myloaders.MySameClassLoader;
//
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported unqualifiedly
+// m1x can read m2x
+// package p2 in m2x is exported unqualifiedly
//
-// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
// Access allowed, an unnamed module can read all modules and p2 in module
-// m2 which is exported unqualifiedly.
+// m2x which is exported unqualifiedly.
public class Umod_ExpUnqual {
@@ -64,44 +64,44 @@ public class Umod_ExpUnqual {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: p2 is exported unqualifiedly
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
.exports("p2")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing class loaders for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
diff --git a/hotspot/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java b/hotspot/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java
index d140cf84d69..4990a379bb4 100644
--- a/hotspot/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java
+++ b/hotspot/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java
@@ -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
@@ -25,8 +25,8 @@
/*
* @test
- * @summary Test if package p2 in module m2 is not exported, then class p1.c1
- * in an unnamed module can not access p2.c2 in module m2.
+ * @summary Test if package p2 in module m2x is not exported, then class p1.c1
+ * in an unnamed module can not access p2.c2 in module m2x.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @compile myloaders/MySameClassLoader.java
@@ -46,13 +46,13 @@ import java.util.Map;
import java.util.Set;
import myloaders.MySameClassLoader;
-// ClassLoader1 --> defines m1 --> no packages
-// defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> no packages
+// defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is not exported
+// m1x can read m2x
+// package p2 in m2x is not exported
//
-// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
+// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
// Access denied since p2 is not exported.
//
public class Umod_PkgNotExp {
@@ -62,51 +62,51 @@ public class Umod_PkgNotExp {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: none
// Packages exported: none
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
// Packages exported: none
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .contains("p2")
+ .packages(Set.of("p2"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
- map.put("m1", MySameClassLoader.loader1);
- map.put("m2", MySameClassLoader.loader1);
+ map.put("m1x", MySameClassLoader.loader1);
+ map.put("m2x", MySameClassLoader.loader1);
- // Create Layer that contains m1 and m2
+ // Create Layer that contains m1x and m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
- assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
+ assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheck/p1/c1Loose.java b/hotspot/test/runtime/modules/AccessCheck/p1/c1Loose.java
index 3722927e1b4..ab03e5de9c0 100644
--- a/hotspot/test/runtime/modules/AccessCheck/p1/c1Loose.java
+++ b/hotspot/test/runtime/modules/AccessCheck/p1/c1Loose.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -26,7 +26,7 @@ import p2.c2;
public class c1Loose {
public c1Loose() {
- // Attempt access - access should succeed since m1 is a loose module
+ // Attempt access - access should succeed since m1x is a loose module
p2.c2 c2_obj = new p2.c2();
c2_obj.method2();
}
diff --git a/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdge.java b/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdge.java
index 55d4a8b7d13..fdceb569684 100644
--- a/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdge.java
+++ b/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdge.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -27,12 +27,12 @@ import p2.c2;
public class c1ReadEdge {
public c1ReadEdge() {
- // Establish read edge from module m1, where c1ReadEdge is defined,
+ // Establish read edge from module m1x, where c1ReadEdge is defined,
// to the unnamed module, where p2.c2 will be defined.
- Module m1 = c1ReadEdge.class.getModule();
+ Module m1x = c1ReadEdge.class.getModule();
ClassLoader loader = c1ReadEdge.class.getClassLoader();
Module unnamed_module = loader.getUnnamedModule();
- m1.addReads(unnamed_module);
+ m1x.addReads(unnamed_module);
// Attempt access - access should succeed
p2.c2 c2_obj = new p2.c2();
diff --git a/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdgeDiffLoader.java b/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdgeDiffLoader.java
index daaee5843c8..03c444172b6 100644
--- a/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdgeDiffLoader.java
+++ b/hotspot/test/runtime/modules/AccessCheck/p1/c1ReadEdgeDiffLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -28,32 +28,32 @@ import p2.c2;
public class c1ReadEdgeDiffLoader {
public c1ReadEdgeDiffLoader() {
- // The goal is to establish a read edge between module m1
+ // The goal is to establish a read edge between module m1x
// which is the module where p1.c1ReadEdgeDiffLoader is defined,
// and the unnamed module that defines p2.c2. This must be
// done in 2 steps:
//
- // Step #1: Establish a read edge between m1, where c1ReadEdgeDiffLoader
+ // Step #1: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
// is defined, and the System ClassLoader's unnamed module,
// where MyDiffClassLoader is defined. This read edge
// is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
//
- // Step #2: Establish a read edge between m1, where c1ReadEdgeDiffLoader
+ // Step #2: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
// is defined, and the MyDiffClassLoader.loader2's unnamed module,
// where p2.c2 will be defined.
- // Step #1: read edge m1 -> System ClassLoader's unnamed module
- Module m1 = c1ReadEdgeDiffLoader.class.getModule();
+ // Step #1: read edge m1x -> System ClassLoader's unnamed module
+ Module m1x = c1ReadEdgeDiffLoader.class.getModule();
ClassLoader system_loader = ClassLoader.getSystemClassLoader();
- Module unnamed_module1 = system_loader.getUnnamedModule();
- m1.addReads(unnamed_module1);
+ Module unnamed_module_one = system_loader.getUnnamedModule();
+ m1x.addReads(unnamed_module_one);
- // Step #2: read edge m1 -> MyDiffClassLoader.loader2's unnamed module
+ // Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
ClassLoader loader2 = MyDiffClassLoader.loader2;
- Module unnamed_module2 = loader2.getUnnamedModule();
- m1.addReads(unnamed_module2);
+ Module unnamed_module_two = loader2.getUnnamedModule();
+ m1x.addReads(unnamed_module_two);
- // Attempt access - access should succeed since m1 can read
+ // Attempt access - access should succeed since m1x can read
// MyDiffClassLoader.loader2's unnamed module
p2.c2 c2_obj = new p2.c2();
c2_obj.method2();
diff --git a/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdge.jcod b/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdge.jcod
index 50df6180233..466d675f220 100644
--- a/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdge.jcod
+++ b/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdge.jcod
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -26,12 +26,12 @@
* import java.lang.reflect.*;
* public class c3ReadEdge {
* public c3ReadEdge() {
- * // Establish read edge from module m1, where c3ReadEdge is defined,
+ * // Establish read edge from module m1x, where c3ReadEdge is defined,
* // to the unnamed module, where c4 will be defined.
- * Module m1 = c3ReadEdge.class.getModule();
+ * Module m1x = c3ReadEdge.class.getModule();
* ClassLoader loader = c3ReadEdge.class.getClassLoader();
* Module unnamed_module = loader.getUnnamedModule();
- * m1.addReads(unnamed_module);
+ * m1x.addReads(unnamed_module);
* // Attempt access - access should succeed
* c4 c4_obj = new c4();
* c4_obj.method4();
diff --git a/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdgeDiffLoader.jcod b/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdgeDiffLoader.jcod
index 103f7eea2c7..3229c7a2054 100644
--- a/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdgeDiffLoader.jcod
+++ b/hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdgeDiffLoader.jcod
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -28,32 +28,32 @@
*
* public class c3ReadEdgeDiffLoader {
* public c3ReadEdgeDiffLoader() {
- * // The goal is to establish a read edge between module m1
+ * // The goal is to establish a read edge between module m1x
* // which is the module where p3.c3ReadEdgeDiffLoader is defined,
* // and the unnamed module that defines c4. This must be
* // done in 2 steps:
* //
- * // Step #1: Establish a read edge between m1, where c3ReadEdgeDiffLoader
+ * // Step #1: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
* // is defined, and the System ClassLoader's unnamed module,
* // where MyDiffClassLoader is defined. This read edge
* // is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
* //
- * // Step #2: Establish a read edge between m1, where c3ReadEdgeDiffLoader
+ * // Step #2: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
* // is defined, and the MyDiffClassLoader.loader2's unnamed module,
* // where c4 will be defined.
*
- * // Step #1: read edge m1 -> System ClassLoader's unnamed module
- * Module m1 = c3ReadEdgeDiffLoader.class.getModule();
+ * // Step #1: read edge m1x -> System ClassLoader's unnamed module
+ * Module m1x = c3ReadEdgeDiffLoader.class.getModule();
* ClassLoader system_loader = ClassLoader.getSystemClassLoader();
- * Module unnamed_module1 = system_loader.getUnnamedModule();
- * m1.addReads(unnamed_module1);
+ * Module unnamed_module_one = system_loader.getUnnamedModule();
+ * m1x.addReads(unnamed_module_one);
*
- * // Step #2: read edge m1 -> MyDiffClassLoader.loader2's unnamed module
+ * // Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
* ClassLoader loader2 = MyDiffClassLoader.loader2;
- * Module unnamed_module2 = loader2.getUnnamedModule();
- * m1.addReads(unnamed_module2);
+ * Module unnamed_module_two = loader2.getUnnamedModule();
+ * m1x.addReads(unnamed_module_two);
*
- * // Attempt access - should succeed since m1 can read
+ * // Attempt access - should succeed since m1x can read
* // MyDiffClassLoader.loader2's unnamed module
* c4 c4_obj = new c4();
* c4_obj.method4();
diff --git a/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java b/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java
index 7872d0d3306..1ce5fdcc4db 100644
--- a/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java
+++ b/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java
@@ -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
@@ -43,7 +43,7 @@ public class AccessCheckAllUnnamed {
// and then test that a class in the unnamed module can access a package in a
// named module that has been exported to all unnamed modules.
public static void main(String args[]) throws Throwable {
- Object m1, m2;
+ Object m1x, m2x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -55,16 +55,16 @@ public class AccessCheckAllUnnamed {
ClassLoader this_cldr = AccessCheckAllUnnamed.class.getClassLoader();
// Define a module for p3.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p3" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/there", new String[] { "p3" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
try {
ModuleHelper.AddModuleExportsToAllUnnamed((Module)null, "p2");
@@ -74,7 +74,7 @@ public class AccessCheckAllUnnamed {
}
try {
- ModuleHelper.AddModuleExportsToAllUnnamed(m2, null);
+ ModuleHelper.AddModuleExportsToAllUnnamed(m2x, null);
throw new RuntimeException("Failed to get the expected NPE for null package");
} catch(NullPointerException e) {
// Expected
@@ -88,21 +88,21 @@ public class AccessCheckAllUnnamed {
}
try {
- ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p3");
+ ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p3");
throw new RuntimeException("Failed to get the expected IAE for package in other module");
} catch(IllegalArgumentException e) {
// Expected
}
try {
- ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p4");
+ ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p4");
throw new RuntimeException("Failed to get the expected IAE for package not in module");
} catch(IllegalArgumentException e) {
// Expected
}
- // Export package p2 in m2 to allUnnamed.
- ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p2");
+ // Export package p2 in m2x to allUnnamed.
+ ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p2");
// p1.c1's ctor tries to call a method in p2.c2. This should succeed because
// p1 is in an unnamed module and p2.c2 is exported to all unnamed modules.
diff --git a/hotspot/test/runtime/modules/AccessCheckExp.java b/hotspot/test/runtime/modules/AccessCheckExp.java
index fa624b0783a..6c3cb07fff8 100644
--- a/hotspot/test/runtime/modules/AccessCheckExp.java
+++ b/hotspot/test/runtime/modules/AccessCheckExp.java
@@ -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
@@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
public class AccessCheckExp {
- // Test that if module1 can read module2, but package p2 in module2 is not
- // exported then class p1.c1 in module1 can not read p2.c2 in module2.
+ // Test that if module_one can read module_two, but package p2 in module_two is not
+ // exported then class p1.c1 in module_one can not read p2.c2 in module_two.
public static void main(String args[]) throws Throwable {
- Object m1, m2;
+ Object m1x, m2x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -54,28 +54,28 @@ public class AccessCheckExp {
ClassLoader this_cldr = AccessCheckExp.class.getClassLoader();
// Define a module for p1.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
- // Make package p1 in m1 visible to everyone.
- ModuleHelper.AddModuleExportsToAll(m1, "p1");
+ // Make package p1 in m1x visible to everyone.
+ ModuleHelper.AddModuleExportsToAll(m1x, "p1");
// p1.c1's ctor tries to call a method in p2.c2, but p2.c2 is not
// exported. So should get IllegalAccessError.
- ModuleHelper.AddReadsModule(m1, m2);
+ ModuleHelper.AddReadsModule(m1x, m2x);
Class p1_c1_class = Class.forName("p1.c1");
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported");
} catch (IllegalAccessError f) {
System.out.println(f.getMessage());
if (!f.getMessage().contains("does not export")) {
diff --git a/hotspot/test/runtime/modules/AccessCheckJavaBase.java b/hotspot/test/runtime/modules/AccessCheckJavaBase.java
index 24f2f77e115..aea13270267 100644
--- a/hotspot/test/runtime/modules/AccessCheckJavaBase.java
+++ b/hotspot/test/runtime/modules/AccessCheckJavaBase.java
@@ -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
@@ -38,16 +38,16 @@ import static jdk.test.lib.Asserts.*;
public class AccessCheckJavaBase {
- // Test that a class defined to module2 always can read java.base.
+ // Test that a class defined to module_two always can read java.base.
public static void main(String args[]) throws Throwable {
// Get the class loader for AccessCheckJavaBase and assume it's also used to
// load class p2.c2.
ClassLoader this_cldr = AccessCheckJavaBase.class.getClassLoader();
// Define a module for p2.
- Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
+ Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
// p2.c2 can read its superclass java.lang.Object defined within java.base
try {
diff --git a/hotspot/test/runtime/modules/AccessCheckRead.java b/hotspot/test/runtime/modules/AccessCheckRead.java
index a36268ace02..193388dbade 100644
--- a/hotspot/test/runtime/modules/AccessCheckRead.java
+++ b/hotspot/test/runtime/modules/AccessCheckRead.java
@@ -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
@@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
public class AccessCheckRead {
- // Test that a class in a package in module1 cannot access a class in
- // a package n module2 if module1 cannot read module2.
+ // Test that a class in a package in module_one cannot access a class in
+ // a package in module_two if module_one cannot read module_two.
public static void main(String args[]) throws Throwable {
- Object m1, m2;
+ Object m1x, m2x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -54,19 +54,19 @@ public class AccessCheckRead {
ClassLoader this_cldr = AccessCheckRead.class.getClassLoader();
// Define a module for p1.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
- // Make package p1 in m1 visible to everyone.
- ModuleHelper.AddModuleExportsToAll(m1, "p1");
+ // Make package p1 in m1x visible to everyone.
+ ModuleHelper.AddModuleExportsToAll(m1x, "p1");
Class p1_c1_class = Class.forName("p1.c1");
@@ -74,7 +74,7 @@ public class AccessCheckRead {
// cannot read p2's module. So should get IllegalAccessError.
try {
p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (m1 can't read m2)");
+ throw new RuntimeException("Failed to get IAE (m1x can't read m2x)");
} catch (IllegalAccessError e) {
System.out.println(e.getMessage());
if (!e.getMessage().contains("does not read") ||
diff --git a/hotspot/test/runtime/modules/AccessCheckSuper.java b/hotspot/test/runtime/modules/AccessCheckSuper.java
index 594c1921e0f..240d79c0ab9 100644
--- a/hotspot/test/runtime/modules/AccessCheckSuper.java
+++ b/hotspot/test/runtime/modules/AccessCheckSuper.java
@@ -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
@@ -48,17 +48,17 @@ public class AccessCheckSuper {
ClassLoader this_cldr = AccessCheckSuper.class.getClassLoader();
// Define a module for p2.
- Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
+ Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
// Define a module for p3.
- Object m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p3" });
- assertNotNull(m3, "Module should not be null");
- ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p3" });
+ Object m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
+ assertNotNull(m3x, "Module should not be null");
+ ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
- // Since a readability edge has not been established between module2
- // and module3, p3.c3 cannot read its superclass p2.c2.
+ // Since a readability edge has not been established between module_two
+ // and module_three, p3.c3 cannot read its superclass p2.c2.
try {
Class p3_c3_class = Class.forName("p3.c3");
throw new RuntimeException("Failed to get IAE (can't read superclass)");
diff --git a/hotspot/test/runtime/modules/AccessCheckUnnamed.java b/hotspot/test/runtime/modules/AccessCheckUnnamed.java
index 4a2ab3e4951..79a685d4c43 100644
--- a/hotspot/test/runtime/modules/AccessCheckUnnamed.java
+++ b/hotspot/test/runtime/modules/AccessCheckUnnamed.java
@@ -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
@@ -42,7 +42,7 @@ public class AccessCheckUnnamed {
// Test that a class in the unnamed module can not access a package in a
// named module that has not been unqualifiedly exported.
public static void main(String args[]) throws Throwable {
- Object m1, m2;
+ Object m1x, m2x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -54,17 +54,17 @@ public class AccessCheckUnnamed {
ClassLoader this_cldr = AccessCheckUnnamed.class.getClassLoader();
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
// p1.c1's ctor tries to call a method in p2.c2. This should fail because
// p1 is in the unnamed module and p2.c2 is not unqualifiedly exported.
Class p1_c1_class = Class.forName("p1.c1");
try {
Object c1_obj = p1_c1_class.newInstance();
- throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to unnamed module)");
+ throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported to unnamed module)");
} catch (IllegalAccessError f) {
System.out.println(f.getMessage());
if (!f.getMessage().contains("does not export p2 to unnamed module")) {
diff --git a/hotspot/test/runtime/modules/AccessCheckWorks.java b/hotspot/test/runtime/modules/AccessCheckWorks.java
index 48d6660f195..0cc9cb981e0 100644
--- a/hotspot/test/runtime/modules/AccessCheckWorks.java
+++ b/hotspot/test/runtime/modules/AccessCheckWorks.java
@@ -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
@@ -39,11 +39,11 @@ import static jdk.test.lib.Asserts.*;
public class AccessCheckWorks {
- // Check that a class in a package in module1 can successfully access a
- // class in module2 when module1 can read module2 and the class's package
+ // Check that a class in a package in module_one can successfully access a
+ // class in module_two when module_one can read module_two and the class's package
// has been exported.
public static void main(String args[]) throws Throwable {
- Object m1, m2;
+ Object m1x, m2x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -55,24 +55,24 @@ public class AccessCheckWorks {
ClassLoader this_cldr = AccessCheckWorks.class.getClassLoader();
// Define a module for p1.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
- // Make package p1 in m1 visible to everyone.
- ModuleHelper.AddModuleExportsToAll(m1, "p1");
+ // Make package p1 in m1x visible to everyone.
+ ModuleHelper.AddModuleExportsToAll(m1x, "p1");
// p1.c1's ctor tries to call a method in p2.c2. This should work because
// p1's module can read p2's module and p2 is exported to p1's module.
- ModuleHelper.AddReadsModule(m1, m2);
- ModuleHelper.AddModuleExports(m2, "p2", m1);
+ ModuleHelper.AddReadsModule(m1x, m2x);
+ ModuleHelper.AddModuleExports(m2x, "p2", m1x);
Class p1_c1_class = Class.forName("p1.c1");
p1_c1_class.newInstance();
}
diff --git a/hotspot/test/runtime/modules/CCE_module_msg.java b/hotspot/test/runtime/modules/CCE_module_msg.java
index 38ff41fde2d..0cca61bef86 100644
--- a/hotspot/test/runtime/modules/CCE_module_msg.java
+++ b/hotspot/test/runtime/modules/CCE_module_msg.java
@@ -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
@@ -83,21 +83,21 @@ public class CCE_module_msg {
ClassLoader this_cldr = CCE_module_msg.class.getClassLoader();
// Define a module for p2.
- Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
try {
- ModuleHelper.AddModuleExportsToAll(m2, "p2");
+ ModuleHelper.AddModuleExportsToAll(m2x, "p2");
Object p2Obj = new p2.c2();
System.out.println((String)p2Obj);
throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
} catch (ClassCastException cce) {
String exception = cce.getMessage();
System.out.println(exception);
- if (exception.contains("module2/p2.c2") ||
- !(exception.contains("module2@") &&
+ if (exception.contains("module_two/p2.c2") ||
+ !(exception.contains("module_two@") &&
exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) {
throw new RuntimeException("Wrong message: " + exception);
}
diff --git a/hotspot/test/runtime/modules/ExportTwice.java b/hotspot/test/runtime/modules/ExportTwice.java
index 538c65926c0..82cefa939e2 100644
--- a/hotspot/test/runtime/modules/ExportTwice.java
+++ b/hotspot/test/runtime/modules/ExportTwice.java
@@ -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
@@ -44,7 +44,7 @@ public class ExportTwice {
// Also, check that a package can be exported to a specific package and then
// exported unqualifiedly.
public static void main(String args[]) throws Throwable {
- Object m1, m2, m3;
+ Object m1x, m2x, m3x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -56,37 +56,37 @@ public class ExportTwice {
ClassLoader this_cldr = ExportTwice.class.getClassLoader();
// Define a module for p1.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
// Define a module for p3.
- m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p3" });
- assertNotNull(m3, "Module should not be null");
- ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p3" });
- ModuleHelper.AddReadsModule(m3, jlObject_jlrM);
+ m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
+ assertNotNull(m3x, "Module should not be null");
+ ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
+ ModuleHelper.AddReadsModule(m3x, jlObject_jlrM);
- // Make package p1 in m1 visible to everyone.
- ModuleHelper.AddModuleExportsToAll(m1, "p1");
+ // Make package p1 in m1x visible to everyone.
+ ModuleHelper.AddModuleExportsToAll(m1x, "p1");
- // Try to export p1 only to m2 after it was exported unqualifiedly. It
+ // Try to export p1 only to m2x after it was exported unqualifiedly. It
// should silently succeed.
- ModuleHelper.AddModuleExports(m1, "p1", m2);
+ ModuleHelper.AddModuleExports(m1x, "p1", m2x);
- // Export p2 to m3 then export it again unqualifiedly.
- ModuleHelper.AddModuleExports(m2, "p2", m3);
- ModuleHelper.AddModuleExportsToAll(m2, "p2");
+ // Export p2 to m3x then export it again unqualifiedly.
+ ModuleHelper.AddModuleExports(m2x, "p2", m3x);
+ ModuleHelper.AddModuleExportsToAll(m2x, "p2");
// p1.c1's ctor tries to call a method in p2.c2. This should work because
// p1's module can read p2's module and p2 is now exported unqualifiedly.
- ModuleHelper.AddReadsModule(m1, m2);
+ ModuleHelper.AddReadsModule(m1x, m2x);
Class p1_c1_class = Class.forName("p1.c1");
p1_c1_class.newInstance();
}
diff --git a/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java b/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java
index e3748530fa7..c00a7104191 100644
--- a/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java
+++ b/hotspot/test/runtime/modules/IgnoreModulePropertiesTest.java
@@ -67,8 +67,8 @@ public class IgnoreModulePropertiesTest {
}
public static void main(String[] args) throws Exception {
- testOption("--add-modules", "java.sqlx", "jdk.module.addmods.0", "java.lang.module.ResolutionException");
- testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.ResolutionException");
+ testOption("--add-modules", "java.sqlx", "jdk.module.addmods.0", "java.lang.module.FindException");
+ testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.FindException");
testOption("--add-reads", "xyzz=yyzd", "jdk.module.addreads.0", "WARNING: Unknown module: xyzz");
testOption("--add-exports", "java.base/xyzz=yyzd", "jdk.module.addexports.0",
"WARNING: package xyzz not in java.base");
diff --git a/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java b/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java
index 7a08787c696..99f47ad4227 100644
--- a/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java
+++ b/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java
@@ -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
@@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
public class JVMAddModuleExportToAllUnnamed {
- // Check that a class in a package in module1 cannot access a class
+ // Check that a class in a package in module_one cannot access a class
// that is in the unnamed module if the accessing package is strict.
public static void main(String args[]) throws Throwable {
- Object m1;
+ Object m1x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -54,13 +54,13 @@ public class JVMAddModuleExportToAllUnnamed {
ClassLoader this_cldr = JVMAddModuleExportToAllUnnamed.class.getClassLoader();
// Define a module for p1.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
- // Make package p1 in m1 visible to everyone.
- ModuleHelper.AddModuleExportsToAll(m1, "p1");
+ // Make package p1 in m1x visible to everyone.
+ ModuleHelper.AddModuleExportsToAll(m1x, "p1");
// p1.c1's ctor tries to call a method in p2.c2. This should not work
// because p2 is in the unnamed module and p1.c1 is strict.
diff --git a/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java b/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java
index 80db658a99d..ec4672327c3 100644
--- a/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java
+++ b/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java
@@ -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
@@ -43,7 +43,7 @@ public class JVMAddModuleExportsToAll {
// and then test that a class in the unnamed module can access a package in
// a named module that has been exported unqualifiedly.
public static void main(String args[]) throws Throwable {
- Object m1, m2, m3;
+ Object m1x, m2x, m3x;
// Get the java.lang.reflect.Module object for module java.base.
Class jlObject = Class.forName("java.lang.Object");
@@ -55,16 +55,16 @@ public class JVMAddModuleExportsToAll {
ClassLoader this_cldr = JVMAddModuleExportsToAll.class.getClassLoader();
// Define a module for p3.
- m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p3" });
- assertNotNull(m1, "Module should not be null");
- ModuleHelper.DefineModule(m1, "9.0", "m1/there", new String[] { "p3" });
- ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
+ m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
+ assertNotNull(m1x, "Module should not be null");
+ ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
+ ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
// Define a module for p2.
- m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
- assertNotNull(m2, "Module should not be null");
- ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
- ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
+ m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
+ assertNotNull(m2x, "Module should not be null");
+ ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+ ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
try {
ModuleHelper.AddModuleExportsToAll((Module)null, "p2");
@@ -74,7 +74,7 @@ public class JVMAddModuleExportsToAll {
}
try {
- ModuleHelper.AddModuleExportsToAll(m2, null);
+ ModuleHelper.AddModuleExportsToAll(m2x, null);
throw new RuntimeException("Failed to get the expected NPE for null package");
} catch(NullPointerException e) {
// Expected
@@ -88,26 +88,26 @@ public class JVMAddModuleExportsToAll {
}
try {
- ModuleHelper.AddModuleExportsToAll(m2, "p3");
+ ModuleHelper.AddModuleExportsToAll(m2x, "p3");
throw new RuntimeException("Failed to get the expected IAE for package that is in another module");
} catch(IllegalArgumentException e) {
// Expected
}
try {
- ModuleHelper.AddModuleExportsToAll(m2, "p4");
+ ModuleHelper.AddModuleExportsToAll(m2x, "p4");
throw new RuntimeException("Failed to get the expected IAE for package not in any module");
} catch(IllegalArgumentException e) {
// Expected
}
- // Export package p2 in m2 unqualifiedly. Then, do a qualified export
- // of p2 in m2 to m3. This should not affect the unqualified export.
- m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p4" });
- assertNotNull(m3, "Module m3 should not be null");
- ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p4" });
- ModuleHelper.AddModuleExportsToAll(m2, "p2");
- ModuleHelper.AddModuleExports(m2, "p2", m3);
+ // Export package p2 in m2x unqualifiedly. Then, do a qualified export
+ // of p2 in m2x to m3x. This should not affect the unqualified export.
+ m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p4" });
+ assertNotNull(m3x, "Module m3x should not be null");
+ ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p4" });
+ ModuleHelper.AddModuleExportsToAll(m2x, "p2");
+ ModuleHelper.AddModuleExports(m2x, "p2", m3x);
// p1.c1's ctor tries to call a method in p2.c2. This should succeed because
// p1 is in an unnamed module and p2.c2 is exported unqualifiedly.
diff --git a/hotspot/test/runtime/modules/JVMAddModulePackage.java b/hotspot/test/runtime/modules/JVMAddModulePackage.java
index 3f7f2fd29a0..e109e728607 100644
--- a/hotspot/test/runtime/modules/JVMAddModulePackage.java
+++ b/hotspot/test/runtime/modules/JVMAddModulePackage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 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
@@ -40,25 +40,25 @@ public class JVMAddModulePackage {
public static void main(String args[]) throws Throwable {
MyClassLoader cl1 = new MyClassLoader();
MyClassLoader cl3 = new MyClassLoader();
- Object module1, module2, module3;
+ Object module_one, module_two, module_three;
boolean result;
- module1 = ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" });
- assertNotNull(module1, "Module should not be null");
- ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" });
- module2 = ModuleHelper.ModuleObject("module2", cl1, new String[] { "yourpackage" });
- assertNotNull(module2, "Module should not be null");
- ModuleHelper.DefineModule(module2, "9.0", "module2/here", new String[] { "yourpackage" });
- module3 = ModuleHelper.ModuleObject("module3", cl3, new String[] { "package/num3" });
- assertNotNull(module3, "Module should not be null");
- ModuleHelper.DefineModule(module3, "9.0", "module3/here", new String[] { "package/num3" });
+ module_one = ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
+ assertNotNull(module_one, "Module should not be null");
+ ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
+ module_two = ModuleHelper.ModuleObject("module_two", cl1, new String[] { "yourpackage" });
+ assertNotNull(module_two, "Module should not be null");
+ ModuleHelper.DefineModule(module_two, "9.0", "module_two/here", new String[] { "yourpackage" });
+ module_three = ModuleHelper.ModuleObject("module_three", cl3, new String[] { "package/num3" });
+ assertNotNull(module_three, "Module should not be null");
+ ModuleHelper.DefineModule(module_three, "9.0", "module_three/here", new String[] { "package/num3" });
// Simple call
- ModuleHelper.AddModulePackage(module1, "new_package");
+ ModuleHelper.AddModulePackage(module_one, "new_package");
// Add a package and export it
- ModuleHelper.AddModulePackage(module1, "package/num3");
- ModuleHelper.AddModuleExportsToAll(module1, "package/num3");
+ ModuleHelper.AddModulePackage(module_one, "package/num3");
+ ModuleHelper.AddModuleExportsToAll(module_one, "package/num3");
// Null module argument, expect an NPE
try {
@@ -78,7 +78,7 @@ public class JVMAddModulePackage {
// Null package argument, expect an NPE
try {
- ModuleHelper.AddModulePackage(module1, null);
+ ModuleHelper.AddModulePackage(module_one, null);
throw new RuntimeException("Failed to get the expected NPE");
} catch(NullPointerException e) {
// Expected
@@ -86,7 +86,7 @@ public class JVMAddModulePackage {
// Existing package, expect an ISE
try {
- ModuleHelper.AddModulePackage(module1, "yourpackage");
+ ModuleHelper.AddModulePackage(module_one, "yourpackage");
throw new RuntimeException("Failed to get the expected ISE");
} catch(IllegalStateException e) {
// Expected
@@ -94,7 +94,7 @@ public class JVMAddModulePackage {
// Invalid package name, expect an IAE
try {
- ModuleHelper.AddModulePackage(module1, "your.package");
+ ModuleHelper.AddModulePackage(module_one, "your.package");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
@@ -102,7 +102,7 @@ public class JVMAddModulePackage {
// Invalid package name, expect an IAE
try {
- ModuleHelper.AddModulePackage(module1, ";your/package");
+ ModuleHelper.AddModulePackage(module_one, ";your/package");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
@@ -110,7 +110,7 @@ public class JVMAddModulePackage {
// Invalid package name, expect an IAE
try {
- ModuleHelper.AddModulePackage(module1, "7[743");
+ ModuleHelper.AddModulePackage(module_one, "7[743");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
@@ -118,7 +118,7 @@ public class JVMAddModulePackage {
// Empty package name, expect an IAE
try {
- ModuleHelper.AddModulePackage(module1, "");
+ ModuleHelper.AddModulePackage(module_one, "");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
@@ -126,8 +126,8 @@ public class JVMAddModulePackage {
// Add package named "java" to an module defined to a class loader other than the boot or platform loader.
try {
- // module1 is defined to a MyClassLoader class loader.
- ModuleHelper.AddModulePackage(module1, "java/foo");
+ // module_one is defined to a MyClassLoader class loader.
+ ModuleHelper.AddModulePackage(module_one, "java/foo");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
if (!e.getMessage().contains("prohibited package name")) {
@@ -136,10 +136,10 @@ public class JVMAddModulePackage {
}
// Package "javabar" should be ok
- ModuleHelper.AddModulePackage(module1, "javabar");
+ ModuleHelper.AddModulePackage(module_one, "javabar");
// Package named "java" defined to the boot class loader, should be ok
- Object module_javabase = module1.getClass().getModule();
+ Object module_javabase = module_one.getClass().getModule();
ModuleHelper.AddModulePackage(module_javabase, "java/foo");
// Package named "java" defined to the platform class loader, should be ok
diff --git a/hotspot/test/runtime/modules/JVMDefineModule.java b/hotspot/test/runtime/modules/JVMDefineModule.java
index 9e44878490d..5ef669ed93b 100644
--- a/hotspot/test/runtime/modules/JVMDefineModule.java
+++ b/hotspot/test/runtime/modules/JVMDefineModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 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
@@ -49,7 +49,7 @@ public class JVMDefineModule {
/* Invalid test, won't compile.
// Invalid classloader argument, expect an IAE
try {
- m = ModuleHelper.ModuleObject("mymodule1", new Object(), new String[] { "mypackage1" });
+ m = ModuleHelper.ModuleObject("mymodule_one", new Object(), new String[] { "mypackage1" });
ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage1" });
throw new RuntimeException("Failed to get expected IAE for bad loader");
} catch(IllegalArgumentException e) {
diff --git a/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java b/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java
index 1f58193c676..ce94bb19536 100644
--- a/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java
+++ b/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java
@@ -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
@@ -79,10 +79,10 @@ public class JVMGetModuleByPkgName {
}
MyClassLoader cl1 = new MyClassLoader();
- Module module1 = (Module)ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" });
- assertNotNull(module1, "Module should not be null");
- ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" });
- if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module1) {
+ Module module_one = (Module)ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
+ assertNotNull(module_one, "Module should not be null");
+ ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
+ if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module_one) {
throw new RuntimeException("Wrong module returned for cl1 mypackage");
}
}
diff --git a/hotspot/test/runtime/modules/ModuleHelper.java b/hotspot/test/runtime/modules/ModuleHelper.java
index 2f0d7f6ec11..26febc2a75e 100644
--- a/hotspot/test/runtime/modules/ModuleHelper.java
+++ b/hotspot/test/runtime/modules/ModuleHelper.java
@@ -84,7 +84,7 @@ public class ModuleHelper {
}
ModuleDescriptor descriptor =
- ModuleDescriptor.module(name).contains(pkg_set).build();
+ ModuleDescriptor.newModule(name).packages(pkg_set).build();
URI uri = URI.create("module:/" + name);
return java.lang.reflect.ModuleHelper.newModule(loader, descriptor);
diff --git a/hotspot/test/runtime/modules/ModuleOptionsTest.java b/hotspot/test/runtime/modules/ModuleOptionsTest.java
index 28064bddc27..e526e06abe1 100644
--- a/hotspot/test/runtime/modules/ModuleOptionsTest.java
+++ b/hotspot/test/runtime/modules/ModuleOptionsTest.java
@@ -43,7 +43,7 @@ public class ModuleOptionsTest {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"--add-modules=i_dont_exist", "--add-modules=java.base", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("ResolutionException");
+ output.shouldContain("FindException");
output.shouldContain("i_dont_exist");
output.shouldHaveExitValue(1);
diff --git a/hotspot/test/runtime/modules/ModuleStress/CustomSystemClassLoader.java b/hotspot/test/runtime/modules/ModuleStress/CustomSystemClassLoader.java
index dca359f6458..643e4bfd547 100644
--- a/hotspot/test/runtime/modules/ModuleStress/CustomSystemClassLoader.java
+++ b/hotspot/test/runtime/modules/ModuleStress/CustomSystemClassLoader.java
@@ -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,7 @@
*/
/**
- * A custom system ClassLoader to define the module "m2" to during iterations of
+ * A custom system ClassLoader to define the module "m2x" to during iterations of
* differing test runs within the test ModuleStress.java
*/
public class CustomSystemClassLoader extends ClassLoader {
diff --git a/hotspot/test/runtime/modules/ModuleStress/ModuleNonBuiltinCLMain.java b/hotspot/test/runtime/modules/ModuleStress/ModuleNonBuiltinCLMain.java
index 79e56f2a457..6186727606f 100644
--- a/hotspot/test/runtime/modules/ModuleStress/ModuleNonBuiltinCLMain.java
+++ b/hotspot/test/runtime/modules/ModuleStress/ModuleNonBuiltinCLMain.java
@@ -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
@@ -35,15 +35,15 @@ import java.util.Map;
import java.util.Set;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader2 --> defines m2 --> packages p2
-// Java System Class Loader --> defines m3 --> packages p3
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader2 --> defines m2x --> packages p2
+// Java System Class Loader --> defines m3x --> packages p3
//
-// m1 can read m2
-// package p2 in m2 is exported to m1 and m3
+// m1x can read m2x
+// package p2 in m2x is exported to m1x and m3x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access allowed since m1 can read m2 and package p2 is exported to m1.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access allowed since m1x can read m2x and package p2 is exported to m1x.
//
public class ModuleNonBuiltinCLMain {
@@ -52,62 +52,62 @@ public class ModuleNonBuiltinCLMain {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported to unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
- // Can read: java.base, m3
+ // Define module: m2x
+ // Can read: java.base, m3x
// Packages: p2
- // Packages exported: package p2 is exported to m1 and m3
+ // Packages exported: package p2 is exported to m1x and m3x
Set targets = new HashSet<>();
- targets.add("m1");
- targets.add("m3");
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ targets.add("m1x");
+ targets.add("m3x");
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .requires("m3")
+ .requires("m3x")
.exports("p2", targets)
.build();
- // Define module: m3
+ // Define module: m3x
// Can read: java.base
// Packages: p3
// Packages exported: none
- ModuleDescriptor descriptor_m3 =
- ModuleDescriptor.module("m3")
+ ModuleDescriptor descriptor_m3x =
+ ModuleDescriptor.newModule("m3x")
.requires("java.base")
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to differing user defined class loaders for this test
Map map = new HashMap<>();
Loader1 cl1 = new Loader1();
Loader2 cl2 = new Loader2();
ClassLoader cl3 = ClassLoader.getSystemClassLoader();
- map.put("m1", cl1);
- map.put("m2", cl2);
- map.put("m3", cl3);
+ map.put("m1x", cl1);
+ map.put("m2x", cl2);
+ map.put("m3x", cl3);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == cl1);
- assertTrue(layer.findLoader("m2") == cl2);
- assertTrue(layer.findLoader("m3") == cl3);
+ assertTrue(layer.findLoader("m1x") == cl1);
+ assertTrue(layer.findLoader("m2x") == cl2);
+ assertTrue(layer.findLoader("m3x") == cl3);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -115,7 +115,7 @@ public class ModuleNonBuiltinCLMain {
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
+ throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
}
}
diff --git a/hotspot/test/runtime/modules/ModuleStress/ModuleSameCLMain.java b/hotspot/test/runtime/modules/ModuleStress/ModuleSameCLMain.java
index cdbc9002405..c2f859e3817 100644
--- a/hotspot/test/runtime/modules/ModuleStress/ModuleSameCLMain.java
+++ b/hotspot/test/runtime/modules/ModuleStress/ModuleSameCLMain.java
@@ -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,14 +34,14 @@ import java.util.Map;
import java.util.Set;
//
-// ClassLoader1 --> defines m1 --> packages p1
-// ClassLoader1 --> defines m2 --> packages p2
+// ClassLoader1 --> defines m1x --> packages p1
+// ClassLoader1 --> defines m2x --> packages p2
//
-// m1 can read m2
-// package p2 in m2 is exported to m1
+// m1x can read m2x
+// package p2 in m2x is exported to m1x
//
-// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
-// Access allowed since m1 can read m2 and package p2 is exported to m1.
+// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
+// Access allowed since m1x can read m2x and package p2 is exported to m1x.
//
public class ModuleSameCLMain {
@@ -50,45 +50,45 @@ public class ModuleSameCLMain {
// publically defined classes within packages of those modules.
public void createLayerOnBoot() throws Throwable {
- // Define module: m1
- // Can read: java.base, m2
+ // Define module: m1x
+ // Can read: java.base, m2x
// Packages: p1
// Packages exported: p1 is exported to unqualifiedly
- ModuleDescriptor descriptor_m1 =
- ModuleDescriptor.module("m1")
+ ModuleDescriptor descriptor_m1x =
+ ModuleDescriptor.newModule("m1x")
.requires("java.base")
- .requires("m2")
+ .requires("m2x")
.exports("p1")
.build();
- // Define module: m2
+ // Define module: m2x
// Can read: java.base
// Packages: p2
- // Packages exported: package p2 is exported to m1
- ModuleDescriptor descriptor_m2 =
- ModuleDescriptor.module("m2")
+ // Packages exported: package p2 is exported to m1x
+ ModuleDescriptor descriptor_m2x =
+ ModuleDescriptor.newModule("m2x")
.requires("java.base")
- .exports("p2", Set.of("m1"))
+ .exports("p2", Set.of("m1x"))
.build();
// Set up a ModuleFinder containing all modules for this layer.
- ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
+ ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
- // Resolves "m1"
+ // Resolves "m1x"
Configuration cf = Layer.boot()
.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
+ .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
// map each module to the same class loader for this test
Map map = new HashMap<>();
Loader1 cl1 = new Loader1();
- map.put("m1", cl1);
- map.put("m2", cl1);
+ map.put("m1x", cl1);
+ map.put("m2x", cl1);
- // Create Layer that contains m1 & m2
+ // Create Layer that contains m1x & m2x
Layer layer = Layer.boot().defineModules(cf, map::get);
- assertTrue(layer.findLoader("m1") == cl1);
- assertTrue(layer.findLoader("m2") == cl1);
+ assertTrue(layer.findLoader("m1x") == cl1);
+ assertTrue(layer.findLoader("m2x") == cl1);
assertTrue(layer.findLoader("java.base") == null);
// now use the same loader to load class p1.c1
@@ -96,7 +96,7 @@ public class ModuleSameCLMain {
try {
p1_c1_class.newInstance();
} catch (IllegalAccessError e) {
- throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
+ throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
}
}
diff --git a/hotspot/test/runtime/modules/ModuleStress/ModuleStress.java b/hotspot/test/runtime/modules/ModuleStress/ModuleStress.java
index 2da921d4d8c..83f706d7092 100644
--- a/hotspot/test/runtime/modules/ModuleStress/ModuleStress.java
+++ b/hotspot/test/runtime/modules/ModuleStress/ModuleStress.java
@@ -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
@@ -83,7 +83,7 @@ public class ModuleStress {
InMemoryJavaCompiler.compile("p1.c1", source1), System.getProperty("test.classes"));
// Test #2: Load two modules defined to the same customer class loader.
- // m1's module readability list and package p2's exportability should
+ // m1x's module readability list and package p2's exportability should
// not be walked at a GC safepoint since both modules are defined to
// the same loader and thus have the exact same life cycle.
pb = ProcessTools.createJavaProcessBuilder(
@@ -97,7 +97,7 @@ public class ModuleStress {
.shouldHaveExitValue(0);
// Test #3: Load two modules in differing custom class loaders.
- // m1's module readability list and package p2's exportability list must
+ // m1x's module readability list and package p2's exportability list must
// be walked at a GC safepoint since both modules are defined to non-builtin
// class loaders which could die and thus be unloaded.
pb = ProcessTools.createJavaProcessBuilder(
@@ -106,15 +106,15 @@ public class ModuleStress {
"ModuleNonBuiltinCLMain");
oa = new OutputAnalyzer(pb.start());
- oa.shouldContain("module m1 reads list must be walked")
- .shouldContain("package p2 defined in module m2, exports list must be walked")
- .shouldNotContain("module m2 reads list must be walked")
+ oa.shouldContain("module m1x reads list must be walked")
+ .shouldContain("package p2 defined in module m2x, exports list must be walked")
+ .shouldNotContain("module m2x reads list must be walked")
.shouldHaveExitValue(0);
// Test #4: Load two modules in differing custom class loaders,
// of which one has been designated as the custom system class loader
// via -Djava.system.class.loader=CustomSystemClassLoader. Since
- // m3 is defined to the system class loader, m2's module readability
+ // m3x is defined to the system class loader, m2x's module readability
// list does not have to be walked at a GC safepoint, but package p2's
// exportability list does.
pb = ProcessTools.createJavaProcessBuilder(
@@ -124,8 +124,8 @@ public class ModuleStress {
"ModuleNonBuiltinCLMain");
oa = new OutputAnalyzer(pb.start());
- oa.shouldContain("package p2 defined in module m2, exports list must be walked")
- .shouldNotContain("module m2 reads list must be walked")
+ oa.shouldContain("package p2 defined in module m2x, exports list must be walked")
+ .shouldNotContain("module m2x reads list must be walked")
.shouldHaveExitValue(0);
}
diff --git a/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/Main.java b/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/Main.java
index 16e8dbc79e1..6ce8823db25 100644
--- a/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/Main.java
+++ b/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/Main.java
@@ -48,7 +48,7 @@ public class Main {
Configuration cf = layerBoot
.configuration()
- .resolveRequires(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
+ .resolve(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
Module testModule = Main.class.getModule();
ClassLoader scl = ClassLoader.getSystemClassLoader();
diff --git a/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/MainGC.java b/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/MainGC.java
index 25c121d3625..45e592f9d62 100644
--- a/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/MainGC.java
+++ b/hotspot/test/runtime/modules/ModuleStress/src/jdk.test/test/MainGC.java
@@ -48,7 +48,7 @@ public class MainGC {
Configuration cf = layerBoot
.configuration()
- .resolveRequires(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
+ .resolve(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
Module testModule = MainGC.class.getModule();
ClassLoader scl = ClassLoader.getSystemClassLoader();
diff --git a/hotspot/test/runtime/modules/PatchModule/PatchModuleDupModule.java b/hotspot/test/runtime/modules/PatchModule/PatchModuleDupModule.java
index f87a582d30a..75489a665fb 100644
--- a/hotspot/test/runtime/modules/PatchModule/PatchModuleDupModule.java
+++ b/hotspot/test/runtime/modules/PatchModule/PatchModuleDupModule.java
@@ -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
@@ -38,8 +38,8 @@ public class PatchModuleDupModule {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "--patch-module=module1=module1_dir",
- "--patch-module=module1=module1_dir",
+ "--patch-module=module_one=module_one_dir",
+ "--patch-module=module_one=module_one_dir",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("java.lang.ExceptionInInitializerError");
diff --git a/hotspot/test/serviceability/jvmti/GetModulesInfo/JvmtiGetAllModulesTest.java b/hotspot/test/serviceability/jvmti/GetModulesInfo/JvmtiGetAllModulesTest.java
index 7c682b5dfa0..dd0105a135f 100644
--- a/hotspot/test/serviceability/jvmti/GetModulesInfo/JvmtiGetAllModulesTest.java
+++ b/hotspot/test/serviceability/jvmti/GetModulesInfo/JvmtiGetAllModulesTest.java
@@ -82,12 +82,11 @@ public class JvmtiGetAllModulesTest {
Asserts.assertEquals(Layer.boot().modules(), getModulesJVMTI());
// Load a new named module
- ModuleDescriptor descriptor
- = ModuleDescriptor.module(MY_MODULE_NAME).build();
+ ModuleDescriptor descriptor = ModuleDescriptor.newModule(MY_MODULE_NAME).build();
ModuleFinder finder = finderOf(descriptor);
ClassLoader loader = new ClassLoader() {};
Configuration parent = Layer.boot().configuration();
- Configuration cf = parent.resolveRequires(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
+ Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
Layer my = Layer.boot().defineModules(cf, m -> loader);
// Verify that the loaded module is indeed reported by JVMTI
diff --git a/hotspot/test/serviceability/sa/LingeredAppWithLargeArray.java b/hotspot/test/serviceability/sa/LingeredAppWithLargeArray.java
new file mode 100644
index 00000000000..44929f05b15
--- /dev/null
+++ b/hotspot/test/serviceability/sa/LingeredAppWithLargeArray.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+import jdk.test.lib.apps.LingeredApp;
+
+public class LingeredAppWithLargeArray extends LingeredApp {
+ public static void main(String args[]) {
+ int[] hugeArray = new int[Integer.MAX_VALUE/2];
+ LingeredApp.main(args);
+ }
+ }
diff --git a/hotspot/test/serviceability/sa/TestHeapDumpForLargeArray.java b/hotspot/test/serviceability/sa/TestHeapDumpForLargeArray.java
new file mode 100644
index 00000000000..70f26fb48eb
--- /dev/null
+++ b/hotspot/test/serviceability/sa/TestHeapDumpForLargeArray.java
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.File;
+import java.nio.file.Files;
+import java.io.IOException;
+import java.io.BufferedInputStream;
+import java.util.stream.Collectors;
+import java.io.FileInputStream;
+
+import sun.jvm.hotspot.HotSpotAgent;
+import sun.jvm.hotspot.debugger.*;
+
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Utils;
+import jdk.test.lib.Asserts;
+
+/*
+ * @test
+ * @library /test/lib
+ * @bug 8171084
+ * @requires (vm.bits == "64" & os.maxMemory > 8g)
+ * @modules java.base/jdk.internal.misc
+ * jdk.hotspot.agent/sun.jvm.hotspot
+ * jdk.hotspot.agent/sun.jvm.hotspot.utilities
+ * jdk.hotspot.agent/sun.jvm.hotspot.oops
+ * jdk.hotspot.agent/sun.jvm.hotspot.debugger
+ * @run main/timeout=1800/othervm -Xmx8g TestHeapDumpForLargeArray
+ */
+
+public class TestHeapDumpForLargeArray {
+
+ private static LingeredAppWithLargeArray theApp = null;
+
+ private static void attachAndDump(String heapDumpFileName,
+ long lingeredAppPid) throws Exception {
+
+ JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+ launcher.addToolArg("jmap");
+ launcher.addToolArg("--binaryheap");
+ launcher.addToolArg("--dumpfile");
+ launcher.addToolArg(heapDumpFileName);
+ launcher.addToolArg("--pid");
+ launcher.addToolArg(Long.toString(lingeredAppPid));
+
+ ProcessBuilder processBuilder = new ProcessBuilder();
+ processBuilder.command(launcher.getCommand());
+ System.out.println(
+ processBuilder.command().stream().collect(Collectors.joining(" ")));
+
+ OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
+ SAOutput.shouldHaveExitValue(0);
+ SAOutput.shouldNotContain("Heap segment size overflow");
+ SAOutput.shouldContain("truncating to");
+ SAOutput.shouldContain("heap written to");
+ SAOutput.shouldContain(heapDumpFileName);
+ System.out.println(SAOutput.getOutput());
+
+ }
+
+ public static void main (String... args) throws Exception {
+
+ String heapDumpFileName = "LargeArrayHeapDump.bin";
+
+ if (!Platform.shouldSAAttach()) {
+ System.out.println(
+ "SA attach not expected to work - test skipped.");
+ return;
+ }
+
+ File heapDumpFile = new File(heapDumpFileName);
+ if (heapDumpFile.exists()) {
+ heapDumpFile.delete();
+ }
+
+ try {
+ List vmArgs = new ArrayList();
+ vmArgs.add("-XX:+UsePerfData");
+ vmArgs.add("-Xmx8g");
+ vmArgs.addAll(Utils.getVmOptions());
+
+ theApp = new LingeredAppWithLargeArray();
+ LingeredApp.startApp(vmArgs, theApp);
+ attachAndDump(heapDumpFileName, theApp.getPid());
+ } finally {
+ LingeredApp.stopApp(theApp);
+ heapDumpFile.delete();
+ }
+ }
+}
diff --git a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
index 2a46621d118..50531949002 100644
--- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
+++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
@@ -53,7 +53,6 @@ import jdk.test.lib.process.ProcessTools;
public class JMapHProfLargeHeapTest {
private static final String HEAP_DUMP_FILE_NAME = "heap.bin";
- private static final String HPROF_HEADER_1_0_1 = "JAVA PROFILE 1.0.1";
private static final String HPROF_HEADER_1_0_2 = "JAVA PROFILE 1.0.2";
private static final long M = 1024L;
private static final long G = 1024L * M;
@@ -65,9 +64,7 @@ public class JMapHProfLargeHeapTest {
}
// All heap dumps should create 1.0.2 file format
- // Hotspot internal heapdumper always use HPROF_HEADER_1_0_2 format,
- // but SA heapdumper still use HPROF_HEADER_1_0_1 for small heaps
- testHProfFileFormat("-Xmx1g", 22 * M, HPROF_HEADER_1_0_1);
+ testHProfFileFormat("-Xmx1g", 22 * M, HPROF_HEADER_1_0_2);
/**
* This test was deliberately commented out since the test system lacks
diff --git a/hotspot/test/testlibrary/jittester/Makefile b/hotspot/test/testlibrary/jittester/Makefile
index 14f0cb3fba1..e4dd97cff23 100644
--- a/hotspot/test/testlibrary/jittester/Makefile
+++ b/hotspot/test/testlibrary/jittester/Makefile
@@ -108,7 +108,7 @@ INIT: $(DIST_DIR)
$(shell if [ ! -d $(CLASSES_DIR) ]; then mkdir -p $(CLASSES_DIR); fi)
install: clean_testbase testgroup testroot copytestlibrary copyaot JAR cleantmp
- $(JAVA) --add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -ea -jar $(DIST_JAR) $(APPLICATION_ARGS)
+ $(JAVA) --add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED -ea -jar $(DIST_JAR) $(APPLICATION_ARGS)
clean_testbase:
@rm -rf $(TESTBASE_DIR)
diff --git a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TestsGenerator.java b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TestsGenerator.java
index 3974f078d7b..952e34182a3 100644
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TestsGenerator.java
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TestsGenerator.java
@@ -43,6 +43,7 @@ public abstract class TestsGenerator implements BiConsumer {
protected final Path generatorDir;
protected final Function preRunActions;
protected final String jtDriverOptions;
+ private static final String DISABLE_WARNINGS = "-XX:-PrintWarnings";
protected TestsGenerator(String suffix) {
this(suffix, s -> new String[0], "");
@@ -57,8 +58,8 @@ public abstract class TestsGenerator implements BiConsumer {
protected void generateGoldenOut(String mainClassName) {
String classPath = getRoot() + File.pathSeparator + generatorDir;
- ProcessBuilder pb = new ProcessBuilder(JAVA, "-Xint", "-Xverify", "-cp", classPath,
- mainClassName);
+ ProcessBuilder pb = new ProcessBuilder(JAVA, "-Xint", DISABLE_WARNINGS, "-Xverify",
+ "-cp", classPath, mainClassName);
String goldFile = mainClassName + ".gold";
try {
runProcess(pb, generatorDir.resolve(goldFile).toString());
@@ -128,6 +129,8 @@ public abstract class TestsGenerator implements BiConsumer {
.append("\n");
}
header.append(" * @run driver jdk.test.lib.jittester.jtreg.JitTesterDriver ")
+ .append(DISABLE_WARNINGS)
+ .append(" ")
.append(jtDriverOptions)
.append(" ")
.append(mainClassName)
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
index 9804e10e82f..2d1cb9696f3 100644
--- a/jaxp/.hgtags
+++ b/jaxp/.hgtags
@@ -396,5 +396,9 @@ f85154af719f99a3b4d81b67a8b4c18a650d10f9 jdk-9+150
13c6906bfc861d99dc35a19c80b7a99f0b0ac58d jdk-9+151
7e3da313b1746578da648155e37dd8526e83153d jdk-9+152
1384504d2cd0e55c5e0becaeaf40ab05cae959d6 jdk-9+153
+0908877116d17c6e59092ec7d53ef687a96d3278 jdk-10+0
7fa738305436d14c0926df0f04892890cacc766b jdk-9+154
48fa77af153288b08ba794e1616a7b0685f3b67e jdk-9+155
+e930c373aaa4e0e712c9a25ba4b03d473b48c294 jdk-9+156
+412df235a8a229469a2cb9e7bb274d43277077d2 jdk-9+157
+60e670a65e07cc309951bd838b484401e6dd7847 jdk-9+158
diff --git a/jaxp/.jcheck/conf b/jaxp/.jcheck/conf
index 5c6f62dc12c..b2581358014 100644
--- a/jaxp/.jcheck/conf
+++ b/jaxp/.jcheck/conf
@@ -1 +1 @@
-project=jdk9
+project=jdk10
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
index e5fac8b7395..d0ddbe10f54 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
@@ -438,7 +438,7 @@ public final class TemplatesImpl implements Templates, Serializable {
Layer bootLayer = Layer.boot();
Configuration cf = bootLayer.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of(mn));
+ .resolve(finder, ModuleFinder.of(), Set.of(mn));
PrivilegedAction pa = () -> bootLayer.defineModules(cf, name -> loader);
Layer layer = AccessController.doPrivileged(pa);
@@ -483,10 +483,11 @@ public final class TemplatesImpl implements Templates, Serializable {
String pn = _tfactory.getPackageName();
assert pn != null && pn.length() > 0;
- ModuleDescriptor descriptor = ModuleDescriptor.module(mn)
- .requires("java.xml")
- .exports(pn)
- .build();
+ ModuleDescriptor descriptor =
+ ModuleDescriptor.newModule(mn, Set.of(ModuleDescriptor.Modifier.SYNTHETIC))
+ .requires("java.xml")
+ .exports(pn)
+ .build();
Module m = createModule(descriptor, loader);
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java
index 1226fe319ff..d6d73ca56a5 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java
@@ -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.
*/
/*
@@ -743,7 +743,7 @@ public class XMLDocumentScannerImpl
// scan XMLDecl
try {
if (fEntityScanner.skipString(XMLDECL)) {
- if (fEntityScanner.peekChar() == ' ') {
+ if (XMLChar.isSpace(fEntityScanner.peekChar())) {
fMarkupDepth++;
scanXMLDeclOrTextDecl(false);
} else {
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java
index f56467532b6..ac5e7e7ba39 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java
@@ -415,9 +415,15 @@ public class XML11Configuration extends ParserConfigurationSettings
/** Current DTD scanner. */
protected XMLDTDScanner fCurrentDTDScanner;
- /** Flag indiciating whether XML11 components have been initialized. */
+ /** Flag indicating whether XML11 components have been initialized. */
private boolean f11Initialized = false;
+ /** Flag indicating whether the symbol table instance was specified during construction **/
+ private boolean fSymbolTableProvided = false;
+
+ /** Flag indicating if the symbol table was initialized and never used before that **/
+ private boolean fSymbolTableJustInitialized = true;
+
//
// Constructors
//
@@ -566,15 +572,18 @@ public class XML11Configuration extends ParserConfigurationSettings
};
addRecognizedProperties(recognizedProperties);
- if (symbolTable == null) {
- symbolTable = new SymbolTable();
+ // Remember if symbolTable was provided from outside
+ fSymbolTableProvided = symbolTable != null;
+ if (!fSymbolTableProvided) {
+ fSymbolTable = new SymbolTable();
+ } else {
+ fSymbolTable = symbolTable;
}
- fSymbolTable = symbolTable;
fProperties.put(SYMBOL_TABLE, fSymbolTable);
fGrammarPool = grammarPool;
if (fGrammarPool != null) {
- fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
+ fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
}
fEntityManager = new XMLEntityManager();
@@ -840,6 +849,7 @@ public class XML11Configuration extends ParserConfigurationSettings
fValidationManager.reset();
fVersionDetector.reset(this);
fConfigUpdated = true;
+ resetSymbolTable();
resetCommon();
short version = fVersionDetector.determineDocVersion(fInputSource);
@@ -858,15 +868,7 @@ public class XML11Configuration extends ParserConfigurationSettings
// resets and sets the pipeline.
fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
fInputSource = null;
- } catch (XNIException ex) {
- if (PRINT_EXCEPTION_STACK_TRACE)
- ex.printStackTrace();
- throw ex;
- } catch (IOException ex) {
- if (PRINT_EXCEPTION_STACK_TRACE)
- ex.printStackTrace();
- throw ex;
- } catch (RuntimeException ex) {
+ } catch (IOException | RuntimeException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
@@ -879,15 +881,7 @@ public class XML11Configuration extends ParserConfigurationSettings
try {
return fCurrentScanner.scanDocument(complete);
- } catch (XNIException ex) {
- if (PRINT_EXCEPTION_STACK_TRACE)
- ex.printStackTrace();
- throw ex;
- } catch (IOException ex) {
- if (PRINT_EXCEPTION_STACK_TRACE)
- ex.printStackTrace();
- throw ex;
- } catch (RuntimeException ex) {
+ } catch (IOException | RuntimeException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
@@ -1589,6 +1583,23 @@ public class XML11Configuration extends ParserConfigurationSettings
}
}
+
+ /**
+ * Reset the symbol table if it wasn't provided during construction
+ * and its not the first time when parse is called after initialization
+ */
+ private void resetSymbolTable() {
+ if (!fSymbolTableProvided) {
+ if (fSymbolTableJustInitialized) {
+ // Skip symbol table reallocation for the first parsing process
+ fSymbolTableJustInitialized = false;
+ } else {
+ fSymbolTable = new SymbolTable();
+ fProperties.put(SYMBOL_TABLE, fSymbolTable);
+ }
+ }
+ }
+
/**
* Returns the state of a feature. This method calls getFeature()
* on ParserConfigurationSettings, bypassing getFeature() on this
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
index 502a8b8debb..3d510286d63 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
@@ -717,7 +717,9 @@ public final class ToHTMLStream extends ToStream
*/
public final void endDocument() throws org.xml.sax.SAXException
{
- flushCharactersBuffer();
+ if (m_doIndent) {
+ flushCharactersBuffer();
+ }
flushPending();
if (m_doIndent && !m_isprevtext)
{
@@ -776,9 +778,11 @@ public final class ToHTMLStream extends ToStream
Attributes atts)
throws SAXException
{
- // will add extra one if having namespace but no matter
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ // will add extra one if having namespace but no matter
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
ElemContext elemContext = m_elemContext;
// clean up any pending things first
@@ -839,8 +843,10 @@ public final class ToHTMLStream extends ToStream
writer.write('<');
writer.write(name);
- m_childNodeNumStack.push(m_childNodeNum);
- m_childNodeNum = 0;
+ if (m_doIndent) {
+ m_childNodeNumStack.add(m_childNodeNum);
+ m_childNodeNum = 0;
+ }
if (m_tracer != null)
firePseudoAttributes();
@@ -915,7 +921,9 @@ public final class ToHTMLStream extends ToStream
final String name)
throws org.xml.sax.SAXException
{
- flushCharactersBuffer();
+ if (m_doIndent) {
+ flushCharactersBuffer();
+ }
// deal with any pending issues
if (m_cdataTagOpen)
closeCDATA();
@@ -997,12 +1005,11 @@ public final class ToHTMLStream extends ToStream
}
}
- m_childNodeNum = m_childNodeNumStack.pop();
- // clean up because the element has ended
- if ((elemFlags & ElemDesc.WHITESPACESENSITIVE) != 0)
- m_ispreserve = true;
- m_isprevtext = false;
-
+ if (m_doIndent) {
+ m_childNodeNum = m_childNodeNumStack.remove(m_childNodeNumStack.size() - 1);
+ // clean up because the element has ended
+ m_isprevtext = false;
+ }
// fire off the end element event
if (m_tracer != null)
super.fireEndElem(name);
@@ -1018,11 +1025,6 @@ public final class ToHTMLStream extends ToStream
}
// some more clean because the element has ended.
- if (!elemContext.m_startTagOpen)
- {
- if (m_doIndent && !m_preserves.isEmpty())
- m_preserves.pop();
- }
m_elemContext = elemContext.m_prev;
// m_isRawStack.pop();
}
@@ -1525,7 +1527,6 @@ public final class ToHTMLStream extends ToStream
closeStartTag();
m_elemContext.m_startTagOpen = false;
}
- m_ispreserve = true;
// With m_ispreserve just set true it looks like shouldIndent()
// will always return false, so drop any possible indentation.
@@ -1602,8 +1603,6 @@ public final class ToHTMLStream extends ToStream
m_elemContext.m_startTagOpen = false;
}
- m_ispreserve = true;
-
if (shouldIndent())
indent();
@@ -1640,8 +1639,10 @@ public final class ToHTMLStream extends ToStream
public void processingInstruction(String target, String data)
throws org.xml.sax.SAXException
{
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
// Process any pending starDocument and startElement first.
flushPending();
@@ -1790,11 +1791,6 @@ public final class ToHTMLStream extends ToStream
*/
if (m_StringOfCDATASections != null)
m_elemContext.m_isCdataSection = isCdataSection();
- if (m_doIndent)
- {
- m_isprevtext = false;
- m_preserves.push(m_ispreserve);
- }
}
catch(IOException e)
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
index 994a7800d97..ae14a4922b1 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
@@ -20,34 +20,36 @@
package com.sun.org.apache.xml.internal.serializer;
-import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
-import com.sun.org.apache.xml.internal.serializer.utils.Utils;
-import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
-import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Deque;
import java.util.EmptyStackException;
import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
-import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
+
import javax.xml.transform.ErrorListener;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
+
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
+import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
+
/**
* This abstract class is a base class for other stream
* serializers (xml, html, text ...) that write output to a stream.
@@ -103,7 +105,7 @@ abstract public class ToStream extends SerializerBase {
* If m_childNodeNum > 1, the text node will be indented.
*
*/
- protected Deque m_childNodeNumStack = new ArrayDeque<>();
+ protected List m_childNodeNumStack = new ArrayList<>();
protected int m_childNodeNum = 0;
@@ -115,26 +117,6 @@ abstract public class ToStream extends SerializerBase {
protected boolean m_ispreserveSpace = false;
- /**
- * Stack to keep track of whether or not we need to
- * preserve whitespace.
- *
- * Used to push/pop values used for the field m_ispreserve, but
- * m_ispreserve is only relevant if m_doIndent is true.
- * If m_doIndent is false this field has no impact.
- *
- */
- protected BoolStack m_preserves = new BoolStack();
-
- /**
- * State flag to tell if preservation of whitespace
- * is important.
- *
- * Used only in shouldIndent() but only if m_doIndent is true.
- * If m_doIndent is false this flag has no impact.
- *
- */
- protected boolean m_ispreserve = false;
/**
* State flag that tells if the previous node processed
@@ -1267,7 +1249,6 @@ abstract public class ToStream extends SerializerBase {
closeStartTag();
m_elemContext.m_startTagOpen = false;
}
- m_ispreserve = true;
if (shouldIndent())
indent();
@@ -1357,8 +1338,6 @@ abstract public class ToStream extends SerializerBase {
m_elemContext.m_startTagOpen = false;
}
- m_ispreserve = true;
-
m_writer.write(ch, start, length);
}
catch (IOException e)
@@ -1405,8 +1384,8 @@ abstract public class ToStream extends SerializerBase {
if (length == 0 || (isInEntityRef()))
return;
- final boolean shouldFormat = shouldFormatOutput();
- if (m_elemContext.m_startTagOpen && !shouldFormat)
+ final boolean shouldNotFormat = !shouldFormatOutput();
+ if (m_elemContext.m_startTagOpen)
{
closeStartTag();
m_elemContext.m_startTagOpen = false;
@@ -1432,8 +1411,12 @@ abstract public class ToStream extends SerializerBase {
if (m_disableOutputEscapingStates.peekOrFalse() || (!m_escaping))
{
- charactersRaw(chars, start, length);
- m_isprevtext = true;
+ if (shouldNotFormat) {
+ charactersRaw(chars, start, length);
+ m_isprevtext = true;
+ } else {
+ m_charactersBuffer.addRawText(chars, start, length);
+ }
// time to fire off characters generation event
if (m_tracer != null)
super.fireCharEvent(chars, start, length);
@@ -1441,16 +1424,16 @@ abstract public class ToStream extends SerializerBase {
return;
}
- if (m_elemContext.m_startTagOpen && !shouldFormat)
+ if (m_elemContext.m_startTagOpen)
{
closeStartTag();
m_elemContext.m_startTagOpen = false;
}
- if (shouldFormat) {
- m_charactersBuffer.addText(chars, start, length);
- } else {
+ if (shouldNotFormat) {
outputCharacters(chars, start, length);
+ } else {
+ m_charactersBuffer.addText(chars, start, length);
}
// time to fire off characters generation event
@@ -1465,7 +1448,14 @@ abstract public class ToStream extends SerializerBase {
* @return True if the content should be formatted.
*/
protected boolean shouldFormatOutput() {
- return !m_ispreserveSpace && m_doIndent;
+ return m_doIndent && !m_ispreserveSpace;
+ }
+
+ /**
+ * @return True if the content in current element should be formatted.
+ */
+ public boolean getIndent() {
+ return shouldFormatOutput();
}
/**
@@ -1506,12 +1496,6 @@ abstract public class ToStream extends SerializerBase {
i = lastDirty;
}
}
- /* If there is some non-whitespace, mark that we may need
- * to preserve this. This is only important if we have indentation on.
- */
- if (i < end)
- m_ispreserve = true;
-
// int lengthClean; // number of clean characters in a row
// final boolean[] isAsciiClean = m_charInfo.getASCIIClean();
@@ -1577,12 +1561,7 @@ abstract public class ToStream extends SerializerBase {
*/
final protected void flushCharactersBuffer() throws SAXException {
try {
- if (shouldFormatOutput() && m_charactersBuffer.hasContent()) {
- if (m_elemContext.m_startTagOpen) {
- closeStartTag();
- m_elemContext.m_startTagOpen = false;
- }
-
+ if (shouldFormatOutput() && m_charactersBuffer.isAnyCharactersBuffered()) {
if (m_elemContext.m_isCdataSection) {
/*
* due to cdata-section-elements atribute, we need this as
@@ -1594,11 +1573,16 @@ abstract public class ToStream extends SerializerBase {
}
m_childNodeNum++;
+ boolean skipBeginningNewlines = false;
if (shouldIndentForText()) {
indent();
m_startNewLine = true;
+ // newline has always been added here because if this is the
+ // text before the first element, shouldIndent() won't
+ // return true.
+ skipBeginningNewlines = true;
}
- m_charactersBuffer.flush();
+ m_charactersBuffer.flush(skipBeginningNewlines);
}
} catch (IOException e) {
throw new SAXException(e);
@@ -1858,8 +1842,10 @@ abstract public class ToStream extends SerializerBase {
if (isInEntityRef())
return;
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
if (m_needToCallStartDocument)
{
@@ -1890,8 +1876,6 @@ abstract public class ToStream extends SerializerBase {
if (namespaceURI != null)
ensurePrefixIsDeclared(namespaceURI, name);
- m_ispreserve = false;
-
if (shouldIndent() && m_startNewLine)
{
indent();
@@ -1912,11 +1896,13 @@ abstract public class ToStream extends SerializerBase {
if (atts != null)
addAttributes(atts);
- m_ispreserveSpace = m_preserveSpaces.peekOrFalse();
- m_preserveSpaces.push(m_ispreserveSpace);
+ if (m_doIndent) {
+ m_ispreserveSpace = m_preserveSpaces.peekOrFalse();
+ m_preserveSpaces.push(m_ispreserveSpace);
- m_childNodeNumStack.push(m_childNodeNum);
- m_childNodeNum = 0;
+ m_childNodeNumStack.add(m_childNodeNum);
+ m_childNodeNum = 0;
+ }
m_elemContext = m_elemContext.push(namespaceURI,localName,name);
m_isprevtext = false;
@@ -2128,7 +2114,9 @@ abstract public class ToStream extends SerializerBase {
if (isInEntityRef())
return;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ flushCharactersBuffer();
+ }
// namespaces declared at the current depth are no longer valid
// so get rid of them
m_prefixMap.popNamespaces(m_elemContext.m_currentElemDepth, null);
@@ -2175,16 +2163,13 @@ abstract public class ToStream extends SerializerBase {
throw new SAXException(e);
}
- if (!m_elemContext.m_startTagOpen && m_doIndent)
- {
- m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
+ if (m_doIndent) {
+ m_ispreserveSpace = m_preserveSpaces.popAndTop();
+ m_childNodeNum = m_childNodeNumStack.remove(m_childNodeNumStack.size() - 1);
+
+ m_isprevtext = false;
}
- m_ispreserveSpace = m_preserveSpaces.popAndTop();
- m_childNodeNum = m_childNodeNumStack.pop();
-
- m_isprevtext = false;
-
// fire off the end element event
if (m_tracer != null)
super.fireEndElem(name);
@@ -2320,8 +2305,10 @@ abstract public class ToStream extends SerializerBase {
int start_old = start;
if (isInEntityRef())
return;
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
if (m_elemContext.m_startTagOpen)
{
closeStartTag();
@@ -2501,8 +2488,10 @@ abstract public class ToStream extends SerializerBase {
*/
public void startCDATA() throws org.xml.sax.SAXException
{
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
m_cdataStartCalled = true;
}
@@ -2588,12 +2577,6 @@ abstract public class ToStream extends SerializerBase {
*/
if (m_StringOfCDATASections != null)
m_elemContext.m_isCdataSection = isCdataSection();
-
- if (m_doIndent)
- {
- m_isprevtext = false;
- m_preserves.push(m_ispreserve);
- }
}
}
@@ -2943,7 +2926,9 @@ abstract public class ToStream extends SerializerBase {
String value,
boolean xslAttribute)
{
- if (m_charactersBuffer.isAnyCharactersBuffered()) {
+ if (!m_charactersBuffer.isAnyCharactersBuffered()) {
+ return doAddAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
+ } else {
/*
* If stylesheet includes xsl:copy-of an attribute node, XSLTC will
* fire an addAttribute event. When a text node is handling in
@@ -2954,8 +2939,6 @@ abstract public class ToStream extends SerializerBase {
*
*/
return m_attributes.getIndex(rawName) < 0;
- } else {
- return doAddAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
}
}
@@ -3086,7 +3069,7 @@ abstract public class ToStream extends SerializerBase {
}
}
- if (rawName.equals("xml:space")) {
+ if (m_doIndent && rawName.equals("xml:space")) {
if (value.equals("preserve")) {
m_ispreserveSpace = true;
if (m_preserveSpaces.size() > 0)
@@ -3227,8 +3210,6 @@ abstract public class ToStream extends SerializerBase {
// Leave m_format alone for now - Brian M.
// this.m_format = null;
this.m_inDoctype = false;
- this.m_ispreserve = false;
- this.m_preserves.clear();
this.m_ispreserveSpace = false;
this.m_preserveSpaces.clear();
this.m_childNodeNum = 0;
@@ -3411,6 +3392,7 @@ abstract public class ToStream extends SerializerBase {
}
}
+
/**
* This inner class is used to buffer the text nodes and the entity
* reference nodes if indentation is on. There is only one CharacterBuffer
@@ -3425,20 +3407,21 @@ abstract public class ToStream extends SerializerBase {
*/
private abstract class GenericCharacters {
/**
- * @return True if having any character other than whitespace or
- * line feed.
+ * @return True if all characters in this Text are newlines.
*/
- abstract boolean hasContent();
-
- abstract void flush() throws SAXException;
+ abstract boolean flush(boolean skipBeginningNewlines) throws SAXException;
/**
- * Converts this GenericCharacters to a new character array.
+ * Converts this GenericCharacters to a new character array. This
+ * method is used to handle cdata-section-elements attribute in
+ * xsl:output. Therefore it doesn't need to consider
+ * skipBeginningNewlines because the text will be involved with CDATA
+ * tag.
*/
abstract char[] toChars();
}
- private Queue bufferedCharacters = new ArrayDeque<>();
+ private List bufferedCharacters = new ArrayList<>();
/**
* Append a text node to the buffer.
@@ -3451,27 +3434,21 @@ abstract public class ToStream extends SerializerBase {
text = Arrays.copyOfRange(chars, start, start + length);
}
- boolean hasContent() {
- for (int i = 0; i < text.length; i++) {
- if (!isWhiteSpace(text[i])) {
+ boolean flush(boolean skipBeginningNewlines) throws SAXException {
+ int start = 0;
+ while (skipBeginningNewlines && text[start] == '\n') {
+ start++;
+ if (start == text.length) {
return true;
}
}
+ outputCharacters(text, start, text.length - start);
return false;
}
- void flush() throws SAXException {
- outputCharacters(text, 0, text.length);
- }
-
char[] toChars() {
return text;
}
-
- boolean isWhiteSpace(char ch) {
- return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r';
- }
-
});
}
@@ -3480,12 +3457,22 @@ abstract public class ToStream extends SerializerBase {
*/
public void addEntityReference(String entityName) {
bufferedCharacters.add(new GenericCharacters() {
- boolean hasContent() {
- return true;
- }
-
- void flush() throws SAXException {
- outputEntityReference(entityName);
+ boolean flush(boolean skipBeginningNewlines) throws SAXException {
+ if (m_elemContext.m_startTagOpen)
+ {
+ closeStartTag();
+ m_elemContext.m_startTagOpen = false;
+ }
+ if (m_cdataTagOpen)
+ closeCDATA();
+ char[] cs = toChars();
+ try {
+ m_writer.write(cs, 0, cs.length);
+ m_isprevtext = true;
+ } catch (IOException e) {
+ throw new SAXException(e);
+ }
+ return false;
}
char[] toChars() {
@@ -3495,35 +3482,69 @@ abstract public class ToStream extends SerializerBase {
}
/**
- * @return True if any GenericCharacters is already buffered.
+ * Append a raw text to the buffer. Used to handle raw characters event.
*/
- public boolean isAnyCharactersBuffered() {
- return !bufferedCharacters.isEmpty();
+ public void addRawText(final char chars[], final int start, final int length) {
+ bufferedCharacters.add(new GenericCharacters() {
+ char[] text;
+
+ {
+ text = Arrays.copyOfRange(chars, start, start + length);
+ }
+
+ boolean flush(boolean skipBeginningNewlines) throws SAXException {
+ try {
+ int start = 0;
+ while (skipBeginningNewlines && text[start] == '\n') {
+ start++;
+ if (start == text.length) {
+ return true;
+ }
+ }
+ m_writer.write(text, start, text.length - start);
+ m_isprevtext = true;
+ } catch (IOException e) {
+ throw new SAXException(e);
+ }
+ return false;
+ }
+
+ char[] toChars() {
+ return text;
+ }
+ });
}
/**
- * @return True if any buffered GenericCharacters has content.
+ * @return True if any GenericCharacters are buffered.
*/
- public boolean hasContent() {
- return bufferedCharacters.stream().anyMatch(GenericCharacters::hasContent);
+ public boolean isAnyCharactersBuffered() {
+ return bufferedCharacters.size() > 0;
}
/**
* Flush all buffered GenericCharacters.
*/
- public void flush() throws SAXException {
- GenericCharacters element;
- while ((element = bufferedCharacters.poll()) != null)
- element.flush();
+ public void flush(boolean skipBeginningNewlines) throws SAXException {
+ Iterator itr = bufferedCharacters.iterator();
+
+ boolean continueSkipBeginningNewlines = skipBeginningNewlines;
+ while (itr.hasNext()) {
+ GenericCharacters element = itr.next();
+ continueSkipBeginningNewlines = element.flush(continueSkipBeginningNewlines);
+ itr.remove();
+ }
}
/**
* Converts all buffered GenericCharacters to a new character array.
*/
public char[] toChars() {
- return bufferedCharacters.stream().map(GenericCharacters::toChars)
- .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString()
- .toCharArray();
+ StringBuilder sb = new StringBuilder();
+ for (GenericCharacters element : bufferedCharacters) {
+ sb.append(element.toChars());
+ }
+ return sb.toString().toCharArray();
}
/**
@@ -3534,6 +3555,7 @@ abstract public class ToStream extends SerializerBase {
}
}
+
// Implement DTDHandler
/**
* If this method is called, the serializer is used as a
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
index 681737ebc88..add764619ae 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
@@ -88,8 +88,6 @@ public final class ToXMLStream extends ToStream
setOmitXMLDeclaration(xmlListener.getOmitXMLDeclaration());
- m_ispreserve = xmlListener.m_ispreserve;
- m_preserves = xmlListener.m_preserves;
m_ispreserveSpace = xmlListener.m_ispreserveSpace;
m_preserveSpaces = xmlListener.m_preserveSpaces;
m_childNodeNum = xmlListener.m_childNodeNum;
@@ -201,7 +199,9 @@ public final class ToXMLStream extends ToStream
*/
public void endDocument() throws org.xml.sax.SAXException
{
- flushCharactersBuffer();
+ if (m_doIndent) {
+ flushCharactersBuffer();
+ }
flushPending();
if (m_doIndent && !m_isprevtext)
{
@@ -235,11 +235,6 @@ public final class ToXMLStream extends ToStream
*/
public void startPreserving() throws org.xml.sax.SAXException
{
-
- // Not sure this is really what we want. -sb
- m_preserves.push(true);
-
- m_ispreserve = true;
}
/**
@@ -251,9 +246,6 @@ public final class ToXMLStream extends ToStream
*/
public void endPreserving() throws org.xml.sax.SAXException
{
-
- // Not sure this is really what we want. -sb
- m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
}
/**
@@ -273,8 +265,10 @@ public final class ToXMLStream extends ToStream
if (isInEntityRef())
return;
- m_childNodeNum++;
- flushCharactersBuffer();
+ if (m_doIndent) {
+ m_childNodeNum++;
+ flushCharactersBuffer();
+ }
flushPending();
if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
index 68864ca7800..1fafb24c641 100644
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
@@ -1024,7 +1024,8 @@ final class DOM3TreeWalker {
return;
}
- if (bDispatch) {
+ if (bDispatch
+ && (!fSerializer.getIndent() || !node.getData().replace('\n', ' ').trim().isEmpty())) {
dispatachChars(node);
}
}
diff --git a/jaxp/src/java.xml/share/classes/module-info.java b/jaxp/src/java.xml/share/classes/module-info.java
index d9259677564..5182cda9f16 100644
--- a/jaxp/src/java.xml/share/classes/module-info.java
+++ b/jaxp/src/java.xml/share/classes/module-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 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
@@ -26,6 +26,8 @@
/**
* Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX),
* the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API.
+ *
+ * @since 9
*/
module java.xml {
exports javax.xml;
@@ -53,12 +55,6 @@ module java.xml {
exports org.xml.sax;
exports org.xml.sax.ext;
exports org.xml.sax.helpers;
- exports com.sun.org.apache.xerces.internal.dom to
- java.xml.ws;
- exports com.sun.org.apache.xerces.internal.jaxp to
- java.xml.ws;
- exports com.sun.org.apache.xerces.internal.util to
- java.xml.ws;
exports com.sun.org.apache.xml.internal.dtm to
java.xml.crypto;
exports com.sun.org.apache.xml.internal.utils to
diff --git a/jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java b/jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java
index bb4d6b3574a..264ad06a95f 100644
--- a/jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java
+++ b/jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java
@@ -22,6 +22,7 @@
*/
package org.w3c.dom.ptests;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.compareWithGold;
import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission;
import static org.testng.Assert.assertEquals;
@@ -157,7 +158,7 @@ public class NodeTest {
Element element = (Element) document.getElementsByTagName("sender").item(0);
parentElement.insertBefore(createTestDocumentFragment(document), element);
- String outputfile = "InsertBefore.out";
+ String outputfile = USER_DIR + "InsertBefore.out";
String goldfile = GOLDEN_DIR + "InsertBeforeGF.out";
tryRunWithTmpPermission(() -> outputXml(document, outputfile), new PropertyPermission("user.dir", "read"));
assertTrue(compareWithGold(goldfile, outputfile));
@@ -175,7 +176,7 @@ public class NodeTest {
Element element = (Element) document.getElementsByTagName("sender").item(0);
parentElement.replaceChild(createTestDocumentFragment(document), element);
- String outputfile = "ReplaceChild3.out";
+ String outputfile = USER_DIR + "ReplaceChild3.out";
String goldfile = GOLDEN_DIR + "ReplaceChild3GF.out";
tryRunWithTmpPermission(() -> outputXml(document, outputfile), new PropertyPermission("user.dir", "read"));
assertTrue(compareWithGold(goldfile, outputfile));
diff --git a/jaxp/test/javax/xml/jaxp/functional/test/astro/DocumentLSTest.java b/jaxp/test/javax/xml/jaxp/functional/test/astro/DocumentLSTest.java
index acfe988c13a..673674b9e65 100644
--- a/jaxp/test/javax/xml/jaxp/functional/test/astro/DocumentLSTest.java
+++ b/jaxp/test/javax/xml/jaxp/functional/test/astro/DocumentLSTest.java
@@ -22,6 +22,7 @@
*/
package test.astro;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.filenameToURL;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -130,7 +131,7 @@ public class DocumentLSTest {
impl = (DOMImplementationLS) db.getDOMImplementation();
LSSerializer domSerializer = impl.createLSSerializer();
MyDOMOutput mydomoutput = new MyDOMOutput();
- try (OutputStream os = new FileOutputStream("test.out")) {
+ try (OutputStream os = new FileOutputStream(USER_DIR + "test.out")) {
mydomoutput.setByteStream(os);
mydomoutput.setEncoding("UTF-8");
assertTrue(domSerializer.write(doc, mydomoutput));
diff --git a/jaxp/test/javax/xml/jaxp/module/ServiceProviderTest/LayerModularXMLParserTest.java b/jaxp/test/javax/xml/jaxp/module/ServiceProviderTest/LayerModularXMLParserTest.java
index 74f051ac04d..fcfba1955ae 100644
--- a/jaxp/test/javax/xml/jaxp/module/ServiceProviderTest/LayerModularXMLParserTest.java
+++ b/jaxp/test/javax/xml/jaxp/module/ServiceProviderTest/LayerModularXMLParserTest.java
@@ -96,7 +96,7 @@ public class LayerModularXMLParserTest {
public void testOneLayer() throws Exception {
ModuleFinder finder1 = ModuleFinder.of(MOD_DIR1);
Configuration cf1 = Layer.boot().configuration()
- .resolveRequiresAndUses(finder1, ModuleFinder.of(), Set.of("test"));
+ .resolveAndBind(finder1, ModuleFinder.of(), Set.of("test"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, scl);
ClassLoader cl1 = layer1.findLoader("test");
@@ -126,12 +126,12 @@ public class LayerModularXMLParserTest {
public void testTwoLayer() throws Exception {
ModuleFinder finder1 = ModuleFinder.of(MOD_DIR1);
Configuration cf1 = Layer.boot().configuration()
- .resolveRequiresAndUses(finder1, ModuleFinder.of(), Set.of("test"));
+ .resolveAndBind(finder1, ModuleFinder.of(), Set.of("test"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, scl);
ModuleFinder finder2 = ModuleFinder.of(MOD_DIR2);
- Configuration cf2 = cf1.resolveRequiresAndUses(finder2, ModuleFinder.of(), Set.of("test"));
+ Configuration cf2 = cf1.resolveAndBind(finder2, ModuleFinder.of(), Set.of("test"));
Layer layer2 = layer1.defineModulesWithOneLoader(cf2, layer1.findLoader("test"));
ClassLoader cl2 = layer2.findLoader("test");
@@ -160,12 +160,12 @@ public class LayerModularXMLParserTest {
public void testTwoLayerWithDuplicate() throws Exception {
ModuleFinder finder1 = ModuleFinder.of(MOD_DIR1, MOD_DIR2);
Configuration cf1 = Layer.boot().configuration()
- .resolveRequiresAndUses(finder1, ModuleFinder.of(), Set.of("test"));
+ .resolveAndBind(finder1, ModuleFinder.of(), Set.of("test"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer1 = Layer.boot().defineModulesWithManyLoaders(cf1, scl);
ModuleFinder finder2 = ModuleFinder.of(MOD_DIR2);
- Configuration cf2 = cf1.resolveRequiresAndUses(finder2, ModuleFinder.of(), Set.of("test"));
+ Configuration cf2 = cf1.resolveAndBind(finder2, ModuleFinder.of(), Set.of("test"));
Layer layer2 = layer1.defineModulesWithOneLoader(cf2, layer1.findLoader("test"));
ClassLoader cl2 = layer2.findLoader("test");
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
index be54c6c2e05..da4ff787589 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
@@ -60,7 +60,7 @@ import org.xml.sax.SAXException;
/*
* @test
- * @bug 6439439 8087303
+ * @bug 6439439 8087303 8174025
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true common.prettyprint.PrettyPrintTest
* @run testng/othervm common.prettyprint.PrettyPrintTest
@@ -69,29 +69,30 @@ import org.xml.sax.SAXException;
@Listeners({jaxp.library.FilePolicy.class})
public class PrettyPrintTest {
/*
- * test CDATA, elements only, text and element, whitespace and element,
- * xml:space property and nested xml:space property, mixed node types.
+ * test CDATA, elements only, text and element, xml:space property, mixed
+ * node types.
*/
@DataProvider(name = "xml-data")
public Object[][] xmlData() throws Exception {
return new Object[][] {
- { read("xmltest1.xml"), read("xmltest1.out") },
- { read("xmltest2.xml"), read("xmltest2.out") },
- { read("xmltest3.xml"), read("xmltest3.out") },
- { read("xmltest4.xml"), read("xmltest4.out") },
- { read("xmltest5.xml"), read("xmltest5.out") },
- { read("xmltest6.xml"), read("xmltest6.out") },
- { read("xmltest7.xml"), read("xmltest7.out") },
- { read("xmltest8.xml"), read("xmltest8.out") } };
+ { "xmltest1.xml", "xmltest1.out" },
+ { "xmltest2.xml", "xmltest2.out" },
+ { "xmltest3.xml", "xmltest3.out" },
+ { "xmltest4.xml", "xmltest4.out" },
+ { "xmltest6.xml", "xmltest6.out" },
+ { "xmltest8.xml", "xmltest8.out" } };
}
/*
* @bug 8087303
- * Test the whitespace text nodes are serialized with pretty-print by LSSerializer and transformer correctly
+ * Test the xml document are serialized with pretty-print by
+ * LSSerializer and transformer correctly
*
*/
@Test(dataProvider = "xml-data")
- public void testXMLPrettyPrint(String source, String expected) throws Exception {
+ public void testXMLPrettyPrint(String sourceFile, String expectedFile) throws Exception {
+ String source = read(sourceFile);
+ String expected = read(expectedFile);
// test it's no change if no pretty-print
String result = serializerWrite(toXmlDocument(source), false);
assertTrue(toXmlDocument(source).isEqualNode(toXmlDocument(result)), "The actual is: " + result);
@@ -104,40 +105,116 @@ public class PrettyPrintTest {
assertEquals(transform(toXmlDocument(source), true).replaceAll("\r\n", "\n"), expected);
}
+
/*
- * test pure text content, and sequent Text nodes.
+ * @bug 8087303
+ * Test a single text node is serialized with pretty-print by
+ * LSSerializer and transformer correctly
+ *
*/
- @DataProvider(name = "xml-node-data")
- public Object[][] xmlNodeData() throws Exception {
- return new Object[][] {
- { newTextNode(read("nodetest1.txt")), read("nodetest1.out") },
- { createDocWithSequentTextNodes(), read("nodetest2.out") } };
+ @Test
+ public void testSingleTextNode() throws Exception {
+ Node xml = newTextNode(read("nodetest1.txt"));
+ String expected = read("nodetest1.out");
+ assertEquals(serializerWrite(xml, true), expected);
+ assertEquals(transform(xml, true).replaceAll("\r\n", "\n"), expected);
}
/*
* @bug 8087303
- * Test the whitespace text nodes are serialized with pretty-print by LSSerializer and transformer correctly,
- * doesn't compare with the source because the test data is Node object
+ * Test the transformer shall keep all whitespace text node in
+ * sequent text nodes
*
*/
- @Test(dataProvider = "xml-node-data")
- public void testXMLNodePrettyPrint(Node xml, String expected) throws Exception {
- assertEquals(serializerWrite(xml, true), expected);
+ @Test
+ public void testSequentTextNodesWithTransformer() throws Exception {
+ Node xml = createDocWithSequentTextNodes();
+ String expected = read("nodetest2.out");
assertEquals(transform(xml, true).replaceAll("\r\n", "\n"), expected);
}
+ /*
+ * @bug 8087303
+ * Test LSSerializer shall eliminate the whitespace text node
+ * in sequent text nodes
+ *
+ */
+ @Test
+ public void testSequentTextNodesWithLSSerializer() throws Exception {
+ Node xml = createDocWithSequentTextNodes();
+ String expected = read("nodetest2ls.out");
+ assertEquals(serializerWrite(xml, true), expected);
+ }
+
+
+ /*
+ * test whitespace and element, nested xml:space property.
+ */
+ @DataProvider(name = "xml-data-whitespace-ls")
+ public Object[][] whitespaceLS() throws Exception {
+ return new Object[][] {
+ { "xmltest5.xml", "xmltest5ls.out" },
+ { "xmltest7.xml", "xmltest7ls.out" } };
+ }
+
+ /*
+ * @bug 8087303
+ * Test LSSerializer shall eliminate the whitespace text node
+ * unless xml:space="preserve"
+ *
+ */
+ @Test(dataProvider = "xml-data-whitespace-ls")
+ public void testWhitespaceWithLSSerializer(String sourceFile, String expectedFile) throws Exception {
+ String source = read(sourceFile);
+ String expected = read(expectedFile);
+ // test it's no change if no pretty-print
+ String result = serializerWrite(toXmlDocument(source), false);
+ assertTrue(toXmlDocument(source).isEqualNode(toXmlDocument(result)), "The actual is: " + result);
+ // test pretty-print
+ assertEquals(serializerWrite(toXmlDocument(source), true), expected);
+ }
+
+ /*
+ * test whitespace and element, nested xml:space property.
+ */
+ @DataProvider(name = "xml-data-whitespace-xslt")
+ public Object[][] whitespaceXSLT() throws Exception {
+ return new Object[][] {
+ { "xmltest5.xml", "xmltest5xslt.out" },
+ { "xmltest7.xml", "xmltest7xslt.out" } };
+ }
+
+ /*
+ * @bug 8087303
+ * Test the transformer shall format the output but keep all
+ * whitespace text node even if xml:space="preserve"
+ *
+ */
+ @Test(dataProvider = "xml-data-whitespace-xslt")
+ public void testWhitespaceWithTransformer(String sourceFile, String expectedFile) throws Exception {
+ String source = read(sourceFile);
+ String expected = read(expectedFile);
+ // test it's no change if no pretty-print
+ String result = transform(toXmlDocument(source), false);
+ assertTrue(toXmlDocument(source).isEqualNode(toXmlDocument(result)), "The actual is: " + result);
+ // test pretty-print
+ assertEquals(transform(toXmlDocument(source), true).replaceAll("\r\n", "\n"), expected);
+ }
+
/*
* test block element, inline element, text, and mixed elements.
*/
@DataProvider(name = "html-data")
public Object[][] htmlData() throws Exception {
return new Object[][] {
- { read("htmltest1.xml"), read("htmltest1.out") },
- { read("htmltest2.xml"), read("htmltest2.out") },
- { read("htmltest3.xml"), read("htmltest3.out") },
- { read("htmltest4.xml"), read("htmltest4.out") },
- { read("htmltest5.xml"), read("htmltest5.out") },
- { read("htmltest6.xml"), read("htmltest6.out") } };
+ { "htmltest1.xml", "htmltest1.out" },
+ { "htmltest2.xml", "htmltest2.out" },
+ { "htmltest3.xml", "htmltest3.out" },
+ { "htmltest4.xml", "htmltest4.out" },
+ { "htmltest5.xml", "htmltest5.out" },
+ { "htmltest6.xml", "htmltest6.out" },
+ /* @bug 8174025, test whitespace between inline elements */
+ { "htmltest7.xml", "htmltest7.out" } };
}
/*
@@ -146,7 +223,9 @@ public class PrettyPrintTest {
*
*/
@Test(dataProvider = "html-data")
- public void testTransformToHTML(String source, String expected) throws Exception {
+ public void testTransformToHTML(String sourceFile, String expectedFile) throws Exception {
+ String source = read(sourceFile);
+ String expected = read(expectedFile);
// test it's no change if no pretty-print
StringWriter writer = new StringWriter();
getTransformer(true, false).transform(new StreamSource(new StringReader(source)), new StreamResult(writer));
@@ -158,6 +237,27 @@ public class PrettyPrintTest {
assertEquals(writer.toString().replaceAll("\r\n", "\n"), expected);
}
+ /*
+ * @bug 8174025
+ * Test the serializer can handle correctly.
+ *
+ */
+ @Test
+ public void testDisableOutputEscaping() throws Exception {
+ final String xsl ="generate-catalog.xsl";
+ final String xml ="simple-entity-resolver-config.xml";
+ final String expectedOutput ="simple-entity-resolver-config-transformed.xml";
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTemplates(new StreamSource(new StringReader(read(xsl)))).newTransformer();
+
+ String key = "schemaBase";
+ String value = "schemas";
+ transformer.setParameter(key, value);
+ StringWriter writer = new StringWriter();
+ transformer.transform(new StreamSource(new StringReader(read(xml))), new StreamResult(writer));
+ assertEquals(writer.toString().replaceAll("\r\n", "\n"), read(expectedOutput));
+ }
+
@Test
public void testLSSerializerFormatPrettyPrint() {
@@ -298,6 +398,9 @@ public class PrettyPrintTest {
Document doc = db.newDocument();
Node root = doc.createElement("root");
doc.appendChild(root);
+ root.appendChild(doc.createTextNode("\n"));
+ root.appendChild(doc.createTextNode("\n"));
+ root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode("t"));
root.appendChild(doc.createTextNode("\n"));
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/generate-catalog.xsl b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/generate-catalog.xsl
new file mode 100644
index 00000000000..e1b8e75171a
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/generate-catalog.xsl
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ <system systemId="
+
+ " uri="
+
+ " />
+
+
+
+
\ No newline at end of file
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest1.xml b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest1.xml
index 50460626a7b..c0959b46dc8 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest1.xml
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest1.xml
@@ -1 +1 @@
-Java Tutorials and Examples 1en-us
\ No newline at end of file
+Java Tutorials and Examples 1en-us
\ No newline at end of file
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest7.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest7.out
new file mode 100644
index 00000000000..2ce8445a6dc
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/htmltest7.out
@@ -0,0 +1,7 @@
+
+
+
\ No newline at end of file
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2.out
index a0d94368a3d..8a7d8fb0d18 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2.out
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2.out
@@ -1,19 +1,30 @@
t
t
-
+
+
t
-
-
-
+
+
+
+
+
+
t
+
t
+
t
+
+
+
+
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2ls.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2ls.out
new file mode 100644
index 00000000000..92e2d1f41e0
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/nodetest2ls.out
@@ -0,0 +1,18 @@
+
+ tt
+
+ t
+
+
+
+
+ t
+
+ t
+
+ t
+
+
+
+
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config-transformed.xml b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config-transformed.xml
new file mode 100644
index 00000000000..238b5e2a2ac
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config-transformed.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config.xml b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config.xml
new file mode 100644
index 00000000000..9156728e13d
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/simple-entity-resolver-config.xml
@@ -0,0 +1,20 @@
+
+
+
+
+ Example 1 Schema Type library 10.0
+ >-//Oracle//Example 1 Schema Type library 10.0//EN
+ http://www.example.test/oracle/schema/example1.xsd
+ META-INF/example1.xsd
+
+
+ Example 2 Schema Type library 10.0
+ >-//Oracle//Example 2 Schema Type library 10.0//EN
+ http://www.example.test/oracle/schema/example2.xsd
+ META-INF/example2.xsd
+
+
\ No newline at end of file
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5ls.out
similarity index 100%
rename from jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5.out
rename to jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5ls.out
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5xslt.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5xslt.out
new file mode 100644
index 00000000000..4178e8ea9c2
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest5xslt.out
@@ -0,0 +1,15 @@
+
+
+
+ Java Tutorials and Examples 1
+
+ en-us
+
+
+
+
+
+
+
+
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7ls.out
similarity index 100%
rename from jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7.out
rename to jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7ls.out
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7xslt.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7xslt.out
new file mode 100644
index 00000000000..06296cddd1d
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest7xslt.out
@@ -0,0 +1,17 @@
+
+ Java
+
+ 5
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.out b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.out
index 621263fbe19..b62fff27a78 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.out
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.out
@@ -1,25 +1,20 @@
-
- t
+ t
-
-t
+ t
-
- t
+ t
-
- t
+ t
t
-
- t
+ t
diff --git a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.xml b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.xml
index e9c1c477d3a..6b9c54af8ed 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.xml
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/prettyprint/xmltest8.xml
@@ -2,14 +2,7 @@
t
t
- t
-
-
- t
-
- t
-
+ t
+ tt
t
-
-
-
+
diff --git a/jaxp/test/javax/xml/jaxp/unittest/dom/ls/LSSerializerTest.java b/jaxp/test/javax/xml/jaxp/unittest/dom/ls/LSSerializerTest.java
index 9068969b318..50c79a962a6 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/dom/ls/LSSerializerTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/dom/ls/LSSerializerTest.java
@@ -279,11 +279,11 @@ public class LSSerializerTest {
"\n" +
" &name1;Jo Smith\n" +
" b &name2;Jo Smith &name1;Jo Smith b\n" +
- " &name;Jo Smith \n" +
+ " &name;Jo Smith \n" +
" &ele1;d\n" +
- " &ele2;eee \n" +
+ " &ele2;eee \n" +
" <att>\n" +
- " &ele; g\n" +
+ " &ele; g\n" +
" &ele2;\n" +
"\n");
@@ -301,7 +301,7 @@ public class LSSerializerTest {
"\n" +
" &name;Jo Smith\n" +
" b &name;Jo Smith &name;Jo Smith b\n" +
- " &name;Jo Smith \n" +
+ " &name;Jo Smith \n" +
" \n" +
" \n" +
" text\n" +
diff --git a/jaxp/test/javax/xml/jaxp/unittest/parsers/BaseParsingTest.java b/jaxp/test/javax/xml/jaxp/unittest/parsers/BaseParsingTest.java
new file mode 100644
index 00000000000..2d15fda1b0e
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/parsers/BaseParsingTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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 parsers;
+
+import java.io.StringReader;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+import org.xml.sax.InputSource;
+
+/**
+ * @test
+ * @bug 8169450
+ * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
+ * @run testng/othervm -DrunSecMngr=true parsers.BaseParsingTest
+ * @run testng/othervm parsers.BaseParsingTest
+ * @summary Tests that verify base parsing
+ */
+@Listeners({jaxp.library.BasePolicy.class})
+public class BaseParsingTest {
+
+ @DataProvider(name = "xmlDeclarations")
+ public static Object[][] xmlDeclarations() {
+ return new Object[][]{
+ {"t"},
+ {"t"},
+ {"t"},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"t"},
+ {"t"},
+ {"t"},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""},
+ {"\n"
+ + "\n"
+ + " t\n"
+ + ""}
+ };
+ }
+
+ /**
+ * @bug 8169450
+ * Verifies that the parser successfully parses the declarations provided in
+ * xmlDeclarations. Exception would otherwise be thrown as reported in 8169450.
+ *
+ * XML Declaration according to https://www.w3.org/TR/REC-xml/#NT-XMLDecl
+ * [23] XMLDecl ::= ''
+ * [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
+ * [25] Eq ::= S? '=' S? [26] VersionNum ::= '1.' [0-9]+
+ *
+ * @param xml the test xml
+ * @throws Exception if the parser fails to parse the xml
+ */
+ @Test(dataProvider = "xmlDeclarations")
+ public void test(String xml) throws Exception {
+ XMLInputFactory xif = XMLInputFactory.newDefaultFactory();
+ XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
+ while (xsr.hasNext()) {
+ xsr.next();
+ }
+ }
+
+ /**
+ * @bug 8169450
+ * This particular issue does not appear in DOM parsing since the spaces are
+ * normalized during version detection. This test case then serves as a guard
+ * against such an issue from occuring in the version detection.
+ *
+ * @param xml the test xml
+ * @throws Exception if the parser fails to parse the xml
+ */
+ @Test(dataProvider = "xmlDeclarations")
+ public void testWithDOM(String xml) throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ db.parse(new InputSource(new StringReader(xml)));
+ }
+}
diff --git a/jaxp/test/javax/xml/jaxp/unittest/parsers/Bug6341770.java b/jaxp/test/javax/xml/jaxp/unittest/parsers/Bug6341770.java
index 942e7ffaed8..1bf27aa09a0 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/parsers/Bug6341770.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/parsers/Bug6341770.java
@@ -23,6 +23,7 @@
package parsers;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission;
import java.io.File;
@@ -61,7 +62,7 @@ public class Bug6341770 {
return;
}
try {
- File dir = new File(ALPHA);
+ File dir = new File(USER_DIR + ALPHA);
dir.delete();
dir.mkdir();
File main = new File(dir, "main.xml");
diff --git a/jaxp/test/javax/xml/jaxp/unittest/sax/Bug7057778Test.java b/jaxp/test/javax/xml/jaxp/unittest/sax/Bug7057778Test.java
index 4bd69f09765..be6dbc986f8 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/sax/Bug7057778Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/sax/Bug7057778Test.java
@@ -23,6 +23,7 @@
package sax;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.getSystemProperty;
import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission;
@@ -69,7 +70,7 @@ public class Bug7057778Test {
@Test
public void testParse() {
File src = new File(getClass().getResource(xml).getFile());
- File dst = new File(xml1);
+ File dst = new File(USER_DIR + xml1);
try {
copyFile(src, dst);
SAXParserFactory spf = SAXParserFactory.newInstance();
diff --git a/jaxp/test/javax/xml/jaxp/unittest/sax/SymbolTableResetTest.java b/jaxp/test/javax/xml/jaxp/unittest/sax/SymbolTableResetTest.java
new file mode 100644
index 00000000000..d54086361eb
--- /dev/null
+++ b/jaxp/test/javax/xml/jaxp/unittest/sax/SymbolTableResetTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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 sax;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.testng.Assert;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.helpers.DefaultHandler;
+
+/*
+ * @test
+ * @bug 8173390
+ * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
+ * @run testng/othervm -DrunSecMngr=true sax.SymbolTableResetTest
+ * @run testng/othervm sax.SymbolTableResetTest
+ * @summary Test that SAXParser reallocates symbol table during
+ * subsequent parse operations
+ */
+@Listeners({jaxp.library.BasePolicy.class})
+public class SymbolTableResetTest {
+
+ /*
+ * Test mimics the SAXParser usage in SAAJ-RI that reuses the
+ * parsers from the internal pool. To avoid memory leaks, symbol
+ * table associated with the parser should be reallocated during each
+ * parse() operation.
+ */
+ @Test
+ public void testReset() throws Exception {
+ // Dummy xml input for parser
+ String input = "Test";
+ // Create SAXParser
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ SAXParser p = spf.newSAXParser();
+ // First parse iteration
+ p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
+ // Get first symbol table reference
+ Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY);
+ p.reset();
+ // Second parse iteration
+ p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
+ // Get second symbol table reference
+ Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY);
+ // Symbol table references should be different
+ Assert.assertNotSame(symTable1, symTable2, "Symbol table references");
+ }
+
+ // Symbol table property
+ private static final String SYMBOL_TABLE_PROPERTY = "http://apache.org/xml/properties/internal/symbol-table";
+
+}
diff --git a/jaxp/test/javax/xml/jaxp/unittest/stream/Bug6688002Test.java b/jaxp/test/javax/xml/jaxp/unittest/stream/Bug6688002Test.java
index 1c4ac758575..1d1f728009d 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/stream/Bug6688002Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/stream/Bug6688002Test.java
@@ -23,6 +23,8 @@
package stream;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
@@ -67,15 +69,15 @@ public class Bug6688002Test {
}
public class MyRunnable implements Runnable {
- final int no;
+ final String no;
MyRunnable(int no) {
- this.no = no;
+ this.no = String.valueOf(no);
}
public void run() {
try {
- FileOutputStream fos = new FileOutputStream("" + no);
+ FileOutputStream fos = new FileOutputStream(USER_DIR + no);
XMLStreamWriter w = getWriter(fos);
// System.out.println("Writer="+w+" Thread="+Thread.currentThread());
w.writeStartDocument();
@@ -89,7 +91,7 @@ public class Bug6688002Test {
w.close();
fos.close();
- FileInputStream fis = new FileInputStream("" + no);
+ FileInputStream fis = new FileInputStream(USER_DIR + no);
XMLStreamReader r = getReader(fis);
while (r.hasNext()) {
r.next();
diff --git a/jaxp/test/javax/xml/jaxp/unittest/stream/XMLEventWriterTest/ReaderToWriterTest.java b/jaxp/test/javax/xml/jaxp/unittest/stream/XMLEventWriterTest/ReaderToWriterTest.java
index 3bd3ca25296..28b871afcd9 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/stream/XMLEventWriterTest/ReaderToWriterTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/stream/XMLEventWriterTest/ReaderToWriterTest.java
@@ -23,6 +23,8 @@
package stream.XMLEventWriterTest;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -58,7 +60,7 @@ public class ReaderToWriterTest {
private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance();
private static final String INPUT_FILE = "W2JDLR4002TestService.wsdl.data";
- private static final String OUTPUT_FILE = "Encoded.wsdl";
+ private static final String OUTPUT_FILE = USER_DIR + "Encoded.wsdl";
/**
* Unit test for writing namespaces when namespaceURI == null.
@@ -126,7 +128,7 @@ public class ReaderToWriterTest {
try {
InputStream in = getClass().getResourceAsStream("ReaderToWriterTest.wsdl");
- OutputStream out = new FileOutputStream("ReaderToWriterTest-out.xml");
+ OutputStream out = new FileOutputStream(USER_DIR + "ReaderToWriterTest-out.xml");
XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
XMLEventWriter writer = XML_OUTPUT_FACTORY.createXMLEventWriter(out, "UTF-8");
diff --git a/jaxp/test/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/WriterTest.java b/jaxp/test/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/WriterTest.java
index 7e681e343c4..abb9957a256 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/WriterTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/stream/XMLStreamWriterTest/WriterTest.java
@@ -23,6 +23,8 @@
package stream.XMLStreamWriterTest;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -84,7 +86,7 @@ public class WriterTest {
System.out.println("Test StreamWriter with out any namespace functionality");
try {
- String outputFile = files[0] + ".out";
+ String outputFile = USER_DIR + files[0] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -98,7 +100,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[0] + ".out", files[0] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[0] + ".org"));
} catch (Exception ex) {
Assert.fail("testOne Failed " + ex);
@@ -113,7 +115,7 @@ public class WriterTest {
System.out.println("Test StreamWriter's Namespace Context");
try {
- String outputFile = files[1] + ".out";
+ String outputFile = USER_DIR + files[1] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(System.out);
@@ -157,7 +159,7 @@ public class WriterTest {
System.out.println("Test StreamWriter for proper element sequence.");
try {
- String outputFile = files[2] + ".out";
+ String outputFile = USER_DIR + files[2] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -172,7 +174,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[2] + ".out", files[2] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[2] + ".org"));
} catch (Exception ex) {
Assert.fail("testThree Failed " + ex);
@@ -188,7 +190,7 @@ public class WriterTest {
try {
- String outputFile = files[3] + ".out";
+ String outputFile = USER_DIR + files[3] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -205,7 +207,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[3] + ".out", files[3] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[3] + ".org"));
} catch (Exception ex) {
Assert.fail("testFour Failed " + ex);
@@ -221,7 +223,7 @@ public class WriterTest {
try {
- String outputFile = files[4] + ".out";
+ String outputFile = USER_DIR + files[4] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(System.out);
@@ -265,7 +267,7 @@ public class WriterTest {
xtw.writeEndDocument();
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[4] + ".out", files[4] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[4] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testFive Failed " + ex);
@@ -281,7 +283,7 @@ public class WriterTest {
try {
- String outputFile = files[5] + ".out";
+ String outputFile = USER_DIR + files[5] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(System.out);
@@ -325,7 +327,7 @@ public class WriterTest {
xtw.writeEndDocument();
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[5] + ".out", files[5] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[5] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testSix Failed " + ex);
@@ -341,7 +343,7 @@ public class WriterTest {
try {
- String outputFile = files[6] + ".out";
+ String outputFile = USER_DIR + files[6] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -374,7 +376,7 @@ public class WriterTest {
xtw.writeEndDocument();
xtw.flush();
xtw.close();
- Assert.assertTrue(checkResults(files[6] + ".out", files[6] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[6] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testSeven Failed " + ex);
@@ -390,7 +392,7 @@ public class WriterTest {
try {
- String outputFile = files[7] + ".out";
+ String outputFile = USER_DIR + files[7] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -424,7 +426,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
// check against testSeven.xml.org
- Assert.assertTrue(checkResults(files[7] + ".out", files[7] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[7] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
ex.printStackTrace();
@@ -442,7 +444,7 @@ public class WriterTest {
try {
- String outputFile = files[8] + ".out";
+ String outputFile = USER_DIR + files[8] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -476,7 +478,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
// check against testSeven.xml.org
- Assert.assertTrue(checkResults(files[8] + ".out", files[7] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[7] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testNine Failed " + ex);
@@ -491,7 +493,7 @@ public class WriterTest {
System.out.println("Test StreamWriter supplied with no namespace information and" + "isRepairingNamespace is set to true.");
try {
- String outputFile = files[9] + ".out";
+ String outputFile = USER_DIR + files[9] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -542,7 +544,7 @@ public class WriterTest {
System.out.println("Test StreamWriter supplied with namespace information passed through startElement and" + "isRepairingNamespace is set to true.");
try {
- String outputFile = files[10] + ".out";
+ String outputFile = USER_DIR + files[10] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -576,7 +578,7 @@ public class WriterTest {
xtw.flush();
xtw.close();
// check against testSeven.xml.org
- Assert.assertTrue(checkResults(files[10] + ".out", files[7] + ".org"));
+ Assert.assertTrue(checkResults(outputFile, files[7] + ".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testEleven Failed " + ex);
@@ -592,7 +594,7 @@ public class WriterTest {
try {
- String outputFile = files[11] + ".out";
+ String outputFile = USER_DIR + files[11] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -643,7 +645,7 @@ public class WriterTest {
try {
- String outputFile = files[12] + ".out";
+ String outputFile = USER_DIR + files[12] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
@@ -695,7 +697,7 @@ public class WriterTest {
try {
- String outputFile = files[14] + ".out";
+ String outputFile = USER_DIR + files[14] + ".out";
System.out.println("Writing output to " + outputFile);
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
xtw = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4693341Test.java b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4693341Test.java
index 2b2a1e94506..1e4266d65e7 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4693341Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4693341Test.java
@@ -23,6 +23,8 @@
package transform;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -55,7 +57,7 @@ public class Bug4693341Test {
// save dtd file to current working directory to avoid writing into source repository
public void copyDTDtoWorkDir() throws IOException {
try (FileInputStream dtdres = new FileInputStream(getClass().getResource("Bug4693341.dtd").getPath());
- FileOutputStream dtdwork = new FileOutputStream("Bug4693341.dtd");) {
+ FileOutputStream dtdwork = new FileOutputStream(USER_DIR + "Bug4693341.dtd");) {
int n;
byte[] buffer = new byte[1024];
while((n = dtdres.read(buffer)) > -1) {
@@ -71,7 +73,7 @@ public class Bug4693341Test {
copyDTDtoWorkDir();
- File outf = new File("Bug4693341.out");
+ File outf = new File(USER_DIR + "Bug4693341.out");
StreamResult result = new StreamResult(new FileOutputStream(outf));
String in = getClass().getResource("Bug4693341.xml").getPath();
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4892774.java b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4892774.java
index cb92eb762ed..0419c1cf8bc 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4892774.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug4892774.java
@@ -23,6 +23,8 @@
package transform;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.File;
import javax.xml.transform.Source;
@@ -58,7 +60,7 @@ public class Bug4892774 {
private final String XML_FILE = "catalog.xml";
private final String XML10_FILE = "catalog_10.xml"; // 1.0 version document
- private final String TEMP_FILE = "tmp.xml";
+ private final String TEMP_FILE = USER_DIR + "tmp.xml";
private final String EXPECTED_VERSION = "1.1";
static private Transformer idTransform = null;
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug6216226Test.java b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug6216226Test.java
index 7031585a864..9ba16dbc9c1 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/Bug6216226Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/Bug6216226Test.java
@@ -23,6 +23,7 @@
package transform;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.runWithTmpPermission;
import java.io.File;
@@ -52,7 +53,7 @@ public class Bug6216226Test {
@Test
public final void test() {
try {
- File test = new File("bug6216226.txt");
+ File test = new File(USER_DIR + "bug6216226.txt");
TransformerFactory tf = TransformerFactory.newInstance();
Transformer xformer = tf.newTransformer();
StringReader st = new StringReader("");
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/CR6935697Test.java b/jaxp/test/javax/xml/jaxp/unittest/transform/CR6935697Test.java
index db8d8721d2e..fe65ee0e7a9 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/CR6935697Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/CR6935697Test.java
@@ -23,6 +23,8 @@
package transform;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.FileOutputStream;
import javax.xml.transform.Result;
@@ -65,7 +67,7 @@ public class CR6935697Test {
Transformer xformer = template.newTransformer();
// Prepare the input and output files
Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
- Result result = new StreamResult(new FileOutputStream(outFilename));
+ Result result = new StreamResult(new FileOutputStream(USER_DIR + outFilename));
// Apply the xsl file to the source file and write the result to the
// output file
xformer.transform(source, result);
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java b/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java
index 87360daf486..3f99410869b 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java
@@ -23,6 +23,7 @@
package transform;
+import java.io.FilePermission;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
@@ -46,6 +47,7 @@ import static org.testng.Assert.assertEquals;
import static jaxp.library.JAXPTestUtilities.runWithAllPerm;
import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
import static jaxp.library.JAXPTestUtilities.setSystemProperty;
+import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission;
import static jaxp.library.JAXPTestUtilities.getSystemProperty;
/*
@@ -77,7 +79,9 @@ public class XSLTFunctionsTest {
Transformer t = tf.newTransformer(new StreamSource(new StringReader(xsl)));
//Transform the xml
- t.transform(new StreamSource(new StringReader(xml)), new StreamResult(new StringWriter()));
+ tryRunWithTmpPermission(
+ () -> t.transform(new StreamSource(new StringReader(xml)), new StreamResult(new StringWriter())),
+ new FilePermission(output, "write"), new FilePermission(redirect, "write"));
// Verifies that the output is redirected successfully
String userDir = getSystemProperty("user.dir");
diff --git a/jaxp/test/javax/xml/jaxp/unittest/transform/util/TransformerUtil.java b/jaxp/test/javax/xml/jaxp/unittest/transform/util/TransformerUtil.java
index 61d7bfe09db..3294aeb93ae 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/util/TransformerUtil.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/util/TransformerUtil.java
@@ -23,6 +23,8 @@
package transform.util;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
@@ -34,7 +36,7 @@ public abstract class TransformerUtil {
protected String type;
- protected final String TEMP_FILE = "tmp.xml";
+ protected final String TEMP_FILE = USER_DIR + "tmp.xml";
public abstract Source prepareSource(InputStream is) throws Exception;
diff --git a/jaxp/test/javax/xml/jaxp/unittest/validation/CR6708840Test.java b/jaxp/test/javax/xml/jaxp/unittest/validation/CR6708840Test.java
index d3a0f1ef40c..71f55a4f3c4 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/validation/CR6708840Test.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/validation/CR6708840Test.java
@@ -23,6 +23,8 @@
package validation;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
+
import java.io.File;
import java.io.FileWriter;
@@ -122,7 +124,7 @@ public class CR6708840Test {
Validator schemaValidator = schemaGrammar.newValidator();
Source staxSrc = new StAXSource(staxReader);
- File resultFile = new File("gMonths.result.xml");
+ File resultFile = new File(USER_DIR + "gMonths.result.xml");
if (resultFile.exists()) {
resultFile.delete();
}
diff --git a/jaxp/test/javax/xml/jaxp/unittest/validation/ValidatorTest.java b/jaxp/test/javax/xml/jaxp/unittest/validation/ValidatorTest.java
index 40ca0cc8d3a..22317b325bb 100644
--- a/jaxp/test/javax/xml/jaxp/unittest/validation/ValidatorTest.java
+++ b/jaxp/test/javax/xml/jaxp/unittest/validation/ValidatorTest.java
@@ -23,6 +23,7 @@
package validation;
+import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.runWithTmpPermission;
import java.io.File;
@@ -61,7 +62,7 @@ public class ValidatorTest {
File resultFile = null;
try {
- resultFile = new File("stax.result");
+ resultFile = new File(USER_DIR + "stax.result");
if (resultFile.exists()) {
resultFile.delete();
}
@@ -88,7 +89,7 @@ public class ValidatorTest {
File resultFile = null;
try {
- resultFile = new File("stax.result");
+ resultFile = new File(USER_DIR + "stax.result");
if (resultFile.exists()) {
resultFile.delete();
}
@@ -117,7 +118,7 @@ public class ValidatorTest {
// test valid gMonths
File resultFile = null;
try {
- resultFile = new File("gMonths.result.xml");
+ resultFile = new File(USER_DIR + "gMonths.result.xml");
if (resultFile.exists()) {
resultFile.delete();
}
@@ -144,7 +145,7 @@ public class ValidatorTest {
// test invalid gMonths
File invalidResultFile = null;
try {
- invalidResultFile = new File("gMonths-invalid.result.xml");
+ invalidResultFile = new File(USER_DIR + "gMonths-invalid.result.xml");
if (invalidResultFile.exists()) {
invalidResultFile.delete();
}
diff --git a/jaxws/.hgtags b/jaxws/.hgtags
index f16d9a59b2b..926c255ad54 100644
--- a/jaxws/.hgtags
+++ b/jaxws/.hgtags
@@ -399,6 +399,7 @@ c8c9c334743caf8155c9809b6b4ac315d3a66476 jdk-9+148
c48b4d4768b1c2b8fe5d1a844ca13732e5dfbe2a jdk-9+151
6f8fb1cf7e5f61c40dcc3654f9a623c505f6de1f jdk-9+152
7a532a9a227137155b905341d4b99939db51220e jdk-9+153
+34af95c7dbff74f3448fcdb7d745524e8a1cc88a jdk-10+0
34af95c7dbff74f3448fcdb7d745524e8a1cc88a jdk-9+154
9b9918656c97724fd89c04a8547043bbd37f5935 jdk-9+155
7c829eba781409b4fe15392639289af1553dcf63 jdk-9+156
diff --git a/jaxws/.jcheck/conf b/jaxws/.jcheck/conf
index 5c6f62dc12c..b2581358014 100644
--- a/jaxws/.jcheck/conf
+++ b/jaxws/.jcheck/conf
@@ -1 +1 @@
-project=jdk9
+project=jdk10
diff --git a/jdk/.hgtags b/jdk/.hgtags
index 5a7c6ba2850..ce164d54c23 100644
--- a/jdk/.hgtags
+++ b/jdk/.hgtags
@@ -396,5 +396,9 @@ c41140100bf1e5c10c7b8f3bde91c16eff7485f5 jdk-9+147
d27bab22ff62823902d93d1d35ca397cfd50d059 jdk-9+151
a20f2cf90762673e1bc4980fd6597e70a2578045 jdk-9+152
1c4411322327aea3f91011ec3977a12a05b09629 jdk-9+153
+f2325d80b37c2817e15039bf64189a08e29c6d39 jdk-10+0
c97e7a8b8da062b9070df442f9cf308e10845fb7 jdk-9+154
e170c858888e83d5c0994504599b6ed7a1fb0cfc jdk-9+155
+7d64e541a6c04c714bcad4c8b553db912f827cd5 jdk-9+156
+fdfa7b2fe9a7db06792eae20f97748f3e85bb83a jdk-9+157
+c476ca73750698fa5654e101af699ee45db38e2a jdk-9+158
diff --git a/jdk/.jcheck/conf b/jdk/.jcheck/conf
index 5c6f62dc12c..b2581358014 100644
--- a/jdk/.jcheck/conf
+++ b/jdk/.jcheck/conf
@@ -1 +1 @@
-project=jdk9
+project=jdk10
diff --git a/jdk/make/CompileModuleTools.gmk b/jdk/make/CompileModuleTools.gmk
index 2bfe520b233..4a9fcdc9809 100644
--- a/jdk/make/CompileModuleTools.gmk
+++ b/jdk/make/CompileModuleTools.gmk
@@ -37,5 +37,7 @@ $(eval $(call SetupJavaCompilation,BUILD_JIGSAW_TOOLS, \
build/tools/jigsaw, \
BIN := $(TOOLS_CLASSES_DIR), \
ADD_JAVAC_FLAGS := \
+ --add-modules jdk.jdeps \
--add-exports java.base/jdk.internal.module=ALL-UNNAMED \
+ --add-exports jdk.jdeps/com.sun.tools.jdeps=ALL-UNNAMED \
))
diff --git a/jdk/make/GenerateModuleSummary.gmk b/jdk/make/GenerateModuleSummary.gmk
index 38d9985c263..9f52ed37a74 100644
--- a/jdk/make/GenerateModuleSummary.gmk
+++ b/jdk/make/GenerateModuleSummary.gmk
@@ -31,11 +31,16 @@ include MakeBase.gmk
include ModuleTools.gmk
GENGRAPHS_DIR := $(IMAGES_OUTPUTDIR)/gengraphs
+SPEC_DOTFILES_DIR := $(IMAGES_OUTPUTDIR)/spec-dotfiles
TOOLS_MODULE_SRCDIR := $(JDK_TOPDIR)/make/src/classes/build/tools/jigsaw
$(GENGRAPHS_DIR)/jdk.dot: $(BUILD_JIGSAW_TOOLS)
$(MKDIR) -p $(@D)
- $(TOOL_GENGRAPHS) $(GENGRAPHS_DIR)
+ $(TOOL_GENGRAPHS) --output $(GENGRAPHS_DIR)
+
+$(SPEC_DOTFILES_DIR)/java.se.dot: $(BUILD_JIGSAW_TOOLS)
+ $(MKDIR) -p $(@D)
+ $(TOOL_GENGRAPHS) --spec --output $(SPEC_DOTFILES_DIR)
$(GENGRAPHS_DIR)/technology-summary.html: $(TOOLS_MODULE_SRCDIR)/technology-summary.html
$(install-file)
@@ -44,4 +49,4 @@ $(GENGRAPHS_DIR)/module-summary.html: $(BUILD_JIGSAW_TOOLS) $(GENGRAPHS_DIR)/tec
$(MKDIR) -p $(@D)
$(TOOL_MODULESUMMARY) -o $@ --module-path $(IMAGES_OUTPUTDIR)/jmods
-all: $(GENGRAPHS_DIR)/jdk.dot $(GENGRAPHS_DIR)/module-summary.html
+all: $(GENGRAPHS_DIR)/jdk.dot $(GENGRAPHS_DIR)/module-summary.html $(SPEC_DOTFILES_DIR)/java.se.dot
diff --git a/jdk/make/ModuleTools.gmk b/jdk/make/ModuleTools.gmk
index 71ca1cf8eaa..45bfbae630e 100644
--- a/jdk/make/ModuleTools.gmk
+++ b/jdk/make/ModuleTools.gmk
@@ -36,6 +36,8 @@ BUILD_TOOLS_JDK := $(call SetupJavaCompilationCompileTarget, \
BUILD_JIGSAW_TOOLS, $(TOOLS_CLASSES_DIR))
TOOL_GENGRAPHS := $(BUILD_JAVA) -esa -ea -cp $(TOOLS_CLASSES_DIR) \
+ --add-modules jdk.jdeps \
+ --add-exports jdk.jdeps/com.sun.tools.jdeps=ALL-UNNAMED \
build.tools.jigsaw.GenGraphs
TOOL_MODULESUMMARY := $(BUILD_JAVA) -esa -ea -cp $(TOOLS_CLASSES_DIR) \
diff --git a/jdk/make/gensrc/GensrcMisc.gmk b/jdk/make/gensrc/GensrcMisc.gmk
index 6b5dcf9e6b6..9a03f118b82 100644
--- a/jdk/make/gensrc/GensrcMisc.gmk
+++ b/jdk/make/gensrc/GensrcMisc.gmk
@@ -116,11 +116,13 @@ else
JCE_DEFAULT_POLICY = limited
endif
-$(eval $(call SetupTextFileProcessing, BUILD_JCESECURITY_JAVA, \
- SOURCE_FILES := $(JDK_TOPDIR)/src/java.base/share/classes/javax/crypto/JceSecurity.java.template, \
- OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/javax/crypto/JceSecurity.java, \
- REPLACEMENTS := \
+ifneq ($(wildcard $(JDK_TOPDIR)/src/java.base/share/classes/javax/crypto/JceSecurity.java.template), )
+ $(eval $(call SetupTextFileProcessing, BUILD_JCESECURITY_JAVA, \
+ SOURCE_FILES := $(JDK_TOPDIR)/src/java.base/share/classes/javax/crypto/JceSecurity.java.template, \
+ OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/javax/crypto/JceSecurity.java, \
+ REPLACEMENTS := \
@@JCE_DEFAULT_POLICY@@ => $(JCE_DEFAULT_POLICY), \
-))
+ ))
-GENSRC_JAVA_BASE += $(BUILD_JCESECURITY_JAVA)
+ GENSRC_JAVA_BASE += $(BUILD_JCESECURITY_JAVA)
+endif
diff --git a/jdk/make/launcher/Launcher-java.base.gmk b/jdk/make/launcher/Launcher-java.base.gmk
index f70d90029a6..06ccec771ea 100644
--- a/jdk/make/launcher/Launcher-java.base.gmk
+++ b/jdk/make/launcher/Launcher-java.base.gmk
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2016, 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
@@ -71,102 +71,37 @@ $(eval $(call SetupBuildLauncher, keytool, \
################################################################################
-BUILD_JEXEC :=
-BUILD_JEXEC_SRC :=
-BUILD_JEXEC_INC :=
-BUILD_JEXEC_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
-
-#
-# UNHANDLED:
-# - COMPILE_APPROACH = normal
-#
-
-#
-# jdk/make/java/Makefile
-#
-ifeq ($(OPENJDK_TARGET_OS), solaris)
- ifeq ($(OPENJDK_TARGET_CPU_BITS), 32)
- BUILD_JEXEC := 1
- endif
-endif
-
ifeq ($(OPENJDK_TARGET_OS), linux)
- BUILD_JEXEC := 1
-endif # OPENJDK_TARGET_OS
-
-#
-# jdk/make/java/jexec/Makefile
-#
-ifeq ($(BUILD_JEXEC), 1)
-
- ifeq ($(OPENJDK_TARGET_OS), windows)
- else ifeq ($(OPENJDK_TARGET_OS), macosx)
- BUILD_JEXEC_SRC := $(JDK_TOPDIR)/src/java.base/macosx/native/launcher
- else
- BUILD_JEXEC_SRC := $(JDK_TOPDIR)/src/java.base/unix/native/launcher
- endif
-
- ifeq ($(OPENJDK_TARGET_OS), linux)
- BUILD_JEXEC_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
- BUILD_JEXEC_INC += -I$(JDK_TOPDIR)/src/java.base/share/native/libjli
- endif
-endif
-
-#
-# Note that the two Makefile's seems to contradict each other,
-# and that src/macosx/bin/jexec.c seems unused
-#
-ifneq ($(BUILD_JEXEC_SRC), )
- $(eval $(call SetupNativeCompilation,BUILD_JEXEC, \
- SRC := $(BUILD_JEXEC_SRC), \
+ $(eval $(call SetupNativeCompilation, BUILD_JEXEC, \
+ SRC := $(JDK_TOPDIR)/src/$(MODULE)/unix/native/launcher, \
INCLUDE_FILES := jexec.c, \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKEXE) \
- $(BUILD_JEXEC_INC), \
+ -I$(JDK_TOPDIR)/src/$(MODULE)/share/native/libjli, \
CFLAGS_linux := -fPIC, \
CFLAGS_solaris := -KPIC, \
LDFLAGS := $(LDFLAGS_JDKEXE), \
OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jexec_obj, \
- OUTPUT_DIR := $(BUILD_JEXEC_DST_DIR), \
- PROGRAM := jexec))
+ OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
+ PROGRAM := jexec, \
+ ))
TARGETS += $(BUILD_JEXEC)
endif
################################################################################
-BUILD_JSPAWNHELPER :=
-BUILD_JSPAWNHELPER_SRC := $(JDK_TOPDIR)/src/java.base/unix/native/jspawnhelper
-JSPAWNHELPER_CFLAGS := -I$(JDK_TOPDIR)/src/java.base/unix/native/libjava
-BUILD_JSPAWNHELPER_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
-LINK_JSPAWNHELPER_OBJECTS := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc.o
-BUILD_JSPAWNHELPER_LDFLAGS :=
-
ifneq ($(findstring $(OPENJDK_TARGET_OS), macosx solaris aix), )
- BUILD_JSPAWNHELPER := 1
-endif
-
-ifeq ($(OPENJDK_TARGET_OS), macosx)
- BUILD_JSPAWNHELPER_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
-endif
-
-ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
- BUILD_JSPAWNHELPER_LDFLAGS += $(COMPILER_TARGET_BITS_FLAG)64
-endif
-
-ifeq ($(BUILD_JSPAWNHELPER), 1)
- $(eval $(call SetupNativeCompilation,BUILD_JSPAWNHELPER, \
- SRC := $(BUILD_JSPAWNHELPER_SRC), \
- INCLUDE_FILES := jspawnhelper.c, \
+ $(eval $(call SetupNativeCompilation, BUILD_JSPAWNHELPER, \
+ SRC := $(JDK_TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
OPTIMIZATION := LOW, \
- CFLAGS := $(CFLAGS_JDKEXE) $(JSPAWNHELPER_CFLAGS), \
- LDFLAGS := $(LDFLAGS_JDKEXE) $(BUILD_JSPAWNHELPER_LDFLAGS), \
- LIBS := $(LINK_JSPAWNHELPER_OBJECTS), \
+ CFLAGS := $(CFLAGS_JDKEXE) -I$(JDK_TOPDIR)/src/$(MODULE)/unix/native/libjava, \
+ EXTRA_OBJECT_FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc.o, \
+ LDFLAGS := $(LDFLAGS_JDKEXE), \
OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jspawnhelper, \
- OUTPUT_DIR := $(BUILD_JSPAWNHELPER_DST_DIR), \
- PROGRAM := jspawnhelper))
-
- $(BUILD_JSPAWNHELPER): $(LINK_JSPAWNHELPER_OBJECTS)
+ OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
+ PROGRAM := jspawnhelper, \
+ ))
TARGETS += $(BUILD_JSPAWNHELPER)
endif
diff --git a/jdk/make/launcher/Launcher-jdk.pack.gmk b/jdk/make/launcher/Launcher-jdk.pack.gmk
index 2ee08c767bf..4fe0fdf411f 100644
--- a/jdk/make/launcher/Launcher-jdk.pack.gmk
+++ b/jdk/make/launcher/Launcher-jdk.pack.gmk
@@ -44,7 +44,7 @@ ifeq ($(USE_EXTERNAL_LIBZ), true)
UNPACKEXE_CFLAGS += -DSYSTEM_ZLIB
UNPACKEXE_LIBS := -lz
else
- UNPACKEXE_CFLAGS += -I$(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib-1.2.8
+ UNPACKEXE_CFLAGS += -I$(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib
UNPACKEXE_ZIPOBJS := $(SUPPORT_OUTPUTDIR)/native/java.base/libzip/zcrc32$(OBJ_SUFFIX) \
$(SUPPORT_OUTPUTDIR)/native/java.base/libzip/deflate$(OBJ_SUFFIX) \
$(SUPPORT_OUTPUTDIR)/native/java.base/libzip/trees$(OBJ_SUFFIX) \
diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk
index 743422b0afe..9407f91b329 100644
--- a/jdk/make/lib/Awt2dLibraries.gmk
+++ b/jdk/make/lib/Awt2dLibraries.gmk
@@ -889,7 +889,7 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
LIBSPLASHSCREEN_LIBS :=
ifneq ($(USE_EXTERNAL_LIBZ), true)
- LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib-1.2.8
+ LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib
LIBSPLASHSCREEN_CFLAGS += $(ZLIB_CPPFLAGS)
endif
diff --git a/jdk/make/lib/CoreLibraries.gmk b/jdk/make/lib/CoreLibraries.gmk
index 3ec50824202..5bb93942087 100644
--- a/jdk/make/lib/CoreLibraries.gmk
+++ b/jdk/make/lib/CoreLibraries.gmk
@@ -202,7 +202,7 @@ $(BUILD_LIBJAVA): $(BUILD_LIBFDLIBM)
BUILD_LIBZIP_EXCLUDES :=
ifeq ($(USE_EXTERNAL_LIBZ), true)
- LIBZIP_EXCLUDES += zlib-1.2.8
+ LIBZIP_EXCLUDES += zlib
endif
BUILD_LIBZIP_REORDER :=
@@ -343,7 +343,7 @@ LIBJLI_CFLAGS += $(addprefix -I, $(LIBJLI_SRC_DIRS))
ifneq ($(USE_EXTERNAL_LIBZ), true)
LIBJLI_CFLAGS += $(ZLIB_CPPFLAGS)
LIBJLI_EXTRA_FILES += \
- $(addprefix $(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib-1.2.8/, \
+ $(addprefix $(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib/, \
inflate.c \
inftrees.c \
inffast.c \
diff --git a/jdk/make/lib/LibCommon.gmk b/jdk/make/lib/LibCommon.gmk
index f326842d0d9..4e1cab991aa 100644
--- a/jdk/make/lib/LibCommon.gmk
+++ b/jdk/make/lib/LibCommon.gmk
@@ -73,7 +73,7 @@ INSTALL_LIBRARIES_HERE := $(call FindLibDirForModule, $(MODULE))
ifeq ($(USE_EXTERNAL_LIBZ), true)
LIBZ := -lz
else
- ZLIB_CPPFLAGS := -I$(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib-1.2.8
+ ZLIB_CPPFLAGS := -I$(JDK_TOPDIR)/src/java.base/share/native/libzip/zlib
endif
###############################################################################
diff --git a/jdk/make/src/classes/build/tools/jigsaw/GenGraphs.java b/jdk/make/src/classes/build/tools/jigsaw/GenGraphs.java
index 4de7b5c719a..902185eef3a 100644
--- a/jdk/make/src/classes/build/tools/jigsaw/GenGraphs.java
+++ b/jdk/make/src/classes/build/tools/jigsaw/GenGraphs.java
@@ -25,29 +25,21 @@
package build.tools.jigsaw;
+import com.sun.tools.jdeps.ModuleDotGraph;
+import com.sun.tools.jdeps.ModuleDotGraph.DotGraphBuilder;
+
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
-import java.lang.module.ResolvedModule;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
-import java.util.function.Function;
-
-import static java.util.stream.Collectors.*;
-import static java.lang.module.ModuleDescriptor.Requires.Modifier.TRANSITIVE;
/**
* Generate the DOT file for a module graph for each module in the JDK
@@ -56,238 +48,100 @@ import static java.lang.module.ModuleDescriptor.Requires.Modifier.TRANSITIVE;
public class GenGraphs {
public static void main(String[] args) throws Exception {
+ Path dir = null;
+ boolean spec = false;
+ for (int i=0; i < args.length; i++) {
+ String arg = args[i];
+ if (arg.equals("--spec")) {
+ spec = true;
+ } else if (arg.equals("--output")) {
+ i++;
+ dir = i < args.length ? Paths.get(args[i]) : null;
+ } else if (arg.startsWith("-")) {
+ throw new IllegalArgumentException("Invalid option: " + arg);
+ }
+ }
- if (args.length != 1) {
- System.err.println("ERROR: specify the output directory");
+ if (dir == null) {
+ System.err.println("ERROR: must specify --output argument");
System.exit(1);
}
- Path dir = Paths.get(args[0]);
+
+ // setup and configure the dot graph attributes
+ initDotGraphAttributes();
Files.createDirectories(dir);
+ GenGraphs genGraphs = new GenGraphs(dir, spec);
+
+ // print dot file for each module
+ Map configurations = new HashMap<>();
+ Set modules = new HashSet<>();
ModuleFinder finder = ModuleFinder.ofSystem();
-
- Set javaSEModules
- = new TreeSet<>(finder.findAll().stream()
- .map(ModuleReference::descriptor)
- .filter(m -> (m.name().startsWith("java.") &&
- !m.name().equals("java.smartcardio")))
- .collect(toSet()));
- Set jdkModules
- = new TreeSet<>(finder.findAll().stream()
- .map(ModuleReference::descriptor)
- .filter(m -> !javaSEModules.contains(m))
- .collect(toSet()));
-
- GenGraphs genGraphs = new GenGraphs(dir, javaSEModules, jdkModules);
- Set mods = new HashSet<>();
- for (ModuleReference mref: finder.findAll()) {
- mods.add(mref.descriptor().name());
- genGraphs.genDotFile(mref);
+ for (ModuleReference mref : finder.findAll()) {
+ String name = (mref.descriptor().name());
+ modules.add(name);
+ if (genGraphs.accept(name, mref.descriptor())) {
+ configurations.put(name, Configuration.empty()
+ .resolve(finder,
+ ModuleFinder.of(),
+ Set.of(name)));
+ }
}
- // all modules
- genGraphs.genDotFile("jdk", mods);
+ if (genGraphs.accept("jdk", null)) {
+ // print a graph of all JDK modules
+ configurations.put("jdk", Configuration.empty()
+ .resolve(finder,
+ ModuleFinder.of(),
+ modules));
+ }
+ genGraphs.genDotFiles(configurations);
}
- private static final String ORANGE = "#e76f00";
- private static final String BLUE = "#437291";
- private static final String GRAY = "#dddddd";
-
- private static final String REEXPORTS = "";
- private static final String REQUIRES = "style=\"dashed\"";
- private static final String REQUIRES_BASE = "color=\"" + GRAY + "\"";
-
- private static final Map weights = new HashMap<>();
- private static final List> ranks = new ArrayList<>();
-
- private static void weight(String s, String t, int w) {
- weights.put(s + ":" + t, w);
- }
-
- private static int weightOf(String s, String t) {
- int w = weights.getOrDefault(s + ":" + t, 1);
- if (w != 1)
- return w;
- if (s.startsWith("java.") && t.startsWith("java."))
- return 10;
- return 1;
- }
-
- static {
+ static void initDotGraphAttributes() {
int h = 1000;
- weight("java.se", "java.sql.rowset", h * 10);
- weight("java.sql.rowset", "java.sql", h * 10);
- weight("java.sql", "java.xml", h * 10);
- weight("java.xml", "java.base", h * 10);
-
- ranks.add(Set.of("java.logging", "java.scripting", "java.xml"));
- ranks.add(Set.of("java.sql"));
- ranks.add(Set.of("java.compiler", "java.instrument"));
- ranks.add(Set.of("java.desktop", "java.management"));
- ranks.add(Set.of("java.corba", "java.xml.ws"));
- ranks.add(Set.of("java.xml.bind", "java.xml.ws.annotation"));
+ DotGraphBuilder.weight("java.se", "java.sql.rowset", h * 10);
+ DotGraphBuilder.weight("java.sql.rowset", "java.sql", h * 10);
+ DotGraphBuilder.weight("java.sql", "java.xml", h * 10);
+ DotGraphBuilder.weight("java.xml", "java.base", h * 10);
+ DotGraphBuilder.sameRankNodes(Set.of("java.logging", "java.scripting", "java.xml"));
+ DotGraphBuilder.sameRankNodes(Set.of("java.sql"));
+ DotGraphBuilder.sameRankNodes(Set.of("java.compiler", "java.instrument"));
+ DotGraphBuilder.sameRankNodes(Set.of("java.desktop", "java.management"));
+ DotGraphBuilder.sameRankNodes(Set.of("java.corba", "java.xml.ws"));
+ DotGraphBuilder.sameRankNodes(Set.of("java.xml.bind", "java.xml.ws.annotation"));
+ DotGraphBuilder.setRankSep(0.7);
+ DotGraphBuilder.setFontSize(12);
+ DotGraphBuilder.setArrowSize(1);
+ DotGraphBuilder.setArrowWidth(2);
}
private final Path dir;
- private final Set javaGroup;
- private final Set jdkGroup;
-
- GenGraphs(Path dir, Set javaGroup, Set jdkGroup) {
+ private final boolean spec;
+ GenGraphs(Path dir, boolean spec) {
this.dir = dir;
- this.javaGroup = Collections.unmodifiableSet(javaGroup);
- this.jdkGroup = Collections.unmodifiableSet(jdkGroup);
+ this.spec = spec;
}
- /**
- * Generates a dot file for the given module reference as the root.
- */
- void genDotFile(ModuleReference mref) throws IOException {
- String name = mref.descriptor().name();
- genDotFile(name, Set.of(name));
+ void genDotFiles(Map configurations) throws IOException {
+ ModuleDotGraph dotGraph = new ModuleDotGraph(configurations, spec);
+ dotGraph.genDotFiles(dir);
}
- /**
- * Generates a dot file for the given set of root modules.
- */
- void genDotFile(String name, Set roots) throws IOException {
- Configuration cf =
- Configuration.empty().resolveRequires(ModuleFinder.ofSystem(),
- ModuleFinder.of(),
- roots);
+ boolean accept(String name, ModuleDescriptor descriptor) {
+ if (!spec) return true;
- Set mds = cf.modules().stream()
- .map(ResolvedModule::reference)
- .map(ModuleReference::descriptor)
- .collect(toSet());
+ if (name.equals("jdk"))
+ return false;
- // generate a dot file for the resolved graph
- try (OutputStream os = Files.newOutputStream(dir.resolve(name + ".dot"));
- PrintStream out = new PrintStream(os)) {
- printGraph(out, name, gengraph(cf),
- mds.stream()
- .collect(toMap(ModuleDescriptor::name, Function.identity()))
- );
- }
+ if (name.equals("java.se") || name.equals("java.se.ee"))
+ return true;
- if (name.equals("java.se") || name.equals("java.se.ee")) {
- // generate a dot file for Java SE module graph
- try (OutputStream os = Files.newOutputStream(dir.resolve(name + "-spec.dot"));
- PrintStream out = new PrintStream(os)) {
- // transitive reduction on the graph of `requires transitive` edges
- // filter out jdk.* modules which are implementation dependences
- Graph graph = requiresTransitiveGraph(cf, true);
- printGraph(out, name, graph,
- mds.stream()
- .filter(md -> !md.name().startsWith("jdk.") &&
- graph.nodes().contains(md.name()))
- .collect(toMap(ModuleDescriptor::name, Function.identity()))
- );
- }
- }
+ // only the module that has exported API
+ return descriptor.exports().stream()
+ .filter(e -> !e.isQualified())
+ .findAny().isPresent();
}
-
- private void printGraph(PrintStream out,
- String name,
- Graph graph,
- Map nameToModule)
- throws IOException
- {
- Set descriptors = new TreeSet<>(nameToModule.values());
-
- out.format("digraph \"%s\" {%n", name);
- out.format("size=\"25,25\";");
- out.format("nodesep=.5;%n");
- out.format("ranksep=1.5;%n");
- out.format("pencolor=transparent;%n");
- out.format("node [shape=plaintext, fontname=\"DejaVuSans\", fontsize=36, margin=\".2,.2\"];%n");
- out.format("edge [penwidth=4, color=\"#999999\", arrowhead=open, arrowsize=2];%n");
-
- out.format("subgraph %sse {%n", name.equals("jdk") ? "cluster_" : "");
- descriptors.stream()
- .filter(javaGroup::contains)
- .map(ModuleDescriptor::name)
- .forEach(mn -> out.format(" \"%s\" [fontcolor=\"%s\", group=%s];%n",
- mn, ORANGE, "java"));
- out.format("}%n");
-
- // same ranks
- ranks.stream()
- .map(group -> descriptors.stream()
- .map(ModuleDescriptor::name)
- .filter(group::contains)
- .map(mn -> "\"" + mn + "\"")
- .collect(joining(",")))
- .filter(group -> group.length() > 0)
- .forEach(group -> out.format("{rank=same %s}%n", group));
-
- descriptors.stream()
- .filter(jdkGroup::contains)
- .map(ModuleDescriptor::name)
- .forEach(mn -> out.format(" \"%s\" [fontcolor=\"%s\", group=%s];%n",
- mn, BLUE, "jdk"));
-
- descriptors.stream()
- .forEach(md -> {
- String mn = md.name();
- Set requiresTransitive = md.requires().stream()
- .filter(d -> d.modifiers().contains(TRANSITIVE))
- .map(d -> d.name())
- .collect(toSet());
-
- graph.adjacentNodes(mn)
- .stream()
- .filter(nameToModule::containsKey)
- .forEach(dn -> {
- String attr = dn.equals("java.base") ? REQUIRES_BASE
- : (requiresTransitive.contains(dn) ? REEXPORTS : REQUIRES);
- int w = weightOf(mn, dn);
- if (w > 1)
- attr += "weight=" + w;
- out.format(" \"%s\" -> \"%s\" [%s];%n", mn, dn, attr);
- });
- });
-
- out.println("}");
- }
-
- /**
- * Returns a Graph of the given Configuration after transitive reduction.
- *
- * Transitive reduction of requires transitive edge and requires edge have
- * to be applied separately to prevent the requires transitive edges
- * (e.g. U -> V) from being reduced by a path (U -> X -> Y -> V)
- * in which V would not be re-exported from U.
- */
- private Graph gengraph(Configuration cf) {
- Graph.Builder builder = new Graph.Builder<>();
- for (ResolvedModule resolvedModule : cf.modules()) {
- String mn = resolvedModule.reference().descriptor().name();
- builder.addNode(mn);
- resolvedModule.reads().stream()
- .map(ResolvedModule::name)
- .forEach(target -> builder.addEdge(mn, target));
- }
- Graph rpg = requiresTransitiveGraph(cf, false);
- return builder.build().reduce(rpg);
- }
-
- /**
- * Returns a Graph containing only requires transitive edges
- * with transitive reduction.
- */
- private Graph requiresTransitiveGraph(Configuration cf, boolean includeBase) {
- Graph.Builder builder = new Graph.Builder<>();
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
- String mn = descriptor.name();
- descriptor.requires().stream()
- .filter(d -> d.modifiers().contains(TRANSITIVE)
- || (includeBase && d.name().equals("java.base")))
- .map(d -> d.name())
- .forEach(d -> builder.addEdge(mn, d));
- }
- return builder.build().reduce();
- }
-}
+}
\ No newline at end of file
diff --git a/jdk/make/src/classes/build/tools/jigsaw/Graph.java b/jdk/make/src/classes/build/tools/jigsaw/Graph.java
deleted file mode 100644
index a835da1ad93..00000000000
--- a/jdk/make/src/classes/build/tools/jigsaw/Graph.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2014, 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 build.tools.jigsaw;
-
-import java.io.PrintStream;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-
-public class Graph {
- private static boolean traceOn = Boolean.getBoolean("build.tools.module.trace");
- private final Set nodes;
- private final Map> edges;
- private Graph(Set nodes, Map> edges) {
- this.nodes = nodes;
- this.edges = edges;
- }
-
- public Set nodes() {
- return nodes;
- }
-
- public Map> edges() {
- return edges;
- }
-
- public Set adjacentNodes(T u) {
- return edges.get(u);
- }
-
- /**
- * Returns a new Graph after transitive reduction
- */
- public Graph reduce() {
- Graph.Builder builder = new Builder<>();
- nodes.stream()
- .forEach(u -> {
- builder.addNode(u);
- edges.get(u).stream()
- .filter(v -> !pathExists(u, v, false))
- .forEach(v -> builder.addEdge(u, v));
- });
- return builder.build();
- }
-
- /**
- * Returns a new Graph after transitive reduction. All edges in
- * the given g takes precedence over this graph.
- *
- * @throw IllegalArgumentException g must be a subgraph this graph
- */
- public Graph reduce(Graph g) {
- boolean subgraph = nodes.containsAll(g.nodes) && g.edges.keySet().stream()
- .allMatch(u -> adjacentNodes(u).containsAll(g.adjacentNodes(u)));
- if (!subgraph) {
- throw new IllegalArgumentException("the given argument is not a subgraph of this graph");
- }
-
- Graph.Builder builder = new Builder<>();
- nodes.stream()
- .forEach(u -> {
- builder.addNode(u);
- // filter the edge if there exists a path from u to v in the given g
- // or there exists another path from u to v in this graph
- edges.get(u).stream()
- .filter(v -> !g.pathExists(u, v) && !pathExists(u, v, false))
- .forEach(v -> builder.addEdge(u, v));
- });
-
- // add the overlapped edges from this graph and the given g
- g.edges().keySet().stream()
- .forEach(u -> g.adjacentNodes(u).stream()
- .filter(v -> isAdjacent(u, v))
- .forEach(v -> builder.addEdge(u, v)));
- return builder.build();
- }
-
- private boolean isAdjacent(T u, T v) {
- return edges.containsKey(u) && edges.get(u).contains(v);
- }
-
- private boolean pathExists(T u, T v) {
- return pathExists(u, v, true);
- }
-
- /**
- * Returns true if there exists a path from u to v in this graph.
- * If includeAdjacent is false, it returns true if there exists
- * another path from u to v of distance > 1
- */
- private boolean pathExists(T u, T v, boolean includeAdjacent) {
- if (!nodes.contains(u) || !nodes.contains(v)) {
- return false;
- }
- if (includeAdjacent && isAdjacent(u, v)) {
- return true;
- }
- Deque stack = new LinkedList<>();
- Set visited = new HashSet<>();
- stack.push(u);
- while (!stack.isEmpty()) {
- T node = stack.pop();
- if (node.equals(v)) {
- if (traceOn) {
- System.out.format("Edge %s -> %s removed%n", u, v);
- }
- return true;
- }
- if (!visited.contains(node)) {
- visited.add(node);
- edges.get(node).stream()
- .filter(e -> includeAdjacent || !node.equals(u) || !e.equals(v))
- .forEach(e -> stack.push(e));
- }
- }
- assert !visited.contains(v);
- return false;
- }
-
- void printGraph(PrintStream out) {
- nodes.stream()
- .forEach(u -> adjacentNodes(u).stream()
- .forEach(v -> out.format("%s -> %s%n", u, v)));
- }
-
- public static class Builder {
- final Set nodes = new HashSet<>();
- final Map> edges = new HashMap<>();
- public void addNode(T node) {
- if (nodes.contains(node)) {
- return;
- }
- nodes.add(node);
- edges.computeIfAbsent(node, _e -> new HashSet<>());
- }
- public void addEdge(T u, T v) {
- addNode(u);
- addNode(v);
- edges.get(u).add(v);
- }
- public Graph build() {
- return new Graph<>(nodes, edges);
- }
- }
-}
diff --git a/jdk/make/src/classes/build/tools/jigsaw/ModuleSummary.java b/jdk/make/src/classes/build/tools/jigsaw/ModuleSummary.java
index e55a1c04855..520fb1b96b0 100644
--- a/jdk/make/src/classes/build/tools/jigsaw/ModuleSummary.java
+++ b/jdk/make/src/classes/build/tools/jigsaw/ModuleSummary.java
@@ -291,9 +291,9 @@ public class ModuleSummary {
static Configuration resolve(Set roots) {
return Configuration.empty()
- .resolveRequires(ModuleFinder.ofSystem(),
- ModuleFinder.of(),
- roots);
+ .resolve(ModuleFinder.ofSystem(),
+ ModuleFinder.of(),
+ roots);
}
static class HtmlDocument {
diff --git a/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
new file mode 100644
index 00000000000..1ba654eb28e
--- /dev/null
+++ b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
@@ -0,0 +1,47 @@
+/*
+ * 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 sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new AixAsynchronousChannelProvider();
+ }
+}
diff --git a/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java
index 3f23cc4fa3b..dbc3ab61de8 100644
--- a/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java
+++ b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.PollSelectorProvider();
+ return new PollSelectorProvider();
}
-
}
diff --git a/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
new file mode 100644
index 00000000000..f2354103264
--- /dev/null
+++ b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
@@ -0,0 +1,47 @@
+/*
+ * 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 sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new LinuxAsynchronousChannelProvider();
+ }
+}
diff --git a/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java
index 1278f1583ee..77531b283b3 100644
--- a/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java
+++ b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.EPollSelectorProvider();
+ return new EPollSelectorProvider();
}
-
}
diff --git a/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
new file mode 100644
index 00000000000..8bb368223e4
--- /dev/null
+++ b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java
@@ -0,0 +1,47 @@
+/*
+ * 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 sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new BsdAsynchronousChannelProvider();
+ }
+}
diff --git a/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java
index e55f8e6bf34..c7d67b27ecd 100644
--- a/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java
+++ b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java
@@ -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
@@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.KQueueSelectorProvider();
+ return new KQueueSelectorProvider();
}
-
}
diff --git a/jdk/src/java.base/macosx/native/launcher/jexec.c b/jdk/src/java.base/macosx/native/launcher/jexec.c
deleted file mode 100644
index 24df31f5288..00000000000
--- a/jdk/src/java.base/macosx/native/launcher/jexec.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (c) 1999, 2012, 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.
- */
-
-/*
- * jexec for J2SE
- *
- * jexec is used by the system to allow execution of JAR files.
- * Essentially jexec needs to run java and
- * needs to be a native ISA executable (not a shell script), although
- * this native ISA executable requirement was a mistake that will be fixed.
- * ( is sparc or i386 or amd64).
- *
- * When you execute a jar file, jexec is executed by the system as follows:
- * /usr/java/jre/lib//jexec -jar JARFILENAME
- * so this just needs to be turned into:
- * /usr/java/jre/bin/java -jar JARFILENAME
- *
- * Solaris systems (new 7's and all 8's) will be looking for jexec at:
- * /usr/java/jre/lib//jexec
- * Older systems may need to add this to their /etc/system file:
- * set javaexec:jexec="/usr/java/jre/lib//jexec"
- * and reboot the machine for this to work.
- *
- * This source should be compiled as:
- * cc -o jexec jexec.c
- *
- * And jexec should be placed at the following location of the installation:
- * /jre/lib//jexec (for Solaris)
- * /lib/jexec (for Linux)
- *
- * NOTE: Unless is the "default" JDK on the system
- * (i.e. /usr/java -> ), this jexec will not be
- * found. The 1.2 java is only the default on Solaris 8 and
- * on systems where the 1.2 packages were installed and no 1.1
- * java was found.
- *
- * NOTE: You must use 1.2 jar to build your jar files. The system
- * doesn't seem to pick up 1.1 jar files.
- *
- * NOTE: We don't need to set LD_LIBRARY_PATH here, even though we
- * are running the actual java binary because the java binary will
- * look for it's libraries through it's own runpath, which uses
- * $ORIGIN.
- *
- * NOTE: This jexec should NOT have any special .so library needs because
- * it appears that this executable will NOT get the $ORIGIN of jexec
- * but the $ORIGIN of the jar file being executed. Be careful to keep
- * this program simple and with no .so dependencies.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-static const int CRAZY_EXEC = ENOEXEC;
-static const int BAD_MAGIC = ENOEXEC;
-
-static const char * BAD_EXEC_MSG = "jexec failed";
-static const char * CRAZY_EXEC_MSG = "missing args";
-static const char * MISSING_JAVA_MSG = "can't locate java";
-static const char * UNKNOWN_ERROR = "unknown error";
-
-/* Define a constant that represents the number of directories to pop off the
- * current location to find the java binary */
-static const int RELATIVE_DEPTH = 3;
-
-/* path to java after popping */
-static const char * BIN_PATH = "/bin/java";
-
-/* flag used when running JAR files */
-static const char * JAR_FLAG = "-jar";
-
-int main(int argc, const char * argv[]);
-void errorExit(int error, const char * message);
-int getJavaPath(const char * path, char * buf, int depth);
-
-/*
- * This is the main entry point. This program (jexec) will attempt to execute
- * a JAR file by finding the Java program (java), relative to its own location.
- * The exact location of the Java program depends on the platform, i.e.
- *
- * /jre/lib//jexec (for Solaris)
- * /lib/jexec (for Linux JDK)
- *
- * Once the Java program is found, this program copies any remaining arguments
- * into another array, which is then used to exec the Java program.
- *
- * On Linux this program does some additional steps. When copying the array of
- * args, it is necessary to insert the "-jar" flag between arg[0], the program
- * name, and the original arg[1], which is presumed to be a path to a JAR file.
- * It is also necessary to verify that the original arg[1] really is a JAR file.
- * (These steps are unnecessary on Solaris because they are taken care of by
- * the kernel.)
- */
-int main(int argc, const char * argv[]) {
- /* We need to exec the original arguments using java, instead of jexec.
- * Also, for Linux, it is necessary to add the "-jar" argument between
- * the new arg[0], and the old arg[1]. To do this we will create a new
- * args array. */
- char java[PATH_MAX + 1]; /* path to java binary */
- const char ** nargv = NULL; /* new args array */
- int nargc = 0; /* new args array count */
- int argi = 0; /* index into old array */
-
- /* Make sure we have something to work with */
- if ((argc < 1) || (argv == NULL)) {
- /* Shouldn't happen... */
- errorExit(CRAZY_EXEC, CRAZY_EXEC_MSG);
- }
-
- /* Get the path to the java binary, which is in a known position relative
- * to our current position, which is in argv[0]. */
- if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
- errorExit(errno, MISSING_JAVA_MSG);
- }
-
- nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
- nargv[nargc++] = java;
-
- if (argc >= 2) {
- const char * jarfile = argv[argi++];
- const char * message = NULL;
-
- /* the next argument is the path to the JAR file */
- nargv[nargc++] = jarfile;
- }
-
- /* finally copy any remaining arguments */
- while (argi < argc) {
- nargv[nargc++] = argv[argi++];
- }
-
- /* finally add one last terminating null */
- nargv[nargc++] = NULL;
-
- /* It's time to exec the java binary with the new arguments. It
- * is possible that we've reached this point without actually
- * having a JAR file argument (i.e. if argc < 2), but we still
- * want to exec the java binary, since that will take care of
- * displaying the correct usage. */
- execv(java, (char * const *) nargv);
-
- /* If the exec worked, this process would have been replaced
- * by the new process. So any code reached beyond this point
- * implies an error in the exec. */
- free(nargv);
- errorExit(errno, BAD_EXEC_MSG);
- return 0; // keep the compiler happy
-}
-
-
-/*
- * Exit the application by setting errno, and writing a message.
- *
- * Parameters:
- * error - errno is set to this value, and it is used to exit.
- * message - the message to write.
- */
-void errorExit(int error, const char * message) {
- if (error != 0) {
- errno = error;
- perror((message != NULL) ? message : UNKNOWN_ERROR);
- }
-
- exit((error == 0) ? 0 : 1);
-}
-
-
-/*
- * Get the path to the java binary that should be relative to the current path.
- *
- * Parameters:
- * path - the input path that the java binary that should be relative to.
- * buf - a buffer of size PATH_MAX or greater that the java path is
- * copied to.
- * depth - the number of names to trim off the current path, including the
- * name of this program.
- *
- * Returns:
- * This function returns 0 on success; otherwise it returns the value of
- * errno.
- */
-int getJavaPath(const char * path, char * buf, int depth) {
- int result = 0;
-
- /* Get the full path to this program. Depending on whether this is Solaris
- * or Linux, this will be something like,
- *
- * /jre/lib//jexec (for Solaris)
- * /lib/jexec (for Linux)
- */
- if (realpath(path, buf) != NULL) {
- int count = 0;
-
- /* Pop off the filename, and then subdirectories for each level of
- * depth */
- for (count = 0; count < depth; count++) {
- *(strrchr(buf, '/')) = '\0';
- }
-
- /* Append the relative location of java, creating something like,
- *
- * /jre/bin/java (for Solaris)
- * /bin/java (for Linux)
- */
- strcat(buf, BIN_PATH);
- }
- else {
- /* Failed to get the path */
- result = errno;
- }
-
- return (result);
-}
diff --git a/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c b/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
index b43f290b0a2..8246b8130a5 100644
--- a/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
+++ b/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
@@ -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
@@ -80,23 +80,31 @@ char *getMacOSXLocale(int cat) {
// "en-GB" (language with alpha-2 region designator)
// "es-419" (language with 3-digit UN M.49 area code)
// "zh-Hans" (language with ISO 15924 script designator)
+ // "zh-Hans-US" (language with ISO 15924 script designator and region)
+ // "zh-Hans-419" (language with ISO 15924 script designator and UN M.49)
//
- // In the case of region designators (alpha-2 or UN M.49), we convert
+ // In the case of region designators (alpha-2 and/or UN M.49), we convert
// to our locale string format by changing '-' to '_'. That is, if
// the '-' is followed by fewer than 4 chars.
char* scriptOrRegion = strchr(languageString, '-');
- if (scriptOrRegion != NULL && strlen(scriptOrRegion) < 5) {
- *scriptOrRegion = '_';
+ if (scriptOrRegion != NULL) {
+ int length = strlen(scriptOrRegion);
+ if (length > 5) {
+ // Region and script both exist. Honor the script for now
+ scriptOrRegion[5] = '\0';
+ } else if (length < 5) {
+ *scriptOrRegion = '_';
- assert((strlen(scriptOrRegion) == 3 &&
+ assert((length == 3 &&
// '-' followed by a 2 character region designator
isalpha(scriptOrRegion[1]) &&
isalpha(scriptOrRegion[2])) ||
- (strlen(scriptOrRegion) == 4 &&
+ (length == 4 &&
// '-' followed by a 3-digit UN M.49 area code
isdigit(scriptOrRegion[1]) &&
isdigit(scriptOrRegion[2]) &&
isdigit(scriptOrRegion[3])));
+ }
}
const char* retVal = languageString;
diff --git a/jdk/src/java.base/share/classes/java/io/FilterInputStream.java b/jdk/src/java.base/share/classes/java/io/FilterInputStream.java
index 3304a1f2eb8..05ab5fa56cb 100644
--- a/jdk/src/java.base/share/classes/java/io/FilterInputStream.java
+++ b/jdk/src/java.base/share/classes/java/io/FilterInputStream.java
@@ -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
@@ -84,7 +84,7 @@ class FilterInputStream extends InputStream {
}
/**
- * Reads up to byte.length bytes of data from this
+ * Reads up to b.length bytes of data from this
* input stream into an array of bytes. This method blocks until some
* input is available.
*
diff --git a/jdk/src/java.base/share/classes/java/io/FilterOutputStream.java b/jdk/src/java.base/share/classes/java/io/FilterOutputStream.java
index cb8f122d0b1..8030979cdaa 100644
--- a/jdk/src/java.base/share/classes/java/io/FilterOutputStream.java
+++ b/jdk/src/java.base/share/classes/java/io/FilterOutputStream.java
@@ -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
@@ -91,8 +91,8 @@ public class FilterOutputStream extends OutputStream {
* b.length.
*
* Note that this method does not call the one-argument
- * write method of its underlying stream with the single
- * argument b.
+ * write method of its underlying output stream with
+ * the single argument b.
*
* @param b the data to be written.
* @exception IOException if an I/O error occurs.
@@ -113,7 +113,7 @@ public class FilterOutputStream extends OutputStream {
* byte to output.
*
* Note that this method does not call the write method
- * of its underlying input stream with the same arguments. Subclasses
+ * of its underlying output stream with the same arguments. Subclasses
* of FilterOutputStream should provide a more efficient
* implementation of this method.
*
diff --git a/jdk/src/java.base/share/classes/java/lang/Class.java b/jdk/src/java.base/share/classes/java/lang/Class.java
index b0e3d3af0cd..0a3b1da91a1 100644
--- a/jdk/src/java.base/share/classes/java/lang/Class.java
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java
@@ -425,6 +425,7 @@ public final class Class implements java.io.Serializable,
*
*
* @since 9
+ * @spec JPMS
*/
@CallerSensitive
public static Class> forName(Module module, String name) {
@@ -819,6 +820,7 @@ public final class Class implements java.io.Serializable,
* @return the module that this class or interface is a member of
*
* @since 9
+ * @spec JPMS
*/
public Module getModule() {
return module;
@@ -924,6 +926,8 @@ public final class Class implements java.io.Serializable,
* this method returns {@code null}.
*
* @return the package of this class.
+ * @revised 9
+ * @spec JPMS
*/
public Package getPackage() {
if (isPrimitive() || isArray()) {
@@ -951,20 +955,30 @@ public final class Class implements java.io.Serializable,
* declaring class} of the {@link #getEnclosingMethod enclosing method} or
* {@link #getEnclosingConstructor enclosing constructor}.
*
- *
This method returns {@code null} if this class represents an array type,
- * a primitive type or void.
+ *
If this class represents an array type then this method returns the
+ * package name of the element type. If this class represents a primitive
+ * type or void then the package name "{@code java.lang}" is returned.
*
* @return the fully qualified package name
*
* @since 9
+ * @spec JPMS
* @jls 6.7 Fully Qualified Names
*/
public String getPackageName() {
String pn = this.packageName;
- if (pn == null && !isArray() && !isPrimitive()) {
- String cn = getName();
- int dot = cn.lastIndexOf('.');
- pn = (dot != -1) ? cn.substring(0, dot).intern() : "";
+ if (pn == null) {
+ Class> c = this;
+ while (c.isArray()) {
+ c = c.getComponentType();
+ }
+ if (c.isPrimitive()) {
+ pn = "java.lang";
+ } else {
+ String cn = c.getName();
+ int dot = cn.lastIndexOf('.');
+ pn = (dot != -1) ? cn.substring(0, dot).intern() : "";
+ }
this.packageName = pn;
}
return pn;
@@ -2491,10 +2505,16 @@ public final class Class implements java.io.Serializable,
* Finds a resource with a given name.
*
*
If this class is in a named {@link Module Module} then this method
- * will attempt to find the resource in the module by means of the absolute
- * resource name, subject to the rules for encapsulation specified in the
- * {@code Module} {@link Module#getResourceAsStream getResourceAsStream}
- * method.
+ * will attempt to find the resource in the module. This is done by
+ * delegating to the module's class loader {@link
+ * ClassLoader#findResource(String,String) findResource(String,String)}
+ * method, invoking it with the module name and the absolute name of the
+ * resource. Resources in named modules are subject to the rules for
+ * encapsulation specified in the {@code Module} {@link
+ * Module#getResourceAsStream getResourceAsStream} method and so this
+ * method returns {@code null} when the resource is a
+ * non-"{@code .class}" resource in a package that is not open to the
+ * caller's module.
*
*
Otherwise, if this class is not in a named module then the rules for
* searching resources associated with a given class are implemented by the
@@ -2503,9 +2523,8 @@ public final class Class implements java.io.Serializable,
* the bootstrap class loader, the method delegates to {@link
* ClassLoader#getSystemResourceAsStream}.
*
- *
Before finding a resource in the caller's module or delegation to a
- * class loader, an absolute resource name is constructed from the given
- * resource name using this algorithm:
+ *
Before delegation, an absolute resource name is constructed from the
+ * given resource name using this algorithm:
*
*
*
@@ -2532,7 +2551,11 @@ public final class Class implements java.io.Serializable,
* least the caller module, or access to the resource is denied
* by the security manager.
* @throws NullPointerException If {@code name} is {@code null}
+ *
+ * @see Module#getResourceAsStream(String)
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public InputStream getResourceAsStream(String name) {
@@ -2585,10 +2608,16 @@ public final class Class implements java.io.Serializable,
* Finds a resource with a given name.
*
*
If this class is in a named {@link Module Module} then this method
- * will attempt to find the resource in the module by means of the absolute
- * resource name, subject to the rules for encapsulation specified in the
- * {@code Module} {@link Module#getResourceAsStream getResourceAsStream}
- * method.
+ * will attempt to find the resource in the module. This is done by
+ * delegating to the module's class loader {@link
+ * ClassLoader#findResource(String,String) findResource(String,String)}
+ * method, invoking it with the module name and the absolute name of the
+ * resource. Resources in named modules are subject to the rules for
+ * encapsulation specified in the {@code Module} {@link
+ * Module#getResourceAsStream getResourceAsStream} method and so this
+ * method returns {@code null} when the resource is a
+ * non-"{@code .class}" resource in a package that is not open to the
+ * caller's module.
*
*
Otherwise, if this class is not in a named module then the rules for
* searching resources associated with a given class are implemented by the
@@ -2627,6 +2656,8 @@ public final class Class implements java.io.Serializable,
* manager.
* @throws NullPointerException If {@code name} is {@code null}
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public URL getResource(String name) {
diff --git a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
index fb771c29a10..06da4a983e1 100644
--- a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java
@@ -207,6 +207,8 @@ import sun.security.util.SecurityConstants;
* @jls 13.1 The Form of a Binary
* @see #resolveClass(Class)
* @since 1.0
+ * @revised 9
+ * @spec JPMS
*/
public abstract class ClassLoader {
@@ -380,12 +382,12 @@ public abstract class ClassLoader {
* method doesn't allow creation of a new class loader.
*
* @since 9
+ * @spec JPMS
*/
protected ClassLoader(String name, ClassLoader parent) {
this(checkCreateClassLoader(name), name, parent);
}
-
/**
* Creates a new class loader using the specified parent class loader for
* delegation.
@@ -440,6 +442,7 @@ public abstract class ClassLoader {
* this class loader is not named.
*
* @since 9
+ * @spec JPMS
*/
public String getName() {
return name;
@@ -710,6 +713,7 @@ public abstract class ClassLoader {
* if the class could not be found.
*
* @since 9
+ * @spec JPMS
*/
protected Class> findClass(String moduleName, String name) {
if (moduleName == null) {
@@ -834,6 +838,8 @@ public abstract class ClassLoader {
* @see java.security.SecureClassLoader
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
protected final Class> defineClass(String name, byte[] b, int off, int len)
throws ClassFormatError
@@ -967,6 +973,9 @@ public abstract class ClassLoader {
* certificates than this class, or if {@code name} begins with
* "{@code java.}" and this class loader is not the platform
* class loader or its ancestor.
+ *
+ * @revised 9
+ * @spec JPMS
*/
protected final Class> defineClass(String name, byte[] b, int off, int len,
ProtectionDomain protectionDomain)
@@ -1041,6 +1050,8 @@ public abstract class ClassLoader {
* @see #defineClass(String, byte[], int, int, ProtectionDomain)
*
* @since 1.5
+ * @revised 9
+ * @spec JPMS
*/
protected final Class> defineClass(String name, java.nio.ByteBuffer b,
ProtectionDomain protectionDomain)
@@ -1264,11 +1275,11 @@ public abstract class ClassLoader {
* Class loader implementations that support the loading from modules
* should override this method.
*
- * @apiNote This method is the basis for the {@code Class} {@link
- * Class#getResource getResource} and {@link Class#getResourceAsStream
- * getResourceAsStream} methods. It is not subject to the rules for
- * encapsulation specified by {@code Module} {@link
- * Module#getResourceAsStream getResourceAsStream}.
+ * @apiNote This method is the basis for the {@link
+ * Class#getResource Class.getResource}, {@link Class#getResourceAsStream
+ * Class.getResourceAsStream}, and {@link Module#getResourceAsStream
+ * Module.getResourceAsStream} methods. It is not subject to the rules for
+ * encapsulation specified by {@code Module.getResourceAsStream}.
*
* @implSpec The default implementation attempts to find the resource by
* invoking {@link #findResource(String)} when the {@code moduleName} is
@@ -1292,6 +1303,7 @@ public abstract class ClassLoader {
*
* @see java.lang.module.ModuleReader#find(String)
* @since 9
+ * @spec JPMS
*/
protected URL findResource(String moduleName, String name) throws IOException {
if (moduleName == null) {
@@ -1342,6 +1354,8 @@ public abstract class ClassLoader {
* @throws NullPointerException If {@code name} is {@code null}
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
public URL getResource(String name) {
Objects.requireNonNull(name);
@@ -1403,6 +1417,8 @@ public abstract class ClassLoader {
* @see #findResources(String)
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
public Enumeration getResources(String name) throws IOException {
Objects.requireNonNull(name);
@@ -1499,6 +1515,8 @@ public abstract class ClassLoader {
* denied by the security manager.
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
protected URL findResource(String name) {
return null;
@@ -1531,6 +1549,8 @@ public abstract class ClassLoader {
* If I/O errors occur
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
protected Enumeration findResources(String name) throws IOException {
return Collections.emptyEnumeration();
@@ -1601,6 +1621,8 @@ public abstract class ClassLoader {
* denied by the security manager.
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
public static URL getSystemResource(String name) {
return getSystemClassLoader().getResource(name);
@@ -1636,6 +1658,8 @@ public abstract class ClassLoader {
* If I/O errors occur
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
public static Enumeration getSystemResources(String name)
throws IOException
@@ -1667,6 +1691,8 @@ public abstract class ClassLoader {
* @throws NullPointerException If {@code name} is {@code null}
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
public InputStream getResourceAsStream(String name) {
Objects.requireNonNull(name);
@@ -1699,6 +1725,8 @@ public abstract class ClassLoader {
* denied by the security manager.
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
public static InputStream getSystemResourceAsStream(String name) {
URL url = getSystemResource(name);
@@ -1749,6 +1777,7 @@ public abstract class ClassLoader {
*
* @see Module#isNamed()
* @since 9
+ * @spec JPMS
*/
public final Module getUnnamedModule() {
return unnamedModule;
@@ -1772,6 +1801,7 @@ public abstract class ClassLoader {
* {@link RuntimePermission}{@code ("getClassLoader")}
*
* @since 9
+ * @spec JPMS
*/
@CallerSensitive
public static ClassLoader getPlatformClassLoader() {
@@ -1847,6 +1877,8 @@ public abstract class ClassLoader {
* {@link Throwable#getCause()} method.
*
* @revised 1.4
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ClassLoader getSystemClassLoader() {
@@ -2101,6 +2133,8 @@ public abstract class ClassLoader {
* defined by this class loader
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*
* @see
* The JAR File Specification: Package Versioning
@@ -2138,6 +2172,7 @@ public abstract class ClassLoader {
* if {@code name} is {@code null}.
*
* @since 9
+ * @spec JPMS
*/
public final Package getDefinedPackage(String name) {
Objects.requireNonNull(name, "name cannot be null");
@@ -2160,6 +2195,7 @@ public abstract class ClassLoader {
* or an zero length array if no package has been defined by this class loader.
*
* @since 9
+ * @spec JPMS
*/
public final Package[] getDefinedPackages() {
return packages().toArray(Package[]::new);
@@ -2196,6 +2232,8 @@ public abstract class ClassLoader {
* a {@code Package} for the specified class loader.
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
@Deprecated(since="9")
protected Package getPackage(String name) {
@@ -2220,6 +2258,8 @@ public abstract class ClassLoader {
* class loader and its ancestors
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
protected Package[] getPackages() {
Stream pkgs = packages();
diff --git a/jdk/src/java.base/share/classes/java/lang/IllegalCallerException.java b/jdk/src/java.base/share/classes/java/lang/IllegalCallerException.java
new file mode 100644
index 00000000000..f882fb21591
--- /dev/null
+++ b/jdk/src/java.base/share/classes/java/lang/IllegalCallerException.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+/**
+ * Thrown to indicate that a method has been called by an inappropriate caller.
+ *
+ * @since 9
+ * @spec JPMS
+ * @see StackWalker#getCallerClass
+ */
+public class IllegalCallerException extends RuntimeException {
+ /**
+ * Constructs an IllegalCallerException with no detail message.
+ */
+ public IllegalCallerException() {
+ super();
+ }
+
+ /**
+ * Constructs an IllegalCallerException with the specified detail
+ * message.
+ *
+ * @param s the String that contains a detailed message (can be null)
+ */
+ public IllegalCallerException(String s) {
+ super(s);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause.
+ *
+ * @param message the detail message (can be null)
+ * @param cause the cause (can be null)
+ */
+ public IllegalCallerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of {@code (cause==null ? null : cause.toString())} (which
+ * typically contains the class and detail message of {@code cause}).
+ *
+ * @param cause the cause (can be null)
+ */
+ public IllegalCallerException(Throwable cause) {
+ super(cause);
+ }
+
+ static final long serialVersionUID = -2349421918363102232L;
+}
diff --git a/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java b/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java
index 5be48729d5a..612ff09f138 100644
--- a/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java
+++ b/jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -55,14 +55,36 @@ interface LiveStackFrame extends StackFrame {
*
*
A single local variable can hold a value of type boolean, byte, char,
* short, int, float, reference or returnAddress. A pair of local variables
- * can hold a value of type long or double. In other words,
- * a value of type long or type double occupies two consecutive local
- * variables. For a value of primitive type, the element in the
- * local variable array is an {@link PrimitiveValue} object;
- * otherwise, the element is an {@code Object}.
+ * can hold a value of type long or double (JVMS section 2.6.1). Primitive
+ * locals are represented in the returned array as {@code PrimitiveSlot}s,
+ * with longs and doubles occupying a pair of consecutive
+ * {@code PrimitiveSlot}s.
*
- *
The returned array may contain null entries if a local variable is not
- * live.
+ *
The current VM implementation does not provide specific type
+ * information for primitive locals. This method simply returns the raw
+ * contents of the VM's primitive locals on a best-effort basis, without
+ * indicating a specific type.
+ *
+ *
The returned array may contain null entries for local variables that
+ * are not live.
+ *
+ * @implNote
+ *
The specific subclass of {@code PrimitiveSlot} will reflect the
+ * underlying architecture, and will be either {@code PrimitiveSlot32} or
+ * {@code PrimitiveSlot64}.
+ *
+ *
How a long or double value is stored in the pair of
+ * {@code PrimitiveSlot}s can vary based on the underlying architecture and
+ * VM implementation. On 32-bit architectures, long/double values are split
+ * between the two {@code PrimitiveSlot32}s.
+ * On 64-bit architectures, the entire value may be stored in one of the
+ * {@code PrimitiveSlot64}s, with the other {@code PrimitiveSlot64} being
+ * unused.
+ *
+ *
The contents of the unused, high-order portion of a
+ * {@code PrimitiveSlot64} (when storing a primitive other than a long or
+ * double) is unspecified. In particular, the unused bits are not
+ * necessarily zeroed out.
*
* @return the local variable array of this stack frame.
*/
@@ -78,7 +100,7 @@ interface LiveStackFrame extends StackFrame {
*
Each entry on the operand stack can hold a value of any Java Virtual
* Machine Type.
* For a value of primitive type, the element in the returned array is
- * an {@link PrimitiveValue} object; otherwise, the element is the {@code Object}
+ * a {@link PrimitiveSlot} object; otherwise, the element is the {@code Object}
* on the operand stack.
*
* @return the operand stack of this stack frame.
@@ -87,107 +109,37 @@ interface LiveStackFrame extends StackFrame {
/**
* UNSUPPORTED This interface is intended to be package-private
- * or move to an internal package.
+ * or moved to an internal package.
*
- * Represents a local variable or an entry on the operand whose value is
+ * Represents a local variable or an entry on the operand stack whose value is
* of primitive type.
*/
- public abstract class PrimitiveValue {
+ public abstract class PrimitiveSlot {
/**
- * Returns the base type of this primitive value, one of
- * {@code B, D, C, F, I, J, S, Z}.
- *
- * @return Name of a base type
- * @jvms table 4.3-A
+ * Returns the size, in bytes, of the slot.
*/
- abstract char type();
+ public abstract int size();
/**
- * Returns the boolean value if this primitive value is of type boolean.
- * @return the boolean value if this primitive value is of type boolean.
+ * Returns the int value if this primitive value is of size 4
+ * @return the int value if this primitive value is of size 4
*
* @throws UnsupportedOperationException if this primitive value is not
- * of type boolean.
- */
- public boolean booleanValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the int value if this primitive value is of type int.
- * @return the int value if this primitive value is of type int.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type int.
+ * of size 4.
*/
public int intValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
+ throw new UnsupportedOperationException("this " + size() + "-byte primitive");
}
/**
- * Returns the long value if this primitive value is of type long.
- * @return the long value if this primitive value is of type long.
+ * Returns the long value if this primitive value is of size 8
+ * @return the long value if this primitive value is of size 8
*
* @throws UnsupportedOperationException if this primitive value is not
- * of type long.
+ * of size 8.
*/
public long longValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the char value if this primitive value is of type char.
- * @return the char value if this primitive value is of type char.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type char.
- */
- public char charValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the byte value if this primitive value is of type byte.
- * @return the byte value if this primitive value is of type byte.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type byte.
- */
- public byte byteValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the short value if this primitive value is of type short.
- * @return the short value if this primitive value is of type short.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type short.
- */
- public short shortValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the float value if this primitive value is of type float.
- * @return the float value if this primitive value is of type float.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type float.
- */
- public float floatValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
- }
-
- /**
- * Returns the double value if this primitive value is of type double.
- * @return the double value if this primitive value is of type double.
- *
- * @throws UnsupportedOperationException if this primitive value is not
- * of type double.
- */
- public double doubleValue() {
- throw new UnsupportedOperationException("this primitive of type " + type());
+ throw new UnsupportedOperationException("this " + size() + "-byte primitive");
}
}
diff --git a/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java b/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
index db8901ea731..b6583adf559 100644
--- a/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
+++ b/jdk/src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -24,15 +24,13 @@
*/
package java.lang;
-import java.lang.StackWalker.Option;
-import java.util.EnumSet;
-import java.util.Set;
-
-import static java.lang.StackWalker.ExtendedOption.*;
-
final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame {
private static Object[] EMPTY_ARRAY = new Object[0];
+ // These flags must match the values maintained in the VM
+ private static final int MODE_INTERPRETED = 0x01;
+ private static final int MODE_COMPILED = 0x02;
+
LiveStackFrameInfo(StackWalker walker) {
super(walker);
}
@@ -41,6 +39,7 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
private Object[] monitors = EMPTY_ARRAY;
private Object[] locals = EMPTY_ARRAY;
private Object[] operands = EMPTY_ARRAY;
+ private int mode = 0;
@Override
public Object[] getMonitors() {
@@ -57,51 +56,44 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
return operands;
}
+ @Override
+ public String toString() {
+ StringBuilder retVal = new StringBuilder(super.toString());
+ if (mode != 0) {
+ retVal.append("(");
+ if ((mode & MODE_INTERPRETED) == MODE_INTERPRETED) {
+ retVal.append(" interpreted ");
+ }
+ if ((mode & MODE_COMPILED) == MODE_COMPILED) {
+ retVal.append(" compiled ");
+ }
+ retVal.append(")");
+ }
+ return retVal.toString();
+ }
+
/*
- * Convert primitive value to {@code Primitive} object to represent
+ * Convert primitive value to {@code PrimitiveSlot} object to represent
* a local variable or an element on the operand stack of primitive type.
*/
- static PrimitiveValue asPrimitive(boolean value) {
- return new BooleanPrimitive(value);
+
+ static PrimitiveSlot asPrimitive(int value) {
+ return new PrimitiveSlot32(value);
}
- static PrimitiveValue asPrimitive(int value) {
- return new IntPrimitive(value);
+ static PrimitiveSlot asPrimitive(long value) {
+ return new PrimitiveSlot64(value);
}
- static PrimitiveValue asPrimitive(short value) {
- return new ShortPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(char value) {
- return new CharPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(byte value) {
- return new BytePrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(long value) {
- return new LongPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(float value) {
- return new FloatPrimitive(value);
- }
-
- static PrimitiveValue asPrimitive(double value) {
- return new DoublePrimitive(value);
- }
-
- private static class IntPrimitive extends PrimitiveValue {
+ private static class PrimitiveSlot32 extends PrimitiveSlot {
final int value;
- IntPrimitive(int value) {
+ PrimitiveSlot32(int value) {
this.value = value;
}
@Override
- public char type() {
- return 'I';
+ public int size() {
+ return 4;
}
@Override
@@ -115,103 +107,15 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
}
}
- private static class ShortPrimitive extends PrimitiveValue {
- final short value;
- ShortPrimitive(short value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'S';
- }
-
- @Override
- public short shortValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class BooleanPrimitive extends PrimitiveValue {
- final boolean value;
- BooleanPrimitive(boolean value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'Z';
- }
-
- @Override
- public boolean booleanValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class CharPrimitive extends PrimitiveValue {
- final char value;
- CharPrimitive(char value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'C';
- }
-
- @Override
- public char charValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class BytePrimitive extends PrimitiveValue {
- final byte value;
- BytePrimitive(byte value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'B';
- }
-
- @Override
- public byte byteValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class LongPrimitive extends PrimitiveValue {
+ private static class PrimitiveSlot64 extends PrimitiveSlot {
final long value;
- LongPrimitive(long value) {
+ PrimitiveSlot64(long value) {
this.value = value;
}
@Override
- public char type() {
- return 'J';
+ public int size() {
+ return 8;
}
@Override
@@ -224,48 +128,4 @@ final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame
return String.valueOf(value);
}
}
-
- private static class FloatPrimitive extends PrimitiveValue {
- final float value;
- FloatPrimitive(float value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'F';
- }
-
- @Override
- public float floatValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- private static class DoublePrimitive extends PrimitiveValue {
- final double value;
- DoublePrimitive(double value) {
- this.value = value;
- }
-
- @Override
- public char type() {
- return 'D';
- }
-
- @Override
- public double doubleValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
}
diff --git a/jdk/src/java.base/share/classes/java/lang/Package.java b/jdk/src/java.base/share/classes/java/lang/Package.java
index 5a19f9771f1..0dcc5e1c12c 100644
--- a/jdk/src/java.base/share/classes/java/lang/Package.java
+++ b/jdk/src/java.base/share/classes/java/lang/Package.java
@@ -111,6 +111,8 @@ import jdk.internal.reflect.Reflection;
* @see ClassLoader#definePackage(String, String, String, String, String, String, String, URL)
*
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
public class Package extends NamedPackage implements java.lang.reflect.AnnotatedElement {
/**
@@ -207,6 +209,9 @@ public class Package extends NamedPackage implements java.lang.reflect.Annotated
* is returned if it is not known.
* @return the vendor that implemented this package, {@code null}
* is returned if it is not known.
+ *
+ * @revised 9
+ * @spec JPMS
*/
public String getImplementationVendor() {
return versionInfo.implVendor;
@@ -334,6 +339,9 @@ public class Package extends NamedPackage implements java.lang.reflect.Annotated
* a {@code Package} for the specified class loader.
*
* @see ClassLoader#getDefinedPackage
+ *
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
@Deprecated(since="9")
@@ -356,6 +364,9 @@ public class Package extends NamedPackage implements java.lang.reflect.Annotated
* class loader and its ancestors
*
* @see ClassLoader#getDefinedPackages
+ *
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static Package[] getPackages() {
diff --git a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
index 8a819ee6db7..084d4661700 100644
--- a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
+++ b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java
@@ -1457,6 +1457,18 @@ class SecurityManager {
.collect(Collectors.toSet());
}
+ /**
+ * Called by java.security.Security
+ */
+ static void invalidatePackageAccessCache() {
+ synchronized (packageAccessLock) {
+ packageAccessValid = false;
+ }
+ synchronized (packageDefinitionLock) {
+ packageDefinitionValid = false;
+ }
+ }
+
/**
* Returns true if the module's loader is the boot or platform loader.
*/
diff --git a/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java b/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java
index 55976485d4f..4fd03331229 100644
--- a/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java
+++ b/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java
@@ -25,11 +25,13 @@
package java.lang;
import jdk.internal.reflect.MethodAccessor;
+import jdk.internal.reflect.ConstructorAccessor;
import java.lang.StackWalker.Option;
import java.lang.StackWalker.StackFrame;
import java.lang.annotation.Native;
import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -684,7 +686,7 @@ final class StackStreamFactory {
frames[n++] = caller;
}
if (frames[1] == null) {
- throw new IllegalStateException("no caller frame");
+ throw new IllegalCallerException("no caller frame");
}
return n;
}
@@ -922,7 +924,8 @@ final class StackStreamFactory {
*/
final void setBatch(int depth, int startIndex, int endIndex) {
if (startIndex <= 0 || endIndex <= 0)
- throw new IllegalArgumentException("startIndex=" + startIndex + " endIndex=" + endIndex);
+ throw new IllegalArgumentException("startIndex=" + startIndex
+ + " endIndex=" + endIndex);
this.origin = startIndex;
this.fence = endIndex;
@@ -980,13 +983,18 @@ final class StackStreamFactory {
private static boolean isReflectionFrame(Class> c) {
if (c.getName().startsWith("jdk.internal.reflect") &&
- !MethodAccessor.class.isAssignableFrom(c)) {
- throw new InternalError("Not jdk.internal.reflect.MethodAccessor: " + c.toString());
+ !MethodAccessor.class.isAssignableFrom(c) &&
+ !ConstructorAccessor.class.isAssignableFrom(c)) {
+ throw new InternalError("Not jdk.internal.reflect.MethodAccessor"
+ + " or jdk.internal.reflect.ConstructorAccessor: "
+ + c.toString());
}
// ## should filter all @Hidden frames?
return c == Method.class ||
- MethodAccessor.class.isAssignableFrom(c) ||
- c.getName().startsWith("java.lang.invoke.LambdaForm");
+ c == Constructor.class ||
+ MethodAccessor.class.isAssignableFrom(c) ||
+ ConstructorAccessor.class.isAssignableFrom(c) ||
+ c.getName().startsWith("java.lang.invoke.LambdaForm");
}
}
diff --git a/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java b/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java
index d95ea5ef826..79b4c7299f6 100644
--- a/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java
+++ b/jdk/src/java.base/share/classes/java/lang/StackTraceElement.java
@@ -92,6 +92,8 @@ public final class StackTraceElement implements java.io.Serializable {
* @throws NullPointerException if {@code declaringClass} or
* {@code methodName} is null
* @since 1.5
+ * @revised 9
+ * @spec JPMS
*/
public StackTraceElement(String declaringClass, String methodName,
String fileName, int lineNumber) {
@@ -128,6 +130,7 @@ public final class StackTraceElement implements java.io.Serializable {
* or {@code methodName} is {@code null}
*
* @since 9
+ * @spec JPMS
*/
public StackTraceElement(String classLoaderName,
String moduleName, String moduleVersion,
@@ -187,6 +190,7 @@ public final class StackTraceElement implements java.io.Serializable {
* point represented by this stack trace element; {@code null}
* if the module name is not available.
* @since 9
+ * @spec JPMS
* @see java.lang.reflect.Module#getName()
*/
public String getModuleName() {
@@ -201,6 +205,7 @@ public final class StackTraceElement implements java.io.Serializable {
* point represented by this stack trace element; {@code null}
* if the module version is not available.
* @since 9
+ * @spec JPMS
* @see java.lang.module.ModuleDescriptor.Version
*/
public String getModuleVersion() {
@@ -216,6 +221,7 @@ public final class StackTraceElement implements java.io.Serializable {
* if the class loader is not named.
*
* @since 9
+ * @spec JPMS
* @see java.lang.ClassLoader#getName()
*/
public String getClassLoaderName() {
@@ -329,6 +335,8 @@ public final class StackTraceElement implements java.io.Serializable {
* {@link java.lang.StackWalker.StackFrame}, where an implementation may
* choose to omit some element in the returned string.
*
+ * @revised 9
+ * @spec JPMS
* @see Throwable#printStackTrace()
*/
public String toString() {
@@ -376,6 +384,9 @@ public final class StackTraceElement implements java.io.Serializable {
* @return true if the specified object is another
* {@code StackTraceElement} instance representing the same
* execution point as this instance.
+ *
+ * @revised 9
+ * @spec JPMS
*/
public boolean equals(Object obj) {
if (obj==this)
diff --git a/jdk/src/java.base/share/classes/java/lang/StackWalker.java b/jdk/src/java.base/share/classes/java/lang/StackWalker.java
index b5c43fd2d67..52d9637c138 100644
--- a/jdk/src/java.base/share/classes/java/lang/StackWalker.java
+++ b/jdk/src/java.base/share/classes/java/lang/StackWalker.java
@@ -29,6 +29,7 @@ import jdk.internal.reflect.CallerSensitive;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.function.Predicate;
import java.util.stream.Stream;
/**
@@ -207,13 +208,23 @@ public final class StackWalker {
/**
* Shows all reflection frames.
*
- *
By default, reflection frames are hidden. This includes the
- * {@link java.lang.reflect.Method#invoke} method
- * and the reflection implementation classes. A {@code StackWalker} with
- * this {@code SHOW_REFLECT_FRAMES} option will show all reflection frames.
- * The {@link #SHOW_HIDDEN_FRAMES} option can also be used to show all
+ *
By default, reflection frames are hidden. A {@code StackWalker}
+ * configured with this {@code SHOW_REFLECT_FRAMES} option
+ * will show all reflection frames that
+ * include {@link java.lang.reflect.Method#invoke} and
+ * {@link java.lang.reflect.Constructor#newInstance(Object...)}
+ * and their reflection implementation classes.
+ *
+ *
The {@link #SHOW_HIDDEN_FRAMES} option can also be used to show all
* reflection frames and it will also show other hidden frames that
* are implementation-specific.
+ *
+ * @apiNote
+ * This option includes the stack frames representing the invocation of
+ * {@code Method} and {@code Constructor}. Any utility methods that
+ * are equivalent to calling {@code Method.invoke} or
+ * {@code Constructor.newInstance} such as {@code Class.newInstance}
+ * are not filtered or controlled by any stack walking option.
*/
SHOW_REFLECT_FRAMES,
/**
@@ -465,28 +476,31 @@ public final class StackWalker {
}
/**
- * Gets the {@code Class} object of the caller invoking the method
- * that calls this {@code getCallerClass} method.
+ * Gets the {@code Class} object of the caller who invoked the method
+ * that invoked {@code getCallerClass}.
*
- *
Reflection frames, {@link java.lang.invoke.MethodHandle}, and
- * hidden frames are filtered regardless of the
+ *
This method filters {@linkplain Option#SHOW_REFLECT_FRAMES reflection
+ * frames}, {@link java.lang.invoke.MethodHandle}, and
+ * {@linkplain Option#SHOW_HIDDEN_FRAMES hidden frames} regardless of the
* {@link Option#SHOW_REFLECT_FRAMES SHOW_REFLECT_FRAMES}
* and {@link Option#SHOW_HIDDEN_FRAMES SHOW_HIDDEN_FRAMES} options
* this {@code StackWalker} has been configured with.
*
+ *
This method should be called when a caller frame is present. If
+ * it is called from the bottom most frame on the stack,
+ * {@code IllegalCallerException} will be thrown.
+ *
*
This method throws {@code UnsupportedOperationException}
* if this {@code StackWalker} is not configured with the
* {@link Option#RETAIN_CLASS_REFERENCE RETAIN_CLASS_REFERENCE} option.
- * This method should be called when a caller frame is present. If
- * it is called from the last frame on the stack,
- * {@code IllegalStateException} will be thrown.
*
* @apiNote
* For example, {@code Util::getResourceBundle} loads a resource bundle
- * on behalf of the caller. It calls this {@code getCallerClass} method
- * to find the method calling {@code Util::getResourceBundle} and uses the caller's
- * class loader to load the resource bundle. The caller class in this example
- * is the {@code MyTool} class.
+ * on behalf of the caller. It invokes {@code getCallerClass} to identify
+ * the class whose method called {@code Util::getResourceBundle}.
+ * Then, it obtains the class loader of that class, and uses
+ * the class loader to load the resource bundle. The caller class
+ * in this example is {@code MyTool}.
*
*
{@code
* class Util {
@@ -517,17 +531,17 @@ public final class StackWalker {
* }
*
* When the {@code getCallerClass} method is called from a method that
- * is the last frame on the stack,
+ * is the bottom most frame on the stack,
* for example, {@code static public void main} method launched by the
* {@code java} launcher, or a method invoked from a JNI attached thread,
- * {@code IllegalStateException} is thrown.
+ * {@code IllegalCallerException} is thrown.
*
* @return {@code Class} object of the caller's caller invoking this method.
*
* @throws UnsupportedOperationException if this {@code StackWalker}
* is not configured with {@link Option#RETAIN_CLASS_REFERENCE
* Option.RETAIN_CLASS_REFERENCE}.
- * @throws IllegalStateException if there is no caller frame, i.e.
+ * @throws IllegalCallerException if there is no caller frame, i.e.
* when this {@code getCallerClass} method is called from a method
* which is the last frame on the stack.
*/
diff --git a/jdk/src/java.base/share/classes/java/lang/StringCoding.java b/jdk/src/java.base/share/classes/java/lang/StringCoding.java
index ccbe6f24b43..7340fed04ca 100644
--- a/jdk/src/java.base/share/classes/java/lang/StringCoding.java
+++ b/jdk/src/java.base/share/classes/java/lang/StringCoding.java
@@ -46,9 +46,6 @@ import sun.nio.cs.ArrayEncoder;
import static java.lang.String.LATIN1;
import static java.lang.String.UTF16;
import static java.lang.String.COMPACT_STRINGS;
-import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Utility class for string encoding and decoding.
@@ -64,6 +61,10 @@ class StringCoding {
private static final ThreadLocal> encoder =
new ThreadLocal<>();
+ private static final Charset ISO_8859_1 = Charset.forName("iso-8859-1");
+ private static final Charset US_ASCII = Charset.forName("us-ascii");
+ private static final Charset UTF_8 = Charset.forName("utf-8");
+
private static boolean warnUnsupportedCharset = true;
private static T deref(ThreadLocal> tl) {
diff --git a/jdk/src/java.base/share/classes/java/lang/System.java b/jdk/src/java.base/share/classes/java/lang/System.java
index 1577e215e35..17e6f605401 100644
--- a/jdk/src/java.base/share/classes/java/lang/System.java
+++ b/jdk/src/java.base/share/classes/java/lang/System.java
@@ -534,6 +534,8 @@ public final class System {
* @param x object for which the hashCode is to be calculated
* @return the hashCode
* @since 1.1
+ * @see Object#hashCode
+ * @see java.util.Objects#hashCode(Object)
*/
@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);
@@ -1942,10 +1944,6 @@ public final class System {
* the application classpath or modulepath.
*/
private static void initPhase3() {
- // Initialize publicLookup early, to avoid bootstrapping circularities
- // with security manager using java.lang.invoke infrastructure.
- java.lang.invoke.MethodHandles.publicLookup();
-
// set security manager
String cn = System.getProperty("java.security.manager");
if (cn != null) {
@@ -2053,6 +2051,9 @@ public final class System {
public String fastUUID(long lsb, long msb) {
return Long.fastUUID(lsb, msb);
}
+ public void invalidatePackageAccessCache() {
+ SecurityManager.invalidatePackageAccessCache();
+ }
});
}
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java b/jdk/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java
index 3f91060ccc8..a7172138ae8 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java
@@ -26,6 +26,7 @@ package java.lang.invoke;
import sun.invoke.util.Wrapper;
+import static java.lang.invoke.MethodHandleInfo.*;
import static sun.invoke.util.Wrapper.forPrimitiveType;
import static sun.invoke.util.Wrapper.forWrapperType;
import static sun.invoke.util.Wrapper.isWrapperType;
@@ -56,11 +57,11 @@ import static sun.invoke.util.Wrapper.isWrapperType;
final String samMethodName; // Name of the SAM method "foo"
final MethodType samMethodType; // Type of the SAM method "(Object)Object"
final MethodHandle implMethod; // Raw method handle for the implementation method
+ final MethodType implMethodType; // Type of the implMethod MethodHandle "(CC,int)String"
final MethodHandleInfo implInfo; // Info about the implementation method handle "MethodHandleInfo[5 CC.impl(int)String]"
final int implKind; // Invocation kind for implementation "5"=invokevirtual
final boolean implIsInstanceMethod; // Is the implementation an instance method "true"
- final Class> implDefiningClass; // Type defining the implementation "class CC"
- final MethodType implMethodType; // Type of the implementation method "(int)String"
+ final Class> implClass; // Class for referencing the implementation method "class CC"
final MethodType instantiatedMethodType; // Instantiated erased functional interface method type "(Integer)Object"
final boolean isSerializable; // Should the returned instance be serializable
final Class>[] markerInterfaces; // Additional marker interfaces to be implemented
@@ -128,19 +129,51 @@ import static sun.invoke.util.Wrapper.isWrapperType;
this.samMethodType = samMethodType;
this.implMethod = implMethod;
+ this.implMethodType = implMethod.type();
this.implInfo = caller.revealDirect(implMethod);
- this.implKind = implInfo.getReferenceKind();
- this.implIsInstanceMethod =
- implKind == MethodHandleInfo.REF_invokeVirtual ||
- implKind == MethodHandleInfo.REF_invokeSpecial ||
- implKind == MethodHandleInfo.REF_invokeInterface;
- this.implDefiningClass = implInfo.getDeclaringClass();
- this.implMethodType = implInfo.getMethodType();
+ switch (implInfo.getReferenceKind()) {
+ case REF_invokeVirtual:
+ case REF_invokeInterface:
+ this.implClass = implMethodType.parameterType(0);
+ // reference kind reported by implInfo may not match implMethodType's first param
+ // Example: implMethodType is (Cloneable)String, implInfo is for Object.toString
+ this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
+ this.implIsInstanceMethod = true;
+ break;
+ case REF_invokeSpecial:
+ // JDK-8172817: should use referenced class here, but we don't know what it was
+ this.implClass = implInfo.getDeclaringClass();
+ this.implKind = REF_invokeSpecial;
+ this.implIsInstanceMethod = true;
+ break;
+ case REF_invokeStatic:
+ case REF_newInvokeSpecial:
+ // JDK-8172817: should use referenced class here for invokestatic, but we don't know what it was
+ this.implClass = implInfo.getDeclaringClass();
+ this.implKind = implInfo.getReferenceKind();
+ this.implIsInstanceMethod = false;
+ break;
+ default:
+ throw new LambdaConversionException(String.format("Unsupported MethodHandle kind: %s", implInfo));
+ }
+
this.instantiatedMethodType = instantiatedMethodType;
this.isSerializable = isSerializable;
this.markerInterfaces = markerInterfaces;
this.additionalBridges = additionalBridges;
+ if (samMethodName.isEmpty() ||
+ samMethodName.indexOf('.') >= 0 ||
+ samMethodName.indexOf(';') >= 0 ||
+ samMethodName.indexOf('[') >= 0 ||
+ samMethodName.indexOf('/') >= 0 ||
+ samMethodName.indexOf('<') >= 0 ||
+ samMethodName.indexOf('>') >= 0) {
+ throw new LambdaConversionException(String.format(
+ "Method name '%s' is not legal",
+ samMethodName));
+ }
+
if (!samBase.isInterface()) {
throw new LambdaConversionException(String.format(
"Functional interface %s is not an interface",
@@ -171,24 +204,12 @@ import static sun.invoke.util.Wrapper.isWrapperType;
* @throws LambdaConversionException if there are improper conversions
*/
void validateMetafactoryArgs() throws LambdaConversionException {
- switch (implKind) {
- case MethodHandleInfo.REF_invokeInterface:
- case MethodHandleInfo.REF_invokeVirtual:
- case MethodHandleInfo.REF_invokeStatic:
- case MethodHandleInfo.REF_newInvokeSpecial:
- case MethodHandleInfo.REF_invokeSpecial:
- break;
- default:
- throw new LambdaConversionException(String.format("Unsupported MethodHandle kind: %s", implInfo));
- }
-
- // Check arity: optional-receiver + captured + SAM == impl
+ // Check arity: captured + SAM == impl
final int implArity = implMethodType.parameterCount();
- final int receiverArity = implIsInstanceMethod ? 1 : 0;
final int capturedArity = invokedType.parameterCount();
final int samArity = samMethodType.parameterCount();
final int instantiatedArity = instantiatedMethodType.parameterCount();
- if (implArity + receiverArity != capturedArity + samArity) {
+ if (implArity != capturedArity + samArity) {
throw new LambdaConversionException(
String.format("Incorrect number of parameters for %s method %s; %d captured parameters, %d functional interface method parameters, %d implementation parameters",
implIsInstanceMethod ? "instance" : "static", implInfo,
@@ -209,8 +230,8 @@ import static sun.invoke.util.Wrapper.isWrapperType;
}
// If instance: first captured arg (receiver) must be subtype of class where impl method is defined
- final int capturedStart;
- final int samStart;
+ final int capturedStart; // index of first non-receiver capture parameter in implMethodType
+ final int samStart; // index of first non-receiver sam parameter in implMethodType
if (implIsInstanceMethod) {
final Class> receiverClass;
@@ -223,45 +244,36 @@ import static sun.invoke.util.Wrapper.isWrapperType;
} else {
// receiver is a captured variable
capturedStart = 1;
- samStart = 0;
+ samStart = capturedArity;
receiverClass = invokedType.parameterType(0);
}
// check receiver type
- if (!implDefiningClass.isAssignableFrom(receiverClass)) {
+ if (!implClass.isAssignableFrom(receiverClass)) {
throw new LambdaConversionException(
String.format("Invalid receiver type %s; not a subtype of implementation type %s",
- receiverClass, implDefiningClass));
- }
-
- Class> implReceiverClass = implMethod.type().parameterType(0);
- if (implReceiverClass != implDefiningClass && !implReceiverClass.isAssignableFrom(receiverClass)) {
- throw new LambdaConversionException(
- String.format("Invalid receiver type %s; not a subtype of implementation receiver type %s",
- receiverClass, implReceiverClass));
+ receiverClass, implClass));
}
} else {
// no receiver
capturedStart = 0;
- samStart = 0;
+ samStart = capturedArity;
}
// Check for exact match on non-receiver captured arguments
- final int implFromCaptured = capturedArity - capturedStart;
- for (int i=0; i implParamType = implMethodType.parameterType(i);
- Class> capturedParamType = invokedType.parameterType(i + capturedStart);
+ Class> capturedParamType = invokedType.parameterType(i);
if (!capturedParamType.equals(implParamType)) {
throw new LambdaConversionException(
String.format("Type mismatch in captured lambda parameter %d: expecting %s, found %s",
i, capturedParamType, implParamType));
}
}
- // Check for adaptation match on SAM arguments
- final int samOffset = samStart - implFromCaptured;
- for (int i=implFromCaptured; i implParamType = implMethodType.parameterType(i);
- Class> instantiatedParamType = instantiatedMethodType.parameterType(i + samOffset);
+ Class> instantiatedParamType = instantiatedMethodType.parameterType(i - capturedArity);
if (!isAdaptableTo(instantiatedParamType, implParamType, true)) {
throw new LambdaConversionException(
String.format("Type mismatch for lambda argument %d: %s is not convertible to %s",
@@ -271,29 +283,40 @@ import static sun.invoke.util.Wrapper.isWrapperType;
// Adaptation match: return type
Class> expectedType = instantiatedMethodType.returnType();
- Class> actualReturnType =
- (implKind == MethodHandleInfo.REF_newInvokeSpecial)
- ? implDefiningClass
- : implMethodType.returnType();
- Class> samReturnType = samMethodType.returnType();
+ Class> actualReturnType = implMethodType.returnType();
if (!isAdaptableToAsReturn(actualReturnType, expectedType)) {
throw new LambdaConversionException(
String.format("Type mismatch for lambda return: %s is not convertible to %s",
actualReturnType, expectedType));
}
- if (!isAdaptableToAsReturnStrict(expectedType, samReturnType)) {
- throw new LambdaConversionException(
- String.format("Type mismatch for lambda expected return: %s is not convertible to %s",
- expectedType, samReturnType));
- }
+
+ // Check descriptors of generated methods
+ checkDescriptor(samMethodType);
for (MethodType bridgeMT : additionalBridges) {
- if (!isAdaptableToAsReturnStrict(expectedType, bridgeMT.returnType())) {
- throw new LambdaConversionException(
- String.format("Type mismatch for lambda expected return: %s is not convertible to %s",
- expectedType, bridgeMT.returnType()));
+ checkDescriptor(bridgeMT);
+ }
+ }
+
+ /** Validate that the given descriptor's types are compatible with {@code instantiatedMethodType} **/
+ private void checkDescriptor(MethodType descriptor) throws LambdaConversionException {
+ for (int i = 0; i < instantiatedMethodType.parameterCount(); i++) {
+ Class> instantiatedParamType = instantiatedMethodType.parameterType(i);
+ Class> descriptorParamType = descriptor.parameterType(i);
+ if (!descriptorParamType.isAssignableFrom(instantiatedParamType)) {
+ String msg = String.format("Type mismatch for instantiated parameter %d: %s is not a subtype of %s",
+ i, instantiatedParamType, descriptorParamType);
+ throw new LambdaConversionException(msg);
}
}
- }
+
+ Class> instantiatedReturnType = instantiatedMethodType.returnType();
+ Class> descriptorReturnType = descriptor.returnType();
+ if (!isAdaptableToAsReturnStrict(instantiatedReturnType, descriptorReturnType)) {
+ String msg = String.format("Type mismatch for lambda expected return: %s is not convertible to %s",
+ instantiatedReturnType, descriptorReturnType);
+ throw new LambdaConversionException(msg);
+ }
+ }
/**
* Check type adaptability for parameter types.
@@ -345,8 +368,8 @@ import static sun.invoke.util.Wrapper.isWrapperType;
|| !fromType.equals(void.class) && isAdaptableTo(fromType, toType, false);
}
private boolean isAdaptableToAsReturnStrict(Class> fromType, Class> toType) {
- if (fromType.equals(void.class)) return toType.equals(void.class);
- return isAdaptableTo(fromType, toType, true);
+ if (fromType.equals(void.class) || toType.equals(void.class)) return fromType.equals(toType);
+ else return isAdaptableTo(fromType, toType, true);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java b/jdk/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java
index d11012e6487..cecfe5efc34 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java
@@ -98,21 +98,17 @@ abstract class DelegatingMethodHandle extends MethodHandle {
Object constraint,
NamedFunction getTargetFn) {
// No pre-action needed.
- return makeReinvokerForm(target, whichCache, constraint, null, true, getTargetFn, null);
+ return makeReinvokerForm(target, whichCache, constraint, true, getTargetFn, null);
}
/** Create a LF which simply reinvokes a target of the given basic type. */
static LambdaForm makeReinvokerForm(MethodHandle target,
int whichCache,
Object constraint,
- String debugString,
boolean forceInline,
NamedFunction getTargetFn,
NamedFunction preActionFn) {
MethodType mtype = target.type().basicType();
Kind kind = whichKind(whichCache);
- if (debugString == null) {
- debugString = kind.defaultLambdaName;
- }
boolean customized = (whichCache < 0 ||
mtype.parameterSlotCount() > MethodType.MAX_MH_INVOKER_ARITY);
boolean hasPreAction = (preActionFn != null);
@@ -144,7 +140,7 @@ abstract class DelegatingMethodHandle extends MethodHandle {
targetArgs[0] = names[NEXT_MH]; // overwrite this MH with next MH
names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
}
- form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline, kind);
+ form = new LambdaForm(ARG_LIMIT, names, forceInline, kind);
if (!customized) {
form = mtype.form().setCachedLambdaForm(whichCache, form);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java b/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java
index ce1f938583f..0b4bd58b624 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java
@@ -242,8 +242,7 @@ class DirectMethodHandle extends MethodHandle {
result = NEW_OBJ;
}
names[LINKER_CALL] = new Name(linker, outArgs);
- String lambdaName = kind.defaultLambdaName + "_" + shortenSignature(basicTypeSignature(mtype));
- LambdaForm lform = new LambdaForm(lambdaName, ARG_LIMIT, names, result, kind);
+ LambdaForm lform = new LambdaForm(ARG_LIMIT, names, result, kind);
// This is a tricky bit of code. Don't send it through the LF interpreter.
lform.compileToBytecode();
@@ -696,22 +695,33 @@ class DirectMethodHandle extends MethodHandle {
if (needsCast && isGetter)
names[POST_CAST] = new Name(NF_checkCast, names[DMH_THIS], names[LINKER_CALL]);
for (Name n : names) assert(n != null);
- // add some detail to the lambdaForm debugname,
- // significant only for debugging
- StringBuilder nameBuilder = new StringBuilder(kind.methodName);
- if (isStatic) {
- nameBuilder.append("Static");
- } else {
- nameBuilder.append("Field");
- }
- if (needsCast) nameBuilder.append("Cast");
- if (needsInit) nameBuilder.append("Init");
+
+ LambdaForm form;
if (needsCast || needsInit) {
// can't use the pre-generated form when casting and/or initializing
- return new LambdaForm(nameBuilder.toString(), ARG_LIMIT, names, RESULT);
+ form = new LambdaForm(ARG_LIMIT, names, RESULT);
} else {
- return new LambdaForm(nameBuilder.toString(), ARG_LIMIT, names, RESULT, kind);
+ form = new LambdaForm(ARG_LIMIT, names, RESULT, kind);
}
+
+ if (LambdaForm.debugNames()) {
+ // add some detail to the lambdaForm debugname,
+ // significant only for debugging
+ StringBuilder nameBuilder = new StringBuilder(kind.methodName);
+ if (isStatic) {
+ nameBuilder.append("Static");
+ } else {
+ nameBuilder.append("Field");
+ }
+ if (needsCast) {
+ nameBuilder.append("Cast");
+ }
+ if (needsInit) {
+ nameBuilder.append("Init");
+ }
+ LambdaForm.associateWithDebugName(form, nameBuilder.toString());
+ }
+ return form;
}
/**
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java
index 0c814bdd470..35f91cc243b 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java
@@ -96,7 +96,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
private final String implMethodClassName; // Name of type containing implementation "CC"
private final String implMethodName; // Name of implementation method "impl"
private final String implMethodDesc; // Type descriptor for implementation methods "(I)Ljava/lang/String;"
- private final Class> implMethodReturnClass; // class for implementation method return type "Ljava/lang/String;"
private final MethodType constructorType; // Generated class constructor type "(CC)void"
private final ClassWriter cw; // ASM class writer
private final String[] argNames; // Generated names for the constructor arguments
@@ -153,12 +152,9 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
super(caller, invokedType, samMethodName, samMethodType,
implMethod, instantiatedMethodType,
isSerializable, markerInterfaces, additionalBridges);
- implMethodClassName = implDefiningClass.getName().replace('.', '/');
+ implMethodClassName = implClass.getName().replace('.', '/');
implMethodName = implInfo.getName();
- implMethodDesc = implMethodType.toMethodDescriptorString();
- implMethodReturnClass = (implKind == MethodHandleInfo.REF_newInvokeSpecial)
- ? implDefiningClass
- : implMethodType.returnType();
+ implMethodDesc = implInfo.getMethodType().toMethodDescriptorString();
constructorType = invokedType.changeReturnType(Void.TYPE);
lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
@@ -467,13 +463,14 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
// Invoke the method we want to forward to
visitMethodInsn(invocationOpcode(), implMethodClassName,
implMethodName, implMethodDesc,
- implDefiningClass.isInterface());
+ implClass.isInterface());
// Convert the return value (if any) and return it
// Note: if adapting from non-void to void, the 'return'
// instruction will pop the unneeded result
+ Class> implReturnClass = implMethodType.returnType();
Class> samReturnClass = methodType.returnType();
- convertType(implMethodReturnClass, samReturnClass, samReturnClass);
+ convertType(implReturnClass, samReturnClass, samReturnClass);
visitInsn(getReturnOpcode(samReturnClass));
// Maxs computed by ClassWriter.COMPUTE_MAXS,these arguments ignored
visitMaxs(-1, -1);
@@ -482,23 +479,13 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
private void convertArgumentTypes(MethodType samType) {
int lvIndex = 0;
- boolean samIncludesReceiver = implIsInstanceMethod &&
- invokedType.parameterCount() == 0;
- int samReceiverLength = samIncludesReceiver ? 1 : 0;
- if (samIncludesReceiver) {
- // push receiver
- Class> rcvrType = samType.parameterType(0);
- visitVarInsn(getLoadOpcode(rcvrType), lvIndex + 1);
- lvIndex += getParameterSize(rcvrType);
- convertType(rcvrType, implDefiningClass, instantiatedMethodType.parameterType(0));
- }
int samParametersLength = samType.parameterCount();
- int argOffset = implMethodType.parameterCount() - samParametersLength;
- for (int i = samReceiverLength; i < samParametersLength; i++) {
+ int captureArity = invokedType.parameterCount();
+ for (int i = 0; i < samParametersLength; i++) {
Class> argType = samType.parameterType(i);
visitVarInsn(getLoadOpcode(argType), lvIndex + 1);
lvIndex += getParameterSize(argType);
- convertType(argType, implMethodType.parameterType(argOffset + i), instantiatedMethodType.parameterType(i));
+ convertType(argType, implMethodType.parameterType(captureArity + i), instantiatedMethodType.parameterType(i));
}
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
index d903d488211..ec81f5093b6 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
@@ -130,7 +130,7 @@ class InvokerBytecodeGenerator {
/** For generating customized code for a single LambdaForm. */
private InvokerBytecodeGenerator(String className, LambdaForm form, MethodType invokerType) {
- this(className, form.debugName, form, invokerType);
+ this(className, form.lambdaName(), form, invokerType);
}
/** For generating customized code for a single LambdaForm. */
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java b/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java
index 0a97622fe84..a221af7e086 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java
@@ -132,7 +132,7 @@ class Invokers {
MethodType mtype = targetType;
MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
- LambdaForm lform = varHandleMethodInvokerHandleForm(ak.methodName(), mtype, isExact);
+ LambdaForm lform = varHandleMethodInvokerHandleForm(ak, mtype, isExact);
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
@@ -325,9 +325,9 @@ class Invokers {
}
names[LINKER_CALL] = new Name(outCallType, outArgs);
if (customized) {
- lform = new LambdaForm(kind.defaultLambdaName, INARG_LIMIT, names);
+ lform = new LambdaForm(INARG_LIMIT, names);
} else {
- lform = new LambdaForm(kind.defaultLambdaName, INARG_LIMIT, names, kind);
+ lform = new LambdaForm(INARG_LIMIT, names, kind);
}
if (isLinker)
lform.compileToBytecode(); // JVM needs a real methodOop
@@ -337,11 +337,10 @@ class Invokers {
}
- static MemberName varHandleInvokeLinkerMethod(String name,
- MethodType mtype) {
+ static MemberName varHandleInvokeLinkerMethod(VarHandle.AccessMode ak, MethodType mtype) {
LambdaForm lform;
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
- lform = varHandleMethodGenericLinkerHandleForm(name, mtype);
+ lform = varHandleMethodGenericLinkerHandleForm(ak, mtype);
} else {
// TODO
throw newInternalError("Unsupported parameter slot count " + mtype.parameterSlotCount());
@@ -349,7 +348,8 @@ class Invokers {
return lform.vmentry;
}
- private static LambdaForm varHandleMethodGenericLinkerHandleForm(String name, MethodType mtype) {
+ private static LambdaForm varHandleMethodGenericLinkerHandleForm(VarHandle.AccessMode ak,
+ MethodType mtype) {
// TODO Cache form?
final int THIS_VH = 0;
@@ -383,14 +383,18 @@ class Invokers {
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType();
names[LINKER_CALL] = new Name(outCallType, outArgs);
- LambdaForm lform = new LambdaForm(name + ":VarHandle_invoke_MT_" + shortenSignature(basicTypeSignature(mtype)),
- ARG_LIMIT + 1, names);
-
+ LambdaForm lform = new LambdaForm(ARG_LIMIT + 1, names, VARHANDLE_LINKER);
+ if (LambdaForm.debugNames()) {
+ String name = ak.methodName() + ":VarHandle_invoke_MT_" +
+ shortenSignature(basicTypeSignature(mtype));
+ LambdaForm.associateWithDebugName(lform, name);
+ }
lform.compileToBytecode();
return lform;
}
- private static LambdaForm varHandleMethodInvokerHandleForm(String name, MethodType mtype, boolean isExact) {
+ private static LambdaForm varHandleMethodInvokerHandleForm(VarHandle.AccessMode ak,
+ MethodType mtype, boolean isExact) {
// TODO Cache form?
final int THIS_MH = 0;
@@ -429,10 +433,14 @@ class Invokers {
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType();
names[LINKER_CALL] = new Name(outCallType, outArgs);
- String debugName = isExact ? ":VarHandle_exactInvoker" : ":VarHandle_invoker";
- LambdaForm lform = new LambdaForm(name + debugName + shortenSignature(basicTypeSignature(mtype)),
- ARG_LIMIT, names);
-
+ Kind kind = isExact ? VARHANDLE_EXACT_INVOKER : VARHANDLE_INVOKER;
+ LambdaForm lform = new LambdaForm(ARG_LIMIT, names, kind);
+ if (LambdaForm.debugNames()) {
+ String name = ak.methodName() +
+ (isExact ? ":VarHandle_exactInvoker_" : ":VarHandle_invoker_") +
+ shortenSignature(basicTypeSignature(mtype));
+ LambdaForm.associateWithDebugName(lform, name);
+ }
lform.prepare();
return lform;
}
@@ -543,7 +551,8 @@ class Invokers {
System.arraycopy(outArgs, 0, outArgs, PREPEND_COUNT, outArgs.length - PREPEND_COUNT);
outArgs[PREPEND_MH] = names[CALL_MH];
names[LINKER_CALL] = new Name(mtype, outArgs);
- lform = new LambdaForm((skipCallSite ? "linkToTargetMethod" : "linkToCallSite"), INARG_LIMIT, names);
+ lform = new LambdaForm(INARG_LIMIT, names,
+ (skipCallSite ? LINK_TO_TARGET_METHOD : LINK_TO_CALL_SITE));
lform.compileToBytecode(); // JVM needs a real methodOop
lform = mtype.form().setCachedLambdaForm(which, lform);
return lform;
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java
index 96b0a944800..0048afbfd9e 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2016, 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
@@ -126,7 +126,6 @@ class LambdaForm {
final boolean forceInline;
final MethodHandle customized;
@Stable final Name[] names;
- final String debugName;
final Kind kind;
MemberName vmentry; // low-level behavior, or null if not yet prepared
private boolean isCompiled;
@@ -268,7 +267,7 @@ class LambdaForm {
}
enum Kind {
- GENERIC(""),
+ GENERIC("invoke"),
ZERO("zero"),
IDENTITY("identity"),
BOUND_REINVOKER("BMH.reinvoke"),
@@ -278,6 +277,8 @@ class LambdaForm {
EXACT_INVOKER("MH.exactInvoker"),
GENERIC_LINKER("MH.invoke_MT"),
GENERIC_INVOKER("MH.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"),
@@ -319,7 +320,18 @@ class LambdaForm {
GET_DOUBLE("getDouble"),
PUT_DOUBLE("putDouble"),
GET_DOUBLE_VOLATILE("getDoubleVolatile"),
- PUT_DOUBLE_VOLATILE("putDoubleVolatile");
+ PUT_DOUBLE_VOLATILE("putDoubleVolatile"),
+ TRY_FINALLY("tryFinally"),
+ COLLECT("collect"),
+ CONVERT("convert"),
+ SPREAD("spread"),
+ LOOP("loop"),
+ FIELD("field"),
+ GUARD("guard"),
+ GUARD_WITH_CATCH("guardWithCatch"),
+ VARHANDLE_EXACT_INVOKER("VH.exactInvoker"),
+ VARHANDLE_INVOKER("VH.invoker"),
+ VARHANDLE_LINKER("VH.invoke_MT");
final String defaultLambdaName;
final String methodName;
@@ -335,25 +347,20 @@ class LambdaForm {
}
}
- LambdaForm(String debugName,
- int arity, Name[] names, int result) {
- this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
+ LambdaForm(int arity, Name[] names, int result) {
+ this(arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
}
- LambdaForm(String debugName,
- int arity, Name[] names, int result, Kind kind) {
- this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
+ LambdaForm(int arity, Name[] names, int result, Kind kind) {
+ this(arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
}
- LambdaForm(String debugName,
- int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
- this(debugName, arity, names, result, forceInline, customized, Kind.GENERIC);
+ LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
+ this(arity, names, result, forceInline, customized, Kind.GENERIC);
}
- LambdaForm(String debugName,
- int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
+ LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
assert(namesOK(arity, names));
this.arity = arity;
this.result = fixResult(result, names);
this.names = names.clone();
- this.debugName = fixDebugName(debugName);
this.forceInline = forceInline;
this.customized = customized;
this.kind = kind;
@@ -364,31 +371,23 @@ class LambdaForm {
compileToBytecode();
}
}
- LambdaForm(String debugName,
- int arity, Name[] names) {
- this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
+ LambdaForm(int arity, Name[] names) {
+ this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
}
- LambdaForm(String debugName,
- int arity, Name[] names, Kind kind) {
- this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind);
+ LambdaForm(int arity, Name[] names, Kind kind) {
+ this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind);
}
- LambdaForm(String debugName,
- int arity, Name[] names, boolean forceInline) {
- this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
+ LambdaForm(int arity, Name[] names, boolean forceInline) {
+ this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
}
- LambdaForm(String debugName,
- int arity, Name[] names, boolean forceInline, Kind kind) {
- this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
+ LambdaForm(int arity, Name[] names, boolean forceInline, Kind kind) {
+ this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
}
- LambdaForm(String debugName,
- Name[] formals, Name[] temps, Name result) {
- this(debugName,
- formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
+ LambdaForm(Name[] formals, Name[] temps, Name result) {
+ this(formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
}
- LambdaForm(String debugName,
- Name[] formals, Name[] temps, Name result, boolean forceInline) {
- this(debugName,
- formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null);
+ LambdaForm(Name[] formals, Name[] temps, Name result, boolean forceInline) {
+ this(formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null);
}
private static Name[] buildNames(Name[] formals, Name[] temps, Name result) {
@@ -408,10 +407,9 @@ class LambdaForm {
this.arity = mt.parameterCount();
this.result = (mt.returnType() == void.class || mt.returnType() == Void.class) ? -1 : arity;
this.names = buildEmptyNames(arity, mt, result == -1);
- this.debugName = "LF.zero";
this.forceInline = true;
this.customized = null;
- this.kind = Kind.GENERIC;
+ this.kind = Kind.ZERO;
assert(nameRefsAreLegal());
assert(isEmpty());
String sig = null;
@@ -436,36 +434,46 @@ class LambdaForm {
return result;
}
- private static String fixDebugName(String debugName) {
- if (DEBUG_NAME_COUNTERS != null) {
- int under = debugName.indexOf('_');
- int length = debugName.length();
- if (under < 0) under = length;
- String debugNameStem = debugName.substring(0, under);
- Integer ctr;
- synchronized (DEBUG_NAME_COUNTERS) {
- ctr = DEBUG_NAME_COUNTERS.get(debugNameStem);
- if (ctr == null) ctr = 0;
- DEBUG_NAME_COUNTERS.put(debugNameStem, ctr+1);
- }
- StringBuilder buf = new StringBuilder(debugNameStem);
- buf.append('_');
- int leadingZero = buf.length();
- buf.append((int) ctr);
- for (int i = buf.length() - leadingZero; i < 3; i++)
- buf.insert(leadingZero, '0');
- if (under < length) {
- ++under; // skip "_"
- while (under < length && Character.isDigit(debugName.charAt(under))) {
- ++under;
- }
- if (under < length && debugName.charAt(under) == '_') ++under;
- if (under < length)
- buf.append('_').append(debugName, under, length);
- }
- return buf.toString();
+ static boolean debugNames() {
+ return DEBUG_NAME_COUNTERS != null;
+ }
+
+ static void associateWithDebugName(LambdaForm form, String name) {
+ assert (debugNames());
+ synchronized (DEBUG_NAMES) {
+ DEBUG_NAMES.put(form, name);
}
- return debugName;
+ }
+
+ String lambdaName() {
+ if (DEBUG_NAMES != null) {
+ synchronized (DEBUG_NAMES) {
+ String name = DEBUG_NAMES.get(this);
+ if (name == null) {
+ name = generateDebugName();
+ }
+ return name;
+ }
+ }
+ return kind.defaultLambdaName;
+ }
+
+ private String generateDebugName() {
+ assert (debugNames());
+ String debugNameStem = kind.defaultLambdaName;
+ Integer ctr = DEBUG_NAME_COUNTERS.getOrDefault(debugNameStem, 0);
+ DEBUG_NAME_COUNTERS.put(debugNameStem, ctr + 1);
+ StringBuilder buf = new StringBuilder(debugNameStem);
+ int leadingZero = buf.length();
+ buf.append((int) ctr);
+ for (int i = buf.length() - leadingZero; i < 3; i++) {
+ buf.insert(leadingZero, '0');
+ }
+ buf.append('_');
+ buf.append(basicTypeSignature());
+ String name = buf.toString();
+ associateWithDebugName(this, name);
+ return name;
}
private static boolean namesOK(int arity, Name[] names) {
@@ -482,7 +490,7 @@ class LambdaForm {
/** Customize LambdaForm for a particular MethodHandle */
LambdaForm customize(MethodHandle mh) {
- LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh, kind);
+ LambdaForm customForm = new LambdaForm(arity, names, result, forceInline, mh, kind);
if (COMPILE_THRESHOLD >= 0 && isCompiled) {
// If shared LambdaForm has been compiled, compile customized version as well.
customForm.compileToBytecode();
@@ -1030,7 +1038,8 @@ class LambdaForm {
}
public String toString() {
- StringBuilder buf = new StringBuilder(debugName+"=Lambda(");
+ String lambdaName = lambdaName();
+ StringBuilder buf = new StringBuilder(lambdaName + "=Lambda(");
for (int i = 0; i < names.length; i++) {
if (i == arity) buf.append(")=>{");
Name n = names[i];
@@ -1742,7 +1751,7 @@ class LambdaForm {
// bootstrap dependency on this method in case we're interpreting LFs
if (isVoid) {
Name[] idNames = new Name[] { argument(0, L_TYPE) };
- idForm = new LambdaForm(idMem.getName(), 1, idNames, VOID_RESULT, Kind.IDENTITY);
+ idForm = new LambdaForm(1, idNames, VOID_RESULT, Kind.IDENTITY);
idForm.compileToBytecode();
idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm));
@@ -1750,14 +1759,14 @@ class LambdaForm {
zeFun = idFun;
} else {
Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) };
- idForm = new LambdaForm(idMem.getName(), 2, idNames, 1, Kind.IDENTITY);
+ idForm = new LambdaForm(2, idNames, 1, Kind.IDENTITY);
idForm.compileToBytecode();
idFun = new NamedFunction(idMem, MethodHandleImpl.makeIntrinsic(
idMem.getInvocationType(), idForm, MethodHandleImpl.Intrinsic.IDENTITY));
Object zeValue = Wrapper.forBasicType(btChar).zero();
Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) };
- zeForm = new LambdaForm(zeMem.getName(), 1, zeNames, 1, Kind.ZERO);
+ zeForm = new LambdaForm(1, zeNames, 1, Kind.ZERO);
zeForm.compileToBytecode();
zeFun = new NamedFunction(zeMem, MethodHandleImpl.makeIntrinsic(
zeMem.getInvocationType(), zeForm, MethodHandleImpl.Intrinsic.ZERO));
@@ -1805,11 +1814,15 @@ class LambdaForm {
}
private static final HashMap DEBUG_NAME_COUNTERS;
+ private static final HashMap DEBUG_NAMES;
static {
- if (debugEnabled())
+ if (debugEnabled()) {
DEBUG_NAME_COUNTERS = new HashMap<>();
- else
+ DEBUG_NAMES = new HashMap<>();
+ } else {
DEBUG_NAME_COUNTERS = null;
+ DEBUG_NAMES = null;
+ }
}
static {
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java
index cc4b97b5479..bcf1733461b 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormBuffer.java
@@ -40,7 +40,6 @@ final class LambdaFormBuffer {
private byte flags;
private int firstChange;
private Name resultName;
- private String debugName;
private ArrayList dups;
private static final int F_TRANS = 0x10, F_OWNED = 0x03;
@@ -50,15 +49,15 @@ final class LambdaFormBuffer {
setNames(lf.names);
int result = lf.result;
if (result == LAST_RESULT) result = length - 1;
- if (result >= 0 && lf.names[result].type != V_TYPE)
+ if (result >= 0 && lf.names[result].type != V_TYPE) {
resultName = lf.names[result];
- debugName = lf.debugName;
+ }
assert(lf.nameRefsAreLegal());
}
private LambdaForm lambdaForm() {
assert(!inTrans()); // need endEdit call to tidy things up
- return new LambdaForm(debugName, arity, nameArray(), resultIndex());
+ return new LambdaForm(arity, nameArray(), resultIndex());
}
Name name(int i) {
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java
index ddd60ca082f..2d9c87ad0d4 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java
@@ -915,7 +915,7 @@ class LambdaFormEditor {
}
}
- form = new LambdaForm(lambdaForm.debugName, arity2, names2, result2);
+ form = new LambdaForm(arity2, names2, result2);
return putInCache(key, form);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
index 010b61809ee..8ea5553fccc 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
@@ -399,7 +399,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
assert(RETURN_CONV == names.length-1);
}
- LambdaForm form = new LambdaForm("convert", lambdaType.parameterCount(), names, RESULT);
+ LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, RESULT, Kind.CONVERT);
return SimpleMethodHandle.make(srcType, form);
}
@@ -608,7 +608,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
}
names[names.length - 1] = new Name(target, (Object[]) targetArgs);
- LambdaForm form = new LambdaForm("spread", lambdaType.parameterCount(), names);
+ LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.SPREAD);
return SimpleMethodHandle.make(srcType, form);
}
@@ -676,7 +676,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
assert(inputArgPos + chunk == collectNamePos); // use of rest of input args also
names[targetNamePos] = new Name(target, (Object[]) targetArgs);
- LambdaForm form = new LambdaForm("collect", lambdaType.parameterCount(), names);
+ LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.COLLECT);
return SimpleMethodHandle.make(srcType, form);
}
@@ -774,7 +774,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
@Override
public LambdaForm apply(MethodHandle target) {
return DelegatingMethodHandle.makeReinvokerForm(target,
- MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
+ MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, false,
DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
}
};
@@ -943,7 +943,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
invokeArgs[0] = names[SELECT_ALT];
names[CALL_TARGET] = new Name(basicType, invokeArgs);
- lform = new LambdaForm("guard", lambdaType.parameterCount(), names, /*forceInline=*/true);
+ lform = new LambdaForm(lambdaType.parameterCount(), names, /*forceInline=*/true, Kind.GUARD);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWT, lform);
}
@@ -1019,7 +1019,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
Object[] unboxArgs = new Object[] {names[GET_UNBOX_RESULT], names[TRY_CATCH]};
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
- lform = new LambdaForm("guardWithCatch", lambdaType.parameterCount(), names);
+ lform = new LambdaForm(lambdaType.parameterCount(), names, Kind.GUARD_WITH_CATCH);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWC, lform);
}
@@ -1886,7 +1886,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
lform = basicType.form().setCachedLambdaForm(MethodTypeForm.LF_LOOP,
- new LambdaForm("loop", lambdaType.parameterCount(), names));
+ new LambdaForm(lambdaType.parameterCount(), names, Kind.LOOP));
}
// BOXED_ARGS is the index into the names array where the loop idiom starts
@@ -2120,7 +2120,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
Object[] unboxArgs = new Object[] {names[GET_UNBOX_RESULT], names[TRY_FINALLY]};
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
- lform = new LambdaForm("tryFinally", lambdaType.parameterCount(), names);
+ lform = new LambdaForm(lambdaType.parameterCount(), names, Kind.TRY_FINALLY);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_TF, lform);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
index 1065b8d1482..110369fb13e 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java
@@ -420,7 +420,7 @@ class MethodHandleNatives {
MethodType mtype,
Object[] appendixResult) {
// Get the signature method type
- MethodType sigType = mtype.basicType();
+ final MethodType sigType = mtype.basicType();
// Get the access kind from the method name
VarHandle.AccessMode ak;
@@ -430,32 +430,37 @@ class MethodHandleNatives {
throw MethodHandleStatics.newInternalError(e);
}
- // If not polymorphic in the return type, such as the compareAndSet
- // methods that return boolean
- if (ak.at.isMonomorphicInReturnType) {
- if (ak.at.returnType != mtype.returnType()) {
- // The caller contains a different return type than that
- // defined by the method
- throw newNoSuchMethodErrorOnVarHandle(name, mtype);
- }
- // Adjust the return type of the signature method type
- sigType = sigType.changeReturnType(ak.at.returnType);
- }
-
- // Get the guard method type for linking
- MethodType guardType = sigType
- // VarHandle at start
- .insertParameterTypes(0, VarHandle.class)
- // Access descriptor at end
- .appendParameterTypes(VarHandle.AccessDescriptor.class);
-
// Create the appendix descriptor constant
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
appendixResult[0] = ad;
if (MethodHandleStatics.VAR_HANDLE_GUARDS) {
+ // If not polymorphic in the return type, such as the compareAndSet
+ // methods that return boolean
+ Class> guardReturnType = sigType.returnType();
+ if (ak.at.isMonomorphicInReturnType) {
+ if (ak.at.returnType != mtype.returnType()) {
+ // The caller contains a different return type than that
+ // defined by the method
+ throw newNoSuchMethodErrorOnVarHandle(name, mtype);
+ }
+ // Adjust the return type of the signature method type
+ guardReturnType = ak.at.returnType;
+ }
+
+ // Get the guard method type for linking
+ final Class>[] guardParams = new Class>[sigType.parameterCount() + 2];
+ // VarHandle at start
+ guardParams[0] = VarHandle.class;
+ for (int i = 0; i < sigType.parameterCount(); i++) {
+ guardParams[i + 1] = sigType.parameterType(i);
+ }
+ // Access descriptor at end
+ guardParams[guardParams.length - 1] = VarHandle.AccessDescriptor.class;
+ MethodType guardType = MethodType.makeImpl(guardReturnType, guardParams, true);
+
MemberName linker = new MemberName(
- VarHandleGuards.class, "guard_" + getVarHandleMethodSignature(sigType),
+ VarHandleGuards.class, getVarHandleGuardMethodName(guardType),
guardType, REF_invokeStatic);
linker = MemberName.getFactory().resolveOrNull(REF_invokeStatic, linker,
@@ -466,16 +471,18 @@ class MethodHandleNatives {
// Fall back to lambda form linkage if guard method is not available
// TODO Optionally log fallback ?
}
- return Invokers.varHandleInvokeLinkerMethod(name, mtype);
+ return Invokers.varHandleInvokeLinkerMethod(ak, mtype);
}
- static String getVarHandleMethodSignature(MethodType mt) {
- StringBuilder sb = new StringBuilder(mt.parameterCount() + 2);
+ static String getVarHandleGuardMethodName(MethodType guardType) {
+ String prefix = "guard_";
+ StringBuilder sb = new StringBuilder(prefix.length() + guardType.parameterCount());
- for (int i = 0; i < mt.parameterCount(); i++) {
- Class> pt = mt.parameterType(i);
+ sb.append(prefix);
+ for (int i = 1; i < guardType.parameterCount() - 1; i++) {
+ Class> pt = guardType.parameterType(i);
sb.append(getCharType(pt));
}
- sb.append('_').append(getCharType(mt.returnType()));
+ sb.append('_').append(getCharType(guardType.returnType()));
return sb.toString();
}
static char getCharType(Class> pt) {
diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
index 16a9e8a941d..98f02d0f19f 100644
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
@@ -25,8 +25,6 @@
package java.lang.invoke;
-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 jdk.internal.vm.annotation.ForceInline;
@@ -111,13 +109,17 @@ public class MethodHandles {
/**
* Returns a {@link Lookup lookup object} which is trusted minimally.
- * It can only be used to create method handles to public members in
+ * The lookup has the {@code PUBLIC} and {@code UNCONDITIONAL} modes.
+ * It can only be used to create method handles to public members of
* public classes in packages that are exported unconditionally.
*
- * For now, the {@linkplain Lookup#lookupClass lookup class} of this lookup
- * object is in an unnamed module.
- * Consequently, the lookup context of this lookup object will be the bootstrap
- * class loader, which means it cannot find user classes.
+ * As a matter of pure convention, the {@linkplain Lookup#lookupClass lookup class}
+ * of this lookup object will be {@link java.lang.Object}.
+ *
+ * @apiNote The use of Object is conventional, and because the lookup modes are
+ * limited, there is no special access provided to the internals of Object, its package
+ * or its module. Consequently, the lookup context of this lookup object will be the
+ * bootstrap class loader, which means it cannot find user classes.
*
*
* Discussion:
@@ -129,17 +131,12 @@ public class MethodHandles {
* Also, it cannot access
* caller sensitive methods.
* @return a lookup object which is trusted minimally
+ *
+ * @revised 9
+ * @spec JPMS
*/
public static Lookup publicLookup() {
- // During VM startup then only classes in the java.base module can be
- // loaded and linked. This is because java.base exports aren't setup until
- // the module system is initialized, hence types in the unnamed module
- // (or any named module) can't link to java/lang/Object.
- if (!jdk.internal.misc.VM.isModuleSystemInited()) {
- return new Lookup(Object.class, Lookup.PUBLIC);
- } else {
- return LookupHelper.PUBLIC_LOOKUP;
- }
+ return Lookup.PUBLIC_LOOKUP;
}
/**
@@ -172,6 +169,7 @@ public class MethodHandles {
* @throws IllegalAccessException if the access check specified above fails
* @throws SecurityException if denied by the security manager
* @since 9
+ * @spec JPMS
* @see Lookup#dropLookupMode
*/
public static Lookup privateLookupIn(Class> targetClass, Lookup lookup) throws IllegalAccessException {
@@ -183,11 +181,11 @@ public class MethodHandles {
throw new IllegalArgumentException(targetClass + " is an array class");
Module targetModule = targetClass.getModule();
Module callerModule = lookup.lookupClass().getModule();
- if (callerModule != targetModule && targetModule.isNamed()) {
- if (!callerModule.canRead(targetModule))
- throw new IllegalAccessException(callerModule + " does not read " + targetModule);
+ if (!callerModule.canRead(targetModule))
+ throw new IllegalAccessException(callerModule + " does not read " + targetModule);
+ if (targetModule.isNamed()) {
String pn = targetClass.getPackageName();
- assert pn != null && pn.length() > 0 : "unnamed package cannot be in named module";
+ assert pn.length() > 0 : "unnamed package cannot be in named module";
if (!targetModule.isOpen(pn, callerModule))
throw new IllegalAccessException(targetModule + " does not open " + pn + " to " + callerModule);
}
@@ -601,6 +599,8 @@ public class MethodHandles {
* so that there can be a secure foundation for lookups.
* Nearly all other methods in the JSR 292 API rely on lookup
* objects to check access requests.
+ *
+ * @revised 9
*/
public static final
class Lookup {
@@ -647,15 +647,33 @@ public class MethodHandles {
* lookup class and public types in packages exported by other modules
* to the module of the lookup class.
* @since 9
+ * @spec JPMS
*/
public static final int MODULE = PACKAGE << 1;
- private static final int ALL_MODES = (PUBLIC | PRIVATE | PROTECTED | PACKAGE | MODULE);
+ /** A single-bit mask representing {@code unconditional} access
+ * which may contribute to the result of {@link #lookupModes lookupModes}.
+ * 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}.
+ * 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}.
+ * @since 9
+ * @spec JPMS
+ * @see #publicLookup()
+ */
+ public static final int UNCONDITIONAL = PACKAGE << 2;
+
+ private static final int ALL_MODES = (PUBLIC | PRIVATE | PROTECTED | PACKAGE | MODULE | UNCONDITIONAL);
+ private static final int FULL_POWER_MODES = (ALL_MODES & ~UNCONDITIONAL);
private static final int TRUSTED = -1;
private static int fixmods(int mods) {
- mods &= (ALL_MODES - PACKAGE - MODULE);
- return (mods != 0) ? mods : (PACKAGE | MODULE);
+ mods &= (ALL_MODES - PACKAGE - MODULE - UNCONDITIONAL);
+ return (mods != 0) ? mods : (PACKAGE | MODULE | UNCONDITIONAL);
}
/** Tells which class is performing the lookup. It is this class against
@@ -682,13 +700,14 @@ public class MethodHandles {
* {@linkplain #PRIVATE PRIVATE (0x02)},
* {@linkplain #PROTECTED PROTECTED (0x04)},
* {@linkplain #PACKAGE PACKAGE (0x08)},
- * and {@linkplain #MODULE MODULE (0x10)}.
+ * {@linkplain #MODULE MODULE (0x10)},
+ * and {@linkplain #UNCONDITIONAL UNCONDITIONAL (0x20)}.
*
* A freshly-created lookup object
- * on the {@linkplain java.lang.invoke.MethodHandles#lookup() caller's class}
- * has all possible bits set, since the caller class can access all its own members,
- * all public types in the caller's module, and all public types in packages exported
- * by other modules to the caller's module.
+ * on the {@linkplain java.lang.invoke.MethodHandles#lookup() caller's class} has
+ * all possible bits set, except {@code UNCONDITIONAL}. The lookup can be used to
+ * access all members of the caller's class, all public types in the caller's module,
+ * and all public types in packages exported by other modules to the caller's module.
* A lookup object on a new lookup class
* {@linkplain java.lang.invoke.MethodHandles.Lookup#in created from a previous lookup object}
* may have some mode bits set to zero.
@@ -701,6 +720,9 @@ public class MethodHandles {
* @return the lookup modes, which limit the kinds of access performed by this lookup object
* @see #in
* @see #dropLookupMode
+ *
+ * @revised 9
+ * @spec JPMS
*/
public int lookupModes() {
return allowedModes & ALL_MODES;
@@ -712,9 +734,9 @@ public class MethodHandles {
* which in turn is called by a method not in this package.
*/
Lookup(Class> lookupClass) {
- this(lookupClass, ALL_MODES);
+ this(lookupClass, FULL_POWER_MODES);
// make sure we haven't accidentally picked up a privileged class:
- checkUnprivilegedlookupClass(lookupClass, ALL_MODES);
+ checkUnprivilegedlookupClass(lookupClass, FULL_POWER_MODES);
}
private Lookup(Class> lookupClass, int allowedModes) {
@@ -730,19 +752,20 @@ public class MethodHandles {
* However, the resulting {@code Lookup} object is guaranteed
* to have no more access capabilities than the original.
* In particular, access capabilities can be lost as follows:
- *
If the lookup class for this {@code Lookup} is not in a named module,
- * and the new lookup class is in a named module {@code M}, then no members in
- * {@code M}'s non-exported packages will be accessible.
- *
If the lookup for this {@code Lookup} is in a named module, and the
- * new lookup class is in a different module {@code M}, then no members, not even
- * public members in {@code M}'s exported packages, will be accessible.
- *
If the new lookup class differs from the old one,
- * protected members will not be accessible by virtue of inheritance.
- * (Protected members may continue to be accessible because of package sharing.)
+ *
If the old lookup class is in a {@link Module#isNamed() named} module, and
+ * the new lookup class is in a different module {@code M}, then no members, not
+ * even public members in {@code M}'s exported packages, will be accessible.
+ * The exception to this is when this lookup is {@link #publicLookup()
+ * publicLookup}, in which case {@code PUBLIC} access is not lost.
+ *
If the old lookup class is in an unnamed module, and the new lookup class
+ * is a different module then {@link #MODULE MODULE} access is lost.
+ *
If the new lookup class differs from the old one then {@code UNCONDITIONAL} is lost.
*
If the new lookup class is in a different package
* than the old one, protected and default (package) members will not be accessible.
*
If the new lookup class is not within the same package member
- * as the old one, private members will not be accessible.
+ * as the old one, private members will not be accessible, and protected members
+ * will not be accessible by virtue of inheritance.
+ * (Protected members may continue to be accessible because of package sharing.)
*
If the new lookup class is not accessible to the old lookup class,
* then no members, not even public members, will be accessible.
* (In all other cases, public members will continue to be accessible.)
@@ -757,32 +780,34 @@ public class MethodHandles {
* @return a lookup object which reports the desired lookup class, or the same object
* if there is no change
* @throws NullPointerException if the argument is null
+ *
+ * @revised 9
+ * @spec JPMS
*/
public Lookup in(Class> requestedLookupClass) {
Objects.requireNonNull(requestedLookupClass);
if (allowedModes == TRUSTED) // IMPL_LOOKUP can make any lookup at all
- return new Lookup(requestedLookupClass, ALL_MODES);
+ return new Lookup(requestedLookupClass, FULL_POWER_MODES);
if (requestedLookupClass == this.lookupClass)
return this; // keep same capabilities
-
- int newModes = (allowedModes & (ALL_MODES & ~PROTECTED));
+ int newModes = (allowedModes & FULL_POWER_MODES);
if (!VerifyAccess.isSameModule(this.lookupClass, requestedLookupClass)) {
- // Allowed to teleport from an unnamed to a named module but resulting
- // Lookup has no access to module private members
- if (this.lookupClass.getModule().isNamed()) {
+ // Need to drop all access when teleporting from a named module to another
+ // module. The exception is publicLookup where PUBLIC is not lost.
+ if (this.lookupClass.getModule().isNamed()
+ && (this.allowedModes & UNCONDITIONAL) == 0)
newModes = 0;
- } else {
- newModes &= ~MODULE;
- }
+ else
+ newModes &= ~(MODULE|PACKAGE|PRIVATE|PROTECTED);
}
if ((newModes & PACKAGE) != 0
&& !VerifyAccess.isSamePackage(this.lookupClass, requestedLookupClass)) {
- newModes &= ~(PACKAGE|PRIVATE);
+ newModes &= ~(PACKAGE|PRIVATE|PROTECTED);
}
// Allow nestmate lookups to be created without special privilege:
if ((newModes & PRIVATE) != 0
&& !VerifyAccess.isSamePackageMember(this.lookupClass, requestedLookupClass)) {
- newModes &= ~PRIVATE;
+ newModes &= ~(PRIVATE|PROTECTED);
}
if ((newModes & PUBLIC) != 0
&& !VerifyAccess.isClassAccessible(requestedLookupClass, this.lookupClass, allowedModes)) {
@@ -801,28 +826,29 @@ public class MethodHandles {
* finds members, but with a lookup mode that has lost the given lookup mode.
* The lookup mode to drop is one of {@link #PUBLIC PUBLIC}, {@link #MODULE
* MODULE}, {@link #PACKAGE PACKAGE}, {@link #PROTECTED PROTECTED} or {@link #PRIVATE PRIVATE}.
- * {@link #PROTECTED PROTECTED} is always dropped and so the resulting lookup
- * mode will never have this access capability. When dropping {@code PACKAGE}
- * then the resulting lookup will not have {@code PACKAGE} or {@code PRIVATE}
- * access. When dropping {@code MODULE} then the resulting lookup will not
- * have {@code MODULE}, {@code PACKAGE}, or {@code PRIVATE} access. If {@code
- * PUBLIC} is dropped then the resulting lookup has no access.
+ * {@link #PROTECTED PROTECTED} and {@link #UNCONDITIONAL UNCONDITIONAL} are always
+ * dropped and so the resulting lookup mode will never have these access capabilities.
+ * When dropping {@code PACKAGE} then the resulting lookup will not have {@code PACKAGE}
+ * or {@code PRIVATE} access. When dropping {@code MODULE} then the resulting lookup will
+ * not have {@code MODULE}, {@code PACKAGE}, or {@code PRIVATE} access. If {@code PUBLIC}
+ * is dropped then the resulting lookup has no access.
* @param modeToDrop the lookup mode to drop
* @return a lookup object which lacks the indicated mode, or the same object if there is no change
* @throws IllegalArgumentException if {@code modeToDrop} is not one of {@code PUBLIC},
- * {@code MODULE}, {@code PACKAGE}, {@code PROTECTED} or {@code PRIVATE}
- * @since 9
+ * {@code MODULE}, {@code PACKAGE}, {@code PROTECTED}, {@code PRIVATE} or {@code UNCONDITIONAL}
* @see MethodHandles#privateLookupIn
+ * @since 9
*/
public Lookup dropLookupMode(int modeToDrop) {
int oldModes = lookupModes();
- int newModes = oldModes & ~(modeToDrop | PROTECTED);
+ int newModes = oldModes & ~(modeToDrop | PROTECTED | UNCONDITIONAL);
switch (modeToDrop) {
case PUBLIC: newModes &= ~(ALL_MODES); break;
case MODULE: newModes &= ~(PACKAGE | PRIVATE); break;
case PACKAGE: newModes &= ~(PRIVATE); break;
case PROTECTED:
- case PRIVATE: break;
+ case PRIVATE:
+ case UNCONDITIONAL: break;
default: throw new IllegalArgumentException(modeToDrop + " is not a valid mode to drop");
}
if (newModes == oldModes) return this; // return self if no change
@@ -835,6 +861,12 @@ public class MethodHandles {
/** Package-private version of lookup which is trusted. */
static final Lookup IMPL_LOOKUP = new Lookup(Object.class, TRUSTED);
+ /** Version of lookup which is trusted minimally.
+ * It can only be used to create method handles to publicly accessible
+ * members in packages that are exported unconditionally.
+ */
+ static final Lookup PUBLIC_LOOKUP = new Lookup(Object.class, (PUBLIC|UNCONDITIONAL));
+
private static void checkUnprivilegedlookupClass(Class> lookupClass, int allowedModes) {
String name = lookupClass.getName();
if (name.startsWith("java.lang.invoke."))
@@ -845,7 +877,7 @@ public class MethodHandles {
// TODO replace with a more formal and less fragile mechanism
// that does not bluntly restrict classes under packages within
// java.base from looking up MethodHandles or VarHandles.
- if (allowedModes == ALL_MODES && lookupClass.getClassLoader() == null) {
+ if (allowedModes == FULL_POWER_MODES && lookupClass.getClassLoader() == null) {
if ((name.startsWith("java.") &&
!name.equals("java.lang.Thread") &&
!name.startsWith("java.util.concurrent.")) ||
@@ -866,6 +898,7 @@ public class MethodHandles {
*
*
If no access is allowed, the suffix is "/noaccess".
*
If only public access to types in exported packages is allowed, the suffix is "/public".
+ *
If only public access and unconditional access are allowed, the suffix is "/publicLookup".
*
If only public and module access are allowed, the suffix is "/module".
*
If only public, module and package access are allowed, the suffix is "/package".
*
If only public, module, package, and private access are allowed, the suffix is "/private".
@@ -884,6 +917,9 @@ public class MethodHandles {
* because it requires a direct subclass relationship between
* caller and callee.)
* @see #in
+ *
+ * @revised 9
+ * @spec JPMS
*/
@Override
public String toString() {
@@ -893,13 +929,15 @@ public class MethodHandles {
return cname + "/noaccess";
case PUBLIC:
return cname + "/public";
+ case PUBLIC|UNCONDITIONAL:
+ return cname + "/publicLookup";
case PUBLIC|MODULE:
return cname + "/module";
case PUBLIC|MODULE|PACKAGE:
return cname + "/package";
- case ALL_MODES & ~PROTECTED:
+ case FULL_POWER_MODES & ~PROTECTED:
return cname + "/private";
- case ALL_MODES:
+ case FULL_POWER_MODES:
return cname;
case TRUSTED:
return "/trusted"; // internal only; not exported
@@ -1580,6 +1618,7 @@ return mh1;
if (refKind == REF_invokeSpecial)
refKind = REF_invokeVirtual;
assert(method.isMethod());
+ @SuppressWarnings("deprecation")
Lookup lookup = m.isAccessible() ? IMPL_LOOKUP : this;
return lookup.getDirectMethodNoSecurityManager(refKind, method.getDeclaringClass(), method, findBoundCallerClass(method));
}
@@ -1662,6 +1701,7 @@ return mh1;
public MethodHandle unreflectConstructor(Constructor> c) throws IllegalAccessException {
MemberName ctor = new MemberName(c);
assert(ctor.isConstructor());
+ @SuppressWarnings("deprecation")
Lookup lookup = c.isAccessible() ? IMPL_LOOKUP : this;
return lookup.getDirectConstructorNoSecurityManager(ctor.getDeclaringClass(), ctor);
}
@@ -1692,6 +1732,7 @@ return mh1;
assert(isSetter
? MethodHandleNatives.refKindIsSetter(field.getReferenceKind())
: MethodHandleNatives.refKindIsGetter(field.getReferenceKind()));
+ @SuppressWarnings("deprecation")
Lookup lookup = f.isAccessible() ? IMPL_LOOKUP : this;
return lookup.getDirectFieldNoSecurityManager(field.getReferenceKind(), f.getDeclaringClass(), field);
}
@@ -2033,9 +2074,9 @@ return mh1;
(defc == refc ||
Modifier.isPublic(refc.getModifiers())));
if (!classOK && (allowedModes & PACKAGE) != 0) {
- classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
+ classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), FULL_POWER_MODES) &&
(defc == refc ||
- VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
+ VerifyAccess.isClassAccessible(refc, lookupClass(), FULL_POWER_MODES)));
}
if (!classOK)
return "class is not public";
@@ -2347,53 +2388,6 @@ return mh1;
static ConcurrentHashMap LOOKASIDE_TABLE = new ConcurrentHashMap<>();
}
- /**
- * Helper class used to lazily create PUBLIC_LOOKUP with a lookup class
- * in an unnamed module.
- *
- * @see Lookup#publicLookup
- */
- private static class LookupHelper {
- private static final String UNNAMED = "Unnamed";
- private static final String OBJECT = "java/lang/Object";
-
- private static Class> createClass() {
- try {
- ClassWriter cw = new ClassWriter(0);
- cw.visit(Opcodes.V1_8,
- Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
- UNNAMED,
- null,
- OBJECT,
- null);
- cw.visitSource(UNNAMED, null);
- cw.visitEnd();
- byte[] bytes = cw.toByteArray();
- ClassLoader loader = new ClassLoader(null) {
- @Override
- protected Class> findClass(String cn) throws ClassNotFoundException {
- if (cn.equals(UNNAMED))
- return super.defineClass(UNNAMED, bytes, 0, bytes.length);
- throw new ClassNotFoundException(cn);
- }
- };
- return loader.loadClass(UNNAMED);
- } catch (Exception e) {
- throw new InternalError(e);
- }
- }
-
- private static final Class> PUBLIC_LOOKUP_CLASS = createClass();
-
- /**
- * Lookup that is trusted minimally. It can only be used to create
- * method handles to publicly accessible members in exported packages.
- *
- * @see MethodHandles#publicLookup
- */
- static final Lookup PUBLIC_LOOKUP = new Lookup(PUBLIC_LOOKUP_CLASS, Lookup.PUBLIC);
- }
-
/**
* Produces a method handle constructing arrays of a desired type.
* The return type of the method handle will be the array type.
diff --git a/jdk/src/java.base/share/classes/java/lang/module/Configuration.java b/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
index 9753569374d..6203b1277ff 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/Configuration.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -42,126 +42,48 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
- * The configuration that is the result of resolution or resolution with
- * service binding.
+ * A configuration that is the result of
+ * resolution or resolution with
+ * service binding.
*
- *
A configuration encapsulates the readability graph that is the
+ * output of resolution. A readability graph is a directed graph where the nodes
+ * are of type {@link ResolvedModule} and the edges represent the readability
+ * amongst the modules. {@code Configuration} defines the {@link #modules()
+ * modules()} method to get the set of resolved modules in the graph. {@code
+ * ResolvedModule} defines the {@link ResolvedModule#reads() reads()} method to
+ * get the set of modules that a resolved module reads. The modules that are
+ * read may be in the same configuration or may be in {@link #parents() parent}
+ * configurations.
*
- *
Resolution is the process of computing the transitive closure of a set
- * of root modules over a set of observable modules by resolving the
- * dependences expressed by {@code requires} clauses.
+ *
Configuration defines the {@link #resolve(ModuleFinder,List,ModuleFinder,Collection)
+ * resolve} method to resolve a collection of root modules, and the {@link
+ * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection) resolveAndBind}
+ * method to do resolution with service binding. There are instance and
+ * static variants of both methods. The instance methods create a configuration
+ * with the receiver as the parent configuration. The static methods are for
+ * more advanced cases where there can be more than one parent configuration.
*
- * The dependence graph is augmented with edges that take account of
- * implicitly declared dependences ({@code requires transitive}) to create a
- * readability graph. A {@code Configuration} encapsulates the
- * resulting graph of {@link ResolvedModule resolved modules}.
- *
- *
If the module {@code m1} is resolved then the resulting configuration
- * contains three modules ({@code m1}, {@code m2}, {@code m3}). The edges in
- * its readability graph are:
Resolution is an additive process. When computing the transitive closure
- * then the dependence relation may include dependences on modules in parent
- * configurations. The result is a relative configuration that is
- * relative to one or more parent configurations and where the readability graph
- * may have edges from modules in the configuration to modules in parent
- * configurations.
- *
- *
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
- * configuration contains two modules ({@code m1}, {@code m2}). The edges in
- * its readability graph are:
- *
{@code
- * m1 --> m2
- * m1 --> java.xml
- * }
- * where module {@code java.xml} is in the parent configuration. For
- * simplicity, this example omits the implicitly declared dependence on the
- * {@code java.base} module.
- *
- *
- *
{@link 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).
Service binding is the process of augmenting a graph of resolved modules
- * from the set of observable modules induced by the service-use dependence
- * ({@code uses} and {@code provides} clauses). Any module that was not
- * previously in the graph requires resolution to compute its transitive
- * closure. Service binding is an iterative process in that adding a module
- * that satisfies some service-use dependence may introduce new service-use
- * dependences.
If the module {@code m1} is resolved then the resulting graph of modules
- * has one module ({@code m1}). If the graph is augmented with modules induced
- * by the service-use dependence relation then the configuration will contain
- * four modules ({@code m1}, {@code m2}, {@code m3}, {@code m4}). The edges in
- * its readability graph are:
The edges in the conceptual service-use graph are:
- *
{@code
- * m1 --> m2 (meaning m1 uses a service that is provided by m2)
- * m1 --> m3
- * }
- *
- *
If this configuration is instantiated as a {@code Layer}, and if code in
- * module {@code m1} uses {@link java.util.ServiceLoader ServiceLoader} to
- * iterate over implementations of {@code p.S.class}, then it will iterate over
- * an instance of {@code p2.S2} and {@code p3.S3}.
+ *
Each {@link java.lang.reflect.Layer 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.
*
*
Example
*
- *
The following example uses the {@code resolveRequires} method to resolve
- * a module named myapp with the configuration for the boot layer as
- * the parent configuration. It prints the name of each resolved module and
- * the names of the modules that each module reads.
+ *
The following example uses the {@link
+ * #resolve(ModuleFinder,ModuleFinder,Collection) resolve} method to resolve a
+ * module named myapp with the configuration for the boot layer as the
+ * parent configuration. It prints the name of each resolved module and the
+ * names of the modules that each module reads.
*
* @since 9
+ * @spec JPMS
* @see java.lang.reflect.Layer
*/
public final class Configuration {
@@ -186,11 +109,23 @@ public final class Configuration {
private final Set modules;
private final Map nameToModule;
+ // module constraints on target
+ private final String osName;
+ private final String osArch;
+ private final String osVersion;
+
+ String osName() { return osName; }
+ String osArch() { return osArch; }
+ String osVersion() { return osVersion; }
+
private Configuration() {
this.parents = Collections.emptyList();
this.graph = Collections.emptyMap();
this.modules = Collections.emptySet();
this.nameToModule = Collections.emptyMap();
+ this.osName = null;
+ this.osArch = null;
+ this.osVersion = null;
}
private Configuration(List parents,
@@ -214,27 +149,30 @@ public final class Configuration {
this.graph = g;
this.modules = Set.of(moduleArray);
this.nameToModule = Map.ofEntries(nameEntries);
- }
+ this.osName = resolver.osName();
+ this.osArch = resolver.osArch();
+ this.osVersion = resolver.osVersion();
+ }
/**
* Resolves a collection of root modules, with this configuration as its
* parent, to create a new configuration. This method works exactly as
* specified by the static {@link
- * #resolveRequires(ModuleFinder,List,ModuleFinder,Collection) resolveRequires}
+ * #resolve(ModuleFinder,List,ModuleFinder,Collection) resolve}
* method when invoked with this configuration as the parent. In other words,
* if this configuration is {@code cf} then this method is equivalent to
* invoking:
*
*
* @param before
* The before module finder to find modules
* @param after
- * The after module finder to locate modules when a
- * module cannot be located by the {@code before} module finder
- * and the module is not in this configuration
+ * The after module finder to locate modules when not
+ * located by the {@code before} module finder or in parent
+ * configurations
* @param roots
* The possibly-empty collection of module names of the modules
* to resolve
@@ -242,16 +180,20 @@ public final class Configuration {
* @return The configuration that is the result of resolving the given
* root modules
*
+ * @throws FindException
+ * If resolution fails for any of the observability-related reasons
+ * specified by the static {@code resolve} method
* @throws ResolutionException
- * If resolution or the post-resolution checks fail
+ * If any of the post-resolution consistency checks specified by
+ * the static {@code resolve} method fail
* @throws SecurityException
* If locating a module is denied by the security manager
*/
- public Configuration resolveRequires(ModuleFinder before,
- ModuleFinder after,
- Collection roots)
+ public Configuration resolve(ModuleFinder before,
+ ModuleFinder after,
+ Collection roots)
{
- return resolveRequires(before, List.of(this), after, roots);
+ return resolve(before, List.of(this), after, roots);
}
@@ -259,12 +201,12 @@ public final class Configuration {
* Resolves a collection of root modules, with service binding, and with
* this configuration as its parent, to create a new configuration.
* This method works exactly as specified by the static {@link
- * #resolveRequiresAndUses(ModuleFinder,List,ModuleFinder,Collection)
- * resolveRequiresAndUses} method when invoked with this configuration
+ * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection)
+ * resolveAndBind} method when invoked with this configuration
* as the parent. In other words, if this configuration is {@code cf} then
* this method is equivalent to invoking:
*
*
*
@@ -272,25 +214,29 @@ public final class Configuration {
* The before module finder to find modules
* @param after
* The after module finder to locate modules when not
- * located by the {@code before} module finder and this
- * configuration
+ * located by the {@code before} module finder or in parent
+ * configurations
* @param roots
* The possibly-empty collection of module names of the modules
* to resolve
*
- * @return The configuration that is the result of resolving the given
- * root modules
+ * @return The configuration that is the result of resolving, with service
+ * binding, the given root modules
*
+ * @throws FindException
+ * If resolution fails for any of the observability-related reasons
+ * specified by the static {@code resolve} method
* @throws ResolutionException
- * If resolution or the post-resolution checks fail
+ * If any of the post-resolution consistency checks specified by
+ * the static {@code resolve} method fail
* @throws SecurityException
* If locating a module is denied by the security manager
*/
- public Configuration resolveRequiresAndUses(ModuleFinder before,
- ModuleFinder after,
- Collection roots)
+ public Configuration resolveAndBind(ModuleFinder before,
+ ModuleFinder after,
+ Collection roots)
{
- return resolveRequiresAndUses(before, List.of(this), after, roots);
+ return resolveAndBind(before, List.of(this), after, roots);
}
@@ -301,14 +247,14 @@ public final class Configuration {
*
* This method is used to create the configuration for the boot layer.
*/
- static Configuration resolveRequiresAndUses(ModuleFinder finder,
- Collection roots,
- boolean check,
- PrintStream traceOutput)
+ static Configuration resolveAndBind(ModuleFinder finder,
+ Collection roots,
+ boolean check,
+ PrintStream traceOutput)
{
List parents = List.of(empty());
Resolver resolver = new Resolver(finder, parents, ModuleFinder.of(), traceOutput);
- resolver.resolveRequires(roots).resolveUses();
+ resolver.resolve(roots).bind();
return new Configuration(parents, resolver, check);
}
@@ -328,11 +274,11 @@ public final class Configuration {
*
*
When all modules have been resolved then the resulting dependency
* graph is checked to ensure that it does not contain cycles. A
- * readability graph is constructed and in conjunction with the module
+ * readability graph is constructed, and in conjunction with the module
* exports and service use, checked for consistency.
*
- *
Resolution and the (post-resolution) consistency checks may fail for
- * following reasons:
+ *
Resolution may fail with {@code FindException} for the following
+ * observability-related reasons:
*
*
*
A root module, or a direct or transitive dependency, is not
@@ -343,6 +289,20 @@ public final class Configuration {
* descriptor ({@code module-info.class}) or two versions of the same
* module are found in the same directory.
*
+ *
A module with the required name is found but the module
+ * requires a different {@link ModuleDescriptor#osName() operating
+ * system}, {@link ModuleDescriptor#osArch() architecture}, or {@link
+ * ModuleDescriptor#osVersion() version} to other modules that have
+ * been resolved for the new configuration or modules in the parent
+ * configurations.
+ *
+ *
+ *
+ *
Post-resolution consistency checks may fail with {@code
+ * ResolutionException} for the following reasons:
+ *
+ *
+ *
*
A cycle is detected, say where module {@code m1} requires
* module {@code m2} and {@code m2} requires {@code m1}.
*
@@ -356,21 +316,12 @@ public final class Configuration {
* module {@code M} nor exported to {@code M} by any module that
* {@code M} reads.
*
- *
A module {@code M} declares that it
- * "{@code provides ... with q.T}" but package {@code q} is not in
- * module {@code M}.
- *
- *
Two or more modules in the configuration are specific to
- * different {@link ModuleDescriptor#osName() operating systems},
- * {@link ModuleDescriptor#osArch() architectures}, or {@link
- * ModuleDescriptor#osVersion() versions}.
- *
- *
Other implementation specific checks, for example referential
- * integrity checks to ensure that different versions of tighly coupled
- * modules cannot be combined in the same configuration.
- *
*
*
+ * @implNote In the implementation then observability of modules may depend
+ * on referential integrity checks that ensure different builds of tightly
+ * coupled modules are not combined in the same configuration.
+ *
* @param before
* The before module finder to find modules
* @param parents
@@ -386,17 +337,22 @@ public final class Configuration {
* @return The configuration that is the result of resolving the given
* root modules
*
+ * @throws FindException
+ * If resolution fails for an observability-related reason
* @throws ResolutionException
- * If resolution or the post-resolution checks fail
+ * If a post-resolution consistency checks fails
* @throws IllegalArgumentException
- * If the list of parents is empty
+ * If the list of parents is empty, or the list has two or more
+ * parents with modules for different target operating systems,
+ * architectures, or versions
+ *
* @throws SecurityException
* If locating a module is denied by the security manager
*/
- public static Configuration resolveRequires(ModuleFinder before,
- List parents,
- ModuleFinder after,
- Collection roots)
+ public static Configuration resolve(ModuleFinder before,
+ List parents,
+ ModuleFinder after,
+ Collection roots)
{
Objects.requireNonNull(before);
Objects.requireNonNull(after);
@@ -407,7 +363,7 @@ public final class Configuration {
throw new IllegalArgumentException("'parents' is empty");
Resolver resolver = new Resolver(before, parentList, after, null);
- resolver.resolveRequires(roots);
+ resolver.resolve(roots);
return new Configuration(parentList, resolver, true);
}
@@ -417,24 +373,24 @@ public final class Configuration {
* configuration.
*
*
This method works exactly as specified by {@link
- * #resolveRequires(ModuleFinder,List,ModuleFinder,Collection)
- * resolveRequires} except that the graph of resolved modules is augmented
+ * #resolve(ModuleFinder,List,ModuleFinder,Collection)
+ * resolve} except that the graph of resolved modules is augmented
* with modules induced by the service-use dependence relation.
*
*
More specifically, the root modules are resolved as if by calling
- * {@code resolveRequires}. The resolved modules, and all modules in the
+ * {@code resolve}. The resolved modules, and all modules in the
* parent configurations, with {@link ModuleDescriptor#uses() service
* dependences} are then examined. All modules found by the given module
* finders that {@link ModuleDescriptor#provides() provide} an
* implementation of one or more of the service types are added to the
* module graph and then resolved as if by calling the {@code
- * resolveRequires} method. Adding modules to the module graph may
- * introduce new service-use dependences and so the process works
- * iteratively until no more modules are added.
+ * resolve} method. Adding modules to the module graph may introduce new
+ * service-use dependences and so the process works iteratively until no
+ * more modules are added.
*
- *
As service binding involves resolution then it may fail with {@link
- * ResolutionException} for exactly the same reasons specified in
- * {@code resolveRequires}.
+ *
As service binding involves resolution then it may fail with {@code
+ * FindException} or {@code ResolutionException} for exactly the same
+ * reasons specified in {@code resolve}.
*
* @param before
* The before module finder to find modules
@@ -448,20 +404,26 @@ public final class Configuration {
* The possibly-empty collection of module names of the modules
* to resolve
*
- * @return The configuration that is the result of resolving the given
- * root modules
+ * @return The configuration that is the result of resolving, with service
+ * binding, the given root modules
*
+ * @throws FindException
+ * If resolution fails for any of the observability-related reasons
+ * specified by the static {@code resolve} method
* @throws ResolutionException
- * If resolution or the post-resolution checks fail
+ * If any of the post-resolution consistency checks specified by
+ * the static {@code resolve} method fail
* @throws IllegalArgumentException
- * If the list of parents is empty
+ * If the list of parents is empty, or the list has two or more
+ * parents with modules for different target operating systems,
+ * architectures, or versions
* @throws SecurityException
* If locating a module is denied by the security manager
*/
- public static Configuration resolveRequiresAndUses(ModuleFinder before,
- List parents,
- ModuleFinder after,
- Collection roots)
+ public static Configuration resolveAndBind(ModuleFinder before,
+ List parents,
+ ModuleFinder after,
+ Collection roots)
{
Objects.requireNonNull(before);
Objects.requireNonNull(after);
@@ -472,7 +434,7 @@ public final class Configuration {
throw new IllegalArgumentException("'parents' is empty");
Resolver resolver = new Resolver(before, parentList, after, null);
- resolver.resolveRequires(roots).resolveUses();
+ resolver.resolve(roots).bind();
return new Configuration(parentList, resolver, true);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/module/FindException.java b/jdk/src/java.base/share/classes/java/lang/module/FindException.java
index d76f2935e7e..411959eb418 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/FindException.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/FindException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -26,10 +26,14 @@
package java.lang.module;
/**
- * Thrown by module finders when finding a module fails.
+ * Thrown by a {@link ModuleFinder ModuleFinder} when an error occurs finding
+ * a module. Also thrown by {@link
+ * Configuration#resolve(ModuleFinder,java.util.List,ModuleFinder,java.util.Collection)
+ * Configuration.resolve} when resolution fails for observability-related
+ * reasons.
*
- * @see ModuleFinder
* @since 9
+ * @spec JPMS
*/
public class FindException extends RuntimeException {
diff --git a/jdk/src/java.base/share/classes/java/lang/module/InvalidModuleDescriptorException.java b/jdk/src/java.base/share/classes/java/lang/module/InvalidModuleDescriptorException.java
index 981f23a5189..3e306886fb2 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/InvalidModuleDescriptorException.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/InvalidModuleDescriptorException.java
@@ -31,6 +31,7 @@ package java.lang.module;
*
* @see ModuleDescriptor#read
* @since 9
+ * @spec JPMS
*/
public class InvalidModuleDescriptorException extends RuntimeException {
private static final long serialVersionUID = 4863390386809347380L;
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
index b10d986ade9..6c05e821026 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -32,6 +32,7 @@ import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
@@ -56,29 +57,83 @@ import jdk.internal.module.ModuleInfo;
/**
* A module descriptor.
*
- *
A {@code ModuleDescriptor} is typically created from the binary form
- * of a module declaration. Alternatively, the {@link ModuleDescriptor.Builder}
- * class can be used to create a {@code ModuleDescriptor} from its components.
- * The {@link #module module}, {@link #openModule openModule}, and {@link
- * #automaticModule automaticModule} methods create builders for building
- * different kinds of modules.
+ *
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
+ * 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
+ * #read(InputStream,Supplier) read} methods defined here.
+ *
+ *
A module descriptor describes a normal, open, or automatic
+ * module. Normal modules and open modules describe their {@link
+ * #requires() dependences}, {@link #exports() exported-packages}, the services
+ * that they {@link #uses() use} or {@link #provides() provide}, and other
+ * components. Normal modules may {@link #opens() open} specific
+ * packages. The module descriptor for an open modules does not declare any
+ * open packages (its {@code opens} method returns an empty set) but when
+ * instantiated in the Java virtual machine then it is treated as if all
+ * packages are open. The module descriptor for an automatic module does not
+ * declare any dependences (except for the mandatory dependency on {@code
+ * java.base}), and does not declare any exported or open packages. Automatic
+ * module receive special treatment during resolution so that they read all
+ * other modules in the configuration. When an automatic module is instantiated
+ * in the Java virtual machine then it reads every unnamed module and is
+ * treated as if all packages are exported and open.
*
*
{@code ModuleDescriptor} objects are immutable and safe for use by
* multiple concurrent threads.
*
- * @since 9
* @see java.lang.reflect.Module
+ * @since 9
+ * @spec JPMS
*/
public class ModuleDescriptor
implements Comparable
{
+ /**
+ * A modifier on a module.
+ *
+ * @see ModuleDescriptor#modifiers()
+ * @since 9
+ */
+ public static enum Modifier {
+ /**
+ * An open module. An open module does not declare any open packages
+ * but the resulting module is treated as if all packages are open.
+ */
+ OPEN,
+
+ /**
+ * An automatic module. An automatic module is treated as if it exports
+ * and opens all packages.
+ *
+ * @apiNote This modifier does not correspond to a module flag in the
+ * binary form of a module declaration ({@code module-info.class}).
+ */
+ AUTOMATIC,
+
+ /**
+ * The module was not explicitly or implicitly declared.
+ */
+ SYNTHETIC,
+
+ /**
+ * The module was implicitly declared.
+ */
+ MANDATED;
+ }
+
+
/**
*
A dependence upon a module
*
* @see ModuleDescriptor#requires()
* @since 9
+ * @spec JPMS
*/
public final static class Requires
@@ -88,7 +143,9 @@ public class ModuleDescriptor
/**
* A modifier on a module dependence.
*
+ * @see Requires#modifiers()
* @since 9
+ * @spec JPMS
*/
public static enum Modifier {
@@ -171,14 +228,18 @@ public class ModuleDescriptor
* Compares this module dependence to another.
*
*
Two {@code Requires} objects are compared by comparing their
- * module name lexicographically. Where the module names are equal then
- * the sets of modifiers are compared based on a value computed from the
- * ordinal of each modifier. Where the module names are equal and the
- * set of modifiers are equal then the version of the modules recorded
- * at compile-time are compared. When comparing the versions recorded
- * at compile-time then a dependence that has a recorded version is
- * considered to succeed a dependence that does not have a recorded
- * version.
+ * module names lexicographically. Where the module names are equal
+ * then the sets of modifiers are compared in the same way that
+ * module modifiers are compared (see {@link ModuleDescriptor#compareTo
+ * ModuleDescriptor.compareTo}). Where the module names are equal and
+ * the set of modifiers are equal then the version of the modules
+ * recorded at compile-time are compared. When comparing the versions
+ * recorded at compile-time then a dependence that has a recorded
+ * version is considered to succeed a dependence that does not have a
+ * recorded version.
+ *
+ * @param that
+ * The module dependence to compare
*
* @return A negative integer, zero, or a positive integer if this module
* dependence is less than, equal to, or greater than the given
@@ -186,39 +247,22 @@ public class ModuleDescriptor
*/
@Override
public int compareTo(Requires that) {
+ if (this == that) return 0;
+
int c = this.name().compareTo(that.name());
- if (c != 0)
- return c;
+ if (c != 0) return c;
// modifiers
- c = Long.compare(this.modsValue(), that.modsValue());
- if (c != 0)
- return c;
+ long v1 = modsValue(this.modifiers());
+ long v2 = modsValue(that.modifiers());
+ c = Long.compare(v1, v2);
+ if (c != 0) return c;
// compiledVersion
- if (this.compiledVersion != null) {
- if (that.compiledVersion != null)
- c = this.compiledVersion.compareTo(that.compiledVersion);
- else
- c = 1;
- } else {
- if (that.compiledVersion != null)
- c = -1;
- }
+ c = compare(this.compiledVersion, that.compiledVersion);
+ if (c != 0) return c;
- return c;
- }
-
- /**
- * Return a value for the modifiers to allow sets of modifiers to be
- * compared.
- */
- private long modsValue() {
- long value = 0;
- for (Modifier m : mods) {
- value += 1 << m.ordinal();
- }
- return value;
+ return 0;
}
/**
@@ -266,9 +310,9 @@ public class ModuleDescriptor
}
/**
- * Returns a string describing module dependence.
+ * Returns a string describing this module dependence.
*
- * @return A string describing module dependence
+ * @return A string describing this module dependence
*/
@Override
public String toString() {
@@ -285,18 +329,23 @@ public class ModuleDescriptor
/**
- *
A module export, may be qualified or unqualified.
+ *
A package exported by a module, may be qualified or unqualified.
*
* @see ModuleDescriptor#exports()
* @since 9
+ * @spec JPMS
*/
- public final static class Exports {
+ public final static class Exports
+ implements Comparable
+ {
/**
- * A modifier on a module export.
+ * A modifier on an exported package.
*
+ * @see Exports#modifiers()
* @since 9
+ * @spec JPMS
*/
public static enum Modifier {
@@ -380,6 +429,52 @@ public class ModuleDescriptor
return targets;
}
+ /**
+ * Compares this module export to another.
+ *
+ *
Two {@code Exports} objects are compared by comparing the package
+ * names lexicographically. Where the packages names are equal then the
+ * sets of modifiers are compared in the same way that module modifiers
+ * are compared (see {@link ModuleDescriptor#compareTo
+ * ModuleDescriptor.compareTo}). Where the package names are equal and
+ * the set of modifiers are equal then the set of target modules are
+ * compared. This is done by sorting the names of the target modules
+ * in ascending order, and according to their natural ordering, and then
+ * comparing the corresponding elements lexicographically. Where the
+ * sets differ in size, and the larger set contains all elements of the
+ * smaller set, then the larger set is considered to succeed the smaller
+ * set.
+ *
+ * @param that
+ * The module export to compare
+ *
+ * @return A negative integer, zero, or a positive integer if this module
+ * export is less than, equal to, or greater than the given
+ * export dependence
+ */
+ @Override
+ public int compareTo(Exports that) {
+ if (this == that) return 0;
+
+ int c = source.compareTo(that.source);
+ if (c != 0)
+ return c;
+
+ // modifiers
+ long v1 = modsValue(this.modifiers());
+ long v2 = modsValue(that.modifiers());
+ c = Long.compare(v1, v2);
+ if (c != 0)
+ return c;
+
+ // targets
+ c = compare(targets, that.targets);
+ if (c != 0)
+ return c;
+
+ return 0;
+ }
+
/**
* Computes a hash code for this module export.
*
@@ -425,9 +520,9 @@ public class ModuleDescriptor
}
/**
- * Returns a string describing module export.
+ * Returns a string describing the exported package.
*
- * @return A string describing module export
+ * @return A string describing the exported package
*/
@Override
public String toString() {
@@ -441,8 +536,7 @@ public class ModuleDescriptor
/**
- *
Represents a module opens directive, may be qualified or
- * unqualified.
+ *
A package opened by a module, may be qualified or unqualified.
*
*
The opens directive in a module declaration declares a
* package to be open to allow all types in the package, and all their
@@ -452,26 +546,30 @@ public class ModuleDescriptor
*
* @see ModuleDescriptor#opens()
* @since 9
+ * @spec JPMS
*/
- public final static class Opens {
-
+ public final static class Opens
+ implements Comparable
+ {
/**
- * A modifier on a module opens directive.
+ * A modifier on an open package.
*
+ * @see Opens#modifiers()
* @since 9
+ * @spec JPMS
*/
public static enum Modifier {
/**
- * The opens was not explicitly or implicitly declared in the
- * source of the module declaration.
+ * The open package was not explicitly or implicitly declared in
+ * the source of the module declaration.
*/
SYNTHETIC,
/**
- * The opens was implicitly declared in the source of the module
- * declaration.
+ * The open package was implicitly declared in the source of the
+ * module declaration.
*/
MANDATED;
@@ -543,6 +641,52 @@ public class ModuleDescriptor
return targets;
}
+ /**
+ * Compares this module opens to another.
+ *
+ *
Two {@code Opens} objects are compared by comparing the package
+ * names lexicographically. Where the packages names are equal then the
+ * sets of modifiers are compared in the same way that module modifiers
+ * are compared (see {@link ModuleDescriptor#compareTo
+ * ModuleDescriptor.compareTo}). Where the package names are equal and
+ * the set of modifiers are equal then the set of target modules are
+ * compared. This is done by sorting the names of the target modules
+ * in ascending order, and according to their natural ordering, and then
+ * comparing the corresponding elements lexicographically. Where the
+ * sets differ in size, and the larger set contains all elements of the
+ * smaller set, then the larger set is considered to succeed the smaller
+ * set.
+ *
+ * @param that
+ * The module opens to compare
+ *
+ * @return A negative integer, zero, or a positive integer if this module
+ * opens is less than, equal to, or greater than the given
+ * module opens
+ */
+ @Override
+ public int compareTo(Opens that) {
+ if (this == that) return 0;
+
+ int c = source.compareTo(that.source);
+ if (c != 0)
+ return c;
+
+ // modifiers
+ long v1 = modsValue(this.modifiers());
+ long v2 = modsValue(that.modifiers());
+ c = Long.compare(v1, v2);
+ if (c != 0)
+ return c;
+
+ // targets
+ c = compare(targets, that.targets);
+ if (c != 0)
+ return c;
+
+ return 0;
+ }
+
/**
* Computes a hash code for this module opens.
*
@@ -588,9 +732,9 @@ public class ModuleDescriptor
}
/**
- * Returns a string describing module opens.
+ * Returns a string describing the open package.
*
- * @return A string describing module opens
+ * @return A string describing the open package
*/
@Override
public String toString() {
@@ -608,10 +752,12 @@ public class ModuleDescriptor
*
* @see ModuleDescriptor#provides()
* @since 9
+ * @spec JPMS
*/
- public final static class Provides {
-
+ public final static class Provides
+ implements Comparable
+ {
private final String service;
private final List providers;
@@ -641,6 +787,46 @@ public class ModuleDescriptor
*/
public List providers() { return providers; }
+ /**
+ * Compares this provides to another.
+ *
+ *
Two {@code Provides} objects are compared by comparing the fully
+ * qualified class name of the service type lexicographically. Where the
+ * class names are equal then the list of the provider class names are
+ * compared by comparing the corresponding elements of both lists
+ * lexicographically and in sequence. Where the lists differ in size,
+ * {@code N} is the size of the shorter list, and the first {@code N}
+ * corresponding elements are equal, then the longer list is considered
+ * to succeed the shorter list.
+ *
+ * @param that
+ * The {@code Provides} to compare
+ *
+ * @return A negative integer, zero, or a positive integer if this provides
+ * is less than, equal to, or greater than the given provides
+ */
+ public int compareTo(Provides that) {
+ if (this == that) return 0;
+
+ int c = service.compareTo(that.service);
+ if (c != 0) return c;
+
+ // compare provider class names in sequence
+ int size1 = this.providers.size();
+ int size2 = that.providers.size();
+ for (int index=0; index size2) ? 1 : -1;
+ }
+ }
+
/**
* Computes a hash code for this provides.
*
@@ -699,7 +885,7 @@ public class ModuleDescriptor
*
*
A version string has three components: The version number itself, an
* optional pre-release version, and an optional build version. Each
- * component is sequence of tokens; each token is either a non-negative
+ * component is a sequence of tokens; each token is either a non-negative
* integer or a string. Tokens are separated by the punctuation characters
* {@code '.'}, {@code '-'}, or {@code '+'}, or by transitions from a
* sequence of digits to a sequence of characters that are neither digits
@@ -740,6 +926,7 @@ public class ModuleDescriptor
*
* @see ModuleDescriptor#version()
* @since 9
+ * @spec JPMS
*/
public final static class Version
@@ -1009,36 +1196,26 @@ public class ModuleDescriptor
}
-
+
private final String name;
private final Version version;
- private final boolean open;
-
- // Indicates if synthesised for a JAR file found on the module path
- private final boolean automatic;
-
- // Not generated from a module-info.java
- private final boolean synthetic;
-
+ private final Set modifiers;
+ private final boolean open; // true if modifiers contains OPEN
+ private final boolean automatic; // true if modifiers contains AUTOMATIC
private final Set requires;
private final Set exports;
private final Set opens;
private final Set uses;
private final Set provides;
-
- // Added post-compilation by tools
private final Set packages;
private final String mainClass;
private final String osName;
private final String osArch;
private final String osVersion;
-
private ModuleDescriptor(String name,
Version version,
- boolean open,
- boolean automatic,
- boolean synthetic,
+ Set modifiers,
Set requires,
Set exports,
Set opens,
@@ -1052,10 +1229,9 @@ public class ModuleDescriptor
{
this.name = name;
this.version = version;
- this.open = open;
- this.automatic = automatic;
- this.synthetic = synthetic;
-
+ this.modifiers = emptyOrUnmodifiableSet(modifiers);
+ this.open = modifiers.contains(Modifier.OPEN);
+ this.automatic = modifiers.contains(Modifier.AUTOMATIC);
assert (requires.stream().map(Requires::name).distinct().count()
== requires.size());
this.requires = emptyOrUnmodifiableSet(requires);
@@ -1071,41 +1247,13 @@ public class ModuleDescriptor
this.osVersion = osVersion;
}
- /**
- * Clones the given module descriptor with an augmented set of packages
- */
- ModuleDescriptor(ModuleDescriptor md, Set pkgs) {
- this.name = md.name;
- this.version = md.version;
- this.open = md.open;
- this.automatic = md.automatic;
- this.synthetic = md.synthetic;
-
- this.requires = md.requires;
- this.exports = md.exports;
- this.opens = md.opens;
- this.uses = md.uses;
- this.provides = md.provides;
-
- Set packages = new HashSet<>(md.packages);
- packages.addAll(pkgs);
- this.packages = emptyOrUnmodifiableSet(packages);
-
- this.mainClass = md.mainClass;
- this.osName = md.osName;
- this.osArch = md.osArch;
- this.osVersion = md.osVersion;
- }
-
/**
* Creates a module descriptor from its components.
* The arguments are pre-validated and sets are unmodifiable sets.
*/
ModuleDescriptor(String name,
Version version,
- boolean open,
- boolean automatic,
- boolean synthetic,
+ Set modifiers,
Set requires,
Set exports,
Set opens,
@@ -1120,9 +1268,9 @@ public class ModuleDescriptor
boolean unused) {
this.name = name;
this.version = version;
- this.open = open;
- this.automatic = automatic;
- this.synthetic = synthetic;
+ this.modifiers = modifiers;
+ this.open = modifiers.contains(Modifier.OPEN);
+ this.automatic = modifiers.contains(Modifier.AUTOMATIC);
this.requires = requires;
this.exports = exports;
this.opens = opens;
@@ -1137,7 +1285,7 @@ public class ModuleDescriptor
}
/**
- *
The module name.
+ *
Returns the module name.
*
* @return The module name
*/
@@ -1145,12 +1293,20 @@ public class ModuleDescriptor
return name;
}
+ /**
+ *
Returns the set of module modifiers.
+ *
+ * @return A possibly-empty unmodifiable set of modifiers
+ */
+ public Set modifiers() {
+ return modifiers;
+ }
+
/**
*
Returns {@code true} if this is an open module.
*
- *
An open module does not declare any open packages (the {@link #opens()
- * opens} method returns an empty set) but the resulting module is treated
- * as if all packages are open.
+ *
This method is equivalent to testing if the set of {@link #modifiers
+ * modifiers} contains the {@link Modifier#OPEN OPEN} modifier.
*
* @return {@code true} if this is an open module
*/
@@ -1161,12 +1317,8 @@ public class ModuleDescriptor
/**
*
Returns {@code true} if this is an automatic module.
*
- *
An automatic module is defined implicitly rather than explicitly
- * and therefore does not have a module declaration. JAR files located on
- * the application module path, or by the {@link ModuleFinder} returned by
- * {@link ModuleFinder#of(java.nio.file.Path[]) ModuleFinder.of}, are
- * treated as automatic modules if they do have not have a module
- * declaration.
+ *
This method is equivalent to testing if the set of {@link #modifiers
+ * modifiers} contains the {@link Modifier#OPEN AUTOMATIC} modifier.
*
* @return {@code true} if this is an automatic module
*/
@@ -1175,20 +1327,13 @@ public class ModuleDescriptor
}
/**
- *
Returns {@code true} if this module descriptor was not generated
- * from an explicit module declaration ({@code module-info.java})
- * or an implicit module declaration (an {@link #isAutomatic() automatic}
- * module).
+ *
Returns the set of {@code Requires} objects representing the module
+ * dependences.
*
- * @return {@code true} if this module descriptor was not generated by
- * an explicit or implicit module declaration
- */
- public boolean isSynthetic() {
- return synthetic;
- }
-
- /**
- *
The dependences of this module.
+ *
The set includes a dependency on "{@code java.base}" when this
+ * module is not named "{@code java.base}". If this module is an automatic
+ * module then it does not have a dependency on any module other than
+ * "{@code java.base}".
*
* @return A possibly-empty unmodifiable set of {@link Requires} objects
*/
@@ -1197,7 +1342,11 @@ public class ModuleDescriptor
}
/**
- *
The module exports.
+ *
Returns the set of {@code Exports} objects representing the exported
+ * packages.
+ *
+ *
If this module is an automatic module then the set of exports
+ * is empty.
*
* @return A possibly-empty unmodifiable set of exported packages
*/
@@ -1206,16 +1355,11 @@ public class ModuleDescriptor
}
/**
- *
The module opens directives.
+ *
Returns the set of {@code Opens} objects representing the open
+ * packages.
*
- *
Each {@code Opens} object in the set represents a package (and
- * the set of target module names when qualified) where all types in the
- * package, and all their members, not just public types and their public
- * members, can be reflected on when using APIs that bypass or suppress
- * default Java language access control checks.
- *
- *
This method returns an empty set when invoked on {@link #isOpen()
- * open} module.
+ *
If this module is an open module or an automatic module then the
+ * set of open packages is empty.
*
* @return A possibly-empty unmodifiable set of open packages
*/
@@ -1224,7 +1368,10 @@ public class ModuleDescriptor
}
/**
- *
The service dependences of this module.
+ *
Returns the set of service dependences.
+ *
+ *
If this module is an automatic module then the set of service
+ * dependences is empty.
*
* @return A possibly-empty unmodifiable set of the fully qualified class
* names of the service types used
@@ -1234,7 +1381,8 @@ public class ModuleDescriptor
}
/**
- *
The services that this module provides.
+ *
Returns the set of {@code Provides} objects representing the
+ * services that the module provides.
*
* @return The possibly-empty unmodifiable set of the services that this
* module provides
@@ -1244,7 +1392,7 @@ public class ModuleDescriptor
}
/**
- * Returns this module's version.
+ *
Returns the module version.
*
* @return This module's version
*/
@@ -1253,10 +1401,10 @@ public class ModuleDescriptor
}
/**
- * Returns a string containing this module's name and, if present, its
- * version.
+ *
Returns a string containing the module name and, if present, its
+ * version.
*
- * @return A string containing this module's name and, if present, its
+ * @return A string containing the module name and, if present, its
* version.
*/
public String toNameAndVersion() {
@@ -1268,51 +1416,51 @@ public class ModuleDescriptor
}
/**
- * Returns the module's main class.
+ *
Returns the module main class.
*
- * @return The fully qualified class name of this module's main class
+ * @return The fully qualified class name of the module's main class
*/
public Optional mainClass() {
return Optional.ofNullable(mainClass);
}
/**
- * Returns the operating system name if this module is operating system
+ * Returns the operating system name if the module is operating system
* specific.
*
* @return The operating system name or an empty {@code Optional}
- * if this module is not operating system specific
+ * if the module is not operating system specific
*/
public Optional osName() {
return Optional.ofNullable(osName);
}
/**
- * Returns the operating system architecture if this module is operating
+ * Returns the operating system architecture if the module is operating
* system architecture specific.
*
* @return The operating system architecture or an empty {@code Optional}
- * if this module is not operating system architecture specific
+ * if the module is not operating system architecture specific
*/
public Optional osArch() {
return Optional.ofNullable(osArch);
}
/**
- * Returns the operating system version if this module is operating
+ * Returns the operating system version if the module is operating
* system version specific.
*
* @return The operating system version or an empty {@code Optional}
- * if this module is not operating system version specific
+ * if the module is not operating system version specific
*/
public Optional osVersion() {
return Optional.ofNullable(osVersion);
}
/**
- * Returns the names of all packages in this module.
+ * Returns the set of packages in the module.
*
- * @return A possibly-empty unmodifiable set of all packages in the module
+ * @return A possibly-empty unmodifiable set of the packages in the module
*/
public Set packages() {
return packages;
@@ -1320,37 +1468,53 @@ public class ModuleDescriptor
/**
- * A builder used for building {@link ModuleDescriptor} objects.
+ * A builder for building {@link ModuleDescriptor} objects.
*
- *
{@code ModuleDescriptor} defines the {@link #module module}, {@link
- * #openModule openModule}, and {@link #automaticModule automaticModule}
- * methods to create builders for building different kinds of modules.
+ *
{@code ModuleDescriptor} defines the {@link #newModule newModule},
+ * {@link #newOpenModule newOpenModule}, and {@link #newAutomaticModule
+ * newAutomaticModule} methods to create builders for building
+ * normal, open, and automatic modules.
+ *
+ *
The set of packages in the module are accumulated by the {@code
+ * Builder} as the {@link ModuleDescriptor.Builder#exports(String) exports},
+ * {@link ModuleDescriptor.Builder#opens(String) opens},
+ * {@link ModuleDescriptor.Builder#packages(Set) packages},
+ * {@link ModuleDescriptor.Builder#provides(String,List) provides}, and
+ * {@link ModuleDescriptor.Builder#mainClass(String) mainClass} methods are
+ * invoked.
+ *
+ *
The module names, package names, and class names that are parameters
+ * specified to the builder methods are the module names, package names,
+ * and qualified names of classes (in named packages) as defined in the
+ * The Java™ Language Specification.
*
* @apiNote A {@code Builder} checks the components and invariants as
- * components are added to the builder. The rational for this is to detect
+ * components are added to the builder. The rationale for this is to detect
* errors as early as possible and not defer all validation to the
- * {@link #build build} method. A {@code Builder} cannot be used to create
- * a {@link ModuleDescriptor#isSynthetic() synthetic} module.
+ * {@link #build build} method.
*
* @since 9
+ * @spec JPMS
*/
public static final class Builder {
final String name;
- final boolean strict; // true if module names are checked
+ final boolean strict;
+ final Set modifiers;
final boolean open;
- final boolean synthetic;
- boolean automatic;
+ final boolean automatic;
+ final Set packages = new HashSet<>();
final Map requires = new HashMap<>();
final Map exports = new HashMap<>();
final Map opens = new HashMap<>();
- final Set concealedPackages = new HashSet<>();
final Set uses = new HashSet<>();
final Map provides = new HashMap<>();
Version version;
@@ -1362,35 +1526,25 @@ public class ModuleDescriptor
/**
* Initializes a new builder with the given module name.
*
- * @param strict
- * Indicates whether module names are checked or not
+ * If {@code strict} is {@code true} then module, package, and class
+ * names are checked to ensure they are legal names. In addition, the
+ * {@link #build buid} method will add "{@code requires java.base}" if
+ * the dependency is not declared.
*/
- Builder(String name, boolean strict, boolean open, boolean synthetic) {
+ Builder(String name, boolean strict, Set modifiers) {
this.name = (strict) ? requireModuleName(name) : name;
this.strict = strict;
- this.open = open;
- this.synthetic = synthetic;
- }
-
- /* package */ Builder automatic(boolean automatic) {
- this.automatic = automatic;
- return this;
+ this.modifiers = modifiers;
+ this.open = modifiers.contains(Modifier.OPEN);
+ this.automatic = modifiers.contains(Modifier.AUTOMATIC);
+ assert !open || !automatic;
}
/**
- * Returns the set of packages that are exported (unconditionally or
- * unconditionally).
+ * Returns a snapshot of the packages in the module.
*/
- /* package */ Set exportedPackages() {
- return exports.keySet();
- }
-
- /**
- * Returns the set of packages that are opened (unconditionally or
- * unconditionally).
- */
- /* package */Set openPackages() {
- return opens.keySet();
+ /* package */ Set packages() {
+ return Collections.unmodifiableSet(packages);
}
/**
@@ -1406,8 +1560,12 @@ public class ModuleDescriptor
* initialized to build
* @throws IllegalStateException
* If the dependence on the module has already been declared
+ * or this builder is for an automatic module
*/
public Builder requires(Requires req) {
+ if (automatic)
+ throw new IllegalStateException("Automatic modules cannot declare"
+ + " dependences");
String mn = req.name();
if (name.equals(mn))
throw new IllegalArgumentException("Dependence on self");
@@ -1433,11 +1591,12 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the module name is {@code null}, is not a legal Java
- * identifier, or is equal to the module name that this builder
+ * If the module name is {@code null}, is not a legal module
+ * name, or is equal to the module name that this builder
* was initialized to build
* @throws IllegalStateException
* If the dependence on the module has already been declared
+ * or this builder is for an automatic module
*/
public Builder requires(Set ms,
String mn,
@@ -1448,6 +1607,23 @@ public class ModuleDescriptor
return requires(new Requires(ms, mn, compiledVersion));
}
+ /* package */Builder requires(Set ms,
+ String mn,
+ String compiledVersion) {
+ Version v = null;
+ try {
+ v = Version.parse(compiledVersion);
+ } catch (IllegalArgumentException e) {
+ // for now, drop un-parsable version when non-strict
+ if (strict) throw e;
+ }
+ if (v == null) {
+ return requires(ms, mn);
+ } else {
+ return requires(ms, mn, v);
+ }
+ }
+
/**
* Adds a dependence on a module with the given (and possibly empty)
* set of modifiers.
@@ -1460,11 +1636,12 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the module name is {@code null}, is not a legal Java
- * identifier, or is equal to the module name that this builder
+ * If the module name is {@code null}, is not a legal module
+ * name, or is equal to the module name that this builder
* was initialized to build
* @throws IllegalStateException
* If the dependence on the module has already been declared
+ * or this builder is for an automatic module
*/
public Builder requires(Set ms, String mn) {
if (strict)
@@ -1481,18 +1658,19 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the module name is {@code null}, is not a legal Java
- * identifier, or is equal to the module name that this builder
+ * If the module name is {@code null}, is not a legal module
+ * name, or is equal to the module name that this builder
* was initialized to build
* @throws IllegalStateException
* If the dependence on the module has already been declared
+ * or this builder is for an automatic module
*/
public Builder requires(String mn) {
return requires(EnumSet.noneOf(Requires.Modifier.class), mn);
}
/**
- * Adds an export.
+ * Adds an exported package.
*
* @param e
* The export
@@ -1500,29 +1678,27 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method or the package is already
- * declared as exported
+ * If the {@link Exports#source package} is already declared as
+ * exported or this builder is for an automatic module
*/
public Builder exports(Exports e) {
- // can't be exported and concealed
- String source = e.source();
- if (concealedPackages.contains(source)) {
- throw new IllegalStateException("Package " + source
- + " already declared");
+ if (automatic) {
+ throw new IllegalStateException("Automatic modules cannot declare"
+ + " exported packages");
}
+ String source = e.source();
if (exports.containsKey(source)) {
throw new IllegalStateException("Exported package " + source
+ " already declared");
}
-
exports.put(source, e);
+ packages.add(source);
return this;
}
/**
- * Adds an export, with the given (and possibly empty) set of modifiers,
- * to export a package to a set of target modules.
+ * Adds an exported package with the given (and possibly empty) set of
+ * modifiers. The package is exported to a set of target modules.
*
* @param ms
* The set of modifiers
@@ -1534,33 +1710,34 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the package name or any of the target modules is {@code
- * null} or is not a legal Java identifier, or the set of
- * targets is empty
+ * If the package name is {@code null} or is not a legal
+ * package name, the set of target modules is empty, or the set
+ * of target modules contains a name that is not a legal module
+ * name
* @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method or the package is already
- * declared as exported
+ * If the package is already declared as exported
+ * or this builder is for an automatic module
*/
public Builder exports(Set ms,
String pn,
Set targets)
{
- Exports e = new Exports(ms, requirePackageName(pn), targets);
+ Exports e = new Exports(ms, pn, targets);
// check targets
targets = e.targets();
if (targets.isEmpty())
throw new IllegalArgumentException("Empty target set");
- if (strict)
+ if (strict) {
+ requirePackageName(e.source());
targets.stream().forEach(Checks::requireModuleName);
-
+ }
return exports(e);
}
/**
- * Adds an unqualified export with the given (and possibly empty) set
- * of modifiers.
+ * Adds an exported package with the given (and possibly empty) set of
+ * modifiers. The package is exported to all modules.
*
* @param ms
* The set of modifiers
@@ -1570,160 +1747,22 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the package name is {@code null} or is not a legal Java
- * identifier
+ * If the package name is {@code null} or is not a legal
+ * package name
* @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method or the package is already
- * declared as exported
+ * If the package is already declared as exported
+ * or this builder is for an automatic module
*/
public Builder exports(Set ms, String pn) {
- Exports e = new Exports(ms, requirePackageName(pn), Collections.emptySet());
+ if (strict) {
+ requirePackageName(pn);
+ }
+ Exports e = new Exports(ms, pn, Collections.emptySet());
return exports(e);
}
/**
- * Adds an export to export a package to a set of target modules.
- *
- * @param pn
- * The package name
- * @param targets
- * The set of target modules names
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the package name or any of the target modules is {@code
- * null} or is not a legal Java identifier, or the set of
- * targets is empty
- * @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method or the package is already
- * declared as exported
- */
- public Builder exports(String pn, Set targets) {
- return exports(Collections.emptySet(), pn, targets);
- }
-
- /**
- * Adds an unqualified export.
- *
- * @param pn
- * The package name
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the package name is {@code null} or is not a legal Java
- * identifier
- * @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method or the package is already
- * declared as exported
- */
- public Builder exports(String pn) {
- return exports(Collections.emptySet(), pn);
- }
-
- /**
- * Adds an opens directive.
- *
- * @param obj
- * The {@code Opens} object
- *
- * @return This builder
- *
- * @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method, the package is already
- * declared as open, or this is a builder for an open module
- */
- public Builder opens(Opens obj) {
- if (open) {
- throw new IllegalStateException("open modules cannot declare"
- + " open packages");
- }
-
- // can't be open and concealed
- String source = obj.source();
- if (concealedPackages.contains(source)) {
- throw new IllegalStateException("Package " + source
- + " already declared");
- }
- if (opens.containsKey(source)) {
- throw new IllegalStateException("Open package " + source
- + " already declared");
- }
-
- opens.put(source, obj);
- return this;
- }
-
-
- /**
- * Adds an opens directive, with the given (and possibly empty)
- * set of modifiers, to open a package to a set of target modules.
- *
- * @param ms
- * The set of modifiers
- * @param pn
- * The package name
- * @param targets
- * The set of target modules names
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the package name or any of the target modules is {@code
- * null} or is not a legal Java identifier, or the set of
- * targets is empty
- * @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method, the package is already
- * declared as open, or this is a builder for an open module
- */
- public Builder opens(Set ms,
- String pn,
- Set targets)
- {
- Opens e = new Opens(ms, requirePackageName(pn), targets);
-
- // check targets
- targets = e.targets();
- if (targets.isEmpty())
- throw new IllegalArgumentException("Empty target set");
- if (strict)
- targets.stream().forEach(Checks::requireModuleName);
-
- return opens(e);
- }
-
- /**
- * Adds an opens directive to open a package with the given (and
- * possibly empty) set of modifiers.
- *
- * @param ms
- * The set of modifiers
- * @param pn
- * The package name
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the package name is {@code null} or is not a legal Java
- * identifier
- * @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method, the package is already
- * declared as open, or this is a builder for an open module
- */
- public Builder opens(Set ms, String pn) {
- Opens e = new Opens(ms, requirePackageName(pn), Collections.emptySet());
- return opens(e);
- }
-
- /**
- * Adds an opens directive to open a package to a set of target
+ * Adds an exported package. The package is exported to a set of target
* modules.
*
* @param pn
@@ -1734,20 +1773,20 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the package name or any of the target modules is {@code
- * null} or is not a legal Java identifier, or the set of
- * targets is empty
+ * If the package name is {@code null} or is not a legal
+ * package name, the set of target modules is empty, or the set
+ * of target modules contains a name that is not a legal module
+ * name
* @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method, the package is already
- * declared as open, or this is a builder for an open module
+ * If the package is already declared as exported
+ * or this builder is for an automatic module
*/
- public Builder opens(String pn, Set targets) {
- return opens(Collections.emptySet(), pn, targets);
+ public Builder exports(String pn, Set targets) {
+ return exports(Collections.emptySet(), pn, targets);
}
/**
- * Adds an opens directive to open a package.
+ * Adds an exported package. The package is exported to all modules.
*
* @param pn
* The package name
@@ -1755,12 +1794,146 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the package name is {@code null} or is not a legal Java
- * identifier
+ * If the package name is {@code null} or is not a legal
+ * package name
* @throws IllegalStateException
- * If the package is already declared as a package with the
- * {@link #contains contains} method, the package is already
- * declared as open, or this is a builder for an open module
+ * If the package is already declared as exported
+ * or this builder is for an automatic module
+ */
+ public Builder exports(String pn) {
+ return exports(Collections.emptySet(), pn);
+ }
+
+ /**
+ * Adds an open package.
+ *
+ * @param obj
+ * The {@code Opens} object
+ *
+ * @return This builder
+ *
+ * @throws IllegalStateException
+ * If the package is already declared as open, or this is a
+ * builder for an open module or automatic module
+ */
+ public Builder opens(Opens obj) {
+ if (open || automatic) {
+ throw new IllegalStateException("Open or automatic modules cannot"
+ + " declare open packages");
+ }
+ String source = obj.source();
+ if (opens.containsKey(source)) {
+ throw new IllegalStateException("Open package " + source
+ + " already declared");
+ }
+ opens.put(source, obj);
+ packages.add(source);
+ return this;
+ }
+
+
+ /**
+ * Adds an open package with the given (and possibly empty) set of
+ * modifiers. The package is open to a set of target modules.
+ *
+ * @param ms
+ * The set of modifiers
+ * @param pn
+ * The package name
+ * @param targets
+ * The set of target modules names
+ *
+ * @return This builder
+ *
+ * @throws IllegalArgumentException
+ * If the package name is {@code null} or is not a legal
+ * package name, the set of target modules is empty, or the set
+ * of target modules contains a name that is not a legal module
+ * name
+ * @throws IllegalStateException
+ * If the package is already declared as open, or this is a
+ * builder for an open module or automatic module
+ */
+ public Builder opens(Set ms,
+ String pn,
+ Set targets)
+ {
+ Opens opens = new Opens(ms, pn, targets);
+
+ // check targets
+ targets = opens.targets();
+ if (targets.isEmpty())
+ throw new IllegalArgumentException("Empty target set");
+ if (strict) {
+ requirePackageName(opens.source());
+ targets.stream().forEach(Checks::requireModuleName);
+ }
+ return opens(opens);
+ }
+
+ /**
+ * Adds an open package with the given (and possibly empty) set of
+ * modifiers. The package is open to all modules.
+ *
+ * @param ms
+ * The set of modifiers
+ * @param pn
+ * The package name
+ *
+ * @return This builder
+ *
+ * @throws IllegalArgumentException
+ * If the package name is {@code null} or is not a legal
+ * package name
+ * @throws IllegalStateException
+ * If the package is already declared as open, or this is a
+ * builder for an open module or automatic module
+ */
+ public Builder opens(Set ms, String pn) {
+ if (strict) {
+ requirePackageName(pn);
+ }
+ Opens e = new Opens(ms, pn, Collections.emptySet());
+ return opens(e);
+ }
+
+ /**
+ * Adds an open package. The package is open to a set of target modules.
+ *
+ * @param pn
+ * The package name
+ * @param targets
+ * The set of target modules names
+ *
+ * @return This builder
+ *
+ * @throws IllegalArgumentException
+ * If the package name is {@code null} or is not a legal
+ * package name, the set of target modules is empty, or the set
+ * of target modules contains a name that is not a legal module
+ * name
+ * @throws IllegalStateException
+ * If the package is already declared as open, or this is a
+ * builder for an open module or automatic module
+ */
+ public Builder opens(String pn, Set targets) {
+ return opens(Collections.emptySet(), pn, targets);
+ }
+
+ /**
+ * Adds an open package. The package is open to all modules.
+ *
+ * @param pn
+ * The package name
+ *
+ * @return This builder
+ *
+ * @throws IllegalArgumentException
+ * If the package name is {@code null} or is not a legal
+ * package name
+ * @throws IllegalStateException
+ * If the package is already declared as open, or this is a
+ * builder for an open module or automatic module
*/
public Builder opens(String pn) {
return opens(Collections.emptySet(), pn);
@@ -1775,12 +1948,16 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If the service type is {@code null} or is not a legal Java
- * identifier
+ * If the service type is {@code null} or not a qualified name of
+ * a class in a named package
* @throws IllegalStateException
* If a dependency on the service type has already been declared
+ * or this is a builder for an an automatic module
*/
public Builder uses(String service) {
+ if (automatic)
+ throw new IllegalStateException("Automatic modules can not declare"
+ + " service dependences");
if (uses.contains(requireServiceTypeName(service)))
throw new IllegalStateException("Dependence upon service "
+ service + " already declared");
@@ -1789,7 +1966,9 @@ public class ModuleDescriptor
}
/**
- * Provides a service with one or more implementations.
+ * Provides a service with one or more implementations. The package for
+ * each {@link Provides#providers provider} (or provider factory) is
+ * added to the module if not already added.
*
* @param p
* The provides
@@ -1801,16 +1980,18 @@ public class ModuleDescriptor
* declared
*/
public Builder provides(Provides p) {
- String st = p.service();
- if (provides.containsKey(st))
+ String service = p.service();
+ if (provides.containsKey(service))
throw new IllegalStateException("Providers of service "
- + st + " already declared");
- provides.put(st, p);
+ + service + " already declared");
+ provides.put(service, p);
+ p.providers().forEach(name -> packages.add(packageName(name)));
return this;
}
/**
- * Provides implementations of a service.
+ * Provides implementations of a service. The package for each provider
+ * (or provider factory) is added to the module if not already added.
*
* @param service
* The service type
@@ -1821,103 +2002,59 @@ public class ModuleDescriptor
*
* @throws IllegalArgumentException
* If the service type or any of the provider class names is
- * {@code null} or is not a legal Java identifier, or the list
- * of provider class names is empty
+ * {@code null} or not a qualified name of a class in a named
+ * package, or the list of provider class names is empty
* @throws IllegalStateException
* If the providers for the service type have already been
* declared
*/
public Builder provides(String service, List providers) {
- if (provides.containsKey(service))
- throw new IllegalStateException("Providers of service "
- + service + " already declared by " + name);
-
- Provides p = new Provides(requireServiceTypeName(service), providers);
+ Provides p = new Provides(service, providers);
// check providers after the set has been copied.
List providerNames = p.providers();
if (providerNames.isEmpty())
throw new IllegalArgumentException("Empty providers set");
- providerNames.forEach(Checks::requireServiceProviderName);
- provides.put(service, p);
- return this;
+ if (strict) {
+ requireServiceTypeName(p.service());
+ providerNames.forEach(Checks::requireServiceProviderName);
+ } else {
+ // Disallow service/providers in unnamed package
+ String pn = packageName(service);
+ if (pn.isEmpty()) {
+ throw new IllegalArgumentException(service
+ + ": unnamed package");
+ }
+ for (String name : providerNames) {
+ pn = packageName(name);
+ if (pn.isEmpty()) {
+ throw new IllegalArgumentException(name
+ + ": unnamed package");
+ }
+ }
+ }
+ return provides(p);
}
/**
- * Provides an implementation of a service.
- *
- * @param service
- * The service type
- * @param provider
- * The provider or provider factory class name
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the service type or the provider class name is {@code
- * null} or is not a legal Java identifier
- * @throws IllegalStateException
- * If the providers for the service type have already been
- * declared
- */
- public Builder provides(String service, String provider) {
- if (provider == null)
- throw new IllegalArgumentException("'provider' is null");
- return provides(service, List.of(provider));
- }
-
- /**
- * Adds a (possible empty) set of packages to the module
+ * Adds packages to the module. All packages in the set of package names
+ * that are not in the module are added to module.
*
* @param pns
- * The set of package names
+ * The (possibly empty) set of package names
*
* @return This builder
*
* @throws IllegalArgumentException
* If any of the package names is {@code null} or is not a
- * legal Java identifier
- * @throws IllegalStateException
- * If any of packages are already declared as packages in
- * the module. This includes packages that are already
- * declared as exported or open packages.
+ * legal package name
*/
- public Builder contains(Set pns) {
- pns.forEach(this::contains);
- return this;
- }
-
- /**
- * Adds a package to the module.
- *
- * @param pn
- * The package name
- *
- * @return This builder
- *
- * @throws IllegalArgumentException
- * If the package name is {@code null}, or is not a legal Java
- * identifier
- * @throws IllegalStateException
- * If the package is already declared as a package in the
- * module. This includes the package already declared as an
- * exported or open package.
- */
- public Builder contains(String pn) {
- Checks.requirePackageName(pn);
- if (concealedPackages.contains(pn)) {
- throw new IllegalStateException("Package " + pn
- + " already declared");
+ public Builder packages(Set pns) {
+ if (strict) {
+ pns = new HashSet<>(pns);
+ pns.forEach(Checks::requirePackageName);
}
- if (exports.containsKey(pn)) {
- throw new IllegalStateException("Exported package "
- + pn + " already declared");
- }
- if (opens.containsKey(pn)) {
- throw new IllegalStateException("Open package "
- + pn + " already declared");
- }
- concealedPackages.add(pn);
+ this.packages.addAll(pns);
return this;
}
@@ -1937,22 +2074,35 @@ public class ModuleDescriptor
/**
* Sets the module version.
*
- * @param v
+ * @param vs
* The version string to parse
*
* @return This builder
*
* @throws IllegalArgumentException
- * If {@code v} is null or cannot be parsed as a version string
+ * If {@code vs} is {@code null} or cannot be parsed as a
+ * version string
*
* @see Version#parse(String)
*/
- public Builder version(String v) {
- return version(Version.parse(v));
+ public Builder version(String vs) {
+ Version v;
+ if (strict) {
+ v = Version.parse(vs);
+ } else {
+ try {
+ v = Version.parse(vs);
+ } catch (IllegalArgumentException ignore) {
+ // for now, ignore when non-strict
+ return this;
+ }
+ }
+ return version(v);
}
/**
- * Sets the module main class.
+ * Sets the module main class. The package for the main class is added
+ * to the module if not already added.
*
* @param mc
* The module main class
@@ -1960,10 +2110,24 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If {@code mainClass} is null or is not a legal Java identifier
+ * If {@code mainClass} is {@code null} or not a qualified
+ * name of a class in a named package
*/
public Builder mainClass(String mc) {
- mainClass = requireBinaryName("main class name", mc);
+ String pn;
+ if (strict) {
+ mc = requireQualifiedClassName("main class name", mc);
+ pn = packageName(mc);
+ assert !pn.isEmpty();
+ } else {
+ // Disallow main class in unnamed package
+ pn = packageName(mc);
+ if (pn.isEmpty()) {
+ throw new IllegalArgumentException(mc + ": unnamed package");
+ }
+ }
+ mainClass = mc;
+ packages.add(pn);
return this;
}
@@ -1976,7 +2140,7 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If {@code name} is null or the empty String
+ * If {@code name} is {@code null} or the empty String
*/
public Builder osName(String name) {
if (name == null || name.isEmpty())
@@ -1994,7 +2158,7 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If {@code name} is null or the empty String
+ * If {@code name} is {@code null} or the empty String
*/
public Builder osArch(String arch) {
if (arch == null || arch.isEmpty())
@@ -2012,7 +2176,7 @@ public class ModuleDescriptor
* @return This builder
*
* @throws IllegalArgumentException
- * If {@code name} is null or the empty String
+ * If {@code name} is {@code null} or the empty String
*/
public Builder osVersion(String version) {
if (version == null || version.isEmpty())
@@ -2024,26 +2188,34 @@ public class ModuleDescriptor
/**
* Builds and returns a {@code ModuleDescriptor} from its components.
*
+ *
The module will require "{@code java.base}" even if the dependence
+ * has not been declared (the exception is when building a module named
+ * "{@code java.base}" as it cannot require itself). The dependence on
+ * "{@code java.base}" will have the {@link
+ * java.lang.module.ModuleDescriptor.Requires.Modifier#MANDATED MANDATED}
+ * modifier if the dependence was not declared.
+ *
* @return The module descriptor
*/
public ModuleDescriptor build() {
Set requires = new HashSet<>(this.requires.values());
-
- Set packages = new HashSet<>();
- packages.addAll(exports.keySet());
- packages.addAll(opens.keySet());
- packages.addAll(concealedPackages);
-
Set exports = new HashSet<>(this.exports.values());
Set opens = new HashSet<>(this.opens.values());
+ // add dependency on java.base
+ if (strict
+ && !name.equals("java.base")
+ && !this.requires.containsKey("java.base")) {
+ requires.add(new Requires(Set.of(Requires.Modifier.MANDATED),
+ "java.base",
+ null));
+ }
+
Set provides = new HashSet<>(this.provides.values());
return new ModuleDescriptor(name,
version,
- open,
- automatic,
- synthetic,
+ modifiers,
requires,
exports,
opens,
@@ -2062,16 +2234,20 @@ public class ModuleDescriptor
* Compares this module descriptor to another.
*
*
Two {@code ModuleDescriptor} objects are compared by comparing their
- * module name lexicographically. Where the module names are equal then
- * the versions, if present, are compared.
- *
- * @apiNote For now, the natural ordering is not consistent with equals.
- * If two module descriptors have equal module names, equal versions if
- * present, but their corresponding components are not equal, then they
- * will be considered equal by this method.
+ * module names lexicographically. Where the module names are equal then the
+ * module versions are compared. When comparing the module versions then a
+ * module descriptor with a version is considered to succeed a module
+ * descriptor that does not have a version. Where the module names are equal
+ * and the versions are equal (or not present in both), then the set of
+ * modifiers are compared. Sets of modifiers are compared by comparing
+ * a binary value computed for each set. If a modifier is present
+ * in the set then the bit at the position of its ordinal is {@code 1}
+ * in the binary value, otherwise {@code 0}. If the two set of modifiers
+ * are also equal then the other components of the module descriptors are
+ * compared in a manner that is consistent with {@code equals}.
*
* @param that
- * The object to which this module descriptor is to be compared
+ * The module descriptor to compare
*
* @return A negative integer, zero, or a positive integer if this module
* descriptor is less than, equal to, or greater than the given
@@ -2079,16 +2255,50 @@ public class ModuleDescriptor
*/
@Override
public int compareTo(ModuleDescriptor that) {
+ if (this == that) return 0;
+
int c = this.name().compareTo(that.name());
if (c != 0) return c;
- if (version == null) {
- if (that.version == null)
- return 0;
- return -1;
- }
- if (that.version == null)
- return +1;
- return version.compareTo(that.version);
+
+ c = compare(this.version, that.version);
+ if (c != 0) return c;
+
+ long v1 = modsValue(this.modifiers());
+ long v2 = modsValue(that.modifiers());
+ c = Long.compare(v1, v2);
+ if (c != 0) return c;
+
+ c = compare(this.requires, that.requires);
+ if (c != 0) return c;
+
+ c = compare(this.packages, that.packages);
+ if (c != 0) return c;
+
+ c = compare(this.exports, that.exports);
+ if (c != 0) return c;
+
+ c = compare(this.opens, that.opens);
+ if (c != 0) return c;
+
+ c = compare(this.uses, that.uses);
+ if (c != 0) return c;
+
+ c = compare(this.provides, that.provides);
+ if (c != 0) return c;
+
+ c = compare(this.mainClass, that.mainClass);
+ if (c != 0) return c;
+
+ c = compare(this.osName, that.osName);
+ if (c != 0) return c;
+
+ c = compare(this.osArch, that.osArch);
+ if (c != 0) return c;
+
+ c = compare(this.osVersion, that.osVersion);
+ if (c != 0) return c;
+
+ return 0;
}
/**
@@ -2115,10 +2325,9 @@ public class ModuleDescriptor
return false;
ModuleDescriptor that = (ModuleDescriptor)ob;
return (name.equals(that.name)
- && open == that.open
- && automatic == that.automatic
- && synthetic == that.synthetic
+ && modifiers.equals(that.modifiers)
&& requires.equals(that.requires)
+ && Objects.equals(packages, that.packages)
&& exports.equals(that.exports)
&& opens.equals(that.opens)
&& uses.equals(that.uses)
@@ -2127,12 +2336,9 @@ public class ModuleDescriptor
&& Objects.equals(mainClass, that.mainClass)
&& Objects.equals(osName, that.osName)
&& Objects.equals(osArch, that.osArch)
- && Objects.equals(osVersion, that.osVersion)
- && Objects.equals(packages, that.packages));
+ && Objects.equals(osVersion, that.osVersion));
}
- private transient int hash; // cached hash code
-
/**
* Computes a hash code for this module descriptor.
*
@@ -2147,10 +2353,9 @@ public class ModuleDescriptor
int hc = hash;
if (hc == 0) {
hc = name.hashCode();
- hc = hc * 43 + Boolean.hashCode(open);
- hc = hc * 43 + Boolean.hashCode(automatic);
- hc = hc * 43 + Boolean.hashCode(synthetic);
+ hc = hc * 43 + Objects.hashCode(modifiers);
hc = hc * 43 + requires.hashCode();
+ hc = hc * 43 + Objects.hashCode(packages);
hc = hc * 43 + exports.hashCode();
hc = hc * 43 + opens.hashCode();
hc = hc * 43 + uses.hashCode();
@@ -2160,18 +2365,18 @@ public class ModuleDescriptor
hc = hc * 43 + Objects.hashCode(osName);
hc = hc * 43 + Objects.hashCode(osArch);
hc = hc * 43 + Objects.hashCode(osVersion);
- hc = hc * 43 + Objects.hashCode(packages);
if (hc == 0)
hc = -1;
hash = hc;
}
return hc;
}
+ private transient int hash; // cached hash code
/**
- * Returns a string describing this descriptor.
+ *
Returns a string describing the module.
*
- * @return A string describing this descriptor
+ * @return A string describing the module
*/
@Override
public String toString() {
@@ -2201,31 +2406,50 @@ public class ModuleDescriptor
*
* @param name
* The module name
+ * @param ms
+ * The set of module modifiers
*
* @return A new builder
*
* @throws IllegalArgumentException
- * If the module name is {@code null} or is not a legal Java
- * identifier
+ * If the module name is {@code null} or is not a legal module
+ * name, or the set of modifiers contains {@link
+ * Modifier#AUTOMATIC AUTOMATIC} with other modifiers
*/
- public static Builder module(String name) {
- return new Builder(name, true, false, false);
+ public static Builder newModule(String name, Set ms) {
+ Set mods = new HashSet<>(ms);
+ if (mods.contains(Modifier.AUTOMATIC) && mods.size() > 1)
+ throw new IllegalArgumentException("AUTOMATIC cannot be used with"
+ + " other modifiers");
+
+ return new Builder(name, true, mods);
+ }
+
+ /**
+ * Instantiates a builder to build a module descriptor for a normal
+ * module. This method is equivalent to invoking {@link #newModule(String,Set)
+ * newModule} with an empty set of {@link ModuleDescriptor.Modifier modifiers}.
+ *
+ * @param name
+ * The module name
+ *
+ * @return A new builder
+ *
+ * @throws IllegalArgumentException
+ * If the module name is {@code null} or is not a legal module
+ * name
+ */
+ public static Builder newModule(String name) {
+ return new Builder(name, true, Set.of());
}
/**
* Instantiates a builder to build a module descriptor for an open module.
- * An open module does not declare any open packages but the resulting
- * module is treated as if all packages are open.
+ * This method is equivalent to invoking {@link #newModule(String,Set)
+ * newModule} with the {@link ModuleDescriptor.Modifier#OPEN OPEN} modifier.
*
- *
As an example, the following creates a module descriptor for an open
- * name "{@code m}" containing two packages, one of which is exported.
The builder for an open module cannot be used to declare any open
+ * packages.
*
* @param name
* The module name
@@ -2233,19 +2457,22 @@ public class ModuleDescriptor
* @return A new builder that builds an open module
*
* @throws IllegalArgumentException
- * If the module name is {@code null} or is not a legal Java
- * identifier
+ * If the module name is {@code null} or is not a legal module
+ * name
*/
- public static Builder openModule(String name) {
- return new Builder(name, true, true, false);
+ public static Builder newOpenModule(String name) {
+ return new Builder(name, true, Set.of(Modifier.OPEN));
}
/**
* Instantiates a builder to build a module descriptor for an automatic
- * module. Automatic modules receive special treatment during resolution
- * (see {@link Configuration}) so that they read all other modules. When
- * Instantiated in the Java virtual machine as a {@link java.lang.reflect.Module}
- * then the Module reads every unnamed module in the Java virtual machine.
+ * module. This method is equivalent to invoking {@link #newModule(String,Set)
+ * newModule} with the {@link ModuleDescriptor.Modifier#AUTOMATIC AUTOMATIC}
+ * modifier.
+ *
+ *
The builder for an automatic module cannot be used to declare module
+ * or service dependences. It also cannot be used to declare any exported
+ * or open packages.
*
* @param name
* The module name
@@ -2253,13 +2480,13 @@ public class ModuleDescriptor
* @return A new builder that builds an automatic module
*
* @throws IllegalArgumentException
- * If the module name is {@code null} or is not a legal Java
- * identifier
+ * If the module name is {@code null} or is not a legal module
+ * name
*
* @see ModuleFinder#of(Path[])
*/
- public static Builder automaticModule(String name) {
- return new Builder(name, true, false, false).automatic(true);
+ public static Builder newAutomaticModule(String name) {
+ return new Builder(name, true, Set.of(Modifier.AUTOMATIC));
}
@@ -2269,8 +2496,12 @@ public class ModuleDescriptor
*
*
If the descriptor encoded in the input stream does not indicate a
* set of packages in the module then the {@code packageFinder} will be
- * invoked. If the {@code packageFinder} throws an {@link UncheckedIOException}
- * then {@link IOException} cause will be re-thrown.
+ * invoked. The set of packages that the {@code packageFinder} returns
+ * must include all the packages that the module exports, opens, as well
+ * as the packages of the service implementations that the module provides,
+ * and the package of the main class (if the module has a main class). If
+ * the {@code packageFinder} throws an {@link UncheckedIOException} then
+ * {@link IOException} cause will be re-thrown.
*
*
If there are bytes following the module descriptor then it is
* implementation specific as to whether those bytes are read, ignored,
@@ -2292,7 +2523,9 @@ public class ModuleDescriptor
* @return The module descriptor
*
* @throws InvalidModuleDescriptorException
- * If an invalid module descriptor is detected
+ * If an invalid module descriptor is detected or the set of
+ * packages returned by the {@code packageFinder} does not include
+ * all of the packages obtained from the module descriptor
* @throws IOException
* If an I/O error occurs reading from the input stream or {@code
* UncheckedIOException} is thrown by the package finder
@@ -2305,8 +2538,12 @@ public class ModuleDescriptor
}
/**
- * Reads the binary form of a module declaration from an input stream
- * as a module descriptor.
+ * Reads the binary form of a module declaration from an input stream as a
+ * module descriptor. This method works exactly as specified by the 2-arg
+ * {@link #read(InputStream,Supplier) read} method with the exception that
+ * a packager finder is not used to find additional packages when the
+ * module descriptor read from the stream does not indicate the set of
+ * packages.
*
* @param in
* The input stream
@@ -2327,7 +2564,13 @@ public class ModuleDescriptor
* as a module descriptor.
*
*
If the descriptor encoded in the byte buffer does not indicate a
- * set of packages then the {@code packageFinder} will be invoked.
+ * set of packages in the module then the {@code packageFinder} will be
+ * invoked. The set of packages that the {@code packageFinder} returns
+ * must include all the packages that the module exports, opens, as well
+ * as the packages of the service implementations that the module provides,
+ * and the package of the main class (if the module has a main class). If
+ * the {@code packageFinder} throws an {@link UncheckedIOException} then
+ * {@link IOException} cause will be re-thrown.
*
*
The module descriptor is read from the buffer stating at index
* {@code p}, where {@code p} is the buffer's {@link ByteBuffer#position()
@@ -2353,7 +2596,9 @@ public class ModuleDescriptor
* @return The module descriptor
*
* @throws InvalidModuleDescriptorException
- * If an invalid module descriptor is detected
+ * If an invalid module descriptor is detected or the set of
+ * packages returned by the {@code packageFinder} does not include
+ * all of the packages obtained from the module descriptor
*/
public static ModuleDescriptor read(ByteBuffer bb,
Supplier> packageFinder)
@@ -2362,8 +2607,11 @@ public class ModuleDescriptor
}
/**
- * Reads the binary form of a module declaration from a byte buffer
- * as a module descriptor.
+ * Reads the binary form of a module declaration from a byte buffer as a
+ * module descriptor. This method works exactly as specified by the 2-arg
+ * {@link #read(ByteBuffer,Supplier) read} method with the exception that a
+ * packager finder is not used to find additional packages when the module
+ * descriptor encoded in the buffer does not indicate the set of packages.
*
* @param bb
* The byte buffer
@@ -2398,6 +2646,11 @@ public class ModuleDescriptor
}
}
+ private static String packageName(String cn) {
+ int index = cn.lastIndexOf('.');
+ return (index == -1) ? "" : cn.substring(0, index);
+ }
+
/**
* Returns a string containing the given set of modifiers and label.
*/
@@ -2407,6 +2660,36 @@ public class ModuleDescriptor
.collect(Collectors.joining(" "));
}
+ private static >
+ int compare(T obj1, T obj2) {
+ if (obj1 != null) {
+ return (obj2 != null) ? obj1.compareTo(obj2) : 1;
+ } else {
+ return (obj2 == null) ? 0 : -1;
+ }
+ }
+
+ /**
+ * Compares two sets of {@code Comparable} objects.
+ */
+ @SuppressWarnings("unchecked")
+ private static >
+ int compare(Set s1, Set s2) {
+ T[] a1 = (T[]) s1.toArray();
+ T[] a2 = (T[]) s2.toArray();
+ Arrays.sort(a1);
+ Arrays.sort(a2);
+ return Arrays.compare(a1, a2);
+ }
+
+ private static > long modsValue(Set set) {
+ long value = 0;
+ for (Enum e : set) {
+ value += 1 << e.ordinal();
+ }
+ return value;
+ }
+
static {
/**
* Setup the shared secret to allow code in other packages access
@@ -2417,19 +2700,21 @@ public class ModuleDescriptor
@Override
public Builder newModuleBuilder(String mn,
boolean strict,
- boolean open,
- boolean synthetic) {
- return new Builder(mn, strict, open, synthetic);
+ Set modifiers) {
+ return new Builder(mn, strict, modifiers);
}
@Override
- public Set exportedPackages(ModuleDescriptor.Builder builder) {
- return builder.exportedPackages();
+ public Set packages(ModuleDescriptor.Builder builder) {
+ return builder.packages();
}
@Override
- public Set openPackages(ModuleDescriptor.Builder builder) {
- return builder.openPackages();
+ public void requires(ModuleDescriptor.Builder builder,
+ Set ms,
+ String mn,
+ String compiledVersion) {
+ builder.requires(ms, mn, compiledVersion);
}
@Override
@@ -2466,23 +2751,10 @@ public class ModuleDescriptor
return new Provides(service, providers, true);
}
- @Override
- public Version newVersion(String v) {
- return new Version(v);
- }
-
- @Override
- public ModuleDescriptor newModuleDescriptor(ModuleDescriptor md,
- Set pkgs) {
- return new ModuleDescriptor(md, pkgs);
- }
-
@Override
public ModuleDescriptor newModuleDescriptor(String name,
Version version,
- boolean open,
- boolean automatic,
- boolean synthetic,
+ Set modifiers,
Set requires,
Set exports,
Set opens,
@@ -2496,9 +2768,7 @@ public class ModuleDescriptor
int hashCode) {
return new ModuleDescriptor(name,
version,
- open,
- automatic,
- synthetic,
+ modifiers,
requires,
exports,
opens,
@@ -2514,12 +2784,12 @@ public class ModuleDescriptor
}
@Override
- public Configuration resolveRequiresAndUses(ModuleFinder finder,
- Collection roots,
- boolean check,
- PrintStream traceOutput)
+ public Configuration resolveAndBind(ModuleFinder finder,
+ Collection roots,
+ boolean check,
+ PrintStream traceOutput)
{
- return Configuration.resolveRequiresAndUses(finder, roots, check, traceOutput);
+ return Configuration.resolveAndBind(finder, roots, check, traceOutput);
}
});
}
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
index 5d01f698806..9fc03dc87b5 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleFinder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -42,14 +42,15 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import jdk.internal.module.ModuleBootstrap;
import jdk.internal.module.ModulePath;
import jdk.internal.module.SystemModuleFinder;
import sun.security.action.GetPropertyAction;
/**
* A finder of modules. A {@code ModuleFinder} is used to find modules during
- * resolution or
- * service binding.
+ * resolution or
+ * service binding.
*
*
A {@code ModuleFinder} can only find one module with a given name. A
* {@code ModuleFinder} that finds modules in a sequence of directories, for
@@ -85,6 +86,7 @@ import sun.security.action.GetPropertyAction;
*
A {@code ModuleFinder} is not required to be thread safe.
*
* @since 9
+ * @spec JPMS
*/
public interface ModuleFinder {
@@ -124,8 +126,8 @@ public interface ModuleFinder {
* to find that module.
*
* @apiNote This is important to have for methods such as {@link
- * Configuration#resolveRequiresAndUses resolveRequiresAndUses} that need
- * to scan the module path to find modules that provide a specific service.
+ * Configuration#resolveAndBind resolveAndBind} that need to scan the
+ * module path to find modules that provide a specific service.
*
* @return The set of all module references that this finder locates
*
@@ -172,7 +174,8 @@ public interface ModuleFinder {
} else {
Path mlib = Paths.get(home, "modules");
if (Files.isDirectory(mlib)) {
- return of(mlib);
+ // exploded build may be patched
+ return ModulePath.of(ModuleBootstrap.patcher(), mlib);
} else {
throw new InternalError("Unable to detect the run-time image");
}
@@ -198,13 +201,9 @@ public interface ModuleFinder {
*
*
If an element is a path to a directory of modules then each entry in
* the directory is a packaged module or the top-level directory of an
- * exploded module. The module finder's {@link #find(String) find} or
- * {@link #findAll() findAll} methods throw {@link FindException} if a
- * directory containing more than one module with the same name is
- * encountered.
- *
- *
If an element in the array is a path to a directory, and that
- * directory contains a file named {@code module-info.class}, then the
+ * exploded module. It it an error if a directory contains more than one
+ * module with the same name. If an element is a path to a directory, and
+ * that directory contains a file named {@code module-info.class}, then the
* directory is treated as an exploded module rather than a directory of
* modules.
*
@@ -214,9 +213,8 @@ public interface ModuleFinder {
* 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 an {@link ModuleDescriptor#isAutomatic automatic}
- * module. The {@link ModuleDescriptor} for an automatic module is created as
- * follows:
+ * top-level directory is created as an automatic module. The components
+ * for the automatic module are derived as follows:
*
*
It {@link ModuleDescriptor#requires() requires} {@code
- * java.base}.
- *
- *
The set of packages in the module is derived from the names
- * of non-directory entries in the JAR file. A candidate package name
- * is derived from an entry using the characters up to, but not
- * including, the last forward slash. All remaining forward slashes are
- * replaced with dot ({@code "."}). If the resulting string is a valid
- * Java identifier then it is assumed to be a package name. For example,
- * if the JAR file contains an entry "{@code p/q/Foo.class}" then the
- * package name derived is "{@code p.q}". All packages are {@link
- * ModuleDescriptor#exports() exported}.
+ *
The set of packages in the module is derived from the
+ * non-directory entries in the JAR file that have names ending in
+ * "{@code .class}". A candidate package name is derived from the name
+ * using the characters up to, but not including, the last forward slash.
+ * All remaining forward slashes are replaced with dot ({@code "."}). If
+ * the resulting string is a legal package name then it is assumed to be
+ * a package name. For example, if the JAR file contains the entry
+ * "{@code p/q/Foo.class}" then the package name derived is
+ * "{@code p.q}".
*
*
The contents of entries starting with {@code
* META-INF/services/} are assumed to be service configuration files
* (see {@link java.util.ServiceLoader}). If the name of a file
- * (that follows {@code META-INF/services/}) is a legal Java identifier
- * then it is assumed to be the fully-qualified binary name of a
- * service type. The entries in the file are assumed to be the
- * fully-qualified binary names of provider classes.
+ * (that follows {@code META-INF/services/}) is a legal class name
+ * then it is assumed to be the fully-qualified class name of a service
+ * type. The entries in the file are assumed to be the fully-qualified
+ * class names of provider classes.
*
*
If the JAR file has a {@code Main-Class} attribute in its
- * main manifest then its value is the {@link
+ * main manifest then its value is the module {@link
* ModuleDescriptor#mainClass() main class}.
*
*
*
*
If a {@code ModuleDescriptor} cannot be created (by means of the
* {@link ModuleDescriptor.Builder ModuleDescriptor.Builder} API) for an
- * automatic module then {@code FindException} is thrown. This can arise,
- * for example, when a legal Java identifier name cannot be derived from
- * the file name of the JAR file or where the JAR file contains a {@code
- * .class} in the top-level directory of the JAR file.
+ * automatic module then {@code FindException} is thrown. This can arise
+ * when a legal module name cannot be derived from the file name of the JAR
+ * file, where the JAR file contains a {@code .class} in the top-level
+ * directory of the JAR file, where an entry in a service configuration
+ * file is not a legal class name or its package name is not in the set of
+ * packages derived for the module, or where the module main class is not
+ * a legal class name or its package is not in the module.
*
*
In addition to JAR files, an implementation may also support modules
- * that are packaged in other implementation specific module formats. When
- * a file is encountered that is not recognized as a packaged module then
- * {@code FindException} is thrown. An implementation may choose to ignore
- * some files, {@link java.nio.file.Files#isHidden hidden} files for
- * example. Paths to files that do not exist are always ignored.
+ * that are packaged in other implementation specific module formats. If
+ * an element in the array specified to this method is a path to a directory
+ * of modules then entries in the directory that not recognized as modules
+ * are ignored. If an element in the array is a path to a packaged module
+ * that is not recognized then a {@code FindException} is thrown when the
+ * file is encountered. Paths to files that do not exist are always ignored.
+ *
*
*
As with automatic modules, the contents of a packaged or exploded
* module may need to be scanned in order to determine the packages
@@ -325,7 +325,7 @@ public interface ModuleFinder {
};
}
- return new ModulePath(entries);
+ return ModulePath.of(entries);
}
/**
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleReader.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleReader.java
index d79d210edd0..c5a7b61c695 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleReader.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleReader.java
@@ -45,7 +45,7 @@ import java.util.stream.Stream;
* module. A module reader is also intended to be used by {@code ClassLoader}
* implementations that load classes and resources from modules.
*
- *
A resource in a module is identified by a name that is a
+ *
A resource in a module is identified by an abstract name that is a
* '{@code /}'-separated path string. For example, module {@code java.base} may
* have a resource "{@code java/lang/Object.class}" that, by convention, is the
* class file for {@code java.lang.Object}.
@@ -61,8 +61,18 @@ import java.util.stream.Stream;
* open}, {@link #read read}, and {@link #list list} methods may throw {@code
* SecurityException} if access is denied by the security manager.
*
+ * @implSpec Implementations of {@code ModuleReader} should take great care
+ * when translating an abstract resource name to the location of a resource in
+ * a packaged module or on the file system. Implementations are advised to
+ * treat resource names with elements such as '{@code .}, '{@code ..}',
+ * elements containing file separators, or empty elements as "not found". More
+ * generally, if the resource name is not in the stream of elements that the
+ * {@code list} method returns then the resource should be treated as "not
+ * found" to avoid inconsistencies.
+ *
* @see ModuleReference
* @since 9
+ * @spec JPMS
*/
public interface ModuleReader extends Closeable {
@@ -148,6 +158,9 @@ public interface ModuleReader extends Closeable {
* If an I/O error occurs or the module reader is closed
* @throws SecurityException
* If denied by the security manager
+ * @throws OutOfMemoryError
+ * If the resource is larger than {@code Integer.MAX_VALUE},
+ * the maximum capacity of a byte buffer
*
* @see ClassLoader#defineClass(String, ByteBuffer, java.security.ProtectionDomain)
*/
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleReference.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleReference.java
index 09a5acec219..54291e78dcc 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleReference.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleReference.java
@@ -44,6 +44,7 @@ import java.util.Optional;
* @see ModuleFinder
* @see ModuleReader
* @since 9
+ * @spec JPMS
*/
public abstract class ModuleReference {
@@ -76,7 +77,7 @@ public abstract class ModuleReference {
/**
* Returns the location of this module's content, if known.
*
- *
This URI, when present, is used as the {@linkplain
+ *
This URI, when present, can be used as the {@linkplain
* java.security.CodeSource#getLocation location} value of a {@link
* java.security.CodeSource CodeSource} so that a module's classes can be
* granted specific permissions when loaded by a {@link
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ResolutionException.java b/jdk/src/java.base/share/classes/java/lang/module/ResolutionException.java
index fb14cfe8200..69cc71f3466 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ResolutionException.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ResolutionException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -26,10 +26,12 @@
package java.lang.module;
/**
- * Thrown when resolving a set of modules or binding fails.
+ * Thrown when resolving a set of modules, or resolving a set of modules with
+ * service binding, fails.
*
* @see Configuration
* @since 9
+ * @spec JPMS
*/
public class ResolutionException extends RuntimeException {
private static final long serialVersionUID = -1031186845316729450L;
diff --git a/jdk/src/java.base/share/classes/java/lang/module/ResolvedModule.java b/jdk/src/java.base/share/classes/java/lang/module/ResolvedModule.java
index 05ef3c4dc1c..a3858ef6c13 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/ResolvedModule.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/ResolvedModule.java
@@ -37,6 +37,7 @@ import java.util.Set;
* module's content.
*
* @since 9
+ * @spec JPMS
* @see Configuration#modules()
*/
public final class ResolvedModule {
diff --git a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
index d2aafdc5d87..1a44475b442 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2016, 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
@@ -49,8 +49,8 @@ import jdk.internal.module.ModuleHashes;
import jdk.internal.module.ModuleReferenceImpl;
/**
- * The resolver used by {@link Configuration#resolveRequires} and
- * {@link Configuration#resolveRequiresAndUses}.
+ * The resolver used by {@link Configuration#resolve} and {@link
+ * Configuration#resolveAndBind}.
*
* @implNote The resolver is used at VM startup and so deliberately avoids
* using lambda and stream usages in code paths used during startup.
@@ -66,7 +66,19 @@ final class Resolver {
// maps module name to module reference
private final Map nameToReference = new HashMap<>();
+ // module constraints on target platform
+ private String osName;
+ private String osArch;
+ private String osVersion;
+ String osName() { return osName; }
+ String osArch() { return osArch; }
+ String osVersion() { return osVersion; }
+
+ /**
+ * @throws IllegalArgumentException if there are more than one parent and
+ * the constraints on the target platform conflict
+ */
Resolver(ModuleFinder beforeFinder,
List parents,
ModuleFinder afterFinder,
@@ -75,15 +87,54 @@ final class Resolver {
this.parents = parents;
this.afterFinder = afterFinder;
this.traceOutput = traceOutput;
+
+ // record constraints on target platform, checking that they don't conflict
+ for (Configuration parent : parents) {
+ String value = parent.osName();
+ if (value != null) {
+ if (osName == null) {
+ osName = value;
+ } else {
+ if (!value.equals(osName)) {
+ failParentConflict("Operating System", osName, value);
+ }
+ }
+ }
+ value = parent.osArch();
+ if (value != null) {
+ if (osArch == null) {
+ osArch = value;
+ } else {
+ if (!value.equals(osArch)) {
+ failParentConflict("OS architecture", osArch, value);
+ }
+ }
+ }
+ value = parent.osVersion();
+ if (value != null) {
+ if (osVersion == null) {
+ osVersion = value;
+ } else {
+ if (!value.equals(osVersion)) {
+ failParentConflict("OS version", osVersion, value);
+ }
+ }
+ }
+ }
}
+ private void failParentConflict(String constraint, String s1, String s2) {
+ String msg = "Parents have conflicting constraints on target "
+ + constraint + ": " + s1 + ", " + s2;
+ throw new IllegalArgumentException(msg);
+ }
/**
* Resolves the given named modules.
*
* @throws ResolutionException
*/
- Resolver resolveRequires(Collection roots) {
+ Resolver resolve(Collection roots) {
// create the visit stack to get us started
Deque q = new ArrayDeque<>();
@@ -100,7 +151,7 @@ final class Resolver {
mref = findWithAfterFinder(root);
if (mref == null) {
- fail("Module %s not found", root);
+ findFail("Module %s not found", root);
}
}
@@ -109,8 +160,7 @@ final class Resolver {
mref.location().ifPresent(uri -> trace(" (%s)", uri));
}
- assert mref.descriptor().name().equals(root);
- nameToReference.put(root, mref);
+ addFoundModule(mref);
q.push(mref.descriptor());
}
@@ -152,19 +202,19 @@ final class Resolver {
mref = findWithAfterFinder(dn);
if (mref == null) {
- fail("Module %s not found, required by %s",
- dn, descriptor.name());
+ findFail("Module %s not found, required by %s",
+ dn, descriptor.name());
}
}
if (!nameToReference.containsKey(dn)) {
- nameToReference.put(dn, mref);
+ addFoundModule(mref);
q.offer(mref.descriptor());
resolved.add(mref.descriptor());
if (isTracing()) {
trace("Module %s located, required by %s",
- dn, descriptor.name());
+ dn, descriptor.name());
mref.location().ifPresent(uri -> trace(" (%s)", uri));
}
}
@@ -181,7 +231,7 @@ final class Resolver {
* Augments the set of resolved modules with modules induced by the
* service-use relation.
*/
- Resolver resolveUses() {
+ Resolver bind() {
// Scan the finders for all available service provider modules. As
// java.base uses services then then module finders will be scanned
@@ -246,7 +296,7 @@ final class Resolver {
mref.location()
.ifPresent(uri -> trace(" (%s)", uri));
}
- nameToReference.put(pn, mref);
+ addFoundModule(mref);
q.push(provider);
}
}
@@ -263,6 +313,81 @@ final class Resolver {
}
+ /**
+ * Add the module to the nameToReference map. Also check any constraints on
+ * the target platform with the constraints of other modules.
+ */
+ private void addFoundModule(ModuleReference mref) {
+ ModuleDescriptor descriptor = mref.descriptor();
+ nameToReference.put(descriptor.name(), mref);
+
+ if (descriptor.osName().isPresent()
+ || descriptor.osArch().isPresent()
+ || descriptor.osVersion().isPresent())
+ checkTargetConstraints(descriptor);
+ }
+
+ /**
+ * Check that the module's constraints on the target platform do not
+ * conflict with the constraints of other modules resolved so far or
+ * modules in parent configurations.
+ */
+ private void checkTargetConstraints(ModuleDescriptor descriptor) {
+ String value = descriptor.osName().orElse(null);
+ if (value != null) {
+ if (osName == null) {
+ osName = value;
+ } else {
+ if (!value.equals(osName)) {
+ failTargetConstraint(descriptor);
+ }
+ }
+ }
+ value = descriptor.osArch().orElse(null);
+ if (value != null) {
+ if (osArch == null) {
+ osArch = value;
+ } else {
+ if (!value.equals(osArch)) {
+ failTargetConstraint(descriptor);
+ }
+ }
+ }
+ value = descriptor.osVersion().orElse(null);
+ if (value != null) {
+ if (osVersion == null) {
+ osVersion = value;
+ } else {
+ if (!value.equals(osVersion)) {
+ failTargetConstraint(descriptor);
+ }
+ }
+ }
+ }
+
+ private void failTargetConstraint(ModuleDescriptor md) {
+ String s1 = targetAsString(osName, osArch, osVersion);
+ String s2 = targetAsString(md);
+ findFail("Module %s has constraints on target platform that conflict" +
+ " with other modules: %s, %s", md.name(), s1, s2);
+ }
+
+ private String targetAsString(ModuleDescriptor descriptor) {
+ String osName = descriptor.osName().orElse(null);
+ String osArch = descriptor.osArch().orElse(null);
+ String osVersion = descriptor.osVersion().orElse(null);
+ return targetAsString(osName, osArch, osVersion);
+ }
+
+ private String targetAsString(String osName, String osArch, String osVersion) {
+ return new StringJoiner("-")
+ .add(Objects.toString(osName, "*"))
+ .add(Objects.toString(osArch, "*"))
+ .add(Objects.toString(osVersion, "*"))
+ .toString();
+ }
+
+
/**
* Execute post-resolution checks and returns the module graph of resolved
* modules as {@code Map}. The resolved modules will be in the given
@@ -281,7 +406,6 @@ final class Resolver {
if (check) {
detectCycles();
- checkPlatformConstraints();
checkHashes();
}
@@ -319,8 +443,7 @@ final class Resolver {
if (!visited.contains(descriptor)) {
boolean added = visitPath.add(descriptor);
if (!added) {
- throw new ResolutionException("Cycle detected: " +
- cycleAsString(descriptor));
+ resolveFail("Cycle detected: %s", cycleAsString(descriptor));
}
for (ModuleDescriptor.Requires requires : descriptor.requires()) {
String dn = requires.name();
@@ -353,86 +476,6 @@ final class Resolver {
}
- /**
- * If there are platform specific modules then check that the OS name,
- * architecture and version match.
- *
- * @apiNote This method does not currently check if the OS matches
- * platform specific modules in parent configurations.
- */
- private void checkPlatformConstraints() {
-
- // first module encountered that is platform specific
- String savedModuleName = null;
- String savedOsName = null;
- String savedOsArch = null;
- String savedOsVersion = null;
-
- for (ModuleReference mref : nameToReference.values()) {
- ModuleDescriptor descriptor = mref.descriptor();
-
- String osName = descriptor.osName().orElse(null);
- String osArch = descriptor.osArch().orElse(null);
- String osVersion = descriptor.osVersion().orElse(null);
-
- if (osName != null || osArch != null || osVersion != null) {
-
- if (savedModuleName == null) {
-
- savedModuleName = descriptor.name();
- savedOsName = osName;
- savedOsArch = osArch;
- savedOsVersion = osVersion;
-
- } else {
-
- boolean matches = platformMatches(osName, savedOsName)
- && platformMatches(osArch, savedOsArch)
- && platformMatches(osVersion, savedOsVersion);
-
- if (!matches) {
- String s1 = platformAsString(savedOsName,
- savedOsArch,
- savedOsVersion);
-
- String s2 = platformAsString(osName, osArch, osVersion);
- fail("Mismatching constraints on target platform: "
- + savedModuleName + ": " + s1
- + ", " + descriptor.name() + ": " + s2);
- }
-
- }
-
- }
- }
-
- }
-
- /**
- * Returns true if the s1 and s2 are equal or one of them is null.
- */
- private boolean platformMatches(String s1, String s2) {
- if (s1 == null || s2 == null)
- return true;
- else
- return Objects.equals(s1, s2);
- }
-
- /**
- * Return a string that encodes the OS name/arch/version.
- */
- private String platformAsString(String osName,
- String osArch,
- String osVersion) {
-
- return new StringJoiner("-")
- .add(Objects.toString(osName, "*"))
- .add(Objects.toString(osArch, "*"))
- .add(Objects.toString(osVersion, "*"))
- .toString();
-
- }
-
/**
* Checks the hashes in the module descriptor to ensure that they match
* any recorded hashes.
@@ -460,7 +503,7 @@ final class Resolver {
continue;
if (!(mref2 instanceof ModuleReferenceImpl)) {
- fail("Unable to compute the hash of module %s", dn);
+ findFail("Unable to compute the hash of module %s", dn);
}
// skip checking the hash if the module has been patched
@@ -469,11 +512,11 @@ final class Resolver {
byte[] recordedHash = hashes.hashFor(dn);
byte[] actualHash = other.computeHash(algorithm);
if (actualHash == null)
- fail("Unable to compute the hash of module %s", dn);
+ findFail("Unable to compute the hash of module %s", dn);
if (!Arrays.equals(recordedHash, actualHash)) {
- fail("Hash of %s (%s) differs to expected hash (%s)" +
- " recorded in %s", dn, toHexString(actualHash),
- toHexString(recordedHash), descriptor.name());
+ findFail("Hash of %s (%s) differs to expected hash (%s)" +
+ " recorded in %s", dn, toHexString(actualHash),
+ toHexString(recordedHash), descriptor.name());
}
}
}
@@ -694,37 +737,38 @@ final class Resolver {
for (ResolvedModule endpoint : reads) {
ModuleDescriptor descriptor2 = endpoint.descriptor();
- for (ModuleDescriptor.Exports export : descriptor2.exports()) {
+ if (descriptor2.isAutomatic()) {
+ // automatic modules read self and export all packages
+ if (descriptor2 != descriptor1){
+ for (String source : descriptor2.packages()) {
+ ModuleDescriptor supplier
+ = packageToExporter.putIfAbsent(source, descriptor2);
- if (export.isQualified()) {
- if (!export.targets().contains(descriptor1.name()))
- continue;
- }
-
- // source is exported to descriptor2
- String source = export.source();
- ModuleDescriptor other
- = packageToExporter.putIfAbsent(source, descriptor2);
-
- if (other != null && other != descriptor2) {
- // package might be local to descriptor1
- if (other == descriptor1) {
- fail("Module %s contains package %s"
- + ", module %s exports package %s to %s",
- descriptor1.name(),
- source,
- descriptor2.name(),
- source,
- descriptor1.name());
- } else {
- fail("Modules %s and %s export package %s to module %s",
- descriptor2.name(),
- other.name(),
- source,
- descriptor1.name());
+ // descriptor2 and 'supplier' export source to descriptor1
+ if (supplier != null) {
+ failTwoSuppliers(descriptor1, source, descriptor2, supplier);
+ }
}
}
+ } else {
+ for (ModuleDescriptor.Exports export : descriptor2.exports()) {
+ if (export.isQualified()) {
+ if (!export.targets().contains(descriptor1.name()))
+ continue;
+ }
+
+ // source is exported by descriptor2
+ String source = export.source();
+ ModuleDescriptor supplier
+ = packageToExporter.putIfAbsent(source, descriptor2);
+
+ // descriptor2 and 'supplier' export source to descriptor1
+ if (supplier != null) {
+ failTwoSuppliers(descriptor1, source, descriptor2, supplier);
+ }
+ }
+
}
}
@@ -735,8 +779,8 @@ final class Resolver {
for (String service : descriptor1.uses()) {
String pn = packageName(service);
if (!packageToExporter.containsKey(pn)) {
- fail("Module %s does not read a module that exports %s",
- descriptor1.name(), pn);
+ resolveFail("Module %s does not read a module that exports %s",
+ descriptor1.name(), pn);
}
}
@@ -744,15 +788,8 @@ final class Resolver {
for (ModuleDescriptor.Provides provides : descriptor1.provides()) {
String pn = packageName(provides.service());
if (!packageToExporter.containsKey(pn)) {
- fail("Module %s does not read a module that exports %s",
- descriptor1.name(), pn);
- }
-
- for (String provider : provides.providers()) {
- if (!packages.contains(packageName(provider))) {
- fail("Provider %s not in module %s",
- provider, descriptor1.name());
- }
+ resolveFail("Module %s does not read a module that exports %s",
+ descriptor1.name(), pn);
}
}
@@ -762,6 +799,42 @@ final class Resolver {
}
+ /**
+ * Fail because a module in the configuration exports the same package to
+ * a module that reads both. This includes the case where a module M
+ * containing a package p reads another module that exports p to at least
+ * module M.
+ */
+ private void failTwoSuppliers(ModuleDescriptor descriptor,
+ String source,
+ ModuleDescriptor supplier1,
+ ModuleDescriptor supplier2) {
+
+ if (supplier2 == descriptor) {
+ ModuleDescriptor tmp = supplier1;
+ supplier1 = supplier2;
+ supplier2 = tmp;
+ }
+
+ if (supplier1 == descriptor) {
+ resolveFail("Module %s contains package %s"
+ + ", module %s exports package %s to %s",
+ descriptor.name(),
+ source,
+ supplier2.name(),
+ source,
+ descriptor.name());
+ } else {
+ resolveFail("Modules %s and %s export package %s to module %s",
+ supplier1.name(),
+ supplier2.name(),
+ source,
+ descriptor.name());
+ }
+
+ }
+
+
/**
* Find a module of the given name in the parent configurations
*/
@@ -779,24 +852,16 @@ final class Resolver {
* Invokes the beforeFinder to find method to find the given module.
*/
private ModuleReference findWithBeforeFinder(String mn) {
- try {
- return beforeFinder.find(mn).orElse(null);
- } catch (FindException e) {
- // unwrap
- throw new ResolutionException(e.getMessage(), e.getCause());
- }
+
+ return beforeFinder.find(mn).orElse(null);
+
}
/**
* Invokes the afterFinder to find method to find the given module.
*/
private ModuleReference findWithAfterFinder(String mn) {
- try {
- return afterFinder.find(mn).orElse(null);
- } catch (FindException e) {
- // unwrap
- throw new ResolutionException(e.getMessage(), e.getCause());
- }
+ return afterFinder.find(mn).orElse(null);
}
/**
@@ -804,34 +869,27 @@ final class Resolver {
* and after ModuleFinders.
*/
private Set findAll() {
- try {
+ Set beforeModules = beforeFinder.findAll();
+ Set afterModules = afterFinder.findAll();
- Set beforeModules = beforeFinder.findAll();
- Set afterModules = afterFinder.findAll();
+ if (afterModules.isEmpty())
+ return beforeModules;
- if (afterModules.isEmpty())
- return beforeModules;
+ if (beforeModules.isEmpty()
+ && parents.size() == 1
+ && parents.get(0) == Configuration.empty())
+ return afterModules;
- if (beforeModules.isEmpty()
- && parents.size() == 1
- && parents.get(0) == Configuration.empty())
- return afterModules;
-
- Set result = new HashSet<>(beforeModules);
- for (ModuleReference mref : afterModules) {
- String name = mref.descriptor().name();
- if (!beforeFinder.find(name).isPresent()
- && findInParent(name) == null) {
- result.add(mref);
- }
+ Set result = new HashSet<>(beforeModules);
+ for (ModuleReference mref : afterModules) {
+ String name = mref.descriptor().name();
+ if (!beforeFinder.find(name).isPresent()
+ && findInParent(name) == null) {
+ result.add(mref);
}
-
- return result;
-
- } catch (FindException e) {
- // unwrap
- throw new ResolutionException(e.getMessage(), e.getCause());
}
+
+ return result;
}
/**
@@ -842,10 +900,18 @@ final class Resolver {
return (index == -1) ? "" : cn.substring(0, index);
}
+ /**
+ * Throw FindException with the given format string and arguments
+ */
+ private static void findFail(String fmt, Object ... args) {
+ String msg = String.format(fmt, args);
+ throw new FindException(msg);
+ }
+
/**
* Throw ResolutionException with the given format string and arguments
*/
- private static void fail(String fmt, Object ... args) {
+ private static void resolveFail(String fmt, Object ... args) {
String msg = String.format(fmt, args);
throw new ResolutionException(msg);
}
diff --git a/jdk/src/java.base/share/classes/java/lang/module/package-info.java b/jdk/src/java.base/share/classes/java/lang/module/package-info.java
index f641638cb2c..1d830079cab 100644
--- a/jdk/src/java.base/share/classes/java/lang/module/package-info.java
+++ b/jdk/src/java.base/share/classes/java/lang/module/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2016, 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
@@ -27,6 +27,112 @@
* Classes to support module descriptors and creating configurations of modules
* by means of resolution and service binding.
*
+ *
Resolution is the process of computing the transitive closure of a set
+ * of root modules over a set of observable modules by resolving the
+ * dependences expressed by {@link
+ * java.lang.module.ModuleDescriptor.Requires requires} clauses.
+ * The dependence graph is augmented with edges that take account of
+ * implicitly declared dependences ({@code requires transitive}) to create a
+ * readability graph. The result of resolution is a {@link
+ * java.lang.module.Configuration Configuration} that encapsulates the
+ * readability graph.
+ *
+ *
As an example, suppose we have the following observable modules:
If the module {@code m1} is resolved then the resulting configuration
+ * contains three modules ({@code m1}, {@code m2}, {@code m3}). The edges in
+ * its readability graph are:
Resolution is an additive process. When computing the transitive closure
+ * then the dependence relation may include dependences on modules in {@link
+ * java.lang.module.Configuration#parents() parent} configurations. The result
+ * is a relative configuration that is relative to one or more parent
+ * configurations and where the readability graph may have edges from modules
+ * in the configuration to modules in parent configurations.
+ *
+ *
As an example, suppose we have the following observable modules:
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
+ * configuration contains two modules ({@code m1}, {@code m2}). The edges in
+ * its readability graph are:
+ *
{@code
+ * m1 --> m2
+ * m1 --> java.xml
+ * }
+ * where module {@code java.xml} is in the parent configuration. For
+ * simplicity, this example omits the implicitly declared dependence on the
+ * {@code java.base} module.
+ *
+ *
Requires clauses that are "{@code requires static}" express an optional
+ * dependence (except at compile-time). If a module declares that it
+ * "{@code requires static M}" then resolution does not search the observable
+ * modules for "{@code M}". However, if "{@code M}" is resolved (because resolution
+ * resolves a module that requires "{@code M}" without the {@link
+ * java.lang.module.ModuleDescriptor.Requires.Modifier#STATIC static} modifier)
+ * then the readability graph will contain read edges for each module that
+ * "{@code requires static M}".
+ *
+ *
{@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).
Service binding is the process of augmenting a graph of resolved modules
+ * from the set of observable modules induced by the service-use dependence
+ * ({@code uses} and {@code provides} clauses). Any module that was not
+ * previously in the graph requires resolution to compute its transitive
+ * closure. Service binding is an iterative process in that adding a module
+ * that satisfies some service-use dependence may introduce new service-use
+ * dependences.
If the module {@code m1} is resolved then the resulting graph of modules
+ * has one module ({@code m1}). If the graph is augmented with modules induced
+ * by the service-use dependence relation then the configuration will contain
+ * four modules ({@code m1}, {@code m2}, {@code m3}, {@code m4}). The edges in
+ * its readability graph are:
The edges in the conceptual service-use graph are:
+ *
{@code
+ * m1 --> m2 (meaning m1 uses a service that is provided by m2)
+ * m1 --> m3
+ * }
+ *
+ *
General Exceptions
+ *
*
Unless otherwise noted, passing a {@code null} argument to a constructor
* or method of any class or interface in this package will cause a {@link
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally,
@@ -34,6 +140,7 @@
* will cause a {@code NullPointerException}, unless otherwise specified.
*
* @since 9
+ * @spec JPMS
*/
package java.lang.module;
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java b/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
index f585b476504..503ce8dfb1e 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -28,38 +28,44 @@ package java.lang.reflect;
import java.lang.annotation.Annotation;
import java.security.AccessController;
-import jdk.internal.misc.VM;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.reflect.ReflectionFactory;
-import sun.security.action.GetPropertyAction;
/**
- * The AccessibleObject class is the base class for Field, Method and
- * Constructor objects. It provides the ability to flag a reflected
- * object as suppressing default Java language access control checks
- * when it is used. The access checks -- module boundaries,
- * public, default (package) access, protected, and private members --
- * are performed when Fields, Methods or Constructors are used to set
- * or get fields, to invoke methods or to create and initialize new
- * instances of classes, respectively. Unlike access control specified
- * in the The Java™ Language Specification and
- * The Java Virtual Machine Specification, access checks
- * with reflected objects assume {@link Module#canRead readability}.
+ * The {@code AccessibleObject} class is the base class for {@code Field},
+ * {@code Method}, and {@code Constructor} objects (known as reflected
+ * objects). It provides the ability to flag a reflected object as
+ * suppressing checks for Java language access control when it is used. This
+ * permits sophisticated applications with sufficient privilege, such as Java
+ * Object Serialization or other persistence mechanisms, to manipulate objects
+ * in a manner that would normally be prohibited.
*
- *
Setting the {@code accessible} flag in a reflected object
- * permits sophisticated applications with sufficient privilege, such
- * as Java Object Serialization or other persistence mechanisms, to
- * manipulate objects in a manner that would normally be prohibited.
+ *
Java language access control prevents use of private members outside
+ * their class; package access members outside their package; protected members
+ * outside their package or subclasses; and public members outside their
+ * module unless they are declared in an {@link Module#isExported(String,Module)
+ * exported} package and the user {@link Module#canRead reads} their module. By
+ * default, Java language access control is enforced (with one variation) when
+ * {@code Field}s, {@code Method}s, or {@code Constructor}s are used to get or
+ * set fields, to invoke methods, or to create and initialize new instances of
+ * classes, respectively. Every reflected object checks that the code using it
+ * is in an appropriate class, package, or module.
*
- *
By default, a reflected object is not accessible.
+ *
The one variation from Java language access control is that the checks
+ * by reflected objects assume readability. That is, the module containing
+ * the use of a reflected object is assumed to read the module in which
+ * the underlying field, method, or constructor is declared.
Whether the checks for Java language access control can be suppressed
+ * (and thus, whether access can be enabled) depends on whether the reflected
+ * object corresponds to a member in an exported or open package
+ * (see {@link #setAccessible(boolean)}).
*
+ * @jls 6.6 Access Control
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
public class AccessibleObject implements AnnotatedElement {
@@ -78,15 +84,11 @@ public class AccessibleObject implements AnnotatedElement {
/**
* Convenience method to set the {@code accessible} flag for an
- * array of objects with a single security check (for efficiency).
+ * array of reflected objects with a single security check (for efficiency).
*
- *
This method cannot be used to enable access to an object that is a
- * {@link Member member} of a class in a different module to the caller and
- * where the class is in a package that is not exported to the caller's
- * module. Additionally, if the member is non-public or its declaring
- * class is non-public, then this method can only be used to enable access
- * if the package is {@link Module#isOpen(String,Module) open} to at least
- * the caller's module.
+ *
This method may be used to enable access to all reflected objects in
+ * the array when access to each reflected object can be enabled as
+ * specified by {@link #setAccessible(boolean) setAccessible(boolean)}.
*
*
If there is a security manager, its
* {@code checkPermission} method is first called with a
@@ -99,10 +101,15 @@ public class AccessibleObject implements AnnotatedElement {
* @param array the array of AccessibleObjects
* @param flag the new value for the {@code accessible} flag
* in each object
- * @throws InaccessibleObjectException if access cannot be enabled
- * @throws SecurityException if the request is denied.
+ * @throws InaccessibleObjectException if access cannot be enabled for all
+ * objects in the array
+ * @throws SecurityException if the request is denied by the security manager
+ * or an element in the array is a constructor for {@code
+ * java.lang.Class}
* @see SecurityManager#checkPermission
* @see ReflectPermission
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static void setAccessible(AccessibleObject[] array, boolean flag) {
@@ -120,41 +127,143 @@ public class AccessibleObject implements AnnotatedElement {
}
/**
- * Set the {@code accessible} flag for this object to
+ * Set the {@code accessible} flag for this reflected object to
* the indicated boolean value. A value of {@code true} indicates that
- * the reflected object should suppress Java language access
- * checking when it is used. A value of {@code false} indicates
- * that the reflected object should enforce Java language access checks
- * while assuming readability (as noted in the class description).
+ * the reflected object should suppress checks for Java language access
+ * control when it is used. A value of {@code false} indicates that
+ * the reflected object should enforce checks for Java language access
+ * control when it is used, with the variation noted in the class description.
*
- *
This method cannot be used to enable access to an object that is a
- * {@link Member member} of a class in a different module to the caller and
- * where the class is in a package that is not exported to the caller's
- * module. Additionally, if the member is non-public or its declaring
- * class is non-public, then this method can only be used to enable access
- * if the package is {@link Module#isOpen(String,Module) open} to at least
- * the caller's module.
+ *
This method may be used by a caller in class {@code C} to enable
+ * access to a {@link Member member} of {@link Member#getDeclaringClass()
+ * declaring class} {@code D} if any of the following hold:
*
- *
If there is a security manager, its
+ *
+ *
{@code C} and {@code D} are in the same module.
+ *
+ *
The member is {@code public} and {@code D} is {@code public} in
+ * a package that the module containing {@code D} {@link
+ * Module#isExported(String,Module) exports} to at least the module
+ * containing {@code C}.
+ *
+ *
The member is {@code protected} {@code static}, {@code D} is
+ * {@code public} in a package that the module containing {@code D}
+ * exports to at least the module containing {@code C}, and {@code C}
+ * is a subclass of {@code D}.
+ *
+ *
{@code D} is in a package that the module containing {@code D}
+ * {@link Module#isOpen(String,Module) opens} to at least the module
+ * containing {@code C}.
+ * All packages in unnamed and open modules are open to all modules and
+ * so this method always succeeds when {@code D} is in an unnamed or
+ * open module.
+ *
+ *
+ *
This method cannot be used to enable access to private members,
+ * members with default (package) access, protected instance members, or
+ * protected constructors when the declaring class is in a different module
+ * to the caller and the package containing the declaring class is not open
+ * to the caller's module.
+ *
+ *
If there is a security manager, its
* {@code checkPermission} method is first called with a
* {@code ReflectPermission("suppressAccessChecks")} permission.
*
* @param flag the new value for the {@code accessible} flag
* @throws InaccessibleObjectException if access cannot be enabled
- * @throws SecurityException if the request is denied
- * @see SecurityManager#checkPermission
- * @see ReflectPermission
+ * @throws SecurityException if the request is denied by the security manager
+ * @see #trySetAccessible
* @see java.lang.invoke.MethodHandles#privateLookupIn
+ * @revised 9
+ * @spec JPMS
*/
public void setAccessible(boolean flag) {
AccessibleObject.checkPermission();
setAccessible0(flag);
}
- void setAccessible0(boolean flag) {
+ /**
+ * Sets the accessible flag and returns the new value
+ */
+ boolean setAccessible0(boolean flag) {
this.override = flag;
+ return flag;
}
+ /**
+ * Set the {@code accessible} flag for this reflected object to {@code true}
+ * if possible. This method sets the {@code accessible} flag, as if by
+ * invoking {@link #setAccessible(boolean) setAccessible(true)}, and returns
+ * the possibly-updated value for the {@code accessible} flag. If access
+ * cannot be enabled, i.e. the checks or Java language access control cannot
+ * be suppressed, this method returns {@code false} (as opposed to {@code
+ * setAccessible(true)} throwing {@code InaccessibleObjectException} when
+ * it fails).
+ *
+ *
This method is a no-op if the {@code accessible} flag for
+ * this reflected object is {@code true}.
+ *
+ *
For example, a caller can invoke {@code trySetAccessible}
+ * on a {@code Method} object for a private instance method
+ * {@code p.T::privateMethod} to suppress the checks for Java language access
+ * control when the {@code Method} is invoked.
+ * If {@code p.T} class is in a different module to the caller and
+ * package {@code p} is open to at least the caller's module,
+ * the code below successfully sets the {@code accessible} flag
+ * to {@code true}.
+ *
+ *
+ * {@code
+ * p.T obj = ....; // instance of p.T
+ * :
+ * Method m = p.T.class.getDeclaredMethod("privateMethod");
+ * if (m.trySetAccessible()) {
+ * m.invoke(obj);
+ * } else {
+ * // package p is not opened to the caller to access private member of T
+ * ...
+ * }
+ * }
+ *
+ *
If there is a security manager, its {@code checkPermission} method
+ * is first called with a {@code ReflectPermission("suppressAccessChecks")}
+ * permission.
+ *
+ * @return {@code true} if the {@code accessible} flag is set to {@code true};
+ * {@code false} if access cannot be enabled.
+ * @throws SecurityException if the request is denied by the security manager
+ *
+ * @since 9
+ * @spec JPMS
+ * @see java.lang.invoke.MethodHandles#privateLookupIn
+ */
+ @CallerSensitive
+ public final boolean trySetAccessible() {
+ AccessibleObject.checkPermission();
+
+ if (override == true) return true;
+
+ // if it's not a Constructor, Method, Field then no access check
+ if (!Member.class.isInstance(this)) {
+ return setAccessible0(true);
+ }
+
+ // does not allow to suppress access check for Class's constructor
+ Class> declaringClass = ((Member) this).getDeclaringClass();
+ if (declaringClass == Class.class && this instanceof Constructor) {
+ return false;
+ }
+
+ if (checkCanSetAccessible(Reflection.getCallerClass(),
+ declaringClass,
+ false)) {
+ return setAccessible0(true);
+ } else {
+ return false;
+ }
+ }
+
+
/**
* If the given AccessibleObject is a {@code Constructor}, {@code Method}
* or {@code Field} then checks that its declaring class is in a package
@@ -164,22 +273,29 @@ public class AccessibleObject implements AnnotatedElement {
// do nothing, needs to be overridden by Constructor, Method, Field
}
+
void checkCanSetAccessible(Class> caller, Class> declaringClass) {
+ checkCanSetAccessible(caller, declaringClass, true);
+ }
+
+ private boolean checkCanSetAccessible(Class> caller,
+ Class> declaringClass,
+ boolean throwExceptionIfDenied) {
Module callerModule = caller.getModule();
Module declaringModule = declaringClass.getModule();
- if (callerModule == declaringModule) return;
- if (callerModule == Object.class.getModule()) return;
- if (!declaringModule.isNamed()) return;
+ if (callerModule == declaringModule) return true;
+ if (callerModule == Object.class.getModule()) return true;
+ if (!declaringModule.isNamed()) return true;
// package is open to caller
String pn = packageName(declaringClass);
if (declaringModule.isOpen(pn, callerModule)) {
- printStackTraceIfOpenedReflectively(declaringModule, pn, callerModule);
- return;
+ dumpStackIfOpenedReflectively(declaringModule, pn, callerModule);
+ return true;
}
- // package is exported to caller and class/member is public
+ // package is exported to caller
boolean isExported = declaringModule.isExported(pn, callerModule);
boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers());
int modifiers;
@@ -188,48 +304,72 @@ public class AccessibleObject implements AnnotatedElement {
} else {
modifiers = ((Field) this).getModifiers();
}
- boolean isMemberPublic = Modifier.isPublic(modifiers);
- if (isExported && isClassPublic && isMemberPublic) {
- printStackTraceIfExportedReflectively(declaringModule, pn, callerModule);
- return;
+ if (isExported && isClassPublic) {
+
+ // member is public
+ if (Modifier.isPublic(modifiers)) {
+ dumpStackIfExportedReflectively(declaringModule, pn, callerModule);
+ return true;
+ }
+
+ // member is protected-static
+ if (Modifier.isProtected(modifiers)
+ && Modifier.isStatic(modifiers)
+ && isSubclassOf(caller, declaringClass)) {
+ dumpStackIfExportedReflectively(declaringModule, pn, callerModule);
+ return true;
+ }
}
- // not accessible
- String msg = "Unable to make ";
- if (this instanceof Field)
- msg += "field ";
- msg += this + " accessible: " + declaringModule + " does not \"";
- if (isClassPublic && isMemberPublic)
- msg += "exports";
- else
- msg += "opens";
- msg += " " + pn + "\" to " + callerModule;
- InaccessibleObjectException e = new InaccessibleObjectException(msg);
- if (Reflection.printStackTraceWhenAccessFails()) {
- e.printStackTrace(System.err);
+ if (throwExceptionIfDenied) {
+ // not accessible
+ String msg = "Unable to make ";
+ if (this instanceof Field)
+ msg += "field ";
+ msg += this + " accessible: " + declaringModule + " does not \"";
+ if (isClassPublic && Modifier.isPublic(modifiers))
+ msg += "exports";
+ else
+ msg += "opens";
+ msg += " " + pn + "\" to " + callerModule;
+ InaccessibleObjectException e = new InaccessibleObjectException(msg);
+ if (Reflection.printStackTraceWhenAccessFails()) {
+ e.printStackTrace(System.err);
+ }
+ throw e;
}
- throw e;
+ return false;
}
- private void printStackTraceIfOpenedReflectively(Module module,
- String pn,
- Module other) {
- printStackTraceIfExposedReflectively(module, pn, other, true);
+ private boolean isSubclassOf(Class> queryClass, Class> ofClass) {
+ while (queryClass != null) {
+ if (queryClass == ofClass) {
+ return true;
+ }
+ queryClass = queryClass.getSuperclass();
+ }
+ return false;
}
- private void printStackTraceIfExportedReflectively(Module module,
- String pn,
- Module other) {
- printStackTraceIfExposedReflectively(module, pn, other, false);
+ private void dumpStackIfOpenedReflectively(Module module,
+ String pn,
+ Module other) {
+ dumpStackIfExposedReflectively(module, pn, other, true);
}
- private void printStackTraceIfExposedReflectively(Module module,
- String pn,
- Module other,
- boolean open)
+ private void dumpStackIfExportedReflectively(Module module,
+ String pn,
+ Module other) {
+ dumpStackIfExposedReflectively(module, pn, other, false);
+ }
+
+ private void dumpStackIfExposedReflectively(Module module,
+ String pn,
+ Module other,
+ boolean open)
{
if (Reflection.printStackTraceWhenAccessSucceeds()
- && !module.isStaticallyExportedOrOpen(pn, other, open))
+ && !module.isStaticallyExportedOrOpen(pn, other, open))
{
String msg = other + " allowed to invoke setAccessible on ";
if (this instanceof Field)
@@ -256,14 +396,99 @@ public class AccessibleObject implements AnnotatedElement {
}
/**
- * Get the value of the {@code accessible} flag for this object.
+ * Get the value of the {@code accessible} flag for this reflected object.
*
* @return the value of the object's {@code accessible} flag
+ *
+ * @deprecated
+ * This method is deprecated because its name hints that it checks
+ * if the reflected object is accessible when it actually indicates
+ * if the checks for Java language access control are suppressed.
+ * This method may return {@code false} on a reflected object that is
+ * accessible to the caller. To test if this reflected object is accessible,
+ * it should use {@link #canAccess(Object)}.
+ *
+ * @revised 9
*/
+ @Deprecated(since="9")
public boolean isAccessible() {
return override;
}
+ /**
+ * Test if the caller can access this reflected object. If this reflected
+ * object corresponds to an instance method or field then this method tests
+ * if the caller can access the given {@code obj} with the reflected object.
+ * For instance methods or fields then the {@code obj} argument must be an
+ * instance of the {@link Member#getDeclaringClass() declaring class}. For
+ * static members and constructors then {@code obj} must be {@code null}.
+ *
+ *
This method returns {@code true} if the {@code accessible} flag
+ * is set to {@code true}, i.e. the checks for Java language access control
+ * are suppressed, or if the caller can access the member as
+ * specified in The Java™ Language Specification,
+ * with the variation noted in the class description.
+ *
+ * @param obj an instance object of the declaring class of this reflected
+ * object if it is an instance method or field
+ *
+ * @return {@code true} if the caller can access this reflected object.
+ *
+ * @throws IllegalArgumentException
+ *
+ *
if this reflected object is a static member or constructor and
+ * the given {@code obj} is non-{@code null}, or
+ *
if this reflected object is an instance method or field
+ * and the given {@code obj} is {@code null} or of type
+ * that is not a subclass of the {@link Member#getDeclaringClass()
+ * declaring class} of the member.
+ *
+ *
+ * @since 9
+ * @spec JPMS
+ * @jls 6.6 Access Control
+ * @see #trySetAccessible
+ * @see #setAccessible(boolean)
+ */
+ @CallerSensitive
+ public final boolean canAccess(Object obj) {
+ if (!Member.class.isInstance(this)) {
+ return override;
+ }
+
+ Class> declaringClass = ((Member) this).getDeclaringClass();
+ int modifiers = ((Member) this).getModifiers();
+ if (!Modifier.isStatic(modifiers) &&
+ (this instanceof Method || this instanceof Field)) {
+ if (obj == null) {
+ throw new IllegalArgumentException("null object for " + this);
+ }
+ // if this object is an instance member, the given object
+ // must be a subclass of the declaring class of this reflected object
+ if (!declaringClass.isAssignableFrom(obj.getClass())) {
+ throw new IllegalArgumentException("object is not an instance of "
+ + declaringClass.getName());
+ }
+ } else if (obj != null) {
+ throw new IllegalArgumentException("non-null object for " + this);
+ }
+
+ // access check is suppressed
+ if (override) return true;
+
+ Class> caller = Reflection.getCallerClass();
+ Class> targetClass;
+ if (this instanceof Constructor) {
+ targetClass = declaringClass;
+ } else {
+ targetClass = Modifier.isStatic(modifiers) ? null : obj.getClass();
+ }
+ return Reflection.verifyMemberAccess(caller,
+ declaringClass,
+ targetClass,
+ modifiers);
+ }
+
/**
* Constructor: only used by the Java Virtual Machine.
*/
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java b/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java
index f64e84f7f37..968e3f30af4 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java
@@ -168,6 +168,13 @@ public final class Constructor extends Executable {
* is true.
*
* @param flag {@inheritDoc}
+ *
+ * @throws InaccessibleObjectException {@inheritDoc}
+ * @throws SecurityException if the request is denied by the security manager
+ * or this is a constructor for {@code java.lang.Class}
+ *
+ * @since 9
+ * @spec JPMS
*/
@Override
@CallerSensitive
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Field.java b/jdk/src/java.base/share/classes/java/lang/reflect/Field.java
index 05b71785ffa..ef892714b03 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Field.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Field.java
@@ -158,6 +158,10 @@ class Field extends AccessibleObject implements Member {
return res;
}
+ /**
+ * @throws InaccessibleObjectException {@inheritDoc}
+ * @throws SecurityException {@inheritDoc}
+ */
@Override
@CallerSensitive
public void setAccessible(boolean flag) {
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/InaccessibleObjectException.java b/jdk/src/java.base/share/classes/java/lang/reflect/InaccessibleObjectException.java
index 34db5150f85..b03d449fecc 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/InaccessibleObjectException.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/InaccessibleObjectException.java
@@ -30,6 +30,7 @@ package java.lang.reflect;
*
* @see AccessibleObject#setAccessible(boolean)
* @since 9
+ * @spec JPMS
*/
public class InaccessibleObjectException extends RuntimeException {
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java b/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
index 9eaf90d0ca8..d6d89980aae 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
@@ -56,20 +56,19 @@ import sun.security.util.SecurityConstants;
/**
* A layer of modules in the Java virtual machine.
*
- *
A layer is created from a graph of modules that is the {@link
- * Configuration} and a function that maps each module to a {@link ClassLoader}.
+ *
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 modules so that the Java virtual machine knows which
- * module that each class is a member of. Each layer, except the {@link
- * #empty() empty} layer, has at least one {@link #parents() parent}.
+ * 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 parent layer. The {@code Module} {@link
- * Module#isExported(String) exports} the packages described by its {@link
- * ModuleDescriptor}.
+ * be in the same layer or a {@link #parents() parent} layer. The {@code Module}
+ * {@link Module#isExported(String) exports} and {@link Module#isOpen(String)
+ * opens} the packages described by its {@link ModuleDescriptor}.
*
*
The {@link #defineModulesWithOneLoader defineModulesWithOneLoader} and
* {@link #defineModulesWithManyLoaders defineModulesWithManyLoaders} methods
@@ -80,7 +79,7 @@ import sun.security.util.SecurityConstants;
* 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 a {@link Layer.Controller
+ * 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
@@ -93,9 +92,8 @@ import sun.security.util.SecurityConstants;
* the {@link #parents() parent} when creating additional layers.
*
*
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
+ * {@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.
*
@@ -115,8 +113,7 @@ import sun.security.util.SecurityConstants;
*
* Layer parent = Layer.boot();
*
- * Configuration cf = parent.configuration()
- * .resolveRequires(finder, ModuleFinder.of(), Set.of("myapp"));
+ * Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
*
* ClassLoader scl = ClassLoader.getSystemClassLoader();
*
@@ -126,6 +123,7 @@ import sun.security.util.SecurityConstants;
* }
*
* @since 9
+ * @spec JPMS
* @see Module#getLayer()
*/
@@ -168,10 +166,15 @@ public final class Layer {
* 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;
@@ -281,10 +284,8 @@ public final class Layer {
* If the parent of the given configuration is not the configuration
* for this layer
* @throws LayerInstantiationException
- * If all modules cannot be defined to the same class loader for any
- * of the reasons listed above or the layer cannot be created because
- * the configuration contains a module named "{@code java.base}" or
- * a module with a package name starting with "{@code java.}"
+ * 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
@@ -325,9 +326,8 @@ public final class Layer {
* If the parent of the given configuration is not the configuration
* for this layer
* @throws LayerInstantiationException
- * If the layer cannot be created because the configuration contains
- * a module named "{@code java.base}" or a module with a package
- * name starting with "{@code java.}"
+ * 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
@@ -365,14 +365,8 @@ public final class Layer {
* If the parent of the given configuration is not the configuration
* for this layer
* @throws LayerInstantiationException
- * If creating the {@code Layer} fails for any of the reasons
- * listed above, the layer cannot be created because the
- * configuration contains a module named "{@code java.base}",
- * a module with a package name starting with "{@code java.}" 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 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
@@ -396,7 +390,6 @@ public final class Layer {
* 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.
*
@@ -414,6 +407,10 @@ public final class Layer {
*
*
*
+ *
In addition, a layer cannot be created if the configuration contains
+ * a module named "{@code java.base}" or a module with a package 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.
@@ -433,9 +430,7 @@ public final class Layer {
* 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 or the layer cannot be created because
- * the configuration contains a module named "{@code java.base}" or
- * a module with a package name starting with "{@code java.}"
+ * of the reasons listed above
* @throws SecurityException
* If {@code RuntimePermission("createClassLoader")} or
* {@code RuntimePermission("getClassLoader")} is denied by
@@ -480,7 +475,6 @@ public final class Layer {
* 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.
*
@@ -533,15 +527,19 @@ public final class Layer {
/**
* Creates a new layer 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. The class loader delegation implemented by these class
- * loaders must respect module readability. The class loaders should be
+ * 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 are
+ * 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.
+ * classes or resources.
*
*
Creating a {@code Layer} can fail for the following reasons:
*
@@ -558,6 +556,13 @@ public final class Layer {
*
*
*
+ *
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 name starting with "{@code java.}" 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.
*
@@ -565,7 +570,7 @@ public final class Layer {
* @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 Java virtual machine.
+ * to the Java virtual machine.
*
* @param cf
* The configuration for the layer
@@ -580,14 +585,7 @@ public final class Layer {
* If the parent configurations do not match the configuration of
* the parent layers, including order
* @throws LayerInstantiationException
- * If creating the {@code Layer} fails for any of the reasons
- * listed above, the layer cannot be created because the
- * configuration contains a module named "{@code java.base}",
- * a module with a package name starting with "{@code java.}" 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 creating the layer fails for any of the reasons listed above
* @throws SecurityException
* If {@code RuntimePermission("getClassLoader")} is denied by
* the security manager
@@ -763,7 +761,7 @@ public final class Layer {
/**
* Returns the module with the given name in this layer, or if not in this
- * layer, the {@linkplain #parents parents} layers. Finding a module in
+ * 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
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java b/jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java
index ff61c41590f..fbd0de0ac85 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/LayerInstantiationException.java
@@ -31,6 +31,7 @@ package java.lang.reflect;
* @see Layer
*
* @since 9
+ * @spec JPMS
*/
public class LayerInstantiationException extends RuntimeException {
private static final long serialVersionUID = -906239691613568347L;
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Method.java b/jdk/src/java.base/share/classes/java/lang/reflect/Method.java
index 027a711d3e1..2208a5cbd81 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Method.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Method.java
@@ -179,6 +179,10 @@ public final class Method extends Executable {
return res;
}
+ /**
+ * @throws InaccessibleObjectException {@inheritDoc}
+ * @throws SecurityException {@inheritDoc}
+ */
@Override
@CallerSensitive
public void setAccessible(boolean flag) {
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Module.java b/jdk/src/java.base/share/classes/java/lang/reflect/Module.java
index 5134b64caf8..e70d9fbb872 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Module.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Module.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -39,7 +39,6 @@ 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.Map;
@@ -74,16 +73,15 @@ import sun.security.util.SecurityConstants;
* 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
- * per {@link ClassLoader ClassLoader} that is obtained by invoking the class
- * loader's {@link ClassLoader#getUnnamedModule() getUnnamedModule} method. The
- * {@link Class#getModule() getModule} method of all types defined by a class
- * loader that are not in a named module return the class loader's unnamed
+ *
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
+ * 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
@@ -91,6 +89,7 @@ import sun.security.util.SecurityConstants;
* be thrown.
*
* @since 9
+ * @spec JPMS
* @see java.lang.Class#getModule
*/
@@ -327,8 +326,9 @@ public final class Module implements AnnotatedElement {
*
* @return this module
*
- * @throws IllegalStateException
- * If this is a named module and the caller is not this module
+ * @throws IllegalCallerException
+ * If this is a named module and the caller's module is not this
+ * module
*
* @see #canRead
*/
@@ -338,7 +338,7 @@ public final class Module implements AnnotatedElement {
if (this.isNamed()) {
Module caller = Reflection.getCallerClass().getModule();
if (caller != this) {
- throw new IllegalStateException(caller + " != " + this);
+ throw new IllegalCallerException(caller + " != " + this);
}
implAddReads(other, true);
}
@@ -533,8 +533,8 @@ public final class Module implements AnnotatedElement {
if (other == this && containsPackage(pn))
return true;
- // all packages in open modules are open
- if (descriptor.isOpen())
+ // all packages in open and automatic modules are open
+ if (descriptor.isOpen() || descriptor.isAutomatic())
return containsPackage(pn);
// exported/opened via module declaration/descriptor
@@ -634,8 +634,7 @@ public final class Module implements AnnotatedElement {
* the given package to the given module.
*
*
This method has no effect if the package is already exported (or
- * open) to the given module. It also has no effect if
- * invoked on an {@link ModuleDescriptor#isOpen open} module.
+ * 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
@@ -653,8 +652,9 @@ public final class Module implements AnnotatedElement {
* @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 IllegalStateException
- * If this is a named module and the caller is not 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)
@@ -665,10 +665,10 @@ public final class Module implements AnnotatedElement {
throw new IllegalArgumentException("package is null");
Objects.requireNonNull(other);
- if (isNamed() && !descriptor.isOpen()) {
+ if (isNamed()) {
Module caller = Reflection.getCallerClass().getModule();
if (caller != this) {
- throw new IllegalStateException(caller + " != " + this);
+ throw new IllegalCallerException(caller + " != " + this);
}
implAddExportsOrOpens(pn, other, /*open*/false, /*syncVM*/true);
}
@@ -686,8 +686,7 @@ public final class Module implements AnnotatedElement {
* access control checks.
*
*
This method has no effect if the package is already open
- * to the given module. It also has no effect if invoked on an {@link
- * ModuleDescriptor#isOpen open} module.
+ * to the given module.
*
* @param pn
* The package name
@@ -699,9 +698,9 @@ public final class Module implements AnnotatedElement {
* @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 IllegalStateException
+ * @throws IllegalCallerException
* If this is a named module and this module has not opened the
- * package to at least the caller
+ * package to at least the caller's module
*
* @see #isOpen(String,Module)
* @see AccessibleObject#setAccessible(boolean)
@@ -713,10 +712,10 @@ public final class Module implements AnnotatedElement {
throw new IllegalArgumentException("package is null");
Objects.requireNonNull(other);
- if (isNamed() && !descriptor.isOpen()) {
+ if (isNamed()) {
Module caller = Reflection.getCallerClass().getModule();
if (caller != this && !isOpen(pn, caller))
- throw new IllegalStateException(pn + " is not open to " + caller);
+ throw new IllegalCallerException(pn + " is not open to " + caller);
implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true);
}
@@ -767,8 +766,8 @@ public final class Module implements AnnotatedElement {
Objects.requireNonNull(other);
Objects.requireNonNull(pn);
- // all packages are open in unnamed and open modules
- if (!isNamed() || descriptor.isOpen())
+ // 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
@@ -819,17 +818,17 @@ public final class Module implements AnnotatedElement {
* 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#resolveRequiresAndUses resolveRequiresAndUses} to be
- * re-run.
+ *
This method does not cause {@link Configuration#resolveAndBind
+ * resolveAndBind} to be re-run.
*
* @param service
* The service type
*
* @return this module
*
- * @throws IllegalStateException
- * If this is a named module and the caller is not 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()
@@ -841,7 +840,7 @@ public final class Module implements AnnotatedElement {
if (isNamed() && !descriptor.isAutomatic()) {
Module caller = Reflection.getCallerClass().getModule();
if (caller != this) {
- throw new IllegalStateException(caller + " != " + this);
+ throw new IllegalCallerException(caller + " != " + this);
}
implAddUses(service);
}
@@ -894,14 +893,13 @@ public final class Module implements AnnotatedElement {
// -- packages --
// Additional packages that are added to the module at run-time.
- // The field is volatile as it may be replaced at run-time
- private volatile Set extraPackages;
+ private volatile Map extraPackages;
private boolean containsPackage(String pn) {
if (descriptor.packages().contains(pn))
return true;
- Set extraPackages = this.extraPackages;
- if (extraPackages != null && extraPackages.contains(pn))
+ Map extraPackages = this.extraPackages;
+ if (extraPackages != null && extraPackages.containsKey(pn))
return true;
return false;
}
@@ -915,7 +913,7 @@ public final class Module implements AnnotatedElement {
* added to the module, dynamic modules
* for example, after it was loaded.
*
- *
For unnamed modules, this method is the equivalent of invoking the
+ *
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.
*
@@ -930,12 +928,12 @@ public final class Module implements AnnotatedElement {
if (isNamed()) {
Set packages = descriptor.packages();
- Set extraPackages = this.extraPackages;
+ Map extraPackages = this.extraPackages;
if (extraPackages == null) {
return packages.toArray(new String[0]);
} else {
return Stream.concat(packages.stream(),
- extraPackages.stream())
+ extraPackages.keySet().stream())
.toArray(String[]::new);
}
@@ -955,10 +953,6 @@ public final class Module implements AnnotatedElement {
* Add a package to this module.
*
* @apiNote This method is for Proxy use.
- *
- * @apiNote This is an expensive operation, not expected to be used often.
- * At this time then it does not validate that the package name is a
- * valid java identifier.
*/
void addPackage(String pn) {
implAddPackage(pn, true);
@@ -976,49 +970,52 @@ public final class Module implements AnnotatedElement {
/**
* Add a package to this module.
*
- * If {@code syncVM} is {@code true} then the VM is notified.
+ * 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())
- throw new InternalError("adding package to unnamed module?");
- if (descriptor.isOpen())
- throw new InternalError("adding package to open module?");
+ 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 InternalError("adding package to module?");
-
- if (descriptor.packages().contains(pn)) {
- // already in module
- return;
- }
-
- Set extraPackages = this.extraPackages;
- if (extraPackages != null && extraPackages.contains(pn)) {
- // already added
- return;
- }
- synchronized (this) {
- // recheck under lock
- extraPackages = this.extraPackages;
- if (extraPackages != null) {
- if (extraPackages.contains(pn)) {
- // already added
- return;
- }
-
- // copy the set
- extraPackages = new HashSet<>(extraPackages);
- extraPackages.add(pn);
- } else {
- extraPackages = Collections.singleton(pn);
+ 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);
}
@@ -1169,8 +1166,9 @@ public final class Module implements AnnotatedElement {
Map nameToModule,
Module m)
{
- // The VM doesn't know about open modules so need to export all packages
- if (descriptor.isOpen()) {
+ // The VM doesn't special case open or automatic modules so need to
+ // export all packages
+ if (descriptor.isOpen() || descriptor.isAutomatic()) {
assert descriptor.opens().isEmpty();
for (String source : descriptor.packages()) {
addExportsToAll0(m, source);
@@ -1375,35 +1373,44 @@ public final class Module implements AnnotatedElement {
/**
- * 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.
+ * 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 modules may be encapsulated so that
+ *
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:
+ * located or not is determined as follows:
*
*
- *
The package name of the resource is derived from the
- * subsequence of characters that precedes the last {@code '/'} and then
- * replacing each {@code '/'} character in the subsequence with
- * {@code '.'}. For example, the package name derived for a resource
- * named "{@code a/b/c/foo.properties}" is "{@code a.b.c}".
+ *
If the resource name ends with "{@code .class}" then it is not
+ * encapsulated.
*
- *
If the package name is a package in the module then the package
- * must be {@link #isOpen open} the module of the caller of this method.
- * If the package is not in the module then the resource is not
- * encapsulated. Resources in the unnamed package or "{@code META-INF}",
- * for example, are never encapsulated because they can never be
- * packages in a named module.
- *
- *
As a special case, resources ending with "{@code .class}" are
- * never 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.
+ * or access to the resource is denied by the security manager.
*
* @param name
* The resource name
@@ -1413,11 +1420,13 @@ public final class Module implements AnnotatedElement {
* @throws IOException
* If an I/O error occurs
*
- * @see java.lang.module.ModuleReader#open(String)
+ * @see Class#getResourceAsStream(String)
*/
@CallerSensitive
public InputStream getResourceAsStream(String name) throws IOException {
- Objects.requireNonNull(name);
+ if (name.startsWith("/")) {
+ name = name.substring(1);
+ }
if (isNamed() && !ResourceHelper.isSimpleResource(name)) {
Module caller = Reflection.getCallerClass().getModule();
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java
index 15d41a4101d..685aebff39a 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java
@@ -25,6 +25,7 @@
package java.lang.reflect;
+import java.lang.module.ModuleDescriptor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
@@ -52,6 +53,9 @@ import sun.reflect.misc.ReflectUtil;
import sun.security.action.GetPropertyAction;
import sun.security.util.SecurityConstants;
+import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC;
+
+
/**
*
* {@code Proxy} provides static methods for creating objects that act like instances
@@ -164,7 +168,8 @@ import sun.security.util.SecurityConstants;
* methods is specified as follows:
*
*
- *
If all the proxy interfaces are in exported packages:
+ *
If all the proxy interfaces are in exported or open
+ * packages:
*
*
if all the proxy interfaces are public, then the proxy class is
* public in a package exported by the
@@ -178,10 +183,11 @@ import sun.security.util.SecurityConstants;
* not possible.
*
*
- *
If at least one proxy interface is a non-exported package:
+ *
If at least one proxy interface is in a package that is
+ * non-exported and non-open:
*
*
if all the proxy interfaces are public, then the proxy class is
- * public in a non-exported package of
+ * public in a non-exported, non-open package of
* dynamic module.
* The names of the package and the module are unspecified.
- * Note that if proxy interfaces with a mix of accessibilities --
- * exported public, exported non-public, non-exported public, non-exported non-public --
- * are proxied by the same instance, then the proxy class's accessibility is
+ * Note that if proxy interfaces with a mix of accessibilities -- for example,
+ * an exported public interface and a non-exported non-public interface -- are
+ * proxied by the same instance, then the proxy class's accessibility is
* governed by the least accessible proxy interface.
*
* Note that it is possible for arbitrary code to obtain access to a proxy class
- * in an exported package with {@link AccessibleObject#setAccessible setAccessible},
- * whereas a proxy class in a non-exported package is never accessible to
+ * in an open package with {@link AccessibleObject#setAccessible setAccessible},
+ * whereas a proxy class in a non-open package is never accessible to
* code outside the module of the proxy class.
*
*
- * Throughout this specification, a "non-exported package" refers to a package that
- * is not exported to all modules. Specifically, it refers to a package that
- * either is not exported at all by its containing module or is exported in a
- * qualified fashion by its containing module.
+ * Throughout this specification, a "non-exported package" refers to a package
+ * that is not exported to all modules, and a "non-open package" refers to
+ * a package that is not open to all modules. Specifically, these terms refer to
+ * a package that either is not exported/open by its containing module or is
+ * exported/open in a qualified fashion by its containing module.
*
*
@@ -272,6 +279,8 @@ import sun.security.util.SecurityConstants;
* @author Peter Jones
* @see InvocationHandler
* @since 1.3
+ * @revised 9
+ * @spec JPMS
*/
public class Proxy implements java.io.Serializable {
private static final long serialVersionUID = -2222568056686623797L;
@@ -358,6 +367,8 @@ public class Proxy implements java.io.Serializable {
* to create a proxy instance instead.
*
* @see Package and Module Membership of Proxy Class
+ * @revised 9
+ * @spec JPMS
*/
@Deprecated
@CallerSensitive
@@ -855,7 +866,11 @@ public class Proxy implements java.io.Serializable {
// create a dynamic module and setup module access
String mn = "jdk.proxy" + counter.incrementAndGet();
String pn = PROXY_PACKAGE_PREFIX + "." + mn;
- Module m = Modules.defineModule(ld, mn, Collections.singleton(pn));
+ ModuleDescriptor descriptor =
+ ModuleDescriptor.newModule(mn, Set.of(SYNTHETIC))
+ .packages(Set.of(pn))
+ .build();
+ Module m = Modules.defineModule(ld, descriptor, null);
Modules.addReads(m, Proxy.class.getModule());
// java.base to create proxy instance
Modules.addExports(m, pn, Object.class.getModule());
@@ -955,6 +970,8 @@ public class Proxy implements java.io.Serializable {
* {@code null}
*
* @see Package and Module Membership of Proxy Class
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static Object newProxyInstance(ClassLoader loader,
@@ -1039,6 +1056,9 @@ public class Proxy implements java.io.Serializable {
* @return {@code true} if the class is a proxy class and
* {@code false} otherwise
* @throws NullPointerException if {@code cl} is {@code null}
+ *
+ * @revised 9
+ * @spec JPMS
*/
public static boolean isProxyClass(Class> cl) {
return Proxy.class.isAssignableFrom(cl) && ProxyBuilder.isProxyClass(cl);
diff --git a/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java b/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java
index c8cb0257b2a..97800b1ce13 100644
--- a/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/package-info.java
@@ -45,5 +45,7 @@
* members declared by a given class.
*
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
package java.lang.reflect;
diff --git a/jdk/src/java.base/share/classes/java/net/URL.java b/jdk/src/java.base/share/classes/java/net/URL.java
index b029b83d7ca..1ac1437ab96 100644
--- a/jdk/src/java.base/share/classes/java/net/URL.java
+++ b/jdk/src/java.base/share/classes/java/net/URL.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, 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
@@ -41,6 +41,8 @@ import java.util.NoSuchElementException;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
+import jdk.internal.misc.JavaNetURLAccess;
+import jdk.internal.misc.SharedSecrets;
import sun.security.util.SecurityConstants;
import sun.security.action.GetPropertyAction;
@@ -1614,6 +1616,17 @@ public final class URL implements java.io.Serializable {
private void setSerializedHashCode(int hc) {
this.hashCode = hc;
}
+
+ static {
+ SharedSecrets.setJavaNetURLAccess(
+ new JavaNetURLAccess() {
+ @Override
+ public URLStreamHandler getHandler(URL u) {
+ return u.handler;
+ }
+ }
+ );
+ }
}
final class UrlDeserializedState {
diff --git a/jdk/src/java.base/share/classes/java/net/URLClassLoader.java b/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
index 2e52fe2b4e9..d6bd9546750 100644
--- a/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/net/URLClassLoader.java
@@ -228,6 +228,7 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* allow creation of a class loader.
*
* @since 9
+ * @spec JPMS
*/
public URLClassLoader(String name,
URL[] urls,
@@ -262,6 +263,7 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* creation of a class loader.
*
* @since 9
+ * @spec JPMS
*/
public URLClassLoader(String name, URL[] urls, ClassLoader parent,
URLStreamHandlerFactory factory) {
@@ -558,6 +560,9 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* @throws IllegalArgumentException if the package name is
* already defined by this class loader
* @return the newly defined {@code Package} object
+ *
+ * @revised 9
+ * @spec JPMS
*/
protected Package definePackage(String name, Manifest man, URL url) {
String path = name.replace('.', '/').concat("/");
diff --git a/jdk/src/java.base/share/classes/java/nio/charset/Charset.java b/jdk/src/java.base/share/classes/java/nio/charset/Charset.java
index 81209891bb4..512045bb8b0 100644
--- a/jdk/src/java.base/share/classes/java/nio/charset/Charset.java
+++ b/jdk/src/java.base/share/classes/java/nio/charset/Charset.java
@@ -300,9 +300,8 @@ public abstract class Charset
*/
private static void checkName(String s) {
int n = s.length();
- if (!atBugLevel("1.4")) {
- if (n == 0)
- throw new IllegalCharsetNameException(s);
+ if (n == 0 && !atBugLevel("1.4")) {
+ throw new IllegalCharsetNameException(s);
}
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
@@ -319,7 +318,9 @@ public abstract class Charset
}
/* The standard set of charsets */
- private static CharsetProvider standardProvider = new StandardCharsets();
+ private static final CharsetProvider standardProvider = new StandardCharsets();
+
+ private static final String[] zeroAliases = new String[0];
// Cache of the most-recently-returned charsets,
// along with the names that were used to find them
@@ -626,7 +627,6 @@ public abstract class Charset
private final String name; // tickles a bug in oldjavac
private final String[] aliases; // tickles a bug in oldjavac
- private final String[] zeroAliases = new String[0];
private Set aliasSet = null;
/**
diff --git a/jdk/src/java.base/share/classes/java/security/DrbgParameters.java b/jdk/src/java.base/share/classes/java/security/DrbgParameters.java
index c71e1cffa28..b17cf07ace8 100644
--- a/jdk/src/java.base/share/classes/java/security/DrbgParameters.java
+++ b/jdk/src/java.base/share/classes/java/security/DrbgParameters.java
@@ -53,8 +53,8 @@ import java.util.Objects;
* for CTR_DRBG. Please note that it is not the algorithm used in
* {@link SecureRandom#getInstance}, which we will call a
* SecureRandom algorithm below),
- *
optionally features, including prediction resistance
- * and reseeding supports.
+ *
optional features, including prediction resistance
+ * and reseeding supports,
*
highest security strength.
*
*
diff --git a/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java b/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java
index ecb12785591..1a9ac151a70 100644
--- a/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java
+++ b/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -38,6 +38,7 @@ import jdk.internal.misc.JavaSecurityAccess;
import jdk.internal.misc.JavaSecurityProtectionDomainAccess;
import static jdk.internal.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
import jdk.internal.misc.SharedSecrets;
+import sun.security.action.GetPropertyAction;
import sun.security.provider.PolicyFile;
import sun.security.util.Debug;
import sun.security.util.FilePermCompat;
@@ -62,6 +63,14 @@ import sun.security.util.SecurityConstants;
public class ProtectionDomain {
+ /**
+ * If true, {@link #impliesWithAltFilePerm} will try to be compatible on
+ * FilePermission checking even if a 3rd-party Policy implementation is set.
+ */
+ private static final boolean filePermCompatInPD =
+ "true".equals(GetPropertyAction.privilegedGetProperty(
+ "jdk.security.filePermCompat"));
+
private static class JavaSecurityAccessImpl implements JavaSecurityAccess {
private JavaSecurityAccessImpl() {
@@ -321,19 +330,27 @@ public class ProtectionDomain {
}
/**
- * This method has the same logic flow as {@link #implies} except that
- * when the {@link FilePermCompat#compat} flag is on it ensures
- * FilePermission compatibility after JDK-8164705. {@code implies()}
- * is called when compat flag is not on or user has extended
- * {@code ProtectionDomain}.
+ * This method has almost the same logic flow as {@link #implies} but
+ * it ensures some level of FilePermission compatibility after JDK-8164705.
*
* This method is called by {@link AccessControlContext#checkPermission}
* and not intended to be called by an application.
*/
boolean impliesWithAltFilePerm(Permission perm) {
- // If this is a subclass of ProtectionDomain. Call the old method.
- if (!FilePermCompat.compat || getClass() != ProtectionDomain.class) {
+ // If FilePermCompat.compat is set (default value), FilePermission
+ // checking compatibility should be considered.
+
+ // If filePermCompatInPD is set, this method checks for alternative
+ // FilePermission to keep compatibility for any Policy implementation.
+ // When set to false (default value), implies() is called since
+ // the PolicyFile implementation already supports compatibility.
+
+ // If this is a subclass of ProtectionDomain, call implies()
+ // because most likely user has overridden it.
+
+ if (!filePermCompatInPD || !FilePermCompat.compat ||
+ getClass() != ProtectionDomain.class) {
return implies(perm);
}
diff --git a/jdk/src/java.base/share/classes/java/security/SecureClassLoader.java b/jdk/src/java.base/share/classes/java/security/SecureClassLoader.java
index 8f84e10324e..4f0bfa4c27f 100644
--- a/jdk/src/java.base/share/classes/java/security/SecureClassLoader.java
+++ b/jdk/src/java.base/share/classes/java/security/SecureClassLoader.java
@@ -125,6 +125,7 @@ public class SecureClassLoader extends ClassLoader {
* doesn't allow creation of a class loader.
*
* @since 9
+ * @spec JPMS
*/
protected SecureClassLoader(String name, ClassLoader parent) {
super(name, parent);
diff --git a/jdk/src/java.base/share/classes/java/security/SecureRandom.java b/jdk/src/java.base/share/classes/java/security/SecureRandom.java
index ac4ee6e7c7a..9154060bfcd 100644
--- a/jdk/src/java.base/share/classes/java/security/SecureRandom.java
+++ b/jdk/src/java.base/share/classes/java/security/SecureRandom.java
@@ -64,8 +64,8 @@ import sun.security.util.Debug;
*
The third statement above returns a {@code SecureRandom} object of the
diff --git a/jdk/src/java.base/share/classes/java/security/Security.java b/jdk/src/java.base/share/classes/java/security/Security.java
index 49b7e991b40..1076b1d7da7 100644
--- a/jdk/src/java.base/share/classes/java/security/Security.java
+++ b/jdk/src/java.base/share/classes/java/security/Security.java
@@ -25,11 +25,12 @@
package java.security;
-import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.io.*;
import java.net.URL;
+
+import jdk.internal.misc.SharedSecrets;
import sun.security.util.Debug;
import sun.security.util.PropertyExpander;
@@ -800,9 +801,6 @@ public final class Security {
* "package.definition", we need to signal to the SecurityManager
* class that the value has just changed, and that it should
* invalidate it's local cache values.
- *
- * Rather than create a new API entry for this function,
- * we use reflection to set a private variable.
*/
private static void invalidateSMCache(String key) {
@@ -810,42 +808,8 @@ public final class Security {
final boolean pd = key.equals("package.definition");
if (pa || pd) {
- AccessController.doPrivileged(new PrivilegedAction<>() {
- public Void run() {
- try {
- /* Get the class via the bootstrap class loader. */
- Class> cl = Class.forName(
- "java.lang.SecurityManager", false, null);
- Field f = null;
- boolean accessible = false;
-
- if (pa) {
- f = cl.getDeclaredField("packageAccessValid");
- accessible = f.isAccessible();
- f.setAccessible(true);
- } else {
- f = cl.getDeclaredField("packageDefinitionValid");
- accessible = f.isAccessible();
- f.setAccessible(true);
- }
- f.setBoolean(f, false);
- f.setAccessible(accessible);
- }
- catch (Exception e1) {
- /* If we couldn't get the class, it hasn't
- * been loaded yet. If there is no such
- * field, we shouldn't try to set it. There
- * shouldn't be a security execption, as we
- * are loaded by boot class loader, and we
- * are inside a doPrivileged() here.
- *
- * NOOP: don't do anything...
- */
- }
- return null;
- } /* run */
- }); /* PrivilegedAction */
- } /* if */
+ SharedSecrets.getJavaLangAccess().invalidatePackageAccessCache();
+ }
}
private static void check(String directive) {
diff --git a/jdk/src/java.base/share/classes/java/util/Objects.java b/jdk/src/java.base/share/classes/java/util/Objects.java
index dad583b9206..c6bf3c96133 100644
--- a/jdk/src/java.base/share/classes/java/util/Objects.java
+++ b/jdk/src/java.base/share/classes/java/util/Objects.java
@@ -343,7 +343,8 @@ public final class Objects {
*/
public static T requireNonNull(T obj, Supplier messageSupplier) {
if (obj == null)
- throw new NullPointerException(messageSupplier.get());
+ throw new NullPointerException(messageSupplier == null ?
+ null : messageSupplier.get());
return obj;
}
diff --git a/jdk/src/java.base/share/classes/java/util/ResourceBundle.java b/jdk/src/java.base/share/classes/java/util/ResourceBundle.java
index 600b1810a2e..b587da9b9e3 100644
--- a/jdk/src/java.base/share/classes/java/util/ResourceBundle.java
+++ b/jdk/src/java.base/share/classes/java/util/ResourceBundle.java
@@ -350,6 +350,8 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
* @see MissingResourceException
* @see ResourceBundleProvider
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
public abstract class ResourceBundle {
@@ -870,6 +872,8 @@ public abstract class ResourceBundle {
* @throws UnsupportedOperationException
* if this method is called in a named module
* @since 1.6
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static final ResourceBundle getBundle(String baseName,
@@ -938,6 +942,7 @@ public abstract class ResourceBundle {
* specified module
* @return a resource bundle for the given base name and the default locale
* @since 9
+ * @spec JPMS
* @see ResourceBundleProvider
*/
@CallerSensitive
@@ -991,6 +996,7 @@ public abstract class ResourceBundle {
* be found in the specified {@code module}
* @return a resource bundle for the given base name and locale in the module
* @since 9
+ * @spec JPMS
*/
@CallerSensitive
public static ResourceBundle getBundle(String baseName, Locale targetLocale, Module module) {
@@ -1036,6 +1042,8 @@ public abstract class ResourceBundle {
* @throws UnsupportedOperationException
* if this method is called in a named module
* @since 1.6
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static final ResourceBundle getBundle(String baseName, Locale targetLocale,
@@ -1243,6 +1251,8 @@ public abstract class ResourceBundle {
* @exception MissingResourceException
* if no resource bundle for the specified base name can be found
* @since 1.2
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ResourceBundle getBundle(String baseName, Locale locale,
@@ -1465,6 +1475,8 @@ public abstract class ResourceBundle {
* @throws UnsupportedOperationException
* if this method is called in a named module
* @since 1.6
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ResourceBundle getBundle(String baseName, Locale targetLocale,
@@ -2194,6 +2206,8 @@ public abstract class ResourceBundle {
* by the caller's module.
*
* @since 1.6
+ * @revised 9
+ * @spec JPMS
* @see ResourceBundle.Control#getTimeToLive(String,Locale)
*/
@CallerSensitive
@@ -2475,6 +2489,8 @@ public abstract class ResourceBundle {
* of {@link ResourceBundleControlProvider} are ignored in named modules.
*
* @since 1.6
+ * @revised 9
+ * @spec JPMS
* @see java.util.spi.ResourceBundleProvider
*/
public static class Control {
@@ -3103,6 +3119,8 @@ public abstract class ResourceBundle {
* if an error occurred when reading resources using
* any I/O operations
* @see java.util.spi.ResourceBundleProvider#getBundle(String, Locale)
+ * @revised 9
+ * @spec JPMS
*/
public ResourceBundle newBundle(String baseName, Locale locale, String format,
ClassLoader loader, boolean reload)
diff --git a/jdk/src/java.base/share/classes/java/util/ServiceLoader.java b/jdk/src/java.base/share/classes/java/util/ServiceLoader.java
index 0b437d44e2e..6ffb6177e39 100644
--- a/jdk/src/java.base/share/classes/java/util/ServiceLoader.java
+++ b/jdk/src/java.base/share/classes/java/util/ServiceLoader.java
@@ -119,7 +119,7 @@ import jdk.internal.reflect.Reflection;
* and deployed as an explicit module must have an appropriate uses
* clause in its module descriptor to declare that the module uses
* implementations of the service. A corresponding requirement is that a
- * provider deployed as a named module must have an appropriate
+ * provider deployed as an explicit module must have an appropriate
* provides clause in its module descriptor to declare that the module
* provides an implementation of the service. The uses and
* provides allow consumers of a service to be linked to modules
@@ -203,8 +203,11 @@ import jdk.internal.reflect.Reflection;
* ordering of modules in a layer, is not defined.
*
*
If a named module declares more than one provider then the providers
- * are located in the order that they appear in the {@code provides} table of
- * the {@code Module} class file attribute ({@code module-info.class}).
+ * are located in the iteration order of the {@link
+ * java.lang.module.ModuleDescriptor.Provides#providers() providers} list.
+ * Providers added dynamically by instrumentation agents ({@link
+ * java.lang.instrument.Instrumentation#redefineModule redefineModule})
+ * are always located after providers declared by the module.
*
*
When locating providers in unnamed modules then the ordering is
* based on the order that the class loader's {@link
@@ -335,6 +338,8 @@ import jdk.internal.reflect.Reflection;
*
* @author Mark Reinhold
* @since 1.6
+ * @revised 9
+ * @spec JPMS
*/
public final class ServiceLoader
@@ -386,6 +391,7 @@ public final class ServiceLoader
*
* @param The service type
* @since 9
+ * @spec JPMS
*/
public static interface Provider extends Supplier {
/**
@@ -927,26 +933,28 @@ public final class ServiceLoader
} else {
catalog = ServicesCatalog.getServicesCatalogOrNull(loader);
}
- Stream stream1;
+ List providers;
if (catalog == null) {
- stream1 = Stream.empty();
+ providers = List.of();
} else {
- stream1 = catalog.findServices(serviceName).stream();
+ providers = catalog.findServices(serviceName);
}
// modules in custom layers that define modules to the class loader
- Stream stream2;
if (loader == null) {
- stream2 = Stream.empty();
+ return providers.iterator();
} else {
+ List allProviders = new ArrayList<>(providers);
Layer bootLayer = Layer.boot();
- stream2 = JLRM_ACCESS.layers(loader)
- .filter(l -> (l != bootLayer))
- .map(l -> providers(l))
- .flatMap(List::stream);
+ Iterator iterator = JLRM_ACCESS.layers(loader).iterator();
+ while (iterator.hasNext()) {
+ Layer layer = iterator.next();
+ if (layer != bootLayer) {
+ allProviders.addAll(providers(layer));
+ }
+ }
+ return allProviders.iterator();
}
-
- return Stream.concat(stream1, stream2).iterator();
}
@Override
@@ -1214,6 +1222,9 @@ public final class ServiceLoader
*
* @return An iterator that lazily loads providers for this loader's
* service
+ *
+ * @revised 9
+ * @spec JPMS
*/
public Iterator iterator() {
@@ -1279,8 +1290,10 @@ public final class ServiceLoader
* provider to be loaded.
*
*
If this loader's provider caches are cleared by invoking the {@link
- * #reload() reload} method then existing streams for this service
- * loader should be discarded.
+ * #reload() reload} method then existing streams for this service loader
+ * should be discarded. The returned stream's source {@code Spliterator} is
+ * fail-fast and will throw {@link ConcurrentModificationException}
+ * if the provider cache has been cleared.
*
*
The following examples demonstrate usage. The first example
* creates a stream of providers, the second example is the same except
@@ -1300,6 +1313,7 @@ public final class ServiceLoader
* @return A stream that lazily loads providers for this loader's service
*
* @since 9
+ * @spec JPMS
*/
public Stream> stream() {
// use cached providers as the source when all providers loaded
@@ -1414,6 +1428,9 @@ public final class ServiceLoader
* if the service type is not accessible to the caller or the
* caller is in an explicit module and its module descriptor does
* not declare that it uses {@code service}
+ *
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ServiceLoader load(Class service,
@@ -1457,6 +1474,9 @@ public final class ServiceLoader
* if the service type is not accessible to the caller or the
* caller is in an explicit module and its module descriptor does
* not declare that it uses {@code service}
+ *
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ServiceLoader load(Class service) {
@@ -1490,6 +1510,9 @@ public final class ServiceLoader
* if the service type is not accessible to the caller or the
* caller is in an explicit module and its module descriptor does
* not declare that it uses {@code service}
+ *
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public static ServiceLoader loadInstalled(Class service) {
@@ -1522,6 +1545,7 @@ public final class ServiceLoader
* not declare that it uses {@code service}
*
* @since 9
+ * @spec JPMS
*/
@CallerSensitive
public static ServiceLoader load(Layer layer, Class service) {
@@ -1551,6 +1575,7 @@ public final class ServiceLoader
* or error is thrown when locating or instantiating the provider.
*
* @since 9
+ * @spec JPMS
*/
public Optional findFirst() {
Iterator iterator = iterator();
diff --git a/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java b/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java
index 06b6c266c89..b0cba4f4915 100644
--- a/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java
+++ b/jdk/src/java.base/share/classes/java/util/spi/AbstractResourceBundleProvider.java
@@ -81,6 +81,7 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
* ResourceBundleProvider Service Providers
*
* @since 9
+ * @spec JPMS
*/
public abstract class AbstractResourceBundleProvider implements ResourceBundleProvider {
private static final JavaUtilResourceBundleAccess RB_ACCESS =
diff --git a/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleControlProvider.java b/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleControlProvider.java
index f74830b4d6a..871d9192ec0 100644
--- a/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleControlProvider.java
+++ b/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleControlProvider.java
@@ -44,6 +44,8 @@ import java.util.ResourceBundle;
*
* @author Masayoshi Okutsu
* @since 1.8
+ * @revised 9
+ * @spec JPMS
* @see ResourceBundle#getBundle(String, java.util.Locale, ClassLoader, ResourceBundle.Control)
* ResourceBundle.getBundle
* @see java.util.ServiceLoader#load(Class)
diff --git a/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java b/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java
index 0074ae32090..251831f1dcb 100644
--- a/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java
+++ b/jdk/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java
@@ -57,6 +57,7 @@ import java.util.ResourceBundle;
* @see
* ResourceBundleProvider Service Providers
* @since 9
+ * @spec JPMS
*/
public interface ResourceBundleProvider {
/**
diff --git a/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java b/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java
index 5191894f4e6..c00b5bf6789 100644
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java
@@ -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
@@ -441,7 +441,7 @@ class ZipEntry implements ZipConstants, Cloneable {
/**
* Sets the size of the compressed entry data.
*
- * @param csize the compressed size to set to
+ * @param csize the compressed size to set
*
* @see #getCompressedSize()
*/
diff --git a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
index 4a78e2eb277..ecd002bc340 100644
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, 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
@@ -274,7 +274,7 @@ class ZipFile implements ZipConstants, Closeable {
*
* @throws IllegalStateException if the zip file has been closed
*
- * Since 1.7
+ * @since 1.7
*/
public String getComment() {
synchronized (this) {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java
index 10506b7029c..e82a27dea43 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -137,10 +137,15 @@ public class BasicImageReader implements AutoCloseable {
int headerSize = ImageHeader.getHeaderSize();
// If no memory map then read header from image file
- if (map == null) {
+ if (headerBuffer == null) {
headerBuffer = ByteBuffer.allocateDirect(headerSize);
- channel.read(headerBuffer, 0L);
- headerBuffer.rewind();
+ if (channel.read(headerBuffer, 0L) == headerSize) {
+ headerBuffer.rewind();
+ } else {
+ throw new IOException("\"" + name + "\" is not an image file");
+ }
+ } else if (headerBuffer.capacity() < headerSize) {
+ throw new IOException("\"" + name + "\" is not an image file");
}
// Interpret the image file header
@@ -156,6 +161,9 @@ public class BasicImageReader implements AutoCloseable {
memoryMap = map.asReadOnlyBuffer();
// Interpret the image index
+ if (memoryMap.capacity() < indexSize) {
+ throw new IOException("The image file \"" + name + "\" is corrupted");
+ }
redirect = intBuffer(memoryMap, header.getRedirectOffset(), header.getRedirectSize());
offsets = intBuffer(memoryMap, header.getOffsetsOffset(), header.getOffsetsSize());
locations = slice(memoryMap, header.getLocationsOffset(), header.getLocationsSize());
diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java
index 60ab472db3e..6082c21bee3 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java
@@ -52,7 +52,9 @@ import java.util.function.Consumer;
* to the jimage file provided by the shipped JDK by tools running on JDK 8.
*/
public final class ImageReader implements AutoCloseable {
- private SharedImageReader reader;
+ private final SharedImageReader reader;
+
+ private volatile boolean closed;
private ImageReader(SharedImageReader reader) {
this.reader = reader;
@@ -71,45 +73,49 @@ public final class ImageReader implements AutoCloseable {
@Override
public void close() throws IOException {
- if (reader == null) {
+ if (closed) {
throw new IOException("image file already closed");
}
-
reader.close(this);
- reader = null;
+ closed = true;
+ }
+
+ private void ensureOpen() throws IOException {
+ if (closed) {
+ throw new IOException("image file closed");
+ }
+ }
+
+ private void requireOpen() {
+ if (closed) {
+ throw new IllegalStateException("image file closed");
+ }
}
// directory management interface
public Directory getRootDirectory() throws IOException {
- if (reader == null) {
- throw new IOException("image file closed");
- }
+ ensureOpen();
return reader.getRootDirectory();
}
+
public Node findNode(String name) throws IOException {
- if (reader == null) {
- throw new IOException("image file closed");
- }
+ ensureOpen();
return reader.findNode(name);
}
public byte[] getResource(Node node) throws IOException {
- if (reader == null) {
- throw new IOException("image file closed");
- }
+ ensureOpen();
return reader.getResource(node);
}
public byte[] getResource(Resource rs) throws IOException {
- if (reader == null) {
- throw new IOException("image file closed");
- }
+ ensureOpen();
return reader.getResource(rs);
}
public ImageHeader getHeader() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getHeader();
}
@@ -118,42 +124,42 @@ public final class ImageReader implements AutoCloseable {
}
public String getName() {
- Objects.requireNonNull(reader, "image file closed");
- return reader.getName() ;
+ requireOpen();
+ return reader.getName();
}
public ByteOrder getByteOrder() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getByteOrder();
}
public Path getImagePath() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getImagePath();
}
public ImageStringsReader getStrings() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getStrings();
}
public ImageLocation findLocation(String mn, String rn) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.findLocation(mn, rn);
}
public ImageLocation findLocation(String name) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.findLocation(name);
}
public String[] getEntryNames() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getEntryNames();
}
public String[] getModuleNames() {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
int off = "/modules/".length();
return reader.findNode("/modules")
.getChildren()
@@ -164,32 +170,32 @@ public final class ImageReader implements AutoCloseable {
}
public long[] getAttributes(int offset) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getAttributes(offset);
}
public String getString(int offset) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getString(offset);
}
public byte[] getResource(String name) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getResource(name);
}
public byte[] getResource(ImageLocation loc) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getResource(loc);
}
public ByteBuffer getResourceBuffer(ImageLocation loc) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getResourceBuffer(loc);
}
public InputStream getResourceStream(ImageLocation loc) {
- Objects.requireNonNull(reader, "image file closed");
+ requireOpen();
return reader.getResourceStream(loc);
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReaderFactory.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReaderFactory.java
index 092b309b0b7..24ac9bfc18a 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReaderFactory.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageReaderFactory.java
@@ -32,6 +32,7 @@ import java.nio.file.Paths;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.function.Function;
/**
* Factory to get ImageReader
@@ -56,21 +57,23 @@ public class ImageReaderFactory {
*/
public static ImageReader get(Path jimage) throws IOException {
Objects.requireNonNull(jimage);
- ImageReader reader = readers.get(jimage);
- if (reader != null) {
- return reader;
- }
- reader = ImageReader.open(jimage);
- // potential race with other threads opening the same URL
- ImageReader r = readers.putIfAbsent(jimage, reader);
- if (r == null) {
- return reader;
- } else {
- reader.close();
- return r;
+ try {
+ return readers.computeIfAbsent(jimage, OPENER);
+ } catch (UncheckedIOException io) {
+ throw io.getCause();
}
}
+ private static Function OPENER = new Function() {
+ public ImageReader apply(Path path) {
+ try {
+ return ImageReader.open(path);
+ } catch (IOException io) {
+ throw new UncheckedIOException(io);
+ }
+ }
+ };
+
/**
* Returns the {@code ImageReader} to read the image file in this
* run-time image.
diff --git a/jdk/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java b/jdk/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java
index 34e99dfdd9b..e95037c7b6e 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java
@@ -78,7 +78,7 @@ public class JmodFile implements AutoCloseable {
HEADER_FILES("include"),
LEGAL_NOTICES("legal"),
MAN_PAGES("man"),
- NATIVE_LIBS("native"),
+ NATIVE_LIBS("lib"),
NATIVE_CMDS("bin");
private final String jmodDir;
@@ -186,7 +186,7 @@ public class JmodFile implements AutoCloseable {
public Entry getEntry(Section section, String name) {
String entry = section.jmodDir() + "/" + name;
ZipEntry ze = zipfile.getEntry(entry);
- return (ze != null) ? new Entry(ze) : null;
+ return (ze == null || ze.isDirectory()) ? null : new Entry(ze);
}
/**
@@ -201,7 +201,7 @@ public class JmodFile implements AutoCloseable {
{
String entry = section.jmodDir() + "/" + name;
ZipEntry e = zipfile.getEntry(entry);
- if (e == null) {
+ if (e == null || e.isDirectory()) {
throw new IOException(name + " not found: " + file);
}
return zipfile.getInputStream(e);
diff --git a/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java b/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
index ab052ec0b30..a0886e82080 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
@@ -57,8 +57,9 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Stream;
-import jdk.internal.module.ModulePatcher.PatchedModuleReader;
import jdk.internal.misc.VM;
+import jdk.internal.module.ModulePatcher.PatchedModuleReader;
+import jdk.internal.module.SystemModules;
/**
@@ -135,7 +136,7 @@ public class BuiltinClassLoader
// maps package name to loaded module for modules in the boot layer
private static final Map packageToModule
- = new ConcurrentHashMap<>(1024);
+ = new ConcurrentHashMap<>(SystemModules.PACKAGES_IN_BOOT_LAYER);
// maps a module name to a module reference
private final Map nameToModule;
@@ -922,13 +923,13 @@ public class BuiltinClassLoader
* Returns the ModuleReader for the given module.
*/
private ModuleReader moduleReaderFor(ModuleReference mref) {
- return moduleToReader.computeIfAbsent(mref, m -> createModuleReader(mref));
+ return moduleToReader.computeIfAbsent(mref, BuiltinClassLoader::createModuleReader);
}
/**
* Creates a ModuleReader for the given module.
*/
- private ModuleReader createModuleReader(ModuleReference mref) {
+ private static ModuleReader createModuleReader(ModuleReference mref) {
try {
return mref.open();
} catch (IOException e) {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/loader/ResourceHelper.java b/jdk/src/java.base/share/classes/jdk/internal/loader/ResourceHelper.java
index a9e0750391a..18a42b7b6f3 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/ResourceHelper.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/ResourceHelper.java
@@ -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
@@ -24,6 +24,10 @@
*/
package jdk.internal.loader;
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
import jdk.internal.module.Checks;
/**
@@ -34,7 +38,8 @@ public final class ResourceHelper {
private ResourceHelper() { }
/**
- * Returns the package name for a resource.
+ * Returns the package name for a resource or the empty package if
+ * the resource name does not contain a slash.
*/
public static String getPackageName(String name) {
int index = name.lastIndexOf('/');
@@ -46,19 +51,75 @@ public final class ResourceHelper {
}
/**
- * Returns true if the resource is a simple resource that can
- * never be encapsulated. Resources ending in "{@code .class}" or where
- * the package name is not a Java identifier are resources that can
- * never be encapsulated.
+ * Returns true if the resource is a simple resource. Simple
+ * resources can never be encapsulated. Resources ending in "{@code .class}"
+ * or where the package name is not a legal package name can not be
+ * encapsulated.
*/
public static boolean isSimpleResource(String name) {
int len = name.length();
if (len > 6 && name.endsWith(".class")) {
return true;
}
- if (!Checks.isJavaIdentifier(getPackageName(name))) {
+ if (!Checks.isPackageName(getPackageName(name))) {
return true;
}
return false;
}
+
+ /**
+ * Converts a resource name to a file path. Returns {@code null} if the
+ * resource name cannot be converted into a file path. Resource names
+ * with empty elements, or elements that are "." or ".." are rejected,
+ * as is a resource name that translates to a file path with a root
+ * component.
+ */
+ public static Path toFilePath(String name) {
+ // scan the resource name to eagerly reject obviously invalid names
+ int next;
+ int off = 0;
+ while ((next = name.indexOf('/', off)) != -1) {
+ int len = next - off;
+ if (!mayTranslate(name, off, len)) {
+ return null;
+ }
+ off = next + 1;
+ }
+ int rem = name.length() - off;
+ if (!mayTranslate(name, off, rem)) {
+ return null;
+ }
+
+ // convert to file path
+ Path path;
+ if (File.separatorChar == '/') {
+ path = Paths.get(name);
+ } else {
+ // not allowed to embed file separators
+ if (name.contains(File.separator))
+ return null;
+ path = Paths.get(name.replace('/', File.separatorChar));
+ }
+
+ // file path not allowed to have root component
+ return (path.getRoot() == null) ? path : null;
+ }
+
+ /**
+ * Returns {@code true} if the element in a resource name is a candidate
+ * to translate to the element of a file path.
+ */
+ private static boolean mayTranslate(String name, int off, int len) {
+ if (len <= 2) {
+ if (len == 0)
+ return false;
+ boolean starsWithDot = (name.charAt(off) == '.');
+ if (len == 1 && starsWithDot)
+ return false;
+ if (len == 2 && starsWithDot && (name.charAt(off+1) == '.'))
+ return false;
+ }
+ return true;
+ }
+
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java b/jdk/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
index d67c342fb0a..d343f8fdcbe 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
@@ -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
@@ -65,6 +65,8 @@ import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.zip.ZipFile;
+import jdk.internal.misc.JavaNetURLAccess;
+import jdk.internal.misc.JavaNetURLClassLoaderAccess;
import jdk.internal.misc.JavaUtilZipFileAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.util.jar.InvalidJarIndexError;
@@ -346,7 +348,7 @@ public class URLClassPath {
* path. The URLs are opened and expanded as needed. Returns null
* if the specified index is out of range.
*/
- private synchronized Loader getLoader(int index) {
+ private synchronized Loader getLoader(int index) {
if (closed) {
return null;
}
@@ -404,31 +406,40 @@ public class URLClassPath {
private Loader getLoader(final URL url) throws IOException {
try {
return java.security.AccessController.doPrivileged(
- new java.security.PrivilegedExceptionAction<>() {
- public Loader run() throws IOException {
- String protocol = url.getProtocol(); // lower cased in URL
- String file = url.getFile();
- if ("jar".equals(protocol)
- && file != null && (file.indexOf("!/") == file.length() - 2)) {
- // extract the nested URL
- URL nestedUrl = new URL(file.substring(0, file.length() - 2));
- return new JarLoader(nestedUrl, jarHandler, lmap, acc);
- } else if (file != null && file.endsWith("/")) {
- if ("file".equals(protocol)) {
- return new FileLoader(url);
- } else {
- return new Loader(url);
+ new java.security.PrivilegedExceptionAction<>() {
+ public Loader run() throws IOException {
+ String protocol = url.getProtocol(); // lower cased in URL
+ String file = url.getFile();
+ if (file != null && file.endsWith("/")) {
+ if ("file".equals(protocol)) {
+ return new FileLoader(url);
+ } else if ("jar".equals(protocol) &&
+ isDefaultJarHandler(url) &&
+ file.endsWith("!/")) {
+ // extract the nested URL
+ URL nestedUrl = new URL(file.substring(0, file.length() - 2));
+ return new JarLoader(nestedUrl, jarHandler, lmap, acc);
+ } else {
+ return new Loader(url);
+ }
+ } else {
+ return new JarLoader(url, jarHandler, lmap, acc);
+ }
}
- } else {
- return new JarLoader(url, jarHandler, lmap, acc);
- }
- }
- }, acc);
+ }, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (IOException)pae.getException();
}
}
+ private static final JavaNetURLAccess JNUA
+ = SharedSecrets.getJavaNetURLAccess();
+
+ private static boolean isDefaultJarHandler(URL u) {
+ URLStreamHandler h = JNUA.getHandler(u);
+ return h instanceof sun.net.www.protocol.jar.Handler;
+ }
+
/*
* Pushes the specified URLs onto the list of unopened URLs.
*/
@@ -493,7 +504,7 @@ public class URLClassPath {
}
/**
- * Inner class used to represent a loader of resources and classes
+ * Nested class used to represent a loader of resources and classes
* from a base URL.
*/
private static class Loader implements Closeable {
@@ -600,7 +611,8 @@ public class URLClassPath {
* close this loader and release all resources
* method overridden in sub-classes
*/
- public void close () throws IOException {
+ @Override
+ public void close() throws IOException {
if (jarfile != null) {
jarfile.close();
}
@@ -615,7 +627,7 @@ public class URLClassPath {
}
/*
- * Inner class used to represent a Loader of resources from a JAR URL.
+ * Nested class class used to represent a Loader of resources from a JAR URL.
*/
static class JarLoader extends Loader {
private JarFile jar;
@@ -798,7 +810,7 @@ public class URLClassPath {
/*
- * Returns true iff atleast one resource in the jar file has the same
+ * Returns true iff at least one resource in the jar file has the same
* package name as that of the specified resource name.
*/
boolean validIndex(final String name) {
@@ -826,6 +838,7 @@ public class URLClassPath {
/*
* Returns the URL for a resource with the specified name
*/
+ @Override
URL findResource(final String name, boolean check) {
Resource rsc = getResource(name, check);
if (rsc != null) {
@@ -837,6 +850,7 @@ public class URLClassPath {
/*
* Returns the JAR Resource for the specified name.
*/
+ @Override
Resource getResource(final String name, boolean check) {
try {
ensureOpen();
@@ -863,7 +877,6 @@ public class URLClassPath {
*/
Resource getResource(final String name, boolean check,
Set visited) {
-
Resource res;
String[] jarFiles;
int count = 0;
@@ -919,7 +932,6 @@ public class URLClassPath {
continue;
}
-
/* Note that the addition of the url to the list of visited
* jars incorporates a check for presence in the hashmap
*/
@@ -975,6 +987,7 @@ public class URLClassPath {
/*
* Returns the JAR file local class path, or null if none.
*/
+ @Override
URL[] getClassPath() throws IOException {
if (index != null) {
return null;
@@ -1002,7 +1015,7 @@ public class URLClassPath {
* Parses value of the Class-Path manifest attribute and returns
* an array of URLs relative to the specified base URL.
*/
- private URL[] parseClassPath(URL base, String value)
+ private static URL[] parseClassPath(URL base, String value)
throws MalformedURLException
{
StringTokenizer st = new StringTokenizer(value);
@@ -1018,7 +1031,7 @@ public class URLClassPath {
}
/*
- * Inner class used to represent a loader of classes and resources
+ * Nested class used to represent a loader of classes and resources
* from a file URL that refers to a directory.
*/
private static class FileLoader extends Loader {
@@ -1038,6 +1051,7 @@ public class URLClassPath {
/*
* Returns the URL for a resource with the specified name
*/
+ @Override
URL findResource(final String name, boolean check) {
Resource rsc = getResource(name, check);
if (rsc != null) {
@@ -1046,6 +1060,7 @@ public class URLClassPath {
return null;
}
+ @Override
Resource getResource(final String name, boolean check) {
final URL url;
try {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
index 6838111c35d..7cb2c1e74a4 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
@@ -174,4 +174,9 @@ public interface JavaLangAccess {
* Invokes Long.fastUUID
*/
String fastUUID(long lsb, long msb);
+
+ /**
+ * Invalidate package access cache
+ */
+ void invalidatePackageAccessCache();
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangModuleAccess.java b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangModuleAccess.java
index eed7a2d2aff..53e8b4c82c7 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangModuleAccess.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangModuleAccess.java
@@ -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
@@ -59,20 +59,21 @@ public interface JavaLangModuleAccess {
*/
ModuleDescriptor.Builder newModuleBuilder(String mn,
boolean strict,
- boolean open,
- boolean synthetic);
+ Set ms);
/**
- * Returns the set of packages that are exported (unconditionally or
- * unconditionally).
+ * Returns a snapshot of the packages in the module.
*/
- Set exportedPackages(ModuleDescriptor.Builder builder);
+ Set packages(ModuleDescriptor.Builder builder);
/**
- * Returns the set of packages that are opened (unconditionally or
- * unconditionally).
+ * Adds a dependence on a module with the given (possibly un-parsable)
+ * version string.
*/
- Set openPackages(ModuleDescriptor.Builder builder);
+ void requires(ModuleDescriptor.Builder builder,
+ Set ms,
+ String mn,
+ String compiledVersion);
/**
* Returns a {@code ModuleDescriptor.Requires} of the given modifiers
@@ -113,24 +114,12 @@ public interface JavaLangModuleAccess {
*/
Provides newProvides(String service, List providers);
- /**
- * Returns a {@code ModuleDescriptor.Version} of the given version.
- */
- Version newVersion(String v);
-
- /**
- * Clones the given module descriptor with an augmented set of packages
- */
- ModuleDescriptor newModuleDescriptor(ModuleDescriptor md, Set pkgs);
-
/**
* Returns a new {@code ModuleDescriptor} instance.
*/
ModuleDescriptor newModuleDescriptor(String name,
Version version,
- boolean open,
- boolean automatic,
- boolean synthetic,
+ Set ms,
Set requires,
Set exports,
Set opens,
@@ -148,9 +137,9 @@ public interface JavaLangModuleAccess {
* and the empty configuration as the parent. The post resolution
* checks are optionally run.
*/
- Configuration resolveRequiresAndUses(ModuleFinder finder,
- Collection roots,
- boolean check,
- PrintStream traceOutput);
+ Configuration resolveAndBind(ModuleFinder finder,
+ Collection roots,
+ boolean check,
+ PrintStream traceOutput);
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaNetURLAccess.java b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaNetURLAccess.java
new file mode 100644
index 00000000000..37e8fd3216c
--- /dev/null
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaNetURLAccess.java
@@ -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. 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.net.URL;
+import java.net.URLStreamHandler;
+
+public interface JavaNetURLAccess {
+ URLStreamHandler getHandler(URL u);
+}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java b/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
index 36514cb1065..321a4ca1fb2 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2016, 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
@@ -58,6 +58,7 @@ public class SharedSecrets {
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
private static JavaNetSocketAccess javaNetSocketAccess;
private static JavaNetUriAccess javaNetUriAccess;
+ private static JavaNetURLAccess javaNetURLAccess;
private static JavaNetURLClassLoaderAccess javaNetURLClassLoaderAccess;
private static JavaNioAccess javaNioAccess;
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
@@ -146,6 +147,16 @@ public class SharedSecrets {
return javaNetUriAccess;
}
+ public static void setJavaNetURLAccess(JavaNetURLAccess jnua) {
+ javaNetURLAccess = jnua;
+ }
+
+ public static JavaNetURLAccess getJavaNetURLAccess() {
+ if (javaNetURLAccess == null)
+ unsafe.ensureClassInitialized(java.net.URL.class);
+ return javaNetURLAccess;
+ }
+
public static void setJavaNetURLClassLoaderAccess(JavaNetURLClassLoaderAccess jnua) {
javaNetURLClassLoaderAccess = jnua;
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/Builder.java b/jdk/src/java.base/share/classes/jdk/internal/module/Builder.java
index 2ef9c11d248..9196f39ff77 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/Builder.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/Builder.java
@@ -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
@@ -38,7 +38,7 @@ import jdk.internal.misc.JavaLangModuleAccess;
import jdk.internal.misc.SharedSecrets;
/**
- * This builder is optimized for reconstituting ModuleDescriptor
+ * This builder is optimized for reconstituting the {@code ModuleDescriptor}s
* for system modules. The validation should be done at jlink time.
*
* 1. skip name validation
@@ -136,9 +136,7 @@ final class Builder {
}
final String name;
- boolean open;
- boolean automatic;
- boolean synthetic;
+ boolean open, synthetic, mandated;
Set requires;
Set exports;
Set opens;
@@ -165,13 +163,13 @@ final class Builder {
return this;
}
- Builder automatic(boolean value) {
- this.automatic = value;
+ Builder synthetic(boolean value) {
+ this.synthetic = value;
return this;
}
- Builder synthetic(boolean value) {
- this.synthetic = value;
+ Builder mandated(boolean value) {
+ this.mandated = value;
return this;
}
@@ -228,13 +226,10 @@ final class Builder {
*
* @throws IllegalArgumentException if {@code v} is null or cannot be
* parsed as a version string
- * @throws IllegalStateException if the module version is already set
*
* @see Version#parse(String)
*/
public Builder version(String v) {
- if (version != null)
- throw new IllegalStateException("module version already set");
Version ver = cachedVersion;
if (ver != null && v.equals(ver.toString())) {
version = ver;
@@ -246,63 +241,63 @@ final class Builder {
/**
* Sets the module main class.
- *
- * @throws IllegalStateException if already set
*/
public Builder mainClass(String mc) {
- if (mainClass != null)
- throw new IllegalStateException("main class already set");
mainClass = mc;
return this;
}
/**
* Sets the OS name.
- *
- * @throws IllegalStateException if already set
*/
public Builder osName(String name) {
- if (osName != null)
- throw new IllegalStateException("OS name already set");
this.osName = name;
return this;
}
/**
* Sets the OS arch.
- *
- * @throws IllegalStateException if already set
*/
public Builder osArch(String arch) {
- if (osArch != null)
- throw new IllegalStateException("OS arch already set");
this.osArch = arch;
return this;
}
/**
* Sets the OS version.
- *
- * @throws IllegalStateException if already set
*/
public Builder osVersion(String version) {
- if (osVersion != null)
- throw new IllegalStateException("OS version already set");
this.osVersion = version;
return this;
}
+ /**
+ * Returns an immutable set of the module modifiers derived from the flags.
+ */
+ private Set modifiers() {
+ int n = 0;
+ if (open) n++;
+ if (synthetic) n++;
+ if (mandated) n++;
+ if (n == 0) {
+ return Collections.emptySet();
+ } else {
+ ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n];
+ if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN;
+ if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC;
+ if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED;
+ return Set.of(mods);
+ }
+ }
+
/**
* Builds a {@code ModuleDescriptor} from the components.
*/
public ModuleDescriptor build(int hashCode) {
assert name != null;
-
return JLMA.newModuleDescriptor(name,
version,
- open,
- automatic,
- synthetic,
+ modifiers(),
requires,
exports,
opens,
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/Checks.java b/jdk/src/java.base/share/classes/jdk/internal/module/Checks.java
index 2fdeaab6211..e19e6528ce0 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/Checks.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/Checks.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -26,7 +26,7 @@
package jdk.internal.module;
/**
- * Utility class for checking module name and binary names.
+ * Utility class for checking module, package, and class names.
*/
public final class Checks {
@@ -58,8 +58,6 @@ public final class Checks {
throw new IllegalArgumentException(name + ": Invalid module name"
+ ": '" + id + "' is not a Java identifier");
}
- //if (!Character.isJavaIdentifierStart(last))
- // throw new IllegalArgumentException(name + ": Module name ends in digit");
return name;
}
@@ -77,8 +75,6 @@ public final class Checks {
int last = isJavaIdentifier(name, off, name.length() - off);
if (last == -1)
return false;
- //if (!Character.isJavaIdentifierStart(last))
- // return false;
return true;
}
@@ -89,40 +85,62 @@ public final class Checks {
* package name
*/
public static String requirePackageName(String name) {
- return requireBinaryName("package name", name);
+ return requireTypeName("package name", name);
}
/**
- * Checks a name to ensure that it's a legal type name.
+ * Returns {@code true} if the given name is a legal package name.
+ */
+ public static boolean isPackageName(String name) {
+ return isTypeName(name);
+ }
+
+ /**
+ * Checks a name to ensure that it's a legal qualified class name
*
* @throws IllegalArgumentException if name is null or not a legal
- * type name
+ * qualified class name
*/
public static String requireServiceTypeName(String name) {
- return requireBinaryName("service type name", name);
+ return requireQualifiedClassName("service type name", name);
}
/**
- * Checks a name to ensure that it's a legal type name.
+ * Checks a name to ensure that it's a legal qualified class name.
*
* @throws IllegalArgumentException if name is null or not a legal
- * type name
+ * qualified class name
*/
public static String requireServiceProviderName(String name) {
- return requireBinaryName("service provider name", name);
+ return requireQualifiedClassName("service provider name", name);
}
/**
- * Returns {@code true} if the given name is a legal binary name.
+ * Checks a name to ensure that it's a legal qualified class name in
+ * a named package.
+ *
+ * @throws IllegalArgumentException if name is null or not a legal
+ * qualified class name in a named package
*/
- public static boolean isJavaIdentifier(String name) {
- return isBinaryName(name);
+ public static String requireQualifiedClassName(String what, String name) {
+ requireTypeName(what, name);
+ if (name.indexOf('.') == -1)
+ throw new IllegalArgumentException(name + ": is not a qualified name of"
+ + " a Java class in a named package");
+ return name;
}
/**
- * Returns {@code true} if the given name is a legal binary name.
+ * Returns {@code true} if the given name is a legal class name.
*/
- public static boolean isBinaryName(String name) {
+ public static boolean isClassName(String name) {
+ return isTypeName(name);
+ }
+
+ /**
+ * Returns {@code true} if the given name is a legal type name.
+ */
+ private static boolean isTypeName(String name) {
int next;
int off = 0;
while ((next = name.indexOf('.', off)) != -1) {
@@ -135,12 +153,12 @@ public final class Checks {
}
/**
- * Checks if the given name is a legal binary name.
+ * Checks if the given name is a legal type name.
*
* @throws IllegalArgumentException if name is null or not a legal
- * binary name
+ * type name
*/
- public static String requireBinaryName(String what, String name) {
+ private static String requireTypeName(String what, String name) {
if (name == null)
throw new IllegalArgumentException("Null " + what);
int next;
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java b/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java
index 69c7ee670dd..fc3c3904850 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java
@@ -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
@@ -26,6 +26,7 @@
package jdk.internal.module;
import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Builder;
import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
@@ -98,14 +99,17 @@ public final class ClassFileAttributes {
// module_flags
int module_flags = cr.readUnsignedShort(off);
- boolean open = ((module_flags & ACC_OPEN) != 0);
- boolean synthetic = ((module_flags & ACC_SYNTHETIC) != 0);
off += 2;
- ModuleDescriptor.Builder builder = JLMA.newModuleBuilder(mn,
- false,
- open,
- synthetic);
+ Set modifiers = new HashSet<>();
+ if ((module_flags & ACC_OPEN) != 0)
+ modifiers.add(ModuleDescriptor.Modifier.OPEN);
+ if ((module_flags & ACC_SYNTHETIC) != 0)
+ modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC);
+ if ((module_flags & ACC_MANDATED) != 0)
+ modifiers.add(ModuleDescriptor.Modifier.MANDATED);
+
+ Builder builder = JLMA.newModuleBuilder(mn, false, modifiers);
// module_version
String module_version = cr.readUTF8(off, buf);
@@ -142,19 +146,13 @@ public final class ClassFileAttributes {
mods.add(Requires.Modifier.MANDATED);
}
-
// requires_version
- Version compiledVersion = null;
String requires_version = cr.readUTF8(off, buf);
off += 2;
- if (requires_version != null) {
- compiledVersion = Version.parse(requires_version);
- }
-
- if (compiledVersion == null) {
+ if (requires_version == null) {
builder.requires(mods, dn);
} else {
- builder.requires(mods, dn, compiledVersion);
+ JLMA.requires(builder, mods, dn, requires_version);
}
}
@@ -283,11 +281,14 @@ public final class ClassFileAttributes {
attr.putShort(module_name_index);
// module_flags
+ Set modifiers = descriptor.modifiers();
int module_flags = 0;
- if (descriptor.isOpen())
+ if (modifiers.contains(ModuleDescriptor.Modifier.OPEN))
module_flags |= ACC_OPEN;
- if (descriptor.isSynthetic())
+ if (modifiers.contains(ModuleDescriptor.Modifier.SYNTHETIC))
module_flags |= ACC_SYNTHETIC;
+ if (modifiers.contains(ModuleDescriptor.Modifier.MANDATED))
+ module_flags |= ACC_MANDATED;
attr.putShort(module_flags);
// module_version
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileConstants.java b/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileConstants.java
index 48fe536c7aa..66e241ee555 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileConstants.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ClassFileConstants.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -46,8 +46,8 @@ public class ClassFileConstants {
// access, requires, exports, and opens flags
public static final int ACC_MODULE = 0x8000;
public static final int ACC_OPEN = 0x0020;
- public static final int ACC_TRANSITIVE = 0x0010;
- public static final int ACC_STATIC_PHASE = 0x0020;
+ public static final int ACC_TRANSITIVE = 0x0020;
+ public static final int ACC_STATIC_PHASE = 0x0040;
public static final int ACC_SYNTHETIC = 0x1000;
public static final int ACC_MANDATED = 0x8000;
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
index 71406460c41..b2c1b4b3548 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -46,6 +46,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
+import java.util.stream.Stream;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.BuiltinClassLoader;
@@ -275,10 +276,10 @@ public final class ModuleBootstrap {
// run the resolver to create the configuration
Configuration cf = SharedSecrets.getJavaLangModuleAccess()
- .resolveRequiresAndUses(finder,
- roots,
- needPostResolutionChecks,
- traceOutput);
+ .resolveAndBind(finder,
+ roots,
+ needPostResolutionChecks,
+ traceOutput);
// time to create configuration
PerfCounters.resolveTime.addElapsedTimeFrom(t3);
@@ -318,20 +319,20 @@ public final class ModuleBootstrap {
// if needed check that there are no split packages in the set of
// resolved modules for the boot layer
if (SystemModules.hasSplitPackages() || needPostResolutionChecks) {
- Map packageToModule = new HashMap<>();
- for (ResolvedModule resolvedModule : cf.modules()) {
- ModuleDescriptor descriptor =
- resolvedModule.reference().descriptor();
- String name = descriptor.name();
- for (String p : descriptor.packages()) {
- String other = packageToModule.putIfAbsent(p, name);
- if (other != null) {
- fail("Package " + p + " in both module "
- + name + " and module " + other);
- }
+ Map packageToModule = new HashMap<>();
+ for (ResolvedModule resolvedModule : cf.modules()) {
+ ModuleDescriptor descriptor =
+ resolvedModule.reference().descriptor();
+ String name = descriptor.name();
+ for (String p : descriptor.packages()) {
+ String other = packageToModule.putIfAbsent(p, name);
+ if (other != null) {
+ fail("Package " + p + " in both module "
+ + name + " and module " + other);
}
}
}
+ }
long t4 = System.nanoTime();
@@ -380,10 +381,9 @@ public final class ModuleBootstrap {
Set otherMods)
{
// resolve all root modules
- Configuration cf = Configuration.empty()
- .resolveRequires(finder,
- ModuleFinder.of(),
- roots);
+ Configuration cf = Configuration.empty().resolve(finder,
+ ModuleFinder.of(),
+ roots);
// module name -> reference
Map map = new HashMap<>();
@@ -416,7 +416,7 @@ public final class ModuleBootstrap {
/**
* Creates a finder from the module path that is the value of the given
- * system property.
+ * system property and optionally patched by --patch-module
*/
private static ModuleFinder createModulePathFinder(String prop) {
String s = System.getProperty(prop);
@@ -429,7 +429,7 @@ public final class ModuleBootstrap {
for (String dir: dirs) {
paths[i++] = Paths.get(dir);
}
- return ModuleFinder.of(paths);
+ return ModulePath.of(patcher, paths);
}
}
@@ -528,6 +528,7 @@ public final class ModuleBootstrap {
if (!extraOpens.isEmpty()) {
addExtraExportsOrOpens(bootLayer, extraOpens, true);
}
+
}
private static void addExtraExportsOrOpens(Layer bootLayer,
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java
index 3aac651577c..b58c717affe 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -37,7 +37,6 @@ import java.lang.module.ModuleDescriptor.Builder;
import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
-import java.lang.module.ModuleDescriptor.Version;
import java.nio.ByteBuffer;
import java.nio.BufferUnderflowException;
import java.util.ArrayList;
@@ -51,7 +50,6 @@ import java.util.function.Supplier;
import jdk.internal.misc.JavaLangModuleAccess;
import jdk.internal.misc.SharedSecrets;
-import jdk.internal.module.ModuleResolution;
import static jdk.internal.module.ClassFileConstants.*;
@@ -221,7 +219,7 @@ public final class ModuleInfo {
Set attributes = new HashSet<>();
Builder builder = null;
- Set packages = null;
+ Set allPackages = null;
String mainClass = null;
String[] osValues = null;
ModuleHashes hashes = null;
@@ -245,7 +243,7 @@ public final class ModuleInfo {
break;
case MODULE_PACKAGES :
- packages = readModulePackagesAttribute(in, cpool);
+ allPackages = readModulePackagesAttribute(in, cpool);
break;
case MODULE_MAIN_CLASS :
@@ -284,51 +282,44 @@ public final class ModuleInfo {
throw invalidModuleDescriptor(MODULE + " attribute not found");
}
+ // ModuleMainClass and ModuleTarget attributes
+ if (mainClass != null) {
+ builder.mainClass(mainClass);
+ }
+ if (osValues != null) {
+ if (osValues[0] != null) builder.osName(osValues[0]);
+ if (osValues[1] != null) builder.osArch(osValues[1]);
+ if (osValues[2] != null) builder.osVersion(osValues[2]);
+ }
+
// If the ModulePackages attribute is not present then the packageFinder
// is used to find the set of packages
boolean usedPackageFinder = false;
- if (packages == null && packageFinder != null) {
+ if (allPackages == null && packageFinder != null) {
try {
- packages = new HashSet<>(packageFinder.get());
+ allPackages = packageFinder.get();
} catch (UncheckedIOException x) {
throw x.getCause();
}
usedPackageFinder = true;
}
- if (packages != null) {
- Set exportedPackages = JLMA.exportedPackages(builder);
- Set openPackages = JLMA.openPackages(builder);
- if (packages.containsAll(exportedPackages)
- && packages.containsAll(openPackages)) {
- packages.removeAll(exportedPackages);
- packages.removeAll(openPackages);
- } else {
- // the set of packages is not complete
- Set exportedAndOpenPackages = new HashSet<>();
- exportedAndOpenPackages.addAll(exportedPackages);
- exportedAndOpenPackages.addAll(openPackages);
- for (String pn : exportedAndOpenPackages) {
- if (!packages.contains(pn)) {
- String tail;
- if (usedPackageFinder) {
- tail = " not found by package finder";
- } else {
- tail = " missing from ModulePackages attribute";
- }
- throw invalidModuleDescriptor("Package " + pn + tail);
- }
+ if (allPackages != null) {
+ Set knownPackages = JLMA.packages(builder);
+ if (!allPackages.containsAll(knownPackages)) {
+ Set missingPackages = new HashSet<>(knownPackages);
+ missingPackages.removeAll(allPackages);
+ assert !missingPackages.isEmpty();
+ String missingPackage = missingPackages.iterator().next();
+ String tail;
+ if (usedPackageFinder) {
+ tail = " not found in module";
+ } else {
+ tail = " missing from ModulePackages class file attribute";
}
- assert false; // should not get here
- }
- builder.contains(packages);
- }
+ throw invalidModuleDescriptor("Package " + missingPackage + tail);
- if (mainClass != null)
- builder.mainClass(mainClass);
- if (osValues != null) {
- if (osValues[0] != null) builder.osName(osValues[0]);
- if (osValues[1] != null) builder.osArch(osValues[1]);
- if (osValues[2] != null) builder.osVersion(osValues[2]);
+ }
+ builder.packages(allPackages);
}
ModuleDescriptor descriptor = builder.build();
@@ -347,10 +338,17 @@ public final class ModuleInfo {
String mn = cpool.getModuleName(module_name_index);
int module_flags = in.readUnsignedShort();
- boolean open = ((module_flags & ACC_OPEN) != 0);
- boolean synthetic = ((module_flags & ACC_SYNTHETIC) != 0);
- Builder builder = JLMA.newModuleBuilder(mn, false, open, synthetic);
+ Set modifiers = new HashSet<>();
+ boolean open = ((module_flags & ACC_OPEN) != 0);
+ if (open)
+ modifiers.add(ModuleDescriptor.Modifier.OPEN);
+ if ((module_flags & ACC_SYNTHETIC) != 0)
+ modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC);
+ if ((module_flags & ACC_MANDATED) != 0)
+ modifiers.add(ModuleDescriptor.Modifier.MANDATED);
+
+ Builder builder = JLMA.newModuleBuilder(mn, false, modifiers);
int module_version_index = in.readUnsignedShort();
if (module_version_index != 0) {
@@ -381,16 +379,11 @@ public final class ModuleInfo {
}
int requires_version_index = in.readUnsignedShort();
- Version compiledVersion = null;
- if (requires_version_index != 0) {
- String vs = cpool.getUtf8(requires_version_index);
- compiledVersion = Version.parse(vs);
- }
-
- if (compiledVersion == null) {
+ if (requires_version_index == 0) {
builder.requires(mods, dn);
} else {
- builder.requires(mods, dn, compiledVersion);
+ String vs = cpool.getUtf8(requires_version_index);
+ JLMA.requires(builder, mods, dn, vs);
}
if (dn.equals("java.base"))
@@ -629,10 +622,7 @@ public final class ModuleInfo {
/**
* Return true if the given attribute name is the name of a pre-defined
- * attribute that is not allowed in the class file.
- *
- * Except for Module, InnerClasses, SourceFile, SourceDebugExtension, and
- * Deprecated, none of the pre-defined attributes in JVMS 4.7 may appear.
+ * attribute in JVMS 4.7 that is not allowed in a module-info class.
*/
private static boolean isAttributeDisallowed(String name) {
Set notAllowed = predefinedNotAllowed;
@@ -640,6 +630,7 @@ public final class ModuleInfo {
notAllowed = Set.of(
"ConstantValue",
"Code",
+ "Deprecated",
"StackMapTable",
"Exceptions",
"EnclosingMethod",
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java
index 0d05ad296e9..73fb660ed7f 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java
@@ -56,7 +56,7 @@ public final class ModuleInfoExtender {
// the packages in the ModulePackages attribute
private Set packages;
- // the value of the module_version in Module attribute
+ // the value for the module version in the Module attribute
private Version version;
// the value of the ModuleMainClass attribute
@@ -78,7 +78,11 @@ public final class ModuleInfoExtender {
}
/**
- * Sets the set of packages for the ModulePackages attribute
+ * Sets the packages for the ModulePackages attribute
+ *
+ * @apiNote This method does not check that the package names are legal
+ * package names or that the set of packages is a super set of the
+ * packages in the module.
*/
public ModuleInfoExtender packages(Set packages) {
this.packages = Collections.unmodifiableSet(packages);
@@ -86,7 +90,7 @@ public final class ModuleInfoExtender {
}
/**
- * Sets the value of the module_version in Module attribute.
+ * Sets the value for the module version in the Module attribute
*/
public ModuleInfoExtender version(Version version) {
this.version = version;
@@ -95,6 +99,9 @@ public final class ModuleInfoExtender {
/**
* Sets the value of the ModuleMainClass attribute.
+ *
+ * @apiNote This method does not check that the main class is a legal
+ * class name in a named package.
*/
public ModuleInfoExtender mainClass(String mainClass) {
this.mainClass = mainClass;
@@ -133,7 +140,7 @@ public final class ModuleInfoExtender {
/**
* A ClassVisitor that supports adding class file attributes. If an
- * attribute already exists then the first occurence of the attribute
+ * attribute already exists then the first occurrence of the attribute
* is replaced.
*/
private static class AttributeAddingClassVisitor extends ClassVisitor {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleLoaderMap.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleLoaderMap.java
index 9c3308f97a0..15e60d0d611 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleLoaderMap.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleLoaderMap.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 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
@@ -41,13 +41,6 @@ import jdk.internal.loader.ClassLoaders;
* are generated at build time.
*/
final class ModuleLoaderMap {
- /*
- * The list of boot modules and platform modules are generated at build time.
- */
- private static final String[] BOOT_MODULES
- = new String[] { "@@BOOT_MODULE_NAMES@@" };
- private static final String[] PLATFORM_MODULES
- = new String[] { "@@PLATFORM_MODULE_NAMES@@" };
/**
* Returns the function to map modules in the given configuration to the
@@ -55,6 +48,10 @@ final class ModuleLoaderMap {
*/
static Function mappingFunction(Configuration cf) {
+ // The list of boot modules and platform modules are generated at build time.
+ final String[] BOOT_MODULES = new String[] { "@@BOOT_MODULE_NAMES@@" };
+ final String[] PLATFORM_MODULES = new String[] { "@@PLATFORM_MODULE_NAMES@@" };
+
Set bootModules = new HashSet<>(BOOT_MODULES.length);
for (String mn : BOOT_MODULES) {
bootModules.add(mn);
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
index 5bd7ef5ed04..fe3f8930ad2 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
@@ -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
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Builder;
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.net.MalformedURLException;
@@ -54,6 +55,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.internal.loader.Resource;
+import jdk.internal.loader.ResourceHelper;
import jdk.internal.misc.JavaLangModuleAccess;
import jdk.internal.misc.SharedSecrets;
import sun.net.www.ParseUtil;
@@ -108,8 +110,11 @@ public final class ModulePatcher {
if (paths == null)
return mref;
- // scan the JAR file or directory tree to get the set of packages
+ // Scan the JAR file or directory tree to get the set of packages.
+ // For automatic modules then packages that do not contain class files
+ // must be ignored.
Set packages = new HashSet<>();
+ boolean isAutomatic = descriptor.isAutomatic();
try {
for (Path file : paths) {
if (Files.isRegularFile(file)) {
@@ -118,8 +123,10 @@ public final class ModulePatcher {
// is not supported by the boot class loader
try (JarFile jf = new JarFile(file.toFile())) {
jf.stream()
+ .filter(e -> !e.isDirectory()
+ && (!isAutomatic || e.getName().endsWith(".class")))
.map(e -> toPackageName(file, e))
- .filter(Checks::isJavaIdentifier)
+ .filter(Checks::isPackageName)
.forEach(packages::add);
}
@@ -129,8 +136,10 @@ public final class ModulePatcher {
Path top = file;
Files.find(top, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile()))
+ .filter(path -> !isAutomatic
+ || path.toString().endsWith(".class"))
.map(path -> toPackageName(top, path))
- .filter(Checks::isJavaIdentifier)
+ .filter(Checks::isPackageName)
.forEach(packages::add);
}
@@ -141,10 +150,30 @@ public final class ModulePatcher {
}
// if there are new packages then we need a new ModuleDescriptor
- Set original = descriptor.packages();
- packages.addAll(original);
- if (packages.size() > original.size()) {
- descriptor = JLMA.newModuleDescriptor(descriptor, packages);
+ packages.removeAll(descriptor.packages());
+ if (!packages.isEmpty()) {
+ Builder builder = JLMA.newModuleBuilder(descriptor.name(),
+ /*strict*/ false,
+ descriptor.modifiers());
+ if (!descriptor.isAutomatic()) {
+ descriptor.requires().forEach(builder::requires);
+ descriptor.exports().forEach(builder::exports);
+ descriptor.opens().forEach(builder::opens);
+ descriptor.uses().forEach(builder::uses);
+ }
+ descriptor.provides().forEach(builder::provides);
+
+ descriptor.version().ifPresent(builder::version);
+ descriptor.mainClass().ifPresent(builder::mainClass);
+ descriptor.osName().ifPresent(builder::osName);
+ descriptor.osArch().ifPresent(builder::osArch);
+ descriptor.osVersion().ifPresent(builder::osVersion);
+
+ // original + new packages
+ builder.packages(descriptor.packages());
+ builder.packages(packages);
+
+ descriptor = builder.build();
}
// return a module reference to the patched module
@@ -471,23 +500,14 @@ public final class ModulePatcher {
@Override
public Resource find(String name) throws IOException {
- Path file = Paths.get(name.replace('/', File.separatorChar));
- if (file.getRoot() == null) {
- file = dir.resolve(file);
- } else {
- // drop the root component so that the resource is
- // located relative to the module directory
- int n = file.getNameCount();
- if (n == 0)
- return null;
- file = dir.resolve(file.subpath(0, n));
- }
-
- if (Files.isRegularFile(file)) {
- return newResource(name, dir, file);
- } else {
- return null;
+ Path path = ResourceHelper.toFilePath(name);
+ if (path != null) {
+ Path file = dir.resolve(path);
+ if (Files.isRegularFile(file)) {
+ return newResource(name, dir, file);
+ }
}
+ return null;
}
private Resource newResource(String name, Path top, Path file) {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java
index fb7871d3c31..ae337423965 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModulePath.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, 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
@@ -35,7 +35,6 @@ import java.io.UncheckedIOException;
import java.lang.module.FindException;
import java.lang.module.InvalidModuleDescriptorException;
import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleDescriptor.Requires;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.net.URI;
@@ -70,12 +69,11 @@ import jdk.internal.util.jar.VersionedStream;
/**
* A {@code ModuleFinder} that locates modules on the file system by searching
- * a sequence of directories or packaged modules.
- *
- * The {@code ModuleFinder} can be created to work in either the run-time
- * or link-time phases. In both cases it locates modular JAR and exploded
- * modules. When created for link-time then it additionally locates
- * modules in JMOD files.
+ * a sequence of directories or packaged modules. The ModuleFinder can be
+ * created to work in either the run-time or link-time phases. In both cases it
+ * locates modular JAR and exploded modules. When created for link-time then it
+ * additionally locates modules in JMOD files. The ModuleFinder can also
+ * optionally patch any modules that it locates with a ModulePatcher.
*/
public class ModulePath implements ModuleFinder {
@@ -87,6 +85,9 @@ public class ModulePath implements ModuleFinder {
// true for the link phase (supports modules packaged in JMOD format)
private final boolean isLinkPhase;
+ // for patching modules, can be null
+ private final ModulePatcher patcher;
+
// the entries on this module path
private final Path[] entries;
private int next;
@@ -94,19 +95,51 @@ public class ModulePath implements ModuleFinder {
// map of module name to module reference map for modules already located
private final Map cachedModules = new HashMap<>();
- public ModulePath(Runtime.Version version, boolean isLinkPhase, Path... entries) {
+
+ private ModulePath(Runtime.Version version,
+ boolean isLinkPhase,
+ ModulePatcher patcher,
+ Path... entries) {
this.releaseVersion = version;
this.isLinkPhase = isLinkPhase;
+ this.patcher = patcher;
this.entries = entries.clone();
for (Path entry : this.entries) {
Objects.requireNonNull(entry);
}
}
- public ModulePath(Path... entries) {
- this(JarFile.runtimeVersion(), false, entries);
+ /**
+ * Returns a ModuleFinder that that locates modules on the file system by
+ * searching a sequence of directories and/or packaged modules. The modules
+ * may be patched by the given ModulePatcher.
+ */
+ public static ModuleFinder of(ModulePatcher patcher, Path... entries) {
+ return new ModulePath(JarFile.runtimeVersion(), false, patcher, entries);
}
+ /**
+ * Returns a ModuleFinder that that locates modules on the file system by
+ * searching a sequence of directories and/or packaged modules.
+ */
+ public static ModuleFinder of(Path... entries) {
+ return of((ModulePatcher)null, entries);
+ }
+
+ /**
+ * Returns a ModuleFinder that that locates modules on the file system by
+ * searching a sequence of directories and/or packaged modules.
+ *
+ * @param version The release version to use for multi-release JAR files
+ * @param isLinkPhase {@code true} if the link phase to locate JMOD files
+ */
+ public static ModuleFinder of(Runtime.Version version,
+ boolean isLinkPhase,
+ Path... entries) {
+ return new ModulePath(version, isLinkPhase, null, entries);
+ }
+
+
@Override
public Optional find(String name) {
Objects.requireNonNull(name);
@@ -195,8 +228,7 @@ public class ModulePath implements ModuleFinder {
if (attrs.isDirectory()) {
Path mi = entry.resolve(MODULE_INFO);
if (!Files.exists(mi)) {
- // does not exist or unable to determine so assume a
- // directory of modules
+ // assume a directory of modules
return scanDirectory(entry);
}
}
@@ -206,11 +238,17 @@ public class ModulePath implements ModuleFinder {
if (mref != null) {
String name = mref.descriptor().name();
return Collections.singletonMap(name, mref);
- } else {
- // skipped
- return Collections.emptyMap();
}
+ // not recognized
+ String msg;
+ if (!isLinkPhase && entry.toString().endsWith(".jmod")) {
+ msg = "JMOD format not supported at execution time";
+ } else {
+ msg = "Module format not recognized";
+ }
+ throw new FindException(msg + ": " + entry);
+
} catch (IOException ioe) {
throw new FindException(ioe);
}
@@ -266,14 +304,11 @@ public class ModulePath implements ModuleFinder {
/**
- * Locates a packaged or exploded module, returning a {@code ModuleReference}
- * to the module. Returns {@code null} if the entry is skipped because it is
- * to a directory that does not contain a module-info.class or it's a hidden
- * file.
+ * Reads a packaged or exploded module, returning a {@code ModuleReference}
+ * to the module. Returns {@code null} if the entry is not recognized.
*
* @throws IOException if an I/O error occurs
- * @throws FindException if the file is not recognized as a module or an
- * error occurs parsing its module descriptor
+ * @throws FindException if an error occurs parsing its module descriptor
*/
private ModuleReference readModule(Path entry, BasicFileAttributes attrs)
throws IOException
@@ -282,24 +317,16 @@ public class ModulePath implements ModuleFinder {
if (attrs.isDirectory()) {
return readExplodedModule(entry); // may return null
- }
-
- String fn = entry.getFileName().toString();
- if (attrs.isRegularFile()) {
- if (fn.endsWith(".jar")) {
- return readJar(entry);
- } else if (fn.endsWith(".jmod")) {
- if (isLinkPhase)
- return readJMod(entry);
- throw new FindException("JMOD files not supported: " + entry);
- }
- }
-
- // skip hidden files
- if (fn.startsWith(".") || Files.isHidden(entry)) {
- return null;
} else {
- throw new FindException("Unrecognized module: " + entry);
+ String fn = entry.getFileName().toString();
+ if (attrs.isRegularFile()) {
+ if (fn.endsWith(".jar")) {
+ return readJar(entry);
+ } else if (isLinkPhase && fn.endsWith(".jmod")) {
+ return readJMod(entry);
+ }
+ }
+ return null;
}
} catch (InvalidModuleDescriptorException e) {
@@ -327,7 +354,7 @@ public class ModulePath implements ModuleFinder {
}
}
- // -- jmod files --
+ // -- JMOD files --
private Set jmodPackages(JmodFile jf) {
return jf.stream()
@@ -339,7 +366,7 @@ public class ModulePath implements ModuleFinder {
}
/**
- * Returns a {@code ModuleReference} to a module in jmod file on the
+ * Returns a {@code ModuleReference} to a module in JMOD file on the
* file system.
*
* @throws IOException
@@ -362,7 +389,7 @@ public class ModulePath implements ModuleFinder {
/**
* Returns the service type corresponding to the name of a services
- * configuration file if it is a valid Java identifier.
+ * configuration file if it is a legal type name.
*
* For example, if called with "META-INF/services/p.S" then this method
* returns a container with the value "p.S".
@@ -374,7 +401,7 @@ public class ModulePath implements ModuleFinder {
String prefix = cf.substring(0, index);
if (prefix.equals(SERVICES_PREFIX)) {
String sn = cf.substring(index);
- if (Checks.isJavaIdentifier(sn))
+ if (Checks.isClassName(sn))
return Optional.of(sn);
}
}
@@ -403,11 +430,10 @@ public class ModulePath implements ModuleFinder {
*
* 1. The module name (and optionally the version) is derived from the file
* name of the JAR file
- * 2. All packages are exported and open
- * 3. It has no non-exported/non-open packages
- * 4. The contents of any META-INF/services configuration files are mapped
+ * 2. All packages are derived from the .class files in the JAR file
+ * 3. The contents of any META-INF/services configuration files are mapped
* to "provides" declarations
- * 5. The Main-Class attribute in the main attributes of the JAR manifest
+ * 4. The Main-Class attribute in the main attributes of the JAR manifest
* is mapped to the module descriptor mainClass
*/
private ModuleDescriptor deriveModuleDescriptor(JarFile jf)
@@ -443,9 +469,7 @@ public class ModulePath implements ModuleFinder {
mn = cleanModuleName(mn);
// Builder throws IAE if module name is empty or invalid
- ModuleDescriptor.Builder builder
- = ModuleDescriptor.automaticModule(mn)
- .requires(Set.of(Requires.Modifier.MANDATED), "java.base");
+ ModuleDescriptor.Builder builder = ModuleDescriptor.newAutomaticModule(mn);
if (vs != null)
builder.version(vs);
@@ -453,17 +477,22 @@ public class ModulePath implements ModuleFinder {
Map> map = VersionedStream.stream(jf)
.filter(e -> !e.isDirectory())
.map(JarEntry::getName)
+ .filter(e -> (e.endsWith(".class") ^ e.startsWith(SERVICES_PREFIX)))
.collect(Collectors.partitioningBy(e -> e.startsWith(SERVICES_PREFIX),
Collectors.toSet()));
- Set resources = map.get(Boolean.FALSE);
+ Set classFiles = map.get(Boolean.FALSE);
Set configFiles = map.get(Boolean.TRUE);
- // all packages are exported and open
- resources.stream()
+
+ // the packages containing class files
+ Set packages = classFiles.stream()
.map(this::toPackageName)
.flatMap(Optional::stream)
.distinct()
- .forEach(pn -> builder.exports(pn).opens(pn));
+ .collect(Collectors.toSet());
+
+ // all packages are exported and open
+ builder.packages(packages);
// map names of service configuration files to service names
Set serviceNames = configFiles.stream()
@@ -481,6 +510,11 @@ public class ModulePath implements ModuleFinder {
String cn;
while ((cn = nextLine(reader)) != null) {
if (cn.length() > 0) {
+ String pn = packageName(cn);
+ if (!packages.contains(pn)) {
+ String msg = "Provider class " + cn + " not in module";
+ throw new IOException(msg);
+ }
providerClasses.add(cn);
}
}
@@ -494,8 +528,15 @@ public class ModulePath implements ModuleFinder {
if (man != null) {
Attributes attrs = man.getMainAttributes();
String mainClass = attrs.getValue(Attributes.Name.MAIN_CLASS);
- if (mainClass != null)
- builder.mainClass(mainClass.replace("/", "."));
+ if (mainClass != null) {
+ mainClass = mainClass.replace("/", ".");
+ String pn = packageName(mainClass);
+ if (!packages.contains(pn)) {
+ String msg = "Main-Class " + mainClass + " not in module";
+ throw new IOException(msg);
+ }
+ builder.mainClass(mainClass);
+ }
}
return builder.build();
@@ -569,10 +610,10 @@ public class ModulePath implements ModuleFinder {
try {
ModuleDescriptor md = deriveModuleDescriptor(jf);
attrs = new ModuleInfo.Attributes(md, null, null);
- } catch (IllegalArgumentException iae) {
+ } catch (IllegalArgumentException e) {
throw new FindException(
"Unable to derive module descriptor for: "
- + jf.getName(), iae);
+ + jf.getName(), e);
}
} else {
@@ -580,7 +621,7 @@ public class ModulePath implements ModuleFinder {
() -> jarPackages(jf));
}
- return ModuleReferences.newJarModule(attrs, file);
+ return ModuleReferences.newJarModule(attrs, patcher, file);
}
}
@@ -617,7 +658,15 @@ public class ModulePath implements ModuleFinder {
// for now
return null;
}
- return ModuleReferences.newExplodedModule(attrs, dir);
+ return ModuleReferences.newExplodedModule(attrs, patcher, dir);
+ }
+
+ /**
+ * Maps a type name to its package name.
+ */
+ private static String packageName(String cn) {
+ int index = cn.lastIndexOf('.');
+ return (index == -1) ? "" : cn.substring(0, index);
}
/**
@@ -629,19 +678,18 @@ public class ModulePath implements ModuleFinder {
*/
private Optional toPackageName(String name) {
assert !name.endsWith("/");
-
int index = name.lastIndexOf("/");
if (index == -1) {
if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
throw new IllegalArgumentException(name
- + " found in top-level directory:"
+ + " found in top-level directory"
+ " (unnamed package not allowed in module)");
}
return Optional.empty();
}
String pn = name.substring(0, index).replace('/', '.');
- if (Checks.isJavaIdentifier(pn)) {
+ if (Checks.isPackageName(pn)) {
return Optional.of(pn);
} else {
// not a valid package name
@@ -654,7 +702,7 @@ public class ModulePath implements ModuleFinder {
* name.
*
* @throws IllegalArgumentException if the name is a class file in
- * the top-level directory (and it's not module-info.class)
+ * the top-level directory (and it's not module-info.class)
*/
private Optional toPackageName(Path file) {
assert file.getRoot() == null;
@@ -664,14 +712,14 @@ public class ModulePath implements ModuleFinder {
String name = file.toString();
if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
throw new IllegalArgumentException(name
- + " found in in top-level directory"
+ + " found in top-level directory"
+ " (unnamed package not allowed in module)");
}
return Optional.empty();
}
String pn = parent.toString().replace(File.separatorChar, '.');
- if (Checks.isJavaIdentifier(pn)) {
+ if (Checks.isPackageName(pn)) {
return Optional.of(pn);
} else {
// not a valid package name
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferenceImpl.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferenceImpl.java
index 2ab42bdb4a2..f861b294aef 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferenceImpl.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferenceImpl.java
@@ -163,7 +163,14 @@ public class ModuleReferenceImpl extends ModuleReference {
@Override
public String toString() {
- return super.toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append("[module ");
+ sb.append(descriptor().name());
+ sb.append(", location=");
+ sb.append(location().orElseThrow(() -> new InternalError()));
+ if (isPatched()) sb.append(" (patched)");
+ sb.append("]");
+ return sb.toString();
}
}
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java
index a2aff8f76be..2e2af727599 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java
@@ -36,7 +36,6 @@ import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -51,7 +50,7 @@ import java.util.stream.Stream;
import java.util.zip.ZipFile;
import jdk.internal.jmod.JmodFile;
-import jdk.internal.misc.JavaLangAccess;
+import jdk.internal.loader.ResourceHelper;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.ModuleHashes.HashSupplier;
import jdk.internal.util.jar.VersionedStream;
@@ -65,20 +64,16 @@ import sun.net.www.ParseUtil;
*/
class ModuleReferences {
-
- private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
-
private ModuleReferences() { }
/**
- * Creates a ModuleReference to a module or to patched module when
- * creating modules for the boot Layer and --patch-module is specified.
+ * Creates a ModuleReference to a possibly-patched module
*/
private static ModuleReference newModule(ModuleInfo.Attributes attrs,
URI uri,
Supplier supplier,
+ ModulePatcher patcher,
HashSupplier hasher) {
-
ModuleReference mref = new ModuleReferenceImpl(attrs.descriptor(),
uri,
supplier,
@@ -86,38 +81,42 @@ class ModuleReferences {
attrs.recordedHashes(),
hasher,
attrs.moduleResolution());
- if (JLA.getBootLayer() == null)
- mref = ModuleBootstrap.patcher().patchIfNeeded(mref);
+ if (patcher != null)
+ mref = patcher.patchIfNeeded(mref);
return mref;
}
/**
- * Creates a ModuleReference to a module packaged as a modular JAR.
+ * Creates a ModuleReference to a possibly-patched module in a modular JAR.
*/
- static ModuleReference newJarModule(ModuleInfo.Attributes attrs, Path file) {
+ static ModuleReference newJarModule(ModuleInfo.Attributes attrs,
+ ModulePatcher patcher,
+ Path file) {
URI uri = file.toUri();
Supplier supplier = () -> new JarModuleReader(file, uri);
HashSupplier hasher = (a) -> ModuleHashes.computeHash(file, a);
- return newModule(attrs, uri, supplier, hasher);
+ return newModule(attrs, uri, supplier, patcher, hasher);
}
/**
- * Creates a ModuleReference to a module packaged as a JMOD.
+ * Creates a ModuleReference to a module in a JMOD file.
*/
static ModuleReference newJModModule(ModuleInfo.Attributes attrs, Path file) {
URI uri = file.toUri();
Supplier supplier = () -> new JModModuleReader(file, uri);
HashSupplier hasher = (a) -> ModuleHashes.computeHash(file, a);
- return newModule(attrs, uri, supplier, hasher);
+ return newModule(attrs, uri, supplier, null, hasher);
}
/**
- * Creates a ModuleReference to an exploded module.
+ * Creates a ModuleReference to a possibly-patched exploded module.
*/
- static ModuleReference newExplodedModule(ModuleInfo.Attributes attrs, Path dir) {
+ static ModuleReference newExplodedModule(ModuleInfo.Attributes attrs,
+ ModulePatcher patcher,
+ Path dir) {
Supplier supplier = () -> new ExplodedModuleReader(dir);
- return newModule(attrs, dir.toUri(), supplier, null);
+ return newModule(attrs, dir.toUri(), supplier, patcher, null);
}
@@ -243,7 +242,8 @@ class ModuleReferences {
}
private JarEntry getEntry(String name) {
- return jf.getJarEntry(Objects.requireNonNull(name));
+ JarEntry entry = jf.getJarEntry(Objects.requireNonNull(name));
+ return (entry == null || entry.isDirectory()) ? null : entry;
}
@Override
@@ -369,21 +369,6 @@ class ModuleReferences {
}
}
- /**
- * Returns a Path to access to the given resource.
- */
- private Path toPath(String name) {
- Path path = Paths.get(name.replace('/', File.separatorChar));
- if (path.getRoot() == null) {
- return dir.resolve(path);
- } else {
- // drop the root component so that the resource is
- // located relative to the module directory
- int n = path.getNameCount();
- return (n > 0) ? dir.resolve(path.subpath(0, n)) : null;
- }
- }
-
/**
* Throws IOException if the module reader is closed;
*/
@@ -391,11 +376,27 @@ class ModuleReferences {
if (closed) throw new IOException("ModuleReader is closed");
}
+ /**
+ * Returns a Path to access the given resource. Returns null if the
+ * resource name does not convert to a file path that locates a regular
+ * file in the module.
+ */
+ private Path toFilePath(String name) {
+ Path path = ResourceHelper.toFilePath(name);
+ if (path != null) {
+ Path file = dir.resolve(path);
+ if (Files.isRegularFile(file)) {
+ return file;
+ }
+ }
+ return null;
+ }
+
@Override
public Optional find(String name) throws IOException {
ensureOpen();
- Path path = toPath(name);
- if (path != null && Files.isRegularFile(path)) {
+ Path path = toFilePath(name);
+ if (path != null) {
try {
return Optional.of(path.toUri());
} catch (IOError e) {
@@ -409,8 +410,8 @@ class ModuleReferences {
@Override
public Optional open(String name) throws IOException {
ensureOpen();
- Path path = toPath(name);
- if (path != null && Files.isRegularFile(path)) {
+ Path path = toFilePath(name);
+ if (path != null) {
return Optional.of(Files.newInputStream(path));
} else {
return Optional.empty();
@@ -420,8 +421,8 @@ class ModuleReferences {
@Override
public Optional read(String name) throws IOException {
ensureOpen();
- Path path = toPath(name);
- if (path != null && Files.isRegularFile(path)) {
+ Path path = toFilePath(name);
+ if (path != null) {
return Optional.of(ByteBuffer.wrap(Files.readAllBytes(path)));
} else {
return Optional.empty();
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java b/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java
index 9f68cfbc421..485d2e130b5 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/Modules.java
@@ -82,8 +82,8 @@ public class Modules {
String name,
Set packages)
{
- ModuleDescriptor descriptor = ModuleDescriptor.module(name)
- .contains(packages)
+ ModuleDescriptor descriptor = ModuleDescriptor.newModule(name)
+ .packages(packages)
.build();
return JLRMA.defineModule(loader, descriptor, null);
@@ -185,7 +185,8 @@ public class Modules {
/**
* Adds a package to a module's content.
*
- * This method is a no-op if the module already contains the package.
+ * This method is a no-op if the module already contains the package or the
+ * module is an unnamed module.
*/
public static void addPackage(Module m, String pn) {
JLRMA.addPackage(m, pn);
diff --git a/jdk/src/java.base/share/classes/jdk/internal/module/SystemModuleFinder.java b/jdk/src/java.base/share/classes/jdk/internal/module/SystemModuleFinder.java
index 5ec0a62ca69..a7ee7ffe74f 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/module/SystemModuleFinder.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/module/SystemModuleFinder.java
@@ -80,8 +80,6 @@ public class SystemModuleFinder implements ModuleFinder {
= PerfCounter.newPerfCounter("jdk.module.finder.jimage.packages");
private static final PerfCounter exportsCount
= PerfCounter.newPerfCounter("jdk.module.finder.jimage.exports");
- // ImageReader used to access all modules in the image
- private static final ImageReader imageReader;
// singleton finder to find modules in the run-time images
private static final SystemModuleFinder INSTANCE;
@@ -96,13 +94,28 @@ public class SystemModuleFinder implements ModuleFinder {
*/
static {
long t0 = System.nanoTime();
- imageReader = ImageReaderFactory.getImageReader();
INSTANCE = new SystemModuleFinder();
initTime.addElapsedTimeFrom(t0);
}
+ /**
+ * Holder class for the ImageReader
+ */
+ private static class SystemImage {
+ static final ImageReader READER;
+ static {
+ long t0 = System.nanoTime();
+ READER = ImageReaderFactory.getImageReader();
+ initTime.addElapsedTimeFrom(t0);
+ }
+
+ static ImageReader reader() {
+ return READER;
+ }
+ }
+
private static boolean isFastPathSupported() {
return SystemModules.MODULE_NAMES.length > 0;
}
@@ -114,7 +127,7 @@ public class SystemModuleFinder implements ModuleFinder {
// this happens when java.base is patched with java.base
// from an exploded image
- return imageReader.getModuleNames();
+ return SystemImage.reader().getModuleNames();
}
// the set of modules in the run-time image
@@ -151,6 +164,7 @@ public class SystemModuleFinder implements ModuleFinder {
descriptors = new ModuleDescriptor[n];
recordedHashes = new ModuleHashes[n];
moduleResolutions = new ModuleResolution[n];
+ ImageReader imageReader = SystemImage.reader();
for (int i = 0; i < names.length; i++) {
String mn = names[i];
ImageLocation loc = imageReader.findLocation(mn, "module-info.class");
@@ -291,6 +305,7 @@ public class SystemModuleFinder implements ModuleFinder {
Objects.requireNonNull(name);
if (closed)
throw new IOException("ModuleReader is closed");
+ ImageReader imageReader = SystemImage.reader();
if (imageReader != null) {
return imageReader.findLocation(module, name);
} else {
@@ -330,7 +345,7 @@ public class SystemModuleFinder implements ModuleFinder {
public Optional read(String name) throws IOException {
ImageLocation location = findImageLocation(name);
if (location != null) {
- return Optional.of(imageReader.getResourceBuffer(location));
+ return Optional.of(SystemImage.reader().getResourceBuffer(location));
} else {
return Optional.empty();
}
@@ -372,7 +387,7 @@ public class SystemModuleFinder implements ModuleFinder {
stack = new ArrayDeque<>();
// push the root node to the stack to get started
- ImageReader.Node dir = imageReader.findNode(moduleRoot);
+ ImageReader.Node dir = SystemImage.reader().findNode(moduleRoot);
if (dir == null || !dir.isDirectory())
throw new IOException(moduleRoot + " not a directory");
stack.push(dir);
@@ -390,7 +405,7 @@ public class SystemModuleFinder implements ModuleFinder {
String name = node.getName();
if (node.isDirectory()) {
// build node
- ImageReader.Node dir = imageReader.findNode(name);
+ ImageReader.Node dir = SystemImage.reader().findNode(name);
assert dir.isDirectory();
stack.push(dir);
} else {
diff --git a/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java b/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java
index 9a410049188..61969590d92 100644
--- a/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2013, 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
@@ -211,15 +211,7 @@ public class Reflection {
if (currentModule == memberModule)
return true; // same module (named or unnamed)
- // memberClass may be primitive or array class
- Class> c = memberClass;
- while (c.isArray()) {
- c = c.getComponentType();
- }
- if (c.isPrimitive())
- return true;
-
- String pkg = c.getPackageName();
+ String pkg = memberClass.getPackageName();
boolean allowed = memberModule.isExported(pkg, currentModule);
if (allowed && memberModule.isNamed() && printStackTraceWhenAccessSucceeds()) {
if (!SharedSecrets.getJavaLangReflectModuleAccess()
@@ -237,10 +229,6 @@ public class Reflection {
private static boolean isSameClassPackage(Class> c1, Class> c2) {
if (c1.getClassLoader() != c2.getClassLoader())
return false;
- while (c1.isArray())
- c1 = c1.getComponentType();
- while (c2.isArray())
- c2 = c2.getComponentType();
return Objects.equals(c1.getPackageName(), c2.getPackageName());
}
@@ -378,12 +366,6 @@ public class Reflection {
}
}
- public static void enableStackTraces() {
- printStackWhenAccessFails = true;
- printStackWhenAccessSucceeds = true;
- printStackPropertiesSet = true;
- }
-
public static boolean printStackTraceWhenAccessFails() {
ensurePrintStackPropertiesSet();
return printStackWhenAccessFails;
@@ -413,11 +395,7 @@ public class Reflection {
if (m2.isNamed())
memberSuffix = " (in " + m2 + ")";
- Class> c = memberClass;
- while (c.isArray()) {
- c = c.getComponentType();
- }
- String memberPackageName = c.getPackageName();
+ String memberPackageName = memberClass.getPackageName();
String msg = currentClass + currentSuffix + " cannot access ";
if (m2.isExported(memberPackageName, m1)) {
diff --git a/jdk/src/java.base/share/classes/module-info.java b/jdk/src/java.base/share/classes/module-info.java
index 185f8f2a1d1..2923ad5ee7a 100644
--- a/jdk/src/java.base/share/classes/module-info.java
+++ b/jdk/src/java.base/share/classes/module-info.java
@@ -25,6 +25,8 @@
/**
* Defines the foundational APIs of the Java SE Platform.
+ *
+ * @since 9
*/
module java.base {
@@ -237,8 +239,7 @@ module java.base {
java.management.rmi,
java.rmi,
java.sql.rowset,
- java.xml,
- java.xml.ws;
+ java.xml;
exports sun.security.action to
java.desktop,
java.security.jgss;
diff --git a/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java b/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
index 9c46aad018f..c3633ff8aab 100644
--- a/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
+++ b/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -39,6 +39,7 @@ public class VerifyAccess {
private VerifyAccess() { } // cannot instantiate
+ private static final int UNCONDITIONAL_ALLOWED = java.lang.invoke.MethodHandles.Lookup.UNCONDITIONAL;
private static final int MODULE_ALLOWED = java.lang.invoke.MethodHandles.Lookup.MODULE;
private static final int PACKAGE_ONLY = 0;
private static final int PACKAGE_ALLOWED = java.lang.invoke.MethodHandles.Lookup.PACKAGE;
@@ -92,7 +93,7 @@ public class VerifyAccess {
int allowedModes) {
if (allowedModes == 0) return false;
assert((allowedModes & PUBLIC) != 0 &&
- (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED|MODULE_ALLOWED)) == 0);
+ (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED|MODULE_ALLOWED|UNCONDITIONAL_ALLOWED)) == 0);
// The symbolic reference class (refc) must always be fully verified.
if (!isClassAccessible(refc, lookupClass, allowedModes)) {
return false;
@@ -173,7 +174,7 @@ public class VerifyAccess {
int allowedModes) {
if (allowedModes == 0) return false;
assert((allowedModes & PUBLIC) != 0 &&
- (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED|MODULE_ALLOWED)) == 0);
+ (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED|MODULE_ALLOWED|UNCONDITIONAL_ALLOWED)) == 0);
int mods = getClassModifiers(refc);
if (isPublic(mods)) {
@@ -191,22 +192,17 @@ public class VerifyAccess {
(lookupModule == refModule))
return true;
- // check readability
- if (lookupModule.canRead(refModule)) {
+ // check readability when UNCONDITIONAL not allowed
+ if (((allowedModes & UNCONDITIONAL_ALLOWED) != 0)
+ || lookupModule.canRead(refModule)) {
// check that refc is in an exported package
- Class> c = refc;
- while (c.isArray()) {
- c = c.getComponentType();
- }
- if (c.isPrimitive())
- return true;
if ((allowedModes & MODULE_ALLOWED) != 0) {
- if (refModule.isExported(c.getPackageName(), lookupModule))
+ if (refModule.isExported(refc.getPackageName(), lookupModule))
return true;
} else {
// exported unconditionally
- if (refModule.isExported(c.getPackageName()))
+ if (refModule.isExported(refc.getPackageName()))
return true;
}
diff --git a/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java b/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java
index ee8f311d2e4..c3410489613 100644
--- a/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java
+++ b/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -591,8 +591,8 @@ public final class LauncherHelper {
c = Class.forName(m, cn);
}
} catch (LinkageError le) {
- abort(null, "java.launcher.module.error3",
- mainClass, m.getName(), le.getLocalizedMessage());
+ abort(null, "java.launcher.module.error3", mainClass, m.getName(),
+ le.getClass().getName() + ": " + le.getLocalizedMessage());
}
if (c == null) {
abort(null, "java.launcher.module.error2", mainClass, mainModule);
@@ -638,14 +638,17 @@ public final class LauncherHelper {
String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC);
mainClass = Class.forName(ncn, false, scl);
} catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
- abort(cnfe1, "java.launcher.cls.error1", cn);
+ abort(cnfe1, "java.launcher.cls.error1", cn,
+ cnfe1.getClass().getCanonicalName(), cnfe1.getMessage());
}
} else {
- abort(cnfe, "java.launcher.cls.error1", cn);
+ abort(cnfe, "java.launcher.cls.error1", cn,
+ cnfe.getClass().getCanonicalName(), cnfe.getMessage());
}
}
} catch (LinkageError le) {
- abort(le, "java.launcher.cls.error6", cn, le.getLocalizedMessage());
+ abort(le, "java.launcher.cls.error6", cn,
+ le.getClass().getName() + ": " + le.getLocalizedMessage());
}
return mainClass;
}
@@ -966,6 +969,10 @@ public final class LauncherHelper {
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)
diff --git a/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties b/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties
index 23439deb377..932a69c3bdf 100644
--- a/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties
+++ b/jdk/src/java.base/share/classes/sun/launcher/resources/launcher.properties
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -175,7 +175,8 @@ The following options are Mac OS X specific:\n\
\ override default icon displayed in dock\n\n
java.launcher.cls.error1=\
- Error: Could not find or load main class {0}
+ Error: Could not find or load main class {0}\n\
+ Caused by: {1}: {2}
java.launcher.cls.error2=\
Error: Main method is not {0} in class {1}, please define the main method as:\n\
\ public static void main(String[] args)
diff --git a/jdk/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java b/jdk/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
index 88e6f5b7caa..893bb55c10a 100644
--- a/jdk/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
+++ b/jdk/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
@@ -32,7 +32,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.AccessController;
import java.security.Permission;
+import java.security.PrivilegedAction;
import jdk.internal.jimage.ImageLocation;
import jdk.internal.jimage.ImageReader;
@@ -51,7 +53,11 @@ import sun.security.action.GetPropertyAction;
public class JavaRuntimeURLConnection extends URLConnection {
// ImageReader to access resources in jimage
- private static final ImageReader reader = ImageReaderFactory.getImageReader();
+ private static final ImageReader reader;
+ static {
+ PrivilegedAction pa = ImageReaderFactory::getImageReader;
+ reader = AccessController.doPrivileged(pa);
+ }
// the module and resource name in the URL
private final String module;
diff --git a/jdk/src/java.base/share/classes/sun/nio/cs/StandardCharsets.java.template b/jdk/src/java.base/share/classes/sun/nio/cs/StandardCharsets.java.template
index f2eeaaafdc3..8969ef1a04b 100644
--- a/jdk/src/java.base/share/classes/sun/nio/cs/StandardCharsets.java.template
+++ b/jdk/src/java.base/share/classes/sun/nio/cs/StandardCharsets.java.template
@@ -32,7 +32,6 @@ package sun.nio.cs;
import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import java.util.Iterator;
-import java.util.Locale;
import java.util.Map;
import sun.security.action.GetPropertyAction;
@@ -44,13 +43,13 @@ public class StandardCharsets extends CharsetProvider {
_INCLUDE_CACHE_MAP_
// Maps canonical names to class names
- private Map classMap;
+ private final Map classMap;
// Maps alias names to canonical names
- private Map aliasMap;
+ private final Map aliasMap;
// Maps canonical names to cached instances
- private Map cache;
+ private final Map cache;
- private String packagePrefix = "sun.nio.cs";
+ private static final String packagePrefix = "sun.nio.cs";
public StandardCharsets() {
this.aliasMap = new Aliases();
@@ -102,10 +101,16 @@ public class StandardCharsets extends CharsetProvider {
if (cln == null)
return null;
- if (cln.equals("US_ASCII")) {
- cs = new US_ASCII();
- cache.put(csn, cs);
- return cs;
+ // As all charset class names added to classMap are string literals we
+ // can check identity here as an optimization
+ if (cln == "US_ASCII") {
+ return cache(csn, new US_ASCII());
+ }
+ if (cln == "ISO_8859_1") {
+ return cache(csn, new ISO_8859_1());
+ }
+ if (cln == "UTF_8") {
+ return cache(csn, new UTF_8());
}
// Instantiate the charset and cache it
@@ -114,9 +119,7 @@ public class StandardCharsets extends CharsetProvider {
Object o = Class.forName(packagePrefix + "." + cln,
true,
this.getClass().getClassLoader()).newInstance();
- cs = (Charset)o;
- cache.put(csn, cs);
- return cs;
+ return cache(csn, (Charset)o);
} catch (ClassNotFoundException |
IllegalAccessException |
InstantiationException x) {
@@ -124,6 +127,11 @@ public class StandardCharsets extends CharsetProvider {
}
}
+ private Charset cache(String csn, Charset cs) {
+ cache.put(csn, cs);
+ return cs;
+ }
+
public final Charset charsetForName(String charsetName) {
synchronized (this) {
return lookup(canonicalize(charsetName));
diff --git a/jdk/src/java.base/share/classes/sun/nio/cs/US_ASCII.java b/jdk/src/java.base/share/classes/sun/nio/cs/US_ASCII.java
index 39b7df07d85..e85ce61ccd8 100644
--- a/jdk/src/java.base/share/classes/sun/nio/cs/US_ASCII.java
+++ b/jdk/src/java.base/share/classes/sun/nio/cs/US_ASCII.java
@@ -31,7 +31,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
-import java.util.Arrays;
public class US_ASCII
extends Charset
diff --git a/jdk/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java b/jdk/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java
index ed69ba3d8b9..6efd90d0670 100644
--- a/jdk/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java
+++ b/jdk/src/java.base/share/classes/sun/security/pkcs/SignerInfo.java
@@ -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
@@ -37,6 +37,7 @@ import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.Timestamp;
+import java.security.cert.CertPathValidatorException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.CertPath;
@@ -48,6 +49,7 @@ import java.util.EnumSet;
import java.util.Set;
import sun.security.timestamp.TimestampToken;
+import sun.security.util.ConstraintsParameters;
import sun.security.util.Debug;
import sun.security.util.DerEncoder;
import sun.security.util.DerInputStream;
@@ -321,6 +323,8 @@ public class SignerInfo implements DerEncoder {
data = content.getContentBytes();
}
+ ConstraintsParameters cparams =
+ new ConstraintsParameters(timestamp);
String digestAlgname = getDigestAlgorithmId().getName();
byte[] dataSigned;
@@ -347,11 +351,11 @@ public class SignerInfo implements DerEncoder {
if (messageDigest == null) // fail if there is no message digest
return null;
- // check that algorithm is not restricted
- if (!JAR_DISABLED_CHECK.permits(DIGEST_PRIMITIVE_SET,
- digestAlgname, null)) {
- throw new SignatureException("Digest check failed. " +
- "Disabled algorithm used: " + digestAlgname);
+ // check that digest algorithm is not restricted
+ try {
+ JAR_DISABLED_CHECK.permits(digestAlgname, cparams);
+ } catch (CertPathValidatorException e) {
+ throw new SignatureException(e.getMessage(), e);
}
MessageDigest md = MessageDigest.getInstance(digestAlgname);
@@ -385,17 +389,18 @@ public class SignerInfo implements DerEncoder {
String algname = AlgorithmId.makeSigAlg(
digestAlgname, encryptionAlgname);
- // check that algorithm is not restricted
- if (!JAR_DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, algname, null)) {
- throw new SignatureException("Signature check failed. " +
- "Disabled algorithm used: " + algname);
+ // check that jar signature algorithm is not restricted
+ try {
+ JAR_DISABLED_CHECK.permits(algname, cparams);
+ } catch (CertPathValidatorException e) {
+ throw new SignatureException(e.getMessage(), e);
}
X509Certificate cert = getCertificate(block);
- PublicKey key = cert.getPublicKey();
if (cert == null) {
return null;
}
+ PublicKey key = cert.getPublicKey();
// check if the public key is restricted
if (!JAR_DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) {
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java
index 90559598aee..0be627b84ac 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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,6 +28,7 @@ package sun.security.provider.certpath;
import java.security.AlgorithmConstraints;
import java.security.CryptoPrimitive;
import java.security.Timestamp;
+import java.security.cert.CertPathValidator;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -53,9 +54,10 @@ import java.security.interfaces.DSAPublicKey;
import java.security.spec.DSAPublicKeySpec;
import sun.security.util.AnchorCertificates;
-import sun.security.util.CertConstraintParameters;
+import sun.security.util.ConstraintsParameters;
import sun.security.util.Debug;
import sun.security.util.DisabledAlgorithmConstraints;
+import sun.security.validator.Validator;
import sun.security.x509.X509CertImpl;
import sun.security.x509.X509CRLImpl;
import sun.security.x509.AlgorithmId;
@@ -79,6 +81,7 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
private final Date pkixdate;
private PublicKey prevPubKey;
private final Timestamp jarTimestamp;
+ private final String variant;
private static final Set SIGNATURE_PRIMITIVE_SET =
Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE));
@@ -109,64 +112,36 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
*
* @param anchor the trust anchor selected to validate the target
* certificate
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*/
- public AlgorithmChecker(TrustAnchor anchor) {
- this(anchor, certPathDefaultConstraints, null);
- }
-
- /**
- * Create a new {@code AlgorithmChecker} with the
- * given {@code TrustAnchor} and {@code AlgorithmConstraints}.
- *
- * @param anchor the trust anchor selected to validate the target
- * certificate
- * @param constraints the algorithm constraints (or null)
- *
- * @throws IllegalArgumentException if the {@code anchor} is null
- */
- public AlgorithmChecker(TrustAnchor anchor,
- AlgorithmConstraints constraints) {
- this(anchor, constraints, null);
- }
-
- /**
- * Create a new {@code AlgorithmChecker} with the
- * given {@code AlgorithmConstraints}.
- *
- * Note that this constructor will be used to check a certification
- * path where the trust anchor is unknown, or a certificate list which may
- * contain the trust anchor. This constructor is used by SunJSSE.
- *
- * @param constraints the algorithm constraints (or null)
- */
- public AlgorithmChecker(AlgorithmConstraints constraints) {
- this.prevPubKey = null;
- this.trustedPubKey = null;
- this.constraints = constraints;
- this.pkixdate = null;
- this.jarTimestamp = null;
+ public AlgorithmChecker(TrustAnchor anchor, String variant) {
+ this(anchor, certPathDefaultConstraints, null, variant);
}
/**
* Create a new {@code AlgorithmChecker} with the given
- * {@code Timestamp}.
+ * {@code AlgorithmConstraints}, {@code Timestamp}, and/or {@code Variant}.
*
- * Note that this constructor will be used to check a certification
- * path for signed JAR files that are timestamped.
+ * Note that this constructor can initialize a variation of situations where
+ * the AlgorithmConstraints, Timestamp, or Variant maybe known.
*
+ * @param constraints the algorithm constraints (or null)
* @param jarTimestamp Timestamp passed for JAR timestamp constraint
* checking. Set to null if not applicable.
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*/
- public AlgorithmChecker(Timestamp jarTimestamp) {
+ public AlgorithmChecker(AlgorithmConstraints constraints,
+ Timestamp jarTimestamp, String variant) {
this.prevPubKey = null;
this.trustedPubKey = null;
- this.constraints = certPathDefaultConstraints;
- if (jarTimestamp == null) {
- throw new IllegalArgumentException(
- "Timestamp cannot be null");
- }
- this.pkixdate = jarTimestamp.getTimestamp();
+ this.constraints = (constraints == null ? certPathDefaultConstraints :
+ constraints);
+ this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
+ null);
this.jarTimestamp = jarTimestamp;
+ this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
/**
@@ -178,12 +153,13 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
* @param constraints the algorithm constraints (or null)
* @param pkixdate Date the constraints are checked against. The value is
* either the PKIXParameter date or null for the current date.
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*
* @throws IllegalArgumentException if the {@code anchor} is null
*/
public AlgorithmChecker(TrustAnchor anchor,
- AlgorithmConstraints constraints,
- Date pkixdate) {
+ AlgorithmConstraints constraints, Date pkixdate, String variant) {
if (anchor != null) {
if (anchor.getTrustedCert() != null) {
@@ -207,6 +183,7 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
this.constraints = constraints;
this.pkixdate = pkixdate;
this.jarTimestamp = null;
+ this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
/**
@@ -217,11 +194,13 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
* certificate
* @param pkixdate Date the constraints are checked against. The value is
* either the PKIXParameter date or null for the current date.
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*
* @throws IllegalArgumentException if the {@code anchor} is null
*/
- public AlgorithmChecker(TrustAnchor anchor, Date pkixdate) {
- this(anchor, certPathDefaultConstraints, pkixdate);
+ public AlgorithmChecker(TrustAnchor anchor, Date pkixdate, String variant) {
+ this(anchor, certPathDefaultConstraints, pkixdate, variant);
}
// Check this 'cert' for restrictions in the AnchorCertificates
@@ -286,6 +265,28 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
null, null, -1, PKIXReason.INVALID_KEY_USAGE);
}
+ X509CertImpl x509Cert;
+ AlgorithmId algorithmId;
+ try {
+ x509Cert = X509CertImpl.toImpl((X509Certificate)cert);
+ algorithmId = (AlgorithmId)x509Cert.get(X509CertImpl.SIG_ALG);
+ } catch (CertificateException ce) {
+ throw new CertPathValidatorException(ce);
+ }
+
+ AlgorithmParameters currSigAlgParams = algorithmId.getParameters();
+ PublicKey currPubKey = cert.getPublicKey();
+ String currSigAlg = ((X509Certificate)cert).getSigAlgName();
+
+ // Check the signature algorithm and parameters against constraints.
+ if (!constraints.permits(SIGNATURE_PRIMITIVE_SET, currSigAlg,
+ currSigAlgParams)) {
+ throw new CertPathValidatorException(
+ "Algorithm constraints check failed on signature " +
+ "algorithm: " + currSigAlg, null, null, -1,
+ BasicReason.ALGORITHM_CONSTRAINED);
+ }
+
// Assume all key usage bits are set if key usage is not present
Set primitives = KU_PRIMITIVE_SET;
@@ -322,101 +323,74 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
}
}
- PublicKey currPubKey = cert.getPublicKey();
+ ConstraintsParameters cp =
+ new ConstraintsParameters((X509Certificate)cert,
+ trustedMatch, pkixdate, jarTimestamp, variant);
+ // Check against local constraints if it is DisabledAlgorithmConstraints
if (constraints instanceof DisabledAlgorithmConstraints) {
- // Check against DisabledAlgorithmConstraints certpath constraints.
- // permits() will throw exception on failure.
- ((DisabledAlgorithmConstraints)constraints).permits(primitives,
- new CertConstraintParameters((X509Certificate)cert,
- trustedMatch, pkixdate, jarTimestamp));
- // If there is no previous key, set one and exit
- if (prevPubKey == null) {
- prevPubKey = currPubKey;
- return;
- }
- }
-
- X509CertImpl x509Cert;
- AlgorithmId algorithmId;
- try {
- x509Cert = X509CertImpl.toImpl((X509Certificate)cert);
- algorithmId = (AlgorithmId)x509Cert.get(X509CertImpl.SIG_ALG);
- } catch (CertificateException ce) {
- throw new CertPathValidatorException(ce);
- }
-
- AlgorithmParameters currSigAlgParams = algorithmId.getParameters();
- String currSigAlg = x509Cert.getSigAlgName();
-
- // If 'constraints' is not of DisabledAlgorithmConstraints, check all
- // everything individually
- if (!(constraints instanceof DisabledAlgorithmConstraints)) {
- // Check the current signature algorithm
- if (!constraints.permits(
- SIGNATURE_PRIMITIVE_SET,
- currSigAlg, currSigAlgParams)) {
- throw new CertPathValidatorException(
- "Algorithm constraints check failed on signature " +
- "algorithm: " + currSigAlg, null, null, -1,
- BasicReason.ALGORITHM_CONSTRAINED);
- }
+ ((DisabledAlgorithmConstraints)constraints).permits(currSigAlg, cp);
+ // DisabledAlgorithmsConstraints does not check primitives, so key
+ // additional key check.
+ } else {
+ // Perform the default constraints checking anyway.
+ certPathDefaultConstraints.permits(currSigAlg, cp);
+ // Call locally set constraints to check key with primitives.
if (!constraints.permits(primitives, currPubKey)) {
throw new CertPathValidatorException(
- "Algorithm constraints check failed on keysize: " +
- sun.security.util.KeyUtil.getKeySize(currPubKey),
+ "Algorithm constraints check failed on key " +
+ currPubKey.getAlgorithm() + " with size of " +
+ sun.security.util.KeyUtil.getKeySize(currPubKey) +
+ "bits",
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
}
+ // If there is no previous key, set one and exit
+ if (prevPubKey == null) {
+ prevPubKey = currPubKey;
+ return;
+ }
+
// Check with previous cert for signature algorithm and public key
- if (prevPubKey != null) {
- if (!constraints.permits(
- SIGNATURE_PRIMITIVE_SET,
- currSigAlg, prevPubKey, currSigAlgParams)) {
- throw new CertPathValidatorException(
+ if (!constraints.permits(
+ SIGNATURE_PRIMITIVE_SET,
+ currSigAlg, prevPubKey, currSigAlgParams)) {
+ throw new CertPathValidatorException(
"Algorithm constraints check failed on " +
"signature algorithm: " + currSigAlg,
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
+ }
+
+ // Inherit key parameters from previous key
+ if (PKIX.isDSAPublicKeyWithoutParams(currPubKey)) {
+ // Inherit DSA parameters from previous key
+ if (!(prevPubKey instanceof DSAPublicKey)) {
+ throw new CertPathValidatorException("Input key is not " +
+ "of a appropriate type for inheriting parameters");
}
- // Inherit key parameters from previous key
- if (PKIX.isDSAPublicKeyWithoutParams(currPubKey)) {
- // Inherit DSA parameters from previous key
- if (!(prevPubKey instanceof DSAPublicKey)) {
- throw new CertPathValidatorException("Input key is not " +
- "of a appropriate type for inheriting parameters");
- }
-
- DSAParams params = ((DSAPublicKey)prevPubKey).getParams();
- if (params == null) {
- throw new CertPathValidatorException(
+ DSAParams params = ((DSAPublicKey)prevPubKey).getParams();
+ if (params == null) {
+ throw new CertPathValidatorException(
"Key parameters missing from public key.");
- }
+ }
- try {
- BigInteger y = ((DSAPublicKey)currPubKey).getY();
- KeyFactory kf = KeyFactory.getInstance("DSA");
- DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
- params.getP(),
- params.getQ(),
- params.getG());
- currPubKey = kf.generatePublic(ks);
- } catch (GeneralSecurityException e) {
- throw new CertPathValidatorException("Unable to generate " +
+ try {
+ BigInteger y = ((DSAPublicKey)currPubKey).getY();
+ KeyFactory kf = KeyFactory.getInstance("DSA");
+ DSAPublicKeySpec ks = new DSAPublicKeySpec(y, params.getP(),
+ params.getQ(), params.getG());
+ currPubKey = kf.generatePublic(ks);
+ } catch (GeneralSecurityException e) {
+ throw new CertPathValidatorException("Unable to generate " +
"key with inherited parameters: " + e.getMessage(), e);
- }
}
}
// reset the previous public key
prevPubKey = currPubKey;
-
- // check the extended key usage, ignore the check now
- // List extendedKeyUsages = x509Cert.getExtendedKeyUsage();
-
- // DO NOT remove any unresolved critical extensions
}
/**
@@ -456,8 +430,10 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
*
* @param key the public key to verify the CRL signature
* @param crl the target CRL
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*/
- static void check(PublicKey key, X509CRL crl)
+ static void check(PublicKey key, X509CRL crl, String variant)
throws CertPathValidatorException {
X509CRLImpl x509CRLImpl = null;
@@ -468,7 +444,7 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
}
AlgorithmId algorithmId = x509CRLImpl.getSigAlgId();
- check(key, algorithmId);
+ check(key, algorithmId, variant);
}
/**
@@ -476,20 +452,16 @@ public final class AlgorithmChecker extends PKIXCertPathChecker {
*
* @param key the public key to verify the CRL signature
* @param algorithmId signature algorithm Algorithm ID
+ * @param variant is the Validator variants of the operation. A null value
+ * passed will set it to Validator.GENERIC.
*/
- static void check(PublicKey key, AlgorithmId algorithmId)
+ static void check(PublicKey key, AlgorithmId algorithmId, String variant)
throws CertPathValidatorException {
String sigAlgName = algorithmId.getName();
AlgorithmParameters sigAlgParams = algorithmId.getParameters();
- if (!certPathDefaultConstraints.permits(
- SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
- throw new CertPathValidatorException(
- "Algorithm constraints check failed on signature algorithm: " +
- sigAlgName + " is disabled",
- null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
- }
+ certPathDefaultConstraints.permits(new ConstraintsParameters(
+ sigAlgName, sigAlgParams, key, variant));
}
-
}
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
index 95ef350a9d3..0f16c646a9c 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2015, 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
@@ -33,6 +33,7 @@ import javax.security.auth.x500.X500Principal;
import java.util.*;
import sun.security.util.Debug;
+import sun.security.validator.Validator;
import static sun.security.x509.PKIXExtensions.*;
import sun.security.x509.*;
@@ -65,6 +66,20 @@ public class DistributionPointFetcher {
* Return the X509CRLs matching this selector. The selector must be
* an X509CRLSelector with certificateChecking set.
*/
+ public static Collection getCRLs(X509CRLSelector selector,
+ boolean signFlag, PublicKey prevKey, String provider,
+ List certStores, boolean[] reasonsMask,
+ Set trustAnchors, Date validity, String variant)
+ throws CertStoreException
+ {
+ return getCRLs(selector, signFlag, prevKey, null, provider, certStores,
+ reasonsMask, trustAnchors, validity, variant);
+ }
+ /**
+ * Return the X509CRLs matching this selector. The selector must be
+ * an X509CRLSelector with certificateChecking set.
+ */
+ // Called by com.sun.deploy.security.RevocationChecker
public static Collection getCRLs(X509CRLSelector selector,
boolean signFlag,
PublicKey prevKey,
@@ -76,7 +91,7 @@ public class DistributionPointFetcher {
throws CertStoreException
{
return getCRLs(selector, signFlag, prevKey, null, provider, certStores,
- reasonsMask, trustAnchors, validity);
+ reasonsMask, trustAnchors, validity, Validator.VAR_GENERIC);
}
/**
@@ -91,7 +106,8 @@ public class DistributionPointFetcher {
List certStores,
boolean[] reasonsMask,
Set trustAnchors,
- Date validity)
+ Date validity,
+ String variant)
throws CertStoreException
{
X509Certificate cert = selector.getCertificateChecking();
@@ -120,7 +136,7 @@ public class DistributionPointFetcher {
DistributionPoint point = t.next();
Collection crls = getCRLs(selector, certImpl,
point, reasonsMask, signFlag, prevKey, prevCert, provider,
- certStores, trustAnchors, validity);
+ certStores, trustAnchors, validity, variant);
results.addAll(crls);
}
if (debug != null) {
@@ -145,7 +161,7 @@ public class DistributionPointFetcher {
X509CertImpl certImpl, DistributionPoint point, boolean[] reasonsMask,
boolean signFlag, PublicKey prevKey, X509Certificate prevCert,
String provider, List certStores,
- Set trustAnchors, Date validity)
+ Set trustAnchors, Date validity, String variant)
throws CertStoreException {
// check for full name
@@ -208,7 +224,7 @@ public class DistributionPointFetcher {
selector.setIssuerNames(null);
if (selector.match(crl) && verifyCRL(certImpl, point, crl,
reasonsMask, signFlag, prevKey, prevCert, provider,
- trustAnchors, certStores, validity)) {
+ trustAnchors, certStores, validity, variant)) {
crls.add(crl);
}
} catch (IOException | CRLException e) {
@@ -316,7 +332,7 @@ public class DistributionPointFetcher {
X509CRL crl, boolean[] reasonsMask, boolean signFlag,
PublicKey prevKey, X509Certificate prevCert, String provider,
Set trustAnchors, List certStores,
- Date validity) throws CRLException, IOException {
+ Date validity, String variant) throws CRLException, IOException {
if (debug != null) {
debug.println("DistributionPointFetcher.verifyCRL: " +
@@ -663,7 +679,7 @@ public class DistributionPointFetcher {
// check the crl signature algorithm
try {
- AlgorithmChecker.check(prevKey, crl);
+ AlgorithmChecker.check(prevKey, crl, variant);
} catch (CertPathValidatorException cpve) {
if (debug != null) {
debug.println("CRL signature algorithm check failed: " + cpve);
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
index 8753072e9d0..dce73028cd0 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -45,6 +45,7 @@ import java.util.Map;
import sun.security.action.GetIntegerAction;
import sun.security.util.Debug;
+import sun.security.validator.Validator;
import sun.security.x509.AccessDescription;
import sun.security.x509.AuthorityInfoAccessExtension;
import sun.security.x509.GeneralName;
@@ -94,42 +95,6 @@ public final class OCSP {
private OCSP() {}
- /**
- * Obtains the revocation status of a certificate using OCSP using the most
- * common defaults. The OCSP responder URI is retrieved from the
- * certificate's AIA extension. The OCSP responder certificate is assumed
- * to be the issuer's certificate (or issued by the issuer CA).
- *
- * @param cert the certificate to be checked
- * @param issuerCert the issuer certificate
- * @return the RevocationStatus
- * @throws IOException if there is an exception connecting to or
- * communicating with the OCSP responder
- * @throws CertPathValidatorException if an exception occurs while
- * encoding the OCSP Request or validating the OCSP Response
- */
- public static RevocationStatus check(X509Certificate cert,
- X509Certificate issuerCert)
- throws IOException, CertPathValidatorException {
- CertId certId = null;
- URI responderURI = null;
- try {
- X509CertImpl certImpl = X509CertImpl.toImpl(cert);
- responderURI = getResponderURI(certImpl);
- if (responderURI == null) {
- throw new CertPathValidatorException
- ("No OCSP Responder URI in certificate");
- }
- certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
- } catch (CertificateException | IOException e) {
- throw new CertPathValidatorException
- ("Exception while encoding OCSPRequest", e);
- }
- OCSPResponse ocspResponse = check(Collections.singletonList(certId),
- responderURI, new OCSPResponse.IssuerInfo(issuerCert), null, null,
- Collections.emptyList());
- return (RevocationStatus)ocspResponse.getSingleResponse(certId);
- }
/**
* Obtains the revocation status of a certificate using OCSP.
@@ -146,6 +111,8 @@ public final class OCSP {
* @throws CertPathValidatorException if an exception occurs while
* encoding the OCSP Request or validating the OCSP Response
*/
+
+ // Called by com.sun.deploy.security.TrustDecider
public static RevocationStatus check(X509Certificate cert,
X509Certificate issuerCert,
URI responderURI,
@@ -154,27 +121,27 @@ public final class OCSP {
throws IOException, CertPathValidatorException
{
return check(cert, issuerCert, responderURI, responderCert, date,
- Collections.emptyList());
+ Collections.emptyList(), Validator.VAR_GENERIC);
}
- // Called by com.sun.deploy.security.TrustDecider
+
public static RevocationStatus check(X509Certificate cert,
- X509Certificate issuerCert,
- URI responderURI,
- X509Certificate responderCert,
- Date date, List extensions)
+ X509Certificate issuerCert, URI responderURI,
+ X509Certificate responderCert, Date date, List extensions,
+ String variant)
throws IOException, CertPathValidatorException
{
- return check(cert, responderURI, null, issuerCert, responderCert, date, extensions);
+ return check(cert, responderURI, null, issuerCert, responderCert, date,
+ extensions, variant);
}
public static RevocationStatus check(X509Certificate cert,
URI responderURI, TrustAnchor anchor, X509Certificate issuerCert,
X509Certificate responderCert, Date date,
- List extensions)
+ List extensions, String variant)
throws IOException, CertPathValidatorException
{
- CertId certId = null;
+ CertId certId;
try {
X509CertImpl certImpl = X509CertImpl.toImpl(cert);
certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
@@ -184,7 +151,7 @@ public final class OCSP {
}
OCSPResponse ocspResponse = check(Collections.singletonList(certId),
responderURI, new OCSPResponse.IssuerInfo(anchor, issuerCert),
- responderCert, date, extensions);
+ responderCert, date, extensions, variant);
return (RevocationStatus) ocspResponse.getSingleResponse(certId);
}
@@ -206,10 +173,10 @@ public final class OCSP {
* @throws CertPathValidatorException if an exception occurs while
* encoding the OCSP Request or validating the OCSP Response
*/
- static OCSPResponse check(List certIds, URI responderURI,
+ static OCSPResponse check(List certIds, URI responderURI,
OCSPResponse.IssuerInfo issuerInfo,
X509Certificate responderCert, Date date,
- List extensions)
+ List extensions, String variant)
throws IOException, CertPathValidatorException
{
byte[] nonce = null;
@@ -226,7 +193,7 @@ public final class OCSP {
// verify the response
ocspResponse.verify(certIds, issuerInfo, responderCert, date,
- nonce);
+ nonce, variant);
} catch (IOException ioe) {
throw new CertPathValidatorException(
"Unable to determine revocation status due to network error",
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java
index d1770da153a..11f1b0996db 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java
@@ -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.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
@@ -375,7 +374,8 @@ public final class OCSPResponse {
}
void verify(List certIds, IssuerInfo issuerInfo,
- X509Certificate responderCert, Date date, byte[] nonce)
+ X509Certificate responderCert, Date date, byte[] nonce,
+ String variant)
throws CertPathValidatorException
{
switch (responseStatus) {
@@ -508,7 +508,8 @@ public final class OCSPResponse {
// Check algorithm constraints specified in security property
// "jdk.certpath.disabledAlgorithms".
AlgorithmChecker algChecker =
- new AlgorithmChecker(issuerInfo.getAnchor(), date);
+ new AlgorithmChecker(issuerInfo.getAnchor(), date,
+ variant);
algChecker.init(false);
algChecker.check(signerCert, Collections.emptySet());
@@ -568,7 +569,7 @@ public final class OCSPResponse {
if (signerCert != null) {
// Check algorithm constraints specified in security property
// "jdk.certpath.disabledAlgorithms".
- AlgorithmChecker.check(signerCert.getPublicKey(), sigAlgId);
+ AlgorithmChecker.check(signerCert.getPublicKey(), sigAlgId, variant);
if (!verifySignature(signerCert)) {
throw new CertPathValidatorException(
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIX.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIX.java
index f6b0b2ed6f3..8a177c04fc1 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIX.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIX.java
@@ -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
@@ -87,6 +87,7 @@ class PKIX {
private Set anchors;
private List certs;
private Timestamp timestamp;
+ private String variant;
ValidatorParams(CertPath cp, PKIXParameters params)
throws InvalidAlgorithmParameterException
@@ -102,8 +103,9 @@ class PKIX {
ValidatorParams(PKIXParameters params)
throws InvalidAlgorithmParameterException
{
- if (params instanceof PKIXTimestampParameters) {
- timestamp = ((PKIXTimestampParameters) params).getTimestamp();
+ if (params instanceof PKIXExtendedParameters) {
+ timestamp = ((PKIXExtendedParameters) params).getTimestamp();
+ variant = ((PKIXExtendedParameters) params).getVariant();
}
this.anchors = params.getTrustAnchors();
@@ -199,6 +201,10 @@ class PKIX {
Timestamp timestamp() {
return timestamp;
}
+
+ String variant() {
+ return variant;
+ }
}
static class BuilderParams extends ValidatorParams {
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java
index ac12fab75ab..b8e20e832f1 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java
@@ -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
@@ -173,9 +173,10 @@ public final class PKIXCertPathValidator extends CertPathValidatorSpi {
// add standard checkers that we will be using
certPathCheckers.add(untrustedChecker);
if (params.timestamp() == null) {
- certPathCheckers.add(new AlgorithmChecker(anchor, params.date()));
+ certPathCheckers.add(new AlgorithmChecker(anchor, params.date(), null));
} else {
- certPathCheckers.add(new AlgorithmChecker(params.timestamp()));
+ certPathCheckers.add(new AlgorithmChecker(null,
+ params.timestamp(), params.variant()));
}
certPathCheckers.add(new KeyChecker(certPathLen,
params.targetCertConstraints()));
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXTimestampParameters.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXExtendedParameters.java
similarity index 91%
rename from jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXTimestampParameters.java
rename to jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXExtendedParameters.java
index 34b497188e0..42c2d1f9c4f 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXTimestampParameters.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXExtendedParameters.java
@@ -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
@@ -39,19 +39,23 @@ import java.util.Set;
/**
* This class is a wrapper for PKIXBuilderParameters so that a Timestamp object
- * can be passed alone when PKIXCertPath is checking signed jar files.
+ * and a string for the variant type, can be passed when doing certpath
+ * checking.
*/
-public class PKIXTimestampParameters extends PKIXBuilderParameters {
+public class PKIXExtendedParameters extends PKIXBuilderParameters {
private final PKIXBuilderParameters p;
private Timestamp jarTimestamp;
+ private final String variant;
- public PKIXTimestampParameters(PKIXBuilderParameters params,
- Timestamp timestamp) throws InvalidAlgorithmParameterException {
+ public PKIXExtendedParameters(PKIXBuilderParameters params,
+ Timestamp timestamp, String variant)
+ throws InvalidAlgorithmParameterException {
super(params.getTrustAnchors(), null);
p = params;
jarTimestamp = timestamp;
+ this.variant = variant;
}
public Timestamp getTimestamp() {
@@ -61,6 +65,10 @@ public class PKIXTimestampParameters extends PKIXBuilderParameters {
jarTimestamp = t;
}
+ public String getVariant() {
+ return variant;
+ }
+
@Override
public void setDate(Date d) {
p.setDate(d);
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java
index 5fba1666119..9b443a733dd 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java
@@ -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
@@ -579,7 +579,7 @@ class RevocationChecker extends PKIXRevocationChecker {
approvedCRLs.addAll(DistributionPointFetcher.getCRLs(
sel, signFlag, prevKey, prevCert,
params.sigProvider(), certStores,
- reasonsMask, anchors, null));
+ reasonsMask, anchors, null, params.variant()));
}
} catch (CertStoreException e) {
if (e instanceof CertStoreTypeException) {
@@ -727,7 +727,7 @@ class RevocationChecker extends PKIXRevocationChecker {
}
}
response.verify(Collections.singletonList(certId), issuerInfo,
- responderCert, params.date(), nonce);
+ responderCert, params.date(), nonce, params.variant());
} else {
URI responderURI = (this.responderURI != null)
@@ -741,7 +741,7 @@ class RevocationChecker extends PKIXRevocationChecker {
response = OCSP.check(Collections.singletonList(certId),
responderURI, issuerInfo, responderCert, null,
- ocspExtensions);
+ ocspExtensions, params.variant());
}
} catch (IOException e) {
throw new CertPathValidatorException(
@@ -853,7 +853,7 @@ class RevocationChecker extends PKIXRevocationChecker {
if (DistributionPointFetcher.verifyCRL(
certImpl, point, crl, reasonsMask, signFlag,
prevKey, null, params.sigProvider(), anchors,
- certStores, params.date()))
+ certStores, params.date(), params.variant()))
{
results.add(crl);
}
diff --git a/jdk/src/java.base/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java b/jdk/src/java.base/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java
index c0cc98a7a36..11d8a067329 100644
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java
+++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java
@@ -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
@@ -344,7 +344,7 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi {
// add the algorithm checker
checkers.add(new AlgorithmChecker(builder.trustAnchor,
- buildParams.date()));
+ buildParams.date(), null));
BasicChecker basicChecker = null;
if (nextState.keyParamsNeeded()) {
diff --git a/jdk/src/java.base/share/classes/sun/security/ssl/EllipticCurvesExtension.java b/jdk/src/java.base/share/classes/sun/security/ssl/EllipticCurvesExtension.java
index d4f2848c973..c91b25e72ef 100644
--- a/jdk/src/java.base/share/classes/sun/security/ssl/EllipticCurvesExtension.java
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/EllipticCurvesExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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
@@ -43,6 +43,9 @@ import sun.security.action.GetPropertyAction;
final class EllipticCurvesExtension extends HelloExtension {
+ /* Class and subclass dynamic debugging support */
+ private static final Debug debug = Debug.getInstance("ssl");
+
private static final int ARBITRARY_PRIME = 0xff01;
private static final int ARBITRARY_CHAR2 = 0xff02;
@@ -159,6 +162,11 @@ final class EllipticCurvesExtension extends HelloExtension {
} // ignore unknown curves
}
}
+ if (idList.isEmpty() && JsseJce.isEcAvailable()) {
+ throw new IllegalArgumentException(
+ "System property jdk.tls.namedGroups(" + property + ") " +
+ "contains no supported elliptic curves");
+ }
} else { // default curves
int[] ids;
if (requireFips) {
@@ -183,16 +191,17 @@ final class EllipticCurvesExtension extends HelloExtension {
}
}
- if (idList.isEmpty()) {
- throw new IllegalArgumentException(
- "System property jdk.tls.namedGroups(" + property + ") " +
- "contains no supported elliptic curves");
- } else {
- supportedCurveIds = new int[idList.size()];
- int i = 0;
- for (Integer id : idList) {
- supportedCurveIds[i++] = id;
- }
+ if (debug != null && idList.isEmpty()) {
+ Debug.log(
+ "Initialized [jdk.tls.namedGroups|default] list contains " +
+ "no available elliptic curves. " +
+ (property != null ? "(" + property + ")" : "[Default]"));
+ }
+
+ supportedCurveIds = new int[idList.size()];
+ int i = 0;
+ for (Integer id : idList) {
+ supportedCurveIds[i++] = id;
}
}
diff --git a/jdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java b/jdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
index 46ae8d5281e..4f0a95ff80b 100644
--- a/jdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
@@ -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
@@ -37,6 +37,7 @@ import javax.net.ssl.*;
import sun.security.provider.certpath.AlgorithmChecker;
import sun.security.action.GetPropertyAction;
+import sun.security.validator.Validator;
public abstract class SSLContextImpl extends SSLContextSpi {
@@ -1436,7 +1437,7 @@ final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
constraints = new SSLAlgorithmConstraints(sslSocket, true);
}
- checkAlgorithmConstraints(chain, constraints);
+ checkAlgorithmConstraints(chain, constraints, isClient);
}
}
@@ -1478,12 +1479,12 @@ final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
constraints = new SSLAlgorithmConstraints(engine, true);
}
- checkAlgorithmConstraints(chain, constraints);
+ checkAlgorithmConstraints(chain, constraints, isClient);
}
}
private void checkAlgorithmConstraints(X509Certificate[] chain,
- AlgorithmConstraints constraints) throws CertificateException {
+ AlgorithmConstraints constraints, boolean isClient) throws CertificateException {
try {
// Does the certificate chain end with a trusted certificate?
@@ -1501,7 +1502,9 @@ final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
// A forward checker, need to check from trust to target
if (checkedLength >= 0) {
- AlgorithmChecker checker = new AlgorithmChecker(constraints);
+ AlgorithmChecker checker =
+ new AlgorithmChecker(constraints, null,
+ (isClient ? Validator.VAR_TLS_CLIENT : Validator.VAR_TLS_SERVER));
checker.init(false);
for (int i = checkedLength; i >= 0; i--) {
Certificate cert = chain[i];
diff --git a/jdk/src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java b/jdk/src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java
index b6ed37cc5a3..954b90d15dd 100644
--- a/jdk/src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java
@@ -39,6 +39,7 @@ import java.security.cert.Certificate;
import javax.net.ssl.*;
import sun.security.provider.certpath.AlgorithmChecker;
+import sun.security.validator.Validator;
/**
* The new X509 key manager implementation. The main differences to the
@@ -661,6 +662,15 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager
return CheckResult.OK;
}
+
+ public String getValidator() {
+ if (this == CLIENT) {
+ return Validator.VAR_TLS_CLIENT;
+ } else if (this == SERVER) {
+ return Validator.VAR_TLS_SERVER;
+ }
+ return Validator.VAR_GENERIC;
+ }
}
// enum for the result of the extension check
@@ -774,7 +784,8 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager
// check the algorithm constraints
if (constraints != null &&
- !conformsToAlgorithmConstraints(constraints, chain)) {
+ !conformsToAlgorithmConstraints(constraints, chain,
+ checkType.getValidator())) {
if (useDebug) {
debug.println("Ignoring alias " + alias +
@@ -811,9 +822,10 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager
}
private static boolean conformsToAlgorithmConstraints(
- AlgorithmConstraints constraints, Certificate[] chain) {
+ AlgorithmConstraints constraints, Certificate[] chain,
+ String variant) {
- AlgorithmChecker checker = new AlgorithmChecker(constraints);
+ AlgorithmChecker checker = new AlgorithmChecker(constraints, null, variant);
try {
checker.init(false);
} catch (CertPathValidatorException cpve) {
diff --git a/jdk/src/java.base/share/classes/sun/security/util/CertConstraintParameters.java b/jdk/src/java.base/share/classes/sun/security/util/CertConstraintParameters.java
deleted file mode 100644
index 23880f7c6aa..00000000000
--- a/jdk/src/java.base/share/classes/sun/security/util/CertConstraintParameters.java
+++ /dev/null
@@ -1,76 +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 sun.security.util;
-
-import java.security.Timestamp;
-import java.security.cert.X509Certificate;
-import java.util.Date;
-
-/**
- * This class is a wrapper for keeping state and passing objects between PKIX,
- * AlgorithmChecker, and DisabledAlgorithmConstraints.
- */
-public class CertConstraintParameters {
- // A certificate being passed to check against constraints.
- private final X509Certificate cert;
- // This is true if the trust anchor in the certificate chain matches a cert
- // in AnchorCertificates
- private final boolean trustedMatch;
- // PKIXParameter date
- private final Date pkixDate;
- // Timestamp of the signed JAR file
- private final Timestamp jarTimestamp;
-
- public CertConstraintParameters(X509Certificate c, boolean match,
- Date pkixdate, Timestamp jarTime) {
- cert = c;
- trustedMatch = match;
- pkixDate = pkixdate;
- jarTimestamp = jarTime;
- }
-
- public CertConstraintParameters(X509Certificate c) {
- this(c, false, null, null);
- }
-
- // Returns if the trust anchor has a match if anchor checking is enabled.
- public boolean isTrustedMatch() {
- return trustedMatch;
- }
-
- public X509Certificate getCertificate() {
- return cert;
- }
-
- public Date getPKIXParamDate() {
- return pkixDate;
- }
-
- public Timestamp getJARTimestamp() {
- return jarTimestamp;
- }
-
-}
diff --git a/jdk/src/java.base/share/classes/sun/security/util/ConstraintsParameters.java b/jdk/src/java.base/share/classes/sun/security/util/ConstraintsParameters.java
new file mode 100644
index 00000000000..84318654557
--- /dev/null
+++ b/jdk/src/java.base/share/classes/sun/security/util/ConstraintsParameters.java
@@ -0,0 +1,135 @@
+/*
+ * 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. 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 sun.security.util;
+
+import sun.security.validator.Validator;
+
+import java.security.AlgorithmParameters;
+import java.security.Key;
+import java.security.Timestamp;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+
+/**
+ * This class contains parameters for checking against constraints that extend
+ * past the publicly available parameters in java.security.AlgorithmConstraints.
+
+ * This is currently on passed between between PKIX, AlgorithmChecker,
+ * and DisabledAlgorithmConstraints.
+ */
+public class ConstraintsParameters {
+ /*
+ * The below 3 values are used the same as the permit() methods
+ * published in java.security.AlgorithmConstraints.
+ */
+ // Algorithm string to be checked against constraints
+ private final String algorithm;
+ // AlgorithmParameters to the algorithm being checked
+ private final AlgorithmParameters algParams;
+ // Public Key being checked against constraints
+ private final Key publicKey;
+
+ /*
+ * New values that are checked against constraints that the current public
+ * API does not support.
+ */
+ // A certificate being passed to check against constraints.
+ private final X509Certificate cert;
+ // This is true if the trust anchor in the certificate chain matches a cert
+ // in AnchorCertificates
+ private final boolean trustedMatch;
+ // PKIXParameter date
+ private final Date pkixDate;
+ // Timestamp of the signed JAR file
+ private final Timestamp jarTimestamp;
+ private final String variant;
+
+ public ConstraintsParameters(X509Certificate c, boolean match,
+ Date pkixdate, Timestamp jarTime, String variant) {
+ cert = c;
+ trustedMatch = match;
+ pkixDate = pkixdate;
+ jarTimestamp = jarTime;
+ this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
+ algorithm = null;
+ algParams = null;
+ publicKey = null;
+ }
+
+ public ConstraintsParameters(String algorithm, AlgorithmParameters params,
+ Key key, String variant) {
+ this.algorithm = algorithm;
+ algParams = params;
+ this.publicKey = key;
+ cert = null;
+ trustedMatch = false;
+ pkixDate = null;
+ jarTimestamp = null;
+ this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
+ }
+
+
+ public ConstraintsParameters(X509Certificate c) {
+ this(c, false, null, null,
+ Validator.VAR_GENERIC);
+ }
+
+ public ConstraintsParameters(Timestamp jarTime) {
+ this(null, false, null, jarTime, Validator.VAR_GENERIC);
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public AlgorithmParameters getAlgParams() {
+ return algParams;
+ }
+
+ public Key getPublicKey() {
+ return publicKey;
+ }
+ // Returns if the trust anchor has a match if anchor checking is enabled.
+ public boolean isTrustedMatch() {
+ return trustedMatch;
+ }
+
+ public X509Certificate getCertificate() {
+ return cert;
+ }
+
+ public Date getPKIXParamDate() {
+ return pkixDate;
+ }
+
+ public Timestamp getJARTimestamp() {
+ return jarTimestamp;
+ }
+
+ public String getVariant() {
+ return variant;
+ }
+}
diff --git a/jdk/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java b/jdk/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java
index 73914fe30ae..a8b4a6f0a40 100644
--- a/jdk/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java
+++ b/jdk/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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,6 +25,8 @@
package sun.security.util;
+import sun.security.validator.Validator;
+
import java.security.CryptoPrimitive;
import java.security.AlgorithmParameters;
import java.security.Key;
@@ -32,10 +34,12 @@ import java.security.cert.CertPathValidatorException;
import java.security.cert.CertPathValidatorException.BasicReason;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -100,12 +104,6 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
@Override
public final boolean permits(Set primitives,
String algorithm, AlgorithmParameters parameters) {
-
- if (primitives == null || primitives.isEmpty()) {
- throw new IllegalArgumentException(
- "No cryptographic primitive specified");
- }
-
return checkAlgorithm(disabledAlgorithms, algorithm, decomposer);
}
@@ -133,6 +131,18 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
return checkConstraints(primitives, algorithm, key, parameters);
}
+ public final void permits(ConstraintsParameters cp)
+ throws CertPathValidatorException {
+ permits(cp.getAlgorithm(), cp);
+ }
+
+ public final void permits(String algorithm, Key key,
+ AlgorithmParameters params, String variant)
+ throws CertPathValidatorException {
+ permits(algorithm, new ConstraintsParameters(algorithm, params, key,
+ (variant == null) ? Validator.VAR_GENERIC : variant));
+ }
+
/*
* Check if a x509Certificate object is permitted. Check if all
* algorithms are allowed, certificate constraints, and the
@@ -140,18 +150,10 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
*
* Uses new style permit() which throws exceptions.
*/
- public final void permits(Set primitives,
- CertConstraintParameters cp) throws CertPathValidatorException {
- checkConstraints(primitives, cp);
- }
- /*
- * Check if Certificate object is within the constraints.
- * Uses new style permit() which throws exceptions.
- */
- public final void permits(Set primitives,
- X509Certificate cert) throws CertPathValidatorException {
- checkConstraints(primitives, new CertConstraintParameters(cert));
+ public final void permits(String algorithm, ConstraintsParameters cp)
+ throws CertPathValidatorException {
+ algorithmConstraints.permits(algorithm, cp);
}
// Check if a string is contained inside the property
@@ -174,7 +176,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
throw new IllegalArgumentException("The key cannot be null");
}
- // check the signature algorithm
+ // check the signature algorithm with parameters
if (algorithm != null && algorithm.length() != 0) {
if (!permits(primitives, algorithm, parameters)) {
return false;
@@ -190,36 +192,6 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
return algorithmConstraints.permits(key);
}
- /*
- * Check algorithm constraints with Certificate
- * Uses new style permit() which throws exceptions.
- */
- private void checkConstraints(Set primitives,
- CertConstraintParameters cp) throws CertPathValidatorException {
-
- X509Certificate cert = cp.getCertificate();
- String algorithm = cert.getSigAlgName();
-
- // Check signature algorithm is not disabled
- if (!permits(primitives, algorithm, null)) {
- throw new CertPathValidatorException(
- "Algorithm constraints check failed on disabled "+
- "signature algorithm: " + algorithm,
- null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
- }
-
- // Check key algorithm is not disabled
- if (!permits(primitives, cert.getPublicKey().getAlgorithm(), null)) {
- throw new CertPathValidatorException(
- "Algorithm constraints check failed on disabled "+
- "public key algorithm: " + algorithm,
- null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
- }
-
- // Check the certificate and key constraints
- algorithmConstraints.permits(cp);
-
- }
/**
* Key and Certificate Constraints
@@ -234,13 +206,13 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
* 'true' means the operation is allowed.
* 'false' means it failed the constraints and is disallowed.
*
- * When passing CertConstraintParameters through permit(), an exception
+ * When passing ConstraintsParameters through permit(), an exception
* will be thrown on a failure to better identify why the operation was
* disallowed.
*/
private static class Constraints {
- private Map> constraintsMap = new HashMap<>();
+ private Map> constraintsMap = new HashMap<>();
private static class Holder {
private static final Pattern DENY_AFTER_PATTERN = Pattern.compile(
@@ -260,23 +232,22 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
// Check if constraint is a complete disabling of an
// algorithm or has conditions.
- String algorithm;
- String policy;
int space = constraintEntry.indexOf(' ');
- if (space > 0) {
- algorithm = AlgorithmDecomposer.hashName(
- constraintEntry.substring(0, space).
- toUpperCase(Locale.ENGLISH));
- policy = constraintEntry.substring(space + 1);
- } else {
- algorithm = constraintEntry.toUpperCase(Locale.ENGLISH);
- if (!constraintsMap.containsKey(algorithm)) {
- constraintsMap.putIfAbsent(algorithm,
- new HashSet<>());
- }
+ String algorithm = AlgorithmDecomposer.hashName(
+ ((space > 0 ? constraintEntry.substring(0, space) :
+ constraintEntry).
+ toUpperCase(Locale.ENGLISH)));
+ List constraintList =
+ constraintsMap.getOrDefault(algorithm,
+ new ArrayList<>(1));
+ constraintsMap.putIfAbsent(algorithm, constraintList);
+ if (space <= 0) {
+ constraintList.add(new DisabledConstraint(algorithm));
continue;
}
+ String policy = constraintEntry.substring(space + 1);
+
// Convert constraint conditions into Constraint classes
Constraint c, lastConstraint = null;
// Allow only one jdkCA entry per constraint entry
@@ -315,7 +286,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
c = new jdkCAConstraint(algorithm);
jdkCALimit = true;
- } else if(entry.startsWith("denyAfter") &&
+ } else if (entry.startsWith("denyAfter") &&
(matcher = Holder.DENY_AFTER_PATTERN.matcher(entry))
.matches()) {
if (debug != null) {
@@ -332,6 +303,12 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
c = new DenyAfterConstraint(algorithm, year, month,
day);
denyAfterLimit = true;
+ } else if (entry.startsWith("usage")) {
+ String s[] = (entry.substring(5)).trim().split(" ");
+ c = new UsageConstraint(algorithm, s);
+ if (debug != null) {
+ debug.println("Constraints usage length is " + s.length);
+ }
} else {
throw new IllegalArgumentException("Error in security" +
" property. Constraint unknown: " + entry);
@@ -340,11 +317,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
// Link multiple conditions for a single constraint
// into a linked list.
if (lastConstraint == null) {
- if (!constraintsMap.containsKey(algorithm)) {
- constraintsMap.putIfAbsent(algorithm,
- new HashSet<>());
- }
- constraintsMap.get(algorithm).add(c);
+ constraintList.add(c);
} else {
lastConstraint.nextConstraint = c;
}
@@ -354,17 +327,17 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
// Get applicable constraints based off the signature algorithm
- private Set getConstraints(String algorithm) {
+ private List getConstraints(String algorithm) {
return constraintsMap.get(algorithm);
}
// Check if KeySizeConstraints permit the specified key
public boolean permits(Key key) {
- Set set = getConstraints(key.getAlgorithm());
- if (set == null) {
+ List list = getConstraints(key.getAlgorithm());
+ if (list == null) {
return true;
}
- for (Constraint constraint : set) {
+ for (Constraint constraint : list) {
if (!constraint.permits(key)) {
if (debug != null) {
debug.println("keySizeConstraint: failed key " +
@@ -377,31 +350,35 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
// Check if constraints permit this cert.
- public void permits(CertConstraintParameters cp)
+ public void permits(String algorithm, ConstraintsParameters cp)
throws CertPathValidatorException {
X509Certificate cert = cp.getCertificate();
if (debug != null) {
- debug.println("Constraints.permits(): " + cert.getSigAlgName());
+ debug.println("Constraints.permits(): " + algorithm +
+ " Variant: " + cp.getVariant());
}
// Get all signature algorithms to check for constraints
- Set algorithms =
- AlgorithmDecomposer.decomposeOneHash(cert.getSigAlgName());
- if (algorithms == null || algorithms.isEmpty()) {
- return;
+ Set algorithms = new HashSet<>();
+ if (algorithm != null) {
+ algorithms.addAll(AlgorithmDecomposer.decomposeOneHash(algorithm));
}
- // Attempt to add the public key algorithm to the set
- algorithms.add(cert.getPublicKey().getAlgorithm());
-
+ // Attempt to add the public key algorithm if cert provided
+ if (cert != null) {
+ algorithms.add(cert.getPublicKey().getAlgorithm());
+ }
+ if (cp.getPublicKey() != null) {
+ algorithms.add(cp.getPublicKey().getAlgorithm());
+ }
// Check all applicable constraints
- for (String algorithm : algorithms) {
- Set set = getConstraints(algorithm);
- if (set == null) {
+ for (String alg : algorithms) {
+ List list = getConstraints(alg);
+ if (list == null) {
continue;
}
- for (Constraint constraint : set) {
+ for (Constraint constraint : list) {
constraint.permits(cp);
}
}
@@ -467,17 +444,17 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
/**
* Check if an algorithm constraint is permitted with a given
- * CertConstraintParameters.
+ * ConstraintsParameters.
*
* If the check inside of {@code permits()} fails, it must call
- * {@code next()} with the same {@code CertConstraintParameters}
+ * {@code next()} with the same {@code ConstraintsParameters}
* parameter passed if multiple constraints need to be checked.
*
* @param cp CertConstraintParameter containing certificate info
* @throws CertPathValidatorException if constraint disallows.
*
*/
- public abstract void permits(CertConstraintParameters cp)
+ public abstract void permits(ConstraintsParameters cp)
throws CertPathValidatorException;
/**
@@ -491,12 +468,12 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
* were disallowed, the last constraint will throw
* {@code CertPathValidatorException}.
*
- * @param cp CertConstraintParameters
+ * @param cp ConstraintsParameters
* @return 'true' if constraint allows the operation, 'false' if
* we are at the end of the constraint list or,
* {@code nextConstraint} is null.
*/
- boolean next(CertConstraintParameters cp)
+ boolean next(ConstraintsParameters cp)
throws CertPathValidatorException {
if (nextConstraint != null) {
nextConstraint.permits(cp);
@@ -525,6 +502,14 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
return false;
}
+
+ String extendedMsg(ConstraintsParameters cp) {
+ return (cp.getCertificate() == null ? "." :
+ " used with certificate: " +
+ cp.getCertificate().getSubjectX500Principal() +
+ (cp.getVariant() != Validator.VAR_GENERIC ?
+ ". Usage was " + cp.getVariant() : "."));
+ }
}
/*
@@ -537,11 +522,11 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
/*
- * Check if CertConstraintParameters has a trusted match, if it does
+ * Check if ConstraintsParameters has a trusted match, if it does
* call next() for any following constraints. If it does not, exit
* as this constraint(s) does not restrict the operation.
*/
- public void permits(CertConstraintParameters cp)
+ public void permits(ConstraintsParameters cp)
throws CertPathValidatorException {
if (debug != null) {
debug.println("jdkCAConstraints.permits(): " + algorithm);
@@ -554,8 +539,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
throw new CertPathValidatorException(
"Algorithm constraints check failed on certificate " +
- "anchor limits. " + algorithm + " used with " +
- cp.getCertificate().getSubjectX500Principal(),
+ "anchor limits. " + algorithm + extendedMsg(cp),
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
}
@@ -615,7 +599,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
* constraints. Throw an exception if this is the last constraint.
*/
@Override
- public void permits(CertConstraintParameters cp)
+ public void permits(ConstraintsParameters cp)
throws CertPathValidatorException {
Date currentDate;
String errmsg;
@@ -628,7 +612,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
errmsg = "PKIXParameter date: ";
} else {
currentDate = new Date();
- errmsg = "Certificate date: ";
+ errmsg = "Current date: ";
}
if (!denyAfterDate.after(currentDate)) {
@@ -637,9 +621,9 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
throw new CertPathValidatorException(
"denyAfter constraint check failed: " + algorithm +
- " used with Constraint date: " +
- dateFormat.format(denyAfterDate) + "; "
- + errmsg + dateFormat.format(currentDate),
+ " used with Constraint date: " +
+ dateFormat.format(denyAfterDate) + "; " + errmsg +
+ dateFormat.format(currentDate) + extendedMsg(cp),
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
}
@@ -660,6 +644,48 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
}
+ /*
+ * The usage constraint is for the "usage" keyword. It checks against the
+ * variant value in ConstraintsParameters.
+ */
+ private static class UsageConstraint extends Constraint {
+ String[] usages;
+
+ UsageConstraint(String algorithm, String[] usages) {
+ this.algorithm = algorithm;
+ this.usages = usages;
+ }
+
+ public void permits(ConstraintsParameters cp)
+ throws CertPathValidatorException {
+ for (String usage : usages) {
+
+ String v = null;
+ if (usage.compareToIgnoreCase("TLSServer") == 0) {
+ v = Validator.VAR_TLS_SERVER;
+ } else if (usage.compareToIgnoreCase("TLSClient") == 0) {
+ v = Validator.VAR_TLS_CLIENT;
+ } else if (usage.compareToIgnoreCase("SignedJAR") == 0) {
+ v = Validator.VAR_PLUGIN_CODE_SIGNING;
+ }
+
+ if (debug != null) {
+ debug.println("Checking if usage constraint " + v +
+ " matches " + cp.getVariant());
+ }
+ if (cp.getVariant().compareTo(v) == 0) {
+ if (next(cp)) {
+ return;
+ }
+ throw new CertPathValidatorException("Usage constraint " +
+ usage + " check failed: " + algorithm +
+ extendedMsg(cp),
+ null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
+ }
+ }
+ }
+ }
+
/*
* This class contains constraints dealing with the key size
* support limits per algorithm. e.g. "keySize <= 1024"
@@ -713,17 +739,22 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
* constraint Any permitted constraint will exit the linked list
* to allow the operation.
*/
- public void permits(CertConstraintParameters cp)
+ public void permits(ConstraintsParameters cp)
throws CertPathValidatorException {
- if (!permitsImpl(cp.getCertificate().getPublicKey())) {
+ Key key = null;
+ if (cp.getPublicKey() != null) {
+ key = cp.getPublicKey();
+ } else if (cp.getCertificate() != null) {
+ key = cp.getCertificate().getPublicKey();
+ }
+ if (key != null && !permitsImpl(key)) {
if (nextConstraint != null) {
nextConstraint.permits(cp);
return;
}
throw new CertPathValidatorException(
"Algorithm constraints check failed on keysize limits. "
- + algorithm + " " + size + "bit key used with "
- + cp.getCertificate().getSubjectX500Principal(),
+ + algorithm + " " + size + "bit key" + extendedMsg(cp),
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
}
}
@@ -762,5 +793,26 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
return true;
}
}
+
+ /*
+ * This constraint is used for the complete disabling of the algorithm.
+ */
+ private static class DisabledConstraint extends Constraint {
+ DisabledConstraint(String algo) {
+ algorithm = algo;
+ }
+
+ public void permits(ConstraintsParameters cp)
+ throws CertPathValidatorException {
+ throw new CertPathValidatorException(
+ "Algorithm constraints check failed on disabled " +
+ "algorithm: " + algorithm + extendedMsg(cp),
+ null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
+ }
+
+ public boolean permits(Key key) {
+ return false;
+ }
+ }
}
diff --git a/jdk/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java b/jdk/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java
index f8022c5ca94..2fe1c7ee91e 100644
--- a/jdk/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java
+++ b/jdk/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, 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
@@ -28,25 +28,23 @@ package sun.security.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.CodeSigner;
-import java.security.CryptoPrimitive;
+import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
+import java.security.Timestamp;
import java.security.cert.CertPath;
import java.security.cert.X509Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Base64;
-import java.util.Collections;
-import java.util.EnumSet;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarException;
import java.util.jar.JarFile;
@@ -61,9 +59,6 @@ public class SignatureFileVerifier {
/* Are we debugging ? */
private static final Debug debug = Debug.getInstance("jar");
- private static final Set DIGEST_PRIMITIVE_SET =
- Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.MESSAGE_DIGEST));
-
private static final DisabledAlgorithmConstraints JAR_DISABLED_CHECK =
new DisabledAlgorithmConstraints(
DisabledAlgorithmConstraints.PROPERTY_JAR_DISABLED_ALGS);
@@ -97,6 +92,14 @@ public class SignatureFileVerifier {
/* for generating certpath objects */
private CertificateFactory certificateFactory = null;
+ /** Algorithms that have been checked if they are weak. */
+ private Map permittedAlgs= new HashMap<>();
+
+ /** TSA timestamp of signed jar. The newest timestamp is used. If there
+ * was no TSA timestamp used when signed, current time is used ("null").
+ */
+ private Timestamp timestamp = null;
+
/**
* Create the named SignatureFileVerifier.
*
@@ -222,15 +225,8 @@ public class SignatureFileVerifier {
/** get digest from cache */
- private MessageDigest getDigest(String algorithm) throws SignatureException {
- // check that algorithm is not restricted
- if (!JAR_DISABLED_CHECK.permits(DIGEST_PRIMITIVE_SET, algorithm, null)) {
- SignatureException e =
- new SignatureException("SignatureFile check failed. " +
- "Disabled algorithm used: " + algorithm);
- throw e;
- }
-
+ private MessageDigest getDigest(String algorithm)
+ throws SignatureException {
if (createdDigests == null)
createdDigests = new HashMap<>();
@@ -302,6 +298,27 @@ public class SignatureFileVerifier {
if (newSigners == null)
return;
+ /*
+ * Look for the latest timestamp in the signature block. If an entry
+ * has no timestamp, use current time (aka null).
+ */
+ for (CodeSigner s: newSigners) {
+ if (debug != null) {
+ debug.println("Gathering timestamp for: " + s.toString());
+ }
+ if (s.getTimestamp() == null) {
+ timestamp = null;
+ break;
+ } else if (timestamp == null) {
+ timestamp = s.getTimestamp();
+ } else {
+ if (timestamp.getTimestamp().before(
+ s.getTimestamp().getTimestamp())) {
+ timestamp = s.getTimestamp();
+ }
+ }
+ }
+
Iterator> entries =
sf.getEntries().entrySet().iterator();
@@ -344,6 +361,68 @@ public class SignatureFileVerifier {
updateSigners(newSigners, signers, JarFile.MANIFEST_NAME);
}
+ /**
+ * Check if algorithm is permitted using the permittedAlgs Map.
+ * If the algorithm is not in the map, check against disabled algorithms and
+ * store the result. If the algorithm is in the map use that result.
+ * False is returned for weak algorithm, true for good algorithms.
+ */
+ boolean permittedCheck(String key, String algorithm) {
+ Boolean permitted = permittedAlgs.get(algorithm);
+ if (permitted == null) {
+ try {
+ JAR_DISABLED_CHECK.permits(algorithm,
+ new ConstraintsParameters(timestamp));
+ } catch(GeneralSecurityException e) {
+ permittedAlgs.put(algorithm, Boolean.FALSE);
+ permittedAlgs.put(key.toUpperCase(), Boolean.FALSE);
+ if (debug != null) {
+ if (e.getMessage() != null) {
+ debug.println(key + ": " + e.getMessage());
+ } else {
+ debug.println(key + ": " + algorithm +
+ " was disabled, no exception msg given.");
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ permittedAlgs.put(algorithm, Boolean.TRUE);
+ return true;
+ }
+
+ // Algorithm has already been checked, return the value from map.
+ return permitted.booleanValue();
+ }
+
+ /**
+ * With a given header (*-DIGEST*), return a string that lists all the
+ * algorithms associated with the header.
+ * If there are none, return "Unknown Algorithm".
+ */
+ String getWeakAlgorithms(String header) {
+ String w = "";
+ try {
+ for (String key : permittedAlgs.keySet()) {
+ if (key.endsWith(header)) {
+ w += key.substring(0, key.length() - header.length()) + " ";
+ }
+ }
+ } catch (RuntimeException e) {
+ w = "Unknown Algorithm(s). Error processing " + header + ". " +
+ e.getMessage();
+ }
+
+ // This means we have an error in finding weak algorithms, run in
+ // debug mode to see permittedAlgs map's values.
+ if (w.length() == 0) {
+ return "Unknown Algorithm(s)";
+ }
+
+ return w;
+ }
+
/**
* See if the whole manifest was signed.
*/
@@ -354,6 +433,7 @@ public class SignatureFileVerifier {
{
Attributes mattr = sf.getMainAttributes();
boolean manifestSigned = false;
+ boolean weakAlgs = true;
// go through all the attributes and process *-Digest-Manifest entries
for (Map.Entry