# HG changeset patch
# User andrew
# Date 1639346076 0
#      Sun Dec 12 21:54:36 2021 +0000
# Node ID 2f1059fcec882677ddb003a27b08cccdcbb83888
# Parent  b2dfa021c7c31ef2f97f37abced5c63b67662cf4
# Parent  45e4e636b757c5254577718065874a21a31af9f4
Merge jdk8u322-b01

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -1347,6 +1347,9 @@
 991bbb9501e2b295a17e1072292df75c5e814836 jdk8u312-b05
 8d77a33908346c055e389682e31e43848bdd050c aarch64-shenandoah-jdk8u312-b05
 cfb19b3c21112002e15aec1ff384d8b478433b32 aarch64-shenandoah-jdk8u312-b05-shenandoah-merge-2021-10-07
+991bbb9501e2b295a17e1072292df75c5e814836 jdk8u322-b00
 ece88aba26eb66ce321e0da344ce2bb148ec9d1e jdk8u312-b06
 132377e2edb21c55beb9dee2806e27979363977e jdk8u312-b07
 0fdfce14a6d9b30aac4fd0b17b71eeef58feb2ce aarch64-shenandoah-jdk8u312-b07
+132377e2edb21c55beb9dee2806e27979363977e jdk8u312-ga
+0d4bfc52c056c1155c46583e30a6828dfbe10bd9 jdk8u322-b01
diff --git a/make/data/cacerts/globalsignr2ca b/make/data/cacerts/globalsignr2ca
deleted file mode 100644
--- a/make/data/cacerts/globalsignr2ca
+++ /dev/null
@@ -1,29 +0,0 @@
-Owner: CN=GlobalSign, O=GlobalSign, OU=GlobalSign Root CA - R2
-Issuer: CN=GlobalSign, O=GlobalSign, OU=GlobalSign Root CA - R2
-Serial number: 400000000010f8626e60d
-Valid from: Fri Dec 15 08:00:00 GMT 2006 until: Wed Dec 15 08:00:00 GMT 2021
-Signature algorithm name: SHA1withRSA
-Subject Public Key Algorithm: 2048-bit RSA key
-Version: 3
------BEGIN CERTIFICATE-----
-MIIDujCCAqKgAwIBAgILBAAAAAABD4Ym5g0wDQYJKoZIhvcNAQEFBQAwTDEgMB4G
-A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjIxEzARBgNVBAoTCkdsb2JhbFNp
-Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDYxMjE1MDgwMDAwWhcNMjExMjE1
-MDgwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEG
-A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI
-hvcNAQEBBQADggEPADCCAQoCggEBAKbPJA6+Lm8omUVCxKs+IVSbC9N/hHD6ErPL
-v4dfxn+G07IwXNb9rfF73OX4YJYJkhD10FPe+3t+c4isUoh7SqbKSaZeqKeMWhG8
-eoLrvozps6yWJQeXSpkqBy+0Hne/ig+1AnwblrjFuTosvNYSuetZfeLQBoZfXklq
-tTleiDTsvHgMCJiEbKjNS7SgfQx5TfC4LcshytVsW33hoCmEofnTlEnLJGKRILzd
-C9XZzPnqJworc5HGnRusyMvo4KD0L5CLTfuwNhv2GXqF4G3yYROIXJ/gkwpRl4pa
-zq+r1feqCapgvdzZX99yqWATXgAByUr6P6TqBwMhAo6CygPCm48CAwEAAaOBnDCB
-mTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUm+IH
-V2ccHsBqBt5ZtJot39wZhi4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5n
-bG9iYWxzaWduLm5ldC9yb290LXIyLmNybDAfBgNVHSMEGDAWgBSb4gdXZxwewGoG
-3lm0mi3f3BmGLjANBgkqhkiG9w0BAQUFAAOCAQEAmYFThxxol4aR7OBKuEQLq4Gs
-J0/WwbgcQ3izDJr86iw8bmEbTUsp9Z8FHSbBuOmDAGJFtqkIk7mpM0sYmsL4h4hO
-291xNBrBVNpGP+DTKqttVCL1OmLNIG+6KYnX3ZHu01yiPqFbQfXf5WRDLenVOavS
-ot+3i9DAgBkcRcAtjOj4LaR0VknFBbVPFd5uRHg5h6h+u/N5GJG79G+dwfCMNYxd
-AfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmgQWpzU/qlULRuJQ/7
-TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq/H5COEBkEveegeGTLg==
------END CERTIFICATE-----
diff --git a/make/data/cacerts/identrustdstx3 b/make/data/cacerts/identrustdstx3
deleted file mode 100644
--- a/make/data/cacerts/identrustdstx3
+++ /dev/null
@@ -1,27 +0,0 @@
-Owner: CN=DST Root CA X3, O=Digital Signature Trust Co.
-Issuer: CN=DST Root CA X3, O=Digital Signature Trust Co.
-Serial number: 44afb080d6a327ba893039862ef8406b
-Valid from: Sat Sep 30 21:12:19 GMT 2000 until: Thu Sep 30 14:01:15 GMT 2021
-Signature algorithm name: SHA1withRSA
-Subject Public Key Algorithm: 2048-bit RSA key
-Version: 3
------BEGIN CERTIFICATE-----
-MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
-MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
-DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
-PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
-Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
-AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
-rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
-OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
-xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
-7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
-aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV
-HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG
-SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69
-ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr
-AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz
-R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5
-JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
-Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
------END CERTIFICATE-----
diff --git a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
--- a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
@@ -32,6 +32,7 @@
 import java.awt.print.*;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.concurrent.atomic.AtomicReference;
 
 import javax.print.*;
 import javax.print.attribute.PrintRequestAttributeSet;
@@ -56,6 +57,7 @@
     private static String sShouldNotReachHere = "Should not reach here.";
 
     private volatile SecondaryLoop printingLoop;
+    private AtomicReference<Throwable> printErrorRef = new AtomicReference<>();
 
     private boolean noDefaultPrinter = false;
 
@@ -265,6 +267,7 @@
                 performingPrinting = true;
                 userCancelled = false;
             }
+            printErrorRef.set(null);
 
             //Add support for PageRange
             PageRanges pr = (attributes == null) ?  null
@@ -323,6 +326,15 @@
             if (printingLoop != null) {
                 printingLoop.exit();
             }
+
+            Throwable printError = printErrorRef.getAndSet(null);
+            if (printError != null) {
+                if (printError instanceof PrinterException) {
+                    throw (PrinterException) printError;
+                }
+                throw (PrinterException)
+                    new PrinterException().initCause(printError);
+            }
         }
 
         // Normalize the collated, # copies, numPages, first/last pages. Need to
@@ -717,22 +729,36 @@
     private Rectangle2D printAndGetPageFormatArea(final Printable printable, final Graphics graphics, final PageFormat pageFormat, final int pageIndex) {
         final Rectangle2D[] ret = new Rectangle2D[1];
 
-        Runnable r = new Runnable() { public void run() { synchronized(ret) {
-            try {
-                int pageResult = printable.print(graphics, pageFormat, pageIndex);
-                if (pageResult != Printable.NO_SUCH_PAGE) {
-                    ret[0] = getPageFormatArea(pageFormat);
+        Runnable r = new Runnable() {
+            @Override
+            public void run() {
+                synchronized (ret) {
+                    try {
+                        int pageResult = printable.print(
+                            graphics, pageFormat, pageIndex);
+                        if (pageResult != Printable.NO_SUCH_PAGE) {
+                            ret[0] = getPageFormatArea(pageFormat);
+                        }
+                    } catch (Throwable t) {
+                        printErrorRef.compareAndSet(null, t);
+                    }
                 }
-            } catch (Exception e) {} // Original code bailed on any exception
-        }}};
+            }
+        };
 
         if (onEventThread) {
-            try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
+            try {
+                EventQueue.invokeAndWait(r);
+            } catch (Throwable t) {
+                printErrorRef.compareAndSet(null, t);
+            }
         } else {
             r.run();
         }
 
-        synchronized(ret) { return ret[0]; }
+        synchronized (ret) {
+            return ret[0];
+        }
     }
 
     // upcall from native
diff --git a/src/macosx/native/sun/awt/CRobot.m b/src/macosx/native/sun/awt/CRobot.m
--- a/src/macosx/native/sun/awt/CRobot.m
+++ b/src/macosx/native/sun/awt/CRobot.m
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,6 @@
  * questions.
  */
 
-
 #import "jni_util.h"
 
 #import <JavaNativeFoundation/JavaNativeFoundation.h>
@@ -33,6 +32,7 @@
 #import "sun_lwawt_macosx_CRobot.h"
 #import "java_awt_event_InputEvent.h"
 #import "sizecalc.h"
+#import "ThreadUtilities.h"
 
 
 // Starting number for event numbers generated by Robot.
@@ -96,38 +96,40 @@
     // Always set all states, in case Apple ever changes default behaviors.
     static int setupDone = 0;
     if (!setupDone) {
-        int i;
-        jint* tmp;
-        jboolean copy = JNI_FALSE;
+        [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+            int i;
+            jint* tmp;
+            jboolean copy = JNI_FALSE;
 
-        setupDone = 1;
-        // Don't block local events after posting ours
-        CGSetLocalEventsSuppressionInterval(0.0);
+            setupDone = 1;
+            // Don't block local events after posting ours
+            CGSetLocalEventsSuppressionInterval(0.0);
 
-        // Let our event's modifier key state blend with local hardware events
-        CGEnableEventStateCombining(TRUE);
+            // Let our event's modifier key state blend with local hardware events
+            CGEnableEventStateCombining(TRUE);
 
-        // Don't let our events block local hardware events
-        CGSetLocalEventsFilterDuringSupressionState(
-                                    kCGEventFilterMaskPermitAllEvents,
-                                    kCGEventSupressionStateSupressionInterval);
-        CGSetLocalEventsFilterDuringSupressionState(
-                                    kCGEventFilterMaskPermitAllEvents,
-                                    kCGEventSupressionStateRemoteMouseDrag);
+            // Don't let our events block local hardware events
+            CGSetLocalEventsFilterDuringSupressionState(
+                                        kCGEventFilterMaskPermitAllEvents,
+                                        kCGEventSupressionStateSupressionInterval);
+            CGSetLocalEventsFilterDuringSupressionState(
+                                        kCGEventFilterMaskPermitAllEvents,
+                                        kCGEventSupressionStateRemoteMouseDrag);
 
-        gsClickCount = 0;
-        gsLastClickTime = 0;
-        gsEventNumber = ROBOT_EVENT_NUMBER_START;
+            gsClickCount = 0;
+            gsLastClickTime = 0;
+            gsEventNumber = ROBOT_EVENT_NUMBER_START;
 
-        gsButtonEventNumber = (int*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(int), gNumberOfButtons);
-        if (gsButtonEventNumber == NULL) {
-            JNU_ThrowOutOfMemoryError(env, NULL);
-            return;
-        }
+            gsButtonEventNumber = (int*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(int), gNumberOfButtons);
+            if (gsButtonEventNumber == NULL) {
+                JNU_ThrowOutOfMemoryError(env, NULL);
+                return;
+            }
 
-        for (i = 0; i < gNumberOfButtons; ++i) {
-            gsButtonEventNumber[i] = ROBOT_EVENT_NUMBER_START;
-        }
+            for (i = 0; i < gNumberOfButtons; ++i) {
+                gsButtonEventNumber[i] = ROBOT_EVENT_NUMBER_START;
+            }
+        }];
     }
 }
 
@@ -239,14 +241,15 @@
 Java_sun_lwawt_macosx_CRobot_mouseWheel
 (JNIEnv *env, jobject peer, jint wheelAmt)
 {
-    CGEventRef event = CGEventCreateScrollWheelEvent(NULL,
-                                            kCGScrollEventUnitLine,
-                                            k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt);
-
-    if (event != NULL) {
-        CGEventPost(kCGSessionEventTap, event);
-        CFRelease(event);
-    }
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+        CGEventRef event = CGEventCreateScrollWheelEvent(NULL,
+                                                kCGScrollEventUnitLine,
+                                                k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt);
+        if (event != NULL) {
+            CGEventPost(kCGSessionEventTap, event);
+            CFRelease(event);
+        }
+    }];
 }
 
 /*
@@ -265,10 +268,12 @@
      * events. So, I've ended up disabling it and opted for another approach
      * that uses Accessibility API instead.
      */
-    CGKeyCode keyCode = GetCGKeyCode(javaKeyCode);
-    AXUIElementRef elem = AXUIElementCreateSystemWide();
-    AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed);
-    CFRelease(elem);
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+        CGKeyCode keyCode = GetCGKeyCode(javaKeyCode);
+        AXUIElementRef elem = AXUIElementCreateSystemWide();
+        AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed);
+        CFRelease(elem);
+    }];
 
 
 #if 0
@@ -345,13 +350,15 @@
 static void PostMouseEvent(const CGPoint point, CGMouseButton button,
                            CGEventType type, int clickCount, int eventNumber)
 {
-    CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, type, point, button);
-    if (mouseEvent != NULL) {
-        CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, clickCount);
-        CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, eventNumber);
-        CGEventPost(kCGSessionEventTap, mouseEvent);
-        CFRelease(mouseEvent);
-    }
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+        CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, type, point, button);
+        if (mouseEvent != NULL) {
+            CGEventSetIntegerValueField(mouseEvent, kCGMouseEventClickState, clickCount);
+            CGEventSetIntegerValueField(mouseEvent, kCGMouseEventNumber, eventNumber);
+            CGEventPost(kCGSessionEventTap, mouseEvent);
+            CFRelease(mouseEvent);
+        }
+    }];
 }
 
 // NOTE: Don't modify this table directly. It is machine generated. See below.
diff --git a/src/macosx/native/sun/osxapp/NSApplicationAWT.m b/src/macosx/native/sun/osxapp/NSApplicationAWT.m
--- a/src/macosx/native/sun/osxapp/NSApplicationAWT.m
+++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.m
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -77,7 +77,26 @@
 AWT_ASSERT_APPKIT_THREAD;
 
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+#ifdef __MAC_10_14 // code for SDK 10.14 or newer
+    SEL appearanceSel = @selector(setAppearance:); // macOS 10.14+
+    if ([self respondsToSelector:appearanceSel]) {
+        NSString *appearanceProp = [PropertiesUtilities
+                javaSystemPropertyForKey:@"apple.awt.application.appearance"
+                                 withEnv:env];
+        if (![@"system" isEqual:appearanceProp]) {
+            // by default use light mode, because dark mode is not supported yet
+            NSAppearance *appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
+            if (appearanceProp != nil) {
+                NSAppearance *requested = [NSAppearance appearanceNamed:appearanceProp];
+                if (requested != nil) {
+                    appearance = requested;
+                }
+            }
+            // [self setAppearance:appearance];
+            [self performSelector:appearanceSel withObject:appearance];
+        }
+    }
+#endif
     // Get default nib file location
     // NOTE: This should learn about the current java.version. Probably best thru
     //  the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this
diff --git a/src/share/classes/java/awt/image/RescaleOp.java b/src/share/classes/java/awt/image/RescaleOp.java
--- a/src/share/classes/java/awt/image/RescaleOp.java
+++ b/src/share/classes/java/awt/image/RescaleOp.java
@@ -27,6 +27,8 @@
 
 import java.awt.color.ColorSpace;
 import java.awt.geom.Rectangle2D;
+import java.awt.AlphaComposite;
+import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.geom.Point2D;
 import java.awt.RenderingHints;
@@ -193,9 +195,10 @@
                                           int   nBands,
                                           int   nElems) {
 
-        byte[][]        lutData = new byte[scale.length][nElems];
+        byte[][]        lutData = new byte[nBands][nElems];
+        int band;
 
-        for (int band=0; band<scale.length; band++) {
+        for (band=0; band<scale.length; band++) {
             float  bandScale   = scale[band];
             float  bandOff     = off[band];
             byte[] bandLutData = lutData[band];
@@ -212,6 +215,17 @@
             }
 
         }
+        int maxToCopy = (nBands == 4 && scale.length == 4) ? 4 : 3;
+        while (band < lutData.length && band < maxToCopy) {
+           System.arraycopy(lutData[band-1], 0, lutData[band], 0, nElems);
+           band++;
+        }
+        if (nBands == 4 && band < nBands) {
+           byte[] bandLutData = lutData[band];
+           for (int i=0; i<nElems; i++) {
+              bandLutData[i] = (byte)i;
+           }
+        }
 
         return new ByteLookupTable(0, lutData);
     }
@@ -228,9 +242,10 @@
                                             int   nBands,
                                             int   nElems) {
 
-        short[][]        lutData = new short[scale.length][nElems];
+        short[][]        lutData = new short[nBands][nElems];
+        int band = 0;
 
-        for (int band=0; band<scale.length; band++) {
+        for (band=0; band<scale.length; band++) {
             float   bandScale   = scale[band];
             float   bandOff     = off[band];
             short[] bandLutData = lutData[band];
@@ -246,6 +261,17 @@
                 bandLutData[i] = (short)val;
             }
         }
+        int maxToCopy = (nBands == 4 && scale.length == 4) ? 4 : 3;
+        while (band < lutData.length && band < maxToCopy) {
+           System.arraycopy(lutData[band-1], 0, lutData[band], 0, nElems);
+           band++;
+        }
+        if (nBands == 4 && band < nBands) {
+           short[] bandLutData = lutData[band];
+           for (int i=0; i<nElems; i++) {
+              bandLutData[i] = (short)i;
+           }
+        }
 
         return new ShortLookupTable(0, lutData);
     }
@@ -300,6 +326,19 @@
             }
         }
 
+      if (dstSM instanceof ComponentSampleModel) {
+           ComponentSampleModel dsm = (ComponentSampleModel)dstSM;
+           if (dsm.getPixelStride() != dst.getNumBands()) {
+               return false;
+           }
+        }
+        if (srcSM instanceof ComponentSampleModel) {
+           ComponentSampleModel csm = (ComponentSampleModel)srcSM;
+           if (csm.getPixelStride() != src.getNumBands()) {
+               return false;
+           }
+        }
+
         return true;
     }
 
@@ -326,16 +365,16 @@
     public final BufferedImage filter (BufferedImage src, BufferedImage dst) {
         ColorModel srcCM = src.getColorModel();
         ColorModel dstCM;
-        int numBands = srcCM.getNumColorComponents();
-
+        int numSrcColorComp = srcCM.getNumColorComponents();
+        int scaleConst = length;
 
         if (srcCM instanceof IndexColorModel) {
             throw new
                 IllegalArgumentException("Rescaling cannot be "+
                                          "performed on an indexed image");
         }
-        if (length != 1 && length != numBands &&
-            length != srcCM.getNumComponents())
+        if (scaleConst != 1 && scaleConst != numSrcColorComp &&
+            scaleConst != srcCM.getNumComponents())
         {
             throw new IllegalArgumentException("Number of scaling constants "+
                                                "does not equal the number of"+
@@ -344,15 +383,17 @@
         }
 
         boolean needToConvert = false;
+        boolean needToDraw = false;
 
         // Include alpha
-        if (length > numBands && srcCM.hasAlpha()) {
-            length = numBands+1;
+        if (scaleConst > numSrcColorComp && srcCM.hasAlpha()) {
+            scaleConst = numSrcColorComp+1;
         }
 
         int width = src.getWidth();
         int height = src.getHeight();
 
+        BufferedImage origDst = dst;
         if (dst == null) {
             dst = createCompatibleDestImage(src, null);
             dstCM = srcCM;
@@ -373,73 +414,47 @@
 
             dstCM = dst.getColorModel();
             if(srcCM.getColorSpace().getType() !=
-               dstCM.getColorSpace().getType()) {
+                 dstCM.getColorSpace().getType()) {
                 needToConvert = true;
                 dst = createCompatibleDestImage(src, null);
             }
 
         }
 
-        BufferedImage origDst = dst;
-
         //
         // Try to use a native BI rescale operation first
         //
         if (ImagingLib.filter(this, src, dst) == null) {
+            if (src.getRaster().getNumBands() !=
+                dst.getRaster().getNumBands()) {
+                needToDraw = true;
+                dst = createCompatibleDestImage(src, null);
+            }
+
             //
             // Native BI rescale failed - convert to rasters
             //
             WritableRaster srcRaster = src.getRaster();
             WritableRaster dstRaster = dst.getRaster();
 
-            if (srcCM.hasAlpha()) {
-                if (numBands-1 == length || length == 1) {
-                    int minx = srcRaster.getMinX();
-                    int miny = srcRaster.getMinY();
-                    int[] bands = new int[numBands-1];
-                    for (int i=0; i < numBands-1; i++) {
-                        bands[i] = i;
-                    }
-                    srcRaster =
-                        srcRaster.createWritableChild(minx, miny,
-                                                      srcRaster.getWidth(),
-                                                      srcRaster.getHeight(),
-                                                      minx, miny,
-                                                      bands);
-                }
-            }
-            if (dstCM.hasAlpha()) {
-                int dstNumBands = dstRaster.getNumBands();
-                if (dstNumBands-1 == length || length == 1) {
-                    int minx = dstRaster.getMinX();
-                    int miny = dstRaster.getMinY();
-                    int[] bands = new int[numBands-1];
-                    for (int i=0; i < numBands-1; i++) {
-                        bands[i] = i;
-                    }
-                    dstRaster =
-                        dstRaster.createWritableChild(minx, miny,
-                                                      dstRaster.getWidth(),
-                                                      dstRaster.getHeight(),
-                                                      minx, miny,
-                                                      bands);
-                }
-            }
-
             //
             // Call the raster filter method
             //
-            filter(srcRaster, dstRaster);
-
+            filterRasterImpl(srcRaster, dstRaster, scaleConst, false);
         }
 
+        if (needToDraw) {
+             Graphics2D g = origDst.createGraphics();
+             g.setComposite(AlphaComposite.Src);
+             g.drawImage(dst, 0, 0, width, height, null);
+             g.dispose();
+        }
         if (needToConvert) {
             // ColorModels are not the same
             ColorConvertOp ccop = new ColorConvertOp(hints);
-            ccop.filter(dst, origDst);
+            dst = ccop.filter(dst, origDst);
         }
-
-        return origDst;
+        return dst;
     }
 
     /**
@@ -461,6 +476,11 @@
      *         stated in the class comments.
      */
     public final WritableRaster filter (Raster src, WritableRaster dst)  {
+        return filterRasterImpl(src, dst, length, true);
+    }
+
+    private WritableRaster filterRasterImpl(Raster src, WritableRaster dst,
+                                            int scaleConst, boolean sCheck) {
         int numBands = src.getNumBands();
         int width  = src.getWidth();
         int height = src.getHeight();
@@ -484,15 +504,15 @@
                             + " does not equal number of bands in dest "
                             + dst.getNumBands());
         }
+
         // Make sure that the arrays match
         // Make sure that the low/high/constant arrays match
-        if (length != 1 && length != src.getNumBands()) {
+        if (sCheck && scaleConst != 1 && scaleConst != src.getNumBands()) {
             throw new IllegalArgumentException("Number of scaling constants "+
                                                "does not equal the number of"+
                                                " of bands in the src raster");
         }
 
-
         //
         // Try for a native raster rescale first
         //
@@ -523,7 +543,7 @@
             //
             // Fall back to the slow code
             //
-            if (length > 1) {
+            if (scaleConst > 1) {
                 step = 1;
             }
 
@@ -558,8 +578,14 @@
                     srcPix = src.getPixel(sX, sY, srcPix);
                     tidx = 0;
                     for (int z=0; z<numBands; z++, tidx += step) {
-                        val = (int)(srcPix[z]*scaleFactors[tidx]
-                                          + offsets[tidx]);
+                        if ((scaleConst == 1 || scaleConst == 3) &&
+                            (z == 3) && (numBands == 4)) {
+                           val = srcPix[z];
+                        } else {
+                            val = (int)(srcPix[z]*scaleFactors[tidx]
+                                              + offsets[tidx]);
+
+                        }
                         // Clamp
                         if ((val & dstMask[z]) != 0) {
                             if (val < 0) {
diff --git a/src/share/classes/java/lang/Thread.java b/src/share/classes/java/lang/Thread.java
--- a/src/share/classes/java/lang/Thread.java
+++ b/src/share/classes/java/lang/Thread.java
@@ -36,6 +36,8 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.LockSupport;
+
+import jdk.internal.misc.TerminatingThreadLocal;
 import sun.nio.ch.Interruptible;
 import sun.reflect.CallerSensitive;
 import sun.reflect.Reflection;
@@ -754,6 +756,9 @@
      * a chance to clean up before it actually exits.
      */
     private void exit() {
+        if (TerminatingThreadLocal.REGISTRY.isPresent()) {
+            TerminatingThreadLocal.threadTerminated();
+        }
         if (group != null) {
             group.threadTerminated(this);
             group = null;
diff --git a/src/share/classes/java/lang/ThreadLocal.java b/src/share/classes/java/lang/ThreadLocal.java
--- a/src/share/classes/java/lang/ThreadLocal.java
+++ b/src/share/classes/java/lang/ThreadLocal.java
@@ -24,6 +24,8 @@
  */
 
 package java.lang;
+import jdk.internal.misc.TerminatingThreadLocal;
+
 import java.lang.ref.*;
 import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -171,6 +173,19 @@
     }
 
     /**
+     * Returns {@code true} if there is a value in the current thread's copy of
+     * this thread-local variable, even if that values is {@code null}.
+     *
+     * @return {@code true} if current thread has associated value in this
+     *         thread-local variable; {@code false} if not
+     */
+    boolean isPresent() {
+        Thread t = Thread.currentThread();
+        ThreadLocalMap map = getMap(t);
+        return map != null && map.getEntry(this) != null;
+    }
+
+    /**
      * Variant of set() to establish initialValue. Used instead
      * of set() in case user has overridden the set() method.
      *
@@ -180,10 +195,14 @@
         T value = initialValue();
         Thread t = Thread.currentThread();
         ThreadLocalMap map = getMap(t);
-        if (map != null)
+        if (map != null) {
             map.set(this, value);
-        else
+        } else {
             createMap(t, value);
+        }
+        if (this instanceof TerminatingThreadLocal) {
+            TerminatingThreadLocal.register((TerminatingThreadLocal<?>) this);
+        }
         return value;
     }
 
@@ -199,10 +218,11 @@
     public void set(T value) {
         Thread t = Thread.currentThread();
         ThreadLocalMap map = getMap(t);
-        if (map != null)
+        if (map != null) {
             map.set(this, value);
-        else
+        } else {
             createMap(t, value);
+        }
     }
 
     /**
@@ -218,8 +238,9 @@
      */
      public void remove() {
          ThreadLocalMap m = getMap(Thread.currentThread());
-         if (m != null)
+         if (m != null) {
              m.remove(this);
+         }
      }
 
     /**
diff --git a/src/share/classes/java/util/JapaneseImperialCalendar.java b/src/share/classes/java/util/JapaneseImperialCalendar.java
--- a/src/share/classes/java/util/JapaneseImperialCalendar.java
+++ b/src/share/classes/java/util/JapaneseImperialCalendar.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -859,7 +859,7 @@
                 } else if (nfd >= (month1 + monthLength)) {
                     nfd = month1 + monthLength - 1;
                 }
-                set(DAY_OF_MONTH, (int)(nfd - month1) + 1);
+                set(DAY_OF_MONTH, getCalendarDate(nfd).getDayOfMonth());
                 return;
             }
 
@@ -1429,7 +1429,7 @@
                     CalendarDate d = gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
                     d.setDate(date.getNormalizedYear(), date.getMonth(), 1);
                     int dayOfWeek = gcal.getDayOfWeek(d);
-                    int monthLength = gcal.getMonthLength(d);
+                    int monthLength = actualMonthLength();
                     dayOfWeek -= getFirstDayOfWeek();
                     if (dayOfWeek < 0) {
                         dayOfWeek += 7;
@@ -2210,7 +2210,7 @@
     private int actualMonthLength() {
         int length = jcal.getMonthLength(jdate);
         int eraIndex = getTransitionEraIndex(jdate);
-        if (eraIndex == -1) {
+        if (eraIndex != -1) {
             long transitionFixedDate = sinceFixedDates[eraIndex];
             CalendarDate d = eras[eraIndex].getSinceDate();
             if (transitionFixedDate <= cachedFixedDate) {
diff --git a/src/share/classes/jdk/internal/misc/TerminatingThreadLocal.java b/src/share/classes/jdk/internal/misc/TerminatingThreadLocal.java
new file mode 100644
--- /dev/null
+++ b/src/share/classes/jdk/internal/misc/TerminatingThreadLocal.java
@@ -0,0 +1,105 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.internal.misc;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+
+/**
+ * A thread-local variable that is notified when a thread terminates and
+ * it has been initialized in the terminating thread (even if it was
+ * initialized with a null value).
+ */
+public class TerminatingThreadLocal<T> extends ThreadLocal<T> {
+
+    @Override
+    public void set(T value) {
+        super.set(value);
+        register(this);
+    }
+
+    @Override
+    public void remove() {
+        super.remove();
+        unregister(this);
+    }
+
+    /**
+     * Invoked by a thread when terminating and this thread-local has an associated
+     * value for the terminating thread (even if that value is null), so that any
+     * native resources maintained by the value can be released.
+     *
+     * @param value current thread's value of this thread-local variable
+     *              (may be null but only if null value was explicitly initialized)
+     */
+    protected void threadTerminated(T value) {
+    }
+
+    // following methods and field are implementation details and should only be
+    // called from the corresponding code int Thread/ThreadLocal class.
+
+    /**
+     * Invokes the TerminatingThreadLocal's {@link #threadTerminated()} method
+     * on all instances registered in current thread.
+     */
+    public static void threadTerminated() {
+        for (TerminatingThreadLocal<?> ttl : REGISTRY.get()) {
+            ttl._threadTerminated();
+        }
+    }
+
+    private void _threadTerminated() { threadTerminated(get()); }
+
+    /**
+     * Register given TerminatingThreadLocal
+     *
+     * @param tl the ThreadLocal to register
+     */
+    public static void register(TerminatingThreadLocal<?> tl) {
+        REGISTRY.get().add(tl);
+    }
+
+    /**
+     * Unregister given TerminatingThreadLocal
+     *
+     * @param tl the ThreadLocal to unregister
+     */
+    private static void unregister(TerminatingThreadLocal<?> tl) {
+        REGISTRY.get().remove(tl);
+    }
+
+    /**
+     * a per-thread registry of TerminatingThreadLocal(s) that have been registered
+     * but later not unregistered in a particular thread.
+     */
+    public static final ThreadLocal<Collection<TerminatingThreadLocal<?>>> REGISTRY =
+        new ThreadLocal<Collection<TerminatingThreadLocal<?>>>() {
+            @Override
+            protected Collection<TerminatingThreadLocal<?>> initialValue() {
+                return Collections.newSetFromMap(new IdentityHashMap<>(4));
+            }
+        };
+}
diff --git a/src/share/classes/jdk/jfr/conf/default.jfc b/src/share/classes/jdk/jfr/conf/default.jfc
--- a/src/share/classes/jdk/jfr/conf/default.jfc
+++ b/src/share/classes/jdk/jfr/conf/default.jfc
@@ -29,6 +29,7 @@
 
     <event name="jdk.ThreadStart">
       <setting name="enabled">true</setting>
+      <setting name="stackTrace">true</setting>
     </event>
 
     <event name="jdk.ThreadEnd">
diff --git a/src/share/classes/jdk/jfr/conf/profile.jfc b/src/share/classes/jdk/jfr/conf/profile.jfc
--- a/src/share/classes/jdk/jfr/conf/profile.jfc
+++ b/src/share/classes/jdk/jfr/conf/profile.jfc
@@ -29,6 +29,7 @@
 
     <event name="jdk.ThreadStart">
       <setting name="enabled">true</setting>
+      <setting name="stackTrace">true</setting>
     </event>
 
     <event name="jdk.ThreadEnd">
diff --git a/src/share/classes/sun/net/httpserver/ChunkedInputStream.java b/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
--- a/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
+++ b/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -135,6 +135,8 @@
             needToReadHeader = true;
             consumeCRLF();
         }
+        if (n < 0 && !eof)
+            throw new IOException("connection closed before all data received");
         return n;
     }
 
diff --git a/src/share/classes/sun/net/httpserver/FixedLengthInputStream.java b/src/share/classes/sun/net/httpserver/FixedLengthInputStream.java
--- a/src/share/classes/sun/net/httpserver/FixedLengthInputStream.java
+++ b/src/share/classes/sun/net/httpserver/FixedLengthInputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -60,6 +60,8 @@
                 t.getServerImpl().requestCompleted (t.getConnection());
             }
         }
+        if (n < 0 && !eof)
+            throw new IOException("connection closed before all data received");
         return n;
     }
 
diff --git a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
--- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
+++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
@@ -1177,7 +1177,12 @@
                             if (p != Proxy.NO_PROXY) {
                                 sel.connectFailed(uri, p.address(), ioex);
                                 if (!it.hasNext()) {
-                                    throw ioex;
+                                    if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
+                                        logger.finest("Retrying with proxy: " + p.toString());
+                                    }
+                                    http = getNewHttpClient(url, p, connectTimeout, false);
+                                    http.setReadTimeout(readTimeout);
+                                    break;
                                 }
                             } else {
                                 throw ioex;
diff --git a/src/share/classes/sun/nio/ch/Util.java b/src/share/classes/sun/nio/ch/Util.java
--- a/src/share/classes/sun/nio/ch/Util.java
+++ b/src/share/classes/sun/nio/ch/Util.java
@@ -35,6 +35,7 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.*;
+import jdk.internal.misc.TerminatingThreadLocal;
 import sun.misc.Unsafe;
 import sun.misc.Cleaner;
 import sun.security.action.GetPropertyAction;
@@ -51,13 +52,18 @@
     private static final long MAX_CACHED_BUFFER_SIZE = getMaxCachedBufferSize();
 
     // Per-thread cache of temporary direct buffers
-    private static ThreadLocal<BufferCache> bufferCache =
-        new ThreadLocal<BufferCache>()
-    {
+    private static ThreadLocal<BufferCache> bufferCache = new TerminatingThreadLocal<BufferCache>() {
         @Override
         protected BufferCache initialValue() {
             return new BufferCache();
         }
+        @Override
+        protected void threadTerminated(BufferCache cache) { // will never be null
+            while (!cache.isEmpty()) {
+                ByteBuffer bb = cache.removeFirst();
+                free(bb);
+            }
+        }
     };
 
     /**
diff --git a/src/share/classes/sun/nio/fs/NativeBuffers.java b/src/share/classes/sun/nio/fs/NativeBuffers.java
--- a/src/share/classes/sun/nio/fs/NativeBuffers.java
+++ b/src/share/classes/sun/nio/fs/NativeBuffers.java
@@ -25,6 +25,7 @@
 
 package sun.nio.fs;
 
+import jdk.internal.misc.TerminatingThreadLocal;
 import sun.misc.Unsafe;
 
 /**
@@ -37,8 +38,21 @@
     private static final Unsafe unsafe = Unsafe.getUnsafe();
 
     private static final int TEMP_BUF_POOL_SIZE = 3;
-    private static ThreadLocal<NativeBuffer[]> threadLocal =
-        new ThreadLocal<NativeBuffer[]>();
+    private static ThreadLocal<NativeBuffer[]> threadLocal = new TerminatingThreadLocal<NativeBuffer[]>() {
+        @Override
+        protected void threadTerminated(NativeBuffer[] buffers) {
+            // threadLocal may be initialized but with initialValue of null
+            if (buffers != null) {
+                for (int i = 0; i < TEMP_BUF_POOL_SIZE; i++) {
+                    NativeBuffer buffer = buffers[i];
+                    if (buffer != null) {
+                        buffer.cleaner().clean();
+                        buffers[i] = null;
+                    }
+                }
+            }
+        }
+    };
 
     /**
      * Allocates a native buffer, of at least the given size, from the heap.
diff --git a/src/share/classes/sun/print/ServiceDialog.java b/src/share/classes/sun/print/ServiceDialog.java
--- a/src/share/classes/sun/print/ServiceDialog.java
+++ b/src/share/classes/sun/print/ServiceDialog.java
@@ -1421,13 +1421,13 @@
             topMargin.addActionListener(this);
             topMargin.getAccessibleContext().setAccessibleName(
                                               getMsg("label.topmargin"));
-            topMargin = new JFormattedTextField(nf);
+
             bottomMargin = new JFormattedTextField(nf);
             bottomMargin.addFocusListener(this);
             bottomMargin.addActionListener(this);
             bottomMargin.getAccessibleContext().setAccessibleName(
                                               getMsg("label.bottommargin"));
-            topMargin = new JFormattedTextField(nf);
+
             c.gridwidth = GridBagConstraints.RELATIVE;
             lblLeft = new JLabel(getMsg("label.leftmargin") + " " + unitsMsg,
                                  JLabel.LEADING);
diff --git a/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/src/share/classes/sun/security/pkcs11/SunPKCS11.java
--- a/src/share/classes/sun/security/pkcs11/SunPKCS11.java
+++ b/src/share/classes/sun/security/pkcs11/SunPKCS11.java
@@ -887,6 +887,25 @@
         createPoller();
     }
 
+    private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
+            throws PKCS11Exception {
+        // assume full support if no mech info available
+        // For vendor-specific mechanisms, often no mech info is provided
+        boolean partialSupport = false;
+
+        if (mechInfo != null) {
+            if ((mechInfo.flags & CKF_DECRYPT) != 0) {
+                // non-legacy cipher mechs should support encryption
+                partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
+            }
+            if ((mechInfo.flags & CKF_VERIFY) != 0) {
+                // non-legacy signature mechs should support signing
+                partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
+            }
+        }
+        return partialSupport;
+    }
+
     // test if a token is present and initialize this provider for it if so.
     // does nothing if no token is found
     // called from constructor and by poller
@@ -920,24 +939,35 @@
         // return a CKM_DES_CBC_PAD.
         final Map<Descriptor,Integer> supportedAlgs =
                                         new HashMap<Descriptor,Integer>();
+
         for (int i = 0; i < supportedMechanisms.length; i++) {
             long longMech = supportedMechanisms[i];
-            boolean isEnabled = config.isEnabled(longMech);
+            CK_MECHANISM_INFO mechInfo = token.getMechanismInfo(longMech);
             if (showInfo) {
-                CK_MECHANISM_INFO mechInfo =
-                        p11.C_GetMechanismInfo(slotID, longMech);
                 System.out.println("Mechanism " +
-                        Functions.getMechanismName(longMech) + ":");
-                if (isEnabled == false) {
+                    Functions.getMechanismName(longMech) + ":");
+                System.out.println(mechInfo == null?
+                    (Constants.INDENT + "info n/a") :
+                    mechInfo);
+            }
+            if (!config.isEnabled(longMech)) {
+                if (showInfo) {
                     System.out.println("DISABLED in configuration");
                 }
-                System.out.println(mechInfo);
-            }
-            if (isEnabled == false) {
                 continue;
             }
+            if (isLegacy(mechInfo)) {
+                if (showInfo) {
+                    System.out.println("DISABLED due to legacy");
+                }
+                continue;
+            }
+
             // we do not know of mechs with the upper 32 bits set
             if (longMech >>> 32 != 0) {
+                if (showInfo) {
+                    System.out.println("DISABLED due to unknown mech value");
+                }
                 continue;
             }
             int mech = (int)longMech;
diff --git a/src/share/native/sun/font/freetypeScaler.c b/src/share/native/sun/font/freetypeScaler.c
--- a/src/share/native/sun/font/freetypeScaler.c
+++ b/src/share/native/sun/font/freetypeScaler.c
@@ -474,17 +474,41 @@
     return ptr_to_jlong(context);
 }
 
+// values used by FreeType (as of version 2.10.1) for italics transformation matrix in FT_GlyphSlot_Oblique
+#define FT_MATRIX_ONE 0x10000
+#define FT_MATRIX_OBLIQUE_XY 0x0366A
+
+static void setupTransform(FT_Matrix* target, FTScalerContext *context) {
+    FT_Matrix* transform = &context->transform;
+    if (context->doItalize) {
+        // we cannot use FT_GlyphSlot_Oblique as it doesn't work well with arbitrary transforms,
+        // so we add corresponding shear transform to the requested glyph transformation
+        target->xx = FT_MATRIX_ONE;
+        target->xy = FT_MATRIX_OBLIQUE_XY;
+        target->yx = 0;
+        target->yy = FT_MATRIX_ONE;
+        FT_Matrix_Multiply(transform, target);
+    } else {
+        target->xx = transform->xx;
+        target->xy = transform->xy;
+        target->yx = transform->yx;
+        target->yy = transform->yy;
+    }
+}
+
 static int setupFTContext(JNIEnv *env,
                           jobject font2D,
                           FTScalerInfo *scalerInfo,
                           FTScalerContext *context) {
+    FT_Matrix matrix;
     int errCode = 0;
 
     scalerInfo->env = env;
     scalerInfo->font2D = font2D;
 
     if (context != NULL) {
-        FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
+        setupTransform(&matrix, context);
+        FT_Set_Transform(scalerInfo->face, &matrix, NULL);
 
         errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
 
@@ -498,11 +522,8 @@
     return errCode;
 }
 
-/* ftsynth.c uses (0x10000, 0x0366A, 0x0, 0x10000) matrix to get oblique
-   outline.  Therefore x coordinate will change by 0x0366A*y.
-   Note that y coordinate does not change. These values are based on
-   libfreetype version 2.9.1. */
-#define OBLIQUE_MODIFIER(y)  (context->doItalize ? ((y)*0x366A/0x10000) : 0)
+// using same values as for the transformation matrix
+#define OBLIQUE_MODIFIER(y)  (context->doItalize ? ((y)*FT_MATRIX_OBLIQUE_XY/FT_MATRIX_ONE) : 0)
 
 /* FT_GlyphSlot_Embolden (ftsynth.c) uses FT_MulFix(units_per_EM, y_scale) / 24
  * strength value when glyph format is FT_GLYPH_FORMAT_OUTLINE. This value has
@@ -876,9 +897,6 @@
     if (context->doBold) { /* if bold style */
         FT_GlyphSlot_Embolden(ftglyph);
     }
-    if (context->doItalize) { /* if oblique */
-        FT_GlyphSlot_Oblique(ftglyph);
-    }
 
     /* generate bitmap if it is not done yet
      e.g. if algorithmic styling is performed and style was added to outline */
@@ -1153,9 +1171,6 @@
     if (context->doBold) { /* if bold style */
         FT_GlyphSlot_Embolden(ftglyph);
     }
-    if (context->doItalize) { /* if oblique */
-        FT_GlyphSlot_Oblique(ftglyph);
-    }
 
     FT_Outline_Translate(&ftglyph->outline,
                          FloatToF26Dot6(xpos),
diff --git a/src/solaris/native/java/net/NetworkInterface.c b/src/solaris/native/java/net/NetworkInterface.c
--- a/src/solaris/native/java/net/NetworkInterface.c
+++ b/src/solaris/native/java/net/NetworkInterface.c
@@ -467,6 +467,7 @@
 
         // put the NetworkInterface into the array
         (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
+        (*env)->DeleteLocalRef(env, netifObj);
 
         curr = curr->next;
     }
@@ -730,12 +731,14 @@
                             ((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
                         JNU_CHECK_EXCEPTION_RETURN(env, NULL);
                         (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
+                        (*env)->DeleteLocalRef(env, ia2Obj);
                     } else {
                         return NULL;
                     }
                 }
                 (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
                 (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
+                (*env)->DeleteLocalRef(env, ibObj);
             } else {
                 return NULL;
             }
@@ -765,6 +768,7 @@
                 (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
                 (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
                 (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
+                (*env)->DeleteLocalRef(env, ibObj);
             } else {
                 return NULL;
             }
@@ -772,6 +776,7 @@
 #endif
 
         (*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj);
+        (*env)->DeleteLocalRef(env, iaObj);
         addrP = addrP->next;
     }
 
@@ -804,6 +809,11 @@
     (*env)->SetObjectField(env, netifObj, ni_bindsID, bindArr);
     (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
 
+    (*env)->DeleteLocalRef(env, name);
+    (*env)->DeleteLocalRef(env, addrArr);
+    (*env)->DeleteLocalRef(env, bindArr);
+    (*env)->DeleteLocalRef(env, childArr);
+
     // return the NetworkInterface
     return netifObj;
 }
diff --git a/src/windows/native/java/net/NetworkInterface.c b/src/windows/native/java/net/NetworkInterface.c
--- a/src/windows/native/java/net/NetworkInterface.c
+++ b/src/windows/native/java/net/NetworkInterface.c
@@ -616,8 +616,10 @@
                   return NULL;
               }
               (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
+              (*env)->DeleteLocalRef(env, ia2Obj);
               (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
               (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
+              (*env)->DeleteLocalRef(env, ibObj);
             }
         } else /* AF_INET6 */ {
             int scope;
@@ -642,9 +644,11 @@
                 (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
                 (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
                 (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
+                (*env)->DeleteLocalRef(env, ibObj);
             }
         }
         (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
+        (*env)->DeleteLocalRef(env, iaObj);
         addrs = addrs->next;
         addr_index++;
     }
@@ -652,6 +656,10 @@
     (*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);
 
     free_netaddr(netaddrP);
+    (*env)->DeleteLocalRef(env, name);
+    (*env)->DeleteLocalRef(env, displayName);
+    (*env)->DeleteLocalRef(env, addrArr);
+    (*env)->DeleteLocalRef(env, bindsArr);
 
     /*
      * Windows doesn't have virtual interfaces, so child array
@@ -662,6 +670,7 @@
       return NULL;
     }
     (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
+    (*env)->DeleteLocalRef(env, childArr);
 
     /* return the NetworkInterface */
     return netifObj;
@@ -882,6 +891,7 @@
 
         /* put the NetworkInterface into the array */
         (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
+        (*env)->DeleteLocalRef(env, netifObj);
 
         curr = curr->next;
     }
diff --git a/test/com/sun/net/httpserver/bugs/TruncatedRequestBody.java b/test/com/sun/net/httpserver/bugs/TruncatedRequestBody.java
new file mode 100644
--- /dev/null
+++ b/test/com/sun/net/httpserver/bugs/TruncatedRequestBody.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8190793
+ * @summary Httpserver does not detect truncated request body
+ */
+
+import com.sun.net.httpserver.HttpContext;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/*
+ * Send two POST requests to the server which are both trucated
+ * and socket closed. Server needs to detect this and throw an IOException
+ * in getRequestBody().read(). Two variants for fixed length and chunked.
+ */
+public class TruncatedRequestBody {
+    static volatile boolean error = false;
+
+    static CountDownLatch latch = new CountDownLatch(2);
+
+    static class Handler implements HttpHandler {
+
+        @Override
+        public void handle(HttpExchange exch) throws IOException {
+            InputStream is = exch.getRequestBody();
+            int c, count = 0;
+            byte[] buf = new byte[128];
+            try {
+            while ((c=is.read(buf)) > 0)
+                count += c;
+            } catch (IOException e) {
+                System.out.println("Exception caught");
+                latch.countDown();
+                throw e;
+            }
+            // shouldn't get to here
+            error = true;
+            latch.countDown();
+            System.out.println("Read " + count + " bytes");
+            is.close();
+            exch.sendResponseHeaders(200, -1);
+        }
+
+    }
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) throws IOException, InterruptedException {
+        Logger logger = Logger.getLogger("com.sun.net.httpserver");
+        ConsoleHandler h = new ConsoleHandler();
+        h.setLevel(Level.ALL);
+        logger.setLevel(Level.ALL);
+        logger.addHandler(h);
+
+        InetSocketAddress addr = new InetSocketAddress(0);
+        HttpServer server = HttpServer.create(addr, 10);
+        HttpContext ct = server.createContext("/", new Handler());
+        ExecutorService ex = Executors.newCachedThreadPool();
+        server.setExecutor(ex);
+        server.start();
+
+        int port = server.getAddress().getPort();
+
+        // Test 1: fixed length
+
+        Socket sock = new Socket("127.0.0.1", port);
+        String s1 = "POST /foo HTTP/1.1\r\nContent-length: 200000\r\n"
+                + "\r\nfoo bar99";
+
+        OutputStream os = sock.getOutputStream();
+        os.write(s1.getBytes(StandardCharsets.ISO_8859_1));
+        Thread.sleep(500);
+
+        sock.close();
+
+        // Test 2: chunked
+
+        String s2 = "POST /foo HTTP/1.1\r\nTransfer-encoding: chunked\r\n\r\n" +
+                "100\r\nFoo bar";
+        sock = new Socket("127.0.0.1", port);
+        os = sock.getOutputStream();
+        os.write(s2.getBytes(StandardCharsets.ISO_8859_1));
+        Thread.sleep(500);
+        sock.close();
+        latch.await();
+        server.stop(0);
+        ex.shutdownNow();
+        if (error)
+            throw new RuntimeException("Test failed");
+    }
+}
diff --git a/test/java/awt/ColorClass/EqualityTest/EqualityTest.java b/test/java/awt/ColorClass/EqualityTest/EqualityTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/ColorClass/EqualityTest/EqualityTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2011, 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.Color;
+import java.awt.SystemColor;
+
+/**
+ * @test
+ * @bug 4559156
+ * @summary java.awt.Color.equals() does not work when comparing to
+ *          java.awt.SystemColor
+ */
+public final class EqualityTest {
+
+    private final static SystemColor [] colorArray = {
+        SystemColor.desktop,
+        SystemColor.activeCaption,
+        SystemColor.activeCaptionText,
+        SystemColor.activeCaptionBorder,
+        SystemColor.inactiveCaption,
+        SystemColor.inactiveCaptionText,
+        SystemColor.inactiveCaptionBorder,
+        SystemColor.window,
+        SystemColor.windowBorder,
+        SystemColor.windowText,
+        SystemColor.menu,
+        SystemColor.menuText,
+        SystemColor.text,
+        SystemColor.textText,
+        SystemColor.textHighlight,
+        SystemColor.textHighlightText,
+        SystemColor.textInactiveText,
+        SystemColor.control,
+        SystemColor.controlText,
+        SystemColor.controlHighlight,
+        SystemColor.controlLtHighlight,
+        SystemColor.controlShadow,
+        SystemColor.controlDkShadow,
+        SystemColor.scrollbar,
+        SystemColor.info,
+        SystemColor.infoText
+    };
+
+    public static void main(final String[] str) {
+        for (final SystemColor system : colorArray) {
+            Color color = new Color(system.getRGB(), system.getAlpha() < 255);
+            System.out.printf("System color = %s = [%d]: color = %s [%d]%n",
+                              system, system.getRGB(), color, color.getRGB());
+            boolean equalityStatement1 = color.equals(system);
+            boolean equalityStatement2 = system.equals(color);
+            if (!equalityStatement1 || !equalityStatement2) {
+                System.out.println("COLOR.equals(SC) = " + equalityStatement1);
+                System.out.println("SC.equals(COLOR) = " + equalityStatement2);
+                throw new RuntimeException("The equals() method doesn't work correctly");
+            }
+        }
+    }
+}
diff --git a/test/java/awt/Robot/NonEmptyErrorStream.java b/test/java/awt/Robot/NonEmptyErrorStream.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/Robot/NonEmptyErrorStream.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * 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.Frame;
+import java.awt.Robot;
+import java.awt.*;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.util.concurrent.TimeUnit;
+
+import jdk.testlibrary.OutputAnalyzer;
+import jdk.testlibrary.ProcessTools;
+
+/**
+ * @test
+ * @bug 8226806
+ * @key headful
+ * @library /lib/testlibrary
+ * @summary checks for unexpected output in stderr and stdout
+ */
+public final class NonEmptyErrorStream {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length == 0) {
+            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                    NonEmptyErrorStream.class.getSimpleName(),"run");
+            Process p = pb.start();
+            OutputAnalyzer output = new OutputAnalyzer(p);
+            p.waitFor(20, TimeUnit.SECONDS);
+            p.destroy();
+            output.shouldHaveExitValue(0);
+            output.stdoutShouldBeEmpty();
+            output.stderrShouldBeEmpty();
+            return;
+        }
+        Frame frame = new Frame();
+        frame.setSize(400, 300);
+        frame.setLocationRelativeTo(null);
+        frame.setVisible(true);
+
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+        robot.waitForIdle();
+        frame.toFront();
+
+        Rectangle rect = frame.getBounds();
+        int x = (int) rect.getCenterX();
+        int y = (int) rect.getCenterY();
+
+        for (int i = 0; i < 20; i++) {
+            robot.getPixelColor(x, y);
+            robot.createScreenCapture(rect);
+        }
+        for (int i = 0; i < 20; i++) {
+            robot.mouseMove(x + 50, y + 50);
+            robot.mouseMove(x - 50, y - 50);
+        }
+        for (int i = 0; i < 20; i++) {
+            robot.keyPress(KeyEvent.VK_ESCAPE);
+            robot.keyRelease(KeyEvent.VK_ESCAPE);
+        }
+        for (int i = 0; i < 20; i++) {
+            robot.mousePress(InputEvent.BUTTON1_MASK);
+            robot.mouseRelease(InputEvent.BUTTON1_MASK);
+        }
+        robot.waitForIdle();
+        frame.dispose();
+    }
+}
diff --git a/test/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java b/test/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java
--- a/test/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java
+++ b/test/java/awt/Window/FullWindowContentTest/FullWindowContentTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -31,7 +31,7 @@
  * @author Alan Snyder
  * @run main FullWindowContentTest
  * @requires (os.family == "mac")
-*/
+ */
 
 import java.awt.AWTException;
 import java.awt.Color;
@@ -120,7 +120,7 @@
     private void checkTranslucent() {
         Color c = getTestPixel();
         int delta = c.getRed() - c.getBlue();
-        if (delta < 50 || delta > 150) {
+        if (delta < 40 || delta > 150) {
             throw new RuntimeException("Test failed: did not find translucent title bar color");
         }
         checkContent();
@@ -129,7 +129,7 @@
     private void checkNormal() {
         Color c = getTestPixel();
         int delta = c.getRed() - c.getBlue();
-        if (delta < -50 || delta > 50) {
+        if (delta < -40 || delta > 40) {
             throw new RuntimeException("Test failed: did not find normal title bar color");
         }
         checkContent();
@@ -202,7 +202,6 @@
         try {
             runSwing(() -> theTest = new FullWindowContentTest());
             theTest.performTest();
-            ;
         } finally {
             if (theTest != null) {
                 runSwing(() -> theTest.dispose());
diff --git a/test/java/awt/font/Rotate/A.ttf b/test/java/awt/font/Rotate/A.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..f80f5c3d569c810493a9fbaf7141a63831733764
GIT binary patch
literal 2348
zc$}S9&2JM|5TEyU_wD*4{-_;0Kmtpg#A$)}D~S^bjUnKeD#0csknquDlNdWv92>_8
ziP{5IDWWY^L6uMsy;ME5MJ))44+&LiB~(@FrM>jRfn)yw+5;lE^LCds2vAjK{dRsc
zJ3Ak{v-1oD0Gtp80ant7L(%lNV_yR(Dr%2p`UZvvzWe<i%1bDBP8GBg{7o+bu)8SV
zpIWS_H%D%t01#GCu0K`E72c2ilt%d~%HG`U@~Iv3U*-Ws7XVG=rwdD$TZ1J4`E$H}
zA)nQze{nsyjQ+22|9MnMr^z=c|A}%_zED}RoCoyJDk#^@7N<1CXK{`4cm-{#1PkOi
zfW?loI;Rz~WPbi*#E&uF_od=|rFs>1qWwkGwUx@*(mml<2j+Jl<#z6qw7^r^2@NJ9
z;DT`zQ*gkdi3Lc(iit(ExoBbul4P5S8Mw%@iDh*4ArMn)&^;Ue6*y{QidIDv3(y2#
zm{>%cb0(G`Kok=*P{?T$8~z0#qQ%VLz()QCHu5*Hk-veB{0(g6Z(t*T1MB|#vvb+9
zR>@AQlgnzdI9Dm=%33L(EvxNq5$K03%;7471{LJfpu!|9<2i|C&7rOcIsIx0^17Xh
z555f|BXgCR%4~KTMs%wgT(kWCp=@qpRx8603OQInr3U4f84qex<zgW_J)=FBnYwn*
zAbOa>z(pwN3C^JWpXnk0AF;YZkw~b!`;|j=K?r#S&)v}dvSJ}YVEf{J^_tMUKcMC7
z0{Mx3JFtP`=wLf+1Sg3RI94_ee7`JVk!8jR_6qsrHmQEFKfiD7cSE2_*mgq_@qC?9
z)La)uJY&D~qWw)l#U7C1NJ1rwlCV%&6bLX$5U3=IATyCrBJfU5E{5WD(AyL0ajo(n
z3H7Y@@CA`DIgr1Djj0^SYu6G(qh0R!9Z;$(U1Kr#R(EsE9q1)zp8Wjik)S?)&`ZC<
zi1>}rG*;9P8JK`uiD9B?iAflL`{aq^$HtBx85ur2bZ8*CFH9#;hpJK3p(-;F^#K!h
zHwp*e5W19<uzM4Ab%@(DDbb>AmTH>BU0$(n7pVc_GBfTCt-A2g(_JN@)ez@g*Y-TY
z3v_0AF3{GOr}6TdS)ei4($O9dFc~37oqivOtk&y`MdO_v?SV!aFV=dw<d4b@qT6-G
ze4fq3@ALa&ov~=JGuRUJ)q3TiKj@FkaT!?<S)8WDj#_KIFd0s!`d;sFx;LmIVXpeE
z-r2ECwmZ^pqelm~P+1_#iFmN%O6CV2Wp?HfWQB?)(dKG$?>N_L+u#vfwgg)3I^S4p
zSC2J>$9KKCE!eQBkrJOA_0*}Kojdbhb8C;yI=I&%Ns+$x*35bO<i}XP(QP5*w?q9W
zJyG>g_6mAvTIbQ6dG9{EXo@fLkoOoi&qHI;lh8m0^;xJ>^&RlSi-_s7lj?J_*_@aL
zT{S0SJ)c~<%;1u)>06t>Pl>GEMPC?Yz2*8CuTCOPSP}PFUV*4rpu*m26=fCn=$yx5
zzz_?%H7DFNL9s{@NRlL28Rtx}$!Nx8(Qfh@MFv?`M2Ep8r$qq;?{Zl=w@PlS1uPaT
zd(FnVjd^TVuv%@*Yv<f9*Vfp;W~-5XCigq+V7EJzIw$8&eb*tEFe6Iu(vL8sPYq7)
zL6itaaclI<lN#L9Hv|b@DSpqO&#8Z(sm{-G_K<hL1PCf!cslr0ld4GZYW2y;!Qr8B
zc-=d}^;XUk7<cykg+cj$1-S9Y!PI(A(>TF+Ms#h@#TeBtz1sjBH2qv(FkQoNKpS;X
P+<_BdMKlVx@EZ9Cw6$!%

diff --git a/test/java/awt/font/Rotate/RotatedItalicsTest.java b/test/java/awt/font/Rotate/RotatedItalicsTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/font/Rotate/RotatedItalicsTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019 JetBrains s.r.o.
+ * 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 8210058
+ * @summary Algorithmic Italic font leans opposite angle in Printing
+ */
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+
+public class RotatedItalicsTest {
+    public static void main(String[] args) throws Exception {
+        File fontFile = new File(System.getProperty("test.src", "."), "A.ttf");
+        Font baseFont = Font.createFont(Font.TRUETYPE_FONT, fontFile);
+        Font font = baseFont.deriveFont(Font.ITALIC, 120);
+
+        BufferedImage image = new BufferedImage(100, 100,
+                                                BufferedImage.TYPE_INT_RGB);
+
+        Graphics2D g = image.createGraphics();
+        g.rotate(Math.PI / 2);
+        g.setFont(font);
+        g.drawString("A", 10, -10);
+        g.dispose();
+
+        if (image.getRGB(50, 76) != Color.white.getRGB()) {
+            throw new RuntimeException("Wrong glyph rendering");
+        }
+    }
+}
diff --git a/test/java/awt/image/RescaleOp/ImageRescaleOpTest.java b/test/java/awt/image/RescaleOp/ImageRescaleOpTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/image/RescaleOp/ImageRescaleOpTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8177393
+ * @summary Verify RescaleOp applied to BufferedImages.
+ * @run main ImageRescaleOpTest
+ */
+
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import static java.awt.image.BufferedImage.*;
+import java.awt.image.RescaleOp;
+import java.awt.Color;
+import java.io.File;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+public class ImageRescaleOpTest {
+
+    int w = 10, h = 10;
+    float scaleFactor = 0.5f;
+    float offset = 0.0f;
+    static boolean saveImage = false;
+
+    public static void main(String[] args) throws Exception {
+        saveImage = args.length > 0;
+        ImageRescaleOpTest test = new ImageRescaleOpTest();
+        test.startTest();
+    }
+
+    String getFileName(int s, int d) {
+        return textFor(s)+"_to_"+textFor(d)+".png";
+    }
+
+    String getMsgText(int s, int d) {
+        return textFor(s)+"->"+textFor(d)+": ";
+    }
+
+    String textFor(int t) {
+       switch (t) {
+           case TYPE_INT_ARGB        : return "ARGB";
+           case TYPE_INT_RGB         : return "RGB";
+           case TYPE_4BYTE_ABGR      : return "4BYTEABGR";
+           case TYPE_3BYTE_BGR       : return "3BYTEBGR";
+           case TYPE_USHORT_555_RGB  : return "USHORT_555_RGB";
+           case TYPE_USHORT_565_RGB  : return "USHORT_565_RGB";
+           case TYPE_USHORT_GRAY     : return "USHORT_GRAY";
+           default                   : return "OTHER";
+       }
+    }
+
+    private void startTest() throws Exception {
+
+        int expect = 0xff7f7f7f;
+        runTest(TYPE_INT_RGB, TYPE_INT_RGB, expect);
+        runTest(TYPE_INT_ARGB, TYPE_INT_ARGB, expect);
+        runTest(TYPE_INT_ARGB, TYPE_INT_RGB, expect);
+        runTest(TYPE_INT_RGB, TYPE_INT_ARGB, expect);
+
+        runTest(TYPE_3BYTE_BGR, TYPE_3BYTE_BGR, expect);
+        runTest(TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, expect);
+        runTest(TYPE_4BYTE_ABGR, TYPE_3BYTE_BGR, expect);
+        runTest(TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR, expect);
+
+        /* Slightly different values here due to limited precision */
+        runTest(TYPE_USHORT_555_RGB, TYPE_USHORT_555_RGB, 0xff7b7b7b);
+        runTest(TYPE_USHORT_565_RGB, TYPE_USHORT_565_RGB, 0xff7b7d7b);
+
+        /* 565->555 and 555->565 results are wrong as the slow code
+         * path used is not accounting for the difference in the range.
+         */
+        //runTest(TYPE_USHORT_555_RGB, TYPE_USHORT_565_RGB, expect);
+        //runTest(TYPE_USHORT_565_RGB, TYPE_USHORT_555_RGB, expect);
+
+        runTest(TYPE_USHORT_GRAY, TYPE_USHORT_GRAY, 0xffbcbcbc);
+
+    }
+
+   private void check(BufferedImage bi, int expect, String msg) {
+        int argb = bi.getRGB(w-1, h-1);
+        System.out.println(msg + Integer.toHexString(argb));
+        if (argb != expect) {
+            throw new RuntimeException(msg +
+                   " expected " + Integer.toHexString(expect) +
+                   " but got " + Integer.toHexString(argb));
+        }
+    }
+
+    private void runTest(int sType, int dType, int expect) {
+
+        BufferedImage src  = new BufferedImage(w, h, sType);
+        BufferedImage dst  = new BufferedImage(w, h, dType);
+        String msg = getMsgText(sType, dType);
+
+        Graphics2D g2d = src.createGraphics();
+        g2d.setColor(Color.WHITE);
+        g2d.fillRect(0, 0, w, h);
+        RescaleOp res = new RescaleOp(scaleFactor, offset, null);
+        res.filter(src, dst);
+        if (saveImage) {
+            try {
+               String fname = getFileName(sType, dType);
+               ImageIO.write(dst, "png", new File(fname));
+            } catch (IOException e) {
+            }
+        }
+        check(dst, expect, msg);
+   }
+}
diff --git a/test/java/awt/image/RescaleOp/RescaleAlphaTest.java b/test/java/awt/image/RescaleOp/RescaleAlphaTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/image/RescaleOp/RescaleAlphaTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+/**
+ * @test
+ * @bug 8080287
+ * @run RescaleAlphaTest
+ * @summary RescaleOp with scaleFactor/alpha should copy alpha to destination
+ * channel
+ */
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.RescaleOp;
+import java.awt.Color;
+import java.awt.Frame;
+import java.io.IOException;
+
+public class RescaleAlphaTest {
+
+    BufferedImage bimg = null, bimg1;
+    int w = 10, h = 10;
+    float scaleFactor = 0.5f;
+    float offset = 0.0f;
+
+    public static void main(String[] args) throws Exception {
+        RescaleAlphaTest test = new RescaleAlphaTest();
+        test.startTest();
+    }
+
+    private void startTest() throws Exception {
+
+        // Test with source image with alpha channel
+
+        bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g2d = bimg.createGraphics();
+        g2d.setColor(Color.GREEN);
+        g2d.fillRect(0, 0, w, h);
+
+        RescaleOp res = new RescaleOp(scaleFactor, offset, null);
+        bimg1 = res.filter(bimg, null);
+
+        // check if destination image has alpha channel copied from src
+        checkForAlpha(bimg1);
+
+        // Test with source image without alpha channel
+        bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+        g2d = bimg.createGraphics();
+        g2d.setColor(Color.GREEN);
+        g2d.fillRect(0, 0, w, h);
+
+
+        res = new RescaleOp(scaleFactor, offset, null);
+
+        // Create destination image with alpha channel
+        bimg1 = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+        bimg1 = res.filter(bimg, bimg1);
+
+        // check if filtered destination image has alpha channel
+        checkForAlpha(bimg1);
+
+    }
+
+    private void checkForAlpha(BufferedImage bi) throws IOException {
+        int argb = bi.getRGB(w/2, h/2);
+        if ((argb >>> 24) != 255) {
+            throw new
+            RuntimeException("Wrong alpha in destination image.RescaleOp with alpha failed.");
+        }
+    }
+}
diff --git a/test/java/awt/print/PrinterJob/ExceptionFromPrintableIsIgnoredTest.java b/test/java/awt/print/PrinterJob/ExceptionFromPrintableIsIgnoredTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/print/PrinterJob/ExceptionFromPrintableIsIgnoredTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * 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 8262731
+   @key headful printer
+   @summary Verify that "PrinterJob.print" throws the expected exception,
+            if "Printable.print" throws an exception.
+   @run main ExceptionFromPrintableIsIgnoredTest MAIN PE
+   @run main ExceptionFromPrintableIsIgnoredTest MAIN RE
+   @run main ExceptionFromPrintableIsIgnoredTest EDT PE
+   @run main ExceptionFromPrintableIsIgnoredTest EDT RE
+ */
+
+import java.awt.Graphics;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import java.lang.reflect.InvocationTargetException;
+import javax.swing.SwingUtilities;
+
+public class ExceptionFromPrintableIsIgnoredTest {
+    private enum TestThreadType {MAIN, EDT}
+    private enum TestExceptionType {PE, RE}
+
+    private volatile Throwable printError;
+
+    public static void main(String[] args) {
+        if (args.length < 2) {
+            throw new RuntimeException("Two arguments are expected:"
+                    + " test thread type and test exception type.");
+        }
+
+        new ExceptionFromPrintableIsIgnoredTest(
+            TestThreadType.valueOf(args[0]),
+            TestExceptionType.valueOf(args[1]));
+    }
+
+    public ExceptionFromPrintableIsIgnoredTest(
+            final TestThreadType threadType,
+            final TestExceptionType exceptionType) {
+        System.out.println(String.format(
+                "Test started. threadType='%s', exceptionType='%s'",
+                threadType, exceptionType));
+
+        String osName = System.getProperty("os.name");
+        boolean isOSX = osName.toLowerCase().startsWith("mac");
+        if ((exceptionType == TestExceptionType.RE) && !isOSX) {
+            System.out.println(
+                "Currently this test scenario can be verified only on macOS.");
+            return;
+        }
+
+        printError = null;
+
+        if (threadType == TestThreadType.MAIN) {
+            runTest(exceptionType);
+        } else if (threadType == TestThreadType.EDT) {
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                    @Override
+                    public void run() {
+                        runTest(exceptionType);
+                    }
+                });
+            } catch (InterruptedException | InvocationTargetException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        if (printError == null) {
+            throw new RuntimeException("No exception was thrown.");
+        } else if (!(printError instanceof PrinterException)) {
+            throw new RuntimeException("Unexpected exception was thrown.");
+        }
+        System.out.println("Test passed.");
+    }
+
+    private void runTest(final TestExceptionType exceptionType) {
+        PrinterJob job = PrinterJob.getPrinterJob();
+        if (job.getPrintService() == null) {
+            System.out.println("No printers are available.");
+            return;
+        }
+
+        job.setPrintable(new Printable() {
+            @Override
+            public int print(Graphics graphics, PageFormat pageFormat,
+                    int pageIndex) throws PrinterException {
+                if (pageIndex > 1) {
+                    return NO_SUCH_PAGE;
+                }
+                if (exceptionType == TestExceptionType.PE) {
+                    throw new PrinterException(
+                        "Exception from 'Printable.print'.");
+                } else if (exceptionType == TestExceptionType.RE) {
+                    throw new RuntimeException(
+                        "Exception from 'Printable.print'.");
+                }
+                return PAGE_EXISTS;
+            }
+        });
+
+        try {
+            job.print();
+        } catch (Throwable t) {
+            printError = t;
+
+            System.out.println("'PrinterJob.print' threw the exception:");
+            t.printStackTrace(System.out);
+        }
+    }
+}
diff --git a/test/java/awt/print/PrinterJob/PageDialogMarginTest.java b/test/java/awt/print/PrinterJob/PageDialogMarginTest.java
new file mode 100644
--- /dev/null
+++ b/test/java/awt/print/PrinterJob/PageDialogMarginTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
+ * 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      6801613
+ * @summary  Verifies if cross-platform pageDialog and printDialog top margin
+ *           entry is working
+ * @run      main/manual PageDialogMarginTest
+ */
+
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+import java.util.Locale;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.standard.MediaPrintableArea;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+public class PageDialogMarginTest {
+
+    public static void main(String[] args) throws Exception {
+        Locale.setDefault(Locale.US);
+        String[] instructions
+                = {
+                    "Page Dialog will be shown.",
+                    "Change top(in) margin value from 1.0 to 2.0",
+                    "Then select OK."
+                };
+        SwingUtilities.invokeAndWait(() -> JOptionPane.showMessageDialog(null,
+                instructions, "Instructions",
+                JOptionPane.INFORMATION_MESSAGE));
+        PrinterJob pj = PrinterJob.getPrinterJob();
+
+        HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+        PageFormat pf = pj.pageDialog(aset);
+        double left = pf.getImageableX();
+        double top = pf.getImageableY();
+
+        System.out.println("pageDialog - left/top from pageFormat: " + left / 72
+                                   + " " + top / 72);
+        System.out.println("pageDialog - left/top from attribute set: "
+                                   + getPrintableXFromASet(aset) + " "
+                                   + getPrintableYFromASet(aset));
+        if (top / 72 != 2.0f || getPrintableYFromASet(aset) != 2.0f) {
+            throw new RuntimeException("Top margin value not updated");
+        }
+    }
+
+    static double getPrintableXFromASet(PrintRequestAttributeSet aset) {
+        try {
+            return ((MediaPrintableArea) aset.get(
+                    MediaPrintableArea.class)).getX(MediaPrintableArea.INCH);
+        } catch (Exception e) {
+            return -1.0;
+        }
+    }
+
+    static double getPrintableYFromASet(PrintRequestAttributeSet aset) {
+        try {
+            return ((MediaPrintableArea) aset.get(
+                    MediaPrintableArea.class)).getY(MediaPrintableArea.INCH);
+        } catch (Exception e) {
+            return -1.0;
+        }
+    }
+
+}
diff --git a/test/java/net/HttpURLConnection/HttpURLConWithProxy.java b/test/java/net/HttpURLConnection/HttpURLConWithProxy.java
--- a/test/java/net/HttpURLConnection/HttpURLConWithProxy.java
+++ b/test/java/net/HttpURLConnection/HttpURLConWithProxy.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
  /*
  * @test
- * @bug 8161016
+ * @bug 8161016 8183369
  * @summary When proxy is set HttpURLConnection should not use DIRECT connection.
  * @run main/othervm HttpURLConWithProxy
  */
@@ -35,9 +35,13 @@
 import java.net.SocketAddress;
 import java.net.URI;
 import java.net.URL;
-import java.net.URLConnection;
+import java.net.HttpURLConnection;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.LogRecord;
 
 public class HttpURLConWithProxy {
 
@@ -47,36 +51,56 @@
 
         System.setProperty("http.proxyHost", "1.1.1.1");
         System.setProperty("http.proxyPort", "1111");
+        String HTTPLOG = "";
+        Logger.getLogger(HTTPLOG).setLevel(Level.ALL);
+        Handler h = new ProxyHandler();
+        h.setLevel(Level.ALL);
+        Logger.getLogger(HTTPLOG).addHandler(h);
 
         ServerSocket ss;
         URL url;
-        URLConnection con;
+        HttpURLConnection con;
 
         // Test1: using Proxy set by System Property:
         try {
             ss = new ServerSocket(0);
             url = new URL("http://localhost:" + ss.getLocalPort());
-            con = url.openConnection();
+            con = (HttpURLConnection) url.openConnection();
             con.setConnectTimeout(10 * 1000);
             con.connect();
-            throw new RuntimeException("Shouldn't use DIRECT connection "
-                    + "when proxy is invalid/down");
+            if(con.usingProxy()){
+                System.out.println("Test1 Passed with: Connection succeeded with proxy");
+            } else {
+                throw new RuntimeException("Shouldn't use DIRECT connection "
+                        + "when proxy is invalid/down");
+            }
         } catch (IOException ie) {
+            if(!ProxyHandler.proxyRetried) {
+                throw new RuntimeException("Connection not retried with proxy");
+            }
             System.out.println("Test1 Passed with: " + ie.getMessage());
         }
 
         // Test2: using custom ProxySelector implementation
+        ProxyHandler.proxyRetried = false;
         MyProxySelector myProxySel = new MyProxySelector();
         ProxySelector.setDefault(myProxySel);
         try {
             ss = new ServerSocket(0);
             url = new URL("http://localhost:" + ss.getLocalPort());
-            con = url.openConnection();
+            con = (HttpURLConnection) url.openConnection();
             con.setConnectTimeout(10 * 1000);
             con.connect();
-            throw new RuntimeException("Shouldn't use DIRECT connection "
-                    + "when proxy is invalid/down");
+            if(con.usingProxy()){
+                System.out.println("Test2 Passed with: Connection succeeded with proxy");
+            } else {
+                throw new RuntimeException("Shouldn't use DIRECT connection "
+                        + "when proxy is invalid/down");
+            }
         } catch (IOException ie) {
+            if(!ProxyHandler.proxyRetried) {
+                throw new RuntimeException("Connection not retried with proxy");
+            }
             System.out.println("Test2 Passed with: " + ie.getMessage());
         }
     }
@@ -104,3 +128,22 @@
         // System.out.println("MyProxySelector.connectFailed(): "+sa);
     }
 }
+
+class ProxyHandler extends Handler {
+    public static boolean proxyRetried = false;
+
+    @Override
+    public void publish(LogRecord record) {
+        if (record.getMessage().contains("Retrying with proxy")) {
+            proxyRetried = true;
+        }
+    }
+
+    @Override
+    public void flush() {
+    }
+
+    @Override
+    public void close() throws SecurityException {
+    }
+}
diff --git a/test/java/net/Inet6Address/B6206527.java b/test/java/net/Inet6Address/B6206527.java
--- a/test/java/net/Inet6Address/B6206527.java
+++ b/test/java/net/Inet6Address/B6206527.java
@@ -25,10 +25,14 @@
  * @test 1.1 05/01/05
  * @bug 6206527
  * @summary "cannot assign address" when binding ServerSocket on Suse 9
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main B6206527
  */
 
 import java.net.*;
 import java.util.*;
+import jdk.testlibrary.NetworkConfiguration;
 
 public class B6206527 {
 
@@ -53,21 +57,12 @@
         ss.bind(new InetSocketAddress(addr, 0));
     }
 
-    public static Inet6Address getLocalAddr () throws Exception {
-        Enumeration e = NetworkInterface.getNetworkInterfaces();
-        while (e.hasMoreElements()) {
-            NetworkInterface ifc = (NetworkInterface) e.nextElement();
-            Enumeration addrs = ifc.getInetAddresses();
-            while (addrs.hasMoreElements()) {
-                InetAddress a = (InetAddress)addrs.nextElement();
-                if (a instanceof Inet6Address) {
-                    Inet6Address ia6 = (Inet6Address) a;
-                    if (ia6.isLinkLocalAddress()) {
-                        return ia6;
-                    }
-                }
-            }
-        }
-        return null;
+    public static Inet6Address getLocalAddr() throws Exception {
+        Optional<Inet6Address> oaddr = NetworkConfiguration.probe()
+                .ip6Addresses()
+                .filter(a -> a.isLinkLocalAddress())
+                .findFirst();
+
+        return oaddr.orElseGet(() -> null);
     }
 }
diff --git a/test/java/net/Inet6Address/B6558853.java b/test/java/net/Inet6Address/B6558853.java
--- a/test/java/net/Inet6Address/B6558853.java
+++ b/test/java/net/Inet6Address/B6558853.java
@@ -21,43 +21,42 @@
  * questions.
  */
 
-/**
+/*
  * @test
  * @bug 6558853
  * @summary  getHostAddress() on connections using IPv6 link-local addrs should have zone id
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main B6558853
  */
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.*;
-import java.util.Enumeration;
+import java.util.Optional;
+import jdk.testlibrary.NetworkConfiguration;
 
 public class B6558853 implements Runnable {
     private InetAddress addr = null;
     private int port = 0;
 
     public static void main(String[] args) throws Exception {
-        ServerSocket ss = new ServerSocket(0);
-        int port = ss.getLocalPort();
-        Enumeration<NetworkInterface> l = NetworkInterface.getNetworkInterfaces();
-        InetAddress dest = null;
-        while (l.hasMoreElements() && dest == null) {
-            NetworkInterface nif = l.nextElement();
-            if (!nif.isUp())
-                continue;
+        Optional<Inet6Address> oaddr = NetworkConfiguration.probe()
+                .ip6Addresses()
+                .filter(a -> a.isLinkLocalAddress())
+                .findFirst();
 
-            for (InterfaceAddress a : nif.getInterfaceAddresses()) {
-                if (a.getAddress() instanceof Inet6Address) {
-                    Inet6Address a6 = (Inet6Address) a.getAddress();
-                    if (a6.isLinkLocalAddress()) {
-                        dest = a6;
-                    }
-                    break;
-                }
-            }
+        if (!oaddr.isPresent()) {
+            System.out.println("No suitable interface found. Exiting.");
+            return;
         }
+
+        Inet6Address dest = oaddr.get();
         System.out.println("Using " + dest);
-        if (dest != null) {
+
+        try (ServerSocket ss = new ServerSocket(0)) {
+            int port = ss.getLocalPort();
             B6558853 test = new B6558853(dest, port);
             Thread thread = new Thread(test);
             thread.start();
diff --git a/test/java/net/InetAddress/CheckJNI.java b/test/java/net/InetAddress/CheckJNI.java
--- a/test/java/net/InetAddress/CheckJNI.java
+++ b/test/java/net/InetAddress/CheckJNI.java
@@ -24,11 +24,15 @@
 /* @test
    @bug 4889870 4890033
    @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
+   @library /lib/testlibrary
+   @build jdk.testlibrary.NetworkConfiguration
    @run main/othervm -Xcheck:jni CheckJNI
 */
 
 import java.net.*;
 import java.util.*;
+import java.util.stream.Collectors;
+import jdk.testlibrary.NetworkConfiguration;
 
 public class CheckJNI {
     static Socket s;
@@ -49,32 +53,23 @@
         dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
         testDatagrams (dg1, dg2);
 
-        /* Use NetworkInterface to find link local IPv6 addrs to test */
-
-        Enumeration ifs = NetworkInterface.getNetworkInterfaces();
-        server = new ServerSocket (0);
+        /* Find link local IPv6 addrs to test */
+        List<Inet6Address> addrs = NetworkConfiguration.probe()
+                .ip6Addresses()
+                .filter(Inet6Address::isLinkLocalAddress)
+                .collect(Collectors.toList());
 
-        while (ifs.hasMoreElements()) {
-            NetworkInterface nif = (NetworkInterface)ifs.nextElement();
-            if (!nif.isUp())
-                continue;
-            Enumeration addrs = nif.getInetAddresses();
-            while (addrs.hasMoreElements()) {
-                InetAddress addr = (InetAddress) addrs.nextElement();
-                if (addr instanceof Inet6Address) {
-                    Inet6Address ia6 = (Inet6Address) addr;
-                    if (ia6.isLinkLocalAddress()) {
-                        System.out.println ("Testing IPv6 Socket");
-                        s = new Socket (ia6, server.getLocalPort());
-                        s.close();
+        server = new ServerSocket(0);
+        for (Inet6Address ia6 : addrs) {
+            System.out.println("Address:" + ia6);
+            System.out.println("Testing IPv6 Socket");
+            s = new Socket(ia6, server.getLocalPort());
+            s.close();
 
-                        System.out.println ("Testing IPv6 DatagramSocket");
-                        dg1 = new DatagramSocket (0, ia6);
-                        dg2 = new DatagramSocket (0, ia6);
-                        testDatagrams (dg1, dg2);
-                    }
-                }
-            }
+            System.out.println("Testing IPv6 DatagramSocket");
+            dg1 = new DatagramSocket(0, ia6);
+            dg2 = new DatagramSocket(0, ia6);
+            testDatagrams(dg1, dg2);
         }
         server.close();
         System.out.println ("OK");
diff --git a/test/java/net/MulticastSocket/B6427403.java b/test/java/net/MulticastSocket/B6427403.java
--- a/test/java/net/MulticastSocket/B6427403.java
+++ b/test/java/net/MulticastSocket/B6427403.java
@@ -23,15 +23,12 @@
 
 /*
  * @test
- *
  * @bug 6427403
- *
  * @summary java.net.MulticastSocket.joinGroup() reports 'socket closed'
- *
  */
 import java.net.*;
 import java.io.*;
-import java.util.*;
+
 public class B6427403 {
     public static void main( String[] args ) throws IOException {
         InetAddress lh = InetAddress.getLocalHost();
@@ -39,4 +36,4 @@
         ms.joinGroup( InetAddress.getByName("224.80.80.80") );
         ms.close();
     }
-}
+}
\ No newline at end of file
diff --git a/test/java/net/MulticastSocket/JoinGroup.java b/test/java/net/MulticastSocket/JoinGroup.java
deleted file mode 100644
--- a/test/java/net/MulticastSocket/JoinGroup.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
- * 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 4091811 4148753
- * @summary Test java.net.MulticastSocket joinGroup and leaveGroup
- *
- */
-
-import java.io.*;
-import java.net.*;
-
-
-public class JoinGroup {
-
-    public static void main(String args[]) throws Exception  {
-        MulticastSocket soc = null;
-        InetAddress sin = null;
-
-        soc = new MulticastSocket();
-        sin = InetAddress.getByName("224.80.80.80");
-        soc.joinGroup(sin);
-        soc.leaveGroup(sin);
-    }
-}
diff --git a/test/java/net/MulticastSocket/JoinLeave.java b/test/java/net/MulticastSocket/JoinLeave.java
new file mode 100644
--- /dev/null
+++ b/test/java/net/MulticastSocket/JoinLeave.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
+ * 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 4091811 4148753 4102731
+ * @summary Test java.net.MulticastSocket joinGroup and leaveGroup
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main JoinLeave
+ */
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.NetworkInterface;
+import jdk.testlibrary.NetworkConfiguration;
+
+public class JoinLeave {
+
+    public static void main(String args[]) throws IOException  {
+        InetAddress ip4Group = InetAddress.getByName("224.80.80.80");
+        InetAddress ip6Group = InetAddress.getByName("ff02::a");
+
+        NetworkConfiguration nc = NetworkConfiguration.probe();
+        nc.ip4MulticastInterfaces().forEach(nic -> joinLeave(ip4Group, nic));
+        nc.ip6MulticastInterfaces().forEach(nic -> joinLeave(ip6Group, nic));
+    }
+
+    static void joinLeave(InetAddress group, NetworkInterface nif)
+    {
+        System.out.println("Joining:" + group + " on " + nif);
+        try (MulticastSocket soc = new MulticastSocket()) {
+            soc.setNetworkInterface(nif);
+            soc.joinGroup(group);
+            soc.leaveGroup(group);
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/Leave.java b/test/java/net/MulticastSocket/Leave.java
deleted file mode 100644
--- a/test/java/net/MulticastSocket/Leave.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
- * 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 4102731
- * @summary Test the java.net.multicastsocket.leave method
- *
- */
-
-import java.net.*;
-import java.io.*;
-
-public class Leave {
-
-    public static void main(String args[]) throws Exception {
-        MulticastSocket socket = null;
-        InetAddress mca = null;
-
-        mca = InetAddress.getByName("224.80.80.80");
-        socket = new MulticastSocket();
-        socket.joinGroup(mca);
-        socket.leaveGroup(mca);
-        socket.close();
-    }
-}
diff --git a/test/java/net/NetworkConfigurationProbe.java b/test/java/net/NetworkConfigurationProbe.java
new file mode 100644
--- /dev/null
+++ b/test/java/net/NetworkConfigurationProbe.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary NOT A TEST. Captures the network interface configuration.
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main NetworkConfigurationProbe
+ */
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.NetworkInterface;
+import jdk.testlibrary.NetworkConfiguration;
+import static java.util.stream.Collectors.joining;
+import static java.lang.System.out;
+
+/**
+ * Not a test. Captures the network interface configuration.
+ */
+public class NetworkConfigurationProbe {
+
+    public static void main(String... args) throws Exception {
+        NetworkConfiguration.printSystemConfiguration(out);
+
+        NetworkConfiguration nc = NetworkConfiguration.probe();
+        String list;
+        list = nc.ip4MulticastInterfaces()
+                  .map(NetworkInterface::getName)
+                  .collect(joining(" "));
+        out.println("ip4MulticastInterfaces: " +  list);
+
+        list = nc.ip4Addresses()
+                  .map(Inet4Address::toString)
+                  .collect(joining(" "));
+        out.println("ip4Addresses: " +  list);
+
+        list = nc.ip6MulticastInterfaces()
+                  .map(NetworkInterface::getName)
+                  .collect(joining(" "));
+        out.println("ip6MulticastInterfaces: " +  list);
+
+        list = nc.ip6Addresses()
+                  .map(Inet6Address::toString)
+                  .collect(joining(" "));
+        out.println("ip6Addresses: " +  list);
+    }
+}
diff --git a/test/java/net/NetworkInterface/Test.java b/test/java/net/NetworkInterface/Test.java
--- a/test/java/net/NetworkInterface/Test.java
+++ b/test/java/net/NetworkInterface/Test.java
@@ -23,8 +23,8 @@
 
 /* @test
  * @bug 4405354 6594296 8058216
- * @run main Test
- * @run main/othervm -Djava.net.preferIPv4Stack=true Test
+ * @run main/othervm -Xcheck:jni Test
+ * @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true Test
  * @summary Basic tests for NetworkInterface
  */
 import java.net.NetworkInterface;
diff --git a/test/java/net/Socket/LinkLocal.java b/test/java/net/Socket/LinkLocal.java
--- a/test/java/net/Socket/LinkLocal.java
+++ b/test/java/net/Socket/LinkLocal.java
@@ -26,9 +26,15 @@
  * @bug 4469866
  * @summary Connecting to a link-local IPv6 address should not
  *          causes a SocketException to be thrown.
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main LinkLocal
  */
+import jdk.testlibrary.NetworkConfiguration;
+
 import java.net.*;
-import java.util.Enumeration;
+import java.util.List;
+import java.util.stream.Collectors;
 
 public class LinkLocal {
 
@@ -134,22 +140,13 @@
          * IPv6 address.
          */
         if (args.length == 0) {
-            Enumeration nifs = NetworkInterface.getNetworkInterfaces();
-            while (nifs.hasMoreElements()) {
-                NetworkInterface ni = (NetworkInterface)nifs.nextElement();
-                if (!ni.isUp())
-                    continue;
+            List<Inet6Address> addrs = NetworkConfiguration.probe()
+                    .ip6Addresses()
+                    .filter(Inet6Address::isLinkLocalAddress)
+                    .collect(Collectors.toList());
 
-                Enumeration addrs = ni.getInetAddresses();
-                while (addrs.hasMoreElements()) {
-                    InetAddress addr = (InetAddress)addrs.nextElement();
-
-                    if (addr instanceof Inet6Address &&
-                        addr.isLinkLocalAddress()) {
-
-                        TestAddress(addr);
-                    }
-                }
+            for (Inet6Address addr : addrs) {
+                TestAddress(addr);
             }
         }
 
diff --git a/test/java/net/SocketPermission/SocketPermissionTest.java b/test/java/net/SocketPermission/SocketPermissionTest.java
--- a/test/java/net/SocketPermission/SocketPermissionTest.java
+++ b/test/java/net/SocketPermission/SocketPermissionTest.java
@@ -25,13 +25,17 @@
  * @test
  * @bug 8047031
  * @summary SocketPermission tests for legacy socket types
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
  * @run testng/othervm SocketPermissionTest
  */
+
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
 import java.net.InetAddress;
 import java.net.MulticastSocket;
+import java.net.NetworkInterface;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketPermission;
@@ -44,11 +48,14 @@
 import java.security.Policy;
 import java.security.PrivilegedExceptionAction;
 import java.security.ProtectionDomain;
+import java.util.Optional;
 
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+
 import static org.testng.Assert.*;
 
+import static jdk.testlibrary.NetworkConfiguration.probe;
 import static java.nio.charset.StandardCharsets.UTF_8;
 
 public class SocketPermissionTest {
@@ -210,12 +217,17 @@
                     new SocketPermission(addr, "listen,resolve"),
                     new SocketPermission("229.227.226.221", "connect,accept"));
 
-            // Positive
-            AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
-                s.joinGroup(group);
-                s.leaveGroup(group);
-                return null;
-            }, acc);
+            // Positive ( requires a functional network interface )
+            Optional<NetworkInterface> onif = probe().ip4MulticastInterfaces().findFirst();
+            if (!onif.isPresent()) {
+                s.setNetworkInterface(onif.get());
+
+                AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
+                    s.joinGroup(group);
+                    s.leaveGroup(group);
+                    return null;
+                }, acc);
+            }
 
             // Negative
             try {
diff --git a/test/java/net/ipv6tests/B6521014.java b/test/java/net/ipv6tests/B6521014.java
--- a/test/java/net/ipv6tests/B6521014.java
+++ b/test/java/net/ipv6tests/B6521014.java
@@ -25,13 +25,15 @@
  * @test
  * @bug 6521014 6543428
  * @summary IOException thrown when Socket tries to bind to an local IPv6 address on SuSE Linux
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main B6521014
  */
 
-
 import java.net.*;
 import java.io.*;
 import java.util.*;
-
+import jdk.testlibrary.NetworkConfiguration;
 
 /*
  *
@@ -52,38 +54,26 @@
  */
 public class B6521014 {
 
-    static InetAddress sin;
-
-    static Inet6Address getLocalAddr () throws Exception {
-        Enumeration e = NetworkInterface.getNetworkInterfaces();
-        while (e.hasMoreElements()) {
-            NetworkInterface ifc = (NetworkInterface) e.nextElement();
-            if (!ifc.isUp())
-                continue;
-            Enumeration addrs = ifc.getInetAddresses();
-            while (addrs.hasMoreElements()) {
-                InetAddress a = (InetAddress)addrs.nextElement();
-                if (a instanceof Inet6Address) {
-                    Inet6Address ia6 = (Inet6Address) a;
-                    if (ia6.isLinkLocalAddress()) {
-                        // remove %scope suffix
-                        return (Inet6Address)InetAddress.getByAddress(ia6.getAddress());
-                    }
-                }
-            }
+    static Inet6Address removeScope(Inet6Address addr) {
+        try {
+            return (Inet6Address)InetAddress.getByAddress(addr.getAddress());
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
         }
-        return null;
     }
 
-    static void test1() throws Exception {
-        ServerSocket ssock;
-        Socket sock;
-        int port;
+    static Optional<Inet6Address> getLocalAddr() throws Exception {
+        return NetworkConfiguration.probe()
+                .ip6Addresses()
+                .filter(Inet6Address::isLinkLocalAddress)
+                .map(B6521014::removeScope)
+                .findFirst();
+    }
 
-        ssock = new ServerSocket(0);
-        port = ssock.getLocalPort();
-        sock = new Socket();
-        try {
+    static void test1(Inet6Address sin) throws Exception {
+        try (ServerSocket ssock = new ServerSocket(0);
+             Socket sock = new Socket()) {
+            int port = ssock.getLocalPort();
             sock.connect(new InetSocketAddress(sin, port), 100);
         } catch (SocketTimeoutException e) {
             // time out exception is okay
@@ -91,36 +81,29 @@
         }
     }
 
-    static void test2() throws Exception {
-        Socket sock;
-        ServerSocket ssock;
-        int port;
-
-        ssock = new ServerSocket(0);
-        ssock.setSoTimeout(100);
-        port = ssock.getLocalPort();
-        sock = new Socket();
-        sock.bind(new InetSocketAddress(sin, 0));
-        try {
+    static void test2(Inet6Address sin) throws Exception {
+        try (ServerSocket ssock = new ServerSocket(0);
+             Socket sock = new Socket()) {
+            int port = ssock.getLocalPort();
+            ssock.setSoTimeout(100);
+            sock.bind(new InetSocketAddress(sin, 0));
             sock.connect(new InetSocketAddress(sin, port), 100);
-        } catch (SocketTimeoutException e) {
+        } catch (SocketTimeoutException expected) {
             // time out exception is okay
             System.out.println("timed out when connecting.");
         }
     }
 
     public static void main(String[] args) throws Exception {
-        sin = getLocalAddr();
-        if (sin == null) {
+        Optional<Inet6Address> oaddr = getLocalAddr();
+        if (!oaddr.isPresent()) {
             System.out.println("Cannot find a link-local address.");
             return;
         }
 
-        try {
-            test1();
-            test2();
-        } catch (IOException e) {
-            throw new RuntimeException("Test failed: cannot create socket.", e);
-        }
+        Inet6Address addr = oaddr.get();
+        System.out.println("Using " + addr);
+        test1(addr);
+        test2(addr);
     }
 }
diff --git a/test/java/net/ipv6tests/TcpTest.java b/test/java/net/ipv6tests/TcpTest.java
--- a/test/java/net/ipv6tests/TcpTest.java
+++ b/test/java/net/ipv6tests/TcpTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, 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
@@ -60,8 +60,7 @@
         dprintln ("Local Addresses");
         dprintln (ia4addr.toString());
         dprintln (ia6addr.toString());
-        test1 (0);
-        test1 (5100);
+        test1();
         test2();
         test3();
         test4();
@@ -69,11 +68,9 @@
 
     /* basic TCP connectivity test using IPv6 only and IPv4/IPv6 together */
 
-    static void test1 (int port) throws Exception {
-        server = new ServerSocket (port);
-        if (port == 0) {
-            port = server.getLocalPort();
-        }
+    static void test1 () throws Exception {
+        server = new ServerSocket (0);
+        int port = server.getLocalPort();
         // try Ipv6 only
         c1 = new Socket ("::1", port);
         s1 = server.accept ();
@@ -107,9 +104,7 @@
     /** bind tests:
      *  1. bind to specific address IPv4 only (any port)
      *  2. bind to specific address IPv6 only (any port)
-     *  3. bind to specific address IPv4 only (specific port)
-     *  4. bind to specific address IPv4 only (specific port)
-     *  5. bind to any address IPv4 (test collision)
+     *  3. bind to any address IPv4 (test collision)
      */
 
     static void test2 () throws Exception {
@@ -147,39 +142,6 @@
         server.close ();
         c1.close ();
 
-        /* now try IPv6 specific port only */
-
-        server = new ServerSocket ();
-        sadr = new InetSocketAddress (ia6addr, 5200);
-        server.bind (sadr);
-        port = server.getLocalPort();
-        t_assert (port == 5200);
-
-        c1 = new Socket (ia6addr, port);
-        try {
-            c2 = new Socket (ia4addr, port);
-            throw new RuntimeException ("connect to IPv4 address should be refused");
-        } catch (IOException e) { }
-        server.close ();
-        c1.close ();
-
-        /* now try IPv4 specific port only */
-
-        server = new ServerSocket ();
-        sadr = new InetSocketAddress (ia4addr, 5200);
-        server.bind (sadr);
-        port = server.getLocalPort();
-        t_assert (port == 5200);
-
-        c1 = new Socket (ia4addr, port);
-
-        try {
-            c2 = new Socket (ia6addr, port);
-            throw new RuntimeException ("connect to IPv6 address should be refused");
-        } catch (IOException e) { }
-        server.accept().close();
-        c1.close ();
-        server.close();
         System.out.println ("Test2: OK");
     }
 
@@ -242,3 +204,4 @@
         System.out.println ("Test4: OK");
     }
 }
+
diff --git a/test/java/net/ipv6tests/Tests.java b/test/java/net/ipv6tests/Tests.java
--- a/test/java/net/ipv6tests/Tests.java
+++ b/test/java/net/ipv6tests/Tests.java
@@ -27,7 +27,10 @@
 
 public class Tests {
 
-    static boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+    static final boolean isWindows =
+            System.getProperty("os.name").startsWith("Windows");
+    static final boolean isMacOS =
+            System.getProperty("os.name").contains("OS X");
 
     /**
      * performs a simple exchange of data between the two sockets
@@ -278,6 +281,8 @@
                         String dName = nic.getDisplayName();
                         if (dName != null && dName.contains("Teredo"))
                             continue;
+                    } else if (isMacOS && nic.getName().contains("awdl")) {
+                        continue;
                     }
                     try {
                         if (nic.isUp() && !nic.isLoopback())
diff --git a/test/java/nio/channels/FileChannel/TempDirectBuffersReclamation.java b/test/java/nio/channels/FileChannel/TempDirectBuffersReclamation.java
new file mode 100644
--- /dev/null
+++ b/test/java/nio/channels/FileChannel/TempDirectBuffersReclamation.java
@@ -0,0 +1,91 @@
+/*
+ * 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.io.IOException;
+import java.io.UncheckedIOException;
+import java.lang.management.BufferPoolMXBean;
+import java.lang.management.ManagementFactory;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
+import static java.nio.file.StandardOpenOption.WRITE;
+
+/*
+ * @test
+ * @bug 8202788
+ * @summary Test reclamation of thread-local temporary direct byte buffers at thread exit
+ * @modules java.management
+ * @run main/othervm TempDirectBuffersReclamation
+ */
+public class TempDirectBuffersReclamation {
+
+    public static void main(String[] args) throws IOException {
+
+        BufferPoolMXBean dbPool = ManagementFactory
+            .getPlatformMXBeans(BufferPoolMXBean.class)
+            .stream()
+            .filter(bp -> bp.getName().equals("direct"))
+            .findFirst()
+            .orElseThrow(() -> new RuntimeException("Can't obtain direct BufferPoolMXBean"));
+
+        long count0 = dbPool.getCount();
+        long memoryUsed0 = dbPool.getMemoryUsed();
+
+        Thread thread = new Thread(TempDirectBuffersReclamation::doFileChannelWrite);
+        thread.start();
+        try {
+            thread.join();
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+
+        long count1 = dbPool.getCount();
+        long memoryUsed1 = dbPool.getMemoryUsed();
+
+        if (count0 != count1 || memoryUsed0 != memoryUsed1) {
+            throw new AssertionError(
+                "Direct BufferPool not same before thread activity and after thread exit.\n" +
+                "Before: # of buffers: " + count0 + ", memory used: " + memoryUsed0 + "\n" +
+                " After: # of buffers: " + count1 + ", memory used: " + memoryUsed1 + "\n"
+            );
+        }
+    }
+
+    static void doFileChannelWrite() {
+        try {
+            Path file = Files.createTempFile("test", ".tmp");
+            try (FileChannel fc = FileChannel.open(file, CREATE, WRITE, TRUNCATE_EXISTING)) {
+                fc.write(ByteBuffer.wrap("HELLO".getBytes(StandardCharsets.UTF_8)));
+            } finally {
+                Files.delete(file);
+            }
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+}
diff --git a/test/java/util/Calendar/CalendarTestScripts/JapaneseTests.java b/test/java/util/Calendar/CalendarTestScripts/JapaneseTests.java
--- a/test/java/util/Calendar/CalendarTestScripts/JapaneseTests.java
+++ b/test/java/util/Calendar/CalendarTestScripts/JapaneseTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,7 +24,7 @@
 /*
  * @test
  * @summary tests Japanese Calendar.
- * @bug 4609228
+ * @bug 4609228 8187649
  * @modules java.base/sun.util
  *          java.base/sun.util.calendar
  * @compile
diff --git a/test/java/util/Calendar/CalendarTestScripts/japanese/japanese_roll.cts b/test/java/util/Calendar/CalendarTestScripts/japanese/japanese_roll.cts
--- a/test/java/util/Calendar/CalendarTestScripts/japanese/japanese_roll.cts
+++ b/test/java/util/Calendar/CalendarTestScripts/japanese/japanese_roll.cts
@@ -435,12 +435,48 @@
 	check date BeforeMeiji $minyear Dec 25
 
 test WEEK_OF_MONTH
-	# Needs to wait for 6191841 fix. (WEEK_OF_MONTH needs to change
-	# ERA and YEAR in a transition month.)
+	use jcal
+	clear all
+
+	# Make sure this test does not throw AIOOBE
+	set date Heisei 1 Aug 1
+	roll week_of_month 1
+	check date Heisei 1 Aug 8
+
+	# Check transition dates
+	set date Showa 64 Jan 7
+	roll week_of_month 1
+	check date Showa 64 Jan 7
+	roll week_of_month -1
+	check date Showa 64 Jan 7
+
+	set date Heisei 1 Jan 31
+	roll week_of_month 1
+	check date Heisei 1 Jan 10
+	roll week_of_month -1
+	check date Heisei 1 Jan 31
 
 test DAY_OF_MONTH
-	# Needs to wait for 6191841 fix. (DAY_OF_MONTH needs to change
-	# ERA and YEAR in a transition month.)
+	use jcal
+	clear all
+
+	# Make sure this test does not throw AIOOBE
+	Set date Heisei 1 Aug 1
+	roll day_of_month 1
+	check date Heisei 1 Aug 2
+
+	# Check transition dates
+	set date Showa 64 Jan 7
+	roll day_of_month 1
+	check date Showa 64 Jan 1
+	roll day_of_month -1
+	check date Showa 64 Jan 7
+
+	set date Heisei 1 Jan 31
+	roll day_of_month 1
+	check date Heisei 1 Jan 8
+	roll day_of_month -1
+	check date Heisei 1 Jan 31
 
 test DAY_OF_YEAR
     use jcal
diff --git a/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java b/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java
--- a/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java
+++ b/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java
@@ -61,7 +61,7 @@
                     // ignore
                 }
             }
-            rmid.shutdown(rmidPort);
+            rmid.destroy();
         }
 
         if (failureCause != null) {
@@ -69,4 +69,4 @@
         }
 
     }
-}
\ No newline at end of file
+}
diff --git a/test/jdk/internal/misc/TerminatingThreadLocal/TestTerminatingThreadLocal.java b/test/jdk/internal/misc/TerminatingThreadLocal/TestTerminatingThreadLocal.java
new file mode 100644
--- /dev/null
+++ b/test/jdk/internal/misc/TerminatingThreadLocal/TestTerminatingThreadLocal.java
@@ -0,0 +1,90 @@
+/*
+ * 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 jdk.internal.misc.TerminatingThreadLocal;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.Consumer;
+
+/*
+ * @test
+ * @bug 8202788
+ * @summary TerminatingThreadLocal unit test
+ * @modules java.base/jdk.internal.misc
+ * @run main TestTerminatingThreadLocal
+ */
+public class TestTerminatingThreadLocal {
+
+    public static void main(String[] args) {
+        ttlTestSet(42,   112);
+        ttlTestSet(null, 112);
+        ttlTestSet(42,  null);
+    }
+
+    static <T> void ttlTestSet(T v0, T v1) {
+        ttlTest(v0, ttl -> {                                         }    );
+        ttlTest(v0, ttl -> { ttl.get();                              }, v0);
+        ttlTest(v0, ttl -> { ttl.get();   ttl.remove();              }    );
+        ttlTest(v0, ttl -> { ttl.get();   ttl.set(v1);               }, v1);
+        ttlTest(v0, ttl -> { ttl.set(v1);                            }, v1);
+        ttlTest(v0, ttl -> { ttl.set(v1); ttl.remove();              }    );
+        ttlTest(v0, ttl -> { ttl.set(v1); ttl.remove(); ttl.get();   }, v0);
+        ttlTest(v0, ttl -> { ttl.get();   ttl.remove(); ttl.set(v1); }, v1);
+    }
+
+    @SafeVarargs
+    static <T> void ttlTest(T initialValue,
+                            Consumer<? super TerminatingThreadLocal<T>> ttlOps,
+                            T... expectedTerminatedValues)
+    {
+        List<T> terminatedValues = new CopyOnWriteArrayList<>();
+
+        TerminatingThreadLocal<T> ttl = new TerminatingThreadLocal<T>() {
+            @Override
+            protected void threadTerminated(T value) {
+                terminatedValues.add(value);
+            }
+
+            @Override
+            protected T initialValue() {
+                return initialValue;
+            }
+        };
+
+        Thread thread = new Thread(() -> ttlOps.accept(ttl));
+        thread.start();
+        try {
+            thread.join();
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+
+        if (!terminatedValues.equals(Arrays.asList(expectedTerminatedValues))) {
+            throw new AssertionError("Expected terminated values: " +
+                                     Arrays.toString(expectedTerminatedValues) +
+                                     " but got: " + terminatedValues);
+        }
+    }
+}
diff --git a/test/jdk/java/awt/font/Rotate/RotatedItalicsTest.java b/test/jdk/java/awt/font/Rotate/RotatedItalicsTest.java
new file mode 100644
diff --git a/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java b/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java
--- a/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java
+++ b/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java
@@ -25,12 +25,17 @@
 
 package jdk.jfr.event.runtime;
 
+import static jdk.test.lib.Asserts.assertEQ;
+import static jdk.test.lib.Asserts.assertNotNull;
+
 import java.time.Duration;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import jdk.jfr.Recording;
 import jdk.jfr.consumer.RecordedEvent;
+import jdk.jfr.consumer.RecordedMethod;
+import jdk.jfr.consumer.RecordedStackTrace;
 import jdk.test.lib.jfr.EventNames;
 import jdk.test.lib.jfr.Events;
 
@@ -62,19 +67,27 @@
         recording.stop();
 
         int currThreadIndex = 0;
-        long currentThreadId = Thread.currentThread().getId();
         List<RecordedEvent> events = Events.fromRecording(recording);
+        events.sort((e1, e2) -> e1.getStartTime().compareTo(e2.getStartTime()));
         Events.hasEvents(events);
         for (RecordedEvent event : events) {
-            System.out.println("Event:" + event);
-            if (event.getThread().getJavaThreadId() != currentThreadId) {
+            if (!event.getThread().getJavaName().startsWith(THREAD_NAME_PREFIX)) {
                 continue;
             }
+            System.out.println("Event:" + event);
             // Threads should be started and stopped in the correct order.
             Events.assertEventThread(event, threads[currThreadIndex % threads.length]);
             String eventName = currThreadIndex < threads.length ? EVENT_NAME_THREAD_START : EVENT_NAME_THREAD_END;
             if (!eventName.equals(event.getEventType().getName())) {
-                throw new Exception("Expected event of tyoe " + eventName + " but got " + event.getEventType().getName());
+                throw new Exception("Expected event of type " + eventName + " but got " + event.getEventType().getName());
+            }
+
+            if (eventName == EVENT_NAME_THREAD_START) {
+                Events.assertEventThread(event, "parentThread", Thread.currentThread());
+                RecordedStackTrace stackTrace = event.getValue("stackTrace");
+                assertNotNull(stackTrace);
+                RecordedMethod topMethod = stackTrace.getFrames().get(0).getMethod();
+                assertEQ(topMethod.getName(), "startThread");
             }
             currThreadIndex++;
         }
diff --git a/test/lib/testlibrary/jdk/testlibrary/NetworkConfiguration.java b/test/lib/testlibrary/jdk/testlibrary/NetworkConfiguration.java
new file mode 100644
--- /dev/null
+++ b/test/lib/testlibrary/jdk/testlibrary/NetworkConfiguration.java
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.testlibrary;
+
+import java.io.PrintStream;
+import java.io.UncheckedIOException;
+import java.io.IOException;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import static java.net.NetworkInterface.getNetworkInterfaces;
+import static java.util.Collections.list;
+
+/**
+ * Helper class for retrieving network interfaces and local addresses
+ * suitable for testing.
+ */
+public class NetworkConfiguration {
+
+    static final boolean isWindows =
+            System.getProperty("os.name").startsWith("Windows");
+    static final boolean isMacOS =
+            System.getProperty("os.name").contains("OS X");
+
+    private Map<NetworkInterface,List<Inet4Address>> ip4Interfaces;
+    private Map<NetworkInterface,List<Inet6Address>> ip6Interfaces;
+
+    private NetworkConfiguration(Map<NetworkInterface,List<Inet4Address>> ip4Interfaces,
+                                 Map<NetworkInterface,List<Inet6Address>> ip6Interfaces)
+    {
+        this.ip4Interfaces = ip4Interfaces;
+        this.ip6Interfaces = ip6Interfaces;
+    }
+
+    /**
+     * Returns a stream of interfaces suitable for functional tests.
+     */
+    public Stream<NetworkInterface> interfaces() {
+        return Stream.concat(ip4Interfaces(), ip6Interfaces())
+                     .distinct();
+    }
+
+    /**
+     * Returns a stream of interfaces suitable for IPv4 functional tests.
+     */
+    public Stream<NetworkInterface> ip4Interfaces() {
+        return ip4Interfaces.keySet().stream()
+                .filter(NetworkConfiguration::isNotExcludedInterface)
+                .filter(hasIp4Addresses);
+    }
+
+    /**
+     * Returns a stream of interfaces suitable for IPv6 functional tests.
+     */
+    public Stream<NetworkInterface> ip6Interfaces() {
+        return ip6Interfaces.keySet().stream()
+                .filter(NetworkConfiguration::isNotExcludedInterface)
+                .filter(hasIp6Addresses);
+    }
+
+    private static boolean isNotExcludedInterface(NetworkInterface nif) {
+        if (isMacOS && nif.getName().contains("awdl"))
+            return false;
+        String dName = nif.getDisplayName();
+        if (isWindows && dName != null && dName.contains("Teredo"))
+            return false;
+        return true;
+    }
+
+    private final Predicate<NetworkInterface> hasIp4Addresses = nif -> {
+        Optional<?> addr = ip4Interfaces.get(nif).stream()
+                .filter(a -> !a.isAnyLocalAddress())
+                .findAny();
+
+        return addr.isPresent();
+    };
+
+    private final Predicate<NetworkInterface> hasIp6Addresses = nif -> {
+        Optional<?> addr = ip6Interfaces.get(nif).stream()
+                .filter(a -> !a.isAnyLocalAddress())
+                .findAny();
+
+        return addr.isPresent();
+    };
+
+
+    /**
+     * Returns a stream of interfaces suitable for IPv4 multicast tests.
+     */
+    public Stream<NetworkInterface> ip4MulticastInterfaces() {
+        return ip4Interfaces().filter(supportsIp4Multicast);
+    }
+
+    /**
+     * Returns a stream of interfaces suitable for IPv6 multicast tests.
+     */
+    public Stream<NetworkInterface> ip6MulticastInterfaces() {
+        return ip6Interfaces().filter(supportsIp6Multicast);
+    }
+
+    private final Predicate<NetworkInterface> supportsIp4Multicast = nif -> {
+        try {
+            if (!nif.supportsMulticast() || nif.isLoopback())
+                return false;
+
+            Optional<?> addr = ip4Interfaces.get(nif).stream()
+                    .filter(a -> !a.isAnyLocalAddress())
+                    .findAny();
+
+            return addr.isPresent();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    };
+
+    private final Predicate<NetworkInterface> supportsIp6Multicast = nif -> {
+        try {
+            if (!nif.supportsMulticast() || nif.isLoopback())
+                return false;
+
+            Optional<?> addr = ip6Interfaces.get(nif).stream()
+                    .filter(a -> !a.isAnyLocalAddress())
+                    .findAny();
+
+            return addr.isPresent();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    };
+
+    /**
+     * Returns all addresses on all "functional" interfaces.
+     */
+    public Stream<InetAddress> addresses(NetworkInterface nif) {
+        return Stream.concat(ip4Interfaces.get(nif).stream(),
+                             ip6Interfaces.get(nif).stream());
+    }
+
+    /**
+     * Returns all IPv4 addresses on all "functional" interfaces.
+     */
+    public Stream<Inet4Address> ip4Addresses() {
+        return ip4Interfaces().flatMap(nif -> ip4Addresses(nif));
+    }
+
+    /**
+     * Returns all IPv6 addresses on all "functional" interfaces.
+     */
+    public Stream<Inet6Address> ip6Addresses() {
+        return ip6Interfaces().flatMap(nif -> ip6Addresses(nif));
+    }
+
+    /**
+     * Returns all IPv4 addresses the given interface.
+     */
+    public Stream<Inet4Address> ip4Addresses(NetworkInterface nif) {
+        return ip4Interfaces.get(nif).stream();
+    }
+
+    /**
+     * Returns all IPv6 addresses for the given interface.
+     */
+    public Stream<Inet6Address> ip6Addresses(NetworkInterface nif) {
+        return ip6Interfaces.get(nif).stream();
+    }
+
+    /**
+     * Return a NetworkConfiguration instance.
+     */
+    public static NetworkConfiguration probe() throws IOException {
+        Map<NetworkInterface, List<Inet4Address>> ip4Interfaces = new HashMap<>();
+        Map<NetworkInterface, List<Inet6Address>> ip6Interfaces = new HashMap<>();
+
+        List<NetworkInterface> nifs = list(getNetworkInterfaces());
+        for (NetworkInterface nif : nifs) {
+            // ignore interfaces that are down
+            if (!nif.isUp() || nif.isPointToPoint())
+                continue;
+
+            List<Inet4Address> ip4Addresses = new LinkedList<>();
+            List<Inet6Address> ip6Addresses = new LinkedList<>();
+            ip4Interfaces.put(nif, ip4Addresses);
+            ip6Interfaces.put(nif, ip6Addresses);
+            for (InetAddress addr : list(nif.getInetAddresses())) {
+                if (addr instanceof Inet4Address)
+                    ip4Addresses.add((Inet4Address)addr);
+                else if (addr instanceof Inet6Address)
+                    ip6Addresses.add((Inet6Address)addr);
+            }
+        }
+        return new NetworkConfiguration(ip4Interfaces, ip6Interfaces);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        interfaces().forEach(nif -> sb.append(interfaceInformation(nif)));
+        return sb.toString();
+    }
+
+    /** Returns detailed information for the given interface. */
+    public static String interfaceInformation(NetworkInterface nif) {
+        StringBuilder sb = new StringBuilder();
+        try {
+            sb.append("Display name: " + nif.getDisplayName() + "\n");
+            sb.append("Name: " + nif.getName() + "\n");
+            for (InetAddress inetAddress : list(nif.getInetAddresses()))
+                sb.append("InetAddress: " + inetAddress + "\n");
+            sb.append("Up? " + nif.isUp() + "\n");
+            sb.append("Loopback? " + nif.isLoopback() + "\n");
+            sb.append("PointToPoint? " + nif.isPointToPoint() + "\n");
+            sb.append("Supports multicast? " + nif.supportsMulticast() + "\n");
+            sb.append("Virtual? " + nif.isVirtual() + "\n");
+            sb.append("Hardware address: " +
+                    Arrays.toString(nif.getHardwareAddress()) + "\n");
+            sb.append("MTU: " + nif.getMTU() + "\n");
+            sb.append("Index: " + nif.getIndex() + "\n");
+            sb.append("\n");
+            return sb.toString();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+
+    /** Prints all the system interface information to the give stream. */
+    public static void printSystemConfiguration(PrintStream out) {
+        try {
+            out.println("*** all system network interface configuration ***");
+            List<NetworkInterface> nifs = list(getNetworkInterfaces());
+            for (NetworkInterface nif : nifs)
+                out.print(interfaceInformation(nif));
+            out.println("*** end ***");
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+}
diff --git a/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java b/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
--- a/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
+++ b/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
@@ -82,6 +82,32 @@
     }
 
     /**
+     * Verify that the stdout contents of output buffer is empty
+     *
+     * @throws RuntimeException
+     *             If stdout was not empty
+     */
+    public void stdoutShouldBeEmpty() {
+        if (!stdout.isEmpty()) {
+            reportDiagnosticSummary();
+            throw new RuntimeException("stdout was not empty");
+        }
+    }
+
+    /**
+     * Verify that the stderr contents of output buffer is empty
+     *
+     * @throws RuntimeException
+     *             If stderr was not empty
+     */
+    public void stderrShouldBeEmpty() {
+        if (!stderr.isEmpty()) {
+            reportDiagnosticSummary();
+            throw new RuntimeException("stderr was not empty");
+        }
+    }
+
+    /**
      * Verify that the stdout and stderr contents of output buffer contains the
      * string
      *
diff --git a/test/sun/nio/ch/TestMaxCachedBufferSize.java b/test/sun/nio/ch/TestMaxCachedBufferSize.java
--- a/test/sun/nio/ch/TestMaxCachedBufferSize.java
+++ b/test/sun/nio/ch/TestMaxCachedBufferSize.java
@@ -39,6 +39,7 @@
 
 import java.util.List;
 import java.util.Random;
+import java.util.concurrent.CountDownLatch;
 
 /*
  * @test
@@ -92,6 +93,7 @@
     // by setting the jdk.nio.maxCachedBufferSize property.
     private static class Worker implements Runnable {
         private final int id;
+        private final CountDownLatch finishLatch, exitLatch;
         private final Random random = new Random();
         private long smallBufferCount = 0;
         private long largeBufferCount = 0;
@@ -151,6 +153,13 @@
                 }
             } catch (IOException e) {
                 throw new Error("I/O error", e);
+            } finally {
+                finishLatch.countDown();
+                try {
+                    exitLatch.await();
+                } catch (InterruptedException e) {
+                    // ignore
+                }
             }
         }
 
@@ -159,8 +168,10 @@
             loop();
         }
 
-        public Worker(int id) {
+        public Worker(int id, CountDownLatch finishLatch, CountDownLatch exitLatch) {
             this.id = id;
+            this.finishLatch = finishLatch;
+            this.exitLatch = exitLatch;
         }
     }
 
@@ -170,10 +181,6 @@
         System.out.printf("Direct %d / %dK\n",
                           directCount, directTotalCapacity / 1024);
 
-        // Note that directCount could be < expectedCount. This can
-        // happen if a GC occurs after one of the worker threads exits
-        // since its thread-local DirectByteBuffer could be cleaned up
-        // before we reach here.
         if (directCount > expectedCount) {
             throw new Error(String.format(
                 "inconsistent direct buffer total count, expected = %d, found = %d",
@@ -207,46 +214,57 @@
                           threadNum, iters, maxBufferSize);
         System.out.println();
 
+        final CountDownLatch finishLatch = new CountDownLatch(threadNum);
+        final CountDownLatch exitLatch = new CountDownLatch(1);
         final Thread[] threads = new Thread[threadNum];
         for (int i = 0; i < threadNum; i += 1) {
-            threads[i] = new Thread(new Worker(i));
+            threads[i] = new Thread(new Worker(i, finishLatch, exitLatch));
             threads[i].start();
         }
 
         try {
-            for (int i = 0; i < threadNum; i += 1) {
-                threads[i].join();
+            try {
+                finishLatch.await();
+            } catch (InterruptedException e) {
+                throw new Error("finishLatch.await() interrupted!", e);
             }
-        } catch (InterruptedException e) {
-            throw new Error("join() interrupted!", e);
-        }
 
-        // There is an assumption here that, at this point, only the
-        // cached DirectByteBuffers should be active. Given we
-        // haven't used any other DirectByteBuffers in this test, this
-        // should hold.
-        //
-        // Also note that we can only do the sanity checking at the
-        // end and not during the run given that, at any time, there
-        // could be buffers currently in use by some of the workers
-        // that will not be cached.
+            // There is an assumption here that, at this point, only the
+            // cached DirectByteBuffers should be active. Given we
+            // haven't used any other DirectByteBuffers in this test, this
+            // should hold.
+            //
+            // Also note that we can only do the sanity checking at the
+            // end and not during the run given that, at any time, there
+            // could be buffers currently in use by some of the workers
+            // that will not be cached.
 
-        System.out.println();
-        if (maxBufferSize < SMALL_BUFFER_MAX_SIZE) {
-            // The max buffer size is smaller than all buffers that
-            // were allocated. No buffers should have been cached.
-            checkDirectBuffers(0, 0);
-        } else if (maxBufferSize < LARGE_BUFFER_MIN_SIZE) {
-            // The max buffer size is larger than all small buffers
-            // but smaller than all large buffers that were
-            // allocated. Only small buffers could have been cached.
-            checkDirectBuffers(threadNum,
-                               (long) threadNum * (long) SMALL_BUFFER_MAX_SIZE);
-        } else {
-            // The max buffer size is larger than all buffers that
-            // were allocated. All buffers could have been cached.
-            checkDirectBuffers(threadNum,
-                               (long) threadNum * (long) LARGE_BUFFER_MAX_SIZE);
+            System.out.println();
+            if (maxBufferSize < SMALL_BUFFER_MAX_SIZE) {
+                // The max buffer size is smaller than all buffers that
+                // were allocated. No buffers should have been cached.
+                checkDirectBuffers(0, 0);
+            } else if (maxBufferSize < LARGE_BUFFER_MIN_SIZE) {
+                // The max buffer size is larger than all small buffers
+                // but smaller than all large buffers that were
+                // allocated. Only small buffers could have been cached.
+                checkDirectBuffers(threadNum,
+                                   (long) threadNum * (long) SMALL_BUFFER_MAX_SIZE);
+            } else {
+                // The max buffer size is larger than all buffers that
+                // were allocated. All buffers could have been cached.
+                checkDirectBuffers(threadNum,
+                                   (long) threadNum * (long) LARGE_BUFFER_MAX_SIZE);
+            }
+        } finally {
+            exitLatch.countDown();
+            try {
+                for (int i = 0; i < threadNum; i += 1) {
+                    threads[i].join();
+                }
+            } catch (InterruptedException e) {
+                // ignore
+            }
         }
     }
 }
diff --git a/test/sun/security/lib/cacerts/VerifyCACerts.java b/test/sun/security/lib/cacerts/VerifyCACerts.java
--- a/test/sun/security/lib/cacerts/VerifyCACerts.java
+++ b/test/sun/security/lib/cacerts/VerifyCACerts.java
@@ -27,7 +27,7 @@
  * @bug 8189131 8198240 8191844 8189949 8191031 8196141 8204923 8195774 8199779
  *      8209452 8209506 8210432 8195793 8216577 8222089 8222133 8222137 8222136
  *      8223499 8225392 8232019 8234245 8233223 8225068 8225069 8243321 8243320
- *      8225072 8258630 8259312 8243559 8256421 8225081
+ *      8243559 8225072 8258630 8259312 8256421 8225081 8225082 8225083
  * @summary Check root CA entries in cacerts file
  */
 import java.io.ByteArrayInputStream;
@@ -53,12 +53,12 @@
             + File.separator + "security" + File.separator + "cacerts";
 
     // The numbers of certs now.
-    private static final int COUNT = 91;
+    private static final int COUNT = 89;
 
     // SHA-256 of cacerts, can be generated with
     // shasum -a 256 cacerts | sed -e 's/../&:/g' | tr '[:lower:]' '[:upper:]' | cut -c1-95
     private static final String CHECKSUM
-            = "9B:C3:0B:24:D4:26:E4:A9:4F:2C:96:25:06:9B:08:E5:13:5B:0B:33:74:5F:78:DB:BD:91:CD:31:D4:37:07:28";
+            = "CC:AD:BB:49:70:97:3F:42:AD:73:91:A0:A2:C4:B8:AA:D1:95:59:F3:B3:22:09:2A:1F:2C:AB:04:47:08:EF:AA";
 
     // map of cert alias to SHA-256 fingerprint
     @SuppressWarnings("serial")
@@ -145,8 +145,6 @@
                     "49:E7:A4:42:AC:F0:EA:62:87:05:00:54:B5:25:64:B6:50:E4:F4:9E:42:E3:48:D6:AA:38:E0:39:E9:57:B1:C1");
             put("dtrustclass3ca2ev [jdk]",
                     "EE:C5:49:6B:98:8C:E9:86:25:B9:34:09:2E:EC:29:08:BE:D0:B0:F3:16:C2:D4:73:0C:84:EA:F1:F3:D3:48:81");
-            put("identrustdstx3 [jdk]",
-                    "06:87:26:03:31:A7:24:03:D9:09:F1:05:E6:9B:CF:0D:32:E1:BD:24:93:FF:C6:D9:20:6D:11:BC:D6:77:07:39");
             put("identrustpublicca [jdk]",
                     "30:D0:89:5A:9A:44:8A:26:20:91:63:55:22:D1:F5:20:10:B5:86:7A:CA:E1:2C:78:EF:95:8F:D4:F4:38:9F:2F");
             put("identrustcommercial [jdk]",
@@ -219,8 +217,6 @@
                     "17:9F:BC:14:8A:3D:D0:0F:D2:4E:A1:34:58:CC:43:BF:A7:F5:9C:81:82:D7:83:A5:13:F6:EB:EC:10:0C:89:24");
             put("globalsigneccrootcar4 [jdk]",
                     "BE:C9:49:11:C2:95:56:76:DB:6C:0A:55:09:86:D7:6E:3B:A0:05:66:7C:44:2C:97:62:B4:FB:B7:73:DE:22:8C");
-            put("globalsignr2ca [jdk]",
-                    "CA:42:DD:41:74:5F:D0:B8:1E:B9:02:36:2C:F9:D8:BF:71:9D:A1:BD:1B:1E:FC:94:6F:5B:4C:99:F4:2C:1B:9E");
             put("teliasonerarootcav1 [jdk]",
                     "DD:69:36:FE:21:F8:F0:77:C1:23:A1:A5:21:C1:22:24:F7:22:55:B7:3E:03:A7:26:06:93:E8:A2:4B:0F:A3:89");
             put("globalsignrootcar6 [jdk]",
@@ -265,8 +261,6 @@
             add("luxtrustglobalrootca [jdk]");
             // Valid until: Wed Mar 17 11:33:33 PDT 2021
             add("quovadisrootca [jdk]");
-            // Valid until: Thu Sep 30 14:01:15 GMT 2021
-            add("identrustdstx3 [jdk]");
         }
     };