diff options
author | Sven Gothel <[email protected]> | 2012-09-07 07:46:13 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-09-07 07:46:13 +0200 |
commit | c29fb2910e1a4d3227c0eeb4158cff3bbb99c783 (patch) | |
tree | 742f29b75761a7350c09fc675d06663f10a828a8 /src/java | |
parent | 8af95c02ba27abfb6ce152be2b970bb3840a7917 (diff) |
Platform: Slight reorder of initialization reducing one PrivilegedAction block.
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index ba89474..9b60f32 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -180,9 +180,30 @@ public class Platform extends PlatformPropsImpl { USE_TEMP_JAR_CACHE = (OS_TYPE != OSType.ANDROID) && isRunningFromJarURL() && Debug.getBooleanProperty(useTempJarCachePropName, true, true); - loadGlueGenRTImpl(); + AWT_AVAILABLE = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { + public Boolean run() { + // load GluegenRT native library + loadGlueGenRTImpl(); + + // JVM bug workaround + JVMUtil.initSingleton(); // requires gluegen-rt, one-time init. + + // detect AWT availability + boolean awtAvailable = false; + { + final ClassLoader cl = Platform.class.getClassLoader(); + if( !Debug.getBooleanProperty("java.awt.headless", true) && + ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.ComponentClass, cl) && + ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, cl) ) { + try { + awtAvailable = false == ((Boolean)ReflectionUtil.callStaticMethod(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, ReflectionUtil.AWTNames.isHeadlessMethod, null, null, cl)).booleanValue(); + } catch (Throwable t) { } + } + } + return new Boolean(awtAvailable); + } + }).booleanValue(); - JVMUtil.initSingleton(); // requires gluegen-rt, one-time init. MachineDescription md = MachineDescriptionRuntime.getRuntime(); if(null == md) { @@ -198,24 +219,7 @@ public class Platform extends PlatformPropsImpl { } } machineDescription = md; - is32Bit = machineDescription.is32Bit(); - - { - final ClassLoader cl = Platform.class.getClassLoader(); - AWT_AVAILABLE = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { - public Boolean run() { - boolean awtAvailable = false; - if( !Debug.getBooleanProperty("java.awt.headless", true) && - ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.ComponentClass, cl) && - ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, cl) ) { - try { - awtAvailable = false == ((Boolean)ReflectionUtil.callStaticMethod(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, ReflectionUtil.AWTNames.isHeadlessMethod, null, null, cl)).booleanValue(); - } catch (Throwable t) { } - } - return new Boolean(awtAvailable); - } - }).booleanValue(); - } + is32Bit = machineDescription.is32Bit(); } private Platform() {} @@ -228,28 +232,23 @@ public class Platform extends PlatformPropsImpl { } private static final void loadGlueGenRTImpl() { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - if(USE_TEMP_JAR_CACHE && TempJarCache.initSingleton()) { - String nativeJarName = null; - URL jarUrlRoot = null; - URL nativeJarURL = null; - try { - final String jarName = JarUtil.getJarBasename(platformClassJarURL); - final String nativeJarBasename = jarName.substring(0, jarName.indexOf(".jar")); // ".jar" already validated w/ JarUtil.getJarBasename(..) - nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar"; - jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(platformClassJarURL) ); - nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); - TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL); - } catch (Exception e0) { - // IllegalArgumentException, IOException - System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while TempJarCache.bootstrapNativeLib() of "+nativeJarURL+" ("+jarUrlRoot+" + "+nativeJarName+")"); - } - } - DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, Platform.class.getClassLoader()); - return null; + if(USE_TEMP_JAR_CACHE && TempJarCache.initSingleton()) { + String nativeJarName = null; + URL jarUrlRoot = null; + URL nativeJarURL = null; + try { + final String jarName = JarUtil.getJarBasename(platformClassJarURL); + final String nativeJarBasename = jarName.substring(0, jarName.indexOf(".jar")); // ".jar" already validated w/ JarUtil.getJarBasename(..) + nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar"; + jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(platformClassJarURL) ); + nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); + TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL); + } catch (Exception e0) { + // IllegalArgumentException, IOException + System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while TempJarCache.bootstrapNativeLib() of "+nativeJarURL+" ("+jarUrlRoot+" + "+nativeJarName+")"); } - }); + } + DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, Platform.class.getClassLoader()); } /** @@ -417,7 +416,7 @@ public class Platform extends PlatformPropsImpl { public static boolean isAWTAvailable() { return AWT_AVAILABLE; } - + // // time / jitter // |