diff options
author | Sven Gothel <[email protected]> | 2012-02-12 06:06:59 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-12 06:06:59 +0100 |
commit | bd5be69aee6987754f1cbf39f61280c5c72536b3 (patch) | |
tree | b6894cbc2bc6e659ac0d921a9c50ff664269faac /src/java | |
parent | 67854df4b16ce92d0e792f3c693ced0a6470f6cc (diff) |
DynamicLibraryBundle (enhancement)
- Hold DEBUG, DEBUG_LOOKUP in DynamicLookupHelper
- Tool complete only if named tool's GetProcAddressFunc is avail
- Allow no tool/glue lib's
- Use DEBUG_LOCKUP for lockup symbol trace
Diffstat (limited to 'src/java')
7 files changed, 53 insertions, 49 deletions
diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index c8bf30a..8a71123 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -53,9 +53,6 @@ import com.jogamp.common.jvm.JNILibLoaderBase; * </ul> */ public class DynamicLibraryBundle implements DynamicLookupHelper { - protected static final boolean DEBUG = NativeLibrary.DEBUG; - protected static final boolean DEBUG_LOOKUP = NativeLibrary.DEBUG_LOOKUP; - private DynamicLibraryBundleInfo info; private List<List<String>> toolLibNames; @@ -68,6 +65,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { private int glueLibLoadedNumber; private long toolGetProcAddressHandle; + private boolean toolGetProcAddressComplete; private HashSet<String> toolGetProcAddressFuncNameSet; private List<String> toolGetProcAddressFuncNameList; @@ -86,16 +84,18 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { glueLibNames = info.getGlueLibNames(); loadLibraries(); toolGetProcAddressFuncNameList = info.getToolGetProcAddressFuncNameList(); - if(null!=toolGetProcAddressFuncNameList) { + if( null != toolGetProcAddressFuncNameList ) { toolGetProcAddressFuncNameSet = new HashSet<String>(toolGetProcAddressFuncNameList); toolGetProcAddressHandle = getToolGetProcAddressHandle(); + toolGetProcAddressComplete = 0 != toolGetProcAddressHandle; } else { toolGetProcAddressFuncNameSet = new HashSet<String>(); toolGetProcAddressHandle = 0; + toolGetProcAddressComplete = true; } if(DEBUG) { System.err.println("DynamicLibraryBundle.init Summary: "+info.getClass().getName()); - System.err.println(" toolGetProcAddressFuncNameList: "+toolGetProcAddressFuncNameList); + System.err.println(" toolGetProcAddressFuncNameList: "+toolGetProcAddressFuncNameList+", complete: "+toolGetProcAddressComplete+", 0x"+Long.toHexString(toolGetProcAddressHandle)); System.err.println(" Tool Lib Names : "+toolLibNames); System.err.println(" Tool Lib Loaded: "+getToolLibLoadedNumber()+"/"+getToolLibNumber()+" "+Arrays.toString(toolLibLoaded)+", complete "+isToolLibComplete()); System.err.println(" Glue Lib Names : "+glueLibNames); @@ -111,6 +111,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } toolGetProcAddressFuncNameSet = null; toolGetProcAddressHandle = 0; + toolGetProcAddressComplete = false; for(int i = 0; i<nativeLibraries.size(); i++) { nativeLibraries.get(i).close(); } @@ -143,7 +144,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { * @see DynamicLibraryBundleInfo#getToolLibNames() */ public final boolean isToolLibComplete() { - return getToolLibNumber() == getToolLibLoadedNumber(); + return toolGetProcAddressComplete && getToolLibNumber() == getToolLibLoadedNumber(); } public final boolean isToolLibLoaded() { @@ -173,7 +174,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { * @see DynamicLibraryBundleInfo#getGlueLibNames() */ public final boolean isGlueLibComplete() { - return isGlueLibLoaded(getGlueLibNumber() - 1); + return 0 == getGlueLibNumber() || isGlueLibLoaded(getGlueLibNumber() - 1); } public final boolean isGlueLibLoaded(int i) { @@ -211,32 +212,27 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } private void loadLibraries() { - if( null == toolLibNames || toolLibNames.size() == 0) { - if(DEBUG) { - System.err.println("No Tool native library names given"); - } - return; - } - - if( null == glueLibNames || glueLibNames.size() == 0 ) { - if(DEBUG) { - System.err.println("No Glue native library names given"); - } - return; - } - - toolLibLoadedNumber = 0; int i; toolLibLoaded = new boolean[toolLibNames.size()]; - for(i=0; i<toolLibNames.size(); i++) { + for(i=toolLibNames.size()-1; i>=0; i--) { toolLibLoaded[i] = false; } - glueLibLoaded = new boolean[glueLibNames.size()]; - for(i=0; i<glueLibNames.size(); i++) { + for(i=glueLibNames.size()-1; i>=0; i--) { glueLibLoaded[i] = false; } + + if(DEBUG) { + if( toolLibNames.size() == 0 ) { + System.err.println("No Tool native library names given"); + } + + if( glueLibNames.size() == 0 ) { + System.err.println("No Glue native library names given"); + } + } + toolLibLoadedNumber = 0; ClassLoader loader = getClass().getClassLoader(); NativeLibrary lib = null; @@ -258,7 +254,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } } } - if( !isToolLibLoaded() ) { + if( toolLibNames.size() > 0 && !isToolLibLoaded() ) { if(DEBUG) { System.err.println("No Tool libraries loaded"); } diff --git a/src/java/com/jogamp/common/os/DynamicLinker.java b/src/java/com/jogamp/common/os/DynamicLinker.java index 924a776..a0da9fb 100755 --- a/src/java/com/jogamp/common/os/DynamicLinker.java +++ b/src/java/com/jogamp/common/os/DynamicLinker.java @@ -43,6 +43,9 @@ package com.jogamp.common.os; linking functionality. */ public interface DynamicLinker { + public static final boolean DEBUG = NativeLibrary.DEBUG; + public static final boolean DEBUG_LOOKUP = NativeLibrary.DEBUG_LOOKUP; + public long openLibraryGlobal(String pathname, boolean debug); public long openLibraryLocal(String pathname, boolean debug); public long lookupSymbol(long libraryHandle, String symbolName); diff --git a/src/java/com/jogamp/common/os/DynamicLookupHelper.java b/src/java/com/jogamp/common/os/DynamicLookupHelper.java index 9c343d5..20fd01e 100755 --- a/src/java/com/jogamp/common/os/DynamicLookupHelper.java +++ b/src/java/com/jogamp/common/os/DynamicLookupHelper.java @@ -39,12 +39,17 @@ package com.jogamp.common.os; +import jogamp.common.Debug; + /** Interface callers may use ProcAddressHelper's * {@link com.jogamp.gluegen.runtime.ProcAddressTable#reset(com.jogamp.common.os.DynamicLookupHelper) reset} * helper method to install function pointers into a * ProcAddressTable. This must typically be written with native * code. */ public interface DynamicLookupHelper { + public static final boolean DEBUG = Debug.debug("NativeLibrary"); + public static final boolean DEBUG_LOOKUP = Debug.debug("NativeLibrary.Lookup"); + /** * Try to fetch the function pointer for function 'funcName'. */ diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index b74f30d..69d69b6 100755 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -41,7 +41,6 @@ package com.jogamp.common.os; import com.jogamp.common.util.IOUtil; -import jogamp.common.Debug; import jogamp.common.os.MacOSXDynamicLinkerImpl; import jogamp.common.os.UnixDynamicLinkerImpl; import jogamp.common.os.WindowsDynamicLinkerImpl; @@ -64,9 +63,7 @@ import java.util.*; ProcAddressTable glue code generation style without additional supporting code needed in the generated library. */ -public class NativeLibrary implements DynamicLookupHelper { - protected static final boolean DEBUG = Debug.debug("NativeLibrary"); - protected static final boolean DEBUG_LOOKUP = Debug.debug("NativeLibrary.Lookup"); +public class NativeLibrary implements DynamicLookupHelper { private static DynamicLinker dynLink; private static String[] prefixes; private static String[] suffixes; diff --git a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java index c1be2c2..4eb381f 100755 --- a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java @@ -51,11 +51,19 @@ public class MacOSXDynamicLinkerImpl implements DynamicLinker { } public long lookupSymbol(long libraryHandle, String symbolName) { - return dlsym(libraryHandle, symbolName); + final long addr = dlsym(libraryHandle, symbolName); + if(DEBUG_LOOKUP) { + System.err.println("MaxOSXDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr)); + } + return addr; } public long lookupSymbolGlobal(String symbolName) { - return dlsym(RTLD_DEFAULT, symbolName); + final long addr = dlsym(RTLD_DEFAULT, symbolName); + if(DEBUG_LOOKUP) { + System.err.println("MacOSXDynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); + } + return addr; } public void closeLibrary(long libraryHandle) { diff --git a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java index 677df32..29998bd 100755 --- a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java @@ -50,11 +50,19 @@ public class UnixDynamicLinkerImpl implements DynamicLinker { } public long lookupSymbol(long libraryHandle, String symbolName) { - return dlsym(libraryHandle, symbolName); + final long addr = dlsym(libraryHandle, symbolName); + if(DEBUG_LOOKUP) { + System.err.println("UnixDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr)); + } + return addr; } public long lookupSymbolGlobal(String symbolName) { - return dlsym(RTLD_DEFAULT, symbolName); + final long addr = dlsym(RTLD_DEFAULT, symbolName); + if(DEBUG_LOOKUP) { + System.err.println("UnixDynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); + } + return addr; } public void closeLibrary(long libraryHandle) { diff --git a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java index f5229f4..e7f5b52 100755 --- a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java @@ -2,23 +2,10 @@ package jogamp.common.os; -import java.security.*; - import com.jogamp.common.os.DynamicLinker; public class WindowsDynamicLinkerImpl implements DynamicLinker { - private static boolean DEBUG; - - static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - DEBUG = (System.getProperty("jogamp.debug.NativeLibrary") != null); - return null; - } - }); - } - /** Interface to C language function: <br> <code> BOOL FreeLibrary(HANDLE hLibModule); </code> */ private static native int FreeLibrary(long hLibModule); @@ -61,14 +48,14 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker { addr = GetProcAddressA(libraryHandle, _symbolName); } } - if(DEBUG) { + if(DEBUG_LOOKUP) { System.err.println("WindowsDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr)); } return addr; } public long lookupSymbolGlobal(String symbolName) { - if(DEBUG) { + if(DEBUG_LOOKUP) { System.err.println("lookupSymbolGlobal: Not supported on Windows"); } // allow DynamicLibraryBundle to continue w/ local libs |