changeset 4972:d6333a031b8d

7119760: [macosx] The OpenGL queue flusher thread is created in the wrong thread group Reviewed-by: prr
author dcherepanov
date Tue, 07 Feb 2012 12:19:17 +0300
parents 4a7a52c2b731
children 0d6cacf5e210
files src/share/classes/sun/java2d/opengl/OGLRenderQueue.java
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java	Mon Feb 06 19:06:04 2012 +0400
+++ b/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java	Tue Feb 07 12:19:17 2012 +0300
@@ -28,6 +28,8 @@
 import sun.java2d.pipe.RenderBuffer;
 import sun.java2d.pipe.RenderQueue;
 import static sun.java2d.pipe.BufferedOpCodes.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * OGL-specific implementation of RenderQueue.  This class provides a
@@ -41,7 +43,19 @@
     private final QueueFlusher flusher;
 
     private OGLRenderQueue() {
-        flusher = new QueueFlusher();
+        /*
+         * The thread must be a member of a thread group
+         * which will not get GCed before VM exit.
+         */
+        flusher = AccessController.doPrivileged(new PrivilegedAction<QueueFlusher>() {
+            public QueueFlusher run() {
+                ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
+                while (rootThreadGroup.getParent() != null) {
+                    rootThreadGroup = rootThreadGroup.getParent();
+                }
+                return new QueueFlusher(rootThreadGroup);
+            }
+        });
     }
 
     /**
@@ -149,8 +163,8 @@
         private Runnable task;
         private Error error;
 
-        public QueueFlusher() {
-            super("Java2D Queue Flusher");
+        public QueueFlusher(ThreadGroup threadGroup) {
+            super(threadGroup, "Java2D Queue Flusher");
             setDaemon(true);
             setPriority(Thread.MAX_PRIORITY);
             start();