Merge "Framework: Clean up RuntimeInit/ZygoteInit/WrapperInit" am: 851afe56b8 am: 0e01cae667
am: 74acde1bc5
Change-Id: I40d67fcde4d9263d5c75d5c3f782a860dcff93f8
This commit is contained in:
@@ -43,8 +43,8 @@ import org.apache.harmony.luni.internal.util.TimezoneGetter;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class RuntimeInit {
|
public class RuntimeInit {
|
||||||
private final static String TAG = "AndroidRuntime";
|
final static String TAG = "AndroidRuntime";
|
||||||
private final static boolean DEBUG = false;
|
final static boolean DEBUG = false;
|
||||||
|
|
||||||
/** true if commonInit() has been called */
|
/** true if commonInit() has been called */
|
||||||
private static boolean initialized;
|
private static boolean initialized;
|
||||||
@@ -53,7 +53,6 @@ public class RuntimeInit {
|
|||||||
|
|
||||||
private static volatile boolean mCrashing = false;
|
private static volatile boolean mCrashing = false;
|
||||||
|
|
||||||
private static final native void nativeZygoteInit();
|
|
||||||
private static final native void nativeFinishInit();
|
private static final native void nativeFinishInit();
|
||||||
private static final native void nativeSetExitWithoutCleanup(boolean exitWithoutCleanup);
|
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!");
|
if (DEBUG) Slog.d(TAG, "Entered RuntimeInit!");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -287,50 +286,7 @@ public class RuntimeInit {
|
|||||||
if (DEBUG) Slog.d(TAG, "Leaving RuntimeInit!");
|
if (DEBUG) Slog.d(TAG, "Leaving RuntimeInit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected static void applicationInit(int targetSdkVersion, String[] argv, ClassLoader classLoader)
|
||||||
* 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> [--] <start class name> <args>
|
|
||||||
* </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)
|
|
||||||
throws Zygote.MethodAndArgsCaller {
|
throws Zygote.MethodAndArgsCaller {
|
||||||
// If the application calls System.exit(), terminate the process
|
// If the application calls System.exit(), terminate the process
|
||||||
// immediately without running any shutdown hooks. It is not possible to
|
// immediately without running any shutdown hooks. It is not possible to
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.android.internal.os;
|
|||||||
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
import com.android.internal.os.Zygote.MethodAndArgsCaller;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -80,7 +80,7 @@ public class WrapperInit {
|
|||||||
// Launch the application.
|
// Launch the application.
|
||||||
String[] runtimeArgs = new String[args.length - 2];
|
String[] runtimeArgs = new String[args.length - 2];
|
||||||
System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length);
|
System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length);
|
||||||
RuntimeInit.wrapperInit(targetSdkVersion, runtimeArgs);
|
WrapperInit.wrapperInit(targetSdkVersion, runtimeArgs);
|
||||||
} catch (Zygote.MethodAndArgsCaller caller) {
|
} catch (Zygote.MethodAndArgsCaller caller) {
|
||||||
caller.run();
|
caller.run();
|
||||||
}
|
}
|
||||||
@@ -121,4 +121,24 @@ public class WrapperInit {
|
|||||||
Zygote.appendQuotedShellArgs(command, args);
|
Zygote.appendQuotedShellArgs(command, args);
|
||||||
Zygote.execShell(command.toString());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -783,7 +783,7 @@ class ZygoteConnection {
|
|||||||
VMRuntime.getCurrentInstructionSet(),
|
VMRuntime.getCurrentInstructionSet(),
|
||||||
pipeFd, parsedArgs.remainingArgs);
|
pipeFd, parsedArgs.remainingArgs);
|
||||||
} else {
|
} else {
|
||||||
RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion,
|
ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion,
|
||||||
parsedArgs.remainingArgs, null /* classLoader */);
|
parsedArgs.remainingArgs, null /* classLoader */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,9 @@ import android.system.OsConstants;
|
|||||||
import android.text.Hyphenator;
|
import android.text.Hyphenator;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Slog;
|
||||||
import android.webkit.WebViewFactory;
|
import android.webkit.WebViewFactory;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
|
||||||
import dalvik.system.DexFile;
|
import dalvik.system.DexFile;
|
||||||
import dalvik.system.PathClassLoader;
|
import dalvik.system.PathClassLoader;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
@@ -458,7 +457,7 @@ public class ZygoteInit {
|
|||||||
/*
|
/*
|
||||||
* Pass the remaining arguments to SystemServer.
|
* Pass the remaining arguments to SystemServer.
|
||||||
*/
|
*/
|
||||||
RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs, cl);
|
ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs, cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* should never reach here */
|
/* should never reach here */
|
||||||
@@ -741,4 +740,33 @@ public class ZygoteInit {
|
|||||||
*/
|
*/
|
||||||
private 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> [--] <start class name> <args>
|
||||||
|
* </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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jo
|
|||||||
gCurRuntime->onStarted();
|
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();
|
gCurRuntime->onZygoteInit();
|
||||||
}
|
}
|
||||||
@@ -234,19 +234,27 @@ static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIE
|
|||||||
/*
|
/*
|
||||||
* JNI registration.
|
* 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)
|
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",
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
@@ -1275,6 +1283,7 @@ static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env
|
|||||||
|
|
||||||
static const RegJNIRec gRegJNI[] = {
|
static const RegJNIRec gRegJNI[] = {
|
||||||
REG_JNI(register_com_android_internal_os_RuntimeInit),
|
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_os_SystemClock),
|
||||||
REG_JNI(register_android_util_EventLog),
|
REG_JNI(register_android_util_EventLog),
|
||||||
REG_JNI(register_android_util_Log),
|
REG_JNI(register_android_util_Log),
|
||||||
|
|||||||
Reference in New Issue
Block a user