Android 8.0频现GC crash

问题现象

  • 复现步骤
    • 手机(Android 8.0, build id为opr6.170623.013)
    • 复现场景一: app crash
      • 选择一个大的txt文档,如:228k.txt
      • 用html方式打开
      • 打开后长按内容,点击全选,后点击分享到信息
      • 选择号码后等待
      • com.android.messaging进程几乎必现native crash
    • 复现场景二: system_server crash
      • 执行MSR压力测试
      • system_server高概率出现native crash

定位分析

  • 相关log
    • tombstone
      ABI: 'arm' 
      pid: 24785, tid: 24795, name: HeapTaskDaemon  >>> system_server <<<
      signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
      Abort message: 'utils.cc:123] 12c00000-52c00000 rw-p 00000000 00:05 3180718    /dev/ashmem/dalvik-main space (region space) (deleted)'
          r0 00000000  r1 000060db  r2 00000006  r3 00000008
          r4 000060d1  r5 000060db  r6 9bbc11d0  r7 0000010c
          r8 0000000b  r9 9bbc1231  sl 0000000a  fp 9bbc1230
          ip 00000000  sp 9bbc11c0  lr b4fee417  pc b501e97c  cpsr 200f0010
          d0  2e656d69746e7572  d1  3031306666646631
          d2  3135373066383036  d3  6f5f646c65696638
          d4  6636633537373864  d5  6636633535373839
          d6  6636633538373837  d7  363533613338317c
          d8  0000000000000000  d9  0000000000000000
          d10 0000000000000000  d11 0000000000000000
          d12 0000000000000000  d13 0000000000000000
          d14 0000000000000000  d15 0000000000000000
          d16 2e74736973726570  d17 2e6761742e676f6c
          d18 00000000c3394019  d19 000000005c000000
          d20 0000000000000000  d21 000000000000005c
          d22 0000000400000004  d23 0000000400000004
          d24 000022c1000002c1  d25 000062c1000042c1
          d26 000022c0000002c0  d27 000062c0000042c0
          d28 720410f8720410f0  d29 7204110872041100
          d30 0000001806897c20  d31 7204110872041100
          scr 20000013
      backtrace:
          #00 pc 0004a97c  /system/lib/libc.so (tgkill+12)
          #01 pc 0001a413  /system/lib/libc.so (abort+54)
          #02 pc 003385df  /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+230)
          #03 pc 00338c6f  /system/lib/libart.so (_ZN3art7Runtime7AborterEPKc+10)
          #04 pc 003efacd  /system/lib/libart.so (_ZN7android4base10LogMessageD1Ev+456)
          #05 pc 001c1c3f  /system/lib/libart.so (_ZNK3art2gc12Verification17LogHeapCorruptionENS_6ObjPtrINS_6mirror6ObjectEEENS_12MemberOffsetEPS4_b+926)
          #06 pc 001769fb  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying13MarkNonMovingEPNS_6mirror6ObjectES5_NS_12MemberOffsetE+290)
          #07 pc 00178097  /system/lib/libart.so (_ZN3art6mirror6Object15VisitReferencesILb1ELNS_17VerifyObjectFlagsE0ELNS_17ReadBarrierOptionE1ENS_2gc9collector17ConcurrentCopying16RefFieldsVisitorES8_EEvRKT2_RKT3_+218)
          #08 pc 00173537  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying19ProcessMarkStackRefEPNS_6mirror6ObjectE+98)
          #09 pc 00173077  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying20ProcessMarkStackOnceEv+402)
          #10 pc 00172ed7  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying16ProcessMarkStackEv+18)
          #11 pc 0016e695  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying12MarkingPhaseEv+456)
          #12 pc 0016dc75  /system/lib/libart.so (_ZN3art2gc9collector17ConcurrentCopying9RunPhasesEv+540)
          #13 pc 0017ccc5  /system/lib/libart.so (_ZN3art2gc9collector16GarbageCollector3RunENS0_7GcCauseEb+268)
          #14 pc 00197adf  /system/lib/libart.so (_ZN3art2gc4Heap22CollectGarbageInternalENS0_9collector6GcTypeENS0_7GcCauseEb+2726)
          #15 pc 001a2f2f  /system/lib/libart.so (_ZN3art2gc4Heap12ConcurrentGCEPNS_6ThreadENS0_7GcCauseEb+70)
          #16 pc 001a8949  /system/lib/libart.so (_ZN3art2gc4Heap16ConcurrentGCTask3RunEPNS_6ThreadE+20)
          #17 pc 001c147b  /system/lib/libart.so (_ZN3art2gc13TaskProcessor11RunAllTasksEPNS_6ThreadE+30)
          #18 pc 7049a4cb  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x9a3000)
      

初步分析

  • gdb 堆栈

    (gdb) bt
    #0  tgkill () at bionic/libc/arch-arm/syscalls/tgkill.S:10
    #1  0xb4fee416 in abort () at bionic/libc/bionic/abort.cpp:49
    #2  0xb206e5e2 in art::Runtime::Abort (msg=<optimized out>) at art/runtime/runtime.cc:523
    #3  0xb206ec72 in art::Runtime::Aborter (abort_message=0x979bd380 "GC tried to mark invalid reference 0x17\nref=0x17 <invalid address>\nholder=0x13780000 klass=0x6f353a18(java.lang.Class<java.lang.Object[]>) length=131069 space=main space (region space) 0x12c00000-0x52"...) at art/runtime/runtime.cc:2333
    #4  0xb2125ace in std::__1::function<void (char const*)>::operator()(char const*) const (this=<optimized out>, __arg=0x979bd380 "GC tried to mark invalid reference 0x17\nref=0x17 <invalid address>\nholder=0x13780000 klass=0x6f353a18(java.lang.Class<java.lang.Object[]>) length=131069 space=main space (region space) 0x12c00000-0x52"...) at external/libcxx/include/functional:1915
    #5  android::base::LogMessage::~LogMessage (this=0x9bbc1288) at system/core/base/logging.cpp:433
    #6  0xb1ef7c42 in art::gc::Verification::LogHeapCorruption (this=<optimized out>, holder=..., offset=..., ref=0x17, fatal=<optimized out>) at external/libcxx/include/new:235
    #7  0xb1eac9fe in art::gc::collector::ConcurrentCopying::MarkNonMoving (this=0xb22c3700, ref=0x17, holder=0x13780000, offset=...) at art/runtime/gc/collector/concurrent_copying.cc:2435
    #8  0xb1eae09a in art::gc::collector::ConcurrentCopying::RefFieldsVisitor::operator() (this=<optimized out>, obj=0x13780000, offset=...) at art/runtime/gc/collector/concurrent_copying.cc:1911
    #9  art::mirror::ObjectArray<art::mirror::Object>::VisitReferences<art::gc::collector::ConcurrentCopying::RefFieldsVisitor> (visitor=..., this=<optimized out>) at art/runtime/mirror/object_array-inl.h:373
    #10 art::mirror::Object::VisitReferences<true, (art::VerifyObjectFlags)0, (art::ReadBarrierOption)1, art::gc::collector::ConcurrentCopying::RefFieldsVisitor, art::gc::collector::ConcurrentCopying::RefFieldsVisitor> (this=0x13780000, visitor=..., ref_visitor=...) at art/runtime/mirror/object-refvisitor-inl.h:54
    #11 0xb1ea953a in art::gc::collector::ConcurrentCopying::Scan (to_ref=0x13780000, this=<optimized out>) at art/runtime/gc/collector/concurrent_copying.cc:1950
    #12 art::gc::collector::ConcurrentCopying::ProcessMarkStackRef (this=0xb22c3700, to_ref=0x13780000) at art/runtime/gc/collector/concurrent_copying.cc:1446
    #13 0xb1ea907a in art::gc::collector::ConcurrentCopying::ProcessMarkStackOnce (this=0xb22c3700) at art/runtime/gc/collector/concurrent_copying.cc:1347
    #14 0xb1ea8eda in art::gc::collector::ConcurrentCopying::ProcessMarkStack (this=0xb22c3700) at art/runtime/gc/collector/concurrent_copying.cc:1326
    #15 0xb1ea4696 in art::gc::collector::ConcurrentCopying::MarkingPhase (this=0xb22c3700) at art/runtime/gc/collector/concurrent_copying.cc:756
    #16 0xb1ea3c78 in art::gc::collector::ConcurrentCopying::RunPhases (this=0xb22c3700) at art/runtime/gc/collector/concurrent_copying.cc:169
    #17 0xb1eb2cc6 in art::gc::collector::GarbageCollector::Run (this=<optimized out>, gc_cause=art::gc::kGcCauseBackground, clear_soft_references=<optimized out>) at art/runtime/gc/collector/garbage_collector.cc:95
    #18 0xb1ecdae2 in art::gc::Heap::CollectGarbageInternal (this=0xb22fd400, gc_type=<optimized out>, gc_cause=art::gc::kGcCauseBackground, clear_soft_references=<optimized out>) at art/runtime/gc/heap.cc:2748
    #19 0xb1ed8f32 in art::gc::Heap::ConcurrentGC (this=0xb22fd400, self=<optimized out>, cause=art::gc::kGcCauseBackground, force_full=<optimized out>) at art/runtime/gc/heap.cc:3752
    #20 0xb1ede94c in art::gc::Heap::ConcurrentGCTask::Run (this=<optimized out>, self=0x60db) at art/runtime/gc/heap.cc:3713
    #21 0xb1ef747c in art::gc::TaskProcessor::RunAllTasks (this=0xb221eb80, self=0xaac57200) at art/runtime/gc/task_processor.cc:124
    #22 0x7049a4cc in ?? ()
    
  • log分析

    #3报出的abort_message完整log为
    (gdb) p (char *)0x979bd380 
    $1 = 0x979bd380 "GC tried to mark invalid reference 0x17\nref=0x17 <invalid address>\nholder=0x13780000 klass=0x6f353a18(java.lang.Class<java.lang.Object[]>) length=131069 space=main space (region space) 0x12c00000-0x52c00000 card=0 adjacent_ram=58775c6fd8775c6f98755c6f78785c6f|183a356f00000010fdff010008f07513field_offset=262168\n"
    
    
  • 查看当前obj=0x17

    (gdb) x /4xw 0x13780000+262168
    0x137c0018:   0x00000017  0x00300032  0x00200030  0x00200035
    

对比实验

  • Nexus 6p无法复现
  • 通过添加log, 发现没有走GC操作

深入分析

  • 查看obj相关的region[]

    ... ...
    $49 = {
      idx_ = 46,  
      begin_ = 0x13780000 "\030:5o", 
      top_ = {
      <std::__1::atomic<unsigned char*>> = {
        <std::__1::__atomic_base<unsigned char*, false>> = {
          __a_ = 0x137e0008 ""
        }, <No data fields>}, <No data fields>}, 
      end_ = 0x137c0000 "\260\207(o", 
      state_ = art::gc::space::RegionSpace::RegionState::kRegionStateLarge, 
      type_ = art::gc::space::RegionSpace::RegionType::kRegionTypeUnevacFromSpace, 
      objects_allocated_ = {
      <std::__1::atomic<unsigned int>> = {
        <std::__1::__atomic_base<unsigned int, true>> = {
          <std::__1::__atomic_base<unsigned int, false>> = {
            __a_ = 0
          }, <No data fields>}, <No data fields>}, <No data fields>}, 
      alloc_time_ = 13,  
      live_bytes_ = 0, 
      is_newly_allocated_ = false, 
      is_a_tlab_ = false, 
      thread_ = 0x0
    }
    
    $50 = {
      idx_ = 47,  
      begin_ = 0x137c0000 "\260\207(o", 
      top_ = {
      <std::__1::atomic<unsigned char*>> = {
        <std::__1::__atomic_base<unsigned char*, false>> = {
          __a_ = 0x137c4000 ""
        }, <No data fields>}, <No data fields>}, 
      end_ = 0x13800000 "\260\207(o", 
      state_ = art::gc::space::RegionSpace::RegionState::kRegionStateAllocated, 
      type_ = art::gc::space::RegionSpace::RegionType::kRegionTypeUnevacFromSpace, 
      objects_allocated_ = {
      <std::__1::atomic<unsigned int>> = {
        <std::__1::__atomic_base<unsigned int, true>> = {
          <std::__1::__atomic_base<unsigned int, false>> = {
            __a_ = 191
          }, <No data fields>}, <No data fields>}, <No data fields>},
      alloc_time_ = 14,
      live_bytes_ = 0,
      is_newly_allocated_ = true,
      is_a_tlab_ = false,
      thread_ = 0x0
    }
    ... ...
    

    可看到,

    • regions_[46]和regions_[47]原本是一个large object, regions_[46]的top_已指向regions_[47],
    • regions_[47]当前的状态为art::gc::space::RegionSpace::RegionState::kRegionStateAllocated, 表示已分配出去,理论上来讲应该是art::gc::space::RegionSpace::RegionState::kRegionStateLargeTail
    • regions_[46]的alloc_time是13, regions_[47]的alloc_time是14, 说明regions_[47]后续在使用过程中又被分配出去了.
  • 网络求助

  • Goolge ART求助

    向Google ART的Nicolas Geoffray发一封求助邮件,描述复现和分析详情,很快收到回复(12分钟).

    Nicolas说此问题已解决,并提供了解决方案的链接.

    Hi Tim,
    
    The change you're looking for is:
    https://android-review.googlesource.com/#/c/platform/art/+/430379/
    
    Thanks for your links. And sorry you got hit by the bug.
    

    同时,Nicolas又更新了https://issuetracker.google.com/issues/65268761

    ng...@google.com  <ng...@google.com>  #4 Sep 6, 2017 04:58PM
    
    The change in AOSP that fixed this is:
    https://android-review.googlesource.com/#/c/platform/art/+/430379/
    
    Unfortunately, it's not known yet when the fix will be available.
    

解决方案

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容