本节讲述nuwa是如何创建一个新进程的。
在Firefox OS启动过程分析-nuwa进程启动中,我们了解到,当b2g进程创建nuwa进程时,在收到nuwa进程ready事件后,就会直接创建一个空壳进程。方便日后要启动的程序直接使用该空壳进程。
那么,如果该空壳进程已经被占用,又要启动新的程序,新的空壳进程是如何被系统创建的呢?
js::jit::DoCallFallback() (js/src/jit/BaselineIC.cpp)
|
|-js::Invoke() (js/src/vm/Interpreter.cpp)
|
|-js::RunScript()
|
|-Interpret()
|
|-js::Invoke()
|
|-CallJSNative() (js/src/jscntxtinlines.h)
|
|-mozilla::dom::GenericBindingMethod() (dom/bindings/BindingUtils.cpp)
|
|-mozilla::dom::NodeBinding::appendChild() (NodeBinding.cpp)
|
|-AppendChild() (dom/base/nsINode.h)
|
|-InsertBefore()
|
|-nsINode::ReplaceOrInsertBefore() (dom/base/nsINode.cpp)
|
|-mozAutoDocUpdate::~mozAutoDocUpdate() (dom/base/mozAutoDocUpdate.h)
|
|-nsHTMLDocument::EndUpdate() (dom/html/nsHTMLDocument.cpp)
|
|-nsDocument::EndUpdate() (dom/base/nsDocument.cpp)
|
|-nsDocument::MaybeInitializeFinalizeFrameLoaders()
|
|-MaybeInitializeFinalizeFrameLoaders ()
|
|-nsFrameLoader::ReallyStartLoading() (dom/base/nsFrameLoader.cpp)
|
|-nsFrameLoader::ReallyStartLoadingInternal()
|
|-nsFrameLoader::TryRemoteBrowser() (dom/base/nsFrameLoader.cpp)
|
|-mozilla::dom::ContentParent::CreateBrowserOrApp() (dom/ipc/ContentParent.cpp)
|
|-mozilla::dom::ContentParent::GetNewOrPreallocatedAppProcess()
|
|-mozilla::PreallocatedProcessManager::Take () (dom/ipc/PreallocatedProcessManager.cpp)
|
|-GetSpareProcess()
|
|-mozilla::dom::ContentParent::ForkNewProcess()
|
|-mozilla::dom::NuwaParent::ForkNewProcess() (dom/ipc/NuwaParent.cpp)
从代码上看,由于运行一个应用其实就是由b2g进程在system窗口中加载一个iframe,一步步调用到
ContentParent::CreateBrowserOrApp(),
在随后的:
ContentParent::GetNewOrPreallocatedAppProcess()
中,b2g进程会去PreallocatedProcessManager中获取下空壳进程,由于没有空壳进程(即mSpareProcesses为空),会调用
NuwaParent::ForkNewProcess
以便发送”SendFork”命令,去创建一个新的空壳进程。
PreallocatedProcessManager::Take()
|
|-GetSpareProcess()
|
|-ContentParent::ForkNewProcess()
|
|-NuwaParent::ForkNewProcess()
ContentParent::ForkNewProcess(aBlocking),
其中,aBlocking可以取false(不用等待空壳进程创建完毕)或true(需要等待空壳进程创建完毕)。
b2g进程需要保证当前系统中一直存在一个空壳进程。
该空壳进程的创建时机是
- 当nuwa进程ready时
- 当前有空壳进程,被占用后
- 当前无空壳进程,b2g阻塞模式创建一个空壳进程后
分析完b2g进程、nuwa进程以及空壳进程后,我们在下篇文章中再分析下Firefox OS是如何加载第一个程序的。