diff options
author | Sven Gothel <[email protected]> | 2011-07-21 11:06:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-07-21 11:06:52 +0200 |
commit | dc4b259b6651bdc0cec0895bc74e26e504870c8e (patch) | |
tree | afd356aa28e4091ce12c8c6bc5e3a6b9edf48a58 /src/java/jogamp/common/os | |
parent | 8e0d7f00c69d79bcdac4be508e5b5999b423e904 (diff) |
GlueGen proper size / alignment of primitive and compound types usage [2/2] - Fin
MachineDesction == MD
MD.StaticConfig:
- enum for all supported static configs (ID -> MD)
- verified at runtime: test runtime queried-MD versus static-MD,
hard fail if not compatible (size/alignment)
SizeThunk primitive sizes:
- Add notion of fixed native size (eg. int64_t) and otherwise (eg. long)
java struct 'wrappers' code generation:
- single class using size/offset arrays of all MachineDescription configurations
- at runtime the array idx is queried in static block
- type aligment for not fixed-native-size types (SizeThunk, undef long/int) via StructAccessor
junit test:
- add float test
- fix native code
- add java (create, write) -> native (verify) test
works (tested) on: linux 32/64 and windows 32/64
Diffstat (limited to 'src/java/jogamp/common/os')
-rw-r--r-- | src/java/jogamp/common/os/MachineDescriptionRuntime.java | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/src/java/jogamp/common/os/MachineDescriptionRuntime.java b/src/java/jogamp/common/os/MachineDescriptionRuntime.java index a5ecc1d..bf49105 100644 --- a/src/java/jogamp/common/os/MachineDescriptionRuntime.java +++ b/src/java/jogamp/common/os/MachineDescriptionRuntime.java @@ -28,64 +28,96 @@ package jogamp.common.os; -import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.MachineDescription; import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.os.Platform; - -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; +import com.jogamp.common.os.MachineDescription.StaticConfig; /** * Runtime MachineDescription */ public class MachineDescriptionRuntime { - public static MachineDescription getMachineDescription(boolean is32BitByCPUArch) { - boolean libsLoaded = true; + static volatile boolean smdQueried = false; + static MachineDescription.StaticConfig smd = null; + + public static MachineDescription.StaticConfig getStatic() { + if(!smdQueried) { + synchronized(MachineDescription.class) { // volatile dbl-checked-locking OK + if(!smdQueried) { + smd = getStaticImpl(); + smdQueried=true; + } + } + } + return smd; + } + private static MachineDescription.StaticConfig getStaticImpl() { + if(Platform.isCPUArch32Bit()) { + if(Platform.getCPUFamily() == Platform.CPUFamily.ARM && Platform.isLittleEndian()) { + return StaticConfig.ARMle_EABI; + } else if(Platform.getOSType() == Platform.OSType.WINDOWS) { + return StaticConfig.X86_32_WINDOWS; + } + return StaticConfig.X86_32_UNIX; + } else { + if(Platform.getOSType() == Platform.OSType.WINDOWS) { + return StaticConfig.X86_64_WINDOWS; + } + return StaticConfig.X86_64_UNIX; + } + } + + static volatile boolean rmdQueried = false; + static MachineDescription rmd = null; + + public static MachineDescription getRuntime() { + if(!rmdQueried) { + synchronized(MachineDescription.class) { // volatile dbl-checked-locking OK + if(!rmdQueried) { + rmd = getRuntimeImpl(); + rmdQueried=true; + } + } + } + return rmd; + } + private static MachineDescription getRuntimeImpl() { try { NativeLibrary.ensureNativeLibLoaded(); } catch (UnsatisfiedLinkError err) { - libsLoaded = false; + return null; } - if(libsLoaded) { - int pointerSizeInBytes = getPointerSizeInBytesImpl(); - switch(pointerSizeInBytes) { - case 4: - case 8: - break; - default: - throw new RuntimeException("Unsupported pointer size "+pointerSizeInBytes+"bytes, please implement."); - } - - final long pageSizeL = getPageSizeInBytesImpl(); - if(Integer.MAX_VALUE < pageSizeL) { - throw new InternalError("PageSize exceeds integer value: " + pageSizeL); - } - - return getMachineDescriptionImpl(pointerSizeInBytes, (int) pageSizeL); - } else { - return MachineDescription.createStatic(is32BitByCPUArch); + int pointerSizeInBytes = getPointerSizeInBytesImpl(); + switch(pointerSizeInBytes) { + case 4: + case 8: + break; + default: + throw new RuntimeException("Unsupported pointer size "+pointerSizeInBytes+"bytes, please implement."); } - } - private static MachineDescription getMachineDescriptionImpl(int pointerSize, int pageSize) { + final long pageSizeL = getPageSizeInBytesImpl(); + if(Integer.MAX_VALUE < pageSizeL) { + throw new InternalError("PageSize exceeds integer value: " + pageSizeL); + } + // size: int, long, float, double, pointer, pageSize // alignment: int8, int16, int32, int64, int, long, float, double, pointer return new MachineDescription( - true /* runtime validated */, MachineDescription.queryIsLittleEndian(), + true /* runtime validated */, Platform.isLittleEndian(), getSizeOfIntImpl(), getSizeOfLongImpl(), - getSizeOfFloatImpl(), getSizeOfDoubleImpl(), getSizeOfLongDoubleImpl(), pointerSize, pageSize, + getSizeOfFloatImpl(), getSizeOfDoubleImpl(), getSizeOfLongDoubleImpl(), + pointerSizeInBytes, (int)pageSizeL, getAlignmentInt8Impl(), getAlignmentInt16Impl(), getAlignmentInt32Impl(), getAlignmentInt64Impl(), getAlignmentIntImpl(), getAlignmentLongImpl(), getAlignmentFloatImpl(), getAlignmentDoubleImpl(), getAlignmentLongDoubleImpl(), getAlignmentPointerImpl()); } - + private static native int getPointerSizeInBytesImpl(); private static native long getPageSizeInBytesImpl(); |