Introducing ART

ART is a new Android runtime being introduced experimentally in the 4.4 release. This is a preview of work in progress in KitKat that can be turned on in Settings > developer options. This is available for the purpose of obtaining early developer and partner feedback.

Important: Dalvik must remain the default runtime or you risk breaking your Android implementations and third-party applications.

Most existing apps should just work when running with ART. However, some techniques that work on Dalvik do not work on ART. For information about the most important issues, see Verifying App Behavior on the Android Runtime (ART).

ART Features

Here are some of the major new features implemented by ART.

Ahead-of-time (AOT) compilation

ART introduces ahead-of-time (AOT) compilation, which can improve app performance. ART also has tighter install-time verification than Dalvik.

At install time, ART compiles apps using the on-device dex2oat tool. This utility accepts DEX files as input and generates a compiled app executable for the target device. The utility should be able to compile all valid DEX files without difficulty. However, some post-processing tools produce invalid files that may be tolerated by Dalvik but cannot be compiled by ART. For more information, see Addressing Garbage Collection Issues.

Improved garbage collection

Garbage collection (GC) can impair an app's performance, resulting in choppy display, poor UI responsiveness, and other problems. ART improves garbage collection in several ways:

  • One GC pause instead of two
  • Parallelized processing during the remaining GC pause
  • Collector with lower pause time for the special case of cleaning up recently-allocated, short-lived objects
  • Improved garbage collection ergonomics, making concurrent garbage collections more timely, which makes GC_FOR_ALLOC events extremely rare in typical use cases

ART currently does not use compacting GC, but this feature is under development in the Android Open Source Project (AOSP). In the meantime, don't perform operations that are incompatible with compacting GC, such as storing pointers to object fields. For more information, see Addressing Garbage Collection Issues.

Development and debugging improvements

ART offers a number of features to improve app development and debugging.

Support for sampling profiler

Historically, developers have used the Traceview tool (designed for tracing application execution) as a profiler. While Traceview gives useful information, its results on Dalvik have been skewed by the per-method-call overhead, and use of the tool noticeably affects run time performance.

ART adds support for a dedicated sampling profiler that does not have these limitations. This gives a more accurate view of app execution without significant slowdown. Sampling support has also been added to Traceview for Dalvik.

Support for more debugging features

ART supports a number of new debugging options, particularly in monitor- and garbage collection-related functionality. For example, you can:

  • See what locks are held in stack traces, then jump to the thread that holds a lock.
  • Ask how many live instances there are of a given class, ask to see the instances, and see what references are keeping an object live.
  • Filter events (like breakpoint) for a specific instance.
  • See the value returned by a method when it exits (using “method-exit” events).
  • Set field watchpoint to suspend the execution of a program when a specific field is accessed and/or modified.

Improved diagnostic detail in exceptions and crash reports

ART gives you as much context and detail as possible when runtime exceptions occur. ART provides expanded exception detail for java.lang.ClassCastException, java.lang.ClassNotFoundException, and java.lang.NullPointerException. (Later versions of Dalvik provided expanded exception detail for java.lang.ArrayIndexOutOfBoundsException and java.lang.ArrayStoreException, which now include the size of the array and the out-of-bounds offset, and ART does this as well.)

For example, java.lang.NullPointerException now shows information about what the app was trying to do with the null pointer, such as the field the app was trying to write to, or the method it was trying to call. Here are some typical examples:

java.lang.NullPointerException: Attempt to write to field 'int
android.accessibilityservice.AccessibilityServiceInfo.flags' on a null object
reference
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String java.lang.Object.toString()' on a null object reference

ART also provides improved context information in app native crash reports, by including both Java and native stack information.

Known Issues

The following known issues are present in the 4.4.1 implementation of ART.

Fixed issues

  • Compile-time issue: Overly aggressive verification and compilation of unused portions of dex files lead to corrupt package messages. This was addressed in AOSP with: https://android-review.googlesource.com/#/c/72374/
  • Debug-time issue: Interactive debugging performance was slow, even in code without breakpoints. This has been addressed in the latest AOSP code.

Enabling ART in Android Build

Two runtimes are now available, the existing Dalvik runtime (libdvm.so) and the ART runtime (libart.so). A device can be built using either or both runtimes. (You can dual boot from Developer options if both runtimes are installed.) See runtime_common.mk. That is included from build/target/product/runtime_libdvm.mk or build/target/product/runtime_libdvm.mk or both.

The dalvikvm command line tool can run with either runtime now. It will default to using the runtime specified in developer options. The default can be overridden by specifying the desired runtime library, for example with -XXlib:libart.so

A new PRODUCT_RUNTIMES variable controls which runtimes are included in a build. Include it within either build/target/product/core_minimal.mk or build/target/product/core_base.mk.

Add this to the device makefile to have both runtimes built and installed, with Dalvik as the default:
PRODUCT_RUNTIMES := runtime_libdvm_default
PRODUCT_RUNTIMES += runtime_libart

Reporting Problems

If you run into any issues that aren’t due to app JNI issues, please report them via the Android Open Source Project Issue Tracker at https://code.google.com/p/android/issues/list. Please include an "adb bugreport" and link to the app in Google Play store if available. Otherwise, if possible, attach an APK that reproduces the issue. Please note that issues (including attachments) are publicly visible.