Merge "Framework: Clean up RuntimeInit/ZygoteInit/WrapperInit"

This commit is contained in:
Treehugger Robot
2017-02-10 00:45:55 +00:00
committed by Gerrit Code Review
5 changed files with 77 additions and 64 deletions

View File

@@ -43,8 +43,8 @@ import org.apache.harmony.luni.internal.util.TimezoneGetter;
* @hide
*/
public class RuntimeInit {
private final static String TAG = "AndroidRuntime";
private final static boolean DEBUG = false;
final static String TAG = "AndroidRuntime";
final static boolean DEBUG = false;
/** true if commonInit() has been called */
private static boolean initialized;
@@ -53,7 +53,6 @@ public class RuntimeInit {
private static volatile boolean mCrashing = false;
private static final native void nativeZygoteInit();
private static final native void nativeFinishInit();
private static final native void nativeSetExitWithoutCleanup(boolean exitWithoutCleanup);
@@ -133,7 +132,7 @@ public class RuntimeInit {
}
}
private static final void commonInit() {
protected static final void commonInit() {
if (DEBUG) Slog.d(TAG, "Entered RuntimeInit!");
/*
@@ -287,50 +286,7 @@ public class RuntimeInit {
if (DEBUG) Slog.d(TAG, "Leaving RuntimeInit!");
}
/**
* The main function called when started through the zygote process. This
* could be unified with main(), if the native code in nativeFinishInit()
* were rationalized with Zygote startup.<p>
*
* Current recognized args:
* <ul>
* <li> <code> [--] &lt;start class name&gt; &lt;args&gt;
* </ul>
*
* @param targetSdkVersion target SDK version
* @param argv arg strings
*/
public static final void zygoteInit(int targetSdkVersion, String[] argv, ClassLoader classLoader)
throws Zygote.MethodAndArgsCaller {
if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from zygote");
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "RuntimeInit");
redirectLogStreams();
commonInit();
nativeZygoteInit();
applicationInit(targetSdkVersion, argv, classLoader);
}
/**
* The main function called when an application is started through a
* wrapper process.
*
* When the wrapper starts, the runtime starts {@link RuntimeInit#main}
* which calls {@link WrapperInit#main} which then calls this method.
* So we don't need to call commonInit() here.
*
* @param targetSdkVersion target SDK version
* @param argv arg strings
*/
public static void wrapperInit(int targetSdkVersion, String[] argv)
throws Zygote.MethodAndArgsCaller {
if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from wrapper");
applicationInit(targetSdkVersion, argv, null);
}
private static void applicationInit(int targetSdkVersion, String[] argv, ClassLoader classLoader)
protected static void applicationInit(int targetSdkVersion, String[] argv, ClassLoader classLoader)
throws Zygote.MethodAndArgsCaller {
// If the application calls System.exit(), terminate the process
// immediately without running any shutdown hooks. It is not possible to

View File

@@ -18,7 +18,7 @@ package com.android.internal.os;
import android.os.Process;
import android.util.Slog;
import com.android.internal.os.Zygote.MethodAndArgsCaller;
import dalvik.system.VMRuntime;
import java.io.DataOutputStream;
import java.io.FileDescriptor;
@@ -80,7 +80,7 @@ public class WrapperInit {
// Launch the application.
String[] runtimeArgs = new String[args.length - 2];
System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length);
RuntimeInit.wrapperInit(targetSdkVersion, runtimeArgs);
WrapperInit.wrapperInit(targetSdkVersion, runtimeArgs);
} catch (Zygote.MethodAndArgsCaller caller) {
caller.run();
}
@@ -121,4 +121,24 @@ public class WrapperInit {
Zygote.appendQuotedShellArgs(command, args);
Zygote.execShell(command.toString());
}
/**
* The main function called when an application is started through a
* wrapper process.
*
* When the wrapper starts, the runtime starts {@link RuntimeInit#main}
* which calls {@link main} which then calls this method.
* So we don't need to call commonInit() here.
*
* @param targetSdkVersion target SDK version
* @param argv arg strings
*/
private static void wrapperInit(int targetSdkVersion, String[] argv)
throws Zygote.MethodAndArgsCaller {
if (RuntimeInit.DEBUG) {
Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from wrapper");
}
RuntimeInit.applicationInit(targetSdkVersion, argv, null);
}
}

View File

@@ -783,7 +783,7 @@ class ZygoteConnection {
VMRuntime.getCurrentInstructionSet(),
pipeFd, parsedArgs.remainingArgs);
} else {
RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion,
ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion,
parsedArgs.remainingArgs, null /* classLoader */);
}
}

View File

@@ -44,10 +44,9 @@ import android.system.OsConstants;
import android.text.Hyphenator;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.webkit.WebViewFactory;
import android.widget.TextView;
import dalvik.system.DexFile;
import dalvik.system.PathClassLoader;
import dalvik.system.VMRuntime;
@@ -468,7 +467,7 @@ public class ZygoteInit {
/*
* Pass the remaining arguments to SystemServer.
*/
RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs, cl);
ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs, cl);
}
/* should never reach here */
@@ -751,4 +750,33 @@ public class ZygoteInit {
*/
private ZygoteInit() {
}
/**
* The main function called when started through the zygote process. This
* could be unified with main(), if the native code in nativeFinishInit()
* were rationalized with Zygote startup.<p>
*
* Current recognized args:
* <ul>
* <li> <code> [--] &lt;start class name&gt; &lt;args&gt;
* </ul>
*
* @param targetSdkVersion target SDK version
* @param argv arg strings
*/
public static final void zygoteInit(int targetSdkVersion, String[] argv,
ClassLoader classLoader) throws Zygote.MethodAndArgsCaller {
if (RuntimeInit.DEBUG) {
Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from zygote");
}
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ZygoteInit");
RuntimeInit.redirectLogStreams();
RuntimeInit.commonInit();
ZygoteInit.nativeZygoteInit();
RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
}
private static final native void nativeZygoteInit();
}

View File

@@ -219,7 +219,7 @@ static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jo
gCurRuntime->onStarted();
}
static void com_android_internal_os_RuntimeInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
{
gCurRuntime->onZygoteInit();
}
@@ -233,19 +233,27 @@ static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIE
/*
* JNI registration.
*/
static const JNINativeMethod gMethods[] = {
{ "nativeFinishInit", "()V",
(void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
{ "nativeZygoteInit", "()V",
(void*) com_android_internal_os_RuntimeInit_nativeZygoteInit },
{ "nativeSetExitWithoutCleanup", "(Z)V",
(void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
};
int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
{
const JNINativeMethod methods[] = {
{ "nativeFinishInit", "()V",
(void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
{ "nativeSetExitWithoutCleanup", "(Z)V",
(void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
};
return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
gMethods, NELEM(gMethods));
methods, NELEM(methods));
}
int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
{
const JNINativeMethod methods[] = {
{ "nativeZygoteInit", "()V",
(void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
};
return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
methods, NELEM(methods));
}
// ----------------------------------------------------------------------
@@ -1274,6 +1282,7 @@ static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env
static const RegJNIRec gRegJNI[] = {
REG_JNI(register_com_android_internal_os_RuntimeInit),
REG_JNI(register_com_android_internal_os_ZygoteInit),
REG_JNI(register_android_os_SystemClock),
REG_JNI(register_android_util_EventLog),
REG_JNI(register_android_util_Log),