在运行时获取 JVM 编译器阈值

Get the JVMs compiler-threshold during runtime

是否可以在运行时获取 JVM CompileThreshold 的当前值?

如果它是手动设置的,我可以从 VM Arguments 中获取它。否则,我可能会采用默认值(例如,服务器上的 Oracles HotSpot 为 10,000),但这可能不正确。有没有更好的办法?

目的是"preheat"启动时的一些功能。

您可以从 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());
}

输出

CompileThreshold = 10000