public class LockGuard extends Object
synchronized (LockGuard.guard(lock)) { }
$ find services/ -name "*.java" -exec sed -i -r \ 's/synchronized.?\((.+?)\)/synchronized \(com.android.server.LockGuard.guard\(\1\)\)/' {} \;The
guard(Object)
method internally verifies that all locking is
done in a consistent order, and will log if any inversion is detected. For
example, if the calling thread is trying to acquire the
ActivityManager
lock while holding the PackageManager
lock,
it will yell.
This class requires no prior knowledge of locks or their ordering; it derives all of this data at runtime. However, this means the overhead is substantial and it should not be enabled by default. For example, here are some benchmarked timings:
Constructor and Description |
---|
LockGuard() |
Modifier and Type | Method and Description |
---|---|
static void |
dump(FileDescriptor fd,
PrintWriter pw,
String[] args) |
static Object |
guard(Object lock)
Check if the calling thread is holding any locks in an inverted order.
|
static void |
installLock(Object lock,
String label)
Report the given lock with a well-known label.
|
public static Object guard(Object lock)
lock
- The lock the calling thread is attempting to acquire.public static void installLock(Object lock, String label)
public static void dump(FileDescriptor fd, PrintWriter pw, String[] args)