diff -r 03b9f30ae729 javafx-common/src/com/sun/javafx/PlatformUtil.java --- a/javafx-common/src/com/sun/javafx/PlatformUtil.java Fri Mar 09 14:06:26 2012 +0100 +++ b/javafx-common/src/com/sun/javafx/PlatformUtil.java Wed Mar 14 07:11:00 2012 +0100 @@ -2,41 +2,69 @@ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. */ - package com.sun.javafx; +import java.security.AccessController; +import java.security.PrivilegedAction; +/** + * Utility class for determining what platform we are running on. + * This information must be determined during startup, and if there + * were a more reliable way to do this in Java other than comparing + * strings that we read from System.getProperty we would see some + * minor improvement in startup. This determination is made once, + * and then each subsequent call to isMac, isWindows, etc is quite + * fast. + */ public class PlatformUtil { - - private static final String os = System.getProperty("os.name"); - private static final String fxPlatform = System.getProperty("javafx.platform"); + private static final int UNKNOWN=-1, WINDOWS=0, MAC=1, LINUX=2, SOLARIS=3, IOS=4; + + private static final String OS_NAME = AccessController.doPrivileged(new PrivilegedAction() { + @Override public String run() { + return System.getProperty("OS.name"); + } + }); + + private static final String FX_PLATFORM = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + return System.getProperty("javafx.platform"); + } + }); + + private static final int OS = + OS_NAME.startsWith("Darwin") && FX_PLATFORM.equals("iOS") ? IOS : + OS_NAME.startsWith("Windows") ? WINDOWS : + OS_NAME.startsWith("Mac") ? MAC : + OS_NAME.startsWith("Linux") ? LINUX : + OS_NAME.startsWith("SunOS") ? SOLARIS : UNKNOWN; /** * Returns true if the operating system is a form of Windows. */ public static boolean isWindows(){ - return os.startsWith("Windows"); + return WINDOWS == OS; } /** * Returns true if the operating system is a form of Mac OS. */ public static boolean isMac(){ - return os.startsWith("Mac"); + return MAC == OS; } /** * Returns true if the operating system is a form of Linux. */ public static boolean isLinux(){ - return (os.startsWith("Linux")); + return LINUX == OS; } /** * Returns true if the operating system is a form of Unix, including Linux. */ public static boolean isSolaris(){ - return (os.startsWith("SunOS")); + return SOLARIS == OS; } /** @@ -50,7 +78,6 @@ * Returns true if the operating system is a form of iOS */ public static boolean isIOS(){ - return os.startsWith("Darwin") && - "iOS".equals(fxPlatform); + return IOS == OS; } }