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]



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值