Android Zygote Startup

Here are some miscellaneous notes on Android startup of the zygote process.

This information is true for eclair, as of August 2010.

Sequence of startup steps
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server Usage: app_process [java-options] cmd-dir start-class-name [options] --setuid=1000 --setgid=1000 \ --setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,3001,3002,3003 --capabilities=130104352,130104352 \ --runtime-init --nice-name=system_server
 * init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote"
 * This is based on the line from init.rc:
 * app_process executes, and executes a runtime environment for a dalvik class
 * app_process usage claims to be:
 * but you can specify --zygote in place of the start-class-name.
 * In the bootup case, --zygote is used
 * source for 'app_process is in frameworks/base/cmds/app_process/app_main.cpp
 * this is the program to debug when debugging zygote/dalvik itself
 * app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)
 * the startSystemServer flag is passed as a parameter on to app_process, to indicate whether to start the system server (duh)
 * runtime is an instance of class AppRuntime, which is sub-classed from AndroidRuntime
 * AndroidRuntime is the main class for starting the dalvik runtime environment
 * source is in frameworks/base/core/jni/AndroidRuntime.cpp
 * the start method starts the virtual machine
 * LOG_BOOT_PROGRESS_START is emitted, with systemTime(SYSTEM_TIME_MONOTONIC)
 * startVM is called
 * eventually, callStaticVoidMethod is called, to actually start executing the start class with method "main" in Dalvik code
 * com.android.internal.os.ZygoteInit:main starts executing
 * source is at: frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
 * the profiler is started
 * the Zygote socket is registered (for later communication to start apps)
 * classes and resources are preloaded
 * if startSystemServer is set, then the system server is started
 * the command line to the system server is:
 * the class which starts executing is: com.android.server.SystemServer
 * a call is made to Zygote.forkSystemServer to actually start this other process
 * zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps
 * see runSelectLoopMode
 * new connections are accepted (and put into array "peers")
 * the spawn command received over the network is executed by calling the runOnce method
 * source code for this is at: frameworks/base/core/java/com/android/internal/os/ZygoteConnection.java
 * eventually, a call is made to Zygote.forkAndSpecialize, which does the actual forking