8042332: Enhance thread contexts in security libraries
authorvaleriep
Fri, 03 Apr 2015 23:01:17 +0000
changeset 29923 e3ee0996bedb
parent 29922 7b9c1e1532cf
child 29924 d5d717f0a455
8042332: Enhance thread contexts in security libraries Summary: Modified to use ManagedLocalsThread wherever applicable. Reviewed-by: xuelei, skoivu
jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java
jdk/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java
jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java
--- a/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java	Fri Apr 03 17:17:36 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/provider/SeedGenerator.java	Fri Apr 03 23:01:17 2015 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -75,6 +75,7 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Random;
+import sun.misc.ManagedLocalsThread;
 import sun.security.util.Debug;
 
 abstract class SeedGenerator {
@@ -304,7 +305,7 @@
                             }
                             finalsg[0] = new ThreadGroup
                                 (group, "SeedGenerator ThreadGroup");
-                            Thread newT = new Thread(finalsg[0],
+                            Thread newT = new ManagedLocalsThread(finalsg[0],
                                 ThreadedSeedGenerator.this,
                                 "SeedGenerator Thread");
                             newT.setPriority(Thread.MIN_PRIORITY);
@@ -341,7 +342,7 @@
                         // Start some noisy threads
                         try {
                             BogusThread bt = new BogusThread();
-                            Thread t = new Thread
+                            Thread t = new ManagedLocalsThread
                                 (seedGroup, bt, "SeedGenerator Thread");
                             t.start();
                         } catch (Exception e) {
--- a/jdk/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java	Fri Apr 03 17:17:36 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java	Fri Apr 03 23:01:17 2015 +0000
@@ -39,6 +39,7 @@
 
 import javax.crypto.BadPaddingException;
 import javax.net.ssl.*;
+import sun.misc.ManagedLocalsThread;
 
 /**
  * Implementation of an SSL socket.  This is a normal connection type
@@ -1078,8 +1079,10 @@
                             HandshakeCompletedEvent event =
                                 new HandshakeCompletedEvent(this, sess);
 
-                            Thread t = new NotifyHandshakeThread(
-                                handshakeListeners.entrySet(), event);
+                            Thread t = new ManagedLocalsThread(
+                                new NotifyHandshake(
+                                    handshakeListeners.entrySet(), event),
+                                "HandshakeCompletedNotify-Thread");
                             t.start();
                         }
                     }
@@ -2575,17 +2578,16 @@
     // events.  This ensures that the notifications don't block the
     // protocol state machine.
     //
-    private static class NotifyHandshakeThread extends Thread {
+    private static class NotifyHandshake implements Runnable {
 
         private Set<Map.Entry<HandshakeCompletedListener,AccessControlContext>>
                 targets;        // who gets notified
         private HandshakeCompletedEvent event;          // the notification
 
-        NotifyHandshakeThread(
+        NotifyHandshake(
             Set<Map.Entry<HandshakeCompletedListener,AccessControlContext>>
             entrySet, HandshakeCompletedEvent e) {
 
-            super("HandshakeCompletedNotify-Thread");
             targets = new HashSet<>(entrySet);          // clone the entry set
             event = e;
         }
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java	Fri Apr 03 17:17:36 2015 +0300
+++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java	Fri Apr 03 23:01:17 2015 +0000
@@ -42,6 +42,7 @@
 import javax.security.auth.callback.PasswordCallback;
 import javax.security.auth.callback.TextOutputCallback;
 
+import sun.misc.ManagedLocalsThread;
 import sun.security.util.Debug;
 import sun.security.util.ResourcesMgr;
 
@@ -811,7 +812,7 @@
             return;
         }
         TokenPoller poller = new TokenPoller(this);
-        Thread t = new Thread(poller, "Poller " + getName());
+        Thread t = new ManagedLocalsThread(poller, "Poller " + getName());
         t.setDaemon(true);
         t.setPriority(Thread.MIN_PRIORITY);
         t.start();