diff --git a/.hgtags-top-repo b/.hgtags-top-repo index e540680549f..a0cde0979fb 100644 --- a/.hgtags-top-repo +++ b/.hgtags-top-repo @@ -379,3 +379,4 @@ be1218f792a450dfb5d4b1f82616b9d95a6a732e jdk-9+133 065724348690eda41fc69112278d8da6dcde548c jdk-9+134 82b94cb5f342319d2cda77f9fa59703ad7fde576 jdk-9+135 3ec350f5f32af249b59620d7e37b54bdcd77b233 jdk-9+136 +d7f519b004254b19e384131d9f0d0e40e31a0fd3 jdk-9+137 diff --git a/Makefile b/Makefile index 2460cd414d8..ebe52d5d7f2 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ ### It also performs some sanity checks on make. ### -# The shell code below will be executed on /usr/ccs/bin/make on Solaris, but not in GNU Make. -# /usr/ccs/bin/make lacks basically every other flow control mechanism. +# The shell code below will be executed on /usr/bin/make on Solaris, but not in GNU Make. +# /usr/bin/make lacks basically every other flow control mechanism. .TEST_FOR_NON_GNUMAKE:sh=echo You are not using GNU Make/gmake, this is a requirement. Check your path. 1>&2 && exit 1 # The .FEATURES variable is likely to be unique for GNU Make. diff --git a/README-builds.html b/README-builds.html index 42cc0f11b7c..6d7d5b52461 100644 --- a/README-builds.html +++ b/README-builds.html @@ -626,8 +626,7 @@ number of different configurations, e.g. debug, release, 32, 64, etc.
The Common UNIX Printing System (CUPS) Headers are required for building the
OpenJDK on Solaris and Linux. The Solaris header files can be obtained by
- installing the package SFWcups from the Solaris Software Companion
- CD/DVD, these often will be installed into the directory /opt/sfw/cups
.
The CUPS header files can always be downloaded from www.cups.org.
@@ -1111,8 +1110,7 @@ version, see "Building GNU make".PATH
./usr/bin/make
on Solaris. If your Solaris system
has the software from the Solaris Developer Companion CD installed, you
-should try and use gmake
which will be located in either the /usr/bin
,
-/opt/sfw/bin
or /usr/sfw/bin
directory./usr/bin/gmake
or /usr/gnu/bin/make
.
*{@code * // a0: BMH - * // a1: inits, a2: steps, a3: preds, a4: finis - * // a5: box, a6: unbox - * // a7 (and following): arguments - * loop=Lambda(a0:L,a1:L,a2:L,a3:L,a4:L,a5:L,a6:L,a7:L)=>{ - * t8:L=MethodHandle.invokeBasic(a5:L,a7:L); // box the arguments into an Object[] - * t9:L=MethodHandleImpl.loop(bt:L,a1:L,a2:L,a3:L,a4:L,t8:L); // call the loop executor (with supplied types in bt) - * t10:L=MethodHandle.invokeBasic(a6:L,t9:L);t10:L} // unbox the result; return the result + * // a1: LoopClauses (containing an array of arrays: inits, steps, preds, finis) + * // a2: box, a3: unbox + * // a4 (and following): arguments + * loop=Lambda(a0:L,a1:L,a2:L,a3:L,a4:L)=>{ + * t5:L=MethodHandle.invokeBasic(a2:L,a4:L); // box the arguments into an Object[] + * t6:L=MethodHandleImpl.loop(bt:L,a1:L,t5:L); // call the loop executor (with supplied types in bt) + * t7:L=MethodHandle.invokeBasic(a3:L,t6:L);t7:L} // unbox the result; return the result * }
* It is compiled into bytecode equivalent to the code seen in {@link MethodHandleImpl#loop(BasicType[], - * MethodHandle[], MethodHandle[], MethodHandle[], MethodHandle[], Object...)}, with the difference that no arrays + * MethodHandleImpl.LoopClauses, Object...)}, with the difference that no arrays * will be used for local state storage. Instead, the local state will be mapped to actual stack slots. *
* Bytecode generation applies an unrolling scheme to enable better bytecode generation regarding local state type * handling. The generated bytecode will have the following form ({@code void} types are ignored for convenience). * Assume there are {@code C} clauses in the loop. *
*{@code - * INIT: (INIT_SEQ for clause 1) - * ... - * (INIT_SEQ for clause C) - * LOOP: (LOOP_SEQ for clause 1) - * ... - * (LOOP_SEQ for clause C) - * GOTO LOOP - * DONE: ... + * PREINIT: ALOAD_1 + * CHECKCAST LoopClauses + * GETFIELD LoopClauses.clauses + * ASTORE clauseDataIndex // place the clauses 2-dimensional array on the stack + * INIT: (INIT_SEQ for clause 1) + * ... + * (INIT_SEQ for clause C) + * LOOP: (LOOP_SEQ for clause 1) + * ... + * (LOOP_SEQ for clause C) + * GOTO LOOP + * DONE: ... * }
* The {@code INIT_SEQ_x} sequence for clause {@code x} (with {@code x} ranging from {@code 0} to {@code C-1}) has * the following shape. Assume slot {@code vx} is used to hold the state for clause {@code x}. *
{@code - * INIT_SEQ_x: ALOAD inits - * CHECKCAST MethodHandle[] + * INIT_SEQ_x: ALOAD clauseDataIndex + * ICONST_0 + * AALOAD // load the inits array * ICONST x * AALOAD // load the init handle for clause x * load args @@ -1361,24 +1369,27 @@ class InvokerBytecodeGenerator { * The {@code LOOP_SEQ_x} sequence for clause {@code x} (with {@code x} ranging from {@code 0} to {@code C-1}) has * the following shape. Again, assume slot {@code vx} is used to hold the state for clause {@code x}. *{@code - * LOOP_SEQ_x: ALOAD steps - * CHECKCAST MethodHandle[] + * LOOP_SEQ_x: ALOAD clauseDataIndex + * ICONST_1 + * AALOAD // load the steps array * ICONST x * AALOAD // load the step handle for clause x * load locals * load args * INVOKEVIRTUAL MethodHandle.invokeBasic * store vx - * ALOAD preds - * CHECKCAST MethodHandle[] + * ALOAD clauseDataIndex + * ICONST_2 + * AALOAD // load the preds array * ICONST x * AALOAD // load the pred handle for clause x * load locals * load args * INVOKEVIRTUAL MethodHandle.invokeBasic * IFNE LOOP_SEQ_x+1 // predicate returned false -> jump to next clause - * ALOAD finis - * CHECKCAST MethodHandle[] + * ALOAD clauseDataIndex + * ICONST_3 + * AALOAD // load the finis array * ICONST x * AALOAD // load the fini handle for clause x * load locals @@ -1397,8 +1408,12 @@ class InvokerBytecodeGenerator { BasicType[] loopClauseTypes = (BasicType[]) invoker.arguments[0]; Class>[] loopLocalStateTypes = Stream.of(loopClauseTypes). filter(bt -> bt != BasicType.V_TYPE).map(BasicType::basicTypeClass).toArray(Class>[]::new); + Class>[] localTypes = new Class>[loopLocalStateTypes.length + 1]; + localTypes[0] = MethodHandleImpl.LoopClauses.class; + System.arraycopy(loopLocalStateTypes, 0, localTypes, 1, loopLocalStateTypes.length); - final int firstLoopStateIndex = extendLocalsMap(loopLocalStateTypes); + final int clauseDataIndex = extendLocalsMap(localTypes); + final int firstLoopStateIndex = clauseDataIndex + 1; Class> returnType = result.function.resolvedHandle().type().returnType(); MethodType loopType = args.function.resolvedHandle().type() @@ -1420,10 +1435,16 @@ class InvokerBytecodeGenerator { Label lDone = new Label(); Label lNext; + // PREINIT: + emitPushArgument(MethodHandleImpl.LoopClauses.class, invoker.arguments[1]); + mv.visitFieldInsn(Opcodes.GETFIELD, LOOP_CLAUSES, "clauses", MHARY2); + emitAstoreInsn(clauseDataIndex); + // INIT: for (int c = 0, state = 0; c < nClauses; ++c) { MethodType cInitType = loopType.changeReturnType(loopClauseTypes[c].basicTypeClass()); - emitLoopHandleInvoke(invoker, inits, c, args, false, cInitType, loopLocalStateTypes, firstLoopStateIndex); + emitLoopHandleInvoke(invoker, inits, c, args, false, cInitType, loopLocalStateTypes, clauseDataIndex, + firstLoopStateIndex); if (cInitType.returnType() != void.class) { emitStoreInsn(BasicType.basicType(cInitType.returnType()), firstLoopStateIndex + state); ++state; @@ -1440,18 +1461,21 @@ class InvokerBytecodeGenerator { boolean isVoid = stepType.returnType() == void.class; // invoke loop step - emitLoopHandleInvoke(invoker, steps, c, args, true, stepType, loopLocalStateTypes, firstLoopStateIndex); + emitLoopHandleInvoke(invoker, steps, c, args, true, stepType, loopLocalStateTypes, clauseDataIndex, + firstLoopStateIndex); if (!isVoid) { emitStoreInsn(BasicType.basicType(stepType.returnType()), firstLoopStateIndex + state); ++state; } // invoke loop predicate - emitLoopHandleInvoke(invoker, preds, c, args, true, predType, loopLocalStateTypes, firstLoopStateIndex); + emitLoopHandleInvoke(invoker, preds, c, args, true, predType, loopLocalStateTypes, clauseDataIndex, + firstLoopStateIndex); mv.visitJumpInsn(Opcodes.IFNE, lNext); // invoke fini - emitLoopHandleInvoke(invoker, finis, c, args, true, finiType, loopLocalStateTypes, firstLoopStateIndex); + emitLoopHandleInvoke(invoker, finis, c, args, true, finiType, loopLocalStateTypes, clauseDataIndex, + firstLoopStateIndex); mv.visitJumpInsn(Opcodes.GOTO, lDone); // this is the beginning of the next loop clause @@ -1483,9 +1507,10 @@ class InvokerBytecodeGenerator { } private void emitLoopHandleInvoke(Name holder, int handles, int clause, Name args, boolean pushLocalState, - MethodType type, Class>[] loopLocalStateTypes, int firstLoopStateSlot) { + MethodType type, Class>[] loopLocalStateTypes, int clauseDataSlot, + int firstLoopStateSlot) { // load handle for clause - emitPushArgument(holder, handles); + emitPushClauseArray(clauseDataSlot, handles); emitIconstInsn(clause); mv.visitInsn(Opcodes.AALOAD); // load loop state (preceding the other arguments) @@ -1499,6 +1524,12 @@ class InvokerBytecodeGenerator { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, MH, "invokeBasic", type.toMethodDescriptorString(), false); } + private void emitPushClauseArray(int clauseDataSlot, int which) { + emitAloadInsn(clauseDataSlot); + emitIconstInsn(which - 1); + mv.visitInsn(Opcodes.AALOAD); + } + private void emitZero(BasicType type) { switch (type) { case I_TYPE: mv.visitInsn(Opcodes.ICONST_0); break; 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 6fdf21e2c91..bcc825bcf15 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 @@ -41,7 +41,6 @@ import java.util.HashMap; import static java.lang.invoke.LambdaForm.BasicType.*; import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeStatic; import static java.lang.invoke.MethodHandleStatics.*; -import java.util.Objects; /** * The symbolic, non-executable form of a method handle's invocation semantics. @@ -732,9 +731,9 @@ class LambdaForm { boolean isLoop(int pos) { // loop idiom: // t_{n}:L=MethodHandle.invokeBasic(...) - // t_{n+1}:L=MethodHandleImpl.loop(types, *, *, *, *, t_{n}) + // t_{n+1}:L=MethodHandleImpl.loop(types, *, t_{n}) // t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1}) - return isMatchingIdiom(pos, "loop", 5); + return isMatchingIdiom(pos, "loop", 2); } /* 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 4fe4bb524a7..ca4f050553f 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 @@ -1689,8 +1689,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; NF_tryFinally = new NamedFunction(MethodHandleImpl.class .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class)); NF_loop = new NamedFunction(MethodHandleImpl.class - .getDeclaredMethod("loop", BasicType[].class, MethodHandle[].class, MethodHandle[].class, - MethodHandle[].class, MethodHandle[].class, Object[].class)); + .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class)); NF_throwException = new NamedFunction(MethodHandleImpl.class .getDeclaredMethod("throwException", Throwable.class)); NF_profileBoolean = new NamedFunction(MethodHandleImpl.class @@ -1794,12 +1793,13 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; MethodHandle collectArgs = varargsArray(type.parameterCount()).asType(varargsType); MethodHandle unboxResult = unboxResultHandle(tloop); - BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLLL(); + LoopClauses clauseData = + new LoopClauses(new MethodHandle[][]{toArray(init), toArray(step), toArray(pred), toArray(fini)}); + BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL(); BoundMethodHandle mh; try { - mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) toArray(init), - (Object) toArray(step), (Object) toArray(pred), (Object) toArray(fini), (Object) collectArgs, - (Object) unboxResult); + mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) clauseData, + (Object) collectArgs, (Object) unboxResult); } catch (Throwable ex) { throw uncaughtException(ex); } @@ -1818,23 +1818,20 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; * {@code t12}): **{@code * loop=Lambda(a0:L,a1:L)=>{ - * t2:L=BoundMethodHandle$Species_L6.argL0(a0:L); // array of init method handles - * t3:L=BoundMethodHandle$Species_L6.argL1(a0:L); // array of step method handles - * t4:L=BoundMethodHandle$Species_L6.argL2(a0:L); // array of pred method handles - * t5:L=BoundMethodHandle$Species_L6.argL3(a0:L); // array of fini method handles - * t6:L=BoundMethodHandle$Species_L6.argL4(a0:L); // helper handle to box the arguments into an Object[] - * t7:L=BoundMethodHandle$Species_L6.argL5(a0:L); // helper handle to unbox the result - * t8:L=MethodHandle.invokeBasic(t6:L,a1:L); // box the arguments into an Object[] - * t9:L=MethodHandleImpl.loop(null,t2:L,t3:L,t4:L,t5:L,t6:L); // call the loop executor - * t10:L=MethodHandle.invokeBasic(t7:L,t9:L);t10:L} // unbox the result; return the result + * t2:L=BoundMethodHandle$Species_L3.argL0(a0:L); // LoopClauses holding init, step, pred, fini handles + * t3:L=BoundMethodHandle$Species_L3.argL1(a0:L); // helper handle to box the arguments into an Object[] + * t4:L=BoundMethodHandle$Species_L3.argL2(a0:L); // helper handle to unbox the result + * t5:L=MethodHandle.invokeBasic(t3:L,a1:L); // box the arguments into an Object[] + * t6:L=MethodHandleImpl.loop(null,t2:L,t3:L); // call the loop executor + * t7:L=MethodHandle.invokeBasic(t4:L,t6:L);t7:L} // unbox the result; return the result * }- * {@code argL0} through {@code argL3} are the arrays of init, step, pred, and fini method handles. - * {@code argL4} and {@code argL5} are auxiliary method handles: {@code argL2} boxes arguments and wraps them into - * {@code Object[]} ({@code ValueConversions.array()}), and {@code argL3} unboxes the result if necessary + * {@code argL0} is a LoopClauses instance holding, in a 2-dimensional array, the init, step, pred, and fini method + * handles. {@code argL1} and {@code argL2} are auxiliary method handles: {@code argL1} boxes arguments and wraps + * them into {@code Object[]} ({@code ValueConversions.array()}), and {@code argL2} unboxes the result if necessary * ({@code ValueConversions.unbox()}). *
- * Having {@code t6} and {@code t7} passed in via a BMH and not hardcoded in the lambda form allows to share lambda + * Having {@code t3} and {@code t4} passed in via a BMH and not hardcoded in the lambda form allows to share lambda * forms among loop combinators with the same basic type. *
* The above template is instantiated by using the {@link LambdaFormEditor} to replace the {@code null} argument to @@ -1845,15 +1842,12 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; private static LambdaForm makeLoopForm(MethodType basicType, BasicType[] localVarTypes) { MethodType lambdaType = basicType.invokerType(); - final int THIS_MH = 0; // the BMH_LLLLLL + final int THIS_MH = 0; // the BMH_LLL final int ARG_BASE = 1; // start of incoming arguments final int ARG_LIMIT = ARG_BASE + basicType.parameterCount(); int nameCursor = ARG_LIMIT; - final int GET_INITS = nameCursor++; - final int GET_STEPS = nameCursor++; - final int GET_PREDS = nameCursor++; - final int GET_FINIS = nameCursor++; + final int GET_CLAUSE_DATA = nameCursor++; final int GET_COLLECT_ARGS = nameCursor++; final int GET_UNBOX_RESULT = nameCursor++; final int BOXED_ARGS = nameCursor++; @@ -1864,14 +1858,11 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; if (lform == null) { Name[] names = arguments(nameCursor - ARG_LIMIT, lambdaType); - BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLLL(); + BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL(); names[THIS_MH] = names[THIS_MH].withConstraint(data); - names[GET_INITS] = new Name(data.getterFunction(0), names[THIS_MH]); - names[GET_STEPS] = new Name(data.getterFunction(1), names[THIS_MH]); - names[GET_PREDS] = new Name(data.getterFunction(2), names[THIS_MH]); - names[GET_FINIS] = new Name(data.getterFunction(3), names[THIS_MH]); - names[GET_COLLECT_ARGS] = new Name(data.getterFunction(4), names[THIS_MH]); - names[GET_UNBOX_RESULT] = new Name(data.getterFunction(5), names[THIS_MH]); + names[GET_CLAUSE_DATA] = new Name(data.getterFunction(0), names[THIS_MH]); + names[GET_COLLECT_ARGS] = new Name(data.getterFunction(1), names[THIS_MH]); + names[GET_UNBOX_RESULT] = new Name(data.getterFunction(2), names[THIS_MH]); // t_{i}:L=MethodHandle.invokeBasic(collectArgs:L,a1:L,...); MethodType collectArgsType = basicType.changeReturnType(Object.class); @@ -1881,10 +1872,10 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; System.arraycopy(names, ARG_BASE, args, 1, ARG_LIMIT - ARG_BASE); names[BOXED_ARGS] = new Name(makeIntrinsic(invokeBasic, Intrinsic.LOOP), args); - // t_{i+1}:L=MethodHandleImpl.loop(localTypes:L,inits:L,steps:L,preds:L,finis:L,t_{i}:L); + // t_{i+1}:L=MethodHandleImpl.loop(localTypes:L,clauses:L,t_{i}:L); Object[] lArgs = new Object[]{null, // placeholder for BasicType[] localTypes - will be added by LambdaFormEditor - names[GET_INITS], names[GET_STEPS], names[GET_PREDS], names[GET_FINIS], names[BOXED_ARGS]}; + names[GET_CLAUSE_DATA], names[BOXED_ARGS]}; names[LOOP] = new Name(NF_loop, lArgs); // t_{i+2}:I=MethodHandle.invokeBasic(unbox:L,t_{i+1}:L); @@ -1900,22 +1891,52 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; return lform.editor().noteLoopLocalTypesForm(BOXED_ARGS, localVarTypes); } + static class LoopClauses { + @Stable final MethodHandle[][] clauses; + LoopClauses(MethodHandle[][] clauses) { + assert clauses.length == 4; + this.clauses = clauses; + } + @Override + public String toString() { + StringBuffer sb = new StringBuffer("LoopClauses -- "); + for (int i = 0; i < 4; ++i) { + if (i > 0) { + sb.append(" "); + } + sb.append('<').append(i).append(">: "); + MethodHandle[] hs = clauses[i]; + for (int j = 0; j < hs.length; ++j) { + if (j > 0) { + sb.append(" "); + } + sb.append('*').append(j).append(": ").append(hs[j]).append('\n'); + } + } + sb.append(" --\n"); + return sb.toString(); + } + } /** * Intrinsified during LambdaForm compilation * (see {@link InvokerBytecodeGenerator#emitLoop(int)}). */ @LambdaForm.Hidden - static Object loop(BasicType[] localTypes, MethodHandle[] init, MethodHandle[] step, MethodHandle[] pred, - MethodHandle[] fini, Object... av) throws Throwable { + static Object loop(BasicType[] localTypes, LoopClauses clauseData, Object... av) throws Throwable { + final MethodHandle[] init = clauseData.clauses[0]; + final MethodHandle[] step = clauseData.clauses[1]; + final MethodHandle[] pred = clauseData.clauses[2]; + final MethodHandle[] fini = clauseData.clauses[3]; int varSize = (int) Stream.of(init).filter(h -> h.type().returnType() != void.class).count(); int nArgs = init[0].type().parameterCount(); Object[] varsAndArgs = new Object[varSize + nArgs]; for (int i = 0, v = 0; i < init.length; ++i) { - if (init[i].type().returnType() == void.class) { - init[i].asFixedArity().invokeWithArguments(av); + MethodHandle ih = init[i]; + if (ih.type().returnType() == void.class) { + ih.invokeWithArguments(av); } else { - varsAndArgs[v++] = init[i].asFixedArity().invokeWithArguments(av); + varsAndArgs[v++] = ih.invokeWithArguments(av); } } System.arraycopy(av, 0, varsAndArgs, varSize, nArgs); @@ -1926,12 +1947,12 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; MethodHandle s = step[i]; MethodHandle f = fini[i]; if (s.type().returnType() == void.class) { - s.asFixedArity().invokeWithArguments(varsAndArgs); + s.invokeWithArguments(varsAndArgs); } else { - varsAndArgs[v++] = s.asFixedArity().invokeWithArguments(varsAndArgs); + varsAndArgs[v++] = s.invokeWithArguments(varsAndArgs); } - if (!(boolean) p.asFixedArity().invokeWithArguments(varsAndArgs)) { - return f.asFixedArity().invokeWithArguments(varsAndArgs); + if (!(boolean) p.invokeWithArguments(varsAndArgs)) { + return f.invokeWithArguments(varsAndArgs); } } } @@ -2122,14 +2143,13 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; Throwable t = null; Object r = null; try { - // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case. - r = target.asFixedArity().invokeWithArguments(av); + r = target.invokeWithArguments(av); } catch (Throwable thrown) { t = thrown; throw t; } finally { Object[] args = target.type().returnType() == void.class ? prepend(av, t) : prepend(av, t, r); - r = cleanup.asFixedArity().invokeWithArguments(args); + r = cleanup.invokeWithArguments(args); } return r; } 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 86685b605de..28364e53ae9 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 @@ -4368,10 +4368,11 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); } // Step 4: fill in missing parameter types. - List
finit = fillParameterTypes(init, commonSuffix); - List fstep = fillParameterTypes(step, commonParameterSequence); - List fpred = fillParameterTypes(pred, commonParameterSequence); - List ffini = fillParameterTypes(fini, commonParameterSequence); + // Also convert all handles to fixed-arity handles. + List finit = fixArities(fillParameterTypes(init, commonSuffix)); + List fstep = fixArities(fillParameterTypes(step, commonParameterSequence)); + List fpred = fixArities(fillParameterTypes(pred, commonParameterSequence)); + List ffini = fixArities(fillParameterTypes(fini, commonParameterSequence)); assert finit.stream().map(MethodHandle::type).map(MethodType::parameterList). allMatch(pl -> pl.equals(commonSuffix)); @@ -4389,6 +4390,10 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); }).collect(Collectors.toList()); } + private static List fixArities(List hs) { + return hs.stream().map(MethodHandle::asFixedArity).collect(Collectors.toList()); + } + /** * Constructs a {@code while} loop from an initializer, a body, and a predicate. This is a convenience wrapper for * the {@linkplain #loop(MethodHandle[][]) generic loop combinator}. @@ -4887,7 +4892,8 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); // target parameter list. cleanup = dropArgumentsToMatch(cleanup, (rtype == void.class ? 1 : 2), targetParamTypes, 0); - return MethodHandleImpl.makeTryFinally(target, cleanup, rtype, targetParamTypes); + // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case. + return MethodHandleImpl.makeTryFinally(target.asFixedArity(), cleanup.asFixedArity(), rtype, targetParamTypes); } /** diff --git a/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java b/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java index db9a3e000b9..1d0e22fec11 100644 --- a/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java +++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java @@ -664,7 +664,7 @@ final class ModuleInfo { try { bb.get(b, off, len); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -681,7 +681,7 @@ final class ModuleInfo { int ch = bb.get(); return (ch != 0); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -690,7 +690,7 @@ final class ModuleInfo { try { return bb.get(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -699,7 +699,7 @@ final class ModuleInfo { try { return ((int) bb.get()) & 0xff; } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -708,7 +708,7 @@ final class ModuleInfo { try { return bb.getShort(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -717,7 +717,7 @@ final class ModuleInfo { try { return ((int) bb.getShort()) & 0xffff; } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -726,7 +726,7 @@ final class ModuleInfo { try { return bb.getChar(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -735,7 +735,7 @@ final class ModuleInfo { try { return bb.getInt(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -744,7 +744,7 @@ final class ModuleInfo { try { return bb.getLong(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -753,7 +753,7 @@ final class ModuleInfo { try { return bb.getFloat(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } @@ -762,7 +762,7 @@ final class ModuleInfo { try { return bb.getDouble(); } catch (BufferUnderflowException e) { - throw new EOFException(); + throw new EOFException(e.getMessage()); } } 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 ba2632b5445..15d41a4101d 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 @@ -597,10 +597,10 @@ public class Proxy implements java.io.Serializable { private final Module module; ProxyBuilder(ClassLoader loader, List > interfaces) { if (!VM.isModuleSystemInited()) { - throw new InternalError("Proxy is not supported until module system is fully initialzed"); + throw new InternalError("Proxy is not supported until module system is fully initialized"); } if (interfaces.size() > 65535) { - throw new IllegalArgumentException("interface limit exceeded"); + throw new IllegalArgumentException("interface limit exceeded: " + interfaces.size()); } Set > refTypes = referencedTypes(loader, interfaces); diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java b/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java index 5708af2653c..9946b128591 100644 --- a/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java +++ b/jdk/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java @@ -2559,6 +2559,13 @@ public class CompletableFuture implements Future , CompletionStage { * exceptionally with a CompletionException with this exception as * cause. * + * Unless overridden by a subclass, a new non-minimal + * CompletableFuture with all methods available can be obtained from + * a minimal CompletionStage via {@link #toCompletableFuture()}. + * For example, completion of a minimal stage can be awaited by + * + *
{@code minimalStage.toCompletableFuture().join(); }+ * * @return the new CompletionStage * @since 9 */ @@ -2853,6 +2860,16 @@ public class CompletableFutureimplements Future , CompletionStage { @Override public CompletableFuture completeOnTimeout (T value, long timeout, TimeUnit unit) { throw new UnsupportedOperationException(); } + @Override public CompletableFuture toCompletableFuture() { + Object r; + if ((r = result) != null) + return new CompletableFuture (encodeRelay(r)); + else { + CompletableFuture d = new CompletableFuture<>(); + unipush(new UniRelay (d, this)); + return d; + } + } } // VarHandle mechanics diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java index e8f7ac614df..98524dedc23 100644 --- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java +++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java @@ -1191,7 +1191,7 @@ public class ForkJoinPool extends AbstractExecutorService { * Default idle timeout value (in milliseconds) for the thread * triggering quiescence to park waiting for new work */ - private static final long DEFAULT_KEEPALIVE = 60000L; + private static final long DEFAULT_KEEPALIVE = 60_000L; /** * Undershoot tolerance for idle timeouts @@ -2303,7 +2303,6 @@ public class ForkJoinPool extends AbstractExecutorService { throw new NullPointerException(); long ms = Math.max(unit.toMillis(keepAliveTime), TIMEOUT_SLOP); - String prefix = "ForkJoinPool-" + nextPoolId() + "-worker-"; int corep = Math.min(Math.max(corePoolSize, parallelism), MAX_CAP); long c = ((((long)(-corep) << TC_SHIFT) & TC_MASK) | (((long)(-parallelism) << RC_SHIFT) & RC_MASK)); @@ -2315,8 +2314,8 @@ public class ForkJoinPool extends AbstractExecutorService { n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; n = (n + 1) << 1; // power of two, including space for submission queues + this.workerNamePrefix = "ForkJoinPool-" + nextPoolId() + "-worker-"; this.workQueues = new WorkQueue[n]; - this.workerNamePrefix = prefix; this.factory = factory; this.ueh = handler; this.saturate = saturate; @@ -2327,11 +2326,19 @@ public class ForkJoinPool extends AbstractExecutorService { checkPermission(); } + private Object newInstanceFromSystemProperty(String property) + throws ReflectiveOperationException { + String className = System.getProperty(property); + return (className == null) + ? null + : ClassLoader.getSystemClassLoader().loadClass(className) + .getConstructor().newInstance(); + } + /** * Constructor for common pool using parameters possibly * overridden by system properties */ - @SuppressWarnings("deprecation") // Class.newInstance private ForkJoinPool(byte forCommonPoolOnly) { int parallelism = -1; ForkJoinWorkerThreadFactory fac = null; @@ -2339,18 +2346,12 @@ public class ForkJoinPool extends AbstractExecutorService { try { // ignore exceptions in accessing/parsing properties String pp = System.getProperty ("java.util.concurrent.ForkJoinPool.common.parallelism"); - String fp = System.getProperty - ("java.util.concurrent.ForkJoinPool.common.threadFactory"); - String hp = System.getProperty - ("java.util.concurrent.ForkJoinPool.common.exceptionHandler"); if (pp != null) parallelism = Integer.parseInt(pp); - if (fp != null) - fac = ((ForkJoinWorkerThreadFactory)ClassLoader. - getSystemClassLoader().loadClass(fp).newInstance()); - if (hp != null) - handler = ((UncaughtExceptionHandler)ClassLoader. - getSystemClassLoader().loadClass(hp).newInstance()); + fac = (ForkJoinWorkerThreadFactory) newInstanceFromSystemProperty( + "java.util.concurrent.ForkJoinPool.common.threadFactory"); + handler = (UncaughtExceptionHandler) newInstanceFromSystemProperty( + "java.util.concurrent.ForkJoinPool.common.exceptionHandler"); } catch (Exception ignore) { } @@ -2373,8 +2374,8 @@ public class ForkJoinPool extends AbstractExecutorService { n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; n = (n + 1) << 1; - this.workQueues = new WorkQueue[n]; this.workerNamePrefix = "ForkJoinPool.commonPool-worker-"; + this.workQueues = new WorkQueue[n]; this.factory = fac; this.ueh = handler; this.saturate = null; diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java index f3e3531dbd9..0d0346f02d6 100644 --- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java +++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java @@ -35,6 +35,9 @@ package java.util.concurrent.atomic; +import static java.lang.Double.doubleToRawLongBits; +import static java.lang.Double.longBitsToDouble; + import java.io.Serializable; import java.util.function.DoubleBinaryOperator; @@ -91,7 +94,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable { public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, double identity) { this.function = accumulatorFunction; - base = this.identity = Double.doubleToRawLongBits(identity); + base = this.identity = doubleToRawLongBits(identity); } /** @@ -101,18 +104,19 @@ public class DoubleAccumulator extends Striped64 implements Serializable { */ public void accumulate(double x) { Cell[] as; long b, v, r; int m; Cell a; - if ((as = cells) != null || - (r = Double.doubleToRawLongBits - (function.applyAsDouble - (Double.longBitsToDouble(b = base), x))) != b && !casBase(b, r)) { + if ((as = cells) != null + || ((r = doubleToRawLongBits + (function.applyAsDouble(longBitsToDouble(b = base), x))) != b + && !casBase(b, r))) { boolean uncontended = true; - if (as == null || (m = as.length - 1) < 0 || - (a = as[getProbe() & m]) == null || - !(uncontended = - (r = Double.doubleToRawLongBits - (function.applyAsDouble - (Double.longBitsToDouble(v = a.value), x))) == v || - a.cas(v, r))) + if (as == null + || (m = as.length - 1) < 0 + || (a = as[getProbe() & m]) == null + || !(uncontended = + ((r = doubleToRawLongBits + (function.applyAsDouble + (longBitsToDouble(v = a.value), x))) == v) + || a.cas(v, r))) doubleAccumulate(x, function, uncontended); } } @@ -128,12 +132,12 @@ public class DoubleAccumulator extends Striped64 implements Serializable { */ public double get() { Cell[] as = cells; - double result = Double.longBitsToDouble(base); + double result = longBitsToDouble(base); if (as != null) { for (Cell a : as) if (a != null) result = function.applyAsDouble - (result, Double.longBitsToDouble(a.value)); + (result, longBitsToDouble(a.value)); } return result; } @@ -168,12 +172,12 @@ public class DoubleAccumulator extends Striped64 implements Serializable { */ public double getThenReset() { Cell[] as = cells; - double result = Double.longBitsToDouble(base); + double result = longBitsToDouble(base); base = identity; if (as != null) { for (Cell a : as) { if (a != null) { - double v = Double.longBitsToDouble(a.value); + double v = longBitsToDouble(a.value); a.reset(identity); result = function.applyAsDouble(result, v); } @@ -267,9 +271,9 @@ public class DoubleAccumulator extends Striped64 implements Serializable { * held by this proxy */ private Object readResolve() { - double d = Double.longBitsToDouble(identity); + double d = longBitsToDouble(identity); DoubleAccumulator a = new DoubleAccumulator(function, d); - a.base = Double.doubleToRawLongBits(value); + a.base = doubleToRawLongBits(value); return a; } } diff --git a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java index 939a4a2eed9..8c6e332ad79 100644 --- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java +++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java @@ -103,14 +103,16 @@ public class LongAccumulator extends Striped64 implements Serializable { */ public void accumulate(long x) { Cell[] as; long b, v, r; int m; Cell a; - if ((as = cells) != null || - (r = function.applyAsLong(b = base, x)) != b && !casBase(b, r)) { + if ((as = cells) != null + || ((r = function.applyAsLong(b = base, x)) != b + && !casBase(b, r))) { boolean uncontended = true; - if (as == null || (m = as.length - 1) < 0 || - (a = as[getProbe() & m]) == null || - !(uncontended = - (r = function.applyAsLong(v = a.value, x)) == v || - a.cas(v, r))) + if (as == null + || (m = as.length - 1) < 0 + || (a = as[getProbe() & m]) == null + || !(uncontended = + (r = function.applyAsLong(v = a.value, x)) == v + || a.cas(v, r))) longAccumulate(x, function, uncontended); } } 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 07038b9ef5e..10506b7029c 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 @@ -186,7 +186,9 @@ public class BasicImageReader implements AutoCloseable { if (result.getMajorVersion() != ImageHeader.MAJOR_VERSION || result.getMinorVersion() != ImageHeader.MINOR_VERSION) { - throw new IOException("The image file \"" + name + "\" is not the correct version"); + throw new IOException("The image file \"" + name + "\" is not " + + "the correct version. Major: " + result.getMajorVersion() + + ". Minor: " + result.getMinorVersion()); } return result; @@ -318,11 +320,11 @@ public class BasicImageReader implements AutoCloseable { private ByteBuffer readBuffer(long offset, long size) { if (offset < 0 || Integer.MAX_VALUE <= offset) { - throw new IndexOutOfBoundsException("offset"); + throw new IndexOutOfBoundsException("Bad offset: " + offset); } if (size < 0 || Integer.MAX_VALUE <= size) { - throw new IndexOutOfBoundsException("size"); + throw new IndexOutOfBoundsException("Bad size: " + size); } if (MAP_ALL) { @@ -382,11 +384,13 @@ public class BasicImageReader implements AutoCloseable { long uncompressedSize = loc.getUncompressedSize(); if (compressedSize < 0 || Integer.MAX_VALUE < compressedSize) { - throw new IndexOutOfBoundsException("Compressed size"); + throw new IndexOutOfBoundsException( + "Bad compressed size: " + compressedSize); } if (uncompressedSize < 0 || Integer.MAX_VALUE < uncompressedSize) { - throw new IndexOutOfBoundsException("Uncompressed size"); + throw new IndexOutOfBoundsException( + "Bad uncompressed size: " + uncompressedSize); } if (compressedSize == 0) { diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java index c4ff85bbfb8..f63665119e2 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java @@ -79,7 +79,8 @@ public final class ImageHeader { Objects.requireNonNull(buffer); if (buffer.capacity() != HEADER_SLOTS) { - throw new InternalError("jimage header not the correct size"); + throw new InternalError( + "jimage header not the correct size: " + buffer.capacity()); } int magic = buffer.get(0); diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java index 16787dad3af..ad0ae42fc3d 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java @@ -81,7 +81,8 @@ public class ImageLocation { } if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { - throw new InternalError("Invalid jimage attribute kind"); + throw new InternalError( + "Invalid jimage attribute kind: " + kind); } int length = attributeLength(data); @@ -91,7 +92,7 @@ public class ImageLocation { value <<= 8; if (!bytes.hasRemaining()) { - throw new InternalError("\"Missing jimage attribute datad"); + throw new InternalError("Missing jimage attribute data"); } value |= bytes.get() & 0xFF; @@ -134,7 +135,8 @@ public class ImageLocation { long getAttribute(int kind) { if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { - throw new InternalError("Invalid jimage attribute kind"); + throw new InternalError( + "Invalid jimage attribute kind: " + kind); } return attributes[kind]; @@ -142,7 +144,8 @@ public class ImageLocation { String getAttributeString(int kind) { if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { - throw new InternalError("Invalid jimage attribute kind"); + throw new InternalError( + "Invalid jimage attribute kind: " + kind); } return getStrings().get((int)attributes[kind]); diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java index 9802afcc93a..774e0e6e62a 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java @@ -82,7 +82,7 @@ public class ImageStream { public void ensure(int needs) { if (needs < 0) { - throw new IndexOutOfBoundsException("needs"); + throw new IndexOutOfBoundsException("Bad value: " + needs); } if (needs > buffer.remaining()) { @@ -106,7 +106,7 @@ public class ImageStream { public void skip(int n) { if (n < 0) { - throw new IndexOutOfBoundsException("n"); + throw new IndexOutOfBoundsException("skip value = " + n); } buffer.position(buffer.position() + n); diff --git a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java index 382e6b1696b..e4a11cbdc14 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java @@ -151,7 +151,7 @@ public class ImageStringsReader implements ImageStrings { try { charsFromMUTF8(chars, bytes, offset, count); } catch (UTFDataFormatException ex) { - throw new InternalError("Attempt to convert non modified UTF-8 byte sequence"); + throw new InternalError("Attempt to convert non modified UTF-8 byte sequence", ex); } return new String(chars); @@ -199,7 +199,8 @@ public class ImageStringsReader implements ImageStrings { ch = buffer.get(); if ((ch & 0xC0) != 0x80) { - throw new InternalError("Bad continuation in modified UTF-8 byte sequence"); + throw new InternalError("Bad continuation in " + + "modified UTF-8 byte sequence: " + ch); } uch = ((uch & ~mask) << 6) | (ch & 0x3F); @@ -208,7 +209,8 @@ public class ImageStringsReader implements ImageStrings { } if ((uch & 0xFFFF) != uch) { - throw new InternalError("UTF-32 char in modified UTF-8 byte sequence"); + throw new InternalError("UTF-32 char in modified UTF-8 " + + "byte sequence: " + uch); } chars[j++] = (char)uch; diff --git a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java index cb6c85d11e3..49285b31dfb 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java @@ -183,7 +183,7 @@ class JrtFileSystem extends FileSystem { public PathMatcher getPathMatcher(String syntaxAndInput) { int pos = syntaxAndInput.indexOf(':'); if (pos <= 0 || pos == syntaxAndInput.length()) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("pos is " + pos); } String syntax = syntaxAndInput.substring(0, pos); String input = syntaxAndInput.substring(pos + 1); @@ -285,7 +285,8 @@ class JrtFileSystem extends FileSystem { for (OpenOption option : options) { Objects.requireNonNull(option); if (!(option instanceof StandardOpenOption)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException( + "option class: " + option.getClass()); } } if (options.contains(StandardOpenOption.WRITE) || diff --git a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java index cf3bbd8d2d9..f23887cabad 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java +++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java @@ -122,7 +122,8 @@ final class JrtPath implements Path { public final JrtPath getName(int index) { initOffsets(); if (index < 0 || index >= offsets.length) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("index: " + + index + ", offsets length: " + offsets.length); } int begin = offsets[index]; int end; @@ -139,7 +140,9 @@ final class JrtPath implements Path { initOffsets(); if (beginIndex < 0 || endIndex > offsets.length || beginIndex >= endIndex) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException( + "beginIndex: " + beginIndex + ", endIndex: " + endIndex + + ", offsets length: " + offsets.length); } // starting/ending offsets int begin = offsets[beginIndex]; @@ -211,7 +214,8 @@ final class JrtPath implements Path { return o; } if (jrtfs != o.jrtfs || isAbsolute() != o.isAbsolute()) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException( + "Incorrect filesystem or path: " + other); } final String tp = this.path; final String op = o.path; @@ -366,7 +370,8 @@ final class JrtPath implements Path { private JrtPath checkPath(Path path) { Objects.requireNonNull(path); if (!(path instanceof JrtPath)) - throw new ProviderMismatchException(); + throw new ProviderMismatchException("path class: " + + path.getClass()); return (JrtPath) path; } @@ -459,7 +464,7 @@ final class JrtPath implements Path { } if (c == '\u0000') { throw new InvalidPathException(path, - "Path: nul character not allowed"); + "Path: NUL character not allowed"); } to.append(c); prevC = c; diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java index a5f3126c16f..f4de0ea0c47 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java +++ b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java @@ -1603,11 +1603,50 @@ public final class Unsafe { return weakCompareAndSwapShort(o, offset, c2s(expected), c2s(x)); } + /** + * The JVM converts integral values to boolean values using two + * different conventions, byte testing against zero and truncation + * to least-significant bit. + * + * The JNI documents specify that, at least for returning + * values from native methods, a Java boolean value is converted + * to the value-set 0..1 by first truncating to a byte (0..255 or + * maybe -128..127) and then testing against zero. Thus, Java + * booleans in non-Java data structures are by convention + * represented as 8-bit containers containing either zero (for + * false) or any non-zero value (for true). + * + *
Java booleans in the heap are also stored in bytes, but are + * strongly normalized to the value-set 0..1 (i.e., they are + * truncated to the least-significant bit). + * + *
The main reason for having different conventions for + * conversion is performance: Truncation to the least-significant + * bit can be usually implemented with fewer (machine) + * instructions than byte testing against zero. + * + *
A number of Unsafe methods load boolean values from the heap + * as bytes. Unsafe converts those values according to the JNI + * rules (i.e, using the "testing against zero" convention). The + * method {@code byte2bool} implements that conversion. + * + * @param b the byte to be converted to boolean + * @return the result of the conversion + */ @ForceInline private boolean byte2bool(byte b) { - return b > 0; + return b != 0; } + /** + * Convert a boolean value to a byte. The return value is strongly + * normalized to the value-set 0..1 (i.e., the value is truncated + * to the least-significant bit). See {@link #byte2bool(byte)} for + * more details on conversion conventions. + * + * @param b the boolean to be converted to byte (and then normalized) + * @return the result of the conversion + */ @ForceInline private byte bool2byte(boolean b) { return b ? (byte)1 : (byte)0; diff --git a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java index 9fe63d56e5e..695795e4338 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java +++ b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java @@ -50,7 +50,7 @@ public class VM { public static void initLevel(int value) { synchronized (lock) { if (value <= initLevel || value > SYSTEM_BOOTED) - throw new InternalError(); + throw new InternalError("Bad level: " + value); initLevel = value; lock.notifyAll(); } 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 b9b93b275ef..ca40bf2706e 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 @@ -153,27 +153,24 @@ public final class ModuleBootstrap { boolean addAllDefaultModules = false; boolean addAllSystemModules = false; boolean addAllApplicationModules = false; - String propValue = getAndRemoveProperty("jdk.module.addmods"); - if (propValue != null) { - for (String mod: propValue.split(",")) { - switch (mod) { - case ALL_DEFAULT: - addAllDefaultModules = true; - break; - case ALL_SYSTEM: - addAllSystemModules = true; - break; - case ALL_MODULE_PATH: - addAllApplicationModules = true; - break; - default : - roots.add(mod); - } + for (String mod: getExtraAddModules()) { + switch (mod) { + case ALL_DEFAULT: + addAllDefaultModules = true; + break; + case ALL_SYSTEM: + addAllSystemModules = true; + break; + case ALL_MODULE_PATH: + addAllApplicationModules = true; + break; + default : + roots.add(mod); } } // --limit-modules - propValue = getAndRemoveProperty("jdk.module.limitmods"); + String propValue = getAndRemoveProperty("jdk.module.limitmods"); if (propValue != null) { Set
mods = new HashSet<>(); for (String mod: propValue.split(",")) { @@ -392,6 +389,32 @@ public final class ModuleBootstrap { } } + /** + * Returns the set of module names specified via --add-modules options + * on the command line + */ + private static Set getExtraAddModules() { + String prefix = "jdk.module.addmods."; + int index = 0; + + // the system property is removed after decoding + String value = getAndRemoveProperty(prefix + index); + if (value == null) { + return Collections.emptySet(); + } + + Set modules = new HashSet<>(); + while (value != null) { + for (String s : value.split(",")) { + if (s.length() > 0) modules.add(s); + } + + index++; + value = getAndRemoveProperty(prefix + index); + } + + return modules; + } /** * Process the --add-reads options to add any additional read edges that @@ -514,7 +537,7 @@ public final class ModuleBootstrap { // value is (, )* if (map.containsKey(key)) - fail(key + " specified more than once"); + fail(key + " specified more than once"); Set values = new HashSet<>(); map.put(key, values); diff --git a/jdk/src/java.base/share/classes/module-info.java b/jdk/src/java.base/share/classes/module-info.java index f49111be646..11d53463dc8 100644 --- a/jdk/src/java.base/share/classes/module-info.java +++ b/jdk/src/java.base/share/classes/module-info.java @@ -166,6 +166,7 @@ module java.base { jdk.charsets, jdk.compiler, jdk.jartool, + jdk.jdeps, jdk.jlink, jdk.net, jdk.scripting.nashorn, @@ -189,7 +190,8 @@ module java.base { jdk.unsupported, jdk.vm.ci; exports jdk.internal.util.jar to - jdk.jartool; + jdk.jartool, + jdk.jdeps; exports jdk.internal.vm to java.management, jdk.jvmstat; diff --git a/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java b/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java index f063e13ac13..7f63ec88264 100644 --- a/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java +++ b/jdk/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java @@ -328,8 +328,6 @@ class DatagramChannelImpl public SocketAddress receive(ByteBuffer dst) throws IOException { if (dst.isReadOnly()) throw new IllegalArgumentException("Read-only buffer"); - if (dst == null) - throw new NullPointerException(); synchronized (readLock) { ensureOpen(); // Socket was not bound before attempting receive @@ -716,8 +714,6 @@ class DatagramChannelImpl @Override public DatagramChannel connect(SocketAddress sa) throws IOException { - int localPort = 0; - synchronized(readLock) { synchronized(writeLock) { synchronized (stateLock) { diff --git a/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java b/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java index 856e0cf2fb6..8e21e522079 100644 --- a/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/jdk/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -616,8 +616,6 @@ class SocketChannelImpl } public boolean connect(SocketAddress sa) throws IOException { - int localPort = 0; - synchronized (readLock) { synchronized (writeLock) { ensureOpenAndUnconnected(); diff --git a/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java b/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java index e72ae9f406c..ac3a9f86a1a 100644 --- a/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java +++ b/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -344,7 +344,8 @@ abstract class SeedGenerator { try { BogusThread bt = new BogusThread(); Thread t = new Thread - (seedGroup, bt, "SeedGenerator Thread", 0, false); + (seedGroup, bt, "SeedGenerator Thread", 0, + false); t.start(); } catch (Exception e) { throw new InternalError("internal error: " + @@ -357,7 +358,8 @@ abstract class SeedGenerator { long startTime = System.nanoTime(); while (System.nanoTime() - startTime < 250000000) { synchronized(this){}; - latch++; + // Mask the sign bit and keep latch non-negative + latch = (latch + 1) & 0x1FFFFFFF; } // Translate the value using the permutation, and xor @@ -431,7 +433,7 @@ abstract class SeedGenerator { // data and using it to mix the trivial permutation. // It should be evenly distributed. The specific values // are not crucial to the security of this class. - private static byte[] rndTab = { + private static final byte[] rndTab = { 56, 30, -107, -6, -86, 25, -83, 75, -12, -64, 5, -128, 78, 21, 16, 32, 70, -81, 37, -51, -43, -46, -108, 87, 29, 17, -55, 22, -11, -111, diff --git a/jdk/src/java.base/share/native/include/jvm.h b/jdk/src/java.base/share/native/include/jvm.h index bf60a857beb..1d6576a6381 100644 --- a/jdk/src/java.base/share/native/include/jvm.h +++ b/jdk/src/java.base/share/native/include/jvm.h @@ -179,6 +179,7 @@ JVM_GetStackTraceElements(JNIEnv *env, jobject throwable, jobjectArray elements) */ enum { JVM_STACKWALK_FILL_CLASS_REFS_ONLY = 0x2, + JVM_STACKWALK_GET_CALLER_CLASS = 0x04, JVM_STACKWALK_SHOW_HIDDEN_FRAMES = 0x20, JVM_STACKWALK_FILL_LIVE_STACK_FRAMES = 0x100 }; diff --git a/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c b/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c index 27230858253..533584fdb7a 100644 --- a/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c +++ b/jdk/src/java.base/unix/native/libjava/ProcessImpl_md.c @@ -152,8 +152,8 @@ defaultPath(void) #ifdef __solaris__ /* These really are the Solaris defaults! */ return (geteuid() == 0 || getuid() == 0) ? - "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:/usr/sbin" : - "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:"; + "/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:/usr/sbin" : + "/usr/xpg4/bin:/usr/bin:/opt/SUNWspro/bin:"; #else return ":/bin:/usr/bin"; /* glibc */ #endif diff --git a/jdk/src/java.base/unix/native/libjli/java_md.h b/jdk/src/java.base/unix/native/libjli/java_md.h index ab99dbbdf66..8e95aced972 100644 --- a/jdk/src/java.base/unix/native/libjli/java_md.h +++ b/jdk/src/java.base/unix/native/libjli/java_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -35,12 +35,12 @@ #include "manifest_info.h" #include "jli_util.h" -#define PATH_SEPARATOR ':' -#define FILESEP "/" -#define FILE_SEPARATOR '/' +#define PATH_SEPARATOR ':' +#define FILESEP "/" +#define FILE_SEPARATOR '/' #define IS_FILE_SEPARATOR(c) ((c) == '/') #ifndef MAXNAMELEN -#define MAXNAMELEN PATH_MAX +#define MAXNAMELEN PATH_MAX #endif #ifdef _LP64 @@ -59,10 +59,13 @@ static jboolean GetJVMPath(const char *jrepath, const char *jvmtype, static jboolean GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative); +#if defined(_AIX) +#include "java_md_aix.h" +#endif + #ifdef MACOSX #include "java_md_macosx.h" #else /* !MACOSX */ #include "java_md_solinux.h" #endif /* MACOSX */ - #endif /* JAVA_MD_H */ diff --git a/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c b/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c index 30b2a93ffcc..3a9e650a5f8 100644 --- a/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c +++ b/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "java_net_InetAddress.h" #include "java_net_Inet4AddressImpl.h" @@ -442,7 +443,15 @@ ping4(JNIEnv *env, DWORD ReplySize = 0; jboolean ret = JNI_FALSE; - ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366051%28v=vs.85%29.aspx + ReplySize = sizeof(ICMP_ECHO_REPLY) // The buffer should be large enough + // to hold at least one ICMP_ECHO_REPLY + // structure + + sizeof(SendData) // plus RequestSize bytes of data. + + 8; // This buffer should also be large enough + // to also hold 8 more bytes of data + // (the size of an ICMP error message) + ReplyBuffer = (VOID*) malloc(ReplySize); if (ReplyBuffer == NULL) { IcmpCloseHandle(hIcmpFile); @@ -478,10 +487,47 @@ ping4(JNIEnv *env, (timeout < 1000) ? 1000 : timeout); // DWORD Timeout } - if (dwRetVal != 0) { + if (dwRetVal == 0) { // if the call failed + TCHAR *buf; + DWORD err = WSAGetLastError(); + switch (err) { + case ERROR_NO_NETWORK: + case ERROR_NETWORK_UNREACHABLE: + case ERROR_HOST_UNREACHABLE: + case ERROR_PROTOCOL_UNREACHABLE: + case ERROR_PORT_UNREACHABLE: + case ERROR_REQUEST_ABORTED: + case ERROR_INCORRECT_ADDRESS: + case ERROR_HOST_DOWN: + case ERROR_INVALID_COMPUTERNAME: + case ERROR_INVALID_NETNAME: + case WSAEHOSTUNREACH: /* Host Unreachable */ + case WSAENETUNREACH: /* Network Unreachable */ + case WSAENETDOWN: /* Network is down */ + case WSAEPFNOSUPPORT: /* Protocol Family unsupported */ + case IP_REQ_TIMED_OUT: + break; + default: + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&buf, 0, NULL); + NET_ThrowNew(env, err, buf); + LocalFree(buf); + break; + } + } else { PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; - if ((int)pEchoReply->RoundTripTime <= timeout) + + // This is to take into account the undocumented minimum + // timeout mentioned in the IcmpSendEcho call above. + // We perform an extra check to make sure that our + // roundtrip time was less than our desired timeout + // for cases where that timeout is < 1000ms. + if (pEchoReply->Status == IP_SUCCESS + && (int)pEchoReply->RoundTripTime <= timeout) + { ret = JNI_TRUE; + } } free(ReplyBuffer); diff --git a/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java b/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java index 984bf8ad239..d0315ada6bf 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java +++ b/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java @@ -67,19 +67,22 @@ public final class ConstructorFinder extends AbstractFinder > { */ public static Constructor> findConstructor(Class> type, Class>...args) throws NoSuchMethodException { if (type.isPrimitive()) { - throw new NoSuchMethodException("Primitive wrapper does not contain constructors"); + throw new NoSuchMethodException("Primitive wrapper does not contain constructors: " + + type.getName()); } if (type.isInterface()) { - throw new NoSuchMethodException("Interface does not contain constructors"); + throw new NoSuchMethodException("Interface does not contain constructors: " + + type.getName()); } if (!FinderUtils.isExported(type)) { - throw new NoSuchMethodException("Class is not accessible"); + throw new NoSuchMethodException("Class is not accessible: " + type.getName()); } if (Modifier.isAbstract(type.getModifiers())) { - throw new NoSuchMethodException("Abstract class cannot be instantiated"); + throw new NoSuchMethodException("Abstract class cannot be instantiated: " + + type.getName()); } if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) { - throw new NoSuchMethodException("Class is not accessible"); + throw new NoSuchMethodException("Class is not accessible: " + type.getName()); } PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); Signature signature = new Signature(type, args); diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java index 5f39ea935fa..e17a5f2e796 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java @@ -2461,16 +2461,16 @@ public abstract class ImageReader { try { bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule()); } catch (MissingResourceException mre) { - throw new IllegalArgumentException("Bundle not found!"); + throw new IllegalArgumentException("Bundle not found!", mre); } String warning = null; try { warning = bundle.getString(keyword); } catch (ClassCastException cce) { - throw new IllegalArgumentException("Resource is not a String!"); + throw new IllegalArgumentException("Resource is not a String!", cce); } catch (MissingResourceException mre) { - throw new IllegalArgumentException("Resource is missing!"); + throw new IllegalArgumentException("Resource is missing!", mre); } listener.warningOccurred(this, warning); diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java b/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java index a9a681ce05f..8723c50773e 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java @@ -1963,16 +1963,16 @@ public abstract class ImageWriter implements ImageTranscoder { try { bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule()); } catch (MissingResourceException mre) { - throw new IllegalArgumentException("Bundle not found!"); + throw new IllegalArgumentException("Bundle not found!", mre); } String warning = null; try { warning = bundle.getString(keyword); } catch (ClassCastException cce) { - throw new IllegalArgumentException("Resource is not a String!"); + throw new IllegalArgumentException("Resource is not a String!", cce); } catch (MissingResourceException mre) { - throw new IllegalArgumentException("Resource is missing!"); + throw new IllegalArgumentException("Resource is missing!", mre); } listener.warningOccurred(this, imageIndex, warning); diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c index c1895cd29d7..7124f6127af 100644 --- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c @@ -442,7 +442,7 @@ getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) { #ifndef __linux__ /* SOLARIS */ if (xrenderLibHandle == NULL) { - xrenderLibHandle = dlopen("/usr/sfw/lib/libXrender.so.1", + xrenderLibHandle = dlopen("/usr/lib/libXrender.so.1", RTLD_LAZY | RTLD_GLOBAL); } #endif diff --git a/jdk/src/java.desktop/unix/native/libjawt/jawt.c b/jdk/src/java.desktop/unix/native/libjawt/jawt.c index 59e9a55cff2..ee61138dd31 100644 --- a/jdk/src/java.desktop/unix/native/libjawt/jawt.c +++ b/jdk/src/java.desktop/unix/native/libjawt/jawt.c @@ -39,6 +39,10 @@ DEF_STATIC_JNI_OnLoad */ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) { +#if defined(HEADLESS) + /* there are no AWT libs available at all */ + return JNI_FALSE; +#else if (awt == NULL) { return JNI_FALSE; } @@ -64,4 +68,5 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) } return JNI_TRUE; +#endif } diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java index c054f312c55..83ecaa1701f 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -68,8 +68,8 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { // master secret as a P11Key private P11Key p11Key; - // version, e.g. 0x0301 - private int version; + // whether SSLv3 is supported + private final boolean supportSSLv3; P11TlsKeyMaterialGenerator(Token token, String algorithm, long mechanism) throws PKCS11Exception { @@ -77,6 +77,11 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { this.token = token; this.algorithm = algorithm; this.mechanism = mechanism; + + // Given the current lookup order specified in SunPKCS11.java, + // if CKM_SSL3_KEY_AND_MAC_DERIVE is not used to construct this object, + // it means that this mech is disabled or unsupported. + this.supportSSLv3 = (mechanism == CKM_SSL3_KEY_AND_MAC_DERIVE); } protected void engineInit(SecureRandom random) { @@ -89,20 +94,26 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { if (params instanceof TlsKeyMaterialParameterSpec == false) { throw new InvalidAlgorithmParameterException(MSG); } - this.spec = (TlsKeyMaterialParameterSpec)params; + + TlsKeyMaterialParameterSpec spec = (TlsKeyMaterialParameterSpec)params; + int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion(); + + if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) || + (version > 0x0302)) { + throw new InvalidAlgorithmParameterException + ("Only" + (supportSSLv3? " SSL 3.0,": "") + + " TLS 1.0, and TLS 1.1 are supported (0x" + + Integer.toHexString(version) + ")"); + } try { p11Key = P11SecretKeyFactory.convertKey (token, spec.getMasterSecret(), "TlsMasterSecret"); } catch (InvalidKeyException e) { throw new InvalidAlgorithmParameterException("init() failed", e); } - version = (spec.getMajorVersion() << 8) | spec.getMinorVersion(); - if ((version < 0x0300) && (version > 0x0302)) { - throw new InvalidAlgorithmParameterException - ("Only SSL 3.0, TLS 1.0, and TLS 1.1 are supported"); - } - // we assume the token supports both the CKM_SSL3_* and the CKM_TLS_* - // mechanisms + this.spec = spec; + this.mechanism = (version == 0x0300)? + CKM_SSL3_KEY_AND_MAC_DERIVE : CKM_TLS_KEY_AND_MAC_DERIVE; } protected void engineInit(int keysize, SecureRandom random) { @@ -115,8 +126,6 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { throw new IllegalStateException ("TlsKeyMaterialGenerator must be initialized"); } - mechanism = (version == 0x0300) ? CKM_SSL3_KEY_AND_MAC_DERIVE - : CKM_TLS_KEY_AND_MAC_DERIVE; int macBits = spec.getMacKeyLength() << 3; int ivBits = spec.getIvLength() << 3; diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java index 73a2ac2e890..128952e8a49 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -61,7 +61,10 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { private TlsMasterSecretParameterSpec spec; private P11Key p11Key; - int version; + CK_VERSION ckVersion; + + // whether SSLv3 is supported + private final boolean supportSSLv3; P11TlsMasterSecretGenerator(Token token, String algorithm, long mechanism) throws PKCS11Exception { @@ -69,6 +72,11 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { this.token = token; this.algorithm = algorithm; this.mechanism = mechanism; + + // Given the current lookup order specified in SunPKCS11.java, if + // CKM_SSL3_MASTER_KEY_DERIVE is not used to construct this object, + // it means that this mech is disabled or unsupported. + supportSSLv3 = (mechanism == CKM_SSL3_MASTER_KEY_DERIVE); } protected void engineInit(SecureRandom random) { @@ -81,7 +89,17 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { if (params instanceof TlsMasterSecretParameterSpec == false) { throw new InvalidAlgorithmParameterException(MSG); } - this.spec = (TlsMasterSecretParameterSpec)params; + + TlsMasterSecretParameterSpec spec = (TlsMasterSecretParameterSpec)params; + int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion(); + if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) || + (version > 0x0302)) { + throw new InvalidAlgorithmParameterException + ("Only" + (supportSSLv3? " SSL 3.0,": "") + + " TLS 1.0, and TLS 1.1 are supported (0x" + + Integer.toHexString(version) + ")"); + } + SecretKey key = spec.getPremasterSecret(); // algorithm should be either TlsRsaPremasterSecret or TlsPremasterSecret, // but we omit the check @@ -90,25 +108,7 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { } catch (InvalidKeyException e) { throw new InvalidAlgorithmParameterException("init() failed", e); } - version = (spec.getMajorVersion() << 8) | spec.getMinorVersion(); - if ((version < 0x0300) || (version > 0x0302)) { - throw new InvalidAlgorithmParameterException - ("Only SSL 3.0, TLS 1.0, and TLS 1.1 supported"); - } - // We assume the token supports the required mechanism. If it does not, - // generateKey() will fail and the failover should take care of us. - } - - protected void engineInit(int keysize, SecureRandom random) { - throw new InvalidParameterException(MSG); - } - - protected SecretKey engineGenerateKey() { - if (spec == null) { - throw new IllegalStateException - ("TlsMasterSecretGenerator must be initialized"); - } - CK_VERSION ckVersion; + this.spec = spec; if (p11Key.getAlgorithm().equals("TlsRsaPremasterSecret")) { mechanism = (version == 0x0300) ? CKM_SSL3_MASTER_KEY_DERIVE : CKM_TLS_MASTER_KEY_DERIVE; @@ -124,6 +124,17 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { : CKM_TLS_MASTER_KEY_DERIVE_DH; ckVersion = null; } + } + + protected void engineInit(int keysize, SecureRandom random) { + throw new InvalidParameterException(MSG); + } + + protected SecretKey engineGenerateKey() { + if (spec == null) { + throw new IllegalStateException + ("TlsMasterSecretGenerator must be initialized"); + } byte[] clientRandom = spec.getClientRandom(); byte[] serverRandom = spec.getServerRandom(); CK_SSL3_RANDOM_DATA random = @@ -139,13 +150,12 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { long keyID = token.p11.C_DeriveKey(session.id(), new CK_MECHANISM(mechanism, params), p11Key.keyID, attributes); int major, minor; - ckVersion = params.pVersion; - if (ckVersion == null) { + if (params.pVersion == null) { major = -1; minor = -1; } else { - major = ckVersion.major; - minor = ckVersion.minor; + major = params.pVersion.major; + minor = params.pVersion.minor; } SecretKey key = P11Key.masterSecretKey(session, keyID, "TlsMasterSecret", 48 << 3, attributes, major, minor); @@ -156,5 +166,4 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { token.releaseSession(session); } } - } diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java index 40d3a634ce5..245c067b3d4 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -60,12 +60,20 @@ final class P11TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { @SuppressWarnings("deprecation") private TlsRsaPremasterSecretParameterSpec spec; + // whether SSLv3 is supported + private final boolean supportSSLv3; + P11TlsRsaPremasterSecretGenerator(Token token, String algorithm, long mechanism) throws PKCS11Exception { super(); this.token = token; this.algorithm = algorithm; this.mechanism = mechanism; + + // Given the current lookup order specified in SunPKCS11.java, + // if CKM_SSL3_PRE_MASTER_KEY_GEN is not used to construct this object, + // it means that this mech is disabled or unsupported. + this.supportSSLv3 = (mechanism == CKM_SSL3_PRE_MASTER_KEY_GEN); } protected void engineInit(SecureRandom random) { @@ -78,7 +86,20 @@ final class P11TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) { throw new InvalidAlgorithmParameterException(MSG); } - this.spec = (TlsRsaPremasterSecretParameterSpec)params; + + TlsRsaPremasterSecretParameterSpec spec = + (TlsRsaPremasterSecretParameterSpec) params; + + int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion(); + + if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) || + (version > 0x0302)) { + throw new InvalidAlgorithmParameterException + ("Only" + (supportSSLv3? " SSL 3.0,": "") + + " TLS 1.0, and TLS 1.1 are supported (0x" + + Integer.toHexString(version) + ")"); + } + this.spec = spec; } protected void engineInit(int keysize, SecureRandom random) { diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java index cd11ad57fe9..262bbb9afd1 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/Secmod.java @@ -45,7 +45,7 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*; * * Secmod secmod = Secmod.getInstance(); * if (secmod.isInitialized() == false) { - * secmod.initialize("/home/myself/.mozilla", "/usr/sfw/lib/mozilla"); + * secmod.initialize("/home/myself/.mozilla"); * } * * Provider p = secmod.getModule(ModuleType.KEYSTORE).getProvider(); diff --git a/jdk/test/com/sun/net/httpserver/Test5.java b/jdk/test/com/sun/net/httpserver/Test5.java index b6d39439b7a..f704cf8ef42 100644 --- a/jdk/test/com/sun/net/httpserver/Test5.java +++ b/jdk/test/com/sun/net/httpserver/Test5.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -145,6 +145,7 @@ public class Test5 extends Test { socket.close(); s = new String (b,0,count, "ISO8859_1"); if (!compare (s, result)) { + System.err.println(" Expected [" + result + "]\n actual [" + s + "]"); throw new RuntimeException ("wrong string result"); } } diff --git a/jdk/test/java/io/PrintStream/FormatLocale.java b/jdk/test/java/io/PrintStream/FormatLocale.java index 08d6817d193..ce10a21b388 100644 --- a/jdk/test/java/io/PrintStream/FormatLocale.java +++ b/jdk/test/java/io/PrintStream/FormatLocale.java @@ -21,10 +21,11 @@ * questions. */ -/** +/* * @test * @bug 8146156 * @summary test whether conversion follows Locale.Category.FORMAT locale. + * @modules jdk.localedata * @run main/othervm FormatLocale */ diff --git a/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/Main.java b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/Main.java new file mode 100644 index 00000000000..8dc52c45d98 --- /dev/null +++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/Main.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8157464 + * @summary Basic test for StackWalker.getCallerClass() + * @library src + * @build java.base/java.util.CSM csm/* + * @run main/othervm csm/jdk.test.CallerSensitiveTest + * @run main/othervm csm/jdk.test.CallerSensitiveTest sm + */ +public class Main { +} + diff --git a/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/jdk/test/CallerSensitiveTest.java b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/jdk/test/CallerSensitiveTest.java new file mode 100644 index 00000000000..c09c327ec3a --- /dev/null +++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/jdk/test/CallerSensitiveTest.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.test; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodHandles.Lookup; +import java.lang.invoke.MethodType; +import java.lang.reflect.Method; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.Policy; +import java.security.ProtectionDomain; +import java.util.CSM.Result; +import java.util.function.Supplier; + +/** + * This test invokes StackWalker::getCallerClass via static reference, + * reflection, MethodHandle, lambda. Also verify that + * StackWalker::getCallerClass can't be called from @CallerSensitive method. + */ +public class CallerSensitiveTest { + private static final String NON_CSM_CALLER_METHOD = "getCallerClass"; + private static final String CSM_CALLER_METHOD = "caller"; + + public static void main(String... args) throws Throwable { + boolean sm = false; + if (args.length > 0 && args[0].equals("sm")) { + sm = true; + PermissionCollection perms = new Permissions(); + perms.add(new StackFramePermission("retainClassReference")); + Policy.setPolicy(new Policy() { + @Override + public boolean implies(ProtectionDomain domain, Permission p) { + return perms.implies(p); + } + }); + System.setSecurityManager(new SecurityManager()); + } + + System.err.format("Test %s security manager.%n", + sm ? "with" : "without"); + + CallerSensitiveTest cstest = new CallerSensitiveTest(); + // test static call to java.util.CSM::caller and CSM::getCallerClass + cstest.staticMethodCall(); + // test java.lang.reflect.Method call + cstest.reflectMethodCall(); + // test java.lang.invoke.MethodHandle + cstest.invokeMethodHandle(Lookup1.lookup); + cstest.invokeMethodHandle(Lookup2.lookup); + // test method ref + cstest.lambda(); + + LambdaTest.lambda(); + + if (failed > 0) { + throw new RuntimeException(failed + " test cases failed."); + } + } + + void staticMethodCall() { + java.util.CSM.caller(); + + Result result = java.util.CSM.getCallerClass(); + checkNonCSMCaller(CallerSensitiveTest.class, result); + } + + void reflectMethodCall() throws Throwable { + Method method1 = java.util.CSM.class.getMethod(CSM_CALLER_METHOD); + method1.invoke(null); + + Method method2 = java.util.CSM.class.getMethod(NON_CSM_CALLER_METHOD); + Result result = (Result) method2.invoke(null); + checkNonCSMCaller(CallerSensitiveTest.class, result); + } + + void invokeMethodHandle(Lookup lookup) throws Throwable { + MethodHandle mh1 = lookup.findStatic(java.util.CSM.class, CSM_CALLER_METHOD, + MethodType.methodType(Class.class)); + Class> c = (Class>)mh1.invokeExact(); + + MethodHandle mh2 = lookup.findStatic(java.util.CSM.class, NON_CSM_CALLER_METHOD, + MethodType.methodType(Result.class)); + Result result = (Result)mh2.invokeExact(); + checkNonCSMCaller(CallerSensitiveTest.class, result); + } + + void lambda() { + Result result = LambdaTest.getCallerClass.get(); + checkNonCSMCaller(CallerSensitiveTest.class, result); + + LambdaTest.caller.get(); + } + + static int failed = 0; + + static void checkNonCSMCaller(Class> expected, Result result) { + if (result.callers.size() != 1) { + throw new RuntimeException("Expected result.callers contain one element"); + } + if (expected != result.callers.get(0)) { + System.err.format("ERROR: Expected %s but got %s%n", expected, + result.callers); + result.frames.stream() + .forEach(f -> System.err.println(" " + f)); + failed++; + } + } + + static class Lookup1 { + static Lookup lookup = MethodHandles.lookup(); + } + + static class Lookup2 { + static Lookup lookup = MethodHandles.lookup(); + } + + static class LambdaTest { + static Supplier> caller = java.util.CSM::caller; + static Supplier getCallerClass = java.util.CSM::getCallerClass; + + static void caller() { + caller.get(); + } + static Result getCallerClass() { + return getCallerClass.get(); + } + + static void lambda() { + Result result = LambdaTest.getCallerClass(); + checkNonCSMCaller(LambdaTest.class, result); + + LambdaTest.caller(); + } + } +} diff --git a/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/module-info.java b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/module-info.java new file mode 100644 index 00000000000..5defa50bc41 --- /dev/null +++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/csm/module-info.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +module csm { + exports jdk.test; +} diff --git a/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/src/java.base/java/util/CSM.java b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/src/java.base/java/util/CSM.java new file mode 100644 index 00000000000..070da3547b4 --- /dev/null +++ b/jdk/test/java/lang/StackWalker/CallerSensitiveMethod/src/java.base/java/util/CSM.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.util; + +import static java.lang.StackWalker.Option.*; +import java.lang.StackWalker.StackFrame; +import java.util.stream.Collectors; + +import jdk.internal.reflect.CallerSensitive; +import jdk.internal.reflect.Reflection; + +public class CSM { + private static StackWalker walker = + StackWalker.getInstance(EnumSet.of(RETAIN_CLASS_REFERENCE, + SHOW_HIDDEN_FRAMES, + SHOW_REFLECT_FRAMES)); + + public static class Result { + public final List > callers; + public final List frames; + Result(List > callers, + List frames) { + this.callers = callers; + this.frames = frames; + } + } + + /** + * Returns the caller of this caller-sensitive method returned by + * by Reflection::getCallerClass. + * + * StackWalker::getCallerClass is expected to throw UOE + */ + @CallerSensitive + public static Class> caller() { + Class> c1 = Reflection.getCallerClass(); + + try { + Class> c2 = walker.getCallerClass(); + throw new RuntimeException("Exception not thrown by StackWalker::getCallerClass"); + } catch (UnsupportedOperationException e) {} + return c1; + } + + /** + * Returns the caller of this non-caller-sensitive method. + */ + public static Result getCallerClass() { + Class> caller = walker.getCallerClass(); + return new Result(List.of(caller), dump()); + } + + static List dump() { + return walker.walk(s -> s.collect(Collectors.toList())); + } +} diff --git a/jdk/test/java/lang/instrument/SimpleAgent.java b/jdk/test/java/lang/instrument/SimpleAgent.java new file mode 100644 index 00000000000..ea3a2a7689d --- /dev/null +++ b/jdk/test/java/lang/instrument/SimpleAgent.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.instrument.Instrumentation; + +class SimpleAgent { + + public static void premain(String args, Instrumentation inst) { + System.out.println("in premain"); + } + +} diff --git a/jdk/test/java/lang/instrument/TestAgentWithLimitMods.java b/jdk/test/java/lang/instrument/TestAgentWithLimitMods.java new file mode 100644 index 00000000000..1571774b45c --- /dev/null +++ b/jdk/test/java/lang/instrument/TestAgentWithLimitMods.java @@ -0,0 +1,40 @@ +/* + * 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 + * @summary Tests that the -javaagent option adds the java.instrument into + * the module graph + * @modules java.instrument + * @run shell MakeJAR3.sh SimpleAgent + * @run main/othervm -javaagent:SimpleAgent.jar -limitmods java.base TestAgentWithLimitMods + * + */ +public class TestAgentWithLimitMods { + + public static void main(String[] args) { + System.out.println("Test passed"); + } + +} diff --git a/jdk/test/java/lang/invoke/MethodHandlesTest.java b/jdk/test/java/lang/invoke/MethodHandlesTest.java index 0f4e7236c62..2098b5bb2a8 100644 --- a/jdk/test/java/lang/invoke/MethodHandlesTest.java +++ b/jdk/test/java/lang/invoke/MethodHandlesTest.java @@ -632,6 +632,7 @@ public class MethodHandlesTest { } public void testFindVirtualClone0() throws Throwable { + if (CAN_SKIP_WORKING) return; // test some ad hoc system methods testFindVirtual(false, PUBLIC, Object.class, Object.class, "clone"); @@ -2798,11 +2799,17 @@ public class MethodHandlesTest { toClauseMajor(postClauses, inits, steps, usePreds, finis); MethodHandle pre = MethodHandles.loop(preClauses); MethodHandle post = MethodHandles.loop(postClauses); + if (verbosity >= 6) { + System.out.println("pre-handle: " + pre); + } Object[] preResults = (Object[]) pre.invokeWithArguments(args); if (verbosity >= 4) { System.out.println("pre-checked: expected " + Arrays.asList(preCheckedResults[i]) + ", actual " + Arrays.asList(preResults)); } + if (verbosity >= 6) { + System.out.println("post-handle: " + post); + } Object[] postResults = (Object[]) post.invokeWithArguments(args); if (verbosity >= 4) { System.out.println("post-checked: expected " + Arrays.asList(postCheckedResults[i]) + ", actual " + diff --git a/jdk/test/java/net/MulticastSocket/TimeToLive.java b/jdk/test/java/net/MulticastSocket/TimeToLive.java index 6d3158f7396..009ff6d0eb3 100644 --- a/jdk/test/java/net/MulticastSocket/TimeToLive.java +++ b/jdk/test/java/net/MulticastSocket/TimeToLive.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -37,26 +37,27 @@ public class TimeToLive { static int[] bad_ttls = { -1, 256 }; public static void main(String[] args) throws Exception { - MulticastSocket socket = new MulticastSocket(6789); - int ttl = socket.getTimeToLive(); - System.out.println("default ttl: " + ttl); - for (int i = 0; i < new_ttls.length; i++) { - socket.setTimeToLive(new_ttls[i]); - if (!(new_ttls[i] == socket.getTimeToLive())) { - throw new RuntimeException("test failure, set/get differ: " + - new_ttls[i] + " / " + - socket.getTimeToLive()); + try (MulticastSocket socket = new MulticastSocket()) { + int ttl = socket.getTimeToLive(); + System.out.println("default ttl: " + ttl); + for (int i = 0; i < new_ttls.length; i++) { + socket.setTimeToLive(new_ttls[i]); + if (!(new_ttls[i] == socket.getTimeToLive())) { + throw new RuntimeException("test failure, set/get differ: " + + new_ttls[i] + " / " + + socket.getTimeToLive()); + } } - } - for (int j = 0; j < bad_ttls.length; j++) { - boolean exception = false; - try { - socket.setTimeToLive(bad_ttls[j]); - } catch (IllegalArgumentException e) { - exception = true; - } - if (!exception) { - throw new RuntimeException("bad argument accepted: " + bad_ttls[j]); + for (int j = 0; j < bad_ttls.length; j++) { + boolean exception = false; + try { + socket.setTimeToLive(bad_ttls[j]); + } catch (IllegalArgumentException e) { + exception = true; + } + if (!exception) { + throw new RuntimeException("bad argument accepted: " + bad_ttls[j]); + } } } } diff --git a/jdk/test/java/net/ServerSocket/ThreadStop.java b/jdk/test/java/net/ServerSocket/ThreadStop.java index 2ebecbb8db8..adf19379280 100644 --- a/jdk/test/java/net/ServerSocket/ThreadStop.java +++ b/jdk/test/java/net/ServerSocket/ThreadStop.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -68,23 +68,23 @@ public class ThreadStop { thr.start(); // give server time to block in ServerSocket.accept() - Thread.currentThread().sleep(2000); + Thread.sleep(2000); // "stop" the thread thr.stop(); // give thread time to stop - Thread.currentThread().sleep(2000); + Thread.sleep(2000); // it's platform specific if Thread.stop interrupts the // thread - on Linux/Windows most likely that thread is // still in accept() so we connect to server which causes // it to unblock and do JNI-stuff with a pending exception - try { - Socket s = new Socket("localhost", svr.localPort()); - } catch (IOException ioe) { } - + try (Socket s = new Socket("localhost", svr.localPort())) { + } catch (IOException ioe) { + } + thr.join(); } } diff --git a/jdk/test/java/net/Socket/InheritHandle.java b/jdk/test/java/net/Socket/InheritHandle.java index 3fa57caa68e..9a9cddae683 100644 --- a/jdk/test/java/net/Socket/InheritHandle.java +++ b/jdk/test/java/net/Socket/InheritHandle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -27,6 +27,7 @@ @author Chris Hegarty */ +import java.net.BindException; import java.net.ServerSocket; import java.io.File; import java.io.IOException; @@ -74,6 +75,11 @@ public class InheritHandle } catch (IOException ioe) { System.out.println("Cannot create process"); ioe.printStackTrace(); + try { + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } return; } @@ -85,9 +91,18 @@ public class InheritHandle System.out.println("Now close the socket and try to create another" + " one listening on the same port"); ss.close(); - ss = new ServerSocket(port); - System.out.println("Second ServerSocket created successfully"); - ss.close(); + int retries = 0; + while (retries < 5) { + try (ServerSocket s = new ServerSocket(port);) { + System.out.println("Second ServerSocket created successfully"); + break; + } catch (BindException e) { + System.out.println("BindException \"" + e.getMessage() + "\", retrying..."); + Thread.sleep(100L); + retries ++; + continue; + } + } } catch (InterruptedException ie) { } catch (IOException ioe) { diff --git a/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java b/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java index c31441d8b1a..f5af425be46 100644 --- a/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java +++ b/jdk/test/java/net/URLClassLoader/definePackage/SplitPackage.java @@ -27,6 +27,7 @@ * @summary Test two URLClassLoader define Package object of the same name * @library /lib/testlibrary * @build CompilerUtils + * @modules jdk.compiler * @run testng SplitPackage */ diff --git a/jdk/test/java/net/URLPermission/nstest/LookupTest.java b/jdk/test/java/net/URLPermission/nstest/LookupTest.java index d5b9141c1d4..eebcff5249f 100644 --- a/jdk/test/java/net/URLPermission/nstest/LookupTest.java +++ b/jdk/test/java/net/URLPermission/nstest/LookupTest.java @@ -37,6 +37,7 @@ public class LookupTest { String url, boolean throwsSecException, boolean throwsIOException) { try { + ProxySelector.setDefault(null); URL u = new URL(url); System.err.println ("Connecting to " + u); URLConnection urlc = u.openConnection(); @@ -71,7 +72,7 @@ public class LookupTest { System.out.print(port); } else if (cmd.equals("-runtest")) { port = Integer.parseInt(args[1]); - String hostsFileName = System.getProperty("test.src", ".") + "/LookupTestHosts"; + String hostsFileName = System.getProperty("user.dir", ".") + "/LookupTestHosts"; System.setProperty("jdk.net.hosts.file", hostsFileName); addMappingToHostsFile("allowedAndFound.com", "127.0.0.1", hostsFileName, false); addMappingToHostsFile("notAllowedButFound.com", "99.99.99.99", hostsFileName, true); diff --git a/jdk/test/java/net/URLPermission/nstest/LookupTestHosts b/jdk/test/java/net/URLPermission/nstest/LookupTestHosts deleted file mode 100644 index 0e64bb8c49f..00000000000 --- a/jdk/test/java/net/URLPermission/nstest/LookupTestHosts +++ /dev/null @@ -1,2 +0,0 @@ -127.0.0.1 allowedAndFound.com -99.99.99.99 notAllowedButFound.com diff --git a/jdk/test/java/net/URLPermission/nstest/lookup.sh b/jdk/test/java/net/URLPermission/nstest/lookup.sh index 798e1c168f6..a6b495c9f35 100644 --- a/jdk/test/java/net/URLPermission/nstest/lookup.sh +++ b/jdk/test/java/net/URLPermission/nstest/lookup.sh @@ -48,6 +48,7 @@ cat << POLICY > policy grant { permission java.net.URLPermission "http://allowedAndFound.com:${port}/-", "*:*"; permission java.net.URLPermission "http://allowedButNotfound.com:${port}/-", "*:*"; + permission java.net.NetPermission "setProxySelector"; permission java.io.FilePermission "< >", "read,write,delete"; permission java.util.PropertyPermission "java.io.tmpdir", "read"; diff --git a/jdk/test/java/net/httpclient/HeadersTest1.java b/jdk/test/java/net/httpclient/HeadersTest1.java index e3c892ef2c1..2c8540e9e83 100644 --- a/jdk/test/java/net/httpclient/HeadersTest1.java +++ b/jdk/test/java/net/httpclient/HeadersTest1.java @@ -23,9 +23,11 @@ * questions. */ -/** +/* * @test * @bug 8153142 + * @modules java.httpclient + * jdk.httpserver * @run main/othervm HeadersTest1 * @summary HeadersTest1 */ @@ -39,9 +41,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; -import java.net.PasswordAuthentication; import java.net.URI; -import java.net.http.*; +import java.net.http.HttpClient; +import java.net.http.HttpHeaders; +import java.net.http.HttpResponse; +import java.net.http.HttpRequest; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.List; diff --git a/jdk/test/java/net/httpclient/ProxyAuthTest.java b/jdk/test/java/net/httpclient/ProxyAuthTest.java index 42bc0c709db..4301e06d708 100644 --- a/jdk/test/java/net/httpclient/ProxyAuthTest.java +++ b/jdk/test/java/net/httpclient/ProxyAuthTest.java @@ -26,6 +26,7 @@ * @test * @bug 8163561 * @modules java.base/sun.net.www + * java.httpclient * @summary Verify that Proxy-Authenticate header is correctly handled * * @run main/othervm ProxyAuthTest diff --git a/jdk/test/java/net/httpclient/whitebox/Driver.java b/jdk/test/java/net/httpclient/whitebox/Driver.java index fbbdb05dbed..b1cc54be137 100644 --- a/jdk/test/java/net/httpclient/whitebox/Driver.java +++ b/jdk/test/java/net/httpclient/whitebox/Driver.java @@ -24,5 +24,6 @@ /* * @test * @bug 8151299 + * @modules java.httpclient * @run testng java.httpclient/java.net.http.SelectorTest */ diff --git a/jdk/test/java/util/Collections/EmptyNavigableMap.java b/jdk/test/java/util/Collections/EmptyNavigableMap.java index 5daf055786a..359d30f4ab6 100644 --- a/jdk/test/java/util/Collections/EmptyNavigableMap.java +++ b/jdk/test/java/util/Collections/EmptyNavigableMap.java @@ -33,7 +33,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; -import java.util.NoSuchElementException; import java.util.NavigableMap; import java.util.SortedMap; import java.util.TreeMap; @@ -41,10 +40,8 @@ import org.testng.annotations.Test; import org.testng.annotations.DataProvider; import static org.testng.Assert.fail; -import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertSame; public class EmptyNavigableMap { diff --git a/jdk/test/java/util/Collections/EmptyNavigableSet.java b/jdk/test/java/util/Collections/EmptyNavigableSet.java index 7541f3d363b..afe216da8d7 100644 --- a/jdk/test/java/util/Collections/EmptyNavigableSet.java +++ b/jdk/test/java/util/Collections/EmptyNavigableSet.java @@ -41,10 +41,9 @@ import org.testng.annotations.Test; import org.testng.annotations.DataProvider; import static org.testng.Assert.fail; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; public class EmptyNavigableSet { diff --git a/jdk/test/java/util/Deque/ChorusLine.java b/jdk/test/java/util/Deque/ChorusLine.java index 2a09c65ef50..9f0d6f89aa5 100644 --- a/jdk/test/java/util/Deque/ChorusLine.java +++ b/jdk/test/java/util/Deque/ChorusLine.java @@ -28,8 +28,14 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.LinkedBlockingDeque; public class ChorusLine { private interface Tweaker { diff --git a/jdk/test/java/util/PriorityQueue/ForgetMeNot.java b/jdk/test/java/util/PriorityQueue/ForgetMeNot.java index 7778d1d793d..6f9f65d529e 100644 --- a/jdk/test/java/util/PriorityQueue/ForgetMeNot.java +++ b/jdk/test/java/util/PriorityQueue/ForgetMeNot.java @@ -28,7 +28,11 @@ * @author Martin Buchholz */ -import java.util.*; +import java.util.Arrays; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.PriorityQueue; +import java.util.Queue; public class ForgetMeNot { private static void checkQ(PriorityQueue q, Integer...elts) { diff --git a/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java b/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java index 206d6e815c5..24229639163 100644 --- a/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java +++ b/jdk/test/java/util/PriorityQueue/PriorityQueueSort.java @@ -37,7 +37,13 @@ * @summary Checks that a priority queue returns elements in sorted order across various operations */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Queue; +import java.util.PriorityQueue; public class PriorityQueueSort { diff --git a/jdk/test/java/util/PriorityQueue/RemoveContains.java b/jdk/test/java/util/PriorityQueue/RemoveContains.java index 4b5d5a93bf2..809478221dd 100644 --- a/jdk/test/java/util/PriorityQueue/RemoveContains.java +++ b/jdk/test/java/util/PriorityQueue/RemoveContains.java @@ -28,8 +28,17 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.PriorityBlockingQueue; +import java.util.concurrent.LinkedTransferQueue; public class RemoveContains { static volatile int passed = 0, failed = 0; diff --git a/jdk/test/java/util/concurrent/Executors/AutoShutdown.java b/jdk/test/java/util/concurrent/Executors/AutoShutdown.java index 7e34e28bded..95dd38c02cc 100644 --- a/jdk/test/java/util/concurrent/Executors/AutoShutdown.java +++ b/jdk/test/java/util/concurrent/Executors/AutoShutdown.java @@ -31,8 +31,6 @@ */ import static java.util.concurrent.Executors.defaultThreadFactory; -import static java.util.concurrent.Executors.newFixedThreadPool; -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.MILLISECONDS; diff --git a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java index 088907cae77..a8bb4c29615 100644 --- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java +++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java @@ -83,15 +83,18 @@ public class CoreThreadTimeOut { tpe.allowCoreThreadTimeOut(true); check(tpe.allowsCoreThreadTimeOut()); equal(countExecutorThreads(), 0); - long t0 = System.nanoTime(); - for (int i = 0; i < threadCount; i++) - tpe.submit(new Runnable() { public void run() {}}); - int count = countExecutorThreads(); - if (millisElapsedSince(t0) < timeoutMillis) - equal(count, threadCount); + long startTime = System.nanoTime(); + for (int i = 0; i < threadCount; i++) { + tpe.submit(() -> {}); + int count = countExecutorThreads(); + if (millisElapsedSince(startTime) < timeoutMillis) + equal(count, i + 1); + } while (countExecutorThreads() > 0 && - millisElapsedSince(t0) < 10 * 1000); + millisElapsedSince(startTime) < LONG_DELAY_MS) + Thread.yield(); equal(countExecutorThreads(), 0); + check(millisElapsedSince(startTime) >= timeoutMillis); tpe.shutdown(); check(tpe.allowsCoreThreadTimeOut()); check(tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); diff --git a/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java b/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java index d3d8f14f5c0..e12284063f1 100644 --- a/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java +++ b/jdk/test/java/util/concurrent/tck/AtomicIntegerArrayTest.java @@ -303,7 +303,7 @@ public class AtomicIntegerArrayTest extends JSR166TestCase { class Counter extends CheckedRunnable { final AtomicIntegerArray aa; - volatile int counts; + int decs; Counter(AtomicIntegerArray a) { aa = a; } public void realRun() { for (;;) { @@ -314,7 +314,7 @@ public class AtomicIntegerArrayTest extends JSR166TestCase { if (v != 0) { done = false; if (aa.compareAndSet(i, v, v - 1)) - ++counts; + decs++; } } if (done) @@ -334,13 +334,11 @@ public class AtomicIntegerArrayTest extends JSR166TestCase { aa.set(i, countdown); Counter c1 = new Counter(aa); Counter c2 = new Counter(aa); - Thread t1 = new Thread(c1); - Thread t2 = new Thread(c2); - t1.start(); - t2.start(); + Thread t1 = newStartedThread(c1); + Thread t2 = newStartedThread(c2); t1.join(); t2.join(); - assertEquals(c1.counts+c2.counts, SIZE * countdown); + assertEquals(c1.decs + c2.decs, SIZE * countdown); } /** diff --git a/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java b/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java index bd74addbf7f..b312388dd6a 100644 --- a/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java +++ b/jdk/test/java/util/concurrent/tck/AtomicLongArrayTest.java @@ -302,7 +302,7 @@ public class AtomicLongArrayTest extends JSR166TestCase { class Counter extends CheckedRunnable { final AtomicLongArray aa; - volatile long counts; + int decs; Counter(AtomicLongArray a) { aa = a; } public void realRun() { for (;;) { @@ -313,7 +313,7 @@ public class AtomicLongArrayTest extends JSR166TestCase { if (v != 0) { done = false; if (aa.compareAndSet(i, v, v - 1)) - ++counts; + decs++; } } if (done) @@ -333,13 +333,11 @@ public class AtomicLongArrayTest extends JSR166TestCase { aa.set(i, countdown); Counter c1 = new Counter(aa); Counter c2 = new Counter(aa); - Thread t1 = new Thread(c1); - Thread t2 = new Thread(c2); - t1.start(); - t2.start(); + Thread t1 = newStartedThread(c1); + Thread t2 = newStartedThread(c2); t1.join(); t2.join(); - assertEquals(c1.counts+c2.counts, SIZE * countdown); + assertEquals(c1.decs + c2.decs, SIZE * countdown); } /** diff --git a/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java b/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java index a29f50e0a24..12f7ee99b53 100644 --- a/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java +++ b/jdk/test/java/util/concurrent/tck/CompletableFutureTest.java @@ -388,7 +388,7 @@ public class CompletableFutureTest extends JSR166TestCase { checkCompletedNormally(f, "test"); } - abstract class CheckedAction { + abstract static class CheckedAction { int invocationCount = 0; final ExecutionMode m; CheckedAction(ExecutionMode m) { this.m = m; } @@ -400,7 +400,7 @@ public class CompletableFutureTest extends JSR166TestCase { void assertInvoked() { assertEquals(1, invocationCount); } } - abstract class CheckedIntegerAction extends CheckedAction { + abstract static class CheckedIntegerAction extends CheckedAction { Integer value; CheckedIntegerAction(ExecutionMode m) { super(m); } void assertValue(Integer expected) { @@ -409,7 +409,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class IntegerSupplier extends CheckedAction + static class IntegerSupplier extends CheckedAction implements Supplier { final Integer value; @@ -428,7 +428,7 @@ public class CompletableFutureTest extends JSR166TestCase { return (x == null) ? null : x + 1; } - class NoopConsumer extends CheckedIntegerAction + static class NoopConsumer extends CheckedIntegerAction implements Consumer { NoopConsumer(ExecutionMode m) { super(m); } @@ -438,7 +438,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class IncFunction extends CheckedIntegerAction + static class IncFunction extends CheckedIntegerAction implements Function { IncFunction(ExecutionMode m) { super(m); } @@ -456,7 +456,7 @@ public class CompletableFutureTest extends JSR166TestCase { - ((y == null) ? 99 : y.intValue()); } - class SubtractAction extends CheckedIntegerAction + static class SubtractAction extends CheckedIntegerAction implements BiConsumer { SubtractAction(ExecutionMode m) { super(m); } @@ -466,7 +466,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class SubtractFunction extends CheckedIntegerAction + static class SubtractFunction extends CheckedIntegerAction implements BiFunction { SubtractFunction(ExecutionMode m) { super(m); } @@ -476,14 +476,14 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class Noop extends CheckedAction implements Runnable { + static class Noop extends CheckedAction implements Runnable { Noop(ExecutionMode m) { super(m); } public void run() { invoked(); } } - class FailingSupplier extends CheckedAction + static class FailingSupplier extends CheckedAction implements Supplier { final CFException ex; @@ -494,7 +494,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingConsumer extends CheckedIntegerAction + static class FailingConsumer extends CheckedIntegerAction implements Consumer { final CFException ex; @@ -506,7 +506,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingBiConsumer extends CheckedIntegerAction + static class FailingBiConsumer extends CheckedIntegerAction implements BiConsumer { final CFException ex; @@ -518,7 +518,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingFunction extends CheckedIntegerAction + static class FailingFunction extends CheckedIntegerAction implements Function { final CFException ex; @@ -530,7 +530,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingBiFunction extends CheckedIntegerAction + static class FailingBiFunction extends CheckedIntegerAction implements BiFunction { final CFException ex; @@ -542,7 +542,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingRunnable extends CheckedAction implements Runnable { + static class FailingRunnable extends CheckedAction implements Runnable { final CFException ex; FailingRunnable(ExecutionMode m) { super(m); ex = new CFException(); } public void run() { @@ -551,7 +551,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class CompletableFutureInc extends CheckedIntegerAction + static class CompletableFutureInc extends CheckedIntegerAction implements Function > { CompletableFutureInc(ExecutionMode m) { super(m); } @@ -564,7 +564,7 @@ public class CompletableFutureTest extends JSR166TestCase { } } - class FailingCompletableFutureFunction extends CheckedIntegerAction + static class FailingCompletableFutureFunction extends CheckedIntegerAction implements Function > { final CFException ex; @@ -3604,29 +3604,53 @@ public class CompletableFutureTest extends JSR166TestCase { * copy returns a CompletableFuture that is completed normally, * with the same value, when source is. */ - public void testCopy() { + public void testCopy_normalCompletion() { + for (boolean createIncomplete : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { CompletableFuture f = new CompletableFuture<>(); + if (!createIncomplete) assertTrue(f.complete(v1)); CompletableFuture g = f.copy(); - checkIncomplete(f); - checkIncomplete(g); - f.complete(1); - checkCompletedNormally(f, 1); - checkCompletedNormally(g, 1); - } + if (createIncomplete) { + checkIncomplete(f); + checkIncomplete(g); + assertTrue(f.complete(v1)); + } + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v1); + }} /** * copy returns a CompletableFuture that is completed exceptionally * when source is. */ - public void testCopy2() { - CompletableFuture f = new CompletableFuture<>(); - CompletableFuture g = f.copy(); - checkIncomplete(f); - checkIncomplete(g); + public void testCopy_exceptionalCompletion() { + for (boolean createIncomplete : new boolean[] { true, false }) + { CFException ex = new CFException(); - f.completeExceptionally(ex); + CompletableFuture f = new CompletableFuture<>(); + if (!createIncomplete) f.completeExceptionally(ex); + CompletableFuture g = f.copy(); + if (createIncomplete) { + checkIncomplete(f); + checkIncomplete(g); + f.completeExceptionally(ex); + } checkCompletedExceptionally(f, ex); checkCompletedWithWrappedException(g, ex); + }} + + /** + * Completion of a copy does not complete its source. + */ + public void testCopy_oneWayPropagation() { + CompletableFuture f = new CompletableFuture<>(); + assertTrue(f.copy().complete(1)); + assertTrue(f.copy().complete(null)); + assertTrue(f.copy().cancel(true)); + assertTrue(f.copy().cancel(false)); + assertTrue(f.copy().completeExceptionally(new CFException())); + checkIncomplete(f); } /** @@ -3991,7 +4015,10 @@ public class CompletableFutureTest extends JSR166TestCase { .collect(Collectors.toList()); List > stages = new ArrayList<>(); - stages.add(new CompletableFuture ().minimalCompletionStage()); + CompletionStage min = + new CompletableFuture ().minimalCompletionStage(); + stages.add(min); + stages.add(min.thenApply(x -> x)); stages.add(CompletableFuture.completedStage(1)); stages.add(CompletableFuture.failedStage(new CFException())); @@ -4027,6 +4054,131 @@ public class CompletableFutureTest extends JSR166TestCase { throw new Error("Methods did not throw UOE: " + bugs); } + /** + * minimalStage.toCompletableFuture() returns a CompletableFuture that + * is completed normally, with the same value, when source is. + */ + public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() { + for (boolean createIncomplete : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { + CompletableFuture f = new CompletableFuture<>(); + CompletionStage minimal = f.minimalCompletionStage(); + if (!createIncomplete) assertTrue(f.complete(v1)); + CompletableFuture g = minimal.toCompletableFuture(); + if (createIncomplete) { + checkIncomplete(f); + checkIncomplete(g); + assertTrue(f.complete(v1)); + } + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v1); + }} + + /** + * minimalStage.toCompletableFuture() returns a CompletableFuture that + * is completed exceptionally when source is. + */ + public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() { + for (boolean createIncomplete : new boolean[] { true, false }) + { + CFException ex = new CFException(); + CompletableFuture f = new CompletableFuture<>(); + CompletionStage minimal = f.minimalCompletionStage(); + if (!createIncomplete) f.completeExceptionally(ex); + CompletableFuture g = minimal.toCompletableFuture(); + if (createIncomplete) { + checkIncomplete(f); + checkIncomplete(g); + f.completeExceptionally(ex); + } + checkCompletedExceptionally(f, ex); + checkCompletedWithWrappedException(g, ex); + }} + + /** + * minimalStage.toCompletableFuture() gives mutable CompletableFuture + */ + public void testMinimalCompletionStage_toCompletableFuture_mutable() { + for (Integer v1 : new Integer[] { 1, null }) + { + CompletableFuture f = new CompletableFuture<>(); + CompletionStage minimal = f.minimalCompletionStage(); + CompletableFuture g = minimal.toCompletableFuture(); + assertTrue(g.complete(v1)); + checkCompletedNormally(g, v1); + checkIncomplete(f); + checkIncomplete(minimal.toCompletableFuture()); + }} + + /** + * minimalStage.toCompletableFuture().join() awaits completion + */ + public void testMinimalCompletionStage_toCompletableFuture_join() throws Exception { + for (boolean createIncomplete : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { + CompletableFuture f = new CompletableFuture<>(); + if (!createIncomplete) assertTrue(f.complete(v1)); + CompletionStage minimal = f.minimalCompletionStage(); + if (createIncomplete) assertTrue(f.complete(v1)); + assertEquals(v1, minimal.toCompletableFuture().join()); + assertEquals(v1, minimal.toCompletableFuture().get()); + checkCompletedNormally(minimal.toCompletableFuture(), v1); + }} + + /** + * Completion of a toCompletableFuture copy of a minimal stage + * does not complete its source. + */ + public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() { + CompletableFuture f = new CompletableFuture<>(); + CompletionStage g = f.minimalCompletionStage(); + assertTrue(g.toCompletableFuture().complete(1)); + assertTrue(g.toCompletableFuture().complete(null)); + assertTrue(g.toCompletableFuture().cancel(true)); + assertTrue(g.toCompletableFuture().cancel(false)); + assertTrue(g.toCompletableFuture().completeExceptionally(new CFException())); + checkIncomplete(g.toCompletableFuture()); + f.complete(1); + checkCompletedNormally(g.toCompletableFuture(), 1); + } + + /** Demo utility method for external reliable toCompletableFuture */ + static CompletableFuture toCompletableFuture(CompletionStage stage) { + CompletableFuture f = new CompletableFuture<>(); + stage.handle((T t, Throwable ex) -> { + if (ex != null) f.completeExceptionally(ex); + else f.complete(t); + return null; + }); + return f; + } + + /** Demo utility method to join a CompletionStage */ + static T join(CompletionStage stage) { + return toCompletableFuture(stage).join(); + } + + /** + * Joining a minimal stage "by hand" works + */ + public void testMinimalCompletionStage_join_by_hand() { + for (boolean createIncomplete : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { + CompletableFuture f = new CompletableFuture<>(); + CompletionStage minimal = f.minimalCompletionStage(); + CompletableFuture g = new CompletableFuture<>(); + if (!createIncomplete) assertTrue(f.complete(v1)); + minimal.thenAccept((x) -> g.complete(x)); + if (createIncomplete) assertTrue(f.complete(v1)); + g.join(); + checkCompletedNormally(g, v1); + checkCompletedNormally(f, v1); + assertEquals(v1, join(minimal)); + }} + static class Monad { static class ZeroException extends RuntimeException { public ZeroException() { super("monadic zero"); } @@ -4317,6 +4469,22 @@ public class CompletableFutureTest extends JSR166TestCase { assertTrue(neverCompleted.thenRun(() -> {}).cancel(true)); } + /** + * Checks for garbage retention when MinimalStage.toCompletableFuture() + * is invoked many times. + * 8161600: Garbage retention when source CompletableFutures are never completed + * + * As of 2016-07, fails with OOME: + * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testToCompletableFutureGarbageRetention tck + */ + public void testToCompletableFutureGarbageRetention() throws Throwable { + final int n = expensiveTests ? 900_000 : 10; + CompletableFuture neverCompleted = new CompletableFuture<>(); + CompletionStage minimal = neverCompleted.minimalCompletionStage(); + for (int i = 0; i < n; i++) + assertTrue(minimal.toCompletableFuture().cancel(true)); + } + // static U join(CompletionStage stage) { // CompletableFuture f = new CompletableFuture<>(); // stage.whenComplete((v, ex) -> { diff --git a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java index 515303e3e64..0b1faad2824 100644 --- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java +++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListMapTest.java @@ -1024,7 +1024,7 @@ public class ConcurrentSkipListMapTest extends JSR166TestCase { static NavigableMap newMap(Class cl) throws Exception { NavigableMap result = - (NavigableMap ) cl.newInstance(); + (NavigableMap ) cl.getConstructor().newInstance(); assertEquals(0, result.size()); assertFalse(result.keySet().iterator().hasNext()); return result; diff --git a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java index 4ec79c8edd3..28c9f6bd81b 100644 --- a/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java +++ b/jdk/test/java/util/concurrent/tck/ConcurrentSkipListSetTest.java @@ -725,7 +725,8 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase { } static NavigableSet newSet(Class cl) throws Exception { - NavigableSet result = (NavigableSet ) cl.newInstance(); + NavigableSet result = + (NavigableSet ) cl.getConstructor().newInstance(); assertEquals(0, result.size()); assertFalse(result.iterator().hasNext()); return result; diff --git a/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java b/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java index bfae2ee323b..8db1063dce9 100644 --- a/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java +++ b/jdk/test/java/util/concurrent/tck/CyclicBarrierTest.java @@ -40,6 +40,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import junit.framework.Test; import junit.framework.TestSuite; @@ -52,11 +53,6 @@ public class CyclicBarrierTest extends JSR166TestCase { return new TestSuite(CyclicBarrierTest.class); } - private volatile int countAction; - private class MyAction implements Runnable { - public void run() { ++countAction; } - } - /** * Spin-waits till the number of waiters == numberOfWaiters. */ @@ -114,14 +110,16 @@ public class CyclicBarrierTest extends JSR166TestCase { * The supplied barrier action is run at barrier */ public void testBarrierAction() throws Exception { - countAction = 0; - CyclicBarrier b = new CyclicBarrier(1, new MyAction()); + final AtomicInteger count = new AtomicInteger(0); + final Runnable incCount = new Runnable() { public void run() { + count.getAndIncrement(); }}; + CyclicBarrier b = new CyclicBarrier(1, incCount); assertEquals(1, b.getParties()); assertEquals(0, b.getNumberWaiting()); b.await(); b.await(); assertEquals(0, b.getNumberWaiting()); - assertEquals(2, countAction); + assertEquals(2, count.get()); } /** diff --git a/jdk/test/java/util/concurrent/tck/DelayQueueTest.java b/jdk/test/java/util/concurrent/tck/DelayQueueTest.java index 4d05c864554..d4a6bdc969c 100644 --- a/jdk/test/java/util/concurrent/tck/DelayQueueTest.java +++ b/jdk/test/java/util/concurrent/tck/DelayQueueTest.java @@ -121,10 +121,8 @@ public class DelayQueueTest extends JSR166TestCase { } public boolean equals(Object other) { - return equals((NanoDelay)other); - } - public boolean equals(NanoDelay other) { - return other.trigger == trigger; + return (other instanceof NanoDelay) && + this.trigger == ((NanoDelay)other).trigger; } // suppress [overrides] javac warning diff --git a/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java b/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java index 282557d97b7..70004764a78 100644 --- a/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java +++ b/jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java @@ -51,6 +51,7 @@ import java.util.concurrent.Future; import java.util.concurrent.RecursiveTask; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; import junit.framework.AssertionFailedError; @@ -84,13 +85,6 @@ public class ForkJoinPoolTest extends JSR166TestCase { // Some classes to test extension and factory methods - static class MyHandler implements Thread.UncaughtExceptionHandler { - volatile int catches = 0; - public void uncaughtException(Thread t, Throwable e) { - ++catches; - } - } - static class MyError extends Error {} // to test handlers @@ -101,9 +95,9 @@ public class ForkJoinPoolTest extends JSR166TestCase { static class FailingThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory { - volatile int calls = 0; + final AtomicInteger calls = new AtomicInteger(0); public ForkJoinWorkerThread newThread(ForkJoinPool p) { - if (++calls > 1) return null; + if (calls.incrementAndGet() > 1) return null; return new FailingFJWSubclass(p); } } diff --git a/jdk/test/java/util/concurrent/tck/JSR166TestCase.java b/jdk/test/java/util/concurrent/tck/JSR166TestCase.java index aaa97d8abcb..8a0360f9b99 100644 --- a/jdk/test/java/util/concurrent/tck/JSR166TestCase.java +++ b/jdk/test/java/util/concurrent/tck/JSR166TestCase.java @@ -1032,14 +1032,17 @@ public class JSR166TestCase extends TestCase { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); System.err.println("------ stacktrace dump start ------"); for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { - String name = info.getThreadName(); + final String name = info.getThreadName(); + String lockName; if ("Signal Dispatcher".equals(name)) continue; if ("Reference Handler".equals(name) - && info.getLockName().startsWith("java.lang.ref.Reference$Lock")) + && (lockName = info.getLockName()) != null + && lockName.startsWith("java.lang.ref.Reference$Lock")) continue; if ("Finalizer".equals(name) - && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) + && (lockName = info.getLockName()) != null + && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) continue; if ("checkForWedgedTest".equals(name)) continue; @@ -1783,7 +1786,7 @@ public class JSR166TestCase extends TestCase { * A CyclicBarrier that uses timed await and fails with * AssertionFailedErrors instead of throwing checked exceptions. */ - public class CheckedBarrier extends CyclicBarrier { + public static class CheckedBarrier extends CyclicBarrier { public CheckedBarrier(int parties) { super(parties); } public int await() { diff --git a/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java b/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java index 1cb2a472658..0946d006276 100644 --- a/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java +++ b/jdk/test/java/util/concurrent/tck/ScheduledExecutorTest.java @@ -537,15 +537,14 @@ public class ScheduledExecutorTest extends JSR166TestCase { * isShutdown is false before shutdown, true after */ public void testIsShutdown() { - final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); - try { - assertFalse(p.isShutdown()); + assertFalse(p.isShutdown()); + try (PoolCleaner cleaner = cleaner(p)) { + try { + p.shutdown(); + assertTrue(p.isShutdown()); + } catch (SecurityException ok) {} } - finally { - try { p.shutdown(); } catch (SecurityException ok) { return; } - } - assertTrue(p.isShutdown()); } /** diff --git a/jdk/test/java/util/concurrent/tck/TreeMapTest.java b/jdk/test/java/util/concurrent/tck/TreeMapTest.java index ebf1dd01b9b..ada561ea119 100644 --- a/jdk/test/java/util/concurrent/tck/TreeMapTest.java +++ b/jdk/test/java/util/concurrent/tck/TreeMapTest.java @@ -829,7 +829,7 @@ public class TreeMapTest extends JSR166TestCase { static NavigableMap newMap(Class cl) throws Exception { NavigableMap result - = (NavigableMap ) cl.newInstance(); + = (NavigableMap ) cl.getConstructor().newInstance(); assertEquals(0, result.size()); assertFalse(result.keySet().iterator().hasNext()); return result; diff --git a/jdk/test/java/util/concurrent/tck/TreeSetTest.java b/jdk/test/java/util/concurrent/tck/TreeSetTest.java index eb7b6efd9d0..dc5b007b0d3 100644 --- a/jdk/test/java/util/concurrent/tck/TreeSetTest.java +++ b/jdk/test/java/util/concurrent/tck/TreeSetTest.java @@ -722,7 +722,8 @@ public class TreeSetTest extends JSR166TestCase { } static NavigableSet newSet(Class cl) throws Exception { - NavigableSet result = (NavigableSet ) cl.newInstance(); + NavigableSet result = + (NavigableSet ) cl.getConstructor().newInstance(); assertEquals(0, result.size()); assertFalse(result.iterator().hasNext()); return result; diff --git a/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java b/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java index 1dd55404a6c..31dc1e74038 100644 --- a/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java +++ b/jdk/test/jdk/internal/misc/Unsafe/TestBadHostClass.java @@ -25,7 +25,6 @@ * @test * @bug 8058575 * @summary Test that bad host classes cause exceptions to get thrown. - * @library /test/lib * @modules java.base/jdk.internal.misc * java.base/jdk.internal.org.objectweb.asm * @run main TestBadHostClass @@ -35,7 +34,6 @@ import java.lang.*; import java.lang.reflect.Field; import jdk.internal.misc.Unsafe; -import jdk.test.lib.unsafe.UnsafeHelper; import jdk.internal.org.objectweb.asm.ClassWriter; import static jdk.internal.org.objectweb.asm.Opcodes.*; diff --git a/jdk/test/jprt.config b/jdk/test/jprt.config index 3d6c975a398..9f438197ec3 100644 --- a/jdk/test/jprt.config +++ b/jdk/test/jprt.config @@ -82,15 +82,12 @@ if [ "${osname}" = SunOS ] ; then fi # Add basic solaris system paths - path4sdk=/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin + path4sdk=/usr/bin:/usr/gnu/bin # Find GNU make - make=/usr/sfw/bin/gmake + make=/usr/bin/gmake if [ ! -f ${make} ] ; then - make=/opt/sfw/bin/gmake - if [ ! -f ${make} ] ; then - make=${slashjava}/devtools/${solaris_arch}/bin/gnumake - fi + make=${slashjava}/devtools/${solaris_arch}/bin/gnumake fi fileMustExist "${make}" make diff --git a/jdk/test/start-Xvfb.sh b/jdk/test/start-Xvfb.sh index ea3d16c9997..ec6a4a2b1c7 100644 --- a/jdk/test/start-Xvfb.sh +++ b/jdk/test/start-Xvfb.sh @@ -59,9 +59,6 @@ else /usr/bin/nohup /usr/bin/X11/Xvfb -fbdir ${currentDir} -pixdepths 8 16 24 32 ${DISPLAY} > ${currentDir}/nohup.$$ 2>&1 & fi WM="/usr/bin/X11/fvwm2" -if [ ! -x ${WM} ] ; then - WM="/opt/sfw/bin/fvwm2" -fi # # Wait for Xvfb to initialize: sleep 5 diff --git a/jdk/test/sun/nio/cs/TestUnmappable.java b/jdk/test/sun/nio/cs/TestUnmappable.java index 6273807cce3..8204fdf4d10 100644 --- a/jdk/test/sun/nio/cs/TestUnmappable.java +++ b/jdk/test/sun/nio/cs/TestUnmappable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -28,11 +28,11 @@ * @bug 8008386 * @summary (cs) Unmappable leading should be decoded to replacement. * Tests for Shift_JIS and MS932 decoding + * @modules jdk.charsets * @run main TestUnmappable */ -import java.nio.*; -import java.nio.charset.*; +import java.nio.charset.Charset; public class TestUnmappable { public static void main(String args[]) throws Exception { diff --git a/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java b/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java index 27944e92f89..81a8b4571ba 100644 --- a/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java +++ b/jdk/test/sun/security/pkcs11/tls/TestKeyMaterial.java @@ -23,7 +23,7 @@ /* * @test - * @bug 6316539 + * @bug 6316539 8136355 * @summary Known-answer-test for TlsKeyMaterial generator * @author Andreas Sterbenz * @library .. @@ -37,6 +37,7 @@ import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Paths; import java.security.Provider; +import java.security.InvalidAlgorithmParameterException; import java.util.Arrays; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; @@ -139,21 +140,28 @@ public class TestKeyMaterial extends PKCS11Test { keyLength, expandedKeyLength, ivLength, macLength, null, -1, -1); - kg.init(spec); - TlsKeyMaterialSpec result = - (TlsKeyMaterialSpec)kg.generateKey(); - match(lineNumber, clientCipherBytes, - result.getClientCipherKey(), cipherAlgorithm); - match(lineNumber, serverCipherBytes, - result.getServerCipherKey(), cipherAlgorithm); - match(lineNumber, clientIv, result.getClientIv(), ""); - match(lineNumber, serverIv, result.getServerIv(), ""); - match(lineNumber, clientMacBytes, result.getClientMacKey(), ""); - match(lineNumber, serverMacBytes, result.getServerMacKey(), ""); - - } else { + try { + kg.init(spec); + TlsKeyMaterialSpec result = + (TlsKeyMaterialSpec)kg.generateKey(); + match(lineNumber, clientCipherBytes, + result.getClientCipherKey(), cipherAlgorithm); + match(lineNumber, serverCipherBytes, + result.getServerCipherKey(), cipherAlgorithm); + match(lineNumber, clientIv, result.getClientIv(), ""); + match(lineNumber, serverIv, result.getServerIv(), ""); + match(lineNumber, clientMacBytes, result.getClientMacKey(), ""); + match(lineNumber, serverMacBytes, result.getServerMacKey(), ""); + } catch (InvalidAlgorithmParameterException iape) { + // SSLv3 support is removed in S12 + if (major == 3 && minor == 0) { + System.out.println("Skip testing SSLv3"); + continue; + } + } + } else { throw new Exception("Unknown line: " + line); - } + } } if (n == 0) { throw new Exception("no tests"); diff --git a/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java b/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java index 67ee6e708bd..de6863608d5 100644 --- a/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java +++ b/jdk/test/sun/security/pkcs11/tls/TestMasterSecret.java @@ -23,7 +23,7 @@ /* * @test - * @bug 6316539 + * @bug 6316539 8136355 * @summary Known-answer-test for TlsMasterSecret generator * @author Andreas Sterbenz * @library .. @@ -38,6 +38,7 @@ import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Paths; import java.security.Provider; +import java.security.InvalidAlgorithmParameterException; import java.util.Arrays; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; @@ -116,15 +117,24 @@ public class TestMasterSecret extends PKCS11Test { new TlsMasterSecretParameterSpec(premasterKey, protoMajor, protoMinor, clientRandom, serverRandom, null, -1, -1); - kg.init(spec); - TlsMasterSecret key = (TlsMasterSecret)kg.generateKey(); - byte[] enc = key.getEncoded(); - if (Arrays.equals(master, enc) == false) { - throw new Exception("mismatch line: " + lineNumber); - } - if ((preMajor != key.getMajorVersion()) || - (preMinor != key.getMinorVersion())) { - throw new Exception("version mismatch line: " + lineNumber); + + try { + kg.init(spec); + TlsMasterSecret key = (TlsMasterSecret)kg.generateKey(); + byte[] enc = key.getEncoded(); + if (Arrays.equals(master, enc) == false) { + throw new Exception("mismatch line: " + lineNumber); + } + if ((preMajor != key.getMajorVersion()) || + (preMinor != key.getMinorVersion())) { + throw new Exception("version mismatch line: " + lineNumber); + } + } catch (InvalidAlgorithmParameterException iape) { + // SSLv3 support is removed in S12 + if (preMajor == 3 && preMinor == 0) { + System.out.println("Skip testing SSLv3"); + continue; + } } } else { throw new Exception("Unknown line: " + line); diff --git a/jdk/test/sun/security/pkcs11/tls/TestPremaster.java b/jdk/test/sun/security/pkcs11/tls/TestPremaster.java index a179bb81c2a..67191a7df28 100644 --- a/jdk/test/sun/security/pkcs11/tls/TestPremaster.java +++ b/jdk/test/sun/security/pkcs11/tls/TestPremaster.java @@ -23,7 +23,7 @@ /* * @test - * @bug 6316539 + * @bug 6316539 8136355 * @summary Basic tests for TlsRsaPremasterSecret generator * @author Andreas Sterbenz * @library .. @@ -34,6 +34,7 @@ */ import java.security.Provider; +import java.security.InvalidAlgorithmParameterException; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec; @@ -61,7 +62,7 @@ public class TestPremaster extends PKCS11Test { System.out.println("OK: " + e); } - int[] protocolVersions = {0x0300, 0x0301, 0x0302, 0x0400}; + int[] protocolVersions = {0x0300, 0x0301, 0x0302}; for (int clientVersion : protocolVersions) { for (int serverVersion : protocolVersions) { test(kg, clientVersion, serverVersion); @@ -81,8 +82,18 @@ public class TestPremaster extends PKCS11Test { "Testing RSA pre-master secret key generation between " + "client (0x%04X) and server(0x%04X)%n", clientVersion, serverVersion); - kg.init(new TlsRsaPremasterSecretParameterSpec( + try { + kg.init(new TlsRsaPremasterSecretParameterSpec( clientVersion, serverVersion)); + } catch (InvalidAlgorithmParameterException iape) { + // S12 removed support for SSL v3.0 + if (clientVersion == 0x300 || serverVersion == 0x300) { + System.out.println("Skip testing SSLv3 due to no support"); + return; + } + // unexpected, pass it up + throw iape; + } SecretKey key = kg.generateKey(); byte[] encoded = key.getEncoded(); if (encoded != null) { // raw key material may be not extractable diff --git a/jdk/test/sun/security/smartcardio/README.txt b/jdk/test/sun/security/smartcardio/README.txt index 5efbb5fa33b..6a0953a61e3 100644 --- a/jdk/test/sun/security/smartcardio/README.txt +++ b/jdk/test/sun/security/smartcardio/README.txt @@ -1,17 +1,17 @@ Rough hints for setting up MUSCLE on Solaris: -Make sure you have libusb, usually in /usr/sfw: +Make sure you have libusb, usually in /usr/lib: -ls -l /usr/sfw/lib/libusb.so -lrwxrwxrwx 1 root other 11 Jan 12 16:02 /usr/sfw/lib/libusb.so -> libusb.so.1 +ls -l /usr/lib/libusb.so +lrwxrwxrwx 1 root other 11 Jan 12 16:02 /usr/lib/libusb.so -> libusb.so.1 Get PCSC and CCID. -rwx------ 1 user staff 529540 Jun 16 18:24 ccid-1.0.1.tar.gz -rwx------ 1 user staff 842654 Jun 16 18:24 pcsc-lite-1.3.1.tar.gz Unpack pcsc -Run ./configure --enable-libusb=/usr/sfw (??) +Run ./configure --enable-libusb (??) gnumake Make /usr/local writeable for user gnumake install diff --git a/jdk/test/sun/security/smartcardio/TestChannel.java b/jdk/test/sun/security/smartcardio/TestChannel.java index c7e022f7c21..90052158ca7 100644 --- a/jdk/test/sun/security/smartcardio/TestChannel.java +++ b/jdk/test/sun/security/smartcardio/TestChannel.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6239117 * @summary test logical channels work * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestChannel */ diff --git a/jdk/test/sun/security/smartcardio/TestConnect.java b/jdk/test/sun/security/smartcardio/TestConnect.java index 467939e1059..fa0631c98ad 100644 --- a/jdk/test/sun/security/smartcardio/TestConnect.java +++ b/jdk/test/sun/security/smartcardio/TestConnect.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6293769 6294527 6309280 * @summary test connect() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestConnect */ diff --git a/jdk/test/sun/security/smartcardio/TestConnectAgain.java b/jdk/test/sun/security/smartcardio/TestConnectAgain.java index f4e6af21cba..7f2343b2edd 100644 --- a/jdk/test/sun/security/smartcardio/TestConnectAgain.java +++ b/jdk/test/sun/security/smartcardio/TestConnectAgain.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6239117 * @summary test connect works correctly if called multiple times/card removed * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestConnectAgain */ diff --git a/jdk/test/sun/security/smartcardio/TestControl.java b/jdk/test/sun/security/smartcardio/TestControl.java index 682f715d1c4..fd1c936582e 100644 --- a/jdk/test/sun/security/smartcardio/TestControl.java +++ b/jdk/test/sun/security/smartcardio/TestControl.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6239117 6470320 * @summary test if transmitControlCommand() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestControl */ diff --git a/jdk/test/sun/security/smartcardio/TestDefault.java b/jdk/test/sun/security/smartcardio/TestDefault.java index 9f3a6660426..190b988e91b 100644 --- a/jdk/test/sun/security/smartcardio/TestDefault.java +++ b/jdk/test/sun/security/smartcardio/TestDefault.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6327047 * @summary verify that TerminalFactory.getDefault() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestDefault */ diff --git a/jdk/test/sun/security/smartcardio/TestDirect.java b/jdk/test/sun/security/smartcardio/TestDirect.java index 5c09ea907ab..bddc3093934 100644 --- a/jdk/test/sun/security/smartcardio/TestDirect.java +++ b/jdk/test/sun/security/smartcardio/TestDirect.java @@ -21,10 +21,11 @@ * questions. */ -/** +/* * @test * @bug 8046343 * @summary Make sure that direct protocol is available + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestDirect */ diff --git a/jdk/test/sun/security/smartcardio/TestExclusive.java b/jdk/test/sun/security/smartcardio/TestExclusive.java index 9e4416ac6d9..cd451321f53 100644 --- a/jdk/test/sun/security/smartcardio/TestExclusive.java +++ b/jdk/test/sun/security/smartcardio/TestExclusive.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6239117 * @summary verify that beginExclusive()/endExclusive() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestExclusive */ diff --git a/jdk/test/sun/security/smartcardio/TestMultiplePresent.java b/jdk/test/sun/security/smartcardio/TestMultiplePresent.java index 15e320d2475..9fd2256bf09 100644 --- a/jdk/test/sun/security/smartcardio/TestMultiplePresent.java +++ b/jdk/test/sun/security/smartcardio/TestMultiplePresent.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6239117 6445367 * @summary test that CardTerminals.waitForCard() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestMultiplePresent */ diff --git a/jdk/test/sun/security/smartcardio/TestPresent.java b/jdk/test/sun/security/smartcardio/TestPresent.java index 1f499e97c12..fea98795d75 100644 --- a/jdk/test/sun/security/smartcardio/TestPresent.java +++ b/jdk/test/sun/security/smartcardio/TestPresent.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6293769 6294527 * @summary test that the isCardPresent()/waitForX() APIs work correctly * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestPresent */ diff --git a/jdk/test/sun/security/smartcardio/TestTransmit.java b/jdk/test/sun/security/smartcardio/TestTransmit.java index 85b32f6dd48..e233a4bb163 100644 --- a/jdk/test/sun/security/smartcardio/TestTransmit.java +++ b/jdk/test/sun/security/smartcardio/TestTransmit.java @@ -21,11 +21,12 @@ * questions. */ -/** +/* * @test * @bug 6293769 6294527 * @summary test transmit() works * @author Andreas Sterbenz + * @modules java.smartcardio/javax.smartcardio * @run main/manual TestTransmit */ diff --git a/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java b/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java index 65e41b56ac2..94f0323b6dc 100644 --- a/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java +++ b/jdk/test/sun/security/ssl/SocketCreation/SocketCreation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -139,7 +139,7 @@ public class SocketCreation { (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); System.out.println("Server: Will call createServerSocket(int)"); - ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort); + ServerSocket sslServerSocket = sslssf.createServerSocket(0); serverPort = sslServerSocket.getLocalPort(); System.out.println("Server: Will accept on SSL server socket..."); @@ -157,7 +157,7 @@ public class SocketCreation { (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); System.out.println("Server: Will call createServerSocket(int, int)"); - ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort, + ServerSocket sslServerSocket = sslssf.createServerSocket(0, 1); serverPort = sslServerSocket.getLocalPort(); @@ -177,7 +177,7 @@ public class SocketCreation { System.out.println("Server: Will call createServerSocket(int, " + " int, InetAddress)"); - ServerSocket sslServerSocket = sslssf.createServerSocket(serverPort, + ServerSocket sslServerSocket = sslssf.createServerSocket(0, 1, InetAddress.getByName("localhost")); serverPort = sslServerSocket.getLocalPort(); @@ -203,14 +203,15 @@ public class SocketCreation { if (sslServerSocket.isBound()) throw new Exception("Server socket is already bound!"); - System.out.println("Server: Will bind SSL server socket to port " + - serverPort + "..."); - - sslServerSocket.bind(new java.net.InetSocketAddress(serverPort)); + sslServerSocket.bind(new java.net.InetSocketAddress(0)); if (!sslServerSocket.isBound()) throw new Exception("Server socket is not bound!"); + serverPort = sslServerSocket.getLocalPort(); + System.out.println("Server: Bound SSL server socket to port " + + serverPort + "..."); + serverReady = true; System.out.println("Server: Will accept on SSL server socket..."); @@ -224,11 +225,10 @@ public class SocketCreation { SSLSocketFactory sslsf = (SSLSocketFactory) SSLSocketFactory.getDefault(); - System.out.println("Server: Will create normal server socket bound" - + " to port " + serverPort + "..."); - - ServerSocket ss = new ServerSocket(serverPort); + ServerSocket ss = new ServerSocket(0); serverPort = ss.getLocalPort(); + System.out.println("Server: Created normal server socket bound" + + " to port " + serverPort + "..."); System.out.println("Server: Will accept on server socket..."); serverReady = true; Socket s = ss.accept(); diff --git a/jdk/test/sun/security/tools/keytool/KeyToolTest.java b/jdk/test/sun/security/tools/keytool/KeyToolTest.java index a783c4e9dbd..7e19d510767 100644 --- a/jdk/test/sun/security/tools/keytool/KeyToolTest.java +++ b/jdk/test/sun/security/tools/keytool/KeyToolTest.java @@ -1761,7 +1761,7 @@ public class KeyToolTest { //PKCS#11 tests // 1. sccs edit cert8.db key3.db - //Runtime.getRuntime().exec("/usr/ccs/bin/sccs edit cert8.db key3.db"); + //Runtime.getRuntime().exec("/usr/bin/sccs edit cert8.db key3.db"); testOK("", p11Arg + ("-storepass test12 -genkey -alias genkey" + " -dname cn=genkey -keysize 512 -keyalg rsa")); testOK("", p11Arg + "-storepass test12 -list"); @@ -1781,7 +1781,7 @@ public class KeyToolTest { testOK("", p11Arg + "-storepass test12 -list"); assertTrue(out.indexOf("Your keystore contains 0 entries") != -1); //(check for empty database listing) - //Runtime.getRuntime().exec("/usr/ccs/bin/sccs unedit cert8.db key3.db"); + //Runtime.getRuntime().exec("/usr/bin/sccs unedit cert8.db key3.db"); remove("genkey.cert"); remove("genkey.certreq"); // 12. sccs unedit cert8.db key3.db diff --git a/jdk/test/tools/launcher/RunpathTest.java b/jdk/test/tools/launcher/RunpathTest.java index 26233b28561..00e757343c3 100644 --- a/jdk/test/tools/launcher/RunpathTest.java +++ b/jdk/test/tools/launcher/RunpathTest.java @@ -40,7 +40,7 @@ public class RunpathTest extends TestHelper { } final String findElfReader() { - String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"}; + String[] paths = {"/usr/sbin", "/usr/bin"}; final String cmd = isSolaris ? "elfdump" : "readelf"; for (String x : paths) { File p = new File(x); diff --git a/jdk/test/tools/launcher/TooSmallStackSize.java b/jdk/test/tools/launcher/TooSmallStackSize.java index 7cc02ab56df..6220dca2740 100644 --- a/jdk/test/tools/launcher/TooSmallStackSize.java +++ b/jdk/test/tools/launcher/TooSmallStackSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -35,6 +35,11 @@ * stack size for the platform (as provided by the JVM error message when a very * small stack is used), and then verify that the JVM can be launched with that stack * size without a crash or any error messages. + * + * Note: The '-Xss ' and '-XX:ThreadStackSize= ' options + * both control Java thread stack size. This repo's version of the test + * exercises the '-Xss' option. The hotspot repo's version of the test + * exercises the '-XX:ThreadStackSize' VM option. */ public class TooSmallStackSize extends TestHelper { @@ -59,7 +64,7 @@ public class TooSmallStackSize extends TestHelper { static String getMinStackAllowed(TestResult tr) { /* * The JVM output will contain in one of the lines: - * "The stack size specified is too small, Specify at least 100k" + * "The Java thread stack size specified is too small. Specify at least 100k" * Although the actual size will vary. We need to extract this size * string from the output and return it. */ @@ -73,6 +78,9 @@ public class TooSmallStackSize extends TestHelper { } } + System.out.println("Expect='" + matchStr + "'"); + System.out.println("Actual:"); + printTestOutput(tr); System.out.println("FAILED: Could not get the stack size from the output"); throw new RuntimeException("test fails"); } @@ -96,11 +104,15 @@ public class TooSmallStackSize extends TestHelper { System.out.println("PASSED: got no error message with stack size of " + stackSize); min_stack_allowed = stackSize; } else { - if (tr.contains("The stack size specified is too small")) { + String matchStr = "The Java thread stack size specified is too small"; + if (tr.contains(matchStr)) { System.out.println("PASSED: got expected error message with stack size of " + stackSize); min_stack_allowed = getMinStackAllowed(tr); } else { // Likely a crash + System.out.println("Expect='" + matchStr + "'"); + System.out.println("Actual:"); + printTestOutput(tr); System.out.println("FAILED: Did not get expected error message with stack size of " + stackSize); throw new RuntimeException("test fails"); } @@ -123,6 +135,8 @@ public class TooSmallStackSize extends TestHelper { System.out.println("PASSED: VM launched with minimum allowed stack size of " + stackSize); } else { // Likely a crash + System.out.println("Test output:"); + printTestOutput(tr); System.out.println("FAILED: VM failed to launch with minimum allowed stack size of " + stackSize); throw new RuntimeException("test fails"); } diff --git a/jdk/test/tools/launcher/modules/addmods/AddModsTest.java b/jdk/test/tools/launcher/modules/addmods/AddModsTest.java index 3ace33457bc..3a7a320bafa 100644 --- a/jdk/test/tools/launcher/modules/addmods/AddModsTest.java +++ b/jdk/test/tools/launcher/modules/addmods/AddModsTest.java @@ -31,6 +31,7 @@ * @summary Basic test for java --add-modules */ +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; @@ -223,6 +224,27 @@ public class AddModsTest { } + /** + * Tests {@code --add-modules} be specified more than once. + */ + public void testWithMultipleAddModules() throws Exception { + + String modulepath = MODS1_DIR.toString() + File.pathSeparator + + MODS2_DIR.toString(); + int exitValue + = executeTestJava("--module-path", modulepath, + "--add-modules", LOGGER_MODULE, + "--add-modules", TEST_MODULE, + "-m", TEST_MID, + "logger.Logger") + .outputTo(System.out) + .errorTo(System.out) + .getExitValue(); + + assertTrue(exitValue == 0); + } + + /** * Attempt to run with a bad module name specified to --add-modules */ diff --git a/jdk/test/tools/pack200/Pack200Test.java b/jdk/test/tools/pack200/Pack200Test.java index 5c50da1e503..0c18de51899 100644 --- a/jdk/test/tools/pack200/Pack200Test.java +++ b/jdk/test/tools/pack200/Pack200Test.java @@ -24,6 +24,7 @@ /* * @test * @bug 6521334 6712743 8007902 8151901 + * @requires (sun.arch.data.model == "64" & os.maxMemory >= 4g) * @summary test general packer/unpacker functionality * using native and java unpackers * @compile -XDignore.symbol.file Utils.java Pack200Test.java diff --git a/make/MainSupport.gmk b/make/MainSupport.gmk index 7683cfeb2af..57fd68deaa5 100644 --- a/make/MainSupport.gmk +++ b/make/MainSupport.gmk @@ -31,11 +31,13 @@ ifndef _MAINSUPPORT_GMK _MAINSUPPORT_GMK := 1 # Run the tests specified by $1, with PRODUCT_HOME specified by $2 +# JT_JAVA is picked up by the jtreg launcher and used to run Jtreg itself. define RunTests ($(CD) $(SRC_ROOT)/test && $(MAKE) $(MAKE_ARGS) -j1 -k MAKEFLAGS= \ JT_HOME=$(JT_HOME) PRODUCT_HOME=$(strip $2) \ TEST_IMAGE_DIR=$(TEST_IMAGE_DIR) \ ALT_OUTPUTDIR=$(OUTPUT_ROOT) TEST_JOBS=$(TEST_JOBS) \ + JT_JAVA=$(BOOT_JDK) \ JOBS=$(JOBS) $1) || true endef diff --git a/nashorn/.hgtags b/nashorn/.hgtags index 26b80a32770..41633a26b9a 100644 --- a/nashorn/.hgtags +++ b/nashorn/.hgtags @@ -370,3 +370,4 @@ ee77c6b3713ab293e027ac3ea1cc16f86dac535f jdk-9+131 e05400ba935753c77697af936db24657eb811022 jdk-9+134 cb00d5ef023a18a66fcb4311ed4474d4145c66e9 jdk-9+135 f11b8f5c4ccbf9c87d283815abac6c0117fba3c0 jdk-9+136 +17ed43add2f9e3528686cd786ae2ed49c8ed36e9 jdk-9+137 diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java index f784b74ca5f..c9fa06880f9 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -2512,7 +2512,8 @@ final class CodeGenerator extends NodeOperatorVisitor elements = objectNode.getElements(); final List > tuples = new ArrayList<>(); - final List gettersSetters = new ArrayList<>(); + // List below will contain getter/setter properties and properties with computed keys (ES6) + final List specialProperties = new ArrayList<>(); final int ccp = getCurrentContinuationEntryPoint(); final List ranges = objectNode.getSplitRanges(); @@ -2522,11 +2523,14 @@ final class CodeGenerator extends NodeOperatorVisitor valueType = (!useDualFields() || value == null || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass(); + final Class> valueType = (!useDualFields() || isComputedOrAccessor || value.getType().isBoolean()) ? Object.class : value.getType().getTypeClass(); tuples.add(new MapTuple (key, symbol, Type.typeFor(valueType), value) { @Override public Class> getValueType() { @@ -2590,26 +2594,41 @@ final class CodeGenerator extends NodeOperatorVisitor map = new HashMap<>(); rp.save(map); compileJdk = (String) map.get("regtest.compilejdk"); diff --git a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java index c08418073fe..10c0580dc50 100644 --- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java +++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherProcessInfoTimeoutHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,6 @@ package jdk.test.failurehandler.jtreg; -import com.sun.javatest.regtest.OS; import com.sun.javatest.regtest.TimeoutHandler; import jdk.test.failurehandler.*; diff --git a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/OS.java b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/OS.java new file mode 100644 index 00000000000..ccc1861f9e7 --- /dev/null +++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/OS.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.test.failurehandler.jtreg; + +// Stripped down version of jtreg internal class com.sun.javatest.regtest.config.OS +class OS { + public final String family; + + private static OS current; + + public static OS current() { + if (current == null) { + String name = System.getProperty("os.name"); + current = new OS(name); + } + return current; + } + + private OS(String name) { + if (name.startsWith("Linux")) { + family = "linux"; + } else if (name.startsWith("Mac") || name.startsWith("Darwin")) { + family = "mac"; + } else if (name.startsWith("SunOS") || name.startsWith("Solaris")) { + family = "solaris"; + } else if (name.startsWith("Windows")) { + family = "windows"; + } else { + // use first word of name + family = name.replaceFirst("^([^ ]+).*", "$1"); + } + } +} + + diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index ec4fa8b63ba..1c5e60021c2 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.java @@ -116,6 +116,14 @@ public class Platform { return (jdkDebug.toLowerCase().contains("debug")); } + public static boolean isSlowDebugBuild() { + return (jdkDebug.toLowerCase().equals("slowdebug")); + } + + public static boolean isFastDebugBuild() { + return (jdkDebug.toLowerCase().equals("fastdebug")); + } + public static String getVMVersion() { return vmVersion; }