Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afb660cb authored by Andreas Gampe's avatar Andreas Gampe Committed by Gerrit Code Review
Browse files

Merge "LockAgent: Refactor violation data"

parents 2d24f7a3 f9425d46
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -66,7 +66,8 @@ public class LockHook {

    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 LockChecker[] sCheckers;
@@ -101,8 +102,8 @@ public class LockHook {
        }
    }

    static void wtf(String message) {
        sHandler.wtf(message);
    static void wtf(Violation v) {
        sHandler.wtf(v);
    }

    static void doCheckOnThisThread(boolean check) {
@@ -151,10 +152,10 @@ public class LockHook {
            super(looper);
        }

        public void wtf(String msg) {
        public void wtf(Violation v) {
            sDoCheck.set(false);
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = msg;
            args.arg1 = v;
            obtainMessage(MSG_WTF, args).sendToTarget();
            sDoCheck.set(true);
        }
@@ -164,13 +165,18 @@ public class LockHook {
            switch (msg.what) {
                case MSG_WTF:
                    SomeArgs args = (SomeArgs) msg.obj;
                    Log.wtf(TAG, (String) args.arg1);
                    handleViolation((Violation) args.arg1);
                    args.recycle();
                    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}.
     */
@@ -224,8 +230,10 @@ public class LockHook {
        }
    }

    static void addViolation(Object o) {
        sViolations.offer(o);
    static void addViolation(Violation v) {
        wtf(v);

        sViolations.offer(v);
        while (sViolations.size() > MAX_VIOLATIONS) {
            sViolations.poll();
        }
@@ -287,4 +295,7 @@ public class LockHook {

        void dump(PrintWriter pw);
    }

    interface Violation {
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ class OnThreadLockChecker implements LockHook.LockChecker {
        heldLocks.remove(index);
    }

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