diff options
Diffstat (limited to 'src/java/com/jogamp/common/jvm')
-rw-r--r-- | src/java/com/jogamp/common/jvm/JNILibLoaderBase.java | 130 |
1 files changed, 79 insertions, 51 deletions
diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java index 9b1865f..3ba8dff 100644 --- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java +++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java @@ -61,7 +61,18 @@ import jogamp.common.Debug; import jogamp.common.os.PlatformPropsImpl; public class JNILibLoaderBase { - public static final boolean DEBUG = Debug.debug("JNILibLoader"); + public static final boolean DEBUG; + protected static final boolean PERF; + + static { + Debug.initSingleton(); + DEBUG = Debug.debug("JNILibLoader"); + PERF = DEBUG || PropertyAccess.isPropertyDefined("jogamp.debug.JNILibLoader.Perf", true); + } + + private static final Object perfSync = new Object(); + private static long perfTotal = 0; + private static long perfCount = 0; public interface LoaderAction { /** @@ -177,6 +188,7 @@ public class JNILibLoaderBase { msg.append(")"); System.err.println(msg.toString()); } + final long t0 = PERF ? System.currentTimeMillis() : 0; // 'Platform.currentTimeMillis()' not yet available! boolean ok = false; @@ -195,28 +207,9 @@ public class JNILibLoaderBase { if (DEBUG) { System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: nativeLibraryPath: %s%n", nativeLibraryPath); } - final ClassLoader cl = classFromJavaJar.getClassLoader(); - final URL nativeLibraryURI = cl.getResource(nativeLibraryPath); - if (null != nativeLibraryURI) { - // We probably have one big-fat jar file, containing java classes - // and all native platform libraries under 'natives/os.and.arch'! - final Uri nativeJarURI = JarUtil.getJarFileUri( jarSubUriRoot.getEncoded().concat(jarBasename) ); - try { - if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) { - ok = true; - if (DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: fat: %s -> %s%n", jarBasename, nativeJarURI); - } - } - } catch(final Exception e) { - if(DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: Caught %s%n", e.getMessage()); - e.printStackTrace(); - } - } - } - if (!ok) { - // We assume one slim native jar file per 'os.and.arch'! + { + // Attempt-1 a 'one slim native jar file' per 'os.and.arch' layout + // with native platform libraries under 'natives/os.and.arch'! final Uri nativeJarURI = JarUtil.getJarFileUri( jarSubUriRoot.getEncoded().concat(nativeJarBasename) ); if (DEBUG) { @@ -224,7 +217,7 @@ public class JNILibLoaderBase { } try { - ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, null /* nativeLibraryPath */); + ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath); } catch(final Exception e) { if(DEBUG) { System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: Caught %s%n", e.getMessage()); @@ -233,40 +226,75 @@ public class JNILibLoaderBase { } } if (!ok) { - // Attempt to find via ClassLoader and Native-Jar-Tag, - // assuming one slim native jar file per 'os.and.arch'! - final String moduleName; + final ClassLoader cl = classFromJavaJar.getClassLoader(); { - final String packageName = classFromJavaJar.getPackage().getName(); - final int idx = packageName.lastIndexOf('.'); - if( 0 <= idx ) { - moduleName = packageName.substring(idx+1); - } else { - moduleName = packageName; + // Attempt-2 a 'one big-fat jar file' layout, containing java classes + // and all native platform libraries under 'natives/os.and.arch' per platform! + final URL nativeLibraryURI = cl.getResource(nativeLibraryPath); + if (null != nativeLibraryURI) { + final Uri nativeJarURI = JarUtil.getJarFileUri( jarSubUriRoot.getEncoded().concat(jarBasename) ); + try { + if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) { + ok = true; + if (DEBUG) { + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: fat: %s -> %s%n", jarBasename, nativeJarURI); + } + } + } catch(final Exception e) { + if(DEBUG) { + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: Caught %s%n", e.getMessage()); + e.printStackTrace(); + } + } } } - final String os_and_arch_dot = PlatformPropsImpl.os_and_arch.replace('-', '.'); - final String nativeJarTagClassName = nativeJarTagPackage + "." + moduleName + "." + os_and_arch_dot + ".TAG"; // TODO: sync with gluegen-cpptasks-base.xml - try { - if(DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ClassLoader/TAG: Locating module %s, os.and.arch %s: %s%n", - moduleName, os_and_arch_dot, nativeJarTagClassName); - } - final Uri nativeJarTagClassJarURI = JarUtil.getJarUri(nativeJarTagClassName, cl); - if (DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ClassLoader/TAG: %s -> %s%n", nativeJarTagClassName, nativeJarTagClassJarURI); + if (!ok) { + // Attempt-3 to find via ClassLoader and Native-Jar-Tag, + // assuming one slim native jar file per 'os.and.arch' + // and native platform libraries under 'natives/os.and.arch'! + final String moduleName; + { + final String packageName = classFromJavaJar.getPackage().getName(); + final int idx = packageName.lastIndexOf('.'); + if( 0 <= idx ) { + moduleName = packageName.substring(idx+1); + } else { + moduleName = packageName; + } } - ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarTagClassJarURI, null /* nativeLibraryPath */); - } catch (final Exception e ) { - if(DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: Caught %s%n", e.getMessage()); - e.printStackTrace(); + final String os_and_arch_dot = PlatformPropsImpl.os_and_arch.replace('-', '.'); + final String nativeJarTagClassName = nativeJarTagPackage + "." + moduleName + "." + os_and_arch_dot + ".TAG"; // TODO: sync with gluegen-cpptasks-base.xml + try { + if(DEBUG) { + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ClassLoader/TAG: Locating module %s, os.and.arch %s: %s%n", + moduleName, os_and_arch_dot, nativeJarTagClassName); + } + final Uri nativeJarTagClassJarURI = JarUtil.getJarUri(nativeJarTagClassName, cl); + if (DEBUG) { + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ClassLoader/TAG: %s -> %s%n", nativeJarTagClassName, nativeJarTagClassJarURI); + } + ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarTagClassJarURI, nativeLibraryPath); + } catch (final Exception e ) { + if(DEBUG) { + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: Caught %s%n", e.getMessage()); + e.printStackTrace(); + } } } } - if (DEBUG) { - System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ok: %b%n", ok); + if (DEBUG || PERF) { + final long tNow = System.currentTimeMillis() - t0; + final long tTotal, tCount; + synchronized(perfSync) { + tCount = perfCount+1; + tTotal = perfTotal + tNow; + perfTotal = tTotal; + perfCount = tCount; + } + final double tAvrg = tTotal / (double)tCount; + System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl.X: %s / %s -> ok: %b; duration: now %d ms, total %d ms (count %d, avrg %.3f ms)%n", + jarBasename, nativeJarBasename, ok, tNow, tTotal, tCount, tAvrg); } return ok; } @@ -585,7 +613,7 @@ public class JNILibLoaderBase { if(DEBUG) { System.err.println("ERROR (retry w/ enumLibPath) - "+ex1.getMessage()); } - final List<String> possiblePaths = NativeLibrary.enumerateLibraryPaths(libraryName, libraryName, libraryName, true, cl); + final List<String> possiblePaths = NativeLibrary.enumerateLibraryPaths(libraryName, libraryName, libraryName, cl); // Iterate down these and see which one if any we can actually find. for (final Iterator<String> iter = possiblePaths.iterator(); 0 == mode && iter.hasNext(); ) { final String path = iter.next(); |