summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wessam Hassanein <wessam@google.com> 2023-03-09 01:56:04 +0000
committer Wessam Hassanein <wessam@google.com> 2023-03-10 07:56:43 +0000
commitb3b5a766bb0d35ceb0f10cefc15047bce1fd64cc (patch)
tree7e87f28d203e3107c151826f98f4a6c3daa5cccd
parentc44c31536526b21456993aa31506785a3619c09e (diff)
Improve Transition GC initiation by improving the Frameworks triggering
signal Transition GC should be initiated when the app status transitions into the cached state from a non-cached state. Test: Local testing Bug: 272381448 Change-Id: I483a3ddaa11ed037d32c5481999fd996e2e2629a
-rw-r--r--core/java/android/app/ActivityThread.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index e709a1ac2d36..30a2303a5e41 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3434,8 +3434,13 @@ public final class ActivityThread extends ClientTransactionHandler
if (mLastProcessState == processState) {
return;
}
+ // Do not issue a transitional GC if we are transitioning between 2 cached states.
+ // Only update if the state flips between cached and uncached or vice versa
+ if (ActivityManager.isProcStateCached(mLastProcessState)
+ != ActivityManager.isProcStateCached(processState)) {
+ updateVmProcessState(processState);
+ }
mLastProcessState = processState;
- updateVmProcessState(processState);
if (localLOGV) {
Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState
+ (fromIpc ? " (from ipc" : ""));
@@ -3444,12 +3449,16 @@ public final class ActivityThread extends ClientTransactionHandler
}
/** Update VM state based on ActivityManager.PROCESS_STATE_* constants. */
+ // Currently ART VM only uses state updates for Transitional GC, and thus
+ // this function initiates a Transitional GC for transitions into Cached apps states.
private void updateVmProcessState(int processState) {
- // TODO: Tune this since things like gmail sync are important background but not jank
- // perceptible.
- final int state = processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
- ? VM_PROCESS_STATE_JANK_PERCEPTIBLE
- : VM_PROCESS_STATE_JANK_IMPERCEPTIBLE;
+ // Only a transition into Cached state should result in a Transitional GC request
+ // to the ART runtime. Update VM state to JANK_IMPERCEPTIBLE in that case.
+ // Note that there are 4 possible cached states currently, all of which are
+ // JANK_IMPERCEPTIBLE from GC point of view.
+ final int state = ActivityManager.isProcStateCached(processState)
+ ? VM_PROCESS_STATE_JANK_IMPERCEPTIBLE
+ : VM_PROCESS_STATE_JANK_PERCEPTIBLE;
VMRuntime.getRuntime().updateProcessState(state);
}