Since the new ART runtime is compiling the apps AOT, I was wondering whether running an app still includes a virtual machine, or the code is executed directly on the system. I haven't been able to extract this information from articles around the web as some mention a virtual machine, where other talks about the apps being compiled to ELF files (to my knowledge, the binary format used by the Linux kernel suggesting that the apps are run natively).
Can anyone help me out on this?
BPou
1 Answer
Short story: yes, ART translates apps to code native to the actual phone's architecture and therefore apps execute natively without the need of a JIT compiler.
Long story: For reasons of compatibility, applications are still bundled in apks carrying the java code compiled into dex files. But instead of just optimizing the .dex code and executing it inside Dalvik VM (DVM), the code is compiled down to native code. This is done on the device using a tool called dex2oat, where oat files are embedded within the regular ELF file format.
The following figure depicts the difference between the usage of DVM and ART:
(Wikipedia: Diagram of the Android Run Time architecture, recreated from information published at A Closer Look at Android RunTime (ART) in Android L.)
The performance improvement comes from the fact that the DVM used JIT compilation each and every time an app is executed, while AOT compilation only happens at install time.
-
1But the compiled ELF file is not a standalone executable binary but a shared object. It's still loaded in memory along with other dependencies by the same
app_process
which startszygote
and forks VMs forsystem_server
and all apps. Mar 5, 2020 at 17:15 -
1Indeed, Android employs a large set of optimizations to speed up the start and runtime performance of apps, such as loading the actual app code oat file into a pre-warmed process that already loaded libraries and even a pre-filled heap with often used objects. Mar 5, 2020 at 17:19
-
Adding these lines to you answer would give a feel of more completeness :) Mar 5, 2020 at 17:21