< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Oop.java

Print this page

 29 import sun.jvm.hotspot.runtime.*;
 30 import sun.jvm.hotspot.types.*;
 31 import sun.jvm.hotspot.utilities.Observable;
 32 import sun.jvm.hotspot.utilities.Observer;
 33 
 34 // Oop represents the superclass for all types of
 35 // objects in the HotSpot object heap.
 36 
 37 public class Oop {
 38   static {
 39     VM.registerVMInitializedObserver(new Observer() {
 40         public void update(Observable o, Object data) {
 41           initialize(VM.getVM().getTypeDataBase());
 42         }
 43       });
 44   }
 45 
 46   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
 47     Type type  = db.lookupType("oopDesc");
 48     mark       = new CIntField(type.getCIntegerField("_mark"), 0);
 49     klass      = new MetadataField(type.getAddressField("_metadata._klass"), 0);
 50     compressedKlass  = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0);
 51     headerSize = type.getSize();





 52   }
 53 
 54   private OopHandle  handle;
 55   private ObjectHeap heap;
 56 
 57   Oop(OopHandle handle, ObjectHeap heap) {
 58     this.handle = handle;
 59     this.heap   = heap;
 60   }
 61 
 62   ObjectHeap getHeap()   { return heap; }
 63 
 64   /** Should not be used or needed by most clients outside this
 65       package; is needed, however, by {@link
 66       sun.jvm.hotspot.utilities.MarkBits}. */
 67   public OopHandle getHandle() { return handle; }
 68 
 69   private static long headerSize;
 70   public  static long getHeaderSize() { return headerSize; } // Header size in bytes.
 71 
 72   private static CIntField mark;
 73   private static MetadataField  klass;
 74   private static NarrowKlassField compressedKlass;
 75 
 76   // Accessors for declared fields
 77   public Mark  getMark()   { return new Mark(getHandle()); }






 78   public Klass getKlass() {
 79     if (VM.getVM().isCompressedKlassPointersEnabled()) {



 80       return (Klass)compressedKlass.getValue(getHandle());
 81     } else {
 82       return (Klass)klass.getValue(getHandle());
 83     }
 84   }
 85 
 86   public boolean isA(Klass k) {
 87     return getKlass().isSubtypeOf(k);
 88   }
 89 
 90   // Returns the byte size of this object
 91   public long getObjectSize() {
 92     Klass k = getKlass();
 93     // All other types should be overriding getObjectSize directly
 94     return ((InstanceKlass)k).getObjectSize(this);
 95   }
 96 
 97   // Type test operations
 98   public boolean isInstance()          { return false; }
 99   public boolean isInstanceRef()       { return false; }

130       return (int) mark.hash();
131     } else {
132       return slowIdentityHash();
133     }
134   }
135 
136   public long slowIdentityHash() {
137     return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
138   }
139 
140   public void iterate(OopVisitor visitor, boolean doVMFields) {
141     visitor.setObj(this);
142     visitor.prologue();
143     iterateFields(visitor, doVMFields);
144     visitor.epilogue();
145   }
146 
147   void iterateFields(OopVisitor visitor, boolean doVMFields) {
148     if (doVMFields) {
149       visitor.doCInt(mark, true);
150       if (VM.getVM().isCompressedKlassPointersEnabled()) {
151         visitor.doMetadata(compressedKlass, true);
152       } else {
153         visitor.doMetadata(klass, true);


154       }
155     }
156   }
157 
158   public void print()      { printOn(System.out); }
159   public void printValue() { printValueOn(System.out); }
160   public void printRaw()   { printRawOn(System.out); }
161 
162   public static void printOopValueOn(Oop obj, PrintStream tty) {
163     if (obj == null) {
164       tty.print("null");
165     } else {
166       obj.printValueOn(tty);
167       tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle()));
168     }
169   }
170 
171   public static void printOopAddressOn(Oop obj, PrintStream tty) {
172     if (obj == null) {
173       tty.print("null");

189     }
190   }
191 
192   public void printRawOn(PrintStream tty) {
193     tty.print("Dumping raw memory for ");
194     printValueOn(tty);
195     tty.println();
196     long size = getObjectSize() * 4;
197     for (long i = 0; i < size; i += 4) {
198       long memVal = getHandle().getCIntegerAt(i, 4, true);
199       tty.println(Long.toHexString(memVal));
200     }
201   }
202 
203   public boolean verify() { return true;}
204 
205   public static Klass getKlassForOopHandle(OopHandle handle) {
206     if (handle == null) {
207       return null;
208     }
209     if (VM.getVM().isCompressedKlassPointersEnabled()) {



210       return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset()));
211     } else {
212       return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset()));
213     }
214   }
215 };

 29 import sun.jvm.hotspot.runtime.*;
 30 import sun.jvm.hotspot.types.*;
 31 import sun.jvm.hotspot.utilities.Observable;
 32 import sun.jvm.hotspot.utilities.Observer;
 33 
 34 // Oop represents the superclass for all types of
 35 // objects in the HotSpot object heap.
 36 
 37 public class Oop {
 38   static {
 39     VM.registerVMInitializedObserver(new Observer() {
 40         public void update(Observable o, Object data) {
 41           initialize(VM.getVM().getTypeDataBase());
 42         }
 43       });
 44   }
 45 
 46   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
 47     Type type  = db.lookupType("oopDesc");
 48     mark       = new CIntField(type.getCIntegerField("_mark"), 0);
 49     if (VM.getVM().isCompactObjectHeadersEnabled()) {
 50       Type markType = db.lookupType("markWord");
 51       headerSize = markType.getSize();
 52     } else {
 53       headerSize = type.getSize();
 54       klass      = new MetadataField(type.getAddressField("_metadata._klass"), 0);
 55       compressedKlass  = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0);
 56     }
 57   }
 58 
 59   private OopHandle  handle;
 60   private ObjectHeap heap;
 61 
 62   Oop(OopHandle handle, ObjectHeap heap) {
 63     this.handle = handle;
 64     this.heap   = heap;
 65   }
 66 
 67   ObjectHeap getHeap()   { return heap; }
 68 
 69   /** Should not be used or needed by most clients outside this
 70       package; is needed, however, by {@link
 71       sun.jvm.hotspot.utilities.MarkBits}. */
 72   public OopHandle getHandle() { return handle; }
 73 
 74   private static long headerSize;
 75   public  static long getHeaderSize() { return headerSize; } // Header size in bytes.
 76 
 77   private static CIntField mark;
 78   private static MetadataField  klass;
 79   private static NarrowKlassField compressedKlass;
 80 
 81   // Accessors for declared fields
 82   public Mark  getMark()   { return new Mark(getHandle()); }
 83 
 84   private static Klass getKlass(Mark mark) {
 85     assert(VM.getVM().isCompactObjectHeadersEnabled());
 86     return mark.getKlass();
 87   }
 88 
 89   public Klass getKlass() {
 90     if (VM.getVM().isCompactObjectHeadersEnabled()) {
 91       assert(VM.getVM().isCompressedKlassPointersEnabled());
 92       return getKlass(getMark());
 93     } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
 94       return (Klass)compressedKlass.getValue(getHandle());
 95     } else {
 96       return (Klass)klass.getValue(getHandle());
 97     }
 98   }
 99 
100   public boolean isA(Klass k) {
101     return getKlass().isSubtypeOf(k);
102   }
103 
104   // Returns the byte size of this object
105   public long getObjectSize() {
106     Klass k = getKlass();
107     // All other types should be overriding getObjectSize directly
108     return ((InstanceKlass)k).getObjectSize(this);
109   }
110 
111   // Type test operations
112   public boolean isInstance()          { return false; }
113   public boolean isInstanceRef()       { return false; }

144       return (int) mark.hash();
145     } else {
146       return slowIdentityHash();
147     }
148   }
149 
150   public long slowIdentityHash() {
151     return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
152   }
153 
154   public void iterate(OopVisitor visitor, boolean doVMFields) {
155     visitor.setObj(this);
156     visitor.prologue();
157     iterateFields(visitor, doVMFields);
158     visitor.epilogue();
159   }
160 
161   void iterateFields(OopVisitor visitor, boolean doVMFields) {
162     if (doVMFields) {
163       visitor.doCInt(mark, true);
164       if (!VM.getVM().isCompactObjectHeadersEnabled()) {
165         if (VM.getVM().isCompressedKlassPointersEnabled()) {
166           visitor.doMetadata(compressedKlass, true);
167         } else {
168           visitor.doMetadata(klass, true);
169         }
170       }
171     }
172   }
173 
174   public void print()      { printOn(System.out); }
175   public void printValue() { printValueOn(System.out); }
176   public void printRaw()   { printRawOn(System.out); }
177 
178   public static void printOopValueOn(Oop obj, PrintStream tty) {
179     if (obj == null) {
180       tty.print("null");
181     } else {
182       obj.printValueOn(tty);
183       tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle()));
184     }
185   }
186 
187   public static void printOopAddressOn(Oop obj, PrintStream tty) {
188     if (obj == null) {
189       tty.print("null");

205     }
206   }
207 
208   public void printRawOn(PrintStream tty) {
209     tty.print("Dumping raw memory for ");
210     printValueOn(tty);
211     tty.println();
212     long size = getObjectSize() * 4;
213     for (long i = 0; i < size; i += 4) {
214       long memVal = getHandle().getCIntegerAt(i, 4, true);
215       tty.println(Long.toHexString(memVal));
216     }
217   }
218 
219   public boolean verify() { return true;}
220 
221   public static Klass getKlassForOopHandle(OopHandle handle) {
222     if (handle == null) {
223       return null;
224     }
225     if (VM.getVM().isCompactObjectHeadersEnabled()) {
226       Mark mark = new Mark(handle);
227       return getKlass(mark);
228     } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
229       return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset()));
230     } else {
231       return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset()));
232     }
233   }
234 };
< prev index next >