Android Runtime

{{Short description|Runtime environment used by Android}}

{{Use mdy dates|date=August 2014}}

{{Infobox software

| name = ART

| logo =

| logo alt =

| logo caption =

| screenshot =

| screenshot alt =

| caption =

| collapsible =

| author =

| developer = Google

| released =

| discontinued =

| ver layout =

| latest release version =

| latest release date =

| latest preview version =

| latest preview date =

| repo = {{URL|https://android.googlesource.com/platform/art/}}

| status =

| programming language = C++

| operating system = Android

| platform = ARM64 RISC-V x86

| included with = Android

| replaces = Dalvik

| size =

| language =

| language count =

| language footnote =

| genre = Runtime environment

| license = Apache License 2.0{{cite web|url=https://android.googlesource.com/platform/art/+/master/NOTICE|title=NOTICE - platform/art - Git at Google|access-date=2021-06-25|archive-date=March 4, 2023|archive-url=https://web.archive.org/web/20230304150150/https://android.googlesource.com/platform/art/+/master/NOTICE|url-status=live}}

| alexa =

| website =

| standard =

| AsOf =

}}

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 some of the application's bytecode into native instructions that are later executed by the device's runtime environment.{{cite web

| url = http://anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/

| title = A Closer Look at Android RunTime (ART) in Android L

| date = July 1, 2014

| access-date = July 5, 2014

| author = Andrei Frumusanu

| publisher = AnandTech

| archive-date = July 5, 2014

| archive-url = https://web.archive.org/web/20140705022457/http://anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l

| url-status = live

}}

Overview

File:ART view.png

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.{{cite web

|url = http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf

|title = A JIT Compiler for Android's Dalvik VM

|date = May 2010

|access-date = March 18, 2015

|author1 = Ben Cheng

|author2 = Bill Buzbee

|publisher = Google

|website = android-app-developer.co.uk

|pages = 5–14

|archive-url = https://web.archive.org/web/20151106221110/http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf

|archive-date = November 6, 2015

|url-status = dead

}}{{cite web

| url = http://www.androidcentral.com/google-android-developer-explains-more-about-dalvik-and-jit-froyo

| title = Google Android developer explains more about Dalvik and the JIT in Froyo

| date = May 26, 2010

| access-date = July 8, 2014

| author = Phil Nickinson

| website = androidcentral.com

| archive-date = April 8, 2017

| archive-url = https://web.archive.org/web/20170408183538/http://www.androidcentral.com/google-android-developer-explains-more-about-dalvik-and-jit-froyo

| url-status = live

}}

Unlike Dalvik, ART introduces the use of ahead-of-time (AOT) compilation by compiling the most performance-critical parts of applications (previously, the entire app) into native machine code upon their installation. This way, 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.{{cite web

| url = https://source.android.com/devices/tech/dalvik/index.html

| title = Android Developers: ART and Dalvik

| date = March 9, 2015

| access-date = March 18, 2015

| website = source.android.com

| archive-date = March 15, 2015

| archive-url = https://web.archive.org/web/20150315163429/http://source.android.com/devices/tech/dalvik/index.html

| url-status = live

}}{{cite web

| url = https://source.android.com/devices/tech/dalvik/configure.html#how_art_works

| title = Android Developers: Configuring ART – How ART works

| date = March 9, 2015 | access-date = March 18, 2015

| website = source.android.com

}}

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 {{Mono|dex2oat}} utility, it is run 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. Long AOT compilation became especially problematic when monthly security updates became the norm, locking users out of the OS for a long time after each update.

To improve on these, a hybrid approach was introduced in Android 7.0 (Nougat) which originally relies on JIT compilation, but later, when the device is idle and charging, compiles the most frequently used code as well as that on the UI thread to native code.{{Cite web |last=Amadeo |first=Ron |date=2016-08-22 |title=Android 7.0 Nougat review—Do more on your gigantic smartphone |url=https://arstechnica.com/gadgets/2016/08/android-7-0-nougat-review-do-more-on-your-gigantic-smartphone/9/#h2 |access-date=2023-04-05 |website=Ars Technica |language=en-us}}

History

Android 4.4 "KitKat" introduced a technology preview of ART as an alternative runtime environment to Dalvik, which remained the default virtual machine.{{cite web

| url = https://www.engadget.com/2013/11/06/new-android-runtime-could-improve-battery-life/

| title = 'ART' experiment in Android KitKat improves battery life and speeds up apps

| date = November 6, 2013

| access-date = July 5, 2014

| author = Sean Buckley

| publisher = Engadget

| archive-date = January 27, 2017

| archive-url = https://web.archive.org/web/20170127122851/https://www.engadget.com/2013/11/06/new-android-runtime-could-improve-battery-life/

| url-status = live

}}{{cite web

| url = http://www.phonearena.com/news/Experimental-Google-ART-runtime-in-Android-KitKat-can-bring-twice-faster-app-executions_id49139

| archive-url = https://archive.today/20140707072521/http://www.phonearena.com/news/Experimental-Google-ART-runtime-in-Android-KitKat-can-bring-twice-faster-app-executions_id49139

| archive-date = July 7, 2014

| title = Experimental Google ART runtime in Android KitKat can bring twice faster app executions

| date = November 7, 2013

| access-date = July 5, 2014

| author = Daniel P.

| website = phonearena.com

| url-status = live

}} In the subsequent major Android release, Android 5.0 "Lollipop", Dalvik was entirely replaced by ART.

Android 7.0 "Nougat" turned the ART from a pure AOT to a hybrid JIT/AOT solution, while switching its Java Runtime Environment from the discontinued Apache Harmony to OpenJDK, introducing a JIT compiler with code profiling.{{Cite web|title=Android 7.0 for Developers|url=https://developer.android.com/about/versions/nougat/android-7.0|access-date=2021-03-22|website=Android Developers|language=en}} 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.{{Cite web |last=Amadeo |first=Ron |date=2016-08-22 |title=Android 7.0 Nougat review—Do more on your gigantic smartphone |url=https://arstechnica.com/gadgets/2016/08/android-7-0-nougat-review-do-more-on-your-gigantic-smartphone/9/#h2 |access-date=2023-04-05 |website=Ars Technica |language=en-us}}{{cite web

| url = https://source.android.com/devices/tech/dalvik/jit-compiler.html

| title = Implementing ART Just-In-Time (JIT) Compiler

| date = January 22, 2017

| access-date = January 22, 2017

| website = source.android.com

| archive-date = August 8, 2023

| archive-url = https://web.archive.org/web/20230808034821/https://source.android.com/docs/core/runtime/jit-compiler

| url-status = live

}}

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.{{Cite web |last=Amadeo |first=Ron |date=2018-09-13 |title=Android 9 Pie, thoroughly reviewed |url=https://arstechnica.com/gadgets/2018/09/android-9-pie-thoroughly-reviewed/ |access-date=2022-08-16 |website=Ars Technica |language=en-us |archive-date=November 30, 2018 |archive-url=https://web.archive.org/web/20181130193516/https://arstechnica.com/gadgets/2018/09/android-9-pie-thoroughly-reviewed/ |url-status=live }}

In July 2021,{{Cite web |title=ProfileInstaller {{!}} Jetpack |url=https://developer.android.com/jetpack/androidx/releases/profileinstaller |access-date=2023-07-05 |website=Android Developers |language=en |archive-date=August 8, 2023 |archive-url=https://web.archive.org/web/20230808034943/https://developer.android.com/jetpack/androidx/releases/profileinstaller |url-status=live }} 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. Baseline profiles are included with releases of AndroidX libraries and Jetpack Compose.{{Cite web |last1=Semenova |first1=Kateryna |last2=Ravikumar |first2=Rahul |last3=Craik |first3=Chris |date=28 January 2022 |title=Improving App Performance with Baseline Profiles |url=https://android-developers.googleblog.com/2022/01/improving-app-performance-with-baseline.html |access-date=2023-07-05 |website=Android Developers Blog |language=en |archive-date=August 8, 2023 |archive-url=https://web.archive.org/web/20230808035038/https://android-developers.googleblog.com/2022/01/improving-app-performance-with-baseline.html |url-status=live }}

ART was updated with a new garbage collector (GC) utilizing the Linux userfaultfd system call in Android 13.{{Citation |last=Gidra |first=Lokesh |title=What's new in app performance |date=May 12, 2022 |url=https://www.youtube.com/watch?v=DYdHLqLVspY |language=en |access-date=2022-08-16 |archive-date=August 16, 2022 |archive-url=https://web.archive.org/web/20220816141916/https://www.youtube.com/watch?v=DYdHLqLVspY&gl=US&hl=en |url-status=live }}{{Cite journal |last1=Gidra |first1=Lokesh |last2=Boehm |first2=Hans-J. |last3=Fernandes |first3=Joel |date=2020-10-12 |title=Utilizing the Linux Userfaultfd System Call in a Compaction Phase of a Garbage Collection Process |url=https://www.tdcommons.org/dpubs_series/3671 |journal=Defensive Publications Series |access-date=August 16, 2022 |archive-date=August 16, 2022 |archive-url=https://web.archive.org/web/20220816141919/https://www.tdcommons.org/dpubs_series/3671/ |url-status=live }}{{Cite web |title=Android 13 is in AOSP! |url=https://android-developers.googleblog.com/2022/08/android-13-is-in-aosp.html |access-date=2022-08-16 |website=Android Developers Blog |language=en |archive-date=August 15, 2022 |archive-url=https://web.archive.org/web/20220815213000/https://android-developers.googleblog.com/2022/08/android-13-is-in-aosp.html |url-status=live }} It reduces memory pressure, compiled code size and jank, and prevents the risk of killing apps because of low memory during garbage collection. Other changes also improve app startup, reduce jank and improve performance. Because of the Mainline project, Android 12's ART will also be updated.

See also

{{Portal|Computer programming}}

References

{{Reflist|30em}}