4

Is it possible to change options and/or modes of Java JVM (JIT) at runtime? E.g. change XX:CompileThreshold, or even switch between interpreted and compiled code (-Xcomp vs -Xint).

My JVM is from OpenJDK (1.6), Hotspot or Zero/Shark

osgx
  • 90,338
  • 53
  • 357
  • 513

2 Answers2

7

You cannot change the JVM mode at runtime, however you can modify some flags without restarting the JVM. Just connect to the JVM using a JMX client (like VisualVM) and use the operation setVMOption of com.sun.management:type=HotSpotDiagnostic.

For instance, if you want to enable detailed GC logging without restarting the JVM, call the method setVMOptions("PrintGCDetails", "true").

Source : http://docs.oracle.com/javase/6/docs/jre/api/management/extension/com/sun/management/HotSpotDiagnosticMXBean.html#setVMOption%28java.lang.String,%20java.lang.String%29

Hope that helps !

Pierre Laporte
  • 1,205
  • 8
  • 11
  • Can I change at runtime the JVM Mode: Interpreter or JIT; or some JIT heuristics (e.g. -XX:CompileThreshold)? – osgx Jun 02 '13 at 22:07
3

You can change some of those settings through MBeans.

Most of them are read-only though.

jontejj
  • 2,800
  • 1
  • 25
  • 27
  • Do you have any links to Sun/Oracle site? – osgx May 31 '13 at 15:03
  • And you are sure that jvm options can't be changed at runtime? – osgx May 31 '13 at 15:14
  • 1
    Looking at http://stackoverflow.com/questions/1754077/setting-jvm-parameters-at-runtime suggests that com.sun.management.HotSpotDiagnosticMXBean#setVMOption(String, String) could help you. But in general I wouldn't rely on it. – jontejj May 31 '13 at 21:14