Sunday, 3 July 2016

Android Run Time(ART) - Comparison with Dalvik Virtual Machine

   ART is the application run time environment for the Android mobile operating system. It has been introduced experimentally along side of Dalvik Virtual Machine(Process virtual machine used in Android before Kitkat version) in Android 4.4 (Kitkat) but later replaced Dalvik Virtual Machine(DVM) to become only run time environment in Android 4.5 (Lollipop). Some of major changes introduced in ART compared to its predecessor DVM is Ahead of Time(AOT) compilation, improvements in garbage collection, development and debugging improvements and certain profiling improvements.

   All Android applications are available in APK(.apk) format. The byte code that Android environment uses is DEX(.dex called dalvik executable code). To maintain backward compatibility, ART uses the same input bytecode as DVM, supplied through standard DEX files, as part of APK files, while the .odex(Optimised DEX) files are replaced with Executable and Linkable Format (ELF) executables. Once an application is compiled by using ART’s on-device dex2oat utility, it run solely from the compiled ELF executable. Following Image shows the life of an APK file in Android environment(with ART) before it is getting installed. When you try to install an Android application on the device the .apk is first depackaged to the DEX files, resources(XMLfiles) and native code. The DEX files are fed to the dex2oat tool where it will compile from DEX to ELF(.elf). Then ELF files is fed to the ART along with the resources and native code which translates the code to the native instructions.

Image: Life of Android Application file(APK) in Android environment during installation time. (Image courtesy:http://anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l)

   Major improvement in ART in relative to Dalvik Virtual Machine(DVM) is the introduction of Ahead Of Time(AOT) compilation. With Dalvik’s JIT(Just-In-Time) compilation, each time when an application will run, it dynamically translates a part of dalvik code in to machine code. As the execution progress more byte code is compiled and cached. That is, whenever an app is relaunched with DVM you have to compile the entire code again in order to run the application. The involvement of CPU in each time compilation will increase the app launch time and decreases the battery life time. So to increase the performance and battery time ART comes with Ahead of Time(AOT) Compilation. With AOT compilation in ART, during the app installation phase, it statically translates the DEX code into machine code and stores it on the device storage. Thus, launching of application requires only to bring the binary code to memory with out the need of recompilation. Thus, ART increases the performance and battery life. Though AOT compilation increases the performance and battery life, it increases the installation time of application and demands the more storage on system.

No comments:

Post a Comment