changeset 13275:601407e6105a

8144630: Use PrivilegedAction to create Thread in Marlin RendererStats Reviewed-by: prr, flar
author lbourges
date Sat, 05 Dec 2015 09:48:43 -0800
parents 313b0c722ffe
children bd052ed8bf6f
files src/java.desktop/share/classes/sun/java2d/marlin/RendererStats.java
diffstat 1 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/sun/java2d/marlin/RendererStats.java	Fri Dec 04 13:52:21 2015 +0300
+++ b/src/java.desktop/share/classes/sun/java2d/marlin/RendererStats.java	Sat Dec 05 09:48:43 2015 -0800
@@ -25,6 +25,8 @@
 
 package sun.java2d.marlin;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentLinkedQueue;
@@ -32,6 +34,7 @@
 import sun.java2d.marlin.stats.Histogram;
 import sun.java2d.marlin.stats.Monitor;
 import sun.java2d.marlin.stats.StatLong;
+import sun.awt.util.ThreadGroupUtils;
 
 /**
  * This class gathers global rendering statistics for debugging purposes only
@@ -237,22 +240,33 @@
     private RendererStats() {
         super();
 
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            @Override
-            public void run() {
-                dump();
+        AccessController.doPrivileged(
+            (PrivilegedAction<Void>) () -> {
+                final Thread hook = new Thread(
+                    ThreadGroupUtils.getRootThreadGroup(),
+                    new Runnable() {
+                        @Override
+                        public void run() {
+                            dump();
+                        }
+                    },
+                    "MarlinStatsHook"
+                );
+                hook.setContextClassLoader(null);
+                Runtime.getRuntime().addShutdownHook(hook);
+
+                if (useDumpThread) {
+                    final Timer statTimer = new Timer("RendererStats");
+                    statTimer.scheduleAtFixedRate(new TimerTask() {
+                        @Override
+                        public void run() {
+                            dump();
+                        }
+                    }, statDump, statDump);
+                }
+                return null;
             }
-        });
-
-        if (useDumpThread) {
-            final Timer statTimer = new Timer("RendererStats");
-            statTimer.scheduleAtFixedRate(new TimerTask() {
-                @Override
-                public void run() {
-                    dump();
-                }
-            }, statDump, statDump);
-        }
+        );
     }
 
     void dump() {