mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8212700: Change the mechanism by which JDK loads the platform-specific AWT Toolkit
Reviewed-by: serb, rriggs
This commit is contained in:
parent
7f841d6d9a
commit
8ca1211aab
13 changed files with 95 additions and 66 deletions
|
@ -90,7 +90,6 @@ public final class SystemProps {
|
||||||
putIfAbsent(props, "http.nonProxyHosts", raw.propDefault(Raw._http_nonProxyHosts_NDX));
|
putIfAbsent(props, "http.nonProxyHosts", raw.propDefault(Raw._http_nonProxyHosts_NDX));
|
||||||
putIfAbsent(props, "ftp.nonProxyHosts", raw.propDefault(Raw._ftp_nonProxyHosts_NDX));
|
putIfAbsent(props, "ftp.nonProxyHosts", raw.propDefault(Raw._ftp_nonProxyHosts_NDX));
|
||||||
putIfAbsent(props, "socksNonProxyHosts", raw.propDefault(Raw._socksNonProxyHosts_NDX));
|
putIfAbsent(props, "socksNonProxyHosts", raw.propDefault(Raw._socksNonProxyHosts_NDX));
|
||||||
putIfAbsent(props, "awt.toolkit", raw.propDefault(Raw._awt_toolkit_NDX));
|
|
||||||
putIfAbsent(props, "sun.arch.abi", raw.propDefault(Raw._sun_arch_abi_NDX));
|
putIfAbsent(props, "sun.arch.abi", raw.propDefault(Raw._sun_arch_abi_NDX));
|
||||||
putIfAbsent(props, "sun.arch.data.model", raw.propDefault(Raw._sun_arch_data_model_NDX));
|
putIfAbsent(props, "sun.arch.data.model", raw.propDefault(Raw._sun_arch_data_model_NDX));
|
||||||
putIfAbsent(props, "sun.os.patch.level", raw.propDefault(Raw._sun_os_patch_level_NDX));
|
putIfAbsent(props, "sun.os.patch.level", raw.propDefault(Raw._sun_os_patch_level_NDX));
|
||||||
|
@ -185,8 +184,7 @@ public final class SystemProps {
|
||||||
public static class Raw {
|
public static class Raw {
|
||||||
// Array indices written by native vmProperties()
|
// Array indices written by native vmProperties()
|
||||||
// The order is arbitrary (but alphabetic for convenience)
|
// The order is arbitrary (but alphabetic for convenience)
|
||||||
@Native private static final int _awt_toolkit_NDX = 0;
|
@Native private static final int _display_country_NDX = 0;
|
||||||
@Native private static final int _display_country_NDX = 1 + _awt_toolkit_NDX;
|
|
||||||
@Native private static final int _display_language_NDX = 1 + _display_country_NDX;
|
@Native private static final int _display_language_NDX = 1 + _display_country_NDX;
|
||||||
@Native private static final int _display_script_NDX = 1 + _display_language_NDX;
|
@Native private static final int _display_script_NDX = 1 + _display_language_NDX;
|
||||||
@Native private static final int _display_variant_NDX = 1 + _display_script_NDX;
|
@Native private static final int _display_variant_NDX = 1 + _display_script_NDX;
|
||||||
|
|
|
@ -204,8 +204,6 @@ Java_jdk_internal_util_SystemProps_00024Raw_platformProperties(JNIEnv *env, jcla
|
||||||
/* patch level */
|
/* patch level */
|
||||||
PUTPROP(propArray, _sun_os_patch_level_NDX, sprops->patch_level);
|
PUTPROP(propArray, _sun_os_patch_level_NDX, sprops->patch_level);
|
||||||
|
|
||||||
PUTPROP(propArray, _awt_toolkit_NDX, sprops->awt_toolkit);
|
|
||||||
|
|
||||||
PUTPROP_PlatformString(propArray, _java_io_tmpdir_NDX, sprops->tmp_dir);
|
PUTPROP_PlatformString(propArray, _java_io_tmpdir_NDX, sprops->tmp_dir);
|
||||||
|
|
||||||
PUTPROP_PlatformString(propArray, _user_name_NDX, sprops->user_name);
|
PUTPROP_PlatformString(propArray, _user_name_NDX, sprops->user_name);
|
||||||
|
|
|
@ -68,8 +68,6 @@ typedef struct {
|
||||||
char *sun_stdout_encoding;
|
char *sun_stdout_encoding;
|
||||||
char *sun_stderr_encoding;
|
char *sun_stderr_encoding;
|
||||||
|
|
||||||
char *awt_toolkit;
|
|
||||||
|
|
||||||
char *unicode_encoding; /* The default endianness of unicode
|
char *unicode_encoding; /* The default endianness of unicode
|
||||||
i.e. UnicodeBig or UnicodeLittle */
|
i.e. UnicodeBig or UnicodeLittle */
|
||||||
|
|
||||||
|
|
|
@ -394,14 +394,6 @@ GetJavaProperties(JNIEnv *env)
|
||||||
/* patches/service packs installed */
|
/* patches/service packs installed */
|
||||||
sprops.patch_level = NULL; // leave it undefined
|
sprops.patch_level = NULL; // leave it undefined
|
||||||
|
|
||||||
/* Java 2D/AWT properties */
|
|
||||||
#ifdef MACOSX
|
|
||||||
// Always the same Toolkit on Mac OS X
|
|
||||||
sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit";
|
|
||||||
#else
|
|
||||||
sprops.awt_toolkit = "sun.awt.X11.XToolkit";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SI_ISALIST
|
#ifdef SI_ISALIST
|
||||||
/* supported instruction sets */
|
/* supported instruction sets */
|
||||||
{
|
{
|
||||||
|
|
|
@ -365,9 +365,6 @@ GetJavaProperties(JNIEnv* env)
|
||||||
return &sprops;
|
return &sprops;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AWT properties */
|
|
||||||
sprops.awt_toolkit = "sun.awt.windows.WToolkit";
|
|
||||||
|
|
||||||
/* tmp dir */
|
/* tmp dir */
|
||||||
{
|
{
|
||||||
WCHAR tmpdir[MAX_PATH + 1];
|
WCHAR tmpdir[MAX_PATH + 1];
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package sun.awt;
|
package sun.awt;
|
||||||
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
|
@ -42,6 +43,10 @@ public class PlatformGraphicsInfo {
|
||||||
return new CGraphicsEnvironment();
|
return new CGraphicsEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Toolkit createToolkit() {
|
||||||
|
return new sun.lwawt.macosx.LWCToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the WindowServer is available, false otherwise.
|
* Returns true if the WindowServer is available, false otherwise.
|
||||||
*
|
*
|
||||||
|
|
|
@ -190,10 +190,16 @@ public final class LWCToolkit extends LWToolkit {
|
||||||
private static final boolean inAWT;
|
private static final boolean inAWT;
|
||||||
|
|
||||||
public LWCToolkit() {
|
public LWCToolkit() {
|
||||||
areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
|
final String extraButtons = "sun.awt.enableExtraMouseButtons";
|
||||||
//set system property if not yet assigned
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
|
areExtraMouseButtonsEnabled =
|
||||||
initAppkit(ThreadGroupUtils.getRootThreadGroup(), GraphicsEnvironment.isHeadless());
|
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
|
||||||
|
//set system property if not yet assigned
|
||||||
|
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled);
|
||||||
|
initAppkit(ThreadGroupUtils.getRootThreadGroup(),
|
||||||
|
GraphicsEnvironment.isHeadless());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -78,6 +78,7 @@ import sun.awt.AWTPermissions;
|
||||||
import sun.awt.AppContext;
|
import sun.awt.AppContext;
|
||||||
import sun.awt.HeadlessToolkit;
|
import sun.awt.HeadlessToolkit;
|
||||||
import sun.awt.PeerEvent;
|
import sun.awt.PeerEvent;
|
||||||
|
import sun.awt.PlatformGraphicsInfo;
|
||||||
import sun.awt.SunToolkit;
|
import sun.awt.SunToolkit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -582,43 +583,17 @@ public abstract class Toolkit {
|
||||||
* specified.
|
* specified.
|
||||||
*
|
*
|
||||||
* @return the default toolkit.
|
* @return the default toolkit.
|
||||||
* @exception AWTError if a toolkit could not be found, or
|
* @throws AWTError in case of an error loading assistive technologies.
|
||||||
* if one could not be accessed or instantiated.
|
|
||||||
* @see java.util.ServiceLoader
|
* @see java.util.ServiceLoader
|
||||||
* @see javax.accessibility.AccessibilityProvider
|
* @see javax.accessibility.AccessibilityProvider
|
||||||
*/
|
*/
|
||||||
public static synchronized Toolkit getDefaultToolkit() {
|
public static synchronized Toolkit getDefaultToolkit() {
|
||||||
if (toolkit == null) {
|
if (toolkit == null) {
|
||||||
java.security.AccessController.doPrivileged(
|
toolkit = PlatformGraphicsInfo.createToolkit();
|
||||||
new java.security.PrivilegedAction<Void>() {
|
if (GraphicsEnvironment.isHeadless() &&
|
||||||
public Void run() {
|
!(toolkit instanceof HeadlessToolkit)) {
|
||||||
Class<?> cls = null;
|
toolkit = new HeadlessToolkit(toolkit);
|
||||||
String nm = System.getProperty("awt.toolkit");
|
}
|
||||||
try {
|
|
||||||
cls = Class.forName(nm);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
|
||||||
if (cl != null) {
|
|
||||||
try {
|
|
||||||
cls = cl.loadClass(nm);
|
|
||||||
} catch (final ClassNotFoundException ignored) {
|
|
||||||
throw new AWTError("Toolkit not found: " + nm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (cls != null) {
|
|
||||||
toolkit = (Toolkit)cls.getConstructor().newInstance();
|
|
||||||
if (GraphicsEnvironment.isHeadless()) {
|
|
||||||
toolkit = new HeadlessToolkit(toolkit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final ReflectiveOperationException ignored) {
|
|
||||||
throw new AWTError("Could not create Toolkit: " + nm);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!GraphicsEnvironment.isHeadless()) {
|
if (!GraphicsEnvironment.isHeadless()) {
|
||||||
loadAssistiveTechnologies();
|
loadAssistiveTechnologies();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package sun.awt;
|
package sun.awt;
|
||||||
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
|
@ -35,6 +36,10 @@ public class PlatformGraphicsInfo {
|
||||||
return new X11GraphicsEnvironment();
|
return new X11GraphicsEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Toolkit createToolkit() {
|
||||||
|
return new sun.awt.X11.XToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from java.awt.GraphicsEnvironment when
|
* Called from java.awt.GraphicsEnvironment when
|
||||||
* to check if on this platform, the JDK should default to
|
* to check if on this platform, the JDK should default to
|
||||||
|
|
|
@ -346,10 +346,14 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||||
|
|
||||||
arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
|
arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
|
||||||
XCursorFontConstants.XC_arrow);
|
XCursorFontConstants.XC_arrow);
|
||||||
areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
|
final String extraButtons = "sun.awt.enableExtraMouseButtons";
|
||||||
//set system property if not yet assigned
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
|
areExtraMouseButtonsEnabled =
|
||||||
|
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
|
||||||
|
//set system property if not yet assigned
|
||||||
|
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
// Detect display mode changes
|
// Detect display mode changes
|
||||||
XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
|
XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
|
||||||
XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
|
XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package sun.awt;
|
package sun.awt;
|
||||||
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
|
||||||
public class PlatformGraphicsInfo {
|
public class PlatformGraphicsInfo {
|
||||||
|
|
||||||
|
@ -33,6 +34,10 @@ public class PlatformGraphicsInfo {
|
||||||
return new Win32GraphicsEnvironment();
|
return new Win32GraphicsEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Toolkit createToolkit() {
|
||||||
|
return new sun.awt.windows.WToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getDefaultHeadlessProperty() {
|
public static boolean getDefaultHeadlessProperty() {
|
||||||
// On Windows, we assume we can always create headful apps.
|
// On Windows, we assume we can always create headful apps.
|
||||||
// Here is where we can add code that would actually check.
|
// Here is where we can add code that would actually check.
|
||||||
|
|
|
@ -245,10 +245,13 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||||
ThreadGroup rootTG = AccessController.doPrivileged(
|
ThreadGroup rootTG = AccessController.doPrivileged(
|
||||||
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
|
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
|
||||||
if (!startToolkitThread(this, rootTG)) {
|
if (!startToolkitThread(this, rootTG)) {
|
||||||
String name = "AWT-Windows";
|
final String name = "AWT-Windows";
|
||||||
Thread toolkitThread = new Thread(rootTG, this, name, 0, false);
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
toolkitThread.setDaemon(true);
|
Thread toolkitThread = new Thread(rootTG, this, name, 0, false);
|
||||||
toolkitThread.start();
|
toolkitThread.setDaemon(true);
|
||||||
|
toolkitThread.start();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -264,10 +267,14 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||||
// Enabled "live resizing" by default. It remains controlled
|
// Enabled "live resizing" by default. It remains controlled
|
||||||
// by the native system though.
|
// by the native system though.
|
||||||
setDynamicLayout(true);
|
setDynamicLayout(true);
|
||||||
|
final String extraButtons = "sun.awt.enableExtraMouseButtons";
|
||||||
areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
//set system property if not yet assigned
|
areExtraMouseButtonsEnabled =
|
||||||
System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
|
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
|
||||||
|
//set system property if not yet assigned
|
||||||
|
System.setProperty(extraButtons, ""+areExtraMouseButtonsEnabled);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
|
setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, 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 8212700
|
||||||
|
* @summary verify the AWT Toolkit implementation class name is not
|
||||||
|
* polluting system properties
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CheckToolkitSystemProperty {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String tkProp = System.getProperty("awt.toolkit");
|
||||||
|
if (tkProp != null) {
|
||||||
|
throw new RuntimeException("tkProp = " + tkProp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue