summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/os/ZygoteServer.java35
1 files changed, 24 insertions, 11 deletions
diff --git a/core/java/com/android/internal/os/ZygoteServer.java b/core/java/com/android/internal/os/ZygoteServer.java
index c898c0db6690..34ea28172cc7 100644
--- a/core/java/com/android/internal/os/ZygoteServer.java
+++ b/core/java/com/android/internal/os/ZygoteServer.java
@@ -143,6 +143,12 @@ class ZygoteServer {
*/
private int mUsapPoolRefillDelayMs = -1;
+ /**
+ * If and when we should refill the USAP pool.
+ */
+ private UsapPoolRefillAction mUsapPoolRefillAction;
+ private long mUsapPoolRefillTriggerTimestamp;
+
private enum UsapPoolRefillAction {
DELAYED,
IMMEDIATE,
@@ -375,6 +381,8 @@ class ZygoteServer {
// are re-enabled in specializeAppProcess.
ZygoteHooks.postForkCommon();
+ resetUsapRefillState();
+
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
return null;
@@ -404,6 +412,11 @@ class ZygoteServer {
}
}
+ void resetUsapRefillState() {
+ mUsapPoolRefillAction = UsapPoolRefillAction.NONE;
+ mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
+ }
+
/**
* Runs the zygote process's select loop. Accepts new connections as
* they happen, and reads commands from connections one spawn-request's
@@ -416,10 +429,11 @@ class ZygoteServer {
socketFDs.add(mZygoteSocket.getFileDescriptor());
peers.add(null);
- long usapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
+ mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
while (true) {
fetchUsapPoolPolicyPropsWithMinInterval();
+ mUsapPoolRefillAction = UsapPoolRefillAction.NONE;
int[] usapPipeFDs = null;
StructPollfd[] pollFDs;
@@ -473,11 +487,11 @@ class ZygoteServer {
int pollTimeoutMs;
- if (usapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
+ if (mUsapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
pollTimeoutMs = -1;
} else {
int elapsedTimeMs =
- (int) (System.currentTimeMillis() - usapPoolRefillTriggerTimestamp);
+ (int) (System.currentTimeMillis() - mUsapPoolRefillTriggerTimestamp);
if (elapsedTimeMs >= mUsapPoolRefillDelayMs) {
// Normalize the poll timeout value when the time between one poll event and the
@@ -496,13 +510,12 @@ class ZygoteServer {
throw new RuntimeException("poll failed", ex);
}
- UsapPoolRefillAction usapPoolRefillAction = UsapPoolRefillAction.NONE;
if (pollReturnValue == 0) {
// The poll timeout has been exceeded. This only occurs when we have finished the
// USAP pool refill delay period.
- usapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
- usapPoolRefillAction = UsapPoolRefillAction.DELAYED;
+ mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP;
+ mUsapPoolRefillAction = UsapPoolRefillAction.DELAYED;
} else {
boolean usapPoolFDRead = false;
@@ -632,15 +645,15 @@ class ZygoteServer {
if (usapPoolCount < mUsapPoolSizeMin) {
// Immediate refill
- usapPoolRefillAction = UsapPoolRefillAction.IMMEDIATE;
+ mUsapPoolRefillAction = UsapPoolRefillAction.IMMEDIATE;
} else if (mUsapPoolSizeMax - usapPoolCount >= mUsapPoolRefillThreshold) {
// Delayed refill
- usapPoolRefillTriggerTimestamp = System.currentTimeMillis();
+ mUsapPoolRefillTriggerTimestamp = System.currentTimeMillis();
}
}
}
- if (usapPoolRefillAction != UsapPoolRefillAction.NONE) {
+ if (mUsapPoolRefillAction != UsapPoolRefillAction.NONE) {
int[] sessionSocketRawFDs =
socketFDs.subList(1, socketFDs.size())
.stream()
@@ -648,7 +661,7 @@ class ZygoteServer {
.toArray();
final boolean isPriorityRefill =
- usapPoolRefillAction == UsapPoolRefillAction.IMMEDIATE;
+ mUsapPoolRefillAction == UsapPoolRefillAction.IMMEDIATE;
final Runnable command =
fillUsapPool(sessionSocketRawFDs, isPriorityRefill);
@@ -657,7 +670,7 @@ class ZygoteServer {
return command;
} else if (isPriorityRefill) {
// Schedule a delayed refill to finish refilling the pool.
- usapPoolRefillTriggerTimestamp = System.currentTimeMillis();
+ mUsapPoolRefillTriggerTimestamp = System.currentTimeMillis();
}
}
}