4

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?

Paschalis
  • 11,929
  • 9
  • 52
  • 82

3 Answers3

4

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.

ray
  • 41
  • 3
0

That's probably because /system/etc/preloaded-classes wasn't really part of boot.art. Android provides the flexibility to choose what goes into boot.art so that the image size can be kept small but which obviously will result into a few classes being loaded at run time during zygote initialization.

sanjivgupta
  • 396
  • 3
  • 12
0

Preloaded-classes file is simply a text file, it lists the class names to be loaded by Zygote. Zygote based on this list to load all the Android Java frameworks, it uses Classs.forName() to load the Java classes.
boot.art is the image file of the classes, so the actual classes are here. ART runtime just takes in charge of loading this file into process memory by memory mapping technology. There is no Java class loading here.

Weidian Huang
  • 2,787
  • 2
  • 20
  • 29