Daneel: The difference between Java and Dalvik

Those of you who kept following IcedRobot might have seen that quite some work went into Daneel over the past months. He1 is in charge of parsing Android applications containing code intended to run on a Dalvik VM and transforming this code into something which can run on any underlying Java VM. So he is a VM compatible with Dalvik on top of a Java VM, or at least that’s what he wants to become.

So Daneel is multilingual in a strange way, he can read and understand Dalvik bytecode, but he only speaks and writes Java bytecode. To understand how he can do that we have to look at the differences between those two dialects.

Registers vs. Stack: We know Dalvik bytecode uses a register-machine, and Java bytecode uses a stack-machine. But each method frame on that stack-machine not only has an operand stack, it also has an array of local variables. Unfortunately this distinction is lost in our register-machine. To understand what this means, let us look at a full Java-Dalvik-Daneel round-trip for a simple method like the following.

public static int addConst(int val) {
   return val + 123456;

The first stop on our round-trip is the Java bytecode. So after we push this snippet through javac we get the following code which makes use of both, an operand stack and local variables.

public static int addConst(int);
  [max_stack=2, max_locals=1, args_size=1]
   0: iload_0
   1: ldc #int 123456
   3: iadd
   4: ireturn

The second stop takes us to the Dalvik bytecode. We push the above code through the dx tool and are left with the following code. Note that the distinction between the operand stack and local variables is lost completely, everything is stored in registers.

public static int addConst(int);
  [regs=2, ins=1, outs=0]
   0: const v0, #0x1E240
   1: add-int/2addr v0, v1
   2: return v0

The third and last step is Daneel reading the Dalvik bytecode and trying to reproduce sane Java bytecode again. The following is what he spits out after chewing on the input for a bit.

public static int addConst(int);
  [max_stack=2, max_locals=2, args_size=1]
   0: ldc #int 123456
   1: istore_1
   2: iload_1
   3: iload_0
   4: iadd
   5: istore_1
   6: iload_1
   7: ireturn

The observant reader will notice the vast difference between what we had at the beginning of our round-trip and what we ended up with. Daneel maps each Dalvik register to a Java local variable. Fortunately any decent Java VM will optimize away the unnecessary load and store instructions and we can achieve acceptable performance with this naive approach already.

Untyped Instructions: Another big difference might not be that obvious at first glance. Notice how the instruction at label 0 in the above Dalvik bytecode (the second stop on our round-trip) accesses register v0 without specifying the exact type of that register? The only thing Daneel can determine at that point in the code is that it’s a 32-bit value we are dealing with, it could be an int or a float value. For zero-constants it could even be a null reference we are dealing with. The exact type of that register is not revealed before the instruction at label 1, where v0 is read again by a typed instruction. It’s at that point that we learn the exact type of that register.

So Daneel has to keep track of all register types while iterating through the instruction stream to determine the exact types and decide which Java bytecode instructions to emit. I intend to write a separate article about how this is done by Daneel in the following days, so stay tuned.

Disclaimer: This is a technical description of just two major differences between Dalvik bytecode and Java bytecode. All political discussions about differences or similarities between Dalvik and Java in general are outside the scope of this article and I won’t comment on them.

1 Yes, Daneel is male. His girlfriend is called Ika. Together they love to drink iced tea because they try to get off caffeine. They even have a butler working for them who is called Jenkins, a very lazy guy who regularly was seen to crash during work.

It was the Law of the Sea,

It was the Law of the Sea, they said. Civilization ends at the waterline. Beyond that, we all enter the food chain, and not always right at the top. http://www.toolbox.com.ph

Hi just stumbled upon your

Hi just stumbled upon your blog from Google after I entered in, "Reply to comment | antforge.org" or perhaps something similar (can't quite remember exactly).
Anyways, I'm happy I found it because your content is exactly what I'm looking
for (writing a college paper) and I hope you don't mind if
I collect some information from here and I will of course credit you as the reference.
Many thanks.

You need to opt for the

You need to opt for the competent and qualitative tampon which will have to be dipped into yogurt.
It is important you recognize when you are having a bad day
and you do things which lift your spirits. Recently, the Ministry of
Health and other six (Bureau) jointly issued
a notice, said the only aloe vera gel product can be used
for food production, processing, and after September 1
this year, production and marketing with Kula Cable aloe gel
food must be marked "This product is aloe, pregnant women and infants and young children with caution,"
the words, and list of ingredients in the label, "Aloe vera gel.

Most of the girls are

Most of the girls are choosing the basic sheepskin slip shoes, as they
are comfortable and stylish. Bourne's President, Thomas Mc - Claskie, always uses his
creative imagery to make trendy shoes for men. Fresh pairs of UGG products arrive in latest designs and fake boots are replicas of these

One of the simple but genuine

One of the simple but genuine pleasures in life is getting up in the morning and hurrying to a mousetrap you set the night before. http://www.toolbox.com.ph

The people who cast the votes

The people who cast the votes decide nothing. The people who count them decide everything. http://www.toolbox.com.ph/

With great power comes great

With great power comes great responsibility.

Visit to purchase Computer

Visit to purchase Computer Cuisine Deluxe for $29.
Regardless of whether or not you love to cook, it really is crucial that each and every kitchen have a
decent kitchen cookware set readily obtainable. Stainless steel cookware with an aluminum or copper core is also good options
for saut.

The name of peace is sweet,

The name of peace is sweet, and the thing itself is beneficial, but there is a great difference between peace and servitude. Peace is freedom in tranquillity, servitude is the worst of all evils, to be resisted not only by war, but even by death.

Great guests to get a karaoke

Great guests to get a karaoke party are great, outgoing, and
they are willing to poke fun at themselves. There's a standard belief inside recording field that you'll be able
to record almost anything with it, also it still will sit right inside mix.
A countersink for recessing the heads from the screws will need to be
used in order to attain a finished product.

Now, if you are looking for

Now, if you are looking for such a brand, you should consider the Bourne shoes.
Thread and stitching - thread used in stitching is always the same as the colour of the leather.
Toe Size: The right shoe will not only fit well but will also be flexible
in the toe area, with enough space for your feet to relax, without
being pinched in very tight.

anti aging skin care A

anti aging skin care A 40-year-old patient with beautiful skin said to me: Everyone I know that has good skin wears sunscreen every day. My mom told me when I was young that I should wear sunscreen daily and I’m so glad I listened. She said, “I don’t tell you a lot of things, but you’ll regret lying in

A healthy low calorie diet

A healthy low calorie diet complemented with exercise has to be followed religiously, if you want to see the
effects of weight loss supplements. Aloe Vera- Aloe gel contains very large sugar
molecules called mucopolysaccharides. Thus, there are lots and loads of medicinal uses and
benefits of aloe vera and above mentioned are just few of them.

Howdy very nice blog!! Guy ..

Howdy very nice blog!! Guy .. Excellent .. Superb .. I'll bookmark your blog and take the feeds additionally?
I am glad to seek out numerous helpful info here within the submit, we'd like develop more techniques in this regard,
thanks for sharing. . . . . .

I want to upload file from my

I want to upload file from my aspx application to sharepoint. When i run the application from my local macine it works fine and the file gets uploaded. However when i publish the websites and run it from the server it gives error "Unauthorized

In this way, the hydroxyl

In this way, the hydroxyl radical is sort of nature's atmospheric "scrubbing bubbles. Anyway, these cleaners work by trapping the allergens and particles, so that clean air can return to the area where it is being used. It contains some robust pre-filter that makes purifying extra efficient.

Épluchez les poires et

Épluchez les poires et coupez-les en petits dés dans un bol. Placez 5 min au micro-ondes (plus si les cubes sont encore trop fermes). Videz le jus dégorgé. Laissez refroidir.