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.

Also, they have ruled the

Also, they have ruled the market due to their anatomical constructions of shoes that make the shoes anti-stress with special shock absorption system.
It compares the design of vintage motorcycles to today's models.
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.

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.

I love what youu ghys are up

I love what youu ghys are up too. Such clever work and
exposure! Keep up the fantastic works gguys I've you guyss to blogroll.

I am regular reader, how are

I am regular reader, how are you everybody? This piece of writing posed at
this web site is really nice.

The brand of Moda in pelle

The brand of Moda in pelle provides extremely stylish, durable and comfortable shoes.
You should always seek advice from someone who has
purchase the original boots before. Moccasin UGG slippers are quite popular among the
men.

Someone younger than me

Someone younger than me please describe this, because I simply noticed still
another sequel to some operation that is used.|a role that started back in 1997's The Dropped You can find multiple
Jurassic Park destinations at Universal Studios Hollywood, Countries of Adventure
in Orlando and Universal Singapore.

Also, they have ruled the

Also, they have ruled the market due to their anatomical constructions of shoes that
make the shoes anti-stress with special shock absorption system.
The Unitron website includes detailed description of
the features and benefits from this product. Wearing an elegant UGG boot with tight jeans can give you a classy
and beautiful look.

Otra de las opciones es el

Otra de las opciones es el Autozoom y el Zoom.

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.

It's great that you are

It's great that you are getting thoughts from this paragraph as well as from
our argument made at this time.

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
originals.

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.

Thamks to my father who

Thamks to my father who shared with me on the topic of this weblog,
this weblog is genuinely remarkable.

I likee reading through a

I likee reading through a post that ccan make people think.
Also, many thanks forr allowing for me to comment!

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.

Hello there I am so glad I

Hello there I am so glad I found your blog, I really
found you by accident, while I was researching on Bing for something else, Anyways I am here
now and would just like to say thanks a lot for a incredible post and a all round entertaining blog (I also love the theme/design), I don’t have time to look over it all
att the inute but I have book-marked it and also included your RSS feeds, so
when I have time I will be backk to read a great deal
more, Please do keep up the fantastic jo.

That is really interesting,

That is really interesting, You're a very skilldd blogger. I've
joined your rss feed and look ahead to seeking extra of your ggreat
post. Also, I've shared your website in my sociawl networks

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.

Desktop enthusiast haven't

Desktop enthusiast haven't been forgotten this year as many
home computers are included in the Black Friday sales from the big name stores.
When you enable Internet connection sharing on one, Windows disables
sharing on the other. This so-called minicomputer was useful when a microcomputer was not powerful enough and
yet a mainframe was too cost prohibitive, especially
in small offices and businesses.

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.

You can adopt their styles to

You can adopt their styles to suit yours;
this is one of the best ways to determine the right fashion for you.
Media doesn't really know how to handle it
and this was never more clear when we saw the Vogue Italia cover for June 2011.
The Fashion Industry is totally focused on how people look and larger people do not figure on mainstream fashion's radar.

É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.

There's certainly a lot to

There's certainly a lot to find out about this topic.

I like all of the points you have made.

Hey There. I foubd your blog

Hey There. I foubd your blog uusing msn. This is a very well written article.I will make sure to bookmark it and comme back to read more of your useful information.
Thanks for the post. I'll certainly comeback.