changeset 12601:d120d2010cc9

Merge
author asaha
date Tue, 20 Dec 2016 13:42:18 -0800
parents 54f9a4d2496f 95763452250b
children 73039997fd0a
files .hgtags src/share/lib/security/java.security-aix src/share/lib/security/java.security-linux src/share/lib/security/java.security-macosx src/share/lib/security/java.security-solaris src/share/lib/security/java.security-windows test/sun/security/tools/jarsigner/TimestampCheck.java
diffstat 39 files changed, 546 insertions(+), 338 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java	Tue Dec 20 13:42:18 2016 -0800
@@ -72,8 +72,7 @@
     public void setDockIconImage(final Image image) {
         try {
             final CImage cImage = getCImageCreator().createFromImage(image);
-            final long nsImagePtr = getNSImagePtrFrom(cImage);
-            nativeSetDockIconImage(nsImagePtr);
+            cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);
         } catch (final Throwable e) {
             throw new RuntimeException(e);
         }
@@ -102,16 +101,4 @@
             throw new RuntimeException(e);
         }
     }
-
-    static long getNSImagePtrFrom(final CImage cImage) {
-        if (cImage == null) return 0;
-
-        try {
-            final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr");
-            cImagePtrField.setAccessible(true);
-            return cImagePtrField.getLong(cImage);
-        } catch (final Throwable e) {
-            throw new RuntimeException(e);
-        }
-    }
 }
--- a/src/macosx/classes/sun/java2d/opengl/CGLLayer.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/java2d/opengl/CGLLayer.java	Tue Dec 20 13:42:18 2016 -0800
@@ -108,7 +108,7 @@
         OGLRenderQueue rq = OGLRenderQueue.getInstance();
         rq.lock();
         try {
-            validate(getPointer(), cglsd);
+            execute(ptr -> validate(ptr, cglsd));
         } finally {
             rq.unlock();
         }
@@ -124,7 +124,7 @@
     private void setScale(final int _scale) {
         if (scale != _scale) {
             scale = _scale;
-            nativeSetScale(getPointer(), scale);
+            execute(ptr -> nativeSetScale(ptr, scale));
         }
     }
 
@@ -138,7 +138,7 @@
         OGLRenderQueue rq = OGLRenderQueue.getInstance();
         rq.lock();
         try {
-            blitTexture(getPointer());
+            execute(ptr -> blitTexture(ptr));
         } finally {
             rq.unlock();
         }
--- a/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -25,6 +25,10 @@
 
 package sun.lwawt.macosx;
 
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
 /**
  * Safely holds and disposes of native AppKit resources, using the
  * correct AppKit threading and Objective-C GC semantics.
@@ -36,6 +40,10 @@
     // TODO this pointer should be private and accessed via CFNativeAction class
     protected volatile long ptr;
 
+    private final ReadWriteLock lock = new ReentrantReadWriteLock();
+    private final Lock writeLock = lock.writeLock();
+    private final Lock readLock = lock.readLock();
+
     /**
      * @param ptr CFRetained native object pointer
      * @param disposeOnAppKitThread is the object needs to be CFReleased on the main thread
@@ -50,21 +58,31 @@
      * @param ptr CFRetained native object pointer
      */
     protected void setPtr(final long ptr) {
-        synchronized (this) {
-            if (this.ptr != 0) dispose();
+        writeLock.lock();
+        try {
+            if (this.ptr != 0) {
+                dispose();
+            }
             this.ptr = ptr;
+        } finally {
+            writeLock.unlock();
         }
     }
 
     /**
-     * Manually CFReleases the native resource
+     * Manually CFReleases the native resource.
      */
     protected void dispose() {
         long oldPtr = 0L;
-        synchronized (this) {
-            if (ptr == 0) return;
+        writeLock.lock();
+        try {
+            if (ptr == 0) {
+                return;
+            }
             oldPtr = ptr;
             ptr = 0;
+        } finally {
+            writeLock.unlock();
         }
 
         nativeCFRelease(oldPtr, disposeOnAppKitThread); // perform outside of the synchronized block
@@ -109,9 +127,14 @@
      *
      * @param  action The native operation
      */
-    public final synchronized void execute(final CFNativeAction action) {
-        if (ptr != 0) {
-            action.run(ptr);
+    public final void execute(final CFNativeAction action) {
+        readLock.lock();
+        try {
+            if (ptr != 0) {
+                action.run(ptr);
+            }
+        } finally {
+            readLock.unlock();
         }
     }
 
@@ -127,9 +150,14 @@
      * @return result of the native operation, usually the native pointer to
      *         some other data
      */
-    final synchronized long executeGet(final CFNativeActionGet action) {
-        if (ptr != 0) {
-            return action.run(ptr);
+    final long executeGet(final CFNativeActionGet action) {
+        readLock.lock();
+        try {
+            if (ptr != 0) {
+                return action.run(ptr);
+            }
+        } finally {
+            readLock.unlock();
         }
         return 0;
     }
--- a/src/macosx/classes/sun/lwawt/macosx/CImage.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CImage.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -33,6 +33,7 @@
 import java.util.List;
 import sun.awt.image.MultiResolutionImage;
 import sun.awt.image.MultiResolutionCachedImage;
+import java.util.concurrent.atomic.AtomicReference;
 
 import sun.awt.image.SunWritableRaster;
 
@@ -235,15 +236,26 @@
 
     /** @return A MultiResolution image created from nsImagePtr, or null. */
     private Image toImage() {
-        if (ptr == 0) return null;
+        if (ptr == 0) {
+            return null;
+        }
 
-        final Dimension2D size = nativeGetNSImageSize(ptr);
+        AtomicReference<Dimension2D> sizeRef = new AtomicReference<>();
+        execute(ptr -> {
+            sizeRef.set(nativeGetNSImageSize(ptr));
+        });
+        final Dimension2D size = sizeRef.get();
+        if (size == null) {
+            return null;
+        }
         final int w = (int)size.getWidth();
         final int h = (int)size.getHeight();
-
-        Dimension2D[] sizes
-                = nativeGetNSImageRepresentationSizes(ptr,
-                        size.getWidth(), size.getHeight());
+        AtomicReference<Dimension2D[]> repRef = new AtomicReference<>();
+        execute(ptr -> {
+            repRef.set(nativeGetNSImageRepresentationSizes(ptr, size.getWidth(),
+                                                           size.getHeight()));
+        });
+        Dimension2D[] sizes = repRef.get();
 
         return sizes == null || sizes.length < 2 ?
                 new MultiResolutionCachedImage(w, h, (width, height)
@@ -256,18 +268,18 @@
         final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
         final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
         final int[] buffer = SunWritableRaster.stealData(dbi, 0);
-        nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight);
+        execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
         SunWritableRaster.markDirty(dbi);
         return bimg;
     }
 
     /** If nsImagePtr != 0 then scale this NSImage. @return *this* */
     CImage resize(final double w, final double h) {
-        if (ptr != 0) nativeSetNSImageSize(ptr, w, h);
+        execute(ptr -> nativeSetNSImageSize(ptr, w, h));
         return this;
     }
 
     void resizeRepresentations(double w, double h) {
-        if (ptr != 0) nativeResizeNSImageRepresentations(ptr, w, h);
+        execute(ptr -> nativeResizeNSImageRepresentations(ptr, w, h));
     }
 }
--- a/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java	Tue Dec 20 13:42:18 2016 -0800
@@ -113,7 +113,13 @@
      */
     public final void setImage(final java.awt.Image img) {
         CImage cimg = CImage.getCreator().createFromImage(img);
-        execute(ptr -> nativeSetImage(ptr, cimg == null ? 0L : cimg.ptr));
+        execute(ptr -> {
+            if (cimg == null) {
+                nativeSetImage(ptr, 0L);
+            } else {
+                cimg.execute(imgPtr -> nativeSetImage(ptr, imgPtr));
+            }
+        });
     }
 
     /**
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,9 @@
         super(0, true);
     }
 
+    /**
+     * Used by JAWT.
+     */
     public long getPointer() {
         return ptr;
     }
@@ -61,7 +64,7 @@
         // translates values from the coordinate system of the top-level window
         // to the coordinate system of the content view
         final Insets insets = platformWindow.getPeer().getInsets();
-        nativeSetBounds(getPointer(), x - insets.left, y - insets.top, w, h);
+        execute(ptr->nativeSetBounds(ptr, x - insets.left, y - insets.top, w, h));
     }
 
     @Override
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java	Tue Dec 20 13:42:18 2016 -0800
@@ -108,11 +108,6 @@
     }
 
     @Override
-    public long getNSWindowPtr() {
-        return 0;
-    }
-
-    @Override
     public SurfaceData getSurfaceData() {
         return null;
     }
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,9 @@
 
 import java.awt.*;
 import java.awt.geom.Rectangle2D;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 
 import sun.awt.CGraphicsConfig;
 import sun.awt.CGraphicsEnvironment;
@@ -83,7 +86,7 @@
      * Cocoa coordinates).
      */
     public void setBounds(int x, int y, int width, int height) {
-        CWrapper.NSView.setFrame(ptr, x, y, width, height);
+        execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height));
     }
 
     // REMIND: CGLSurfaceData expects top-level's size
@@ -96,7 +99,7 @@
     }
 
     public void setToolTip(String msg) {
-        CWrapper.NSView.setToolTip(ptr, msg);
+        execute(ptr -> CWrapper.NSView.setToolTip(ptr, msg));
     }
 
     // ----------------------------------------------------------------------
@@ -147,18 +150,25 @@
     }
 
     public void setAutoResizable(boolean toResize) {
-        nativeSetAutoResizable(this.getAWTView(), toResize);
+        execute(ptr -> nativeSetAutoResizable(ptr, toResize));
     }
 
     public boolean isUnderMouse() {
-        return nativeIsViewUnderMouse(getAWTView());
+        AtomicBoolean ref = new AtomicBoolean();
+        execute(ptr -> {
+            ref.set(nativeIsViewUnderMouse(ptr));
+        });
+        return ref.get();
     }
 
     public GraphicsDevice getGraphicsDevice() {
         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
         CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
-        int displayID = nativeGetNSViewDisplayID(getAWTView());
-        GraphicsDevice gd = cge.getScreenDevice(displayID);
+        AtomicInteger ref = new AtomicInteger();
+        execute(ptr -> {
+            ref.set(nativeGetNSViewDisplayID(ptr));
+        });
+        GraphicsDevice gd = cge.getScreenDevice(ref.get());
         if (gd == null) {
             // this could possibly happen during device removal
             // use the default screen device in this case
@@ -168,8 +178,15 @@
     }
 
     public Point getLocationOnScreen() {
-        Rectangle r = nativeGetLocationOnScreen(this.getAWTView()).getBounds();
-        return new Point(r.x, r.y);
+        AtomicReference<Rectangle> ref = new AtomicReference<>();
+        execute(ptr -> {
+            ref.set(nativeGetLocationOnScreen(ptr).getBounds());
+        });
+        Rectangle r = ref.get();
+        if (r != null) {
+            return new Point(r.x, r.y);
+        }
+        return new Point(0, 0);
     }
 
     // ----------------------------------------------------------------------
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Tue Dec 20 13:42:18 2016 -0800
@@ -31,6 +31,9 @@
 import java.awt.peer.WindowPeer;
 import java.beans.*;
 import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.List;
 import java.util.Objects;
 
@@ -178,16 +181,16 @@
             c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString()));
         }},
         new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
-            nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
+            c.execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
         }},
         new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
             if (value == null || !(value instanceof java.io.File)) {
-                nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
+                c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, null));
                 return;
             }
 
             final String filename = ((java.io.File)value).getAbsolutePath();
-            nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
+            c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, filename));
         }}
     }) {
         public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
@@ -232,7 +235,6 @@
         contentView = createContentView();
         contentView.initialize(peer, responder);
 
-        final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
         Rectangle bounds;
         if (!IS(DECORATED, styleBits)) {
             // For undecorated frames the move/resize event does not come if the frame is centered on the screen
@@ -241,9 +243,21 @@
         } else {
             bounds = _peer.constrainBounds(_target.getBounds());
         }
-        final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
-                ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
-        setPtr(nativeWindowPtr);
+        AtomicLong ref = new AtomicLong();
+        contentView.execute(viewPtr -> {
+            if (owner != null) {
+                owner.execute(ownerPtr -> {
+                    ref.set(nativeCreateNSWindow(viewPtr, ownerPtr, styleBits,
+                                                 bounds.x, bounds.y,
+                                                 bounds.width, bounds.height));
+                });
+            } else {
+                ref.set(nativeCreateNSWindow(viewPtr, 0,
+                                             styleBits, bounds.x, bounds.y,
+                                             bounds.width, bounds.height));
+            }
+        });
+        setPtr(ref.get());
 
         if (target instanceof javax.swing.RootPaneContainer) {
             final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
@@ -405,30 +419,31 @@
 
     // this is the counter-point to -[CWindow _nativeSetStyleBit:]
     private void setStyleBits(final int mask, final boolean value) {
-        nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0);
+        execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
     }
 
     private native void _toggleFullScreenMode(final long model);
 
     public void toggleFullScreen() {
-        _toggleFullScreenMode(getNSWindowPtr());
+        execute(this::_toggleFullScreenMode);
     }
 
     @Override // PlatformWindow
     public void setMenuBar(MenuBar mb) {
-        final long nsWindowPtr = getNSWindowPtr();
         CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
-        if (mbPeer != null) {
-            mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
-        } else {
-            nativeSetNSWindowMenuBar(nsWindowPtr, 0);
-        }
+        execute(nsWindowPtr->{
+            if (mbPeer != null) {
+                mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
+            } else {
+                nativeSetNSWindowMenuBar(nsWindowPtr, 0);
+            }
+        });
     }
 
     @Override // PlatformWindow
     public void dispose() {
         contentView.dispose();
-        nativeDispose(getNSWindowPtr());
+        execute(CPlatformWindow::nativeDispose);
         CPlatformWindow.super.dispose();
     }
 
@@ -441,7 +456,11 @@
 
     @Override // PlatformWindow
     public Insets getInsets() {
-        return nativeGetNSWindowInsets(getNSWindowPtr());
+        AtomicReference<Insets> ref = new AtomicReference<>();
+        execute(ptr -> {
+            ref.set(nativeGetNSWindowInsets(ptr));
+        });
+        return ref.get() != null ? ref.get() : new Insets(0, 0, 0, 0);
     }
 
     @Override // PlatformWindow
@@ -468,12 +487,18 @@
     @Override // PlatformWindow
     public void setBounds(int x, int y, int w, int h) {
 //        assert CThreading.assertEventQueue();
-        nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
+        execute(ptr -> nativeSetNSWindowBounds(ptr, x, y, w, h));
     }
 
     private boolean isMaximized() {
-        return undecorated ? this.normalBounds != null
-                : CWrapper.NSWindow.isZoomed(getNSWindowPtr());
+        if (undecorated) {
+            return this.normalBounds != null;
+        }
+        AtomicBoolean ref = new AtomicBoolean();
+        execute(ptr -> {
+            ref.set(CWrapper.NSWindow.isZoomed(ptr));
+        });
+        return ref.get();
     }
 
     private void maximize() {
@@ -481,7 +506,7 @@
             return;
         }
         if (!undecorated) {
-            CWrapper.NSWindow.zoom(getNSWindowPtr());
+            execute(CWrapper.NSWindow::zoom);
         } else {
             deliverZoom(true);
 
@@ -505,7 +530,7 @@
             return;
         }
         if (!undecorated) {
-            CWrapper.NSWindow.zoom(getNSWindowPtr());
+            execute(CWrapper.NSWindow::zoom);
         } else {
             deliverZoom(false);
 
@@ -521,8 +546,6 @@
 
     @Override // PlatformWindow
     public void setVisible(boolean visible) {
-        final long nsWindowPtr = getNSWindowPtr();
-
         // Configure stuff
         updateIconImages();
         updateFocusabilityForAutoRequestFocus(false);
@@ -534,30 +557,44 @@
         if (blocker == null || !visible) {
             // If it ain't blocked, or is being hidden, go regular way
             if (visible) {
-                CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
+                contentView.execute(viewPtr -> {
+                    execute(ptr -> CWrapper.NSWindow.makeFirstResponder(ptr,
+                                                                        viewPtr));
+                });
 
                 boolean isPopup = (target.getType() == Window.Type.POPUP);
-                if (isPopup) {
-                    // Popups in applets don't activate applet's process
-                    CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
-                } else {
-                    CWrapper.NSWindow.orderFront(nsWindowPtr);
-                }
+                execute(ptr -> {
+                    if (isPopup) {
+                        // Popups in applets don't activate applet's process
+                        CWrapper.NSWindow.orderFrontRegardless(ptr);
+                    } else {
+                        CWrapper.NSWindow.orderFront(ptr);
+                    }
 
-                boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
-                if (!isKeyWindow) {
-                    CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
-                }
+                    boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(ptr);
+                    if (!isKeyWindow) {
+                        CWrapper.NSWindow.makeKeyWindow(ptr);
+                    }
+                });
             } else {
-                // immediately hide the window
-                CWrapper.NSWindow.orderOut(nsWindowPtr);
-                // process the close
-                CWrapper.NSWindow.close(nsWindowPtr);
+                execute(ptr->{
+                    // immediately hide the window
+                    CWrapper.NSWindow.orderOut(ptr);
+                    // process the close
+                    CWrapper.NSWindow.close(ptr);
+                });
             }
         } else {
             // otherwise, put it in a proper z-order
-            CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
-                    ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
+            CPlatformWindow bw
+                    = (CPlatformWindow) blocker.getPlatformWindow();
+            bw.execute(blockerPtr -> {
+                execute(ptr -> {
+                    CWrapper.NSWindow.orderWindow(ptr,
+                                                  CWrapper.NSWindow.NSWindowBelow,
+                                                  blockerPtr);
+                });
+            });
         }
         this.visible = visible;
 
@@ -576,7 +613,7 @@
                     }
                     switch (frameState) {
                         case Frame.ICONIFIED:
-                            CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                            execute(CWrapper.NSWindow::miniaturize);
                             break;
                         case Frame.MAXIMIZED_BOTH:
                             maximize();
@@ -598,7 +635,11 @@
         if (visible) {
             // Order myself above my parent
             if (owner != null && owner.isVisible()) {
-                CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr());
+                owner.execute(ownerPtr -> {
+                    execute(ptr -> {
+                        CWrapper.NSWindow.orderWindow(ptr, CWrapper.NSWindow.NSWindowAbove, ownerPtr);
+                    });
+                });
                 applyWindowLevel(target);
             }
 
@@ -608,7 +649,11 @@
                 if (p instanceof LWWindowPeer) {
                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
                     if (pw != null && pw.isVisible()) {
-                        CWrapper.NSWindow.orderWindow(pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr);
+                        pw.execute(childPtr -> {
+                            execute(ptr -> {
+                                CWrapper.NSWindow.orderWindow(childPtr, CWrapper.NSWindow.NSWindowAbove, ptr);
+                            });
+                        });
                         pw.applyWindowLevel(w);
                     }
                 }
@@ -624,25 +669,22 @@
 
     @Override // PlatformWindow
     public void setTitle(String title) {
-        nativeSetNSWindowTitle(getNSWindowPtr(), title);
+        execute(ptr -> nativeSetNSWindowTitle(ptr, title));
     }
 
     // Should be called on every window key property change.
     @Override // PlatformWindow
     public void updateIconImages() {
-        final long nsWindowPtr = getNSWindowPtr();
         final CImage cImage = getImageForTarget();
-        nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
-    }
-
-    public long getNSWindowPtr() {
-        final long nsWindowPtr = ptr;
-        if (nsWindowPtr == 0L) {
-            if(logger.isLoggable(PlatformLogger.Level.FINE)) {
-                logger.fine("NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
+        execute(ptr -> {
+            if (cImage == null) {
+                nativeSetNSWindowMinimizedIcon(ptr, 0L);
+            } else {
+                cImage.execute(imagePtr -> {
+                    nativeSetNSWindowMinimizedIcon(ptr, imagePtr);
+                });
             }
-        }
-        return nsWindowPtr;
+        });
     }
 
     public SurfaceData getSurfaceData() {
@@ -651,13 +693,11 @@
 
     @Override  // PlatformWindow
     public void toBack() {
-        final long nsWindowPtr = getNSWindowPtr();
-        nativePushNSWindowToBack(nsWindowPtr);
+        execute(CPlatformWindow::nativePushNSWindowToBack);
     }
 
     @Override  // PlatformWindow
     public void toFront() {
-        final long nsWindowPtr = getNSWindowPtr();
         LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
         Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
         if( w != null && w.getPeer() != null
@@ -666,7 +706,7 @@
             lwcToolkit.activateApplicationIgnoringOtherApps();
         }
         updateFocusabilityForAutoRequestFocus(false);
-        nativePushNSWindowToFront(nsWindowPtr);
+        execute(CPlatformWindow::nativePushNSWindowToFront);
         updateFocusabilityForAutoRequestFocus(true);
     }
 
@@ -677,7 +717,7 @@
 
     @Override
     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
-        nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH);
+        execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
     }
 
     @Override
@@ -694,19 +734,22 @@
 
     @Override
     public boolean requestWindowFocus() {
-
-        long ptr = getNSWindowPtr();
-        if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
-            CWrapper.NSWindow.makeMainWindow(ptr);
-        }
-        CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
+        execute(ptr -> {
+            if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
+                CWrapper.NSWindow.makeMainWindow(ptr);
+            }
+            CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
+        });
         return true;
     }
 
     @Override
     public boolean isActive() {
-        long ptr = getNSWindowPtr();
-        return CWrapper.NSWindow.isKeyWindow(ptr);
+        AtomicBoolean ref = new AtomicBoolean();
+        execute(ptr -> {
+            ref.set(CWrapper.NSWindow.isKeyWindow(ptr));
+        });
+        return ref.get();
     }
 
     @Override
@@ -732,21 +775,21 @@
 
     @Override
     public void setOpacity(float opacity) {
-        CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
+        execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
     }
 
     @Override
     public void setOpaque(boolean isOpaque) {
-        CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
+        execute(ptr -> CWrapper.NSWindow.setOpaque(ptr, isOpaque));
         boolean isTextured = (peer == null) ? false : peer.isTextured();
         if (!isTextured) {
             if (!isOpaque) {
-                CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0);
+                execute(ptr -> CWrapper.NSWindow.setBackgroundColor(ptr, 0));
             } else if (peer != null) {
                 Color color = peer.getBackground();
                 if (color != null) {
                     int rgb = color.getRGB();
-                    CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb);
+                    execute(ptr->CWrapper.NSWindow.setBackgroundColor(ptr, rgb));
                 }
             }
         }
@@ -759,12 +802,12 @@
     @Override
     public void enterFullScreenMode() {
         isFullScreenMode = true;
-        nativeEnterFullScreenMode(getNSWindowPtr());
+        execute(CPlatformWindow::nativeEnterFullScreenMode);
     }
 
     @Override
     public void exitFullScreenMode() {
-        nativeExitFullScreenMode(getNSWindowPtr());
+        execute(CPlatformWindow::nativeExitFullScreenMode);
         isFullScreenMode = false;
     }
 
@@ -783,7 +826,6 @@
         int prevWindowState = peer.getState();
         if (prevWindowState == windowState) return;
 
-        final long nsWindowPtr = getNSWindowPtr();
         if ((windowState & Frame.ICONIFIED) != 0) {
             // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
             windowState = Frame.ICONIFIED;
@@ -795,18 +837,18 @@
                     // the zoom call toggles between the normal and the max states
                     unmaximize();
                 }
-                CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                execute(CWrapper.NSWindow::miniaturize);
                 break;
             case Frame.MAXIMIZED_BOTH:
                 if (prevWindowState == Frame.ICONIFIED) {
                     // let's return into the normal states first
-                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                    execute(CWrapper.NSWindow::deminiaturize);
                 }
                 maximize();
                 break;
             case Frame.NORMAL:
                 if (prevWindowState == Frame.ICONIFIED) {
-                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                    execute(CWrapper.NSWindow::deminiaturize);
                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
                     // the zoom call toggles between the normal and the max states
                     unmaximize();
@@ -826,12 +868,12 @@
             return;
         }
 
-        nativeSetEnabled(getNSWindowPtr(), !blocked);
+        execute(ptr -> nativeSetEnabled(ptr, !blocked));
         checkBlockingAndOrder();
     }
 
     public final void invalidateShadow(){
-        nativeRevalidateNSWindowShadow(getNSWindowPtr());
+        execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
     }
 
     // ----------------------------------------------------------------------
@@ -1011,11 +1053,11 @@
 
         pWindow.orderAboveSiblings();
 
-        final long nsWindowPtr = pWindow.getNSWindowPtr();
-        CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
-        CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
-        CWrapper.NSWindow.makeMainWindow(nsWindowPtr);
-
+        pWindow.execute(ptr -> {
+            CWrapper.NSWindow.orderFrontRegardless(ptr);
+            CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
+            CWrapper.NSWindow.makeMainWindow(ptr);
+        });
         return true;
     }
 
@@ -1035,10 +1077,12 @@
             owner.orderAboveSiblings();
 
             // Order the window to front of the stack of child windows
-            final long nsWindowSelfPtr = getNSWindowPtr();
-            final long nsWindowOwnerPtr = owner.getNSWindowPtr();
-            CWrapper.NSWindow.orderFront(nsWindowOwnerPtr);
-            CWrapper.NSWindow.orderWindow(nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove, nsWindowOwnerPtr);
+            owner.execute(nsWindowOwnerPtr->{
+                execute(nsWindowSelfPtr->{
+                    CWrapper.NSWindow.orderFront(nsWindowOwnerPtr);
+                    CWrapper.NSWindow.orderWindow(nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove, nsWindowOwnerPtr);
+                });
+            });
         }
 
         applyWindowLevel(target);
@@ -1046,9 +1090,9 @@
 
     protected void applyWindowLevel(Window target) {
         if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) {
-            CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
+            execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSFloatingWindowLevel));
         } else if (target.getType() == Window.Type.POPUP) {
-            CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel);
+            execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSPopUpMenuWindowLevel));
         }
     }
 
--- a/src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java	Tue Dec 20 13:42:18 2016 -0800
@@ -36,6 +36,7 @@
 import java.awt.peer.TrayIconPeer;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.concurrent.atomic.AtomicReference;
 
 public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
     private TrayIcon target;
@@ -88,10 +89,6 @@
         return nativeCreate();
     }
 
-    private long getModel() {
-        return ptr;
-    }
-
     private native long nativeCreate();
 
     //invocation from the AWTTrayIcon.m
@@ -154,7 +151,7 @@
 
     @Override
     public void setToolTip(String tooltip) {
-        nativeSetToolTip(getModel(), tooltip);
+        execute(ptr -> nativeSetToolTip(ptr, tooltip));
     }
 
     //adds tooltip to the NSStatusBar's NSButton.
@@ -183,7 +180,12 @@
         }
 
         CImage cimage = CImage.getCreator().createFromImage(image);
-        setNativeImage(getModel(), cimage.ptr, target.isImageAutoSize());
+        boolean imageAutoSize = target.isImageAutoSize();
+        cimage.execute(imagePtr -> {
+            execute(ptr -> {
+                setNativeImage(ptr, imagePtr, imageAutoSize);
+            });
+        });
     }
 
     private native void setNativeImage(final long model, final long nsimage, final boolean autosize);
@@ -363,7 +365,14 @@
     private void showMessageDialog() {
 
         Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
-        Point2D iconLoc = nativeGetIconLocation(getModel());
+        AtomicReference<Point2D> ref = new AtomicReference<>();
+        execute(ptr -> {
+            ref.set(nativeGetIconLocation(ptr));
+        });
+        Point2D iconLoc = ref.get();
+        if (iconLoc == null) {
+            return;
+        }
 
         int dialogY = (int)iconLoc.getY();
         int dialogX = (int)iconLoc.getX();
--- a/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java	Tue Dec 20 13:42:18 2016 -0800
@@ -74,13 +74,13 @@
 
     @Override
     public void dispose() {
-        CWrapper.NSView.removeFromSuperview(view.getAWTView());
+        view.execute(CWrapper.NSView::removeFromSuperview);
         view.dispose();
     }
 
     @Override
     public void setVisible(boolean visible) {
-        CWrapper.NSView.setHidden(view.getAWTView(), !visible);
+        view.execute(ptr -> CWrapper.NSView.setHidden(ptr, !visible));
     }
 
     @Override
--- a/src/macosx/classes/sun/lwawt/macosx/CWarningWindow.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CWarningWindow.java	Tue Dec 20 13:42:18 2016 -0800
@@ -219,14 +219,14 @@
     @Override
     public void setVisible(boolean visible) {
         synchronized (lock) {
-            final long nsWindowPtr = getNSWindowPtr();
-
-            // Actually show or hide the window
-            if (visible) {
-                CWrapper.NSWindow.orderFront(nsWindowPtr);
-            } else {
-                CWrapper.NSWindow.orderOut(nsWindowPtr);
-            }
+            execute(ptr -> {
+                // Actually show or hide the window
+                if (visible) {
+                    CWrapper.NSWindow.orderFront(ptr);
+                } else {
+                    CWrapper.NSWindow.orderOut(ptr);
+                }
+            });
 
             this.visible = visible;
 
@@ -234,8 +234,13 @@
             if (visible) {
                 // Order myself above my parent
                 if (owner != null && owner.isVisible()) {
-                    CWrapper.NSWindow.orderWindow(nsWindowPtr,
-                            CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr());
+                    owner.execute(ownerPtr -> {
+                        execute(ptr -> {
+                            CWrapper.NSWindow.orderWindow(ptr,
+                                                          CWrapper.NSWindow.NSWindowAbove,
+                                                          ownerPtr);
+                        });
+                    });
 
                     // do not allow security warning to be obscured by other windows
                     applyWindowLevel(ownerWindow);
--- a/src/macosx/native/sun/awt/AWTSurfaceLayers.h	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/native/sun/awt/AWTSurfaceLayers.h	Tue Dec 20 13:42:18 2016 -0800
@@ -41,6 +41,8 @@
     CALayer *windowLayer;
 }
 
+@property (retain) CALayer *windowLayer;
+
 - (id) initWithWindowLayer: (CALayer *)windowLayer;
 - (void) setBounds: (CGRect)rect;
 
--- a/src/macosx/native/sun/awt/AWTSurfaceLayers.m	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/macosx/native/sun/awt/AWTSurfaceLayers.m	Tue Dec 20 13:42:18 2016 -0800
@@ -38,11 +38,15 @@
     self = [super init];
     if (self == nil) return self;
 
-    windowLayer = aWindowLayer;
+    self.windowLayer = aWindowLayer;
 
     return self;
 }
 
+- (void) dealloc {
+    self.windowLayer = nil;
+    [super dealloc];
+}
 
 - (CALayer *) layer {
     return layer;
--- a/src/share/classes/sun/misc/Launcher.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/share/classes/sun/misc/Launcher.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,11 +28,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.FilePermission;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.MalformedURLException;
-import java.net.URLStreamHandler;
-import java.net.URLStreamHandlerFactory;
+import java.net.*;
 import java.util.HashSet;
 import java.util.StringTokenizer;
 import java.util.Set;
@@ -213,8 +209,16 @@
             URL[] urls = super.getURLs();
             File prevDir = null;
             for (int i = 0; i < urls.length; i++) {
-                // Get the ext directory from the URL
-                File dir = new File(urls[i].getPath()).getParentFile();
+                // Get the ext directory from the URL; convert to
+                // URI first, so the URL will be decoded.
+                URI uri;
+                try {
+                    uri = urls[i].toURI();
+                } catch (URISyntaxException ue) {
+                    // skip this URL if cannot convert it to URI
+                    continue;
+                }
+                File dir = new File(uri).getParentFile();
                 if (dir != null && !dir.equals(prevDir)) {
                     // Look in architecture-specific subdirectory first
                     // Read from the saved system properties to avoid deadlock
--- a/src/share/classes/sun/net/www/http/HttpClient.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/share/classes/sun/net/www/http/HttpClient.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -98,7 +98,15 @@
     // from previous releases.
     private static boolean retryPostProp = true;
 
+    /* Value of the system property jdk.ntlm.cache;
+       if false, then NTLM connections will not be cached.
+       The default value is 'true'. */
+    private static final boolean cacheNTLMProp;
+
     volatile boolean keepingAlive = false;     /* this is a keep-alive connection */
+    volatile boolean disableKeepAlive;/* keep-alive has been disabled for this
+                                         connection - this will be used when
+                                         recomputing the value of keepingAlive */
     int keepAliveConnections = -1;    /* number of keep-alives left */
 
     /**Idle timeout value, in milliseconds. Zero means infinity,
@@ -149,6 +157,9 @@
         String retryPost = java.security.AccessController.doPrivileged(
             new sun.security.action.GetPropertyAction("sun.net.http.retryPost"));
 
+        String cacheNTLM = java.security.AccessController.doPrivileged(
+            new sun.security.action.GetPropertyAction("jdk.ntlm.cache"));
+
         if (keepAlive != null) {
             keepAliveProp = Boolean.valueOf(keepAlive).booleanValue();
         } else {
@@ -157,9 +168,15 @@
 
         if (retryPost != null) {
             retryPostProp = Boolean.valueOf(retryPost).booleanValue();
-        } else
-            retryPostProp = true;
+        } else {
+             retryPostProp = true;
+        }
 
+        if (cacheNTLM != null) {
+            cacheNTLMProp = Boolean.parseBoolean(cacheNTLM);
+        } else {
+            cacheNTLMProp = true;
+        }
     }
 
     /**
@@ -708,6 +725,7 @@
                 nread += r;
             }
             String keep=null;
+            String authenticate=null;
             ret = b[0] == 'H' && b[1] == 'T'
                     && b[2] == 'T' && b[3] == 'P' && b[4] == '/' &&
                 b[5] == '1' && b[6] == '.';
@@ -736,17 +754,37 @@
                  */
                 if (usingProxy) { // not likely a proxy will return this
                     keep = responses.findValue("Proxy-Connection");
+                    authenticate = responses.findValue("Proxy-Authenticate");
                 }
                 if (keep == null) {
                     keep = responses.findValue("Connection");
+                    authenticate = responses.findValue("WWW-Authenticate");
                 }
+
+                // 'disableKeepAlive' starts with the value false.
+                // It can transition from false to true, but once true
+                // it stays true.
+                // If cacheNTLMProp is false, and disableKeepAlive is false,
+                // then we need to examine the response headers to figure out
+                // whether we are doing NTLM authentication. If we do NTLM,
+                // and cacheNTLMProp is false, than we can't keep this connection
+                // alive: we will switch disableKeepAlive to true.
+                boolean canKeepAlive = !disableKeepAlive;
+                if (canKeepAlive && cacheNTLMProp == false && authenticate != null) {
+                    authenticate = authenticate.toLowerCase(Locale.US);
+                    canKeepAlive = !authenticate.startsWith("ntlm ");
+                }
+                disableKeepAlive |= !canKeepAlive;
+
                 if (keep != null && keep.toLowerCase(Locale.US).equals("keep-alive")) {
                     /* some servers, notably Apache1.1, send something like:
                      * "Keep-Alive: timeout=15, max=1" which we should respect.
                      */
-                    HeaderParser p = new HeaderParser(
+                    if (disableKeepAlive) {
+                        keepAliveConnections = 1;
+                    } else {
+                        HeaderParser p = new HeaderParser(
                             responses.findValue("Keep-Alive"));
-                    if (p != null) {
                         /* default should be larger in case of proxy */
                         keepAliveConnections = p.findInt("max", usingProxy?50:5);
                         keepAliveTimeout = p.findInt("timeout", usingProxy?60:5);
@@ -756,7 +794,7 @@
                      * We're talking 1.1 or later. Keep persistent until
                      * the server says to close.
                      */
-                    if (keep != null) {
+                    if (keep != null || disableKeepAlive) {
                         /*
                          * The only Connection token we understand is close.
                          * Paranoia: if there is any Connection header then
@@ -838,7 +876,7 @@
                 keepAliveConnections = 1;
                 keepingAlive = false;
             } else {
-                keepingAlive = true;
+                keepingAlive = !disableKeepAlive;
             }
             failedOnce = false;
         } else {
@@ -871,7 +909,7 @@
                 (cl >= 0 ||
                  code == HttpURLConnection.HTTP_NOT_MODIFIED ||
                  code == HttpURLConnection.HTTP_NO_CONTENT)) {
-                keepingAlive = true;
+                keepingAlive = !disableKeepAlive;
                 failedOnce = false;
             } else if (keepingAlive) {
                 /* Previously we were keeping alive, and now we're not.  Remove
--- a/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -64,8 +64,7 @@
      * repeatedly, via the Authenticator. Default is false, which means that this
      * behavior is switched off.
      */
-    static boolean serializeAuth;
-
+    static final boolean serializeAuth;
     static {
         serializeAuth = java.security.AccessController.doPrivileged(
             new sun.security.action.GetBooleanAction(
@@ -105,6 +104,16 @@
     public String getProtocolScheme() {
         return protocol;
     }
+    /**
+     * Whether we should cache this instance in the AuthCache.
+     * This method returns {@code true} by default.
+     * Subclasses may override this method to add
+     * additional restrictions.
+     * @return {@code true} by default.
+     */
+    protected boolean useAuthCache() {
+        return true;
+    }
 
     /**
      * requests is used to ensure that interaction with the
@@ -341,9 +350,11 @@
      */
     void addToCache() {
         String key = cacheKey(true);
-        cache.put(key, this);
-        if (supportsPreemptiveAuthorization()) {
-            cache.put(cacheKey(false), this);
+        if (useAuthCache()) {
+            cache.put(key, this);
+            if (supportsPreemptiveAuthorization()) {
+                cache.put(cacheKey(false), this);
+            }
         }
         endAuthRequest(key);
     }
--- a/src/share/classes/sun/security/smartcardio/CardImpl.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/share/classes/sun/security/smartcardio/CardImpl.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -280,13 +280,14 @@
     }
 
     public String toString() {
-        return "PC/SC card in " + terminal.getName()
+        return "PC/SC card in " + terminal.name
             + ", protocol " + getProtocol() + ", state " + state;
     }
 
     protected void finalize() throws Throwable {
         try {
             if (state == State.OK) {
+                state = State.DISCONNECTED;
                 SCardDisconnect(cardId, SCARD_LEAVE_CARD);
             }
         } finally {
--- a/src/solaris/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/solaris/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,11 +74,15 @@
 
     private String hostname;
     private static String defaultDomain; /* Domain to use if not specified by user */
+    private static final boolean ntlmCache;  /* Whether cache is enabled for NTLM */
 
     static {
         defaultDomain = java.security.AccessController.doPrivileged(
             new sun.security.action.GetPropertyAction("http.auth.ntlm.domain", ""));
-    };
+        String ntlmCacheProp = java.security.AccessController.doPrivileged(
+            new sun.security.action.GetPropertyAction("jdk.ntlm.cache", "true"));
+        ntlmCache = Boolean.parseBoolean(ntlmCacheProp);
+    }
 
     public static boolean supportsTransparentAuth () {
         return false;
@@ -167,6 +171,11 @@
         init (pw);
     }
 
+    @Override
+    protected boolean useAuthCache() {
+        return ntlmCache && super.useAuthCache();
+    }
+
     /**
      * @return true if this authentication supports preemptive authorization
      */
@@ -243,4 +252,3 @@
         return result;
     }
 }
-
--- a/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Tue Dec 20 13:42:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,11 +50,15 @@
 
     private String hostname;
     private static String defaultDomain; /* Domain to use if not specified by user */
+    private static final boolean ntlmCache; /* Whether cache is enabled for NTLM */
 
     static {
         defaultDomain = java.security.AccessController.doPrivileged(
             new sun.security.action.GetPropertyAction("http.auth.ntlm.domain",
                                                       "domain"));
+        String ntlmCacheProp = java.security.AccessController.doPrivileged(
+            new sun.security.action.GetPropertyAction("jdk.ntlm.cache", "true"));
+        ntlmCache = Boolean.parseBoolean(ntlmCacheProp);
     };
 
     private void init0() {
@@ -130,6 +134,11 @@
         init (pw);
     }
 
+    @Override
+    protected boolean useAuthCache() {
+        return ntlmCache && super.useAuthCache();
+    }
+
     /**
      * @return true if this authentication supports preemptive authorization
      */
--- a/src/windows/native/sun/windows/awt.h	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt.h	Tue Dec 20 13:42:18 2016 -0800
@@ -57,15 +57,6 @@
     }                                                                     \
 }
 
-#define JNI_CHECK_PEER_GOTO(peer, where) {                                \
-    JNI_CHECK_NULL_GOTO(peer, "peer", where);                             \
-    pData = JNI_GET_PDATA(peer);                                          \
-    if (pData == NULL) {                                                  \
-        THROW_NULL_PDATA_IF_NOT_DESTROYED(peer);                          \
-        goto where;                                                       \
-    }                                                                     \
-}
-
 #define JNI_CHECK_NULL_RETURN(obj, msg) {                                 \
     if (obj == NULL) {                                                    \
         env->ExceptionClear();                                            \
@@ -74,15 +65,6 @@
     }                                                                     \
 }
 
-#define JNI_CHECK_PEER_RETURN(peer) {                                     \
-    JNI_CHECK_NULL_RETURN(peer, "peer");                                  \
-    pData = JNI_GET_PDATA(peer);                                          \
-    if (pData == NULL) {                                                  \
-        THROW_NULL_PDATA_IF_NOT_DESTROYED(peer);                          \
-        return;                                                           \
-    }                                                                     \
-}
-
 #define JNI_CHECK_PEER_CREATION_RETURN(peer) {                            \
     if (peer == NULL ) {                                                  \
         return;                                                           \
@@ -109,6 +91,33 @@
     }                                                                     \
 }
 
+/**
+ * This macros must be used under SyncCall or on the Toolkit thread.
+ */
+#define JNI_CHECK_PEER_GOTO(peer, where) {                                \
+    JNI_CHECK_NULL_GOTO(peer, "peer", where);                             \
+    pData = JNI_GET_PDATA(peer);                                          \
+    if (pData == NULL) {                                                  \
+        THROW_NULL_PDATA_IF_NOT_DESTROYED(peer);                          \
+        goto where;                                                       \
+    }                                                                     \
+}
+
+/**
+ * This macros must be used under SyncCall or on the Toolkit thread.
+ */
+#define JNI_CHECK_PEER_RETURN(peer) {                                     \
+    JNI_CHECK_NULL_RETURN(peer, "peer");                                  \
+    pData = JNI_GET_PDATA(peer);                                          \
+    if (pData == NULL) {                                                  \
+        THROW_NULL_PDATA_IF_NOT_DESTROYED(peer);                          \
+        return;                                                           \
+    }                                                                     \
+}
+
+/**
+ * This macros must be used under SyncCall or on the Toolkit thread.
+ */
 #define JNI_CHECK_PEER_RETURN_NULL(peer) {                                \
     JNI_CHECK_NULL_RETURN_NULL(peer, "peer");                             \
     pData = JNI_GET_PDATA(peer);                                          \
@@ -118,6 +127,9 @@
     }                                                                     \
 }
 
+/**
+ * This macros must be used under SyncCall or on the Toolkit thread.
+ */
 #define JNI_CHECK_PEER_RETURN_VAL(peer, val) {                            \
     JNI_CHECK_NULL_RETURN_VAL(peer, "peer", val);                         \
     pData = JNI_GET_PDATA(peer);                                          \
--- a/src/windows/native/sun/windows/awt_Button.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Button.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -65,6 +65,7 @@
 /* Create a new AwtButton object and window. */
 AwtButton* AwtButton::Create(jobject self, jobject parent)
 {
+    DASSERT(AwtToolkit::IsMainThread());
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     /* the result */
@@ -88,7 +89,6 @@
 
         JNI_CHECK_PEER_GOTO(parent, done);
         awtParent = (AwtCanvas*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "awtParent", done);
 
         target = env->GetObjectField(self, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "target", done);
@@ -374,9 +374,6 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(self);
-
     SetLabelStruct *sls = new SetLabelStruct;
     sls->button = env->NewGlobalRef(self);
     sls->label = (label != NULL) ? (jstring)env->NewGlobalRef(label) : NULL;
@@ -398,14 +395,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
-
     AwtToolkit::CreateComponent(
         self, parent, (AwtToolkit::ComponentFactory)AwtButton::Create);
 
-    JNI_CHECK_PEER_CREATION_RETURN(self);
-
     CATCH_BAD_ALLOC;
 }
 
--- a/src/windows/native/sun/windows/awt_Canvas.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Canvas.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -59,6 +59,7 @@
  */
 AwtCanvas* AwtCanvas::Create(jobject self, jobject hParent)
 {
+    DASSERT(AwtToolkit::IsMainThread());
     TRY;
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
@@ -74,12 +75,11 @@
             return NULL;
         }
 
+        PDATA pData;
         AwtComponent* parent;
 
-        JNI_CHECK_NULL_GOTO(hParent, "null hParent", done);
-
-        parent = (AwtComponent*)JNI_GET_PDATA(hParent);
-        JNI_CHECK_NULL_GOTO(parent, "null parent", done);
+        JNI_CHECK_PEER_GOTO(hParent, done);
+        parent = (AwtCanvas*)pData;
 
         target = env->GetObjectField(self, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
@@ -236,12 +236,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtCanvas::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Checkbox.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Checkbox.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -70,6 +70,7 @@
 
 AwtCheckbox* AwtCheckbox::Create(jobject peer, jobject parent)
 {
+    DASSERT(AwtToolkit::IsMainThread());
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     jstring label = NULL;
@@ -81,11 +82,10 @@
             return NULL;
         }
 
+        PDATA pData;
         AwtComponent* awtParent;
-        JNI_CHECK_NULL_GOTO(parent, "null parent", done);
-
-        awtParent = (AwtComponent*)JNI_GET_PDATA(parent);
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
+        JNI_CHECK_PEER_GOTO(parent, done);
+        awtParent = (AwtCanvas*)pData;
 
         target = env->GetObjectField(peer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
@@ -667,11 +667,10 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtCheckbox::Create);
+    PDATA pData;
     JNI_CHECK_PEER_CREATION_RETURN(self);
 
 #ifdef DEBUG
--- a/src/windows/native/sun/windows/awt_Choice.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Choice.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -104,7 +104,7 @@
 }
 
 AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
-
+    DASSERT(AwtToolkit::IsMainThread());
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     jobject target = NULL;
@@ -115,12 +115,10 @@
         if (env->EnsureLocalCapacity(1) < 0) {
             return NULL;
         }
+        PDATA pData;
         AwtCanvas* awtParent;
-
-        JNI_CHECK_NULL_GOTO(parent, "null parent", done);
-
-        awtParent = (AwtCanvas*)JNI_GET_PDATA(parent);
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
+        JNI_CHECK_PEER_GOTO(parent, done);
+        awtParent = (AwtCanvas*)pData;
 
         target = env->GetObjectField(peer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
@@ -829,12 +827,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtChoice::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Component.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Component.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -150,6 +150,11 @@
     jobject component;
     jboolean doSetFocus;
 };
+// Struct for _SetParent function
+struct SetParentStruct {
+    jobject component;
+    jobject parentComp;
+};
 /************************************************************************/
 
 //////////////////////////////////////////////////////////////////////////
@@ -261,9 +266,6 @@
 {
     DASSERT(AwtToolkit::IsMainThread());
 
-    /* Disconnect all links. */
-    UnlinkObjects();
-
     /*
      * All the messages for this component are processed, native
      * resources are freed, and Java object is not connected to
@@ -275,6 +277,8 @@
 
 void AwtComponent::Dispose()
 {
+    DASSERT(AwtToolkit::IsMainThread());
+
     // NOTE: in case the component/toplevel was focused, Java should
     // have already taken care of proper transferring it or clearing.
 
@@ -293,8 +297,10 @@
     /* Release global ref to input method */
     SetInputMethod(NULL, TRUE);
 
-    if (m_childList != NULL)
+    if (m_childList != NULL) {
         delete m_childList;
+        m_childList = NULL;
+    }
 
     DestroyDropTarget();
     ReleaseDragCapture(0);
@@ -317,6 +323,9 @@
         m_brushBackground = NULL;
     }
 
+    /* Disconnect all links. */
+    UnlinkObjects();
+
     if (m_bPauseDestroy) {
         // AwtComponent::WmNcDestroy could be released now
         m_bPauseDestroy = FALSE;
@@ -6114,21 +6123,36 @@
     return result;
 }
 
-void AwtComponent::SetParent(void * param) {
+void AwtComponent::_SetParent(void * param)
+{
     if (AwtToolkit::IsMainThread()) {
-        AwtComponent** comps = (AwtComponent**)param;
-        if ((comps[0] != NULL) && (comps[1] != NULL)) {
-            HWND selfWnd = comps[0]->GetHWnd();
-            HWND parentWnd = comps[1]->GetHWnd();
-            if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
-                // Shouldn't trigger native focus change
-                // (only the proxy may be the native focus owner).
-                ::SetParent(selfWnd, parentWnd);
-            }
+        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+        SetParentStruct *data = (SetParentStruct*) param;
+        jobject self = data->component;
+        jobject parent = data->parentComp;
+
+        AwtComponent *awtComponent = NULL;
+        AwtComponent *awtParent = NULL;
+
+        PDATA pData;
+        JNI_CHECK_PEER_GOTO(self, ret);
+        awtComponent = (AwtComponent *)pData;
+        JNI_CHECK_PEER_GOTO(parent, ret);
+        awtParent = (AwtComponent *)pData;
+
+        HWND selfWnd = awtComponent->GetHWnd();
+        HWND parentWnd = awtParent->GetHWnd();
+        if (::IsWindow(selfWnd) && ::IsWindow(parentWnd)) {
+            // Shouldn't trigger native focus change
+            // (only the proxy may be the native focus owner).
+            ::SetParent(selfWnd, parentWnd);
         }
-        delete[] comps;
+ret:
+        env->DeleteGlobalRef(self);
+        env->DeleteGlobalRef(parent);
+        delete data;
     } else {
-        AwtToolkit::GetInstance().InvokeFunction(AwtComponent::SetParent, param);
+        AwtToolkit::GetInstance().InvokeFunction(AwtComponent::_SetParent, param);
     }
 }
 
@@ -6955,15 +6979,12 @@
 Java_sun_awt_windows_WComponentPeer_pSetParent(JNIEnv* env, jobject self, jobject parent) {
     TRY;
 
-    typedef AwtComponent* PComponent;
-    AwtComponent** comps = new PComponent[2];
-    AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(self);
-    AwtComponent* parentComp = (AwtComponent*)JNI_GET_PDATA(parent);
-    comps[0] = comp;
-    comps[1] = parentComp;
-
-    AwtToolkit::GetInstance().SyncCall(AwtComponent::SetParent, comps);
-    // comps is deleted in SetParent
+    SetParentStruct * data = new SetParentStruct;
+    data->component = env->NewGlobalRef(self);
+    data->parentComp = env->NewGlobalRef(parent);
+
+    AwtToolkit::GetInstance().SyncCall(AwtComponent::_SetParent, data);
+    // global refs and data are deleted in SetParent
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Component.h	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Component.h	Tue Dec 20 13:42:18 2016 -0800
@@ -665,6 +665,7 @@
     static void _RemoveNativeDropTarget(void *param);
     static jintArray _CreatePrintedPixels(void *param);
     static jboolean _NativeHandlesWheelScrolling(void *param);
+    static void _SetParent(void * param);
     static void _SetRectangularShape(void *param);
     static void _SetZOrder(void *param);
 
--- a/src/windows/native/sun/windows/awt_Dialog.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Dialog.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -112,12 +112,13 @@
         PDATA pData;
         AwtWindow* awtParent = NULL;
         HWND hwndParent = NULL;
+
         target = env->GetObjectField(peer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
 
         if (parent != NULL) {
             JNI_CHECK_PEER_GOTO(parent, done);
-            awtParent = (AwtWindow *)(JNI_GET_PDATA(parent));
+            awtParent = (AwtWindow *)pData;
             hwndParent = awtParent->GetHWnd();
         } else {
             // There is no way to prevent a parentless dialog from showing on
@@ -784,11 +785,9 @@
 {
     TRY;
 
-    PDATA pData;
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtDialog::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Frame.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Frame.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -1578,12 +1578,12 @@
 
     PDATA pData;
 
-    pData = JNI_GET_PDATA(peer);
+    JNI_CHECK_PEER_GOTO(peer, ret);
     AwtFrame *f = (AwtFrame *)pData;
 
     // dialog here may be NULL, for example, if the blocker is a native dialog
     // however, we need to install/unistall modal hooks anyway
-    pData = JNI_GET_PDATA(blockerPeer);
+    JNI_CHECK_PEER_GOTO(blockerPeer, ret);
     AwtDialog *d = (AwtDialog *)pData;
 
     if ((f != NULL) && ::IsWindow(f->GetHWnd()))
@@ -1635,7 +1635,7 @@
             }
         }
     }
-
+ret:
     env->DeleteGlobalRef(self);
     env->DeleteGlobalRef(peer);
     env->DeleteGlobalRef(blockerPeer);
@@ -1807,8 +1807,6 @@
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtFrame::Create);
-    PDATA pData;
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
@@ -1922,8 +1920,6 @@
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtFrame::Create);
-    PDATA pData;
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Label.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Label.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -80,7 +80,7 @@
 
         JNI_CHECK_PEER_GOTO(parent, done);
         awtParent = (AwtCanvas*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "awtParent", done);
+
         target  = env->GetObjectField(labelPeer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "target", done);
 
@@ -392,12 +392,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtLabel::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_List.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_List.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -89,10 +89,9 @@
 
         PDATA pData;
         AwtCanvas* awtParent;
+
         JNI_CHECK_PEER_GOTO(parent, done);
-
         awtParent = (AwtCanvas*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
 
         /* target is Hjava_awt_List * */
         target = env->GetObjectField(peer, AwtObject::targetID);
@@ -928,9 +927,6 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(self);
-
     SelectElementStruct *ses = new SelectElementStruct;
     ses->list = env->NewGlobalRef(self);
     ses->index = pos;
@@ -994,11 +990,8 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)AwtList::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_ScrollPane.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_ScrollPane.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -96,10 +96,9 @@
 
         PDATA pData;
         AwtComponent* awtParent;
+
         JNI_CHECK_PEER_GOTO(parent, done);
-
         awtParent = (AwtComponent*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
 
         target = env->GetObjectField(self, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
@@ -679,11 +678,10 @@
 
     DTRACE_PRINTLN2("%x: WScrollPanePeer.create(%x)", self, parent);
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtScrollPane::Create);
+    PDATA pData;
     JNI_CHECK_PEER_CREATION_RETURN(self);
     ((AwtScrollPane*)pData)->VerifyState();
 
--- a/src/windows/native/sun/windows/awt_Scrollbar.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Scrollbar.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -38,7 +38,11 @@
     jint value;
     jint visible;
     jint min, max;
-
+};
+// struct for _SetLineIncrement()/_SetPageIncrement() methods
+struct SetIncrementStruct {
+    jobject scrollbar;
+    jint increment;
 };
 /************************************************************************
  * AwtScrollbar fields
@@ -108,10 +112,9 @@
 
         PDATA pData;
         AwtCanvas* awtParent;
+
         JNI_CHECK_PEER_GOTO(parent, done);
-
         awtParent = (AwtCanvas*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
 
         target = env->GetObjectField(peer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
@@ -471,6 +474,52 @@
     delete svs;
 }
 
+void AwtScrollbar::_SetLineIncrement(void *param)
+{
+    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+
+    SetIncrementStruct *sis = (SetIncrementStruct *)param;
+    jobject self = sis->scrollbar;
+    jint increment = sis->increment;
+
+    AwtScrollbar *sb = NULL;
+
+    PDATA pData;
+    JNI_CHECK_PEER_GOTO(self, ret);
+    sb = (AwtScrollbar *)pData;
+    if (::IsWindow(sb->GetHWnd()))
+    {
+        sb->SetLineIncrement(increment);
+    }
+ret:
+    env->DeleteGlobalRef(self);
+
+    delete sis;
+}
+
+void AwtScrollbar::_SetPageIncrement(void *param)
+{
+    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+
+    SetIncrementStruct *sis = (SetIncrementStruct *)param;
+    jobject self = sis->scrollbar;
+    jint increment = sis->increment;
+
+    AwtScrollbar *sb = NULL;
+
+    PDATA pData;
+    JNI_CHECK_PEER_GOTO(self, ret);
+    sb = (AwtScrollbar *)pData;
+    if (::IsWindow(sb->GetHWnd()))
+    {
+        sb->SetPageIncrement(increment);
+    }
+ret:
+    env->DeleteGlobalRef(self);
+
+    delete sis;
+}
+
 /************************************************************************
  * Scrollbar native methods
  */
@@ -546,10 +595,12 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(self);
-    AwtScrollbar* c = (AwtScrollbar*)pData;
-    c->SetLineIncrement(increment);
+    SetIncrementStruct *sis = new SetIncrementStruct;
+    sis->scrollbar = env->NewGlobalRef(self);
+    sis->increment = increment;
+
+    AwtToolkit::GetInstance().SyncCall(AwtScrollbar::_SetLineIncrement, sis);
+    // global ref and svs are deleted in _SetValues
 
     CATCH_BAD_ALLOC;
 }
@@ -565,10 +616,12 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(self);
-    AwtScrollbar* c = (AwtScrollbar*)pData;
-    c->SetPageIncrement(increment);
+    SetIncrementStruct *sis = new SetIncrementStruct;
+    sis->scrollbar = env->NewGlobalRef(self);
+    sis->increment = increment;
+
+    AwtToolkit::GetInstance().SyncCall(AwtScrollbar::_SetPageIncrement, sis);
+    // global ref and svs are deleted in _SetValues
 
     CATCH_BAD_ALLOC;
 }
@@ -584,12 +637,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtScrollbar::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Scrollbar.h	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Scrollbar.h	Tue Dec 20 13:42:18 2016 -0800
@@ -77,6 +77,8 @@
 
     INLINE virtual BOOL IsScrollbar() { return TRUE; }
 
+    static void _SetLineIncrement(void *param);
+    static void _SetPageIncrement(void *param);
     // invoked on Toolkit thread
     static void _SetValues(void *param);
 
--- a/src/windows/native/sun/windows/awt_TextArea.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_TextArea.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -543,12 +543,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtTextArea::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_TextComponent.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_TextComponent.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -95,10 +95,9 @@
 
         PDATA pData;
         AwtCanvas* awtParent;
+
         JNI_CHECK_PEER_GOTO(parent, done);
-
         awtParent = (AwtCanvas*)pData;
-        JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done);
 
         target = env->GetObjectField(peer, AwtObject::targetID);
         JNI_CHECK_NULL_GOTO(target, "null target", done);
--- a/src/windows/native/sun/windows/awt_TextField.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_TextField.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -301,12 +301,9 @@
 {
     TRY;
 
-    PDATA pData;
-    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtTextField::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/windows/native/sun/windows/awt_Window.cpp	Tue Dec 20 13:28:30 2016 -0800
+++ b/src/windows/native/sun/windows/awt_Window.cpp	Tue Dec 20 13:42:18 2016 -0800
@@ -3246,12 +3246,9 @@
 {
     TRY;
 
-    PDATA pData;
-//    JNI_CHECK_PEER_RETURN(parent);
     AwtToolkit::CreateComponent(self, parent,
                                 (AwtToolkit::ComponentFactory)
                                 AwtWindow::Create);
-    JNI_CHECK_PEER_CREATION_RETURN(self);
 
     CATCH_BAD_ALLOC;
 }
--- a/test/sun/security/tools/jarsigner/warnings/Test.java	Tue Dec 20 13:28:30 2016 -0800
+++ b/test/sun/security/tools/jarsigner/warnings/Test.java	Tue Dec 20 13:42:18 2016 -0800
@@ -197,21 +197,4 @@
         cmd.addAll(Arrays.asList(args));
         return ProcessTools.executeCommand(cmd.toArray(new String[cmd.size()]));
     }
-
-    protected OutputAnalyzer keytool(String... cmd) throws Throwable {
-        return tool(KEYTOOL, cmd);
-    }
-
-    protected OutputAnalyzer jarsigner(String... cmd) throws Throwable {
-        return tool(JARSIGNER, cmd);
-    }
-
-    private OutputAnalyzer tool(String tool, String... args) throws Throwable {
-        List<String> cmd = new ArrayList<>();
-        cmd.add(tool);
-        cmd.add("-J-Duser.language=en");
-        cmd.add("-J-Duser.country=US");
-        cmd.addAll(Arrays.asList(args));
-        return ProcessTools.executeCommand(cmd.toArray(new String[cmd.size()]));
-    }
 }