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

Commit 0a9ee1af authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Optionally trigger CG in onTrimMemory()

Set a trim-level threshold to debug.am.run_gc_trim_level to activate it.

Bug: 135148702
Test: Manual test with "setprop debug.am.run_gc_trim_level 0", run a lot of
heavy apps and take pictures, and check logcat for the "force_gc" event log.
Test: Manual test with "setprop debug.am.run_mallopt_trim_level 0", run a lot of
heavy apps and take pictures, and check logcat for a debug log.

Change-Id: I73b4dc7374e85e9a22c98ab17da53aa6cb25a188
parent ba3f191b
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -2080,7 +2080,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        @Override
        public final boolean queueIdle() {
            doGcIfNeeded();
            nPurgePendingResources();
            purgePendingResources();
            return false;
        }
    }
@@ -2088,9 +2088,7 @@ public final class ActivityThread extends ClientTransactionHandler {
    final class PurgeIdler implements MessageQueue.IdleHandler {
        @Override
        public boolean queueIdle() {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "purgePendingResources");
            nPurgePendingResources();
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            purgePendingResources();
            return false;
        }
    }
@@ -2460,13 +2458,17 @@ public final class ActivityThread extends ClientTransactionHandler {
    }

    void doGcIfNeeded() {
        doGcIfNeeded("bg");
    }

    void doGcIfNeeded(String reason) {
        mGcIdlerScheduled = false;
        final long now = SystemClock.uptimeMillis();
        //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
        //        + "m now=" + now);
        if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) {
            //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!");
            BinderInternal.forceGc("bg");
            BinderInternal.forceGc(reason);
        }
    }

@@ -6006,6 +6008,16 @@ public final class ActivityThread extends ClientTransactionHandler {

        WindowManagerGlobal.getInstance().trimMemory(level);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

        if (SystemProperties.getInt("debug.am.run_gc_trim_level", Integer.MAX_VALUE) <= level) {
            unscheduleGcIdler();
            doGcIfNeeded("tm");
        }
        if (SystemProperties.getInt("debug.am.run_mallopt_trim_level", Integer.MAX_VALUE)
                <= level) {
            unschedulePurgeIdler();
            purgePendingResources();
        }
    }

    private void setupGraphicsSupport(Context context) {
@@ -7346,6 +7358,12 @@ public final class ActivityThread extends ClientTransactionHandler {
        throw new RuntimeException("Main thread loop unexpectedly exited");
    }

    private void purgePendingResources() {
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "purgePendingResources");
        nPurgePendingResources();
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }

    // ------------------ Regular JNI ------------------------
    private native void nPurgePendingResources();
    private native void nDumpGraphicsInfo(FileDescriptor fd);