I'm still investigating issues I have with GC tuning (see prior question), which involves lots of reading and experimentation.
Sun Java5+ JVMs attempt to automatically select the optimal GC strategy and parameters based on their environment, which is great, but I can't figure out how to query the running JVM to find out what those parameters are.
Ideally, I'd like to see what values of the various GC-related -XX options are being used, as selected automatically by the VM. If I had that, I could have a baseline to begin tweaking.
Anyone know to recover these values from a running VM?
What is Java Garbage Collection? Java applications obtain objects in memory as needed. It is the task of garbage collection (GC) in the Java virtual machine (JVM) to automatically determine what memory is no longer being used by a Java application and to recycle this memory for other uses.
Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted. The garbage collection implementation lives in the JVM. Each JVM can implement garbage collection however it pleases; the only requirement is that it meets the JVM specification.
Parallel Garbage Collector. It's the default GC of the JVM, and sometimes called Throughput Collectors. Unlike Serial Garbage Collector, it uses multiple threads for managing heap space, but it also freezes other application threads while performing GC.
-XX:+PrintCommandLineFlags Prints flags passed on command line or configured by the ergonomics (auto-sizing) features.
-XX:+PrintFlagsInitial Dumps ALL the default flags and values.
-XX:+PrintFlagsFinal Dumps ALL the flags after processing command line and ergonomics.
So I think the latter will do for you, just add it to your command line script.
Check out the HotSpotDiagnosticMBean
The following example will print out the value of an option as well as whether the value is DEFAULT or VM_CREATION:
import java.lang.management.ManagementFactory;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
public class HotSpotTest {
public static void main(String [] args) throws Exception {
printHotSpotOption("MaxHeapFreeRatio");
printHotSpotOption("SurvivorRatio");
printHotSpotOptions();
}
private static void printHotSpotOption(String option) throws Exception {
ObjectName name = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
String operationName = "getVMOption";
Object [] params = new Object [] {option};
String [] signature = new String[] {String.class.getName()};
Object result = ManagementFactory.getPlatformMBeanServer().invoke(name, operationName, params, signature);
CompositeDataSupport data = (CompositeDataSupport) result;
System.out.println(option);
System.out.println("- Value: "+data.get("value"));
System.out.println("- Origin: "+data.get("origin"));
}
private static void printHotSpotOptions() throws Exception {
ObjectName name = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
String attributeName = "DiagnosticOptions";
Object result = ManagementFactory.getPlatformMBeanServer().getAttribute(name, attributeName);
CompositeData [] array = (CompositeData[]) result;
for (CompositeData d : array) {
System.out.println(d.get("name"));
System.out.println("- Value: "+d.get("value"));
System.out.println("- Origin: "+d.get("origin"));
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With