Merge "Revert "Zygote: Load system server code early"" into rvc-dev am: 98bf50a88e am: b614033835 am: cc1438f931
Change-Id: I24ecaf060319c5f4741d7531d4c73e814c776474
This commit is contained in:
@@ -125,12 +125,6 @@ public class ZygoteInit {
|
|||||||
|
|
||||||
private static boolean sPreloadComplete;
|
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) {
|
static void preload(TimingsTraceLog bootTimingsTraceLog) {
|
||||||
Log.d(TAG, "begin preload");
|
Log.d(TAG, "begin preload");
|
||||||
bootTimingsTraceLog.traceBegin("BeginPreload");
|
bootTimingsTraceLog.traceBegin("BeginPreload");
|
||||||
@@ -508,13 +502,7 @@ public class ZygoteInit {
|
|||||||
|
|
||||||
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
|
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
|
||||||
if (systemServerClasspath != null) {
|
if (systemServerClasspath != null) {
|
||||||
if (performSystemServerDexOpt(systemServerClasspath)) {
|
performSystemServerDexOpt(systemServerClasspath);
|
||||||
// Throw away the cached classloader. If we compiled here, the classloader would
|
|
||||||
// not have had AoT-ed artifacts.
|
|
||||||
// Note: This only works in a very special environment where selinux enforcement is
|
|
||||||
// disabled, e.g., Mac builds.
|
|
||||||
sCachedSystemServerClassLoader = null;
|
|
||||||
}
|
|
||||||
// Capturing profiles is only supported for debug or eng builds since selinux normally
|
// Capturing profiles is only supported for debug or eng builds since selinux normally
|
||||||
// prevents it.
|
// prevents it.
|
||||||
if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
|
if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
|
||||||
@@ -546,9 +534,10 @@ public class ZygoteInit {
|
|||||||
|
|
||||||
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
|
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
|
||||||
} else {
|
} else {
|
||||||
createSystemServerClassLoader();
|
ClassLoader cl = null;
|
||||||
ClassLoader cl = sCachedSystemServerClassLoader;
|
if (systemServerClasspath != null) {
|
||||||
if (cl != null) {
|
cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion);
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(cl);
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,24 +552,6 @@ public class ZygoteInit {
|
|||||||
/* should never reach here */
|
/* 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 void createSystemServerClassLoader() {
|
|
||||||
if (sCachedSystemServerClassLoader != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
|
|
||||||
// TODO: Should we run optimization here?
|
|
||||||
if (systemServerClasspath != null) {
|
|
||||||
sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath,
|
|
||||||
VMRuntime.SDK_VERSION_CUR_DEVELOPMENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note that preparing the profiles for system server does not require special selinux
|
* 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
|
* permissions. From the installer perspective the system server is a regular package which can
|
||||||
@@ -645,16 +616,15 @@ public class ZygoteInit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs dex-opt on the elements of {@code classPath}, if needed. We choose the instruction
|
* Performs dex-opt on the elements of {@code classPath}, if needed. We choose the instruction
|
||||||
* set of the current runtime. If something was compiled, return true.
|
* set of the current runtime.
|
||||||
*/
|
*/
|
||||||
private static boolean performSystemServerDexOpt(String classPath) {
|
private static void performSystemServerDexOpt(String classPath) {
|
||||||
final String[] classPathElements = classPath.split(":");
|
final String[] classPathElements = classPath.split(":");
|
||||||
final IInstalld installd = IInstalld.Stub
|
final IInstalld installd = IInstalld.Stub
|
||||||
.asInterface(ServiceManager.getService("installd"));
|
.asInterface(ServiceManager.getService("installd"));
|
||||||
final String instructionSet = VMRuntime.getRuntime().vmInstructionSet();
|
final String instructionSet = VMRuntime.getRuntime().vmInstructionSet();
|
||||||
|
|
||||||
String classPathForElement = "";
|
String classPathForElement = "";
|
||||||
boolean compiledSomething = false;
|
|
||||||
for (String classPathElement : classPathElements) {
|
for (String classPathElement : classPathElements) {
|
||||||
// We default to the verify filter because the compilation will happen on /data and
|
// We default to the verify filter because the compilation will happen on /data and
|
||||||
// system server cannot load executable code outside /system.
|
// system server cannot load executable code outside /system.
|
||||||
@@ -695,7 +665,6 @@ public class ZygoteInit {
|
|||||||
uuid, classLoaderContext, seInfo, false /* downgrade */,
|
uuid, classLoaderContext, seInfo, false /* downgrade */,
|
||||||
targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null,
|
targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null,
|
||||||
"server-dexopt");
|
"server-dexopt");
|
||||||
compiledSomething = true;
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
// Ignore (but log), we need this on the classpath for fallback mode.
|
// Ignore (but log), we need this on the classpath for fallback mode.
|
||||||
Log.w(TAG, "Failed compiling classpath element for system server: "
|
Log.w(TAG, "Failed compiling classpath element for system server: "
|
||||||
@@ -706,8 +675,6 @@ public class ZygoteInit {
|
|||||||
classPathForElement = encodeSystemServerClassPath(
|
classPathForElement = encodeSystemServerClassPath(
|
||||||
classPathForElement, classPathElement);
|
classPathForElement, classPathElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
return compiledSomething;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -121,16 +121,11 @@ typedef const std::function<void(std::string)>& fail_fn_t;
|
|||||||
static pid_t gSystemServerPid = 0;
|
static pid_t gSystemServerPid = 0;
|
||||||
|
|
||||||
static constexpr const char* kPropFuse = "persist.sys.fuse";
|
static constexpr const char* kPropFuse = "persist.sys.fuse";
|
||||||
static constexpr const char* kZygoteClassName = "com/android/internal/os/Zygote";
|
static const char kZygoteClassName[] = "com/android/internal/os/Zygote";
|
||||||
|
|
||||||
static jclass gZygoteClass;
|
static jclass gZygoteClass;
|
||||||
static jmethodID gCallPostForkSystemServerHooks;
|
static jmethodID gCallPostForkSystemServerHooks;
|
||||||
static jmethodID gCallPostForkChildHooks;
|
static jmethodID gCallPostForkChildHooks;
|
||||||
|
|
||||||
static constexpr const char* kZygoteInitClassName = "com/android/internal/os/ZygoteInit";
|
|
||||||
static jclass gZygoteInitClass;
|
|
||||||
static jmethodID gCreateSystemServerClassLoader;
|
|
||||||
|
|
||||||
static bool gIsSecurityEnforced = true;
|
static bool gIsSecurityEnforced = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1796,15 +1791,6 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
|
|||||||
fail_fn("Error calling post fork system server hooks.");
|
fail_fn("Error calling post fork system server hooks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefetch the classloader for the system server. This is done early to
|
|
||||||
// allow a tie-down of the proper system server selinux domain.
|
|
||||||
env->CallStaticVoidMethod(gZygoteInitClass, gCreateSystemServerClassLoader);
|
|
||||||
if (env->ExceptionCheck()) {
|
|
||||||
// Be robust here. The Java code will attempt to create the classloader
|
|
||||||
// at a later point (but may not have rights to use AoT artifacts).
|
|
||||||
env->ExceptionClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(oth): Remove hardcoded label here (b/117874058).
|
// TODO(oth): Remove hardcoded label here (b/117874058).
|
||||||
static const char* kSystemServerLabel = "u:r:system_server:s0";
|
static const char* kSystemServerLabel = "u:r:system_server:s0";
|
||||||
if (selinux_android_setcon(kSystemServerLabel) != 0) {
|
if (selinux_android_setcon(kSystemServerLabel) != 0) {
|
||||||
@@ -2482,13 +2468,6 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) {
|
|||||||
gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks",
|
gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks",
|
||||||
"(IZZLjava/lang/String;)V");
|
"(IZZLjava/lang/String;)V");
|
||||||
|
|
||||||
gZygoteInitClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteInitClassName));
|
return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
|
||||||
gCreateSystemServerClassLoader = GetStaticMethodIDOrDie(env, gZygoteInitClass,
|
|
||||||
"createSystemServerClassLoader",
|
|
||||||
"()V");
|
|
||||||
|
|
||||||
RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
|
|
||||||
|
|
||||||
return JNI_OK;
|
|
||||||
}
|
}
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
Reference in New Issue
Block a user