diff options
| author | 2020-03-13 13:57:07 +0000 | |
|---|---|---|
| committer | 2020-03-13 13:57:07 +0000 | |
| commit | 8f2ce6f24a710d7fddccbbd1d5d23c0a94954d24 (patch) | |
| tree | b2a86853ed0ad5cb6df29b69f3dfc934930ce80e | |
| parent | 64737571b81c9745880b8ad38c963a6dfc14aa6b (diff) | |
| parent | 6be3b0e117903c6aa696f91829012e74df8a4581 (diff) | |
Merge "Revert "Zygote: Load system server code early""
| -rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 47 | ||||
| -rw-r--r-- | core/jni/com_android_internal_os_Zygote.cpp | 24 |
2 files changed, 9 insertions, 62 deletions
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 300f71af5dd5..021f48746889 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -122,12 +122,6 @@ 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"); @@ -499,13 +493,7 @@ public class ZygoteInit { final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH"); if (systemServerClasspath != null) { - if (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; - } + performSystemServerDexOpt(systemServerClasspath); // Capturing profiles is only supported for debug or eng builds since selinux normally // prevents it. if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) { @@ -537,9 +525,10 @@ public class ZygoteInit { throw new IllegalStateException("Unexpected return from WrapperInit.execApplication"); } else { - createSystemServerClassLoader(); - ClassLoader cl = sCachedSystemServerClassLoader; - if (cl != null) { + ClassLoader cl = null; + if (systemServerClasspath != null) { + cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion); + Thread.currentThread().setContextClassLoader(cl); } @@ -555,24 +544,6 @@ public class ZygoteInit { } /** - * 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 * permissions. From the installer perspective the system server is a regular package which can * capture profile information. @@ -636,16 +607,15 @@ public class ZygoteInit { /** * 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 IInstalld installd = IInstalld.Stub .asInterface(ServiceManager.getService("installd")); final String instructionSet = VMRuntime.getRuntime().vmInstructionSet(); String classPathForElement = ""; - boolean compiledSomething = false; for (String classPathElement : classPathElements) { // We default to the verify filter because the compilation will happen on /data and // system server cannot load executable code outside /system. @@ -686,7 +656,6 @@ public class ZygoteInit { uuid, classLoaderContext, seInfo, false /* downgrade */, targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null, "server-dexopt"); - compiledSomething = true; } catch (RemoteException | ServiceSpecificException e) { // Ignore (but log), we need this on the classpath for fallback mode. Log.w(TAG, "Failed compiling classpath element for system server: " @@ -697,8 +666,6 @@ public class ZygoteInit { classPathForElement = encodeSystemServerClassPath( classPathForElement, classPathElement); } - - return compiledSomething; } /** diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 0ce61de270f8..22f0478ce841 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -113,15 +113,11 @@ typedef const std::function<void(std::string)>& fail_fn_t; static pid_t gSystemServerPid = 0; -static constexpr const char* kZygoteClassName = "com/android/internal/os/Zygote"; +static const char kZygoteClassName[] = "com/android/internal/os/Zygote"; static jclass gZygoteClass; static jmethodID gCallPostForkSystemServerHooks; static jmethodID gCallPostForkChildHooks; -static constexpr const char* kZygoteInitClassName = "com/android/internal/os/ZygoteInit"; -static jclass gZygoteInitClass; -static jmethodID gCreateSystemServerClassLoader; - static bool gIsSecurityEnforced = true; /** @@ -1221,15 +1217,6 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, 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). static const char* kSystemServerLabel = "u:r:system_server:s0"; if (selinux_android_setcon(kSystemServerLabel) != 0) { @@ -1908,13 +1895,6 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) { gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks", "(IZZLjava/lang/String;)V"); - gZygoteInitClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteInitClassName)); - gCreateSystemServerClassLoader = GetStaticMethodIDOrDie(env, gZygoteInitClass, - "createSystemServerClassLoader", - "()V"); - - RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); - - return JNI_OK; + return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); } } // namespace android |