Eager java class loading

Tags:



I’m trying to do some benchmarking of JVMs running on various hardware and OS platforms. I’ve created an algorithm to exercise the parts of the JVM I’m interested in and intend to run this algorithm many times to find a decent average.

When I run the benchmark, I find that the first run is significantly longer than subsequent runs:

132ms
86ms
77ms
89ms
72ms

My suspicion is that classes are loaded lazily, putting a large overhead on the first run. While this is indeed a feature that I assume is unique to each JVM, it’s not one I’m interested in at this point.

Is there a standard command line option or property to eagerly load classes? or does anyone have any other theories?

Answer

The simplest thing to do is ignore the first run. (If that is a valid thing to do) Note: if you run the same code 10,000 times, it will compile the code further and you get better results, so you might want to ignore the first 10K results for some micro-benchmarks.

Some JVMs support eager loading but I don’t think Sun’s JVM does.

JWrapper support AOT https://www.jwrapper.com/features



Source: stackoverflow