diff options
author | Sven Gothel <[email protected]> | 2015-02-02 00:22:29 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-02-02 00:22:29 +0100 |
commit | 7db9df61142694965b50f2e0553d4c9e5668439b (patch) | |
tree | 411c69a61d0f693acd55a65f458a2d2b75b84db8 /src/java/com/jogamp/gluegen | |
parent | 234819d531cdf20842cd0b3302935b187b2012d6 (diff) |
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.
Diffstat (limited to 'src/java/com/jogamp/gluegen')
9 files changed, 108 insertions, 83 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 5673aac..93a1ecc 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -43,7 +43,7 @@ import java.util.*; import java.io.*; import java.text.MessageFormat; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; import com.jogamp.gluegen.cgram.types.*; import java.util.logging.Logger; @@ -109,7 +109,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { protected static final String STRING_CHARS_PREFIX = "_strchars_"; // We need this in order to compute sizes of certain types - protected MachineDescription machDesc; + protected MachineDataInfo machDesc; /** * Constructs an emitter for the specified binding, and sets a default @@ -124,7 +124,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { final boolean isJavaMethodStatic, final boolean forImplementingMethodCall, final boolean forIndirectBufferAndArrayImplementation, - final MachineDescription machDesc) + final MachineDataInfo machDesc) { super(output, false); @@ -289,7 +289,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { /** * Used for certain internal type size computations */ - public final MachineDescription getMachineDescription() { return machDesc; } + public final MachineDataInfo getMachineDataInfo() { return machDesc; } @Override diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 3924ec2..346920d 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -54,7 +54,7 @@ import com.jogamp.gluegen.cgram.types.*; import java.util.logging.Logger; -import jogamp.common.os.MachineDescriptionRuntime; +import jogamp.common.os.MachineDataInfoRuntime; import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*; @@ -166,7 +166,7 @@ public class JavaConfiguration { private final Map<String, String> structPackages = new HashMap<String, String>(); private final List<String> customCCode = new ArrayList<String>(); private final List<String> forcedStructs = new ArrayList<String>(); - private final Map<String, String> structMachineDescriptorIndex = new HashMap<String, String>(); + private final Map<String, String> structMachineDataInfoIndex = new HashMap<String, String>(); private final Map<String, String> returnValueCapacities = new HashMap<String, String>(); private final Map<String, String> returnValueLengths = new HashMap<String, String>(); private final Map<String, List<String>> temporaryCVariableDeclarations = new HashMap<String, List<String>>(); @@ -650,12 +650,12 @@ public class JavaConfiguration { * <p> * If undefined, code generation uses the default expression: * <pre> - * private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal(); + * private static final int mdIdx = MachineDataInfoRuntime.getStatic().ordinal(); * </pre> * </p> */ - public String returnStructMachineDescriptorIndex(final String structName) { - return structMachineDescriptorIndex.get(structName); + public String returnStructMachineDataInfoIndex(final String structName) { + return structMachineDataInfoIndex.get(structName); } /** @@ -1123,8 +1123,8 @@ public class JavaConfiguration { readTemporaryCVariableAssignment(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because TemporaryCVariableAssignment changes them. - } else if (cmd.equalsIgnoreCase("StructMachineDescriptorIndex")) { - readStructMachineDescriptorIndex(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("StructMachineDataInfoIndex")) { + readStructMachineDataInfoIndex(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because StructMachineDescriptorIndex changes them. } else if (cmd.equalsIgnoreCase("ReturnValueCapacity")) { @@ -1525,14 +1525,14 @@ public class JavaConfiguration { } } - protected void readStructMachineDescriptorIndex(final StringTokenizer tok, final String filename, final int lineNo) { + protected void readStructMachineDataInfoIndex(final StringTokenizer tok, final String filename, final int lineNo) { try { final String structName = tok.nextToken(); String restOfLine = tok.nextToken("\n\r\f"); restOfLine = restOfLine.trim(); - structMachineDescriptorIndex.put(structName, restOfLine); + structMachineDataInfoIndex.put(structName, restOfLine); } catch (final NoSuchElementException e) { - throw new RuntimeException("Error parsing \"StructMachineDescriptorIndex\" command at line " + lineNo + + throw new RuntimeException("Error parsing \"StructMachineDataInfoIndex\" command at line " + lineNo + " in file \"" + filename + "\"", e); } } diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 48c7047..d2dc4ba 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -42,7 +42,7 @@ package com.jogamp.gluegen; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.DynamicLookupHelper; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; import java.io.*; import java.util.*; @@ -53,7 +53,7 @@ import com.jogamp.gluegen.cgram.types.*; import java.nio.Buffer; import java.util.logging.Logger; -import jogamp.common.os.MachineDescriptionRuntime; +import jogamp.common.os.MachineDataInfoRuntime; import static java.util.logging.Level.*; import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*; @@ -100,8 +100,8 @@ 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 final MachineDescription machDescJava = MachineDescription.StaticConfig.LP64_UNIX.md; - private final MachineDescription.StaticConfig[] machDescTargetConfigs = MachineDescription.StaticConfig.values(); + private final MachineDataInfo machDescJava = MachineDataInfo.StaticConfig.LP64_UNIX.md; + private final MachineDataInfo.StaticConfig[] machDescTargetConfigs = MachineDataInfo.StaticConfig.values(); protected final static Logger LOG = Logger.getLogger(JavaEmitter.class.getPackage().getName()); @@ -858,7 +858,7 @@ public class JavaEmitter implements GlueEmitter { this.requiresStaticInitialization = false; // reset - // machDescJava global MachineDescription is the one used to determine + // machDescJava global MachineDataInfo 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 @@ -868,11 +868,11 @@ public class JavaEmitter implements GlueEmitter { // 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 machDescTarget MachineDescription is the one used to determine how + // The machDescTarget MachineDataInfo 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 machDescJava MachineDescription is always 64bit unix, + // Note that machDescJava MachineDataInfo is always 64bit unix, // which complies w/ Java types. boolean needsNativeCode = false; @@ -935,7 +935,7 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println("import " + cfg.gluegenRuntimePackage() + ".*;"); javaWriter.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;"); javaWriter.println("import " + Buffers.class.getPackage().getName() + ".*;"); - javaWriter.println("import " + MachineDescriptionRuntime.class.getName() + ";"); + javaWriter.println("import " + MachineDataInfoRuntime.class.getName() + ";"); javaWriter.println(); final List<String> imports = cfg.imports(); for (final String str : imports) { @@ -963,10 +963,10 @@ public class JavaEmitter implements GlueEmitter { javaWriter.println(); javaWriter.println(" StructAccessor accessor;"); javaWriter.println(); - final String cfgMachDescrIdxCode = cfg.returnStructMachineDescriptorIndex(containingJTypeName); - final String machDescrIdxCode = null != cfgMachDescrIdxCode ? cfgMachDescrIdxCode : "private static final int mdIdx = MachineDescriptionRuntime.getStatic().ordinal();"; + final String cfgMachDescrIdxCode = cfg.returnStructMachineDataInfoIndex(containingJTypeName); + final String machDescrIdxCode = null != cfgMachDescrIdxCode ? cfgMachDescrIdxCode : "private static final int mdIdx = MachineDataInfoRuntime.getStatic().ordinal();"; javaWriter.println(" "+machDescrIdxCode); - javaWriter.println(" private final MachineDescription md;"); + javaWriter.println(" private final MachineDataInfo md;"); javaWriter.println(); // generate all offset and size arrays generateOffsetAndSizeArrays(javaWriter, " ", containingJTypeName, structCType, null, null); /* w/o offset */ @@ -1058,7 +1058,7 @@ public class JavaEmitter implements GlueEmitter { } if( !cfg.manuallyImplement(JavaConfiguration.canonicalStructFieldSymbol(containingJTypeName, containingJTypeName)) ) { javaWriter.println(" " + containingJTypeName + "(java.nio.ByteBuffer buf) {"); - javaWriter.println(" md = MachineDescription.StaticConfig.values()[mdIdx].md;"); + javaWriter.println(" md = MachineDataInfo.StaticConfig.values()[mdIdx].md;"); javaWriter.println(" accessor = new StructAccessor(buf);"); javaWriter.println(" }"); javaWriter.println(); @@ -1948,7 +1948,7 @@ public class JavaEmitter implements GlueEmitter { } private static final boolean DEBUG_TYPEC2JAVA = false; - private JavaType typeToJavaType(final Type cType, final MachineDescription curMachDesc) { + private JavaType typeToJavaType(final Type cType, final MachineDataInfo curMachDesc) { final JavaType jt = typeToJavaTypeImpl(cType, curMachDesc); if( DEBUG_TYPEC2JAVA ) { System.err.println("typeToJavaType: "+cType.getDebugString()+" -> "+jt.getDebugString()); @@ -1961,7 +1961,7 @@ public class JavaEmitter implements GlueEmitter { (opt.getTargetType().getName() != null) && (opt.getTargetType().getName().equals("JNIEnv")); } - private JavaType typeToJavaTypeImpl(final Type cType, final MachineDescription curMachDesc) { + private JavaType typeToJavaTypeImpl(final Type cType, final MachineDataInfo curMachDesc) { // Recognize JNIEnv* case up front if( isJNIEnvPointer(cType) ) { return JavaType.createForJNIEnv(); @@ -2194,7 +2194,7 @@ public class JavaEmitter implements GlueEmitter { private String compatiblePrimitiveJavaTypeName(final Type fieldType, final JavaType javaType, - final MachineDescription curMachDesc) { + final MachineDataInfo curMachDesc) { final Class<?> c = javaType.getJavaClass(); if (!isIntegerType(c)) { // FIXME @@ -2583,7 +2583,7 @@ public class JavaEmitter implements GlueEmitter { private MethodBinding bindFunction(final FunctionSymbol sym, final JavaType containingType, final Type containingCType, - final MachineDescription curMachDesc) { + final MachineDataInfo curMachDesc) { final MethodBinding binding = new MethodBinding(sym, containingType, containingCType); diff --git a/src/java/com/jogamp/gluegen/cgram/types/Field.java b/src/java/com/jogamp/gluegen/cgram/types/Field.java index afaeade..858d81a 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Field.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Field.java @@ -39,7 +39,7 @@ package com.jogamp.gluegen.cgram.types; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; /** Represents a field in a struct or union. */ @@ -83,8 +83,8 @@ public class Field { public SizeThunk getOffset() { return offset; } /** Offset, in bytes, of this field in the containing data structure - given the specified MachineDescription. */ - public long getOffset(final MachineDescription machDesc) { return offset.computeSize(machDesc); } + given the specified MachineDataInfo. */ + public long getOffset(final MachineDataInfo machDesc) { return offset.computeSize(machDesc); } /** Sets the offset of this field in the containing data structure. */ public void setOffset(final SizeThunk offset) { this.offset = offset; } diff --git a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java index c13e5d5..9843d6b 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java +++ b/src/java/com/jogamp/gluegen/cgram/types/SizeThunk.java @@ -40,7 +40,7 @@ package com.jogamp.gluegen.cgram.types; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; /** Provides a level of indirection between the definition of a type's size and the absolute value of this size. Necessary when @@ -64,104 +64,104 @@ public abstract class SizeThunk implements Cloneable { public final boolean hasFixedNativeSize() { return fixedNativeSize; } - public abstract long computeSize(MachineDescription machDesc); - public abstract long computeAlignment(MachineDescription machDesc); + public abstract long computeSize(MachineDataInfo machDesc); + public abstract long computeAlignment(MachineDataInfo machDesc); public static final SizeThunk INT8 = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.int8SizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.int8AlignmentInBytes(); } }; public static final SizeThunk INT16 = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.int16SizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.int16AlignmentInBytes(); } }; public static final SizeThunk INT32 = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.int32SizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.int32AlignmentInBytes(); } }; public static final SizeThunk INTxx = new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.intSizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.intAlignmentInBytes(); } }; public static final SizeThunk LONG = new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.longSizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.longAlignmentInBytes(); } }; public static final SizeThunk INT64 = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.int64SizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.int64AlignmentInBytes(); } }; public static final SizeThunk FLOAT = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.floatSizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.floatAlignmentInBytes(); } }; public static final SizeThunk DOUBLE = new SizeThunk(true) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.doubleSizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.doubleAlignmentInBytes(); } }; public static final SizeThunk POINTER = new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return machDesc.pointerSizeInBytes(); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return machDesc.pointerAlignmentInBytes(); } }; @@ -172,11 +172,11 @@ public abstract class SizeThunk implements Cloneable { final SizeThunk thunk2) { return new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return thunk1.computeSize(machDesc) + thunk2.computeSize(machDesc); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { final long thunk1A = thunk1.computeAlignment(machDesc); final long thunk2A = thunk2.computeAlignment(machDesc); return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; @@ -188,11 +188,11 @@ public abstract class SizeThunk implements Cloneable { final SizeThunk thunk2) { return new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return thunk1.computeSize(machDesc) * thunk2.computeSize(machDesc); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { final long thunk1A = thunk1.computeAlignment(machDesc); final long thunk2A = thunk2.computeAlignment(machDesc); return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; @@ -204,22 +204,37 @@ public abstract class SizeThunk implements Cloneable { final SizeThunk alignmentThunk) { return new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { - // x % 2n == x & (2n - 1) - // remainder = net_size & ( alignment - 1 ) - // padding = alignment - remainder ; - // aligned_size = net_size + padding ; + public long computeSize(final MachineDataInfo machDesc) { + /** + * padding = ( alignment - ( net_size % alignment ) ) % alignment ; + * aligned_size = net_size + padding ; + * + * With x % 2n == x & (2n - 1) + * + * Either: + * remainder = net_size & ( alignment - 1 ) + * padding = ( remainder > 0 ) ? alignment - remainder ; + * aligned_size = net_size + padding ; + * + * Or: + * padding = ( alignment - ( net_size & ( alignment - 1 ) ) ) & ( alignment - 1 ); + * aligned_size = net_size + padding ; + * + */ - final long size = offsetThunk.computeSize(machDesc); + final long net_size = offsetThunk.computeSize(machDesc); final long alignment = alignmentThunk.computeAlignment(machDesc); - final long remainder = size & ( alignment - 1 ) ; + /** + final long remainder = net_size & ( alignment - 1 ) ; final long padding = (remainder > 0) ? alignment - remainder : 0; - return size + padding; + */ + final long padding = ( alignment - ( net_size & ( alignment - 1 ) ) ) & ( alignment - 1 ); + return net_size + padding; } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { final long thunk1A = offsetThunk.computeAlignment(machDesc); final long thunk2A = alignmentThunk.computeAlignment(machDesc); return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; @@ -231,11 +246,11 @@ public abstract class SizeThunk implements Cloneable { final SizeThunk thunk2) { return new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return Math.max(thunk1.computeSize(machDesc), thunk2.computeSize(machDesc)); } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { final long thunk1A = thunk1.computeAlignment(machDesc); final long thunk2A = thunk2.computeAlignment(machDesc); return ( thunk1A > thunk2A ) ? thunk1A : thunk2A ; @@ -246,11 +261,11 @@ public abstract class SizeThunk implements Cloneable { public static SizeThunk constant(final int constant) { return new SizeThunk(false) { @Override - public long computeSize(final MachineDescription machDesc) { + public long computeSize(final MachineDataInfo machDesc) { return constant; } @Override - public long computeAlignment(final MachineDescription machDesc) { + public long computeAlignment(final MachineDataInfo machDesc) { return 1; // no alignment for constants } }; diff --git a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java index 9d1a293..86f1ae1 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java +++ b/src/java/com/jogamp/gluegen/cgram/types/StructLayout.java @@ -40,7 +40,7 @@ package com.jogamp.gluegen.cgram.types; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; import com.jogamp.gluegen.GlueGen; /** Encapsulates algorithm for laying out data structures. Note that @@ -67,9 +67,9 @@ public class StructLayout { SizeThunk curOffset = SizeThunk.constant(baseOffset); SizeThunk maxSize = SizeThunk.constant(0); - final MachineDescription dbgMD; + final MachineDataInfo dbgMD; if( GlueGen.debug() ) { - dbgMD = MachineDescription.StaticConfig.LP64_UNIX.md; + dbgMD = MachineDataInfo.StaticConfig.LP64_UNIX.md; System.err.printf("SL.__: o %03d, s %03d, t %s{%d}%n", curOffset.computeSize(dbgMD), 0, t, t.getNumFields()); } else { dbgMD = null; diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java index 63890a1..28ba6b4 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java @@ -42,7 +42,7 @@ package com.jogamp.gluegen.cgram.types; import java.util.List; -import com.jogamp.common.os.MachineDescription; +import com.jogamp.common.os.MachineDataInfo; /** Models a C type. Primitive types include int, float, and double. All types have an associated name. Structs and unions are @@ -112,7 +112,7 @@ public abstract class Type implements Cloneable { { long _mdSize = -1; try { - _mdSize = size.computeSize(MachineDescription.StaticConfig.LP64_UNIX.md); + _mdSize = size.computeSize(MachineDataInfo.StaticConfig.LP64_UNIX.md); } catch (final Exception e) {} mdSize = _mdSize; } @@ -180,8 +180,8 @@ public abstract class Type implements Cloneable { /** SizeThunk which computes size of this type in bytes. */ public SizeThunk getSize() { return size; } - /** Size of this type in bytes according to the given MachineDescription. */ - public long getSize(final MachineDescription machDesc) { + /** Size of this type in bytes according to the given MachineDataInfo. */ + public long getSize(final MachineDataInfo machDesc) { final SizeThunk thunk = getSize(); if (thunk == null) { throw new RuntimeException("No size set for type \"" + getName() + "\""); diff --git a/src/java/com/jogamp/gluegen/package.html b/src/java/com/jogamp/gluegen/package.html index 2b4f1fa..689fa05 100644 --- a/src/java/com/jogamp/gluegen/package.html +++ b/src/java/com/jogamp/gluegen/package.html @@ -60,13 +60,23 @@ </ul> <h5>Simple alignment arithmetic</h5> - <blockquote>remainder = offset % alignment</blockquote> - since alignment is a multiple of 2 <code>-> x % 2n == x & (2n - 1)</code><br> - <blockquote>remainder = offset & ( alignment - 1 )</blockquote> + Modulo operation, where the 2nd handles the case offset == alignment: <blockquote> - padding = (remainder > 0) ? alignment - remainder : 0 ;<br> + padding = ( alignment - ( offset % alignment ) ) % alignment ; <br> + aligned_offset = offset + padding ; + </blockquote> + Optimization utilizing alignment as a multiple of 2 <code>-> x % 2n == x & ( 2n - 1 )</code><br> + <blockquote> + remainder = offset & ( alignment - 1 ) ; <br> + padding = ( remainder > 0 ) ? alignment - remainder : 0 ;<br> + aligned_offset = offset + padding ; + </blockquote> + Without branching, using the 2nd modulo operation for the case offset == alignment: + <blockquote> + padding = ( alignment - ( offset & ( alignment - 1 ) ) ) & ( alignment - 1 ) ;<br> aligned_offset = offset + padding ; </blockquote> + See <code>com.jogamp.gluegen.cgram.types.SizeThunk.align(..)</code>. <h5>Type Size & Alignment for x86, x86_64, armv6l-32bit-eabi and Window(mingw/mingw64)</h5> Runtime query is implemented as follows: diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java index 351e0cd..5c059c9 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java @@ -76,7 +76,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { methodToWrap.getIsJavaMethodStatic(), true, methodToWrap.forIndirectBufferAndArrayImplementation(), - methodToWrap.getMachineDescription() + methodToWrap.getMachineDataInfo() ); if (methodToWrap.getReturnValueCapacityExpression() != null) { |