Dalvik 虛擬機

原文:http://en.wikipedia.org/wiki/Dalvik_%28software%29

Dalvik(Software)

Dalvik(軟件)

Dalvik is the process virtual machine (VM) in Google's Android operating system. It is the software that runs the apps on Android devices. Dalvik is thus an integral part of Android, which is typically used on mobile devices such asmobile phones andtablet computers as well as more recently on embedded devices such as smart TVs and media streamers. Programs are commonly written inJava and compiled to bytecode. They are then converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files before installation on a device. The compact Dalvik Executable format is designed to be suitable for systems that are constrained in terms ofmemory and processor speed.

Dalvik 是Google Android操作系統中的進程虛擬機。他是在Android設備上運行應用程序的軟件。因此,Dalvik是Android的一個組成部分,Android通常用於諸如地移動電話和平板電腦等移動設備,最近也多用於智能電視和流媒體處理器等嵌入式設備。程序通常用Java編寫,編譯成二進制代碼(bytecode)。而後在安裝到設備之前將其從Java虛擬機適用的.class文件轉換成虛擬機使用的.dex(Dalvik可執行)文件。這種精簡的Dalvik可執行格式被設計適用於受內存和處理速度限制的系統。

Dalvik is open-source software. It was originally written by Dan Bornstein, who named it after the fishing village ofDalvík inEyjafjörður,Iceland, where some of his ancestors lived.[1][2]

Dalvik是開源軟件,最初由Dan Bornstein編寫完成,名字取於位於冰島Eyjafjörður的漁村Dalvik,那是Dan Bornstein的部分祖上祖居之處。

Architecture

架構

Unlike Java VMs, which are stack machines, the Dalvik VM uses a register-based architecture.

與衆多的採用棧架構的Java虛擬機不同,Dalvik虛擬機採用基於寄存器的架構。


A tool called dx is used to convert some (but not all) Java .class files into the .dex format. Multiple classes are included in a single .dex file. Duplicate strings and other constants used in multiple class files are included only once in the .dex output to conserve space. Javabytecode is also converted into an alternativeinstruction set used by the Dalvik VM. An uncompressed .dex file is typically a few percent smaller in size than acompressed .jar (Java Archive) derived from the same .class files.[3]

dx工具用於將部分(而非全部)Java .class文件轉換成.dex格式,單個.dex文件包含多個類文件。多個.class文件用到的完全相同的string和其他常量在輸出的.dex文件中只被包含一次以節省空間。Java字節碼同樣也被轉換爲另一種Dalvik VM使用的指令集。未壓縮的.dex文件通常比壓縮的.jar(Java架構,從同樣的.class文件生成)小几個百分點。


The Dalvik executables may be modified again when installed onto a mobile device. In order to gain furtheroptimizations, byte order may be swapped in certain data, simple data structures and function libraries may be linked inline, and empty class objects may be short-circuited, for example.

Dalvik可執行文件在安裝到移動設備時有可能再一次被修改:爲獲取進一步的優化,字節順序在某些可靠的數據處可能有所變換,簡單數據結構和功能庫可能內聯地鏈接,空類對象可能被短路,如此等等。

As of Android 2.2, Dalvik has a just-in-time compiler.[4]

對於Android2.2,Dalvik有一個JIT(just-in-time)編譯器。

Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs:[5]

  • The VM was slimmed down to use less space
  • The constant pool has been modified to use only 32-bit indices to simplify the interpreter
  • Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions. Dalvik instead uses its own 16-bit instruction set that works directly on local variables. The local variable is commonly picked by a 4-bit 'virtual register' field. This lowers Dalvik's instruction count and raises its interpreter speed.

Moreover, according to Google, the design of Dalvik permits a device to run multiple instances of the VM efficiently.[6]

由於對低內存要求的優化,Dalvik具有與其他標準VM有所不同的獨特特性:

       精簡化VM以求使用較少的空間

       常量池修改爲只採用32bit的索引以求簡化解釋器

       標準Java字節碼執行8bit棧指令,局部變量必須由另外的指令從操作數棧中拷進拷出。而Dalvik使用其16bit指令集,該指令集直接作用於局部變量,局部變量通常常常由四個bit的虛擬寄存器域選擇,這降低了Dalvik的指令個數並提高了解釋速度。

       另外,根據google要求,Dalvik的設計允許設備高效地運行多個VM的實例

Performance

The relative merits of stack machines versus register-based approaches are a subject of ongoing debate.[7]

Generally, stack-based machines must use instructions to load data on the stack and manipulate that data, and, thus, require more instructions than register machines to implement the samehigh level code, but the instructions in a register machine must encode the source and destination registers and, therefore, tend to be larger. This difference is primarily of importance to VM interpreters for whichopcode dispatch tends to be expensive along with other factors similarly relevant tojust-in-time compilation.

However, tests performed on ARM devices by Oracle with standard non-graphical Java benchmarks on both Android 2.2 and Java SE embedded (both based on Java SE 6) seemed to show that Android 2.2 was 2 to 3 times slower than Java SE embedded.[8]

Class library

Dalvik does not align to Java SE nor Java ME class library profiles[9][10] (e.g., Java ME classes, AWT or Swing are not supported). Instead it uses its own library[11] built on a subset of theApache Harmony Java implementation.

Licensing and patents

Dalvik is published under the terms of the Apache License 2.0.[12] Google says that Dalvik is aclean-room implementation rather than a development on top of a standard Java runtime, which would mean it does not inherit copyright-based license restrictions from either the standard-edition or open-source-edition Java runtimes.[13]Oracle and some reviewers dispute this.[14]

On 12 August 2010, Oracle, which acquired Sun Microsystems in April 2009 and therefore owns the rights to Java, sued Google over claimed infringement of copyrights and patents. Oracle alleged that Google, in developing Android, knowingly, directly and repeatedly infringed Oracle's Java-related intellectual property.[15][16][17] In May 2012 the jury in this case found that Google did not infringe on Oracle's patents, and the trial judge ruled that the structure of the Java APIs used by Google was not copyrightable.[18][19] The parties agreed to zero dollars in statutory damages for a small amount of copied code.[20]

On non-Android platforms

In 2011, the software company Myriad Group announced "Alien Dalvik", a port of the Dalvik virtual machine to platforms other than Android.[21][22]



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章