F7ANTY
f7anty
采纳率0%
2018-03-16 02:53

java程序通过JNI调用第三方so文件,运行出现crash,导致程序退出

80

在spring boot中使用JNI集成第三方so文件,通过
java -XX:+UnlockDiagnosticVMOptions -XX:+VerifyBeforeGC -XX:+VerifyAfterGC -jar xxxxx.jar运行,在调用第三方so文件时出现crash,导致程序退出
图片说明
下面是crash产生的日志文件hs_err_pid17314.log

 #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (instanceKlass.cpp:3358), pid=17314, tid=0x00007ff1fe6e6700
#  guarantee(false) failed: boom
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 compiled mode linux-amd64 compressed oops)
# Core dump written. Default location: /data/html/agora/core or core.17314
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x00007ff22c1c6000):  VMThread [stack: 0x00007ff1fe5e6000,0x00007ff1fe6e7000] [id=17324]

Stack: [0x00007ff1fe5e6000,0x00007ff1fe6e7000],  sp=0x00007ff1fe6e5200,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0xac5c2a]  VMError::report_and_die()+0x2ba
V  [libjvm.so+0x4fbc92]  report_vm_error(char const*, int, char const*, char const*)+0x62
V  [libjvm.so+0x655582]  VerifyFieldClosure::do_oop(unsigned int*)+0x102
V  [libjvm.so+0x64b651]  InstanceKlass::oop_oop_iterate_nv(oopDesc*, NoHeaderExtendedOopClosure*)+0x91
V  [libjvm.so+0x63ea8f]  InstanceKlass::oop_verify_on(oopDesc*, outputStream*)+0x5f
V  [libjvm.so+0x8dd059]  MutableSpace::verify()+0x69
V  [libjvm.so+0x992486]  PSYoungGen::verify()+0x16
V  [libjvm.so+0xa8cf6c]  Universe::verify(VerifyOption, char const*, bool)+0xcc
V  [libjvm.so+0x98e6f0]  PSScavenge::invoke_no_policy()+0x330
V  [libjvm.so+0x98fa81]  PSScavenge::invoke()+0x41
V  [libjvm.so+0x9467d0]  ParallelScavengeHeap::failed_mem_allocate(unsigned long)+0x70
V  [libjvm.so+0xac7647]  VM_ParallelGCFailedAllocation::doit()+0x97
V  [libjvm.so+0xacf125]  VM_Operation::evaluate()+0x55
V  [libjvm.so+0xacd4fa]  VMThread::evaluate_operation(VM_Operation*)+0xba
V  [libjvm.so+0xacd87e]  VMThread::loop()+0x1ce
V  [libjvm.so+0xacdcf0]  VMThread::run()+0x70
V  [libjvm.so+0x924ea8]  java_start(Thread*)+0x108

VM_Operation (0x00007ff1753d7780): ParallelGCFailedAllocation, mode: safepoint, requested by thread 0x00007ff128001000
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • cccfire 杨园亮 3年前

    第一步 建立一个监听类

    建立监听类的作用是在应用中间件启动时自动执行加载程序。

    1)创建一个类实现ServletContextListener 接口

    2)实现contextInitialized方法

    3)在项目的web.xml 文件中配置此监听类
    第二步 添加动态库到系统变量

    将dll/so文件所在的路径添加到系统环境java.library.path 中

    添加过程需要使用到反射机制来进行,不能使用System.setProperty()进行设置,设置了也无效。直接看代码:
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    private void addDirToPath(String s){
    try {
    //获取系统path变量对象
    Field field=ClassLoader.class.getDeclaredField("sys_paths");
    //设置此变量对象可访问
    field.setAccessible(true);
    //获取此变量对象的值
    String[] path=(String[])field.get(null);
    //创建字符串数组,在原来的数组长度上增加一个,用于存放增加的目录
    String[] tem=new String[path.length+1];
    //将原来的path变量复制到tem中
    System.arraycopy(path,0,tem,0,path.length);
    //将增加的目录存入新的变量数组中
    tem[path.length]=s;
    //将增加目录后的数组赋给path变量对象
    field.set(null,tem);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    第三步 加载动态库文件

    接下来就可以写上下文初始化的方法了:
    ?
    1
    2
    3
    4
    5
    6
    7
    8

    public void contextInitialized(ServletContextEvent arg0) {
    //获取存放dll文件的绝对路径(假设将dll文件放在系统根目录下的WEB-INF文件夹中)
    String path=arg0.getServletContext().getRealPath("WEB-INF");
    //将此目录添加到系统环境变量中
    addDirToPath(path);
    //加载相应的dll/so文件,注意要将'\'替换为'/'
    System.load(path.replaceAll("\\","/")+"/XXXX.dll");
    }
    第四步 重启启动应用中间件(Tomcat|Weblogic)

    至此就可以在你的java程序中使用dll/so文件的方法了。

    点赞 评论 复制链接分享
  • changk521 changk521 3年前

    你java类名要和so名称一致

    点赞 评论 复制链接分享
  • WeiXin_zjmgly 一世琥珀色 3年前

    先根据接口文档检查数据类型,如果没错的话可能是so问题

    点赞 评论 复制链接分享
  • LXdragon1991 龙图腾之祥龙 3年前

    先根据接口文档检查数据类型,如果没错的话可能是so问题,让其他人给个测试的函数再试试吧。

    点赞 评论 复制链接分享
  • F7ANTY f7anty 3年前

    上图中在crash的时候有输出 Failed: 0x0000000724e62b08 -> 0x0000000324c18200,通过hsdb分析附近的栈信息,如下

    图片说明

    图片说明

    上图中标识的红框是不是表明yuv: ** BAD OOP 是一个坏的指针

    点赞 评论 复制链接分享
  • molu_guest YanJa99 3年前

    太多了,难道不能捡重要的错误吗

    点赞 评论 复制链接分享
  • oyljerry oyljerry 3年前

    failed_mem_allocate 看上去是so中分配内存等失败了,so的接口代码中增加一些输出,进一步定位

    点赞 评论 复制链接分享
  • F7ANTY f7anty 3年前
     ---------------  P R O C E S S  ---------------
    
    Java Threads: ( => current thread )
      0x00007ff1300d7800 JavaThread "I/O dispatcher 32" [_thread_in_native, id=17603, stack(0x00007ff0ffbfc000,0x00007ff0ffcfd000)]
      0x00007ff1300d5800 JavaThread "I/O dispatcher 31" [_thread_in_native, id=17602, stack(0x00007ff0ffcfd000,0x00007ff0ffdfe000)]
      0x00007ff1300d3800 JavaThread "I/O dispatcher 30" [_thread_in_native, id=17601, stack(0x00007ff0ffdfe000,0x00007ff0ffeff000)]
      0x00007ff1300d1800 JavaThread "I/O dispatcher 29" [_thread_in_native, id=17600, stack(0x00007ff0ffeff000,0x00007ff100000000)]
      0x00007ff1300cf800 JavaThread "I/O dispatcher 28" [_thread_in_native, id=17599, stack(0x00007ff1740d4000,0x00007ff1741d5000)]
      0x00007ff1300ce000 JavaThread "I/O dispatcher 27" [_thread_in_native, id=17598, stack(0x00007ff1741d5000,0x00007ff1742d6000)]
      0x00007ff1300cc000 JavaThread "I/O dispatcher 26" [_thread_in_native, id=17597, stack(0x00007ff1742d6000,0x00007ff1743d7000)]
      0x00007ff1300ca800 JavaThread "I/O dispatcher 25" [_thread_in_native, id=17596, stack(0x00007ff1743d7000,0x00007ff1744d8000)]
      0x00007ff1282f0000 JavaThread "Thread-12" daemon [_thread_blocked, id=17595, stack(0x00007ff1744d8000,0x00007ff1745d9000)]
      0x00007ff1282ef800 JavaThread "pool-8-thread-1" [_thread_in_native, id=17594, stack(0x00007ff1745d9000,0x00007ff1746da000)]
      0x00007ff128004000 JavaThread "process reaper" daemon [_thread_blocked, id=17500, stack(0x00007ff21c02b000,0x00007ff21c064000)]
      0x00007ff128001000 JavaThread "Thread-11" [_thread_blocked, id=17489, stack(0x00007ff1749db000,0x00007ff1753dc000)]
      0x00007ff158004800 JavaThread "pool-2-thread-2" [_thread_in_native, id=17467, stack(0x00007ff1746da000,0x00007ff1747db000)]
      0x00007ff164a34000 JavaThread "pool-2-thread-1" [_thread_blocked, id=17411, stack(0x00007ff1753dc000,0x00007ff1754dd000)]
      0x00007ff10c0d5800 JavaThread "I/O dispatcher 24" [_thread_in_native, id=17410, stack(0x00007ff1754dd000,0x00007ff1755de000)]
      0x00007ff10c0d4000 JavaThread "I/O dispatcher 23" [_thread_in_native, id=17409, stack(0x00007ff1755de000,0x00007ff1756df000)]
      0x00007ff10c0d2000 JavaThread "I/O dispatcher 22" [_thread_in_native, id=17408, stack(0x00007ff1756df000,0x00007ff1757e0000)]
      0x00007ff10c0d0000 JavaThread "I/O dispatcher 21" [_thread_in_native, id=17407, stack(0x00007ff1757e0000,0x00007ff1758e1000)]
      0x00007ff10c0ce800 JavaThread "I/O dispatcher 20" [_thread_in_native, id=17406, stack(0x00007ff1758e1000,0x00007ff1759e2000)]
      0x00007ff10c0cc800 JavaThread "I/O dispatcher 19" [_thread_in_native, id=17405, stack(0x00007ff1759e2000,0x00007ff175ae3000)]
      0x00007ff10c0cb000 JavaThread "I/O dispatcher 18" [_thread_in_native, id=17404, stack(0x00007ff175ae3000,0x00007ff175be4000)]
      0x00007ff10c0c9000 JavaThread "I/O dispatcher 17" [_thread_in_native, id=17403, stack(0x00007ff175be4000,0x00007ff175ce5000)]
      0x00007ff164975000 JavaThread "Thread-9" daemon [_thread_blocked, id=17402, stack(0x00007ff175ce5000,0x00007ff175de6000)]
      0x00007ff164974000 JavaThread "pool-7-thread-1" [_thread_in_native, id=17401, stack(0x00007ff175de6000,0x00007ff175ee7000)]
      0x00007ff22c008800 JavaThread "DestroyJavaVM" [_thread_blocked, id=17315, stack(0x00007ff235bea000,0x00007ff235ceb000)]
      0x00007ff22d723800 JavaThread "Thread-8" [_thread_blocked, id=17387, stack(0x00007ff1760e7000,0x00007ff1761e8000)]
      0x00007ff22ce20000 JavaThread "grpc-default-boss-ELG-1-1" daemon [_thread_in_native, id=17386, stack(0x00007ff1761e8000,0x00007ff1762e9000)]
      0x00007ff13c0d7000 JavaThread "I/O dispatcher 16" [_thread_in_native, id=17385, stack(0x00007ff1766e9000,0x00007ff1767ea000)]
      0x00007ff13c0d5000 JavaThread "I/O dispatcher 15" [_thread_in_native, id=17384, stack(0x00007ff1767ea000,0x00007ff1768eb000)]
      0x00007ff13c0d3800 JavaThread "I/O dispatcher 14" [_thread_in_native, id=17383, stack(0x00007ff1768eb000,0x00007ff1769ec000)]
      0x00007ff13c0d1800 JavaThread "I/O dispatcher 13" [_thread_in_native, id=17382, stack(0x00007ff1769ec000,0x00007ff176aed000)]
      0x00007ff13c0d0000 JavaThread "I/O dispatcher 12" [_thread_in_native, id=17381, stack(0x00007ff176aed000,0x00007ff176bee000)]
      0x00007ff13c0ce000 JavaThread "I/O dispatcher 11" [_thread_in_native, id=17380, stack(0x00007ff176bee000,0x00007ff176cef000)]
      0x00007ff13c0cc000 JavaThread "I/O dispatcher 10" [_thread_in_native, id=17379, stack(0x00007ff176cef000,0x00007ff176df0000)]
      0x00007ff13c001800 JavaThread "I/O dispatcher 9" [_thread_in_native, id=17378, stack(0x00007ff176df0000,0x00007ff176ef1000)]
      0x00007ff18c32a000 JavaThread "Thread-7" daemon [_thread_blocked, id=17377, stack(0x00007ff176ef1000,0x00007ff176ff2000)]
      0x00007ff18c359800 JavaThread "pool-4-thread-1" [_thread_in_native, id=17376, stack(0x00007ff176ff2000,0x00007ff1770f3000)]
      0x00007ff22ca79800 JavaThread "http-nio-50000-AsyncTimeout" daemon [_thread_blocked, id=17375, stack(0x00007ff1770f3000,0x00007ff1771f4000)]
      0x00007ff22ca78000 JavaThread "http-nio-50000-Acceptor-0" daemon [_thread_in_native, id=17374, stack(0x00007ff1771f4000,0x00007ff1772f5000)]
      0x00007ff22de8a800 JavaThread "http-nio-50000-ClientPoller-1" daemon [_thread_in_native, id=17373, stack(0x00007ff1772f5000,0x00007ff1773f6000)]
      0x00007ff22c2b7000 JavaThread "http-nio-50000-ClientPoller-0" daemon [_thread_in_native, id=17372, stack(0x00007ff1773f6000,0x00007ff1774f7000)]
      0x00007ff22e2f8800 JavaThread "http-nio-50000-exec-10" daemon [_thread_blocked, id=17371, stack(0x00007ff1774f7000,0x00007ff1775f8000)]
      0x00007ff22e2f7000 JavaThread "http-nio-50000-exec-9" daemon [_thread_blocked, id=17370, stack(0x00007ff1775f8000,0x00007ff1776f9000)]
      0x00007ff22da0e800 JavaThread "http-nio-50000-exec-8" daemon [_thread_blocked, id=17369, stack(0x00007ff1776f9000,0x00007ff1777fa000)]
      0x00007ff22ce58000 JavaThread "http-nio-50000-exec-7" daemon [_thread_blocked, id=17368, stack(0x00007ff1777fa000,0x00007ff1778fb000)]
      0x00007ff22ccb7000 JavaThread "http-nio-50000-exec-6" daemon [_thread_blocked, id=17367, stack(0x00007ff1778fb000,0x00007ff1779fc000)]
      0x00007ff22d4b9000 JavaThread "http-nio-50000-exec-5" daemon [_thread_blocked, id=17366, stack(0x00007ff1779fc000,0x00007ff177afd000)]
      0x00007ff22e91d000 JavaThread "http-nio-50000-exec-4" daemon [_thread_blocked, id=17365, stack(0x00007ff177afd000,0x00007ff177bfe000)]
      0x00007ff22c9e2000 JavaThread "http-nio-50000-exec-3" daemon [_thread_blocked, id=17364, stack(0x00007ff177bfe000,0x00007ff177cff000)]
      0x00007ff22cc0f800 JavaThread "http-nio-50000-exec-2" daemon [_thread_blocked, id=17363, stack(0x00007ff177cff000,0x00007ff177e00000)]
      0x00007ff22e077000 JavaThread "http-nio-50000-exec-1" daemon [_thread_blocked, id=17362, stack(0x00007ff1b4033000,0x00007ff1b4134000)]
      0x00007ff22cf0e000 JavaThread "NioBlockingSelector.BlockPoller-1" daemon [_thread_in_native, id=17361, stack(0x00007ff1b4a37000,0x00007ff1b4b38000)]
      0x00007ff22d0de800 JavaThread "pool-3-thread-1" [_thread_blocked, id=17360, stack(0x00007ff1b4b38000,0x00007ff1b4c39000)]
      0x00007ff22e750800 JavaThread "commons-pool-EvictionTimer" daemon [_thread_blocked, id=17355, stack(0x00007ff1b4534000,0x00007ff1b4635000)]
      0x00007ff22d70c000 JavaThread "container-0" [_thread_blocked, id=17353, stack(0x00007ff1b4635000,0x00007ff1b4736000)]
      0x00007ff22cf8f000 JavaThread "ContainerBackgroundProcessor[StandardEngine[Tomcat]]" daemon [_thread_blocked, id=17352, stack(0x00007ff1b4736000,0x00007ff1b4837000)]
      0x00007ff1b0c44000 JavaThread "I/O dispatcher 8" [_thread_in_native, id=17349, stack(0x00007ff1d4672000,0x00007ff1d4773000)]
      0x00007ff1b0bd2000 JavaThread "I/O dispatcher 7" [_thread_in_native, id=17348, stack(0x00007ff1d4773000,0x00007ff1d4874000)]
      0x00007ff1b035f000 JavaThread "I/O dispatcher 6" [_thread_in_native, id=17347, stack(0x00007ff1d4874000,0x00007ff1d4975000)]
      0x00007ff1b007c000 JavaThread "I/O dispatcher 5" [_thread_in_native, id=17346, stack(0x00007ff1d4975000,0x00007ff1d4a76000)]
      0x00007ff1b0309800 JavaThread "I/O dispatcher 4" [_thread_in_native, id=17345, stack(0x00007ff1d4a76000,0x00007ff1d4b77000)]
      0x00007ff1b076e000 JavaThread "I/O dispatcher 3" [_thread_in_native, id=17344, stack(0x00007ff1d4b77000,0x00007ff1d4c78000)]
      0x00007ff1b01cc800 JavaThread "I/O dispatcher 2" [_thread_in_native, id=17343, stack(0x00007ff1d4c78000,0x00007ff1d4d79000)]
      0x00007ff1b0d72000 JavaThread "I/O dispatcher 1" [_thread_in_native, id=17342, stack(0x00007ff1d4d79000,0x00007ff1d4e7a000)]
      0x00007ff22e79b000 JavaThread "Thread-2" daemon [_thread_blocked, id=17341, stack(0x00007ff1fc08a000,0x00007ff1fc18b000)]
      0x00007ff22e73a000 JavaThread "pool-1-thread-1" [_thread_in_native, id=17340, stack(0x00007ff1fcd9c000,0x00007ff1fce9d000)]
      0x00007ff22c218000 JavaThread "Service Thread" daemon [_thread_blocked, id=17332, stack(0x00007ff1fddde000,0x00007ff1fdedf000)]
      0x00007ff22c20e000 JavaThread "C1 CompilerThread3" daemon [_thread_blocked, id=17331, stack(0x00007ff1fdedf000,0x00007ff1fdfe0000)]
      0x00007ff22c20c000 JavaThread "C2 CompilerThread2" daemon [_thread_blocked, id=17330, stack(0x00007ff1fdfe0000,0x00007ff1fe0e1000)]
      0x00007ff22c20a000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=17329, stack(0x00007ff1fe0e1000,0x00007ff1fe1e2000)]
      0x00007ff22c207000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=17328, stack(0x00007ff1fe1e2000,0x00007ff1fe2e3000)]
      0x00007ff22c205800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=17327, stack(0x00007ff1fe2e3000,0x00007ff1fe3e4000)]
      0x00007ff22c1d2800 JavaThread "Finalizer" daemon [_thread_blocked, id=17326, stack(0x00007ff1fe3e4000,0x00007ff1fe4e5000)]
      0x00007ff22c1ce000 JavaThread "Reference Handler" daemon [_thread_blocked, id=17325, stack(0x00007ff1fe4e5000,0x00007ff1fe5e6000)]
    
    Other Threads:
    =>0x00007ff22c1c6000 VMThread [stack: 0x00007ff1fe5e6000,0x00007ff1fe6e7000] [id=17324]
      0x00007ff22c213800 WatcherThread [stack: 0x00007ff1fdcdd000,0x00007ff1fddde000] [id=17333]
    
    VM state:at safepoint (normal execution)
    
    VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
    [0x00007ff22c005e50] Threads_lock - owner thread: 0x00007ff22c1c6000
    [0x00007ff22c006350] Heap_lock - owner thread: 0x00007ff128001000
    
    Heap:
     PSYoungGen      total 466944K, used 454656K [0x0000000719800000, 0x0000000736d00000, 0x00000007c0000000)
      eden space 454656K, 100% used [0x0000000719800000,0x0000000735400000,0x0000000735400000)
      from space 12288K, 0% used [0x0000000736080000,0x0000000736080000,0x0000000736c80000)
      to   space 12800K, 0% used [0x0000000735400000,0x0000000735400000,0x0000000736080000)
     ParOldGen       total 225280K, used 34933K [0x00000005cc800000, 0x00000005da400000, 0x0000000719800000)
      object space 225280K, 15% used [0x00000005cc800000,0x00000005cea1d580,0x00000005da400000)
     Metaspace       used 66039K, capacity 67058K, committed 67456K, reserved 1110016K
      class space    used 6509K, capacity 6683K, committed 6784K, reserved 1048576K
    
    Card table byte_map: [0x00007ff232022000,0x00007ff232fbf000] byte_map_base: 0x00007ff22f1be000
    
    点赞 评论 复制链接分享

为你推荐