1, art is faster than Dalvik, is because art is performing local machine instructions. , and Dalvik executes the Dex bytecode, which is performed through the interpreter. Although Dalvik also JIT-generates local machine instructions for frequently executed code, translating Dex bytecode into local machine instructions during application run can also affect the execution of the application itself, so even if Dalvik uses JIT, Also, to a certain extent, it is not as straightforward as running the local machine instructions.
zygote process is started by creating a Dalvik or art virtual machine from the interface shown in Figure 1, so it seems that art executes the local machine instruction, but it appears to be a no-compromise virtual machine. It is also because of this art is a virtual machine that executes local machine instructions. This conclusion seems a bit contradictory, since it is the implementation of local machine instructions, why is called a virtual machine? As you can see from the next article, art has a garbage collection mechanism in addition to the Java Virtual Machine interface, as well as a Java Core class library call.
mentioned above,art can load and run directly on the basis of not recompiling the APK,This is due to the fact that the APK was executed during installation of the AOT. The AOT (Ahead of time) is relative to JIT (Just in time). It isis to translate the Dex bytecode that it contains before the APK runs, and to get the corresponding local machine instructions so that it can be executed directly at run time.. This technique not only allows us to make any changes to the original APK, but also allows the apk to be translated only once during installation, and can be run countless times as a local machine instruction. This technique is similar to the way that we write a program in C + + language and then compile an executable program with GCC, and finally the executable can be loaded countless times into the execution of the system.
In art, the Dex bytecode that is packaged in the APK is translated into local machine instructions by LLVM. LLVM is a framework system for rapid development of its own compilers,
If we don't forget , in the Dalvik runtime, the APK is installed, The installation service Packagemanagerservice will invoke a tool through the daemon Installd dexopt to optimize the classes.dex that are packaged in the APK with Dex bytecode, and the optimized files are saved in/data/ The Dalvik-cache directory, and with a suffix of. Odex, indicates that this is an optimized Dex file. In the art runtime, when the APK is installed, the same installation service Packagemanagerservice will call another tool through the daemon Installd dex2oat to package in the APK contains Dex byte code into the translation. This translator is actually a compiler based on the LLVM architecture, and its frontend is a DEX parser. After the translation is an elf-formatted oat file, the oat file is also terminated with the. Odex suffix, and is also saved in the/data/dalvik-cache directory.
/span>
art operating principles are briefly introduced, summarized as follows:
1. The zygote process created during the Android system boot process utilizes the Java Virtual Machine interface exported by the art runtime to create an art virtual machine.
2. APK is installed, the Classes.dex file packaged in it will be translated into the local machine instruction by the tool dex2oat, and eventually get an elf-formatted oat file.
3. APK runtime, the above generated oat file will be loaded into memory, and the art virtual machine can be found through the inside of the Oatdata and Oatexec section of any one of the methods corresponding to the local machine instructions to execute.
Pick From: http://blog.csdn.net/luoshengyang/article/details/39256813
Android Art Introduction