changeset 17561:8dd36c04cfaf

Merge
author amurillo
date Fri, 19 Aug 2016 12:17:32 -0700
parents b61ee43309f3 45cef6862663
children 88b20e3124c9
files
diffstat 98 files changed, 2593 insertions(+), 1128 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Aug 19 10:09:53 2016 -0400
+++ b/.hgtags	Fri Aug 19 12:17:32 2016 -0700
@@ -374,3 +374,4 @@
 47699aa2e69ec2702542dc73eb01de3bfb61aea0 jdk-9+129
 6c827500e34587061af97ad6fef0e859280255c5 jdk-9+130
 8c57f4c293bbc5609928308a6d91ba765760b5f9 jdk-9+131
+d5c70818cd8a82e76632c8c815bdb4f75f53aeaf jdk-9+132
--- a/make/copy/Copy-java.base.gmk	Fri Aug 19 10:09:53 2016 -0400
+++ b/make/copy/Copy-java.base.gmk	Fri Aug 19 12:17:32 2016 -0700
@@ -183,7 +183,7 @@
 
 DEF_POLICY_SRC_LIST := $(DEF_POLICY_SRC)
 
-ifeq ($(OPENJDK_TARGET_OS), windows)
+ifneq ($(filter $(OPENJDK_TARGET_OS), windows solaris), )
   DEF_POLICY_SRC_LIST += $(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/lib/security/default.policy
 endif
 
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, 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
@@ -107,7 +107,7 @@
             throw new InvalidKeySpecException("Key length is negative");
         }
         try {
-            this.prf = Mac.getInstance(prfAlgo, SunJCE.getInstance());
+            this.prf = Mac.getInstance(prfAlgo);
         } catch (NoSuchAlgorithmException nsae) {
             // not gonna happen; re-throw just in case
             InvalidKeySpecException ike = new InvalidKeySpecException();
--- a/src/java.base/share/classes/java/io/BufferedReader.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/BufferedReader.java	Fri Aug 19 12:17:32 2016 -0700
@@ -560,7 +560,7 @@
      * @since 1.8
      */
     public Stream<String> lines() {
-        Iterator<String> iter = new Iterator<String>() {
+        Iterator<String> iter = new Iterator<>() {
             String nextLine = null;
 
             @Override
--- a/src/java.base/share/classes/java/io/ByteArrayOutputStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/ByteArrayOutputStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -187,7 +187,7 @@
      * @return  the current contents of this output stream, as a byte array.
      * @see     java.io.ByteArrayOutputStream#size()
      */
-    public synchronized byte toByteArray()[] {
+    public synchronized byte[] toByteArray() {
         return Arrays.copyOf(buf, count);
     }
 
--- a/src/java.base/share/classes/java/io/CharArrayWriter.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/CharArrayWriter.java	Fri Aug 19 12:17:32 2016 -0700
@@ -165,7 +165,7 @@
      *
      * @param  csq
      *         The character sequence to append.  If {@code csq} is
-     *         {@code null}, then the four characters "{@code null}" are
+     *         {@code null}, then the four characters {@code "null"} are
      *         appended to this writer.
      *
      * @return  This writer
@@ -173,7 +173,7 @@
      * @since  1.5
      */
     public CharArrayWriter append(CharSequence csq) {
-        String s = (csq == null ? "null" : csq.toString());
+        String s = String.valueOf(csq);
         write(s, 0, s.length());
         return this;
     }
@@ -193,7 +193,7 @@
      *         The character sequence from which a subsequence will be
      *         appended.  If {@code csq} is {@code null}, then characters
      *         will be appended as if {@code csq} contained the four
-     *         characters "{@code null}".
+     *         characters {@code "null"}.
      *
      * @param  start
      *         The index of the first character in the subsequence
@@ -212,9 +212,8 @@
      * @since  1.5
      */
     public CharArrayWriter append(CharSequence csq, int start, int end) {
-        String s = (csq == null ? "null" : csq).subSequence(start, end).toString();
-        write(s, 0, s.length());
-        return this;
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     /**
@@ -251,7 +250,7 @@
      *
      * @return an array of chars copied from the input data.
      */
-    public char toCharArray()[] {
+    public char[] toCharArray() {
         synchronized (lock) {
             return Arrays.copyOf(buf, count);
         }
--- a/src/java.base/share/classes/java/io/FileSystem.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/FileSystem.java	Fri Aug 19 12:17:32 2016 -0700
@@ -228,13 +228,8 @@
     static boolean useCanonPrefixCache = true;
 
     private static boolean getBooleanProperty(String prop, boolean defaultVal) {
-        String val = System.getProperty(prop);
-        if (val == null) return defaultVal;
-        if (val.equalsIgnoreCase("true")) {
-            return true;
-        } else {
-            return false;
-        }
+        return Boolean.parseBoolean(System.getProperty(prop,
+                String.valueOf(defaultVal)));
     }
 
     static {
--- a/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1265,22 +1265,21 @@
         WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
         Boolean result = Caches.subclassAudits.get(key);
         if (result == null) {
-            result = Boolean.valueOf(auditSubclass(cl));
+            result = auditSubclass(cl);
             Caches.subclassAudits.putIfAbsent(key, result);
         }
-        if (result.booleanValue()) {
-            return;
+        if (!result) {
+            sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
         }
-        sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
     }
 
     /**
      * Performs reflective checks on given subclass to verify that it doesn't
-     * override security-sensitive non-final methods.  Returns true if subclass
-     * is "safe", false otherwise.
+     * override security-sensitive non-final methods.  Returns TRUE if subclass
+     * is "safe", FALSE otherwise.
      */
-    private static boolean auditSubclass(final Class<?> subcl) {
-        Boolean result = AccessController.doPrivileged(
+    private static Boolean auditSubclass(Class<?> subcl) {
+        return AccessController.doPrivileged(
             new PrivilegedAction<>() {
                 public Boolean run() {
                     for (Class<?> cl = subcl;
@@ -1303,7 +1302,6 @@
                 }
             }
         );
-        return result.booleanValue();
     }
 
     /**
--- a/src/java.base/share/classes/java/io/ObjectOutputStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/ObjectOutputStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1050,22 +1050,21 @@
         WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
         Boolean result = Caches.subclassAudits.get(key);
         if (result == null) {
-            result = Boolean.valueOf(auditSubclass(cl));
+            result = auditSubclass(cl);
             Caches.subclassAudits.putIfAbsent(key, result);
         }
-        if (result.booleanValue()) {
-            return;
+        if (!result) {
+            sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
         }
-        sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
     }
 
     /**
      * Performs reflective checks on given subclass to verify that it doesn't
-     * override security-sensitive non-final methods.  Returns true if subclass
-     * is "safe", false otherwise.
+     * override security-sensitive non-final methods.  Returns TRUE if subclass
+     * is "safe", FALSE otherwise.
      */
-    private static boolean auditSubclass(final Class<?> subcl) {
-        Boolean result = AccessController.doPrivileged(
+    private static Boolean auditSubclass(Class<?> subcl) {
+        return AccessController.doPrivileged(
             new PrivilegedAction<>() {
                 public Boolean run() {
                     for (Class<?> cl = subcl;
@@ -1088,7 +1087,6 @@
                 }
             }
         );
-        return result.booleanValue();
     }
 
     /**
--- a/src/java.base/share/classes/java/io/ObjectStreamClass.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/ObjectStreamClass.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1509,11 +1509,9 @@
     private static String getPackageName(Class<?> cl) {
         String s = cl.getName();
         int i = s.lastIndexOf('[');
-        if (i >= 0) {
-            s = s.substring(i + 2);
-        }
-        i = s.lastIndexOf('.');
-        return (i >= 0) ? s.substring(0, i) : "";
+        i = (i < 0) ? 0 : i + 2;
+        int j = s.lastIndexOf('.');
+        return (i < j) ? s.substring(i, j) : "";
     }
 
     /**
@@ -1535,14 +1533,14 @@
     private static String getMethodSignature(Class<?>[] paramTypes,
                                              Class<?> retType)
     {
-        StringBuilder sbuf = new StringBuilder();
-        sbuf.append('(');
+        StringBuilder sb = new StringBuilder();
+        sb.append('(');
         for (int i = 0; i < paramTypes.length; i++) {
-            appendClassSignature(sbuf, paramTypes[i]);
+            appendClassSignature(sb, paramTypes[i]);
         }
-        sbuf.append(')');
-        appendClassSignature(sbuf, retType);
-        return sbuf.toString();
+        sb.append(')');
+        appendClassSignature(sb, retType);
+        return sb.toString();
     }
 
     /**
--- a/src/java.base/share/classes/java/io/OutputStreamWriter.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/OutputStreamWriter.java	Fri Aug 19 12:17:32 2016 -0700
@@ -233,22 +233,16 @@
 
     @Override
     public Writer append(CharSequence csq, int start, int end) throws IOException {
-        if (csq == null) {
-            write("null".subSequence(start, end).toString());
-            return this;
-        } else {
-            return append(csq.subSequence(start, end));
-        }
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     @Override
     public Writer append(CharSequence csq) throws IOException {
-        if (csq == null) {
-            se.write("null");
-        } else if (csq instanceof CharBuffer) {
+        if (csq instanceof CharBuffer) {
             se.write((CharBuffer) csq);
         } else {
-            se.write(csq.toString());
+            se.write(String.valueOf(csq));
         }
         return this;
     }
--- a/src/java.base/share/classes/java/io/PrintStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/PrintStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -568,7 +568,7 @@
      * @param      b   The {@code boolean} to be printed
      */
     public void print(boolean b) {
-        write(b ? "true" : "false");
+        write(String.valueOf(b));
     }
 
     /**
@@ -663,10 +663,7 @@
      * @param      s   The {@code String} to be printed
      */
     public void print(String s) {
-        if (s == null) {
-            s = "null";
-        }
-        write(s);
+        write(String.valueOf(s));
     }
 
     /**
@@ -1068,10 +1065,7 @@
      * @since  1.5
      */
     public PrintStream append(CharSequence csq) {
-        if (csq == null)
-            print("null");
-        else
-            print(csq.toString());
+        print(String.valueOf(csq));
         return this;
     }
 
@@ -1111,9 +1105,8 @@
      * @since  1.5
      */
     public PrintStream append(CharSequence csq, int start, int end) {
-        CharSequence cs = (csq == null ? "null" : csq);
-        write(cs.subSequence(start, end).toString());
-        return this;
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     /**
--- a/src/java.base/share/classes/java/io/PrintWriter.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/PrintWriter.java	Fri Aug 19 12:17:32 2016 -0700
@@ -504,7 +504,7 @@
      * @param      b   The {@code boolean} to be printed
      */
     public void print(boolean b) {
-        write(b ? "true" : "false");
+        write(String.valueOf(b));
     }
 
     /**
@@ -599,10 +599,7 @@
      * @param      s   The {@code String} to be printed
      */
     public void print(String s) {
-        if (s == null) {
-            s = "null";
-        }
-        write(s);
+        write(String.valueOf(s));
     }
 
     /**
@@ -1005,10 +1002,7 @@
      * @since  1.5
      */
     public PrintWriter append(CharSequence csq) {
-        if (csq == null)
-            write("null");
-        else
-            write(csq.toString());
+        write(String.valueOf(csq));
         return this;
     }
 
@@ -1047,9 +1041,8 @@
      * @since  1.5
      */
     public PrintWriter append(CharSequence csq, int start, int end) {
-        CharSequence cs = (csq == null ? "null" : csq);
-        write(cs.subSequence(start, end).toString());
-        return this;
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     /**
--- a/src/java.base/share/classes/java/io/SequenceInputStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/SequenceInputStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -65,12 +65,7 @@
      */
     public SequenceInputStream(Enumeration<? extends InputStream> e) {
         this.e = e;
-        try {
-            nextStream();
-        } catch (IOException ex) {
-            // This should never happen
-            throw new Error("panic");
-        }
+        peekNextStream();
     }
 
     /**
@@ -86,16 +81,10 @@
      */
     public SequenceInputStream(InputStream s1, InputStream s2) {
         Vector<InputStream> v = new Vector<>(2);
-
         v.addElement(s1);
         v.addElement(s2);
         e = v.elements();
-        try {
-            nextStream();
-        } catch (IOException ex) {
-            // This should never happen
-            throw new Error("panic");
-        }
+        peekNextStream();
     }
 
     /**
@@ -105,14 +94,17 @@
         if (in != null) {
             in.close();
         }
+        peekNextStream();
+    }
 
+    private void peekNextStream() {
         if (e.hasMoreElements()) {
             in = (InputStream) e.nextElement();
             if (in == null)
                 throw new NullPointerException();
+        } else {
+            in = null;
         }
-        else in = null;
-
     }
 
     /**
--- a/src/java.base/share/classes/java/io/StringBufferInputStream.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/StringBufferInputStream.java	Fri Aug 19 12:17:32 2016 -0700
@@ -108,6 +108,7 @@
      *             <code>-1</code> if there is no more data because the end of
      *             the stream has been reached.
      */
+    @SuppressWarnings("deprecation")
     public synchronized int read(byte b[], int off, int len) {
         if (b == null) {
             throw new NullPointerException();
@@ -126,12 +127,8 @@
         if (len <= 0) {
             return 0;
         }
-        String  s = buffer;
-        int cnt = len;
-        while (--cnt >= 0) {
-            b[off++] = (byte)s.charAt(pos++);
-        }
-
+        buffer.getBytes(pos, pos + len, b, off);
+        pos += len;
         return len;
     }
 
--- a/src/java.base/share/classes/java/io/StringReader.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/StringReader.java	Fri Aug 19 12:17:32 2016 -0700
@@ -142,8 +142,8 @@
      */
     public boolean ready() throws IOException {
         synchronized (lock) {
-        ensureOpen();
-        return true;
+            ensureOpen();
+            return true;
         }
     }
 
--- a/src/java.base/share/classes/java/io/StringWriter.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/StringWriter.java	Fri Aug 19 12:17:32 2016 -0700
@@ -139,7 +139,7 @@
      *
      * @param  csq
      *         The character sequence to append.  If {@code csq} is
-     *         {@code null}, then the four characters "{@code null}" are
+     *         {@code null}, then the four characters {@code "null"} are
      *         appended to this writer.
      *
      * @return  This writer
@@ -147,10 +147,7 @@
      * @since  1.5
      */
     public StringWriter append(CharSequence csq) {
-        if (csq == null)
-            write("null");
-        else
-            write(csq.toString());
+        write(String.valueOf(csq));
         return this;
     }
 
@@ -170,7 +167,7 @@
      *         The character sequence from which a subsequence will be
      *         appended.  If {@code csq} is {@code null}, then characters
      *         will be appended as if {@code csq} contained the four
-     *         characters "{@code null}".
+     *         characters {@code "null"}.
      *
      * @param  start
      *         The index of the first character in the subsequence
@@ -189,9 +186,8 @@
      * @since  1.5
      */
     public StringWriter append(CharSequence csq, int start, int end) {
-        CharSequence cs = (csq == null ? "null" : csq);
-        write(cs.subSequence(start, end).toString());
-        return this;
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     /**
--- a/src/java.base/share/classes/java/io/Writer.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/io/Writer.java	Fri Aug 19 12:17:32 2016 -0700
@@ -221,7 +221,7 @@
      *
      * @param  csq
      *         The character sequence to append.  If {@code csq} is
-     *         {@code null}, then the four characters "{@code null}" are
+     *         {@code null}, then the four characters {@code "null"} are
      *         appended to this writer.
      *
      * @return  This writer
@@ -232,10 +232,7 @@
      * @since  1.5
      */
     public Writer append(CharSequence csq) throws IOException {
-        if (csq == null)
-            write("null");
-        else
-            write(csq.toString());
+        write(String.valueOf(csq));
         return this;
     }
 
@@ -256,7 +253,7 @@
      *         The character sequence from which a subsequence will be
      *         appended.  If {@code csq} is {@code null}, then characters
      *         will be appended as if {@code csq} contained the four
-     *         characters "{@code null}".
+     *         characters {@code "null"}.
      *
      * @param  start
      *         The index of the first character in the subsequence
@@ -278,9 +275,8 @@
      * @since  1.5
      */
     public Writer append(CharSequence csq, int start, int end) throws IOException {
-        CharSequence cs = (csq == null ? "null" : csq);
-        write(cs.subSequence(start, end).toString());
-        return this;
+        if (csq == null) csq = "null";
+        return append(csq.subSequence(start, end));
     }
 
     /**
--- a/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Aug 19 12:17:32 2016 -0700
@@ -36,7 +36,6 @@
 import java.lang.invoke.LambdaForm.NamedFunction;
 import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.reflect.Field;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.function.Function;
@@ -308,7 +307,7 @@
         /*non-public*/ char fieldTypeChar(int i) {
             return typeChars.charAt(i);
         }
-        Object fieldSignature() {
+        String fieldSignature() {
             return typeChars;
         }
         public Class<? extends BoundMethodHandle> fieldHolder() {
--- a/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/DelegatingMethodHandle.java	Fri Aug 19 12:17:32 2016 -0700
@@ -27,6 +27,7 @@
 
 import java.util.Arrays;
 import static java.lang.invoke.LambdaForm.*;
+import static java.lang.invoke.LambdaForm.Kind.*;
 import static java.lang.invoke.MethodHandleStatics.*;
 
 /**
@@ -96,14 +97,8 @@
                                         int whichCache,
                                         Object constraint,
                                         NamedFunction getTargetFn) {
-        String debugString;
-        switch(whichCache) {
-            case MethodTypeForm.LF_REBIND:            debugString = "BMH.reinvoke";      break;
-            case MethodTypeForm.LF_DELEGATE:          debugString = "MH.delegate";       break;
-            default:                                  debugString = "MH.reinvoke";       break;
-        }
         // No pre-action needed.
-        return makeReinvokerForm(target, whichCache, constraint, debugString, true, getTargetFn, null);
+        return makeReinvokerForm(target, whichCache, constraint, null, true, getTargetFn, null);
     }
     /** Create a LF which simply reinvokes a target of the given basic type. */
     static LambdaForm makeReinvokerForm(MethodHandle target,
@@ -114,6 +109,10 @@
                                         NamedFunction getTargetFn,
                                         NamedFunction preActionFn) {
         MethodType mtype = target.type().basicType();
+        Kind kind = whichKind(whichCache);
+        if (debugString == null) {
+            debugString = kind.defaultLambdaName;
+        }
         boolean customized = (whichCache < 0 ||
                 mtype.parameterSlotCount() > MethodType.MAX_MH_INVOKER_ARITY);
         boolean hasPreAction = (preActionFn != null);
@@ -145,13 +144,21 @@
             targetArgs[0] = names[NEXT_MH];  // overwrite this MH with next MH
             names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
         }
-        form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline);
+        form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline, kind);
         if (!customized) {
             form = mtype.form().setCachedLambdaForm(whichCache, form);
         }
         return form;
     }
 
+    private static Kind whichKind(int whichCache) {
+        switch(whichCache) {
+            case MethodTypeForm.LF_REBIND:   return BOUND_REINVOKER;
+            case MethodTypeForm.LF_DELEGATE: return DELEGATE;
+            default:                         return REINVOKER;
+        }
+    }
+
     static final NamedFunction NF_getTarget;
     static {
         try {
@@ -160,5 +167,13 @@
         } catch (ReflectiveOperationException ex) {
             throw newInternalError(ex);
         }
+        // The Holder class will contain pre-generated DelegatingMethodHandles resolved
+        // speculatively using MemberName.getFactory().resolveOrNull. However, that
+        // doesn't initialize the class, which subtly breaks inlining etc. By forcing
+        // initialization of the Holder class we avoid these issues.
+        UNSAFE.ensureClassInitialized(Holder.class);
     }
+
+    /* Placeholder class for DelegatingMethodHandles generated ahead of time */
+    final class Holder {}
 }
--- a/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java	Fri Aug 19 12:17:32 2016 -0700
@@ -38,6 +38,7 @@
 import java.util.Objects;
 
 import static java.lang.invoke.LambdaForm.*;
+import static java.lang.invoke.LambdaForm.Kind.*;
 import static java.lang.invoke.MethodHandleNatives.Constants.*;
 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
 import static java.lang.invoke.MethodHandleStatics.newInternalError;
@@ -189,14 +190,15 @@
     static LambdaForm makePreparedLambdaForm(MethodType mtype, int which) {
         boolean needsInit = (which == LF_INVSTATIC_INIT);
         boolean doesAlloc = (which == LF_NEWINVSPECIAL);
-        String linkerName, lambdaName;
+        String linkerName;
+        LambdaForm.Kind kind;
         switch (which) {
-        case LF_INVVIRTUAL:    linkerName = "linkToVirtual";    lambdaName = "DMH.invokeVirtual";    break;
-        case LF_INVSTATIC:     linkerName = "linkToStatic";     lambdaName = "DMH.invokeStatic";     break;
-        case LF_INVSTATIC_INIT:linkerName = "linkToStatic";     lambdaName = "DMH.invokeStaticInit"; break;
-        case LF_INVSPECIAL:    linkerName = "linkToSpecial";    lambdaName = "DMH.invokeSpecial";    break;
-        case LF_INVINTERFACE:  linkerName = "linkToInterface";  lambdaName = "DMH.invokeInterface";  break;
-        case LF_NEWINVSPECIAL: linkerName = "linkToSpecial";    lambdaName = "DMH.newInvokeSpecial"; break;
+        case LF_INVVIRTUAL:    linkerName = "linkToVirtual";   kind = DIRECT_INVOKE_VIRTUAL;     break;
+        case LF_INVSTATIC:     linkerName = "linkToStatic";    kind = DIRECT_INVOKE_STATIC;      break;
+        case LF_INVSTATIC_INIT:linkerName = "linkToStatic";    kind = DIRECT_INVOKE_STATIC_INIT; break;
+        case LF_INVSPECIAL:    linkerName = "linkToSpecial";   kind = DIRECT_INVOKE_SPECIAL;     break;
+        case LF_INVINTERFACE:  linkerName = "linkToInterface"; kind = DIRECT_INVOKE_INTERFACE;   break;
+        case LF_NEWINVSPECIAL: linkerName = "linkToSpecial";   kind = DIRECT_NEW_INVOKE_SPECIAL; break;
         default:  throw new InternalError("which="+which);
         }
 
@@ -240,11 +242,11 @@
             result = NEW_OBJ;
         }
         names[LINKER_CALL] = new Name(linker, outArgs);
-        lambdaName += "_" + shortenSignature(basicTypeSignature(mtype));
-        LambdaForm lform = new LambdaForm(lambdaName, ARG_LIMIT, names, result);
+        String lambdaName = kind.defaultLambdaName + "_" + shortenSignature(basicTypeSignature(mtype));
+        LambdaForm lform = new LambdaForm(lambdaName, ARG_LIMIT, names, result, kind);
 
         // This is a tricky bit of code.  Don't send it through the LF interpreter.
-        lform.compileToBytecode(Holder.class);
+        lform.compileToBytecode();
         return lform;
     }
 
@@ -705,7 +707,7 @@
     }
 
     static {
-        // The DMH class will contain pre-generated DirectMethodHandles resolved
+        // The Holder class will contain pre-generated DirectMethodHandles resolved
         // speculatively using MemberName.getFactory().resolveOrNull. However, that
         // doesn't initialize the class, which subtly breaks inlining etc. By forcing
         // initialization of the Holder class we avoid these issues.
@@ -713,5 +715,5 @@
     }
 
     /* Placeholder class for DirectMethodHandles generated ahead of time */
-    private final class Holder {}
+    final class Holder {}
 }
--- a/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Aug 19 12:17:32 2016 -0700
@@ -29,21 +29,56 @@
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Opcodes;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+
 /**
  * Helper class to assist the GenerateJLIClassesPlugin to get access to
  * generate classes ahead of time.
  */
 class GenerateJLIClassesHelper {
 
-    static byte[] generateDMHClassBytes(String className,
+    static byte[] generateDirectMethodHandleHolderClassBytes(String className,
             MethodType[] methodTypes, int[] types) {
         LambdaForm[] forms = new LambdaForm[methodTypes.length];
+        String[] names = new String[methodTypes.length];
         for (int i = 0; i < forms.length; i++) {
             forms[i] = DirectMethodHandle.makePreparedLambdaForm(methodTypes[i],
                                                                  types[i]);
-            methodTypes[i] = forms[i].methodType();
+            names[i] = forms[i].kind.defaultLambdaName;
         }
-        return generateCodeBytesForLFs(className, forms, methodTypes);
+        return generateCodeBytesForLFs(className, names, forms);
+    }
+
+    static byte[] generateDelegatingMethodHandleHolderClassBytes(String className,
+            MethodType[] methodTypes) {
+
+        HashSet<MethodType> dedupSet = new HashSet<>();
+        ArrayList<LambdaForm> forms = new ArrayList<>();
+        ArrayList<String> names = new ArrayList<>();
+        for (int i = 0; i < methodTypes.length; i++) {
+            // generate methods representing the DelegatingMethodHandle
+            if (dedupSet.add(methodTypes[i])) {
+                // reinvokers are variant with the associated SpeciesData
+                // and shape of the target LF, but we can easily pregenerate
+                // the basic reinvokers associated with Species_L. Ultimately we
+                // may want to consider pregenerating more of these, which will
+                // require an even more complex naming scheme
+                LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
+                forms.add(reinvoker);
+                String speciesSig = BoundMethodHandle
+                        .speciesData(reinvoker).fieldSignature();
+                assert(speciesSig.equals("L"));
+                names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
+
+                LambdaForm delegate = makeDelegateFor(methodTypes[i]);
+                forms.add(delegate);
+                names.add(delegate.kind.defaultLambdaName);
+            }
+        }
+        return generateCodeBytesForLFs(className,
+                names.toArray(new String[0]),
+                forms.toArray(new LambdaForm[0]));
     }
 
     /*
@@ -51,22 +86,45 @@
      * a class with a specified name.
      */
     private static byte[] generateCodeBytesForLFs(String className,
-            LambdaForm[] forms, MethodType[] types) {
-        assert(forms.length == types.length);
+            String[] names, LambdaForm[] forms) {
 
         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
         cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
                 className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
         cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);
+
         for (int i = 0; i < forms.length; i++) {
-            InvokerBytecodeGenerator g
-                    = new InvokerBytecodeGenerator(className, forms[i], types[i]);
-            g.setClassWriter(cw);
-            g.addMethod();
+            addMethod(className, names[i], forms[i],
+                    forms[i].methodType(), cw);
         }
         return cw.toByteArray();
     }
 
+    private static void addMethod(String className, String methodName, LambdaForm form,
+            MethodType type, ClassWriter cw) {
+        InvokerBytecodeGenerator g
+                = new InvokerBytecodeGenerator(className, methodName, form, type);
+        g.setClassWriter(cw);
+        g.addMethod();
+    }
+
+    private static LambdaForm makeReinvokerFor(MethodType type) {
+        MethodHandle emptyHandle = MethodHandles.empty(type);
+        return DelegatingMethodHandle.makeReinvokerForm(emptyHandle,
+                MethodTypeForm.LF_REBIND,
+                BoundMethodHandle.speciesData_L(),
+                BoundMethodHandle.speciesData_L().getterFunction(0));
+    }
+
+    private static LambdaForm makeDelegateFor(MethodType type) {
+        MethodHandle handle = MethodHandles.empty(type);
+        return DelegatingMethodHandle.makeReinvokerForm(
+                handle,
+                MethodTypeForm.LF_DELEGATE,
+                DelegatingMethodHandle.class,
+                DelegatingMethodHandle.NF_getTarget);
+    }
+
     static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
             final String types) {
         for (char c : types.toCharArray()) {
--- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Aug 19 12:17:32 2016 -0700
@@ -46,6 +46,7 @@
 
 import static java.lang.invoke.LambdaForm.*;
 import static java.lang.invoke.LambdaForm.BasicType.*;
+import static java.lang.invoke.LambdaForm.Kind.*;
 import static java.lang.invoke.MethodHandleNatives.Constants.*;
 import static java.lang.invoke.MethodHandleStatics.*;
 
@@ -125,9 +126,15 @@
     }
 
     /** For generating customized code for a single LambdaForm. */
-    InvokerBytecodeGenerator(String className, LambdaForm form, MethodType invokerType) {
+    private InvokerBytecodeGenerator(String className, LambdaForm form, MethodType invokerType) {
+        this(className, form.debugName, form, invokerType);
+    }
+
+    /** For generating customized code for a single LambdaForm. */
+    InvokerBytecodeGenerator(String className, String invokerName,
+            LambdaForm form, MethodType invokerType) {
         this(form, form.names.length,
-             className, form.debugName, invokerType);
+             className, invokerName, invokerType);
         // Create an array to map name indexes to locals indexes.
         Name[] names = form.names;
         for (int i = 0, index = 0; i < localsMap.length; i++) {
@@ -597,10 +604,42 @@
         return c.getName().replace('.', '/');
     }
 
+    private static MemberName resolveFrom(String name, MethodType type, Class<?> holder) {
+        MemberName member = new MemberName(holder, name, type, REF_invokeStatic);
+        MemberName resolvedMember = MemberName.getFactory().resolveOrNull(REF_invokeStatic, member, holder);
+
+        return resolvedMember;
+    }
+
+    private static MemberName lookupPregenerated(LambdaForm form) {
+        if (form.customized != null) {
+            // No pre-generated version for customized LF
+            return null;
+        }
+        MethodType invokerType = form.methodType();
+        String name = form.kind.methodName;
+        switch (form.kind) {
+            case BOUND_REINVOKER: {
+                name = name + "_" + BoundMethodHandle.speciesData(form).fieldSignature();
+                return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
+            }
+            case DELEGATE:                  return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
+            case DIRECT_INVOKE_INTERFACE:   // fall-through
+            case DIRECT_INVOKE_SPECIAL:     // fall-through
+            case DIRECT_INVOKE_STATIC:      // fall-through
+            case DIRECT_INVOKE_STATIC_INIT: // fall-through
+            case DIRECT_INVOKE_VIRTUAL:     return resolveFrom(name, invokerType, DirectMethodHandle.Holder.class);
+        }
+        return null;
+    }
+
     /**
      * Generate customized bytecode for a given LambdaForm.
      */
     static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
+        MemberName pregenerated = lookupPregenerated(form);
+        if (pregenerated != null)  return pregenerated; // pre-generated bytecode
+
         InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("MH", form, invokerType);
         return g.loadMethod(g.generateCustomizedCodeBytes());
     }
--- a/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/LambdaForm.java	Fri Aug 19 12:17:32 2016 -0700
@@ -41,6 +41,7 @@
 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.
@@ -127,6 +128,7 @@
     final MethodHandle customized;
     @Stable final Name[] names;
     final String debugName;
+    final Kind kind;
     MemberName vmentry;   // low-level behavior, or null if not yet prepared
     private boolean isCompiled;
 
@@ -266,12 +268,46 @@
         }
     }
 
+    enum Kind {
+        GENERIC(""),
+        BOUND_REINVOKER("BMH.reinvoke"),
+        REINVOKER("MH.reinvoke"),
+        DELEGATE("MH.delegate"),
+        DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual"),
+        DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial"),
+        DIRECT_INVOKE_STATIC("DMH.invokeStatic"),
+        DIRECT_NEW_INVOKE_SPECIAL("DMH.newInvokeSpecial"),
+        DIRECT_INVOKE_INTERFACE("DMH.invokeInterface"),
+        DIRECT_INVOKE_STATIC_INIT("DMH.invokeStaticInit");
+
+        final String defaultLambdaName;
+        final String methodName;
+
+        private Kind(String defaultLambdaName) {
+            this.defaultLambdaName = defaultLambdaName;
+            int p = defaultLambdaName.indexOf('.');
+            if (p > -1) {
+                this.methodName = defaultLambdaName.substring(p + 1);
+            } else {
+                this.methodName = defaultLambdaName;
+            }
+        }
+    }
+
     LambdaForm(String debugName,
                int arity, Name[] names, int result) {
-        this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null);
+        this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
+    }
+    LambdaForm(String debugName,
+               int arity, Name[] names, int result, Kind kind) {
+        this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
     }
     LambdaForm(String debugName,
                int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
+        this(debugName, arity, names, result, forceInline, customized, Kind.GENERIC);
+    }
+    LambdaForm(String debugName,
+               int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
         assert(namesOK(arity, names));
         this.arity = arity;
         this.result = fixResult(result, names);
@@ -279,6 +315,7 @@
         this.debugName = fixDebugName(debugName);
         this.forceInline = forceInline;
         this.customized = customized;
+        this.kind = kind;
         int maxOutArity = normalize();
         if (maxOutArity > MethodType.MAX_MH_INVOKER_ARITY) {
             // Cannot use LF interpreter on very high arity expressions.
@@ -288,11 +325,15 @@
     }
     LambdaForm(String debugName,
                int arity, Name[] names) {
-        this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
+        this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
     }
     LambdaForm(String debugName,
                int arity, Name[] names, boolean forceInline) {
-        this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null);
+        this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
+    }
+    LambdaForm(String debugName,
+               int arity, Name[] names, boolean forceInline, Kind kind) {
+        this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
     }
     LambdaForm(String debugName,
                Name[] formals, Name[] temps, Name result) {
@@ -325,6 +366,7 @@
         this.debugName = "LF.zero";
         this.forceInline = true;
         this.customized = null;
+        this.kind = Kind.GENERIC;
         assert(nameRefsAreLegal());
         assert(isEmpty());
         String sig = null;
@@ -395,7 +437,7 @@
 
     /** Customize LambdaForm for a particular MethodHandle */
     LambdaForm customize(MethodHandle mh) {
-        LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh);
+        LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh, kind);
         if (COMPILE_THRESHOLD >= 0 && isCompiled) {
             // If shared LambdaForm has been compiled, compile customized version as well.
             customForm.compileToBytecode();
@@ -773,28 +815,6 @@
         }
     }
 
-    /**
-     * Generate optimizable bytecode for this form after first looking for a
-     * pregenerated version in a specified class.
-     */
-    void compileToBytecode(Class<?> lookupClass) {
-        if (vmentry != null && isCompiled) {
-            return;  // already compiled somehow
-        }
-        MethodType invokerType = methodType();
-        assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType));
-        int dot = debugName.indexOf('.');
-        String methodName = (dot > 0) ? debugName.substring(dot + 1) : debugName;
-        MemberName member = new MemberName(lookupClass, methodName, invokerType, REF_invokeStatic);
-        MemberName resolvedMember = MemberName.getFactory().resolveOrNull(REF_invokeStatic, member, lookupClass);
-        if (resolvedMember != null) {
-            vmentry = resolvedMember;
-            isCompiled = true;
-        } else {
-            compileToBytecode();
-        }
-    }
-
     private static void computeInitialPreparedForms() {
         // Find all predefined invokers and associate them with canonical empty lambda forms.
         for (MemberName m : MemberName.getFactory().getMethods(LambdaForm.class, false, null, null, null)) {
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1718,10 +1718,19 @@
             }
 
             @Override
-            public byte[] generateDMHClassBytes(String className,
-            MethodType[] methodTypes, int[] types) {
+            public byte[] generateDirectMethodHandleHolderClassBytes(
+                    String className, MethodType[] methodTypes, int[] types) {
                 return GenerateJLIClassesHelper
-                        .generateDMHClassBytes(className, methodTypes, types);
+                        .generateDirectMethodHandleHolderClassBytes(
+                                className, methodTypes, types);
+            }
+
+            @Override
+            public byte[] generateDelegatingMethodHandleHolderClassBytes(
+                    String className, MethodType[] methodTypes) {
+                return GenerateJLIClassesHelper
+                        .generateDelegatingMethodHandleHolderClassBytes(
+                                className, methodTypes);
             }
 
             @Override
--- a/src/java.base/share/classes/java/security/Provider.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/security/Provider.java	Fri Aug 19 12:17:32 2016 -0700
@@ -601,7 +601,7 @@
     public synchronized Object compute(Object key, BiFunction<? super Object,
             ? super Object, ? extends Object> remappingFunction) {
         check("putProviderProperty." + name);
-        check("removeProviderProperty" + name);
+        check("removeProviderProperty." + name);
 
         if (debug != null) {
             debug.println("Compute " + name + " provider property " + key);
@@ -632,7 +632,7 @@
     public synchronized Object computeIfAbsent(Object key, Function<? super Object,
             ? extends Object> mappingFunction) {
         check("putProviderProperty." + name);
-        check("removeProviderProperty" + name);
+        check("removeProviderProperty." + name);
 
         if (debug != null) {
             debug.println("ComputeIfAbsent " + name + " provider property " +
@@ -662,7 +662,7 @@
     public synchronized Object computeIfPresent(Object key, BiFunction<? super Object,
             ? super Object, ? extends Object> remappingFunction) {
         check("putProviderProperty." + name);
-        check("removeProviderProperty" + name);
+        check("removeProviderProperty." + name);
 
         if (debug != null) {
             debug.println("ComputeIfPresent " + name + " provider property " +
@@ -695,7 +695,7 @@
     public synchronized Object merge(Object key, Object value,  BiFunction<? super Object,
             ? super Object, ? extends Object>  remappingFunction) {
         check("putProviderProperty." + name);
-        check("removeProviderProperty" + name);
+        check("removeProviderProperty." + name);
 
         if (debug != null) {
             debug.println("Merge " + name + " provider property " + key);
@@ -904,8 +904,8 @@
             if (!checkLegacy(key)) {
                 return null;
             }
-            legacyStrings.computeIfAbsent((String) key,
-                    (Function<? super String, ? extends String>) remappingFunction);
+            legacyStrings.compute((String) key,
+                    (BiFunction<? super String,? super String, ? extends String>) remappingFunction);
         }
         return super.compute(key, remappingFunction);
     }
--- a/src/java.base/share/classes/java/text/DateFormatSymbols.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/text/DateFormatSymbols.java	Fri Aug 19 12:17:32 2016 -0700
@@ -399,7 +399,10 @@
      * Calendar Elements in the Unicode Locale Data Markup Language
      * (LDML) specification</a> for more details.
      *
-     * @return the month strings.
+     * @return the month strings. Use
+     * {@link java.util.Calendar#JANUARY Calendar.JANUARY},
+     * {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY},
+     * etc. to index the result array.
      */
     public String[] getMonths() {
         return Arrays.copyOf(months, months.length);
@@ -407,7 +410,9 @@
 
     /**
      * Sets month strings. For example: "January", "February", etc.
-     * @param newMonths the new month strings.
+     * @param newMonths the new month strings. The array should
+     * be indexed by {@link java.util.Calendar#JANUARY Calendar.JANUARY},
+     * {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
      */
     public void setMonths(String[] newMonths) {
         months = Arrays.copyOf(newMonths, newMonths.length);
@@ -427,7 +432,10 @@
      * Calendar Elements in the Unicode Locale Data Markup Language
      * (LDML) specification</a> for more details.
      *
-     * @return the short month strings.
+     * @return the short month strings. Use
+     * {@link java.util.Calendar#JANUARY Calendar.JANUARY},
+     * {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY},
+     * etc. to index the result array.
      */
     public String[] getShortMonths() {
         return Arrays.copyOf(shortMonths, shortMonths.length);
@@ -435,7 +443,9 @@
 
     /**
      * Sets short month strings. For example: "Jan", "Feb", etc.
-     * @param newShortMonths the new short month strings.
+     * @param newShortMonths the new short month strings. The array should
+     * be indexed by {@link java.util.Calendar#JANUARY Calendar.JANUARY},
+     * {@link java.util.Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
      */
     public void setShortMonths(String[] newShortMonths) {
         shortMonths = Arrays.copyOf(newShortMonths, newShortMonths.length);
@@ -444,8 +454,10 @@
 
     /**
      * Gets weekday strings. For example: "Sunday", "Monday", etc.
-     * @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
-     * <code>Calendar.MONDAY</code>, etc. to index the result array.
+     * @return the weekday strings. Use
+     * {@link java.util.Calendar#SUNDAY Calendar.SUNDAY},
+     * {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. to index
+     * the result array.
      */
     public String[] getWeekdays() {
         return Arrays.copyOf(weekdays, weekdays.length);
@@ -454,8 +466,8 @@
     /**
      * Sets weekday strings. For example: "Sunday", "Monday", etc.
      * @param newWeekdays the new weekday strings. The array should
-     * be indexed by <code>Calendar.SUNDAY</code>,
-     * <code>Calendar.MONDAY</code>, etc.
+     * be indexed by {@link java.util.Calendar#SUNDAY Calendar.SUNDAY},
+     * {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc.
      */
     public void setWeekdays(String[] newWeekdays) {
         weekdays = Arrays.copyOf(newWeekdays, newWeekdays.length);
@@ -464,8 +476,10 @@
 
     /**
      * Gets short weekday strings. For example: "Sun", "Mon", etc.
-     * @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,
-     * <code>Calendar.MONDAY</code>, etc. to index the result array.
+     * @return the short weekday strings. Use
+     * {@link java.util.Calendar#SUNDAY Calendar.SUNDAY},
+     * {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc. to index
+     * the result array.
      */
     public String[] getShortWeekdays() {
         return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
@@ -474,8 +488,8 @@
     /**
      * Sets short weekday strings. For example: "Sun", "Mon", etc.
      * @param newShortWeekdays the new short weekday strings. The array should
-     * be indexed by <code>Calendar.SUNDAY</code>,
-     * <code>Calendar.MONDAY</code>, etc.
+     * be indexed by {@link java.util.Calendar#SUNDAY Calendar.SUNDAY},
+     * {@link java.util.Calendar#MONDAY Calendar.MONDAY}, etc.
      */
     public void setShortWeekdays(String[] newShortWeekdays) {
         shortWeekdays = Arrays.copyOf(newShortWeekdays, newShortWeekdays.length);
--- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java	Fri Aug 19 12:17:32 2016 -0700
@@ -147,11 +147,7 @@
      * @return the previous value
      */
     public final boolean getAndSet(boolean newValue) {
-        boolean prev;
-        do {
-            prev = get();
-        } while (!compareAndSet(prev, newValue));
-        return prev;
+        return (int)VALUE.getAndSet(this, (newValue ? 1 : 0)) != 0;
     }
 
     /**
--- a/src/java.base/share/classes/java/util/concurrent/locks/StampedLock.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/java/util/concurrent/locks/StampedLock.java	Fri Aug 19 12:17:32 2016 -0700
@@ -263,6 +263,47 @@
      * is theoretically possible, so we additionally add a
      * storeStoreFence after lock acquisition CAS.
      *
+     * ----------------------------------------------------------------
+     * Here's an informal proof that plain reads by _successful_
+     * readers see plain writes from preceding but not following
+     * writers (following Boehm and the C++ standard [atomics.fences]):
+     *
+     * Because of the total synchronization order of accesses to
+     * volatile long state containing the sequence number, writers and
+     * _successful_ readers can be globally sequenced.
+     *
+     * int x, y;
+     *
+     * Writer 1:
+     * inc sequence (odd - "locked")
+     * storeStoreFence();
+     * x = 1; y = 2;
+     * inc sequence (even - "unlocked")
+     *
+     * Successful Reader:
+     * read sequence (even)
+     * // must see writes from Writer 1 but not Writer 2
+     * r1 = x; r2 = y;
+     * acquireFence();
+     * read sequence (even - validated unchanged)
+     * // use r1 and r2
+     *
+     * Writer 2:
+     * inc sequence (odd - "locked")
+     * storeStoreFence();
+     * x = 3; y = 4;
+     * inc sequence (even - "unlocked")
+     *
+     * Visibility of writer 1's stores is normal - reader's initial
+     * read of state synchronizes with writer 1's final write to state.
+     * Lack of visibility of writer 2's plain writes is less obvious.
+     * If reader's read of x or y saw writer 2's write, then (assuming
+     * semantics of C++ fences) the storeStoreFence would "synchronize"
+     * with reader's acquireFence and reader's validation read must see
+     * writer 2's initial write to state and so validation must fail.
+     * But making this "proof" formal and rigorous is an open problem!
+     * ----------------------------------------------------------------
+     *
      * The memory layout keeps lock state and queue pointers together
      * (normally on the same cache line). This usually works well for
      * read-mostly loads. In most other cases, the natural tendency of
@@ -276,14 +317,14 @@
     /** Number of processors, for spin control */
     private static final int NCPU = Runtime.getRuntime().availableProcessors();
 
-    /** Maximum number of retries before enqueuing on acquisition */
-    private static final int SPINS = (NCPU > 1) ? 1 << 6 : 0;
+    /** Maximum number of retries before enqueuing on acquisition; at least 1 */
+    private static final int SPINS = (NCPU > 1) ? 1 << 6 : 1;
 
-    /** Maximum number of retries before blocking at head on acquisition */
-    private static final int HEAD_SPINS = (NCPU > 1) ? 1 << 10 : 0;
+    /** Maximum number of tries before blocking at head on acquisition */
+    private static final int HEAD_SPINS = (NCPU > 1) ? 1 << 10 : 1;
 
     /** Maximum number of retries before re-blocking */
-    private static final int MAX_HEAD_SPINS = (NCPU > 1) ? 1 << 16 : 0;
+    private static final int MAX_HEAD_SPINS = (NCPU > 1) ? 1 << 16 : 1;
 
     /** The period for yielding when waiting for overflow spinlock */
     private static final int OVERFLOW_YIELD_RATE = 7; // must be power 2 - 1
@@ -1228,6 +1269,11 @@
                         WCOWAIT.compareAndSet(h, c, c.cowait) &&
                         (w = c.thread) != null) // help release
                         LockSupport.unpark(w);
+                    if (Thread.interrupted()) {
+                        if (interruptible)
+                            return cancelWaiter(node, p, true);
+                        wasInterrupted = true;
+                    }
                     if (h == (pp = p.prev) || h == p || pp == null) {
                         long m, s, ns;
                         do {
@@ -1264,11 +1310,6 @@
                                 LockSupport.parkNanos(this, time);
                         }
                         node.thread = null;
-                        if (Thread.interrupted()) {
-                            if (interruptible)
-                                return cancelWaiter(node, p, true);
-                            wasInterrupted = true;
-                        }
                     }
                 }
             }
--- a/src/java.base/share/classes/javax/net/ssl/SSLEngine.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLEngine.java	Fri Aug 19 12:17:32 2016 -0700
@@ -861,6 +861,13 @@
      * be enabled by default, since this list may include cipher suites which
      * do not meet quality of service requirements for those defaults.  Such
      * cipher suites might be useful in specialized applications.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return  an array of cipher suite names
      * @see     #getEnabledCipherSuites()
@@ -880,6 +887,13 @@
      * or the requisite certificates (and private keys) for the suite are
      * not available, or an anonymous suite is enabled but authentication
      * is required.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return  an array of cipher suite names
      * @see     #getSupportedCipherSuites()
@@ -896,6 +910,14 @@
      * fail.  Following a successful call to this method, only suites
      * listed in the {@code suites} parameter are enabled for use.
      * <P>
+     * Note that the standard list of cipher suite names may be found in the
+     * <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list or might not
+     * use the recommended name for a certain cipher suite.
+     * <P>
      * See {@link #getEnabledCipherSuites()} for more information
      * on why a specific cipher suite may never be used on a engine.
      *
--- a/src/java.base/share/classes/javax/net/ssl/SSLParameters.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLParameters.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, 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
@@ -108,7 +108,12 @@
      * <p>
      * Calling this constructor is equivalent to calling the no-args
      * constructor followed by
-     * {@code setCipherSuites(cipherSuites);}.
+     * {@code setCipherSuites(cipherSuites);}.  Note that the
+     * standard list of cipher suite names may be found in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list.
      *
      * @param cipherSuites the array of ciphersuites (or null)
      */
@@ -123,6 +128,12 @@
      * Calling this constructor is equivalent to calling the no-args
      * constructor followed by
      * {@code setCipherSuites(cipherSuites); setProtocols(protocols);}.
+     * Note that the standard list of cipher suite names may be found in the
+     * <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list.
      *
      * @param cipherSuites the array of ciphersuites (or null)
      * @param protocols the array of protocols (or null)
@@ -139,6 +150,13 @@
     /**
      * Returns a copy of the array of ciphersuites or null if none
      * have been set.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return a copy of the array of ciphersuites or null if none
      * have been set.
@@ -150,7 +168,13 @@
     /**
      * Sets the array of ciphersuites.
      *
-     * @param cipherSuites the array of ciphersuites (or null)
+     * @param cipherSuites the array of ciphersuites (or null).  Note that the
+     * standard list of cipher suite names may be found in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list or might not
+     * use the recommended name for a certain cipher suite.
      */
     public void setCipherSuites(String[] cipherSuites) {
         this.cipherSuites = clone(cipherSuites);
--- a/src/java.base/share/classes/javax/net/ssl/SSLServerSocket.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLServerSocket.java	Fri Aug 19 12:17:32 2016 -0700
@@ -195,6 +195,13 @@
      * or the requisite certificates (and private keys) for the suite are
      * not available, or an anonymous suite is enabled but authentication
      * is required.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return an array of cipher suites enabled
      * @see #getSupportedCipherSuites()
@@ -215,6 +222,14 @@
      * in this ServerSocket's authentication context will not be used
      * in any case, even if they are enabled.
      * <P>
+     * Note that the standard list of cipher suite names may be found in the
+     * <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list or might not
+     * use the recommended name for a certain cipher suite.
+     * <P>
      * <code>SSLSocket</code>s returned from <code>accept()</code>
      * inherit this setting.
      *
@@ -236,6 +251,13 @@
      * be enabled by default, since this list may include cipher suites which
      * do not meet quality of service requirements for those defaults.  Such
      * cipher suites are useful in specialized applications.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return an array of cipher suite names
      * @see #getEnabledCipherSuites()
--- a/src/java.base/share/classes/javax/net/ssl/SSLServerSocketFactory.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLServerSocketFactory.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -123,6 +123,13 @@
      * will use one of these cipher suites.  The minimum quality of service
      * for these defaults requires confidentiality protection and server
      * authentication (that is, no anonymous cipher suites).
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @see #getSupportedCipherSuites()
      * @return array of the cipher suites enabled by default
@@ -137,6 +144,13 @@
      * be enabled by default, since this list may include cipher suites which
      * do not meet quality of service requirements for those defaults.  Such
      * cipher suites are useful in specialized applications.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return an array of cipher suite names
      * @see #getDefaultCipherSuites()
--- a/src/java.base/share/classes/javax/net/ssl/SSLSocket.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLSocket.java	Fri Aug 19 12:17:32 2016 -0700
@@ -265,6 +265,13 @@
      * be enabled by default, since this list may include cipher suites which
      * do not meet quality of service requirements for those defaults.  Such
      * cipher suites might be useful in specialized applications.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return an array of cipher suite names
      * @see #getEnabledCipherSuites()
@@ -284,6 +291,13 @@
      * or the requisite certificates (and private keys) for the suite are
      * not available, or an anonymous suite is enabled but authentication
      * is required.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @return an array of cipher suite names
      * @see #getSupportedCipherSuites()
@@ -300,6 +314,14 @@
      * fail.  Following a successful call to this method, only suites
      * listed in the <code>suites</code> parameter are enabled for use.
      * <P>
+     * Note that the standard list of cipher suite names may be found in the
+     * <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation.  Providers
+     * may support cipher suite names not found in this list or might not
+     * use the recommended name for a certain cipher suite.
+     * <P>
      * See {@link #getEnabledCipherSuites()} for more information
      * on why a specific ciphersuite may never be used on a connection.
      *
--- a/src/java.base/share/classes/javax/net/ssl/SSLSocketFactory.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/javax/net/ssl/SSLSocketFactory.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -148,6 +148,13 @@
      * will use one of these cipher suites.  The minimum quality of service
      * for these defaults requires confidentiality protection and server
      * authentication (that is, no anonymous cipher suites).
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @see #getSupportedCipherSuites()
      * @return array of the cipher suites enabled by default
@@ -160,6 +167,13 @@
      * be enabled by default, since this list may include cipher suites which
      * do not meet quality of service requirements for those defaults.  Such
      * cipher suites are useful in specialized applications.
+     * <P>
+     * The returned array includes cipher suites from the list of standard
+     * cipher suite names in the <a href=
+     * "{@docRoot}/../technotes/guides/security/StandardNames.html#ciphersuites">
+     * JSSE Cipher Suite Names</a> section of the Java Cryptography
+     * Architecture Standard Algorithm Name Documentation, and may also
+     * include other cipher suites that the provider supports.
      *
      * @see #getDefaultCipherSuites()
      * @return an array of cipher suite names
--- a/src/java.base/share/classes/jdk/internal/misc/JavaLangInvokeAccess.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaLangInvokeAccess.java	Fri Aug 19 12:17:32 2016 -0700
@@ -51,8 +51,17 @@
      * an {@code int} representing method type.  Used by
      * GenerateJLIClassesPlugin to generate such a class during the jlink phase.
      */
-    byte[] generateDMHClassBytes(String className, MethodType[] methodTypes,
-            int[] types);
+    byte[] generateDirectMethodHandleHolderClassBytes(String className,
+            MethodType[] methodTypes, int[] types);
+
+    /**
+     * Returns a {@code byte[]} containing the bytecode for a class implementing
+     * DelegatingMethodHandles of each {@code MethodType} kind in the
+     * {@code methodTypes} argument.  Used by GenerateJLIClassesPlugin to
+     * generate such a class during the jlink phase.
+     */
+    byte[] generateDelegatingMethodHandleHolderClassBytes(String className,
+            MethodType[] methodTypes);
 
     /**
      * Returns a {@code byte[]} containing the bytecode for a BoundMethodHandle
--- a/src/java.base/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -24,9 +24,8 @@
  */
 
 /**
- * java.base defines and exports the core APIs of the Java SE platform.
+ * Defines the foundational APIs of the Java SE Platform.
  */
-
 module java.base {
 
     exports java.io;
--- a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Fri Aug 19 12:17:32 2016 -0700
@@ -580,6 +580,9 @@
             Entry entry;
 
             if (key instanceof PrivateKey) {
+                // Check that all the certs are X.509 certs
+                checkX509Certs(chain);
+
                 PrivateKeyEntry keyEntry = new PrivateKeyEntry();
                 keyEntry.date = new Date();
 
@@ -690,6 +693,9 @@
                                   Certificate[] chain)
         throws KeyStoreException
     {
+        // Check that all the certs are X.509 certs
+        checkX509Certs(chain);
+
         // Private key must be encoded as EncryptedPrivateKeyInfo
         // as defined in PKCS#8
         try {
@@ -960,6 +966,13 @@
     private void setCertEntry(String alias, Certificate cert,
         Set<KeyStore.Entry.Attribute> attributes) throws KeyStoreException {
 
+        // Check that the cert is an X.509 cert
+        if (cert != null && (!(cert instanceof X509Certificate))) {
+            throw new KeyStoreException(
+                "Only X.509 certificates are supported - rejecting class: " +
+                cert.getClass().getName());
+        }
+
         Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
         if (entry != null && entry instanceof KeyEntry) {
             throw new KeyStoreException("Cannot overwrite own certificate");
@@ -1505,6 +1518,21 @@
         return set.size() == certChain.length;
     }
 
+    /*
+     * Check that all the certificates are X.509 certificates
+     */
+    private static void checkX509Certs(Certificate[] certs)
+            throws KeyStoreException {
+        if (certs != null) {
+            for (Certificate cert : certs) {
+                if (!(cert instanceof X509Certificate)) {
+                    throw new KeyStoreException(
+                        "Only X.509 certificates are supported - " +
+                        "rejecting class: " + cert.getClass().getName());
+                }
+            }
+        }
+    }
 
     /*
      * Create PKCS#12 Attributes, friendlyName, localKeyId and trustedKeyUsage.
--- a/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java	Fri Aug 19 12:17:32 2016 -0700
@@ -59,6 +59,11 @@
             "jdk.tls.client.enableStatusRequestExtension", true);
     private final boolean serverEnableStapling = Debug.getBooleanProperty(
             "jdk.tls.server.enableStatusRequestExtension", false);
+    private final static Collection<CipherSuite> clientCustomizedCipherSuites =
+            getCustomizedCipherSuites("jdk.tls.client.cipherSuites");
+    private final static Collection<CipherSuite> serverCustomizedCipherSuites =
+            getCustomizedCipherSuites("jdk.tls.server.cipherSuites");
+
     private volatile StatusResponseManager statusResponseManager;
 
     SSLContextImpl() {
@@ -336,20 +341,52 @@
         return isClient ? clientEnableStapling : serverEnableStapling;
     }
 
+
     /*
-     * Return the list of all available CipherSuites with a priority of
-     * minPriority or above.
+     * Return the list of all available CipherSuites that are supported
+     * using currently installed providers.
+     */
+    private static CipherSuiteList getApplicableSupportedCipherSuiteList(
+            ProtocolList protocols) {
+
+        return getApplicableCipherSuiteList(
+                CipherSuite.allowedCipherSuites(),
+                protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
+    }
+
+    /*
+     * Return the list of all available CipherSuites that are default enabled
+     * in client or server side.
+     */
+    private static CipherSuiteList getApplicableEnabledCipherSuiteList(
+            ProtocolList protocols, boolean isClient) {
+
+        if (isClient) {
+            if (!clientCustomizedCipherSuites.isEmpty()) {
+                return getApplicableCipherSuiteList(
+                        clientCustomizedCipherSuites,
+                        protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
+            }
+        } else {
+            if (!serverCustomizedCipherSuites.isEmpty()) {
+                return getApplicableCipherSuiteList(
+                        serverCustomizedCipherSuites,
+                        protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
+            }
+        }
+
+        return getApplicableCipherSuiteList(
+                CipherSuite.allowedCipherSuites(),
+                protocols, CipherSuite.DEFAULT_SUITES_PRIORITY);
+    }
+
+    /*
+     * Return the list of available CipherSuites which are applicable to
+     * the specified protocols.
      */
     private static CipherSuiteList getApplicableCipherSuiteList(
-            ProtocolList protocols, boolean onlyEnabled) {
-
-        int minPriority = CipherSuite.SUPPORTED_SUITES_PRIORITY;
-        if (onlyEnabled) {
-            minPriority = CipherSuite.DEFAULT_SUITES_PRIORITY;
-        }
-
-        Collection<CipherSuite> allowedCipherSuites =
-                                    CipherSuite.allowedCipherSuites();
+            Collection<CipherSuite> allowedCipherSuites,
+            ProtocolList protocols, int minPriority) {
 
         TreeSet<CipherSuite> suites = new TreeSet<>();
         if (!(protocols.collection().isEmpty()) &&
@@ -386,6 +423,67 @@
         return new CipherSuiteList(suites);
     }
 
+    /*
+     * Get the customized cipher suites specified by the given system property.
+     */
+    private static Collection<CipherSuite> getCustomizedCipherSuites(
+            String propertyName) {
+
+        String property = GetPropertyAction.privilegedGetProperty(propertyName);
+        if (debug != null && Debug.isOn("sslctx")) {
+            System.out.println(
+                    "System property " + propertyName + " is set to '" +
+                    property + "'");
+        }
+        if (property != null && property.length() != 0) {
+            // remove double quote marks from beginning/end of the property
+            if (property.length() > 1 && property.charAt(0) == '"' &&
+                    property.charAt(property.length() - 1) == '"') {
+                property = property.substring(1, property.length() - 1);
+            }
+        }
+
+        if (property != null && property.length() != 0) {
+            String[] cipherSuiteNames = property.split(",");
+            Collection<CipherSuite> cipherSuites =
+                        new ArrayList<>(cipherSuiteNames.length);
+            for (int i = 0; i < cipherSuiteNames.length; i++) {
+                cipherSuiteNames[i] = cipherSuiteNames[i].trim();
+                if (cipherSuiteNames[i].isEmpty()) {
+                    continue;
+                }
+
+                CipherSuite suite;
+                try {
+                    suite = CipherSuite.valueOf(cipherSuiteNames[i]);
+                } catch (IllegalArgumentException iae) {
+                    if (debug != null && Debug.isOn("sslctx")) {
+                        System.out.println(
+                                "Unknown or unsupported cipher suite name: " +
+                                cipherSuiteNames[i]);
+                    }
+
+                    continue;
+                }
+
+                if (suite.isAvailable()) {
+                    cipherSuites.add(suite);
+                } else {
+                    if (debug != null && Debug.isOn("sslctx")) {
+                        System.out.println(
+                                "The current installed providers do not " +
+                                "support cipher suite: " + cipherSuiteNames[i]);
+                    }
+                }
+            }
+
+            return cipherSuites;
+        }
+
+        return Collections.emptyList();
+    }
+
+
     private static String[] getAvailableProtocols(
             ProtocolVersion[] protocolCandidates) {
 
@@ -481,10 +579,10 @@
                 }));
             }
 
-            supportedCipherSuiteList = getApplicableCipherSuiteList(
-                    supportedProtocolList, false);          // all supported
-            serverDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    serverDefaultProtocolList, true);       // enabled only
+            supportedCipherSuiteList = getApplicableSupportedCipherSuiteList(
+                    supportedProtocolList);
+            serverDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    serverDefaultProtocolList, false);
         }
 
         @Override
@@ -541,8 +639,8 @@
                 }));
             }
 
-            clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);       // enabled only
+            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    clientDefaultProtocolList, true);
         }
 
         @Override
@@ -581,8 +679,9 @@
                 }));
             }
 
-            clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);       // enabled only
+            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    clientDefaultProtocolList, true);
+
         }
 
         @Override
@@ -623,8 +722,8 @@
                 }));
             }
 
-            clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);       // enabled only
+            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    clientDefaultProtocolList, true);
         }
 
         @Override
@@ -757,8 +856,9 @@
 
                 clientDefaultProtocolList = new ProtocolList(
                         getAvailableProtocols(candidates));
-                clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);   // enabled only
+                clientDefaultCipherSuiteList =
+                        getApplicableEnabledCipherSuiteList(
+                                clientDefaultProtocolList, true);
             } else {
                 clientDefaultProtocolList = null;       // unlikely to be used
                 clientDefaultCipherSuiteList = null;    // unlikely to be used
@@ -1032,10 +1132,10 @@
                 ProtocolVersion.DTLS12
             }));
 
-            supportedCipherSuiteList = getApplicableCipherSuiteList(
-                    supportedProtocolList, false);          // all supported
-            serverDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    serverDefaultProtocolList, true);       // enabled only
+            supportedCipherSuiteList = getApplicableSupportedCipherSuiteList(
+                    supportedProtocolList);
+            serverDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    serverDefaultProtocolList, false);
         }
 
         @Override
@@ -1090,8 +1190,8 @@
                 ProtocolVersion.DTLS10
             }));
 
-            clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);       // enabled only
+            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    clientDefaultProtocolList, true);
         }
 
         @Override
@@ -1122,8 +1222,8 @@
                 ProtocolVersion.DTLS12
             }));
 
-            clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);       // enabled only
+            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
+                    clientDefaultProtocolList, true);
         }
 
         @Override
@@ -1187,8 +1287,9 @@
 
                 clientDefaultProtocolList = new ProtocolList(
                         getAvailableProtocols(candidates));
-                clientDefaultCipherSuiteList = getApplicableCipherSuiteList(
-                    clientDefaultProtocolList, true);   // enabled only
+                clientDefaultCipherSuiteList =
+                        getApplicableEnabledCipherSuiteList(
+                                clientDefaultProtocolList, true);
             } else {
                 clientDefaultProtocolList = null;       // unlikely to be used
                 clientDefaultCipherSuiteList = null;    // unlikely to be used
--- a/src/java.base/share/classes/sun/security/tools/keytool/Main.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.base/share/classes/sun/security/tools/keytool/Main.java	Fri Aug 19 12:17:32 2016 -0700
@@ -3631,8 +3631,8 @@
                 if (time != null) {
                     if (time.matches("\\d\\d:\\d\\d:\\d\\d")) {
                         c.set(Calendar.HOUR_OF_DAY, Integer.valueOf(time.substring(0, 2)));
-                        c.set(Calendar.MINUTE, Integer.valueOf(time.substring(0, 2)));
-                        c.set(Calendar.SECOND, Integer.valueOf(time.substring(0, 2)));
+                        c.set(Calendar.MINUTE, Integer.valueOf(time.substring(3, 5)));
+                        c.set(Calendar.SECOND, Integer.valueOf(time.substring(6, 8)));
                         c.set(Calendar.MILLISECOND, 0);
                     } else {
                         throw ioe;
--- a/src/java.compact1/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.compact1/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Aggregates {@code java.base}, {@code java.logging}, and {@code java.scripting}.
+ */
 module java.compact1 {
     requires public java.logging;
     requires public java.scripting;
--- a/src/java.compact2/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.compact2/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Supplements {@code java.compact1} with JDBC, JAXP, and RMI.
+ */
 module java.compact2 {
     requires public java.compact1;
     requires public java.rmi;
--- a/src/java.compact3/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.compact3/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,10 @@
  * questions.
  */
 
+/**
+ * Supplements {@code java.compact2} with JDBC RowSet, JMX, JNDI, Compiler,
+ * Instrumentation, Preferences, Security, and XML cryptography APIs.
+ */
 module java.compact3 {
     requires public java.compact2;
     requires public java.compiler;
--- a/src/java.datatransfer/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.datatransfer/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -24,10 +24,8 @@
  */
 
 /**
- * Provides interfaces and classes for transferring data between and
- * within applications.
+ * Defines an API for transferring data between and within applications.
  */
-
 module java.datatransfer {
     exports java.awt.datatransfer;
     exports sun.datatransfer to java.desktop;
--- a/src/java.desktop/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.desktop/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -24,9 +24,9 @@
  */
 
 /**
-  * java.desktop defines and exports the user interface, graphics
-  * and imaging APIs of the Java SE platform.
-  */
+ * Defines the AWT and Swing user interface toolkits, plus APIs for
+ * accessibility, audio, imaging, printing, and JavaBeans.
+ */
 module java.desktop {
     requires public java.datatransfer;
     requires public java.xml;
--- a/src/java.httpclient/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.httpclient/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the high-level HTTP and WebSocket API.
+ */
 module java.httpclient {
     requires java.base;
     exports java.net.http;
--- a/src/java.instrument/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.instrument/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,10 @@
  * questions.
  */
 
+/**
+ * Defines services that allow agents to
+ * instrument programs running on the JVM.
+ */
 module java.instrument {
     exports java.lang.instrument;
 }
--- a/src/java.logging/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.logging/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Java Logging API.
+ */
 module java.logging {
     exports java.util.logging;
     provides jdk.internal.logger.DefaultLoggerFinder with
--- a/src/java.management/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.management/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,12 @@
  * questions.
  */
 
+/**
+ * Defines the Java Management Extensions (JMX) API.
+ * <P>
+ * The JMX API consists of interfaces for monitoring and management of the
+ * JVM and other components in the Java runtime.
+ */
 module java.management {
     requires public java.rmi;
     requires java.logging;
--- a/src/java.naming/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.naming/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Java Naming and Directory Interface (JNDI) API.
+ */
 module java.naming {
     requires java.security.sasl;
 
--- a/src/java.prefs/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.prefs/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Preferences API.
+ */
 module java.prefs {
     requires java.xml;
 
--- a/src/java.rmi/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.rmi/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Remote Method Invocation (RMI) API.
+ */
 module java.rmi {
     requires java.logging;
 
--- a/src/java.scripting/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.scripting/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Scripting API.
+ */
 module java.scripting {
     exports javax.script;
     uses javax.script.ScriptEngineFactory;
--- a/src/java.se/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.se/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,13 @@
  * questions.
  */
 
+/**
+ * Defines the core Java SE API.
+ * <P>
+ * The modules defining
+ * CORBA and Java EE APIs are not required by this module, but they are
+ * required by {@code java.se.ee}.
+ */
 module java.se {
     requires public java.compact3;
     requires public java.datatransfer;
--- a/src/java.security.jgss/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.security.jgss/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,11 @@
  * questions.
  */
 
+/**
+ * Defines the Java binding of the IETF Generic Security Services API (GSS-API).
+ * <P>
+ * This module also contains GSS-API mechanisms including Kerberos v5 and SPNEGO.
+ */
 module java.security.jgss {
     requires java.naming;
     exports javax.security.auth.kerberos;
--- a/src/java.security.sasl/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.security.sasl/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,13 @@
  * questions.
  */
 
+/**
+ * Defines Java support for the IETF Simple Authentication and Security Layer
+ * (SASL).
+ * <P>
+ * This module also contains SASL mechanisms including DIGEST-MD5,
+ * CRAM-MD5, and NTLM.
+ */
 module java.security.sasl {
     requires java.logging;
 
--- a/src/java.smartcardio/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.smartcardio/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the Java Smart Card I/O API.
+ */
 module java.smartcardio {
     exports javax.smartcardio;
     provides java.security.Provider with sun.security.smartcardio.SunPCSC;
--- a/src/java.sql.rowset/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.sql.rowset/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the JDBC RowSet API.
+ */
 module java.sql.rowset {
     requires public java.logging;
     requires public java.naming;
--- a/src/java.sql/share/classes/javax/sql/DataSource.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.sql/share/classes/javax/sql/DataSource.java	Fri Aug 19 12:17:32 2016 -0700
@@ -64,7 +64,7 @@
  * <P>
  * A driver that is accessed via a {@code DataSource} object does not
  * register itself with the {@code DriverManager}.  Rather, a
- * {@code DataSource} object is retrieved though a lookup operation
+ * {@code DataSource} object is retrieved through a lookup operation
  * and then used to create a {@code Connection} object.  With a basic
  * implementation, the connection obtained through a {@code DataSource}
  * object is identical to a connection obtained through the
--- a/src/java.sql/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.sql/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines the JDBC API.
+ */
 module java.sql {
     requires public java.logging;
     requires public java.xml;
--- a/src/java.transaction/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.transaction/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,12 @@
  * questions.
  */
 
+/**
+ * Defines a subset of the Java Transaction API (JTA) to support CORBA interop.
+ * <P>
+ * The subset consists of RMI exception types which are mapped to CORBA system
+ * exceptions by the 'Java Language to IDL Mapping Specification'.
+ */
 module java.transaction {
     requires public java.rmi;
     exports javax.transaction;
--- a/src/java.xml.crypto/share/classes/module-info.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/java.xml.crypto/share/classes/module-info.java	Fri Aug 19 12:17:32 2016 -0700
@@ -23,6 +23,9 @@
  * questions.
  */
 
+/**
+ * Defines an API for XML cryptography.
+ */
 module java.xml.crypto {
     requires public java.xml;
     requires java.logging;
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/Key.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/Key.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, 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
@@ -30,7 +30,6 @@
 /**
  * The handle for an RSA or DSA key using the Microsoft Crypto API.
  *
- * @see DSAPrivateKey
  * @see RSAPrivateKey
  * @see RSAPublicKey
  *
@@ -41,9 +40,35 @@
 {
     private static final long serialVersionUID = -1088859394025049194L;
 
-    // Native handle
-    protected long hCryptProv = 0;
-    protected long hCryptKey = 0;
+    static class NativeHandles {
+        long hCryptProv = 0;
+        long hCryptKey = 0;
+
+        public NativeHandles(long hCryptProv, long hCryptKey) {
+            this.hCryptProv = hCryptProv;
+            this.hCryptKey = hCryptKey;
+        }
+
+        /**
+         * Finalization method
+         */
+        protected void finalize() throws Throwable
+        {
+            try {
+                synchronized(this)
+                {
+                    cleanUp(hCryptProv, hCryptKey);
+                    hCryptProv = 0;
+                    hCryptKey = 0;
+                }
+
+            } finally {
+                super.finalize();
+            }
+        }
+    }
+
+    protected NativeHandles handles;
 
     // Key length
     protected int keyLength = 0;
@@ -51,32 +76,13 @@
     /**
      * Construct a Key object.
      */
-    protected Key(long hCryptProv, long hCryptKey, int keyLength)
+    protected Key(NativeHandles handles, int keyLength)
     {
-        this.hCryptProv = hCryptProv;
-        this.hCryptKey = hCryptKey;
+        this.handles = handles;
         this.keyLength = keyLength;
     }
 
     /**
-     * Finalization method
-     */
-    protected void finalize() throws Throwable
-    {
-        try {
-            synchronized(this)
-            {
-                cleanUp(hCryptProv, hCryptKey);
-                hCryptProv = 0;
-                hCryptKey = 0;
-            }
-
-        } finally {
-            super.finalize();
-        }
-    }
-
-    /**
      * Native method to cleanup the key handle.
      */
     private native static void cleanUp(long hCryptProv, long hCryptKey);
@@ -96,7 +102,7 @@
      */
     public long getHCryptKey()
     {
-        return hCryptKey;
+        return handles.hCryptKey;
     }
 
     /**
@@ -104,12 +110,12 @@
      */
     public long getHCryptProvider()
     {
-        return hCryptProv;
+        return handles.hCryptProv;
     }
 
     /**
      * Returns the standard algorithm name for this key. For
-     * example, "DSA" would indicate that this key is a DSA key.
+     * example, "RSA" would indicate that this key is a RSA key.
      * See Appendix A in the <a href=
      * "../../../guide/security/CryptoSpec.html#AppA">
      * Java Cryptography Architecture API Specification &amp; Reference </a>
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/KeyStore.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/KeyStore.java	Fri Aug 19 12:17:32 2016 -0700
@@ -168,7 +168,7 @@
             }
             certChain = chain;
         }
-    };
+    }
 
     /*
      * An X.509 certificate factory.
@@ -798,7 +798,8 @@
             }
 
             storeWithUniqueAlias(alias, new KeyEntry(alias,
-                    new RSAPrivateKey(hCryptProv, hCryptKey, keyLength),
+                    new RSAPrivateKey(new Key.NativeHandles(hCryptProv,
+                            hCryptKey), keyLength),
                     certChain));
         }
         catch (Throwable e)
@@ -854,7 +855,6 @@
      * Load keys and/or certificates from keystore into Collection.
      *
      * @param name Name of keystore.
-     * @param entries Collection of key/certificate.
      */
     private native void loadKeysOrCertificateChains(String name)
             throws KeyStoreException;
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAKeyPair.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAKeyPair.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 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
@@ -41,8 +41,9 @@
      */
     RSAKeyPair(long hCryptProv, long hCryptKey, int keyLength)
     {
-        privateKey = new RSAPrivateKey(hCryptProv, hCryptKey, keyLength);
-        publicKey = new RSAPublicKey(hCryptProv, hCryptKey, keyLength);
+        Key.NativeHandles handles = new Key.NativeHandles(hCryptProv, hCryptKey);
+        privateKey = new RSAPrivateKey(handles, keyLength);
+        publicKey = new RSAPublicKey(handles, keyLength);
     }
 
     public RSAPrivateKey getPrivate() {
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAPrivateKey.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAPrivateKey.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, 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
@@ -42,7 +42,15 @@
      */
     RSAPrivateKey(long hCryptProv, long hCryptKey, int keyLength)
     {
-        super(hCryptProv, hCryptKey, keyLength);
+        super(new NativeHandles(hCryptProv, hCryptKey), keyLength);
+    }
+
+    /**
+     * Construct an RSAPrivateKey object.
+     */
+    RSAPrivateKey(NativeHandles handles, int keyLength)
+    {
+        super(handles, keyLength);
     }
 
     /**
@@ -63,8 +71,8 @@
     public String toString()
     {
         return "RSAPrivateKey [size=" + keyLength + " bits, type=" +
-            getKeyType(hCryptKey) + ", container=" +
-            getContainerName(hCryptProv) + "]";
+            getKeyType(handles.hCryptKey) + ", container=" +
+            getContainerName(handles.hCryptProv) + "]";
     }
 
     // This class is not serializable
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAPublicKey.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAPublicKey.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, 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
@@ -51,7 +51,15 @@
      */
     RSAPublicKey(long hCryptProv, long hCryptKey, int keyLength)
     {
-        super(hCryptProv, hCryptKey, keyLength);
+        super(new NativeHandles(hCryptProv, hCryptKey), keyLength);
+    }
+
+    /**
+     * Construct an RSAPublicKey object.
+     */
+    RSAPublicKey(NativeHandles handles, int keyLength)
+    {
+        super(handles, keyLength);
     }
 
     /**
@@ -77,8 +85,8 @@
         StringBuffer sb = new StringBuffer();
 
         sb.append("RSAPublicKey [size=").append(keyLength)
-            .append(" bits, type=").append(getKeyType(hCryptKey))
-            .append(", container=").append(getContainerName(hCryptProv))
+            .append(" bits, type=").append(getKeyType(handles.hCryptKey))
+            .append(", container=").append(getContainerName(handles.hCryptProv))
             .append("]\n  modulus: ").append(getModulus())
             .append("\n  public exponent: ").append(getPublicExponent());
 
@@ -93,7 +101,7 @@
         if (exponent == null) {
 
             try {
-                publicKeyBlob = getPublicKeyBlob(hCryptKey);
+                publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
                 exponent = new BigInteger(1, getExponent(publicKeyBlob));
 
             } catch (KeyException e) {
@@ -112,7 +120,7 @@
         if (modulus == null) {
 
             try {
-                publicKeyBlob = getPublicKeyBlob(hCryptKey);
+                publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
                 modulus = new BigInteger(1, getModulus(publicKeyBlob));
 
             } catch (KeyException e) {
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Fri Aug 19 12:17:32 2016 -0700
@@ -55,7 +55,7 @@
 
     private static final String DESCRIPTION = PluginsResourceBundle.getDescription(NAME);
 
-    private static final String DMH = "java/lang/invoke/DirectMethodHandle$Holder";
+    private static final String DIRECT_METHOD_HANDLE = "java/lang/invoke/DirectMethodHandle$Holder";
     private static final String DMH_INVOKE_VIRTUAL = "invokeVirtual";
     private static final String DMH_INVOKE_STATIC = "invokeStatic";
     private static final String DMH_INVOKE_SPECIAL = "invokeSpecial";
@@ -63,6 +63,8 @@
     private static final String DMH_INVOKE_INTERFACE = "invokeInterface";
     private static final String DMH_INVOKE_STATIC_INIT = "invokeStaticInit";
 
+    private static final String DELEGATING_METHOD_HANDLE = "java/lang/invoke/DelegatingMethodHandle$Holder";
+
     private static final JavaLangInvokeAccess JLIA
             = SharedSecrets.getJavaLangInvokeAccess();
 
@@ -222,7 +224,15 @@
     @Override
     public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
         // Copy all but DMH_ENTRY to out
-        in.transformAndCopy(entry -> entry.path().equals(DMH_ENTRY) ? null : entry, out);
+        in.transformAndCopy(entry -> {
+                // filter out placeholder entries
+                if (entry.path().equals(DIRECT_METHOD_HANDLE_ENTRY) ||
+                    entry.path().equals(DELEGATING_METHOD_HANDLE_ENTRY)) {
+                    return null;
+                } else {
+                    return entry;
+                }
+            }, out);
         speciesTypes.forEach(types -> generateBMHClass(types, out));
         generateDMHClass(out);
         return out.build();
@@ -264,15 +274,24 @@
             }
         }
         try {
-            byte[] bytes =
-                    JLIA.generateDMHClassBytes(DMH, methodTypes, dmhTypes);
-            ResourcePoolEntry ndata = ResourcePoolEntry.create(DMH_ENTRY, bytes);
+            byte[] bytes = JLIA.generateDirectMethodHandleHolderClassBytes(
+                    DIRECT_METHOD_HANDLE, methodTypes, dmhTypes);
+            ResourcePoolEntry ndata = ResourcePoolEntry
+                    .create(DIRECT_METHOD_HANDLE_ENTRY, bytes);
+            out.add(ndata);
+
+            bytes = JLIA.generateDelegatingMethodHandleHolderClassBytes(
+                    DELEGATING_METHOD_HANDLE, methodTypes);
+            ndata = ResourcePoolEntry.create(DELEGATING_METHOD_HANDLE_ENTRY, bytes);
             out.add(ndata);
         } catch (Exception ex) {
             throw new PluginException(ex);
         }
     }
-    private static final String DMH_ENTRY = "/java.base/" + DMH + ".class";
+    private static final String DIRECT_METHOD_HANDLE_ENTRY =
+            "/java.base/" + DIRECT_METHOD_HANDLE + ".class";
+    private static final String DELEGATING_METHOD_HANDLE_ENTRY =
+            "/java.base/" + DELEGATING_METHOD_HANDLE + ".class";
 
     // Convert LL -> LL, L3 -> LLL
     private static String expandSignature(String signature) {
@@ -310,15 +329,19 @@
         assert(parts.length == 2);
         assert(parts[1].length() == 1);
         String parameters = expandSignature(parts[0]);
-        Class<?> rtype = primitiveType(parts[1].charAt(0));
-        Class<?>[] ptypes = new Class<?>[parameters.length()];
-        for (int i = 0; i < ptypes.length; i++) {
-            ptypes[i] = primitiveType(parameters.charAt(i));
+        Class<?> rtype = simpleType(parts[1].charAt(0));
+        if (parameters.isEmpty()) {
+            return MethodType.methodType(rtype);
+        } else {
+            Class<?>[] ptypes = new Class<?>[parameters.length()];
+            for (int i = 0; i < ptypes.length; i++) {
+                ptypes[i] = simpleType(parameters.charAt(i));
+            }
+            return MethodType.methodType(rtype, ptypes);
         }
-        return MethodType.methodType(rtype, ptypes);
     }
 
-    private static Class<?> primitiveType(char c) {
+    private static Class<?> simpleType(char c) {
         switch (c) {
             case 'F':
                 return float.class;
--- a/test/ProblemList.txt	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/ProblemList.txt	Fri Aug 19 12:17:32 2016 -0700
@@ -211,6 +211,8 @@
 
 java/rmi/transport/dgcDeadLock/DGCDeadLock.java                 8029360 macosx-all
 
+sun/rmi/runtime/Log/6409194/NoConsoleOutput.java                8164124 windows-all
+
 ############################################################################
 
 # jdk_security
--- a/test/java/lang/StackWalker/VerifyStackTrace.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/lang/StackWalker/VerifyStackTrace.java	Fri Aug 19 12:17:32 2016 -0700
@@ -205,8 +205,12 @@
                     .replaceAll("java.base@(\\d+\\.){0,3}(\\d+)/", "java.base/")
                     .replaceAll("/[0-9]+\\.run", "/xxxxxxxx.run")
                     .replaceAll("/[0-9]+\\.invoke", "/xxxxxxxx.invoke")
+                    // DMHs may or may not be pre-generated, making frames differ
                     .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH")
                     .replaceAll("DMH\\.invoke", "DMH/xxxxxxxx.invoke")
+                    // invoke frames may or may not have basic method type
+                    // information encoded for diagnostic purposes
+                    .replaceAll("xx\\.invoke([A-Za-z]*)_[A-Z]+_[A-Z]", "xx.invoke$1")
                     .replaceAll("\\$[0-9]+", "\\$??");
         } else {
             return produced;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/security/KeyPairGenerator/FinalizeHalf.java	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,90 @@
+/*
+ * 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 8163896
+ * @summary Finalizing one key of a KeyPair invalidates the other key
+ */
+
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
+import java.security.ProviderException;
+import java.security.Security;
+import java.util.function.Consumer;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FinalizeHalf {
+
+    static int failures = 0;
+
+    public static void main(String[] args) throws Throwable {
+        List<Consumer<Key>> methods = new ArrayList<>();
+        methods.add((Key k) -> k.getEncoded());
+        methods.add((Key k) -> k.toString());
+
+        for (String algo : new String[] {"DiffieHellman", "DSA", "RSA"}) {
+            for (Provider provider : Security.getProviders()) {
+                for (boolean priv : new boolean[] {true, false}) {
+                    for (Consumer<Key> method : methods) {
+                        test(algo, provider, priv, method);
+                    }
+                }
+            }
+        }
+
+        if (failures > 0) {
+            throw new RuntimeException(failures + " test(s) failed.");
+        }
+    }
+
+    static void test(String algo, Provider provider, boolean priv,
+            Consumer<Key> method) throws Exception {
+        KeyPairGenerator generator;
+        try {
+            generator = KeyPairGenerator.getInstance(algo, provider);
+        } catch (NoSuchAlgorithmException nsae) {
+            return;
+        }
+
+        System.out.println("Checking " + provider.getName() + ", " + algo);
+
+        KeyPair pair = generator.generateKeyPair();
+        Key key = priv ? pair.getPrivate() : pair.getPublic();
+
+        pair = null;
+        for (int i = 0; i < 32; ++i) {
+            System.gc();
+        }
+
+        try {
+            method.accept(key);
+        } catch (ProviderException pe) {
+            failures++;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/security/Security/ClassLoader/DeprivilegedModuleLoaderTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import javax.security.auth.kerberos.KeyTab;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import com.sun.security.auth.callback.TextCallbackHandler;
+import com.sun.security.jgss.AuthorizationDataEntry;
+
+/*
+ * @test
+ * @bug 8159964
+ * @summary Classes from deprivileged modules should get loaded through
+ *          Platform Classloader.
+ * @run main DeprivilegedModuleLoaderTest
+ */
+public class DeprivilegedModuleLoaderTest {
+
+    public static void main(String[] args) {
+
+        boolean pass = true;
+        List<Class<?>> classes = getDeprivilegedClasses();
+        for (Class<?> cls : classes) {
+            try {
+                pass &= testPlatformClassLoader(cls);
+            } catch (Exception exc) {
+                exc.printStackTrace(System.out);
+                pass = false;
+            }
+        }
+
+        if (!pass) {
+            throw new RuntimeException("Atleast one test failed.");
+        }
+    }
+
+    private static List<Class<?>> getDeprivilegedClasses() {
+
+        List<Class<?>> classes = new ArrayList<Class<?>>();
+        // Test from java.xml.crypto/javax/xml/crypto/dsig package
+        classes.add(XMLSignatureFactory.class);
+        // Test from java.xml.crypto/javax/xml/crypto package
+        classes.add(KeySelectorException.class);
+        // Test From java.security.jgss/javax/security/auth/kerberos package
+        classes.add(KeyTab.class);
+        // Test from jdk.security.jgss/com/sun/security/jgss package
+        classes.add(AuthorizationDataEntry.class);
+        // Test from jdk.security.auth/com/sun/security/auth/callback package
+        classes.add(TextCallbackHandler.class);
+        return classes;
+    }
+
+    private static boolean testPlatformClassLoader(Class<?> cls) {
+
+        ClassLoader loader = cls.getClassLoader();
+        if (loader == null) {
+            throw new RuntimeException(String.format(
+                    "Loaded through Bootstrap Classloader: '%s'", cls));
+        } else if (!loader.toString().contains("PlatformClassLoader")) {
+            throw new RuntimeException(String.format(
+                    "Not loaded through Platform ClassLoader: '%s'", cls));
+        }
+        System.out.println(String.format(
+                "Pass: '%s' get loaded through PlatformClassLoader", cls));
+        return true;
+    }
+}
--- a/test/java/security/testlibrary/SimpleOCSPServer.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/security/testlibrary/SimpleOCSPServer.java	Fri Aug 19 12:17:32 2016 -0700
@@ -64,6 +64,8 @@
     private static final SimpleDateFormat utcDateFmt =
             new SimpleDateFormat("MMM dd yyyy, HH:mm:ss z");
 
+    static final int FREE_PORT = 0;
+
     // CertStatus values
     public static enum CertStatus {
         CERT_STATUS_GOOD,
@@ -88,7 +90,8 @@
     private volatile boolean started = false;
     private volatile boolean serverReady = false;
     private volatile boolean receivedShutdown = false;
-    private long delayMsec = 0;
+    private volatile boolean acceptConnections = true;
+    private volatile long delayMsec = 0;
 
     // Fields used in the generation of responses
     private long nextUpdateInterval = -1;
@@ -116,7 +119,7 @@
      */
     public SimpleOCSPServer(KeyStore ks, String password, String issuerAlias,
             String signerAlias) throws GeneralSecurityException, IOException {
-        this(null, 0, ks, password, issuerAlias, signerAlias);
+        this(null, FREE_PORT, ks, password, issuerAlias, signerAlias);
     }
 
     /**
@@ -230,6 +233,15 @@
                     while (!receivedShutdown) {
                         try {
                             Socket newConnection = servSocket.accept();
+                            if (!acceptConnections) {
+                                try {
+                                    log("Reject connection");
+                                    newConnection.close();
+                                } catch (IOException e) {
+                                    // ignore
+                                }
+                                continue;
+                            }
                             threadPool.submit(new OcspHandler(newConnection));
                         } catch (SocketTimeoutException timeout) {
                             // Nothing to do here.  If receivedShutdown
@@ -257,6 +269,23 @@
     }
 
     /**
+     * Make the OCSP server reject incoming connections.
+     */
+    public synchronized void rejectConnections() {
+        log("Reject OCSP connections");
+        acceptConnections = false;
+    }
+
+    /**
+     * Make the OCSP server accept incoming connections.
+     */
+    public synchronized void acceptConnections() {
+        log("Accept OCSP connections");
+        acceptConnections = true;
+    }
+
+
+    /**
      * Stop the OCSP server.
      */
     public synchronized void stop() {
@@ -499,13 +528,11 @@
      * on the incoming request.
      */
     public void setDelay(long delayMillis) {
-        if (!started) {
-            delayMsec = delayMillis > 0 ? delayMillis : 0;
-            if (delayMsec > 0) {
-                log("OCSP latency set to " + delayMsec + " milliseconds.");
-            } else {
-                log("OCSP latency disabled");
-            }
+        delayMsec = delayMillis > 0 ? delayMillis : 0;
+        if (delayMsec > 0) {
+            log("OCSP latency set to " + delayMsec + " milliseconds.");
+        } else {
+            log("OCSP latency disabled");
         }
     }
 
--- a/test/java/util/concurrent/BlockingQueue/PollMemoryLeak.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/BlockingQueue/PollMemoryLeak.java	Fri Aug 19 12:17:32 2016 -0700
@@ -26,43 +26,133 @@
  * However, the following notice accompanied the original version of this
  * file:
  *
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group and released to the public domain, as explained at
+ * Written by Doug Lea and Martin Buchholz with assistance from
+ * members of JCP JSR-166 Expert Group and released to the public
+ * domain, as explained at
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 /*
  * @test
  * @bug 6236036 6264015
- * @compile PollMemoryLeak.java
- * @run main/othervm -Xmx8m PollMemoryLeak
- * @summary  Checks for OutOfMemoryError when an unbounded
- * number of aborted timed waits occur without a signal.
+ * @summary Checks for a memory leak when a sequence of aborted timed
+ * waits occur without a signal.  Uses the strategy of detecting
+ * changes in the size of the object graph retained by a root object.
  */
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.LinkedTransferQueue;
+import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.TimeUnit;
 
 public class PollMemoryLeak {
-    public static void main(String[] args) throws InterruptedException {
-        final BlockingQueue[] qs = {
-            new LinkedBlockingDeque(10),
-            new LinkedBlockingQueue(10),
-            new LinkedTransferQueue(),
-            new ArrayBlockingQueue(10),
-            new ArrayBlockingQueue(10, true),
-            new SynchronousQueue(),
-            new SynchronousQueue(true),
-        };
-        final long start = System.currentTimeMillis();
-        final long end = start + 10 * 1000;
-        while (System.currentTimeMillis() < end)
-            for (BlockingQueue q : qs)
-                q.poll(1, TimeUnit.NANOSECONDS);
+    public static void main(String[] args) throws Throwable {
+        new PollMemoryLeak().main();
+    }
+
+    void main() throws Throwable {
+        test(new LinkedBlockingDeque(10));
+        test(new LinkedBlockingQueue(10));
+        test(new LinkedTransferQueue());
+        test(new ArrayBlockingQueue(10));
+        test(new PriorityBlockingQueue());
+        test(new SynchronousQueue());
+        test(new SynchronousQueue(true));
+    }
+
+    void test(BlockingQueue q) throws Throwable {
+        assertNoLeak(q, () -> timedPoll(q));
+
+        // A demo that the leak detection infrastructure works
+        // assertNoLeak(q, () -> q.add(1));
+        // printRetainedObjects(q);
+    }
+
+    static void timedPoll(BlockingQueue q) {
+        try { q.poll(1, TimeUnit.NANOSECONDS); }
+        catch (InterruptedException ex) { throw new AssertionError(ex); }
+    }
+
+    // -------- leak detection infrastructure ---------------
+    void assertNoLeak(Object root, Runnable r) {
+        int prev = retainedObjects(root).size();
+        for (int i = 0; i < 3; i++) {
+            for (int j = 0; j < 3; j++) r.run();
+            int next = retainedObjects(root).size();
+            if (next <= prev)
+                return;
+            prev = next;
+        }
+        throw new AssertionError(
+            String.format("probable memory leak in %s: %s",
+                          root.getClass().getSimpleName(), root));
+    }
+
+    ConcurrentHashMap<Class<?>, Collection<Field>> classFields
+        = new ConcurrentHashMap<Class<?>, Collection<Field>>();
+
+    Collection<Field> referenceFieldsOf(Class<?> k) {
+        Collection<Field> fields = classFields.get(k);
+        if (fields == null) {
+            fields = new ArrayDeque<Field>();
+            ArrayDeque<Field> allFields = new ArrayDeque<Field>();
+            for (Class<?> c = k; c != null; c = c.getSuperclass())
+                for (Field field : c.getDeclaredFields())
+                    if (!Modifier.isStatic(field.getModifiers())
+                        && !field.getType().isPrimitive())
+                        fields.add(field);
+            AccessibleObject.setAccessible(
+                fields.toArray(new AccessibleObject[0]), true);
+            classFields.put(k, fields);
+        }
+        return fields;
+    }
+
+    static Object get(Field field, Object x) {
+        try { return field.get(x); }
+        catch (IllegalAccessException ex) { throw new AssertionError(ex); }
+    }
+
+    Set<Object> retainedObjects(Object x) {
+        ArrayDeque<Object> todo = new ArrayDeque<Object>() {
+            public void push(Object x) { if (x != null) super.push(x); }};
+        Set<Object> uniqueObjects = Collections.newSetFromMap(
+            new IdentityHashMap<Object, Boolean>());
+        todo.push(x);
+        while (!todo.isEmpty()) {
+            Object y = todo.pop();
+            if (uniqueObjects.contains(y))
+                continue;
+            uniqueObjects.add(y);
+            Class<?> k = y.getClass();
+            if (k.isArray() && !k.getComponentType().isPrimitive()) {
+                for (int i = 0, len = Array.getLength(y); i < len; i++)
+                    todo.push(Array.get(y, i));
+            } else {
+                for (Field field : referenceFieldsOf(k))
+                    todo.push(get(field, y));
+            }
+        }
+        return uniqueObjects;
+    }
+
+    /** for debugging the retained object graph */
+    void printRetainedObjects(Object x) {
+        for (Object y : retainedObjects(x))
+            System.out.printf("%s : %s%n", y.getClass().getSimpleName(), y);
     }
 }
--- a/test/java/util/concurrent/ConcurrentLinkedQueue/RemoveLeak.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/ConcurrentLinkedQueue/RemoveLeak.java	Fri Aug 19 12:17:32 2016 -0700
@@ -35,26 +35,120 @@
  * @test
  * @bug 8054446 8137184 8137185
  * @summary Regression test for memory leak in remove(Object)
- * @run main/othervm -Xmx2200k RemoveLeak
  */
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.LinkedTransferQueue;
+import java.util.concurrent.PriorityBlockingQueue;
 
 public class RemoveLeak {
-    public static void main(String[] args) {
-        int i = 0;
-        // Without bug fix, OutOfMemoryError was observed at iteration 65120
-        int iterations = 10 * 65120;
-        try {
-            ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
-            queue.add(0L);
-            while (i++ < iterations) {
-                queue.add(1L);
-                queue.remove(1L);
+    public static void main(String[] args) throws Throwable {
+        new RemoveLeak().main();
+    }
+
+    void main() throws Throwable {
+        test(new ConcurrentLinkedDeque());
+        test(new ConcurrentLinkedQueue());
+        test(new LinkedBlockingDeque(10));
+        test(new LinkedBlockingQueue(10));
+        test(new LinkedTransferQueue());
+        test(new ArrayBlockingQueue(10));
+        test(new PriorityBlockingQueue());
+    }
+
+    void test(Collection c) throws Throwable {
+        assertNoLeak(c, () -> addRemove(c));
+
+        // A demo that the leak detection infrastructure works
+        // assertNoLeak(c, () -> c.add(1));
+        // printRetainedObjects(c);
+    }
+
+    static void addRemove(Collection c) {
+        c.add(1);
+        c.remove(1);
+    }
+
+    // -------- leak detection infrastructure ---------------
+    void assertNoLeak(Object root, Runnable r) {
+        int prev = retainedObjects(root).size();
+        for (int i = 0; i < 3; i++) {
+            for (int j = 0; j < 3; j++) r.run();
+            int next = retainedObjects(root).size();
+            if (next <= prev)
+                return;
+            prev = next;
+        }
+        throw new AssertionError(
+            String.format("probable memory leak in %s: %s",
+                          root.getClass().getSimpleName(), root));
+    }
+
+    ConcurrentHashMap<Class<?>, Collection<Field>> classFields
+        = new ConcurrentHashMap<Class<?>, Collection<Field>>();
+
+    Collection<Field> referenceFieldsOf(Class<?> k) {
+        Collection<Field> fields = classFields.get(k);
+        if (fields == null) {
+            fields = new ArrayDeque<Field>();
+            ArrayDeque<Field> allFields = new ArrayDeque<Field>();
+            for (Class<?> c = k; c != null; c = c.getSuperclass())
+                for (Field field : c.getDeclaredFields())
+                    if (!Modifier.isStatic(field.getModifiers())
+                        && !field.getType().isPrimitive())
+                        fields.add(field);
+            AccessibleObject.setAccessible(
+                fields.toArray(new AccessibleObject[0]), true);
+            classFields.put(k, fields);
+        }
+        return fields;
+    }
+
+    static Object get(Field field, Object x) {
+        try { return field.get(x); }
+        catch (IllegalAccessException ex) { throw new AssertionError(ex); }
+    }
+
+    Set<Object> retainedObjects(Object x) {
+        ArrayDeque<Object> todo = new ArrayDeque<Object>() {
+            public void push(Object x) { if (x != null) super.push(x); }};
+        Set<Object> uniqueObjects = Collections.newSetFromMap(
+            new IdentityHashMap<Object, Boolean>());
+        todo.push(x);
+        while (!todo.isEmpty()) {
+            Object y = todo.pop();
+            if (uniqueObjects.contains(y))
+                continue;
+            uniqueObjects.add(y);
+            Class<?> k = y.getClass();
+            if (k.isArray() && !k.getComponentType().isPrimitive()) {
+                for (int i = 0, len = Array.getLength(y); i < len; i++)
+                    todo.push(Array.get(y, i));
+            } else {
+                for (Field field : referenceFieldsOf(k))
+                    todo.push(get(field, y));
             }
-        } catch (Error t) {
-            System.err.printf("failed at iteration %d/%d%n", i, iterations);
-            throw t;
         }
+        return uniqueObjects;
+    }
+
+    /** for debugging the retained object graph */
+    void printRetainedObjects(Object x) {
+        for (Object y : retainedObjects(x))
+            System.out.printf("%s : %s%n", y.getClass().getSimpleName(), y);
     }
 }
--- a/test/java/util/concurrent/forkjoin/FJExceptionTableLeak.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/forkjoin/FJExceptionTableLeak.java	Fri Aug 19 12:17:32 2016 -0700
@@ -26,51 +26,117 @@
  * However, the following notice accompanied the original version of this
  * file:
  *
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group and released to the public domain, as explained at
+ * Written by Doug Lea and Martin Buchholz with assistance from
+ * members of JCP JSR-166 Expert Group and released to the public
+ * domain, as explained at
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 /*
  * @test
- * @author Doug Lea
  * @bug 8004138
- * @key intermittent
- * @summary Check if ForkJoinPool table leaks thrown exceptions.
- * @run main/othervm -Xmx8m -Djava.util.concurrent.ForkJoinPool.common.parallelism=4 FJExceptionTableLeak
+ * @summary Checks that ForkJoinTask thrown exceptions are not leaked.
+ * This whitebox test is sensitive to forkjoin implementation details.
  */
 
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ForkJoinTask;
 import java.util.concurrent.RecursiveAction;
+import java.util.function.BooleanSupplier;
 
 public class FJExceptionTableLeak {
-    // This test was observed to fail with pre-bug-fix jdk7 -Xmx8m,
-    // using STEPS = 220 and TASKS_PER_STEP = 100
-    static final int PRE_BUG_FIX_FAILURE_STEPS = 220;
-    static final int STEPS = 10 * PRE_BUG_FIX_FAILURE_STEPS;
-    static final int TASKS_PER_STEP = 100;
-
     static class FailingTaskException extends RuntimeException {}
     static class FailingTask extends RecursiveAction {
-        public void compute() {
-            throw new FailingTaskException();
-        }
+        public void compute() { throw new FailingTaskException(); }
     }
 
-    public static void main(String[] args) throws InterruptedException {
-        ForkJoinPool pool = new ForkJoinPool(4);
-        FailingTask[] tasks = new FailingTask[TASKS_PER_STEP];
-        for (int k = 0; k < STEPS; ++k) {
-            for (int i = 0; i < tasks.length; ++i)
-                tasks[i] = new FailingTask();
-            for (int i = 0; i < tasks.length; ++i)
-                pool.execute(tasks[i]);
-            for (int i = 0; i < tasks.length; ++i) {
+    static int bucketsInuse(Object[] exceptionTable) {
+        int count = 0;
+        for (Object x : exceptionTable)
+            if (x != null) count++;
+        return count;
+    }
+
+    public static void main(String[] args) throws Exception {
+        final ForkJoinPool pool = new ForkJoinPool(4);
+        final Field exceptionTableField =
+            ForkJoinTask.class.getDeclaredField("exceptionTable");
+        exceptionTableField.setAccessible(true);
+        final Object[] exceptionTable = (Object[]) exceptionTableField.get(null);
+
+        if (bucketsInuse(exceptionTable) != 0) throw new AssertionError();
+
+        final ArrayList<FailingTask> tasks = new ArrayList<>();
+
+        // Keep submitting failing tasks until most of the exception
+        // table buckets are in use
+        do {
+            for (int i = 0; i < exceptionTable.length; i++) {
+                FailingTask task = new FailingTask();
+                pool.execute(task);
+                tasks.add(task); // retain strong refs to all tasks, for now
+            }
+            for (FailingTask task : tasks) {
                 try {
-                    tasks[i].join();
+                    task.join();
                     throw new AssertionError("should throw");
                 } catch (FailingTaskException success) {}
             }
+        } while (bucketsInuse(exceptionTable) < exceptionTable.length * 3 / 4);
+
+        // Retain a strong ref to one last failing task;
+        // task.join() will trigger exception table expunging.
+        FailingTask lastTask = tasks.get(0);
+
+        // Clear all other strong refs, making exception table cleanable
+        tasks.clear();
+
+        BooleanSupplier exceptionTableIsClean = () -> {
+            try {
+                lastTask.join();
+                throw new AssertionError("should throw");
+            } catch (FailingTaskException expected) {}
+            int count = bucketsInuse(exceptionTable);
+            if (count == 0)
+                throw new AssertionError("expected to find last task");
+            return count == 1;
+        };
+        gcAwait(exceptionTableIsClean);
+    }
+
+    // --------------- GC finalization infrastructure ---------------
+
+    /** No guarantees, but effective in practice. */
+    static void forceFullGc() {
+        CountDownLatch finalizeDone = new CountDownLatch(1);
+        WeakReference<?> ref = new WeakReference<Object>(new Object() {
+            protected void finalize() { finalizeDone.countDown(); }});
+        try {
+            for (int i = 0; i < 10; i++) {
+                System.gc();
+                if (finalizeDone.await(1L, SECONDS) && ref.get() == null) {
+                    System.runFinalization(); // try to pick up stragglers
+                    return;
+                }
+            }
+        } catch (InterruptedException unexpected) {
+            throw new AssertionError("unexpected InterruptedException");
         }
+        throw new AssertionError("failed to do a \"full\" gc");
+    }
+
+    static void gcAwait(BooleanSupplier s) {
+        for (int i = 0; i < 10; i++) {
+            if (s.getAsBoolean())
+                return;
+            forceFullGc();
+        }
+        throw new AssertionError("failed to satisfy condition");
     }
 }
--- a/test/java/util/concurrent/tck/ArrayBlockingQueueTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/ArrayBlockingQueueTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -492,7 +492,7 @@
             }});
 
         await(aboutToWait);
-        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
+        waitForThreadToEnterWaitState(t);
         t.interrupt();
         awaitTermination(t);
         checkEmpty(q);
--- a/test/java/util/concurrent/tck/AtomicBooleanTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/AtomicBooleanTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -136,11 +136,14 @@
      * getAndSet returns previous value and sets to given value
      */
     public void testGetAndSet() {
-        AtomicBoolean ai = new AtomicBoolean(true);
-        assertEquals(true, ai.getAndSet(false));
-        assertEquals(false, ai.getAndSet(false));
-        assertEquals(false, ai.getAndSet(true));
-        assertTrue(ai.get());
+        AtomicBoolean ai = new AtomicBoolean();
+        boolean[] booleans = { false, true };
+        for (boolean before : booleans)
+            for (boolean after : booleans) {
+                ai.set(before);
+                assertEquals(before, ai.getAndSet(after));
+                assertEquals(after, ai.get());
+            }
     }
 
     /**
--- a/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/ConcurrentHashMap8Test.java	Fri Aug 19 12:17:32 2016 -0700
@@ -433,7 +433,7 @@
         Integer[] elements = new Integer[size];
         for (int i = 0; i < size; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         Iterator it = full.iterator();
@@ -523,7 +523,7 @@
         Integer[] elements = new Integer[size];
         for (int i = 0; i < size; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray())));
@@ -553,7 +553,7 @@
         Integer[] elements = new Integer[size];
         for (int i = 0; i < size; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         Arrays.fill(a, 42);
--- a/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/CopyOnWriteArrayListTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -291,7 +291,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedArray(elements);
 
         Iterator it = full.iterator();
@@ -459,7 +459,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedArray(elements);
 
         assertTrue(Arrays.equals(elements, full.toArray()));
@@ -487,7 +487,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedArray(elements);
 
         Arrays.fill(a, 42);
--- a/test/java/util/concurrent/tck/CopyOnWriteArraySetTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/CopyOnWriteArraySetTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -251,7 +251,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         Iterator it = full.iterator();
@@ -338,7 +338,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         assertTrue(Arrays.equals(elements, full.toArray()));
@@ -366,7 +366,7 @@
         Integer[] elements = new Integer[SIZE];
         for (int i = 0; i < SIZE; i++)
             elements[i] = i;
-        Collections.shuffle(Arrays.asList(elements));
+        shuffle(elements);
         Collection<Integer> full = populatedSet(elements);
 
         Arrays.fill(a, 42);
--- a/test/java/util/concurrent/tck/ForkJoinTask8Test.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/ForkJoinTask8Test.java	Fri Aug 19 12:17:32 2016 -0700
@@ -948,7 +948,7 @@
                 AsyncFib f = new AsyncFib(8);
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 ForkJoinTask[] tasks = { f, g };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks[0], tasks[1]);
                     shouldThrow();
@@ -975,7 +975,7 @@
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks[0], tasks[1], tasks[2]);
                     shouldThrow();
@@ -1002,7 +1002,7 @@
                 AsyncFib g = new AsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(Arrays.asList(tasks));
                     shouldThrow();
--- a/test/java/util/concurrent/tck/ForkJoinTaskTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/ForkJoinTaskTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -924,7 +924,7 @@
                 AsyncFib f = new AsyncFib(8);
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 ForkJoinTask[] tasks = { f, g };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks);
                     shouldThrow();
@@ -962,7 +962,7 @@
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks);
                     shouldThrow();
@@ -983,10 +983,9 @@
                 AsyncFib g = new AsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                List taskList = Arrays.asList(tasks);
-                Collections.shuffle(taskList);
+                shuffle(tasks);
                 try {
-                    invokeAll(taskList);
+                    invokeAll(Arrays.asList(tasks));
                     shouldThrow();
                 } catch (FJException success) {
                     checkCompletedAbnormally(f, success);
@@ -1594,7 +1593,7 @@
                 AsyncFib f = new AsyncFib(8);
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 ForkJoinTask[] tasks = { f, g };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks);
                     shouldThrow();
@@ -1632,7 +1631,7 @@
                 FailingAsyncFib g = new FailingAsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                Collections.shuffle(Arrays.asList(tasks));
+                shuffle(tasks);
                 try {
                     invokeAll(tasks);
                     shouldThrow();
@@ -1653,10 +1652,9 @@
                 AsyncFib g = new AsyncFib(9);
                 AsyncFib h = new AsyncFib(7);
                 ForkJoinTask[] tasks = { f, g, h };
-                List taskList = Arrays.asList(tasks);
-                Collections.shuffle(taskList);
+                shuffle(tasks);
                 try {
-                    invokeAll(taskList);
+                    invokeAll(Arrays.asList(tasks));
                     shouldThrow();
                 } catch (FJException success) {
                     checkCompletedAbnormally(f, success);
--- a/test/java/util/concurrent/tck/JSR166TestCase.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/JSR166TestCase.java	Fri Aug 19 12:17:32 2016 -0700
@@ -68,6 +68,7 @@
 import java.security.SecurityPermission;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -89,6 +90,7 @@
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -1278,7 +1280,7 @@
      * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
      */
     void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
-        long startTime = System.nanoTime();
+        long startTime = 0L;
         for (;;) {
             Thread.State s = thread.getState();
             if (s == Thread.State.BLOCKED ||
@@ -1287,6 +1289,8 @@
                 return;
             else if (s == Thread.State.TERMINATED)
                 fail("Unexpected thread termination");
+            else if (startTime == 0L)
+                startTime = System.nanoTime();
             else if (millisElapsedSince(startTime) > timeoutMillis) {
                 threadAssertTrue(thread.isAlive());
                 return;
@@ -1900,4 +1904,7 @@
                                1000L, MILLISECONDS,
                                new SynchronousQueue<Runnable>());
 
+    static <T> void shuffle(T[] array) {
+        Collections.shuffle(Arrays.asList(array), ThreadLocalRandom.current());
+    }
 }
--- a/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/LinkedBlockingDequeTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -792,7 +792,7 @@
             }});
 
         aboutToWait.await();
-        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
+        waitForThreadToEnterWaitState(t);
         t.interrupt();
         awaitTermination(t);
         checkEmpty(q);
--- a/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/LinkedBlockingQueueTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -481,7 +481,7 @@
             }});
 
         await(aboutToWait);
-        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
+        waitForThreadToEnterWaitState(t);
         t.interrupt();
         awaitTermination(t);
         checkEmpty(q);
--- a/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/PriorityBlockingQueueTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -437,7 +437,7 @@
             }});
 
         aboutToWait.await();
-        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
+        waitForThreadToEnterWaitState(t);
         t.interrupt();
         awaitTermination(t);
     }
--- a/test/java/util/concurrent/tck/StampedLockTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/java/util/concurrent/tck/StampedLockTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -34,10 +34,12 @@
 
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.StampedLock;
@@ -57,207 +59,188 @@
     }
 
     /**
-     * A runnable calling writeLockInterruptibly
+     * Releases write lock, checking isWriteLocked before and after
      */
-    class InterruptibleLockRunnable extends CheckedRunnable {
-        final StampedLock lock;
-        InterruptibleLockRunnable(StampedLock l) { lock = l; }
-        public void realRun() throws InterruptedException {
-            lock.writeLockInterruptibly();
-        }
+    void releaseWriteLock(StampedLock lock, long stamp) {
+        assertTrue(lock.isWriteLocked());
+        assertValid(lock, stamp);
+        lock.unlockWrite(stamp);
+        assertFalse(lock.isWriteLocked());
+        assertFalse(lock.validate(stamp));
     }
 
     /**
-     * A runnable calling writeLockInterruptibly that expects to be
-     * interrupted
+     * Releases read lock, checking isReadLocked before and after
      */
-    class InterruptedLockRunnable extends CheckedInterruptedRunnable {
-        final StampedLock lock;
-        InterruptedLockRunnable(StampedLock l) { lock = l; }
-        public void realRun() throws InterruptedException {
-            lock.writeLockInterruptibly();
-        }
+    void releaseReadLock(StampedLock lock, long stamp) {
+        assertTrue(lock.isReadLocked());
+        assertValid(lock, stamp);
+        lock.unlockRead(stamp);
+        assertFalse(lock.isReadLocked());
+        assertTrue(lock.validate(stamp));
     }
 
-    /**
-     * Releases write lock, checking isWriteLocked before and after
-     */
-    void releaseWriteLock(StampedLock lock, long s) {
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(s);
+    long assertNonZero(long v) {
+        assertTrue(v != 0L);
+        return v;
+    }
+
+    long assertValid(StampedLock lock, long stamp) {
+        assertTrue(stamp != 0L);
+        assertTrue(lock.validate(stamp));
+        return stamp;
+    }
+
+    void assertUnlocked(StampedLock lock) {
+        assertFalse(lock.isReadLocked());
         assertFalse(lock.isWriteLocked());
+        assertEquals(0, lock.getReadLockCount());
+        assertValid(lock, lock.tryOptimisticRead());
+    }
+
+    List<Action> lockLockers(Lock lock) {
+        List<Action> lockers = new ArrayList<>();
+        lockers.add(() -> lock.lock());
+        lockers.add(() -> lock.lockInterruptibly());
+        lockers.add(() -> lock.tryLock());
+        lockers.add(() -> lock.tryLock(Long.MIN_VALUE, DAYS));
+        lockers.add(() -> lock.tryLock(0L, DAYS));
+        lockers.add(() -> lock.tryLock(Long.MAX_VALUE, DAYS));
+        return lockers;
+    }
+
+    List<Function<StampedLock, Long>> readLockers() {
+        List<Function<StampedLock, Long>> readLockers = new ArrayList<>();
+        readLockers.add((sl) -> sl.readLock());
+        readLockers.add((sl) -> sl.tryReadLock());
+        readLockers.add((sl) -> readLockInterruptiblyUninterrupted(sl));
+        readLockers.add((sl) -> tryReadLockUninterrupted(sl, Long.MIN_VALUE, DAYS));
+        readLockers.add((sl) -> tryReadLockUninterrupted(sl, 0L, DAYS));
+        readLockers.add((sl) -> sl.tryConvertToReadLock(sl.tryOptimisticRead()));
+        return readLockers;
+    }
+
+    List<BiConsumer<StampedLock, Long>> readUnlockers() {
+        List<BiConsumer<StampedLock, Long>> readUnlockers = new ArrayList<>();
+        readUnlockers.add((sl, stamp) -> sl.unlockRead(stamp));
+        readUnlockers.add((sl, stamp) -> assertTrue(sl.tryUnlockRead()));
+        readUnlockers.add((sl, stamp) -> sl.asReadLock().unlock());
+        readUnlockers.add((sl, stamp) -> sl.unlock(stamp));
+        readUnlockers.add((sl, stamp) -> assertValid(sl, sl.tryConvertToOptimisticRead(stamp)));
+        return readUnlockers;
+    }
+
+    List<Function<StampedLock, Long>> writeLockers() {
+        List<Function<StampedLock, Long>> writeLockers = new ArrayList<>();
+        writeLockers.add((sl) -> sl.writeLock());
+        writeLockers.add((sl) -> sl.tryWriteLock());
+        writeLockers.add((sl) -> writeLockInterruptiblyUninterrupted(sl));
+        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS));
+        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, 0L, DAYS));
+        writeLockers.add((sl) -> sl.tryConvertToWriteLock(sl.tryOptimisticRead()));
+        return writeLockers;
+    }
+
+    List<BiConsumer<StampedLock, Long>> writeUnlockers() {
+        List<BiConsumer<StampedLock, Long>> writeUnlockers = new ArrayList<>();
+        writeUnlockers.add((sl, stamp) -> sl.unlockWrite(stamp));
+        writeUnlockers.add((sl, stamp) -> assertTrue(sl.tryUnlockWrite()));
+        writeUnlockers.add((sl, stamp) -> sl.asWriteLock().unlock());
+        writeUnlockers.add((sl, stamp) -> sl.unlock(stamp));
+        writeUnlockers.add((sl, stamp) -> assertValid(sl, sl.tryConvertToOptimisticRead(stamp)));
+        return writeUnlockers;
     }
 
     /**
      * Constructed StampedLock is in unlocked state
      */
     public void testConstructor() {
-        StampedLock lock;
-        lock = new StampedLock();
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
+        assertUnlocked(new StampedLock());
     }
 
     /**
-     * write-locking and read-locking an unlocked lock succeed
+     * write-locking, then unlocking, an unlocked lock succeed
      */
-    public void testLock() {
+    public void testWriteLock_lockUnlock() {
         StampedLock lock = new StampedLock();
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long s = lock.writeLock();
-        assertTrue(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        lock.unlockWrite(s);
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long rs = lock.readLock();
-        assertFalse(lock.isWriteLocked());
-        assertTrue(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 1);
-        lock.unlockRead(rs);
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
+
+        for (Function<StampedLock, Long> writeLocker : writeLockers())
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
+            assertFalse(lock.isWriteLocked());
+            assertFalse(lock.isReadLocked());
+            assertEquals(0, lock.getReadLockCount());
+
+            long s = writeLocker.apply(lock);
+            assertValid(lock, s);
+            assertTrue(lock.isWriteLocked());
+            assertFalse(lock.isReadLocked());
+            assertEquals(0, lock.getReadLockCount());
+            writeUnlocker.accept(lock, s);
+            assertUnlocked(lock);
+        }
     }
 
     /**
-     * unlock releases either a read or write lock
+     * read-locking, then unlocking, an unlocked lock succeed
      */
-    public void testUnlock() {
+    public void testReadLock_lockUnlock() {
         StampedLock lock = new StampedLock();
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long s = lock.writeLock();
-        assertTrue(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        lock.unlock(s);
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long rs = lock.readLock();
-        assertFalse(lock.isWriteLocked());
-        assertTrue(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 1);
-        lock.unlock(rs);
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
+
+        for (Function<StampedLock, Long> readLocker : readLockers())
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            long s = 42;
+            for (int i = 0; i < 2; i++) {
+                s = assertValid(lock, readLocker.apply(lock));
+                assertFalse(lock.isWriteLocked());
+                assertTrue(lock.isReadLocked());
+                assertEquals(i + 1, lock.getReadLockCount());
+            }
+            for (int i = 0; i < 2; i++) {
+                assertFalse(lock.isWriteLocked());
+                assertTrue(lock.isReadLocked());
+                assertEquals(2 - i, lock.getReadLockCount());
+                readUnlocker.accept(lock, s);
+            }
+            assertUnlocked(lock);
+        }
     }
 
     /**
-     * tryUnlockRead/Write succeeds if locked in associated mode else
-     * returns false
+     * tryUnlockWrite fails if not write locked
      */
-    public void testTryUnlock() {
+    public void testTryUnlockWrite_failure() {
         StampedLock lock = new StampedLock();
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long s = lock.writeLock();
-        assertTrue(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        assertFalse(lock.tryUnlockRead());
-        assertTrue(lock.tryUnlockWrite());
         assertFalse(lock.tryUnlockWrite());
-        assertFalse(lock.tryUnlockRead());
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
-        long rs = lock.readLock();
-        assertFalse(lock.isWriteLocked());
-        assertTrue(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 1);
-        assertFalse(lock.tryUnlockWrite());
-        assertTrue(lock.tryUnlockRead());
-        assertFalse(lock.tryUnlockRead());
-        assertFalse(lock.tryUnlockWrite());
-        assertFalse(lock.isWriteLocked());
-        assertFalse(lock.isReadLocked());
-        assertEquals(lock.getReadLockCount(), 0);
+
+        for (Function<StampedLock, Long> readLocker : readLockers())
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            long s = assertValid(lock, readLocker.apply(lock));
+            assertFalse(lock.tryUnlockWrite());
+            assertTrue(lock.isReadLocked());
+            readUnlocker.accept(lock, s);
+            assertUnlocked(lock);
+        }
     }
 
     /**
-     * write-unlocking an unlocked lock throws IllegalMonitorStateException
+     * tryUnlockRead fails if not read locked
      */
-    public void testWriteUnlock_IMSE() {
+    public void testTryUnlockRead_failure() {
         StampedLock lock = new StampedLock();
-        try {
-            lock.unlockWrite(0L);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
+        assertFalse(lock.tryUnlockRead());
+
+        for (Function<StampedLock, Long> writeLocker : writeLockers())
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
+            long s = writeLocker.apply(lock);
+            assertFalse(lock.tryUnlockRead());
+            assertTrue(lock.isWriteLocked());
+            writeUnlocker.accept(lock, s);
+            assertUnlocked(lock);
+        }
     }
 
     /**
-     * write-unlocking an unlocked lock throws IllegalMonitorStateException
-     */
-    public void testWriteUnlock_IMSE2() {
-        StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        lock.unlockWrite(s);
-        try {
-            lock.unlockWrite(s);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
-    }
-
-    /**
-     * write-unlocking after readlock throws IllegalMonitorStateException
-     */
-    public void testWriteUnlock_IMSE3() {
-        StampedLock lock = new StampedLock();
-        long s = lock.readLock();
-        try {
-            lock.unlockWrite(s);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
-    }
-
-    /**
-     * read-unlocking an unlocked lock throws IllegalMonitorStateException
-     */
-    public void testReadUnlock_IMSE() {
-        StampedLock lock = new StampedLock();
-        long s = lock.readLock();
-        lock.unlockRead(s);
-        try {
-            lock.unlockRead(s);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
-    }
-
-    /**
-     * read-unlocking an unlocked lock throws IllegalMonitorStateException
-     */
-    public void testReadUnlock_IMSE2() {
-        StampedLock lock = new StampedLock();
-        try {
-            lock.unlockRead(0L);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
-    }
-
-    /**
-     * read-unlocking after writeLock throws IllegalMonitorStateException
-     */
-    public void testReadUnlock_IMSE3() {
-        StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        try {
-            lock.unlockRead(s);
-            shouldThrow();
-        } catch (IllegalMonitorStateException success) {}
-    }
-
-    /**
-     * validate(0) fails
+     * validate(0L) fails
      */
     public void testValidate0() {
         StampedLock lock = new StampedLock();
@@ -265,29 +248,24 @@
     }
 
     /**
-     * A stamp obtained from a successful lock operation validates
+     * A stamp obtained from a successful lock operation validates while the lock is held
      */
     public void testValidate() throws InterruptedException {
         StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        assertTrue(lock.validate(s));
-        lock.unlockWrite(s);
-        s = lock.readLock();
-        assertTrue(lock.validate(s));
-        lock.unlockRead(s);
-        assertTrue((s = lock.tryWriteLock()) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockWrite(s);
-        assertTrue((s = lock.tryReadLock()) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockRead(s);
-        assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockWrite(s);
-        assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockRead(s);
-        assertTrue((s = lock.tryOptimisticRead()) != 0L);
+
+        for (Function<StampedLock, Long> readLocker : readLockers())
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            long s = assertNonZero(readLocker.apply(lock));
+            assertTrue(lock.validate(s));
+            readUnlocker.accept(lock, s);
+        }
+
+        for (Function<StampedLock, Long> writeLocker : writeLockers())
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
+            long s = assertNonZero(writeLocker.apply(lock));
+            assertTrue(lock.validate(s));
+            writeUnlocker.accept(lock, s);
+        }
     }
 
     /**
@@ -295,124 +273,190 @@
      */
     public void testValidate2() throws InterruptedException {
         StampedLock lock = new StampedLock();
-        long s;
-        assertTrue((s = lock.writeLock()) != 0L);
+        long s = assertNonZero(lock.writeLock());
         assertTrue(lock.validate(s));
         assertFalse(lock.validate(lock.tryWriteLock()));
-        assertFalse(lock.validate(lock.tryWriteLock(10L, MILLISECONDS)));
+        assertFalse(lock.validate(lock.tryWriteLock(0L, SECONDS)));
         assertFalse(lock.validate(lock.tryReadLock()));
-        assertFalse(lock.validate(lock.tryReadLock(10L, MILLISECONDS)));
+        assertFalse(lock.validate(lock.tryReadLock(0L, SECONDS)));
         assertFalse(lock.validate(lock.tryOptimisticRead()));
         lock.unlockWrite(s);
     }
 
+    void assertThrowInterruptedExceptionWhenPreInterrupted(Action[] actions) {
+        for (Action action : actions) {
+            Thread.currentThread().interrupt();
+            try {
+                action.run();
+                shouldThrow();
+            }
+            catch (InterruptedException success) {}
+            catch (Throwable fail) { threadUnexpectedException(fail); }
+            assertFalse(Thread.interrupted());
+        }
+    }
+
     /**
-     * writeLockInterruptibly is interruptible
+     * interruptible operations throw InterruptedException when pre-interrupted
      */
-    public void testWriteLockInterruptibly_Interruptible()
-            throws InterruptedException {
+    public void testInterruptibleOperationsThrowInterruptedExceptionWhenPreInterrupted() {
+        final CountDownLatch running = new CountDownLatch(1);
+        final StampedLock lock = new StampedLock();
+
+        Action[] interruptibleLockActions = {
+            () -> lock.writeLockInterruptibly(),
+            () -> lock.tryWriteLock(Long.MIN_VALUE, DAYS),
+            () -> lock.tryWriteLock(Long.MAX_VALUE, DAYS),
+            () -> lock.readLockInterruptibly(),
+            () -> lock.tryReadLock(Long.MIN_VALUE, DAYS),
+            () -> lock.tryReadLock(Long.MAX_VALUE, DAYS),
+            () -> lock.asWriteLock().lockInterruptibly(),
+            () -> lock.asWriteLock().tryLock(0L, DAYS),
+            () -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS),
+            () -> lock.asReadLock().lockInterruptibly(),
+            () -> lock.asReadLock().tryLock(0L, DAYS),
+            () -> lock.asReadLock().tryLock(Long.MAX_VALUE, DAYS),
+        };
+        shuffle(interruptibleLockActions);
+
+        assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions);
+        {
+            long s = lock.writeLock();
+            assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions);
+            lock.unlockWrite(s);
+        }
+        {
+            long s = lock.readLock();
+            assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions);
+            lock.unlockRead(s);
+        }
+    }
+
+    void assertThrowInterruptedExceptionWhenInterrupted(Action[] actions) {
+        int n = actions.length;
+        Future<?>[] futures = new Future<?>[n];
+        CountDownLatch threadsStarted = new CountDownLatch(n);
+        CountDownLatch done = new CountDownLatch(n);
+
+        for (int i = 0; i < n; i++) {
+            Action action = actions[i];
+            futures[i] = cachedThreadPool.submit(new CheckedRunnable() {
+                public void realRun() throws Throwable {
+                    threadsStarted.countDown();
+                    try {
+                        action.run();
+                        shouldThrow();
+                    }
+                    catch (InterruptedException success) {}
+                    catch (Throwable fail) { threadUnexpectedException(fail); }
+                    assertFalse(Thread.interrupted());
+                    done.countDown();
+                }});
+        }
+
+        await(threadsStarted);
+        assertEquals(n, done.getCount());
+        for (Future<?> future : futures) // Interrupt all the tasks
+            future.cancel(true);
+        await(done);
+    }
+
+    /**
+     * interruptible operations throw InterruptedException when write locked and interrupted
+     */
+    public void testInterruptibleOperationsThrowInterruptedExceptionWriteLockedInterrupted() {
         final CountDownLatch running = new CountDownLatch(1);
         final StampedLock lock = new StampedLock();
         long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.writeLockInterruptibly();
-            }});
 
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
+        Action[] interruptibleLockBlockingActions = {
+            () -> lock.writeLockInterruptibly(),
+            () -> lock.tryWriteLock(Long.MAX_VALUE, DAYS),
+            () -> lock.readLockInterruptibly(),
+            () -> lock.tryReadLock(Long.MAX_VALUE, DAYS),
+            () -> lock.asWriteLock().lockInterruptibly(),
+            () -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS),
+            () -> lock.asReadLock().lockInterruptibly(),
+            () -> lock.asReadLock().tryLock(Long.MAX_VALUE, DAYS),
+        };
+        shuffle(interruptibleLockBlockingActions);
+
+        assertThrowInterruptedExceptionWhenInterrupted(interruptibleLockBlockingActions);
     }
 
     /**
-     * timed tryWriteLock is interruptible
+     * interruptible operations throw InterruptedException when read locked and interrupted
      */
-    public void testWriteTryLock_Interruptible() throws InterruptedException {
+    public void testInterruptibleOperationsThrowInterruptedExceptionReadLockedInterrupted() {
         final CountDownLatch running = new CountDownLatch(1);
         final StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.tryWriteLock(2 * LONG_DELAY_MS, MILLISECONDS);
-            }});
+        long s = lock.readLock();
 
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
+        Action[] interruptibleLockBlockingActions = {
+            () -> lock.writeLockInterruptibly(),
+            () -> lock.tryWriteLock(Long.MAX_VALUE, DAYS),
+            () -> lock.asWriteLock().lockInterruptibly(),
+            () -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS),
+        };
+        shuffle(interruptibleLockBlockingActions);
+
+        assertThrowInterruptedExceptionWhenInterrupted(interruptibleLockBlockingActions);
     }
 
     /**
-     * readLockInterruptibly is interruptible
+     * Non-interruptible operations ignore and preserve interrupt status
      */
-    public void testReadLockInterruptibly_Interruptible()
-            throws InterruptedException {
-        final CountDownLatch running = new CountDownLatch(1);
+    public void testNonInterruptibleOperationsIgnoreInterrupts() {
         final StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.readLockInterruptibly();
-            }});
+        Thread.currentThread().interrupt();
 
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
-    }
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            long s = assertValid(lock, lock.readLock());
+            readUnlocker.accept(lock, s);
+            s = assertValid(lock, lock.tryReadLock());
+            readUnlocker.accept(lock, s);
+        }
 
-    /**
-     * timed tryReadLock is interruptible
-     */
-    public void testReadTryLock_Interruptible() throws InterruptedException {
-        final CountDownLatch running = new CountDownLatch(1);
-        final StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.tryReadLock(2 * LONG_DELAY_MS, MILLISECONDS);
-            }});
+        lock.asReadLock().lock();
+        lock.asReadLock().unlock();
 
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
+            long s = assertValid(lock, lock.writeLock());
+            writeUnlocker.accept(lock, s);
+            s = assertValid(lock, lock.tryWriteLock());
+            writeUnlocker.accept(lock, s);
+        }
+
+        lock.asWriteLock().lock();
+        lock.asWriteLock().unlock();
+
+        assertTrue(Thread.interrupted());
     }
 
     /**
      * tryWriteLock on an unlocked lock succeeds
      */
-    public void testWriteTryLock() {
+    public void testTryWriteLock() {
         final StampedLock lock = new StampedLock();
         long s = lock.tryWriteLock();
         assertTrue(s != 0L);
         assertTrue(lock.isWriteLocked());
-        long s2 = lock.tryWriteLock();
-        assertEquals(s2, 0L);
+        assertEquals(0L, lock.tryWriteLock());
         releaseWriteLock(lock, s);
     }
 
     /**
      * tryWriteLock fails if locked
      */
-    public void testWriteTryLockWhenLocked() {
+    public void testTryWriteLockWhenLocked() {
         final StampedLock lock = new StampedLock();
         long s = lock.writeLock();
         Thread t = newStartedThread(new CheckedRunnable() {
             public void realRun() {
-                long ws = lock.tryWriteLock();
-                assertTrue(ws == 0L);
+                assertEquals(0L, lock.tryWriteLock());
             }});
 
+        assertEquals(0L, lock.tryWriteLock());
         awaitTermination(t);
         releaseWriteLock(lock, s);
     }
@@ -420,15 +464,15 @@
     /**
      * tryReadLock fails if write-locked
      */
-    public void testReadTryLockWhenLocked() {
+    public void testTryReadLockWhenLocked() {
         final StampedLock lock = new StampedLock();
         long s = lock.writeLock();
         Thread t = newStartedThread(new CheckedRunnable() {
             public void realRun() {
-                long rs = lock.tryReadLock();
-                assertEquals(rs, 0L);
+                assertEquals(0L, lock.tryReadLock());
             }});
 
+        assertEquals(0L, lock.tryReadLock());
         awaitTermination(t);
         releaseWriteLock(lock, s);
     }
@@ -442,13 +486,20 @@
         Thread t = newStartedThread(new CheckedRunnable() {
             public void realRun() throws InterruptedException {
                 long s2 = lock.tryReadLock();
-                assertTrue(s2 != 0L);
+                assertValid(lock, s2);
                 lock.unlockRead(s2);
                 long s3 = lock.tryReadLock(LONG_DELAY_MS, MILLISECONDS);
-                assertTrue(s3 != 0L);
+                assertValid(lock, s3);
                 lock.unlockRead(s3);
                 long s4 = lock.readLock();
+                assertValid(lock, s4);
                 lock.unlockRead(s4);
+                lock.asReadLock().lock();
+                lock.asReadLock().unlock();
+                lock.asReadLock().lockInterruptibly();
+                lock.asReadLock().unlock();
+                lock.asReadLock().tryLock(Long.MIN_VALUE, DAYS);
+                lock.asReadLock().unlock();
             }});
 
         awaitTermination(t);
@@ -470,7 +521,7 @@
             }});
 
         running.await();
-        waitForThreadToEnterWaitState(t, 100);
+        waitForThreadToEnterWaitState(t, MEDIUM_DELAY_MS);
         assertFalse(lock.isWriteLocked());
         lock.unlockRead(rs);
         awaitTermination(t);
@@ -497,6 +548,7 @@
                 lock.unlockWrite(ws);
             }});
 
+        assertTrue(lock.isReadLocked());
         assertFalse(lock.isWriteLocked());
         lock.unlockRead(s);
         awaitTermination(t2);
@@ -508,25 +560,31 @@
      */
     public void testReadAfterWriteLock() {
         final StampedLock lock = new StampedLock();
+        final CountDownLatch threadsStarted = new CountDownLatch(2);
         final long s = lock.writeLock();
         Thread t1 = newStartedThread(new CheckedRunnable() {
             public void realRun() {
+                threadsStarted.countDown();
                 long rs = lock.readLock();
                 lock.unlockRead(rs);
             }});
         Thread t2 = newStartedThread(new CheckedRunnable() {
             public void realRun() {
+                threadsStarted.countDown();
                 long rs = lock.readLock();
                 lock.unlockRead(rs);
             }});
 
+        await(threadsStarted);
+        waitForThreadToEnterWaitState(t1, MEDIUM_DELAY_MS);
+        waitForThreadToEnterWaitState(t2, MEDIUM_DELAY_MS);
         releaseWriteLock(lock, s);
         awaitTermination(t1);
         awaitTermination(t2);
     }
 
     /**
-     * tryReadLock succeeds if readlocked but not writelocked
+     * tryReadLock succeeds if read locked but not write locked
      */
     public void testTryLockWhenReadLocked() {
         final StampedLock lock = new StampedLock();
@@ -534,7 +592,7 @@
         Thread t = newStartedThread(new CheckedRunnable() {
             public void realRun() {
                 long rs = lock.tryReadLock();
-                threadAssertTrue(rs != 0L);
+                assertValid(lock, rs);
                 lock.unlockRead(rs);
             }});
 
@@ -543,15 +601,14 @@
     }
 
     /**
-     * tryWriteLock fails when readlocked
+     * tryWriteLock fails when read locked
      */
-    public void testWriteTryLockWhenReadLocked() {
+    public void testTryWriteLockWhenReadLocked() {
         final StampedLock lock = new StampedLock();
         long s = lock.readLock();
         Thread t = newStartedThread(new CheckedRunnable() {
             public void realRun() {
-                long ws = lock.tryWriteLock();
-                threadAssertEquals(ws, 0L);
+                threadAssertEquals(0L, lock.tryWriteLock());
             }});
 
         awaitTermination(t);
@@ -559,86 +616,82 @@
     }
 
     /**
-     * timed tryWriteLock times out if locked
+     * timed lock operations time out if lock not available
      */
-    public void testWriteTryLock_Timeout() {
+    public void testTimedLock_Timeout() throws Exception {
+        ArrayList<Future<?>> futures = new ArrayList<>();
+
+        // Write locked
         final StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedRunnable() {
+        long stamp = lock.writeLock();
+        assertEquals(0L, lock.tryReadLock(0L, DAYS));
+        assertEquals(0L, lock.tryReadLock(Long.MIN_VALUE, DAYS));
+        assertFalse(lock.asReadLock().tryLock(0L, DAYS));
+        assertFalse(lock.asReadLock().tryLock(Long.MIN_VALUE, DAYS));
+        assertEquals(0L, lock.tryWriteLock(0L, DAYS));
+        assertEquals(0L, lock.tryWriteLock(Long.MIN_VALUE, DAYS));
+        assertFalse(lock.asWriteLock().tryLock(0L, DAYS));
+        assertFalse(lock.asWriteLock().tryLock(Long.MIN_VALUE, DAYS));
+
+        futures.add(cachedThreadPool.submit(new CheckedRunnable() {
             public void realRun() throws InterruptedException {
                 long startTime = System.nanoTime();
-                long timeoutMillis = 10;
-                long ws = lock.tryWriteLock(timeoutMillis, MILLISECONDS);
-                assertEquals(ws, 0L);
-                assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
-            }});
+                assertEquals(0L, lock.tryWriteLock(timeoutMillis(), MILLISECONDS));
+                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
+            }}));
 
-        awaitTermination(t);
+        futures.add(cachedThreadPool.submit(new CheckedRunnable() {
+            public void realRun() throws InterruptedException {
+                long startTime = System.nanoTime();
+                assertEquals(0L, lock.tryReadLock(timeoutMillis(), MILLISECONDS));
+                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
+            }}));
+
+        // Read locked
+        final StampedLock lock2 = new StampedLock();
+        long stamp2 = lock2.readLock();
+        assertEquals(0L, lock2.tryWriteLock(0L, DAYS));
+        assertEquals(0L, lock2.tryWriteLock(Long.MIN_VALUE, DAYS));
+        assertFalse(lock2.asWriteLock().tryLock(0L, DAYS));
+        assertFalse(lock2.asWriteLock().tryLock(Long.MIN_VALUE, DAYS));
+
+        futures.add(cachedThreadPool.submit(new CheckedRunnable() {
+            public void realRun() throws InterruptedException {
+                long startTime = System.nanoTime();
+                assertEquals(0L, lock2.tryWriteLock(timeoutMillis(), MILLISECONDS));
+                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
+            }}));
+
+        for (Future<?> future : futures)
+            assertNull(future.get());
+
+        releaseWriteLock(lock, stamp);
+        releaseReadLock(lock2, stamp2);
+    }
+
+    /**
+     * writeLockInterruptibly succeeds if unlocked
+     */
+    public void testWriteLockInterruptibly() throws InterruptedException {
+        final StampedLock lock = new StampedLock();
+        long s = lock.writeLockInterruptibly();
+        assertTrue(lock.isWriteLocked());
         releaseWriteLock(lock, s);
     }
 
     /**
-     * timed tryReadLock times out if write-locked
-     */
-    public void testReadTryLock_Timeout() {
-        final StampedLock lock = new StampedLock();
-        long s = lock.writeLock();
-        Thread t = newStartedThread(new CheckedRunnable() {
-            public void realRun() throws InterruptedException {
-                long startTime = System.nanoTime();
-                long timeoutMillis = 10;
-                long rs = lock.tryReadLock(timeoutMillis, MILLISECONDS);
-                assertEquals(rs, 0L);
-                assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
-            }});
-
-        awaitTermination(t);
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(s);
-    }
-
-    /**
-     * writeLockInterruptibly succeeds if unlocked, else is interruptible
-     */
-    public void testWriteLockInterruptibly() throws InterruptedException {
-        final CountDownLatch running = new CountDownLatch(1);
-        final StampedLock lock = new StampedLock();
-        long s = lock.writeLockInterruptibly();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.writeLockInterruptibly();
-            }});
-
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        assertTrue(lock.isWriteLocked());
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
-    }
-
-    /**
-     * readLockInterruptibly succeeds if lock free else is interruptible
+     * readLockInterruptibly succeeds if lock free
      */
     public void testReadLockInterruptibly() throws InterruptedException {
-        final CountDownLatch running = new CountDownLatch(1);
         final StampedLock lock = new StampedLock();
-        long s;
-        s = lock.readLockInterruptibly();
+
+        long s = assertValid(lock, lock.readLockInterruptibly());
+        assertTrue(lock.isReadLocked());
         lock.unlockRead(s);
-        s = lock.writeLockInterruptibly();
-        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
-            public void realRun() throws InterruptedException {
-                running.countDown();
-                lock.readLockInterruptibly();
-            }});
 
-        running.await();
-        waitForThreadToEnterWaitState(t, 100);
-        t.interrupt();
-        awaitTermination(t);
-        releaseWriteLock(lock, s);
+        lock.asReadLock().lockInterruptibly();
+        assertTrue(lock.isReadLocked());
+        lock.asReadLock().unlock();
     }
 
     /**
@@ -670,54 +723,39 @@
     }
 
     /**
-     * tryOptimisticRead succeeds and validates if unlocked, fails if locked
+     * tryOptimisticRead succeeds and validates if unlocked, fails if
+     * exclusively locked
      */
     public void testValidateOptimistic() throws InterruptedException {
         StampedLock lock = new StampedLock();
-        long s, p;
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue((s = lock.writeLock()) != 0L);
-        assertFalse((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockWrite(s);
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue((s = lock.readLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue(lock.validate(p));
-        lock.unlockRead(s);
-        assertTrue((s = lock.tryWriteLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertFalse((p = lock.tryOptimisticRead()) != 0L);
-        lock.unlockWrite(s);
-        assertTrue((s = lock.tryReadLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        lock.unlockRead(s);
-        assertTrue(lock.validate(p));
-        assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
-        assertFalse((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue(lock.validate(s));
-        lock.unlockWrite(s);
-        assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        lock.unlockRead(s);
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
+
+        assertValid(lock, lock.tryOptimisticRead());
+
+        for (Function<StampedLock, Long> writeLocker : writeLockers()) {
+            long s = assertValid(lock, writeLocker.apply(lock));
+            assertEquals(0L, lock.tryOptimisticRead());
+            releaseWriteLock(lock, s);
+        }
+
+        for (Function<StampedLock, Long> readLocker : readLockers()) {
+            long s = assertValid(lock, readLocker.apply(lock));
+            long p = assertValid(lock, lock.tryOptimisticRead());
+            releaseReadLock(lock, s);
+            assertTrue(lock.validate(p));
+        }
+
+        assertValid(lock, lock.tryOptimisticRead());
     }
 
     /**
      * tryOptimisticRead stamp does not validate if a write lock intervenes
      */
     public void testValidateOptimisticWriteLocked() {
-        StampedLock lock = new StampedLock();
-        long s, p;
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
-        assertTrue((s = lock.writeLock()) != 0L);
+        final StampedLock lock = new StampedLock();
+        final long p = assertValid(lock, lock.tryOptimisticRead());
+        final long s = assertValid(lock, lock.writeLock());
         assertFalse(lock.validate(p));
-        assertFalse((p = lock.tryOptimisticRead()) != 0L);
+        assertEquals(0L, lock.tryOptimisticRead());
         assertTrue(lock.validate(s));
         lock.unlockWrite(s);
     }
@@ -730,8 +768,8 @@
             throws InterruptedException {
         final CountDownLatch running = new CountDownLatch(1);
         final StampedLock lock = new StampedLock();
-        long s, p;
-        assertTrue((p = lock.tryOptimisticRead()) != 0L);
+        final long p = assertValid(lock, lock.tryOptimisticRead());
+
         Thread t = newStartedThread(new CheckedInterruptedRunnable() {
             public void realRun() throws InterruptedException {
                 lock.writeLockInterruptibly();
@@ -741,228 +779,209 @@
 
         running.await();
         assertFalse(lock.validate(p));
-        assertFalse((p = lock.tryOptimisticRead()) != 0L);
+        assertEquals(0L, lock.tryOptimisticRead());
         t.interrupt();
         awaitTermination(t);
     }
 
     /**
-     * tryConvertToOptimisticRead succeeds and validates if successfully locked,
+     * tryConvertToOptimisticRead succeeds and validates if successfully locked
      */
     public void testTryConvertToOptimisticRead() throws InterruptedException {
         StampedLock lock = new StampedLock();
-        long s, p;
+        long s, p, q;
         assertEquals(0L, lock.tryConvertToOptimisticRead(0L));
 
-        assertTrue((s = lock.tryOptimisticRead()) != 0L);
+        s = assertValid(lock, lock.tryOptimisticRead());
         assertEquals(s, lock.tryConvertToOptimisticRead(s));
         assertTrue(lock.validate(s));
 
-        assertTrue((p = lock.readLock()) != 0L);
-        assertTrue((s = lock.tryOptimisticRead()) != 0L);
-        assertEquals(s, lock.tryConvertToOptimisticRead(s));
-        assertTrue(lock.validate(s));
-        lock.unlockRead(p);
+        for (Function<StampedLock, Long> writeLocker : writeLockers()) {
+            s = assertValid(lock, writeLocker.apply(lock));
+            p = assertValid(lock, lock.tryConvertToOptimisticRead(s));
+            assertFalse(lock.validate(s));
+            assertTrue(lock.validate(p));
+            assertUnlocked(lock);
+        }
 
-        assertTrue((s = lock.writeLock()) != 0L);
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
-
-        assertTrue((s = lock.readLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
-
-        assertTrue((s = lock.tryWriteLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
-
-        assertTrue((s = lock.tryReadLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
-
-        assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
-
-        assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToOptimisticRead(s)) != 0L);
-        assertTrue(lock.validate(p));
+        for (Function<StampedLock, Long> readLocker : readLockers()) {
+            s = assertValid(lock, readLocker.apply(lock));
+            q = assertValid(lock, lock.tryOptimisticRead());
+            assertEquals(q, lock.tryConvertToOptimisticRead(q));
+            assertTrue(lock.validate(q));
+            assertTrue(lock.isReadLocked());
+            p = assertValid(lock, lock.tryConvertToOptimisticRead(s));
+            assertTrue(lock.validate(p));
+            assertTrue(lock.validate(s));
+            assertUnlocked(lock);
+            assertEquals(q, lock.tryConvertToOptimisticRead(q));
+            assertTrue(lock.validate(q));
+        }
     }
 
     /**
-     * tryConvertToReadLock succeeds and validates if successfully locked
-     * or lock free;
+     * tryConvertToReadLock succeeds for valid stamps
      */
     public void testTryConvertToReadLock() throws InterruptedException {
         StampedLock lock = new StampedLock();
         long s, p;
 
-        assertFalse((p = lock.tryConvertToReadLock(0L)) != 0L);
+        assertEquals(0L, lock.tryConvertToReadLock(0L));
 
-        assertTrue((s = lock.tryOptimisticRead()) != 0L);
-        assertTrue((p = lock.tryConvertToReadLock(s)) != 0L);
+        s = assertValid(lock, lock.tryOptimisticRead());
+        p = assertValid(lock, lock.tryConvertToReadLock(s));
         assertTrue(lock.isReadLocked());
         assertEquals(1, lock.getReadLockCount());
+        assertTrue(lock.validate(s));
         lock.unlockRead(p);
 
-        assertTrue((s = lock.tryOptimisticRead()) != 0L);
+        s = assertValid(lock, lock.tryOptimisticRead());
         lock.readLock();
-        assertTrue((p = lock.tryConvertToReadLock(s)) != 0L);
+        p = assertValid(lock, lock.tryConvertToReadLock(s));
         assertTrue(lock.isReadLocked());
         assertEquals(2, lock.getReadLockCount());
         lock.unlockRead(p);
         lock.unlockRead(p);
+        assertUnlocked(lock);
 
-        assertTrue((s = lock.writeLock()) != 0L);
-        assertTrue((p = lock.tryConvertToReadLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isReadLocked());
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(p);
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            for (Function<StampedLock, Long> writeLocker : writeLockers()) {
+                s = assertValid(lock, writeLocker.apply(lock));
+                p = assertValid(lock, lock.tryConvertToReadLock(s));
+                assertFalse(lock.validate(s));
+                assertTrue(lock.isReadLocked());
+                assertEquals(1, lock.getReadLockCount());
+                readUnlocker.accept(lock, p);
+            }
 
-        assertTrue((s = lock.readLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertEquals(s, lock.tryConvertToReadLock(s));
-        assertTrue(lock.validate(s));
-        assertTrue(lock.isReadLocked());
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(s);
-
-        assertTrue((s = lock.tryWriteLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToReadLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(p);
-
-        assertTrue((s = lock.tryReadLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertEquals(s, lock.tryConvertToReadLock(s));
-        assertTrue(lock.validate(s));
-        assertTrue(lock.isReadLocked());
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(s);
-
-        assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
-        assertTrue((p = lock.tryConvertToReadLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isReadLocked());
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(p);
-
-        assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        assertEquals(s, lock.tryConvertToReadLock(s));
-        assertTrue(lock.validate(s));
-        assertTrue(lock.isReadLocked());
-        assertEquals(1, lock.getReadLockCount());
-        lock.unlockRead(s);
+            for (Function<StampedLock, Long> readLocker : readLockers()) {
+                s = assertValid(lock, readLocker.apply(lock));
+                assertEquals(s, lock.tryConvertToReadLock(s));
+                assertTrue(lock.validate(s));
+                assertTrue(lock.isReadLocked());
+                assertEquals(1, lock.getReadLockCount());
+                readUnlocker.accept(lock, s);
+            }
+        }
     }
 
     /**
-     * tryConvertToWriteLock succeeds and validates if successfully locked
-     * or lock free;
+     * tryConvertToWriteLock succeeds if lock available; fails if multiply read locked
      */
     public void testTryConvertToWriteLock() throws InterruptedException {
         StampedLock lock = new StampedLock();
         long s, p;
 
-        assertFalse((p = lock.tryConvertToWriteLock(0L)) != 0L);
+        assertEquals(0L, lock.tryConvertToWriteLock(0L));
 
         assertTrue((s = lock.tryOptimisticRead()) != 0L);
         assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L);
         assertTrue(lock.isWriteLocked());
         lock.unlockWrite(p);
 
-        assertTrue((s = lock.writeLock()) != 0L);
-        assertEquals(s, lock.tryConvertToWriteLock(s));
-        assertTrue(lock.validate(s));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(s);
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
+            for (Function<StampedLock, Long> writeLocker : writeLockers()) {
+                s = assertValid(lock, writeLocker.apply(lock));
+                assertEquals(s, lock.tryConvertToWriteLock(s));
+                assertTrue(lock.validate(s));
+                assertTrue(lock.isWriteLocked());
+                writeUnlocker.accept(lock, s);
+            }
 
-        assertTrue((s = lock.readLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(p);
+            for (Function<StampedLock, Long> readLocker : readLockers()) {
+                s = assertValid(lock, readLocker.apply(lock));
+                p = assertValid(lock, lock.tryConvertToWriteLock(s));
+                assertFalse(lock.validate(s));
+                assertTrue(lock.validate(p));
+                assertTrue(lock.isWriteLocked());
+                writeUnlocker.accept(lock, p);
+            }
+        }
 
-        assertTrue((s = lock.tryWriteLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertEquals(s, lock.tryConvertToWriteLock(s));
-        assertTrue(lock.validate(s));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(s);
-
-        assertTrue((s = lock.tryReadLock()) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(p);
-
-        assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
-        assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(p);
-
-        assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
-        assertTrue(lock.validate(s));
-        assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L);
-        assertTrue(lock.validate(p));
-        assertTrue(lock.isWriteLocked());
-        lock.unlockWrite(p);
+        // failure if multiply read locked
+        for (Function<StampedLock, Long> readLocker : readLockers()) {
+            s = assertValid(lock, readLocker.apply(lock));
+            p = assertValid(lock, readLocker.apply(lock));
+            assertEquals(0L, lock.tryConvertToWriteLock(s));
+            assertTrue(lock.validate(s));
+            assertTrue(lock.validate(p));
+            assertEquals(2, lock.getReadLockCount());
+            lock.unlock(p);
+            lock.unlock(s);
+            assertUnlocked(lock);
+        }
     }
 
     /**
      * asWriteLock can be locked and unlocked
      */
-    public void testAsWriteLock() {
+    public void testAsWriteLock() throws Throwable {
         StampedLock sl = new StampedLock();
         Lock lock = sl.asWriteLock();
-        lock.lock();
-        assertFalse(lock.tryLock());
-        lock.unlock();
-        assertTrue(lock.tryLock());
+        for (Action locker : lockLockers(lock)) {
+            locker.run();
+            assertTrue(sl.isWriteLocked());
+            assertFalse(sl.isReadLocked());
+            assertFalse(lock.tryLock());
+            lock.unlock();
+            assertUnlocked(sl);
+        }
     }
 
     /**
      * asReadLock can be locked and unlocked
      */
-    public void testAsReadLock() {
+    public void testAsReadLock() throws Throwable {
         StampedLock sl = new StampedLock();
         Lock lock = sl.asReadLock();
-        lock.lock();
-        lock.unlock();
-        assertTrue(lock.tryLock());
+        for (Action locker : lockLockers(lock)) {
+            locker.run();
+            assertTrue(sl.isReadLocked());
+            assertFalse(sl.isWriteLocked());
+            assertEquals(1, sl.getReadLockCount());
+            locker.run();
+            assertTrue(sl.isReadLocked());
+            assertEquals(2, sl.getReadLockCount());
+            lock.unlock();
+            lock.unlock();
+            assertUnlocked(sl);
+        }
     }
 
     /**
      * asReadWriteLock.writeLock can be locked and unlocked
      */
-    public void testAsReadWriteLockWriteLock() {
+    public void testAsReadWriteLockWriteLock() throws Throwable {
         StampedLock sl = new StampedLock();
         Lock lock = sl.asReadWriteLock().writeLock();
-        lock.lock();
-        assertFalse(lock.tryLock());
-        lock.unlock();
-        assertTrue(lock.tryLock());
+        for (Action locker : lockLockers(lock)) {
+            locker.run();
+            assertTrue(sl.isWriteLocked());
+            assertFalse(sl.isReadLocked());
+            assertFalse(lock.tryLock());
+            lock.unlock();
+            assertUnlocked(sl);
+        }
     }
 
     /**
      * asReadWriteLock.readLock can be locked and unlocked
      */
-    public void testAsReadWriteLockReadLock() {
+    public void testAsReadWriteLockReadLock() throws Throwable {
         StampedLock sl = new StampedLock();
         Lock lock = sl.asReadWriteLock().readLock();
-        lock.lock();
-        lock.unlock();
-        assertTrue(lock.tryLock());
+        for (Action locker : lockLockers(lock)) {
+            locker.run();
+            assertTrue(sl.isReadLocked());
+            assertFalse(sl.isWriteLocked());
+            assertEquals(1, sl.getReadLockCount());
+            locker.run();
+            assertTrue(sl.isReadLocked());
+            assertEquals(2, sl.getReadLockCount());
+            lock.unlock();
+            lock.unlock();
+            assertUnlocked(sl);
+        }
     }
 
     /**
@@ -985,8 +1004,7 @@
         Runnable[] actions = {
             () -> {
                 StampedLock sl = new StampedLock();
-                long stamp = sl.tryOptimisticRead();
-                assertTrue(stamp != 0);
+                long stamp = assertValid(sl, sl.tryOptimisticRead());
                 sl.unlockRead(stamp);
             },
             () -> {
@@ -1003,21 +1021,21 @@
             },
             () -> {
                 StampedLock sl = new StampedLock();
-                long stamp = sl.tryOptimisticRead();
                 sl.readLock();
+                long stamp = assertValid(sl, sl.tryOptimisticRead());
                 sl.unlockRead(stamp);
             },
             () -> {
                 StampedLock sl = new StampedLock();
-                long stamp = sl.tryOptimisticRead();
                 sl.readLock();
+                long stamp = assertValid(sl, sl.tryOptimisticRead());
                 sl.unlock(stamp);
             },
 
             () -> {
                 StampedLock sl = new StampedLock();
                 long stamp = sl.tryConvertToOptimisticRead(sl.writeLock());
-                assertTrue(stamp != 0);
+                assertValid(sl, stamp);
                 sl.writeLock();
                 sl.unlockWrite(stamp);
             },
@@ -1043,7 +1061,7 @@
             () -> {
                 StampedLock sl = new StampedLock();
                 long stamp = sl.tryConvertToOptimisticRead(sl.readLock());
-                assertTrue(stamp != 0);
+                assertValid(sl, stamp);
                 sl.writeLock();
                 sl.unlockWrite(stamp);
             },
@@ -1063,7 +1081,7 @@
                 StampedLock sl = new StampedLock();
                 sl.readLock();
                 long stamp = sl.tryConvertToOptimisticRead(sl.readLock());
-                assertTrue(stamp != 0);
+                assertValid(sl, stamp);
                 sl.readLock();
                 sl.unlockRead(stamp);
             },
@@ -1106,100 +1124,84 @@
     }
 
     /**
-     * Invalid write stamps result in IllegalMonitorStateException
+     * Invalid stamps result in IllegalMonitorStateException
      */
-    public void testInvalidWriteStampsThrowIllegalMonitorStateException() {
-        List<Function<StampedLock, Long>> writeLockers = new ArrayList<>();
-        writeLockers.add((sl) -> sl.writeLock());
-        writeLockers.add((sl) -> writeLockInterruptiblyUninterrupted(sl));
-        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS));
-        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, 0, DAYS));
+    public void testInvalidStampsThrowIllegalMonitorStateException() {
+        final StampedLock sl = new StampedLock();
 
-        List<BiConsumer<StampedLock, Long>> writeUnlockers = new ArrayList<>();
-        writeUnlockers.add((sl, stamp) -> sl.unlockWrite(stamp));
-        writeUnlockers.add((sl, stamp) -> assertTrue(sl.tryUnlockWrite()));
-        writeUnlockers.add((sl, stamp) -> sl.asWriteLock().unlock());
-        writeUnlockers.add((sl, stamp) -> sl.unlock(stamp));
+        assertThrows(IllegalMonitorStateException.class,
+                     () -> sl.unlockWrite(0L),
+                     () -> sl.unlockRead(0L),
+                     () -> sl.unlock(0L));
 
-        List<Consumer<StampedLock>> mutaters = new ArrayList<>();
-        mutaters.add((sl) -> {});
-        mutaters.add((sl) -> sl.readLock());
-        for (Function<StampedLock, Long> writeLocker : writeLockers)
-            mutaters.add((sl) -> writeLocker.apply(sl));
+        final long optimisticStamp = sl.tryOptimisticRead();
+        final long readStamp = sl.readLock();
+        sl.unlockRead(readStamp);
+        final long writeStamp = sl.writeLock();
+        sl.unlockWrite(writeStamp);
+        assertTrue(optimisticStamp != 0L && readStamp != 0L && writeStamp != 0L);
+        final long[] noLongerValidStamps = { optimisticStamp, readStamp, writeStamp };
+        final Runnable assertNoLongerValidStampsThrow = () -> {
+            for (long noLongerValidStamp : noLongerValidStamps)
+                assertThrows(IllegalMonitorStateException.class,
+                             () -> sl.unlockWrite(noLongerValidStamp),
+                             () -> sl.unlockRead(noLongerValidStamp),
+                             () -> sl.unlock(noLongerValidStamp));
+        };
+        assertNoLongerValidStampsThrow.run();
 
-        for (Function<StampedLock, Long> writeLocker : writeLockers)
-        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers)
-        for (Consumer<StampedLock> mutater : mutaters) {
-            final StampedLock sl = new StampedLock();
+        for (Function<StampedLock, Long> readLocker : readLockers())
+        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
+            final long stamp = readLocker.apply(sl);
+            assertValid(sl, stamp);
+            assertNoLongerValidStampsThrow.run();
+            assertThrows(IllegalMonitorStateException.class,
+                         () -> sl.unlockWrite(stamp),
+                         () -> sl.unlockRead(sl.tryOptimisticRead()),
+                         () -> sl.unlockRead(0L));
+            readUnlocker.accept(sl, stamp);
+            assertUnlocked(sl);
+            assertNoLongerValidStampsThrow.run();
+        }
+
+        for (Function<StampedLock, Long> writeLocker : writeLockers())
+        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
             final long stamp = writeLocker.apply(sl);
-            assertTrue(stamp != 0L);
+            assertValid(sl, stamp);
+            assertNoLongerValidStampsThrow.run();
             assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlockRead(stamp));
+                         () -> sl.unlockRead(stamp),
+                         () -> sl.unlockWrite(0L));
             writeUnlocker.accept(sl, stamp);
-            mutater.accept(sl);
-            assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlock(stamp),
-                         () -> sl.unlockRead(stamp),
-                         () -> sl.unlockWrite(stamp));
+            assertUnlocked(sl);
+            assertNoLongerValidStampsThrow.run();
         }
     }
 
     /**
-     * Invalid read stamps result in IllegalMonitorStateException
+     * Read locks can be very deeply nested
      */
-    public void testInvalidReadStampsThrowIllegalMonitorStateException() {
-        List<Function<StampedLock, Long>> readLockers = new ArrayList<>();
-        readLockers.add((sl) -> sl.readLock());
-        readLockers.add((sl) -> readLockInterruptiblyUninterrupted(sl));
-        readLockers.add((sl) -> tryReadLockUninterrupted(sl, Long.MIN_VALUE, DAYS));
-        readLockers.add((sl) -> tryReadLockUninterrupted(sl, 0, DAYS));
-
-        List<BiConsumer<StampedLock, Long>> readUnlockers = new ArrayList<>();
-        readUnlockers.add((sl, stamp) -> sl.unlockRead(stamp));
-        readUnlockers.add((sl, stamp) -> assertTrue(sl.tryUnlockRead()));
-        readUnlockers.add((sl, stamp) -> sl.asReadLock().unlock());
-        readUnlockers.add((sl, stamp) -> sl.unlock(stamp));
-
-        List<Function<StampedLock, Long>> writeLockers = new ArrayList<>();
-        writeLockers.add((sl) -> sl.writeLock());
-        writeLockers.add((sl) -> writeLockInterruptiblyUninterrupted(sl));
-        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS));
-        writeLockers.add((sl) -> tryWriteLockUninterrupted(sl, 0, DAYS));
-
-        List<BiConsumer<StampedLock, Long>> writeUnlockers = new ArrayList<>();
-        writeUnlockers.add((sl, stamp) -> sl.unlockWrite(stamp));
-        writeUnlockers.add((sl, stamp) -> assertTrue(sl.tryUnlockWrite()));
-        writeUnlockers.add((sl, stamp) -> sl.asWriteLock().unlock());
-        writeUnlockers.add((sl, stamp) -> sl.unlock(stamp));
-
-
-        for (Function<StampedLock, Long> readLocker : readLockers)
-        for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers)
-        for (Function<StampedLock, Long> writeLocker : writeLockers)
-        for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers) {
-            final StampedLock sl = new StampedLock();
-            final long stamp = readLocker.apply(sl);
-            assertTrue(stamp != 0L);
-            assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlockWrite(stamp));
-            readUnlocker.accept(sl, stamp);
-            assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlock(stamp),
-                         () -> sl.unlockRead(stamp),
-                         () -> sl.unlockWrite(stamp));
-            final long writeStamp = writeLocker.apply(sl);
-            assertTrue(writeStamp != 0L);
-            assertTrue(writeStamp != stamp);
-            assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlock(stamp),
-                         () -> sl.unlockRead(stamp),
-                         () -> sl.unlockWrite(stamp));
-            writeUnlocker.accept(sl, writeStamp);
-            assertThrows(IllegalMonitorStateException.class,
-                         () -> sl.unlock(stamp),
-                         () -> sl.unlockRead(stamp),
-                         () -> sl.unlockWrite(stamp));
+    public void testDeeplyNestedReadLocks() {
+        final StampedLock lock = new StampedLock();
+        final int depth = 300;
+        final long[] stamps = new long[depth];
+        final List<Function<StampedLock, Long>> readLockers = readLockers();
+        final List<BiConsumer<StampedLock, Long>> readUnlockers = readUnlockers();
+        for (int i = 0; i < depth; i++) {
+            Function<StampedLock, Long> readLocker
+                = readLockers.get(i % readLockers.size());
+            long stamp = readLocker.apply(lock);
+            assertEquals(i + 1, lock.getReadLockCount());
+            assertTrue(lock.isReadLocked());
+            stamps[i] = stamp;
         }
+        for (int i = 0; i < depth; i++) {
+            BiConsumer<StampedLock, Long> readUnlocker
+                = readUnlockers.get(i % readUnlockers.size());
+            assertEquals(depth - i, lock.getReadLockCount());
+            assertTrue(lock.isReadLocked());
+            readUnlocker.accept(lock, stamps[depth - 1 - i]);
+        }
+        assertUnlocked(lock);
     }
-
 }
--- a/test/javax/net/ssl/Stapling/SSLSocketWithStapling.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/javax/net/ssl/Stapling/SSLSocketWithStapling.java	Fri Aug 19 12:17:32 2016 -0700
@@ -119,20 +119,22 @@
             System.setProperty("javax.net.debug", "ssl");
         }
 
-        // Create the PKI we will use for the test and start the OCSP servers
-        createPKI();
+        try {
+            // Create the PKI we will use for the test and start the OCSP servers
+            createPKI();
 
-        testAllDefault();
-        testPKIXParametersRevEnabled();
-        testRevokedCertificate();
-        testHardFailFallback();
-        testSoftFailFallback();
-        testLatencyNoStaple(false);
-        testLatencyNoStaple(true);
-
-        // shut down the OCSP responders before finishing the test
-        intOcsp.stop();
-        rootOcsp.stop();
+            testAllDefault();
+            testPKIXParametersRevEnabled();
+            testRevokedCertificate();
+            testHardFailFallback();
+            testSoftFailFallback();
+            testLatencyNoStaple(false);
+            testLatencyNoStaple(true);
+        } finally {
+            // shut down the OCSP responders before finishing the test
+            intOcsp.stop();
+            rootOcsp.stop();
+        }
     }
 
     /**
@@ -281,11 +283,9 @@
         ServerParameters servParams = new ServerParameters();
         serverReady = false;
 
-        // Stop the OCSP responders and give a 1 second delay before
-        // running the test.
-        intOcsp.stop();
-        rootOcsp.stop();
-        Thread.sleep(1000);
+        // make OCSP responders reject connections
+        intOcsp.rejectConnections();
+        rootOcsp.rejectConnections();
 
         System.out.println("=======================================");
         System.out.println("Stapling enbled in client and server,");
@@ -315,9 +315,9 @@
         System.out.println("                 PASS");
         System.out.println("=======================================\n");
 
-        // Start the OCSP responders up again
-        intOcsp.start();
-        rootOcsp.start();
+        // Make OCSP responders accept connections
+        intOcsp.acceptConnections();
+        rootOcsp.acceptConnections();
 
         // Wait 5 seconds for server ready
         for (int i = 0; (i < 100 && (!intOcsp.isServerReady() || !rootOcsp.isServerReady())); i++) {
@@ -338,11 +338,9 @@
         ServerParameters servParams = new ServerParameters();
         serverReady = false;
 
-        // Stop the OCSP responders and give a 1 second delay before
-        // running the test.
-        intOcsp.stop();
-        rootOcsp.stop();
-        Thread.sleep(1000);
+        // make OCSP responders reject connections
+        intOcsp.rejectConnections();
+        rootOcsp.rejectConnections();
 
         System.out.println("=======================================");
         System.out.println("Stapling enbled in client and server,");
@@ -372,9 +370,9 @@
         System.out.println("                 PASS");
         System.out.println("=======================================\n");
 
-        // Start the OCSP responders up again
-        intOcsp.start();
-        rootOcsp.start();
+        // Make OCSP responders accept connections
+        intOcsp.acceptConnections();
+        rootOcsp.acceptConnections();
 
         // Wait 5 seconds for server ready
         for (int i = 0; (i < 100 && (!intOcsp.isServerReady() || !rootOcsp.isServerReady())); i++) {
@@ -401,15 +399,10 @@
         ServerParameters servParams = new ServerParameters();
         serverReady = false;
 
-        // Stop the OCSP responders and give a 1 second delay before
-        // running the test.
-        intOcsp.stop();
-        rootOcsp.stop();
-        Thread.sleep(1000);
+        // Give a 1 second delay before running the test.
         intOcsp.setDelay(3000);
         rootOcsp.setDelay(3000);
-        rootOcsp.start();
-        intOcsp.start();
+        Thread.sleep(1000);
 
         // Wait 5 seconds for server ready
         for (int i = 0; (i < 100 && (!intOcsp.isServerReady() || !rootOcsp.isServerReady())); i++) {
@@ -458,13 +451,9 @@
         System.out.println("========================================\n");
 
         // Remove the OCSP responder latency
-        intOcsp.stop();
-        rootOcsp.stop();
-        Thread.sleep(1000);
         intOcsp.setDelay(0);
         rootOcsp.setDelay(0);
-        rootOcsp.start();
-        intOcsp.start();
+        Thread.sleep(1000);
 
         // Wait 5 seconds for server ready
         for (int i = 0; (i < 100 && (!intOcsp.isServerReady() || !rootOcsp.isServerReady())); i++) {
@@ -676,6 +665,7 @@
                          * Release the client, if not active already...
                          */
                         System.err.println("Server died...");
+                        e.printStackTrace(System.err);
                         serverReady = true;
                         serverException = e;
                     }
--- a/test/javax/xml/crypto/dsig/TransformService/NullParent.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/javax/xml/crypto/dsig/TransformService/NullParent.java	Fri Aug 19 12:17:32 2016 -0700
@@ -26,6 +26,7 @@
  * @bug 8022120
  * @summary check that the init and marshalParams methods throw
  *          NullPointerException when the parent parameter is null
+ * @run main/othervm/java.security.policy==test.policy NullParent
  */
 
 import javax.xml.crypto.dsig.CanonicalizationMethod;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/xml/crypto/dsig/TransformService/test.policy	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,3 @@
+grant {
+
+};
--- a/test/javax/xml/crypto/dsig/keyinfo/KeyInfo/Marshal.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/javax/xml/crypto/dsig/keyinfo/KeyInfo/Marshal.java	Fri Aug 19 12:17:32 2016 -0700
@@ -27,7 +27,7 @@
  * @summary Test that KeyInfo.marshal works correctly
  * @modules java.xml.crypto/org.jcp.xml.dsig.internal.dom
  * @compile -XDignore.symbol.file Marshal.java
- * @run main Marshal
+ * @run main/othervm/java.security.policy==test.policy Marshal
  * @author Sean Mullan
  */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/xml/crypto/dsig/keyinfo/KeyInfo/test.policy	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,3 @@
+grant {
+    permission java.lang.RuntimePermission "accessClassInPackage.org.jcp.xml.dsig.internal.dom";
+};
--- a/test/sun/misc/URLClassPath/ClassnameCharTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/sun/misc/URLClassPath/ClassnameCharTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -103,16 +103,60 @@
 
     //--------------------- Infrastructure ---------------------------
     static volatile int passed = 0, failed = 0;
-    static boolean pass() {passed++; return true;}
-    static boolean fail() {failed++; server.stop(0); Thread.dumpStack(); return false;}
-    static boolean fail(String msg) {System.out.println(msg); return fail();}
-    static void unexpected(Throwable t) {failed++; server.stop(0); t.printStackTrace();}
-    static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}
+
+    static boolean pass() {
+        passed++;
+        return true;
+    }
+
+    static boolean fail() {
+        failed++;
+        if (server != null) {
+            server.stop(0);
+        }
+        Thread.dumpStack();
+        return false;
+    }
+
+    static boolean fail(String msg) {
+        System.out.println(msg);
+        return fail();
+    }
+
+    static void unexpected(Throwable t) {
+        failed++;
+        if (server != null) {
+            server.stop(0);
+        }
+        t.printStackTrace();
+    }
+
+    static boolean check(boolean cond) {
+        if (cond) {
+            pass();
+        } else {
+            fail();
+        }
+        return cond;
+    }
+
     static boolean equal(Object x, Object y) {
-        if (x == null ? y == null : x.equals(y)) return pass();
-        else return fail(x + " not equal to " + y);}
+        if (x == null ? y == null : x.equals(y)) {
+            return pass();
+        } else {
+            return fail(x + " not equal to " + y);
+        }
+    }
+
     public static void main(String[] args) throws Throwable {
-        try {realMain(args);} catch (Throwable t) {unexpected(t);}
+        try {
+            realMain(args);
+        } catch (Throwable t) {
+            unexpected(t);
+        }
         System.out.println("\nPassed = " + passed + " failed = " + failed);
-        if (failed > 0) throw new AssertionError("Some tests failed");}
+        if (failed > 0) {
+            throw new AssertionError("Some tests failed");
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/krb5/auto/CommMatcher.java	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,86 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Matches the krb5 debug output:
+ * >>> KDCCommunication: kdc=host UDP:11555, timeout=100,Attempt =1, #bytes=138
+ *
+ * Example:
+ *   CommMatcher cm = new CommMatcher();
+ *   cm.addPort(12345).addPort(23456);
+ *   for (String line : debugOutput) {
+ *       if (cm.match(line)) {
+ *           println("KDC: %c, %s, Timeout: %d\n",
+ *              cm.kdc(), cm.protocol(), cm.timeout());
+ *       }
+ *   }
+ */
+public class CommMatcher {
+
+    static final Pattern re = Pattern.compile(
+            ">>> KDCCommunication: kdc=\\S+ (TCP|UDP):(\\d+), " +
+                    "timeout=(\\d+),Attempt\\s*=(\\d+)");
+
+    List<Integer> kdcPorts = new ArrayList<>();
+    Matcher matcher;
+
+    /**
+     * Add KDC ports one by one. The 1st KDC will be 'a' in {@link #kdc()},
+     * 2nd is 'b', etc, etc.
+     */
+    public CommMatcher addPort(int port) {
+        if (port > 0) {
+            kdcPorts.add(port);
+        } else {
+            kdcPorts.clear();
+        }
+        return this;
+    }
+
+    public boolean match(String line) {
+        matcher = re.matcher(line);
+        return matcher.find();
+    }
+
+    public String protocol() {
+        return matcher.group(1);
+    }
+
+    public char kdc() {
+        int port = Integer.parseInt(matcher.group(2));
+        return (char)(kdcPorts.indexOf(port) + 'a');
+    }
+
+    public int timeout() {
+        return BadKdc.toSymbolicSec(Integer.parseInt(matcher.group(3)));
+    }
+
+    public int attempt() {
+        return Integer.parseInt(matcher.group(4));
+    }
+}
--- a/test/sun/security/krb5/auto/MaxRetries.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/sun/security/krb5/auto/MaxRetries.java	Fri Aug 19 12:17:32 2016 -0700
@@ -30,6 +30,7 @@
  * @summary support max_retries in krb5.conf
  */
 
+import javax.security.auth.login.LoginException;
 import java.io.*;
 import java.net.DatagramSocket;
 import java.security.Security;
@@ -37,46 +38,86 @@
 public class MaxRetries {
 
     static int idlePort = -1;
+    static CommMatcher cm = new CommMatcher();
 
     public static void main(String[] args)
             throws Exception {
 
         System.setProperty("sun.security.krb5.debug", "true");
-        new OneKDC(null).writeJAASConf();
+        OneKDC kdc = new OneKDC(null).writeJAASConf();
 
         // An idle UDP socket to prevent PortUnreachableException
         DatagramSocket ds = new DatagramSocket();
         idlePort = ds.getLocalPort();
 
+        cm.addPort(idlePort);
+        cm.addPort(kdc.getPort());
+
         System.setProperty("java.security.krb5.conf", "alternative-krb5.conf");
 
-        // For tryLast
         Security.setProperty("krb5.kdc.bad.policy", "trylast");
+
+        // We always make the real timeout to be 1 second
+        BadKdc.setRatio(0.25f);
         rewriteMaxRetries(4);
-        test1(4000, 6);         // 1 1 1 1 2 2
-        test1(4000, 2);         // 2 2
 
+        // Explanation: In this case, max_retries=4 and timeout=4s.
+        // For AS-REQ without preauth, we will see 4 4s timeout on kdc#1
+        // ("a4" repeat 4 times), and one 4s timeout on kdc#2 ("b4"). For
+        // AS-REQ with preauth, one 4s timeout on kdc#2 (second "b4").
+        // we tolerate 4 real timeout on kdc#2, so make it "(b4){2,6}".
+        test1("a4a4a4a4b4b4", "a4a4a4a4(b4){2,6}");
+        test1("b4b4", "(b4){2,6}");
+
+        BadKdc.setRatio(1f);
         rewriteMaxRetries(1);
-        test1(1000, 3);         // 1 2 2
-        test1(1000, 2);         // 2 2
+        // Explanation: Since max_retries=1 only, we could fail in 1st or 2nd
+        // AS-REQ to kdc#2.
+        String actual = test1("a1b1b1", "(a1b1b1|a1b1x|a1b1b1x)");
+        if (actual.endsWith("x")) {
+            // If 1st attempt fails, all bads are back available
+            test1("a1b1b1", "(a1b1b1|a1b1x|a1b1b1x)");
+        } else {
+            test1("b1b1", "(b1b1|b1x|b1b1x)");
+        }
 
+        BadKdc.setRatio(0.2f);
         rewriteMaxRetries(-1);
-        test1(5000, 4);         // 1 1 2 2
-        test1(5000, 2);         // 2 2
+        test1("a5a5a5b5b5", "a5a5a5(b5){2,4}");
+        test1("b5b5", "(b5){2,4}");
 
-        // For tryLess
-        Security.setProperty("krb5.kdc.bad.policy", "tryless:1," + BadKdc.toReal(5000));
+        BadKdc.setRatio(0.25f);
+        Security.setProperty("krb5.kdc.bad.policy",
+                "tryless:1,1000");
         rewriteMaxRetries(4);
-        test1(4000, 7);         // 1 1 1 1 2 1 2
-        test1(4000, 4);         // 1 2 1 2
+        test1("a4a4a4a4b4a4b4", "a4a4a4a4(b4){1,3}a4(b4){1,3}");
+        test1("a4b4a4b4", "a4(b4){1,3}a4(b4){1,3}");
 
+        BadKdc.setRatio(1f);
         rewriteMaxRetries(1);
-        test1(1000, 4);         // 1 2 1 2
-        test1(1000, 4);         // 1 2 1 2
+        actual = test1("a1b1a1b1", "(a1b1|a1b1x|a1b1a1b1|a1b1a1b1x)");
+        if (actual.endsWith("x")) {
+            test1("a1b1a1b1", "(a1b1|a1b1x|a1b1a1b1|a1b1a1b1x)");
+        } else {
+            test1("a1b1a1b1", "(a1b1|a1b1x|a1b1a1b1|a1b1a1b1x)");
+        }
 
+        BadKdc.setRatio(.2f);
         rewriteMaxRetries(-1);
-        test1(5000, 5);         // 1 1 2 1 2
-        test1(5000, 4);         // 1 2 1 2
+        test1("a5a5a5b5a5b5", "a5a5a5(b5){1,2}a5(b5){1,2}");
+        test1("a5b5a5b5", "a5(b5){1,2}a5(b5){1,2}");
+
+        BadKdc.setRatio(1f);
+        rewriteMaxRetries(2);
+        if (BadKdc.toReal(2000) > 1000) {
+            // Explanation: if timeout is longer than 1s in tryLess,
+            // we will see "a1" at 2nd kdc#1 access
+            test1("a2a2b2a1b2", "a2a2(b2){1,2}a1(b2){1,2}");
+        } else {
+            test1("a2a2b2a2b2", "a2a2(b2){1,2}a2(b2){1,2}");
+        }
+
+        BadKdc.setRatio(1f);
 
         rewriteUdpPrefLimit(-1, -1);    // default, no limit
         test2("UDP");
@@ -95,32 +136,52 @@
 
     /**
      * One round of test for max_retries and timeout.
-     * @param timeout the expected timeout
-     * @param count the expected total try
+     *
+     * @param exact the expected exact match, where no timeout
+     *              happens for real KDCs
+     * @param relaxed the expected relaxed match, where some timeout
+     *                could happen for real KDCs
+     * @return the actual result
      */
-    private static void test1(int timeout, int count) throws Exception {
-        String timeoutTag = "timeout=" + BadKdc.toReal(timeout);
+    private static String test1(String exact, String relaxed) throws Exception {
         ByteArrayOutputStream bo = new ByteArrayOutputStream();
         PrintStream oldout = System.out;
         System.setOut(new PrintStream(bo));
-        Context c = Context.fromJAAS("client");
+        boolean failed = false;
+        long start = System.nanoTime();
+        try {
+            Context c = Context.fromJAAS("client");
+        } catch (LoginException e) {
+            failed = true;
+        }
         System.setOut(oldout);
 
         String[] lines = new String(bo.toByteArray()).split("\n");
-        System.out.println("----------------- TEST (" + timeout + "," +
-                count + ") -----------------");
+        System.out.println("----------------- TEST (" + exact
+                + ") -----------------");
+
+        // Result, a series of timeout + kdc#
+        StringBuilder sb = new StringBuilder();
         for (String line: lines) {
-            if (line.startsWith(">>> KDCCommunication")) {
+            if (cm.match(line)) {
                 System.out.println(line);
-                if (line.indexOf(timeoutTag) < 0) {
-                    throw new Exception("Wrong timeout value" + timeoutTag);
-                }
-                count--;
+                sb.append(cm.kdc()).append(cm.timeout());
             }
         }
-        if (count != 0) {
-            throw new Exception("Retry count is " + count + " less");
+        if (failed) {
+            sb.append("x");
         }
+        System.out.println("Time: " + (System.nanoTime() - start) / 1000000000d);
+        String actual = sb.toString();
+        System.out.println("Actual: " + actual);
+        if (actual.equals(exact)) {
+            System.out.println("Exact match: " + exact);
+        } else if (actual.matches(relaxed)) {
+            System.out.println("!!!! Tolerant match: " + relaxed);
+        } else {
+            throw new Exception("Match neither " + exact + " nor " + relaxed);
+        }
+        return actual;
     }
 
     /**
@@ -138,11 +199,11 @@
         String[] lines = new String(bo.toByteArray()).split("\n");
         System.out.println("----------------- TEST -----------------");
         for (String line: lines) {
-            if (line.startsWith(">>> KDCCommunication")) {
+            if (cm.match(line)) {
                 System.out.println(line);
                 count--;
-                if (line.indexOf(proto) < 0) {
-                    throw new Exception("Wrong timeout value");
+                if (!cm.protocol().equals(proto)) {
+                    throw new Exception("Wrong protocol value");
                 }
             }
         }
@@ -165,6 +226,7 @@
             }
             if (s.startsWith("[realms]")) {
                 // Reconfig global setting
+                fw.write("kdc_timeout = 5000\n");
                 if (global != -1) {
                     fw.write("udp_preference_limit = " + global + "\n");
                 }
@@ -183,7 +245,8 @@
 
     /**
      * Set max_retries and timeout value for realm. The global value is always
-     * 2 and 5000.
+     * 3 and 5000.
+     *
      * @param value max_retries and timeout/1000 for a realm, -1 means none.
      */
     private static void rewriteMaxRetries(int value) throws Exception {
@@ -196,7 +259,7 @@
             }
             if (s.startsWith("[realms]")) {
                 // Reconfig global setting
-                fw.write("max_retries = 2\n");
+                fw.write("max_retries = 3\n");
                 fw.write("kdc_timeout = " + BadKdc.toReal(5000) + "\n");
             } else if (s.trim().startsWith("kdc = ")) {
                 if (value != -1) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/ssl/SSLContextImpl/CustomizedCipherSuites.java	Fri Aug 19 12:17:32 2016 -0700
@@ -0,0 +1,270 @@
+/*
+ * 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.
+ */
+
+// SunJSSE does not support dynamic system properties, no way to re-use
+// system properties in samevm/agentvm mode.
+
+/*
+ * @test
+ * @bug 8162362
+ * @summary Cannot enable previously default enabled cipher suites
+ * @run main/othervm
+ *      CustomizedCipherSuites Default true
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.client.cipherSuites="unknown"
+ *      CustomizedCipherSuites Default true
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.client.cipherSuites=""
+ *      CustomizedCipherSuites Default true
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.client.cipherSuites="SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default true
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.server.cipherSuites="SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default false
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.client.cipherSuites="TLS_RSA_WITH_AES_128_CBC_SHA,unknown,SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default true
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ *      ""
+ * @run main/othervm
+ *      -Djdk.tls.server.cipherSuites="TLS_RSA_WITH_AES_128_CBC_SHA,unknown,SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default false
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      ""
+ * @run main/othervm
+ *      -Djdk.tls.server.cipherSuites="SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default true
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ * @run main/othervm
+ *      -Djdk.tls.client.cipherSuites="SSL_RSA_WITH_DES_CBC_SHA"
+ *      CustomizedCipherSuites Default false
+ *      TLS_RSA_WITH_AES_128_CBC_SHA
+ *      SSL_RSA_WITH_DES_CBC_SHA
+ */
+
+import javax.net.ssl.*;
+
+/**
+ * Test the customized default cipher suites.
+ *
+ * This test is based on the behavior that SSL_RSA_WITH_DES_CBC_SHA is
+ * disabled by default, and TLS_RSA_WITH_AES_128_CBC_SHA is enabled by
+ * default in JDK.  If the behavior is changed in the future, please
+ * update the test cases above accordingly.
+ */
+public class CustomizedCipherSuites {
+
+    private static String contextProtocol;
+    private static boolean isClientMode;
+
+    private static String enabledCipherSuite;
+    private static String disabledCipherSuite;
+
+    public static void main(String[] args) throws Exception {
+
+        contextProtocol = trimQuotes(args[0]);
+        isClientMode = Boolean.parseBoolean(args[1]);
+        enabledCipherSuite = trimQuotes(args[2]);
+        disabledCipherSuite = trimQuotes(args[3]);
+
+        //
+        // Create instance of SSLContext with the specified protocol.
+        //
+        SSLContext context = SSLContext.getInstance(contextProtocol);
+
+        // Default SSLContext is initialized automatically.
+        if (!contextProtocol.equals("Default")) {
+            // Use default TK, KM and random.
+            context.init((KeyManager[])null, (TrustManager[])null, null);
+        }
+
+        // SSLContext default parameters is client mode in JDK.
+        if (isClientMode) {
+            //
+            // Check default parameters of the specified SSLContext protocol
+            //
+            SSLParameters parameters = context.getDefaultSSLParameters();
+            System.out.println("Checking SSLContext default parameters ...");
+            checkEnabledCiphers(parameters.getCipherSuites());
+        }
+
+        //
+        // Check supported parameters of the specified SSLContext protocol
+        //
+        SSLParameters parameters = context.getSupportedSSLParameters();
+        System.out.println("Checking SSLContext suppport parameters ...");
+        checkSupportedCiphers(parameters.getCipherSuites());
+
+
+        //
+        // Check the default cipher suites of SSLEngine.
+        //
+        SSLEngine engine = context.createSSLEngine();
+        engine.setUseClientMode(isClientMode);
+
+        System.out.println("Checking SSLEngine default cipher suites ...");
+        checkEnabledCiphers(engine.getEnabledCipherSuites());
+
+        //
+        // Check the supported cipher suites of SSLEngine.
+        //
+        System.out.println("Checking SSLEngine supported cipher suites ...");
+        checkSupportedCiphers(engine.getSupportedCipherSuites());
+
+        if (isClientMode) {
+            SSLSocketFactory factory = context.getSocketFactory();
+            // Use an unconnected socket.
+            try (SSLSocket socket = (SSLSocket)factory.createSocket()) {
+                //
+                // Check the default cipher suites of SSLSocket.
+                //
+                System.out.println(
+                        "Checking SSLSocket default cipher suites ...");
+                checkEnabledCiphers(socket.getEnabledCipherSuites());
+
+                //
+                // Check the supported cipher suites of SSLSocket.
+                //
+                System.out.println(
+                        "Checking SSLSocket supported cipher suites ...");
+                checkSupportedCiphers(socket.getSupportedCipherSuites());
+            }
+        } else {
+            SSLServerSocketFactory factory = context.getServerSocketFactory();
+            // Use an unbound server socket.
+            try (SSLServerSocket socket =
+                    (SSLServerSocket)factory.createServerSocket()) {
+                //
+                // Check the default cipher suites of SSLServerSocket.
+                //
+                System.out.println(
+                        "Checking SSLServerSocket default cipher suites ...");
+                checkEnabledCiphers(socket.getEnabledCipherSuites());
+
+                //
+                // Check the supported cipher suites of SSLServerSocket.
+                //
+                System.out.println(
+                        "Checking SSLServerSocket supported cipher suites ...");
+                checkSupportedCiphers(socket.getSupportedCipherSuites());
+            }
+        }
+
+        System.out.println("\t... Success");
+    }
+
+    private static void checkEnabledCiphers(
+            String[] ciphers) throws Exception {
+
+        if (ciphers.length == 0) {
+            throw new Exception("No default cipher suites");
+        }
+
+        boolean isMatch = false;
+        if (enabledCipherSuite.isEmpty()) {
+            // Don't check if not specify the expected cipher suite.
+            isMatch = true;
+        }
+
+        boolean isBroken = false;
+        for (String cipher : ciphers) {
+            System.out.println("\tdefault cipher suite " + cipher);
+            if (!enabledCipherSuite.isEmpty() &&
+                        cipher.equals(enabledCipherSuite)) {
+                isMatch = true;
+            }
+
+            if (!disabledCipherSuite.isEmpty() &&
+                        cipher.equals(disabledCipherSuite)) {
+                isBroken = true;
+            }
+        }
+
+        if (!isMatch) {
+            throw new Exception(
+                "Cipher suite " + enabledCipherSuite + " should be enabled");
+        }
+
+        if (isBroken) {
+            throw new Exception(
+                "Cipher suite " + disabledCipherSuite + " should be disabled");
+        }
+    }
+
+    private static void checkSupportedCiphers(
+            String[] ciphers) throws Exception {
+
+        if (ciphers.length == 0) {
+            throw new Exception("No supported cipher suites");
+        }
+
+        boolean hasEnabledCipherSuite = enabledCipherSuite.isEmpty();
+        boolean hasDisabledCipherSuite = disabledCipherSuite.isEmpty();
+        for (String cipher : ciphers) {
+            System.out.println("\tsupported cipher suite " + cipher);
+            if (!enabledCipherSuite.isEmpty() &&
+                        cipher.equals(enabledCipherSuite)) {
+                hasEnabledCipherSuite = true;
+            }
+
+            if (!disabledCipherSuite.isEmpty() &&
+                        cipher.equals(disabledCipherSuite)) {
+                hasDisabledCipherSuite = true;
+            }
+        }
+
+        if (!hasEnabledCipherSuite) {
+            throw new Exception(
+                "Cipher suite " + enabledCipherSuite + " should be supported");
+        }
+
+        if (!hasDisabledCipherSuite) {
+            throw new Exception(
+                "Cipher suite " + disabledCipherSuite + " should be supported");
+        }
+    }
+
+    private static String trimQuotes(String candidate) {
+        if (candidate != null && candidate.length() != 0) {
+            // Remove double quote marks from beginning/end of the string.
+            if (candidate.length() > 1 && candidate.charAt(0) == '"' &&
+                    candidate.charAt(candidate.length() - 1) == '"') {
+                return candidate.substring(1, candidate.length() - 1);
+            }
+        }
+
+        return candidate;
+    }
+}
--- a/test/sun/security/tools/keytool/StartDateTest.java	Fri Aug 19 10:09:53 2016 -0400
+++ b/test/sun/security/tools/keytool/StartDateTest.java	Fri Aug 19 12:17:32 2016 -0700
@@ -49,23 +49,31 @@
 
         new File("jks").delete();
 
-        run("-keystore jks -storetype jks -storepass changeit -keypass changeit -alias me " +
-                "-keyalg rsa -genkeypair -dname CN=Haha -startdate +1y");
-        cal.setTime(getIssueDate());
+        run("one", "+1y");
+        cal.setTime(getIssueDate("one"));
         System.out.println(cal);
         if (cal.get(Calendar.YEAR) != year + 1) {
             throw new Exception("Function check #1 fails");
         }
 
-        run("-keystore jks -storetype jks -storepass changeit -keypass changeit -alias me " +
-                "-selfcert -startdate +1m");
-        cal.setTime(getIssueDate());
+        run("two", "+1m");
+        cal.setTime(getIssueDate("two"));
         System.out.println(cal);
         if (cal.get(Calendar.MONTH) != (month + 1) % 12) {
             throw new Exception("Function check #2 fails");
         }
 
-        new File("jks").delete();
+        run("three", "2009/10/11 12:34:56");
+        cal.setTime(getIssueDate("three"));
+        System.out.println(cal);
+        if (cal.get(Calendar.YEAR) != 2009 ||
+                cal.get(Calendar.MONTH) != Calendar.OCTOBER ||
+                cal.get(Calendar.DAY_OF_MONTH) != 11 ||
+                cal.get(Calendar.HOUR_OF_DAY) != 12 ||
+                cal.get(Calendar.MINUTE) != 34 ||
+                cal.get(Calendar.SECOND) != 56) {
+            throw new Exception("Function check #3 fails");
+        }
 
         // Part 2: Test format
         Method m = sun.security.tools.keytool.Main.class.getDeclaredMethod(
@@ -129,16 +137,23 @@
         }
     }
 
-    static void run(String s) throws Exception {
-        sun.security.tools.keytool.Main.main((s+" -debug").split(" "));
+    // The keytool command line template, alias and startdate TBD
+    static String[] cmd = ("-alias tbd -startdate tbd -keystore jks " +
+            "-storetype jks -storepass changeit -keypass changeit " +
+            "-keyalg rsa -genkeypair -dname CN=Haha -debug").split(" ");
+
+    static void run(String alias, String startDate) throws Exception {
+        cmd[1] = alias;
+        cmd[3] = startDate;
+        sun.security.tools.keytool.Main.main(cmd);
     }
 
-    static Date getIssueDate() throws Exception {
+    static Date getIssueDate(String alias) throws Exception {
         KeyStore ks = KeyStore.getInstance("jks");
         try (FileInputStream fis = new FileInputStream("jks")) {
             ks.load(fis, "changeit".toCharArray());
         }
-        X509Certificate cert = (X509Certificate)ks.getCertificate("me");
+        X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
         return cert.getNotBefore();
     }
 }