自从Android5.0,art称为默认的虚拟机模式。采用AOT(ahead of time)编译策略。

During an app’s installation, installd triggers dex2oat compiler to create app cache in OAT format. installd is the process in the device to receive commands from Android framework for apps’ installation.An OAT format file is named base.odex in a specific folder and only the app is able to access (except root privilege). This folder is the app’s sandbox folder. When an app starts next time, ART will load the app’s cache file into the memory of its own process rather than the reinstallation of the app’s APK file to reduce startup time and improve runtime performance. The cache file contains the app’s Dalvik bytecode for runtime interpretation or native code for direct execution.

In Android 7, an app’s compiling mode is decided by –compiler-filter option. Three compiling modes are introduced to save power, improve runtime performance, and reduce installation time that is mainly occupied by native code compilation on both Android 5 and 6. They are Ahead Of Time (AOT), Just In Time (JIT), and interpreter for Java runtime. AOT translates Dalvik bytecode into native code during an app’s installation by the on-device compiler dex2oat, while JIT is much more flexible to compile Dalvik bytecode at runtime.A compilation daemon is used to compile collected classes or methods in a profile file when the device is idle and charging [10]. The profile guided compilation will store frequently executed methods into an app’s image file (base.art), which avoids JIT compilation again [12, 15]. The interpreter interprets Dalvik byte code for execution without consuming time for compilation.

The cache file is a special Executable and Linkable Format (ELF) file with an OAT structure and stored in an app’s sandbox folder.For example, YouTube’s cache is /data/app/com.google.android.youtube-1/oat/arm64/base.odex created by dex2oat compiler. /data/app/com.google.android.youtube-1 is the app’s sandbox folder (the app’s data folder). base.odex is actually an OAT file with .odex extension. An image file base.art in the folder consists of compiled frequently used methods, which improves runtime class lookup performance.

If base.odex exists, ART will check the existence of base.art and update ClassTable to accelerate linking of methods when class linker looks up classes. ClassTable is a sophisticated structure to record already found classes into memory. Otherwise, ART reads DEX content from base.odex and uses DefineClass (a representation to find a class by traversing all included Android framework’s cache) which is slower than ClassTable searching to link classes in terms of runtime performance

results matching ""

    No results matching ""