summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsg215889 <[email protected]>2009-07-28 18:57:07 -0700
committersg215889 <[email protected]>2009-07-28 18:57:07 -0700
commitabea54842158e588112f6e35d1ba3c5f069dfc29 (patch)
tree6e311b8d655a0e04d3ad1c90cb06a67256863aaf
parentf607cdf272dffbd45e6389c5715a9596e85c2a90 (diff)
Fix: Native CPU 32/64 bit detection; Tested on CVM/J2SE
-rwxr-xr-xmake/build.xml23
-rw-r--r--make/make.gluegen.all.linux-x86.sh13
-rw-r--r--make/make.gluegen.all.linux-x86_64.sh12
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/CPU.java25
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/NativeLibrary.java2
-rw-r--r--src/java/com/sun/gluegen/test/TestPointerBufferEndian.java5
-rw-r--r--src/java/com/sun/gluegen/test/TestStructAccessorEndian.java5
-rw-r--r--src/native/common/CPU.c10
8 files changed, 54 insertions, 41 deletions
diff --git a/make/build.xml b/make/build.xml
index cc538ae..51aaf3d 100755
--- a/make/build.xml
+++ b/make/build.xml
@@ -240,7 +240,7 @@
</target>
<target name="declare.win32" depends="declare.win32.vc6,declare.win32.vc7,declare.win32.vc8,declare.win32.vc8_x64,declare.win32.vc9,declare.win32.mingw" if="isWindows" >
- <property name="c.src.dir" value="windows" />
+ <property name="c.src.dir.os" value="windows" />
<property name="java.includes.dir.platform" value="${java.includes.dir}/win32" />
</target>
@@ -263,7 +263,7 @@
</target>
<target name="declare.linux" depends="declare.linux.x86,declare.linux.amd64,declare.linux.ia64" if="isLinux" >
- <property name="c.src.dir" value="unix" />
+ <property name="c.src.dir.os" value="unix" />
<property name="java.includes.dir.platform" value="${java.includes.dir}/linux" />
</target>
@@ -286,7 +286,7 @@
</target>
<target name="declare.solaris" depends="declare.solaris32,declare.solarisSparcv9,declare.solarisAMD64" if="isSolaris" >
- <property name="c.src.dir" value="unix" />
+ <property name="c.src.dir.os" value="unix" />
<property name="java.includes.dir.platform" value="${java.includes.dir}/solaris" />
</target>
@@ -294,7 +294,7 @@
<echo message="MacOSX" />
<property name="compiler.cfg.id" value="compiler.cfg.macosx" />
<property name="linker.cfg.id" value="linker.cfg.macosx" />
- <property name="c.src.dir" value="macosx" />
+ <property name="c.src.dir.os" value="macosx" />
<property name="java.includes.dir.platform" value="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Headers" />
</target>
@@ -302,7 +302,7 @@
<echo message="FreeBSD" />
<property name="compiler.cfg.id" value="compiler.cfg.freebsd" />
<property name="linker.cfg.id" value="linker.cfg.linux" />
- <property name="c.src.dir" value="unix" />
+ <property name="c.src.dir.os" value="unix" />
<property name="java.includes.dir.freebsd" value="${java.includes.dir}/freebsd" />
</target>
@@ -310,7 +310,7 @@
<echo message="HP-UX" />
<property name="compiler.cfg.id" value="compiler.cfg.hpux" />
<property name="linker.cfg.id" value="linker.cfg.hpux" />
- <property name="c.src.dir" value="unix" />
+ <property name="c.src.dir.os" value="unix" />
<property name="java.includes.dir.hpux" value="${java.includes.dir}/hp-ux" />
</target>
@@ -318,7 +318,7 @@
<!-- Common properties -->
<property name="java.includes.dir" value="${java.home.dir}/include" /> <!-- NOTE: this MUST be relative for FileSet -->
- <property name="c.compiler.src.files" value="src/native/${c.src.dir}/*.c" />
+ <property name="c.compiler.src.files.os" value="src/native/${c.src.dir.os}/*.c" />
<property name="output.lib.name" value="gluegen-rt" />
</target>
@@ -340,7 +340,7 @@
</target>
<target name="c.build" depends="c.configure" unless="build.javaonly" >
- <fail message="Requires '${c.compiler.src.files}'" unless="c.compiler.src.files"/>
+ <fail message="Requires '${c.compiler.src.files.os}'" unless="c.compiler.src.files.os"/>
<fail message="Requires '${compiler.cfg.id}'" unless="compiler.cfg.id"/>
<fail message="Requires '${linker.cfg.id}'" unless="linker.cfg.id"/>
<fail message="Requires '${output.lib.name}'" unless="output.lib.name"/>
@@ -356,7 +356,9 @@
<mkdir dir="${build}/obj" />
- <echo message="Compiling ${c.compiler.src.files}" />
+ <property name="c.compiler.src.files.common" value="src/native/common/*.c" />
+
+ <echo message="Compiling ${c.compiler.src.files.os} ${c.compiler.src.files.common}" />
<echo message="user.dir=${user.dir}" />
<cc outtype="shared"
@@ -378,7 +380,8 @@
<fileset dir="..">
<patternset>
- <include name="${c.compiler.src.files}" />
+ <include name="${c.compiler.src.files.os}" />
+ <include name="${c.compiler.src.files.common}" />
</patternset>
</fileset>
diff --git a/make/make.gluegen.all.linux-x86.sh b/make/make.gluegen.all.linux-x86.sh
index 58c4215..87352c3 100644
--- a/make/make.gluegen.all.linux-x86.sh
+++ b/make/make.gluegen.all.linux-x86.sh
@@ -3,12 +3,13 @@
. ../../setenv-build-jogl-x86.sh
# -Dc.compiler.debug=true
+# -Dgluegen.cpptasks.detected.os=true \
+# -DisUnix=true \
+# -DisLinux=true \
+# -DisLinuxX86=true \
+# -DisX11=true \
-ant -v \
+ant \
-Drootrel.build=build-x86 \
- -Dgluegen.cpptasks.detected.os=true \
- -DisUnix=true \
- -DisLinux=true \
- -DisLinuxX86=true \
- -DisX11=true \
+ -Dos.arch=x86 \
$* 2>&1 | tee make.gluegen.all.linux-x86.log
diff --git a/make/make.gluegen.all.linux-x86_64.sh b/make/make.gluegen.all.linux-x86_64.sh
index a787c57..98ef4ed 100644
--- a/make/make.gluegen.all.linux-x86_64.sh
+++ b/make/make.gluegen.all.linux-x86_64.sh
@@ -3,12 +3,12 @@
. ../../setenv-build-jogl-x86_64.sh
# -Dc.compiler.debug=true
+# -Dgluegen.cpptasks.detected.os=true \
+# -DisUnix=true \
+# -DisLinux=true \
+# -DisLinuxAMD64=true \
+# -DisX11=true \
-ant -v \
+ant \
-Drootrel.build=build-x86_64 \
- -Dgluegen.cpptasks.detected.os=true \
- -DisUnix=true \
- -DisLinux=true \
- -DisLinuxAMD64=true \
- -DisX11=true \
$* 2>&1 | tee make.gluegen.all.linux-x86_64.log
diff --git a/src/java/com/sun/gluegen/runtime/CPU.java b/src/java/com/sun/gluegen/runtime/CPU.java
index c7e6bc1..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,23 +48,16 @@ public class CPU {
private static boolean is32Bit;
static {
+ NativeLibrary.ensureNativeLibLoaded();
+
boolean done=false;
// Try to use Sun's sun.arch.data.model first ..
- int bits = 0;
- try {
- String bitS =
- (String) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return System.getProperty("sun.arch.data.model");
- }
- });
- if(null!=bitS && bitS.length()>0) {
- bits = Integer.parseInt(bitS);
- is32Bit = ( 32 == bits );
- done = true ;
- }
- } catch (NumberFormatException nfe) {}
+ 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
@@ -114,4 +108,7 @@ public class 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) {
diff --git a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java
index cd375af..ba77eed 100644
--- a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java
+++ b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java
@@ -8,10 +8,11 @@ public class TestPointerBufferEndian {
public static void main (String[] args) {
boolean direct = args.length>0 && args[0].equals("-direct");
boolean ok = true;
- String bits = System.getProperty("sun.arch.data.model");
+ int bitsPtr = CPU.getPointerSizeInBits();
+ String bitsProp = System.getProperty("sun.arch.data.model");
String os = System.getProperty("os.name");
String cpu = System.getProperty("os.arch");
- System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bits+">");
+ System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">");
System.out.println("CPU is: "+ (CPU.is32Bit()?"32":"64") + " bit");
System.out.println("Buffer is in: "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian");
PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(3);
diff --git a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java
index fa28cb6..dc53a10 100644
--- a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java
+++ b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java
@@ -7,10 +7,11 @@ import java.nio.*;
public class TestStructAccessorEndian {
public static void main (String args[]) {
boolean ok = true;
- String bits = System.getProperty("sun.arch.data.model");
+ int bitsPtr = CPU.getPointerSizeInBits();
+ String bitsProp = System.getProperty("sun.arch.data.model");
String os = System.getProperty("os.name");
String cpu = System.getProperty("os.arch");
- System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bits+">");
+ System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">");
System.out.println("CPU is: "+ (CPU.is32Bit()?"32":"64") + " bit");
System.out.println("Buffer is in: "+ (BufferFactory.isLittleEndian()?"little":"big") + " endian");
ByteBuffer tst = BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_LONG * 3);
diff --git a/src/native/common/CPU.c b/src/native/common/CPU.c
new file mode 100644
index 0000000..8c4135c
--- /dev/null
+++ b/src/native/common/CPU.c
@@ -0,0 +1,10 @@
+
+#include <jni.h>
+
+#include <assert.h>
+
+JNIEXPORT jint JNICALL
+Java_com_sun_gluegen_runtime_CPU_getPointerSizeInBits(JNIEnv *env, jclass _unused) {
+ return sizeof(void *) * 8;
+}
+