Android ART和Dalvik之间有什么区别和联系?

2026-04-19 11:201阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1121个文字,预计阅读时间需要5分钟。

Android ART和Dalvik之间有什么区别和联系?

ART+与Dalvik在本文中

ART特性:- 预编译(AOT)- 改进垃圾回收- 开发和调试改进

问题报告:Android运行时(ART)是应用程序和一些系统使用的托管运行时。


ART and Dalvik


IN THIS DOCUMENT

  1. ART Features
  1. Ahead-of-time (AOT) compilation
  2. Improved garbage collection
  3. Development and debugging improvements
  1. Reporting Problems


Android ART和Dalvik之间有什么区别和联系?


Android runtime (ART) is the managed runtime used by applications and some system services on Android. ART and its predecessor Dalvik were originally created specifically for the Android project. ART as the runtime executes the Dalvik Executable format and Dex bytecode specification.

ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik should work when running with ART. However, some techniques that work on Dalvik do not work on ART. For information about the most important issues, seeVerifying App Behavior on the Android Runtime (ART).

ART Features


Here are some of the major 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-devicedex2oattool. This utility acceptsDEXfiles 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, seeAddressing 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 total GC time for the special case of cleaning up recently-allocated, short-lived objects
  • Improved garbage collection ergonomics, making concurrent garbage collections more timely, which makesGC_FOR_ALLOCevents extremely rare in typical use cases
  • Compacting GC to reduce background memory usage and fragmentation

Development and debugging improvements

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

Support for sampling profiler

Historically, developers have used theTraceviewtool (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 was added to Traceview for Dalvik in the KitKat release.

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 forjava.lang.ClassCastException,java.lang.ClassNotFoundException, andjava.lang.NullPointerException. (Later versions of Dalvik provided expanded exception detail forjava.lang.ArrayIndexOutOfBoundsExceptionandjava.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


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.

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 atb.android.com. Please include an"adb bugreport"

本文共计1121个文字,预计阅读时间需要5分钟。

Android ART和Dalvik之间有什么区别和联系?

ART+与Dalvik在本文中

ART特性:- 预编译(AOT)- 改进垃圾回收- 开发和调试改进

问题报告:Android运行时(ART)是应用程序和一些系统使用的托管运行时。


ART and Dalvik


IN THIS DOCUMENT

  1. ART Features
  1. Ahead-of-time (AOT) compilation
  2. Improved garbage collection
  3. Development and debugging improvements
  1. Reporting Problems


Android ART和Dalvik之间有什么区别和联系?


Android runtime (ART) is the managed runtime used by applications and some system services on Android. ART and its predecessor Dalvik were originally created specifically for the Android project. ART as the runtime executes the Dalvik Executable format and Dex bytecode specification.

ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik should work when running with ART. However, some techniques that work on Dalvik do not work on ART. For information about the most important issues, seeVerifying App Behavior on the Android Runtime (ART).

ART Features


Here are some of the major 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-devicedex2oattool. This utility acceptsDEXfiles 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, seeAddressing 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 total GC time for the special case of cleaning up recently-allocated, short-lived objects
  • Improved garbage collection ergonomics, making concurrent garbage collections more timely, which makesGC_FOR_ALLOCevents extremely rare in typical use cases
  • Compacting GC to reduce background memory usage and fragmentation

Development and debugging improvements

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

Support for sampling profiler

Historically, developers have used theTraceviewtool (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 was added to Traceview for Dalvik in the KitKat release.

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 forjava.lang.ClassCastException,java.lang.ClassNotFoundException, andjava.lang.NullPointerException. (Later versions of Dalvik provided expanded exception detail forjava.lang.ArrayIndexOutOfBoundsExceptionandjava.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


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.

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 atb.android.com. Please include an"adb bugreport"