tags:

views:

200

answers:

4

Here's a phrase that I heard a lot throughout high school and university computer science classes:

"That's not an issue for modern JVMs."

Usually this would come up in discussions about overall performance or optimization strategies. It was always treated as a kind of magical final answer, though, as if it makes issues no longer worth thinking about. And that just leads me to wonder: what are the differences between the prototypical "modern JVM" and older JVMs, really?

+6  A: 

The most significant improvement in JVM technology is the JIT: Just In Time compiler. The JIT optimizes the code as it runs, thereby producing huge performance gains which makes Java (at least in some domains) competitive with C/C++ programs.

An interesting discussion regarding the benefits of dynamic optimization (as the code runs) vs. static optimization (during compilation) can be found in Steve Yegge's talk: http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html (which, BTW is interesting in its own right).

Other JVM improvements, which are not entirely unrelated to JIT, is faster dispatch of virtual methods, both for class methods and interface methods.

Itay
+6  A: 

Uncontended synchronization used to be slow.
Garbage collection has gotten a lot faster.
Hotspot optimization has gotten better.
Some really old JVMs had green threads exclusively.

Nathan Hughes
I was going to say that the 'modern JVM' is more of a statement about the poor performance of proto-JVMs than a statement about the current generation
Jherico
+1  A: 

A modern JIT can aggressively optimize machine code based on profiling information and other information derived from the byte code:

  • Machine code can be generated with an optimization level derived from the expected usage (it WAS used a lot, perhaps it will be used even more). This helps a lot!
  • Calls to object.getFoo() can be inlined so the contents of the method is placed directly in the generated code without the method call. This can be done recursively, and may result in complex code being replaced with just the few instructions actually done.
  • Garbage collection has improved immensely. This means in much time not being spent.
Thorbjørn Ravn Andersen
+1  A: 

Related question that explains the garbage collection bit in more detail:

http://stackoverflow.com/questions/2931170/does-variable-null-set-it-for-garbage-collection

Lord Torgamus