Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hotspot JIT optimizations

In a lecture about JIT in Hotspot I want to give as many examples as possible of the specific optimizations that JIT performs.

I know just about "method inlining", but there should be much more. Give a vote for every example.

like image 573
Artiom Gourevitch Avatar asked Oct 21 '11 20:10

Artiom Gourevitch


3 Answers

Well, you should scan Brian Goetz's articles for examples.

In brief, HotSpot can and will:

  1. Inline methods
  2. Join adjacent synchronized blocks on the same object
  3. Eliminate locks if monitor is not reachable from other threads
  4. Eliminate dead code (hence most of micro-benchmarks are senseless)
  5. Drop memory write for non-volatile variables
  6. Replace interface calls with direct method calls for methods only implemented once

et cetera

like image 114
alf Avatar answered Oct 22 '22 19:10

alf


There is a great presentation on the optimizations used by modern JVMs on the Jikes RVM site: ACACES’06 - Dynamic Compilation and Adaptive Optimization in Virtual Machines

It discusses architecture, tradeoffs, measurements and techniques. And names at least 20 things JVMs do to optimize the machine code.

like image 27
Patrick Avatar answered Oct 22 '22 17:10

Patrick


I think the interesting stuff are those things that a conventional compiler can't do contrary to the JIT. Inlining methods, eliminating dead code, CSE, live analysis, etc. are all done by your average c++ compiler as well, nothing "special" here

But optimizing something based on optimistic assumptions and then deoptimizing later if they turn out to be wrong? (assuming a specific type, removing branches that will fail later anyhow if not done,..) Removing virtual calls if we can guarantee that there exists only one class at the moment (again something that only reliably works with deoptimization)? Adaptive optimization is I think the one thing that really distinguishes the JIT from your run of the mill c++ compiler.

Maybe also mention the runtime profiling done by the JIT to analyse which optimizations it should apply (not that unique anymore with all the profile-guided optimizations though).

like image 45
Voo Avatar answered Oct 22 '22 18:10

Voo