javajit

How to check if the JIT compiler is off in Java


I would like to know how to check if the JIT compiler is turned off. I have the following code which is meant to turn the JIT compiler off.The problem is, I am not sure if it is actually doing that. So I was wondering if there is a way of checking if the JIT is off. I looked at the Compiler class but there isn't any method like isDisabled/enabled().

Code:

Compiler.disable();  

Any help or direction will be highly appreciated.


Solution

  • I don't believe you can turn the JIT off at runtime.

    If you want to seriously benchmark a Java program, you should definitely be ignoring the first few runs. Getting reliable benchmarks in Java is an extremely tricky business, best left to people much smarter than you or I.

    I recommend using Caliper, which is used internally at Google for microbenchmarking and is plenty smart about warming up the JIT and stuff. In particular, look at the example here, which shows how to measure the efficiency of an algorithm for different input sizes.