JNI DETECTED ERROR IN APPLICATION: java_object == null

记录一个问题,在调用一个j ni方法的时候报了一个错误,错误日志如下:

01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: java_object == null

01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] in call to GetObjectClass
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] “main” prio=5 tid=1 Runnable
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] | group=”main” sCount=0 dsCount=0 obj=0x768497a8 self=0xee105400
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] | sysTid=20617 nice=0 cgrp=default sched=0/0 handle=0xf1736534
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] | state=R schedstat=( 0 0 0 ) utm=85 stm=9 core=7 HZ=100
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] | stack=0xff770000-0xff772000 stackSize=8MB
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] | held mutexes= “mutator lock”(shared held)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #00 pc 00351449 /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+128)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #01 pc 0033195d /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+304)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #02 pc 00239f77 /system/lib/libart.so (ZN3art9JavaVMExt8JniAbortEPKcS2+846)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #03 pc 0023a523 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+66)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #04 pc 00265777 /system/lib/libart.so (_ZN3art3JNI14GetObjectClassEP7_JNIEnvP8_jobject+478)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #05 pc 000c14a5 /system/lib/libart.so (_ZN3art8CheckJNI14GetObjectClassEP7_JNIEnvP8_jobject+460)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #06 pc 000f6813 /data/app/com.teligen.dialer.mihua-2/lib/arm/libsimterm.so (getSignHashBytes2+18)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #07 pc 000f6add /data/app/com.teligen.dialer.mihua-2/lib/arm/libsimterm.so (_Z9checkSignP7_JNIEnv+20)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #08 pc 000f6b41 /data/app/com.teligen.dialer.mihua-2/lib/arm/libsimterm.so (JNI_OnLoad+60)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #09 pc 0023bf25 /system/lib/libart.so (ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEP8_jobjectP8_jstringPS9+1844)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #10 pc 0000315f /system/lib/libopenjdkjvm.so (JVM_NativeLoad+178)
01-02 10:29:26.288 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] native: #11 pc 0007118d /system/framework/arm/boot.oat (Java_java_lang_Runtime_nativeLoad__Ljava_lang_String_2Ljava_lang_ClassLoader_2Ljava_lang_String_2+144)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at java.lang.Runtime.nativeLoad(Native method)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at java.lang.Runtime.doLoad(Runtime.java:1060)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] - locked <0x0b6e1ccc> (a java.lang.Runtime)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at java.lang.Runtime.loadLibrary0(Runtime.java:975)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] - locked <0x0b6e1ccc> (a java.lang.Runtime)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at java.lang.System.loadLibrary(System.java:1567)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at net.teligen.term.SimTermJni.loadLibrary(SimTermJni.java:342)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at net.teligen.term.SimTermJni.(SimTermJni.java:36)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at net.teligen.term.SimTermJni.getInstance(SimTermJni.java:23)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at com.teligen.jmtxCommon.manager.DualLinkManager.getAvIp(DualLinkManager.java:43)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at com.teligen.jmtxCommon.manager.DualLinkManager.initIP(DualLinkManager.java:64)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] at com.teligen.jmtxCommon.global.LogLoader.getInstance(LogLoader.java:102)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470] - locked <0x0c709b15> (a java.lang.Class

分析

现象:

1.在主进程的其他地方触发调用是正常的,不会报错!
2.在remote进程的ContentProvider的onCreate里面去调用jni方法,就会出现这个错误
JNI DETECTED ERROR IN APPLICATION: java_object == null

我的分析

其他地方能正常调用,说明jni方法本身是没有问题的,调用失败我猜测可能有以下的问题:

1.代码被混淆
2.没有loadLibrary so
3.loadLibrary so有依赖的so没有load,或者顺序不对
4.loadLibrary比较慢

然后依次验证猜想,都被一一排除了!

java_object == null

在仔细看了一下报错,java_object应该是调用jni方法的传递到jni层的哪个对象,这个对象是由系统进行传参的,正常情况来说不会有问题,这里最大怀疑还是调用时机出现问题!

看到这个日志:

held mutexes= "mutator lock"(shared held)

01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470]   - locked <0x0b6e1ccc> 
(a java.lang.Runtime)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470]   at java.lang.Runtime.loadLibrary0(Runtime.java:975)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470]   - locked <0x0b6e1ccc> (a java.lang.Runtime)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc:470]   - locked <0x0c709b15> (a  java.lang.Class)
01-02 10:29:26.289 20617-20617/? A/art: art/runtime/java_vm_ext.cc

看到了locked <0x0c709b15>,locked <0x0b6e1ccc>,应该是有两个地方同时去加载so,或者同时去初始化单例,被锁住了!

解决

根据以上分析,可能是调用的顺序有点问题,于是我讲调用的地方延后就没有报错了!现在还是一脸懵逼!先在这里记录一下!
有知道原因的大神麻烦指导一下!

你可能感兴趣的:(JNI DETECTED ERROR IN APPLICATION: java_object == null)