JNI不是很熟,请高手指点下如何定位/debug,多谢!!!
JNI代码实现如下:
--------------------------------------------------------------------------------------------
JNIEXPORT jint JNICALL Java_client_common_ClientJNI_GetPolicy
(JNIEnv * env, jclass cl, jstring login_name, jstring ip_addr, jobject obj)
{
std::cout << "===============GetPolicy." << std::endl;
const char * c_username = env->GetStringUTFChars(login_name, NULL);
if (NULL == c_username) {
std::cout << "Failed to get user name." << std::endl;
return -1;
}
const char * c_address = env->GetStringUTFChars(ip_addr, NULL);
if (NULL == c_address ) {
std::cout << "Failed to get address." << std::endl;
env->ReleaseStringUTFChars(login_name, c_username);
return -1;
}
// 访问数据库,根据c_username 和 c_address 读取数据....
env->ReleaseStringUTFChars(login_name, c_username);
env->ReleaseStringUTFChars(ip_addr, c_address);
return 0;
}
--------------------------------------------------------------------------------------------
tomcat里的Java程序会调用这个方法,一个连接时没有问题。当同时20个连接访问的时候,JVM发生了crash。
tomcat 的catalina.out:
--------------------------------------------------------------------------------------------
INFO: Server startup in 1481 ms
===============GetPolicy.
//前面多个访问正常,然后突然就歇菜了...
===============GetPolicy.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xf7af14f8, pid=8715, tid=4088118160
#
# JRE version: 6.0_23-b05
# Java VM: Java HotSpot(TM) Client VM (19.0-b09 mixed mode, sharing linux-x86 )
# Problematic frame:
# V [libjvm.so+0x4324f8]
#
# An error report file with more information is saved as:
# /var/hs_err_pid8715.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------------------------------------------------------------------------------------
/var/hs_err_pid8715.log文件很长,部分内容:
--------------------------------------------------------------------------------------------
Register to memory mapping:
EAX=0x6c717370
0x6c717370 is pointing to unknown location
EBX=0xf7b930b0
0xf7b930b0: <offset 0x4d40b0> in /usr/iwss/AdminUI/jre/lib/i386/client/libjvm.so at 0xf76bf000
ECX=0x00000000
0x00000000 is pointing to unknown location
EDX=0x6c717370
0x6c717370 is pointing to unknown location
...
Stack: [0xf3a6b000,0xf3abc000], sp=0xf3aba138, free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x4324f8]
V [libjvm.so+0x238a7b]
V [libjvm.so+0x238b15]
V [libjvm.so+0x260759]
C [libRClientJNI.so+0x243c8] _ZN10_Jv_JNIEnv12NewStringUTFEPKc+0x1c
C [libRClientJNI.so+0x23e48] Java_client_common_ClientJNI_GetPolicy+0x5a4
j client.common.ClientJNI.GetPolicy(Ljava/lang/String;Ljava/lang/String;Ljava/lang/ObjectI+0
--------------------------------------------------------------------------------------------
多谢!