当前位置:网站首页>3、 Zygote start process

3、 Zygote start process

2022-04-23 22:04:00 Laugh three little_ Creat

zygote By app_main.cpp Inside AppRuntime Object's start() After the method is started, the following things are done

find \frameworks\base\core\java\com\android\internal\os\ZygoteInit.java open main() The following code can be seen in the function

1、 establish ZygoteServer

 ZygoteServer zygoteServer = new ZygoteServer();

2、 Load classes ahead of time , Load system resources , Load other

// 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);// Preload core method 

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

preload() method code :

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

3、 start-up SystemServer

if (startSystemServer) {
     Runnable r = forkSystemServer(abiList, socketName, zygoteServer);
     if (r != null) {
         r.run();// Execute through reflection mechanism SystemServer.java Of main() function 
         return;
     }
}

4、 Loop to receive subprocess messages

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

Uncle , Give me a coin

 

版权声明
本文为[Laugh three little_ Creat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232202429762.html