9

I'm having an issue in my Java application where the JIT breaks the code. If I disable the JIT, everything works fine, but runs 10-20x slower.

Is there any way to disable the JIT for a specific method or class?

Edit: I'm using Ubuntu 10.10, getting the same results both with:

OpenJDK Runtime Environment (IcedTea6 1.9) (6b20-1.9-0ubuntu1)
OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode)

and:

Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)
Ralf
  • 14,655
  • 9
  • 48
  • 58
  • Did you file a bug already? Or did you find an existing bug, which describes your problem? – soc Oct 23 '10 at 14:20
  • Sounds very unlikely that it's due to the JIT, no? Couldn't it be due to a race-condition (since the timing changes when you disable jit)... – aioobe Oct 23 '10 at 14:34
  • I'm only using a single thread. I'm busy looking into the bug, but don't really have the time right now. The bug occurs consistently after a specific method has been compiled by the JIT. For now I'm just setting the -XX:CompileThreshold option high enough. – Ralf Oct 23 '10 at 14:53
  • Have you tried a later version of the JDK ? – Romain Hippeau Oct 23 '10 at 16:13
  • 2
    Blaming the JVM should usually be pretty far down the list :) – bwawok Oct 23 '10 at 17:00
  • I'll see who's to blame later when I have the time, but for now disabling the JIT for a specific method makes my problem go away. – Ralf Oct 23 '10 at 17:23

2 Answers2

9

The following option works on my JVMs, to exclude a specific method:

-X:CompileCommand=exclude,the/package/and/Class,methodName
Ralf
  • 14,655
  • 9
  • 48
  • 58
  • 2
    Sun/Oracle Java 6 and above use `-XX:CompileCommand` option. See [`java` options for more information](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html), specifically for v8. – Alexey Ivanov Nov 10 '14 at 09:54
  • 1
    Sorry to dig up such an old post; if I were to use this with a named inner class would I delimit it as `com/domain/package/Outer/Inner` or `com/domain/package/Outer$Inner`? – nanofarad Feb 23 '15 at 00:24
  • I encountered the same problem today. After some experimenting, it seems that we should use `com/domain/package/Outer$Inner`. – TsReaper Dec 20 '18 at 03:44
6

Yes, there is one. You can supply the affected classes you want to exclude JIT compilation at start-up:

-Xjit:exclude={package/class.method|package/class.method}
soc
  • 27,983
  • 20
  • 111
  • 215