< prev index next >

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

Print this page

 37 public class Mark extends VMObject {
 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     markField  = type.getCIntegerField("_mark");
 49 
 50     ageBits             = db.lookupLongConstant("markWord::age_bits").longValue();
 51     lockBits            = db.lookupLongConstant("markWord::lock_bits").longValue();
 52     maxHashBits         = db.lookupLongConstant("markWord::max_hash_bits").longValue();
 53     hashBits            = db.lookupLongConstant("markWord::hash_bits").longValue();
 54     lockShift           = db.lookupLongConstant("markWord::lock_shift").longValue();
 55     ageShift            = db.lookupLongConstant("markWord::age_shift").longValue();
 56     hashShift           = db.lookupLongConstant("markWord::hash_shift").longValue();



 57     lockMask            = db.lookupLongConstant("markWord::lock_mask").longValue();
 58     lockMaskInPlace     = db.lookupLongConstant("markWord::lock_mask_in_place").longValue();
 59     ageMask             = db.lookupLongConstant("markWord::age_mask").longValue();
 60     ageMaskInPlace      = db.lookupLongConstant("markWord::age_mask_in_place").longValue();
 61     hashMask            = db.lookupLongConstant("markWord::hash_mask").longValue();
 62     hashMaskInPlace     = db.lookupLongConstant("markWord::hash_mask_in_place").longValue();
 63     lockedValue         = db.lookupLongConstant("markWord::locked_value").longValue();
 64     unlockedValue       = db.lookupLongConstant("markWord::unlocked_value").longValue();
 65     monitorValue        = db.lookupLongConstant("markWord::monitor_value").longValue();
 66     markedValue         = db.lookupLongConstant("markWord::marked_value").longValue();
 67     noHash              = db.lookupLongConstant("markWord::no_hash").longValue();
 68     noHashInPlace       = db.lookupLongConstant("markWord::no_hash_in_place").longValue();
 69     noLockInPlace       = db.lookupLongConstant("markWord::no_lock_in_place").longValue();
 70     maxAge              = db.lookupLongConstant("markWord::max_age").longValue();
 71   }
 72 
 73   // Field accessors
 74   private static CIntegerField markField;
 75 
 76   // Constants -- read from VM
 77   private static long ageBits;
 78   private static long lockBits;
 79   private static long maxHashBits;
 80   private static long hashBits;
 81 
 82   private static long lockShift;
 83   private static long ageShift;
 84   private static long hashShift;

 85 
 86   private static long lockMask;
 87   private static long lockMaskInPlace;
 88   private static long ageMask;
 89   private static long ageMaskInPlace;
 90   private static long hashMask;
 91   private static long hashMaskInPlace;
 92 
 93   private static long lockedValue;
 94   private static long unlockedValue;
 95   private static long monitorValue;
 96   private static long markedValue;
 97 
 98   private static long noHash;
 99 
100   private static long noHashInPlace;
101   private static long noLockInPlace;
102 
103   private static long maxAge;
104 
105   /* Constants in markWord used by CMS. */
106   private static long cmsShift;
107   private static long cmsMask;
108   private static long sizeShift;
109 




110   public Mark(Address addr) {
111     super(addr);
112   }
113 
114   public long value() {
115     return markField.getValue(addr);
116   }
117 
118   public Address valueAsAddress() {
119     return addr.getAddressAt(markField.getOffset());
120   }
121 
122   // lock accessors (note that these assume lock_shift == 0)
123   public boolean isLocked() {
124     return (Bits.maskBitsLong(value(), lockMaskInPlace) != unlockedValue);
125   }
126   public boolean isUnlocked() {
127     return (Bits.maskBitsLong(value(), lockMaskInPlace) == unlockedValue);
128   }
129   public boolean isMarked() {

169     return ((value() & unlockedValue) == 0);
170   }
171   public Mark displacedMarkHelper() {
172     if (Assert.ASSERTS_ENABLED) {
173       Assert.that(hasDisplacedMarkHelper(), "check");
174     }
175     Address addr = valueAsAddress().andWithMask(~monitorValue);
176     return new Mark(addr.getAddressAt(0));
177   }
178   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
179 
180   // hash operations
181   public long hash() {
182     return Bits.maskBitsLong(value() >> hashShift, hashMask);
183   }
184 
185   public boolean hasNoHash() {
186     return hash() == noHash;
187   }
188 






189   // Debugging
190   public void printOn(PrintStream tty) {
191     if (isLocked()) {
192       tty.print("locked(0x" +
193                 Long.toHexString(value()) + ")->");
194       displacedMarkHelper().printOn(tty);
195     } else {
196       if (Assert.ASSERTS_ENABLED) {
197         Assert.that(isUnlocked(), "just checking");
198       }
199       tty.print("mark(");
200       tty.print("hash " + Long.toHexString(hash()) + ",");
201       tty.print("age " + age() + ")");
202     }
203   }
204 
205   public long getSize() { return (long)(value() >> sizeShift); }
206 }

 37 public class Mark extends VMObject {
 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     markField  = type.getCIntegerField("_mark");
 49 
 50     ageBits             = db.lookupLongConstant("markWord::age_bits").longValue();
 51     lockBits            = db.lookupLongConstant("markWord::lock_bits").longValue();
 52     maxHashBits         = db.lookupLongConstant("markWord::max_hash_bits").longValue();
 53     hashBits            = db.lookupLongConstant("markWord::hash_bits").longValue();
 54     lockShift           = db.lookupLongConstant("markWord::lock_shift").longValue();
 55     ageShift            = db.lookupLongConstant("markWord::age_shift").longValue();
 56     hashShift           = db.lookupLongConstant("markWord::hash_shift").longValue();
 57     if (VM.getVM().isLP64()) {
 58       klassShift          = db.lookupLongConstant("markWord::klass_shift").longValue();
 59     }
 60     lockMask            = db.lookupLongConstant("markWord::lock_mask").longValue();
 61     lockMaskInPlace     = db.lookupLongConstant("markWord::lock_mask_in_place").longValue();
 62     ageMask             = db.lookupLongConstant("markWord::age_mask").longValue();
 63     ageMaskInPlace      = db.lookupLongConstant("markWord::age_mask_in_place").longValue();
 64     hashMask            = db.lookupLongConstant("markWord::hash_mask").longValue();
 65     hashMaskInPlace     = db.lookupLongConstant("markWord::hash_mask_in_place").longValue();
 66     lockedValue         = db.lookupLongConstant("markWord::locked_value").longValue();
 67     unlockedValue       = db.lookupLongConstant("markWord::unlocked_value").longValue();
 68     monitorValue        = db.lookupLongConstant("markWord::monitor_value").longValue();
 69     markedValue         = db.lookupLongConstant("markWord::marked_value").longValue();
 70     noHash              = db.lookupLongConstant("markWord::no_hash").longValue();
 71     noHashInPlace       = db.lookupLongConstant("markWord::no_hash_in_place").longValue();
 72     noLockInPlace       = db.lookupLongConstant("markWord::no_lock_in_place").longValue();
 73     maxAge              = db.lookupLongConstant("markWord::max_age").longValue();
 74   }
 75 
 76   // Field accessors
 77   private static CIntegerField markField;
 78 
 79   // Constants -- read from VM
 80   private static long ageBits;
 81   private static long lockBits;
 82   private static long maxHashBits;
 83   private static long hashBits;
 84 
 85   private static long lockShift;
 86   private static long ageShift;
 87   private static long hashShift;
 88   private static long klassShift;
 89 
 90   private static long lockMask;
 91   private static long lockMaskInPlace;
 92   private static long ageMask;
 93   private static long ageMaskInPlace;
 94   private static long hashMask;
 95   private static long hashMaskInPlace;
 96 
 97   private static long lockedValue;
 98   private static long unlockedValue;
 99   private static long monitorValue;
100   private static long markedValue;
101 
102   private static long noHash;
103 
104   private static long noHashInPlace;
105   private static long noLockInPlace;
106 
107   private static long maxAge;
108 
109   /* Constants in markWord used by CMS. */
110   private static long cmsShift;
111   private static long cmsMask;
112   private static long sizeShift;
113 
114   public static long getKlassShift() {
115     return klassShift;
116   }
117 
118   public Mark(Address addr) {
119     super(addr);
120   }
121 
122   public long value() {
123     return markField.getValue(addr);
124   }
125 
126   public Address valueAsAddress() {
127     return addr.getAddressAt(markField.getOffset());
128   }
129 
130   // lock accessors (note that these assume lock_shift == 0)
131   public boolean isLocked() {
132     return (Bits.maskBitsLong(value(), lockMaskInPlace) != unlockedValue);
133   }
134   public boolean isUnlocked() {
135     return (Bits.maskBitsLong(value(), lockMaskInPlace) == unlockedValue);
136   }
137   public boolean isMarked() {

177     return ((value() & unlockedValue) == 0);
178   }
179   public Mark displacedMarkHelper() {
180     if (Assert.ASSERTS_ENABLED) {
181       Assert.that(hasDisplacedMarkHelper(), "check");
182     }
183     Address addr = valueAsAddress().andWithMask(~monitorValue);
184     return new Mark(addr.getAddressAt(0));
185   }
186   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
187 
188   // hash operations
189   public long hash() {
190     return Bits.maskBitsLong(value() >> hashShift, hashMask);
191   }
192 
193   public boolean hasNoHash() {
194     return hash() == noHash;
195   }
196 
197   public Klass getKlass() {
198     assert(VM.getVM().isCompactObjectHeadersEnabled());
199     assert(!hasMonitor());
200     return (Klass)Metadata.instantiateWrapperFor(addr.getCompKlassAddressAt(0));
201   }
202 
203   // Debugging
204   public void printOn(PrintStream tty) {
205     if (isLocked()) {
206       tty.print("locked(0x" +
207                 Long.toHexString(value()) + ")->");
208       displacedMarkHelper().printOn(tty);
209     } else {
210       if (Assert.ASSERTS_ENABLED) {
211         Assert.that(isUnlocked(), "just checking");
212       }
213       tty.print("mark(");
214       tty.print("hash " + Long.toHexString(hash()) + ",");
215       tty.print("age " + age() + ")");
216     }
217   }
218 
219   public long getSize() { return (long)(value() >> sizeShift); }
220 }
< prev index next >