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