From 7db9df61142694965b50f2e0553d4c9e5668439b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 2 Feb 2015 00:22:29 +0100 Subject: Bug 1126 - Remove static query requirement of MachineDescriptor, find matching StaticConfig at runtime; Fix PPC (Bug 1056) and MIPSLE (Bug 1014) issues. Currently the StaticConfig is being queried via the key[OSType, CPUType ..] as pre-determined by Java properties or the ELF parser. This adds complication to maintain different platforms and the key query might not even be sufficient. The MachineDescriptor's StaticConfig only purpose shall be to speed-up native data size and offset/alignment retrieval. This is done by using the StaticConfig index within all StaticConfig[]s as a lookup-index for the precomputed struct's size and offset tables. +++ Solution: Rename: MachineDescriptor -> MachineDataInfo Rename: MachineDescriptorRuntime -> MachineDataInfoRuntime After having defined os.and.arch (OSType, CPUType and ABIType) w/ the optional help of the now self containing ELF Reader (Bug 1125), the native gluegen-rt library gets loaded enabling JNI methods. It is satisfactory to retrieve MachineDataInfo at runtime w/ JNI and find the matching/compatible StaticConfig. Only in case none is found, the program needs to abort. Otherwise the found MachineDataInfo.StaticConfig and MachineDataInfo are stored for further use (see above). This removes above complication and key to StaticConfig mapping. New platforms simply need to add a new unique entry into the StaticConfig[] table. ++ Also fixes Bug 1056 (PPC), thanks to tmancill [@] debian [.] org, and Bug 1014 (MIPSLE), thanks to Dejan Latinovic. Parts of the patch for Bug 1014 from Dejan Latinovic are included. also solved by this change set. --- src/java/com/jogamp/common/os/MachineDataInfo.java | 372 +++++++++++++++++++++ .../com/jogamp/common/os/MachineDescription.java | 318 ------------------ src/java/com/jogamp/common/os/Platform.java | 87 ++--- src/java/com/jogamp/common/util/IOUtil.java | 8 +- src/java/com/jogamp/common/util/VersionUtil.java | 4 +- 5 files changed, 424 insertions(+), 365 deletions(-) create mode 100644 src/java/com/jogamp/common/os/MachineDataInfo.java delete mode 100644 src/java/com/jogamp/common/os/MachineDescription.java (limited to 'src/java/com/jogamp/common') diff --git a/src/java/com/jogamp/common/os/MachineDataInfo.java b/src/java/com/jogamp/common/os/MachineDataInfo.java new file mode 100644 index 0000000..0192cd8 --- /dev/null +++ b/src/java/com/jogamp/common/os/MachineDataInfo.java @@ -0,0 +1,372 @@ +/* + * 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 jogamp.common.os.PlatformPropsImpl; + +/** + * Machine data description for alignment and size onle, see {@link com.jogamp.gluegen}. + *

+ * {@code little-endian} / {@code big/endian} description is left, + * allowing re-using instances in {@link MachineDataInfo.StaticConfig StaticConfig}. + * Use {@link {@link PlatformPropsImpl#LITTLE_ENDIAN}. + *

+ *

+ * Further more, the value {@ MachineDataInfo#pageSizeInBytes} shall be ignored + * in {@link MachineDataInfo.StaticConfig StaticConfig}, see {@link MachineDataInfo#compatible(MachineDataInfo)}. + *

+ */ +public class MachineDataInfo { + /* arch os int, long, float, doubl, ldoubl, ptr, page */ + private final static int[] size_arm_mips_32 = { 4, 4, 4, 8, 8, 4, 4096 }; + private final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; + private final static int[] size_x86_32_macos = { 4, 4, 4, 8, 16, 4, 4096 }; + private final static int[] size_ppc_32_unix = { 4, 4, 4, 8, 16, 4, 4096 }; + private final static int[] size_sparc_32_sunos = { 4, 4, 4, 8, 16, 4, 8192 }; + private final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; + private final static int[] size_lp64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; + private final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; + + /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */ + private final static int[] align_arm_mips_32 = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; + private final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; + private final static int[] align_x86_32_macos = { 1, 2, 4, 4, 4, 4, 4, 4, 16, 4 }; + private final static int[] align_ppc_32_unix = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 4 }; + private final static int[] align_sparc_32_sunos = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; + private final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; + private final static int[] align_lp64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; + private final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; + + /** + * Static enumeration of {@link MachineDataInfo} instances + * used for high performance data size and alignment lookups, + * e.g. for generated structures. + *

+ * The value {@link MachineDataInfo#pageSizeInBytes} shall be ignored + * for static instances! + *

+ *

+ * If changing this table, you need to: + *

+ * .. b/c the generated code for glued structures must reflect this change! + *

+ */ + public enum StaticConfig { + /** {@link Platform.CPUType#ARM} or {@link Platform.CPUType#MIPS_32} */ + ARM_MIPS_32( size_arm_mips_32, align_arm_mips_32), + /** {@link Platform.CPUType#X86_32} Unix */ + X86_32_UNIX( size_x86_32_unix, align_x86_32_unix), + /** {@link Platform.CPUType#X86_32} MacOS (Special case gcc4/OSX) */ + X86_32_MACOS( size_x86_32_macos, align_x86_32_macos), + /** {@link Platform.CPUType#PPC} Unix */ + PPC_32_UNIX( size_ppc_32_unix, align_ppc_32_unix), + /** {@link Platform.CPUType#SPARC_32} Solaris */ + SPARC_32_SUNOS( size_sparc_32_sunos, align_sparc_32_sunos), + /** {@link Platform.CPUType#X86_32} Windows */ + X86_32_WINDOWS( size_x86_32_windows, align_x86_32_windows), + /** LP64 Unix, e.g.: {@link Platform.CPUType#X86_64} Unix, {@link Platform.CPUType#ARM64} EABI, {@link Platform.CPUType#PPC64} Unix, .. */ + LP64_UNIX( size_lp64_unix, align_lp64_unix), + /** {@link Platform.CPUType#X86_64} Windows */ + X86_64_WINDOWS( size_x86_64_windows, align_x86_64_windows); + // 8 + + public final MachineDataInfo md; + + StaticConfig(final int[] sizes, final int[] alignments) { + int i=0, j=0; + this.md = new MachineDataInfo(false, + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + sizes[i++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++], + alignments[j++]); + } + + public final StringBuilder toString(StringBuilder sb) { + if(null==sb) { + sb = new StringBuilder(); + } + sb.append("MachineDataInfoStatic: ").append(this.name()).append("(").append(this.ordinal()).append("): "); + md.toString(sb); + return sb; + } + public final String toShortString() { + return this.name()+"("+this.ordinal()+")"; + } + @Override + public String toString() { + return toString(null).toString(); + } + + /** + * Static's {@link MachineDataInfo} shall be unique by the + * {@link MachineDataInfo#compatible(MachineDataInfo) compatible} criteria. + */ + public static final void validateUniqueMachineDataInfo() { + final StaticConfig[] scs = StaticConfig.values(); + for(int i=scs.length-1; i>=0; i--) { + final StaticConfig a = scs[i]; + for(int j=scs.length-1; j>=0; j--) { + if( i != j ) { + final StaticConfig b = scs[j]; + if( a.md.compatible(b.md) ) { + // oops + final String msg = "Duplicate/Compatible MachineDataInfo in StaticConfigs: Elements ["+i+": "+a.toShortString()+"] and ["+j+": "+b.toShortString()+"]"; + System.err.println(msg); + System.err.println(a); + System.err.println(b); + throw new InternalError(msg); + } + } + } + } + } + public static final StaticConfig findCompatible(final MachineDataInfo md) { + final StaticConfig[] scs = StaticConfig.values(); + for(int i=scs.length-1; i>=0; i--) { + final StaticConfig a = scs[i]; + if( a.md.compatible(md) ) { + return a; + } + } + return null; + } + } + + final private boolean runtimeValidated; + + final private int int8SizeInBytes = 1; + final private int int16SizeInBytes = 2; + final private int int32SizeInBytes = 4; + final private int int64SizeInBytes = 8; + + final private int intSizeInBytes; + final private int longSizeInBytes; + final private int floatSizeInBytes; + final private int doubleSizeInBytes; + final private int ldoubleSizeInBytes; + final private int pointerSizeInBytes; + final private int pageSizeInBytes; + + final private int int8AlignmentInBytes; + final private int int16AlignmentInBytes; + final private int int32AlignmentInBytes; + final private int int64AlignmentInBytes; + final private int intAlignmentInBytes; + final private int longAlignmentInBytes; + final private int floatAlignmentInBytes; + final private int doubleAlignmentInBytes; + final private int ldoubleAlignmentInBytes; + final private int pointerAlignmentInBytes; + + public MachineDataInfo(final boolean runtimeValidated, + + final int intSizeInBytes, + final int longSizeInBytes, + final int floatSizeInBytes, + final int doubleSizeInBytes, + final int ldoubleSizeInBytes, + final int pointerSizeInBytes, + final int pageSizeInBytes, + + final int int8AlignmentInBytes, + final int int16AlignmentInBytes, + final int int32AlignmentInBytes, + final int int64AlignmentInBytes, + final int intAlignmentInBytes, + final int longAlignmentInBytes, + final int floatAlignmentInBytes, + final int doubleAlignmentInBytes, + final int ldoubleAlignmentInBytes, + final int pointerAlignmentInBytes) { + this.runtimeValidated = runtimeValidated; + + this.intSizeInBytes = intSizeInBytes; + this.longSizeInBytes = longSizeInBytes; + this.floatSizeInBytes = floatSizeInBytes; + this.doubleSizeInBytes = doubleSizeInBytes; + this.ldoubleSizeInBytes = ldoubleSizeInBytes; + this.pointerSizeInBytes = pointerSizeInBytes; + this.pageSizeInBytes = pageSizeInBytes; + + this.int8AlignmentInBytes = int8AlignmentInBytes; + this.int16AlignmentInBytes = int16AlignmentInBytes; + this.int32AlignmentInBytes = int32AlignmentInBytes; + this.int64AlignmentInBytes = int64AlignmentInBytes; + this.intAlignmentInBytes = intAlignmentInBytes; + this.longAlignmentInBytes = longAlignmentInBytes; + this.floatAlignmentInBytes = floatAlignmentInBytes; + this.doubleAlignmentInBytes = doubleAlignmentInBytes; + this.ldoubleAlignmentInBytes = ldoubleAlignmentInBytes; + 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; + } + + 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 ldoubleSizeInBytes() { return ldoubleSizeInBytes; } + public final int pointerSizeInBytes() { return pointerSizeInBytes; } + public final int pageSizeInBytes() { return pageSizeInBytes; } + + 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 ldoubleAlignmentInBytes() { return ldoubleAlignmentInBytes; } + public final int pointerAlignmentInBytes() { return pointerAlignmentInBytes; } + + /** + * @return number of pages required for size in bytes + */ + public int pageCount(final int size) { + return ( size + ( pageSizeInBytes - 1) ) / pageSizeInBytes ; // integer arithmetic + } + + /** + * @return page aligned size in bytes + */ + public int pageAlignedSize(final int size) { + return pageCount(size) * pageSizeInBytes; + } + + /** + * Checks whether two size objects are equal. Two instances + * of MachineDataInfo are considered equal if all components + * match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}. + * @return true if the two MachineDataInfo are equal; + * otherwise false. + */ + @Override + public final boolean equals(final Object obj) { + if (this == obj) { return true; } + if ( !(obj instanceof MachineDataInfo) ) { return false; } + final MachineDataInfo md = (MachineDataInfo) obj; + + return pageSizeInBytes == md.pageSizeInBytes && + compatible(md); + } + + /** + * Checks whether two {@link MachineDataInfo} objects are equal. + *

+ * Two {@link MachineDataInfo} instances are considered equal if all components + * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}. + *

+ * @return true if the two {@link MachineDataInfo} are equal; + * otherwise false. + */ + public final boolean compatible(final MachineDataInfo md) { + return intSizeInBytes == md.intSizeInBytes && + longSizeInBytes == md.longSizeInBytes && + floatSizeInBytes == md.floatSizeInBytes && + doubleSizeInBytes == md.doubleSizeInBytes && + ldoubleSizeInBytes == md.ldoubleSizeInBytes && + pointerSizeInBytes == md.pointerSizeInBytes && + + int8AlignmentInBytes == md.int8AlignmentInBytes && + int16AlignmentInBytes == md.int16AlignmentInBytes && + int32AlignmentInBytes == md.int32AlignmentInBytes && + int64AlignmentInBytes == md.int64AlignmentInBytes && + intAlignmentInBytes == md.intAlignmentInBytes && + longAlignmentInBytes == md.longAlignmentInBytes && + floatAlignmentInBytes == md.floatAlignmentInBytes && + doubleAlignmentInBytes == md.doubleAlignmentInBytes && + ldoubleAlignmentInBytes == md.ldoubleAlignmentInBytes && + pointerAlignmentInBytes == md.pointerAlignmentInBytes ; + } + + public StringBuilder toString(StringBuilder sb) { + if(null==sb) { + sb = new StringBuilder(); + } + sb.append("MachineDataInfo: runtimeValidated ").append(isRuntimeValidated()).append(", 32Bit ").append(4 == pointerAlignmentInBytes).append(", primitive size / alignment:").append(PlatformPropsImpl.NEWLINE); + sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes); + sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline()); + sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes); + sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline()); + 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(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline()); + 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/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java deleted file mode 100644 index 2a4627e..0000000 --- a/src/java/com/jogamp/common/os/MachineDescription.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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 jogamp.common.os.PlatformPropsImpl; - -/** - * For alignment and size see {@link com.jogamp.gluegen} - */ -public class MachineDescription { - /* arch os int, long, float, doubl, ldoubl, ptr, page */ - private final static int[] size_armeabi = { 4, 4, 4, 8, 8, 4, 4096 }; - private final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; - private final static int[] size_x86_32_macos = { 4, 4, 4, 8, 16, 4, 4096 }; - private final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; - private final static int[] size_lp64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; - private final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; - private final static int[] size_sparc_32_sunos = { 4, 4, 4, 8, 16, 4, 8192 }; - - /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */ - private final static int[] align_armeabi = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; - private final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; - private final static int[] align_x86_32_macos = { 1, 2, 4, 4, 4, 4, 4, 4, 16, 4 }; - private final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; - private final static int[] align_lp64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; - private final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; - private final static int[] align_sparc_32_sunos = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; - - public enum StaticConfig { - /** {@link Platform.CPUType#ARM} EABI Little Endian */ - ARMle_EABI(true, size_armeabi, align_armeabi), - /** {@link Platform.CPUType#X86_32} Little Endian Unix */ - X86_32_UNIX(true, size_x86_32_unix, align_x86_32_unix), - /** LP64 Unix, e.g.: {@link Platform.CPUType#X86_64} Little Endian Unix, {@link Platform.CPUType#ARM64} EABI Little Endian, ... */ - LP64_UNIX(true, size_lp64_unix, align_lp64_unix), - /** {@link Platform.CPUType#X86_32} Little Endian MacOS (Special case gcc4/OSX) */ - X86_32_MACOS(true, size_x86_32_macos, align_x86_32_macos), - /** {@link Platform.CPUType#X86_32} Little Endian Windows */ - X86_32_WINDOWS(true, size_x86_32_windows, align_x86_32_windows), - /** {@link Platform.CPUType#X86_64} Little Endian Windows */ - X86_64_WINDOWS(true, size_x86_64_windows, align_x86_64_windows), - /** {@link Platform.CPUType#SPARC_32} Big Endian Solaris */ - SPARC_32_SUNOS(false, size_sparc_32_sunos, align_sparc_32_sunos); - - public final MachineDescription md; - - StaticConfig(final boolean littleEndian, final int[] sizes, final int[] alignments) { - int i=0, j=0; - this.md = new MachineDescription(false, littleEndian, - sizes[i++], - sizes[i++], - sizes[i++], - sizes[i++], - sizes[i++], - sizes[i++], - sizes[i++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++], - alignments[j++]); - } - - public final StringBuilder toString(StringBuilder sb) { - if(null==sb) { - sb = new StringBuilder(); - } - sb.append("MachineDescriptionStatic: ").append(this.name()).append("(").append(this.ordinal()).append("): "); - md.toString(sb); - return sb; - } - public final String toShortString() { - return this.name()+"("+this.ordinal()+")"; - } - @Override - public String toString() { - return toString(null).toString(); - } - } - - - 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 intSizeInBytes; - final private int longSizeInBytes; - final private int floatSizeInBytes; - final private int doubleSizeInBytes; - final private int ldoubleSizeInBytes; - final private int pointerSizeInBytes; - final private int pageSizeInBytes; - - final private int int8AlignmentInBytes; - final private int int16AlignmentInBytes; - final private int int32AlignmentInBytes; - final private int int64AlignmentInBytes; - final private int intAlignmentInBytes; - final private int longAlignmentInBytes; - final private int floatAlignmentInBytes; - final private int doubleAlignmentInBytes; - final private int ldoubleAlignmentInBytes; - final private int pointerAlignmentInBytes; - - public MachineDescription(final boolean runtimeValidated, - final boolean littleEndian, - - final int intSizeInBytes, - final int longSizeInBytes, - final int floatSizeInBytes, - final int doubleSizeInBytes, - final int ldoubleSizeInBytes, - final int pointerSizeInBytes, - final int pageSizeInBytes, - - final int int8AlignmentInBytes, - final int int16AlignmentInBytes, - final int int32AlignmentInBytes, - final int int64AlignmentInBytes, - final int intAlignmentInBytes, - final int longAlignmentInBytes, - final int floatAlignmentInBytes, - final int doubleAlignmentInBytes, - final int ldoubleAlignmentInBytes, - final int pointerAlignmentInBytes) { - this.runtimeValidated = runtimeValidated; - this.littleEndian = littleEndian; - - this.intSizeInBytes = intSizeInBytes; - this.longSizeInBytes = longSizeInBytes; - this.floatSizeInBytes = floatSizeInBytes; - this.doubleSizeInBytes = doubleSizeInBytes; - this.ldoubleSizeInBytes = ldoubleSizeInBytes; - this.pointerSizeInBytes = pointerSizeInBytes; - this.pageSizeInBytes = pageSizeInBytes; - - this.int8AlignmentInBytes = int8AlignmentInBytes; - this.int16AlignmentInBytes = int16AlignmentInBytes; - this.int32AlignmentInBytes = int32AlignmentInBytes; - this.int64AlignmentInBytes = int64AlignmentInBytes; - this.intAlignmentInBytes = intAlignmentInBytes; - this.longAlignmentInBytes = longAlignmentInBytes; - this.floatAlignmentInBytes = floatAlignmentInBytes; - this.doubleAlignmentInBytes = doubleAlignmentInBytes; - this.ldoubleAlignmentInBytes = ldoubleAlignmentInBytes; - 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; - } - - 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 ldoubleSizeInBytes() { return ldoubleSizeInBytes; } - public final int pointerSizeInBytes() { return pointerSizeInBytes; } - public final int pageSizeInBytes() { return pageSizeInBytes; } - - 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 ldoubleAlignmentInBytes() { return ldoubleAlignmentInBytes; } - public final int pointerAlignmentInBytes() { return pointerAlignmentInBytes; } - - /** - * @return number of pages required for size in bytes - */ - public int pageCount(final int size) { - return ( size + ( pageSizeInBytes - 1) ) / pageSizeInBytes ; // integer arithmetic - } - - /** - * @return page aligned size in bytes - */ - public int pageAlignedSize(final int size) { - return pageCount(size) * pageSizeInBytes; - } - - /** - * Checks whether two size objects are equal. Two instances - * of MachineDescription are considered equal if all components - * match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}. - * @return true if the two MachineDescription are equal; - * otherwise false. - */ - @Override - public final boolean equals(final Object obj) { - if (this == obj) { return true; } - if ( !(obj instanceof MachineDescription) ) { return false; } - final MachineDescription md = (MachineDescription) obj; - - return pageSizeInBytes == md.pageSizeInBytes && - compatible(md); - } - - /** - * Checks whether two size objects are equal. Two instances - * of MachineDescription are considered equal if all components - * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}. - * @return true if the two MachineDescription are equal; - * otherwise false. - */ - public final boolean compatible(final MachineDescription md) { - return littleEndian == md.littleEndian && - - intSizeInBytes == md.intSizeInBytes && - longSizeInBytes == md.longSizeInBytes && - floatSizeInBytes == md.floatSizeInBytes && - doubleSizeInBytes == md.doubleSizeInBytes && - ldoubleSizeInBytes == md.ldoubleSizeInBytes && - pointerSizeInBytes == md.pointerSizeInBytes && - - int8AlignmentInBytes == md.int8AlignmentInBytes && - int16AlignmentInBytes == md.int16AlignmentInBytes && - int32AlignmentInBytes == md.int32AlignmentInBytes && - int64AlignmentInBytes == md.int64AlignmentInBytes && - intAlignmentInBytes == md.intAlignmentInBytes && - longAlignmentInBytes == md.longAlignmentInBytes && - floatAlignmentInBytes == md.floatAlignmentInBytes && - doubleAlignmentInBytes == md.doubleAlignmentInBytes && - ldoubleAlignmentInBytes == md.ldoubleAlignmentInBytes && - pointerAlignmentInBytes == md.pointerAlignmentInBytes ; - } - - public StringBuilder toString(StringBuilder sb) { - if(null==sb) { - sb = new StringBuilder(); - } - sb.append("MachineDescription: runtimeValidated ").append(isRuntimeValidated()).append(", littleEndian ").append(isLittleEndian()).append(", 32Bit ").append(4 == pointerAlignmentInBytes).append(", primitive size / alignment:").append(PlatformPropsImpl.NEWLINE); - sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes); - sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline()); - sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes); - sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline()); - 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(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline()); - 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/Platform.java b/src/java/com/jogamp/common/os/Platform.java index 6f6c99d..2e63550 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -41,7 +41,7 @@ import com.jogamp.common.util.VersionNumber; import com.jogamp.common.util.cache.TempJarCache; import jogamp.common.jvm.JVMUtil; -import jogamp.common.os.MachineDescriptionRuntime; +import jogamp.common.os.MachineDataInfoRuntime; import jogamp.common.os.PlatformPropsImpl; /** @@ -50,7 +50,7 @@ import jogamp.common.os.PlatformPropsImpl; * Some field declarations and it's static initialization has been delegated * to it's super class {@link PlatformPropsImpl} to solve * static initialization interdependencies w/ the GlueGen native library loading - * and it's derived information {@link #getMachineDescription()}, {@link #is32Bit()}, ..
+ * and it's derived information {@link #getMachineDataInfo()}, {@link #is32Bit()}, ..
* This mechanism is preferred in this case to avoid synchronization and locking * and allow better performance accessing the mentioned fields/methods. *

@@ -75,42 +75,51 @@ public class Platform extends PlatformPropsImpl { /** PA RISC */ PA_RISC, /** Itanium */ - IA64; + IA64, + /** Hitachi SuperH */ + SuperH; } public enum CPUType { - /** X86 32bit */ - X86_32( CPUFamily.X86, true), - /** X86 64bit */ - X86_64( CPUFamily.X86, false), - /** ARM 32bit default */ + /** ARM 32bit default, usually little endian */ ARM( CPUFamily.ARM, true), - /** ARM7EJ, ARM9E, ARM10E, XScale */ + /** ARM7EJ, ARM9E, ARM10E, XScale, usually little endian */ ARMv5( CPUFamily.ARM, true), - /** ARM11 */ + /** ARM11, usually little endian */ ARMv6( CPUFamily.ARM, true), - /** ARM Cortex */ + /** ARM Cortex, usually little endian */ ARMv7( CPUFamily.ARM, true), - /** ARM64 default (64bit) */ + // 4 + + /** X86 32bit, little endian */ + X86_32( CPUFamily.X86, true), + /** PPC 32bit default, usually big endian */ + PPC( CPUFamily.PPC, true), + /** MIPS 32bit, big endian (mips) or little endian (mipsel) */ + MIPS_32( CPUFamily.MIPS, true), + /** Hitachi SuperH 32bit default, ??? endian */ + SuperH( CPUFamily.SuperH, true), + /** SPARC 32bit, big endian */ + SPARC_32( CPUFamily.SPARC, true), + // 9 + + /** ARM64 default (64bit), usually little endian */ ARM64( CPUFamily.ARM, false), - /** ARM AArch64 (64bit) */ + /** ARM AArch64 (64bit), usually little endian */ ARMv8_A( CPUFamily.ARM, false), - /** PPC 32bit default */ - PPC( CPUFamily.PPC, true), - /** PPC 64bit default */ + /** X86 64bit, little endian */ + X86_64( CPUFamily.X86, false), + /** PPC 64bit default, usually big endian */ PPC64( CPUFamily.PPC, false), - /** SPARC 32bit */ - SPARC_32( CPUFamily.SPARC, true), - /** SPARC 64bit */ - SPARCV9_64(CPUFamily.SPARC, false), - /** MIPS 32bit */ - MIPS_32( CPUFamily.MIPS, true), - /** MIPS 64bit */ + /** MIPS 64bit, big endian (mips64) or little endian (mipsel64) ? */ MIPS_64( CPUFamily.MIPS, false), - /** Itanium 64bit default */ + /** Itanium 64bit default, little endian */ IA64( CPUFamily.IA64, false), - /** PA_RISC2_0 64bit */ + /** SPARC 64bit, big endian */ + SPARCV9_64(CPUFamily.SPARC, false), + /** PA_RISC2_0 64bit, ??? endian */ PA_RISC2_0(CPUFamily.PA_RISC, false); + // 17 public final CPUFamily family; public final boolean is32Bit; @@ -186,8 +195,12 @@ public class Platform extends PlatformPropsImpl { return PPC64; } else if( cpuABILower.startsWith("ppc") ) { return PPC; + } else if( cpuABILower.startsWith("mips64") ) { + return MIPS_64; } else if( cpuABILower.startsWith("mips") ) { return MIPS_32; + } else if( cpuABILower.startsWith("superh") ) { + return SuperH; } else { throw new RuntimeException("Please port CPUType detection to your platform (CPU_ABI string '" + cpuABILower + "')"); } @@ -259,7 +272,7 @@ public class Platform extends PlatformPropsImpl { // post loading native lib: // - private static final MachineDescription machineDescription; + private static final MachineDataInfo machineDescription; /** true if AWT is available and not in headless mode, otherwise false. */ public static final boolean AWT_AVAILABLE; @@ -320,19 +333,11 @@ public class Platform extends PlatformPropsImpl { USE_TEMP_JAR_CACHE = _USE_TEMP_JAR_CACHE[0]; AWT_AVAILABLE = _AWT_AVAILABLE[0]; - final MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); - MachineDescription md = MachineDescriptionRuntime.getRuntime(); - if(null == md) { - md = smd.md; - System.err.println("Warning: Using static MachineDescription: "+smd); - } else { - if(!md.compatible(smd.md)) { - throw new RuntimeException("Incompatible MachineDescriptions:"+PlatformPropsImpl.NEWLINE+ - " Static "+smd+PlatformPropsImpl.NEWLINE+ - " Runtime "+md); - } - } - machineDescription = md; + // + // Validate and setup MachineDataInfo.StaticConfig + // + MachineDataInfoRuntime.initialize(); + machineDescription = MachineDataInfoRuntime.getRuntime(); } private Platform() {} @@ -496,9 +501,9 @@ public class Platform extends PlatformPropsImpl { } /** - * Returns the MachineDescription of the running machine. + * Returns the MachineDataInfo of the running machine. */ - public static MachineDescription getMachineDescription() { + public static MachineDataInfo getMachineDataInfo() { return machineDescription; } diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 1fd7cbf..c773b21 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -54,7 +54,7 @@ import jogamp.common.os.PlatformPropsImpl; import com.jogamp.common.net.AssetURLContext; import com.jogamp.common.net.Uri; import com.jogamp.common.nio.Buffers; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; import com.jogamp.common.os.Platform; public class IOUtil { @@ -160,14 +160,14 @@ public class IOUtil { * @throws IOException */ public static int copyStream2Stream(final InputStream in, final OutputStream out, final int totalNumBytes) throws IOException { - return copyStream2Stream(Platform.getMachineDescription().pageSizeInBytes(), in, out, totalNumBytes); + return copyStream2Stream(Platform.getMachineDataInfo().pageSizeInBytes(), in, out, totalNumBytes); } /** * Copy the specified input stream to the specified output stream. The total * number of bytes written is returned. * - * @param bufferSize the intermediate buffer size, should be {@link MachineDescription#pageSizeInBytes()} for best performance. + * @param bufferSize the intermediate buffer size, should be {@link MachineDataInfo#pageSizeInBytes()} for best performance. * @param in the source * @param out the destination * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown @@ -246,7 +246,7 @@ public class IOUtil { if( initialCapacity < avail ) { initialCapacity = avail; } - final MachineDescription machine = Platform.getMachineDescription(); + final MachineDataInfo machine = Platform.getMachineDataInfo(); ByteBuffer data = Buffers.newDirectByteBuffer( machine.pageAlignedSize( initialCapacity ) ); final byte[] chunk = new byte[machine.pageSizeInBytes()]; int chunk2Read = Math.min(machine.pageSizeInBytes(), avail); diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java index aef3fc2..6fec8fa 100644 --- a/src/java/com/jogamp/common/util/VersionUtil.java +++ b/src/java/com/jogamp/common/util/VersionUtil.java @@ -59,7 +59,7 @@ public class VersionUtil { // environment sb.append("Platform: ").append(Platform.getOSType()).append(" / ").append(Platform.getOSName()).append(' ').append(Platform.getOSVersion()).append(" (").append(Platform.getOSVersionNumber()).append("), "); sb.append(Platform.getArchName()).append(" (").append(Platform.getCPUType()).append(", ").append(Platform.getABIType()).append("), "); - sb.append(Runtime.getRuntime().availableProcessors()).append(" cores"); + sb.append(Runtime.getRuntime().availableProcessors()).append(" cores, ").append("littleEndian ").append(PlatformPropsImpl.LITTLE_ENDIAN); sb.append(Platform.getNewline()); if( Platform.OSType.ANDROID == PlatformPropsImpl.OS_TYPE ) { sb.append("Platform: Android Version: ").append(AndroidVersion.CODENAME).append(", "); @@ -67,7 +67,7 @@ public class VersionUtil { sb.append(Platform.getNewline()); } - Platform.getMachineDescription().toString(sb).append(Platform.getNewline()); + Platform.getMachineDataInfo().toString(sb).append(Platform.getNewline()); // JVM/JRE sb.append("Platform: Java Version: ").append(Platform.getJavaVersion()).append(" (").append(Platform.getJavaVersionNumber()).append("u").append(PlatformPropsImpl.JAVA_VERSION_UPDATE).append("), VM: ").append(Platform.getJavaVMName()); -- cgit v1.2.3