Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android的BUG(四) - Android app的卡死問題

Android的BUG(四) - Android app的卡死問題

編輯:關於Android編程

運行一些apk造成應用卡死的問題

做android,免不了要去運行一些跑分程序,常用的跑分程序有quadrant(象限),nbench,安兔兔等。作為系統工程師,對這些跑分程序都非常的不屑,這個只能是一個不客觀的參考,但客戶都喜歡拿這個比較,於是乎,各家各廠都或多或少會針對此做優化(甚至是作弊或直接的作假),這可不是什麼好現象,浮誇的厲害,到處放衛星,畝產萬斤的。國內大家常用的跑分程序,就是安兔兔了,但是不知道大家有沒有發現,安兔兔跑起來後,有時會卡住不動,除了返回鍵和觸摸操作都沒什麼用。

出現這一問題時,home鍵可以退出,繼續運行其他應用,說明系統此時還是正常的。Top,vmstat看一下,也沒有高CPU/IO占用率的進程,ps –t看一下,也沒發現D狀態的線程。不過,<span style="ps –t倒是發現了一個現象:

app_47    9691  8787  610076 28768 ffffffff 2aac4424 S com.antutu.ABenchMark
app_47    9706  9691  609060 24476 80061b00 2aac5434 S com.antutu.ABenchMark
出現了同名的進程!這很奇怪~
看這兩個進程的父進程, 一個是zygote, 另外一個,則是com.antutu.ABenchMark自己。由此大約可以推斷出來,後一個進程是前一個進程fork出來的,fork後還沒來得及exec就卡住了。

接上adb,看下兩個進程的狀態吧:

Process: 9691
(gdb) bt
#0  read () at bionic/libc/arch-mips/syscalls/read.S:13
#1  0x2ad6d7d0 in executeProcess (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
    errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:165
#2  ProcessManager_exec (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
    errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:240
#3  0x2b8cccc4 in call_it () at external/libffi/src/mips/o32.S:145
#4  0x0026eb78 in ?? ()
沒什麼特別的,確實是卡在process的fork中。

再看看process 9706

(gdb) info thread
* 1 Thread 9706  __futex_syscall4 () at bionic/libc/arch-mips/bionic/atomics_mips.S:218
(gdb) bt
#0  __futex_syscall4 () at bionic/libc/arch-mips/bionic/atomics_mips.S:218
#1  0x2aabc288 in _normal_lock (mutex=0x2ab2142c) at bionic/libc/bionic/pthread.c:951
#2  pthread_mutex_lock (mutex=0x2ab2142c) at bionic/libc/bionic/pthread.c:1041
#3  0x2aabf848 in dlmalloc (bytes=4096) at bionic/libc/bionic/dlmalloc.c:4261
#4  0x2aace004 in __smakebuf (fp=0x2ab21598) at bionic/libc/stdio/makebuf.c:62
#5  0x2aad4658 in __swsetup (fp=0x2ab21598) at bionic/libc/stdio/wsetup.c:73
#6  0x2aace6a0 in putc_unlocked (c=48, fp=<value optimized out>) at bionic/libc/stdio/putc.c:46
#7  0x2aace744 in putc (c=48, fp=0x2ab21598) at bionic/libc/stdio/putc.c:64
#8  0x2aae44c0 in cpuacct_add (uid=<value optimized out>) at bionic/libc/bionic/cpuacct.c:55
#9  0x2aae57b0 in fork () at bionic/libc/bionic/fork.c:57
#10 0x2ad6d764 in executeProcess (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
    errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:92
#11 ProcessManager_exec (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
    errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:240
#12 0x2b8cccc4 in call_it () at external/libffi/src/mips/o32.S:145
#13 0x0026eb78 in ?? ()
(gdb)
可以看到停在bionic的fork中了,具體函數是: cpuacct_add(getuid()); 中的fprintf。 錯誤原因從bt上看得到,又是鎖的問題。

這個問題找到原因後,解決方法倒是沒有花什麼精力,直接google一下,問題和解決方法都出來了:

https://code.google.com/p/android/issues/detail?id=19916
Comment 1 by [email protected], Nov 23, 2011
This issue has also been found on ICS.  cpuacct_add should not be doing anything that calls malloc() or free().  Proposed fixes are here:
http://review.omapzoom.org/16579
http://review.omapzoom.org/16573

現在越來越多的apk,會偷偷的fork進程,執行系統中的命令或dump調試信息,甚至如skype,會一下fork很多自己寫的native服務,看著總歸不是很爽
作者:freshui

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved