Lower daemons priority to 124 (libcore).
To avoid jank.
Bug: 36631902
Test: boot marlin oc-dev and check priorities.
Test: test-art-host
Change-Id: I345fb7cb9353de26d563d493ece596f5fd9417de
(cherry picked from commit dd102945c6912fbfe192b1ebe33600d846258826)
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
index b29b895..c96016f 100644
--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
+++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
@@ -69,7 +69,7 @@
* {@code postForkChild}.
*/
public void postForkCommon() {
- Daemons.start();
+ Daemons.startPostZygoteFork();
}
private static native long nativePreFork();
diff --git a/libart/src/main/java/dalvik/system/VMRuntime.java b/libart/src/main/java/dalvik/system/VMRuntime.java
index 6a673f2..d553846 100644
--- a/libart/src/main/java/dalvik/system/VMRuntime.java
+++ b/libart/src/main/java/dalvik/system/VMRuntime.java
@@ -421,4 +421,9 @@
* Should be called just once. Subsequent calls are ignored.
*/
public static native void registerSensitiveThread();
+
+ /**
+ * Sets up the priority of the system daemon thread (caller).
+ */
+ public static native void setSystemDaemonThreadPriority();
}
diff --git a/libart/src/main/java/java/lang/Daemons.java b/libart/src/main/java/java/lang/Daemons.java
index 15a8ab6..0e2cb45 100644
--- a/libart/src/main/java/java/lang/Daemons.java
+++ b/libart/src/main/java/java/lang/Daemons.java
@@ -46,6 +46,13 @@
HeapTaskDaemon.INSTANCE.start();
}
+ public static void startPostZygoteFork() {
+ ReferenceQueueDaemon.INSTANCE.startPostZygoteFork();
+ FinalizerDaemon.INSTANCE.startPostZygoteFork();
+ FinalizerWatchdogDaemon.INSTANCE.startPostZygoteFork();
+ HeapTaskDaemon.INSTANCE.startPostZygoteFork();
+ }
+
public static void stop() {
HeapTaskDaemon.INSTANCE.stop();
ReferenceQueueDaemon.INSTANCE.stop();
@@ -61,12 +68,22 @@
private static abstract class Daemon implements Runnable {
private Thread thread;
private String name;
+ private boolean postZygoteFork;
protected Daemon(String name) {
this.name = name;
}
public synchronized void start() {
+ startInternal();
+ }
+
+ public synchronized void startPostZygoteFork() {
+ postZygoteFork = true;
+ startInternal();
+ }
+
+ public void startInternal() {
if (thread != null) {
throw new IllegalStateException("already running");
}
@@ -75,7 +92,18 @@
thread.start();
}
- public abstract void run();
+ public void run() {
+ if (postZygoteFork) {
+ // We don't set the priority before the Thread.start() call above because
+ // Thread.start() will call SetNativePriority and overwrite the desired native
+ // priority. We (may) use a native priority that doesn't have a corresponding
+ // java.lang.Thread-level priority (native priorities are more coarse-grained.)
+ VMRuntime.getRuntime().setSystemDaemonThreadPriority();
+ }
+ runInternal();
+ }
+
+ public abstract void runInternal();
/**
* Returns true while the current thread should continue to run; false
@@ -141,7 +169,7 @@
super("ReferenceQueueDaemon");
}
- @Override public void run() {
+ @Override public void runInternal() {
while (isRunning()) {
Reference<?> list;
try {
@@ -173,7 +201,7 @@
super("FinalizerDaemon");
}
- @Override public void run() {
+ @Override public void runInternal() {
// This loop may be performance critical, since we need to keep up with mutator
// generation of finalizable objects.
// We minimize the amount of work we do per finalizable object. For example, we avoid
@@ -244,7 +272,7 @@
super("FinalizerWatchdogDaemon");
}
- @Override public void run() {
+ @Override public void runInternal() {
while (isRunning()) {
if (!sleepUntilNeeded()) {
// We have been interrupted, need to see if this daemon has been stopped.
@@ -419,7 +447,7 @@
VMRuntime.getRuntime().stopHeapTaskProcessor();
}
- @Override public void run() {
+ @Override public void runInternal() {
synchronized (this) {
if (isRunning()) {
// Needs to be synchronized or else we there is a race condition where we start