From 1eadaf928f4f61aae4de1c8bf33c5b77bdfa882f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 18 Jun 2014 01:49:08 +0200 Subject: GlueGen: Refine compound [array] call-by-value native code injection and initialization Follow-up of commit 9843e983a4fc71a64eb3de9cb364a1f4ffa56b3a Only add static initialization code (java, native) and hence native code 'JVMUtil_NewDirectByteBufferCopy(..)' if either required _or_ forced via configuration. This shall reduce possible sideffects and dead code. Add JavaConfiguration: /** * Returns true if the static initialization java code calling initializeImpl() * for the given class will be manually implemented by the end user * as requested via configuration directive ManualStaticInitCall 'class-name'. */ public boolean manualStaticInitCall(String clazzName); /** * Returns true if the static initialization java code implementing initializeImpl() * and the native code implementing: *
 *   static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, void * source_address, jlong capacity);
 * 
* for the given class will be included in the generated code, always, * as requested via configuration directive ForceStaticInitCode 'class-name'. *

* If case above code has been generated, static class initialization is generated * to call initializeImpl(), see {@link #manualStaticInitCall(String)}. *

*/ public boolean forceStaticInitCode(String clazzName); --- src/java/com/jogamp/gluegen/JavaConfiguration.java | 52 +++++++++++++++++----- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'src/java/com/jogamp/gluegen/JavaConfiguration.java') diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 7cecbce..552b237 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -156,7 +156,8 @@ public class JavaConfiguration { private boolean forceUseNIODirectOnly4All = false; private final Set useNIODirectOnly = new HashSet(); private final Set manuallyImplement = new HashSet(); - private final Set manualStaticInit = new HashSet(); + private final Set manualStaticInitCall = new HashSet(); + private final Set forceStaticInitCode = new HashSet(); private final Map> customJavaCode = new HashMap>(); private final Map> classJavadoc = new HashMap>(); private final Map> methodJavadoc = new HashMap>(); @@ -538,10 +539,30 @@ public class JavaConfiguration { return manuallyImplement.contains(functionName); } - /** Returns true if the static initialization java code for the given class will be - manually implemented by the end user. */ - public boolean manualStaticInit(String clazzName) { - return manualStaticInit.contains(clazzName); + /** + * Returns true if the static initialization java code calling initializeImpl() + * for the given class will be manually implemented by the end user + * as requested via configuration directive ManualStaticInitCall 'class-name'. + */ + public boolean manualStaticInitCall(String clazzName) { + return manualStaticInitCall.contains(clazzName); + } + + /** + * Returns true if the static initialization java code implementing initializeImpl() + * and the native code implementing: + *
+   *   static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, void * source_address, jlong capacity);
+   * 
+ * for the given class will be included in the generated code, always, + * as requested via configuration directive ForceStaticInitCode 'class-name'. + *

+ * If case above code has been generated, static class initialization is generated + * to call initializeImpl(), see {@link #manualStaticInitCall(String)}. + *

+ */ + public boolean forceStaticInitCode(String clazzName) { + return forceStaticInitCode.contains(clazzName); } /** Returns a list of Strings containing user-implemented code for @@ -990,8 +1011,10 @@ public class JavaConfiguration { readIgnoreField(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("ManuallyImplement")) { readManuallyImplement(tok, filename, lineNo); - } else if (cmd.equalsIgnoreCase("ManualStaticInit")) { - readManualStaticInit(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("ManualStaticInitCall")) { + readManualStaticInitCall(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("ForceStaticInitCode")) { + readForceStaticInitCode(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("CustomJavaCode")) { readCustomJavaCode(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop @@ -1292,12 +1315,21 @@ public class JavaConfiguration { " in file \"" + filename + "\"", e); } } - protected void readManualStaticInit(StringTokenizer tok, String filename, int lineNo) { + protected void readManualStaticInitCall(StringTokenizer tok, String filename, int lineNo) { + try { + String name = tok.nextToken(); + manualStaticInitCall.add(name); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"ManualStaticInitCall\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected void readForceStaticInitCode(StringTokenizer tok, String filename, int lineNo) { try { String name = tok.nextToken(); - manualStaticInit.add(name); + forceStaticInitCode.add(name); } catch (NoSuchElementException e) { - throw new RuntimeException("Error parsing \"ManualStaticInit\" command at line " + lineNo + + throw new RuntimeException("Error parsing \"ForceStaticInitCode\" command at line " + lineNo + " in file \"" + filename + "\"", e); } } -- cgit v1.2.3