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.
-
You want to check this at runtime?Louis Wasserman– Louis Wasserman2012年02月26日 21:38:54 +00:00Commented Feb 26, 2012 at 21:38
-
Yes, I would like to check it at runtime.isaiah– isaiah2012年02月26日 21:48:04 +00:00Commented Feb 26, 2012 at 21:48
-
1Maybe I should also add why I am doing this. Basically, we have a program that's meant to time how long it takes to run an algorithm (e.g. quicksort) based on the size of the data. What we noticed was that the first two times are really skewed compared to the other results and we are of the opinion that this is due to the initialisation of the JIT compiler. As a result, we wanted to see the effect on the times when the JIT is off.isaiah– isaiah2012年02月26日 21:50:22 +00:00Commented Feb 26, 2012 at 21:50
-
It is not really a boolean thing, methods get optimized and deoptimized in different tiers. It is best to use a benchmark harness which supports warmup. I would use JMH. It even has compiler control annotations.eckes– eckes2016年01月29日 11:20:03 +00:00Commented Jan 29, 2016 at 11:20
-
Another reason to check at runtime, I have an application that appears to switch to interpreted only mode after a certain point in time. I have tracked down a JIT bug (bugs.java.com/bugdatabase/view_bug.do?bug_id=8023983) that appears to be related. I want to know if something has "whomped" memory and overwritten that flag.pojo-guy– pojo-guy2019年01月16日 20:13:42 +00:00Commented Jan 16, 2019 at 20:13
5 Answers 5
(Not a direct answer to your question since it seems your were trying to turn off the JIT compiler programmatically, but based on your comment, this might be of interest.)
If you want to turn off the JIT compiler on a Sun/Oracle JVM, you should try the -Xint option:
-Xint
Operate in interpreted-only mode. Compilation to native code is disabled, and all bytecodes are executed by the interpreter. The performance benefits offered by the Java HotSpot Client VM's adaptive compiler will not be present in this mode.
3 Comments
javac: invalid flag: -Xint.java -X in Oracle JRE 8. Whether or not to use the JIT compiler is a JRE decision, this has nothing to do with compiling the source code into bytecode (what javac does): you're probably getting this error because you're using it with javac not java.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.
4 Comments
In the article Performance Features and Tools.
The JIT compiler was first made available as a performance update in the Java Development Kit (JDK) 1.1.6 software release and is now a standard tool invoked whenever you use the java interpreter command in the Java 2 platform release.
You can disable the JIT compiler using the
-Djava.compiler=NONEoption to the Java VM.
So, you can deduce that when the variable is not set, or set to something other than NONE, then the JIT is enabled.
1 Comment
IBM JVMs definitely support the Java interface java/lang/Compiler.disable() and .enable() which was introduced in Java 5, I believe. That includes WebSphere Real Time (which is a JVM designed to provide more predictable performance) as well as our "standard" JVMs. If you call disable(), it will prevent JIT compilations until you call enable().
I work for IBM on the JIT compiler team. We don't usually recommend people to use this interface, because interfering with JIT compilation heuristics is generally not a good idea, but there are reasonable real-time scenarios where you would use it.
Comments
You can printout methods when they get compiled, with `-XX:+PrintCompilation if your method isn't printed out or suddenly gets faster after it is print out, you can see the likely cause.