Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zygote preloading vs boot.art loading

Boot images loading (boot.oat, boot.art)

When Android boots up, it loads some boot images which contain some frequently used classes. In particular boot.oat contains the code of the classes, and boot.art some pre-initialized heap. This speedups application launch, and saves some memory due to the paging mechanism. (More details here)

Zygote preloading

In ZygoteInit.java, there is a preload function. It preloads classes, resources, shared libraries, etc. preloadClasses in particular loads the classes found in: /system/etc/preloaded-classes. Which basically causes the static initializers of these classes run.

How they differ?

What is the difference between the two? Isn't the sole purpose of boot.art to avoid the explicit initialization that is done by zygotespreload`?

Shouldn't the zygote's preload run only for imageless bootup?

like image 757
Paschalis Avatar asked Oct 28 '25 13:10

Paschalis


1 Answers

What is the difference between the two? Isn't the sole purpose of boot.art to avoid the explicit initialization that is done by zygote's preload`?

boot.art is a oat file. It contains all the classes in BOOTCLASSLOADER. Oat is a special elf format. It's a necessary file in ART VM. It will be generated at first boot or integrated in the phone by manufacturer.

/system/etc/preloaded-classes is a file contains a list of classes that will be initialized in the zygote.

Shouldn't the zygote's preload run only for imageless bootup?

boot.art is not an image.

boot.art is a special oat file. It contains all the class definitions of jars (framework.jar etc.) in BOOTCLASSLOADER and is in the memory of every application. Android converts these jar files to oat file to support the ART VM. Loading boot.art will load all the class definitions in boot.art into the memory of the zygote process. The classes are not initialized by ClassLoader after loading into memory and they are usually initialized when first used.

Some classes in boot.art are used in almost every application so we can initialize them in zygote to avoid initializing them in every application. Preload will call the Class.forName method to initialize the classes in /system/etc/preloaded-classes. Class.forName initializes the static block in target class and does other initialization operations. The result of preload is actually memory change and the change remains in the forked processes. So preload will save class initialization time.

like image 68
ray Avatar answered Oct 31 '25 01:10

ray