aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/os/Platform.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-21 11:06:52 +0200
committerSven Gothel <[email protected]>2011-07-21 11:06:52 +0200
commitdc4b259b6651bdc0cec0895bc74e26e504870c8e (patch)
treeafd356aa28e4091ce12c8c6bc5e3a6b9edf48a58 /src/java/com/jogamp/common/os/Platform.java
parent8e0d7f00c69d79bcdac4be508e5b5999b423e904 (diff)
GlueGen proper size / alignment of primitive and compound types usage [2/2] - Fin
MachineDesction == MD MD.StaticConfig: - enum for all supported static configs (ID -> MD) - verified at runtime: test runtime queried-MD versus static-MD, hard fail if not compatible (size/alignment) SizeThunk primitive sizes: - Add notion of fixed native size (eg. int64_t) and otherwise (eg. long) java struct 'wrappers' code generation: - single class using size/offset arrays of all MachineDescription configurations - at runtime the array idx is queried in static block - type aligment for not fixed-native-size types (SizeThunk, undef long/int) via StructAccessor junit test: - add float test - fix native code - add java (create, write) -> native (verify) test works (tested) on: linux 32/64 and windows 32/64
Diffstat (limited to 'src/java/com/jogamp/common/os/Platform.java')
-rw-r--r--src/java/com/jogamp/common/os/Platform.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index 85567a8..4db5b09 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -28,9 +28,14 @@
package com.jogamp.common.os;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import com.jogamp.common.nio.Buffers;
+
import jogamp.common.os.MachineDescriptionRuntime;
/**
@@ -41,6 +46,7 @@ import jogamp.common.os.MachineDescriptionRuntime;
public class Platform {
public static final boolean JAVA_SE;
+ public static final boolean LITTLE_ENDIAN;
public static final String OS;
public static final String OS_lower;
public static final String OS_VERSION;
@@ -139,6 +145,8 @@ public class Platform {
JAVA_SE = initIsJavaSE();
+ LITTLE_ENDIAN = queryIsLittleEndianImpl();
+
if( ARCH_lower.equals("x86") ||
ARCH_lower.equals("i386") ||
ARCH_lower.equals("i486") ||
@@ -171,13 +179,34 @@ public class Platform {
}
OS_TYPE = getOSTypeImpl();
- machineDescription = MachineDescriptionRuntime.getMachineDescription(getIs32BitByCPUArchImpl());
+ MachineDescription md = MachineDescriptionRuntime.getRuntime();
+ if(null == md) {
+ MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic();
+ md = smd.md;
+ System.err.println("Warning: Using static MachineDescription: "+smd);
+ } else {
+ MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic();
+ if(!md.compatible(smd.md)) {
+ throw new RuntimeException("Incompatible MachineDescriptions:"+Platform.NEWLINE+
+ " Static "+smd+Platform.NEWLINE+
+ " Runtime "+md);
+ }
+ }
+ machineDescription = md;
is32Bit = machineDescription.is32Bit();
}
private Platform() {}
- private static boolean getIs32BitByCPUArchImpl() throws RuntimeException {
+ private static boolean queryIsLittleEndianImpl() {
+ ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order
+ IntBuffer tst_i = tst_b.asIntBuffer();
+ ShortBuffer tst_s = tst_b.asShortBuffer();
+ tst_i.put(0, 0x0A0B0C0D);
+ return 0x0C0D == tst_s.get(0);
+ }
+
+ public static boolean isCPUArch32Bit() throws RuntimeException {
switch( CPU_ARCH ) {
case X86_32:
case ARM:
@@ -257,6 +286,13 @@ public class Platform {
}
/**
+ * Returns true if this machine is little endian, otherwise false.
+ */
+ public static boolean isLittleEndian() {
+ return LITTLE_ENDIAN;
+ }
+
+ /**
* Returns the OS name.
*/
public static String getOS() {