diff options
Diffstat (limited to 'src/java/com/sun/gluegen/runtime')
-rwxr-xr-x | src/java/com/sun/gluegen/runtime/CPU.java | 87 | ||||
-rwxr-xr-x | src/java/com/sun/gluegen/runtime/NativeLibrary.java | 2 |
2 files changed, 59 insertions, 30 deletions
diff --git a/src/java/com/sun/gluegen/runtime/CPU.java b/src/java/com/sun/gluegen/runtime/CPU.java index 0456e9f..ee6c9f5 100755 --- a/src/java/com/sun/gluegen/runtime/CPU.java +++ b/src/java/com/sun/gluegen/runtime/CPU.java @@ -38,6 +38,7 @@ */ package com.sun.gluegen.runtime; +import java.security.*; /** Provides information to autogenerated struct accessors about what kind of data model (32- or 64-bit) is being used by the currently @@ -47,39 +48,67 @@ public class CPU { private static boolean is32Bit; static { - // We don't seem to need an AccessController.doPrivileged() block - // here as these system properties are visible even to unsigned - // applets - // Note: this code is replicated in StructLayout.java - String os = System.getProperty("os.name").toLowerCase(); - String cpu = System.getProperty("os.arch").toLowerCase(); - if ((os.startsWith("windows") && cpu.equals("x86")) || - (os.startsWith("windows") && cpu.equals("arm")) || - (os.startsWith("linux") && cpu.equals("i386")) || - (os.startsWith("linux") && cpu.equals("x86")) || - (os.startsWith("mac os") && cpu.equals("ppc")) || - (os.startsWith("mac os") && cpu.equals("i386")) || - (os.startsWith("darwin") && cpu.equals("ppc")) || - (os.startsWith("darwin") && cpu.equals("i386")) || - (os.startsWith("sunos") && cpu.equals("sparc")) || - (os.startsWith("sunos") && cpu.equals("x86")) || - (os.startsWith("freebsd") && cpu.equals("i386")) || - (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))) { - is32Bit = true; - } else if ((os.startsWith("windows") && cpu.equals("amd64")) || - (os.startsWith("linux") && cpu.equals("amd64")) || - (os.startsWith("linux") && cpu.equals("x86_64")) || - (os.startsWith("linux") && cpu.equals("ia64")) || - (os.startsWith("mac os") && cpu.equals("x86_64")) || - (os.startsWith("darwin") && cpu.equals("x86_64")) || - (os.startsWith("sunos") && cpu.equals("sparcv9")) || - (os.startsWith("sunos") && cpu.equals("amd64"))) { - } else { - throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os + "/" + cpu + ")"); + NativeLibrary.ensureNativeLibLoaded(); + + boolean done=false; + + // Try to use Sun's sun.arch.data.model first .. + int bits = getPointerSizeInBits(); + if ( 32 == bits || 64 == bits ) { + is32Bit = ( 32 == bits ); + done = true ; + } + + if(!done) { + // We don't seem to need an AccessController.doPrivileged() block + // here as these system properties are visible even to unsigned + // applets + // Note: this code is replicated in StructLayout.java + String os = System.getProperty("os.name").toLowerCase(); + String cpu = System.getProperty("os.arch").toLowerCase(); + + if(!done) { + if ((os.startsWith("windows") && cpu.equals("x86")) || + (os.startsWith("windows") && cpu.equals("arm")) || + (os.startsWith("linux") && cpu.equals("i386")) || + (os.startsWith("linux") && cpu.equals("x86")) || + (os.startsWith("mac os") && cpu.equals("ppc")) || + (os.startsWith("mac os") && cpu.equals("i386")) || + (os.startsWith("darwin") && cpu.equals("ppc")) || + (os.startsWith("darwin") && cpu.equals("i386")) || + (os.startsWith("sunos") && cpu.equals("sparc")) || + (os.startsWith("sunos") && cpu.equals("x86")) || + (os.startsWith("freebsd") && cpu.equals("i386")) || + (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))) { + is32Bit = true; + done = true; + } + } + + if(!done) { + if ((os.startsWith("windows") && cpu.equals("amd64")) || + (os.startsWith("linux") && cpu.equals("amd64")) || + (os.startsWith("linux") && cpu.equals("x86_64")) || + (os.startsWith("linux") && cpu.equals("ia64")) || + (os.startsWith("mac os") && cpu.equals("x86_64")) || + (os.startsWith("darwin") && cpu.equals("x86_64")) || + (os.startsWith("sunos") && cpu.equals("sparcv9")) || + (os.startsWith("sunos") && cpu.equals("amd64"))) { + is32Bit = false; + done = true; + } + } + + if(!done) { + throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os + "/" + cpu + ")"); + } } } public static boolean is32Bit() { return is32Bit; } + + public static native int getPointerSizeInBits(); + } diff --git a/src/java/com/sun/gluegen/runtime/NativeLibrary.java b/src/java/com/sun/gluegen/runtime/NativeLibrary.java index 22063a5..c4c9f25 100755 --- a/src/java/com/sun/gluegen/runtime/NativeLibrary.java +++ b/src/java/com/sun/gluegen/runtime/NativeLibrary.java @@ -412,7 +412,7 @@ public class NativeLibrary { } private static volatile boolean loadedDynLinkNativeLib; - private static void ensureNativeLibLoaded() { + static void ensureNativeLibLoaded() { if (!loadedDynLinkNativeLib) { synchronized (NativeLibrary.class) { if (!loadedDynLinkNativeLib) { |