From 2f6586292cd298bbc19d8acda0f7cf303c82078b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 18 Jun 2014 03:46:38 +0200 Subject: GlueGen: Refine compound [array] call-by-value native code injection and initialization Follow-up of commit 1eadaf928f4f61aae4de1c8bf33c5b77bdfa882f - Refine MethodBinding detection for 'requiresStaticInitialization', i.e. return type is a "compound type" and not a pointer - JVMUtil_NewDirectByteBufferCopy: Throw FatalError if initializeImpl() has not been called --- src/java/com/jogamp/gluegen/JavaEmitter.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java') 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 { *

* This is currently true, if one of the following method returns true *

*

@@ -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"+ -- cgit v1.2.3