posts - 23,  comments - 3,  trackbacks - 0
最近的项目涉及到了JAVA需要调用C程序的问题。主要是调用C写的加密算法。
主要解决方案是应用JNI去调用C生成的so库
用eclispe新建一个java project项目,项目名称为spidHandle,注意下面VC的项目名称也是spidHandle,他们分别是用eclispe和VC6.0创建的,不是同个项目。
编写一个JNI入口类SpidHandle.java:
Java代码  收藏代码
  1. package com.spidHandle.api;  
  2. public class SpidHandle {  
  3.         static {  
  4.                 System.loadLibrary("spidhandle");  
  5.         }  
  6.           
  7.         public String buildSpID(String path, String login_name, String password, String key)  
  8.         {  
  9.             return getSPID(path, login_name, password, key);  
  10.         }  
  11.           
  12.         public native String getSPID(String path, String login_name, String password, String key);  
  13.   
  14.     /** 
  15.      * @param args 
  16.      *  
  17.      * 供测试用 
  18.      */  
  19.     public static void main(String[] args) {  
  20.         // TODO Auto-generated method stub  
  21.         String keyforMD5 = "A6EIo8tuaKS";  
  22.         String s = new SpidHandle().buildSpID("/test", "test", "test", keyforMD5);  
  23.         System.out.println(s);  
  24.     }  
  25.   
  26. }  


通过CMD命令窗口,CMD命令窗口定位到SpidHandle.java的目录下,编译SpidHandle.java文件:
Java代码  收藏代码
  1. javac SpidHandle.java  

执行JAVAC命令后,在同个文件目录下生成SpidHandle.class
将CMD窗口退回到包的根目录下,如spidHandle工程路径为:
Z:\project\work_workspace\spidhandle
其中通过编译后的SpidHandle.class存在于目录下:
Z:\project\work_workspace\spidhandle\src\com\spidHandle\api
由于SpidHandle类所在的包是com.spidHandle.api,所以CMD命令窗口要退回到Z:\project\work_workspace\spidhandle\src目录
然后在CMD窗口中执行
Java代码  收藏代码
  1. javah com.spidHandle.api.SpidHandle  

执行后在Z:\project\work_workspace\spidhandle\src目录下生成文件
com_spidHandle_api_SpidHandle.h文件。
安装VC6.0开发工具。如果你是在windows下开发,那可以先生成DLL,这样你就可以在Windows下调试。其实JNI调用DLL和SO是一样的,只是运行的操作系统不一样而已。下面是如何用VC6.0创建一个DLL项目。
创建一个项目工程,名为spidhandle的工程,创建过程如下:
1、打开VC6.0->文件->新建
2、在弹出窗口中的工程选项卡中选择Win32 Dynamic-Link Library;工程名命名为spidhandle;点击确定。
3、在新的提示窗口中选择一个空白的DLL工程,点击完成。
4、在菜单的工具栏中选择选项,弹出选项窗口。切换到目录选项卡
5、在目录选项卡中新建目录,新建的目录为你JDK所在的目录下的include目录,如:
   D:\Program Files\Java\jdk1.6.0_16\include
  再新建一个目录,新建的目录为include文件夹下的win32目录,如
   D:\Program Files\Java\jdk1.6.0_16\include\win32
  此步主要是向工程引入jni所需要的头文件,如include中包含了jni.h,jni_md.h
6、将com_spidHandle_api_SpidHandle.h头文件拷贝到vc6.0工程spidHandle根目录下,将其添加到工 程的Header Files,右键工程窗口中的Header Files,选择添加文件到目录下,选择工程路径下的com_spidHandle_api_SpidHandle.h文件。
7、在spidHandle工程根目录的文件夹中新建com_spidHandle_api_SpidHandle.h头文件对应的cpp文件, 文件名称为com_spidHandle_api_SpidHandle.cpp,然后返回VC6.0操作界面,将其添加到工程的Source Files,右键工程窗口中的Source Files,选择添加文件到目录下,选择工程路径下的com_spidHandle_api_SpidHandle.cpp文件。
Java代码  收藏代码
  1. #include "com_spidHandle_api_SpidHandle.h"  
  2. #include <string.h>  
  3.   
  4. #include "MD5.h"  
  5.   
  6. const static char* version = "1201.01";  
  7.   
  8. JNIEXPORT jstring JNICALL Java_com_spidHandle_api_SpidHandle_getSPID  
  9.  (JNIEnv *env , jobject obj, jstring path, jstring login_name, jstring password, jstring key)  
  10. {  
  11.     printf("-= com_spidHandle_api_SpidHandle Version  %s =- \n", version);  
  12.     char icpid[256];  
  13.     const char * md5="A6EIo8tuaKS";  
  14.   
  15.     const char* login_user = env->GetStringUTFChars(login_name, false);  
  16.     const char* login_pwd = env->GetStringUTFChars(password, false);  
  17.     const char* md5_key = env->GetStringUTFChars(key, false);  
  18.     const char* path_str = env->GetStringUTFChars(path, false);  
  19.       
  20.     memset(icpid, 0, 256);  
  21.   
  22.     printf("login_user = %s\n", login_user);  
  23.     printf("path = %s\n", path_str);  
  24.     printf("login_pwd = %s\n", login_pwd);  
  25.     printf("md5_key = %s\n", md5_key);    
  26.   
  27.     // 不管播放哪个url 直接用这个加密  -_-||   
  28.     // pPath = "tmes_224";  
  29.     // 组建加密部分  
  30.     char *p=icpid;  
  31.     *p=strlen(login_user);  
  32.     p++;  
  33.     strcpy(p,login_user);  
  34.     p+=strlen(login_user);  
  35.     *p=strlen(path_str);  
  36.     p++;  
  37.     strcpy(p,path_str);  
  38.     p+=strlen(path_str);  
  39.       
  40.     if(strlen(md5_key) > 1)  
  41.         md5 = md5_key;  
  42.     *p=strlen(md5);  
  43.     p++;  
  44.     strcpy(p,md5);  
  45.     p+=strlen(md5);  
  46.   
  47.     MD5 m1;  
  48.     m1 << md5 << login_user << login_pwd;  
  49.   
  50.     const char *pmd5 = m1.HexDigest();  // symbian专用  
  51.     char md5buf[256];  
  52.     memset(md5buf,0,256);  
  53.     memcpy( md5buf,pmd5,strlen(pmd5) ); // 结束symbian专用  
  54.   
  55.     printf("md5buf = %s\n", md5buf);  
  56.       
  57.     int pmd5_len = strlen(pmd5);  
  58.   
  59.     *p=strlen(md5buf);  
  60.     p++;  
  61.     strcpy(p,md5buf);  
  62.     p+=strlen(md5buf);  
  63.   
  64.     printf("spid = %s\n", icpid);  
  65.   
  66.     return env->NewStringUTF(icpid);  
  67. }  

8、将MD5.h,MD5.cpp拷贝到工程目录下,即跟com_spidHandle_api_SpidHandle.h文件同在项目根目录下。这两个文件其实是我用到的加密类。不是VC自有的,是另外同事开发的。
9、在VC6.0的菜单栏中选择组建;在工程文件夹下的Debug文件夹中生成spidHandle.dll
10、可以将spidHandle.dll拷贝到JAVA PROJECT的spidHandle的项目里,放在项目的根目录,即Z:\project\work_workspace\spidhandle目录 下,用eclispe运行SpidHandle.java文件。在输出窗口中会打印com_spidHandle_api_SpidHandle.cpp
的printf输出部分。

生成so文件,此步需要在linux上操作。
1、将com_spidHandle_api_SpidHandle.h, MD5.h,com_spidHandle_api_SpidHandle.cpp,MD5.cpp文件拷贝到linux下,如拷贝到/home/spidHandle目录中去;
2、在linux下,命令切换到spidHandle文件夹下,执行:
g++ com_spidHandle_api_SpidHandle.cpp MD5.cpp -I/usr/java/jdk1.6.0_16/include -I/usr/java/jdk1.6.0_16/include/linux -fPIC -shared -o libspidhandle.so
命令。其中-I/usr/java/jdk1.6.0_16/include
-I/usr/java/jdk1.6.0_16/include/linux 表示需要引入的头文件。相当于生成DLL引入了jni.h等文件。-fPIC表示生成共享库文件,libspidhandle.so表示库文件名。
3、执行export LD_LIBRARY_PATH=/home/spidHandle
  此步是设置将库文件所在路径加入LD_LIBRARY_PATH中去,如果不执行此步,在运行中就会出现异常:
Java代码  收藏代码
  1. java.lang.UnsatisfiedLinkError: no XXX in java.library.path  

4、可以在Linux中部署一个简单的web 应用,如一个简单的test项目,在servlet中调用该so,调用代码如下:
Java代码  收藏代码
  1. String spid = new SpidHandle().buildSpID(pathforMD5, user,pwd,keyforMD5);  

spid为加密后返回的结果。


补充:
过程中所碰到的问题:

问题1
java.lang.UnsatisfiedLinkError: /home/spidhandle/libspidhandle.so: /home/spidhandle/libspidhandle.so: wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)

在linux中,用servlet调用该so,出现上面的异常,主要因为我所部署应用的linux服务器是64位的,而所生成的so是32位的,后来将项目部署到32位的服务器上就解决问题了。
如何查看linux操作系统是32位还是64位的,可以运行下面命令:
查看操作系统位数
Java代码  收藏代码
  1. file /bin/ls  


问题2
运行servlet,JVM崩溃,并输出JVM异常,异常文件在tomcat启动文件startup.sh同个目录下,如tomcat/bin下,文件格式为hs_err_pid*.log 如,hs_err_pid23600.log
错误日志内容:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xb6e5a1ef, pid=23600, tid=2431036272
#
# JRE version: 6.0_16-b01
# Java VM: Java HotSpot(TM) Server VM (14.2-b01 mixed mode linux-x86 )
# Problematic frame:
# V  [libjvm.so+0x3931ef]
#
# 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 (0x085bbc00):  JavaThread "http-8080-1" daemon [_thread_in_vm, id=23622, stack(0x90e1a000,0x90e6b000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000000

Registers:
EAX=0x00000000, EBX=0xb71dd7c0, ECX=0xb71f87e0, EDX=0x00000ffc
ESP=0x90e696d4, EBP=0x90e69748, ESI=0x0825b0a8, EDI=0x00090e69
EIP=0xb6e5a1ef, CR2=0x00000000, EFLAGS=0x00010296

Top of Stack: (sp=0x90e696d4)
0x90e696d4:   b71d5ec8 00000000 b6e5a127 b7783a30
0x90e696e4:   b77624c0 00000000 90e69700 0825b0a8
0x90e696f4:   080de058 080de060 080de44c 085bbc00
0x90e69704:   00000000 b77d8ff4 9106c730 085bbc00
0x90e69714:   90e69750 b77c7f56 9106c8e8 085bbc00
0x90e69724:   00000001 00000005 00000000 90dd6601
0x90e69734:   90dd6000 00004044 90dd9ff4 927ec5f4
0x90e69744:   085bbc00 90e69768 90dd6fbd 085bbd10

Instructions: (pc=0xb6e5a1ef)
0xb6e5a1df:   ac 8b 46 08 89 45 b0 8b 46 0c 89 45 b4 8b 45 0c
0xb6e5a1ef:   8b 00 50 e8 09 ae fd ff 83 ec 0c 89 c7 50 e8 aa

Stack: [0x90e1a000,0x90e6b000],  sp=0x90e696d4,  free space=317k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x3931ef]
C  [libspidhandle.so+0xfbd]  _ZN7JNIEnv_17GetStringUTFCharsEP8_jstringPh+0x27
C  [libspidhandle.so+0xc6e]  Java_com_spidHandle_api_SpidHandle_getSPID+0x52
j  com.spidHandle.api.SpidHandle.getSPID(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;+0
j  com.spidHandle.api.SpidHandle.buildSpID(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;+6
j  com.play.servlet.PlayServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+1044
j  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+376
j  org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+101
j  org.apache.catalina.core.StandardWrapperValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+804
j  org.apache.catalina.core.StandardContextValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+365
j  org.apache.catalina.core.StandardHostValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+64
j  org.apache.catalina.valves.ErrorReportValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6
j  org.apache.catalina.core.StandardEngineValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+42
j  org.apache.catalina.connector.CoyoteAdapter.service(Lorg/apache/coyote/Request;Lorg/apache/coyote/Response;)V+158
j  org.apache.coyote.http11.Http11Processor.process(Ljava/net/Socket;)V+514
j  org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Ljava/net/Socket;)Z+82
j  org.apache.tomcat.util.net.JIoEndpoint$Worker.run()V+41
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub
V  [libjvm.so+0x36ca20]
V  [libjvm.so+0x530828]
V  [libjvm.so+0x36c227]
V  [libjvm.so+0x36c2da]
V  [libjvm.so+0x3e95f5]
V  [libjvm.so+0x61097e]
V  [libjvm.so+0x531cce]
C  [libpthread.so.0+0x6725]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.spidHandle.api.SpidHandle.getSPID(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;+0
j  com.spidHandle.api.SpidHandle.buildSpID(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;+6
j  com.play.servlet.PlayServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+1044
j  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+376
j  org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+101
j  org.apache.catalina.core.StandardWrapperValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+804
j  org.apache.catalina.core.StandardContextValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+365
j  org.apache.catalina.core.StandardHostValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+64
j  org.apache.catalina.valves.ErrorReportValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6
j  org.apache.catalina.core.StandardEngineValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+42
j  org.apache.catalina.connector.CoyoteAdapter.service(Lorg/apache/coyote/Request;Lorg/apache/coyote/Response;)V+158
j  org.apache.coyote.http11.Http11Processor.process(Ljava/net/Socket;)V+514
j  org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Ljava/net/Socket;)Z+82
j  org.apache.tomcat.util.net.JIoEndpoint$Worker.run()V+41
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
=>0x085bbc00 JavaThread "http-8080-1" daemon [_thread_in_vm, id=23622, stack(0x90e1a000,0x90e6b000)]
  0x912ecc00 JavaThread "TP-Monitor" daemon [_thread_blocked, id=23619, stack(0x90e6b000,0x90ebc000)]
  0x91069c00 JavaThread "TP-Processor4" daemon [_thread_in_native, id=23618, stack(0x90ebc000,0x90f0d000)]
  0x9105f400 JavaThread "TP-Processor3" daemon [_thread_blocked, id=23617, stack(0x90f0d000,0x90f5e000)]
  0x9102f800 JavaThread "TP-Processor2" daemon [_thread_blocked, id=23616, stack(0x90f5e000,0x90faf000)]
  0x912ea400 JavaThread "TP-Processor1" daemon [_thread_blocked, id=23615, stack(0x90faf000,0x91000000)]
  0x912da000 JavaThread "http-8080-Acceptor-0" daemon [_thread_in_native, id=23614, stack(0x9113c000,0x9118d000)]
  0x91036000 JavaThread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon [_thread_blocked, id=23613, stack(0x9118d000,0x911de000)]
  0x912ac400 JavaThread "GC Daemon" daemon [_thread_blocked, id=23612, stack(0x91305000,0x91356000)]
  0x91615c00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=23610, stack(0x9141d000,0x9146e000)]
  0x91613c00 JavaThread "CompilerThread1" daemon [_thread_blocked, id=23609, stack(0x9146e000,0x914ef000)]
  0x91612000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=23608, stack(0x914ef000,0x91570000)]
  0x91610800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=23607, stack(0x91570000,0x915c1000)]
  0x91600800 JavaThread "Finalizer" daemon [_thread_blocked, id=23606, stack(0x9170f000,0x91760000)]
  0x080d8400 JavaThread "Reference Handler" daemon [_thread_blocked, id=23605, stack(0x91760000,0x917b1000)]
  0x08058400 JavaThread "main" [_thread_in_native, id=23601, stack(0xb6a4e000,0xb6a9f000)]

Other Threads:
  0x080d4400 VMThread [stack: 0x917b1000,0x91832000] [id=23604]
  0x91617800 WatcherThread [stack: 0x9139c000,0x9141d000] [id=23611]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
PSYoungGen      total 24448K, used 339K [0xb0420000, 0xb1da0000, 0xb3900000)
  eden space 23168K, 1% used [0xb0420000,0xb0474cf8,0xb1ac0000)
  from space 1280K, 0% used [0xb1c20000,0xb1c20000,0xb1d60000)
  to   space 1408K, 0% used [0xb1ac0000,0xb1ac0000,0xb1c20000)
PSOldGen        total 27072K, used 8597K [0x95d00000, 0x97770000, 0xb0420000)
  object space 27072K, 31% used [0x95d00000,0x96565510,0x97770000)
PSPermGen       total 19200K, used 11186K [0x91d00000, 0x92fc0000, 0x95d00000)
  object space 19200K, 58% used [0x91d00000,0x927ec980,0x92fc0000)

Dynamic libraries:
08048000-08052000 r-xp 00000000 08:03 5775425    /usr/java/jdk1.6.0_16/bin/java
08052000-08053000 rwxp 00009000 08:03 5775425    /usr/java/jdk1.6.0_16/bin/java
08053000-08c64000 rwxp 00000000 00:00 0          [heap]
90cac000-90cb9000 r-xp 00000000 08:03 28295296   /lib/libgcc_s.so.1
90cb9000-90cba000 r-xp 0000c000 08:03 28295296   /lib/libgcc_s.so.1
90cba000-90cbb000 rwxp 0000d000 08:03 28295296   /lib/libgcc_s.so.1
90cbb000-90da3000 r-xp 00000000 08:03 5337022    /usr/lib/libstdc++.so.6.0.10
90da3000-90da7000 r-xp 000e7000 08:03 5337022    /usr/lib/libstdc++.so.6.0.10
90da7000-90da8000 rwxp 000eb000 08:03 5337022    /usr/lib/libstdc++.so.6.0.10
90da8000-90dae000 rwxp 00000000 00:00 0
90dd6000-90dd9000 r-xp 00000000 08:03 27729947   /home/play/lib/libspidhandle.so
90dd9000-90dda000 r-xp 00002000 08:03 27729947   /home/play/lib/libspidhandle.so
90dda000-90ddb000 rwxp 00003000 08:03 27729947   /home/play/lib/libspidhandle.so
90ddb000-90ddc000 r-xs 0000e000 08:03 5808917    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/spidhandle.jar
90ddc000-90ddd000 r-xs 00001000 08:03 5808916    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/slf4j-simple-1.5.8.jar
90ddd000-90ddf000 r-xs 00004000 08:03 5808915    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/slf4j-api-1.5.6.jar
90ddf000-90de5000 r-xs 00035000 08:03 5808914    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/logback-core-0.9.15.jar
90de5000-90dea000 r-xs 00023000 08:03 5808913    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/logback-classic-0.9.15.jar
90dea000-90df1000 r-xs 00059000 08:03 5808912    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/log4j-1.2.15.jar
90df1000-90dfd000 r-xs 000a2000 08:03 5808911    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/jxl.jar
90dfd000-90e07000 r-xs 0005c000 08:03 5808910    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/jstl-1.2.jar
90e07000-90e1a000 r-xs 00114000 08:03 5808909    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/jsf-impl.jar
90e1a000-90e1d000 ---p 00000000 00:00 0
90e1d000-90e6b000 rwxp 00000000 00:00 0          [threadstack:0004d494]
90e6b000-90e6e000 ---p 00000000 00:00 0
90e6e000-90ebc000 rwxp 00000000 00:00 0
90ebc000-90ebf000 ---p 00000000 00:00 0
90ebf000-90f0d000 rwxp 00000000 00:00 0
90f0d000-90f10000 ---p 00000000 00:00 0
90f10000-90f5e000 rwxp 00000000 00:00 0
90f5e000-90f61000 ---p 00000000 00:00 0
90f61000-90faf000 rwxp 00000000 00:00 0
90faf000-90fb2000 ---p 00000000 00:00 0
90fb2000-91000000 rwxp 00000000 00:00 0
91000000-910b3000 rwxp 00000000 00:00 0
910b3000-91100000 ---p 00000000 00:00 0
91100000-91105000 r-xs 0004a000 08:03 5808908    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/jsf-api.jar
91105000-91107000 r-xs 0000d000 08:03 5808907    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/commons-logging-1.1.1.jar
91107000-9113c000 r-xs 00000000 08:03 20439789   /var/run/nscd/dbl5FOXp (deleted)
9113c000-9113f000 ---p 00000000 00:00 0
9113f000-9118d000 rwxp 00000000 00:00 0
9118d000-91190000 ---p 00000000 00:00 0
91190000-911de000 rwxp 00000000 00:00 0
911de000-911f1000 r-xp 00000000 08:03 5784005    /usr/java/jdk1.6.0_16/jre/lib/i386/libnet.so
911f1000-911f2000 rwxp 00013000 08:03 5784005    /usr/java/jdk1.6.0_16/jre/lib/i386/libnet.so
911f2000-911f5000 r-xs 00027000 08:03 5783936    /usr/java/jdk1.6.0_16/jre/lib/ext/sunjce_provider.jar
911f5000-911fc000 r-xs 00091000 08:03 5784036    /usr/java/jdk1.6.0_16/jre/lib/jsse.jar
911fc000-91200000 r-xs 00035000 08:03 5783937    /usr/java/jdk1.6.0_16/jre/lib/ext/sunpkcs11.jar
91200000-912f8000 rwxp 00000000 00:00 0
912f8000-91300000 ---p 00000000 00:00 0
91300000-91302000 r-xs 0000a000 08:03 5808906    /usr/apache-tomcat-6.0.32/webapps/play/WEB-INF/lib/commons-codec-1.3.jar
91302000-91305000 r-xs 00013000 08:03 5784024    /usr/java/jdk1.6.0_16/jre/lib/jce.jar
91305000-91308000 ---p 00000000 00:00 0
91308000-91356000 rwxp 00000000 00:00 0
91356000-91359000 r-xs 000cb000 08:03 5783821    /usr/java/jdk1.6.0_16/jre/lib/ext/localedata.jar
91359000-9135d000 r-xs 00036000 08:03 5808320    /usr/apache-tomcat-6.0.32/lib/catalina-tribes.jar
9135d000-91360000 r-xs 0000f000 08:03 5808331    /usr/apache-tomcat-6.0.32/lib/tomcat-i18n-es.jar
91360000-9136a000 r-xs 000b1000 08:03 5808329    /usr/apache-tomcat-6.0.32/lib/tomcat-coyote.jar
9136a000-91371000 r-xs 0007a000 08:03 5808325    /usr/apache-tomcat-6.0.32/lib/jasper.jar
91371000-91380000 r-xs 0011a000 08:03 5808321    /usr/apache-tomcat-6.0.32/lib/catalina.jar
91380000-91382000 r-xs 0001e000 08:03 5808319    /usr/apache-tomcat-6.0.32/lib/catalina-ha.jar
91382000-91386000 r-xs 0003a000 08:03 5808330    /usr/apache-tomcat-6.0.32/lib/tomcat-dbcp.jar
91386000-91388000 r-xs 0000c000 08:03 5808318    /usr/apache-tomcat-6.0.32/lib/catalina-ant.jar
91388000-9138a000 r-xs 00007000 08:03 5808323    /usr/apache-tomcat-6.0.32/lib/el-api.jar
9138a000-9138c000 r-xs 00014000 08:03 5808328    /usr/apache-tomcat-6.0.32/lib/servlet-api.jar
9138c000-9139a000 r-xs 00170000 08:03 5808322    /usr/apache-tomcat-6.0.32/lib/ecj-3.3.1.jar
9139a000-9139c000 r-xs 0000c000 08:03 5808333    /usr/apache-tomcat-6.0.32/lib/tomcat-i18n-ja.jar
9139c000-9139d000 ---p 00000000 00:00 0
9139d000-9141d000 rwxp 00000000 00:00 0
9141d000-91420000 ---p 00000000 00:00 0
91420000-9146e000 rwxp 00000000 00:00 0
9146e000-91471000 ---p 00000000 00:00 0
91471000-914ef000 rwxp 00000000 00:00 0
914ef000-914f2000 ---p 00000000 00:00 0
914f2000-91570000 rwxp 00000000 00:00 0
91570000-91573000 ---p 00000000 00:00 0
91573000-915c1000 rwxp 00000000 00:00 0
915c1000-91600000 r-xp 00000000 08:03 5546089    /usr/lib/locale/en_US.utf8/LC_CTYPE
91600000-916ff000 rwxp 00000000 00:00 0
916ff000-91700000 ---p 00000000 00:00 0
91700000-91701000 rwxp 00000000 00:00 0
91701000-91703000 r-xs 00011000 08:03 5808326    /usr/apache-tomcat-6.0.32/lib/jsp-api.jar
91703000-91705000 r-xs 0000b000 08:03 5808332    /usr/apache-tomcat-6.0.32/lib/tomcat-i18n-fr.jar
91705000-91708000 r-xs 00019000 08:03 5808324    /usr/apache-tomcat-6.0.32/lib/jasper-el.jar
91708000-9170e000 r-xp 00000000 08:03 5784001    /usr/java/jdk1.6.0_16/jre/lib/i386/libmanagement.so
9170e000-9170f000 rwxp 00005000 08:03 5784001    /usr/java/jdk1.6.0_16/jre/lib/i386/libmanagement.so
9170f000-91712000 ---p 00000000 00:00 0
91712000-91760000 rwxp 00000000 00:00 0
91760000-91763000 ---p 00000000 00:00 0
91763000-917b1000 rwxp 00000000 00:00 0
917b1000-917b2000 ---p 00000000 00:00 0
917b2000-91865000 rwxp 00000000 00:00 0
91865000-919fb000 r-xs 02fb3000 08:03 5784038    /usr/java/jdk1.6.0_16/jre/lib/rt.jar
919fb000-919fc000 ---p 00000000 00:00 0
919fc000-91a7c000 rwxp 00000000 00:00 0
91a7c000-91a7d000 ---p 00000000 00:00 0
91a7d000-91b07000 rwxp 00000000 00:00 0
91b07000-91b1d000 rwxp 00000000 00:00 0
91b1d000-91b2b000 rwxp 00000000 00:00 0
91b2b000-91bf1000 rwxp 00000000 00:00 0
91bf1000-91bfb000 rwxp 00000000 00:00 0
91bfb000-91c11000 rwxp 00000000 00:00 0
91c11000-91c1f000 rwxp 00000000 00:00 0
91c1f000-91ce4000 rwxp 00000000 00:00 0
91ce4000-91cf2000 rwxp 00000000 00:00 0
91cf2000-91cff000 rwxp 00000000 00:00 0
91cff000-92fc0000 rwxp 00000000 00:00 0
92fc0000-95d00000 rwxp 00000000 00:00 0
95d00000-97770000 rwxp 00000000 00:00 0
97770000-b0420000 rwxp 00000000 00:00 0
b0420000-b1da0000 rwxp 00000000 00:00 0
b1da0000-b3900000 rwxp 00000000 00:00 0
b3900000-b3901000 r-xs 00003000 08:03 5808317    /usr/apache-tomcat-6.0.32/lib/annotations-api.jar
b3901000-b3902000 r-xs 00006000 08:03 5808298    /usr/apache-tomcat-6.0.32/bin/tomcat-juli.jar
b3902000-b3903000 r-xs 00005000 08:03 5808288    /usr/apache-tomcat-6.0.32/bin/commons-daemon.jar
b3903000-b390a000 r-xs 00000000 08:03 5523095    /usr/lib/gconv/gconv-modules.cache
b390a000-b3913000 rwxp 00000000 00:00 0
b3913000-b39ca000 rwxp 00000000 00:00 0
b39ca000-b3c0a000 rwxp 00000000 00:00 0
b3c0a000-b69ca000 rwxp 00000000 00:00 0
b69ca000-b69d9000 r-xp 00000000 08:03 5784014    /usr/java/jdk1.6.0_16/jre/lib/i386/libzip.so
b69d9000-b69db000 rwxp 0000e000 08:03 5784014    /usr/java/jdk1.6.0_16/jre/lib/i386/libzip.so
b69db000-b69e3000 rwxs 00000000 08:03 6743707    /tmp/hsperfdata_root/23600
b69e3000-b6a18000 r-xs 00000000 08:03 20439787   /var/run/nscd/passwd
b6a18000-b6a1e000 r-xp 00000000 08:03 5784018    /usr/java/jdk1.6.0_16/jre/lib/i386/native_threads/libhpi.so
b6a1e000-b6a1f000 rwxp 00006000 08:03 5784018    /usr/java/jdk1.6.0_16/jre/lib/i386/native_threads/libhpi.so
b6a1f000-b6a42000 r-xp 00000000 08:03 5783990    /usr/java/jdk1.6.0_16/jre/lib/i386/libjava.so
b6a42000-b6a44000 rwxp 00023000 08:03 5783990    /usr/java/jdk1.6.0_16/jre/lib/i386/libjava.so
b6a44000-b6a4c000 r-xp 00000000 08:03 28295217   /lib/librt-2.11.1.so
b6a4c000-b6a4d000 r-xp 00007000 08:03 28295217   /lib/librt-2.11.1.so
b6a4d000-b6a4e000 rwxp 00008000 08:03 28295217   /lib/librt-2.11.1.so
b6a4e000-b6a51000 ---p 00000000 00:00 0
b6a51000-b6a9f000 rwxp 00000000 00:00 0
b6a9f000-b6ac5000 r-xp 00000000 08:03 28295195   /lib/libm-2.11.1.so
b6ac5000-b6ac6000 r-xp 00026000 08:03 28295195   /lib/libm-2.11.1.so
b6ac6000-b6ac7000 rwxp 00027000 08:03 28295195   /lib/libm-2.11.1.so
b6ac7000-b7194000 r-xp 00000000 08:03 5784022    /usr/java/jdk1.6.0_16/jre/lib/i386/server/libjvm.so
b7194000-b71e2000 rwxp 006cc000 08:03 5784022    /usr/java/jdk1.6.0_16/jre/lib/i386/server/libjvm.so
b71e2000-b7605000 rwxp 00000000 00:00 0
b7605000-b7760000 r-xp 00000000 08:03 28295187   /lib/libc-2.11.1.so
b7760000-b7762000 r-xp 0015b000 08:03 28295187   /lib/libc-2.11.1.so
b7762000-b7763000 rwxp 0015d000 08:03 28295187   /lib/libc-2.11.1.so
b7763000-b7767000 rwxp 00000000 00:00 0
b7767000-b776a000 r-xp 00000000 08:03 28295193   /lib/libdl-2.11.1.so
b776a000-b776b000 r-xp 00002000 08:03 28295193   /lib/libdl-2.11.1.so
b776b000-b776c000 rwxp 00003000 08:03 28295193   /lib/libdl-2.11.1.so
b776c000-b7773000 r-xp 00000000 08:03 5783973    /usr/java/jdk1.6.0_16/jre/lib/i386/jli/libjli.so
b7773000-b7775000 rwxp 00006000 08:03 5783973    /usr/java/jdk1.6.0_16/jre/lib/i386/jli/libjli.so
b7775000-b778c000 r-xp 00000000 08:03 28295213   /lib/libpthread-2.11.1.so
b778c000-b778d000 r-xp 00016000 08:03 28295213   /lib/libpthread-2.11.1.so
b778d000-b778e000 rwxp 00017000 08:03 28295213   /lib/libpthread-2.11.1.so
b778e000-b7790000 rwxp 00000000 00:00 0
b7790000-b7791000 r-xs 00005000 08:03 5808283    /usr/apache-tomcat-6.0.32/bin/bootstrap.jar
b7791000-b7792000 rwxp 00000000 00:00 0
b7792000-b7793000 r-xp 00000000 00:00 0
b7793000-b77a8000 r-xp 00000000 08:03 28295198   /lib/libnsl-2.11.1.so
b77a8000-b77a9000 r-xp 00014000 08:03 28295198   /lib/libnsl-2.11.1.so
b77a9000-b77aa000 rwxp 00015000 08:03 28295198   /lib/libnsl-2.11.1.so
b77aa000-b77ac000 rwxp 00000000 00:00 0
b77ac000-b77b7000 r-xp 00000000 08:03 5784013    /usr/java/jdk1.6.0_16/jre/lib/i386/libverify.so
b77b7000-b77b8000 rwxp 0000b000 08:03 5784013    /usr/java/jdk1.6.0_16/jre/lib/i386/libverify.so
b77b8000-b77b9000 rwxp 00000000 00:00 0
b77b9000-b77d8000 r-xp 00000000 08:03 28295180   /lib/ld-2.11.1.so
b77d8000-b77d9000 r-xp 0001e000 08:03 28295180   /lib/ld-2.11.1.so
b77d9000-b77da000 rwxp 0001f000 08:03 28295180   /lib/ld-2.11.1.so
bfcc6000-bfcdb000 rwxp 00000000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]

VM Arguments:
jvm_args: -Djava.util.logging.config.file=/usr/apache-tomcat-6.0.32/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/apache-tomcat-6.0.32/endorsed -Dcatalina.base=/usr/apache-tomcat-6.0.32 -Dcatalina.home=/usr/apache-tomcat-6.0.32 -Djava.io.tmpdir=/usr/apache-tomcat-6.0.32/temp
java_command: org.apache.catalina.startup.Bootstrap start
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=/usr/java/jdk1.6.0_16
CLASSPATH=/usr/apache-tomcat-6.0.32/bin/bootstrap.jar
PATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/java/jdk1.6.0_16/bin:/usr/java/jdk1.6.0_16/jre/bin
LD_LIBRARY_PATH=/usr/java/jdk1.6.0_16/jre/lib/i386/server:/usr/java/jdk1.6.0_16/jre/lib/i386:/usr/java/jdk1.6.0_16/jre/../lib/i386:/home/play/lib
SHELL=/bin/bash
HOSTTYPE=i386
OSTYPE=linux
MACHTYPE=i686-suse-linux

Signal Handlers:
SIGSEGV: [libjvm.so+0x650710], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGBUS: [libjvm.so+0x650710], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGFPE: [libjvm.so+0x52f600], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGPIPE: [libjvm.so+0x52f600], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGXFSZ: [libjvm.so+0x52f600], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGILL: [libjvm.so+0x52f600], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x5321f0], sa_mask[0]=0x00000000, sa_flags=0x10000004
SIGHUP: [libjvm.so+0x531f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGINT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGTERM: [libjvm.so+0x531f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGQUIT: [libjvm.so+0x531f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004


---------------  S Y S T E M  ---------------

OS:SUSE Linux Enterprise Server 11 (i586)
VERSION = 11
PATCHLEVEL = 1

uname:Linux 2.6.32.12-0.7-pae #1 SMP 2010-05-20 11:14:20 +0200 i686
libc:glibc 2.11.1 NPTL 2.11.1
rlimit: STACK 8192k, CORE 1k, NPROC 15118, NOFILE 8192, AS 3192000k
load average:0.00 0.04 0.05

CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 10, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3

Memory: 4k page, physical 1941704k(213752k free), swap 2048276k(1540564k free)

vm_info: Java HotSpot(TM) Server VM (14.2-b01) for linux-x86 JRE (1.6.0_16-b01), built on Jul 31 2009 06:03:51 by "java_re" with gcc 3.2.1-7a (J2SE release)

time: Sat Mar 12 17:13:08 2011
elapsed time: 27 seconds

一开始以为是JVM无法释放C的对象,但后来发现
Java代码  收藏代码
  1. Heap  
  2.  PSYoungGen      total 24448K, used 339K [0xb0420000, 0xb1da0000, 0xb3900000)  
  3.   eden space 23168K, 1% used [0xb0420000,0xb0474cf8,0xb1ac0000)  
  4.   from space 1280K, 0% used [0xb1c20000,0xb1c20000,0xb1d60000)  
  5.   to   space 1408K, 0% used [0xb1ac0000,0xb1ac0000,0xb1c20000)  
  6.  PSOldGen        total 27072K, used 8597K [0x95d00000, 0x97770000, 0xb0420000)  
  7.   object space 27072K, 31% used [0x95d00000,0x96565510,0x97770000)  
  8.  PSPermGen       total 19200K, used 11186K [0x91d00000, 0x92fc0000, 0x95d00000)  
  9.   object space 19200K, 58% used [0x91d00000,0x927ec980,0x92fc0000)  


并没有出现堆栈缢出的现象,所以排除该原因。

查阅 文档:
      JavaTM 2 Platform, Standard Edition 5.0
      Troubleshooting and Diagnostic Guide
      文档中提到:
     
      If you get a crash in a native application library (like the above examples) then you may be able to
      attach the native debugger (dbx, gdb, windbg depending on the operating system) to the core file/crash
      dump if it is available. Another approach is run with the -Xcheck:jni option added to the command
      line (section 1.17.3). The -Xcheck:jni option is not guaranteed to find all issues with JNI code but it
      can help identify a significant number of issues.
     
      解决方法:
      启动JVM时增加启动参数 -Xcheck:jni
      日志中输出JNI的错误日志:
     
Java代码  收藏代码
  1. FATAL ERROR in native method: JNI string operation received a non-string  
  2. at com.spidHandle.api.SpidHandle.getSPID(Native Method)  
  3. at com.spidHandle.api.SpidHandle.buildSpID(SpidHandle.java:12)  
  4. at com.play.servlet.PlayServlet.service(PlayServlet.java:190)  
  5. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
  6. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  7. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)  
  8. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)  
  9. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)  
  10. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)  
  11. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  
  12. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)  
  13. at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)  
  14. at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)  
  15. at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)  
  16. at java.lang.Thread.run(Thread.java:619)
JVM崩溃的原因找到了.是由于传入C方法体中某个参数值为NULL,如buildSpID(String path, String login_name, String password, String key)中login_name为NULL,导致传递给C程序的参数为NULL.NULL值传递给C,C不能识别他为字符串,所以JVM崩溃.

http://zhxmyself.iteye.com/blog/961249
posted on 2011-09-27 14:42 temper 阅读(6188) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: