Virtual Machine VM

VM acts as a hardware for performing operations. VM can be divided into two categories based on its working and functionality:
  • System Virtual Machine
  • Process Virtual Machiine
Based on its architecture VMs are divided into:
  • Stack based VM
  • Register based VM
System VM vs Process VM
The System VM simulates the complete system hardware stack and supports the execution of complete operating system. On the other hand, Process VM adds up layer over an operating system which is use to simulate the programming environment for the execution of the individual process.

The Process VM is created when process begins and it ends when process gets terminated. The main purpose of process VM is to provide platform independency. JVM and CLR (Common Language Runtime) are examples of Process VM.

Stack based vs Register based VM
A register VM is likely to have an intrinsic performance advantage over a stack based VM. Byte code verification is likely to be faster on a register VM because stack height integrity checks will be greatly simplified.

As we know JVM is high performance and provides excellent memory management. But it need to be optimized for low-powered handheld devices. The Dalvik Virtual Machine is optimized for mobile devices. It is register based VM. It is optimized to use less space.

Dalvik is the name of a town and Dalvik VM was written by Dan Bornstein. 

How DVM works
Every java program is compiled to byte code. The Java Byte code is then transformed into Dalvik byte-code with the help of dx tool and stored in .dex  file, and that's on what Dalvik performs operations such as verification and optimization.

In other words,
The javac tool compiles the java source file into class file. The dx tool takes all the class files of your application and generates a single .dex file.
The aapt (Android Assets Packaging Tool) handles the packaging process and combine .dex and manifest file and create .apk file that is your application.

Comments

Popular posts from this blog

SQLiteDatabase (Without SqliteOpenHelper class)

Set current date to Button and Datepicker dialog

MVC Architecture in Android