diff options
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 28 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/MethodBinding.java | 25 |
2 files changed, 46 insertions, 7 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 1da57de..18e8b81 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -489,7 +489,7 @@ public class JavaEmitter implements GlueEmitter { * <p> * This is currently true, if one of the following method returns <code>true</code> * <ul> - * <li>{@link MethodBinding#signatureUsesCompoundTypeWrappers() one of the binding's signature uses compound-types}</li> + * <li>{@link MethodBinding#signatureRequiresStaticInitialization() one of the binding's signature requires it}</li> * <li>{@link JavaConfiguration#forceStaticInitCode(String)}</li> * </ul> * </p> @@ -534,7 +534,10 @@ public class JavaEmitter implements GlueEmitter { null != epilogue; if( !requiresStaticInitialization ) { - requiresStaticInitialization = binding.signatureUsesCompoundTypeWrappers(); + requiresStaticInitialization = binding.signatureRequiresStaticInitialization(); + if( requiresStaticInitialization ) { + LOG.log(INFO, "StaticInit Trigger.1 \"{0}\"", binding); + } } final JavaMethodBindingEmitter emitter = @@ -593,7 +596,10 @@ public class JavaEmitter implements GlueEmitter { if ( !cfg.isUnimplemented( binding.getName() ) ) { if( !requiresStaticInitialization ) { - requiresStaticInitialization = binding.signatureUsesCompoundTypeWrappers(); + requiresStaticInitialization = binding.signatureRequiresStaticInitialization(); + if( requiresStaticInitialization ) { + LOG.log(INFO, "StaticInit Trigger.2 \"{0}\"", binding); + } } // If we already generated a public native entry point for this @@ -1766,6 +1772,7 @@ public class JavaEmitter implements GlueEmitter { "static const char * clazzNameBuffersStaticNewCstrSignature = \"(I)Ljava/nio/ByteBuffer;\";\n"+ "static jclass clazzBuffers = NULL;\n"+ "static jmethodID cstrBuffersNew = NULL;\n"+ + "static jboolean _initClazzAccessDone = JNI_FALSE;\n"+ "\n"+ "static jboolean _initClazzAccess(JNIEnv *env) {\n"+ " jclass c;\n"+ @@ -1788,18 +1795,27 @@ public class JavaEmitter implements GlueEmitter { " cstrBuffersNew = (*env)->GetStaticMethodID(env, clazzBuffers,\n"+ " clazzNameBuffersStaticNewCstrName, clazzNameBuffersStaticNewCstrSignature);\n"+ " if(NULL==cstrBuffersNew) {\n"+ - " fprintf(stderr, \"FatalError: Java_jogamp_common_jvm_JVMUtil:: can't create %s.%s %s\\n\",\n"+ + " fprintf(stderr, \"FatalError: can't create %s.%s %s\\n\",\n"+ " clazzNameBuffers,\n"+ " clazzNameBuffersStaticNewCstrName, clazzNameBuffersStaticNewCstrSignature);\n"+ " (*env)->FatalError(env, clazzNameBuffersStaticNewCstrName);\n"+ " return JNI_FALSE;\n"+ " }\n"+ + " _initClazzAccessDone = JNI_TRUE;\n"+ " return JNI_TRUE;\n"+ "}\n"+ "\n"+ "static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, void * source_address, jlong capacity) {\n"+ - " jobject jbyteBuffer = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffersNew, capacity);\n"+ - " void * byteBufferPtr = (*env)->GetDirectBufferAddress(env, jbyteBuffer);\n"+ + " jobject jbyteBuffer;\n"+ + " void * byteBufferPtr;\n"+ + "\n"+ + " if( JNI_FALSE == _initClazzAccessDone ) {\n"+ + " fprintf(stderr, \"FatalError: initializeImpl() not called\\n\");\n"+ + " (*env)->FatalError(env, \"initializeImpl() not called\");\n"+ + " return NULL;\n"+ + " }\n"+ + " jbyteBuffer = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffersNew, capacity);\n"+ + " byteBufferPtr = (*env)->GetDirectBufferAddress(env, jbyteBuffer);\n"+ " memcpy(byteBufferPtr, source_address, capacity);\n"+ " return jbyteBuffer;\n"+ "}\n"+ diff --git a/src/java/com/jogamp/gluegen/MethodBinding.java b/src/java/com/jogamp/gluegen/MethodBinding.java index d199db1..61732fb 100644 --- a/src/java/com/jogamp/gluegen/MethodBinding.java +++ b/src/java/com/jogamp/gluegen/MethodBinding.java @@ -68,6 +68,7 @@ public class MethodBinding { private boolean signatureUsesCPrimitivePointers; private boolean signatureUsesCArrays; private boolean signatureUsesJavaPrimitiveArrays; + private boolean signatureRequiresStaticInitialization; private JavaType containingType; private Type containingCType; private int thisPointerIndex = -1; @@ -96,6 +97,7 @@ public class MethodBinding { this.signatureUsesCPrimitivePointers = bindingToCopy.signatureUsesCPrimitivePointers; this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays; this.signatureUsesJavaPrimitiveArrays = bindingToCopy.signatureUsesJavaPrimitiveArrays; + this.signatureRequiresStaticInitialization = bindingToCopy.signatureRequiresStaticInitialization; this.thisPointerIndex = bindingToCopy.thisPointerIndex; } @@ -254,6 +256,21 @@ public class MethodBinding { } /** + * Returns true if the wrapper implementation requires + * static native code to be initialized, see {@link JavaConfiguration#forceStaticInitCode(String)}. + * <p> + * Currently triggered by: + * <ul> + * <li>Return type is a "compound type" and not a pointer</li> + * </ul> + * </p> + */ + public boolean signatureRequiresStaticInitialization() { + computeSignatureProperties(); + return signatureRequiresStaticInitialization; + } + + /** * Returns true if the return type or any of the outgoing arguments * in the method's signature use arrays of "compound type wrappers", * or NIO-based wrappers for C data structures. @@ -326,11 +343,17 @@ public class MethodBinding { signatureUsesCPrimitivePointers = false; signatureUsesCArrays = false; signatureUsesJavaPrimitiveArrays = false; + signatureRequiresStaticInitialization = false; - if (javaReturnType.isCompoundTypeWrapper()) { + if ( javaReturnType.isCompoundTypeWrapper() ) { // Needs wrapping and/or setting of byte order (neither of which // can be done easily from native code) signatureUsesCompoundTypeWrappers = true; + + final Type cReturnType = getCReturnType(); + if ( !cReturnType.isPointer() ) { // FIXME: Compound call-by-value + signatureRequiresStaticInitialization = true; + } } if (javaReturnType.isNIOBuffer() || |