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

Commit 9abefed6 authored by Chih-Yu Huang's avatar Chih-Yu Huang
Browse files

am: Migrate updateAndTrimProcessLSP() to ProcessRecordInternal

This CL updates OomAdjuster's updateAndTrimProcessLSP to use
ProcessRecordInternal. To achieve this, some fields and
methods previously part of ProcessRecord are moved to the
ProcessRecordInternal abstract class.

Bug: 441412109
Test: m services.core
Test: atest MockingOomAdjusterTests OomAdjusterTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController
Flag: EXEMPT PURE_REFACTOR

Change-Id: I64ba65029621b34b16172b198d0585bd2e89b3e8
parent edcd7eaa
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -1120,18 +1120,17 @@ public abstract class OomAdjuster {
        int numEmpty = 0;
        int numTrimming = 0;

        boolean proactiveKillsEnabled = mConstants.PROACTIVE_KILLS_ENABLED;
        double lowSwapThresholdPercent = mConstants.LOW_SWAP_THRESHOLD_PERCENT;
        double freeSwapPercent =  proactiveKillsEnabled ? getFreeSwapPercent() : 1.00;
        ProcessRecord lruCachedApp = null;
        final boolean proactiveKillsEnabled = mConstants.PROACTIVE_KILLS_ENABLED;
        final double lowSwapThresholdPercent = mConstants.LOW_SWAP_THRESHOLD_PERCENT;
        final double freeSwapPercent = proactiveKillsEnabled ? getFreeSwapPercent() : 1.00;
        ProcessRecordInternal lruCachedApp = null;

        for (int i = numLru - 1; i >= 0; i--) {
            ProcessRecord app = lruList.get(i);
            final ProcessRecordInternal state = app;
            final ProcessRecordInternal app = lruList.get(i);
            if (!app.isKilledByAm() && app.isProcessRunning()) {
                if (!Flags.fixApplyOomadjOrder()) {
                    // We don't need to apply the update for the process which didn't get computed
                    if (state.getCompletedAdjSeq() == mAdjSeq) {
                    if (app.getCompletedAdjSeq() == mAdjSeq) {
                        applyOomAdjLSP(app, doingAll, now, nowElapsed, oomAdjReason, true);
                    }
                }
@@ -1144,23 +1143,23 @@ public abstract class OomAdjuster {
                    continue;
                }

                final ProcessServiceRecord psr = app.mServices;
                final ProcessServiceRecordInternal psr = app.getServices();
                // Count the number of process types.
                switch (state.getCurProcState()) {
                switch (app.getCurProcState()) {
                    case PROCESS_STATE_CACHED_ACTIVITY:
                    case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
                        mNumCachedHiddenProcs++;
                        numCached++;
                        final int connectionGroup = psr.getConnectionGroup();
                        if (connectionGroup != 0) {
                            if (lastCachedGroupUid == app.info.uid
                            if (lastCachedGroupUid == app.getApplicationUid()
                                    && lastCachedGroup == connectionGroup) {
                                // If this process is the next in the same group, we don't
                                // want it to count against our limit of the number of cached
                                // processes, so bump up the group count to account for it.
                                numCachedExtraGroup++;
                            } else {
                                lastCachedGroupUid = app.info.uid;
                                lastCachedGroupUid = app.getApplicationUid();
                                lastCachedGroup = connectionGroup;
                            }
                        } else {
@@ -1228,7 +1227,7 @@ public abstract class OomAdjuster {
                    updateAppUidRecLSP(app);
                }

                if (state.getCurProcState() >= ActivityManager.PROCESS_STATE_HOME
                if (app.getCurProcState() >= ActivityManager.PROCESS_STATE_HOME
                        && !app.isKilledByAm()) {
                    numTrimming++;
                }
@@ -1239,7 +1238,7 @@ public abstract class OomAdjuster {
            // We need to apply the update starting from the least recently used.
            // Otherwise, they won't be in the correct LRU order in LMKD.
            for (int i = 0; i < numLru; i++) {
                ProcessRecord app = lruList.get(i);
                final ProcessRecord app = lruList.get(i);
                // We don't need to apply the update for the process which didn't get computed
                if (!app.isKilledByAm() && app.isProcessRunning()
                        && app.getCompletedAdjSeq() == mAdjSeq) {
+3 −35
Original line number Diff line number Diff line
@@ -295,24 +295,12 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
    @GuardedBy("mProcLock")
    private boolean mWaitedForDebugger;

    /**
     * For managing the LRU list.
     */
    @CompositeRWLock({"mService", "mProcLock"})
    private long mLastActivityTime;

    /**
     * Set to true when process was launched with a wrapper attached.
     */
    @GuardedBy("mService")
    private boolean mUsingWrapper;

    /**
     * Class to run on start if this is a special isolated process.
     */
    @GuardedBy("mService")
    private String mIsolatedEntryPoint;

    /**
     * Arguments to pass to isolatedEntryPoint's main().
     */
@@ -485,7 +473,7 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        pw.print(prefix); pw.print("thread="); pw.println(mThread);
        pw.print(prefix); pw.print("pid="); pw.println(mPid);
        pw.print(prefix); pw.print("lastActivityTime=");
        TimeUtils.formatDuration(mLastActivityTime, nowUptime, pw);
        TimeUtils.formatDuration(getLastActivityTime(), nowUptime, pw);
        pw.print(prefix); pw.print("startUpTime=");
        TimeUtils.formatDuration(mStartUptime, nowUptime, pw);
        pw.print(prefix); pw.print("startElapsedTime=");
@@ -509,8 +497,8 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
            pw.print(" killedByAm="); pw.print(isKilledByAm());
            pw.print(" waitingToKill="); pw.println(getWaitingToKill());
        }
        if (mIsolatedEntryPoint != null || mIsolatedEntryPointArgs != null) {
            pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(mIsolatedEntryPoint);
        if (getIsolatedEntryPoint() != null || mIsolatedEntryPointArgs != null) {
            pw.print(prefix); pw.print("isolatedEntryPoint="); pw.println(getIsolatedEntryPoint());
            pw.print(prefix); pw.print("isolatedEntryPointArgs=");
            pw.println(Arrays.toString(mIsolatedEntryPointArgs));
        }
@@ -1034,16 +1022,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        mWaitedForDebugger = waitedForDebugger;
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
    long getLastActivityTime() {
        return mLastActivityTime;
    }

    @GuardedBy({"mService", "mProcLock"})
    void setLastActivityTime(long lastActivityTime) {
        mLastActivityTime = lastActivityTime;
    }

    @GuardedBy("mService")
    boolean isUsingWrapper() {
        return mUsingWrapper;
@@ -1055,16 +1033,6 @@ class ProcessRecord extends ProcessRecordInternal implements WindowProcessListen
        mWindowProcessController.setUsingWrapper(usingWrapper);
    }

    @GuardedBy("mService")
    String getIsolatedEntryPoint() {
        return mIsolatedEntryPoint;
    }

    @GuardedBy("mService")
    void setIsolatedEntryPoint(String isolatedEntryPoint) {
        mIsolatedEntryPoint = isolatedEntryPoint;
    }

    @GuardedBy("mService")
    String[] getIsolatedEntryPointArgs() {
        return mIsolatedEntryPointArgs;
+28 −0
Original line number Diff line number Diff line
@@ -836,10 +836,18 @@ public abstract class ProcessRecordInternal {
    @GuardedBy("mProcLock")
    private int mRenderThreadTid;

    /** Class to run on start if this is a special isolated process. */
    @GuardedBy("mServiceLock")
    private String mIsolatedEntryPoint;

    /** Process is waiting to be killed when in the bg, and reason. */
    @GuardedBy("mServiceLock")
    private String mWaitingToKill;

    /** For managing the LRU list. */
    @CompositeRWLock({"mServiceLock", "mProcLock"})
    private long mLastActivityTime;

    // TODO(b/425766486): Change to package-private after the OomAdjusterImpl class is moved to
    //                    the psc package.
    public final OomAdjusterImpl.ProcessRecordNode[] mLinkedNodes =
@@ -1819,6 +1827,16 @@ public abstract class ProcessRecordInternal {
        return mLastCachedTime;
    }

    @GuardedBy("mServiceLock")
    public String getIsolatedEntryPoint() {
        return mIsolatedEntryPoint;
    }

    @GuardedBy("mServiceLock")
    public void setIsolatedEntryPoint(String isolatedEntryPoint) {
        mIsolatedEntryPoint = isolatedEntryPoint;
    }

    @GuardedBy("mServiceLock")
    public String getWaitingToKill() {
        return mWaitingToKill;
@@ -1829,6 +1847,16 @@ public abstract class ProcessRecordInternal {
        mWaitingToKill = waitingToKill;
    }

    @GuardedBy(anyOf = {"mServiceLock", "mProcLock"})
    public long getLastActivityTime() {
        return mLastActivityTime;
    }

    @GuardedBy({"mServiceLock", "mProcLock"})
    public void setLastActivityTime(long lastActivityTime) {
        mLastActivityTime = lastActivityTime;
    }

    @GuardedBy("mProcLock")
    public int getRenderThreadTid() {
        return mRenderThreadTid;