8047149: Enhance thread contexts in core libraries
authorchegar
Thu, 02 Apr 2015 11:43:11 +0100
changeset 29919 be906afc335b
parent 29918 3ac7231c0f1a
child 29920 f81c14f472ab
8047149: Enhance thread contexts in core libraries Reviewed-by: alanb
jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java
jdk/src/java.base/share/classes/java/lang/ref/Reference.java
jdk/src/java.base/share/classes/sun/misc/GC.java
jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java
jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java
jdk/src/java.base/share/classes/sun/misc/Signal.java
jdk/src/java.logging/share/classes/java/util/logging/LogManager.java
jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java
jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java
jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
--- a/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java	Thu Apr 02 11:43:11 2015 +0100
@@ -28,6 +28,7 @@
 import java.security.PrivilegedAction;
 import java.security.AccessController;
 import sun.misc.JavaLangAccess;
+import sun.misc.ManagedLocalsThread;
 import sun.misc.SharedSecrets;
 import sun.misc.VM;
 
@@ -126,7 +127,7 @@
                     for (ThreadGroup tgn = tg;
                          tgn != null;
                          tg = tgn, tgn = tg.getParent());
-                    Thread sft = new Thread(tg, proc, "Secondary finalizer");
+                    Thread sft = new ManagedLocalsThread(tg, proc, "Secondary finalizer");
                     sft.start();
                     try {
                         sft.join();
@@ -185,7 +186,7 @@
                 }}});
     }
 
-    private static class FinalizerThread extends Thread {
+    private static class FinalizerThread extends ManagedLocalsThread {
         private volatile boolean running;
         FinalizerThread(ThreadGroup g) {
             super(g, "Finalizer");
--- a/jdk/src/java.base/share/classes/java/lang/ref/Reference.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/java/lang/ref/Reference.java	Thu Apr 02 11:43:11 2015 +0100
@@ -27,6 +27,7 @@
 
 import sun.misc.Cleaner;
 import sun.misc.JavaLangRefAccess;
+import sun.misc.ManagedLocalsThread;
 import sun.misc.SharedSecrets;
 
 /**
@@ -126,7 +127,7 @@
 
     /* High-priority thread to enqueue pending References
      */
-    private static class ReferenceHandler extends Thread {
+    private static class ReferenceHandler extends ManagedLocalsThread {
 
         private static void ensureClassInitialized(Class<?> clazz) {
             try {
--- a/jdk/src/java.base/share/classes/sun/misc/GC.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/misc/GC.java	Thu Apr 02 11:43:11 2015 +0100
@@ -82,8 +82,7 @@
      */
     public static native long maxObjectInspectionAge();
 
-
-    private static class Daemon extends Thread {
+    private static class Daemon extends ManagedLocalsThread {
 
         public void run() {
             for (;;) {
--- a/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/misc/ManagedLocalsThread.java	Thu Apr 02 11:43:11 2015 +0100
@@ -34,6 +34,10 @@
     private static final long THREAD_LOCALS;
     private static final long INHERITABLE_THREAD_LOCALS;
 
+    public ManagedLocalsThread() {
+        eraseThreadLocals();
+    }
+
     public ManagedLocalsThread(Runnable target) {
         super(target);
         eraseThreadLocals();
@@ -44,6 +48,11 @@
         eraseThreadLocals();
     }
 
+    public ManagedLocalsThread(ThreadGroup group, String name) {
+        super(group, name);
+        eraseThreadLocals();
+    }
+
     public ManagedLocalsThread(ThreadGroup group, Runnable target, String name) {
         super(group, target, name);
         eraseThreadLocals();
--- a/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/misc/RequestProcessor.java	Thu Apr 02 11:43:11 2015 +0100
@@ -77,7 +77,7 @@
      */
     public static synchronized void startProcessing() {
         if (dispatcher == null) {
-            dispatcher = new Thread(new RequestProcessor(), "Request Processor");
+            dispatcher = new ManagedLocalsThread(new RequestProcessor(), "Request Processor");
             dispatcher.setPriority(Thread.NORM_PRIORITY + 2);
             dispatcher.start();
         }
--- a/jdk/src/java.base/share/classes/sun/misc/Signal.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/misc/Signal.java	Thu Apr 02 11:43:11 2015 +0100
@@ -213,7 +213,7 @@
             }
         };
         if (handler != null) {
-            new Thread(runnable, sig + " handler").start();
+            new ManagedLocalsThread(runnable, sig + " handler").start();
         }
     }
 
--- a/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java	Thu Apr 02 11:43:11 2015 +0100
@@ -34,6 +34,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import sun.misc.JavaAWTAccess;
+import sun.misc.ManagedLocalsThread;
 import sun.misc.SharedSecrets;
 
 /**
@@ -248,7 +249,7 @@
 
     // This private class is used as a shutdown hook.
     // It does a "reset" to close all open handlers.
-    private class Cleaner extends Thread {
+    private class Cleaner extends ManagedLocalsThread {
 
         private Cleaner() {
             /* Set context class loader to null in order to avoid
--- a/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java	Thu Apr 02 11:43:11 2015 +0100
@@ -31,6 +31,7 @@
 import java.util.Timer;
 import java.util.TimerTask;
 import java.lang.ref.WeakReference;
+import sun.misc.ManagedLocalsThread;
 
 
 /*
@@ -343,7 +344,7 @@
     {
         if (timer == null) {
             timer = new Timer(true); // daemon
-            Thread flushThread = new Thread() {
+            Thread flushThread = new ManagedLocalsThread() {
                 @Override
                 public void run() {
                     flushWorld();
--- a/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java	Thu Apr 02 11:43:11 2015 +0100
@@ -29,6 +29,7 @@
 import java.io.*;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import sun.misc.ManagedLocalsThread;
 // These imports needed only as a workaround for a JavaDoc bug
 import java.lang.Integer;
 import java.lang.Long;
@@ -1470,7 +1471,7 @@
      * A single background thread ("the event notification thread") monitors
      * the event queue and delivers events that are placed on the queue.
      */
-    private static class EventDispatchThread extends Thread {
+    private static class EventDispatchThread extends ManagedLocalsThread {
         public void run() {
             while(true) {
                 // Wait on eventQueue till an event is present
--- a/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java	Mon Mar 16 23:59:02 2015 +0300
+++ b/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java	Thu Apr 02 11:43:11 2015 +0100
@@ -30,7 +30,7 @@
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
-
+import sun.misc.ManagedLocalsThread;
 import sun.util.logging.PlatformLogger;
 
 /**
@@ -450,7 +450,7 @@
         // Add shutdown hook to flush cached prefs on normal termination
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
             public Void run() {
-                Runtime.getRuntime().addShutdownHook(new Thread() {
+                Runtime.getRuntime().addShutdownHook(new ManagedLocalsThread() {
                     public void run() {
                         syncTimer.cancel();
                         syncWorld();