Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JIT

 
Joanne Fire
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using JIT, will I compile as fast as C++? If I understand correctly, we still have another step to do compared to the C++ complier. My question would be, how would compiling it on the fly/dynamically make it faster than without the JIT?
 
Brian Daniel
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Hotspot JIT calculates on the fly which bits of code are to be used more frequently and only spends time compiling those, the rest of the one-hit-wonder pieces of code are interpreted still.
 
Mark Herschberg
Sheriff
Posts: 6037
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will it compile as fast as C++? I don't know, I've never heard of any tests of compilers. In terms of run time performence, they will be comporable in most cases (your specific milage may vary).
Remember that most byte code is interpreted. The byte codes is run by the JVM. JVM actions are performed by a sequence of native instruction calls (i.e. OS/chipset calls). When a set of calls get compiled directly to native code, that set runs faster, b/c you removed a level of indirection (it's somewhat analogous to inlining a method call). Of course, there is an up front performence penalty for doing the actual compilation.
Note that most JITs run in two modes, client and server, to reflect the different behavioral patterns of each type of application.

--Mark
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing that limits Java performance, compared to something like C, is its greater run-time checking of operations. For instance, Java always checks for attempts to read/write off the end of an array or String. C compilers typically either do not check or, depending how the code is written, cannot check such things. Thus the Java is potentially more stable, and certainly easier to debug, but the C has the potential to be faster.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
One thing that limits Java performance, compared to something like C, is its greater run-time checking of operations. For instance, Java always checks for attempts to read/write off the end of an array or String. C compilers typically either do not check or, depending how the code is written, cannot check such things. Thus the Java is potentially more stable, and certainly easier to debug, but the C has the potential to be faster.

On the other hand, the hot spot engine may remove these checks, if it analyzes that they aren't necessary. In fact, the dynamic optimization at runtime performed by the hotspot engine can lead to better performance in some areas as the static optimization of other compilers would be capable of.
 
Joanne Fire
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thank you all, Brian, Mark, Ilja, Peter for your input, all these explanations really allowed me to understand this more clearly, you are all great! Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic