package jogamp.common.os;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.security.PrivilegedAction;
import java.util.List;
import jogamp.common.Debug;
import jogamp.common.os.elf.ElfHeaderPart1;
import jogamp.common.os.elf.ElfHeaderPart2;
import jogamp.common.os.elf.SectionArmAttributes;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.os.AndroidVersion;
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.common.os.Platform;
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.os.Platform.OSType;
import com.jogamp.common.util.SecurityUtil;
import com.jogamp.common.util.VersionNumber;
/**
* Abstract parent class of {@link Platform} initializing and holding
* platform information, which are initialized independent
* of other classes.
*
* This class is not intended to be exposed in the public namespace
* and solely exist to solve initialization interdependencies.
* Please use {@link Platform} to access the public fields!
*
*/
public abstract class PlatformPropsImpl {
static final boolean DEBUG = Debug.debug("Platform");
/**
* Returns {@code true} if the given {@link CPUType}s and {@link ABIType}s are compatible.
*/
public static final boolean isCompatible(final CPUType cpu1, final ABIType abi1, final CPUType cpu2, final ABIType abi2) {
return cpu1.isCompatible(cpu2) && abi1.isCompatible(abi2);
}
//
// static initialization order:
//
public static final String OS;
public static final String OS_lower;
public static final String OS_VERSION;
public static final VersionNumber OS_VERSION_NUMBER;
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 VersionNumber JAVA_VERSION_NUMBER;
public static final int JAVA_VERSION_UPDATE;
public static final String JAVA_VM_NAME;
public static final String JAVA_RUNTIME_NAME;
/** True if having {@link java.nio.LongBuffer} and {@link java.nio.DoubleBuffer} available. */
public static final boolean JAVA_SE;
/**
* True only if being compatible w/ language level 6, e.g. JRE 1.6.
*
* Implies {@link #isJavaSE()}.
*
*
* Note: We claim Android is compatible.
*
*/
public static final boolean JAVA_6;
/**
* True only if being compatible w/ language level 9, e.g. JRE 9.
*
* Implies {@link #JAVA_6} and {@link #isJavaSE()}
*
*
* Since JRE 9, the version string has dropped the major release number,
* see JEP 223: http://openjdk.java.net/jeps/223
*
*/
public static final boolean JAVA_9;
/**
* True only if being compatible w/ language level 17, e.g. JRE 17 (LTS).
*
* Implies {@link #JAVA_9}, {@link #JAVA_6} and {@link #isJavaSE()}
*
*/
public static final boolean JAVA_17;
/**
* True only if being compatible w/ language level 21, e.g. JRE 21 (LTS).
*
*/
public static final boolean JAVA_21;
public static final String NEWLINE;
public static final boolean LITTLE_ENDIAN;
public static final CPUType CPU_ARCH;
public static final ABIType ABI_TYPE;
public static final OSType OS_TYPE;
public static final String os_and_arch;
/**
* Usually GlueGen and subsequent JogAmp modules are build using dynamic libraries on supported platforms,
* hence this boolean is expected to be true.
*
* However, on certain systems static libraries are being used on which native JNI library loading is disabled.
*
*/
public static final boolean useDynamicLibraries;
static {
// We don't seem to need an AccessController.doPrivileged() block
// here as these system properties are visible even to unsigned Applets.
final boolean isAndroid = AndroidVersion.isAvailable; // also triggers it's static initialization
JAVA_VENDOR = System.getProperty("java.vendor");
JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
JAVA_VERSION = System.getProperty("java.version");
JAVA_VERSION_NUMBER = new VersionNumber(JAVA_VERSION);
{
int usIdx = JAVA_VERSION.lastIndexOf("-u"); // OpenJDK update notation
int usOff;
if( 0 < usIdx ) {
usOff = 2;
} else {
usIdx = JAVA_VERSION.lastIndexOf("_"); // Oracle update notation
usOff = 1;
}
if( 0 < usIdx ) {
final String buildS = PlatformPropsImpl.JAVA_VERSION.substring(usIdx+usOff);
final VersionNumber update = new VersionNumber(buildS);
JAVA_VERSION_UPDATE = update.getMajor();
} else {
JAVA_VERSION_UPDATE = 0;
}
}
JAVA_VM_NAME = System.getProperty("java.vm.name");
JAVA_RUNTIME_NAME = getJavaRuntimeNameImpl();
JAVA_SE = initIsJavaSE();
if( JAVA_SE ) {
if( JAVA_VERSION_NUMBER.compareTo(new VersionNumber(21, 0, 0)) >= 0 ) {
JAVA_21 = true;
JAVA_17 = true;
JAVA_9 = true;
JAVA_6 = true;
} else if( JAVA_VERSION_NUMBER.compareTo(new VersionNumber(17, 0, 0)) >= 0 ) {
JAVA_21 = false;
JAVA_17 = true;
JAVA_9 = true;
JAVA_6 = true;
} else if( JAVA_VERSION_NUMBER.compareTo(new VersionNumber(9, 0, 0)) >= 0 ) {
JAVA_21 = false;
JAVA_17 = false;
JAVA_9 = true;
JAVA_6 = true;
} else if( isAndroid || JAVA_VERSION_NUMBER.compareTo(new VersionNumber(1, 6, 0)) >= 0 ) {
JAVA_21 = false;
JAVA_17 = false;
JAVA_9 = false;
JAVA_6 = true;
} else {
// we probably don't support anything below 1.6
JAVA_21 = false;
JAVA_17 = false;
JAVA_9 = false;
JAVA_6 = false;
}
} else {
// we probably don't support anything below 1.6 or non JavaSE
JAVA_21 = false;
JAVA_17 = false;
JAVA_9 = false;
JAVA_6 = false;
}
NEWLINE = System.getProperty("line.separator");
OS = System.getProperty("os.name");
OS_lower = OS.toLowerCase();
OS_VERSION = System.getProperty("os.version");
OS_VERSION_NUMBER = new VersionNumber(OS_VERSION);
OS_TYPE = getOSTypeImpl(OS_lower, isAndroid);
// Hard values, i.e. w/ probing binaries
final String elfCpuName;
final CPUType elfCpuType;
final ABIType elfABIType;
final int elfLittleEndian;
final boolean elfValid;
{
final String[] _elfCpuName = { null };
final CPUType[] _elfCpuType = { null };
final ABIType[] _elfAbiType = { null };
final int[] _elfLittleEndian = { 0 }; // 1 - little, 2 - big
final boolean[] _elfValid = { false };
SecurityUtil.doPrivileged(new PrivilegedAction