summaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/common/os/MachineDescription.java223
-rwxr-xr-xsrc/java/com/jogamp/common/os/NativeLibrary.java64
-rw-r--r--src/java/com/jogamp/common/os/Platform.java256
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java18
-rw-r--r--src/java/com/jogamp/common/util/VersionUtil.java5
-rw-r--r--src/java/com/jogamp/gluegen/CMethodBindingEmitter.java1
-rw-r--r--src/java/com/jogamp/gluegen/DebugEmitter.java1
-rw-r--r--src/java/com/jogamp/gluegen/GlueEmitter.java2
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java5
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java2
-rw-r--r--src/java/com/jogamp/gluegen/StructLayout.java53
-rw-r--r--src/java/com/jogamp/gluegen/cgram/GnuCParser.g4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/HeaderParser.g12
-rw-r--r--src/java/com/jogamp/gluegen/cgram/StdCParser.g4
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Field.java2
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java82
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java46
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java46
-rwxr-xr-xsrc/java/com/jogamp/gluegen/cgram/types/SizeThunk.java20
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/Type.java2
-rw-r--r--src/java/com/jogamp/gluegen/package.html90
22 files changed, 566 insertions, 376 deletions
diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java
new file mode 100644
index 0000000..a407187
--- /dev/null
+++ b/src/java/com/jogamp/common/os/MachineDescription.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.common.os;
+
+import com.jogamp.common.util.VersionUtil;
+
+/**
+ * For alignment and size see {@link com.jogamp.gluegen}
+ */
+public class MachineDescription {
+ final private boolean runtimeValidated;
+
+ final private boolean littleEndian;
+
+ final private int int8SizeInBytes = 1;
+ final private int int16SizeInBytes = 2;
+ final private int int32SizeInBytes = 4;
+ final private int int64SizeInBytes = 8;
+
+ final private int charSizeInBytes;
+ final private int shortSizeInBytes;
+ final private int intSizeInBytes;
+ final private int longSizeInBytes;
+ final private int floatSizeInBytes;
+ final private int doubleSizeInBytes;
+ final private int pointerSizeInBytes;
+ final private int pageSizeInBytes;
+ final private boolean is32Bit;
+
+ final private int int8AlignmentInBytes;
+ final private int int16AlignmentInBytes;
+ final private int int32AlignmentInBytes;
+ final private int int64AlignmentInBytes;
+ final private int charAlignmentInBytes;
+ final private int shortAlignmentInBytes;
+ final private int intAlignmentInBytes;
+ final private int longAlignmentInBytes;
+ final private int floatAlignmentInBytes;
+ final private int doubleAlignmentInBytes;
+ final private int pointerAlignmentInBytes;
+
+ public MachineDescription(boolean runtimeValidated,
+
+ boolean littleEndian,
+
+ int charSizeInBytes,
+ int shortSizeInBytes,
+ int intSizeInBytes,
+ int longSizeInBytes,
+ int floatSizeInBytes,
+ int doubleSizeInBytes,
+ int pointerSizeInBytes,
+ int pageSizeInBytes,
+
+ int int8AlignmentInBytes,
+ int int16AlignmentInBytes,
+ int int32AlignmentInBytes,
+ int int64AlignmentInBytes,
+ int charAlignmentInBytes,
+ int shortAlignmentInBytes,
+ int intAlignmentInBytes,
+ int longAlignmentInBytes,
+ int floatAlignmentInBytes,
+ int doubleAlignmentInBytes,
+ int pointerAlignmentInBytes) {
+ this.runtimeValidated = runtimeValidated;
+
+ this.littleEndian = littleEndian;
+
+ this.charSizeInBytes = charSizeInBytes;
+ this.shortSizeInBytes = shortSizeInBytes;
+ this.intSizeInBytes = intSizeInBytes;
+ this.longSizeInBytes = longSizeInBytes;
+ this.floatSizeInBytes = floatSizeInBytes;
+ this.doubleSizeInBytes = doubleSizeInBytes;
+ this.pointerSizeInBytes = pointerSizeInBytes;
+ this.pageSizeInBytes = pageSizeInBytes;
+ this.is32Bit = 4 == pointerSizeInBytes;
+
+ this.int8AlignmentInBytes = int8AlignmentInBytes;
+ this.int16AlignmentInBytes = int16AlignmentInBytes;
+ this.int32AlignmentInBytes = int32AlignmentInBytes;
+ this.int64AlignmentInBytes = int64AlignmentInBytes;
+ this.charAlignmentInBytes = charAlignmentInBytes;
+ this.shortAlignmentInBytes = shortAlignmentInBytes;
+ this.intAlignmentInBytes = intAlignmentInBytes;
+ this.longAlignmentInBytes = longAlignmentInBytes;
+ this.floatAlignmentInBytes = floatAlignmentInBytes;
+ this.doubleAlignmentInBytes = doubleAlignmentInBytes;
+ this.pointerAlignmentInBytes = pointerAlignmentInBytes;
+ }
+
+ /**
+ * @return true if all values are validated at runtime, otherwise false (i.e. for static compilation w/ preset values)
+ */
+ public final boolean isRuntimeValidated() {
+ return runtimeValidated;
+ }
+
+ /**
+ * Returns true only if this system uses little endian byte ordering.
+ */
+ public final boolean isLittleEndian() {
+ return littleEndian;
+ }
+
+ /**
+ * Returns true if this JVM/ARCH is 32bit.
+ */
+ public final boolean is32Bit() {
+ return is32Bit;
+ }
+
+ /**
+ * Returns true if this JVM/ARCH is 64bit.
+ */
+ public final boolean is64Bit() {
+ return !is32Bit;
+ }
+
+ public final int charSizeInBytes() { return charSizeInBytes; }
+ public final int shortSizeInBytes() { return shortSizeInBytes; }
+ public final int intSizeInBytes() { return intSizeInBytes; }
+ public final int longSizeInBytes() { return longSizeInBytes; }
+ public final int int8SizeInBytes() { return int8SizeInBytes; }
+ public final int int16SizeInBytes() { return int16SizeInBytes; }
+ public final int int32SizeInBytes() { return int32SizeInBytes; }
+ public final int int64SizeInBytes() { return int64SizeInBytes; }
+ public final int floatSizeInBytes() { return floatSizeInBytes; }
+ public final int doubleSizeInBytes() { return doubleSizeInBytes; }
+ public final int pointerSizeInBytes() { return pointerSizeInBytes; }
+ public final int pageSizeInBytes() { return pageSizeInBytes; }
+
+ public final int charAlignmentInBytes() { return charAlignmentInBytes; }
+ public final int shortAlignmentInBytes() { return shortAlignmentInBytes; }
+ public final int intAlignmentInBytes() { return intAlignmentInBytes; }
+ public final int longAlignmentInBytes() { return longAlignmentInBytes; }
+ public final int int8AlignmentInBytes() { return int8AlignmentInBytes; }
+ public final int int16AlignmentInBytes() { return int16AlignmentInBytes; }
+ public final int int32AlignmentInBytes() { return int32AlignmentInBytes; }
+ public final int int64AlignmentInBytes() { return int64AlignmentInBytes; }
+ public final int floatAlignmentInBytes() { return floatAlignmentInBytes; }
+ public final int doubleAlignmentInBytes() { return doubleAlignmentInBytes; }
+ public final int pointerAlignmentInBytes() { return pointerAlignmentInBytes; }
+
+ /**
+ * @return number of pages required for size in bytes
+ */
+ public int pageCount(int size) {
+ return ( size + ( pageSizeInBytes - 1) ) / pageSizeInBytes ; // integer arithmetic
+ }
+
+ /**
+ * @return page aligned size in bytes
+ */
+ public int pageAlignedSize(int size) {
+ return pageCount(size) * pageSizeInBytes;
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+ sb.append("MachineDescription: runtimeValidated ").append(isRuntimeValidated()).append(", littleEndian ").append(isLittleEndian()).append(", 32Bit ").append(is32Bit()).append(", primitive size / alignment:").append(Platform.getNewline());
+ sb.append(" char ").append(charSizeInBytes) .append(" / ").append(charAlignmentInBytes);
+ sb.append(", short ").append(shortSizeInBytes) .append(" / ").append(shortAlignmentInBytes);
+ sb.append(", int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes);
+ sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline());
+ sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes);
+ sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes);
+ sb.append(", int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes);
+ sb.append(", int64 ").append(int64SizeInBytes) .append(" / ").append(int64AlignmentInBytes).append(Platform.getNewline());
+ sb.append(" float ").append(floatSizeInBytes) .append(" / ").append(floatAlignmentInBytes);
+ sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes);
+ sb.append(", pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes);
+ sb.append(", page ").append(pageSizeInBytes);
+ return sb;
+ }
+
+ @Override
+ public String toString() {
+ return toString(null).toString();
+ }
+
+}
diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index 558aa3e..30075fd 100755
--- a/src/java/com/jogamp/common/os/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -59,54 +59,39 @@ import java.util.*;
supporting code needed in the generated library. */
public class NativeLibrary implements DynamicLookupHelper {
- private static final int WINDOWS = 1;
- private static final int UNIX = 2;
- private static final int MACOSX = 3;
protected static boolean DEBUG;
protected static boolean DEBUG_LOOKUP;
- private static int platform;
private static DynamicLinker dynLink;
private static String[] prefixes;
private static String[] suffixes;
static {
- // Determine platform we're running on
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- String osName = System.getProperty("os.name").toLowerCase();
- if (osName.startsWith("wind")) {
- platform = WINDOWS;
- } else if (osName.startsWith("mac os x")) {
- platform = MACOSX;
- } else {
- platform = UNIX;
- }
-
- DEBUG = (System.getProperty("jogamp.debug.NativeLibrary") != null);
- DEBUG_LOOKUP = (System.getProperty("jogamp.debug.NativeLibrary.Lookup") != null);
-
- return null;
- }
- });
// Instantiate dynamic linker implementation
- switch (platform) {
+ switch (Platform.OS_TYPE) {
case WINDOWS:
dynLink = new WindowsDynamicLinkerImpl();
prefixes = new String[] { "" };
suffixes = new String[] { ".dll" };
break;
- case UNIX:
- dynLink = new UnixDynamicLinkerImpl();
- prefixes = new String[] { "lib" };
- suffixes = new String[] { ".so" };
- break;
- case MACOSX:
+
+ case MACOS:
dynLink = new MacOSXDynamicLinkerImpl();
prefixes = new String[] { "lib", "" };
suffixes = new String[] { ".dylib", ".jnilib", "" };
break;
+
+ /*
+ case FREEBSD:
+ case DALVIK:
+ case SUNOS:
+ case HPUX:
+ case OPENKODE:
+ case LINUX: */
default:
- throw new InternalError("Platform not initialized properly");
+ dynLink = new UnixDynamicLinkerImpl();
+ prefixes = new String[] { "lib" };
+ suffixes = new String[] { ".so" };
+ break;
}
}
@@ -306,7 +291,7 @@ public class NativeLibrary implements DynamicLookupHelper {
addPaths(userDir, baseNames, paths);
// Add probable Mac OS X-specific paths
- if (platform == MACOSX) {
+ if (Platform.OS_TYPE == Platform.OSType.MACOS) {
// Add historical location
addPaths("/Library/Frameworks/" + libName + ".Framework", baseNames, paths);
// Add current location
@@ -325,15 +310,22 @@ public class NativeLibrary implements DynamicLookupHelper {
private static String selectName(String windowsLibName,
String unixLibName,
String macOSXLibName) {
- switch (platform) {
+ switch (Platform.OS_TYPE) {
case WINDOWS:
return windowsLibName;
- case UNIX:
- return unixLibName;
- case MACOSX:
+
+ case MACOS:
return macOSXLibName;
+
+ /*
+ case FREEBSD:
+ case DALVIK:
+ case SUNOS:
+ case HPUX:
+ case OPENKODE:
+ case LINUX: */
default:
- throw new InternalError();
+ return unixLibName;
}
}
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index 0775f37..680d5be 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -26,18 +26,13 @@
* or implied, of JogAmp Community.
*/
-/*
- * Created on Sunday, March 28 2010 14:43
- */
package com.jogamp.common.os;
-import com.jogamp.common.nio.Buffers;
-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-import java.nio.ShortBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import jogamp.common.os.MachineDescriptionRuntime;
+
/**
* Utility class for querying platform specific properties.
* @author Michael Bien
@@ -46,97 +41,157 @@ import java.security.PrivilegedAction;
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;
public static final String ARCH;
+ public static final String ARCH_lower;
public static final String JAVA_VENDOR;
public static final String JAVA_VENDOR_URL;
public static final String JAVA_VERSION;
public static final String NEWLINE;
+ public enum OSType {
+ LINUX(0), FREEBSD(1), DALVIK(2), MACOS(3), SUNOS(4), HPUX(5), WINDOWS(6), OPENKODE(7);
+
+ public final int id;
+
+ OSType(int id){
+ this.id = id;
+ }
+ }
+ public static final OSType OS_TYPE;
+
+ public enum CPUType {
+ X86(0), IA(1), ARM(2), SPARC(3), PA_RISC(4), PPC(5);
+
+ public final int id;
+
+ CPUType(int id){
+ this.id = id;
+ }
+ }
+ public static final CPUType CPU_TYPE;
+
+ public enum CPUArch {
+ X86_32(0), X86_64(1), IA64(2), ARM_32(3), SPARC_32(4), SPARCV9_64(5), PA_RISC2_0(6), PPC(7);
+
+ public final int id;
+
+ CPUArch(int id){
+ this.id = id;
+ }
+ }
+ public static final CPUArch CPU_ARCH;
+
private static final boolean is32Bit;
- private static final int pointerSizeInBits;
- private static final int pageSize;
+ private static final MachineDescription machineDescription;
+
static {
// 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");
+ OS_lower = OS.toLowerCase();
OS_VERSION = System.getProperty("os.version");
ARCH = System.getProperty("os.arch");
+ ARCH_lower = ARCH.toLowerCase();
JAVA_VENDOR = System.getProperty("java.vendor");
JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
JAVA_VERSION = System.getProperty("java.version");
NEWLINE = System.getProperty("line.separator");
JAVA_SE = initIsJavaSE();
- LITTLE_ENDIAN = initByteOrder();
- boolean libsLoaded = true;
- try{
- NativeLibrary.ensureNativeLibLoaded();
- }catch (UnsatisfiedLinkError err){
- libsLoaded = false;
- }
+ if( ARCH_lower.equals("x86") ||
+ ARCH_lower.equals("i386") ||
+ ARCH_lower.equals("i486") ||
+ ARCH_lower.equals("i586") ||
+ ARCH_lower.equals("i686") ) {
+ CPU_ARCH = CPUArch.X86_32;
+ CPU_TYPE = CPUType.X86;
+ } else if( ARCH_lower.equals("x86_64") ||
+ ARCH_lower.equals("amd64") ) {
+ CPU_ARCH = CPUArch.X86_64;
+ CPU_TYPE = CPUType.X86;
+ } else if( ARCH_lower.equals("ia64") ) {
+ CPU_ARCH = CPUArch.IA64;
+ CPU_TYPE = CPUType.IA;
+ } else if( ARCH_lower.equals("arm") ) {
+ CPU_ARCH = CPUArch.ARM_32;
+ CPU_TYPE = CPUType.ARM;
+ } else if( ARCH_lower.equals("sparc") ) {
+ CPU_ARCH = CPUArch.SPARC_32;
+ CPU_TYPE = CPUType.SPARC;
+ } else if( ARCH_lower.equals("sparcv9") ) {
+ CPU_ARCH = CPUArch.SPARCV9_64;
+ CPU_TYPE = CPUType.SPARC;
+ } else if( ARCH_lower.equals("pa_risc2.0") ) {
+ CPU_ARCH = CPUArch.PA_RISC2_0;
+ CPU_TYPE = CPUType.PA_RISC;
+ } else if( ARCH_lower.equals("ppc") ) {
+ CPU_ARCH = CPUArch.PPC;
+ CPU_TYPE = CPUType.PPC;
+ } else {
+ throw new RuntimeException("Please port CPU detection to your platform (" + OS_lower + "/" + ARCH_lower + ")");
+ }
+ OS_TYPE = getOSTypeImpl();
- if(libsLoaded) {
- pointerSizeInBits = getPointerSizeInBitsImpl();
- final long pageSizeL = getPageSizeImpl();
- if(Integer.MAX_VALUE < pageSizeL) {
- throw new InternalError("PageSize exceeds integer value: " + pageSizeL);
- }
- pageSize = (int) pageSizeL ;
- }else{
- pointerSizeInBits = -1;
- pageSize = -1;
- }
-
- is32Bit = initArch();
-
+ machineDescription = MachineDescriptionRuntime.getMachineDescription(getIs32BitByCPUArchImpl());
+ is32Bit = machineDescription.is32Bit();
}
private Platform() {}
- private static boolean initArch() throws RuntimeException {
- if ( 32 == pointerSizeInBits || 64 == pointerSizeInBits ) {
- return 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") && arch_lc.equals("ppc")) ||
- (os_lc.startsWith("mac os") && arch_lc.equals("i386")) ||
- (os_lc.startsWith("darwin") && arch_lc.equals("ppc")) ||
- (os_lc.startsWith("darwin") && arch_lc.equals("i386")) ||
- (os_lc.startsWith("sunos") && arch_lc.equals("sparc")) ||
- (os_lc.startsWith("sunos") && arch_lc.equals("x86")) ||
- (os_lc.startsWith("freebsd") && arch_lc.equals("i386")) ||
- (os_lc.startsWith("hp-ux") && arch_lc.equals("pa_risc2.0"))) {
+ private static boolean getIs32BitByCPUArchImpl() throws RuntimeException {
+ switch( CPU_ARCH ) {
+ case X86_32:
+ case ARM_32:
+ case SPARC_32:
+ case PPC:
return 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") && arch_lc.equals("x86_64")) ||
- (os_lc.startsWith("darwin") && arch_lc.equals("x86_64")) ||
- (os_lc.startsWith("sunos") && arch_lc.equals("sparcv9")) ||
- (os_lc.startsWith("sunos") && arch_lc.equals("amd64"))) {
+ case X86_64:
+ case IA64:
+ case SPARCV9_64:
+ case PA_RISC2_0:
return false;
- }else{
- throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os_lc + "/" + arch_lc + ")");
- }
+ default:
+ throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + Platform.OS_lower + "/" + Platform.ARCH_lower + "("+Platform.CPU_ARCH+"))");
}
}
-
+
+ private static OSType getOSTypeImpl() throws RuntimeException {
+ if ( OS_lower.startsWith("linux") ) {
+ return OSType.LINUX;
+ }
+ if ( OS_lower.startsWith("freebsd") ) {
+ return OSType.FREEBSD;
+ }
+ if ( OS_lower.startsWith("dalvik") ) {
+ return OSType.DALVIK;
+ }
+ if ( OS_lower.startsWith("mac os x") ||
+ OS_lower.startsWith("darwin") ) {
+ return OSType.MACOS;
+ }
+ if ( OS_lower.startsWith("sunos") ) {
+ return OSType.SUNOS;
+ }
+ if ( OS_lower.startsWith("hp-ux") ) {
+ return OSType.HPUX;
+ }
+ if ( OS_lower.startsWith("windows") ) {
+ return OSType.WINDOWS;
+ }
+ if ( OS_lower.startsWith("kd") ) {
+ return OSType.OPENKODE;
+ }
+ throw new RuntimeException("Please port OS detection to your platform (" + OS_lower + "/" + ARCH_lower + ")");
+ }
+
private static boolean initIsJavaSE() {
-
// the fast path, check property Java SE instead of traversing through the ClassLoader
String java_runtime_name = (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@@ -159,18 +214,6 @@ public class Platform {
return false;
}
- private static boolean initByteOrder() {
- 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);
- }
-
- private static native int getPointerSizeInBitsImpl();
- private static native long getPageSizeImpl();
-
-
/**
* Returns true only if this program is running on the Java Standard Edition.
*/
@@ -179,13 +222,6 @@ public class Platform {
}
/**
- * Returns true only if this system uses little endian byte ordering.
- */
- public static boolean isLittleEndian() {
- return LITTLE_ENDIAN;
- }
-
- /**
* Returns the OS name.
*/
public static String getOS() {
@@ -208,6 +244,27 @@ public class Platform {
}
/**
+ * Returns the OS type.
+ */
+ public static OSType getOSType() {
+ return OS_TYPE;
+ }
+
+ /**
+ * Returns the CPU type.
+ */
+ public static CPUType getCPUType() {
+ return CPU_TYPE;
+ }
+
+ /**
+ * Returns the CPU architecture.
+ */
+ public static CPUArch getCPUArch() {
+ return CPU_ARCH;
+ }
+
+ /**
* Returns the JAVA.
*/
public static String getJavaVendor() {
@@ -236,37 +293,28 @@ public class Platform {
}
/**
- * Returns true if this JVM is a 32bit JVM.
+ * Returns true if this JVM/ARCH is 32bit.
+ * <p>Shortcut to {@link #getMachineDescription()}.{@link MachineDescription#is32Bit() is32Bit()}</p>
*/
public static boolean is32Bit() {
- return is32Bit;
+ // return Platform.machineDescription.is32Bit();
+ return Platform.is32Bit; // used very often
}
/**
- * Returns true if this JVM is a 64bit JVM.
+ * Returns true if this JVM/ARCH is 64bit.
+ * <p>Shortcut to {@link #getMachineDescription()}.{@link MachineDescription#is32Bit() is64Bit()}</p>
*/
public static boolean is64Bit() {
- return !is32Bit;
- }
-
- public static int getPointerSizeInBits() {
- return pointerSizeInBits;
+ // return Platform.machineDescription.is64Bit();
+ return !Platform.is32Bit; // used very often
}
- public static int getPointerSizeInBytes() {
- return pointerSizeInBits/8;
- }
-
- public static int getPageSize() {
- return pageSize;
- }
-
- public static int getPageNumber(int size) {
- return ( size + ( pageSize - 1) ) / pageSize ; // integer arithmetic
+ /**
+ * Returns the MachineDescription of the running machine.
+ */
+ public static MachineDescription getMachineDescription() {
+ return machineDescription;
}
-
- public static int getPageAlignedSize(int size) {
- return getPageNumber(size) * pageSize;
- }
}
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index b2d9ed4..5b00fb4 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -42,6 +42,7 @@ import java.net.URLConnection;
import java.nio.ByteBuffer;
import com.jogamp.common.nio.Buffers;
+import com.jogamp.common.os.MachineDescription;
import com.jogamp.common.os.Platform;
public class IOUtil {
@@ -81,7 +82,7 @@ public class IOUtil {
* number of bytes written is returned.
*/
public static int copyStream2Stream(InputStream in, OutputStream out, int totalNumBytes) throws IOException {
- final byte[] buf = new byte[Platform.getPageSize()];
+ final byte[] buf = new byte[Platform.getMachineDescription().pageSizeInBytes()];
int numBytes = 0;
while (true) {
int count;
@@ -137,16 +138,16 @@ public class IOUtil {
if( !(stream instanceof BufferedInputStream) ) {
stream = new BufferedInputStream(stream);
}
- int totalRead = 0;
int avail = stream.available();
- ByteBuffer data = Buffers.newDirectByteBuffer( Platform.getPageAlignedSize(avail) );
- byte[] chunk = new byte[Platform.getPageSize()];
- int chunk2Read = Math.min(Platform.getPageSize(), avail);
+ final MachineDescription machine = Platform.getMachineDescription();
+ ByteBuffer data = Buffers.newDirectByteBuffer( machine.pageAlignedSize(avail) );
+ byte[] chunk = new byte[machine.pageSizeInBytes()];
+ int chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
int numRead = 0;
do {
if (avail > data.remaining()) {
- final ByteBuffer newData = Buffers.newDirectByteBuffer(
- Platform.getPageAlignedSize(data.position() + avail) );
+ final ByteBuffer newData = Buffers.newDirectByteBuffer(
+ machine.pageAlignedSize(data.position() + avail) );
newData.put(data);
data = newData;
}
@@ -154,10 +155,9 @@ public class IOUtil {
numRead = stream.read(chunk, 0, chunk2Read);
if (numRead >= 0) {
data.put(chunk, 0, numRead);
- totalRead += numRead;
}
avail = stream.available();
- chunk2Read = Math.min(Platform.getPageSize(), avail);
+ chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
} while (avail > 0 && numRead >= 0);
data.flip();
diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java
index 632e127..1589755 100644
--- a/src/java/com/jogamp/common/util/VersionUtil.java
+++ b/src/java/com/jogamp/common/util/VersionUtil.java
@@ -57,10 +57,7 @@ public class VersionUtil {
sb.append(Platform.getArch()).append(" (arch) ").append(Runtime.getRuntime().availableProcessors()).append(" cores");
sb.append(Platform.getNewline());
- // arch
- sb.append("Platform: littleEndian ").append(Platform.isLittleEndian()).append(", 32Bit ");
- sb.append(Platform.is32Bit()).append(", a-ptr bit-size ").append(Platform.getPointerSizeInBits());
- sb.append(Platform.getNewline());
+ Platform.getMachineDescription().toString(sb).append(Platform.getNewline());
// JVM/JRE
sb.append("Platform: Java ").append(Platform.getJavaVersion()).append(", ").append(System.getProperty("java.vm.name")).append(", ");
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
index ba2eb17..d47cded 100644
--- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
@@ -43,6 +43,7 @@ import java.util.*;
import java.io.*;
import java.text.MessageFormat;
+import com.jogamp.common.os.MachineDescription;
import com.jogamp.gluegen.cgram.types.*;
import java.util.logging.Logger;
diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java
index 22cc0c5..fc536c8 100644
--- a/src/java/com/jogamp/gluegen/DebugEmitter.java
+++ b/src/java/com/jogamp/gluegen/DebugEmitter.java
@@ -41,6 +41,7 @@ package com.jogamp.gluegen;
import java.util.*;
+import com.jogamp.common.os.MachineDescription;
import com.jogamp.gluegen.cgram.types.*;
/** Debug emitter which prints the parsing results to standard output. */
diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java
index 5f627f9..ed06b19 100644
--- a/src/java/com/jogamp/gluegen/GlueEmitter.java
+++ b/src/java/com/jogamp/gluegen/GlueEmitter.java
@@ -40,6 +40,8 @@
package com.jogamp.gluegen;
import java.util.*;
+
+import com.jogamp.common.os.MachineDescription;
import com.jogamp.gluegen.cgram.types.*;
/** Specifies the interface by which GlueGen requests glue code to be
diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java
index 286aac4..c898058 100644
--- a/src/java/com/jogamp/gluegen/GlueGen.java
+++ b/src/java/com/jogamp/gluegen/GlueGen.java
@@ -40,9 +40,14 @@
package com.jogamp.gluegen;
import com.jogamp.common.GlueGenVersion;
+import com.jogamp.common.os.MachineDescription;
+
import java.io.*;
import java.util.*;
+import jogamp.common.os.MachineDescription32Bit;
+import jogamp.common.os.MachineDescription64Bit;
+
import antlr.*;
import com.jogamp.gluegen.cgram.*;
import com.jogamp.gluegen.cgram.types.*;
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 745176a..d92e589 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -42,6 +42,8 @@ package com.jogamp.gluegen;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.os.DynamicLookupHelper;
+import com.jogamp.common.os.MachineDescription;
+
import java.io.*;
import java.util.*;
import java.text.MessageFormat;
diff --git a/src/java/com/jogamp/gluegen/StructLayout.java b/src/java/com/jogamp/gluegen/StructLayout.java
index ea8768f..392e1b1 100644
--- a/src/java/com/jogamp/gluegen/StructLayout.java
+++ b/src/java/com/jogamp/gluegen/StructLayout.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -39,6 +40,7 @@
package com.jogamp.gluegen;
+import com.jogamp.common.os.Platform;
import com.jogamp.gluegen.cgram.types.*;
/** Encapsulates algorithm for laying out data structures. Note that
@@ -119,36 +121,39 @@ public class StructLayout {
+ /**
+ * <P>See alignment in {@link com.jogamp.common.os.MachineDescription}.</p>
+ *
+ * <P>The code is currently used at compile time {@link JavaEmitter#layoutStruct(CompoundType t)} once,
+ * and code for structs is emitted for generic 32bit and 64bit only {@link JavaEmitter#emitStruct(CompoundType structType, String alternateName)}.</p>
+ */
public static StructLayout createForCurrentPlatform() {
- // Note: this code is replicated in (from?) Platform.java
- String os = System.getProperty("os.name").toLowerCase();
- String cpu = System.getProperty("os.arch").toLowerCase();
- if ((os.startsWith("windows") && cpu.equals("x86"))) {
- // It appears that Windows uses a packing alignment of 4 bytes in 32-bit mode
+ final Platform.OSType osType = Platform.getOSType();
+ final Platform.CPUArch cpuArch = Platform.getCPUArch();
+
+ if( ( Platform.OSType.WINDOWS == osType && Platform.CPUArch.X86_32 == cpuArch ) || // It appears that Windows uses a packing alignment of 4 bytes in 32-bit mode
+ ( Platform.CPUArch.ARM_32 == cpuArch )
+ ) {
return new StructLayout(0, 4);
- } else if ((os.startsWith("windows") && cpu.equals("amd64")) ||
- (os.startsWith("linux") && cpu.equals("i386")) ||
- (os.startsWith("linux") && cpu.equals("x86")) ||
- (os.startsWith("linux") && cpu.equals("amd64")) ||
- (os.startsWith("linux") && cpu.equals("x86_64")) ||
- (os.startsWith("linux") && cpu.equals("ia64")) ||
- (os.startsWith("sunos") && cpu.equals("sparc")) ||
- (os.startsWith("sunos") && cpu.equals("sparcv9")) ||
- (os.startsWith("sunos") && cpu.equals("x86")) ||
- (os.startsWith("sunos") && cpu.equals("amd64")) ||
- (os.startsWith("mac os") && cpu.equals("ppc")) ||
- (os.startsWith("mac os") && cpu.equals("i386")) ||
- (os.startsWith("mac os") && cpu.equals("x86_64")) ||
- (os.startsWith("freebsd") && cpu.equals("i386")) ||
- (os.startsWith("freebsd") && cpu.equals("amd64")) ||
- (os.startsWith("hp-ux") && cpu.equals("pa_risc2.0"))
+ } else if ((Platform.OSType.WINDOWS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.LINUX == osType && Platform.CPUArch.IA64 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.SPARC_32 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.SPARCV9_64 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.SUNOS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.PPC == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.MACOS == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.FREEBSD == osType && Platform.CPUArch.X86_32 == cpuArch) ||
+ (Platform.OSType.FREEBSD == osType && Platform.CPUArch.X86_64 == cpuArch) ||
+ (Platform.OSType.HPUX == osType && Platform.CPUArch.PA_RISC2_0 == cpuArch)
) {
- // FIXME: make struct alignment configurable? May need to change
- // packing rules on a per-type basis?
return new StructLayout(0, 8);
} else {
// FIXME: add more ports
- throw new RuntimeException("Please port StructLayout to your OS (" + os + ") and CPU (" + cpu + ")");
+ throw new RuntimeException("Please port StructLayout to your OS (" + osType + ") and CPU (" + cpuArch + ")");
}
}
}
diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
index 58d3171..e8ca8c5 100644
--- a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/GnuCParser.g
@@ -313,6 +313,10 @@ typeSpecifier [int specCount] returns [int retSpecCount]
| "double"
| "signed"
| "unsigned"
+ | "int8_t"
+ | "uint8_t"
+ | "int16_t"
+ | "uint16_t"
| "__int32"
| "int32_t"
| "wchar_t"
diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
index 1beeb7d..dbe2f98 100644
--- a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g
@@ -183,6 +183,10 @@ typeSpecifier
| "double"
| "signed"
| "unsigned"
+ | "int8_t"
+ | "uint8_t"
+ | "int16_t"
+ | "uint16_t"
| "__int32"
| "int32_t"
| "wchar_t"
diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
index a0d2a83..79f966f 100644
--- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/HeaderParser.g
@@ -504,11 +504,15 @@ typeSpecifier[int attributes] returns [Type t] {
| "long" { t = new IntType("long" , SizeThunk.LONG, unsigned, cvAttrs); }
| "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs); }
| "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); }
- | "__int32" { t = new IntType("__int32", SizeThunk.INT, unsigned, cvAttrs); }
- | "int32_t" { t = new IntType("int32_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ }
- | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ }
- | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT, true, cvAttrs, true); /* TS: always unsigned */ }
+ | "__int32" { t = new IntType("__int32", SizeThunk.INT32, unsigned, cvAttrs); }
| "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); }
+ | "int8_t" { t = new IntType("int8_t", SizeThunk.INT8, false, cvAttrs); /* TS: always signed */ }
+ | "uint8_t" { t = new IntType("uint8_t", SizeThunk.INT8, true, cvAttrs); /* TS: always unsigned */ }
+ | "int16_t" { t = new IntType("int16_t", SizeThunk.INT16, false, cvAttrs); /* TS: always signed */ }
+ | "uint16_t" { t = new IntType("uint16_t", SizeThunk.INT16, true, cvAttrs); /* TS: always unsigned */ }
+ | "int32_t" { t = new IntType("int32_t", SizeThunk.INT32, false, cvAttrs); /* TS: always signed */ }
+ | "wchar_t" { t = new IntType("wchar_t", SizeThunk.INT32, false, cvAttrs); /* TS: always signed */ }
+ | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT32, true, cvAttrs, true); /* TS: always unsigned */ }
| "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, false, cvAttrs); /* TS: always signed */ }
| "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, true, cvAttrs, true); /* TS: always unsigned */ }
| "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, false, cvAttrs); /* TS: always signed */ }
diff --git a/src/java/com/jogamp/gluegen/cgram/StdCParser.g b/src/java/com/jogamp/gluegen/cgram/StdCParser.g
index 231e371..7b34656 100644
--- a/src/java/com/jogamp/gluegen/cgram/StdCParser.g
+++ b/src/java/com/jogamp/gluegen/cgram/StdCParser.g
@@ -265,6 +265,10 @@ typeSpecifier [int specCount] returns [int retSpecCount]
| "double"
| "signed"
| "unsigned"
+ | "int8_t"
+ | "uint8_t"
+ | "int16_t"
+ | "uint16_t"
| "__int32"
| "int32_t"
| "wchar_t"
diff --git a/src/java/com/jogamp/gluegen/cgram/types/Field.java b/src/java/com/jogamp/gluegen/cgram/types/Field.java
index 07d90ea..2479e3d 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/Field.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/Field.java
@@ -39,6 +39,8 @@
package com.jogamp.gluegen.cgram.types;
+import com.jogamp.common.os.MachineDescription;
+
/** Represents a field in a struct or union. */
public class Field {
diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java
deleted file mode 100644
index d2598e0..0000000
--- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2003 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.cgram.types;
-
-public class MachineDescription {
- private int charSizeInBytes;
- private int shortSizeInBytes;
- private int intSizeInBytes;
- private int longSizeInBytes;
- private int int64SizeInBytes;
- private int floatSizeInBytes;
- private int doubleSizeInBytes;
- private int pointerSizeInBytes;
- private int structAlignmentInBytes;
-
- public MachineDescription(int charSizeInBytes,
- int shortSizeInBytes,
- int intSizeInBytes,
- int longSizeInBytes,
- int int64SizeInBytes,
- int floatSizeInBytes,
- int doubleSizeInBytes,
- int pointerSizeInBytes,
- int structAlignmentInBytes) {
- this.charSizeInBytes = charSizeInBytes;
- this.shortSizeInBytes = shortSizeInBytes;
- this.intSizeInBytes = intSizeInBytes;
- this.longSizeInBytes = longSizeInBytes;
- this.int64SizeInBytes = int64SizeInBytes;
- this.floatSizeInBytes = floatSizeInBytes;
- this.doubleSizeInBytes = doubleSizeInBytes;
- this.pointerSizeInBytes = pointerSizeInBytes;
- this.structAlignmentInBytes = structAlignmentInBytes;
- }
-
- public int charSizeInBytes() { return charSizeInBytes; }
- public int shortSizeInBytes() { return shortSizeInBytes; }
- public int intSizeInBytes() { return intSizeInBytes; }
- public int longSizeInBytes() { return longSizeInBytes; }
- public int int64SizeInBytes() { return int64SizeInBytes; }
- public int floatSizeInBytes() { return floatSizeInBytes; }
- public int doubleSizeInBytes() { return doubleSizeInBytes; }
- public int pointerSizeInBytes() { return pointerSizeInBytes; }
- public int structAlignmentInBytes() { return structAlignmentInBytes; }
-}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java
deleted file mode 100644
index 6bbb801..0000000
--- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription32Bit.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2003 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.cgram.types;
-
-public class MachineDescription32Bit extends MachineDescription {
- public MachineDescription32Bit() {
- super(1, 2, 4, 4, 8, 4, 8, 4, 8);
- }
-}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java b/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java
deleted file mode 100644
index 38328e4..0000000
--- a/src/java/com/jogamp/gluegen/cgram/types/MachineDescription64Bit.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2003 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.cgram.types;
-
-public class MachineDescription64Bit extends MachineDescription {
- public MachineDescription64Bit() {
- super(1, 2, 4, 8, 8, 4, 8, 8, 16);
- }
-}
diff --git a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java
index 40ddd57..1584a13 100755
--- a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java
@@ -40,6 +40,8 @@
package com.jogamp.gluegen.cgram.types;
+import com.jogamp.common.os.MachineDescription;
+
/** Provides a level of indirection between the definition of a type's
size and the absolute value of this size. Necessary when
generating glue code for two different CPU architectures (e.g.,
@@ -84,6 +86,24 @@ public abstract class SizeThunk implements Cloneable {
}
};
+ public static final SizeThunk INT8 = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.int8SizeInBytes();
+ }
+ };
+
+ public static final SizeThunk INT16 = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.int16SizeInBytes();
+ }
+ };
+
+ public static final SizeThunk INT32 = new SizeThunk() {
+ public long compute(MachineDescription machDesc) {
+ return machDesc.int32SizeInBytes();
+ }
+ };
+
public static final SizeThunk INT64 = new SizeThunk() {
public long compute(MachineDescription machDesc) {
return machDesc.int64SizeInBytes();
diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java
index c58bfae..95afc2c 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/Type.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java
@@ -42,6 +42,8 @@ package com.jogamp.gluegen.cgram.types;
import java.util.List;
+import com.jogamp.common.os.MachineDescription;
+
/** Models a C type. Primitive types include int, float, and
double. All types have an associated name. Structs and unions are
modeled as "compound" types -- composed of fields of primitive or
diff --git a/src/java/com/jogamp/gluegen/package.html b/src/java/com/jogamp/gluegen/package.html
index 2862fe6..f8a2e6d 100644
--- a/src/java/com/jogamp/gluegen/package.html
+++ b/src/java/com/jogamp/gluegen/package.html
@@ -9,32 +9,80 @@
Gluegen has build-in types (terminal symbols) for:<br/>
<br/>
<table border="1">
- <tr><th>type</th> <th>java bits</th> <th>native-x32 bits</th><th>native-x64 bits</th><th>type</th> <th>signed</th> <th>origin</th</tr>
- <tr><th>void</th> <th> 0</th> <th> 0</th> <th> 0</th> <th>void</th> <th>void</th> <th>ANSI-C</th></tr>
- <tr><th>char</th> <th> 8</th> <th> 8</th> <th> 8</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr>
- <tr><th>short</th> <th>16</th> <th>16</th> <th>16</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr>
- <tr><th>int</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed or unsigned</th><th>ANSI-C</th></tr>
- <tr><th>long</th> <th>64</th> <th>32</th> <th>32<sup>1</sup></th> <th>integer</th><th>signed or unsigned</th><th>Windows</th></tr>
- <tr><th>long</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed or unsigned</th><th>Unix</th></tr>
- <tr><th>float</th> <th>32</th> <th>32</th> <th>32</th> <th>float</th> <th>signed</th> <th>ANSI-C</th></tr>
- <tr><th>double</th> <th>64</th> <th>64</th> <th>64</th> <th>double</th> <th>signed</th> <th>ANSI-C</th></tr>
- <tr><th>__int32</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr>
- <tr><th>int32_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
- <tr><th>wchar_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr>
- <tr><th>uint32_t</th> <th>32</th> <th>32</th> <th>32</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
- <tr><th>__int64</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>signed or unsigned</th><th>windows</th></tr>
- <tr><th>int64_t</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
- <tr><th>uint64_t</th> <th>64</th> <th>64</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
- <tr><th>ptrdiff_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed</th> <th>stddef.h</th></tr>
- <tr><th>intptr_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>signed</th> <th>stdint.h</th></tr>
- <tr><th>size_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stddef.h</th></tr>
- <tr><th>uintptr_t</th> <th>64</th> <th>32</th> <th>64</th> <th>integer</th><th>unsigned</th> <th>stdint.h</th></tr>
+ <tr><th>type</th> <th>java bits</th> <th colspan="2">native bits</th> <th>type</th> <th>signed</th> <th>origin</th></tr>
+ <tr><th></th> <th></th> <th>x32</th> <th>x64</th> <th></th> <th></th> <th></th></tr>
+ <tr><td>void</td> <td> 0</td> <td> 0</td> <td> 0</td> <td>void</td> <td>void</td> <td>ANSI-C</td></tr>
+ <tr><td>char</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr>
+ <tr><td>short</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr>
+ <tr><td>int</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>any</td> <td>ANSI-C</td></tr>
+ <tr><td>long</td> <td>64</td> <td>32</td> <td><b>32<sup>1</sup></b></td> <td>integer</td><td>any</td> <td>ANSI-C - Windows</td></tr>
+ <tr><td>long</td> <td>64</td> <td>32</td> <td><b>64</b></td> <td>integer</td><td>any</td> <td>ANSI-C - Unix</td></tr>
+ <tr><td>float</td> <td>32</td> <td>32</td> <td>32</td> <td>float</td> <td>signed</td> <td>ANSI-C</td></tr>
+ <tr><td>double</td> <td>64</td> <td>64</td> <td>64</td> <td>double</td> <td>signed</td> <td>ANSI-C</td></tr>
+ <tr><td>__int32</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>any</td> <td>windows</td></tr>
+ <tr><td>__int64</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>any</td> <td>windows</td></tr>
+ <tr><td>int8_t</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr>
+ <tr><td>uint8_t</td> <td> 8</td> <td> 8</td> <td> 8</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr>
+ <tr><td>int16_t</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr>
+ <tr><td>uint16_t</td> <td>16</td> <td>16</td> <td>16</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr>
+ <tr><td>int32_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr>
+ <tr><td>uint32_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr>
+ <tr><td>int64_t</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr>
+ <tr><td>uint64_t</td> <td>64</td> <td>64</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr>
+ <tr><td>intptr_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>signed</td> <td>stdint.h</td></tr>
+ <tr><td>uintptr_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stdint.h</td></tr>
+ <tr><td>ptrdiff_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>signed</td> <td>stddef.h</td></tr>
+ <tr><td>size_t</td> <td>64</td> <td>32</td> <td>64</td> <td>integer</td><td>unsigned</td> <td>stddef.h</td></tr>
+ <tr><td>wchar_t</td> <td>32</td> <td>32</td> <td>32</td> <td>integer</td><td>signed</td> <td>stddef.h</td></tr>
</table>
<p>
<b>Warning:</b> Try to avoid unspecified bit sized types, especially <b>long</b>, since it differs on Unix and Windows!<br/>
<b>Note 1:</b> Type <b>long</b> will result in broken code on Windows, since we don't differentiate the OS and it's bit size is ambiguous.
</p>
- <p>
+
+ <h4>GlueGen Internal Alignment for Compound Data</h4>
+ In general, depending on CPU and it's configuration (OS), alignment is set up
+ for each type (char, short, int, long, ..),<br>
+ where structures are aligned naturally, i.e. their inner components are aligned.<br>
+ See:<br>
+ <ul>
+ <li><a href="http://en.wikipedia.org/wiki/Data_structure_alignment">Wikipedia Data Structure Alignment</a></li>
+ <li><a href="http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding">Wikipedia Data Structure Alignment - Padding</a></li>
+ <li><a href="http://www.viva64.com/en/l/0021/">Viva64 Data Alignment</a></li>
+ <li><a href="http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/64bitPorting/transition/transition.html#//apple_ref/doc/uid/TP40001064-CH207-SW1">Apple: Darwin 64bit Porting - Data Type Size &amp; Alignment</a></li>
+ </ul>
+
+ <h5>Type Size &amp; Alignment for x86, x86_64, armv7l-32bit-eabi and Window(mingw/mingw64)</h5>
+ Runtime query is implemented as follows:
+ <pre>
+ typedef struct {
+ _TYPE_ s0; // ensures start address alignment
+ char fill; // nibble one byte
+ // padding to align s1
+ _TYPE_ s1; //
+ } type_t;
+
+ padding = sizeof(type_t) - 2 * sizeof(_TYPE_) - sizeof(char);
+ alignment = sizeof(type_t) - 2 * sizeof(_TYPE_) ;
+ </pre>
+ <table border="1">
+ <tr><th>type</th> <th colspan="2">32 bits</th><th colspan="2">64 bits</th></tr>
+ <tr><th></th> <th>size</th><th>alignment</th><th>size</th><th>alignment</th></tr>
+ <tr><td>char</td> <td> 1</td> <td> 1</td> <td> 1</td> <td> 1</td></tr>
+ <tr><td>short</td> <td> 2</td> <td> 2</td> <td> 2</td> <td> 2</td></tr>
+ <tr><td>int</td> <td> 4</td> <td> 4</td> <td> 4</td> <td> 4</td></tr>
+ <tr><td>float</td> <td> 4</td> <td> 4</td> <td> 4</td> <td> 4</td></tr>
+ <tr><td>long</td> <td> 4</td> <td> 4</td> <td> 8<sup>&dagger;</sup>,4<sup>&lowast;</sup></td> <td> 8<sup>&dagger;</sup>,4<sup>&lowast;</sup></td></tr>
+ <tr><td>pointer</td> <td> 4</td> <td> 4</td> <td> 8</td> <td> 8</td></tr>
+ <tr><td>long long</td> <td> 8</td> <td>4<sup>&dagger;</sup>,8<sup>&lowast;</sup><sup>+</sup></td> <td> 8</td> <td> 8</td></tr>
+ <tr><td>double</td> <td> 8</td> <td>4<sup>&dagger;</sup>,8<sup>&lowast;</sup><sup>+</sup></td> <td> 8</td> <td> 8</td></tr>
+ <tr><td>long double</td><td>12<sup>&dagger;</sup><sup>&lowast;</sup>,8<sup>+</sup></td> <td>4<sup>&dagger;</sup><sup>&lowast;</sup>,8<sup>+</sup></td> <td> 16</td> <td>16</td></tr>
+ </table><br>
+ <sup>&dagger;</sup> Linux, Darwin<br>
+ <sup>+</sup>armv7l-32bit-eabi (linux)<br>
+ <sup>&lowast;</sup> Windows<br>
+ </P>
+
<h4>GlueGen Platform Header Files</h4>
GlueGen provides convenient platform headers,<br/>
which can be included in your C header files for native compilation and GlueGen code generation.<br/>