三、zygote启动流程

三、zygote启动流程,第1张

zygote被app_main.cpp里面的AppRuntime对象的start()方法启动之后做了以下事情

找到\frameworks\base\core\java\com\android\internal\os\ZygoteInit.java打开main()函数在里面看到如下代码

1、创建ZygoteServer

 ZygoteServer zygoteServer = new ZygoteServer();

2、提前加载类,加载系统资源,加载其它

// In some configurations, we avoid preloading resources and classes eagerly.
// In such cases, we will preload things prior to our first fork.
if (!enableLazyPreload) {
   bootTimingsTraceLog.traceBegin("ZygotePreload");
   EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
   SystemClock.uptimeMillis());

   preload(bootTimingsTraceLog);//预加载核心方法

   EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
   SystemClock.uptimeMillis());
   bootTimingsTraceLog.traceEnd(); // ZygotePreload
}

preload()方法代码:

static void preload(TimingsTraceLog bootTimingsTraceLog) {
        preloadClasses();
        
        preloadResources();
        
        nativePreloadAppProcessHALs();
        
        preloadOpenGL();
        
        preloadSharedLibraries();
        preloadTextResources(); 
}

3、启动SystemServer

if (startSystemServer) {
     Runnable r = forkSystemServer(abiList, socketName, zygoteServer);
     if (r != null) {
         r.run();//通过反射机制执行SystemServer.java的main()函数
         return;
     }
}

4、循环接收子进程消息

// The select loop returns early in the child process after a fork and
// loops forever in the zygote.
caller = zygoteServer.runSelectLoop(abiList);

大爷,赏个铜板呗

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/724062.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存