Is a Dalvik virtual machine instance created for each application?

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


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.


  1. 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.

  2. 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.

  3. 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

Pictorial Representation

IMG


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 included dx tool.

Also have a look at What is... The Dalvik Virtual Machine for detailed description about DVM.

Tags:

Android

Dalvik