src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
changeset 50445 bd6b78feb6a3
parent 49463 ccb003941743
child 50523 7b7c75d87f9b
child 56719 a846e7bbcdfa
equal deleted inserted replaced
50444:db65921e9a9b 50445:bd6b78feb6a3
   127       } else {
   127       } else {
   128          throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
   128          throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
   129       }
   129       }
   130 
   130 
   131       System.out.println();
   131       System.out.println();
   132       printInternStringStatistics();
       
   133    }
   132    }
   134 
   133 
   135    // Helper methods
   134    // Helper methods
   136 
   135 
   137    private void printGCAlgorithm(Map flagMap) {
   136    private void printGCAlgorithm(Map flagMap) {
   256          }
   255          }
   257       } else {
   256       } else {
   258          return -1;
   257          return -1;
   259       }
   258       }
   260    }
   259    }
   261 
       
   262    private void printInternStringStatistics() {
       
   263       class StringStat implements StringTable.StringVisitor {
       
   264          private int count;
       
   265          private long size;
       
   266          private OopField stringValueField;
       
   267 
       
   268          StringStat() {
       
   269             VM vm = VM.getVM();
       
   270             SystemDictionary sysDict = vm.getSystemDictionary();
       
   271             InstanceKlass strKlass = sysDict.getStringKlass();
       
   272             // String has a field named 'value' of type 'byte[]'.
       
   273             stringValueField = (OopField) strKlass.findField("value", "[B");
       
   274          }
       
   275 
       
   276          private long stringSize(Instance instance) {
       
   277             // We include String content in size calculation.
       
   278             return instance.getObjectSize() +
       
   279                    stringValueField.getValue(instance).getObjectSize();
       
   280          }
       
   281 
       
   282          public void visit(Instance str) {
       
   283             count++;
       
   284             size += stringSize(str);
       
   285          }
       
   286 
       
   287          public void print() {
       
   288             System.out.println(count +
       
   289                   " interned Strings occupying " + size + " bytes.");
       
   290          }
       
   291       }
       
   292 
       
   293       StringStat stat = new StringStat();
       
   294       StringTable strTable = VM.getVM().getStringTable();
       
   295       strTable.stringsDo(stat);
       
   296       stat.print();
       
   297    }
       
   298 }
   260 }