251 if (f.isBool()) { 252 return f.getBool()? 1L : 0L; 253 } else { 254 return Long.parseLong(f.getValue()); 255 } 256 } else { 257 return -1; 258 } 259 } 260 261 private void printInternStringStatistics() { 262 class StringStat implements StringTable.StringVisitor { 263 private int count; 264 private long size; 265 private OopField stringValueField; 266 267 StringStat() { 268 VM vm = VM.getVM(); 269 SystemDictionary sysDict = vm.getSystemDictionary(); 270 InstanceKlass strKlass = sysDict.getStringKlass(); 271 // String has a field named 'value' of type 'char[]'. 272 stringValueField = (OopField) strKlass.findField("value", "[C"); 273 } 274 275 private long stringSize(Instance instance) { 276 // We include String content in size calculation. 277 return instance.getObjectSize() + 278 stringValueField.getValue(instance).getObjectSize(); 279 } 280 281 public void visit(Instance str) { 282 count++; 283 size += stringSize(str); 284 } 285 286 public void print() { 287 System.out.println(count + 288 " interned Strings occupying " + size + " bytes."); 289 } 290 } 291 292 StringStat stat = new StringStat(); | 251 if (f.isBool()) { 252 return f.getBool()? 1L : 0L; 253 } else { 254 return Long.parseLong(f.getValue()); 255 } 256 } else { 257 return -1; 258 } 259 } 260 261 private void printInternStringStatistics() { 262 class StringStat implements StringTable.StringVisitor { 263 private int count; 264 private long size; 265 private OopField stringValueField; 266 267 StringStat() { 268 VM vm = VM.getVM(); 269 SystemDictionary sysDict = vm.getSystemDictionary(); 270 InstanceKlass strKlass = sysDict.getStringKlass(); 271 // String has a field named 'value' of type 'byte[]'. 272 stringValueField = (OopField) strKlass.findField("value", "[B"); 273 } 274 275 private long stringSize(Instance instance) { 276 // We include String content in size calculation. 277 return instance.getObjectSize() + 278 stringValueField.getValue(instance).getObjectSize(); 279 } 280 281 public void visit(Instance str) { 282 count++; 283 size += stringSize(str); 284 } 285 286 public void print() { 287 System.out.println(count + 288 " interned Strings occupying " + size + " bytes."); 289 } 290 } 291 292 StringStat stat = new StringStat(); |