ART: interpreter, JIT and AOT

Runtime, build and Gradle Mid-level Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Order the steps

Order what happens to a hot method in an app installed without a Baseline Profile.

  • Later launches run the AOT-compiled code
  • The method gets hot: the JIT compiles it and ART records it in the app's local profile
  • While the device is idle and charging, dex2oat compiles profiled methods ahead of time
  • The first runs are interpreted

Choose an answer, then open Show answer below to check it.

Show answer

Answer: D B C A

  1. The first runs are interpreted Nothing has been compiled yet.
  2. The method gets hot: the JIT compiles it and ART records it in the app's local profile JIT code lasts only for this run; the profile remembers which code matters.
  3. While the device is idle and charging, dex2oat compiles profiled methods ahead of time Background, profile-guided AOT.
  4. Later launches run the AOT-compiled code No interpretation or JIT warm-up for that method.

30-second answer

ART starts with code that hasn't been compiled: it interprets it, and the JIT compiles methods that get hot. While doing so it records those hot methods in a profile. Later, when the device is idle and charging, a background job (dex2oat) compiles the profiled methods ahead of time, so later launches run machine code. Baseline Profiles and Play's Cloud Profiles give ART that list at install time, so even the first launch is fast.

Practise saying it · 30 s. No recording, just a timer

Explain how ART runs app code.

Say your answer out loud, then check which of these points you covered:

  • Interpreter first
  • JIT for hot methods
  • Local profile
  • Idle-time AOT with dex2oat
  • Baseline and Cloud Profiles

Deep dive

ART replaced Dalvik in Android 5.0.

Each DEX file is limited to 65,536 method references; with minSdk 21+, multidex is built in and needs no library.

Profile-guided compilation runs while the device is idle and charging.

Android doesn't run a JVM; it runs DEX on ART.

Common mistakes

  • Saying Android runs a standard JVM.
  • Adding the multidex library to an app with minSdk 21 or higher.
  • Thinking all code is compiled ahead of time at install.

Senior take & follow-ups

Explain the interpret, JIT, profile, AOT cycle, then say how Baseline Profiles skip the slow first runs.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why is the first launch after install often the slowest?

    Show hint

    Without a profile, startup code is interpreted and JIT-compiled before ART has anything to compile ahead of time.

  2. Why do baseline profiles help?

    Show hint

    Hot startup code is compiled before first launch instead of interpreted.

Suggest a fix if something here is wrong or out of date.