1page.title=ART and Dalvik 2@jd:body 3 4<!-- 5 Copyright 2014 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--> 19 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</div> 27</div> 28 29<p>Android runtime (ART) is the managed runtime used by applications and some system 30services on Android. ART and its predecessor Dalvik were originally created 31specifically for the Android project. ART as the runtime executes the Dalvik 32Executable format and Dex bytecode specification.</p> 33 34<p>ART and Dalvik are compatible runtimes running Dex bytecode, so apps 35developed for Dalvik should work when running with ART. However, some 36techniques that work on Dalvik do not work on ART. For information about the 37most important issues, see <a 38href="http://developer.android.com/guide/practices/verifying-apps-art.html">Verifying 39App Behavior on the Android Runtime (ART)</a>.</p> 40 41<h2 id="features">ART Features</h2> 42 43<p>Here are some of the major features implemented by ART.</p> 44 45<h3 id="AOT_compilation">Ahead-of-time (AOT) compilation</h3> 46 47<p>ART introduces ahead-of-time (AOT) compilation, which can improve app 48performance. ART also has tighter install-time verification than Dalvik.</p> 49 50<p>At install time, ART compiles apps using the on-device 51<strong>dex2oat</strong> tool. This utility accepts <a 52href="http://source.android.com/devices/tech/dalvik/dex-format.html">DEX</a> files as input and 53generates a compiled app executable for the target device. The utility should be 54able to compile all valid DEX files without difficulty. However, some 55post-processing tools produce invalid files that may be tolerated by Dalvik but 56cannot be compiled by ART. For more information, see <a 57href="http://developer.android.com/guide/practices/verifying-apps-art.html#GC_Migration">Addressing 58Garbage Collection Issues</a>.</p> 59 60<h3 id="Improved_GC">Improved garbage collection</h3> 61 62<p>Garbage collection (GC) can impair an app's performance, resulting in choppy 63display, poor UI responsiveness, and other problems. ART improves garbage 64collection in several ways:</p> 65 66<ul> 67 <li>One GC pause instead of two</li> 68 <li>Parallelized processing during the remaining GC pause</li> 69 <li>Collector with lower total GC time for the special case of cleaning up 70 recently-allocated, short-lived objects</li> 71 <li>Improved garbage collection ergonomics, making concurrent garbage 72 collections more timely, which makes <a 73 href="http://developer.android.com/tools/debugging/debugging-memory.html#LogMessages"><code>GC_FOR_ALLOC</code></a> 74 events extremely rare in typical use cases</li> 75 <li>Compacting GC to reduce background memory usage and fragmentation</li> 76</ul> 77 78<h3 id="Debugging_Imp">Development and debugging improvements</h3> 79 80<p>ART offers a number of features to improve app development and debugging.</p> 81 82<h4 id="Sampling_Profiler">Support for sampling profiler</h4> 83 84<p>Historically, developers have used the <a 85href=" http://developer.android.com/tools/help/traceview.html">Traceview</a> 86tool (designed for tracing 87application execution) as a profiler. While Traceview gives useful information, 88its results on Dalvik have been skewed by the per-method-call overhead, and use 89of the tool noticeably affects run time performance.</p> 90 91<p>ART adds support for a dedicated sampling profiler that does not have these 92limitations. This gives a more accurate view of app execution without 93significant slowdown. Sampling support was added to Traceview for 94Dalvik in the KitKat release.</p> 95 96<h4 id="Debugging_Features">Support for more debugging features</h4> 97 98<p>ART supports a number of new debugging options, particularly in monitor- and 99garbage collection-related functionality. For example, you can:</p> 100 101<ul> 102 <li>See what locks are held in stack traces, then jump to the thread that 103 holds a lock.</li> 104 <li>Ask how many live instances there are of a given class, ask to see the 105 instances, and see what references are keeping an object live.</li> 106 <li>Filter events (like breakpoint) for a specific instance.</li> 107 <li>See the value returned by a method when it exits (using “method-exit” 108 events).</li> 109 <li>Set field watchpoint to suspend the execution of a program when a specific 110 field is accessed and/or modified.</li> 111</ul> 112 113<h4 id="Crash_Reports">Improved diagnostic detail in exceptions and crash reports</h4> 114 115<p>ART gives you as much context and detail as possible when runtime exceptions 116occur. ART provides expanded exception detail for <code><a 117href="http://developer.android.com/reference/java/lang/ClassCastException.html">java.lang.ClassCastException</a></code>, 118<code><a 119href="http://developer.android.com/reference/java/lang/ClassNotFoundException.html">java.lang.ClassNotFoundException</a></code>, 120and <code><a 121href="http://developer.android.com/reference/java/lang/NullPointerException.html">java.lang.NullPointerException</a></code>. 122(Later versions of Dalvik provided expanded exception detail for <code><a 123href="http://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException.html">java.lang.ArrayIndexOutOfBoundsException</a></code> 124and <code><a 125href="http://developer.android.com/reference/java/lang/ArrayStoreException.html">java.lang.ArrayStoreException</a></code>, 126which now include the size of the array and the out-of-bounds offset, and ART 127does this as well.)</p> 128 129<p>For example, <code><a 130href="http://developer.android.com/reference/java/lang/NullPointerException.html">java.lang.NullPointerException</a></code> 131now shows information about what the app was trying to do with the null pointer, 132such as the field the app was trying to write to, or the method it was trying to 133call. Here are some typical examples:</p> 134 135<pre class="no-pretty-print"> 136java.lang.NullPointerException: Attempt to write to field 'int 137android.accessibilityservice.AccessibilityServiceInfo.flags' on a null object 138reference</pre> 139 140<pre class="no-pretty-print"> 141java.lang.NullPointerException: Attempt to invoke virtual method 142'java.lang.String java.lang.Object.toString()' on a null object reference</pre> 143 144<p>ART also provides improved context information in app native crash reports, 145by including both Java and native stack information. </p> 146 147<h2 id="Reporting_Problems">Reporting Problems</h2> 148 149<p>If you run into any issues that aren’t due to app JNI issues, please report 150them via the Android Open Source Project Issue Tracker at <a 151href="http://b.android.com">http://b.android.com</a>. 152Please include an <code>"adb bugreport"</code> and link to the app in Google 153Play store if available. Otherwise, if possible, attach an APK that reproduces 154the issue. Please note that issues (including attachments) are publicly 155visible.</p> 156