From c917f74d9235feefd1788a7b9ba34ed8f1215850 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 20 Apr 2015 19:16:37 -0700 Subject: [PATCH] Frameworks/base: Use better Class.forName in ZygoteInit Use the three-argument version of Class.forName. This saves an expensive stack lookup for the caller's class-loader on each invocation. Bug: 19498458 Change-Id: I859affde31e580fd2de3f70ee0a9295936c2d9f4 --- core/java/com/android/internal/os/ZygoteInit.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 50ddbd16ba392..da53995868e4e 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -267,7 +267,12 @@ public class ZygoteInit { if (false) { Log.v(TAG, "Preloading " + line + "..."); } - Class.forName(line); + // Load and explicitly initialize the given class. Use the tree-argument version + // of forName to avoid repeated stack lookups (to derive the caller's + // class-loader). Use true to force initialization, and null for the boot + // classpath class-loader (could as well cache the class-loader of this class in + // a variable). + Class.forName(line, true, null); count++; } catch (ClassNotFoundException e) { Log.w(TAG, "Class not found for preloading: " + line);