agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java	Fri Nov  4 13:06:44 2011
--- new/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java	Fri Nov  4 13:06:44 2011

*** 28,37 **** --- 28,38 ---- import sun.jvm.hotspot.gc_interface.*; import sun.jvm.hotspot.gc_implementation.g1.*; import sun.jvm.hotspot.gc_implementation.parallelScavenge.*; import sun.jvm.hotspot.gc_implementation.shared.*; import sun.jvm.hotspot.memory.*; + import sun.jvm.hotspot.oops.*; import sun.jvm.hotspot.runtime.*; public class HeapSummary extends Tool { public static void main(String[] args) {
*** 132,141 **** --- 133,145 ---- printValMB("free = ", permFree); System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used"); } else { throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass()); } + + System.out.println(); + printInternStringStatistics(); } // Helper methods private void printGCAlgorithm(Map flagMap) {
*** 246,251 **** --- 250,292 ---- } } else { return -1; } } + + private void printInternStringStatistics() { + class StringStat implements StringTable.StringVisitor { + private int count; + private long size; + private OopField stringValueField; + + StringStat() { + VM vm = VM.getVM(); + SystemDictionary sysDict = vm.getSystemDictionary(); + InstanceKlass strKlass = sysDict.getStringKlass(); + // String has a field named 'value' of type 'char[]'. + stringValueField = (OopField) strKlass.findField("value", "[C"); + } + + private long stringSize(Instance instance) { + // We include String content in size calculation. + return instance.getObjectSize() + + stringValueField.getValue(instance).getObjectSize(); + } + + public void visit(Instance str) { + count++; + size += stringSize(str); + } + + public void print() { + System.out.println(count + + " interned Strings occupying " + size + " bytes."); + } + } + + StringStat stat = new StringStat(); + StringTable strTable = VM.getVM().getStringTable(); + strTable.stringsDo(stat); + stat.print(); + } }

agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File