Dalvik and art in Android and the difference analysis _android

Source: Internet
Author: User
Tags java se

To know the difference between Dalvik and art, first of all, we have to know what the two are?

What is Dalvik?
Dalvik is Google's own virtual machine designed for the Android platform.
Dalvik virtual Machine is one of the core components of Android mobile device platform developed by Google and other vendors.
It can support the operation of a Java application that has been converted to. dex format, the. dex format is a compressed format designed for Dalvik that is suitable for systems with limited memory and processor speed.
Dalvik is optimized to allow instances of multiple virtual machines to run concurrently in limited memory, and each Dalvik application executes as a stand-alone Linux process. Independent processes can prevent all programs from shutting down when a virtual machine crashes.
For a long time, the Dalvik virtual machine has been blamed by users for slowing down the Android system at a slower pace than the source of iOS.
June 25, 2014, Android L officially unveiled in the Google I/O conference, the Android L change a lot, Google will directly delete Dalvik, instead of it is rumored art.

What is art?
That's Android Runtime
The mechanism of ART differs from that of Dalvik. Under the Dalvik, every time the application runs, bytecode needs to be converted to machine code via the Just-in-time compiler (just in, JIT), which slows down the application's efficiency, and in the art environment, the bytecode is precompiled into machine code the first time it is installed, Make it a real local application. This process is called precompilation (aot,ahead-of-time). In this way, the application's startup (first) and execution will become much faster.

Here's the difference analysis.

What does Dalvik have to do with the JVM?
Main differences:
The Dalvik is based on registers, and the JVM is based on stacks.
Dalvik runs the Dex file, while the JVM runs Java bytecode
Starting with Android 2.2, Dalvik supports JIT (Just-in-time, just-in-time compilation technology).
The optimized Dalvik has some different features than other standard virtual machines:
1. Occupy Less space
2. For simplified translation, the constant pool uses only 32-bit indexes
3. The standard Java bytecode implements a 8-bit stack instruction, Dalvik uses a 16-bit instruction set to directly effect local variables. Local variables typically come from the 4-bit "virtual registers" area. This reduces the Dalvik instruction count and improves the translation speed.
When Android starts, the Dalvik VM monitors All Programs (APK) and creates dependency trees, optimizes the code for each program, and stores it in the Dalvik cache. Dalvik first load will generate cache files to provide the next fast load, so the first time will be very slow.
The Dalvik interpreter uses a predefined goto address, where each instruction accesses memory on a 64-byte boundary. This saves an instruction to check the table time. To enhance functionality, Dalvik also provides fast interpreter.

In general, a stack-based machine must use instructions to load and manipulate data from the stack, and therefore, relative to a register-based machine, they require more instructions to achieve the same performance. But the instructions on the Register machine must be encoded, so their instructions tend to be larger.

The Dalvik virtual machine does not support either Java SE nor Java Me class libraries (such as Java classes, which are not supported by AWT and swing). Instead, it uses its own set of class libraries (a subset of Apache Harmony Java).

What are the pros and cons of art?
Advantages:
1, the system performance of a significant increase.
2, the application starts faster, runs faster, the experience is smoother, the tactile feedback is more timely.
3, longer battery endurance.
4, support the lower hardware.
Disadvantages:
1. Machine code occupies more storage space, the bytecode becomes machine code, may increase 10%-20% (although in the application package, executable code is often only part of.) For example, the latest Google + APK is 28.3 MB, but the code is only 6.9 MB. )
2. The installation time of the application will become longer.

Tips: Most smartphones now allow users to choose whether to use Dalvik or art mode. Of course, the default or Dalvik mode is used.
Usage: Settings-accessibility-developer options (developer tools)-Choose a running environment (the steps for different phone settings may not be the same).

A few differences between Dalvik and art
Dalvik is the implementation of the Compile + run, the installation is faster, open the application is relatively slow, the use of space small
Art is installed when the compile, the implementation of the time can be directly run, installation slow, open application fast, occupy a large space
By analogy, riding a bicycle
Dalvik is a bicycle that has been folded up, and a bicycle must be assembled before it can be ridden.
ART is a bicycle that has already been assembled and can be taken out of the car every time you ride.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.