< 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       compressedKlass  = new NarrowKlassField(type.getAddressField("_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}. */
 71   public OopHandle getHandle() { return handle; }

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




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

 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       compressedKlass  = new NarrowKlassField(type.getAddressField("_compressed_klass"), 0);
 54     }
 55   }
 56 
 57   private OopHandle  handle;
 58   private ObjectHeap heap;
 59 
 60   Oop(OopHandle handle, ObjectHeap heap) {
 61     this.handle = handle;
 62     this.heap   = heap;
 63   }
 64 
 65   ObjectHeap getHeap()   { return heap; }
 66 
 67   /** Should not be used or needed by most clients outside this
 68       package; is needed, however, by {@link
 69       sun.jvm.hotspot.utilities.MarkBits}. */
 70   public OopHandle getHandle() { return handle; }

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