< prev index next >

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

Print this page

 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}. */

115   public static long alignObjectSize(long size) {
116     return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes());
117   }
118 
119   // All vm's align longs, so pad out certain offsets.
120   public static long alignObjectOffset(long offset) {
121     return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
122   }
123 
124   public boolean equals(Object obj) {
125     if (obj instanceof Oop other) {
126       return getHandle().equals(other.getHandle());
127     }
128     return false;
129  }
130 
131   public int hashCode() { return getHandle().hashCode(); }
132 
133   /** Identity hash in the target VM */
134   public long identityHash() {




135     Mark mark = getMark();
136     if (mark.isUnlocked() && (!mark.hasNoHash())) {
137       return (int) mark.hash();
138     } else if (mark.isMarked()) {
139       return (int) mark.hash();
140     } else {
141       return slowIdentityHash();
142     }
143   }
144 
145   public long slowIdentityHash() {
146     return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
147   }
148 
149   public void iterate(OopVisitor visitor, boolean doVMFields) {
150     visitor.setObj(this);
151     visitor.prologue();
152     iterateFields(visitor, doVMFields);
153     visitor.epilogue();
154   }

 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       headerSize = 4;

 51     } else {
 52       headerSize = type.getSize();
 53       klass      = new MetadataField(type.getAddressField("_metadata._klass"), 0);
 54       compressedKlass  = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0);
 55     }
 56   }
 57 
 58   private OopHandle  handle;
 59   private ObjectHeap heap;
 60 
 61   Oop(OopHandle handle, ObjectHeap heap) {
 62     this.handle = handle;
 63     this.heap   = heap;
 64   }
 65 
 66   ObjectHeap getHeap()   { return heap; }
 67 
 68   /** Should not be used or needed by most clients outside this
 69       package; is needed, however, by {@link
 70       sun.jvm.hotspot.utilities.MarkBits}. */

114   public static long alignObjectSize(long size) {
115     return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes());
116   }
117 
118   // All vm's align longs, so pad out certain offsets.
119   public static long alignObjectOffset(long offset) {
120     return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
121   }
122 
123   public boolean equals(Object obj) {
124     if (obj instanceof Oop other) {
125       return getHandle().equals(other.getHandle());
126     }
127     return false;
128  }
129 
130   public int hashCode() { return getHandle().hashCode(); }
131 
132   /** Identity hash in the target VM */
133   public long identityHash() {
134     if (VM.getVM().isCompactObjectHeadersEnabled()) {
135       System.exit(-23);
136         throw new InternalError("Not yet implemented");
137     }
138     Mark mark = getMark();
139     if (mark.isUnlocked() && (!mark.hasNoHash())) {
140       return (int) mark.hash();
141     } else if (mark.isMarked()) {
142       return (int) mark.hash();
143     } else {
144       return slowIdentityHash();
145     }
146   }
147 
148   public long slowIdentityHash() {
149     return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
150   }
151 
152   public void iterate(OopVisitor visitor, boolean doVMFields) {
153     visitor.setObj(this);
154     visitor.prologue();
155     iterateFields(visitor, doVMFields);
156     visitor.epilogue();
157   }
< prev index next >