Loading core/java/com/android/internal/os/InstallerConnection.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.net.LocalSocketAddress; import android.os.SystemClock; import android.os.SystemClock; import android.util.Slog; import android.util.Slog; import com.android.internal.util.Preconditions; import libcore.io.IoUtils; import libcore.io.IoUtils; import libcore.io.Streams; import libcore.io.Streams; Loading @@ -42,11 +44,22 @@ public class InstallerConnection { private OutputStream mOut; private OutputStream mOut; private LocalSocket mSocket; private LocalSocket mSocket; private volatile Object mWarnIfHeld; private final byte buf[] = new byte[1024]; private final byte buf[] = new byte[1024]; public InstallerConnection() { public InstallerConnection() { } } /** * Yell loudly if someone tries making future calls while holding a lock on * the given object. */ public void setWarnIfHeld(Object warnIfHeld) { Preconditions.checkState(mWarnIfHeld == null); mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld); } public synchronized String transact(String cmd) { public synchronized String transact(String cmd) { if (!connect()) { if (!connect()) { Slog.e(TAG, "connection failed"); Slog.e(TAG, "connection failed"); Loading Loading @@ -84,6 +97,11 @@ public class InstallerConnection { } } public int execute(String cmd) { public int execute(String cmd) { if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); } String res = transact(cmd); String res = transact(cmd); try { try { return Integer.parseInt(res); return Integer.parseInt(res); Loading services/core/java/com/android/server/MountService.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1440,7 +1440,7 @@ class MountService extends IMountService.Stub mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, null); null); mConnector.setDebug(true); mConnector.setDebug(true); mConnector.setLockWarning(mLock); mConnector.setWarnIfHeld(mLock); Thread thread = new Thread(mConnector, VOLD_TAG); Thread thread = new Thread(mConnector, VOLD_TAG); thread.start(); thread.start(); Loading services/core/java/com/android/server/NativeDaemonConnector.java +10 −8 Original line number Original line Diff line number Diff line Loading @@ -25,10 +25,10 @@ import android.os.Message; import android.os.PowerManager; import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.util.LocalLog; import android.util.LocalLog; import android.util.Log; import android.util.Slog; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import com.google.android.collect.Lists; import com.google.android.collect.Lists; import java.io.FileDescriptor; import java.io.FileDescriptor; Loading Loading @@ -58,7 +58,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo private LocalLog mLocalLog; private LocalLog mLocalLog; private volatile boolean mDebug = false; private volatile boolean mDebug = false; private volatile Object mLockWarning; private volatile Object mWarnIfHeld; private final ResponseQueue mResponseQueue; private final ResponseQueue mResponseQueue; Loading Loading @@ -110,11 +110,12 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo } } /** /** * Yell loudly if someone tries making future {@link #execute(Command)} calls while holding a * Yell loudly if someone tries making future {@link #execute(Command)} * lock on the given object. * calls while holding a lock on the given object. */ */ public void setLockWarning(Object lockWarning) { public void setWarnIfHeld(Object warnIfHeld) { mLockWarning = lockWarning; Preconditions.checkState(mWarnIfHeld == null); mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld); } } @Override @Override Loading Loading @@ -404,8 +405,9 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo */ */ public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args) public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args) throws NativeDaemonConnectorException { throws NativeDaemonConnectorException { if (mLockWarning != null && Thread.holdsLock(mLockWarning)) { if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { Log.wtf(TAG, "Calling thread is holding lock " + mLockWarning, new Throwable()); Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); } } final long startTime = SystemClock.elapsedRealtime(); final long startTime = SystemClock.elapsedRealtime(); Loading services/core/java/com/android/server/pm/Installer.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,14 @@ public final class Installer extends SystemService { mInstaller = new InstallerConnection(); mInstaller = new InstallerConnection(); } } /** * Yell loudly if someone tries making future calls while holding a lock on * the given object. */ public void setWarnIfHeld(Object warnIfHeld) { mInstaller.setWarnIfHeld(warnIfHeld); } @Override @Override public void onStart() { public void onStart() { Slog.i(TAG, "Waiting for installd to be ready."); Slog.i(TAG, "Waiting for installd to be ready."); Loading services/core/java/com/android/server/pm/PackageManagerService.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -2391,6 +2391,11 @@ public class PackageManagerService extends IPackageManager.Stub { // tidy. // tidy. Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); // The initial scanning above does many calls into installd while // holding the mPackages lock, but we're mostly interested in yelling // once we have a booted system. mInstaller.setWarnIfHeld(mPackages); // Expose private service for system components to use. // Expose private service for system components to use. LocalServices.addService(PackageManagerInternal.class, new PackageManagerInternalImpl()); LocalServices.addService(PackageManagerInternal.class, new PackageManagerInternalImpl()); } } Loading Loading
core/java/com/android/internal/os/InstallerConnection.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.net.LocalSocketAddress; import android.os.SystemClock; import android.os.SystemClock; import android.util.Slog; import android.util.Slog; import com.android.internal.util.Preconditions; import libcore.io.IoUtils; import libcore.io.IoUtils; import libcore.io.Streams; import libcore.io.Streams; Loading @@ -42,11 +44,22 @@ public class InstallerConnection { private OutputStream mOut; private OutputStream mOut; private LocalSocket mSocket; private LocalSocket mSocket; private volatile Object mWarnIfHeld; private final byte buf[] = new byte[1024]; private final byte buf[] = new byte[1024]; public InstallerConnection() { public InstallerConnection() { } } /** * Yell loudly if someone tries making future calls while holding a lock on * the given object. */ public void setWarnIfHeld(Object warnIfHeld) { Preconditions.checkState(mWarnIfHeld == null); mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld); } public synchronized String transact(String cmd) { public synchronized String transact(String cmd) { if (!connect()) { if (!connect()) { Slog.e(TAG, "connection failed"); Slog.e(TAG, "connection failed"); Loading Loading @@ -84,6 +97,11 @@ public class InstallerConnection { } } public int execute(String cmd) { public int execute(String cmd) { if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); } String res = transact(cmd); String res = transact(cmd); try { try { return Integer.parseInt(res); return Integer.parseInt(res); Loading
services/core/java/com/android/server/MountService.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1440,7 +1440,7 @@ class MountService extends IMountService.Stub mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, null); null); mConnector.setDebug(true); mConnector.setDebug(true); mConnector.setLockWarning(mLock); mConnector.setWarnIfHeld(mLock); Thread thread = new Thread(mConnector, VOLD_TAG); Thread thread = new Thread(mConnector, VOLD_TAG); thread.start(); thread.start(); Loading
services/core/java/com/android/server/NativeDaemonConnector.java +10 −8 Original line number Original line Diff line number Diff line Loading @@ -25,10 +25,10 @@ import android.os.Message; import android.os.PowerManager; import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.util.LocalLog; import android.util.LocalLog; import android.util.Log; import android.util.Slog; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import com.google.android.collect.Lists; import com.google.android.collect.Lists; import java.io.FileDescriptor; import java.io.FileDescriptor; Loading Loading @@ -58,7 +58,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo private LocalLog mLocalLog; private LocalLog mLocalLog; private volatile boolean mDebug = false; private volatile boolean mDebug = false; private volatile Object mLockWarning; private volatile Object mWarnIfHeld; private final ResponseQueue mResponseQueue; private final ResponseQueue mResponseQueue; Loading Loading @@ -110,11 +110,12 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo } } /** /** * Yell loudly if someone tries making future {@link #execute(Command)} calls while holding a * Yell loudly if someone tries making future {@link #execute(Command)} * lock on the given object. * calls while holding a lock on the given object. */ */ public void setLockWarning(Object lockWarning) { public void setWarnIfHeld(Object warnIfHeld) { mLockWarning = lockWarning; Preconditions.checkState(mWarnIfHeld == null); mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld); } } @Override @Override Loading Loading @@ -404,8 +405,9 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo */ */ public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args) public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args) throws NativeDaemonConnectorException { throws NativeDaemonConnectorException { if (mLockWarning != null && Thread.holdsLock(mLockWarning)) { if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { Log.wtf(TAG, "Calling thread is holding lock " + mLockWarning, new Throwable()); Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); } } final long startTime = SystemClock.elapsedRealtime(); final long startTime = SystemClock.elapsedRealtime(); Loading
services/core/java/com/android/server/pm/Installer.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,14 @@ public final class Installer extends SystemService { mInstaller = new InstallerConnection(); mInstaller = new InstallerConnection(); } } /** * Yell loudly if someone tries making future calls while holding a lock on * the given object. */ public void setWarnIfHeld(Object warnIfHeld) { mInstaller.setWarnIfHeld(warnIfHeld); } @Override @Override public void onStart() { public void onStart() { Slog.i(TAG, "Waiting for installd to be ready."); Slog.i(TAG, "Waiting for installd to be ready."); Loading
services/core/java/com/android/server/pm/PackageManagerService.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -2391,6 +2391,11 @@ public class PackageManagerService extends IPackageManager.Stub { // tidy. // tidy. Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); // The initial scanning above does many calls into installd while // holding the mPackages lock, but we're mostly interested in yelling // once we have a booted system. mInstaller.setWarnIfHeld(mPackages); // Expose private service for system components to use. // Expose private service for system components to use. LocalServices.addService(PackageManagerInternal.class, new PackageManagerInternalImpl()); LocalServices.addService(PackageManagerInternal.class, new PackageManagerInternalImpl()); } } Loading