Firefox OS启动过程分析-nuwa创建新进程
本节讲述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)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
从代码上看,由于运行一个应用其实就是由b2g进程在system窗口中加载一个iframe,一步步调用到
ContentParent::CreateBrowserOrApp(),
- 1
在随后的:
ContentParent::GetNewOrPreallocatedAppProcess()
- 1
中,b2g进程会去PreallocatedProcessManager中获取下空壳进程,由于没有空壳进程(即mSpareProcesses为空),会调用
NuwaParent::ForkNewProcess
- 1
以便发送”SendFork”命令,去创建一个新的空壳进程。
PreallocatedProcessManager::Take()
|
|-GetSpareProcess()
|
|-ContentParent::ForkNewProcess()
|
|-NuwaParent::ForkNewProcess()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
ContentParent::ForkNewProcess(aBlocking),
- 1
其中,aBlocking可以取false(不用等待空壳进程创建完毕)或true(需要等待空壳进程创建完毕)。
b2g进程需要保证当前系统中一直存在一个空壳进程。
该空壳进程的创建时机是
- 当nuwa进程ready时
- 当前有空壳进程,被占用后
- 当前无空壳进程,b2g阻塞模式创建一个空壳进程后
- 1
- 2
- 3
- 4
- 5
分析完b2g进程、nuwa进程以及空壳进程后,我们在下篇文章中再分析下Firefox OS是如何加载第一个程序的。