Question

I have a question involving the Android framework.

Every boot sequence shown on the Internet or in books shows the flow starting from zygote to dalvik as follows.

Android Boot Sequence Image

However, according to my code research, init processor runs app_process(app_main.cpp) before loading zygote like this :

[init.rc] : 

service zygote **/system/bin/app_process** -Xzygote /system/bin --zygote --start-system-server

Because zygote(ZygoteInit.java) is java file(a kind of class), it needs the dalvik virtual machine to be executed so app_process(app_main.cpp) initializes dalvik machine and makes it ready for start.

And then loads ZygoteInit.java via dalvik.

Thus, zygote actually run.

It seems to me that the process which initializes and loads dalvik is not zygote but app_process and zygote is under dalvik because it is composed of java code.

The only thing that makes me doubt this is some code in app_main.cpp.

Watching main function in app_main.cpp file, you can find some lines as below :

[app_main.cpp] :

       if (niceName && *niceName) {

            setArgv0(argv0, niceName);

            **set_process_name(niceName);**

       }

niceName is pointing to the string "zygote".

That means app_process is changed to zygote process using the set_process_name() function. If it is true, everything is OK. But I don't know what the fact is.

Anyone make me sure of what is first.

Try to browse android code in :

http://androidxref.com/4.4_r1/

Was it helpful?

Solution

Dalvik is shipped on Android as a loadable library. app_process links with that library, and uses it. As such app_process starts a Dalvik VM within its own process.

The Zygote is just a special case of this.

So, to more directly answer your question: During a typical start-up, the first Dalvik VM to run is one that is spawned within an app_process process, and it is passed arguments which cause it to become the Zygote process of the running system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top