Open-source software. It was originally written by Dan Bornstein.

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 as mobile phones and tablet computers as well as more recently on embedded devices such as smart TVs and media streamers. Programs are commonly written in Java 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 of memory and processor speed.

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


The relative merits of these two approaches is a subject of continuous argument but the underlying technology sometimes blurs the ideological boundaries. Moreover, the relative advantages of the two approaches depend on the interpretation/compilation strategy chosen. Generally, however, 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 same high level code. However, 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 whom opcode dispatch tends to be expensive and other factors are relevant for JIT compilation.

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. Java bytecode is also converted into an alternative instruction set used by the Dalvik VM. An uncompressed .dex file is typically a few percent smaller in size than a compressed .jar (Java Archive) derived from the same .class files.

The Dalvik executables may be modified again when installed onto a mobile device. In order to gain further optimizations, 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.

Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs:
  • 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
  • as of Android 2.2, Dalvik has a just-in-time compiler


by arawn
Aug 14, 2012