MyPasswordIsLasercats
MyPasswordIsLasercats

Reputation: 1630

Get the JVMs compiler-threshold during runtime

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.

Upvotes: 1

Views: 415

Answers (1)

SubOptimal
SubOptimal

Reputation: 22973

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

Upvotes: 3

Related Questions