diff options
author | Piotr Jastrzebski <haaawk@google.com> | 2015-03-31 08:53:33 +0100 |
---|---|---|
committer | Piotr Jastrzebski <haaawk@google.com> | 2015-04-09 08:42:03 +0100 |
commit | cea2c6317356b984290ff579d5cde6d2f03668ff (patch) | |
tree | 28885566f220d17a7d4e3e62d2b50eb642240ec6 /dalvik | |
parent | 562c8bf8a191fd2f3fa9364ed4c3017c1808f8b7 (diff) | |
download | libcore-cea2c6317356b984290ff579d5cde6d2f03668ff.zip libcore-cea2c6317356b984290ff579d5cde6d2f03668ff.tar.gz libcore-cea2c6317356b984290ff579d5cde6d2f03668ff.tar.bz2 |
Stop sleeping in waitUntilAllThreadsStopped spin instead.
We occasionally have to wait for threads to finish
but 10ms seems too long and is a significant part of
total time of Zygote fork (up to 15-20%).
It turns out that all Java threads are already stopped
but we're still waiting for their OS counterparts to finish.
This shouldn't take much time so we can just spin here.
In my experiments the spinning was never taking more than 1ms.
Change-Id: Ib63c0610a0786924060a644331dadaf97f65f0d5
Diffstat (limited to 'dalvik')
-rw-r--r-- | dalvik/src/main/java/dalvik/system/ZygoteHooks.java | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java index 59d8820..134c2f4 100644 --- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java +++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java @@ -70,13 +70,10 @@ public final class ZygoteHooks { */ private static void waitUntilAllThreadsStopped() { File tasks = new File("/proc/self/task"); + // All Java daemons are stopped already. We're just waiting for their OS counterparts to + // finish as well. This shouldn't take much time so spinning is ok here. while (tasks.list().length > 1) { - try { - // Experimentally, booting and playing about with a stingray, I never saw us - // go round this loop more than once with a 10ms sleep. - Thread.sleep(10); - } catch (InterruptedException ignored) { - } + Thread.yield(); } } } |