Android ART runtime and Dalvik virtual machine, androiddalvik

Source: Internet
Author: User

Android ART runtime and Dalvik virtual machine, androiddalvik

In the past few days, an OSGi framework (Apache Felix) needs to be used in Android for a project. Therefore, an experiment is performed on a tablet of a certain brand of android 4.4.2.

The experiment is simple: Use the dx and aapt tools in the android sdk to convert the felix. jar package and some bundles jar packages in the felix package into jar Packages containing dex bytecode. In this way, these jar packages can be run on Android. (Because Android uses the Dalvik virtual machine instead of the standard Java virtual machine, the "native" jar package cannot be run directly on Android) then, when I convert all the jar packages and copy them to the existing Android tablet, the following error is reported:

Java. lang. unsupportedOperationException: can't load this type of class file.

At that time, I thought it was an error during jar package conversion. I deleted all the packages and re-downloaded them and re-converted them. I still returned this error.

After a day of struggle, I think it may be because of the problems of the art and Dalvik models. So I copied the same jar package to my Android phone (version 4.4.4 runs in dalvik mode) and ran smoothly. Then, you can run the jar package again in the art mode to report an error on the tablet.

 

ART (Android Runtime)

ART is a more efficient and energy-saving running mechanism. It is introduced in Android 4.4 and can be set in "Developer options"-"select running mode. Currently, the latest Android L version sets the ART mode as the default.

 

Dalvik Virtual Machine

"Java Virtual Machine" for running java on Android ". But it does not run the. class file (java bytecode), but the. dex file (dex bytecode ). The Dalvik Virtual Machine contains an interpreter used to execute the dex bytecode.

 

Two important differences must be clarified here

The Dalvik Virtual Machine interprets the executed dex bytecode.

The ART virtual machine executes the local machine code. (These local machine codes are converted from dex bytecode)

Take a look at the following conversion process:

Java-> java bytecode (. jar)-> dalvik bytecode (. dex)

Java-> java bytecode (. jar)-> dalvik bytecode (. dex)-> optimized android runtime machine code (. odex)

 

Advantages of ART

ART uses AOT (Ahead-Of-Time) Compilation. During the first installation Of an application, bytecode is pre-compiled into a machine code and stored locally. In Dalvik, every time an application runs, bytecode must be converted to machine code through the real-time compiler before execution.

When the App is running, the ART mode is less than the Dalvik mode, so the App running efficiency will be improved and the memory usage will be reduced accordingly.

So Gu Ge started the ART mode by default in the latest Android L version, hoping that Android can get rid of the choppy problem. We also hope that the Android L will be smooth and smooth. In other words, I personally feel that the paper design of Android L is really comfortable and cool.

 

Small cost

The ART mode is more efficient than the dalvik mode, but it also pays some price because it needs to be converted into machine code, therefore, the storage occupied by the APP will also be increased accordingly (For details, refer to the test link at the end). At the same time, the conversion process is in the APP installation process, therefore, the installation duration of the APP will also increase accordingly, but these are all trivial matters, because the App is only installed once. In order to run smoothly, it is worthwhile to install the APP for a long time.

 

Seamless replacement of Dalvik virtual machines during ART operation

Currently, most Android devices run in dalvik mode. How can ART replace dalvik without affecting the use of the original dalvik?

I am not taking the Android development direction here, so I will not study the details in depth. Here I strongly recommend the following blog post for details:

Process Analysis of seamless replacement of Dalvik Virtual Machine During http://blog.csdn.net/luoshengyang/article/details/18006645 Android ART Runtime

 

Read recommendations:

Http://www.zhihu.com/topic/19905311 zhihu Android Runtime (ART)

Test comparison between http://www.pcpop.com/doc/0/967/967006.shtml ART and Dalvik

 

Note: For reprint, please indicate the source:Http://www.programfish.com/blog? P = 113

Welcome to my personal website:Http://www.programfish.com/

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.