Zygote (app_process) Correlation Analysis 2

Source: Internet
Author: User

The start-up process from init.c to Zygote (app_process) has been analyzed in the previous article.

Start analyzing frameworks/base/cmds/app_process/app_main.cpp today.

Service Zygote/system/bin/app_process-xzygote/system/bin--zygote--start-system-server

The above content will be used in the app_main.cpp.

/** The way to start zygote is/system/bin/app_process-xzygote/system/bin--zygote--start-system-server* so argc = 5* argv inside This is the 5 parameters argv[0]== "/system/bin/app_process", argv[1] = = "-xzygote" ....*/intMainintargcConst Char*Constargv[])    {    ...    Appruntime runtime; ... ..//This function returns 1, which means that only the-xzytote parameter is processed, and the so-called processing is actually adding this parameter to the moptions variable of the runtime object.     inti =runtime.addvmarguments (argc, argv); //Next arg is parent directory    if(I <argc) {Runtime.mparentdir= argv[i++]; }    //Next arg is startup classname or "--zygote"//Process command Line arguments       if(I <argc) {arg= argv[i++]; if(0= = strcmp ("--zygote", Arg)) {            BOOLStartsystemserver = (i < ARGC)?strcmp (Argv[i],"--start-system-server") ==0:false; SetArgv0 (Argv0,"zygote"); Set_process_name ("zygote"); Runtime.start ("Com.android.internal.os.ZygoteInit", Startsystemserver); } Else{set_process_name (argv0); Runtime.mclassname=Arg; //remainder of args get passed to startup class main ()RUNTIME.MARGC = argc-i; RUNTIME.MARGV= argv+i; LOGV ("APP process is starting with pid=%d, class=%s.\n", Getpid (), Runtime.getclassname ());        Runtime.start (); }    } Else{log_always_fatal ("App_process:no class name or--zygote supplied."); fprintf (stderr,"Error:no class name or--zygote supplied.\n");        App_usage (); return Ten;}


It can be seen from the code that the start function of the appruntime is called to complete the zygote start.

Appruntime inherited from Androidruntime Analysis: (Zygote into the Java world)

The AndroidRuntime.cpp start function is called.

In this function is the main action, relatively simple.

start ():

   Set the root directory "/system" STARTVM ()  1. Call JNI's virtual machine creation function.     2. Set the virtual machine's heapsize default to 16MB Startreg ()  1. Register the JNI function.  2. Call Com.android via JNI. Internal . Os.  The main function of the Zygoteinit class. Zygoteinit related  1. Find the main function of the Zygoteinit class (Java Class)  2. Enter the Java world by calling Callstaticvoidmethod () (Zygoteinit.java Main ())

Let's look at the code:

voidStartConst Char* ClassName,Const Char*options) {       //start the virtual machinejnienv*env; if(STARTVM (&AMP;MJAVAVM, &env)! =0) {              return; }       //registerJNI       if(Startreg (ENV) <0) {              return; }//the Main method for JNI calls to JavaJmethodid Startmeth = env->Getstaticmethodid (Startclass, "main", "([ljava/lang/string;) V"); //JNI call to find Zygoteinit classJclass Startclass= env->Findclass (className);
    run the main function of the Zygoteinit class
Env
-Callstaticvoidmethod (Startclass, Startmeth, Strarray);}

In the next section we continue to analyze the main function of the Com.android.internal.os.ZygoteInit class .

Zygote (app_process) Correlation Analysis 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.