How the Dalvik Virtual Machine Works on Google Android

Sayed Hashimi, Satya Komatineni & Dave MacLean

(The following is an excerpt from "Pro Android 2," published by APress)

As part of Android, Google has spent a lot of time thinking about optimizing designs for low-powered handheld devices. Handheld devices lag behind their desktop counterparts in memory and speed by eight to ten years. They also have limited power for computation; a handheld device's total RAM might be as little as 64MB, and its available space for applications might be as little as 20MB.

The performance requirements on handsets are severe as a result, requiring handset designers to optimize everything. If you look at the list of packages in Android, you'll see that they are full-featured and extensive. According to Google, these system libraries might use as much as 10 to 20MB, even with their optimized JVM.

These issues led Google to revisit the standard JVM implementation in many respects. (The key figure in Google's implementation of this JVM is Dan Bornstein, who wrote the Dalvik VM-Dalvik is the name of a town in Iceland.) First, the Dalvik VM takes the generated Java class files and combines them into one or more Dalvik Executable (.dex) files. It reuses duplicate information from multiple class files, effectively reducing the space requirement (uncompressed) by half from a traditional .jar file. For example, the
.dex file of the web browser app in Android is about 200K, whereas the equivalent uncompressed .jar version is about 500K. The .dex file of the alarm clock app is about 50K, and roughly twice that size in its . jar version.

Second, Google has fine-tuned the garbage collection in the Dalvik VM, but it has chosen to omit a just-in-time (JIT) compiler, in early releases. The 2.0 codebase seem to have the necessary sources for a JIT compiler but is not enabled in the final release. It is anticipated that it will be part of future releases. The company can justify this choice because many of Android's core libraries, including the graphics libraries, are implemented in C and C++. For example, the Java graphics APIs are actually thin wrapper classes around the native code using the Java Native Interface (JNI). Similarly, Android provides an optimized C-based native library to access the SQLite database, but this library is encapsulated in a higher-level Java API. Because most of the core code is in C and C++, Google reasoned that the impact of JIT compilation would not be significant.

Finally, the Dalvik VM uses a different kind of assembly-code generation, in which it uses registers as the primary units of data storage instead of the stack. Google is hoping to accomplish 30 percent fewer instructions as a result. We should point out that the final executable code in Android, as a result of the Dalvik VM, is based not on Java byte code but on .dex files instead. This means you cannot directly execute Java byte code; you have to start with Java class files and then convert them to linkable .dex files.

Add Comment      Leave a comment on this blog post
Aug 20, 2010 10:08 AM Anonymous Anonymous  says:
Android runs on a irtual machine thats not JVM but Davik VMI wanted to know more on this topic Reply
Feb 16, 2011 11:02 AM Anonymous Anonymous  says:
why google is reinventing the wheel?????? just optimised the jvm . Reply
May 6, 2011 9:34 AM Anonymous Anonymous  says: in response to Anonymous
You did read the start of the article? Reply
Aug 10, 2011 10:08 AM regime hyperprotein� regime hyperprotein�  says:
Excellent read, I just passed this onto a colleague who was doing a little research on that. And he just bought me lunch since I found it for him smile Therefore let me rephrase that: Thank you for lunch! Reply
Sep 4, 2011 3:09 PM tarot pas cher tarot pas cher  says:
I real happy to find this website on bing, just what I was looking for :D besides saved to fav. Reply
Sep 30, 2011 10:09 AM Anonymous Anonymous  says:
i went throuh it,seems to be ok.... Reply
Sep 30, 2011 10:34 AM Anonymous Anonymous  says: in response to Anonymous
u seems to be blazing the situvation out...............:) Reply
Feb 27, 2012 10:02 AM Karen Millen Karen Millen  says:
It is anticipated that it will be part of future releases. The company can justify this choice because many of Android�s core libraries, including the graphics libraries, are implemented in C and C++. Reply
Mar 4, 2012 11:03 AM Shine Shine  says:
I am not that familiar with Google Android. Reply

Post a comment





(Maximum characters: 1200). You have 1200 characters left.




Subscribe to our Newsletters

Sign up now and get the best business technology insights direct to your inbox.