ART Runtime Flashcards
ANDROID › System
- What is the main difference between ART and Dalvik?
- Dalvik used a JIT-only interpreter. ART, which replaced it as of Android 5.0, adds ahead-of-time (AOT) compilation via dex2oat plus JIT and interpretation, executing the same DEX bytecode but with better runtime performance and GC.
- How do AOT, JIT, and profile-guided compilation work together on Android 7+?
- Apps install fast and run interpreted/JIT at first. ART records hot methods into a profile; while the device is idle/charging, dex2oat AOT-compiles those profiled methods. This profile-guided hybrid avoids full install-time AOT while still compiling the code that matters.
- What is a Baseline Profile and how does it speed up startup?
- A list of hot methods/classes shipped in the APK/AAB (assets/dexopt/baseline.prof). ART AOT-compiles those methods at install time, so critical paths run compiled instead of being interpreted/JITed on first launch, improving startup by roughly 30%.
- What is a Cloud Profile and how does it differ from a Baseline Profile?
- Cloud Profiles are aggregated by Google Play from real-world usage across users (Android 9+) and delivered hours-to-days after an update. Baseline Profiles ship in the app and apply immediately at install; cloud profiles complement them and need a large user base.
- What is DEX and what does dex2oat do?
- DEX (Dalvik Executable) is the register-based bytecode format both Dalvik and ART run, produced from .class files by D8. dex2oat is ART's compiler that converts DEX into a compiled OAT/ELF binary optimized for the device, at install time or during idle background dexopt.
- What problem does multidex solve and when do you need it?
- A single DEX file can reference at most 65,536 (64K) methods. Multidex splits an app across multiple DEX files to exceed that limit. It is automatic for minSdk 21+ (ART loads multiple DEX natively); only pre-21 needed the multidex support library.
- Describe ART's garbage collection basics.
- ART uses a mostly-concurrent collector with typically a single short pause, concurrent copying to cut fragmentation and background memory, and a pause length independent of heap size. A dedicated collector handles short-lived objects, making GC_FOR_ALLOC stalls rare.
- What does it mean for code to be 'compiled' on Android, and why is it faster?
- Compiled means dex2oat translated DEX into native machine code stored in an OAT file, so the CPU runs it directly. Interpreted code is decoded instruction-by-instruction and JIT compiles hot paths at runtime with warmup cost; AOT-compiled code skips that warmup.
- How do you generate a Baseline Profile, and how does R8/minification interact with it?
- Use the BaselineProfileRule with Macrobenchmark to exercise critical journeys, generating human-readable rules the Gradle plugin compiles to binary. Generate on a non-minified variant; on AGP 8.2+, R8 rewrites the rules to match obfuscated/optimized release code.