提交 b746c767 编写于 作者: P pchelko

8031477: [macosx] Loading AWT native library fails

8002191: AWT-Shutdown thread does not start with the AppletSecurity on Linux
8031032: SQE test failures after JDK-8025010 was fixed
Reviewed-by: serb, ddehaven
上级 ab5b700d
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,8 @@ package sun.font; ...@@ -27,6 +27,8 @@ package sun.font;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -38,6 +40,7 @@ import javax.swing.plaf.FontUIResource; ...@@ -38,6 +40,7 @@ import javax.swing.plaf.FontUIResource;
import sun.awt.FontConfiguration; import sun.awt.FontConfiguration;
import sun.awt.HeadlessToolkit; import sun.awt.HeadlessToolkit;
import sun.misc.ThreadGroupUtils;
import sun.lwawt.macosx.*; import sun.lwawt.macosx.*;
public class CFontManager extends SunFontManager { public class CFontManager extends SunFontManager {
...@@ -215,24 +218,19 @@ public class CFontManager extends SunFontManager { ...@@ -215,24 +218,19 @@ public class CFontManager extends SunFontManager {
}); });
} }
}; };
java.security.AccessController.doPrivileged( AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() { (PrivilegedAction<Void>) () -> {
public Object run() { /* The thread must be a member of a thread group
/* The thread must be a member of a thread group * which will not get GCed before VM exit.
* which will not get GCed before VM exit. * Make its parent the top-level thread group.
* Make its parent the top-level thread group. */
*/ ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup tg = fileCloser = new Thread(rootTG, fileCloserRunnable);
Thread.currentThread().getThreadGroup(); fileCloser.setContextClassLoader(null);
for (ThreadGroup tgn = tg; Runtime.getRuntime().addShutdownHook(fileCloser);
tgn != null; return null;
tg = tgn, tgn = tg.getParent()); }
fileCloser = new Thread(tg, fileCloserRunnable); );
fileCloser.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(fileCloser);
return null;
}
});
} }
} }
} }
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -39,6 +39,7 @@ import sun.awt.*; ...@@ -39,6 +39,7 @@ import sun.awt.*;
import sun.lwawt.macosx.*; import sun.lwawt.macosx.*;
import sun.print.*; import sun.print.*;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
import sun.misc.ThreadGroupUtils;
public abstract class LWToolkit extends SunToolkit implements Runnable { public abstract class LWToolkit extends SunToolkit implements Runnable {
...@@ -72,30 +73,17 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { ...@@ -72,30 +73,17 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
protected final void init() { protected final void init() {
AWTAutoShutdown.notifyToolkitThreadBusy(); AWTAutoShutdown.notifyToolkitThreadBusy();
ThreadGroup mainTG = AccessController.doPrivileged( ThreadGroup rootTG = AccessController.doPrivileged(
new PrivilegedAction<ThreadGroup>() { (PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
public ThreadGroup run() {
ThreadGroup currentTG = Thread.currentThread().getThreadGroup();
ThreadGroup parentTG = currentTG.getParent();
while (parentTG != null) {
currentTG = parentTG;
parentTG = currentTG.getParent();
}
return currentTG;
}
}
);
Runtime.getRuntime().addShutdownHook( Runtime.getRuntime().addShutdownHook(
new Thread(mainTG, new Runnable() { new Thread(rootTG, () -> {
public void run() { shutdown();
shutdown(); waitForRunState(STATE_CLEANUP);
waitForRunState(STATE_CLEANUP);
}
}) })
); );
Thread toolkitThread = new Thread(mainTG, this, "AWT-LW"); Thread toolkitThread = new Thread(rootTG, this, "AWT-LW");
toolkitThread.setDaemon(true); toolkitThread.setDaemon(true);
toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
toolkitThread.start(); toolkitThread.start();
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -433,12 +433,11 @@ JNF_COCOA_ENTER(env); ...@@ -433,12 +433,11 @@ JNF_COCOA_ENTER(env);
if (isSWTInWebStart(env)) { if (isSWTInWebStart(env)) {
forceEmbeddedMode = YES; forceEmbeddedMode = YES;
} }
JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; JNIEnv* env = [ThreadUtilities getJNIEnvUncached];
jclass jc_SunToolkit = (*env)->FindClass(env, "sun/awt/SunToolkit"); jclass jc_ThreadGroupUtils = (*env)->FindClass(env, "sun/misc/ThreadGroupUtils");
jmethodID sjm_getRootThreadGroup = (*env)->GetStaticMethodID(env, jc_SunToolkit, "getRootThreadGroup", "()Ljava/lang/ThreadGroup;"); jmethodID sjm_getRootThreadGroup = (*env)->GetStaticMethodID(env, jc_ThreadGroupUtils, "getRootThreadGroup", "()Ljava/lang/ThreadGroup;");
jobject rootThreadGroup = (*env)->CallStaticObjectMethod(env, jc_SunToolkit, sjm_getRootThreadGroup); jobject rootThreadGroup = (*env)->CallStaticObjectMethod(env, jc_ThreadGroupUtils, sjm_getRootThreadGroup);
appkitThreadGroup = (*env)->NewGlobalRef(env, rootThreadGroup); [ThreadUtilities setAppkitThreadGroup:(*env)->NewGlobalRef(env, rootThreadGroup)];
// The current thread was attached in getJNIEnvUnchached. // The current thread was attached in getJNIEnvUnchached.
// Detach it back. It will be reattached later if needed with a proper TG // Detach it back. It will be reattached later if needed with a proper TG
[ThreadUtilities detachCurrentThread]; [ThreadUtilities detachCurrentThread];
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -122,15 +122,13 @@ do { \ ...@@ -122,15 +122,13 @@ do { \
#endif /* AWT_THREAD_ASSERTS */ #endif /* AWT_THREAD_ASSERTS */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Set from JNI_Onload
extern jobject appkitThreadGroup;
__attribute__((visibility("default"))) __attribute__((visibility("default")))
@interface ThreadUtilities { } @interface ThreadUtilities { }
+ (JNIEnv*)getJNIEnv; + (JNIEnv*)getJNIEnv;
+ (JNIEnv*)getJNIEnvUncached; + (JNIEnv*)getJNIEnvUncached;
+ (void)detachCurrentThread; + (void)detachCurrentThread;
+ (void)setAppkitThreadGroup:(jobject)group;
//Wrappers for the corresponding JNFRunLoop methods with a check for main thread //Wrappers for the corresponding JNFRunLoop methods with a check for main thread
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block;
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,18 +33,18 @@ ...@@ -33,18 +33,18 @@
// The following must be named "jvm", as there are extern references to it in AWT // The following must be named "jvm", as there are extern references to it in AWT
JavaVM *jvm = NULL; JavaVM *jvm = NULL;
static JNIEnv *appKitEnv = NULL; static JNIEnv *appKitEnv = NULL;
jobject appkitThreadGroup = NULL; static jobject appkitThreadGroup = NULL;
inline void attachCurrentThread(void** env) { inline void attachCurrentThread(void** env) {
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_2;
args.name = NULL; // Set from LWCToolkit
if ([NSThread isMainThread]) { if ([NSThread isMainThread]) {
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_4;
args.name = "AppKit Thread";
args.group = appkitThreadGroup; args.group = appkitThreadGroup;
(*jvm)->AttachCurrentThreadAsDaemon(jvm, env, &args);
} else { } else {
args.group = NULL; (*jvm)->AttachCurrentThreadAsDaemon(jvm, env, NULL);
} }
(*jvm)->AttachCurrentThreadAsDaemon(jvm, env, &args);
} }
@implementation ThreadUtilities @implementation ThreadUtilities
...@@ -67,6 +67,10 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -67,6 +67,10 @@ AWT_ASSERT_APPKIT_THREAD;
(*jvm)->DetachCurrentThread(jvm); (*jvm)->DetachCurrentThread(jvm);
} }
+ (void)setAppkitThreadGroup:(jobject)group {
appkitThreadGroup = group;
}
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block { + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block {
if ([NSThread isMainThread] && wait == YES) { if ([NSThread isMainThread] && wait == YES) {
block(); block();
......
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1062,11 +1062,11 @@ public class EventQueue { ...@@ -1062,11 +1062,11 @@ public class EventQueue {
t.setContextClassLoader(classLoader); t.setContextClassLoader(classLoader);
t.setPriority(Thread.NORM_PRIORITY + 1); t.setPriority(Thread.NORM_PRIORITY + 1);
t.setDaemon(false); t.setDaemon(false);
AWTAutoShutdown.getInstance().notifyThreadBusy(t);
return t; return t;
} }
} }
); );
AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
dispatchThread.start(); dispatchThread.start();
} }
} finally { } finally {
......
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,13 +29,13 @@ import java.awt.AWTEvent; ...@@ -29,13 +29,13 @@ import java.awt.AWTEvent;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import sun.misc.ThreadGroupUtils;
/** /**
* This class is to let AWT shutdown automatically when a user is done * This class is to let AWT shutdown automatically when a user is done
...@@ -217,7 +217,10 @@ public final class AWTAutoShutdown implements Runnable { ...@@ -217,7 +217,10 @@ public final class AWTAutoShutdown implements Runnable {
synchronized (activationLock) { synchronized (activationLock) {
synchronized (mainLock) { synchronized (mainLock) {
if (!isReadyToShutdown() && blockerThread == null) { if (!isReadyToShutdown() && blockerThread == null) {
activateBlockerThread(); AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
activateBlockerThread();
return null;
});
} else { } else {
mainLock.notifyAll(); mainLock.notifyAll();
timeoutPassed = false; timeoutPassed = false;
...@@ -333,13 +336,12 @@ public final class AWTAutoShutdown implements Runnable { ...@@ -333,13 +336,12 @@ public final class AWTAutoShutdown implements Runnable {
/** /**
* Creates and starts a new blocker thread. Doesn't return until * Creates and starts a new blocker thread. Doesn't return until
* the new blocker thread starts. * the new blocker thread starts.
*
* Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
*/ */
private void activateBlockerThread() { private void activateBlockerThread() {
Thread thread = new Thread(SunToolkit.getRootThreadGroup(), this, "AWT-Shutdown"); Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown");
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { thread.setContextClassLoader(null);
thread.setContextClassLoader(null);
return null;
});
thread.setDaemon(false); thread.setDaemon(false);
blockerThread = thread; blockerThread = thread;
thread.start(); thread.start();
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1116,17 +1116,6 @@ public abstract class SunToolkit extends Toolkit ...@@ -1116,17 +1116,6 @@ public abstract class SunToolkit extends Toolkit
return startupLocale; return startupLocale;
} }
protected static ThreadGroup getRootThreadGroup() {
return AccessController.doPrivileged((PrivilegedAction<ThreadGroup>) () -> {
ThreadGroup currentTG = Thread.currentThread().getThreadGroup();
ThreadGroup parentTG = currentTG.getParent();
while (parentTG != null) {
currentTG = parentTG;
parentTG = currentTG.getParent();
}
return currentTG;
});
}
/** /**
* Returns the default keyboard locale of the underlying operating system * Returns the default keyboard locale of the underlying operating system
*/ */
......
/* /*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,12 +27,15 @@ package sun.font; ...@@ -27,12 +27,15 @@ package sun.font;
import java.io.File; import java.io.File;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.misc.ThreadGroupUtils;
public class CreatedFontTracker { public class CreatedFontTracker {
...@@ -112,28 +115,18 @@ public class CreatedFontTracker { ...@@ -112,28 +115,18 @@ public class CreatedFontTracker {
static void init() { static void init() {
if (t == null) { if (t == null) {
// Add a shutdown hook to remove the temp file. // Add a shutdown hook to remove the temp file.
java.security.AccessController.doPrivileged( AccessController.doPrivileged(
new java.security.PrivilegedAction() { (PrivilegedAction<Void>) () -> {
public Object run() { /* The thread must be a member of a thread group
/* The thread must be a member of a thread group * which will not get GCed before VM exit.
* which will not get GCed before VM exit. * Make its parent the top-level thread group.
* Make its parent the top-level thread group. */
*/ ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup tg = t = new Thread(rootTG, TempFileDeletionHook::runHooks);
Thread.currentThread().getThreadGroup(); t.setContextClassLoader(null);
for (ThreadGroup tgn = tg; Runtime.getRuntime().addShutdownHook(t);
tgn != null; return null;
tg = tgn, tgn = tg.getParent()); });
t = new Thread(tg, new Runnable() {
public void run() {
runHooks();
}
});
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
return null;
}
});
} }
} }
......
/* /*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -52,6 +52,7 @@ import javax.swing.plaf.FontUIResource; ...@@ -52,6 +52,7 @@ import javax.swing.plaf.FontUIResource;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.FontConfiguration; import sun.awt.FontConfiguration;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.misc.ThreadGroupUtils;
import sun.java2d.FontSupport; import sun.java2d.FontSupport;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
...@@ -2521,24 +2522,18 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE { ...@@ -2521,24 +2522,18 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}); });
} }
}; };
java.security.AccessController.doPrivileged( AccessController.doPrivileged(
new java.security.PrivilegedAction() { (PrivilegedAction<Void>) () -> {
public Object run() { /* The thread must be a member of a thread group
/* The thread must be a member of a thread group * which will not get GCed before VM exit.
* which will not get GCed before VM exit. * Make its parent the top-level thread group.
* Make its parent the top-level thread group. */
*/ ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup tg = fileCloser = new Thread(rootTG, fileCloserRunnable);
Thread.currentThread().getThreadGroup(); fileCloser.setContextClassLoader(null);
for (ThreadGroup tgn = tg; Runtime.getRuntime().addShutdownHook(fileCloser);
tgn != null; return null;
tg = tgn, tgn = tg.getParent()); });
fileCloser = new Thread(tg, fileCloserRunnable);
fileCloser.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(fileCloser);
return null;
}
});
} }
} }
} }
......
/* /*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,10 +25,14 @@ ...@@ -25,10 +25,14 @@
package sun.java2d; package sun.java2d;
import sun.misc.ThreadGroupUtils;
import java.lang.ref.Reference; import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.ref.PhantomReference; import java.lang.ref.PhantomReference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -76,26 +80,20 @@ public class Disposer implements Runnable { ...@@ -76,26 +80,20 @@ public class Disposer implements Runnable {
} }
} }
disposerInstance = new Disposer(); disposerInstance = new Disposer();
java.security.AccessController.doPrivileged( AccessController.doPrivileged(
new java.security.PrivilegedAction() { (PrivilegedAction<Void>) () -> {
public Object run() {
/* The thread must be a member of a thread group /* The thread must be a member of a thread group
* which will not get GCed before VM exit. * which will not get GCed before VM exit.
* Make its parent the top-level thread group. * Make its parent the top-level thread group.
*/ */
ThreadGroup tg = Thread.currentThread().getThreadGroup(); ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
for (ThreadGroup tgn = tg; Thread t = new Thread(rootTG, disposerInstance, "Java2D Disposer");
tgn != null;
tg = tgn, tgn = tg.getParent());
Thread t =
new Thread(tg, disposerInstance, "Java2D Disposer");
t.setContextClassLoader(null); t.setContextClassLoader(null);
t.setDaemon(true); t.setDaemon(true);
t.setPriority(Thread.MAX_PRIORITY); t.setPriority(Thread.MAX_PRIORITY);
t.start(); t.start();
return null; return null;
} }
}
); );
} }
......
/* /*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package sun.java2d.opengl; package sun.java2d.opengl;
import sun.misc.ThreadGroupUtils;
import sun.java2d.pipe.RenderBuffer; import sun.java2d.pipe.RenderBuffer;
import sun.java2d.pipe.RenderQueue; import sun.java2d.pipe.RenderQueue;
import static sun.java2d.pipe.BufferedOpCodes.*; import static sun.java2d.pipe.BufferedOpCodes.*;
...@@ -47,14 +48,8 @@ public class OGLRenderQueue extends RenderQueue { ...@@ -47,14 +48,8 @@ public class OGLRenderQueue extends RenderQueue {
* The thread must be a member of a thread group * The thread must be a member of a thread group
* which will not get GCed before VM exit. * which will not get GCed before VM exit.
*/ */
flusher = AccessController.doPrivileged(new PrivilegedAction<QueueFlusher>() { flusher = AccessController.doPrivileged((PrivilegedAction<QueueFlusher>) () -> {
public QueueFlusher run() { return new QueueFlusher(ThreadGroupUtils.getRootThreadGroup());
ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
while (rootThreadGroup.getParent() != null) {
rootThreadGroup = rootThreadGroup.getParent();
}
return new QueueFlusher(rootThreadGroup);
}
}); });
} }
......
/*
* Copyright (c) 2014, 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;
/**
* A utility class needed to access the root {@code ThreadGroup}
*
* The class should not depend on any others, because it' called from JNI_OnLoad of the AWT
* native library. Triggering class loading could could lead to a deadlock.
*/
public final class ThreadGroupUtils {
private ThreadGroupUtils() {
// Avoid instantiation
}
/**
* Returns a root thread group.
* Should be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION}
*
* @return a root {@code ThreadGroup}
*/
public static ThreadGroup getRootThreadGroup() {
ThreadGroup currentTG = Thread.currentThread().getThreadGroup();
ThreadGroup parentTG = currentTG.getParent();
while (parentTG != null) {
currentTG = parentTG;
parentTG = currentTG.getParent();
}
return currentTG;
}
}
/* /*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,7 +49,7 @@ import javax.swing.UIDefaults; ...@@ -49,7 +49,7 @@ import javax.swing.UIDefaults;
import sun.awt.*; import sun.awt.*;
import sun.font.FontConfigManager; import sun.font.FontConfigManager;
import sun.java2d.SunGraphicsEnvironment; import sun.java2d.SunGraphicsEnvironment;
import sun.misc.PerformanceLogger; import sun.misc.*;
import sun.print.PrintJob2D; import sun.print.PrintJob2D;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
import sun.security.action.GetBooleanAction; import sun.security.action.GetBooleanAction;
...@@ -254,27 +254,25 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -254,27 +254,25 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} finally { } finally {
awtUnlock(); awtUnlock();
} }
PrivilegedAction<Void> a = new PrivilegedAction<Void>() { PrivilegedAction<Void> a = () -> {
public Void run() { Thread shutdownThread = new Thread(sun.misc.ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") {
Thread shutdownThread = new Thread(getRootThreadGroup(), "XToolkt-Shutdown-Thread") { public void run() {
public void run() { XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance(); if (peer != null) {
if (peer != null) { peer.dispose();
peer.dispose();
}
if (xs != null) {
((XAWTXSettings)xs).dispose();
}
freeXKB();
if (log.isLoggable(PlatformLogger.Level.FINE)) {
dumpPeers();
}
} }
}; if (xs != null) {
shutdownThread.setContextClassLoader(null); ((XAWTXSettings)xs).dispose();
Runtime.getRuntime().addShutdownHook(shutdownThread); }
return null; freeXKB();
} if (log.isLoggable(PlatformLogger.Level.FINE)) {
dumpPeers();
}
}
};
shutdownThread.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdownThread);
return null;
}; };
AccessController.doPrivileged(a); AccessController.doPrivileged(a);
} }
...@@ -318,17 +316,13 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -318,17 +316,13 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
init(); init();
XWM.init(); XWM.init();
SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME); SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
toolkitThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
PrivilegedAction<Thread> action = new PrivilegedAction() { Thread thread = new Thread(sun.misc.ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT");
public Thread run() { thread.setContextClassLoader(null);
Thread thread = new Thread(getRootThreadGroup(), XToolkit.this, "AWT-XAWT"); thread.setPriority(Thread.NORM_PRIORITY + 1);
thread.setContextClassLoader(null); thread.setDaemon(true);
thread.setPriority(Thread.NORM_PRIORITY + 1); return thread;
thread.setDaemon(true); });
return thread;
}
};
toolkitThread = AccessController.doPrivileged(action);
toolkitThread.start(); toolkitThread.start();
} }
} }
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -42,6 +42,8 @@ import sun.java2d.opengl.GLXGraphicsConfig; ...@@ -42,6 +42,8 @@ import sun.java2d.opengl.GLXGraphicsConfig;
import sun.java2d.xr.XRGraphicsConfig; import sun.java2d.xr.XRGraphicsConfig;
import sun.java2d.loops.SurfaceType; import sun.java2d.loops.SurfaceType;
import sun.misc.ThreadGroupUtils;
/** /**
* This is an implementation of a GraphicsDevice object for a single * This is an implementation of a GraphicsDevice object for a single
* X11 screen. * X11 screen.
...@@ -423,28 +425,19 @@ public class X11GraphicsDevice ...@@ -423,28 +425,19 @@ public class X11GraphicsDevice
// is already in the original DisplayMode at that time, this // is already in the original DisplayMode at that time, this
// hook will have no effect) // hook will have no effect)
shutdownHookRegistered = true; shutdownHookRegistered = true;
PrivilegedAction<Void> a = new PrivilegedAction<Void>() { PrivilegedAction<Void> a = () -> {
public Void run() { ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup mainTG = Thread.currentThread().getThreadGroup(); Runnable r = () -> {
ThreadGroup parentTG = mainTG.getParent(); Window old = getFullScreenWindow();
while (parentTG != null) { if (old != null) {
mainTG = parentTG; exitFullScreenExclusive(old);
parentTG = mainTG.getParent(); setDisplayMode(origDisplayMode);
} }
Runnable r = new Runnable() { };
public void run() { Thread t = new Thread(rootTG, r,"Display-Change-Shutdown-Thread-"+screen);
Window old = getFullScreenWindow(); t.setContextClassLoader(null);
if (old != null) { Runtime.getRuntime().addShutdownHook(t);
exitFullScreenExclusive(old); return null;
setDisplayMode(origDisplayMode);
}
}
};
Thread t = new Thread(mainTG, r,"Display-Change-Shutdown-Thread-"+screen);
t.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(t);
return null;
}
}; };
AccessController.doPrivileged(a); AccessController.doPrivileged(a);
} }
......
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -39,6 +39,7 @@ import java.util.concurrent.*; ...@@ -39,6 +39,7 @@ import java.util.concurrent.*;
import static sun.awt.shell.Win32ShellFolder2.*; import static sun.awt.shell.Win32ShellFolder2.*;
import sun.awt.OSInfo; import sun.awt.OSInfo;
import sun.misc.ThreadGroupUtils;
// NOTE: This class supersedes Win32ShellFolderManager, which was removed // NOTE: This class supersedes Win32ShellFolderManager, which was removed
// from distribution after version 1.4.2. // from distribution after version 1.4.2.
...@@ -509,23 +510,16 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -509,23 +510,16 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
} }
} }
}; };
comThread = comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
AccessController.doPrivileged(
new PrivilegedAction<Thread>() {
public Thread run() {
/* The thread must be a member of a thread group /* The thread must be a member of a thread group
* which will not get GCed before VM exit. * which will not get GCed before VM exit.
* Make its parent the top-level thread group. * Make its parent the top-level thread group.
*/ */
ThreadGroup tg = Thread.currentThread().getThreadGroup(); ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
for (ThreadGroup tgn = tg; Thread thread = new Thread(rootTG, comRun, "Swing-Shell");
tgn != null;
tg = tgn, tgn = tg.getParent());
Thread thread = new Thread(tg, comRun, "Swing-Shell");
thread.setDaemon(true); thread.setDaemon(true);
return thread; return thread;
} }
}
); );
return comThread; return comThread;
} }
......
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -39,6 +39,7 @@ import java.security.PrivilegedAction; ...@@ -39,6 +39,7 @@ import java.security.PrivilegedAction;
import sun.awt.AWTAutoShutdown; import sun.awt.AWTAutoShutdown;
import sun.awt.LightweightFrame; import sun.awt.LightweightFrame;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.misc.ThreadGroupUtils;
import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsDevice;
import sun.awt.Win32GraphicsEnvironment; import sun.awt.Win32GraphicsEnvironment;
import sun.java2d.d3d.D3DRenderQueue; import sun.java2d.d3d.D3DRenderQueue;
...@@ -240,7 +241,8 @@ public class WToolkit extends SunToolkit implements Runnable { ...@@ -240,7 +241,8 @@ public class WToolkit extends SunToolkit implements Runnable {
AWTAutoShutdown.notifyToolkitThreadBusy(); AWTAutoShutdown.notifyToolkitThreadBusy();
// Find a root TG and attach Appkit thread to it // Find a root TG and attach Appkit thread to it
ThreadGroup rootTG = getRootThreadGroup(); ThreadGroup rootTG = AccessController.doPrivileged(
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
if (!startToolkitThread(this, rootTG)) { if (!startToolkitThread(this, rootTG)) {
Thread toolkitThread = new Thread(rootTG, this, "AWT-Windows"); Thread toolkitThread = new Thread(rootTG, this, "AWT-Windows");
toolkitThread.setDaemon(true); toolkitThread.setDaemon(true);
...@@ -270,17 +272,11 @@ public class WToolkit extends SunToolkit implements Runnable { ...@@ -270,17 +272,11 @@ public class WToolkit extends SunToolkit implements Runnable {
} }
private final void registerShutdownHook() { private final void registerShutdownHook() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
public Void run() { Thread shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), this::shutdown);
Thread shutdown = new Thread(getRootThreadGroup(), new Runnable() { shutdown.setContextClassLoader(null);
public void run() { Runtime.getRuntime().addShutdownHook(shutdown);
shutdown(); return null;
}
});
shutdown.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdown);
return null;
}
}); });
} }
......
/* /*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,8 +36,9 @@ import java.security.AccessController; ...@@ -36,8 +36,9 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import sun.awt.SunToolkit;
import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.misc.ThreadGroupUtils;
import sun.awt.Win32GraphicsConfig; import sun.awt.Win32GraphicsConfig;
import sun.awt.windows.WComponentPeer; import sun.awt.windows.WComponentPeer;
import sun.java2d.InvalidPipeException; import sun.java2d.InvalidPipeException;
...@@ -92,21 +93,12 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager ...@@ -92,21 +93,12 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
public D3DScreenUpdateManager() { public D3DScreenUpdateManager() {
done = false; done = false;
AccessController.doPrivileged( AccessController.doPrivileged(
new PrivilegedAction() { (PrivilegedAction<Void>) () -> {
public Object run() { ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup currentTG = Thread shutdown = new Thread(rootTG, () -> {
Thread.currentThread().getThreadGroup(); done = true;
ThreadGroup parentTG = currentTG.getParent(); wakeUpUpdateThread();
while (parentTG != null) { });
currentTG = parentTG;
parentTG = currentTG.getParent();
}
Thread shutdown = new Thread(currentTG, new Runnable() {
public void run() {
done = true;
wakeUpUpdateThread();
}
});
shutdown.setContextClassLoader(null); shutdown.setContextClassLoader(null);
try { try {
Runtime.getRuntime().addShutdownHook(shutdown); Runtime.getRuntime().addShutdownHook(shutdown);
...@@ -115,7 +107,6 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager ...@@ -115,7 +107,6 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
} }
return null; return null;
} }
}
); );
} }
...@@ -354,21 +345,17 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager ...@@ -354,21 +345,17 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
*/ */
private synchronized void startUpdateThread() { private synchronized void startUpdateThread() {
if (screenUpdater == null) { if (screenUpdater == null) {
screenUpdater = (Thread)java.security.AccessController.doPrivileged( screenUpdater = AccessController.doPrivileged(
new java.security.PrivilegedAction() { (PrivilegedAction<Thread>) () -> {
public Object run() { ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
ThreadGroup tg = Thread t = new Thread(rootTG,
Thread.currentThread().getThreadGroup(); D3DScreenUpdateManager.this,
for (ThreadGroup tgn = tg; "D3D Screen Updater");
tgn != null; tg = tgn, tgn = tg.getParent());
Thread t = new Thread(tg, D3DScreenUpdateManager.this,
"D3D Screen Updater");
// REMIND: should it be higher? // REMIND: should it be higher?
t.setPriority(Thread.NORM_PRIORITY + 2); t.setPriority(Thread.NORM_PRIORITY + 2);
t.setDaemon(true); t.setDaemon(true);
return t; return t;
} });
});
screenUpdater.start(); screenUpdater.start();
} else { } else {
wakeUpUpdateThread(); wakeUpUpdateThread();
......
/*
* Copyright (c) 2014, 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.
*
* 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.
*/
/*
@test
@bug 8031477
@summary Crash while awt starting
@author Petr Pchelko
@run main/othervm LoadAWTCrashTest
*/
public class LoadAWTCrashTest {
public static void main(String[] args) {
System.loadLibrary("awt");
// If the bug is present JVM would crash or deadlock
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册