Lably
Skip to content

Android Runtime

Runtime environment used by Android

  • 3 min read
  • 2 chapters

Related on Lably

Through Operating system, Virtual machine and Translator (computing)

Overview

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.

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.

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 from the compiled ELF executable; as a result, ART eliminates various application execution overheads associated with Dalvik's interpretation and trace-based JIT compilation.

Initially, a disadvantage of ART was that additional time was required for compilation when an application was installed, and applications took 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 this, a hybrid approach was introduced in Android 7.0 (Nougat). Newly installed apps run using JIT compilation, and get profiled by the runtime. When the device is idle and charging, the runtime performs AOT compilation on the most frequently used ("hot") code.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication