This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JIT Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JIT Question" Watch "JIT Question" New topic

JIT Question

Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
I was reading about the JIT compiler from an earlier post and followed on one of the links. I have a few questions regarding the JIT.
1. Does the JIT come with every JVM for all platforms i.e. is the JIT a part of the JVM.
2. What do they mean that 'if the JIT is present, the code will run faster' - if the JIT is a part of JVM, then won't it always be present. Can you separate it from the JVM and if so, why would you do that.
3. Using JIT the code runs faster because the JVM passes the .class file to the JIT. Does not not create a delay and slow the execution process because now first the JVM will parse the bytecode and then the JIT will execute it in the native code. Isn't there a performance issue here.
4. How would you know if you have a JIT installed and how would you know it is being called.
I apologise if these questions seem trivial but I'm starting off new in Java.
Thanks In Advance,
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250

I can't answer all of your questions however basically two forms of java exist. The first is a JRE which is the Java Runtime Environment. This would be installed on the client or end-user pc. I don't believe the compiler exists in this environment. Secondly you can have the JSDK, which is the Java Software Developer's Kit, this obviously is used by the developer and would contain the compiler along with the additional tools and features. You might look at and see if you can find a feature list between the two installations.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Actually, the JIT Compiler or Just In Time Compiler has been a core part of Sun's VM for a while.
(I think) Prior to 1.3, JIT had to be switched on when executing a Java Application and I think there may have been a checkbox for it in IE settings.
However, 1.3 and up default to using JIT. There is of course a switch to turn it off if you want to.

GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I just found the below simple explanation from here

You first run "javac", the Java Compiler, which turns the Java code into what is known as "bytecodes" and puts them into the "hello.class" file. This class file can then be interpreted on any machine which has a Java Virtual Machine on it. The key word here is "interpreted". The Java Virtual Machine processes each of the bytecodes in the .class file and executes them. This is similar to what other interpreted languages do, such as Basic, LISP, and Smalltalk.
When a JIT is present, the Java Virtual Machine does something different. After reading in the .class file for interpretation, it hands the .class file to the JIT. The JIT will take the bytecodes and compile them into native code for the machine that you are running on. It can actually be faster to grab the bytecodes, compile them, and run the resulting executable than it is to just interpret them. The JIT is an integral part of the Java Virtual Machine, so you never notice it's there, except your Java runs faster. Some environments allow you to choose whether or not to JIT code.
Java is a dynamic language, so you are not allowed to "statically" compile all the .class files into machine code until they are actually called. Thus the JIT is really "just-in-time", since it compiles methods on a method by method basis just before they are called. If you call the same method more than once, the JIT'd code can really pay off as you do not have to re-JIT the method and can simply re-execute the native code.
Does it make sense to always JIT code? No, not always. Sometimes JIT'd code does not run any faster than interpreted code. If the Java Virtual Machine is not spending its time interpreting bytecodes, then JIT'ing the bytes codes will not speed things up. Although it is rare, things might slow down since you are spending the time compiling the bytecodes when you could have been interpreting them.
I agree. Here's the link:
subject: JIT Question
It's not a secret anymore!