8149653: Move sun.misc.InnocuousThread to jdk.internal.misc
authorchegar
Mon, 15 Feb 2016 10:13:21 +0000
changeset 35786 9d26db88aa14
parent 35785 d17d49d794e6
child 35787 39cff2356d03
8149653: Move sun.misc.InnocuousThread to jdk.internal.misc Reviewed-by: mchung, rriggs
jdk/src/java.base/share/classes/java/lang/ProcessHandleImpl.java
jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java
jdk/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java
jdk/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java
jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java
jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java
jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java
jdk/src/java.base/share/classes/sun/nio/ch/Invoker.java
jdk/src/java.base/share/classes/sun/nio/ch/ThreadPool.java
jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java
jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java
jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java
--- a/jdk/src/java.base/share/classes/java/lang/ProcessHandleImpl.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/ProcessHandleImpl.java	Mon Feb 15 10:13:21 2016 +0000
@@ -42,8 +42,6 @@
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
-import sun.misc.InnocuousThread;
-
 import static java.security.AccessController.doPrivileged;
 
 /**
--- a/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java	Mon Feb 15 10:13:21 2016 +0000
@@ -47,7 +47,7 @@
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import sun.misc.InnocuousThread;
+import jdk.internal.misc.InnocuousThread;
 import jdk.internal.misc.VM;
 import sun.util.logging.PlatformLogger;
 import jdk.internal.logger.LazyLoggers.LazyLoggerAccessor;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java	Mon Feb 15 10:13:21 2016 +0000
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.ProtectionDomain;
+import java.security.PrivilegedAction;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A thread that has no permissions, is not a member of any user-defined
+ * ThreadGroup and supports the ability to erase ThreadLocals.
+ */
+public final class InnocuousThread extends Thread {
+    private static final jdk.internal.misc.Unsafe UNSAFE;
+    private static final long THREAD_LOCALS;
+    private static final long INHERITABLE_THREAD_LOCALS;
+    private static final ThreadGroup INNOCUOUSTHREADGROUP;
+    private static final AccessControlContext ACC;
+    private static final long INHERITEDACCESSCONTROLCONTEXT;
+    private static final long CONTEXTCLASSLOADER;
+
+    private static final AtomicInteger threadNumber = new AtomicInteger(1);
+
+    public InnocuousThread(Runnable target) {
+        this(INNOCUOUSTHREADGROUP, target,
+             "InnocuousThread-" + threadNumber.getAndIncrement());
+    }
+
+    public InnocuousThread(Runnable target, String name) {
+        this(INNOCUOUSTHREADGROUP, target, name);
+    }
+
+    public InnocuousThread(ThreadGroup group, Runnable target, String name) {
+        super(group, target, name, 0L, false);
+        UNSAFE.putOrderedObject(this, INHERITEDACCESSCONTROLCONTEXT, ACC);
+        UNSAFE.putOrderedObject(this, CONTEXTCLASSLOADER, ClassLoader.getSystemClassLoader());
+    }
+
+    @Override
+    public void setUncaughtExceptionHandler(UncaughtExceptionHandler x) {
+        // silently fail
+    }
+
+    @Override
+    public void setContextClassLoader(ClassLoader cl) {
+        // Allow clearing of the TCCL to remove the reference to the system classloader.
+        if (cl == null)
+            super.setContextClassLoader(null);
+        else
+            throw new SecurityException("setContextClassLoader");
+    }
+
+    /**
+     * Drops all thread locals (and inherited thread locals).
+     */
+    public final void eraseThreadLocals() {
+        UNSAFE.putObject(this, THREAD_LOCALS, null);
+        UNSAFE.putObject(this, INHERITABLE_THREAD_LOCALS, null);
+    }
+
+    // ensure run method is run only once
+    private volatile boolean hasRun;
+
+    @Override
+    public void run() {
+        if (Thread.currentThread() == this && !hasRun) {
+            hasRun = true;
+            super.run();
+        }
+    }
+
+    // Use Unsafe to access Thread group and ThreadGroup parent fields
+    static {
+        try {
+            ACC = new AccessControlContext(new ProtectionDomain[] {
+                new ProtectionDomain(null, null)
+            });
+
+            // Find and use topmost ThreadGroup as parent of new group
+            UNSAFE = jdk.internal.misc.Unsafe.getUnsafe();
+            Class<?> tk = Thread.class;
+            Class<?> gk = ThreadGroup.class;
+
+            THREAD_LOCALS = UNSAFE.objectFieldOffset
+                    (tk.getDeclaredField("threadLocals"));
+            INHERITABLE_THREAD_LOCALS = UNSAFE.objectFieldOffset
+                    (tk.getDeclaredField("inheritableThreadLocals"));
+            INHERITEDACCESSCONTROLCONTEXT = UNSAFE.objectFieldOffset
+                (tk.getDeclaredField("inheritedAccessControlContext"));
+            CONTEXTCLASSLOADER = UNSAFE.objectFieldOffset
+                (tk.getDeclaredField("contextClassLoader"));
+
+            long tg = UNSAFE.objectFieldOffset(tk.getDeclaredField("group"));
+            long gp = UNSAFE.objectFieldOffset(gk.getDeclaredField("parent"));
+            ThreadGroup group = (ThreadGroup)
+                UNSAFE.getObject(Thread.currentThread(), tg);
+
+            while (group != null) {
+                ThreadGroup parent = (ThreadGroup)UNSAFE.getObject(group, gp);
+                if (parent == null)
+                    break;
+                group = parent;
+            }
+            final ThreadGroup root = group;
+            INNOCUOUSTHREADGROUP = AccessController.doPrivileged(
+                (PrivilegedAction<ThreadGroup>) () ->
+                    { return new ThreadGroup(root, "InnocuousThreadGroup"); });
+        } catch (Exception e) {
+            throw new Error(e);
+        }
+    }
+}
--- a/jdk/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java	Mon Feb 15 10:13:21 2016 +0000
@@ -33,7 +33,7 @@
 import java.util.concurrent.ThreadFactory;
 import java.util.function.Function;
 
-import sun.misc.InnocuousThread;
+import jdk.internal.misc.InnocuousThread;
 
 /**
  * CleanerImpl manages a set of object references and corresponding cleaning actions.
--- a/jdk/src/java.base/share/classes/sun/misc/InnocuousThread.java	Sun Feb 14 14:30:48 2016 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.ProtectionDomain;
-import java.security.PrivilegedAction;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * A thread that has no permissions, is not a member of any user-defined
- * ThreadGroup and supports the ability to erase ThreadLocals.
- */
-public final class InnocuousThread extends Thread {
-    private static final jdk.internal.misc.Unsafe UNSAFE;
-    private static final long THREAD_LOCALS;
-    private static final long INHERITABLE_THREAD_LOCALS;
-    private static final ThreadGroup INNOCUOUSTHREADGROUP;
-    private static final AccessControlContext ACC;
-    private static final long INHERITEDACCESSCONTROLCONTEXT;
-    private static final long CONTEXTCLASSLOADER;
-
-    private static final AtomicInteger threadNumber = new AtomicInteger(1);
-
-    public InnocuousThread(Runnable target) {
-        this(INNOCUOUSTHREADGROUP, target,
-             "InnocuousThread-" + threadNumber.getAndIncrement());
-    }
-
-    public InnocuousThread(Runnable target, String name) {
-        this(INNOCUOUSTHREADGROUP, target, name);
-    }
-
-    public InnocuousThread(ThreadGroup group, Runnable target, String name) {
-        super(group, target, name, 0L, false);
-        UNSAFE.putOrderedObject(this, INHERITEDACCESSCONTROLCONTEXT, ACC);
-        UNSAFE.putOrderedObject(this, CONTEXTCLASSLOADER, ClassLoader.getSystemClassLoader());
-    }
-
-    @Override
-    public void setUncaughtExceptionHandler(UncaughtExceptionHandler x) {
-        // silently fail
-    }
-
-    @Override
-    public void setContextClassLoader(ClassLoader cl) {
-        // Allow clearing of the TCCL to remove the reference to the system classloader.
-        if (cl == null)
-            super.setContextClassLoader(null);
-        else
-            throw new SecurityException("setContextClassLoader");
-    }
-
-    /**
-     * Drops all thread locals (and inherited thread locals).
-     */
-    public final void eraseThreadLocals() {
-        UNSAFE.putObject(this, THREAD_LOCALS, null);
-        UNSAFE.putObject(this, INHERITABLE_THREAD_LOCALS, null);
-    }
-
-    // ensure run method is run only once
-    private volatile boolean hasRun;
-
-    @Override
-    public void run() {
-        if (Thread.currentThread() == this && !hasRun) {
-            hasRun = true;
-            super.run();
-        }
-    }
-
-    // Use Unsafe to access Thread group and ThreadGroup parent fields
-    static {
-        try {
-            ACC = new AccessControlContext(new ProtectionDomain[] {
-                new ProtectionDomain(null, null)
-            });
-
-            // Find and use topmost ThreadGroup as parent of new group
-            UNSAFE = jdk.internal.misc.Unsafe.getUnsafe();
-            Class<?> tk = Thread.class;
-            Class<?> gk = ThreadGroup.class;
-
-            THREAD_LOCALS = UNSAFE.objectFieldOffset
-                    (tk.getDeclaredField("threadLocals"));
-            INHERITABLE_THREAD_LOCALS = UNSAFE.objectFieldOffset
-                    (tk.getDeclaredField("inheritableThreadLocals"));
-            INHERITEDACCESSCONTROLCONTEXT = UNSAFE.objectFieldOffset
-                (tk.getDeclaredField("inheritedAccessControlContext"));
-            CONTEXTCLASSLOADER = UNSAFE.objectFieldOffset
-                (tk.getDeclaredField("contextClassLoader"));
-
-            long tg = UNSAFE.objectFieldOffset(tk.getDeclaredField("group"));
-            long gp = UNSAFE.objectFieldOffset(gk.getDeclaredField("parent"));
-            ThreadGroup group = (ThreadGroup)
-                UNSAFE.getObject(Thread.currentThread(), tg);
-
-            while (group != null) {
-                ThreadGroup parent = (ThreadGroup)UNSAFE.getObject(group, gp);
-                if (parent == null)
-                    break;
-                group = parent;
-            }
-            final ThreadGroup root = group;
-            INNOCUOUSTHREADGROUP = AccessController.doPrivileged(
-                (PrivilegedAction<ThreadGroup>) () ->
-                    { return new ThreadGroup(root, "InnocuousThreadGroup"); });
-        } catch (Exception e) {
-            throw new Error(e);
-        }
-    }
-}
--- a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java	Mon Feb 15 10:13:21 2016 +0000
@@ -30,7 +30,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.net.URL;
-import sun.misc.InnocuousThread;
+import jdk.internal.misc.InnocuousThread;
 
 /**
  * A class that implements a cache of idle Http connections for keep-alive
--- a/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java	Mon Feb 15 10:13:21 2016 +0000
@@ -27,9 +27,9 @@
 
 import java.io.*;
 
-import sun.misc.InnocuousThread;
 import sun.net.ProgressSource;
 import sun.net.www.MeteredStream;
+import jdk.internal.misc.InnocuousThread;
 
 /**
  * A stream that has the property of being able to be kept alive for
--- a/jdk/src/java.base/share/classes/sun/nio/ch/Invoker.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/Invoker.java	Mon Feb 15 10:13:21 2016 +0000
@@ -29,6 +29,7 @@
 import java.util.concurrent.*;
 import java.security.AccessController;
 import sun.security.action.GetIntegerAction;
+import jdk.internal.misc.InnocuousThread;
 
 /**
  * Defines static methods to invoke a completion handler or arbitrary task.
@@ -134,9 +135,9 @@
         // clear thread locals when in default thread pool
         if (System.getSecurityManager() != null) {
             Thread me = Thread.currentThread();
-            if (me instanceof sun.misc.InnocuousThread) {
+            if (me instanceof InnocuousThread) {
                 GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get();
-                ((sun.misc.InnocuousThread)me).eraseThreadLocals();
+                ((InnocuousThread)me).eraseThreadLocals();
                 if (thisGroupAndInvokeCount != null) {
                     myGroupAndInvokeCount.set(thisGroupAndInvokeCount);
                 }
--- a/jdk/src/java.base/share/classes/sun/nio/ch/ThreadPool.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/ThreadPool.java	Mon Feb 15 10:13:21 2016 +0000
@@ -30,6 +30,7 @@
 import java.security.PrivilegedAction;
 import sun.security.action.GetPropertyAction;
 import sun.security.action.GetIntegerAction;
+import jdk.internal.misc.InnocuousThread;
 
 /**
  * Encapsulates a thread pool associated with a channel group.
@@ -81,7 +82,7 @@
         } else {
             return (Runnable r) -> {
                 PrivilegedAction<Thread> action = () -> {
-                    Thread t = new sun.misc.InnocuousThread(r);
+                    Thread t = new InnocuousThread(r);
                     t.setDaemon(true);
                     return t;
                };
--- a/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/sun/awt/im/InputMethodManager.java	Mon Feb 15 10:13:21 2016 +0000
@@ -55,7 +55,6 @@
 import java.util.prefs.Preferences;
 import sun.awt.InputMethodSupport;
 import sun.awt.SunToolkit;
-import sun.misc.InnocuousThread;
 import sun.misc.ManagedLocalsThread;
 
 /**
--- a/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/sun/font/SunFontManager.java	Mon Feb 15 10:13:21 2016 +0000
@@ -54,7 +54,6 @@
 import sun.awt.SunToolkit;
 import sun.awt.util.ThreadGroupUtils;
 import sun.java2d.FontSupport;
-import sun.misc.InnocuousThread;
 import sun.misc.ManagedLocalsThread;
 import sun.util.logging.PlatformLogger;
 
--- a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java	Sun Feb 14 14:30:48 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java	Mon Feb 15 10:13:21 2016 +0000
@@ -28,7 +28,6 @@
 import sun.awt.util.ThreadGroupUtils;
 import sun.java2d.pipe.RenderBuffer;
 import sun.java2d.pipe.RenderQueue;
-import sun.misc.InnocuousThread;
 import sun.misc.ManagedLocalsThread;
 
 import static sun.java2d.pipe.BufferedOpCodes.*;