当前位置:网站首页>三、zygote启动流程

三、zygote启动流程

2022-04-23 22:03:00 笑三少_Creat

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);

大爷,赏个铜板呗

 

版权声明
本文为[笑三少_Creat]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u011337503/article/details/124366488