As the title states,
Why is there a separate instance of VM(Dalvik/ART) for every App on Android?(the need for it)
and, what would have happened if the Android OS had chosen a model where a single VM runs all the apps?
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.
In most cases, every Android application runs in its own Linux process. This process is created for the application when some of its code needs to be run, and will remain running until it is no longer needed and the system needs to reclaim its memory for use by other applications.
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.
ART and its predecessor Dalvik were originally created specifically for the Android project. ART as the runtime executes the Dalvik Executable format and Dex bytecode specification. ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik should work when running with ART.
There are many reasons why running multiple applications in a single process doesn't work; here's two:
Two applications that don't trust one another shouldn't be able to view each other's memory, even if they use native code or reflection.
If a process leaks memory and crashes, it harms only itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With