Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Android need a Virtual Machine(DVM)?

Virtual Machines are used for running apps on different OS(Java compiles code into OS independent .class files which is interpreted into bytecode). Since android apps run on the same OS (i.e Android), it doesn't require a VM (I could be wrong here). Then why does it need a Dalvik VM?

like image 594
Jaison Varghese Avatar asked Mar 28 '12 18:03

Jaison Varghese


People also ask

Why does Android need a virtual machine?

Why android needs a virtual machine is on the basis that Google engineered Android API to vastly use a Java interface. Java itself is usually run on a virtual machine. The purpose of a virtual machine is to be able to abstract hardware by simulating it.

What is the main purpose of DVM?

The primary educational goal of the DVM program is to set the stage for a productive career within the veterinary medical profession. Whilst the program is designed to provide students with entry-level knowledge and skills, it also provides opportunities for students to follow specific career paths.

What is Dalvik virtual machine and why we required DVM for Android application execution?

The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile devices. It optimizes the virtual machine for memory, battery life and performance. Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.

Why do we need Dalvik virtual machine?

In DVM executable is APK. Execution is faster. From Android 2.2 SDK Dalvik has it's own JIT (Just In Time) compiler. DVM has been designed so that a device can run multiple instances of the Virtual Machine effectively.


2 Answers

Android Platform can run on different architectures - ARM, MIPs and x86. To abstract out the need to compile binaries for each architecture VM comes into play. It also does memory management for the developer.

like image 102
Rajdeep Dua Avatar answered Oct 11 '22 13:10

Rajdeep Dua


We need someone to compile and convert the java classes into bytecode which can be executed by the interpreter.

It is similar to JVM ... you have .java files which will be compiled by java compiler into .class files. the .class files are nothing but bytecode which will be run by the JVM. JVM can reside on any platform(windows,linux or unix).

In android too the files are compiled into .dex files and run by DVM. just to give an idea, when is application is installed, the Android OS assigns unique linux user id, a DVM is assigned for each app. So in short each app has own linux process, DVM and linux user id.

The java files are compiled into .dex files which consume less memory compared to .class files.

Now assume 10 applications are having 10 individual DVM's and the OS has 10 process to handle.

The dispatcher or scheduler in the android OS is responsible for handling these 10 processes....which is why we have android activity life cycle.

You need DVM to maintain the running state of each process(each app).

like image 23
user109245 Avatar answered Oct 11 '22 14:10

user109245