summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-03-28 19:26:16 +0200
committerSven Gothel <[email protected]>2010-03-28 19:26:16 +0200
commitca2ccb29bd3cd4d9c73ca96ce02402888ac9e9af (patch)
treea06c5ea8b8fbf90c4d4a2affdd9afe882caf6baa /src/java/com/jogamp
parentbe3ddc922fda13c0ba344909b3639a2c78c4b809 (diff)
Merge CPU to Platform
Diffstat (limited to 'src/java/com/jogamp')
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/CPU.java100
-rw-r--r--src/java/com/jogamp/gluegen/runtime/Platform.java67
-rw-r--r--src/java/com/jogamp/gluegen/runtime/PointerBuffer.java2
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java4
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/PointerBufferSE.java6
5 files changed, 67 insertions, 112 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/CPU.java b/src/java/com/jogamp/gluegen/runtime/CPU.java
deleted file mode 100755
index 9c2f81e..0000000
--- a/src/java/com/jogamp/gluegen/runtime/CPU.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2005 Sun Microsystems, Inc. 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;
-
-/** Provides information to autogenerated struct accessors about what
- kind of data model (32- or 64-bit) is being used by the currently
- running process. */
-
-public class CPU {
-
- private final static boolean is32Bit;
-
- static {
-
- NativeLibrary.ensureNativeLibLoaded();
-
- // Try to use Sun's sun.arch.data.model first ..
- int bits = getPointerSizeInBits();
- if ( 32 == bits || 64 == bits ) {
- is32Bit = ( 32 == bits );
- }else {
- // 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 = Platform.getOS().toLowerCase();
- String cpu = Platform.getArch().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"))) {
- is32Bit = false;
- }else{
- 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/jogamp/gluegen/runtime/Platform.java b/src/java/com/jogamp/gluegen/runtime/Platform.java
index 7c5e97e..e4090c4 100644
--- a/src/java/com/jogamp/gluegen/runtime/Platform.java
+++ b/src/java/com/jogamp/gluegen/runtime/Platform.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Michael Bien
+ * Copyright (c) 2010, Michael Bien, Sven Gothel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,15 +36,62 @@ import java.nio.ShortBuffer;
/**
* Utility class for querying platform specific properties.
- * @author Michael Bien
+ * @author Michael Bien, Sven Gothel
*/
public class Platform {
public static final boolean JAVA_SE;
public static final boolean LITTLE_ENDIAN;
+ private final static boolean is32Bit;
+ private final static int pointerSizeInBits;
+ private final static String os, arch;
+
static {
- // platform
+ NativeLibrary.ensureNativeLibLoaded();
+
+ // We don't seem to need an AccessController.doPrivileged() block
+ // here as these system properties are visible even to unsigned
+ // applets
+ os = System.getProperty("os.name");
+ arch = System.getProperty("os.arch");
+
+ pointerSizeInBits = getPointerSizeInBitsImpl();
+
+ // Try to use Sun's sun.arch.data.model first ..
+ if ( 32 == pointerSizeInBits || 64 == pointerSizeInBits ) {
+ is32Bit = ( 32 == pointerSizeInBits );
+ }else {
+ String os_lc = os.toLowerCase();
+ String arch_lc = arch.toLowerCase();
+
+ if ((os_lc.startsWith("windows") && arch_lc.equals("x86")) ||
+ (os_lc.startsWith("windows") && arch_lc.equals("arm")) ||
+ (os_lc.startsWith("linux") && arch_lc.equals("i386")) ||
+ (os_lc.startsWith("linux") && arch_lc.equals("x86")) ||
+ (os_lc.startsWith("mac os_lc") && arch_lc.equals("ppc")) ||
+ (os_lc.startsWith("mac os_lc") && arch_lc.equals("i386")) ||
+ (os_lc.startsWith("darwin") && arch_lc.equals("ppc")) ||
+ (os_lc.startsWith("darwin") && arch_lc.equals("i386")) ||
+ (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparc")) ||
+ (os_lc.startsWith("sunos_lc") && arch_lc.equals("x86")) ||
+ (os_lc.startsWith("freebsd") && arch_lc.equals("i386")) ||
+ (os_lc.startsWith("hp-ux") && arch_lc.equals("pa_risc2.0"))) {
+ is32Bit = true;
+ } else if ((os_lc.startsWith("windows") && arch_lc.equals("amd64")) ||
+ (os_lc.startsWith("linux") && arch_lc.equals("amd64")) ||
+ (os_lc.startsWith("linux") && arch_lc.equals("x86_64")) ||
+ (os_lc.startsWith("linux") && arch_lc.equals("ia64")) ||
+ (os_lc.startsWith("mac os_lc") && arch_lc.equals("x86_64")) ||
+ (os_lc.startsWith("darwin") && arch_lc.equals("x86_64")) ||
+ (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparcv9")) ||
+ (os_lc.startsWith("sunos_lc") && arch_lc.equals("amd64"))) {
+ is32Bit = false;
+ }else{
+ throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os_lc + "/" + arch_lc + ")");
+ }
+ }
+
// fast path
boolean se = System.getProperty("java.runtime.name").indexOf("Java SE") != -1;
@@ -69,6 +116,8 @@ public class Platform {
private Platform() {}
+ private static native int getPointerSizeInBitsImpl();
+
/**
* Returns true only if this program is running on the Java Standard Edition.
*/
@@ -87,21 +136,27 @@ public class Platform {
* Returns the OS name.
*/
public static String getOS() {
- return System.getProperty("os.name");
+ return os;
}
/**
* Returns the CPU architecture String.
*/
public static String getArch() {
- return System.getProperty("os.arch");
+ return arch;
}
/**
* Returns true if this JVM is a 32bit JVM.
*/
public static boolean is32Bit() {
- return CPU.is32Bit();
+ return is32Bit;
+ }
+
+ public static int getPointerSizeInBits() {
+ return pointerSizeInBits;
}
}
+
+
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
index bd73e56..3bff090 100644
--- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
@@ -87,7 +87,7 @@ public abstract class PointerBuffer {
}
public static int elementSize() {
- return CPU.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG;
+ return Platform.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG;
}
public int limit() {
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
index 27082b6..0ae7af6 100755
--- a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
@@ -59,7 +59,7 @@ final class PointerBufferME_CDC_FP extends PointerBuffer {
if (0 > idx || idx >= capacity) {
throw new IndexOutOfBoundsException();
}
- if (CPU.is32Bit()) {
+ if (Platform.is32Bit()) {
return pb.get(idx);
} else {
idx = idx << 1; // 8-byte to 4-byte offset
@@ -77,7 +77,7 @@ final class PointerBufferME_CDC_FP extends PointerBuffer {
throw new IndexOutOfBoundsException();
}
backup[idx] = v;
- if (CPU.is32Bit()) {
+ if (Platform.is32Bit()) {
pb.put(idx, (int) v);
} else {
idx = idx << 1; // 8-byte to 4-byte offset
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java
index 9c67dda..6f131a9 100755
--- a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java
@@ -48,7 +48,7 @@ final class PointerBufferSE extends PointerBuffer {
PointerBufferSE(ByteBuffer bb) {
super(bb);
- if (CPU.is32Bit()) {
+ if (Platform.is32Bit()) {
this.pb = bb.asIntBuffer();
} else {
this.pb = bb.asLongBuffer();
@@ -64,7 +64,7 @@ final class PointerBufferSE extends PointerBuffer {
if (0 > idx || idx >= capacity) {
throw new IndexOutOfBoundsException();
}
- if (CPU.is32Bit()) {
+ if (Platform.is32Bit()) {
return ((IntBuffer) pb).get(idx);
} else {
return ((LongBuffer) pb).get(idx);
@@ -76,7 +76,7 @@ final class PointerBufferSE extends PointerBuffer {
throw new IndexOutOfBoundsException();
}
backup[idx] = v;
- if (CPU.is32Bit()) {
+ if (Platform.is32Bit()) {
((IntBuffer) pb).put(idx, (int) v);
} else {
((LongBuffer) pb).put(idx, v);