querying the memory usage of a Java object
package agent;
public class MyAgent {
private static volatile Instrumentation globalInstr;
public static void premain(String args, Instrumentation inst) {
globalInstr = inst;
System.out.println("this is test");
}
public static long getObjectSize(Object obj) {
if (globalInstr == null)
throw new IllegalStateException("Agent not initted");
return globalInstr.getObjectSize(obj);
}
}
package agent;
public interface Instrumentation {
long getObjectSize(Object obj);
}
未完成…待更新…