From 68a4e0a38fca00e9615a3c8ccb2d46edc88cf338 Mon Sep 17 00:00:00 2001 From: Vairavan Srinivasan Date: Mon, 14 Feb 2011 20:45:59 -0800 Subject: frameworks/base: acquire lock on am only when needed appendDropBoxProcessHeaders acquires a lock on am while accessing ProcessRecord (even if it is null). Watchdog thread ends up invoking this function (with a null ProcessRecord) to add the stack file to dropbox. This function would block if and when the watchdog thread is invoked due to unavailability of lock on am resulting in a deadlock. This would prevent watchdog from killing system_server. Change-Id: Ieb34b767779cb587e0c5f536b9b7ba44fb9a28d9 --- .../com/android/server/am/ActivityManagerService.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 2322ee1..92721fe 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -6730,18 +6730,25 @@ public final class ActivityManagerService extends ActivityManagerNative * to append various headers to the dropbox log text. */ private void appendDropBoxProcessHeaders(ProcessRecord process, StringBuilder sb) { + // Watchdog thread ends up invoking this function (with + // a null ProcessRecord) to add the stack file to dropbox. + // Do not acquire a lock on this (am) in such cases, as it + // could cause a potential deadlock, if and when watchdog + // is invoked due to unavailability of lock on am and it + // would prevent watchdog from killing system_server. + if (process == null) { + sb.append("Process: system_server\n"); + return; + } // Note: ProcessRecord 'process' is guarded by the service // instance. (notably process.pkgList, which could otherwise change // concurrently during execution of this method) synchronized (this) { - if (process == null || process.pid == MY_PID) { + if (process.pid == MY_PID) { sb.append("Process: system_server\n"); } else { sb.append("Process: ").append(process.processName).append("\n"); } - if (process == null) { - return; - } int flags = process.info.flags; IPackageManager pm = AppGlobals.getPackageManager(); sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n"); -- cgit v1.1