summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/os
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-17 16:34:39 +0200
committerSven Gothel <[email protected]>2011-07-17 16:34:39 +0200
commitf733203dfbd034a6b1aa3eb2cd616437c982c435 (patch)
tree4ace71d4b129870b02f962b714c9dce9f83bc294 /src/java/com/jogamp/common/os
parentad3dc39ccfddb007c3e91acf454f804573969419 (diff)
GlueGen proper size / alignment of primitive and compound types usage [1/2] - Preparation.
Currently GlueGen fails for type long (size) and some alignments (see package.html). - The size and alignment values shall be queried at runtime. - Compound alignment needs to follow the described natural alignment (also @runtime). - - Build - add Linux Arm7 (EABI) - junit test - added compound/struct tests, pointing out the shortcomings of current impl. - package.html - Added alignment documentation - remove intptr.cfg - add GluGen types int8_t, int16_t, uint8_t, uint16_t - move MachineDescription* into runtime - Platform - has runtime MachineDescription - moved size, .. to MachineDescription - use enums for OSType, CPUArch and CPUType defined by os.name/os.arch, triggering exception if os/arch is not supported. This avoids Java String comparison and conscious os/arch detection. - MachineDescription: - compile time instances MachineDescription32Bits, MachineDescription64Bits - runtime queried instance MachineDescriptionRuntime - correct size, alignment, page size, ..
Diffstat (limited to 'src/java/com/jogamp/common/os')
-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
3 files changed, 403 insertions, 140 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;
- }
}