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)

从代码上看,由于运行一个应用其实就是由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是如何加载第一个程序的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值