changeset 14064:5e1641ac146b icedtea-3.13.0pre01

Merge jdk8u222-b01
author andrew
date Fri, 24 May 2019 04:01:22 +0100
parents 42f25fec42bd (current diff) e880f2d161bf (diff)
children 5de3df8a3724
files .hgtags src/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java src/share/classes/java/lang/invoke/MethodHandleProxies.java src/share/classes/sun/security/ssl/SSLContextImpl.java src/share/classes/sun/security/ssl/TrustManagerFactoryImpl.java src/share/classes/sun/security/ssl/TrustStoreManager.java src/share/classes/sun/security/validator/KeyStores.java src/solaris/classes/sun/awt/X11/XWindow.java src/solaris/native/sun/awt/gtk3_interface.c src/solaris/native/sun/awt/gtk3_interface.h src/solaris/native/sun/awt/multiVis.c test/java/nio/Buffer/Chars.java test/java/nio/file/FileStore/Basic.java test/tools/launcher/RunpathTest.java
diffstat 40 files changed, 2016 insertions(+), 648 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon Apr 22 17:30:12 2019 +0100
+++ b/.hgtags	Fri May 24 04:01:22 2019 +0100
@@ -1050,6 +1050,7 @@
 4d01af1665277b6f5f5a6c9107f01bb6c1e0942d jdk8u202-b26
 d10b8de706c1ea867abc5518dbb1cf92f6965f6a jdk8u202-ga
 478a4add975beb90696a4ead5f8fcd9c17fc1a83 jdk8u212-b00
+fcf246aa327f6384be94464b2c8aa0ef03af473d jdk8u222-b00
 fcf246aa327f6384be94464b2c8aa0ef03af473d jdk8u212-b01
 acab6dbdd0b55e524d50e9b1c4f12c90e2f424c5 jdk8u212-b02
 ac2ef877d3e8062c1ce72757538daae6cad1118f jdk8u212-b03
--- a/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/macosx/native/sun/awt/JavaComponentAccessibility.m	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -325,15 +325,15 @@
         }
 
         JavaComponentAccessibility *child = [self createWithParent:parent accessible:jchild role:childJavaRole index:childIndex withEnv:env withView:parent->fView];
-        
+
         (*env)->DeleteLocalRef(env, jchild);
         (*env)->DeleteLocalRef(env, jchildJavaRole);
-        
+
         [children addObject:child];
         childIndex++;
     }
     (*env)->DeleteLocalRef(env, jchildrenAndRoles);
-    
+
     return children;
 }
 
@@ -646,6 +646,9 @@
         }
         // The above set of attributes is immutable per role, but some objects, if
         // they are the child of a list, need to add the selected and index attributes.
+        if ([self accessibilityIsIgnored]) {
+            return names;
+        }
         id myParent = [self accessibilityParentAttribute];
         if ([myParent isKindOfClass:[JavaComponentAccessibility class]]) {
             NSString *parentRole = [(JavaComponentAccessibility *)myParent javaRole];
@@ -1060,7 +1063,7 @@
                                     sjc_CAccessibility,
                                     "requestSelection",
                                     "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V" );
-    
+
     if ([(NSNumber*)value boolValue]) {
         JNIEnv* env = [ThreadUtilities getJNIEnv];
         JNFCallStaticVoidMethod(env, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
@@ -1167,7 +1170,7 @@
     // Need to handle popupmenus differently.
     //
     // At least for now don't handle combo box menus.
-    // This may change when later fixing issues which currently 
+    // This may change when later fixing issues which currently
     // exist for combo boxes, but for now the following is only
     // for JPopupMenus, not for combobox menus.
     id parent = [self parent];
@@ -1349,7 +1352,7 @@
     NSWindow* hostWindow = [[self->fView window] retain];
     jobject focused = JNFCallStaticObjectMethod(env, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop)
     [hostWindow release];
-    
+
     if (focused != NULL) {
         if (JNFIsInstanceOf(env, focused, &sjc_Accessible)) {
             value = [JavaComponentAccessibility createWithAccessible:focused withEnv:env withView:fView];
--- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java	Fri May 24 04:01:22 2019 +0100
@@ -734,7 +734,8 @@
               region == Region.TOOL_BAR_DRAG_WINDOW ||
               region == Region.TOOL_TIP ||
               region == Region.TREE ||
-              region == Region.VIEWPORT) {
+              region == Region.VIEWPORT ||
+              region == Region.TEXT_PANE) {
             return true;
         }
         if (!GTKLookAndFeel.is3()) {
@@ -742,8 +743,7 @@
                   region == Region.FORMATTED_TEXT_FIELD ||
                   region == Region.PASSWORD_FIELD ||
                   region == Region.SPINNER ||
-                  region == Region.TEXT_FIELD ||
-                  region == Region.TEXT_PANE) {
+                  region == Region.TEXT_FIELD) {
                 return true;
             }
         }
@@ -762,6 +762,14 @@
         if (classKey != null) {
             Object value = getClassSpecificValue(classKey);
             if (value != null) {
+                //This is a workaround as the "slider-length" property has been
+                //deprecated for GtkScale from gtk 3.20, so default value of 31
+                //is used and makes redering of slider wrong. Value 14 is being
+                //used as default value for Slider.thumbHeight is 14 and making
+                //width 14 as well makes slider thumb render in proper shape
+                if ("Slider.thumbWidth".equals(key) && value.equals(31)) {
+                    return 14;
+                }
                 return value;
             }
         }
@@ -774,8 +782,15 @@
             return getColorForState(context, ColorType.FOREGROUND);
         }
         else if (key == "ScrollBar.minimumThumbSize") {
+            //This is a workaround as the "min-slider-length" property has been
+            //deprecated for GtkScrollBar from gtk 3.20, so default value of 21
+            //is used and makes ScrollBar thumb very small. Value 40 is being
+            //used as this is the value mentioned in css files
             int len =
                 getClassSpecificIntValue(context, "min-slider-length", 21);
+            if (len == 21) {
+                len = 40;
+            }
             JScrollBar sb = (JScrollBar)context.getComponent();
             if (sb.getOrientation() == JScrollBar.HORIZONTAL) {
                 return new DimensionUIResource(len, 0);
@@ -1150,13 +1165,24 @@
         ICONS_MAP = new HashMap<String, GTKStockIcon>();
         ICONS_MAP.put("FileChooser.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
         ICONS_MAP.put("FileChooser.okIcon",     new GTKStockIcon("gtk-ok",     4));
-        ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6));
-        ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6));
-        ICONS_MAP.put("OptionPane.warningIcon", new GTKStockIcon("gtk-dialog-warning", 6));
-        ICONS_MAP.put("OptionPane.questionIcon", new GTKStockIcon("gtk-dialog-question", 6));
         ICONS_MAP.put("OptionPane.yesIcon", new GTKStockIcon("gtk-yes", 4));
         ICONS_MAP.put("OptionPane.noIcon", new GTKStockIcon("gtk-no", 4));
         ICONS_MAP.put("OptionPane.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
         ICONS_MAP.put("OptionPane.okIcon", new GTKStockIcon("gtk-ok", 4));
+
+        //check whether the gtk version is >= 3.10 as the Icon names were
+        //changed from this version
+        UNIXToolkit tk = (UNIXToolkit)Toolkit.getDefaultToolkit();
+        if (tk.checkGtkVersion(3, 10, 0)) {
+            ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("dialog-error", 6));
+            ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("dialog-information", 6));
+            ICONS_MAP.put("OptionPane.warningIcon", new GTKStockIcon("dialog-warning", 6));
+            ICONS_MAP.put("OptionPane.questionIcon", new GTKStockIcon("dialog-question", 6));
+        } else {
+            ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6));
+            ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6));
+            ICONS_MAP.put("OptionPane.warningIcon", new GTKStockIcon("gtk-dialog-warning", 6));
+            ICONS_MAP.put("OptionPane.questionIcon", new GTKStockIcon("gtk-dialog-question", 6));
+        }
     }
 }
--- a/src/share/classes/java/lang/invoke/MethodHandleProxies.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/java/lang/invoke/MethodHandleProxies.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  * 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,6 +30,8 @@
 import java.security.PrivilegedAction;
 import sun.invoke.WrapperInstance;
 import java.util.ArrayList;
+import java.util.concurrent.ConcurrentHashMap;
+
 import sun.reflect.CallerSensitive;
 import sun.reflect.Reflection;
 import sun.reflect.misc.ReflectUtil;
@@ -50,8 +52,10 @@
      * A single-method interface is an interface which declares a uniquely named method.
      * When determining the uniquely named method of a single-method interface,
      * the public {@code Object} methods ({@code toString}, {@code equals}, {@code hashCode})
-     * are disregarded.  For example, {@link java.util.Comparator} is a single-method interface,
-     * even though it re-declares the {@code Object.equals} method.
+     * are disregarded as are any default (non-abstract) methods.
+     * For example, {@link java.util.Comparator} is a single-method interface,
+     * even though it re-declares the {@code Object.equals} method and also
+     * declares default methods, such as {@code Comparator.reverse}.
      * <p>
      * The interface must be public.  No additional access checks are performed.
      * <p>
@@ -175,6 +179,8 @@
             checkTarget = checkTarget.asType(checkTarget.type().changeReturnType(Object.class));
             vaTargets[i] = checkTarget.asSpreader(Object[].class, smMT.parameterCount());
         }
+        final ConcurrentHashMap<Method, MethodHandle> defaultMethodMap =
+                hasDefaultMethods(intfc) ? new ConcurrentHashMap<>() : null;
         final InvocationHandler ih = new InvocationHandler() {
                 private Object getArg(String name) {
                     if ((Object)name == "getWrapperInstanceTarget")  return target;
@@ -190,6 +196,9 @@
                         return getArg(method.getName());
                     if (isObjectMethod(method))
                         return callObjectMethod(proxy, method, args);
+                    if (isDefaultMethod(method)) {
+                        return callDefaultMethod(defaultMethodMap, proxy, intfc, method, args);
+                    }
                     throw newInternalError("bad proxy method: "+method);
                 }
             };
@@ -319,4 +328,45 @@
         if (uniqueName == null)  return null;
         return methods.toArray(new Method[methods.size()]);
     }
+
+    private static
+    boolean isDefaultMethod(Method m) {
+        return !Modifier.isAbstract(m.getModifiers());
+    }
+
+    private static
+    boolean hasDefaultMethods(Class<?> intfc) {
+        for (Method m : intfc.getMethods()) {
+            if (!isObjectMethod(m) &&
+                !Modifier.isAbstract(m.getModifiers())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static
+    Object callDefaultMethod(ConcurrentHashMap<Method, MethodHandle> defaultMethodMap,
+                             Object self, Class<?> intfc, Method m, Object[] args) throws Throwable {
+        assert(isDefaultMethod(m) && !isObjectMethod(m)) : m;
+
+        // Lazily compute the associated method handle from the method
+        MethodHandle dmh = defaultMethodMap.computeIfAbsent(m, mk -> {
+            try {
+                // Look up the default method for special invocation thereby
+                // avoiding recursive invocation back to the proxy
+                MethodHandle mh = MethodHandles.Lookup.IMPL_LOOKUP.findSpecial(
+                        intfc, mk.getName(),
+                        MethodType.methodType(mk.getReturnType(), mk.getParameterTypes()),
+                        self.getClass());
+                return mh.asSpreader(Object[].class, mk.getParameterCount());
+            } catch (NoSuchMethodException | IllegalAccessException e) {
+                // The method is known to exist and should be accessible, this
+                // method would not be called unless the invokeinterface to the
+                // default (public) method passed access control checks
+                throw new InternalError(e);
+            }
+        });
+        return dmh.invoke(self, args);
+    }
 }
--- a/src/share/classes/java/util/JapaneseImperialCalendar.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/java/util/JapaneseImperialCalendar.java	Fri May 24 04:01:22 2019 +0100
@@ -38,21 +38,21 @@
 import sun.util.calendar.ZoneInfo;
 
 /**
- * <code>JapaneseImperialCalendar</code> implements a Japanese
+ * {@code JapaneseImperialCalendar} implements a Japanese
  * calendar system in which the imperial era-based year numbering is
  * supported from the Meiji era. The following are the eras supported
  * by this calendar system.
- * <pre><tt>
+ * <pre>{@code
  * ERA value   Era name    Since (in Gregorian)
  * ------------------------------------------------------
  *     0       N/A         N/A
- *     1       Meiji       1868-01-01 midnight local time
- *     2       Taisho      1912-07-30 midnight local time
- *     3       Showa       1926-12-25 midnight local time
- *     4       Heisei      1989-01-08 midnight local time
+ *     1       Meiji       1868-01-01T00:00:00 local time
+ *     2       Taisho      1912-07-30T00:00:00 local time
+ *     3       Showa       1926-12-25T00:00:00 local time
+ *     4       Heisei      1989-01-08T00:00:00 local time
  *     5       Reiwa       2019-05-01T00:00:00 local time
  * ------------------------------------------------------
- * </tt></pre>
+ * }</pre>
  *
  * <p><code>ERA</code> value 0 specifies the years before Meiji and
  * the Gregorian year values are used. Unlike {@link
@@ -108,7 +108,6 @@
     private static final int REIWA = 5;
 
     private static final int EPOCH_OFFSET   = 719163; // Fixed date of January 1, 1970 (Gregorian)
-    private static final int EPOCH_YEAR     = 1970;
 
     // Useful millisecond constants.  Although ONE_DAY and ONE_WEEK can fit
     // into ints, they must be longs in order to prevent arithmetic overflow
@@ -354,6 +353,7 @@
      * <code>false</code> otherwise.
      * @see Calendar#compareTo(Calendar)
      */
+    @Override
     public boolean equals(Object obj) {
         return obj instanceof JapaneseImperialCalendar &&
             super.equals(obj);
@@ -363,6 +363,7 @@
      * Generates the hash code for this
      * <code>JapaneseImperialCalendar</code> object.
      */
+    @Override
     public int hashCode() {
         return super.hashCode() ^ jdate.hashCode();
     }
@@ -395,6 +396,7 @@
      * or if any calendar fields have out-of-range values in
      * non-lenient mode.
      */
+    @Override
     public void add(int field, int amount) {
         // If amount == 0, do nothing even the given field is out of
         // range. This is tested by JCK.
@@ -523,6 +525,7 @@
         }
     }
 
+    @Override
     public void roll(int field, boolean up) {
         roll(field, up ? +1 : -1);
     }
@@ -547,6 +550,7 @@
      * @see #add(int,int)
      * @see #set(int,int)
      */
+    @Override
     public void roll(int field, int amount) {
         // If amount == 0, do nothing even the given field is out of
         // range. This is tested by JCK.
--- a/src/share/classes/sun/java2d/pisces/PiscesCache.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/java2d/pisces/PiscesCache.java	Fri May 24 04:01:22 2019 +0100
@@ -167,6 +167,15 @@
         rowAARLE[row][1] = end;
     }
 
+    void getBBox(int bbox[]) {
+        // Since we add +1 to bboxX1,bboxY1 so when PTG asks for bbox,
+        // we will give after -1
+        bbox[0] = bboxX0;
+        bbox[1] = bboxY0;
+        bbox[2] = bboxX1 - 1;
+        bbox[3] = bboxY1 - 1;
+    }
+
     @Override
     public String toString() {
         String ret = "bbox = ["+
--- a/src/share/classes/sun/java2d/pisces/PiscesTileGenerator.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/java2d/pisces/PiscesTileGenerator.java	Fri May 24 04:01:22 2019 +0100
@@ -76,10 +76,7 @@
     }
 
     public void getBbox(int bbox[]) {
-        bbox[0] = cache.bboxX0;
-        bbox[1] = cache.bboxY0;
-        bbox[2] = cache.bboxX1;
-        bbox[3] = cache.bboxY1;
+        cache.getBBox(bbox);
         //System.out.println("bbox["+bbox[0]+", "+bbox[1]+" => "+bbox[2]+", "+bbox[3]+"]");
     }
 
--- a/src/share/classes/sun/security/ssl/SSLContextImpl.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/security/ssl/SSLContextImpl.java	Fri May 24 04:01:22 2019 +0100
@@ -873,12 +873,20 @@
         }
 
         private static TrustManager[] getTrustManagers() throws Exception {
-            KeyStore ks =
-                TrustManagerFactoryImpl.getCacertsKeyStore("defaultctx");
+            TrustManagerFactory tmf = TrustManagerFactory.getInstance(
+                    TrustManagerFactory.getDefaultAlgorithm());
+            if ("SunJSSE".equals(tmf.getProvider().getName())) {
+                // The implementation will load the default KeyStore
+                // automatically.  Cached trust materials may be used
+                // for performance improvement.
+                tmf.init((KeyStore)null);
+            } else {
+                // Use the explicitly specified KeyStore for third party's
+                // TrustManagerFactory implementation.
+                KeyStore ks = TrustStoreManager.getTrustedKeyStore();
+                tmf.init(ks);
+            }
 
-            TrustManagerFactory tmf = TrustManagerFactory.getInstance(
-                TrustManagerFactory.getDefaultAlgorithm());
-            tmf.init(ks);
             return tmf.getTrustManagers();
         }
 
--- a/src/share/classes/sun/security/ssl/TrustManagerFactoryImpl.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/security/ssl/TrustManagerFactoryImpl.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -32,6 +32,7 @@
 import javax.net.ssl.*;
 
 import sun.security.validator.Validator;
+import sun.security.validator.TrustStoreUtil;
 
 abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
 
@@ -47,7 +48,7 @@
     protected void engineInit(KeyStore ks) throws KeyStoreException {
         if (ks == null) {
             try {
-                ks = getCacertsKeyStore("trustmanager");
+                trustManager = getInstance(TrustStoreManager.getTrustedCerts());
             } catch (SecurityException se) {
                 // eat security exceptions but report other throwables
                 if (debug != null && Debug.isOn("trustmanager")) {
@@ -72,14 +73,17 @@
                         "SunX509: skip default keystore: " + e);
                 }
                 throw new KeyStoreException(
-                    "problem accessing trust store" + e);
+                    "problem accessing trust store", e);
             }
+        } else {
+            trustManager = getInstance(TrustStoreUtil.getTrustedCerts(ks));
         }
-        trustManager = getInstance(ks);
+
         isInitialized = true;
     }
 
-    abstract X509TrustManager getInstance(KeyStore ks) throws KeyStoreException;
+    abstract X509TrustManager getInstance(
+            Collection<X509Certificate> trustedCerts);
 
     abstract X509TrustManager getInstance(ManagerFactoryParameters spec)
             throws InvalidAlgorithmParameterException;
@@ -126,131 +130,14 @@
                 });
     }
 
-    /**
-     * Returns the keystore with the configured CA certificates.
-     */
-    static KeyStore getCacertsKeyStore(String dbgname) throws Exception
-    {
-        String storeFileName = null;
-        File storeFile = null;
-        FileInputStream fis = null;
-        String defaultTrustStoreType;
-        String defaultTrustStoreProvider;
-        final HashMap<String,String> props = new HashMap<>();
-        final String sep = File.separator;
-        KeyStore ks = null;
-
-        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
-            @Override
-            public Void run() throws Exception {
-                props.put("trustStore", System.getProperty(
-                                "javax.net.ssl.trustStore"));
-                props.put("javaHome", System.getProperty(
-                                        "java.home"));
-                props.put("trustStoreType", System.getProperty(
-                                "javax.net.ssl.trustStoreType",
-                                KeyStore.getDefaultType()));
-                props.put("trustStoreProvider", System.getProperty(
-                                "javax.net.ssl.trustStoreProvider", ""));
-                props.put("trustStorePasswd", System.getProperty(
-                                "javax.net.ssl.trustStorePassword", ""));
-                return null;
-            }
-        });
-
-        /*
-         * Try:
-         *      javax.net.ssl.trustStore  (if this variable exists, stop)
-         *      jssecacerts
-         *      cacerts (system and local)
-         *
-         * If none exists, we use an empty keystore.
-         */
-
-        try {
-            storeFileName = props.get("trustStore");
-            if (!"NONE".equals(storeFileName)) {
-                if (storeFileName != null) {
-                    storeFile = new File(storeFileName);
-                    fis = getFileInputStream(storeFile);
-                } else {
-                    String javaHome = props.get("javaHome");
-                    storeFile = new File(javaHome + sep + "lib" + sep
-                                         + "security" + sep +
-                                         "jssecacerts");
-                    if ((fis = getFileInputStream(storeFile)) == null) {
-                        /* Check system cacerts DB first; /etc/pki/java/cacerts */
-                        storeFile = new File(sep + "etc" + sep + "pki" + sep
-                                             + "java" + sep + "cacerts");
-                        if ((fis = getFileInputStream(storeFile)) == null) {
-                            storeFile = new File(javaHome + sep + "lib" + sep
-                                                 + "security" + sep +
-                                                 "cacerts");
-                            fis = getFileInputStream(storeFile);
-                        }
-                    }
-                }
-
-                if (fis != null) {
-                    storeFileName = storeFile.getPath();
-                } else {
-                    storeFileName = "No File Available, using empty keystore.";
-                }
-            }
-
-            defaultTrustStoreType = props.get("trustStoreType");
-            defaultTrustStoreProvider = props.get("trustStoreProvider");
-            if (debug != null && Debug.isOn(dbgname)) {
-                System.out.println("trustStore is: " + storeFileName);
-                System.out.println("trustStore type is : " +
-                                    defaultTrustStoreType);
-                System.out.println("trustStore provider is : " +
-                                    defaultTrustStoreProvider);
-            }
-
-            /*
-             * Try to initialize trust store.
-             */
-            if (defaultTrustStoreType.length() != 0) {
-                if (debug != null && Debug.isOn(dbgname)) {
-                    System.out.println("init truststore");
-                }
-                if (defaultTrustStoreProvider.length() == 0) {
-                    ks = KeyStore.getInstance(defaultTrustStoreType);
-                } else {
-                    ks = KeyStore.getInstance(defaultTrustStoreType,
-                                            defaultTrustStoreProvider);
-                }
-                char[] passwd = null;
-                String defaultTrustStorePassword =
-                        props.get("trustStorePasswd");
-                if (defaultTrustStorePassword.length() != 0)
-                    passwd = defaultTrustStorePassword.toCharArray();
-
-                // if trustStore is NONE, fis will be null
-                ks.load(fis, passwd);
-
-                // Zero out the temporary password storage
-                if (passwd != null) {
-                    for (int i = 0; i < passwd.length; i++) {
-                        passwd[i] = (char)0;
-                    }
-                }
-            }
-        } finally {
-            if (fis != null) {
-                fis.close();
-            }
+    public static final class SimpleFactory extends TrustManagerFactoryImpl {
+        @Override
+        X509TrustManager getInstance(
+                Collection<X509Certificate> trustedCerts) {
+            return new X509TrustManagerImpl(
+                    Validator.TYPE_SIMPLE, trustedCerts);
         }
 
-        return ks;
-    }
-
-    public static final class SimpleFactory extends TrustManagerFactoryImpl {
-        @Override
-        X509TrustManager getInstance(KeyStore ks) throws KeyStoreException {
-            return new X509TrustManagerImpl(Validator.TYPE_SIMPLE, ks);
-        }
         @Override
         X509TrustManager getInstance(ManagerFactoryParameters spec)
                 throws InvalidAlgorithmParameterException {
@@ -258,13 +145,15 @@
                 ("SunX509 TrustManagerFactory does not use "
                 + "ManagerFactoryParameters");
         }
-   }
+    }
 
     public static final class PKIXFactory extends TrustManagerFactoryImpl {
         @Override
-        X509TrustManager getInstance(KeyStore ks) throws KeyStoreException {
-            return new X509TrustManagerImpl(Validator.TYPE_PKIX, ks);
+        X509TrustManager getInstance(
+                Collection<X509Certificate> trustedCerts) {
+            return new X509TrustManagerImpl(Validator.TYPE_PKIX, trustedCerts);
         }
+
         @Override
         X509TrustManager getInstance(ManagerFactoryParameters spec)
                 throws InvalidAlgorithmParameterException {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/sun/security/ssl/TrustStoreManager.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,400 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.ssl;
+
+import java.lang.ref.WeakReference;
+import java.io.*;
+import java.util.*;
+
+import java.security.*;
+import java.security.cert.*;
+import java.security.cert.Certificate;
+
+import sun.security.action.*;
+import sun.security.validator.TrustStoreUtil;
+
+/**
+ * Collection of static utility methods to manage the default trusted KeyStores
+ * effectively.
+ */
+final class TrustStoreManager {
+    private static final Debug debug = Debug.getInstance("ssl");
+
+    // A singleton service to manage the default trusted KeyStores effectively.
+    private static final TrustAnchorManager tam = new TrustAnchorManager();
+
+    // Restrict instantiation of this class.
+    private TrustStoreManager() {
+        // empty
+    }
+
+    /**
+     * Return an unmodifiable set of all trusted X509Certificates contained
+     * in the default trusted KeyStore.
+     */
+    public static Set<X509Certificate> getTrustedCerts() throws Exception {
+        return tam.getTrustedCerts(TrustStoreDescriptor.createInstance());
+    }
+
+    /**
+     * Return an instance of the default trusted KeyStore.
+     */
+    public static KeyStore getTrustedKeyStore() throws Exception {
+        return tam.getKeyStore(TrustStoreDescriptor.createInstance());
+    }
+
+    /**
+     * A descriptor of the default trusted KeyStore.
+     *
+     * The preference of the default trusted KeyStore is:
+     *    javax.net.ssl.trustStore
+     *    jssecacerts
+     *    cacerts (system and local)
+     */
+    private static final class TrustStoreDescriptor {
+        private static final String fileSep = File.separator;
+        private static final String defaultStorePath =
+                GetPropertyAction.privilegedGetProperty("java.home") +
+                fileSep + "lib" + fileSep + "security";
+        private static final String defaultStore =
+                defaultStorePath + fileSep + "cacerts";
+        private static final String jsseDefaultStore =
+                defaultStorePath + fileSep + "jssecacerts";
+        /* Check system cacerts DB: /etc/pki/java/cacerts */
+        private static final String systemStore =
+                fileSep + "etc" + fileSep + "pki" +
+                fileSep + "java" + fileSep + "cacerts";
+
+        // the trust store name
+        private final String storeName;
+
+        // the trust store type, JKS/PKCS12
+        private final String storeType;
+
+        // the provider of the trust store
+        private final String storeProvider;
+
+        // the password used for the trust store
+        private final String storePassword;
+
+        // the File object of the trust store
+        private final File storeFile;
+
+        // the last modified time of the store
+        private final long lastModified;
+
+        private TrustStoreDescriptor(String storeName, String storeType,
+                String storeProvider, String storePassword,
+                File storeFile, long lastModified) {
+            this.storeName = storeName;
+            this.storeType = storeType;
+            this.storeProvider = storeProvider;
+            this.storePassword = storePassword;
+            this.storeFile = storeFile;
+            this.lastModified = lastModified;
+
+            if (debug != null && Debug.isOn("trustmanager")) {
+                System.out.println(
+                    "trustStore is: " + storeName + "\n" +
+                    "trustStore type is: " + storeType + "\n" +
+                    "trustStore provider is: " + storeProvider + "\n" +
+                    "the last modified time is: " + (new Date(lastModified)));
+            }
+        }
+
+        /**
+         * Create an instance of TrustStoreDescriptor for the default
+         * trusted KeyStore.
+         */
+        static TrustStoreDescriptor createInstance() {
+             return AccessController.doPrivileged(new PrivilegedAction<TrustStoreDescriptor>() {
+
+                @Override
+                public TrustStoreDescriptor run() {
+                    // Get the system properties for trust store.
+                    String storePropName = System.getProperty(
+                            "javax.net.ssl.trustStore", jsseDefaultStore);
+                    String storePropType = System.getProperty(
+                            "javax.net.ssl.trustStoreType",
+                            KeyStore.getDefaultType());
+                    String storePropProvider = System.getProperty(
+                            "javax.net.ssl.trustStoreProvider", "");
+                    String storePropPassword = System.getProperty(
+                            "javax.net.ssl.trustStorePassword", "");
+
+                    String temporaryName = "";
+                    File temporaryFile = null;
+                    long temporaryTime = 0L;
+                    if (!"NONE".equals(storePropName)) {
+                        String[] fileNames =
+                                new String[] {storePropName,
+                                              systemStore, defaultStore};
+                        for (String fileName : fileNames) {
+                            File f = new File(fileName);
+                            if (f.isFile() && f.canRead()) {
+                                temporaryName = fileName;;
+                                temporaryFile = f;
+                                temporaryTime = f.lastModified();
+
+                                break;
+                            }
+
+                            // Not break, the file is inaccessible.
+                            if (debug != null &&
+                                    Debug.isOn("trustmanager")) {
+                                System.out.println(
+                                    "Inaccessible trust store: " +
+                                    storePropName);
+                            }
+                        }
+                    } else {
+                        temporaryName = storePropName;
+                    }
+
+                    return new TrustStoreDescriptor(
+                            temporaryName, storePropType, storePropProvider,
+                            storePropPassword, temporaryFile, temporaryTime);
+                }
+            });
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == this) {
+                return true;
+            }
+
+            if (obj instanceof TrustStoreDescriptor) {
+                TrustStoreDescriptor that = (TrustStoreDescriptor)obj;
+                return ((this.lastModified == that.lastModified) &&
+                    Objects.equals(this.storeName, that.storeName) &&
+                    Objects.equals(this.storeType, that.storeType) &&
+                    Objects.equals(this.storeProvider, that.storeProvider));
+            }
+
+            return false;
+        }
+
+
+        // Please be careful if computing security-sensitive attributes'
+        // hash code.  For example the storePassword should not be computed.
+        @Override
+        public int hashCode() {
+            int result = 17;
+
+            if (storeName != null && !storeName.isEmpty()) {
+                result = 31 * result + storeName.hashCode();
+            }
+
+            if (storeType != null && !storeType.isEmpty()) {
+                result = 31 * result + storeType.hashCode();
+            }
+
+            if (storeProvider != null && !storeProvider.isEmpty()) {
+                result = 31 * result + storeProvider.hashCode();
+            }
+
+            if (storeFile != null) {
+                result = 31 * result + storeFile.hashCode();
+            }
+
+            if (lastModified != 0L) {
+                result = (int)(31 * result + lastModified);
+            }
+
+            return result;
+        }
+    }
+
+    /**
+     * The trust anchors manager used to expedite the performance.
+     *
+     * This class can be used to provide singleton services to access default
+     * trust KeyStore more effectively.
+     */
+    private static final class TrustAnchorManager {
+        // Last trust store descriptor.
+        private TrustStoreDescriptor descriptor;
+
+        // The key store used for the trust anchors.
+        //
+        // Use weak reference so that the heavy loaded KeyStore object can
+        // be atomically cleared, and reloaded if needed.
+        private WeakReference<KeyStore> ksRef;
+
+        // The trusted X.509 certificates in the key store.
+        //
+        // Use weak reference so that the heavy loaded certificates collection
+        // objects can be atomically cleared, and reloaded if needed.
+        private WeakReference<Set<X509Certificate>> csRef;
+
+        private TrustAnchorManager() {
+            this.descriptor = null;
+            this.ksRef = new WeakReference<>(null);
+            this.csRef = new WeakReference<>(null);
+        }
+
+        /**
+         * Get the default trusted KeyStore with the specified descriptor.
+         *
+         * @return null if the underlying KeyStore is not available.
+         */
+        synchronized KeyStore getKeyStore(
+                TrustStoreDescriptor descriptor) throws Exception {
+
+            TrustStoreDescriptor temporaryDesc = this.descriptor;
+            KeyStore ks = ksRef.get();
+            if ((ks != null) && descriptor.equals(temporaryDesc)) {
+                return ks;
+            }
+
+            // Reload a new key store.
+            if ((debug != null) && Debug.isOn("trustmanager")) {
+                System.out.println("Reload the trust store");
+            }
+
+            ks = loadKeyStore(descriptor);
+            this.descriptor = descriptor;
+            this.ksRef = new WeakReference<>(ks);
+
+            return ks;
+        }
+
+        /**
+         * Get trusted certificates in the default trusted KeyStore with
+         * the specified descriptor.
+         *
+         * @return empty collection if the underlying KeyStore is not available.
+         */
+        synchronized Set<X509Certificate> getTrustedCerts(
+                TrustStoreDescriptor descriptor) throws Exception {
+
+            KeyStore ks = null;
+            TrustStoreDescriptor temporaryDesc = this.descriptor;
+            Set<X509Certificate> certs = csRef.get();
+            if (certs != null) {
+                if (descriptor.equals(temporaryDesc)) {
+                    return certs;
+                } else {
+                    // Use the new descriptor.
+                    this.descriptor = descriptor;
+                }
+            } else {
+                // Try to use the cached store at first.
+                if (descriptor.equals(temporaryDesc)) {
+                    ks = ksRef.get();
+                } else {
+                    // Use the new descriptor.
+                    this.descriptor = descriptor;
+                }
+            }
+
+            // Reload the trust store if needed.
+            if (ks == null) {
+                if ((debug != null) && Debug.isOn("trustmanager")) {
+                    System.out.println("Reload the trust store");
+                }
+                ks = loadKeyStore(descriptor);
+            }
+
+            // Reload trust certs from the key store.
+            if ((debug != null) && Debug.isOn("trustmanager")) {
+                System.out.println("Reload trust certs");
+            }
+
+            certs = loadTrustedCerts(ks);
+            if ((debug != null) && Debug.isOn("trustmanager")) {
+                System.out.println("Reloaded " + certs.size() + " trust certs");
+            }
+
+            // Note that as ks is a local variable, it is not
+            // necessary to add it to the ksRef weak reference.
+            this.csRef = new WeakReference<>(certs);
+
+            return certs;
+        }
+
+        /**
+         * Load the the KeyStore as described in the specified descriptor.
+         */
+        private static KeyStore loadKeyStore(
+                TrustStoreDescriptor descriptor) throws Exception {
+            if (!"NONE".equals(descriptor.storeName) &&
+                    descriptor.storeFile == null) {
+
+                // No file available, no KeyStore available.
+                if (debug != null && Debug.isOn("trustmanager")) {
+                    System.out.println("No available key store");
+                }
+
+                return null;
+            }
+
+            KeyStore ks;
+            if (descriptor.storeProvider.isEmpty()) {
+                ks = KeyStore.getInstance(descriptor.storeType);
+            } else {
+                ks = KeyStore.getInstance(
+                        descriptor.storeType, descriptor.storeProvider);
+            }
+
+            char[] password = null;
+            if (!descriptor.storePassword.isEmpty()) {
+                password = descriptor.storePassword.toCharArray();
+            }
+
+            if (!"NONE".equals(descriptor.storeName)) {
+                try (FileInputStream fis = AccessController.doPrivileged(
+                        new OpenFileInputStreamAction(descriptor.storeFile))) {
+                    ks.load(fis, password);
+                } catch (FileNotFoundException fnfe) {
+                    // No file available, no KeyStore available.
+                    if (debug != null && Debug.isOn("trustmanager")) {
+                        System.out.println(
+                            "Not available key store: " + descriptor.storeName);
+                    }
+
+                    return null;
+                }
+            } else {
+                ks.load(null, password);
+            }
+
+            return ks;
+        }
+
+        /**
+         * Load trusted certificates from the specified KeyStore.
+         */
+        private static Set<X509Certificate> loadTrustedCerts(KeyStore ks) {
+            if (ks == null) {
+                return Collections.<X509Certificate>emptySet();
+            }
+
+            return TrustStoreUtil.getTrustedCerts(ks);
+        }
+    }
+}
--- a/src/share/classes/sun/security/ssl/X509TrustManagerImpl.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/security/ssl/X509TrustManagerImpl.java	Fri May 24 04:01:22 2019 +0100
@@ -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
@@ -68,16 +68,21 @@
 
     private static final Debug debug = Debug.getInstance("ssl");
 
-    X509TrustManagerImpl(String validatorType, KeyStore ks)
-            throws KeyStoreException {
+    X509TrustManagerImpl(String validatorType,
+            Collection<X509Certificate> trustedCerts) {
+
         this.validatorType = validatorType;
         this.pkixParams = null;
-        if (ks == null) {
+
+        if (trustedCerts == null) {
             trustedCerts = Collections.<X509Certificate>emptySet();
-        } else {
-            trustedCerts = KeyStores.getTrustedCerts(ks);
         }
-        showTrustedCerts();
+
+        this.trustedCerts = trustedCerts;
+
+        if (debug != null && Debug.isOn("trustmanager")) {
+            showTrustedCerts();
+        }
     }
 
     X509TrustManagerImpl(String validatorType, PKIXBuilderParameters params) {
@@ -90,7 +95,10 @@
         Validator v = getValidator(Validator.VAR_TLS_SERVER);
         trustedCerts = v.getTrustedCertificates();
         serverValidator = v;
-        showTrustedCerts();
+
+        if (debug != null && Debug.isOn("trustmanager")) {
+            showTrustedCerts();
+        }
     }
 
     @Override
@@ -287,22 +295,20 @@
     }
 
     private void showTrustedCerts() {
-        if (debug != null && Debug.isOn("trustmanager")) {
-            for (X509Certificate cert : trustedCerts) {
-                System.out.println("adding as trusted cert:");
-                System.out.println("  Subject: "
-                                        + cert.getSubjectX500Principal());
-                System.out.println("  Issuer:  "
-                                        + cert.getIssuerX500Principal());
-                System.out.println("  Algorithm: "
-                                        + cert.getPublicKey().getAlgorithm()
-                                        + "; Serial number: 0x"
-                                        + cert.getSerialNumber().toString(16));
-                System.out.println("  Valid from "
-                                        + cert.getNotBefore() + " until "
-                                        + cert.getNotAfter());
-                System.out.println();
-            }
+        for (X509Certificate cert : trustedCerts) {
+            System.out.println("adding as trusted cert:");
+            System.out.println("  Subject: "
+                                    + cert.getSubjectX500Principal());
+            System.out.println("  Issuer:  "
+                                    + cert.getIssuerX500Principal());
+            System.out.println("  Algorithm: "
+                                    + cert.getPublicKey().getAlgorithm()
+                                    + "; Serial number: 0x"
+                                    + cert.getSerialNumber().toString(16));
+            System.out.println("  Valid from "
+                                    + cert.getNotBefore() + " until "
+                                    + cert.getNotAfter());
+            System.out.println();
         }
     }
 
--- a/src/share/classes/sun/security/validator/KeyStores.java	Mon Apr 22 17:30:12 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.security.validator;
-
-import java.io.*;
-import java.util.*;
-
-import java.security.*;
-import java.security.cert.*;
-import java.security.cert.Certificate;
-
-import sun.security.action.*;
-
-/**
- * Collection of static utility methods related to KeyStores.
- *
- * @author Andreas Sterbenz
- */
-public class KeyStores {
-
-    private KeyStores() {
-        // empty
-    }
-
-    // in the future, all accesses to the system cacerts keystore should
-    // go through this class. but not right now.
-/*
-    private final static String javaHome =
-        (String)AccessController.doPrivileged(new GetPropertyAction("java.home"));
-
-    private final static char SEP = File.separatorChar;
-
-    private static KeyStore caCerts;
-
-    private static KeyStore getKeyStore(String type, String name,
-            char[] password) throws IOException {
-        if (type == null) {
-            type = "JKS";
-        }
-        try {
-            KeyStore ks = KeyStore.getInstance(type);
-            FileInputStream in = (FileInputStream)AccessController.doPrivileged
-                                        (new OpenFileInputStreamAction(name));
-            ks.load(in, password);
-            return ks;
-        } catch (GeneralSecurityException e) {
-            // XXX
-            throw new IOException();
-        } catch (PrivilegedActionException e) {
-            throw (IOException)e.getCause();
-        }
-    }
-
-    /**
-     * Return a KeyStore with the contents of the lib/security/cacerts file.
-     * The file is only opened once per JVM invocation and the contents
-     * cached subsequently.
-     *
-    public synchronized static KeyStore getCaCerts() throws IOException {
-        if (caCerts != null) {
-            return caCerts;
-        }
-        String name = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
-        caCerts = getKeyStore(null, name, null);
-        return caCerts;
-    }
-*/
-
-    /**
-     * Return a Set with all trusted X509Certificates contained in
-     * this KeyStore.
-     */
-    public static Set<X509Certificate> getTrustedCerts(KeyStore ks) {
-        Set<X509Certificate> set = new HashSet<X509Certificate>();
-        try {
-            for (Enumeration<String> e = ks.aliases(); e.hasMoreElements(); ) {
-                String alias = e.nextElement();
-                if (ks.isCertificateEntry(alias)) {
-                    Certificate cert = ks.getCertificate(alias);
-                    if (cert instanceof X509Certificate) {
-                        set.add((X509Certificate)cert);
-                    }
-                } else if (ks.isKeyEntry(alias)) {
-                    Certificate[] certs = ks.getCertificateChain(alias);
-                    if ((certs != null) && (certs.length > 0) &&
-                            (certs[0] instanceof X509Certificate)) {
-                        set.add((X509Certificate)certs[0]);
-                    }
-                }
-            }
-        } catch (KeyStoreException e) {
-            // ignore
-        }
-        return set;
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/sun/security/validator/TrustStoreUtil.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.validator;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.cert.X509Certificate;
+import java.security.cert.Certificate;
+
+/**
+ * Collection of static utility methods related to trust anchor KeyStores.
+ *
+ * @author Andreas Sterbenz
+ */
+public final class TrustStoreUtil {
+
+    private TrustStoreUtil() {
+        // empty
+    }
+
+    /**
+     * Return an unmodifiable Set with all trusted X509Certificates contained
+     * in the specified KeyStore.
+     */
+    public static Set<X509Certificate> getTrustedCerts(KeyStore ks) {
+        Set<X509Certificate> set = new HashSet<>();
+        try {
+            for (Enumeration<String> e = ks.aliases(); e.hasMoreElements(); ) {
+                String alias = e.nextElement();
+                if (ks.isCertificateEntry(alias)) {
+                    Certificate cert = ks.getCertificate(alias);
+                    if (cert instanceof X509Certificate) {
+                        set.add((X509Certificate)cert);
+                    }
+                } else if (ks.isKeyEntry(alias)) {
+                    Certificate[] certs = ks.getCertificateChain(alias);
+                    if ((certs != null) && (certs.length > 0) &&
+                            (certs[0] instanceof X509Certificate)) {
+                        set.add((X509Certificate)certs[0]);
+                    }
+                }
+            }
+        } catch (KeyStoreException e) {
+            // ignore
+            //
+            // This should be rare, but better to log this in the future.
+        }
+
+        return Collections.unmodifiableSet(set);
+    }
+}
--- a/src/share/classes/sun/security/validator/Validator.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/security/validator/Validator.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -166,7 +166,7 @@
      */
     public static Validator getInstance(String type, String variant,
             KeyStore ks) {
-        return getInstance(type, variant, KeyStores.getTrustedCerts(ks));
+        return getInstance(type, variant, TrustStoreUtil.getTrustedCerts(ks));
     }
 
     /**
--- a/src/share/classes/sun/util/calendar/Era.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/share/classes/sun/util/calendar/Era.java	Fri May 24 04:01:22 2019 +0100
@@ -41,21 +41,16 @@
  * <code>CalendarDate</code>.
  *
  * <p>The following era names are defined in this release.
- * <!-- TODO: use HTML table -->
- * <pre><tt>
+ * <pre>{@code
  *   Calendar system         Era name         Since (in Gregorian)
  *   -----------------------------------------------------------------------
- *   Japanese calendar       Meiji            1868-01-01 midnight local time
- *                           Taisho           1912-07-30 midnight local time
- *                           Showa            1926-12-26 midnight local time
- *                           Heisei           1989-01-08 midnight local time
+ *   Japanese calendar       Meiji            1868-01-01T00:00:00 local time
+ *                           Taisho           1912-07-30T00:00:00 local time
+ *                           Showa            1926-12-25T00:00:00 local time
+ *                           Heisei           1989-01-08T00:00:00 local time
  *                           Reiwa            2019-05-01T00:00:00 local time
- *   Julian calendar         BeforeCommonEra  -292275055-05-16T16:47:04.192Z
- *                           CommonEra        0000-12-30 midnight local time
- *   Taiwanese calendar      MinGuo           1911-01-01 midnight local time
- *   Thai Buddhist calendar  BuddhistEra      -543-01-01 midnight local time
  *   -----------------------------------------------------------------------
- * </tt></pre>
+ * }</pre>
  *
  * @author Masayoshi Okutsu
  * @since 1.5
--- a/src/solaris/classes/sun/awt/X11/XWindow.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/solaris/classes/sun/awt/X11/XWindow.java	Fri May 24 04:01:22 2019 +0100
@@ -446,14 +446,7 @@
             if (!doEraseBackground()) {
                 return;
             }
-            // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set
-            // Note: When OGL is enabled, surfaceData.pixelFor() will not
-            // return a pixel value appropriate for passing to
-            // XSetWindowBackground().  Therefore, we will use the ColorModel
-            // for this component in order to calculate a pixel value from
-            // the given RGB value.
-            ColorModel cm = getColorModel();
-            int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm);
+            int pixel = surfaceData.pixelFor(c.getRGB());
             XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel);
             XlibWrapper.XClearWindow(XToolkit.getDisplay(), getContentWindow());
         }
--- a/src/solaris/native/sun/awt/gtk3_interface.c	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/solaris/native/sun/awt/gtk3_interface.c	Fri May 24 04:01:22 2019 +0100
@@ -258,6 +258,7 @@
 
 static gboolean gtk3_version_3_10 = TRUE;
 static gboolean gtk3_version_3_14 = FALSE;
+static gboolean gtk3_version_3_20 = FALSE;
 
 GtkApi* gtk3_load(JNIEnv *env, const char* lib_name)
 {
@@ -400,6 +401,18 @@
         }
         gtk3_version_3_14 = !fp_gtk_check_version(3, 14, 0);
 
+        if (!fp_gtk_check_version(3, 20, 0)) {
+            gtk3_version_3_20 = TRUE;
+            fp_gtk_widget_path_copy = dl_symbol("gtk_widget_path_copy");
+            fp_gtk_widget_path_new = dl_symbol("gtk_widget_path_new");
+            fp_gtk_widget_path_append_type = dl_symbol("gtk_widget_path_append_type");
+            fp_gtk_widget_path_iter_set_object_name = dl_symbol("gtk_widget_path_iter_set_object_name");
+            fp_gtk_style_context_set_path = dl_symbol("gtk_style_context_set_path");
+            fp_gtk_widget_path_unref = dl_symbol("gtk_widget_path_unref");
+            fp_gtk_style_context_get_path = dl_symbol("gtk_style_context_get_path");
+            fp_gtk_style_context_new = dl_symbol("gtk_style_context_new");
+        }
+
         fp_gdk_window_create_similar_surface =
                       dl_symbol("gdk_window_create_similar_surface");
         fp_gtk_settings_get_for_screen =
@@ -561,7 +574,6 @@
                                                 "gtk_combo_box_new_with_entry");
         fp_gtk_separator_tool_item_new = dlsym(gtk3_libhandle,
                                                  "gtk_separator_tool_item_new");
-
         fp_g_list_append = dl_symbol("g_list_append");
         fp_g_list_free = dl_symbol("g_list_free");
         fp_g_list_free_full = dl_symbol("g_list_free_full");
@@ -1362,6 +1374,90 @@
     return result;
 }
 
+static void append_element (GtkWidgetPath *path, const gchar *selector)
+{
+    fp_gtk_widget_path_append_type (path, G_TYPE_NONE);
+    fp_gtk_widget_path_iter_set_object_name (path, -1, selector);
+}
+
+static GtkWidgetPath* createWidgetPath(const GtkWidgetPath* path) {
+    if (path == NULL) {
+        return fp_gtk_widget_path_new();
+    } else {
+        return fp_gtk_widget_path_copy(path);
+    }
+}
+
+static GtkStyleContext* get_style(WidgetType widget_type, const gchar *detail)
+{
+    if (!gtk3_version_3_20) {
+        gtk3_widget = gtk3_get_widget(widget_type);
+        GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
+        fp_gtk_style_context_save (context);
+        if (detail != 0) {
+             transform_detail_string(detail, context);
+        }
+        return context;
+    } else {
+        gtk3_widget = gtk3_get_widget(widget_type);
+        GtkStyleContext* widget_context = fp_gtk_widget_get_style_context (gtk3_widget);
+        GtkWidgetPath *path = NULL;
+        if (detail != 0) {
+            if (strcmp(detail, "checkbutton") == 0) {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, "check");
+            } else if (strcmp(detail, "radiobutton") == 0) {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, "radio");
+            } else if (strcmp(detail, "vscale") == 0 || strcmp(detail, "hscale") == 0) {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, "slider");
+            } else if (strcmp(detail, "trough") == 0) {
+                //This is a fast solution to the scrollbar trough not being rendered properly
+                if (widget_type == HSCROLL_BAR || widget_type == HSCROLL_BAR_TRACK ||
+                    widget_type == VSCROLL_BAR || widget_type == VSCROLL_BAR_TRACK) {
+                    path = createWidgetPath (NULL);
+                } else {
+                    path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                }
+                append_element(path, detail);
+            } else if (strcmp(detail, "bar") == 0) {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, "trough");
+                append_element(path, "progress");
+            } else if (strcmp(detail, "vscrollbar") == 0 || strcmp(detail, "hscrollbar") == 0) {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, "button");
+            } else if (strcmp(detail, "check") == 0) {
+                path = createWidgetPath (NULL);
+                append_element(path, detail);
+            } else if (strcmp(detail, "option") == 0) {
+                path = createWidgetPath (NULL);
+                append_element(path, "radio");
+            } else {
+                path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+                append_element(path, detail);
+            }
+        } else {
+            path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
+        }
+
+        GtkStyleContext *context = fp_gtk_style_context_new ();
+        fp_gtk_style_context_set_path (context, path);
+        fp_gtk_widget_path_unref (path);
+        return context;
+    }
+}
+
+static void disposeOrRestoreContext(GtkStyleContext *context)
+{
+    if (!gtk3_version_3_20) {
+        fp_gtk_style_context_restore (context);
+    } else {
+        fp_g_object_unref (context);
+    }
+}
+
 static void gtk3_paint_arrow(WidgetType widget_type, GtkStateType state_type,
         GtkShadowType shadow_type, const gchar *detail,
         gint x, gint y, gint width, gint height,
@@ -1509,13 +1605,9 @@
      */
     gtk3_set_direction(gtk3_widget, dir);
 
-    GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
-    fp_gtk_style_context_save (context);
-
-    transform_detail_string(detail, context);
+    GtkStyleContext* context = get_style(widget_type, detail);
 
     GtkStateFlags flags = get_gtk_flags(state_type);
-
     if (shadow_type == GTK_SHADOW_IN && widget_type != COMBO_BOX_ARROW_BUTTON) {
         flags |= GTK_STATE_FLAG_ACTIVE;
     }
@@ -1532,23 +1624,31 @@
         fp_gtk_style_context_add_class (context, "default");
     }
 
+    if (fp_gtk_style_context_has_class(context, "trough")) {
+        flags |= GTK_STATE_FLAG_BACKDROP;
+    }
+
     fp_gtk_style_context_set_state (context, flags);
 
-    if (fp_gtk_style_context_has_class(context, "progressbar")) {
-        fp_gtk_render_activity (context, cr, x, y, width, height);
-    } else {
-        fp_gtk_render_background (context, cr, x, y, width, height);
-        if (shadow_type != GTK_SHADOW_NONE) {
-            fp_gtk_render_frame(context, cr, x, y, width, height);
-        }
+    fp_gtk_render_background (context, cr, x, y, width, height);
+    if (shadow_type != GTK_SHADOW_NONE) {
+        fp_gtk_render_frame(context, cr, x, y, width, height);
     }
 
-    fp_gtk_style_context_restore (context);
+    disposeOrRestoreContext(context);
+
     /*
      * Reset the text direction to the default value so that we don't
      * accidentally affect other operations and widgets.
      */
     gtk3_set_direction(gtk3_widget, GTK_TEXT_DIR_LTR);
+
+    //This is a fast solution to the scrollbar trough not being rendered properly
+    if ((widget_type == HSCROLL_BAR || widget_type == HSCROLL_BAR_TRACK ||
+        widget_type == VSCROLL_BAR || widget_type == VSCROLL_BAR_TRACK) && detail != 0) {
+        gtk3_paint_box(widget_type, state_type, shadow_type, NULL,
+                    x, y, width, height, synth_state, dir);
+    }
 }
 
 static void gtk3_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
@@ -1580,23 +1680,19 @@
 static void gtk3_paint_check(WidgetType widget_type, gint synth_state,
         const gchar *detail, gint x, gint y, gint width, gint height)
 {
-    gtk3_widget = gtk3_get_widget(widget_type);
-
-    GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
-
-    fp_gtk_style_context_save (context);
+    GtkStyleContext* context = get_style(widget_type, detail);
 
     GtkStateFlags flags = get_gtk_state_flags(synth_state);
     if (gtk3_version_3_14 && (synth_state & SELECTED)) {
-        flags = GTK_STATE_FLAG_CHECKED;
+        flags &= ~GTK_STATE_FLAG_SELECTED;
+        flags |= GTK_STATE_FLAG_CHECKED;
     }
     fp_gtk_style_context_set_state(context, flags);
 
-    fp_gtk_style_context_add_class (context, "check");
-
-    fp_gtk_render_check (context, cr, x, y, width, height);
-
-    fp_gtk_style_context_restore (context);
+    fp_gtk_render_background(context, cr, x, y, width, height);
+    fp_gtk_render_frame(context, cr, x, y, width, height);
+    fp_gtk_render_check(context, cr, x, y, width, height);
+    disposeOrRestoreContext(context);
 }
 
 
@@ -1612,7 +1708,11 @@
 
     GtkStateFlags flags = get_gtk_flags(state_type);
     if (expander_style == GTK_EXPANDER_EXPANDED) {
-        flags |= GTK_STATE_FLAG_ACTIVE;
+        if (gtk3_version_3_14) {
+            flags |= GTK_STATE_FLAG_CHECKED;
+        } else {
+            flags |= GTK_STATE_FLAG_ACTIVE;
+        }
     }
 
     fp_gtk_style_context_set_state(context, flags);
@@ -1677,14 +1777,18 @@
         (widget_type == CHECK_BOX || widget_type == RADIO_BUTTON)) {
         return;
     }
-    gtk3_widget = gtk3_get_widget(widget_type);
-
-    GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
-
-    fp_gtk_style_context_save (context);
-
-    if (detail != 0) {
-        transform_detail_string(detail, context);
+
+    GtkStyleContext* context = NULL;
+    if (widget_type == TOOL_TIP) {
+        context = get_style(widget_type, detail);
+        fp_gtk_style_context_add_class(context, "background");
+    } else {
+        gtk3_widget = gtk3_get_widget(widget_type);
+        context = fp_gtk_widget_get_style_context (gtk3_widget);
+        fp_gtk_style_context_save (context);
+        if (detail != 0) {
+            transform_detail_string(detail, context);
+        }
     }
 
     GtkStateFlags flags = get_gtk_flags(state_type);
@@ -1700,8 +1804,11 @@
     }
 
     fp_gtk_render_background (context, cr, x, y, width, height);
-
-    fp_gtk_style_context_restore (context);
+    if (widget_type == TOOL_TIP) {
+        disposeOrRestoreContext(context);
+    } else {
+        fp_gtk_style_context_restore (context);
+    }
 }
 
 static void gtk3_paint_focus(WidgetType widget_type, GtkStateType state_type,
@@ -1783,25 +1890,19 @@
 static void gtk3_paint_option(WidgetType widget_type, gint synth_state,
         const gchar *detail, gint x, gint y, gint width, gint height)
 {
-     gtk3_widget = gtk3_get_widget(widget_type);
-
-     GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
-
-     fp_gtk_style_context_save (context);
+     GtkStyleContext* context = get_style(widget_type, detail);
 
      GtkStateFlags flags = get_gtk_state_flags(synth_state);
      if (gtk3_version_3_14 && (synth_state & SELECTED)) {
-         flags = GTK_STATE_FLAG_CHECKED;
+         flags &= ~GTK_STATE_FLAG_SELECTED;
+         flags |= GTK_STATE_FLAG_CHECKED;
      }
      fp_gtk_style_context_set_state(context, flags);
 
-     if (detail != 0) {
-         transform_detail_string(detail, context);
-     }
-
+     fp_gtk_render_background(context, cr, x, y, width, height);
+     fp_gtk_render_frame(context, cr, x, y, width, height);
      fp_gtk_render_option(context, cr, x, y, width, height);
-
-     fp_gtk_style_context_restore (context);
+     disposeOrRestoreContext(context);
 }
 
 static void gtk3_paint_shadow(WidgetType widget_type, GtkStateType state_type,
@@ -1860,15 +1961,7 @@
         gint x, gint y, gint width, gint height, GtkOrientation orientation,
         gboolean has_focus)
 {
-    gtk3_widget = gtk3_get_widget(widget_type);
-
-    GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
-
-    fp_gtk_style_context_save (context);
-
-    if (detail) {
-       transform_detail_string(detail, context);
-    }
+    GtkStyleContext *context = get_style(widget_type, detail);
 
     GtkStateFlags flags = get_gtk_flags(state_type);
 
@@ -1882,9 +1975,10 @@
 
     fp_gtk_style_context_set_state (context, flags);
 
+    fp_gtk_render_background (context, cr, x, y, width, height);
+    fp_gtk_render_frame(context, cr, x, y, width, height);
     (*fp_gtk_render_slider)(context, cr, x, y, width, height, orientation);
-
-    fp_gtk_style_context_restore (context);
+    disposeOrRestoreContext(context);
 }
 
 static void gtk3_paint_background(WidgetType widget_type,
@@ -2274,12 +2368,19 @@
 
     init_containers();
 
-    gtk3_widget = gtk3_get_widget(widget_type);
-
-    GtkStyleContext* context = fp_gtk_widget_get_style_context(gtk3_widget);
-
+    if (gtk3_version_3_20) {
+        if ((widget_type == TEXT_FIELD || widget_type == PASSWORD_FIELD || widget_type == SPINNER_TEXT_FIELD ||
+            widget_type == FORMATTED_TEXT_FIELD) && state_type == GTK_STATE_SELECTED && color_type == TEXT_BACKGROUND) {
+            widget_type = TEXT_AREA;
+        }
+    }
+
+    GtkStyleContext* context = NULL;
     if (widget_type == TOOL_TIP) {
-        fp_gtk_style_context_add_class(context, "tooltip");
+        context = get_style(widget_type, "tooltip");
+    } else {
+        gtk3_widget = gtk3_get_widget(widget_type);
+        context = fp_gtk_widget_get_style_context(gtk3_widget);
     }
     if (widget_type == CHECK_BOX_MENU_ITEM
      || widget_type == RADIO_BUTTON_MENU_ITEM) {
@@ -2297,7 +2398,9 @@
 
     result = recode_color(color.alpha) << 24 | recode_color(color.red) << 16 |
              recode_color(color.green) << 8 | recode_color(color.blue);
-
+    if (widget_type == TOOL_TIP) {
+        disposeOrRestoreContext(context);
+    }
     return result;
 }
 
--- a/src/solaris/native/sun/awt/gtk3_interface.h	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/solaris/native/sun/awt/gtk3_interface.h	Fri May 24 04:01:22 2019 +0100
@@ -162,6 +162,7 @@
 typedef void GtkRange;
 typedef void GtkProgressBar;
 typedef void GtkProgress;
+typedef void GtkWidgetPath;
 
 /* Some real structures */
 typedef struct
@@ -238,7 +239,6 @@
   GType    owner_type;
 } GParamSpec;
 
-
 static gchar* (*fp_glib_check_version)(guint required_major,
                            guint required_minor, guint required_micro);
 
@@ -573,5 +573,18 @@
 static void (*fp_gtk_widget_size_request)(GtkWidget *widget,
                                           GtkRequisition *requisition);
 static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range);
+static GtkWidgetPath* (*fp_gtk_widget_path_copy)
+        (const GtkWidgetPath *path);
+static const GtkWidgetPath* (*fp_gtk_style_context_get_path)
+        (GtkStyleContext *context);
+static GtkWidgetPath* (*fp_gtk_widget_path_new) (void);
+static gint (*fp_gtk_widget_path_append_type)
+        (GtkWidgetPath *path, GType type);
+static void (*fp_gtk_widget_path_iter_set_object_name)
+        (GtkWidgetPath *path, gint pos, const char *name);
+static void (*fp_gtk_style_context_set_path)
+        (GtkStyleContext *context, GtkWidgetPath *path);
+static void (*fp_gtk_widget_path_unref) (GtkWidgetPath *path);
+static GtkStyleContext* (*fp_gtk_style_context_new) (void);
 
 #endif /* !_GTK3_INTERFACE_H */
--- a/src/solaris/native/sun/awt/multiVis.c	Mon Apr 22 17:30:12 2019 +0100
+++ b/src/solaris/native/sun/awt/multiVis.c	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/BasicStroke/DashOffset.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
+ * 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.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.awt.image.VolatileImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import javax.imageio.ImageIO;
+
+import static java.awt.image.BufferedImage.TYPE_INT_RGB;
+
+/*
+ * @test
+ * @bug 4469881 8217263
+ * @summary Verifies that dashed rectangles drawn to the screen line
+ *          up with their undashed counterparts
+ * @author flar
+ * @run main/othervm -Dsun.java2d.uiScale=1 DashOffset
+ */
+public class DashOffset {
+
+    private static final BasicStroke dash =
+            new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
+                            BasicStroke.JOIN_MITER, 10.0f,
+                            new float[] {2.0f, 2.0f}, 0.0f);
+
+    private static final Color COLOR1 = Color.BLUE;
+    private static final Color COLOR2 = Color.GREEN;
+
+    private static final Color BACKGROUND = Color.WHITE;
+
+    private static final int WIDTH = 20;
+    private static final int HEIGHT = 20;
+
+    private static final int OFFSET = 2;
+
+    private static final int MAX_DASH_LENGTH = 3;
+
+    public static void main(String[] argv) throws Exception {
+        final boolean saveImage = argv.length > 0 && "-save".equals(argv[0]);
+
+        final BufferedImage img = new BufferedImage(WIDTH, HEIGHT,
+                                                    TYPE_INT_RGB);
+        try {
+            draw(img);
+            validate(img);
+        } finally {
+            if (saveImage) {
+                save(img, "bufferedImage.png");
+            }
+        }
+
+        if (GraphicsEnvironment.isHeadless()) {
+            return;
+        }
+
+        BufferedImage snapshot = null;
+        try {
+            final GraphicsConfiguration gc =
+                    GraphicsEnvironment.getLocalGraphicsEnvironment()
+                                       .getDefaultScreenDevice()
+                                       .getDefaultConfiguration();
+
+            VolatileImage vi = gc.createCompatibleVolatileImage(WIDTH, HEIGHT);
+            int attempt = 0;
+            do {
+                vi.validate(gc);
+                draw(vi);
+                snapshot = vi.getSnapshot();
+            } while (vi.contentsLost() && ++attempt <= 10);
+            if (attempt > 10) {
+                throw new RuntimeException("Too many attempts: " + attempt);
+            }
+            validate(snapshot);
+        } finally {
+            if (saveImage) {
+                save(snapshot, "volatileImage.png");
+            }
+        }
+    }
+
+    private static void draw(final Image img) {
+        Graphics g = img.getGraphics();
+        g.setColor(BACKGROUND);
+        g.fillRect(0, 0, WIDTH, HEIGHT);
+        g.setColor(COLOR1);
+        g.drawRect(OFFSET, OFFSET, WIDTH - OFFSET * 2, HEIGHT - OFFSET * 2);
+        g.setColor(COLOR2);
+        g.clipRect(OFFSET, OFFSET, WIDTH - OFFSET * 2 + 1, HEIGHT - OFFSET * 2 + 1);
+        ((Graphics2D) g).setStroke(dash);
+        g.drawRect(OFFSET, OFFSET, WIDTH - OFFSET * 2, HEIGHT - OFFSET * 2);
+        g.dispose();
+    }
+
+    private static void validate(final BufferedImage img) {
+        checkHorizontalLine(img, OFFSET);
+        checkHorizontalLine(img, HEIGHT - OFFSET);
+        checkVerticalLine(img, OFFSET);
+        checkVerticalLine(img, WIDTH - OFFSET);
+        checkCorners(img);
+    }
+
+    private static void checkHorizontalLine(final BufferedImage img,
+                                            final int y) {
+        int prev = img.getRGB(OFFSET, y);
+        int curr;
+        int count = 1;
+        checkColor(OFFSET, y, prev, COLOR1, COLOR2);
+        for (int x = OFFSET + 1; x <= WIDTH - OFFSET; x++) {
+            curr = img.getRGB(x, y);
+            if (curr != prev) {
+                checkColor(x, y, curr, COLOR1, COLOR2);
+                checkCount(x, y, count);
+                prev = curr;
+                count = 1;
+            } else {
+                count++;
+            }
+            if (x < WIDTH - OFFSET) {
+                checkColor(x, y - 1, img.getRGB(x, y - 1), BACKGROUND);
+                checkColor(x, y + 1, img.getRGB(x, y + 1), BACKGROUND);
+            }
+        }
+        checkCount(WIDTH - OFFSET, y, count);
+    }
+
+    private static void checkVerticalLine(final BufferedImage img,
+                                          final int x) {
+        int prev = img.getRGB(x, OFFSET);
+        checkColor(x, OFFSET, prev, COLOR1, COLOR2);
+        int count = 1;
+        for (int y = OFFSET + 1; y <= HEIGHT - OFFSET; y++) {
+            int curr = img.getRGB(x, y);
+            if (curr != prev) {
+                checkColor(x, y, curr, COLOR1, COLOR2);
+                checkCount(x, y, count);
+                prev = curr;
+                count = 1;
+            } else {
+                count++;
+            }
+            if (y < HEIGHT - OFFSET) {
+                checkColor(x - 1, y, img.getRGB(x - 1, y), BACKGROUND);
+                checkColor(x + 1, y, img.getRGB(x + 1, y), BACKGROUND);
+            }
+        }
+        checkCount(x, HEIGHT - OFFSET, count);
+    }
+
+    private static void checkCorners(final BufferedImage img) {
+        int[][] corners = {
+                {OFFSET - 1, OFFSET - 1},
+                {OFFSET,     OFFSET - 1},
+                {OFFSET - 1, OFFSET + 1},
+
+                {OFFSET - 1, HEIGHT - OFFSET},
+                {OFFSET - 1, HEIGHT - OFFSET + 1},
+                {OFFSET,     HEIGHT - OFFSET + 1},
+
+                {WIDTH - OFFSET,     OFFSET - 1},
+                {WIDTH - OFFSET + 1, OFFSET - 1},
+                {WIDTH - OFFSET + 1, OFFSET},
+
+                {WIDTH - OFFSET + 1, HEIGHT - OFFSET},
+                {WIDTH - OFFSET + 1, HEIGHT - OFFSET + 1},
+                {WIDTH - OFFSET,     HEIGHT - OFFSET + 1},
+        };
+
+        for (int[] corner : corners) {
+            int color = img.getRGB(corner[0], corner[1]);
+            checkColor(corner[0], corner[1], color, BACKGROUND);
+        }
+    }
+
+    private static void checkColor(final int x, final int y,
+                                   final int color,
+                                   final Color... validColors) {
+        checkColor(x, y, color, Arrays.stream(validColors)
+                                      .mapToInt(Color::getRGB)
+                                      .toArray());
+    }
+
+    private static void checkColor(final int x, final int y,
+                                   final int color,
+                                   final int... validColors) {
+        for (int valid : validColors) {
+            if (color == valid) {
+                return;
+            }
+        }
+        throw new RuntimeException("Unexpected color at " + x + ", " + y
+                + ": " + Integer.toHexString(color) + "; expected: "
+                + Arrays.stream(validColors)
+                        .mapToObj(Integer::toHexString)
+                        .collect(Collectors.joining(", ")));
+    }
+
+    private static void checkCount(final int x, final int y, final int count) {
+        if (count > MAX_DASH_LENGTH) {
+            throw new RuntimeException("Dash is longer than " + MAX_DASH_LENGTH
+                    + " at " + x + ", " + y);
+        }
+    }
+
+    private static void save(final BufferedImage img,
+                             final String fileName) throws IOException {
+        ImageIO.write(img, "png", new File(fileName));
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/lang/invoke/MethodHandlesProxiesTest.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * 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 8206955
+ * @run testng/othervm -ea -esa test.java.lang.invoke.MethodHandlesProxiesTest
+ */
+
+package test.java.lang.invoke;
+
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandleProxies;
+import java.lang.invoke.MethodHandles;
+
+import static org.testng.Assert.assertEquals;
+
+public class MethodHandlesProxiesTest {
+
+    public interface A {
+    default String a() {
+        return "A";
+    }
+    }
+
+    public interface B {
+    default String b() {
+        return "B";
+    }
+    }
+
+    public interface C extends A, B {
+        String f();
+
+    default String c() {
+        return "C";
+    }
+
+    default String concat() {
+        return a() + b() + c();
+    }
+    }
+
+    public interface Override extends C {
+        String f();
+
+    default String a() {
+        return "OA";
+    }
+
+    default String b() {
+        return "OB";
+    }
+
+    default String c() {
+        return "OC";
+    }
+    }
+
+    @Test
+        public static void testDefaultMethods() throws Throwable {
+        MethodHandle target = MethodHandles.constant(String.class, "F");
+        C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);
+
+        assertEquals(proxy.f(), "F");
+        assertEquals(proxy.a(), "A");
+        assertEquals(proxy.b(), "B");
+        assertEquals(proxy.c(), "C");
+        assertEquals(proxy.concat(), "ABC");
+    }
+
+    @Test
+        public static void testOverriddenDefaultMethods() throws Throwable {
+        MethodHandle target = MethodHandles.constant(String.class, "F");
+        Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);
+
+        assertEquals(proxy.a(), "OA");
+        assertEquals(proxy.b(), "OB");
+        assertEquals(proxy.c(), "OC");
+    }
+}
--- a/test/java/net/Socket/asyncClose/AsyncClose.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/AsyncClose.java	Fri May 24 04:01:22 2019 +0100
@@ -21,15 +21,17 @@
  * questions.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import static java.util.concurrent.CompletableFuture.*;
+
 /*
  * @test
  * @bug 4344135
  * @summary Check that {Socket,ServerSocket,DatagramSocket}.close will
  *          cause any thread blocked on the socket to throw a SocketException.
- * @run main/timeout=60 AsyncClose
  */
-import java.net.*;
-import java.io.*;
 
 public class AsyncClose {
 
@@ -37,34 +39,35 @@
 
         AsyncCloseTest tests[] = {
             new Socket_getInputStream_read(),
-            new Socket_getInputStream_read(5000),
+            new Socket_getInputStream_read(20000),
             new Socket_getOutputStream_write(),
             new DatagramSocket_receive(),
-            new DatagramSocket_receive(5000),
+            new DatagramSocket_receive(20000),
             new ServerSocket_accept(),
-            new ServerSocket_accept(5000),
+            new ServerSocket_accept(20000),
         };
 
         int failures = 0;
 
-        for (int i=0; i<tests.length; i++) {
-            AsyncCloseTest tst = tests[i];
+        List<CompletableFuture<AsyncCloseTest>> cfs = new ArrayList<>();
+        for (AsyncCloseTest test : tests)
+            cfs.add( supplyAsync(() -> test.go()));
+
+        for (CompletableFuture<AsyncCloseTest> cf : cfs) {
+            AsyncCloseTest test = cf.get();
 
             System.out.println("******************************");
-            System.out.println("Test: " + tst.description());
-
-            if (tst.go()) {
+            System.out.println("Test: " + test.description());
+            if (test.hasPassed()) {
                 System.out.println("Passed.");
             } else {
-                System.out.println("Failed: " + tst.failureReason());
+                System.out.println("Failed: " + test.failureReason());
                 failures++;
             }
             System.out.println("");
-
         }
 
-        if (failures > 0) {
+        if (failures > 0)
             throw new Exception(failures + " sub-tests failed - see log.");
-        }
     }
 }
--- a/test/java/net/Socket/asyncClose/AsyncCloseTest.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/AsyncCloseTest.java	Fri May 24 04:01:22 2019 +0100
@@ -29,11 +29,22 @@
 
     public abstract String description();
 
-    public abstract boolean go() throws Exception;
+    public abstract AsyncCloseTest go();
 
+    public synchronized boolean hasPassed() {
+        return passed;
+    }
 
-    protected synchronized void failed(String reason) {
-        this.reason = reason;
+    protected synchronized AsyncCloseTest passed() {
+        if (reason == null)
+            passed = true;
+        return this;
+    }
+
+    protected synchronized AsyncCloseTest failed(String r) {
+        passed = false;
+        reason = r;
+        return this;
     }
 
     public synchronized String failureReason() {
@@ -48,7 +59,7 @@
         return closed;
     }
 
+    private boolean passed;
     private String reason;
     private boolean closed;
-
 }
--- a/test/java/net/Socket/asyncClose/DatagramSocket_receive.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/DatagramSocket_receive.java	Fri May 24 04:01:22 2019 +0100
@@ -26,20 +26,25 @@
  * throws a SocketException if the socket is asynchronously closed.
  */
 import java.net.*;
+import java.util.concurrent.CountDownLatch;
 
 public class DatagramSocket_receive extends AsyncCloseTest implements Runnable {
-    DatagramSocket s;
-    int timeout = 0;
+    private final DatagramSocket s;
+    private final int timeout;
+    private final CountDownLatch latch;
 
-    public DatagramSocket_receive() {
+    public DatagramSocket_receive() throws SocketException {
+        this(0);
     }
 
-    public DatagramSocket_receive(int timeout) {
+    public DatagramSocket_receive(int timeout) throws SocketException {
         this.timeout = timeout;
+        latch = new CountDownLatch(1);
+        s = new DatagramSocket();
     }
 
     public String description() {
-        String s = "DatagramSocket.receive";
+        String s = "DatagramSocket.receive(DatagramPacket)";
         if (timeout > 0) {
             s += " (timeout specified)";
         }
@@ -47,46 +52,45 @@
     }
 
     public void run() {
-        DatagramPacket p;
         try {
-
             byte b[] = new byte[1024];
-            p  = new DatagramPacket(b, b.length);
-
+            DatagramPacket p  = new DatagramPacket(b, b.length);
             if (timeout > 0) {
                 s.setSoTimeout(timeout);
             }
+            latch.countDown();
+            s.receive(p);
+            failed("DatagramSocket.receive(DatagramPacket) returned unexpectly!!");
+        } catch (SocketException se) {
+            if (latch.getCount() != 1) {
+                closed();
+            }
         } catch (Exception e) {
             failed(e.getMessage());
-            return;
-        }
-
-        try {
-            s.receive(p);
-        } catch (SocketException se) {
-            closed();
-        } catch (Exception e) {
-            failed(e.getMessage());
+        } finally {
+            if (latch.getCount() == 1) {
+                latch.countDown();
+            }
         }
     }
 
-    public boolean go() throws Exception {
-        s = new DatagramSocket();
-
-        Thread thr = new Thread(this);
-        thr.start();
-
-        Thread.currentThread().sleep(1000);
+    public AsyncCloseTest go() {
+        try {
+            Thread thr = new Thread(this);
+            thr.start();
+            latch.await();
+            Thread.sleep(5000); //sleep, so receive(DatagramPacket) can block
+            s.close();
+            thr.join();
 
-        s.close();
-
-        Thread.currentThread().sleep(1000);
-
-        if (isClosed()) {
-            return true;
-        } else {
-            failed("DatagramSocket.receive wasn't preempted");
-            return false;
+            if (isClosed()) {
+                return passed();
+            } else {
+                return failed("DatagramSocket.receive(DatagramPacket) wasn't preempted");
+            }
+        } catch (Exception x) {
+            failed(x.getMessage());
+            throw new RuntimeException(x);
         }
     }
 }
--- a/test/java/net/Socket/asyncClose/ServerSocket_accept.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/ServerSocket_accept.java	Fri May 24 04:01:22 2019 +0100
@@ -25,17 +25,23 @@
  * Tests that a thread blocked in ServerSocket.accept
  * throws a SocketException if the socket is asynchronously closed.
  */
+import java.io.IOException;
 import java.net.*;
+import java.util.concurrent.CountDownLatch;
 
 public class ServerSocket_accept extends AsyncCloseTest implements Runnable {
-    ServerSocket ss;
-    int timeout = 0;
+    private final ServerSocket ss;
+    private final int timeout;
+    private final CountDownLatch latch;
 
-    public ServerSocket_accept() {
+    public ServerSocket_accept() throws IOException {
+       this(0);
     }
 
-    public ServerSocket_accept(int timeout) {
+    public ServerSocket_accept(int timeout) throws IOException {
         this.timeout = timeout;
+        latch = new CountDownLatch(1);
+        ss = new ServerSocket(0);
     }
 
     public String description() {
@@ -48,7 +54,9 @@
 
     public void run() {
         try {
+            latch.countDown();
             Socket s = ss.accept();
+            failed("ServerSocket.accept() returned unexpectly!!");
         } catch (SocketException se) {
             closed();
         } catch (Exception e) {
@@ -56,23 +64,23 @@
         }
     }
 
-    public boolean go() throws Exception {
-        ss = new ServerSocket(0);
-
-        Thread thr = new Thread(this);
-        thr.start();
-
-        Thread.currentThread().sleep(1000);
+    public AsyncCloseTest go(){
+        try {
+            Thread thr = new Thread(this);
+            thr.start();
+            latch.await();
+            Thread.sleep(5000); //sleep, so ServerSocket.accept() can block
+            ss.close();
+            thr.join();
 
-        ss.close();
-
-        Thread.currentThread().sleep(1000);
-
-        if (isClosed()) {
-            return true;
-        } else {
-            failed("ServerSocket.accept() wasn't preempted");
-            return false;
+            if (isClosed()) {
+                return passed();
+            } else {
+                return failed("ServerSocket.accept() wasn't preempted");
+            }
+        } catch (Exception x) {
+            failed(x.getMessage());
+            throw new RuntimeException(x);
         }
     }
 }
--- a/test/java/net/Socket/asyncClose/Socket_getInputStream_read.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/Socket_getInputStream_read.java	Fri May 24 04:01:22 2019 +0100
@@ -27,16 +27,21 @@
  */
 import java.net.*;
 import java.io.*;
+import java.util.concurrent.CountDownLatch;
 
 public class Socket_getInputStream_read extends AsyncCloseTest implements Runnable {
-    Socket s;
-    int timeout = 0;
+    private final Socket s;
+    private final int timeout;
+    private final CountDownLatch latch;
 
     public Socket_getInputStream_read() {
+        this(0);
     }
 
     public Socket_getInputStream_read(int timeout) {
         this.timeout = timeout;
+        latch = new CountDownLatch(1);
+        s = new Socket();
     }
 
     public String description() {
@@ -48,53 +53,48 @@
     }
 
     public void run() {
-        InputStream in;
-
         try {
-            in = s.getInputStream();
+            InputStream in = s.getInputStream();
             if (timeout > 0) {
                 s.setSoTimeout(timeout);
             }
+            latch.countDown();
+            int n = in.read();
+            failed("Socket.getInputStream().read() returned unexpectly!!");
+        } catch (SocketException se) {
+            if (latch.getCount() != 1) {
+                closed();
+            }
         } catch (Exception e) {
             failed(e.getMessage());
-            return;
-        }
-
-        try {
-            int n = in.read();
-            failed("getInptuStream().read() returned unexpectly!!");
-        } catch (SocketException se) {
-            closed();
-        } catch (Exception e) {
-            failed(e.getMessage());
+        } finally {
+            if (latch.getCount() == 1) {
+                latch.countDown();
+            }
         }
     }
 
-    public boolean go() throws Exception {
-
-        ServerSocket ss = new ServerSocket(0);
-
-        InetAddress lh = InetAddress.getLocalHost();
-        s = new Socket();
-        s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
-
-        Socket s2 = ss.accept();
-
-        Thread thr = new Thread(this);
-        thr.start();
+    public AsyncCloseTest go() {
+        try {
+            ServerSocket ss = new ServerSocket(0);
+            InetAddress lh = InetAddress.getLocalHost();
+            s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
+            Socket s2 = ss.accept();
+            Thread thr = new Thread(this);
+            thr.start();
+            latch.await();
+            Thread.sleep(5000); //sleep, so Socket.getInputStream().read() can block
+            s.close();
+            thr.join();
 
-        Thread.currentThread().sleep(1000);
-
-        s.close();
-
-        Thread.currentThread().sleep(1000);
-
-        if (isClosed()) {
-            return true;
-        } else {
-            failed("getInputStream().read() wasn't preempted");
-            return false;
+            if (isClosed()) {
+                return passed();
+            } else {
+                return failed("Socket.getInputStream().read() wasn't preempted");
+            }
+        } catch (Exception x) {
+            failed(x.getMessage());
+            throw new RuntimeException(x);
         }
-
     }
 }
--- a/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java	Fri May 24 04:01:22 2019 +0100
@@ -27,9 +27,16 @@
  */
 import java.net.*;
 import java.io.*;
+import java.util.concurrent.CountDownLatch;
 
 public class Socket_getOutputStream_write extends AsyncCloseTest implements Runnable {
-    Socket s;
+    private final Socket s;
+    private final CountDownLatch latch;
+
+    public Socket_getOutputStream_write() {
+        latch = new CountDownLatch(1);
+        s = new Socket();
+    }
 
     public String description() {
         return "Socket.getOutputStream().write()";
@@ -38,40 +45,45 @@
     public void run() {
         try {
             OutputStream out = s.getOutputStream();
+            byte b[] = new byte[8192];
+            latch.countDown();
             for (;;) {
-                byte b[] = new byte[8192];
                 out.write(b);
             }
         } catch (SocketException se) {
-            closed();
+            if (latch.getCount() != 1) {
+                closed();
+            }
         } catch (Exception e) {
             failed(e.getMessage());
+        } finally {
+            if (latch.getCount() == 1) {
+                latch.countDown();
+            }
         }
     }
 
-    public boolean go() throws Exception {
-        ServerSocket ss = new ServerSocket(0);
-
-        InetAddress lh = InetAddress.getLocalHost();
-        s = new Socket();
-        s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
-
-        Socket s2 = ss.accept();
-
-        Thread thr = new Thread(this);
-        thr.start();
+    public AsyncCloseTest go() {
+        try {
+            ServerSocket ss = new ServerSocket(0);
+            InetAddress lh = InetAddress.getLocalHost();
+            s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
+            Socket s2 = ss.accept();
+            Thread thr = new Thread(this);
+            thr.start();
+            latch.await();
+            Thread.sleep(1000);
+            s.close();
+            thr.join();
 
-        Thread.currentThread().sleep(2000);
-
-        s.close();
-
-        Thread.currentThread().sleep(2000);
-
-        if (isClosed()) {
-            return true;
-        } else {
-            failed("getOutputStream().write() wasn't preempted");
-            return false;
+            if (isClosed()) {
+                return passed();
+            } else {
+                return failed("Socket.getOutputStream().write() wasn't preempted");
+            }
+        } catch (Exception x) {
+            failed(x.getMessage());
+            throw new RuntimeException(x);
         }
     }
 }
--- a/test/java/net/ipv6tests/UdpTest.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/net/ipv6tests/UdpTest.java	Fri May 24 04:01:22 2019 +0100
@@ -147,6 +147,7 @@
         final InetAddress ia6 = ia6addr;
         final int port = s1.getLocalPort();
 
+        s1.setSoTimeout(10000);
         runAfter (2000, new Runnable () {
             public void run () {
                 try {
@@ -157,7 +158,7 @@
         });
         t1 = System.currentTimeMillis();
         s1.receive (new DatagramPacket (new byte [128], 128));
-        checkTime (System.currentTimeMillis() - t1, 2000);
+        checkTime (System.currentTimeMillis() - t1, 4000);
         s1.close ();
         s2.close ();
         System.out.println ("Test2: OK");
--- a/test/java/nio/Buffer/Chars.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/nio/Buffer/Chars.java	Fri May 24 04:01:22 2019 +0100
@@ -52,8 +52,8 @@
      */
     static CharBuffer randomizeRange(CharBuffer cb) {
         int mid = cb.capacity() >>> 1;
-        int start = RAND.nextInt(mid);
-        int end = mid + RAND.nextInt(mid);
+        int start = RAND.nextInt(mid + 1); // from 0 to mid
+        int end = mid + RAND.nextInt(cb.capacity() - mid + 1); // from mid to capacity
         cb.position(start);
         cb.limit(end);
         return cb;
--- a/test/java/nio/channels/Selector/ChangingInterests.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/nio/channels/Selector/ChangingInterests.java	Fri May 24 04:01:22 2019 +0100
@@ -138,8 +138,10 @@
             ServerSocketChannel.open().bind(new InetSocketAddress(0));
 
         final SocketChannel sc = SocketChannel.open();
+        sc.setOption(StandardSocketOptions.TCP_NODELAY, true);
         sc.connect(new InetSocketAddress(lh, ssc.socket().getLocalPort()));
         SocketChannel peer = ssc.accept();
+        peer.setOption(StandardSocketOptions.TCP_NODELAY, true);
 
         sc.configureBlocking(false);
 
--- a/test/java/nio/file/FileStore/Basic.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/nio/file/FileStore/Basic.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -116,9 +116,21 @@
                 store.type());
 
             // check space attributes are accessible
-            store.getTotalSpace();
-            store.getUnallocatedSpace();
-            store.getUsableSpace();
+            try {
+                store.getTotalSpace();
+                store.getUnallocatedSpace();
+                store.getUsableSpace();
+            } catch (NoSuchFileException nsfe) {
+                // ignore exception as the store could have been
+                // deleted since the iterator was instantiated
+                System.err.format("%s was not found\n", store);
+            } catch (AccessDeniedException ade) {
+                // ignore exception as the lack of ability to access the
+                // store due to lack of file permission or similar does not
+                // reflect whether the space attributes would be accessible
+                // were access to be permitted
+                System.err.format("%s is inaccessible\n", store);
+            }
 
             // two distinct FileStores should not be equal
             assertTrue(!store.equals(prev));
--- a/test/java/time/test/java/time/chrono/TestJapaneseChronology.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/java/time/test/java/time/chrono/TestJapaneseChronology.java	Fri May 24 04:01:22 2019 +0100
@@ -165,7 +165,7 @@
             { "Taisho", JapaneseEra.TAISHO,     null },
             { "Showa",  JapaneseEra.SHOWA,      null },
             { "Heisei", JapaneseEra.HEISEI,     null },
-            { "Reiwa", JapaneseEra.of(3),       null },
+            { "Reiwa",  JapaneseEra.of(3),      null },
             { "NewEra", null,                   IllegalArgumentException.class},
         };
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/accessibility/SlowPanelIteration/SlowPanelIteration.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * 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.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+/**
+ * @test
+ * @key headful
+ * @bug 8202768
+ * @summary we should not hang when lots of panels are used
+ */
+public final class SlowPanelIteration {
+
+    private static JFrame frame;
+    private static Point center = new Point();
+    private static volatile CountDownLatch go;
+
+    public static void main(final String[] args) throws Exception {
+        Robot r = new Robot();
+        // accessibility tool will need time to react to our clicks
+        r.setAutoDelay(200);
+        try {
+            EventQueue.invokeAndWait(SlowPanelIteration::showUI);
+            for (int i = 0; i < 10; ++i) {
+                go = new CountDownLatch(1);
+                r.mouseMove(center.x, center.y);
+                r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+                r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+                if (!go.await(10, TimeUnit.SECONDS)) {
+                    throw new RuntimeException("Too slow operation");
+                }
+            }
+        } finally {
+            EventQueue.invokeAndWait(SlowPanelIteration::dispose);
+        }
+    }
+
+    private static void showUI() {
+        frame = new JFrame();
+        frame.setSize(new Dimension(400, 400));
+        frame.setLocationRelativeTo(null);
+
+        final Container content = frame.getContentPane();
+        content.setLayout(new BorderLayout(0, 0));
+        Container lastPanel = content;
+        for (int i = 0; i < 500; i++) {
+            final JPanel p = new JPanel();
+            p.setLayout(new BorderLayout(0, 0));
+            lastPanel.add(p);
+            lastPanel.addMouseListener(new MouseAdapter() {
+                @Override
+                public void mouseClicked(MouseEvent e) {
+                    System.out.println("click");
+                    go.countDown();
+                }
+            });
+            lastPanel = p;
+        }
+
+        lastPanel.setBackground(Color.GREEN);
+        frame.setVisible(true);
+
+        Point loc = frame.getLocationOnScreen();
+        center.x = loc.x + frame.getWidth() / 2;
+        center.y = loc.y + frame.getHeight() / 2;
+    }
+
+    private static void dispose() {
+        if (frame != null) {
+            frame.dispose();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/xml/jaxp/transform/8207760/JDK8207760.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * 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.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.testng.Assert;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+import java.util.Random;
+import javax.xml.transform.OutputKeys;
+import org.testng.annotations.DataProvider;
+
+/*
+ * @test
+ * @run testng/othervm JDK8207760
+ * @summary Verifies that a surrogate pair at the edge of a buffer is properly handled
+ * @bug 8207760
+ */
+public class JDK8207760 {
+    final String xsl8207760 =
+        "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
+        "    <xsl:output omit-xml-declaration=\"yes\" indent=\"no\" />\n" +
+        "\n" +
+        "    <xsl:template match=\"node()|@*\">\n" +
+        "        <xsl:copy>\n" +
+        "            <xsl:apply-templates select=\"node()|@*\" />\n" +
+        "        </xsl:copy>\n" +
+        "    </xsl:template>\n" +
+        "</xsl:stylesheet>\n";
+
+    final String xsl8207760_2 = "<xsl:stylesheet \n" +
+        "  version=\"1.0\" \n" +
+        "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
+        "\n" +
+        "  <xsl:output method=\"xml\" indent=\"no\" cdata-section-elements=\"source\"/>\n" +
+        "\n" +
+        "  <xsl:template match=\"source\">\n" +
+                "        <xsl:copy>\n" +
+                "            <xsl:apply-templates select=\"node()\" />\n" +
+                "        </xsl:copy>\n" +
+        "  </xsl:template>\n" +
+        "\n" +
+        "</xsl:stylesheet>";
+
+    final String xsl8207760_3 = "<xsl:stylesheet \n" +
+        "  version=\"1.0\" \n" +
+        "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
+        "\n" +
+        "  <xsl:output method=\"xml\" indent=\"no\" cdata-section-elements=\"source\"/>\n" +
+        "\n" +
+        "  <xsl:template match=\"source\">\n" +
+        "    <xsl:copy>\n" +
+        "      <!-- Copy the attributes -->\n" +
+        "      <xsl:apply-templates select=\"@*\"/>\n" +
+        "      <!-- Convert the contained nodes (elements and text) into text -->\n" +
+        "      <xsl:variable name=\"subElementsText\">\n" +
+        "        <xsl:apply-templates select=\"node()\"/>\n" +
+        "      </xsl:variable>\n" +
+        "      <!-- Output the XML directive and the converted nodes -->\n" +
+        "      <xsl:value-of select=\"$subElementsText\"/>\n" +
+        "    </xsl:copy>\n" +
+        "  </xsl:template>\n" +
+        "\n" +
+        "</xsl:stylesheet>";
+
+    @DataProvider(name = "xsls")
+    public Object[][] getDataBug8207760_cdata() {
+        return new Object[][]{
+            {xsl8207760_2},
+            {xsl8207760_3},
+        };
+    }
+
+    /*
+     * @bug 8207760
+     * Verifies that a surrogate pair at the edge of a buffer is properly handled
+     * when serializing into a Character section.
+     */
+    @Test
+    public final void testBug8207760() throws Exception {
+        String[] xmls = prepareXML(false);
+        Transformer t = createTransformerFromInputstream(
+                new ByteArrayInputStream(xsl8207760.getBytes(StandardCharsets.UTF_8)));
+        t.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
+        StringWriter sw = new StringWriter();
+        t.transform(new StreamSource(new StringReader(xmls[0])), new StreamResult(sw));
+        Assert.assertEquals(sw.toString().replaceAll(System.lineSeparator(), "\n"), xmls[1]);
+    }
+
+    /*
+     * @bug 8207760
+     * Verifies that a surrogate pair at the edge of a buffer is properly handled
+     * when serializing into a CDATA section.
+     */
+    @Test(dataProvider = "xsls")
+    public final void testBug8207760_cdata(String xsl) throws Exception {
+        String[] xmls = prepareXML(true);
+        Transformer t = createTransformerFromInputstream(
+                new ByteArrayInputStream(xsl.getBytes(StandardCharsets.UTF_8)));
+        t.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
+        StringWriter sw = new StringWriter();
+        t.transform(new StreamSource(new StringReader(xmls[0])), new StreamResult(sw));
+        Assert.assertEquals(sw.toString().replaceAll(System.lineSeparator(), "\n"), xmls[1]);
+    }
+
+    private String[] prepareXML(boolean cdata) {
+        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><source>";
+        if (cdata) {
+            xml += "<![CDATA[";
+        }
+        String tail = "abc 123 </source>";
+        if (cdata) {
+            tail = "abc 123 ]]></source>";
+        }
+        String temp = generateString(1023);
+        xml = xml + temp + '\uD83C' + '\uDF42' + tail;
+        //xml = xml + temp + tail;
+        String expected = (!cdata) ? "<source>" + temp + "&#127810;" + tail
+                : xml;
+
+        return new String[]{xml, expected};
+    }
+
+    static final char[] CHARS = "abcdefghijklmnopqrstuvwxyz \n".toCharArray();
+    StringBuilder sb = new StringBuilder(1024 << 4);
+    Random random = new Random();
+
+    private String generateString(int size) {
+        sb.setLength(0);
+        for (int i = 0; i < size; i++) {
+            char c = CHARS[random.nextInt(CHARS.length)];
+            sb.append(c);
+        }
+
+        return sb.toString();
+    }
+
+    private Transformer createTransformerFromInputstream(InputStream xslStream)
+            throws TransformerException {
+        return TransformerFactory.newInstance().newTransformer(new StreamSource(xslStream));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/java2d/pisces/OpenJDKFillBug.java	Fri May 24 04:01:22 2019 +0100
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+import java.awt.Color;
+import java.awt.Composite;
+import java.awt.CompositeContext;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.awt.image.RasterFormatException;
+
+/**
+ * @test
+ * @bug 8048782
+ * @summary Test program that demonstrates PiscesRendering bug in
+ * OpenJDK 1.7.0.60 (and probably in all other OpenJDK versions, too).
+ */
+
+public class OpenJDKFillBug
+{
+    /**
+     * Test program that demonstrates a bug in OpenJDK 1.7.0.60 (and
+     * probably in all other OpenJDK versions, too). To see the bug, simply run
+     * the 'main' program with OpenJDK. The bug makes the 'g2d.fill'
+     * method fail with the following exception:
+     *
+     * This bug is found in OpenJDK but also is present in OracleJDK
+     * if run with
+     * -Dsun.java2d.renderer=sun.java2d.pisces.PiscesRenderingEngine
+     *
+     * The bug is related to sun.java2d.pisces.PiscesCache constructor
+     * that accepts '(int minx,int miny,int maxx,int maxy)' arguments:
+     * the internal 'bboxX1' and 'bboxY1' are set to values one greater
+     * than given maximum X and Y values. Those maximum values are then
+     * later used in AAShapePipe' class 'renderTiles' method, where a
+     * Y/X loop eventually calls 'GeneralCompositePipe' class
+     * 'renderPathTile' method. In that method, the operation will
+     * eventually call 'IntegerInterleavedRaster' class
+     * 'createWritableChild' method with arguments:
+     *
+     * <UL>
+     * <LI>x=800
+     * <LI>y=0
+     * <LI>width=2 (this value is too high: should be 1)
+     * <LI>height=32
+     * <LI>x0=0
+     * <LI>y0=0
+     * <LI>bandList[]=null
+     * </UL>
+     *
+     * This calls for a sub-raster with bounds that fall outside the
+     * original raster, and therefore the 'createWritableChild' method
+     * correctly throws 'RasterFormatException'.
+     *
+     * The bug is closely related to the use of a custom Composite
+     * implementation, which are quite rare. The application where this
+     * bug was first detected implements a high-quality PDF rendering
+     * engine that needs custom Composite operations to properly
+     * implement PDF advanced color blending and masking operators.
+     */
+
+    public static void main(String args[])
+    {
+        BufferedImage bi = new BufferedImage(801,1202,
+                                             BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g2d = bi.createGraphics();
+        GeneralPath gp = new GeneralPath();
+        AffineTransform m = new AffineTransform(2.483489907915543,
+                                                0.0,
+                                                0.0,
+                                                -2.4844977263331955,
+                                                0.0,
+                                                1202.0);
+        Composite c = new CustomComposite();
+
+        gp.moveTo(-4.511, -14.349);
+        gp.lineTo(327.489, -14.349);
+        gp.lineTo(327.489, 494.15);
+        gp.lineTo(-4.511, 494.15);
+        gp.closePath();
+
+        g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
+                             RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
+                             RenderingHints.VALUE_RENDER_QUALITY);
+        g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
+                             RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST,
+                             Integer.valueOf(140));
+        g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
+                             RenderingHints.VALUE_DITHER_ENABLE);
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+                             RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                             RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
+                             RenderingHints.VALUE_STROKE_NORMALIZE);
+        g2d.setPaint(Color.red);
+        g2d.setComposite(c);
+        g2d.setTransform(m);
+        try {
+            g2d.fill(gp);
+        } catch (RasterFormatException rfe) {
+            System.out.println("Test failed");
+            throw new RuntimeException("xmax/ymax rounding cause RasterFormatException: " + rfe);
+        }
+        g2d.dispose();
+        System.out.println("Test passed");
+    }
+
+    // === CustomComposite ===
+
+    /**
+     * Dummy custom Composite implementation.
+     */
+
+    public static class CustomComposite implements Composite
+    {
+        @Override
+        public CompositeContext createContext(ColorModel srcColorModel,
+                                              ColorModel dstColorModel,
+                                              RenderingHints hints)
+        {
+            return new CustomCompositeContext();
+        }
+
+        // === CustomCompositeContext ===
+
+        /**
+         * Dummy custom CompositeContext implementation.
+         */
+
+        public static class CustomCompositeContext implements CompositeContext
+        {
+
+            @Override
+            public void dispose()
+            {
+                // NOP
+            }
+
+            @Override
+            public void compose(Raster src,Raster dstIn,WritableRaster dstOut)
+            {
+                // NOP
+            }
+        }
+    }
+}
--- a/test/sun/nio/cs/MalformedSurrogates.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/sun/nio/cs/MalformedSurrogates.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,64 +22,132 @@
  */
 
 /* @test
-   @bug 4153987
-   @summary Malformed surrogates should be handled by the converter in
-   substitution mode.
+ * @bug 4153987
+ * @summary Malformed surrogates should be handled by the converter in
+ * substitution mode.
  */
-
 import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.MalformedInputException;
+import java.nio.charset.UnmappableCharacterException;
+import java.util.SortedMap;
 
 public class MalformedSurrogates {
 
-    public static void main(String[] args) throws Exception {
-
-        String fe = System.getProperty("file.encoding");
-        if (  fe.equalsIgnoreCase("UTF8")
-              || fe.equalsIgnoreCase("UTF-8")
-              || fe.equalsIgnoreCase("UTF_8"))
-            // This test is meaningless if the default charset
-            // does handle surrogates
-            return;
+    private static final String PREFIX = "abc";
+    private static final String SUFFIX = "efgh";
+    private static final String MALFORMED_SURROGATE = PREFIX + "\uD800\uDB00" + SUFFIX;
+    private static final String NORMAL_SURROGATE = PREFIX + "\uD800\uDC00" + SUFFIX;
+    private static final String REVERSED_SURROGATE = PREFIX + "\uDC00\uD800" + SUFFIX;
+    private static final String SOLITARY_HIGH_SURROGATE = PREFIX + "\uD800" + SUFFIX;
+    private static final String SOLITARY_LOW_SURROGATE = PREFIX + "\uDC00" + SUFFIX;
 
-        System.out.println("Testing string conversion...");
-        /* Example with malformed surrogate, and an offset */
-        String t = "abc\uD800\uDB00efgh";
-        String t2 = t.substring(2);
-        byte[] b = t2.getBytes();
-        System.err.println(b.length);
-        for (int i = 0; i < b.length; i++)
-            System.err.println("[" + i + "]" + "=" + (char) b[i]
-                               + "=" + (int) b[i]);
-        if (b.length != 7) {
-            throw new Exception("Bad string conversion for bad surrogate");
+    public static void main(String[] args) throws IOException {
+        SortedMap<String, Charset> map = Charset.availableCharsets();
+        for (String name : map.keySet()) {
+            Charset charset = map.get(name);
+            if (charset.canEncode() && !charset.name().equals("x-COMPOUND_TEXT")) {
+                testNormalSurrogate(charset, NORMAL_SURROGATE);
+                testMalformedSurrogate(charset, MALFORMED_SURROGATE);
+                testMalformedSurrogate(charset, REVERSED_SURROGATE);
+                testMalformedSurrogate(charset, SOLITARY_HIGH_SURROGATE);
+                testMalformedSurrogate(charset, SOLITARY_LOW_SURROGATE);
+                testSurrogateWithReplacement(charset, NORMAL_SURROGATE);
+                testSurrogateWithReplacement(charset, MALFORMED_SURROGATE);
+                testSurrogateWithReplacement(charset, REVERSED_SURROGATE);
+                testSurrogateWithReplacement(charset, SOLITARY_HIGH_SURROGATE);
+                testSurrogateWithReplacement(charset, SOLITARY_LOW_SURROGATE);
+            }
+        }
+    }
+
+    public static void testMalformedSurrogate(Charset cs, String surrogate) throws IOException {
+        CharsetEncoder en = cs.newEncoder();
+        if (en.canEncode(surrogate)) {
+            throw new RuntimeException("testMalformedSurrogate failed with charset " + cs.name());
+        }
+
+        try {
+            en.encode(CharBuffer.wrap(surrogate));
+            throw new RuntimeException("Should throw MalformedInputException or UnmappableCharacterException");
+        } catch (MalformedInputException | UnmappableCharacterException ex) {
+        } finally {
+            en.reset();
         }
 
-        /* Example with a proper surrogate, no offset. Always worked */
-        String t3 = "abc\uD800\uDC00efgh";
-        byte[] b2 = t3.getBytes();
-        System.out.println(b2.length);
-        for(int i = 0; i < b2.length; i++)
-            System.err.println("[" + i + "]" + "=" + (char) b2[i]);
-        if (b2.length != 8) {
-            throw new Exception("Bad string conversion for good surrogate");
+        try (OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), en)) {
+            osw.write(surrogate);
+            throw new RuntimeException("Should throw MalformedInputException or UnmappableCharacterException");
+        } catch (MalformedInputException | UnmappableCharacterException ex) {
+        }
+    }
+
+    public static void testNormalSurrogate(Charset cs, String surrogate) throws IOException {
+        CharsetEncoder en = cs.newEncoder();
+        try {
+            en.encode(CharBuffer.wrap(surrogate));
+        } catch (UnmappableCharacterException ex) {
+        } finally {
+            en.reset();
         }
 
-        OutputStream os = new ByteArrayOutputStream();
-        OutputStreamWriter osw = new OutputStreamWriter(os);
-        System.out.println("Testing flush....");
-        /* Check for the case where the converter has a left over
-           high surrogate when flush is called on the converter */
-        osw.flush();
-        String s = "abc\uD800"; // High surrogate
-        char[] c = s.toCharArray();
-        osw.write(s, 0, 4);
-        osw.flush();
+        try (OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), en)) {
+            osw.write(surrogate);
+        } catch (UnmappableCharacterException ex) {
+        }
+    }
 
-        System.out.println("Testing convert...");
-        /* Verify that all other characters go through */
-        for (int k = 1; k < 65535 ; k++) {
-            osw.write("Char[" + k + "]=\"" + ((char) k) + "\"");
+    public static void testSurrogateWithReplacement(Charset cs, String surrogate) throws IOException {
+        CharsetEncoder en = cs.newEncoder();
+        CharsetDecoder de = cs.newDecoder();
+        if (!en.canEncode(NORMAL_SURROGATE)) {
+            return;
+        }
+        String expected = null;
+        String replace = new String(en.replacement(), cs);
+        switch (surrogate) {
+            case MALFORMED_SURROGATE:
+            case REVERSED_SURROGATE:
+                expected = PREFIX + replace + replace + SUFFIX;
+                break;
+            case SOLITARY_HIGH_SURROGATE:
+            case SOLITARY_LOW_SURROGATE:
+                expected = PREFIX + replace + SUFFIX;
+                break;
+            default:
+                expected = NORMAL_SURROGATE;
         }
 
+        try {
+            en.onMalformedInput(CodingErrorAction.REPLACE);
+            en.onUnmappableCharacter(CodingErrorAction.REPLACE);
+            ByteBuffer bbuf = en.encode(CharBuffer.wrap(surrogate));
+            CharBuffer cbuf = de.decode(bbuf);
+            if (!cbuf.toString().equals(expected)) {
+                throw new RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
+            }
+        } finally {
+            en.reset();
+            de.reset();
+        }
+
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                OutputStreamWriter osw = new OutputStreamWriter(bos, en);) {
+            osw.write(surrogate);
+            osw.flush();
+            try (InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bos.toByteArray()), de)) {
+                CharBuffer cbuf = CharBuffer.allocate(expected.length());
+                isr.read(cbuf);
+                cbuf.rewind();
+                if (!cbuf.toString().equals(expected)) {
+                    throw new RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
+                }
+            }
+        }
     }
 }
--- a/test/sun/security/rsa/SpecTest.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/sun/security/rsa/SpecTest.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -20,31 +20,31 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @bug 8044199 8137231
+ * @summary Check same KeyPair's private key and public key have same modulus.
+ * also check public key's public exponent equals to given spec's public
+ * exponent. Only key size 1024 is tested with RSAKeyGenParameterSpec.F0 (3).
+ * @run main SpecTest 512
+ * @run main SpecTest 768
+ * @run main SpecTest 1024
+ * @run main SpecTest 1024 3
+ * @run main SpecTest 2048
+ * @run main/timeout=240 SpecTest 4096
+ * @run main/timeout=240 SpecTest 5120
+ */
 import java.math.BigInteger;
-import java.security.InvalidAlgorithmParameterException;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.interfaces.RSAKey;
 import java.security.interfaces.RSAPrivateKey;
 import java.security.interfaces.RSAPublicKey;
 import java.security.spec.RSAKeyGenParameterSpec;
 
-/**
- * @test
- * @bug 8044199
- * @summary Check same KeyPair's private key and public key have same modulus.
- *  also check public key's public exponent equals to given spec's public
- *  exponent.
- * @run main SpecTest 512
- * @run main SpecTest 768
- * @run main SpecTest 1024
- * @run main SpecTest 2048
- * @run main/timeout=240 SpecTest 4096
- * @run main/timeout=240 SpecTest 5120
- */
 public class SpecTest {
+
     /**
      * ALGORITHM name, fixed as RSA.
      */
@@ -69,14 +69,14 @@
         // test the getModulus method
         if ((priv instanceof RSAKey) && (pub instanceof RSAKey)) {
             if (!priv.getModulus().equals(pub.getModulus())) {
-                System.err.println("priv.getModulus() = " + priv.getModulus());
-                System.err.println("pub.getModulus() = " + pub.getModulus());
+                System.out.println("priv.getModulus() = " + priv.getModulus());
+                System.out.println("pub.getModulus() = " + pub.getModulus());
                 passed = false;
             }
 
             if (!pubExponent.equals(pub.getPublicExponent())) {
-                System.err.println("pubExponent = " + pubExponent);
-                System.err.println("pub.getPublicExponent() = "
+                System.out.println("pubExponent = " + pubExponent);
+                System.out.println("pub.getPublicExponent() = "
                         + pub.getPublicExponent());
                 passed = false;
             }
@@ -84,36 +84,26 @@
         return passed;
     }
 
-    public static void main(String[] args) {
-        int failCount = 0;
+    public static void main(String[] args) throws Exception {
 
-        // Test key size.
-        int size = Integer.parseInt(args[0]);
+        int size = 0;
 
-        try {
-            KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
-            kpg1.initialize(new RSAKeyGenParameterSpec(size,
-                    RSAKeyGenParameterSpec.F4));
-            if (!specTest(kpg1.generateKeyPair(),
-                    RSAKeyGenParameterSpec.F4)) {
-                failCount++;
-            }
-
-            KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
-            kpg2.initialize(new RSAKeyGenParameterSpec(size,
-                    RSAKeyGenParameterSpec.F0));
-            if (!specTest(kpg2.generateKeyPair(), RSAKeyGenParameterSpec.F0)) {
-                failCount++;
-            }
-        } catch (NoSuchAlgorithmException | NoSuchProviderException
-                | InvalidAlgorithmParameterException ex) {
-            ex.printStackTrace(System.err);
-            failCount++;
+        if (args.length >= 1) {
+            size = Integer.parseInt(args[0]);
+        } else {
+            throw new RuntimeException("Missing keysize to test with");
         }
 
-        if (failCount != 0) {
-            throw new RuntimeException("There are " + failCount
-                    + " tests failed.");
+        BigInteger publicExponent
+                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;
+
+        System.out.println("Running test with key size: " + size
+                + " and public exponent: " + publicExponent);
+
+        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
+        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
+        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
+            throw new RuntimeException("Test failed.");
         }
     }
 }
--- a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/BadTSProvider.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/BadTSProvider.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -21,18 +21,21 @@
  * questions.
  */
 
+//
+// SunJSSE does not support dynamic system properties, no way to re-use
+// system properties in samevm/agentvm mode.
+//
+
 /*
  * @test
  * @bug 4919147
  * @summary Support for token-based KeyStores
  * @run main/othervm BadTSProvider
- *
- *     SunJSSE does not support dynamic system properties, no way to re-use
- *     system properties in samevm/agentvm mode.
  */
 
 import java.io.*;
 import java.net.*;
+import java.security.*;
 import javax.net.ssl.*;
 
 public class BadTSProvider {
@@ -179,13 +182,19 @@
             // XXX this test must be updated if the exception message changes
 
             Throwable cause = se.getCause();
-            if (cause instanceof java.security.NoSuchAlgorithmException == false) {
+            if (!(cause instanceof NoSuchAlgorithmException)) {
                 se.printStackTrace();
                 throw new Exception("Unexpected exception" + se);
             }
 
             cause = cause.getCause();
-            if (cause instanceof java.security.NoSuchProviderException == false) {
+            if (!(cause instanceof KeyStoreException)) {
+                se.printStackTrace();
+                throw new Exception("Unexpected exception" + se);
+            }
+
+            cause = cause.getCause();
+            if (!(cause instanceof NoSuchProviderException)) {
                 se.printStackTrace();
                 throw new Exception("Unexpected exception" + se);
             }
--- a/test/sun/security/validator/EndEntityExtensionCheck.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/sun/security/validator/EndEntityExtensionCheck.java	Fri May 24 04:01:22 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
-import sun.security.validator.KeyStores;
+import sun.security.validator.TrustStoreUtil;
 import sun.security.validator.Validator;
 
 
@@ -112,7 +112,7 @@
 
         Validator v = Validator.getInstance(Validator.TYPE_SIMPLE,
                                             Validator.VAR_TLS_CLIENT,
-                                            KeyStores.getTrustedCerts(ks));
+                                            TrustStoreUtil.getTrustedCerts(ks));
         try {
             v.validate(chain);
             throw new Exception("Chain should not have validated " +
--- a/test/tools/launcher/RunpathTest.java	Mon Apr 22 17:30:12 2019 +0100
+++ b/test/tools/launcher/RunpathTest.java	Fri May 24 04:01:22 2019 +0100
@@ -57,14 +57,14 @@
         final TestResult tr = doExec(elfreaderCmd, "-d", javacmd);
         if (!tr.matches(expectedRpath)) {
             System.out.println(tr);
-            throw new RuntimeException("FAILED: RPATH strings " +
+            throw new RuntimeException("FAILED: RPATH/RUNPATH strings " +
                     expectedRpath + " not found in " + javaCmd);
         }
-        System.out.println(javacmd + " contains expected RPATHS");
+        System.out.println(javacmd + " contains expected RPATHS/RUNPATH");
     }
 
     void testRpath() {
-        String expectedRpath = ".*RPATH.*\\$ORIGIN/../lib/" + getJreArch() + ".*";
+        String expectedRpath = ".*R(UN)?PATH.*\\$ORIGIN/../lib/" + getJreArch() + ".*";
         elfCheck(javaCmd, expectedRpath);
     }