Android Zygote Startup

Revision as of 12:09, 2 September 2010 by Tim Bird (Talk | contribs) (add bootup sequence notes)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

  • 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:
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
  • app_process executes, and executes a runtime environment for a dalvik class
    • app_process usage claims to be:
Usage: app_process [java-options] cmd-dir start-class-name [options]
    • 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("", 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
  • starts executing
    • source is at: frameworks/base/core/java/com/android/internal/os/
  • the profiler is started
  • the Zygote socket is registered (for later communication to start apps)
  • classes and resources are preloaded
  • 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/
  • eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking