Software:Android Runtime

From HandWiki
Short description: Runtime environment used by Android
ART
Developer(s)Google
Repositoryandroid.googlesource.com/platform/art/
Written inC, C++
Operating systemAndroid
TypeRuntime environment
LicenseApache License 2.0[1]

Android Runtime (ART) is an application runtime environment used by the Android operating system. Replacing Dalvik, the process virtual machine originally used by Android, ART performs the translation of the application's bytecode into native instructions that are later executed by the device's runtime environment.[2]

Overview

A comparison of Dalvik and ART architectures

Android 2.2 "Froyo" brought trace-based just-in-time (JIT) compilation into Dalvik, optimizing the execution of applications by continually profiling applications each time they run and dynamically compiling frequently executed short segments of their bytecode into native machine code. While Dalvik interprets the rest of an application's bytecode, native execution of those short bytecode segments, called "traces", provides significant performance improvements.[3][4]

Unlike Dalvik, ART introduces the use of ahead-of-time (AOT) compilation by compiling entire applications into native machine code upon their installation. By eliminating Dalvik's interpretation and trace-based JIT compilation, ART improves the overall execution efficiency and reduces power consumption, which results in improved battery autonomy on mobile devices. At the same time, ART brings faster execution of applications, improved memory allocation and garbage collection (GC) mechanisms, new applications debugging features, and more accurate high-level profiling of applications.[2][5][6]

To maintain backward compatibility, ART uses the same input bytecode as Dalvik, supplied through standard .dex files as part of APK files, while the .odex files are replaced with Executable and Linkable Format (ELF) executables. Once an application is compiled by using ART's on-device dex2oat utility, it is run solely from the compiled ELF executable; as a result, ART eliminates various application execution overheads associated with Dalvik's interpretation and trace-based JIT compilation. A disadvantage of ART is that additional time is required for compilation when an application is installed, and applications take up slightly more secondary storage (usually flash memory) to store the compiled code.[2][5][6]

History

Android 4.4 "KitKat" introduced a technology preview of ART as an alternative runtime environment to Dalvik, which remained the default virtual machine.[7][8] In the subsequent major Android release, Android 5.0 "Lollipop", Dalvik was entirely replaced by ART.

Android 7.0 "Nougat" switched its Java Runtime Environment from the discontinued Apache Harmony to OpenJDK, introducing a JIT compiler with code profiling to ART, which lets it constantly improve the performance of Android apps as they run.[9] The JIT compiler complements ART's AOT compiler, helping to improve runtime performance and save storage space by identifying "hot code" (code which is frequently used, runs on the UI thread or affects startup time), which the AOT compiler compiles to machine code while the device is idle and charging. Less-frequently used code relies on JIT compilation.[10][11]

Android 9 "Pie" reduced the amount of storage used by APKs by using compressed bytecode files, and profiler data can be uploaded to Google Play servers to be bundled with apps when downloaded by users with a similar device, which shortens download time from Google Play by up to 40%. Google Play cloud profiles allow apps to be optimized on installation, which helps avoid the initial performance issues present on Android 7.0 to 8.1.[12]

In July 2021,[13] the concept of baseline profiles was introduced. Baseline profiles are ART profiles that define methods and classes which should undergo AOT compilation from an app's first launch, and are compatible with Android 7.0 and later. They provide similar functionality to Android 9's Google Play cloud profiles when they are not available and automatically merge with cloud profiles when they are available.[14]

ART was updated with a new garbage collector (GC) utilizing the Linux userfaultfd system call in Android 13.[15][16][17] It reduces memory pressure, compiled code size and jank, and prevents the risk of killing apps because of low memory during garbage collection.[17] Other changes also improve app startup, reduce jank and improve performance.[17] Because of the Mainline project, Android 12 ART will also be updated.[15]

See also

References

  1. "NOTICE - platform/art - Git at Google". https://android.googlesource.com/platform/art/+/master/NOTICE. 
  2. 2.0 2.1 2.2 Andrei Frumusanu (July 1, 2014). "A Closer Look at Android RunTime (ART) in Android L". AnandTech. http://anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/. 
  3. "A JIT Compiler for Android's Dalvik VM". Google. May 2010. pp. 5–14. http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf. 
  4. Phil Nickinson (May 26, 2010). "Google Android developer explains more about Dalvik and the JIT in Froyo". http://www.androidcentral.com/google-android-developer-explains-more-about-dalvik-and-jit-froyo. 
  5. 5.0 5.1 "Android Developers: ART and Dalvik". March 9, 2015. https://source.android.com/devices/tech/dalvik/index.html. 
  6. 6.0 6.1 "Android Developers: Configuring ART – How ART works". March 9, 2015. https://source.android.com/devices/tech/dalvik/configure.html#how_art_works. 
  7. Sean Buckley (November 6, 2013). "'ART' experiment in Android KitKat improves battery life and speeds up apps". Engadget. https://www.engadget.com/2013/11/06/new-android-runtime-could-improve-battery-life/. 
  8. Daniel P. (November 7, 2013). "Experimental Google ART runtime in Android KitKat can bring twice faster app executions". http://www.phonearena.com/news/Experimental-Google-ART-runtime-in-Android-KitKat-can-bring-twice-faster-app-executions_id49139. 
  9. "Android 7.0 for Developers" (in en). https://developer.android.com/about/versions/nougat/android-7.0. 
  10. Amadeo, Ron (2016-08-22). "Android 7.0 Nougat review—Do more on your gigantic smartphone" (in en-us). https://arstechnica.com/gadgets/2016/08/android-7-0-nougat-review-do-more-on-your-gigantic-smartphone/9/#h2. 
  11. "Implementing ART Just-In-Time (JIT) Compiler". January 22, 2017. https://source.android.com/devices/tech/dalvik/jit-compiler.html. 
  12. Amadeo, Ron (2018-09-13). "Android 9 Pie, thoroughly reviewed" (in en-us). https://arstechnica.com/gadgets/2018/09/android-9-pie-thoroughly-reviewed/. 
  13. "ProfileInstaller | Jetpack" (in en). https://developer.android.com/jetpack/androidx/releases/profileinstaller. 
  14. Semenova, Kateryna; Ravikumar, Rahul; Craik, Chris (28 January 2022). "Improving App Performance with Baseline Profiles" (in en). https://android-developers.googleblog.com/2022/01/improving-app-performance-with-baseline.html. 
  15. 15.0 15.1 Gidra, Lokesh (in en), What's new in app performance, https://www.youtube.com/watch?v=DYdHLqLVspY, retrieved 2022-08-16 
  16. Gidra, Lokesh; Boehm, Hans-J.; Fernandes, Joel (2020-10-12). "Utilizing the Linux Userfaultfd System Call in a Compaction Phase of a Garbage Collection Process". Defensive Publications Series. https://www.tdcommons.org/dpubs_series/3671. Retrieved August 16, 2022. 
  17. 17.0 17.1 17.2 "Android 13 is in AOSP!" (in en). https://android-developers.googleblog.com/2022/08/android-13-is-in-aosp.html. 

External links