Is there a way to show the flags used in the running JVM?

Although we have explicitly set several JVM flags for our applications, it is very difficult to understand if: 1. Boolean flags are already enabled by default (defaults changed between minor JDK / JRE updates) 2. One flag negates the other 3. What is the default for of a given arbitrary flag is on your specific systems (given by Java ergonomics)

To summarize: Is there a command line tool similar to

java -XX:+PrintFlagsFinal

      

where can I check the values ​​of all flags for an already running JVM?

+3


source to share


3 answers


For HotSpot, you can use (from ehcache)



private static String getHotSpotVmOptionValue(String name) {
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName beanName = ObjectName.getInstance("com.sun.management:type=HotSpotDiagnostic");
        Object vmOption = server.invoke(beanName, "getVMOption", new Object[] {name}, new String[] {"java.lang.String"});
        return (String)((CompositeData)vmOption).get("value");
    } catch (Throwable t) {
        return null;
    }
}

      

+4


source


You are looking for jinfo . It allows you to view and set JVM flags from the command line. It is one of the many widely unknown "Tools and Utilities" for the JVM.



+1


source


This method applies to any java application running locally or remotely.

  • Start your Java application.
  • Run JVisualVM found in you JDK (e.g. C: \ Program Files \ Java \ jdk1.8.0_05 \ Bin \ jvisualvm.exe)
  • When this useful tool starts to view the list of running Java applications under the "local" tree node.
  • Double click [your application] (pid [n]) in the tree
  • The contents of the test expression will be displayed on the right side of the tab. In the middle of the Browse tab, you will see the JVM arguments for the application.

jvisualvm can be found in any JDK since JDK 6 7. Video tutorial on jvisualvm is here.

0


source







All Articles