< 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     if (mark.hasMonitor()) {
 87       ObjectMonitor mon = mark.monitor();
 88       mark = mon.header();
 89     }
 90     return mark.getKlass();
 91   }
 92 
 93   public Klass getKlass() {
 94     if (VM.getVM().isCompactObjectHeadersEnabled()) {
 95       assert(VM.getVM().isCompressedKlassPointersEnabled());
 96       return getKlass(getMark());
 97     } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
 98       return (Klass)compressedKlass.getValue(getHandle());
 99     } else {
100       return (Klass)klass.getValue(getHandle());
101     }
102   }
103 
104   public boolean isA(Klass k) {
105     return getKlass().isSubtypeOf(k);
106   }
107 
108   // Returns the byte size of this object
109   public long getObjectSize() {
110     Klass k = getKlass();
111     // All other types should be overriding getObjectSize directly
112     return ((InstanceKlass)k).getObjectSize(this);
113   }
114 
115   // Type test operations
116   public boolean isInstance()          { return false; }
117   public boolean isInstanceRef()       { return false; }

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

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