Android Runtime - Dalvik Virtual Machine
The Dalvik Virtual Machine (DVM) was the original runtime environment for Android applications, interpreting bytecode from Dalvik Executable (DEX) files, but was replaced by the Android Runtime (ART) in Android 5.0 (API level 21)
The Dalvik Virtual Machine (DVM) was a key component of the Android runtime environment before it was replaced by Android Runtime (ART) in Android 5.0 (Lollipop). Dalvik was specifically designed for Android to optimize performance and memory usage on mobile devices. Below is an overview of Dalvik, its architecture, and how it compares to ART.
Features of Dalvik
1. Register-Based Architecture:
- Unlike the stack-based Java Virtual Machine (JVM), Dalvik uses a register-based architecture, which reduces the number of instructions and improves performance.
2. DEX Files:
- Android applications are compiled into .dex files, which are more compact than traditional .class files used by the JVM.
- Multiple .class files are merged into a single .dex file during the build process, reducing redundancy and saving space.
3. Just-In-Time (JIT) Compilation:
- Dalvik uses JIT compilation to convert bytecode into native machine code at runtime. This improves performance but can lead to slower app startup times.
4. Sandboxing:
- Each Android app runs in its own instance of the Dalvik VM, providing process isolation and security.
5. Garbage Collection:
- Dalvik includes a garbage collector to manage memory allocation and deallocation, though it was less efficient compared to modern garbage collectors.
General working process of Dalvik
1. Compilation:
- Java source code is compiled into .class files by the Java compiler (javac).
- The .class files are then converted into .dex files by the dx tool (or d8 in modern builds).
2. Execution:
- The .dex files are executed by the Dalvik VM on the Android device.
- Dalvik uses JIT compilation to translate bytecode into native machine code during runtime.
Comparison: Dalvik vs ART
Feature
|
Dalvik
|
ART
|
Compilation
|
Just-In-Time
(JIT)
|
Ahead-Of-Time
(AOT)
|
Performance
|
Slower
startup and execution
|
Faster
startup and execution
|
Garbage
Collection
|
Less
efficient
|
More
efficient
|
Battery
Life
|
Higher power
consumption
|
Lower power
consumption
|
Storage
|
Smaller .dex files
|
Larger
compiled native code
|
64-Bit
Support
|
No
|
Yes
|
0 Comments