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.

Good post

Good post

Whitish often make you

Whitish often make you confused is not it? This type is often referred to as abnormal whiteness. Type of leucorrhoe is classified into the type of disease. Pathological vaginal discharge can affect women's health in general and especially health in feminine areas. Find out the solution use crystal x (english version include)for pregnancy and whitish programs. http://www.crystalxpedia.com/2016/03/benarkah-obat-crystal-x-aman.html

Pathological vaginal discharge occurs due to infection resulting in an increase in the number of premature babies, and in pregnant women (especially) infants born will also be affected by infection. Infants affected by viral infections have the potential to experience gastrointestinal indigestion and respiratory distress until it can cause death in these infants. Infants who are infected by bacteria even when living can be at risk of blindness. So use for solution problem your female organ, trush me by safety! http://www.crystalxme.net/2014/06/kupas-tuntas-manfaat-yang-terkandung.html

At this time I am ready to do

At this time I am ready to do my breakfast, later than having my
breakfast coming again to read other news.

Dapatkan produk chitosan

Oh thank you yes already

Oh thank you yes already provide this information. You are also very good at all has been posting this article. Very helpful for me.

http://Fleble.com Cara Cepat

http://Fleble.com Cara Cepat Baca Berita Berkualitas!
http://fleble.com/populer pencarian topik berita terpopuler
http://fleble.com/index index berita terkini
http://en.fleble.com/ english version
http://en.fleble.com/populer popular english version
http://en.fleble.com/index index english

Magnificent beat ! I wish to

Magnificent beat ! I wish to apprentice while
you amend your site, how can i subscribe for a blog web site?

The account aided me a acceptable deal. I had been a little bit acquainted
of this your broadcast offered bright clear concept

Thus you are allowed to enter

Thus you are allowed to enter the "Loop GIF animation" setting, so
that the final GIF will be animated forever.

To support this rising interest, research shows the highest number of online video watchers to be among the
young generation (pre-teens, teens, 20s, and 30s). Millions of people across the world
watch satellite TV and surf the net as well.

berita terkini dan terpopuler

berita terkini dan terpopuler di http://britau.com
indeks berita terkini di http://britau.com/index
nonton siaran langsung bola online di http://nobartv.com
nonton siaran tv streaming online di http://nobartv.com/tv-online
nonton jadwal siaran langsung live streaming liga inggris di http://nobartv.com/jadwal/9/liga-inggris
nonton jadwal siaran langsung live streaming liga italia di http://nobartv.com/jadwal/1/serie-a-italia
nonton live streaming siaran bein sports 3 di http://nobartv.com/tv-online/1/81/Bein-Sports-3
indeks berita bola terkini hari ini di http://nobartv.com/index-berita
kabar berita bola terkini dan terbaru di http://nobartv.com/beritabola
komunitas sepak bola online indonesia di http://soccerio.net

I recognized the main

I recognized the main difference in quality of work you provide me with a different end result, you might be now well-known blog similar to this, congratulations !!

You're so awesome! I don't

You're so awesome! I don't suppose I've truly read a single thing like that before.
So good to find another person with some original thoughts on this issue.
Really.. many thanks for starting this up. This site is something that is needed on the internet, someone with some originality!

I know this web site provides

I know this web site provides quality depending articles and
other data, is there any other site which presents such
data in quality?

With great power comes great

With great power comes great responsibility.

This silly warm-up running

This silly warm-up running activity will get their hearts
pumping and teach a valuable lesson in listening.
(2010). The swinging motion should not be directed from the hips, but the foot joints.

They have several advantages

They have several advantages in their favor. Bundles.

If you have decided to buy the HP Pavilion p7qe, you should know
that there are many discount offers present.

Thanks , I've recently been

Thanks , I've recently been searching for info about this
subject for ages aand yours is thhe greatest I've discovered
so far. But, what inn regards to the conclusion? Are you certain concerning the source?

An impressive share! I've

An impressive share! I've just forwarded this onto a friend who
was doing a little research on this. And he actually bought me dinner because I discovered it for him...
lol. So allow me to reword this.... Thajk YOU for the meal!!
But yeah, thanks for spending tiime to talk about this issue here on your blog.

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.

Thanks in support of sharing

Thanks in support of sharing such a nice idea, post is fastidious, thats why i have read
it fully

cheap jerseys usa Patrriots

cheap jerseys usa Patrriots store wholesale nfl jerseys

Weight Loss High 20 Herbs for

Weight Loss High 20 Herbs for Weight Loss
- Healthmeup cambogia extract right manner weight loss
herbs that basically work fats&nbsp.