Jni 方法在两次调用后导致 JVM 崩溃
好吧,我的问题是我有一个使用 Jni 从 Java 应用程序调用的 C++ 方法。问题是该方法在第一次调用时运行良好,但当第二次调用时,JVM 崩溃了。显示错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77d0e39e, pid=3776, tid=3100
#
# JRE version: 6.0_29-b11
# Java VM: Java HotSpot(TM) Client VM (20.4-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [ntdll.dll+0x2e39e]
#
# An error report file with more information is saved as:
# C:\Users\OPTIMAL1\workspace\XtremeGUI\hs_err_pid3776.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
这是使用 Jni 从我的 Java 应用程序调用的 C++ 方法:
JNIEXPORT void JNICALL Java_MainFrame_Jni_Functions_displayParameterResults (JNIEnv *env, jobject obj){
cout << "begin!!!!!!!!!!!!!!" << endl;
cout << "before!!!!!!!!!!!!!!" << endl;
jclass jclazz = env->FindClass("MainFrame/Jni/TablesObjects");
cout << "after***************" << jclazz <<endl;
int size = xtremeDataGA.resultsData.parameter.size();
jdouble* jdbl = new jdouble(size);
for(int i=0; i<size; i++)
jdbl[i] = xtremeDataGA.resultsData.parameter.at(i).at(0).at(0);
jdoubleArray jdblArr = env->NewDoubleArray(size);
env->SetDoubleArrayRegion(jdblArr, 0, size, jdbl);
jclass jStringClass = env->FindClass("java/lang/String");
jobjectArray jStringArray = env->NewObjectArray(6, jStringClass, 0);
for(int i=0; i<6; i++)
env->SetObjectArrayElement(jStringArray, i, env->NewStringUTF("a") );
jmethodID mid = env->GetStaticMethodID(jclazz, "resultsParameterInsertCol", "([Ljava/lang/Object;[D)V");
env->CallStaticVoidMethod(jclazz, mid, jStringArray, jdblArr);
cout << "end!!!!!!!!!!!!!!" << endl;
}
编辑: 问题已解决。没有任何语法/编码错误。该错误是由于我需要在本地重新声明的全局对象声明造成的。
Well, my problem is that I've got a C++ method that I call from my Java application using Jni. The problem is that the method works well at first call but when it's called a second time, the JVM crashes. There is the displayed error :
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77d0e39e, pid=3776, tid=3100
#
# JRE version: 6.0_29-b11
# Java VM: Java HotSpot(TM) Client VM (20.4-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [ntdll.dll+0x2e39e]
#
# An error report file with more information is saved as:
# C:\Users\OPTIMAL1\workspace\XtremeGUI\hs_err_pid3776.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
And here is the C++ method that is called from my Java app using Jni :
JNIEXPORT void JNICALL Java_MainFrame_Jni_Functions_displayParameterResults (JNIEnv *env, jobject obj){
cout << "begin!!!!!!!!!!!!!!" << endl;
cout << "before!!!!!!!!!!!!!!" << endl;
jclass jclazz = env->FindClass("MainFrame/Jni/TablesObjects");
cout << "after***************" << jclazz <<endl;
int size = xtremeDataGA.resultsData.parameter.size();
jdouble* jdbl = new jdouble(size);
for(int i=0; i<size; i++)
jdbl[i] = xtremeDataGA.resultsData.parameter.at(i).at(0).at(0);
jdoubleArray jdblArr = env->NewDoubleArray(size);
env->SetDoubleArrayRegion(jdblArr, 0, size, jdbl);
jclass jStringClass = env->FindClass("java/lang/String");
jobjectArray jStringArray = env->NewObjectArray(6, jStringClass, 0);
for(int i=0; i<6; i++)
env->SetObjectArrayElement(jStringArray, i, env->NewStringUTF("a") );
jmethodID mid = env->GetStaticMethodID(jclazz, "resultsParameterInsertCol", "([Ljava/lang/Object;[D)V");
env->CallStaticVoidMethod(jclazz, mid, jStringArray, jdblArr);
cout << "end!!!!!!!!!!!!!!" << endl;
}
EDIT : The problem is solved. There wasn't any syntax / coding error. The error was due to a global object declaration that I needed to re-declare locally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论