Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JIT and related doubts.  RSS feed

 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have some doubts regarding JIT.I have read some materials but still could not get a clear picture of JIT and how it works.

Is this something that is there in java.exe and converts codes to native when it feels like any method is complex(like having more of loops).Do we need to enable JIT in the runtime system.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double post
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you say is correct.

You know how Java works: the Java compiler compiles your source code to bytecode, which is a kind of platform-independent machine code. To run the bytecode, you need an interpreter that reads and executes the bytecode instructions on the processor that it's running on.

The JIT is what its name says it is: the Just In Time compiler. It compiles Java bytecode to native machine code at runtime.

If you have a program with a loop that is executed many times, it would be a big waste of processing power if the bytecode in the loop has to be interpreted again and again, in every iteration of the loop. So, what the JIT does is compile the bytecode to native machine code instructions once, and then runs that native code directly.

You don't need to enable the JIT; it is by default enabled when you run a Java program. I don't think it is even possible to disable it (I don't see any switch for java.exe to do that).

How and when the JIT decides to compile bytecode to native code is an implementation detail; you don't need to worry about that and probably there is no documentation that explains in minute detail how it works (well, you could look at the source code of Sun's JVM if you really would want to know...).
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jasper.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
You don't need to enable the JIT; it is by default enabled when you run a Java program. I don't think it is even possible to disable it (I don't see any switch for java.exe to do that)


Java 1.3 used to ship with a JVM called "classic", which was an alternative to "hotspot". I believe the former did not have JIT and the latter did.

Later Java does not seem to come with a "classic" JVM. You get "client" and "server", both of which have JIT.

Maybe, if you use the compiler switches to generate class files compatible with 1.3, you could run your later code with "classic". Not sure if that would work. Not sure either why one would want to do it, except to see how darn slow it runs!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!