Skip to content

Instantly share code, notes, and snippets.

@khotyn
Created December 26, 2011 11:26
Show Gist options
  • Save khotyn/1520947 to your computer and use it in GitHub Desktop.
Save khotyn/1520947 to your computer and use it in GitHub Desktop.
Garbage collectors used in HotSpot JVM under different VM Options
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
* Print the Collector used in the program.
* @author khotyn
*/
public class GarbageCollectors {
public static void main(String[] args) throws InterruptedException, IOException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> names = server.queryNames(null, null);
for (ObjectName name : names) {
if (name.toString().contains("GarbageCollector")) {
System.out.println(name);
}
}
}
}
echo 'Client:'
java -client GarbageCollectors
echo 'Server:'
java -server GarbageCollectors
echo 'UseSerialGC:'
java -XX:+UseSerialGC GarbageCollectors
echo 'UseParallelGC:'
java -XX:+UseParallelGC GarbageCollectors
echo 'UseParNewGC:'
java -XX:+UseParNewGC GarbageCollectors
echo 'UseParalllelOldGC:'
java -XX:+UseParallelOldGC GarbageCollectors
echo 'UseConcMarkSweepGC:'
java -XX:+UseConcMarkSweepGC GarbageCollectors
echo 'UseG1GC:'
java -XX:+UseG1GC GarbageCollectors
@khotyn
Copy link
Author

khotyn commented Dec 26, 2011

The result:

Client:
java.lang:type=GarbageCollector,name=Copy
java.lang:type=GarbageCollector,name=MarkSweepCompact
Server:
java.lang:type=GarbageCollector,name=PS MarkSweep
java.lang:type=GarbageCollector,name=PS Scavenge
UseSerialGC:
java.lang:type=GarbageCollector,name=Copy
java.lang:type=GarbageCollector,name=MarkSweepCompact
UseParallelGC:
java.lang:type=GarbageCollector,name=PS MarkSweep
java.lang:type=GarbageCollector,name=PS Scavenge
UseParNewGC:
java.lang:type=GarbageCollector,name=ParNew
java.lang:type=GarbageCollector,name=MarkSweepCompact
UseParalllelOldGC:
java.lang:type=GarbageCollector,name=PS MarkSweep
java.lang:type=GarbageCollector,name=PS Scavenge
UseConcMarkSweepGC:
java.lang:type=GarbageCollector,name=ConcurrentMarkSweep
java.lang:type=GarbageCollector,name=ParNew
UseG1GC:
java.lang:type=GarbageCollector,name=G1 Old Generation
java.lang:type=GarbageCollector,name=G1 Young Generation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment