Hi Sean,

Not sure of what's the problem there. I think you need to debug the
problem by yourself. When we need to debug JNI code we build all in
debug (or release with debug info) and use the 'Attach to process'
functionality in debuggers. Attaching to java process and then setting
the breakpoint in JNI code you can debug and spot the problem. It's a
little bit tricky but sometimes necessary :).

Anyway we made something similar inside osgvp code. Take a look at:
- 
https://devel.gvsig.org/svn/osgvp/trunk/wrappers/java/libjni-osgvpcore/src/main/native/josgvpcore/UpdateNodeListener.cpp

and this piece of code:
// code in Java
package org.gvsig.osgvp.util;

import org.gvsig.osgvp.core.osg.Node;

public interface UpdateNodeListener {
        public void update(Node node);
}
// other code in c
JNIEXPORT void JNICALL
Java_org_gvsig_osgvp_core_osg_Node_native_1setUpdateListener(JNIEnv
*env, jclass, jlong cptr, jobject updateListener)
{
        osg::Node *node = reinterpret_cast<osg::Node*>(cptr);
        if(node==0) return;

        JavaVM *vm;
        env->GetJavaVM(&vm);
        jclass cls = env->GetObjectClass(updateListener);
        jmethodID jniExecMethod = env->GetMethodID(cls, "update",
"(Lorg/gvsig/osgvp/core/osg/Node;)V");
        if (jniExecMethod == 0)
        {
                std::cerr << "UpdateNodeListener: not update(Node node) method
found!" << std::endl;
                return;
        }
        node->setUpdateCallback(new
osgvp::core::UpdateListener(vm,cls,env->NewGlobalRef(updateListener),jniExecMethod));
}

Good luck,
Rafa.


2012/5/9 Sean K <[email protected]>:
> Thank you for the background information.
>
> There is different JNI issue that I am encountering.
>
> I was invoking a static function member from the native code.
>
> At this point, I dont mind using a static function member, but for
> thread safety in subsequent release, I need to switch it to use an
> instance function member.
>
> I saw the documentation about using non-static function members.  And
> I think I updated the code to use it correctly.   But it encounters a
> runtime crash in the jvm.
>
> the crash and java and native code fragments follows:
>
> static callback invoked from native: 7870.00
> static callback passing integer invoked.
> 333
> #
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (jni.cpp:947), pid=1852, tid=5864
> #  Error: ShouldNotReachHere()
> #
> # JRE version: 6.0_32-b05
> # Java VM: Java HotSpot(TM) Client VM (20.7-b02 mixed mode, sharing
> windows-x86 )
> # An error report file with more information is saved as:
> # C:\Users\sk\workspace\osg\osgnativelib\hs_err_pid1852.log
> #
> # If you would like to submit a bug report, please visit:
> #   http://java.sun.com/webapps/bugreport/crash.jsp
> #
>
>
> #
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (jni.cpp:947), pid=1852, tid=5864
> #  Error: ShouldNotReachHere()
> #
> # JRE version: 6.0_32-b05
> # Java VM: Java HotSpot(TM) Client VM (20.7-b02 mixed mode, sharing
> windows-x86 )
> # If you would like to submit a bug report, please visit:
> #   http://java.sun.com/webapps/bugreport/crash.jsp
> #
>
> ---------------  T H R E A D  ---------------
>
> Current thread (0x0264a800):  JavaThread "main" [_thread_in_vm,
> id=5864, stack(0x00550000,0x005a0000)]
>
> Stack: [0x00550000,0x005a0000],  sp=0x0059f878,  free space=318k
> Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native 
> code)
> V  [jvm.dll+0x13373a]
> V  [jvm.dll+0x12e6db]
> V  [jvm.dll+0x9529c]
> V  [jvm.dll+0x95a27]
> V  [jvm.dll+0x9890c]
> C  [HelloWorldWin32Library.dll+0x116d3]  JNIEnv_::CallVoidMethod+0x43
> C  [HelloWorldWin32Library.dll+0x14274]
> Java_com_foo_osgjni_core_MathFuncTest_Multiple+0x114
> j  com.foo.osgjni.core.MathFuncTest.Multiple(DD)D+0
> j  com.foo.osgjni.core.MathFuncTest.main([Ljava/lang/String;)V+15
> v  ~StubRoutines::call_stub
> V  [jvm.dll+0xfad4b]
> V  [jvm.dll+0x18c421]
> V  [jvm.dll+0xfadcd]
> V  [jvm.dll+0x95836]
> V  [jvm.dll+0x9d673]
> C  [javaw.exe+0x2155]
> C  [javaw.exe+0x8614]
> C  [kernel32.dll+0x1339a]  BaseThreadInitThunk+0x12
> C  [ntdll.dll+0x39ed2]  RtlInitializeExceptionChain+0x63
> C  [ntdll.dll+0x39ea5]  RtlInitializeExceptionChain+0x36
>
> Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
> j  com.foo.osgjni.core.MathFuncTest.Multiple(DD)D+0
> j  com.foo.osgjni.core.MathFuncTest.main([Ljava/lang/String;)V+15
> v  ~StubRoutines::call_stub
>
>
> #define STATICMETHODFUNCTIONNAME "callback"
> #define FUNCTION_SIGNATURE "(Ljava/lang/String;)V"
>
> #define STATICCALLNUMBERFUNCTIONNAME "callnumber"
> #define STATICCALLNUMBERFUNCTION_SIGNATURE "(I)V"
>
> #define INSTANCEMETHODFUNCTIONNAME "callbackInstance"
> #define INSTANCE_FUNCTION_SIGNATURE "(I)V"
>
>
>
> JNIEXPORT jdouble JNICALL Java_osgjni_core_MathFuncTest_Multiple
>  (JNIEnv *penv, jobject obj, jdouble left, jdouble right) {
>          jdouble product = left * right;
>          jclass cls = penv->GetObjectClass(obj);
>          jmethodID midStatic = penv->GetStaticMethodID(cls,
> STATICMETHODFUNCTIONNAME, FUNCTION_SIGNATURE);
>          jmethodID midStaticNumber = penv->GetStaticMethodID(cls,
> STATICCALLNUMBERFUNCTIONNAME, STATICCALLNUMBERFUNCTION_SIGNATURE);
>          jmethodID midInstance = penv->GetMethodID(cls,
> INSTANCEMETHODFUNCTIONNAME, INSTANCE_FUNCTION_SIGNATURE);
>          char buffer[20];
>          sprintf(buffer, "%5.2f", product);
>          jstring jstr = penv->NewStringUTF(buffer);
>          if (midStatic != 0) {
>                  penv->CallStaticVoidMethod(cls, midStatic,  jstr);
>          }
>          if (midStaticNumber != 0) {
>                  penv->CallStaticVoidMethod(cls, midStaticNumber,  333);
>          }
>          if (midInstance != 0) {
>                  penv->CallVoidMethod(cls, midInstance,  10);
>          }
>          return product;
> }
>
> public class MathFuncTest {
>
>        native double Multiple (double left, double right);
>
>
>        static {
>                
> System.load("c:\\DEV\\src\\test\\Debug\\HelloWorldWin32Library.dll");
>        }
>
>        /**
>         * this is used for the static function member test.
>         * @param msg
>         */
>
>        public static void callnumber (int number) {
>                System.out.println("static callback passing integer invoked.");
>                System.out.println(number);
>        }
>
>        /**
>         * this is used for the static function member test.
>         * @param msg
>         *
>         *
>         */
>        public static void callback(String msg) {
>                //System.out.println(msg);
>                if (msg != null){
>                        System.out.println("static callback invoked from 
> native: "+ msg);
>                }
>        }
>
>
>        /**
>         * this is used for the instance function member test.
>         * @param msg
>         *
>         *
>         */
>        public void callbackInstance (int number) {
>                System.out.println("instance callback invoked from native: "+ 
> number);
>        }
>
>
>
>        /**
>         * @param args
>         */
>        public static void main(String[] args) {
>                MathFuncTest test = new MathFuncTest();
>                double product = test.Multiple(10, 787);
>                System.out.println("native java: product is : "+product);
>        }
>
> }
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



-- 
Rafael Gaitán Linares
CTO at Mirage Technologies S.L - http://www.mirage-tech.com
gvSIG3D Developer - http://gvsig3d.blogspot.com
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to