1

Is it possible to get the current value of the JVMs CompileThreshold during runtime?

If it was set manually I can get it form the VM Arguments. Otherwise I may assume default values (e.g. 10,000 for Oracles HotSpot on Servers), but this might not be correct. Is there are better way?

The purpose is to "preheat" some functions during startup.

Community
  • 1
  • 1
MyPasswordIsLasercats
  • 1,610
  • 15
  • 24
  • You can call the functions with appropriate parameters to pre-compile it. But the function may be recompiled later depending on call parameters. "preheat" is only useful for benchmarking. You should avoid all the magic for a normal application. It may complicate the code and dependencies but does not really improve the applications performance. – Konrad Jul 31 '15 at 09:33
  • Hi @Konrad. Your guess is correct: It's for a toolbox that should help to measure performance. – MyPasswordIsLasercats Jul 31 '15 at 15:29

1 Answers1

3

You can retrive this information from the HotSpotDiagnosticMXBean.

static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";

public static void main(String[] args) throws Exception {
    Class clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    HotSpotDiagnosticMXBean bean = (HotSpotDiagnosticMXBean) ManagementFactory
            .newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME, clazz);
    VMOption vmOption = bean.getVMOption("CompileThreshold");
    System.out.printf("%s = %s%n", vmOption.getName(), vmOption.getValue());
}

output

CompileThreshold = 10000
MyPasswordIsLasercats
  • 1,610
  • 15
  • 24
SubOptimal
  • 22,518
  • 3
  • 53
  • 69