JIT Compiler


  • Although Java is interpreted, Just-In-Time compilers provide "client-side" compilation of byte-codes to machine code (native binary)

  • This provides
    • Improved performance
    • Better match to specific hardware


Detailed Description:

"So how can we improve the performance of Java compared to native code? Let's look at the Just In Time (JIT) compiler. While the JIT technology is not new, its development for Java is rather new.

A Just In Time compiler gets invoked when the byte codes are loaded into your Java virtual machine. These byte codes are platform neutral. A Just In Time compiler takes over, takes the byte codes, and converts them into native codes. It converts byte code, which is pseudo machine code, into native machine code for that platform. This can improve the performance of Java code running on a particular platform. The general feeling is that Java code going through a JIT is about three to five times slower than native code. That's a factor of ten improvement. It still does take some time to actually execute, but it's getting much closer to C and C++ native code performance times.

There is one other point to make. During their build process, most developers producing C and C++ code have to compile their product to execute on a particular machine architecture. They do this in the development shop. When I get their code on my machine, I don't have any opportunity to change what architecture they compiled for during development.

So, for example, let's say that I have a Pentium machine. The original development team wanted to fit the widest marketplace, and they compiled their code to run on a 386 machine. So when it actually runs on my Pentium machine, it still runs as 386 code. That's what's happening in the industry today for most people. The greatest common denominator in the marketplace today for Intel architecture is the 386. So the largest market is 386, then 486, and to a lesser extent, Pentium.

Now, let's look at it with Java. With Java, we actually compile to byte code, and that byte code is platform independent. We download it, using whatever means necessary, let's say the Internet, and it's on our machine. When it's received on our machine, that's when it's going to be compiled using a Just In Time compiler. The JIT compiler can actually check the architecture of my machine before it starts to compile. It can determine that I've got a Pentium machine, and so the JIT can compile the byte code directly to Pentium code using whatever optimizations and benefits the Pentium architecture has. Thus there is a potential that the Java code that's just in time compiled on a Pentium machine could actually be faster than the C code originally compiled for 386 architecture. I do not have any specific instances where this is taking place, but the potential is there."