Merge "LockAgent: Refactor violation data" am: afb660cb49

am: bea5f08d86

Change-Id: Ib5a20d8b8aa81260883f4631a00390a819211d09
This commit is contained in:
Andreas Gampe
2019-06-20 14:09:37 -07:00
committed by android-build-merger
2 changed files with 20 additions and 10 deletions

View File

@@ -66,7 +66,8 @@ public class LockHook {
static final StatLogger sStats = new StatLogger(new String[] { "on-thread", }); static final StatLogger sStats = new StatLogger(new String[] { "on-thread", });
private static final ConcurrentLinkedQueue<Object> sViolations = new ConcurrentLinkedQueue<>(); private static final ConcurrentLinkedQueue<Violation> sViolations =
new ConcurrentLinkedQueue<>();
private static final int MAX_VIOLATIONS = 50; private static final int MAX_VIOLATIONS = 50;
private static final LockChecker[] sCheckers; private static final LockChecker[] sCheckers;
@@ -101,8 +102,8 @@ public class LockHook {
} }
} }
static void wtf(String message) { static void wtf(Violation v) {
sHandler.wtf(message); sHandler.wtf(v);
} }
static void doCheckOnThisThread(boolean check) { static void doCheckOnThisThread(boolean check) {
@@ -151,10 +152,10 @@ public class LockHook {
super(looper); super(looper);
} }
public void wtf(String msg) { public void wtf(Violation v) {
sDoCheck.set(false); sDoCheck.set(false);
SomeArgs args = SomeArgs.obtain(); SomeArgs args = SomeArgs.obtain();
args.arg1 = msg; args.arg1 = v;
obtainMessage(MSG_WTF, args).sendToTarget(); obtainMessage(MSG_WTF, args).sendToTarget();
sDoCheck.set(true); sDoCheck.set(true);
} }
@@ -164,13 +165,18 @@ public class LockHook {
switch (msg.what) { switch (msg.what) {
case MSG_WTF: case MSG_WTF:
SomeArgs args = (SomeArgs) msg.obj; SomeArgs args = (SomeArgs) msg.obj;
Log.wtf(TAG, (String) args.arg1); handleViolation((Violation) args.arg1);
args.recycle(); args.recycle();
break; break;
} }
} }
} }
private static void handleViolation(Violation v) {
String msg = v.toString();
Log.wtf(TAG, msg);
}
/** /**
* Generates a hash for a given stacktrace of a {@link Throwable}. * Generates a hash for a given stacktrace of a {@link Throwable}.
*/ */
@@ -224,8 +230,10 @@ public class LockHook {
} }
} }
static void addViolation(Object o) { static void addViolation(Violation v) {
sViolations.offer(o); wtf(v);
sViolations.offer(v);
while (sViolations.size() > MAX_VIOLATIONS) { while (sViolations.size() > MAX_VIOLATIONS) {
sViolations.poll(); sViolations.poll();
} }
@@ -287,4 +295,7 @@ public class LockHook {
void dump(PrintWriter pw); void dump(PrintWriter pw);
} }
interface Violation {
}
} }

View File

@@ -220,7 +220,7 @@ class OnThreadLockChecker implements LockHook.LockChecker {
heldLocks.remove(index); heldLocks.remove(index);
} }
private static class Violation { private static class Violation implements LockHook.Violation {
int mSelfTid; int mSelfTid;
String mSelfName; String mSelfName;
Object mAlreadyHeld; Object mAlreadyHeld;
@@ -323,7 +323,6 @@ class OnThreadLockChecker implements LockHook.LockChecker {
if (LockHook.shouldDumpStacktrace(mStacktraceHasher.get(), mDumpedStacktraceHashes, if (LockHook.shouldDumpStacktrace(mStacktraceHasher.get(), mDumpedStacktraceHashes,
Boolean.TRUE, v.mStack, 0, to)) { Boolean.TRUE, v.mStack, 0, to)) {
mNumDetectedUnique.incrementAndGet(); mNumDetectedUnique.incrementAndGet();
LockHook.wtf(v.toString());
LockHook.addViolation(v); LockHook.addViolation(v);
} }
} }