Reputation: 3086
Is a Dalvik virtual machine instance created for each application, or all Android applications share the same Dalvik virtual machine instance?
Upvotes: 56
Views: 51930
Reputation: 11141
From the developer docs:
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently.
The Dalvik VM executes files in the Dalvik Executable (
.dex
) format which is optimised for minimal memory footprint.The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the
.dex
format by the includeddx
tool.
Also have a look at What is... The Dalvik Virtual Machine for detailed description about DVM.
Upvotes: 63
Reputation: 42824
The Dalvik virtual machine is built specifically for Android. It was built to address the battery life and processing power problems, and it is free.
We are using Dalvik VM instead of Java Virtual Machine (JVM) because the Java compiler, the Java tools are free, but the JVM is not free, so the Android developers from Google have made their own virtual machine, and made it as free.
A virtual machine is necessary because the virtual machine helps in debugging, as a virtual computer so that my applications can run different devices the same way
Upvotes: 38
Reputation: 387
A .java
file is given to the java compiler (javac
) to generate the .class
file.
All .class
files are given to dx
tool to generate a single dex
file.
The dex
file is given to the Dalvik VM to generate the final machine code.
The final machine code is given to the CPU to execute.
Upvotes: 32
Reputation: 73
Dalvik is a virtual machine where every android application runs. Through Dalvik, device is able to run multiple virtual machines through better memory management as Dalvik VMs are register based and hence memory efficient
Every android app runs in its own process, with its own instance of Dalvik VM. First, Java files are connverted to .class file by java compiler .class files are given to "dx" tool which converts it to .dex format .dex file is given to DVM to produce machine code Machine code is executed by CPU
.apk file contains .dex file in zip format which can be run on Dalvik VMs
Why Dalvik ? 1. DVM are built for battery life, processing power and its free 2. We're using DVM instead of JVM as JVM is not free Dalvik VMs gives consistency across all the mobile devices i.e. one application will run across different devices in the same way
Upvotes: 2
Reputation: 2686
All apk's basic source code is in java language . When you build this project all .java files get converted to .class now the dx tool of adk converts all .class files to classes.dex file .And this classes.dex file is executed on dalvik virtual machine.
For more info on dalvik virtual machine: http://www.slideshare.net/jserv/understanding-the-dalvik-virtual-machine
Dalvik virtual machine is intended to run multiple VMs at a time . So every app runs in its own process, with its own instance of the Dalvik virtual machine as said by @sahilMahajanMj .
And this classes.dex file is further optimized to odex file and saved in /dalvik/dalvik-cache
To know more about odex click this .
If you want to know why DVM for android why not JVM click this
Upvotes: 14