4

The problem i'm interested in at the moment is profiling/optimizing some piece of code. General recommendation for profiling with Java is "run", "wait for some time for hotspot JIT compiler to do its job", "repeat the test" ...

So the questions are

  • how long shoud I wait for hotspot to start and complete its job?
  • will JIT run while CPU is rather saturated (by other threads)? - it may happen in real life that process constantly loads CPU up to 100%.
  • how many executions of the same piece of code is needed to identify the "hot spots"?
  • is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?
4
  • You're probably better off using a pre-built framework to deal with all of these problems, like Caliper. Jan 28, 2013 at 20:50
  • 1
    try JMH(Java Microbenchmark Harness) tutorials.jenkov.com/java-performance/jmh.html
    – D3Hunter
    Jun 14, 2017 at 16:16
  • @LouisWasserman Caliper was proven to be incompetently designed by Google. It just can't deal with OSR gracefully. JMH is the golden standard of microbenchmarking in Java. Dec 2, 2020 at 12:01
  • @WojciechKudla: at the time that comment was written, JMH had not even had an 0.1 release. I agree JMH is the golden standard today. Dec 2, 2020 at 18:10

1 Answer 1

0

how long shoud I wait for hotspot to start and complete its job?

About 10,000 calls/iterations and a few milli-seconds.

will JIT run while CPU is rather saturated (by other threads)? - it may happen in real life that process constantly loads CPU up to 100%.

Yes, it may take longer, but performing test at 100% of CPU it's usually a good idea as the results are less likely to be representative of what you would do in production.

how many executions of the same piece of code is needed to identify the "hot spots"?

I would wait until the code has warmed up where possible. Realistic test data, a few seconds at high CPU utilisation and a decent profiler is usually enough.

is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?

Other than running it enough times no. Compiling the class too early can lead to sub-optimal code. The code is optimised based on how it is used. JRockit (which is also owned by Oracle) has/had such a feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.