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

Commit 82f91da7 authored by Mathieu Chartier's avatar Mathieu Chartier Committed by Android Git Automerger
Browse files

am ad4a285a: am ebac4d1b: Merge "Change conditionallyCheckInstanceCounts to...

am ad4a285a: am ebac4d1b: Merge "Change conditionallyCheckInstanceCounts to use countInstancesOfClasses"

* commit 'ad4a285a':
  Change conditionallyCheckInstanceCounts to use countInstancesOfClasses
parents 1d9a312c ad4a285a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -991,7 +991,7 @@ public final class ActivityThread {
            long nativeFree = Debug.getNativeHeapFreeSize() / 1024;

            Runtime runtime = Runtime.getRuntime();

            runtime.gc();  // Do GC since countInstancesOfClass counts unreachable objects.
            long dalvikMax = runtime.totalMemory() / 1024;
            long dalvikFree = runtime.freeMemory() / 1024;
            long dalvikAllocated = dalvikMax - dalvikFree;
+12 −9
Original line number Diff line number Diff line
@@ -1574,7 +1574,8 @@ public final class StrictMode {
     */
    public static void conditionallyCheckInstanceCounts() {
        VmPolicy policy = getVmPolicy();
        if (policy.classInstanceLimit.size() == 0) {
        int policySize = policy.classInstanceLimit.size();
        if (policySize == 0) {
            return;
        }

@@ -1583,17 +1584,19 @@ public final class StrictMode {
        System.gc();

        // Note: classInstanceLimit is immutable, so this is lock-free
        for (Map.Entry<Class, Integer> entry : policy.classInstanceLimit.entrySet()) {
            Class klass = entry.getKey();
            int limit = entry.getValue();
            long instances = VMDebug.countInstancesOfClass(klass, false);
            if (instances <= limit) {
                continue;
            }
        // Create the classes array.
        Class[] classes = policy.classInstanceLimit.keySet().toArray(new Class[policySize]);
        long[] instanceCounts = VMDebug.countInstancesOfClasses(classes, false);
        for (int i = 0; i < classes.length; ++i) {
            Class klass = classes[i];
            int limit = policy.classInstanceLimit.get(klass);
            long instances = instanceCounts[i];
            if (instances > limit) {
                Throwable tr = new InstanceCountViolation(klass, instances, limit);
                onVmPolicyViolation(tr.getMessage(), tr);
            }
        }
    }

    private static long sLastInstanceCountCheckMillis = 0;
    private static boolean sIsIdlerRegistered = false;  // guarded by StrictMode.class