Skip to content

Commit

Permalink
Unify JNI Library Loading into JNILibLoaderBase and use it for the gl…
Browse files Browse the repository at this point in the history
…uegen-rt native lib as well

- removed redundance
- move proper JNLPAppletLauncher custom libloader code into JNILibLoaderBase
- prepares for new JAR temp cache ..
  • Loading branch information
sgothel committed Sep 21, 2011
1 parent 0e44b33 commit def691b
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 152 deletions.
46 changes: 28 additions & 18 deletions src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
Expand Up @@ -106,7 +106,7 @@ public void loadLibrary(String libname, String[] preload, boolean preloadIgnoreE
}
}

private static final HashSet loaded = new HashSet();
private static final HashSet<String> loaded = new HashSet<String>();
private static LoaderAction loaderAction = new DefaultAction();

public static boolean isLoaded(String libName) {
Expand Down Expand Up @@ -145,30 +145,41 @@ protected static synchronized void loadLibrary(String libname, String[] preload,
}
}

private static final Class customLauncherClass;
// private static final Class<?> customLauncherClass;
private static final Method customLoadLibraryMethod;

// FIXME centralize logging
static {
Class launcherClass = null;
final String sunAppletLauncherProperty = "sun.jnlp.applet.launcher";
final String sunAppletLauncherClassName = "org.jdesktop.applet.util.JNLPAppletLauncher";
final boolean usingJNLPAppletLauncher = Boolean.valueOf(System.getProperty(sunAppletLauncherProperty)).booleanValue();

Class<?> launcherClass = null;
Method loadLibraryMethod = null;

if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false, localACC) ) {
if (usingJNLPAppletLauncher) {
try {
launcherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher");
loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
} catch (ClassNotFoundException ex) {
if(DEBUG) {
ex.printStackTrace();
}
} catch (NoSuchMethodException ex) {
if(DEBUG) {
ex.printStackTrace();
}
launcherClass = null;
launcherClass = Class.forName(sunAppletLauncherClassName);
} catch (ClassNotFoundException cnfe) {
// oops .. look like JNLPAppletLauncher doesn't exist, despite property
// this may happen if a previous applet was using JNLPAppletLauncher in the same JVM
System.err.println("JNILibLoaderBase: <"+sunAppletLauncherClassName+"> not found, despite enabled property <"+sunAppletLauncherProperty+">, JNLPAppletLauncher was probably used before");
System.setProperty(sunAppletLauncherProperty, Boolean.FALSE.toString());
} catch (LinkageError le) {
throw le;
}
if(null != launcherClass) {
try {
loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
} catch (NoSuchMethodException ex) {
if(DEBUG) {
ex.printStackTrace();
}
launcherClass = null;
}
}
}

if(null==launcherClass) {
String launcherClassName = Debug.getProperty("jnlp.launcher.class", false, localACC);
if(null!=launcherClassName) {
Expand All @@ -187,8 +198,7 @@ protected static synchronized void loadLibrary(String libname, String[] preload,
}
}
}

customLauncherClass = launcherClass;
// customLauncherClass = launcherClass;
customLoadLibraryMethod = loadLibraryMethod;
}

Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/common/jvm/JVMUtil.java
Expand Up @@ -37,7 +37,7 @@
import com.jogamp.common.os.NativeLibrary;

import jogamp.common.Debug;
import com.jogamp.gluegen.runtime.NativeLibLoader;
import com.jogamp.gluegen.runtime.GlueGenJNILibLoader;

/**
* Currently this tool works around the Hotspot race condition bugs:
Expand All @@ -54,7 +54,7 @@ public class JVMUtil {
private static final boolean DEBUG = Debug.debug("JVMUtil");

static {
NativeLibLoader.loadGlueGenRT();
GlueGenJNILibLoader.loadGlueGenRT();

ByteBuffer buffer = Buffers.newDirectByteBuffer(64);
if( ! initialize(buffer) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/common/nio/AbstractBuffer.java
Expand Up @@ -32,7 +32,7 @@
package com.jogamp.common.nio;

import com.jogamp.common.os.*;
import com.jogamp.gluegen.runtime.NativeLibLoader;
import com.jogamp.gluegen.runtime.GlueGenJNILibLoader;

import java.nio.Buffer;
import java.nio.ByteBuffer;
Expand All @@ -49,7 +49,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
protected int position;

static {
NativeLibLoader.loadGlueGenRT();
GlueGenJNILibLoader.loadGlueGenRT();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/common/nio/PointerBuffer.java
Expand Up @@ -39,7 +39,7 @@
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.LongObjectHashMap;
import com.jogamp.gluegen.runtime.NativeLibLoader;
import com.jogamp.gluegen.runtime.GlueGenJNILibLoader;

/**
* Hardware independent container for native pointer arrays.
Expand All @@ -55,7 +55,7 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> {
protected LongObjectHashMap dataMap = null;

static {
NativeLibLoader.loadGlueGenRT();
GlueGenJNILibLoader.loadGlueGenRT();
}

/** no backup array, use for direct usage only */
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/common/os/DynamicLibraryBundle.java
Expand Up @@ -250,7 +250,7 @@ private void loadLibraries() {
boolean ignoreError = true;
boolean res;
try {
res = GlueJNILibLoaderBase.loadLibrary(libName, ignoreError);
res = GlueJNILibLoader.loadLibrary(libName, ignoreError);
if(DEBUG && !res) {
System.err.println("Info: Could not load JNI/Glue library: "+libName);
}
Expand Down Expand Up @@ -339,7 +339,7 @@ public long dynamicLookupFunction(String funcName) {
}

/** Inherit access */
static class GlueJNILibLoaderBase extends JNILibLoaderBase {
static class GlueJNILibLoader extends JNILibLoaderBase {
protected static synchronized boolean loadLibrary(String libname, boolean ignoreError) {
return JNILibLoaderBase.loadLibrary(libname, ignoreError);
}
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/jogamp/common/os/NativeLibrary.java
Expand Up @@ -41,7 +41,7 @@
package com.jogamp.common.os;

import com.jogamp.common.util.IOUtil;
import com.jogamp.gluegen.runtime.NativeLibLoader;
import com.jogamp.gluegen.runtime.GlueGenJNILibLoader;
import jogamp.common.Debug;
import jogamp.common.os.MacOSXDynamicLinkerImpl;
import jogamp.common.os.UnixDynamicLinkerImpl;
Expand Down Expand Up @@ -175,7 +175,7 @@ public static NativeLibrary open(String windowsLibName,
if (DEBUG) {
System.err.println("Trying to load " + path);
}
NativeLibLoader.loadGlueGenRT();
GlueGenJNILibLoader.loadGlueGenRT();
long res;
if(global) {
res = dynLink.openLibraryGlobal(path, DEBUG);
Expand Down
62 changes: 62 additions & 0 deletions src/java/com/jogamp/gluegen/runtime/GlueGenJNILibLoader.java
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2011 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
* ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
*
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/

package com.jogamp.gluegen.runtime;

import java.security.*;

import com.jogamp.common.jvm.JNILibLoaderBase;

/** Class providing control over whether GlueGen loads the native code
associated with the NativeLibrary implementation. Alternative app
launchers such as those running within applets may want to disable
this default loading behavior and load the native code via another
(manual) mechanism. */
public class GlueGenJNILibLoader extends JNILibLoaderBase {

public static void loadGlueGenRT() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
loadLibrary("gluegen-rt", false);
return null;
}
});
}
}
120 changes: 0 additions & 120 deletions src/java/com/jogamp/gluegen/runtime/NativeLibLoader.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/java/jogamp/common/os/MachineDescriptionRuntime.java
Expand Up @@ -32,7 +32,7 @@
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.common.os.Platform;
import com.jogamp.common.os.MachineDescription.StaticConfig;
import com.jogamp.gluegen.runtime.NativeLibLoader;
import com.jogamp.gluegen.runtime.GlueGenJNILibLoader;

/**
* Runtime MachineDescription
Expand Down Expand Up @@ -85,7 +85,7 @@ public static MachineDescription getRuntime() {
}
private static MachineDescription getRuntimeImpl() {
try {
NativeLibLoader.loadGlueGenRT();
GlueGenJNILibLoader.loadGlueGenRT();
} catch (UnsatisfiedLinkError err) {
return null;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@
public class BindingJNILibLoader extends JNILibLoaderBase {

public static void loadBindingtest1p1() {
AccessController.doPrivileged(new PrivilegedAction() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
loadLibrary("Bindingtest1p1", null, true);
return null;
Expand All @@ -43,7 +43,7 @@ public Object run() {
}

public static void loadBindingtest1p2() {
AccessController.doPrivileged(new PrivilegedAction() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
loadLibrary("Bindingtest1p2", null, true);
return null;
Expand Down

0 comments on commit def691b

Please sign in to comment.