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

Commit 99761ed6 authored by Chih-Yu Huang's avatar Chih-Yu Huang
Browse files

am: Make maybeSetProcessFollowUpUpdateLocked use internal class

This CL makes the `OomAdjuster.maybeSetProcessFollowUpUpdateLocked()` to
operate directly on `ProcessRecordInternal`. To achieve that, it moves
`mKilled` field from `ProcessRecord` to `ProcessRecordInternal`.

Bug: 425766486
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT pure refactor
Change-Id: I734e23fd7fbf810a964a3c2d75b3905984a147b9
parent c854507c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ public abstract class OomAdjuster {
    protected final ActiveUids mTmpUidRecords;
    protected final ArrayDeque<ProcessRecordInternal> mTmpQueue;
    protected final ArraySet<ProcessRecordInternal> mTmpProcessSet = new ArraySet<>();
    protected final ArraySet<ProcessRecord> mPendingProcessSet = new ArraySet<>();
    protected final ArraySet<ProcessRecordInternal> mPendingProcessSet = new ArraySet<>();

    /**
     * List of processes that we want to batch for LMKD to adjust their respective
@@ -395,7 +395,7 @@ public abstract class OomAdjuster {
    protected int mProcessStateCurTop = PROCESS_STATE_TOP;

    @GuardedBy("mService")
    private final ArraySet<ProcessRecord> mFollowUpUpdateSet = new ArraySet<>();
    private final ArraySet<ProcessRecordInternal> mFollowUpUpdateSet = new ArraySet<>();

    protected static final long NO_FOLLOW_UP_TIME = Long.MAX_VALUE;
    @GuardedBy("mService")
@@ -888,7 +888,7 @@ public abstract class OomAdjuster {
        long nextFollowUpUptimeMs = Long.MAX_VALUE;
        mNextFollowUpUpdateUptimeMs = NO_FOLLOW_UP_TIME;
        for (int i = mFollowUpUpdateSet.size() - 1; i >= 0; i--) {
            final ProcessRecord proc = mFollowUpUpdateSet.valueAtUnchecked(i);
            final ProcessRecordInternal proc = mFollowUpUpdateSet.valueAtUnchecked(i);
            final long followUpUptimeMs = proc.getFollowupUpdateUptimeMs();

            if (proc.isKilled()) {
@@ -2958,7 +2958,7 @@ public abstract class OomAdjuster {
    }

    @GuardedBy("mService")
    protected void maybeSetProcessFollowUpUpdateLocked(ProcessRecord proc,
    protected void maybeSetProcessFollowUpUpdateLocked(ProcessRecordInternal proc,
            long updateUptimeMs, long now) {
        if (updateUptimeMs <= now) {
            // Time sensitive period has already passed. No need to schedule a follow up.
+3 −2
Original line number Diff line number Diff line
@@ -837,7 +837,8 @@ public class OomAdjusterImpl extends OomAdjuster {
     * Perform a partial update on the target processes and their reachable processes.
     */
    @GuardedBy({"mService", "mProcLock"})
    private void partialUpdateLSP(@OomAdjReason int oomAdjReason, ArraySet<ProcessRecord> targets) {
    private void partialUpdateLSP(@OomAdjReason int oomAdjReason,
            ArraySet<ProcessRecordInternal> targets) {
        final ProcessRecord topApp = getTopProcess();
        final long now = mInjector.getUptimeMillis();
        final long nowElapsed = mInjector.getElapsedRealtimeMillis();
@@ -853,7 +854,7 @@ public class OomAdjusterImpl extends OomAdjuster {
        reachables.clear();

        for (int i = 0, size = targets.size(); i < size; i++) {
            final ProcessRecord target = targets.valueAtUnchecked(i);
            final ProcessRecordInternal target = targets.valueAtUnchecked(i);
            target.resetCachedInfo();
            target.setReachable(true);
            reachables.add(target);
+3 −19
Original line number Diff line number Diff line
@@ -284,12 +284,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilledByAm;

    /**
     * True once we know the process has been killed.
     */
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilled;

    /**
     * The timestamp in uptime when this process was killed.
     */
@@ -529,8 +523,8 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        pw.print(prefix); pw.print("startSeq="); pw.println(mStartSeq);
        pw.print(prefix); pw.print("mountMode="); pw.println(
                DebugUtils.valueToString(Zygote.class, "MOUNT_EXTERNAL_", mMountMode));
        if (mKilled || mKilledByAm || mWaitingToKill != null) {
            pw.print(prefix); pw.print("killed="); pw.print(mKilled);
        if (isKilled() || mKilledByAm || mWaitingToKill != null) {
            pw.print(prefix); pw.print("killed="); pw.print(isKilled());
            pw.print(" killedByAm="); pw.print(mKilledByAm);
            pw.print(" waitingToKill="); pw.println(mWaitingToKill);
        }
@@ -998,16 +992,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        mKilledByAm = killedByAm;
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
    boolean isKilled() {
        return mKilled;
    }

    @GuardedBy({"mService", "mProcLock"})
    void setKilled(boolean killed) {
        mKilled = killed;
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
    long getKillTime() {
        return mKillTime;
@@ -1344,7 +1328,7 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
            }
            if (!mPersistent) {
                synchronized (mProcLock) {
                    mKilled = true;
                    setKilled(true);
                    mKilledByAm = true;
                    mKillTime = SystemClock.uptimeMillis();
                }
+14 −0
Original line number Diff line number Diff line
@@ -261,6 +261,10 @@ public abstract class ProcessRecordInternal {
    // The ActivityManagerGlobalLock object, which can only be used as a lock object.
    private final Object mProcLock;

    /** True once we know the process has been killed. */
    @CompositeRWLock({"mService", "mProcLock"})
    private boolean mKilled;

    /**
     * Maximum OOM adjustment for this process.
     */
@@ -707,6 +711,16 @@ public abstract class ProcessRecordInternal {
        mLastStateTime = now;
    }

    @GuardedBy(anyOf = {"mServiceLock", "mProcLock"})
    public boolean isKilled() {
        return mKilled;
    }

    @GuardedBy({"mServiceLock", "mProcLock"})
    public void setKilled(boolean killed) {
        mKilled = killed;
    }

    @GuardedBy("mServiceLock")
    public void setMaxAdj(int maxAdj) {
        mMaxAdj = maxAdj;