summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/os
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
committerSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
commita3f2d08801c5a54048faca52f422bcededf81b2a (patch)
tree96e83956b62ae3e25043ccc67f4cb1c2c1f232a1 /src/java/com/jogamp/common/os
parent0deceee37d943faa7c34971388863a27f395d6a5 (diff)
Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless
ELF Reader 'jogamp.common.os.elf' currently uses Platform's pre-determined OS_TYPE and CPUType. It also uses the host platforms MachineDescription, hence can not read ELF files from other machines. This also forbids Platform to determine CPUType etc w/o having a valid 'os.arch' property. +++ ElfHeader should be split in - ElfHeaderPart1 (CPUType independent) - ElfHeaderPart2 (CPUType dependent) Fix shall make the ELF Reader self containing by only using ELF CPUType data, etc. This requires customization of struct parsing, where MachineDescription.Static index shall be - defined in ElfHeaderPart1 using e_Ident's CPUType. - used in ElfHeaderPart2 and all its struct types.
Diffstat (limited to 'src/java/com/jogamp/common/os')
-rw-r--r--src/java/com/jogamp/common/os/AndroidVersion.java97
-rw-r--r--src/java/com/jogamp/common/os/MachineDescription.java6
-rw-r--r--src/java/com/jogamp/common/os/Platform.java197
3 files changed, 171 insertions, 129 deletions
diff --git a/src/java/com/jogamp/common/os/AndroidVersion.java b/src/java/com/jogamp/common/os/AndroidVersion.java
index f727a47..840933f 100644
--- a/src/java/com/jogamp/common/os/AndroidVersion.java
+++ b/src/java/com/jogamp/common/os/AndroidVersion.java
@@ -30,7 +30,6 @@ package com.jogamp.common.os;
import java.lang.reflect.Field;
import com.jogamp.common.os.Platform.ABIType;
-import com.jogamp.common.os.Platform.CPUFamily;
import com.jogamp.common.os.Platform.CPUType;
import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.common.util.ReflectionUtil;
@@ -67,61 +66,6 @@ public class AndroidVersion {
private static final String androidBuildVersion = "android.os.Build$VERSION";
private static final String androidBuildVersionCodes = "android.os.Build$VERSION_CODES";
- /**
- * Returns {@link CPUType} for matching <code>cpuABI<code>,
- * i.e. {@link #CPU_ABI} or {@link #CPU_ABI2},
- * or <code>null</code> for no match.
- * <p>
- * FIXME: Where is a comprehensive list of known 'android.os.Build.CPU_ABI' and 'android.os.Build.CPU_ABI2' strings ?<br/>
- * Fount this one: <code>http://www.kandroid.org/ndk/docs/CPU-ARCH-ABIS.html</code>
- * <pre>
- * lib/armeabi/libfoo.so
- * lib/armeabi-v7a/libfoo.so
- * lib/x86/libfoo.so
- * lib/mips/libfoo.so
- * </pre>
- * </p>
- */
- private static final CPUType getCPUTypeImpl(final String cpuABI) {
- if( null == cpuABI ) {
- return null;
- } else if( cpuABI.equals("armv8-a") ||
- cpuABI.equals("arm64-v8a") ) {
- return CPUType.ARMv8_A;
- } else if( cpuABI.equals("aarch64") ||
- cpuABI.startsWith("arm64") ) {
- return CPUType.ARM64;
- } else if( cpuABI.equals("armeabi-v7a") ||
- cpuABI.equals("armeabi-v7a-hard") ) {
- return CPUType.ARMv7;
- } else if( cpuABI.equals("armeabi") ||
- cpuABI.startsWith("arm") ) { // last 32bit chance ..
- return CPUType.ARM;
- } else if( cpuABI.equals("x86") ) {
- return CPUType.X86_32;
- } else if( cpuABI.equals("mips") ) { // no 32bit vs 64bit identifier ?
- return CPUType.MIPS_32;
- } else {
- return null;
- }
- }
- private static final ABIType getABITypeImpl(final CPUType cpuType, final String cpuABI) {
- if( null == cpuType || null == cpuABI ) {
- return null;
- } else if( CPUFamily.ARM == cpuType.family ) {
- if( CPUType.ARM64 == cpuType ||
- CPUType.ARMv8_A == cpuType ) {
- return ABIType.EABI_AARCH64;
- } else if( cpuABI.equals("armeabi-v7a-hard") ) {
- return ABIType.EABI_GNU_ARMHF;
- } else {
- return ABIType.EABI_GNU_ARMEL;
- }
- } else {
- return ABIType.GENERIC_ABI;
- }
- }
-
static {
final ClassLoader cl = AndroidVersion.class.getClassLoader();
Class<?> abClass = null;
@@ -138,7 +82,7 @@ public class AndroidVersion {
abvcClass = ReflectionUtil.getClass(androidBuildVersionCodes, true, cl);
abvcObject = abvcClass.newInstance();
} catch (final Exception e) { /* n/a */ }
- isAvailable = null != abObject && null != abvObject && null != abvcObject;
+ isAvailable = null != abObject && null != abvObject;
if(isAvailable) {
CPU_ABI = getString(abClass, abObject, "CPU_ABI", true);
CPU_ABI2 = getString(abClass, abObject, "CPU_ABI2", true);
@@ -146,9 +90,36 @@ public class AndroidVersion {
INCREMENTAL = getString(abvClass, abvObject, "INCREMENTAL", false);
RELEASE = getString(abvClass, abvObject, "RELEASE", false);
SDK_INT = getInt(abvClass, abvObject, "SDK_INT");
- final IntObjectHashMap version_codes = getVersionCodes(abvcClass, abvcObject);
- final String sdk_name = (String) version_codes.get(SDK_INT);
+ final String sdk_name;
+ if( null != abvcObject ) {
+ final IntObjectHashMap version_codes = getVersionCodes(abvcClass, abvcObject);
+ sdk_name = (String) version_codes.get(SDK_INT);
+ } else {
+ sdk_name = null;
+ }
SDK_NAME = ( null != sdk_name ) ? sdk_name : "SDK_"+SDK_INT ;
+
+ /**
+ * <p>
+ * FIXME: Where is a comprehensive list of known 'android.os.Build.CPU_ABI' and 'android.os.Build.CPU_ABI2' strings ?<br/>
+ * Fount this one: <code>http://www.kandroid.org/ndk/docs/CPU-ARCH-ABIS.html</code>
+ * <pre>
+ * lib/armeabi/libfoo.so
+ * lib/armeabi-v7a/libfoo.so
+ * lib/x86/libfoo.so
+ * lib/mips/libfoo.so
+ * </pre>
+ * </p>
+ */
+ CPU_TYPE = Platform.CPUType.query(CPU_ABI);
+ ABI_TYPE = Platform.ABIType.query(CPU_TYPE, CPU_ABI);
+ if( null != CPU_ABI2 && CPU_ABI2.length() > 0 ) {
+ CPU_TYPE2 = Platform.CPUType.query(CPU_ABI2);
+ ABI_TYPE2 = Platform.ABIType.query(CPU_TYPE2, CPU_ABI2);
+ } else {
+ CPU_TYPE2 = null;
+ ABI_TYPE2 = null;
+ }
} else {
CPU_ABI = null;
CPU_ABI2 = null;
@@ -157,11 +128,11 @@ public class AndroidVersion {
RELEASE = null;
SDK_INT = -1;
SDK_NAME = null;
+ CPU_TYPE = null;
+ ABI_TYPE = null;
+ CPU_TYPE2 = null;
+ ABI_TYPE2 = null;
}
- CPU_TYPE = getCPUTypeImpl(CPU_ABI);
- ABI_TYPE = getABITypeImpl(CPU_TYPE, CPU_ABI);
- CPU_TYPE2 = getCPUTypeImpl(CPU_ABI2);
- ABI_TYPE2 = getABITypeImpl(CPU_TYPE2, CPU_ABI2);
}
private static final IntObjectHashMap getVersionCodes(final Class<?> cls, final Object obj) {
diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java
index 98093d0..2a4627e 100644
--- a/src/java/com/jogamp/common/os/MachineDescription.java
+++ b/src/java/com/jogamp/common/os/MachineDescription.java
@@ -104,7 +104,7 @@ public class MachineDescription {
alignments[j++]);
}
- public StringBuilder toString(StringBuilder sb) {
+ public final StringBuilder toString(StringBuilder sb) {
if(null==sb) {
sb = new StringBuilder();
}
@@ -112,7 +112,9 @@ public class MachineDescription {
md.toString(sb);
return sb;
}
-
+ public final String toShortString() {
+ return this.name()+"("+this.ordinal()+")";
+ }
@Override
public String toString() {
return toString(null).toString();
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index 0d00a9a..6f6c99d 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -58,97 +58,186 @@ import jogamp.common.os.PlatformPropsImpl;
public class Platform extends PlatformPropsImpl {
public enum OSType {
- LINUX(0), FREEBSD(1), ANDROID(2), MACOS(3), SUNOS(4), HPUX(5), WINDOWS(6), OPENKODE(7);
-
- public final int id;
-
- OSType(final int id){
- this.id = id;
- }
+ LINUX, FREEBSD, ANDROID, MACOS, SUNOS, HPUX, WINDOWS, OPENKODE;
}
public enum CPUFamily {
/** AMD/Intel */
- X86( 0x00000000),
+ X86,
/** ARM */
- ARM( 0x00010000),
+ ARM,
/** Power PC */
- PPC( 0x00020000),
+ PPC,
/** SPARC */
- SPARC( 0x00030000),
+ SPARC,
/** Mips */
- MIPS( 0x00040000),
+ MIPS,
/** PA RISC */
- PA_RISC(0xFFFF0000),
+ PA_RISC,
/** Itanium */
- IA64( 0xFFFF1000);
-
- public final int id;
-
- CPUFamily(final int id){
- this.id = id;
- }
+ IA64;
}
public enum CPUType {
/** X86 32bit */
- X86_32( CPUFamily.X86, 0x0001, true),
+ X86_32( CPUFamily.X86, true),
/** X86 64bit */
- X86_64( CPUFamily.X86, 0x0002, false),
+ X86_64( CPUFamily.X86, false),
/** ARM 32bit default */
- ARM( CPUFamily.ARM, 0x0000, true),
+ ARM( CPUFamily.ARM, true),
/** ARM7EJ, ARM9E, ARM10E, XScale */
- ARMv5( CPUFamily.ARM, 0x0001, true),
+ ARMv5( CPUFamily.ARM, true),
/** ARM11 */
- ARMv6( CPUFamily.ARM, 0x0002, true),
+ ARMv6( CPUFamily.ARM, true),
/** ARM Cortex */
- ARMv7( CPUFamily.ARM, 0x0004, true),
+ ARMv7( CPUFamily.ARM, true),
/** ARM64 default (64bit) */
- ARM64( CPUFamily.ARM, 0x0008, false),
+ ARM64( CPUFamily.ARM, false),
/** ARM AArch64 (64bit) */
- ARMv8_A( CPUFamily.ARM, 0x0010, false),
+ ARMv8_A( CPUFamily.ARM, false),
/** PPC 32bit default */
- PPC( CPUFamily.PPC, 0x0000, true),
+ PPC( CPUFamily.PPC, true),
+ /** PPC 64bit default */
+ PPC64( CPUFamily.PPC, false),
/** SPARC 32bit */
- SPARC_32( CPUFamily.SPARC, 0x0001, true),
+ SPARC_32( CPUFamily.SPARC, true),
/** SPARC 64bit */
- SPARCV9_64(CPUFamily.SPARC, 0x0002, false),
+ SPARCV9_64(CPUFamily.SPARC, false),
/** MIPS 32bit */
- MIPS_32( CPUFamily.MIPS, 0x0001, true),
+ MIPS_32( CPUFamily.MIPS, true),
/** MIPS 64bit */
- MIPS_64( CPUFamily.MIPS, 0x0002, false),
+ MIPS_64( CPUFamily.MIPS, false),
/** Itanium 64bit default */
- IA64( CPUFamily.IA64, 0x0000, false),
+ IA64( CPUFamily.IA64, false),
/** PA_RISC2_0 64bit */
- PA_RISC2_0(CPUFamily.PA_RISC, 0x0001, false);
+ PA_RISC2_0(CPUFamily.PA_RISC, false);
- public final int id;
public final CPUFamily family;
public final boolean is32Bit;
- CPUType(final CPUFamily type, final int id, final boolean is32Bit){
+ CPUType(final CPUFamily type, final boolean is32Bit){
this.family = type;
- this.id = id;
this.is32Bit = is32Bit;
}
- public CPUFamily getFamily() { return family; }
+ /**
+ * Returns {@code true} if the given {@link CPUType} is compatible
+ * w/ this one, i.e. at least {@link #family} and {@link #is32Bit} is equal.
+ */
+ public final boolean isCompatible(final CPUType other) {
+ if( null == other ) {
+ return false;
+ } else if( other == this ) {
+ return true;
+ } else {
+ return this.family == other.family &&
+ this.is32Bit == other.is32Bit;
+ }
+ }
+
+ public static final CPUType query(final String cpuABILower) {
+ if( null == cpuABILower ) {
+ throw new IllegalArgumentException("Null cpuABILower arg");
+ }
+ if( cpuABILower.equals("x86") ||
+ cpuABILower.equals("i386") ||
+ cpuABILower.equals("i486") ||
+ cpuABILower.equals("i586") ||
+ cpuABILower.equals("i686") ) {
+ return X86_32;
+ } else if( cpuABILower.equals("x86_64") ||
+ cpuABILower.equals("amd64") ) {
+ return X86_64;
+ } else if( cpuABILower.equals("ia64") ) {
+ return IA64;
+ } else if( cpuABILower.equals("aarch64") ) {
+ return ARM64;
+ } else if( cpuABILower.startsWith("arm") ) {
+ if( cpuABILower.equals("armv8-a") ||
+ cpuABILower.equals("arm-v8-a") ||
+ cpuABILower.equals("arm-8-a") ||
+ cpuABILower.equals("arm64-v8a") ) {
+ return ARMv8_A;
+ } else if( cpuABILower.startsWith("arm64") ) {
+ return ARM64;
+ } else if( cpuABILower.startsWith("armv7") ||
+ cpuABILower.startsWith("arm-v7") ||
+ cpuABILower.startsWith("arm-7") ||
+ cpuABILower.startsWith("armeabi-v7") ) {
+ return ARMv7;
+ } else if( cpuABILower.startsWith("armv5") ||
+ cpuABILower.startsWith("arm-v5") ||
+ cpuABILower.startsWith("arm-5") ) {
+ return ARMv5;
+ } else if( cpuABILower.startsWith("armv6") ||
+ cpuABILower.startsWith("arm-v6") ||
+ cpuABILower.startsWith("arm-6") ) {
+ return ARMv6;
+ } else {
+ return ARM;
+ }
+ } else if( cpuABILower.equals("sparcv9") ) {
+ return SPARCV9_64;
+ } else if( cpuABILower.equals("sparc") ) {
+ return SPARC_32;
+ } else if( cpuABILower.equals("pa_risc2.0") ) {
+ return PA_RISC2_0;
+ } else if( cpuABILower.startsWith("ppc64") ) {
+ return PPC64;
+ } else if( cpuABILower.startsWith("ppc") ) {
+ return PPC;
+ } else if( cpuABILower.startsWith("mips") ) {
+ return MIPS_32;
+ } else {
+ throw new RuntimeException("Please port CPUType detection to your platform (CPU_ABI string '" + cpuABILower + "')");
+ }
+ }
}
public enum ABIType {
- GENERIC_ABI ( 0x0000 ),
+ GENERIC_ABI ( 0x00 ),
/** ARM GNU-EABI ARMEL -mfloat-abi=softfp */
- EABI_GNU_ARMEL ( 0x0001 ),
+ EABI_GNU_ARMEL ( 0x01 ),
/** ARM GNU-EABI ARMHF -mfloat-abi=hard */
- EABI_GNU_ARMHF ( 0x0002 ),
+ EABI_GNU_ARMHF ( 0x02 ),
/** ARM EABI AARCH64 (64bit) */
- EABI_AARCH64 ( 0x0003 );
+ EABI_AARCH64 ( 0x03 );
public final int id;
ABIType(final int id){
this.id = id;
}
+
+ /**
+ * Returns {@code true} if the given {@link ABIType} is compatible
+ * w/ this one, i.e. they are equal.
+ */
+ public final boolean isCompatible(final ABIType other) {
+ if( null == other ) {
+ return false;
+ } else {
+ return other == this;
+ }
+ }
+
+ public static final ABIType query(final CPUType cpuType, final String cpuABILower) {
+ if( null == cpuType ) {
+ throw new IllegalArgumentException("Null cpuType");
+ } else if( null == cpuABILower ) {
+ throw new IllegalArgumentException("Null cpuABILower");
+ } else if( CPUFamily.ARM == cpuType.family ) {
+ if( !cpuType.is32Bit ) {
+ return EABI_AARCH64;
+ } else if( cpuABILower.equals("armeabi-v7a-hard") ) {
+ return EABI_GNU_ARMHF;
+ } else {
+ return EABI_GNU_ARMEL;
+ }
+ } else {
+ return GENERIC_ABI;
+ }
+ }
}
private static final String useTempJarCachePropName = "jogamp.gluegen.UseTempJarCache";
@@ -261,26 +350,6 @@ public class Platform extends PlatformPropsImpl {
public static void initSingleton() { }
/**
- * Returns true only if having {@link java.nio.LongBuffer} and {@link java.nio.DoubleBuffer} available.
- */
- public static boolean isJavaSE() {
- return JAVA_SE;
- }
-
- /**
- * Returns true only if being compatible w/ language level 6, e.g. JRE 1.6.
- * <p>
- * Implies {@link #isJavaSE()}.
- * </p>
- * <p>
- * <i>Note</i>: We claim Android is compatible.
- * </p>
- */
- public static boolean isJava6() {
- return JAVA_6;
- }
-
- /**
* Returns true if this machine is little endian, otherwise false.
*/
public static boolean isLittleEndian() {
@@ -328,7 +397,7 @@ public class Platform extends PlatformPropsImpl {
* Returns the CPU family.
*/
public static CPUFamily getCPUFamily() {
- return CPU_ARCH.getFamily();
+ return CPU_ARCH.family;
}
/**