[ImageJ-devel] How does the JVM/JIT work?

Johannes Schindelin Johannes.Schindelin at gmx.de
Mon Nov 26 14:56:01 CST 2012


Hi,

in a recent discussion revolving around the performance of ImgLib2, the
question came up where to find a good documentation about the Just In Time
("JIT") compiler of Oracle/Sun's Java Virtual Machine ("JVM"). As it
happens, I just stumbled over this:

http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals

It explains more than the JIT, and is a bit short on the details about the
Just In Time compiler, so let me add a bit more information from the top
of my head:

Sun's own implementation of a Just-In-Time compiler (called "Hotspot") was
introduced after the Kaffe project showed how much more performant Java
can be when methods are compiled to native code.

A major boost in Hotspot technology came with Java 5. This came most
likely in response to IBM's Jikes RVM, an experimental Java Virtual
Machine invented to do research on virtual machines.

Again a major improvement in Hotspot technology came with Java 6.

The principle is easy: very simple statistics are recorded whenever the
virtual machine interprets the bytecode. Whenever a certain threshold is
reached (in Oracle/Sun's Java 6, you can configure this with the
-XX:CompileThreshold command-line option), the method is compiled to
native code before being executed.

Since the statistics are crucial in determining how much to inline code
(which was so far the major benefit of Java over C++: it can inline code
after the fact, something C++ learnt with the advent of the Clang module
to LLVM: http://clang.llvm.org/cxx_status.html), that seems to be where
the improvements in Java 6 came from.

Of course, you do not want to acquire too many statistics, otherwise the
statistics themselves will provide an undesired performance bottleneck.

The major improvement in Java 7 is that the statistics continue to be
acquired after compiling methods into native code so that subsequent
further optimization is possible.

It is a major shame that we cannot require Java 7 in Fiji due to the Apple
issue: only the latest and greatest MacOSX versions (which do not even
support the PowerPC computers sold by Apple a scant 6 years ago!) can run
Java 7, and reports state that it is not as stable as Java 6 used to be
(except for that AWT issue http://fiji.sc/bugzilla/show_bug.cgi?id=197).

Ciao,
Dscho



More information about the ImageJ-devel mailing list