本机Java在JNI上崩溃
Native to Java crash on JNI
我有一个运行c++的windows服务,它通过JNI调用Java。
当使用windows服务管理器停止服务时,服务崩溃。
c++向JNI寄存器如下:
SAPPHIRE_DLL_API int sapphire_adapter_initialize(CSACallbacks* callbacks)
{
JavaVMInitArgs vm_args;
JavaVMOption options[4];
int flow = 0;
g_pPumpCallbacks = callbacks;
for (flow = 0; flow == 0; flow++)
{
//options[0].optionString = "-Djava.class.path=SapphireAdapter.jar;hdpservices.jar;..\virgo-tomcat-server-3.6.1.RELEASE\pickup\com.hospira.hdpservices_1.0.0.jar;slf4j-api.jar;slf4j-log4j12.jar;log4j.jar";
options[0].optionString = "-Djava.class.path=SapphireAdapter.jar;hdpservices.jar;slf4j-api.jar;slf4j-log4j12.jar;log4j.jar";
options[1].optionString = "-verbose:jni"; /* print JNI-related messages */
//options[2].optionString = "-Xdebug";
//options[3].optionString = "-Xrunjdwp:transport=dt_socket,address=8998,server=y,suspend=y"; /* Enable Remote Debugging */
vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = 2; // set to 2 for verbose output from jni or 4 for remote debugging.
vm_args.options = &options[0];
vm_args.ignoreUnrecognized = 0;
jint res = JNI_CreateJavaVM(&g_jvm, (void **)&g_env, &vm_args);
if (res != 0)
{
jint result = JNI_GetCreatedJavaVMs(&g_jvm, 1, NULL);
if(result != JNI_OK)
break;
result = g_jvm->GetEnv((void**)&g_env, JNI_VERSION_1_8);
}
if (! g_masterClassDef.cls)
g_masterClassDef.cls = (jclass)g_env->NewGlobalRef(g_env->FindClass("com/hospira/sapphire/adapter/SapphireAdapter"));
if (! g_masterClassDef.cls)
break;
g_masterClassDef.mtd_constructor = g_env->GetMethodID(g_masterClassDef.cls, "<init>", "()V");
g_masterClassDef.mtd_setReference = g_env->GetMethodID(g_masterClassDef.cls, "setReferenceId", "(J)V");
g_masterClassDef.mtd_getReference = g_env->GetMethodID(g_masterClassDef.cls, "referenceId", "()J");
g_masterClassDef.mtd_connect = g_env->GetMethodID(g_masterClassDef.cls, "connect", "(Ljava/lang/String;I)V");
g_masterClassDef.mtd_disconnect = g_env->GetMethodID(g_masterClassDef.cls, "disconnect", "()V");
g_masterClassDef.mtd_cleanup = g_env->GetStaticMethodID(g_masterClassDef.cls, "cleanup", "()V");
OutputDebugString(_T("g_masterClassDef.mtd_cleanup is 0 ? "));
(g_masterClassDef.mtd_cleanup == 0 ) ? OutputDebugString(_T(" YES")) : OutputDebugString(_T(" no")) ;
g_masterClassDef.mtd_sendRegistration = g_env->GetMethodID(g_masterClassDef.cls, "sendRegistrationSignal", "([B)Z");
g_masterClassDef.mtd_sendClinicalStatus = g_env->GetMethodID(g_masterClassDef.cls, "sendClinicalStatusSignal", "([B)Z");
g_masterClassDef.mtd_sendLogDownload = g_env->GetMethodID(g_masterClassDef.cls, "sendLogDownloadSig", "([B)Z");
g_masterClassDef.mtd_sendDeployUpdateInquiry = g_env->GetMethodID(g_masterClassDef.cls, "sendDeployUpdateInquiry", "([B)Z");
g_masterClassDef.mtd_sendTimeSync = g_env->GetMethodID(g_masterClassDef.cls, "sendTimeSync", "([B)Z");
g_masterClassDef.mtd_setIdleTimes = g_env->GetStaticMethodID(g_masterClassDef.cls, "setIdleTimes", "(II)V");
}
return flow;
}
我知道注册是成功的g_masterClassDef。mtd_cleanup是0 -在DebugView中没有。
c++代码调用以下语句:
CCommunicationToMedNet::~CCommunicationToMedNet(void)
{
sapphire_adapter_uninitialize();
d_LoggerWrite(CMediatorLogging::e_Severity_Info, _T("Uninitialized sapphire adaptor"));
}
接口类SapphireAdapter sapphire_adapter_uninitialize()是
SAPPHIRE_DLL_API void sapphire_adapter_uninitialize()
{
g_env->CallStaticVoidMethod(g_masterClassDef.cls, g_masterClassDef.mtd_cleanup);
g_env->DeleteGlobalRef(g_masterClassDef.cls);
g_jvm->DestroyJavaVM();
g_jvm = NULL;
g_env = NULL;
g_pPumpCallbacks = NULL;
}
3) Java代码无关紧要,因为Java方法永远不会被调用。
Stack: [0x0000000000210000,0x0000000000310000], sp=0x000000000030f260, free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [jvm.dll+0x31165]
V [jvm.dll+0x274b86]
V [jvm.dll+0x212ad2]
V [jvm.dll+0x32cf42]
V [jvm.dll+0x212e63]
V [jvm.dll+0x147a68]
V [jvm.dll+0x14d608]
C [SapphireAdapter.dll+0x12bc]
C [SapphireAdapter.dll+0x169e]
C [MedNetMediatorService.exe+0xe2746]
C [MedNetMediatorService.exe+0xe3929]
C [MedNetMediatorService.exe+0xe9c52]
C [MSVCR110.dll+0x22fe1]
C [MedNetMediatorService.exe+0x170616]
C [kernel32.dll+0x159bd]
C [ntdll.dll+0x2a2e1]
4)进一步查看错误报告,我发现:
Internal exceptions (10 events):
Event: 0.149 Thread 0x00000000005bf000 Exception <a >'java/lang/ArrayIndexOutOfBoundsException': 22 (0x00000000d7240d58) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u746087hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 0.150 Thread 0x00000000005bf000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': 160> (0x00000000d72431a8) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u746087hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
5)查看堆栈跟踪-似乎代码从未到达JVM方法对如何解决这个问题有什么想法吗?
mtd_cleanup
是一个静态方法,因此应该由CallStaticVoidMethod
调用。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- Android (ART) 崩溃并显示错误 JNI 在应用程序中检测到错误:jstring 是无效的本地引用
- JNI - 在 NewObjectArray 上崩溃
- 相机崩溃:带JNI代码的致命信号6(Sigabrt)
- 呼叫功能时JNI C Android应用程序崩溃
- Android - JNI 在集原生C++变量上崩溃
- Android JNI 中的原生崩溃 SIGSEGV
- 从c++类崩溃到Java的JNI回调
- 调用AAssetManager_fromJava时崩溃:"JNI WARNING: instance fieldID 0x571819bc not valid"
- 静态 c++ 对象中的 JNI 环境指针并调用连续两次使用字符串参数的 Java 函数会使 JVM 崩溃
- 使用 OpenCV OnCameraFrame 在 JNI 中出现内存不足崩溃
- Android JNI :调用对象方法时应用程序崩溃
- 使用JNI调用或使用Openfeint更改活动会导致应用程序崩溃
- matlab调用Findclass JNI崩溃
- JNI "env->GetStaticMethodID()"崩溃的程序
- c++ JNI在做任何IO/Streams时崩溃/挂起
- Android JNI错误:调用带有布尔参数的函数会导致崩溃
- 与JNI崩溃服务器JVM的访问冲突
- 本机Java在JNI上崩溃
- 加载JNI时会因未定义的符号而崩溃