Merge "Revert^2 "Zygote: Load system server code early"" am: 8be0de5892 am: 387a79c188 am: 3d5d8f4f01 am: 2517eadc2f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1744478

Change-Id: Ib631ffab2bbbdf9a22bf06f5c253b2bb9ed0de8a
This commit is contained in:
Orion Hodson
2021-06-25 16:37:08 +00:00
committed by Automerger Merge Worker
2 changed files with 48 additions and 5 deletions

View File

@@ -127,6 +127,12 @@ public class ZygoteInit {
private static boolean sPreloadComplete;
/**
* Cached classloader to use for the system server. Will only be populated in the system
* server process.
*/
private static ClassLoader sCachedSystemServerClassLoader = null;
static void preload(TimingsTraceLog bootTimingsTraceLog) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
@@ -540,10 +546,8 @@ public class ZygoteInit {
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
} else {
ClassLoader cl = null;
if (systemServerClasspath != null) {
cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion);
ClassLoader cl = getOrCreateSystemServerClassLoader();
if (cl != null) {
Thread.currentThread().setContextClassLoader(cl);
}
@@ -558,6 +562,23 @@ public class ZygoteInit {
/* should never reach here */
}
/**
* Create the classloader for the system server and store it in
* {@link sCachedSystemServerClassLoader}. This function may be called through JNI in
* system server startup, when the runtime is in a critically low state. Do not do
* extended computation etc here.
*/
private static ClassLoader getOrCreateSystemServerClassLoader() {
if (sCachedSystemServerClassLoader == null) {
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
if (systemServerClasspath != null) {
sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath,
VMRuntime.SDK_VERSION_CUR_DEVELOPMENT);
}
}
return sCachedSystemServerClassLoader;
}
/**
* Note that preparing the profiles for system server does not require special selinux
* permissions. From the installer perspective the system server is a regular package which can