Study concluded the Android system in-depth understanding of zygote

In-depth understanding of zygote

  1. zygote is created by the init process according init.rc file configuration items.
  2. AppRuntime overloaded onStarted, onZygoteInit and onExit function
  3. Android Java to create a world system of Trilogy:
    A) Create a virtual machine --startVm
    b) registered JNI function --startReg
    main c) When calling Java through JNI function, pay attention to the function call, class belongs is com.android. internal.os.ZygoteInit, the parameter passed is "com.android.internal.os.ZygoteInittrue", after calling ZygoteInit the main function, zygote then entered the Java world.
  4. Step zygote creation of Java:
    A) create AppRuntime object and call its start. Since then the activity is controlled by the rules AppRuntime;
    b) call startVm create a Java virtual machine, and then call startReg to register JNI function;
    c) main function through JNI call com.android.internal.os.ZygoteInit class into the Java world, but nothing in this case;
    D) call registerZygoteSocket, by following the function in response to the request. Call preloadClasses and preloadResources by zygote.
    e) call startSystemServer split a child process to system_server for Java World Service;
    f) Zygote start-up work to complete the Java world, after calling runSelectLoopMode, then sleep.
  5. SystemServer call flow :
    A) ZygoteInit call startSystemServer, create system_server process;
    b) calling SS handleSystemServerProcess complete their mission;
    c) handleSystemServerProcess exception is thrown, the final call com.android.server.SystemServer main function;
    d) main function loads libandroid_server.so of init1 and call native functions;
    E) init1 function through JNI calls, init2 com.android.server.SystemServer function class. init2 function to create a thread, for various loading-Service;
    F) Binder added INIT1 final function communication system;
  6. Zygote process in response to the request :
    A) Zygote process calls runSelectLoopMode ();
    B) SystemServer message sending process;
    C) the fork () to create a subprocess;
    D) subroutine call android.app.ActivityThread main function;
Published 39 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_43443900/article/details/103238637