anr DexFile分析

来源:互联网 发布:车饰用品大全淘宝 编辑:程序博客网 时间:2024/06/03 20:46


1、发生anr的时间:

08-01 02:09:50.606 1002 1029 I am_anr : [0,7607,ctrip.android.view,951598660,Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)]

2、call stack如下:

"main" prio=5 tid=1 Nativegroup="main" sCount=1 dsCount=0 obj=0x75b08268 self=0xf3085400sysTid=7607 nice=0 cgrp=default sched=0/0 handle=0xf65b9534state=S schedstat=( 591111702 23724771 381 ) utm=30 stm=28 core=7 HZ=100stack=0xff2ff000-0xff301000 stackSize=8MBheld mutexes=kernel: (couldn't read /proc/self/task/7607/stack)native: #00 pc 0004af28 /system/lib/libc.so (wait4+8)native: #01 pc 00350aad /system/lib/libart.so (ZN3art17ExecAndReturnCodeERNSt316vectorINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS5_IS7_EEEEPS7+500)native: #02 pc 00350df9 /system/lib/libart.so (ZN3art4ExecERNSt316vectorINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS5_IS7_EEEEPS7+20)native: #03 pc 002ce691 /system/lib/libart.so (ZN3art16OatFileAssistant7Dex2OatERKNSt316vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEEPS8+4536)native: #04 pc 002ca55b /system/lib/libart.so (ZN3art16OatFileAssistant15GenerateOatFileENS_14CompilerFilter6FilterEPNSt3_112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE+3218)native: #05 pc 002d0e6f /system/lib/libart.so (ZN3art14OatFileManager19OpenDexFilesFromOatEPKcS2_P8_jobjectP13_jobjectArrayPPKNS_7OatFileEPNSt3_16vectorINSB_12basic_stringIcNSB_11char_traitsIcEENSB_9allocatorIcEEEENSG_ISI_EEEE+306)native: #06 pc 002a3c63 /system/lib/libart.so (_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray+166)native: #07 pc 0015939f /system/framework/arm/boot-core-libart.oat (Java_dalvik_system_DexFile_openDexFileNative__Ljava_lang_String_2Ljava_lang_String_2ILjava_lang_ClassLoader_2_3Ldalvik_system_DexPathList_00024Element_2+178)at dalvik.system.DexFile.openDexFileNative(Native method)at dalvik.system.DexFile.openDexFile(DexFile.java:373)at dalvik.system.DexFile.<init>(DexFile.java:150)at dalvik.system.DexFile.loadDex(DexFile.java:221)at dalvik.system.DexPathList.loadDexFile(DexPathList.java:362)at dalvik.system.DexPathList.makeElements(DexPathList.java:323)at dalvik.system.DexPathList.makePathElements(DexPathList.java:281)at java.lang.reflect.Method.invoke!(Native method)at ctrip.android.bundle.a.a$c.a(SourceFile:-1)at ctrip.android.bundle.a.a$c.b(SourceFile:-1)at ctrip.android.bundle.a.a$c.a(SourceFile:-1)at ctrip.android.bundle.a.a.a(SourceFile:-1)at ctrip.android.bundle.framework.a.c.f(SourceFile:-1)at ctrip.android.bundle.framework.a.b.d(SourceFile:-1)at ctrip.android.bundle.framework.b.d(SourceFile:-1)locked <0x0ec3f838> (a ctrip.android.bundle.framework.b)at ctrip.android.bundle.framework.BundleCore.run(SourceFile:-1)at ctrip.base.component.CtripBaseApplication.a(SourceFile:-1)at ctrip.base.component.CtripBaseApplication.attachBaseContext(SourceFile:-1)at android.app.Application.attach(Application.java:189)at java.lang.reflect.Method.invoke!(Native method)at com.stub.StubApp.attachBaseContext(StubApplication.java:216)at android.app.Application.attach(Application.java:189)at android.app.Instrumentation.newApplication(Instrumentation.java:1008)at android.app.Instrumentation.newApplication(Instrumentation.java:992)at android.app.LoadedApk.makeApplication(LoadedApk.java:801)at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5481)at android.app.ActivityThread.-wrap2(ActivityThread.java:-1)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)at android.os.Handler.dispatchMessage(Handler.java:110)at android.os.Looper.loop(Looper.java:203)at android.app.ActivityThread.main(ActivityThread.java:6255)at java.lang.reflect.Method.invoke!(Native method)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1064)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)


###Android N的编译模式 在compiler_filter.h,我们可以看到dex2oat一共有12种编译模式:

  enum Filter {    kVerifyNone,          // Skip verification but mark all classes as verified anyway.    kVerifyAtRuntime,     // Delay verication to runtime, do not compile anything.    kVerifyProfile,       // Verify only the classes in the profile, compile only JNI stubs.    kInterpretOnly,       // Verify everything, compile only JNI stubs.    kTime,                // Compile methods, but minimize compilation time.    kSpaceProfile,        // Maximize space savings based on profile.    kSpace,               // Maximize space savings.    kBalanced,            // Good performance return on compilation investment.    kSpeedProfile,        // Maximize runtime performance based on profile.    kSpeed,               // Maximize runtime performance.    kEverythingProfile,   // Compile everything capable of being compiled based on profile.    kEverything,          // Compile everything capable of being compiled.  };

以上12种编译模式按照排列次序逐渐增强,系统默认采用的编译模式:(我们可以在在手机上执行getprop | grep pm查看)

pm.dexopt.ab-ota: [speed-profile]pm.dexopt.bg-dexopt: [speed-profile]pm.dexopt.boot: [verify-profile]pm.dexopt.core-app: [speed]pm.dexopt.first-boot: [interpret-only]pm.dexopt.forced-dexopt: [speed]pm.dexopt.install: [interpret-only]pm.dexopt.nsys-library: [speed]pm.dexopt.shared-apk: [speed]

kSpeedProfile, // Maximize runtime performance based on profile.
其含义是根据profile对于某一个app的热点代码采用speed模式加快其启动;
一般没有优化的话,基本上是 kInterpretOnly, // Verify everything, compile only JNI stubs
两者的区别后者是边解释边执行,前者是热点代码编译后生成可直接执行的目标代码,加快启动


规避方法参考:


code/art /dex2oat/dex2oat.cc

--- a/dex2oat/dex2oat.cc+++ b/dex2oat/dex2oat.cc@@ -858,7 +858,11 @@ class Dex2Oat FINAL {             << CommandLine();       }     }-+    //changed :whitelist +    if ((oat_location_.find("com.tencent.mm") != std::string::npos) || (oat_location_.find("com.tencent.mobileqq") != std::string::npos)){+      compiler_options_->compiler_filter_ = CompilerFilter::kSpeedProfile;+    }+    //end     // It they are not set, use default values for inlining settings.     // TODO: We should rethink the compiler filter. We mostly save     // time here, which is orthogonal to space.


更改没有风险,无非就是空间换时间而已。





原创粉丝点击