Dalvik is the highly CPU-optimized virtual machine that is custom designed for the embedded environment. Android applications execute in a Dalvik VM (DVM). Dalvik is thus an integral part of Android devices. Each Android device has its specific version of DVM. Dalvik is designed to run on Linux kernel, which provides memory management, process isolation, threading support, security, and per-processing for faster application execution. Dalvik is designed to allow multiple VM instances to run at once. Every application runs in its own process, with it’s own instance of the DVM.

There are several advantages associated with running applications in VMs. Your application is essentially sandboxed, in that it cannot harmfully interfere (intentionally or otherwise) with the other applications, underlying OS, or directly access the device hardware. Also, this level of abstraction makes your application to become platform independent in that it is not tied to any specific device.

Another reason of replacing the JVM with the DVM is the licensing issue. Dalvik has licensed its source code under the Apache license, making it inexpensive for device manufacturers and service carriers. They can use and modify it without paying any licensing fees. They don't need to submit their proprietary extensions back to the open source community. On the other hand, the Java language, SDK tools, and libraries are free, But the JVM is not. The JVM is available under the GPL v2 open source which is not businesses friendly,

compile process with dalvik

dex format

The compact dex format is especially designed for systems that have limited memory and processing power. The.dex format is optimized for minimal memory footprint. It has an average of 30% less instructions sets than the Java bytecode.

When the Java compiler finishes creating the Java classes, the Dalvik dx compiler re-compiles them to Dalvik bytecode. Afterwards these multiple classes are aggregated and merged into one single .dex file.

The Dalvik places emphasis on code/data sharing to reduce memory usage. To conserve space, the dx compiler eliminates all the redundant information that is present in the classes. Duplicate strings and other constants like numeric constants, references to other classes, etc. used in multiple class files are included only once in the .dex output. The dex compiler also eliminates some constants by inlining their values directly into the bytecode.

Given a set of .class files, create an uncompressed .dex file and a compressed .jar file from them and compare their sizes. In an average case, you will find that the size of the .dex file is a little smaller than that of the .jar file.