26 27 import java.io.*; 28 import sun.jvm.hotspot.debugger.*; 29 import sun.jvm.hotspot.gc.shared.OopStorage; 30 import sun.jvm.hotspot.memory.*; 31 import sun.jvm.hotspot.oops.*; 32 import sun.jvm.hotspot.runtime.*; 33 34 /** 35 * This is abstract base class for heap graph writers. This class does 36 * not assume any file format for the heap graph. It hides heap 37 * iteration, object (fields) iteration mechanism from derived 38 * classes. This class does not even accept OutputStream etc. so that 39 * derived class can construct specific writer/filter from input 40 * stream. 41 */ 42 43 public abstract class AbstractHeapGraphWriter implements HeapGraphWriter { 44 // the function iterates heap and calls Oop type specific writers 45 protected void write() throws IOException { 46 SymbolTable symTbl = VM.getVM().getSymbolTable(); 47 javaLangClass = symTbl.probe("java/lang/Class"); 48 javaLangString = symTbl.probe("java/lang/String"); 49 javaLangThread = symTbl.probe("java/lang/Thread"); 50 ObjectHeap heap = VM.getVM().getObjectHeap(); 51 try { 52 heap.iterate(new DefaultHeapVisitor() { 53 public void prologue(long usedSize) { 54 try { 55 writeHeapHeader(); 56 } catch (IOException exp) { 57 throw new RuntimeException(exp); 58 } 59 } 60 61 public boolean doObj(Oop oop) { 62 try { 63 writeHeapRecordPrologue(); 64 if (oop instanceof TypeArray) { 65 writePrimitiveArray((TypeArray)oop); 66 } else if (oop instanceof ObjArray) { 67 Klass klass = oop.getKlass(); 68 ObjArrayKlass oak = (ObjArrayKlass) klass; 69 Klass bottomType = oak.getBottomKlass(); 441 } else { 442 // some other RuntimeException, just re-throw 443 throw re; 444 } 445 } 446 447 // whether a given oop is Java visible or hotspot internal? 448 protected boolean isJavaVisible(Oop oop) { 449 if (oop instanceof Instance || oop instanceof TypeArray) { 450 return true; 451 } else if (oop instanceof ObjArray) { 452 ObjArrayKlass oak = (ObjArrayKlass) oop.getKlass(); 453 Klass bottomKlass = oak.getBottomKlass(); 454 return bottomKlass instanceof InstanceKlass || 455 bottomKlass instanceof TypeArrayKlass; 456 } else { 457 return false; 458 } 459 } 460 461 protected Symbol javaLangClass; 462 protected Symbol javaLangString; 463 protected Symbol javaLangThread; 464 } | 26 27 import java.io.*; 28 import sun.jvm.hotspot.debugger.*; 29 import sun.jvm.hotspot.gc.shared.OopStorage; 30 import sun.jvm.hotspot.memory.*; 31 import sun.jvm.hotspot.oops.*; 32 import sun.jvm.hotspot.runtime.*; 33 34 /** 35 * This is abstract base class for heap graph writers. This class does 36 * not assume any file format for the heap graph. It hides heap 37 * iteration, object (fields) iteration mechanism from derived 38 * classes. This class does not even accept OutputStream etc. so that 39 * derived class can construct specific writer/filter from input 40 * stream. 41 */ 42 43 public abstract class AbstractHeapGraphWriter implements HeapGraphWriter { 44 // the function iterates heap and calls Oop type specific writers 45 protected void write() throws IOException { 46 javaLangClass = "java/lang/Class"; 47 javaLangString = "java/lang/String"; 48 javaLangThread = "java/lang/Thread"; 49 ObjectHeap heap = VM.getVM().getObjectHeap(); 50 try { 51 heap.iterate(new DefaultHeapVisitor() { 52 public void prologue(long usedSize) { 53 try { 54 writeHeapHeader(); 55 } catch (IOException exp) { 56 throw new RuntimeException(exp); 57 } 58 } 59 60 public boolean doObj(Oop oop) { 61 try { 62 writeHeapRecordPrologue(); 63 if (oop instanceof TypeArray) { 64 writePrimitiveArray((TypeArray)oop); 65 } else if (oop instanceof ObjArray) { 66 Klass klass = oop.getKlass(); 67 ObjArrayKlass oak = (ObjArrayKlass) klass; 68 Klass bottomType = oak.getBottomKlass(); 440 } else { 441 // some other RuntimeException, just re-throw 442 throw re; 443 } 444 } 445 446 // whether a given oop is Java visible or hotspot internal? 447 protected boolean isJavaVisible(Oop oop) { 448 if (oop instanceof Instance || oop instanceof TypeArray) { 449 return true; 450 } else if (oop instanceof ObjArray) { 451 ObjArrayKlass oak = (ObjArrayKlass) oop.getKlass(); 452 Klass bottomKlass = oak.getBottomKlass(); 453 return bottomKlass instanceof InstanceKlass || 454 bottomKlass instanceof TypeArrayKlass; 455 } else { 456 return false; 457 } 458 } 459 460 protected String javaLangClass; 461 protected String javaLangString; 462 protected String javaLangThread; 463 } |