Jit compiler

Search This thread

robin04

Senior Member
Jan 14, 2010
365
0
Padova
This thread has been opened for those who are curious to know how the compiler "just in time".

Functional characteristics in general:

The JIT compiler translates bytecode into native machine code at runtime. This compilation process (also known as dynamic translation) is executed only once, and creates a link between the bytecode and the corresponding compiled code. The purpose of this process is to increase the speed in which to run Java programs.
A JIT compiler is based on two concepts in the recent run-time environments: bytecode compilation and dynamic compilation.
In a system for compiling bytecode as Perl, GNU, Java, etc.. The source code is translated into an intermediate representation known as bytecode. The bytecode is then interpreted or executed in a virtual machine (VM).
In a JIT environment, the first phase is the compilation of bytecodes, which transforms the source code in a portable and optimized intermediate representation, called bytecode. Subsequently, the byte code is installed on the target system. When the code is executed, the compiler execution environment translates into native machine code. The translation into machine code can occur for files or function: the functions can only be completed when they are to be executed, hence the name "just-in-time
The just-in-time compilation allows a good compromise between execution speed and code portability. During the compilation of the bytecode is executed most of the "heavy work", ie all those operations that require a long time to run, as the syntactic and semantic analysis of source code and a first phase of optimization, the compilation from bytecode to native code is much faster.


In particular for android devices:

Here some information on the operation related to android
Essentially, Java is usually translated from source to Java bytecode (an intermediate step between Java itself & processor specific machine code) when the app is compiled. When it is executed, this bytecode has to be interpreted into machine code. What JIT does is cache the results of such interpretation, so that, for example, if a particular section of bytecode is executed multiple times, it will only have to be interpreted that first time. JIT for Java has been around for a good while.
Android uses their own special Java Virtual Machine, which we hear of often - the Dalvik Virtual Machine. This works on similar principles to a typical JVM, but it produces a type of intermediate bytecode that is optimised for execution on devices with limited resources. This code, incidentally, is called a Dalvik Executable, which explains all the .dex sufficies in Android.
As this Dalvik Virtual Machine is relatively new, the further refinement of just in time compilation for it is only now reaching a stage where it's production ready - or at least hopefully will be soon. All pretty exciting as it can boost performance by around 200-300%
 
Last edited:

robin04

Senior Member
Jan 14, 2010
365
0
Padova
No, not really. I'm missing the point of this post :). Is it a question, is it ment as an answer somewhere else? Did you click on 'post new topic' instead of 'post reply' somewhere?

is not difficult to understand.
I just opened a new thread to explain how the JIT.
Who is curious to know how can read the thread.
Anyway thanks for the comment. I'll do some changes to the thread to clarify the reason for its existence.
 

kieranc

Senior Member
Feb 9, 2008
321
48
No, not really. I'm missing the point of this post :). Is it a question, is it ment as an answer somewhere else? Did you click on 'post new topic' instead of 'post reply' somewhere?

It's only useful if you realise you don't know what JIT is ;)
I now have a better understanding of how it works, thanks!
 

MerXury13

Senior Member
Jan 23, 2010
158
21
why is it so difficult to bring this to a hero rom? the JiT compiler by google seems to be nearly ready ...:confused:
 

FunkTrooper

Senior Member
Nov 30, 2009
112
4
Forgive my ignorance, but I thought this was how Android apps always work — they come as bytecode and the phone translates them into native code when needed... right?

How else does it work?
 

cauli

Senior Member
Mar 7, 2010
320
0
Here's some info on JIT & here's how it pertains to Android :)

Essentially, Java is usually translated from source to Java bytecode (an intermediate step between Java itself & processor specific machine code) when the app is compiled. When it is executed, this bytecode has to be interpreted into machine code. What JIT does is cache the results of such interpretation, so that, for example, if a particular section of bytecode is executed multiple times, it will only have to be interpreted that first time. JIT for Java has been around for a good while.

Android uses their own special Java Virtual Machine, which we hear of often - the Dalvik Virtual Machine. This works on similar principles to a typical JVM, but it produces a type of intermediate bytecode that is optimised for execution on devices with limited resources. This code, incidentally, is called a Dalvik Executable, which explains all the .dex sufficies in Android.

As this Dalvik Virtual Machine is relatively new, the further refinement of just in time compilation for it is only now reaching a stage where it's production ready - or at least hopefully will be soon. All pretty exciting as it can boost performance by around 200-300% :D

HTH
 
Last edited:

robin04

Senior Member
Jan 14, 2010
365
0
Padova
Here's some info on JIT & here's how it pertains to Android :)

Essentially, Java is usually translated from source to Java bytecode (an intermediate step between Java itself & processor specific machine code) when the app is compiled. When it is executed, this bytecode has to be interpreted into machine code. What JIT does is cache the results of such interpretation, so that, for example, if a particular section of bytecode is executed multiple times, it will only have to be interpreted that first time. JIT for Java has been around for a good while.

Android uses their own special Java Virtual Machine, which we hear of often - the Dalvik Virtual Machine. This works on similar principles to a typical JVM, but it produces a type of intermediate bytecode that is optimised for execution on devices with limited resources. This code, incidentally, is called a Dalvik Executable, which explains all the .dex sufficies in Android.

As this Dalvik Virtual Machine is relatively new, the further refinement of just in time compilation for it is only now reaching a stage where it's production ready - or at least hopefully will be soon. All pretty exciting as it can boost performance by around 200-300% :D

HTH

Thanks for the deepening. Add this post to the first ;)
 

foxmeister

Senior Member
Mar 10, 2008
4,035
383
Ealing
Forgive my ignorance, but I thought this was how Android apps always work — they come as bytecode and the phone translates them into native code when needed... right?

How else does it work?

In a typical Java environment, without JIT, the application is always interpreted. This makes the applications exceptionally portable, since the underlying architecture (CPU instruction set etc) is largely immaterial.

In a JIT environment, some or all of those bytecodes (as JIT usually works by method) are compiled directly down to native code as the application is run (hence Just-In-Time). Some or all of the application then effectively becomes a native application targeted at a specific architecture rather than an fully interpreted application.

Simplistically, the net result is that a JIT-compiled app is usually slower to start, but faster to run.

See here for some details of Android JIT compilers.

On a related note, not all Android applications are fully interpreted java anyway. If an application uses the NDK, portions of it may be written as native code (see here).

Regards,

Dave
 

tomfreay

Senior Member
Sep 5, 2008
143
0
Interesting thread, one thing I don't know is if the native code produced by JIT is just cached or stored? Ie if its cached, starting an application will take a while the first time, then really quick the second time until that app is taken out of the cache

Or is it that the JIT native code replaces the java on that device, so once run, its always quicker even if the phone is rebooted etc?
 

cauli

Senior Member
Mar 7, 2010
320
0
Interesting thread, one thing I don't know is if the native code produced by JIT is just cached or stored? Ie if its cached, starting an application will take a while the first time, then really quick the second time until that app is taken out of the cache

Or is it that the JIT native code replaces the java on that device, so once run, its always quicker even if the phone is rebooted etc?

Aiui the cache exists in memory purely for the duration of the program's execution & hence is recomputed everytime the program is run. This is consistent with a discussion I found after a quick google where some posters ask why isn't it stored longer term. You might find it interesting, though note being a forum thread one can't rely on its accuracy ;)

Note, this is not to be confused with the Dalvik cache in which some optimisations are performed on the .dex when an app is first run (or in the case of system apps, in advance - this is what the .odex files are). I /think/ & this is speculative on my part, there might be some overlap in the types of optimisations but essentially, the Dalvik cache optimisations are less far reaching than JIT's & still result in Dalvik bytecode (more or less) unlike JIT.

I probably can't add anymore as that's pretty much all I know at the moment. Adding guesswork isn't going to do much for the archival value of this thread.
 

tomfreay

Senior Member
Sep 5, 2008
143
0
Interesting read, thanks for posting that. Will be really interesting to see what practical benefits this brings to Android.
 

terryazthompson

Senior Member
Nov 21, 2009
65
0
Just curious of the versions of JIT. Correct me and enlighten me if you can...

JIT is being developed by google and IS or WILL BE open sourced?

The code being currently used in ROMs is not a final version?

How often has this code been updated. Has it been just one release or is google (or others) releasing more often?

Thanks if you can help me.
 

cauli

Senior Member
Mar 7, 2010
320
0
JIT is being developed by google and IS or WILL BE open sourced?
I think JIT will be a part of the Froyo (Android 2.2) imminent(ish) release & is subject therefore to the same release policy, ie code developed behind closed doors with periodic releases of new versions in source code form under an open license, E&OE, aiui (posting as no one else has replied).