blob: 902593ea3923b16ddfb27d0269aa66d7d48fe869 [file] [log] [blame]
Clay Murphy84887ed2013-10-29 11:45:49 -07001page.title=Introducing ART
2@jd:body
3
4<!--
5 Copyright 2013 The Android Open Source Project
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
Andrew Solovay4ef28172014-05-20 15:07:23 -070019
20
21<div id="qv-wrapper">
22<div id="qv">
23 <h2 id="Contents">In this document</h2>
24 <ol id="auto-toc">
25 </ol>
26 <strong>See also</strong>
27 <ol>
28 <li><a
29 href="http://developer.android.com/guide/practices/verifying-apps-art.html">Verifying
30 App Behavior on the Android Runtime (ART)</a></li>
31 </ol>
32</div>
33</div>
34
Clay Murphy84887ed2013-10-29 11:45:49 -070035<p>
36ART is a new Android runtime being introduced experimentally in the 4.4
37release. This is a preview of work in progress in KitKat that can be turned on
Andrew Solovay4ef28172014-05-20 15:07:23 -070038in <strong>Settings</strong> &gt; <strong>developer options</strong>. This is
39available for the purpose of obtaining early developer and partner feedback.</p>
Clay Murphy84887ed2013-10-29 11:45:49 -070040
Andrew Solovay4ef28172014-05-20 15:07:23 -070041<p class="caution"><strong>Important:</strong> Dalvik must remain the default
42runtime or you risk breaking your Android implementations and third-party
43applications.</p>
Clay Murphy84887ed2013-10-29 11:45:49 -070044
Andrew Solovay4ef28172014-05-20 15:07:23 -070045<p>Most existing apps should just work when running with ART. However, some
46techniques that work on Dalvik do not work on ART. For information about the
47most important issues, see <a
48href="http://developer.android.com/guide/practices/verifying-apps-art.html">Verifying
49App Behavior on the Android Runtime (ART)</a>.</p>
Clay Murphy84887ed2013-10-29 11:45:49 -070050
Andrew Solovay4ef28172014-05-20 15:07:23 -070051<h2 id="features">ART Features</h2>
52
53<p>Here are some of the major new features implemented by ART.</p>
54
55<h3 id="AOT_compilation">Ahead-of-time (AOT) compilation</h3>
56
57<p>ART introduces ahead-of-time (AOT) compilation, which can improve app
58performance. ART also has tighter install-time verification than Dalvik.</p>
59
60<p>At install time, ART compiles apps using the on-device
61<strong>dex2oat</strong> tool. This utility accepts <a
62href="http://source.android.com/devices/tech/dalvik/dex-format.html">DEX</a> files as input and
63generates a compiled app executable for the target device. The utility should be
64able to compile all valid DEX files without difficulty. However, some
65post-processing tools produce invalid files that may be tolerated by Dalvik but
66cannot be compiled by ART. For more information, see <a
67href="http://developer.android.com/guide/practices/verifying-apps-art.html#GC_Migration">Addressing
68Garbage Collection Issues</a>.</p>
69
70<h3 id="Improved_GC">Improved garbage collection</h3>
71
72<p>Garbage collection (GC) can impair an app's performance, resulting in choppy
73display, poor UI responsiveness, and other problems. ART improves garbage
74collection in several ways:</p>
75
76<ul>
77 <li>One GC pause instead of two</li>
78 <li>Parallelized processing during the remaining GC pause</li>
79 <li>Collector with lower pause time for the special case of cleaning up
80 recently-allocated, short-lived objects</li>
81 <li>Improved garbage collection ergonomics, making concurrent garbage
82 collections more timely, which makes <a
83 href="http://developer.android.com/tools/debugging/debugging-memory.html#LogMessages"><code>GC_FOR_ALLOC</code></a>
84 events extremely rare in typical use cases</li>
85</ul>
86
87<p>ART currently does not use compacting GC, but this feature is under
88development in the <a href="https://source.android.com">Android Open Source
89Project (AOSP)</a>. In the meantime, don't perform operations that are
90incompatible with compacting GC, such as storing pointers to object fields. For
91more information, see <a
92href="http://developer.android.com/guide/practices/verifying-apps-art.html#GC_Migration">Addressing
93Garbage Collection Issues</a>.</p>
94
95<h3 id="Debugging_Imp">Development and debugging improvements</h3>
96
97<p>ART offers a number of features to improve app development and debugging.</p>
98
99<h4 id="Sampling_Profiler">Support for sampling profiler</h4>
100
101<p>Historically, developers have used the <a
102href=" http://developer.android.com/tools/help/traceview.html">Traceview</a>
103tool (designed for tracing
104application execution) as a profiler. While Traceview gives useful information,
105its results on Dalvik have been skewed by the per-method-call overhead, and use
106of the tool noticeably affects run time performance.</p>
107
108<p>ART adds support for a dedicated sampling profiler that does not have these
109limitations. This gives a more accurate view of app execution without
110significant slowdown. Sampling support has also been added to Traceview for
111Dalvik.</p>
112
113<h4 id="Debugging_Features">Support for more debugging features</h4>
114
115<p>ART supports a number of new debugging options, particularly in monitor- and
116garbage collection-related functionality. For example, you can:</p>
117
118<ul>
119 <li>See what locks are held in stack traces, then jump to the thread that
120 holds a lock.</li>
121 <li>Ask how many live instances there are of a given class, ask to see the
122 instances, and see what references are keeping an object live.</li>
123 <li>Filter events (like breakpoint) for a specific instance.</li>
124 <li>See the value returned by a method when it exits (using method-exit
125 events).</li>
126 <li>Set field watchpoint to suspend the execution of a program when a specific
127 field is accessed and/or modified.</li>
128</ul>
129
130<h4 id="Crash_Reports">Improved diagnostic detail in exceptions and crash reports</h4>
131
132<p>ART gives you as much context and detail as possible when runtime exceptions
133occur. ART provides expanded exception detail for <code><a
134href="http://developer.android.com/reference/java/lang/ClassCastException.html">java.lang.ClassCastException</a></code>,
135<code><a
136href="http://developer.android.com/reference/java/lang/ClassNotFoundException.html">java.lang.ClassNotFoundException</a></code>,
137and <code><a
138href="http://developer.android.com/reference/java/lang/NullPointerException.html">java.lang.NullPointerException</a></code>.
139(Later versions of Dalvik provided expanded exception detail for <code><a
140href="http://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException.html">java.lang.ArrayIndexOutOfBoundsException</a></code>
141and <code><a
142href="http://developer.android.com/reference/java/lang/ArrayStoreException.html">java.lang.ArrayStoreException</a></code>,
143which now include the size of the array and the out-of-bounds offset, and ART
144does this as well.)</p>
145
146<p>For example, <code><a
147href="http://developer.android.com/reference/java/lang/NullPointerException.html">java.lang.NullPointerException</a></code>
148now shows information about what the app was trying to do with the null pointer,
149such as the field the app was trying to write to, or the method it was trying to
150call. Here are some typical examples:</p>
151
152<pre class="no-pretty-print">
153java.lang.NullPointerException: Attempt to write to field 'int
154android.accessibilityservice.AccessibilityServiceInfo.flags' on a null object
155reference</pre>
156
157<pre class="no-pretty-print">
158java.lang.NullPointerException: Attempt to invoke virtual method
159'java.lang.String java.lang.Object.toString()' on a null object reference</pre>
160
161<p>ART also provides improved context information in app native crash reports,
162by including both Java and native stack information. </p>
163
164<h2 id="Known_Issues">Known Issues</h2>
165
166<p>The following known issues are present in the 4.4.1 implementation of ART.</p>
167
168<ul>
169
170 <li><em>Compile-time issue:</em> As noted above, ART flags unbalanced
171 <code>monitorenter</code>/<code>moniterexit</code> instructions. We relaxed
172 this check in 4.4.1 but intend to restore this verification in the future once
173 tools are fixed, as this check is necessary for certain compiler
174 optimizations. <a
175 href="https://code.google.com/p/android/issues/detail?id=61916">https://code.google.com/p/android/issues/detail?id=61916</a></li>
176
177 <li><em>Run-time issue:</em> There was an issue where JNI
178 <code>GetFieldID</code> and <code>GetStaticFieldID</code> were using the wrong
179 class loader on unattached threads, often leading to later CheckJNI errors or
180 NoSuchFieldError exceptions. <a
181 href="http://code.google.com/p/android/issues/detail?id=63970">http://code.google.com/p/android/issues/detail?id=63970</a></li>
182
183 <li><em>Run-time issue:</em> Calling JNI <code>NewDirectByteBuffer()</code>
184 with byte size of <code>0</code> led to the following CheckJNI error: <pre
185 class="no-pretty-print"> JNI DETECTED ERROR IN APPLICATION: capacity must be
186 greater than 0: 0</pre> <a
187 href="http://code.google.com/p/android/issues/detail?id=63055">http://code.google.com/p/android/issues/detail?id=63055</a></li>
188
189</ul>
190
191<h3 id="Fixed_Issues">Fixed issues</h3>
192
193<ul>
194
195 <li><em>Compile-time issue:</em> Overly aggressive verification and
196 compilation of unused portions of dex files lead to corrupt package messages.
197 This was addressed in AOSP with: <a
198 href="https://android-review.googlesource.com/#/c/72374/">https://android-review.googlesource.com/#/c/72374/</a></li>
199
200 <li><em>Debug-time issue:</em> Interactive debugging performance was slow,
201 even in code without breakpoints. This has been addressed in the latest AOSP
202 code.</li>
203
204</ul>
205
206<h2 id="building">Enabling ART in Android Build</h2>
207
208<p> Two runtimes are now available, the existing Dalvik runtime
209(<code>libdvm.so</code>) and the ART runtime (<code>libart.so</code>). A device
210can be built using either or both runtimes. (You can dual boot from
211<strong>Developer options</strong> if both runtimes are installed.) See
212runtime_common.mk. That is included from build/target/product/runtime_libdvm.mk
213or build/target/product/runtime_libdvm.mk or both.</p>
214
215<p> The <code>dalvikvm</code> command line tool can run with either runtime now.
216It will default to using the runtime specified in <strong>developer
217options</strong>. The default can be overridden by specifying the desired
218runtime library, for example with <code>-XXlib:libart.so</code> </p>
Clay Murphy84887ed2013-10-29 11:45:49 -0700219
220<p>
221A new <code>PRODUCT_RUNTIMES</code> variable controls which runtimes
222are included in a build. Include it within either
Andrew Solovay4ef28172014-05-20 15:07:23 -0700223<code>build/target/product/core_minimal.mk</code> or
224<code>build/target/product/core_base.mk</code>.
Clay Murphy84887ed2013-10-29 11:45:49 -0700225</p>
226
227<p>
228Add this to the device makefile to have both runtimes
229built and installed, with Dalvik as the default:
230</br>
231<code>PRODUCT_RUNTIMES := runtime_libdvm_default</code>
232</br>
233<code>PRODUCT_RUNTIMES += runtime_libart</code>
234</p>
Andrew Solovay4ef28172014-05-20 15:07:23 -0700235
236<h2 id="Reporting_Problems">Reporting Problems</h2>
237
238<p>If you run into any issues that arent due to app JNI issues, please report
239them via the Android Open Source Project Issue Tracker at <a
240href="https://code.google.com/p/android/issues/list">https://code.google.com/p/android/issues/list</a>.
241Please include an <code>"adb bugreport"</code> and link to the app in Google
242Play store if available. Otherwise, if possible, attach an APK that reproduces
243the issue. Please note that issues (including attachments) are publicly
244visible.</p>