Skip to content

Instantly share code, notes, and snippets.

@charleehu
charleehu / GCUtils.java
Created November 21, 2011 08:46 — forked from rednaxelafx/GCUtils.java
HotSpot VM utils
public class GCUtils {
private static final String DISABLE_EXPLICIT_GC = "DisableExplicitGC"; // need to be "manageable" in VM
public static void forceGC() {
String oldValue = HotSpotUtils.getVMOption(DISABLE_EXPLICIT_GC);
if ("true".equals(oldValue)) {
HotSpotUtils.setVMOption(DISABLE_EXPLICIT_GC, "false");
System.gc();
HotSpotUtils.setVMOption(DISABLE_EXPLICIT_GC, oldValue);
} else {
@charleehu
charleehu / DirectMemorySize.java
Created January 30, 2012 09:05 — forked from rednaxelafx/DirectMemorySize.java
An Serviceability-Agent based tool to see stats of NIO direct memory, as an alternative on JDKs without JMX support for direct memory monitoring.
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
public class DirectMemorySize extends Tool {