Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can you not do on the Dalvik VM (Android's VM) that you can in Sun VM?

I know that you can run almost all Java in Dalvik's VM that you can in Java's VM but the limitations are not very clear. Has anyone run into any major stumbling blocks? Any major libraries having trouble? Any languages that compile to Java byte code (Scala, Jython etc...) not work as expected?

like image 730
Ichorus Avatar asked Oct 23 '08 15:10

Ichorus


People also ask

What is the difference between Dalvik virtual machine and Android virtual machine?

Dalvik is a discontinued process virtual machine (VM) in the Android OS that executes applications written for Android. Dalvik bytecode format is still used as a distribution format, but no longer at runtime in newer Android versions. Android itself is a Linux system with Dalvik sitting on top of it.

What does Dalvik virtual machine do?

Role of the Dalvik Virtual Machine The Role of the DVM in Android includes: Optimizing the Virtual Machine for memory, battery life, and performance. Conversion of class files into . dex file through Dex compiler that runs on Dalvik VM.

What is the role of Dalvik in Android development?

Dalvik plays an important role in the development of Android. It acts as a virtual machine where the Android application runs. It is with the help of Dalvik only that devices can execute multiple virtual machines effectively along with better memory management.


2 Answers

There is a number of things that Dalvik will not handle or will not handle quite the same way as standard Java bytecode, though most of them are quite advanced.

The most severe example is runtime bytecode generation and custom class loading. Let's say you would like to create some bytecode and then use classloader to load it for you, if that trick works on your normal machine, it is guaranteed to not work on Dalvik, unless you change your bytecode generation.

That prevents you from using certain dependency injection frameworks, most known example being Google Guice (though I am sure some people work on that). On the other hand AspectJ should work as it uses bytecode instrumentation as a compilation step (though I don't know if anyone tried).

As to other jvm languages -- anything that in the end compiles to standard bytecode and does not use bytecode instrumentation at runtime can be converted to Dalvik and should work. I know people did run Jython on Android and it worked ok.

Other thing to be aware of is that there is no just in time compilation. This is not strictly Dalviks problem (you can always compile any bytecode on the fly if you wish) but that Android does not support that and is unlikely to do so. In the effect while microbenchmarking for standard Java was useless -- components had different runtime characterstics in tests than as parts of larger systems -- microbenchmarks for Android phones totally make sense.

like image 151
Marcin Avatar answered Oct 05 '22 17:10

Marcin


If you see "Dalvik Virtual Machine internals" Google IO session, you can find Dalvik does not support generational GC.

So, it could degrade performance of frequent object creation and deletion. Java VM supports generational GC so, it would show better GC performance for the same situation.

And also, Dalvik uses trace-granuality JIT instead of method granuality JIT.

like image 37
Wonil Avatar answered Oct 05 '22 19:10

Wonil