Is a Dalvik virtual machine instance created for each application?

AndroidDalvik

Android Problem Overview


Is a Dalvik virtual machine instance created for each application, or all Android applications share the same Dalvik virtual machine instance?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

  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

Solution 3 - Android

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.

Solution 4 - Android

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

Solution 5 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRockystechView Question on Stackoverflow
Solution 1 - AndroidSahil Mahajan MjView Answer on Stackoverflow
Solution 2 - AndroidDevrathView Answer on Stackoverflow
Solution 3 - AndroidTapsee PanuView Answer on Stackoverflow
Solution 4 - AndroidImposterView Answer on Stackoverflow
Solution 5 - AndroidAkash RajView Answer on Stackoverflow