diff options
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r-- | src/java/com/jogamp/common/nio/StructAccessor.java | 65 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/MachineDescription.java | 294 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 40 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/DebugEmitter.java | 3 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/GlueEmitter.java | 20 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/GlueGen.java | 5 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 378 | ||||
-rwxr-xr-x | src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java | 35 |
8 files changed, 433 insertions, 407 deletions
diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java index 5c0e70a..41da290 100644 --- a/src/java/com/jogamp/common/nio/StructAccessor.java +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -113,6 +113,37 @@ public class StructAccessor { bb.putInt(byteOffset, v); } + /** Retrieves the int at the specified byteOffset. */ + public final int getIntAt(int byteOffset, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 2: + return (int) bb.getShort(byteOffset) & 0x0000FFFF ; + case 4: + return bb.getInt(byteOffset); + case 8: + return (int) ( bb.getLong(byteOffset) & 0x00000000FFFFFFFFL ) ; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + + /** Puts a int at the specified byteOffset. */ + public final void setIntAt(int byteOffset, int v, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 2: + bb.putShort(byteOffset, (short) ( v & 0x0000FFFF ) ); + break; + case 4: + bb.putInt(byteOffset, v); + break; + case 8: + bb.putLong(byteOffset, (long)v & 0x00000000FFFFFFFFL ); + break; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + /** Retrieves the float at the specified byteOffset. */ public final float getFloatAt(int byteOffset) { return bb.getFloat(byteOffset); @@ -133,20 +164,42 @@ public class StructAccessor { bb.putDouble(byteOffset, v); } - /** - * Retrieves the long at the specified byteOffset. - */ + /** Retrieves the long at the specified byteOffset. */ public final long getLongAt(int byteOffset) { return bb.getLong(byteOffset); } - /** - * Puts a long at the specified byteOffset. - */ + /** Puts a long at the specified byteOffset. */ public final void setLongAt(int byteOffset, long v) { bb.putLong(byteOffset, v); } + /** Retrieves the long at the specified byteOffset. */ + public final long getLongAt(int byteOffset, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 4: + return (long) bb.getInt(byteOffset) & 0x00000000FFFFFFFFL; + case 8: + return bb.getLong(byteOffset); + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + + /** Puts a long at the specified byteOffset. */ + public final void setLongAt(int byteOffset, long v, int nativeSizeInBytes) { + switch(nativeSizeInBytes) { + case 4: + bb.putInt(byteOffset, (int) ( v & 0x00000000FFFFFFFFL ) ); + break; + case 8: + bb.putLong(byteOffset, v); + break; + default: + throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); + } + } + public final void setBytesAt(int byteOffset, byte[] v) { for (int i = 0; i < v.length; i++) { bb.put(byteOffset++, v[i]); diff --git a/src/java/com/jogamp/common/os/MachineDescription.java b/src/java/com/jogamp/common/os/MachineDescription.java index 7534917..43f2975 100644 --- a/src/java/com/jogamp/common/os/MachineDescription.java +++ b/src/java/com/jogamp/common/os/MachineDescription.java @@ -40,77 +40,93 @@ package com.jogamp.common.os; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; - -import com.jogamp.common.nio.Buffers; - /** * For alignment and size see {@link com.jogamp.gluegen} */ public class MachineDescription { - /* arch os int, long, float, doubl, ldoubl, ptr, page */ - final static int[] size_armeabi = { 4, 4, 4, 8, 8, 4, 4096 }; - final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; - final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; - final static int[] size_x86_64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; - final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; + public enum ID { + /** {@link Platform.CPUType#ARM} EABI Little Endian */ + ARMle_EABI(Platform.CPUType.ARM), + /** {@link Platform.CPUType#X86_32} Little Endian Unix */ + X86_32_UNIX(Platform.CPUType.X86_32), + /** {@link Platform.CPUType#X86_64} Little Endian Unix */ + X86_64_UNIX(Platform.CPUType.X86_64), + /** {@link Platform.CPUType#X86_32} Little Endian Windows */ + X86_32_WINDOWS(Platform.CPUType.X86_32), + /** {@link Platform.CPUType#X86_64} Little Endian Windows */ + X86_64_WINDOWS(Platform.CPUType.X86_64); + + public final Platform.CPUType cpu; + + ID(Platform.CPUType cpu){ + this.cpu = cpu; + } + } + + /* 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_windows = { 4, 4, 4, 8, 12, 4, 4096 }; + private final static int[] size_x86_64_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 */ - final static int[] align_armeabi = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; - final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; - final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; - final static int[] align_x86_64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; - final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; + /* 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_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; + private final static int[] align_x86_64_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 }; - public enum Config { - ARM_EABI(size_armeabi, align_armeabi), - X86_32_UNIX(size_x86_32_unix, align_x86_32_unix), - X86_64_UNIX(size_x86_64_unix, align_x86_64_unix), - X86_32_WINDOWS(size_x86_32_windows, align_x86_32_windows), - X86_64_WINDOWS(size_x86_64_windows, align_x86_64_windows); + public enum StaticConfig { + /** {@link MachineDescription.ID#ARMle_EABI } */ + ARMle_EABI(ID.ARMle_EABI, true, size_armeabi, align_armeabi), + /** {@link MachineDescription.ID#X86_32_UNIX } */ + X86_32_UNIX(ID.X86_32_UNIX, true, size_x86_32_unix, align_x86_32_unix), + /** {@link MachineDescription.ID#X86_64_UNIX } */ + X86_64_UNIX(ID.X86_64_UNIX, true, size_x86_64_unix, align_x86_64_unix), + /** {@link MachineDescription.ID#X86_32_WINDOWS } */ + X86_32_WINDOWS(ID.X86_32_WINDOWS, true, size_x86_32_windows, align_x86_32_windows), + /** {@link MachineDescription.ID#X86_64_WINDOWS } */ + X86_64_WINDOWS(ID.X86_64_WINDOWS, true, size_x86_64_windows, align_x86_64_windows); - public final int intSizeInBytes; - public final int longSizeInBytes; - public final int floatSizeInBytes; - public final int doubleSizeInBytes; - public final int ldoubleSizeInBytes; - public final int pointerSizeInBytes; - public final int pageSizeInBytes; + public final ID id; + public final MachineDescription md; - public final int int8AlignmentInBytes; - public final int int16AlignmentInBytes; - public final int int32AlignmentInBytes; - public final int int64AlignmentInBytes; - public final int intAlignmentInBytes; - public final int longAlignmentInBytes; - public final int floatAlignmentInBytes; - public final int doubleAlignmentInBytes; - public final int ldoubleAlignmentInBytes; - public final int pointerAlignmentInBytes; + StaticConfig(ID id, boolean littleEndian, int[] sizes, int[] alignments) { + this.id = id; + 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++]); + } - Config(int[] sizes, int[] alignments) { - int i=0; - intSizeInBytes = sizes[i++]; - longSizeInBytes = sizes[i++];; - floatSizeInBytes = sizes[i++];; - doubleSizeInBytes = sizes[i++];; - ldoubleSizeInBytes = sizes[i++];; - pointerSizeInBytes = sizes[i++];; - pageSizeInBytes = sizes[i++];; - - i=0; - int8AlignmentInBytes = alignments[i++]; - int16AlignmentInBytes = alignments[i++]; - int32AlignmentInBytes = alignments[i++]; - int64AlignmentInBytes = alignments[i++]; - intAlignmentInBytes = alignments[i++]; - longAlignmentInBytes = alignments[i++]; - floatAlignmentInBytes = alignments[i++]; - doubleAlignmentInBytes = alignments[i++]; - ldoubleAlignmentInBytes = alignments[i++]; - pointerAlignmentInBytes = alignments[i++]; + public 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; + } + + @Override + public String toString() { + return toString(null).toString(); } } @@ -144,72 +160,6 @@ public class MachineDescription { final private int ldoubleAlignmentInBytes; final private int pointerAlignmentInBytes; - public static boolean queryIsLittleEndian() { - 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); - } - - public static MachineDescription createStaticArmEABI() { - return new MachineDescription(false, queryIsLittleEndian(), Config.ARM_EABI); - } - public static MachineDescription createStaticUnix32() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_32_UNIX); - } - public static MachineDescription createStaticUnix64() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_64_UNIX); - } - public static MachineDescription createStaticWindows32() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_32_WINDOWS); - } - public static MachineDescription createStaticWindows64() { - return new MachineDescription(false, queryIsLittleEndian(), Config.X86_64_WINDOWS); - } - public static MachineDescription createStatic(boolean is32BitByCPUArch) { - if(is32BitByCPUArch) { - if(Platform.getCPUFamily() == Platform.CPUFamily.ARM) { - return createStaticArmEABI(); - } else if(Platform.getOSType() == Platform.OSType.WINDOWS) { - return createStaticWindows32(); - } - return createStaticUnix32(); - } else { - if(Platform.getOSType() == Platform.OSType.WINDOWS) { - return createStaticWindows64(); - } - return createStaticUnix64(); - } - } - - public MachineDescription(boolean runtimeValidated, - boolean littleEndian, - Config config) { - this.runtimeValidated = runtimeValidated; - this.littleEndian = littleEndian; - - this.intSizeInBytes = config.intSizeInBytes; - this.longSizeInBytes = config.longSizeInBytes; - this.floatSizeInBytes = config.floatSizeInBytes; - this.doubleSizeInBytes = config.doubleSizeInBytes; - this.ldoubleSizeInBytes = config.ldoubleSizeInBytes; - this.pointerSizeInBytes = config.pointerSizeInBytes; - this.pageSizeInBytes = config.pageSizeInBytes; - this.is32Bit = 4 == config.pointerSizeInBytes; - - this.int8AlignmentInBytes = config.int8AlignmentInBytes; - this.int16AlignmentInBytes = config.int16AlignmentInBytes; - this.int32AlignmentInBytes = config.int32AlignmentInBytes; - this.int64AlignmentInBytes = config.int64AlignmentInBytes; - this.intAlignmentInBytes = config.intAlignmentInBytes; - this.longAlignmentInBytes = config.longAlignmentInBytes; - this.floatAlignmentInBytes = config.floatAlignmentInBytes; - this.doubleAlignmentInBytes = config.doubleAlignmentInBytes; - this.ldoubleAlignmentInBytes = config.ldoubleAlignmentInBytes; - this.pointerAlignmentInBytes = config.pointerAlignmentInBytes; - } - public MachineDescription(boolean runtimeValidated, boolean littleEndian, @@ -319,29 +269,75 @@ public class MachineDescription { public int pageAlignedSize(int size) { return pageCount(size) * pageSizeInBytes; } + + /** + * Checks whether two size objects are equal. Two instances + * of <code>MachineDescription</code> are considered equal if all components + * match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}. + * @return <code>true</code> if the two MachineDescription are equal; + * otherwise <code>false</code>. + */ + public final boolean equals(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 <code>MachineDescription</code> are considered equal if all components + * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}. + * @return <code>true</code> if the two MachineDescription are equal; + * otherwise <code>false</code>. + */ + public final boolean compatible(MachineDescription md) { + return littleEndian == md.littleEndian && + + intSizeInBytes == md.intSizeInBytes && + longSizeInBytes == md.longSizeInBytes && + floatSizeInBytes == md.floatSizeInBytes && + doubleSizeInBytes == md.doubleSizeInBytes && + ldoubleSizeInBytes == md.ldoubleSizeInBytes && + pointerSizeInBytes == md.pointerSizeInBytes && + is32Bit == md.is32Bit && + + 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(is32Bit()).append(", primitive size / alignment:").append(Platform.getNewline()); - 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; + 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(" 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(); - } + @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 85567a8..4db5b09 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -28,9 +28,14 @@ package com.jogamp.common.os; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; import java.security.AccessController; import java.security.PrivilegedAction; +import com.jogamp.common.nio.Buffers; + import jogamp.common.os.MachineDescriptionRuntime; /** @@ -41,6 +46,7 @@ import jogamp.common.os.MachineDescriptionRuntime; 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; @@ -139,6 +145,8 @@ public class Platform { JAVA_SE = initIsJavaSE(); + LITTLE_ENDIAN = queryIsLittleEndianImpl(); + if( ARCH_lower.equals("x86") || ARCH_lower.equals("i386") || ARCH_lower.equals("i486") || @@ -171,13 +179,34 @@ public class Platform { } OS_TYPE = getOSTypeImpl(); - machineDescription = MachineDescriptionRuntime.getMachineDescription(getIs32BitByCPUArchImpl()); + MachineDescription md = MachineDescriptionRuntime.getRuntime(); + if(null == md) { + MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); + md = smd.md; + System.err.println("Warning: Using static MachineDescription: "+smd); + } else { + MachineDescription.StaticConfig smd = MachineDescriptionRuntime.getStatic(); + if(!md.compatible(smd.md)) { + throw new RuntimeException("Incompatible MachineDescriptions:"+Platform.NEWLINE+ + " Static "+smd+Platform.NEWLINE+ + " Runtime "+md); + } + } + machineDescription = md; is32Bit = machineDescription.is32Bit(); } private Platform() {} - private static boolean getIs32BitByCPUArchImpl() throws RuntimeException { + private static boolean queryIsLittleEndianImpl() { + 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); + } + + public static boolean isCPUArch32Bit() throws RuntimeException { switch( CPU_ARCH ) { case X86_32: case ARM: @@ -257,6 +286,13 @@ public class Platform { } /** + * Returns true if this machine is little endian, otherwise false. + */ + public static boolean isLittleEndian() { + return LITTLE_ENDIAN; + } + + /** * Returns the OS name. */ public static String getOS() { diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java index 6afc55c..ce6ae69 100644 --- a/src/java/com/jogamp/gluegen/DebugEmitter.java +++ b/src/java/com/jogamp/gluegen/DebugEmitter.java @@ -52,9 +52,6 @@ public class DebugEmitter implements GlueEmitter { public void readConfigurationFile(String filename) {} - public void setMachineDescription(MachineDescription md32, - MachineDescription md64) {} - public void beginEmission(GlueEmitterControls controls) { System.out.println("----- BEGIN EMISSION OF GLUE CODE -----"); } diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java index ac1065b..99bf31d 100644 --- a/src/java/com/jogamp/gluegen/GlueEmitter.java +++ b/src/java/com/jogamp/gluegen/GlueEmitter.java @@ -54,26 +54,6 @@ public interface GlueEmitter { public void readConfigurationFile(String filename) throws Exception; - /** Sets the description of the underlying hardware. "md32" - specifies the description of a 32-bit version of the underlying - CPU architecture. "md64" specifies the description of a 64-bit - version of the underlying CPU architecture. At least one must be - specified. When both are specified, the bulk of the glue code is - generated using the 32-bit machine description, but structs are - laid out twice and the base class delegates between the 32-bit - and 64-bit implementation at run time. This allows Java code - which can access both 32-bit and 64-bit versions of the data - structures to be included in the same jar file. <P> - - It is up to the end user to provide the appropriate opaque - definitions to ensure that types of varying size (longs and - pointers in particular) are exposed to Java in such a way that - changing the machine description does not cause different shared - glue code to be generated for the 32- and 64-bit ports. - */ - public void setMachineDescription(MachineDescription md32, - MachineDescription md64); - /** * Begin the emission of glue code. This might include opening files, * emitting class headers, etc. diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index c0e87ee..744d526 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -188,11 +188,6 @@ public class GlueGen implements GlueEmitterControls { } } - // Provide MachineDescriptions to emitter - final MachineDescription md32 = MachineDescription.createStaticUnix32(); - final MachineDescription md64 = MachineDescription.createStaticUnix64(); - emit.setMachineDescription(md32, md64); - // Repackage the enum and #define statements from the parser into a common format // so that SymbolFilters can operate upon both identically constants = new ArrayList<ConstantDefinition>(); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index dfa7594..c68fae8 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -60,6 +60,8 @@ import com.jogamp.gluegen.runtime.types.Type; import java.nio.Buffer; import java.util.logging.Logger; +import jogamp.common.os.MachineDescriptionRuntime; + import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; @@ -97,9 +99,9 @@ public class JavaEmitter implements GlueEmitter { private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class private PrintWriter cWriter; - private MachineDescription machDesc32; - private MachineDescription machDesc64; - + private final MachineDescription machDescJava = MachineDescription.StaticConfig.X86_64_UNIX.md; + private final MachineDescription.StaticConfig[] machDescTargetConfigs = MachineDescription.StaticConfig.values(); + protected final static Logger LOG = Logger.getLogger(JavaEmitter.class.getPackage().getName()); public void readConfigurationFile(String filename) throws Exception { @@ -107,16 +109,6 @@ public class JavaEmitter implements GlueEmitter { cfg.read(filename); } - public void setMachineDescription(MachineDescription md32, MachineDescription md64) { - - if ((md32 == null) && (md64 == null)) { - throw new RuntimeException("Must specify at least one MachineDescription"); - } - - machDesc32 = md32; - machDesc64 = md64; - } - class ConstantRenamer implements SymbolFilter { private List<ConstantDefinition> constants; @@ -615,7 +607,7 @@ public class JavaEmitter implements GlueEmitter { cfg.allStatic(), (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue), !cfg.nioDirectOnly(binding.getName()), - machDesc64); + machDescJava); prepCEmitter(binding, cEmitter); allEmitters.add(cEmitter); } @@ -663,7 +655,7 @@ public class JavaEmitter implements GlueEmitter { try { // Get Java binding for the function - MethodBinding mb = bindFunction(sym, null, null, machDesc64); + MethodBinding mb = bindFunction(sym, null, null, machDescJava); // JavaTypes representing C pointers in the initial // MethodBinding have not been lowered yet to concrete types @@ -771,19 +763,6 @@ public class JavaEmitter implements GlueEmitter { } public void emitStruct(CompoundType structType, String alternateName) throws Exception { - // Emit abstract base class delegating to 32-bit or 64-bit implementations - emitStructImpl(structType, alternateName, machDesc32, machDesc64, true, false); - // Emit concrete implementing class for each variant - emitStructImpl(structType, alternateName, machDesc32, machDesc64, false, true); - emitStructImpl(structType, alternateName, machDesc32, machDesc64, false, false); - } - - public void emitStructImpl(CompoundType structType, - String alternateName, - MachineDescription md32, - MachineDescription md64, - boolean doBaseClass, - boolean do32Bit) throws Exception { String name = structType.getName(); if (name == null && alternateName != null) { name = alternateName; @@ -805,50 +784,31 @@ public class JavaEmitter implements GlueEmitter { } String containingTypeName = containingType.getName(); - if ((md32 == null) || (md64 == null)) { - throw new RuntimeException("Must supply both 32- and 64-bit MachineDescriptions to emitStructImpl"); - } - String suffix = ""; - - // The "external" MachineDescription is the one used to determine - // the sizes of the primitive types seen in the public API. For - // example, if a C long is an element of a struct, it is the size + // machDescJava global MachineDescription is the one used to determine + // the sizes of the primitive types seen in the public API in Java. + // For example, if a C long is an element of a struct, it is the size // of a Java int on a 32-bit machine but the size of a Java long // on a 64-bit machine. To support both of these sizes with the // same API, the abstract base class must take and return a Java // long from the setter and getter for this field. However the // implementation on a 32-bit platform must downcast this to an - // int and set only an int's worth of data in the struct. The - // "internal" MachineDescription is the one used to determine how + // int and set only an int's worth of data in the struct. + // + // The machDescTarget MachineDescription is the one used to determine how // much data to set in or get from the struct and exactly from // where it comes. // - // Note that the 64-bit MachineDescription is always used as the - // external MachineDescription. - - MachineDescription extMachDesc = md64; - MachineDescription intMachDesc = null; - - if (!doBaseClass) { - if (do32Bit) { - intMachDesc = md32; - suffix = "32"; - } else { - intMachDesc = md64; - suffix = "64"; - } - } + // Note that machDescJava MachineDescription is always 64bit unix, + // which complies w/ Java types. boolean needsNativeCode = false; // Native code for calls through function pointers gets emitted // into the abstract base class; Java code which accesses fields // gets emitted into the concrete classes - if (doBaseClass) { - for (int i = 0; i < structType.getNumFields(); i++) { - if (structType.getField(i).getType().isFunctionPointer()) { - needsNativeCode = true; - break; - } + for (int i = 0; i < structType.getNumFields(); i++) { + if (structType.getField(i).getType().isFunctionPointer()) { + needsNativeCode = true; + break; } } @@ -859,7 +819,7 @@ public class JavaEmitter implements GlueEmitter { writer = openFile( cfg.javaOutputDir() + File.separator + CodeGenUtils.packageAsPath(structClassPkg) + - File.separator + containingTypeName + suffix + ".java"); + File.separator + containingTypeName + ".java"); CodeGenUtils.emitAutogeneratedWarning(writer, this); if (needsNativeCode) { String nRoot = cfg.nativeOutputDir(); @@ -883,6 +843,7 @@ public class JavaEmitter implements GlueEmitter { writer.println("import " + cfg.gluegenRuntimePackage() + ".*;"); writer.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;"); writer.println("import " + Buffers.class.getPackage().getName() + ".*;"); + writer.println("import " + MachineDescriptionRuntime.class.getName() + ";"); writer.println(); List<String> imports = cfg.imports(); for (String str : imports) { @@ -895,10 +856,7 @@ public class JavaEmitter implements GlueEmitter { for (String doc : javadoc) { writer.println(doc); } - writer.print((doBaseClass ? "public " : "") + (doBaseClass ? "abstract " : "") + "class " + containingTypeName + suffix + " "); - if (!doBaseClass) { - writer.print("extends " + containingTypeName + " "); - } + writer.print("public class " + containingTypeName + " "); boolean firstIteration = true; List<String> userSpecifiedInterfaces = cfg.implementedInterfaces(containingTypeName); for (String userInterface : userSpecifiedInterfaces) { @@ -911,67 +869,95 @@ public class JavaEmitter implements GlueEmitter { } writer.println("{"); writer.println(); - if (doBaseClass) { - writer.println(" StructAccessor accessor;"); - writer.println(); - } + writer.println(" StructAccessor accessor;"); + writer.println(); + writer.println(" private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();"); + writer.println(); + // generate all offset and size arrays + generateOffsetAndSizeArrays(writer, containingTypeName, structType, null); /* w/o offset */ + for (int i = 0; i < structType.getNumFields(); i++) { + final Field field = structType.getField(i); + final Type fieldType = field.getType(); + + if (!cfg.shouldIgnoreInInterface(name + " " + field.getName())) { + final String renamed = cfg.getJavaSymbolRename(field.getName()); + final String fieldName = renamed==null ? field.getName() : renamed; + if (fieldType.isFunctionPointer()) { + // no offset/size for function pointer .. + } else if (fieldType.isCompound()) { + // FIXME: will need to support this at least in order to + // handle the union in jawt_Win32DrawingSurfaceInfo (fabricate + // a name?) + if (fieldType.getName() == null) { + throw new RuntimeException("Anonymous structs as fields not supported yet (field \"" + + field + "\" in type \"" + name + "\")"); + } + + generateOffsetAndSizeArrays(writer, fieldName, fieldType, field); + } else if (fieldType.isArray()) { + Type baseElementType = field.getType().asArray().getBaseElementType(); + + if(!baseElementType.isPrimitive()) + break; + + generateOffsetAndSizeArrays(writer, fieldName, null, field); /* w/o size */ + } else { + JavaType externalJavaType = null; + try { + externalJavaType = typeToJavaType(fieldType, false, machDescJava); + } catch (Exception e) { + System.err.println("Error occurred while creating accessor for field \"" + + field.getName() + "\" in type \"" + name + "\""); + throw(e); + } + if (externalJavaType.isPrimitive()) { + // Primitive type + generateOffsetAndSizeArrays(writer, fieldName, null, field); /* w/o size */ + } else { + // FIXME + LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name}); + // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + + // "\") not implemented yet"); + } + } + } + } + writer.println(); writer.println(" public static int size() {"); - if (doBaseClass) { - writer.println(" if (Platform.is32Bit()) {"); - writer.println(" return " + containingTypeName + "32" + ".size();"); - writer.println(" } else {"); - writer.println(" return " + containingTypeName + "64" + ".size();"); - writer.println(" }"); - } else { - writer.println(" return " + structType.getSize(intMachDesc) + ";"); - } + writer.println(" return "+containingTypeName+"_size[mdIdx];"); writer.println(" }"); writer.println(); - if (doBaseClass) { - writer.println(" public static " + containingTypeName + " create() {"); - writer.println(" return create(Buffers.newDirectByteBuffer(size()));"); - writer.println(" }"); - writer.println(); - writer.println(" public static " + containingTypeName + " create(java.nio.ByteBuffer buf) {"); - writer.println(" if (Platform.is32Bit()) {"); - writer.println(" return new " + containingTypeName + "32(buf);"); - writer.println(" } else {"); - writer.println(" return new " + containingTypeName + "64(buf);"); - writer.println(" }"); - writer.println(" }"); - writer.println(); - writer.println(" " + containingTypeName + "(java.nio.ByteBuffer buf) {"); - writer.println(" accessor = new StructAccessor(buf);"); - writer.println(" }"); - writer.println(); - writer.println(" public java.nio.ByteBuffer getBuffer() {"); - writer.println(" return accessor.getBuffer();"); - writer.println(" }"); - } else { - writer.println(" " + containingTypeName + suffix + "(java.nio.ByteBuffer buf) {"); - writer.println(" super(buf);"); - writer.println(" }"); - writer.println(); - } - for (int i = 0; i < structType.getNumFields(); i++) { + writer.println(" public static " + containingTypeName + " create() {"); + writer.println(" return create(Buffers.newDirectByteBuffer(size()));"); + writer.println(" }"); + writer.println(); + writer.println(" public static " + containingTypeName + " create(java.nio.ByteBuffer buf) {"); + writer.println(" return new " + containingTypeName + "(buf);"); + writer.println(" }"); + writer.println(); + writer.println(" " + containingTypeName + "(java.nio.ByteBuffer buf) {"); + writer.println(" accessor = new StructAccessor(buf);"); + writer.println(" }"); + writer.println(); + writer.println(" public java.nio.ByteBuffer getBuffer() {"); + writer.println(" return accessor.getBuffer();"); + writer.println(" }"); - Field field = structType.getField(i); - Type fieldType = field.getType(); + for (int i = 0; i < structType.getNumFields(); i++) { + final Field field = structType.getField(i); + final Type fieldType = field.getType(); if (!cfg.shouldIgnoreInInterface(name + " " + field.getName())) { - - String renamed = cfg.getJavaSymbolRename(field.getName()); - String fieldName = renamed==null ? field.getName() : renamed; + final String renamed = cfg.getJavaSymbolRename(field.getName()); + final String fieldName = renamed==null ? field.getName() : renamed; if (fieldType.isFunctionPointer()) { - - if (doBaseClass) { try { // Emit method call and associated native code FunctionType funcType = fieldType.asPointer().getTargetType().asFunction(); FunctionSymbol funcSym = new FunctionSymbol(fieldName, funcType); - MethodBinding binding = bindFunction(funcSym, containingType, containingCType, machDesc64); + MethodBinding binding = bindFunction(funcSym, containingType, containingCType, machDescJava); binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis writer.println(); @@ -1024,14 +1010,13 @@ public class JavaEmitter implements GlueEmitter { false, true, false, // FIXME: should unify this with the general emission code - machDesc64); + machDescJava); prepCEmitter(binding, cEmitter); cEmitter.emit(); } catch (Exception e) { System.err.println("While processing field " + field + " of type " + name + ":"); throw(e); } - } } else if (fieldType.isCompound()) { // FIXME: will need to support this at least in order to // handle the union in jawt_Win32DrawingSurfaceInfo (fabricate @@ -1042,15 +1027,11 @@ public class JavaEmitter implements GlueEmitter { } writer.println(); - generateGetterSignature(writer, doBaseClass, fieldType.getName(), capitalizeString(fieldName)); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.println(" return " + fieldType.getName() + ".create(accessor.slice(" + - field.getOffset(intMachDesc) + ", " + fieldType.getSize(intMachDesc) + "));"); - writer.println(" }"); - } + generateGetterSignature(writer, false, fieldType.getName(), capitalizeString(fieldName)); + writer.println(" {"); + writer.println(" return " + fieldType.getName() + ".create( accessor.slice( " + + fieldName+"_offset[mdIdx], "+fieldName+"_size[mdIdx] ) );"); + writer.println(" }"); } else if (fieldType.isArray()) { @@ -1059,110 +1040,70 @@ public class JavaEmitter implements GlueEmitter { if(!baseElementType.isPrimitive()) break; - String paramType = typeToJavaType(baseElementType, false, extMachDesc).getName(); + String paramType = typeToJavaType(baseElementType, false, machDescJava).getName(); String capitalized = capitalizeString(fieldName); - final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc); - // Setter writer.println(); - generateSetterSignature(writer, doBaseClass, containingTypeName, capitalized, paramType+"[]"); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + byteOffset + ", "); - writer.println("val);"); - writer.println(" return this;"); - writer.println(" }"); - } + generateSetterSignature(writer, false, containingTypeName, capitalized, paramType+"[]"); + writer.println(" {"); + writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + fieldName+"_offset[mdIdx], val);"); + writer.println(" return this;"); + writer.println(" }"); writer.println(); // Getter - generateGetterSignature(writer, doBaseClass, paramType+"[]", capitalized); - if (doBaseClass) { - writer.println(";"); - } else { - writer.println(" {"); - writer.print (" return "); - writer.println("accessor.get" + capitalizeString(paramType) + "sAt(" + byteOffset + ", new " +paramType+"["+fieldType.asArray().getLength()+"]);"); - writer.println(" }"); - } - + generateGetterSignature(writer, false, paramType+"[]", capitalized); + writer.println(" {"); + writer.print (" return accessor.get" + capitalizeString(paramType) + "sAt(" + fieldName+"_offset[mdIdx], new " +paramType+"["+fieldType.asArray().getLength()+"]);"); + writer.println(" }"); } else { - JavaType internalJavaType = null; - JavaType externalJavaType = null; - + JavaType javaType = null; + try { - externalJavaType = typeToJavaType(fieldType, false, extMachDesc); - if (!doBaseClass) { - internalJavaType = typeToJavaType(fieldType, false, intMachDesc); - } + javaType = typeToJavaType(fieldType, false, machDescJava); } catch (Exception e) { System.err.println("Error occurred while creating accessor for field \"" + field.getName() + "\" in type \"" + name + "\""); throw(e); } - if (externalJavaType.isPrimitive()) { + if (javaType.isPrimitive()) { // Primitive type - String externalJavaTypeName = null; - String internalJavaTypeName = null; - externalJavaTypeName = externalJavaType.getName(); - if (!doBaseClass) { - internalJavaTypeName = internalJavaType.getName(); - } + final boolean fieldTypeNativeSizeFixed = fieldType.getSize().hasFixedNativeSize() || isOpaque(fieldType) ; + String javaTypeName = javaType.getName(); if (isOpaque(fieldType)) { - externalJavaTypeName = compatiblePrimitiveJavaTypeName(fieldType, externalJavaType, extMachDesc); - if (!doBaseClass) { - internalJavaTypeName = compatiblePrimitiveJavaTypeName(fieldType, internalJavaType, intMachDesc); - } - } - String capitalized = null; - if (!doBaseClass) { - capitalized = capitalizeString(internalJavaTypeName); + javaTypeName = compatiblePrimitiveJavaTypeName(fieldType, javaType, machDescJava); } - final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc); + String capJavaTypeName = capitalizeString(javaTypeName); + writer.println(); - String capitalizedFieldName = capitalizeString(fieldName); + String capFieldName = capitalizeString(fieldName); // Setter - generateSetterSignature(writer, doBaseClass, containingTypeName, capitalizedFieldName, externalJavaTypeName); - if (doBaseClass) { - writer.println(";"); + generateSetterSignature(writer, false, containingTypeName, capFieldName, javaTypeName); + writer.println(" {"); + if( fieldTypeNativeSizeFixed ) { + writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val);"); } else { - writer.println(" {"); - writer.print (" accessor.set" + capitalized + "At(" + byteOffset + ", "); - if (!externalJavaTypeName.equals(internalJavaTypeName)) { - writer.print("(" + internalJavaTypeName + ") "); - } - writer.println("val);"); - writer.println(" return this;"); - writer.println(" }"); + writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());"); } + writer.println(" return this;"); + writer.println(" }"); writer.println(); + // Getter - generateGetterSignature(writer, doBaseClass, externalJavaTypeName, capitalizedFieldName); - if (doBaseClass) { - writer.println(";"); + generateGetterSignature(writer, false, javaTypeName, capFieldName); + writer.println(" {"); + writer.print (" return "); + if( fieldTypeNativeSizeFixed ) { + writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx]);"); } else { - writer.println(" {"); - writer.print (" return "); - if (!externalJavaTypeName.equals(internalJavaTypeName)) { - writer.print("(" + externalJavaTypeName + ") "); - } - writer.println("accessor.get" + capitalized + "At(" + byteOffset + ");"); - writer.println(" }"); - } - } else { - // FIXME - LOG.log(WARNING, "Complicated fields (field \"{0}\" of type \"{1}\") not implemented yet", new Object[]{field, name}); - // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + - // "\") not implemented yet"); + writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());"); + } + writer.println(" }"); } } } } - if (doBaseClass) { - emitCustomJavaCode(writer, containingTypeName); - } + emitCustomJavaCode(writer, containingTypeName); writer.println("}"); writer.flush(); writer.close(); @@ -1201,14 +1142,39 @@ public class JavaEmitter implements GlueEmitter { // Internals only below this point // - private void generateGetterSignature(PrintWriter writer, boolean baseClass, String returnTypeName, String capitalizedFieldName) { - writer.print(" public " + (baseClass ? "abstract " : "") + returnTypeName + " get" + capitalizedFieldName + "()"); - } + private void generateGetterSignature(PrintWriter writer, boolean abstractMethod, String returnTypeName, String capitalizedFieldName) { + writer.print(" public " + (abstractMethod ? "abstract " : "") + returnTypeName + " get" + capitalizedFieldName + "()"); + } - private void generateSetterSignature(PrintWriter writer, boolean baseClass, String returnTypeName, String capitalizedFieldName, String paramTypeName) { - writer.print(" public " + (baseClass ? "abstract " : "") + returnTypeName + " set" + capitalizedFieldName + "(" + paramTypeName + " val)"); - } + private void generateSetterSignature(PrintWriter writer, boolean abstractMethod, String returnTypeName, String capitalizedFieldName, String paramTypeName) { + writer.print(" public " + (abstractMethod ? "abstract " : "") + returnTypeName + " set" + capitalizedFieldName + "(" + paramTypeName + " val)"); + } + private void generateOffsetAndSizeArrays(PrintWriter writer, String fieldName, Type fieldType, Field field) { + if(null != field) { + writer.print(" private static final int[] "+fieldName+"_offset = new int[] { "); + for( int i=0; i < machDescTargetConfigs.length; i++ ) { + if(0<i) { + writer.print(", "); + } + writer.print(field.getOffset(machDescTargetConfigs[i].md) + + " /* " + machDescTargetConfigs[i].name() + " */"); + } + writer.println(" };"); + } + if(null!=fieldType) { + writer.print(" private static final int[] "+fieldName+"_size = new int[] { "); + for( int i=0; i < machDescTargetConfigs.length; i++ ) { + if(0<i) { + writer.print(", "); + } + writer.print(fieldType.getSize(machDescTargetConfigs[i].md) + + " /* " + machDescTargetConfigs[i].name() + " */"); + } + writer.println(" };"); + } + } + private JavaType typeToJavaType(Type cType, boolean outgoingArgument, MachineDescription curMachDesc) { // Recognize JNIEnv* case up front PointerType opt = cType.asPointer(); diff --git a/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java b/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java index b9d4eda..3b36957 100755 --- a/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java +++ b/src/java/com/jogamp/gluegen/runtime/types/SizeThunk.java @@ -47,10 +47,11 @@ import com.jogamp.common.os.MachineDescription; generating glue code for two different CPU architectures (e.g., 32-bit and 64-bit) from the same internal representation of the various types involved. */ - public abstract class SizeThunk implements Cloneable { + private boolean fixedNativeSize; + // Private constructor because there are only a few of these - private SizeThunk() {} + private SizeThunk(boolean fixedNativeSize) { this.fixedNativeSize = fixedNativeSize; } public Object clone() { try { @@ -59,11 +60,13 @@ public abstract class SizeThunk implements Cloneable { throw new InternalError(); } } + + public final boolean hasFixedNativeSize() { return fixedNativeSize; } public abstract long computeSize(MachineDescription machDesc); public abstract long computeAlignment(MachineDescription machDesc); - public static final SizeThunk INT8 = new SizeThunk() { + public static final SizeThunk INT8 = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.int8SizeInBytes(); } @@ -72,7 +75,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk INT16 = new SizeThunk() { + public static final SizeThunk INT16 = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.int16SizeInBytes(); } @@ -81,7 +84,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk INT32 = new SizeThunk() { + public static final SizeThunk INT32 = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.int32SizeInBytes(); } @@ -90,7 +93,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk INTxx = new SizeThunk() { + public static final SizeThunk INTxx = new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return machDesc.intSizeInBytes(); } @@ -99,7 +102,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk LONG = new SizeThunk() { + public static final SizeThunk LONG = new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return machDesc.longSizeInBytes(); } @@ -108,7 +111,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk INT64 = new SizeThunk() { + public static final SizeThunk INT64 = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.int64SizeInBytes(); } @@ -117,7 +120,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk FLOAT = new SizeThunk() { + public static final SizeThunk FLOAT = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.floatSizeInBytes(); } @@ -126,7 +129,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk DOUBLE = new SizeThunk() { + public static final SizeThunk DOUBLE = new SizeThunk(true) { public long computeSize(MachineDescription machDesc) { return machDesc.doubleSizeInBytes(); } @@ -135,7 +138,7 @@ public abstract class SizeThunk implements Cloneable { } }; - public static final SizeThunk POINTER = new SizeThunk() { + public static final SizeThunk POINTER = new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return machDesc.pointerSizeInBytes(); } @@ -148,7 +151,7 @@ public abstract class SizeThunk implements Cloneable { // arithmetic on these values public static SizeThunk add(final SizeThunk thunk1, final SizeThunk thunk2) { - return new SizeThunk() { + return new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return thunk1.computeSize(machDesc) + thunk2.computeSize(machDesc); } @@ -162,7 +165,7 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk mul(final SizeThunk thunk1, final SizeThunk thunk2) { - return new SizeThunk() { + return new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return thunk1.computeSize(machDesc) * thunk2.computeSize(machDesc); } @@ -176,7 +179,7 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk align(final SizeThunk offsetThunk, final SizeThunk alignmentThunk) { - return new SizeThunk() { + return new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { // x % 2n == x & (2n - 1) // remainder = net_size & ( alignment - 1 ) @@ -201,7 +204,7 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk max(final SizeThunk thunk1, final SizeThunk thunk2) { - return new SizeThunk() { + return new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return Math.max(thunk1.computeSize(machDesc), thunk2.computeSize(machDesc)); } @@ -214,7 +217,7 @@ public abstract class SizeThunk implements Cloneable { } public static SizeThunk constant(final int constant) { - return new SizeThunk() { + return new SizeThunk(false) { public long computeSize(MachineDescription machDesc) { return constant; } |