< prev index next >

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

Print this page

 35 import sun.jvm.hotspot.utilities.Observer;
 36 
 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     biasedLockBits      = db.lookupLongConstant("markWord::biased_lock_bits").longValue();
 53     maxHashBits         = db.lookupLongConstant("markWord::max_hash_bits").longValue();
 54     hashBits            = db.lookupLongConstant("markWord::hash_bits").longValue();

 55     lockShift           = db.lookupLongConstant("markWord::lock_shift").longValue();
 56     biasedLockShift     = db.lookupLongConstant("markWord::biased_lock_shift").longValue();
 57     ageShift            = db.lookupLongConstant("markWord::age_shift").longValue();
 58     hashShift           = db.lookupLongConstant("markWord::hash_shift").longValue();




 59     lockMask            = db.lookupLongConstant("markWord::lock_mask").longValue();
 60     lockMaskInPlace     = db.lookupLongConstant("markWord::lock_mask_in_place").longValue();
 61     biasedLockMask      = db.lookupLongConstant("markWord::biased_lock_mask").longValue();
 62     biasedLockMaskInPlace  = db.lookupLongConstant("markWord::biased_lock_mask_in_place").longValue();
 63     biasedLockBitInPlace  = db.lookupLongConstant("markWord::biased_lock_bit_in_place").longValue();
 64     ageMask             = db.lookupLongConstant("markWord::age_mask").longValue();
 65     ageMaskInPlace      = db.lookupLongConstant("markWord::age_mask_in_place").longValue();
 66     hashMask            = db.lookupLongConstant("markWord::hash_mask").longValue();
 67     hashMaskInPlace     = db.lookupLongConstant("markWord::hash_mask_in_place").longValue();


 68     biasedLockAlignment  = db.lookupLongConstant("markWord::biased_lock_alignment").longValue();
 69     lockedValue         = db.lookupLongConstant("markWord::locked_value").longValue();
 70     unlockedValue       = db.lookupLongConstant("markWord::unlocked_value").longValue();
 71     monitorValue        = db.lookupLongConstant("markWord::monitor_value").longValue();
 72     markedValue         = db.lookupLongConstant("markWord::marked_value").longValue();
 73     biasedLockPattern = db.lookupLongConstant("markWord::biased_lock_pattern").longValue();
 74     noHash              = db.lookupLongConstant("markWord::no_hash").longValue();
 75     noHashInPlace       = db.lookupLongConstant("markWord::no_hash_in_place").longValue();
 76     noLockInPlace       = db.lookupLongConstant("markWord::no_lock_in_place").longValue();
 77     maxAge              = db.lookupLongConstant("markWord::max_age").longValue();
 78   }
 79 
 80   // Field accessors
 81   private static CIntegerField markField;
 82 
 83   // Constants -- read from VM
 84   private static long ageBits;
 85   private static long lockBits;
 86   private static long biasedLockBits;
 87   private static long maxHashBits;
 88   private static long hashBits;

 89 
 90   private static long lockShift;
 91   private static long biasedLockShift;
 92   private static long ageShift;
 93   private static long hashShift;


 94 
 95   private static long lockMask;
 96   private static long lockMaskInPlace;
 97   private static long biasedLockMask;
 98   private static long biasedLockMaskInPlace;
 99   private static long biasedLockBitInPlace;
100   private static long ageMask;
101   private static long ageMaskInPlace;
102   private static long hashMask;
103   private static long hashMaskInPlace;


104   private static long biasedLockAlignment;
105 
106   private static long lockedValue;
107   private static long unlockedValue;
108   private static long monitorValue;
109   private static long markedValue;
110   private static long biasedLockPattern;
111 
112   private static long noHash;
113 
114   private static long noHashInPlace;
115   private static long noLockInPlace;
116 
117   private static long maxAge;
118 
119   /* Constants in markWord used by CMS. */
120   private static long cmsShift;
121   private static long cmsMask;
122   private static long sizeShift;
123 




124   public Mark(Address addr) {
125     super(addr);
126   }
127 
128   public long value() {
129     return markField.getValue(addr);
130   }
131 
132   public Address valueAsAddress() {
133     return addr.getAddressAt(markField.getOffset());
134   }
135 
136   // Biased locking accessors
137   // These must be checked by all code which calls into the
138   // ObjectSynchoronizer and other code. The biasing is not understood
139   // by the lower-level CAS-based locking code, although the runtime
140   // fixes up biased locks to be compatible with it when a bias is
141   // revoked.
142   public boolean hasBiasPattern() {
143     return (Bits.maskBitsLong(value(), biasedLockMaskInPlace) == biasedLockPattern);

198       Assert.that(hasMonitor(), "check");
199     }
200     // Use xor instead of &~ to provide one extra tag-bit check.
201     Address monAddr = valueAsAddress().xorWithMask(monitorValue);
202     return new ObjectMonitor(monAddr);
203   }
204   public boolean hasDisplacedMarkHelper() {
205     return ((value() & unlockedValue) == 0);
206   }
207   public Mark displacedMarkHelper() {
208     if (Assert.ASSERTS_ENABLED) {
209       Assert.that(hasDisplacedMarkHelper(), "check");
210     }
211     Address addr = valueAsAddress().andWithMask(~monitorValue);
212     return new Mark(addr.getAddressAt(0));
213   }
214   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
215 
216   // hash operations
217   public long hash() {
218     return Bits.maskBitsLong(value() >> hashShift, hashMask);




219   }
220 
221   public boolean hasNoHash() {
222     return hash() == noHash;
223   }
224 






225   // Debugging
226   public void printOn(PrintStream tty) {
227     if (isLocked()) {
228       tty.print("locked(0x" +
229                 Long.toHexString(value()) + ")->");
230       displacedMarkHelper().printOn(tty);
231     } else {
232       if (Assert.ASSERTS_ENABLED) {
233         Assert.that(isUnlocked(), "just checking");
234       }
235       tty.print("mark(");
236       tty.print("hash " + Long.toHexString(hash()) + ",");
237       tty.print("age " + age() + ")");
238     }
239   }
240 
241   public long getSize() { return (long)(value() >> sizeShift); }
242 }

 35 import sun.jvm.hotspot.utilities.Observer;
 36 
 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     biasedLockBits      = db.lookupLongConstant("markWord::biased_lock_bits").longValue();
 53     maxHashBits         = db.lookupLongConstant("markWord::max_hash_bits").longValue();
 54     hashBits            = db.lookupLongConstant("markWord::hash_bits").longValue();
 55     hashBitsCompact     = db.lookupLongConstant("markWord::hash_bits_compact").longValue();
 56     lockShift           = db.lookupLongConstant("markWord::lock_shift").longValue();
 57     biasedLockShift     = db.lookupLongConstant("markWord::biased_lock_shift").longValue();
 58     ageShift            = db.lookupLongConstant("markWord::age_shift").longValue();
 59     hashShift           = db.lookupLongConstant("markWord::hash_shift").longValue();
 60     hashShiftCompact    = db.lookupLongConstant("markWord::hash_shift_compact").longValue();
 61     if (VM.getVM().isLP64()) {
 62       klassShift          = db.lookupLongConstant("markWord::klass_shift").longValue();
 63     }
 64     lockMask            = db.lookupLongConstant("markWord::lock_mask").longValue();
 65     lockMaskInPlace     = db.lookupLongConstant("markWord::lock_mask_in_place").longValue();
 66     biasedLockMask      = db.lookupLongConstant("markWord::biased_lock_mask").longValue();
 67     biasedLockMaskInPlace  = db.lookupLongConstant("markWord::biased_lock_mask_in_place").longValue();
 68     biasedLockBitInPlace  = db.lookupLongConstant("markWord::biased_lock_bit_in_place").longValue();
 69     ageMask             = db.lookupLongConstant("markWord::age_mask").longValue();
 70     ageMaskInPlace      = db.lookupLongConstant("markWord::age_mask_in_place").longValue();
 71     hashMask            = db.lookupLongConstant("markWord::hash_mask").longValue();
 72     hashMaskInPlace     = db.lookupLongConstant("markWord::hash_mask_in_place").longValue();
 73     hashMaskCompact     = db.lookupLongConstant("markWord::hash_mask_compact").longValue();
 74     hashMaskCompactInPlace = db.lookupLongConstant("markWord::hash_mask_compact_in_place").longValue();
 75     biasedLockAlignment  = db.lookupLongConstant("markWord::biased_lock_alignment").longValue();
 76     lockedValue         = db.lookupLongConstant("markWord::locked_value").longValue();
 77     unlockedValue       = db.lookupLongConstant("markWord::unlocked_value").longValue();
 78     monitorValue        = db.lookupLongConstant("markWord::monitor_value").longValue();
 79     markedValue         = db.lookupLongConstant("markWord::marked_value").longValue();
 80     biasedLockPattern = db.lookupLongConstant("markWord::biased_lock_pattern").longValue();
 81     noHash              = db.lookupLongConstant("markWord::no_hash").longValue();
 82     noHashInPlace       = db.lookupLongConstant("markWord::no_hash_in_place").longValue();
 83     noLockInPlace       = db.lookupLongConstant("markWord::no_lock_in_place").longValue();
 84     maxAge              = db.lookupLongConstant("markWord::max_age").longValue();
 85   }
 86 
 87   // Field accessors
 88   private static CIntegerField markField;
 89 
 90   // Constants -- read from VM
 91   private static long ageBits;
 92   private static long lockBits;
 93   private static long biasedLockBits;
 94   private static long maxHashBits;
 95   private static long hashBits;
 96   private static long hashBitsCompact;
 97 
 98   private static long lockShift;
 99   private static long biasedLockShift;
100   private static long ageShift;
101   private static long hashShift;
102   private static long hashShiftCompact;
103   private static long klassShift;
104 
105   private static long lockMask;
106   private static long lockMaskInPlace;
107   private static long biasedLockMask;
108   private static long biasedLockMaskInPlace;
109   private static long biasedLockBitInPlace;
110   private static long ageMask;
111   private static long ageMaskInPlace;
112   private static long hashMask;
113   private static long hashMaskInPlace;
114   private static long hashMaskCompact;
115   private static long hashMaskCompactInPlace;
116   private static long biasedLockAlignment;
117 
118   private static long lockedValue;
119   private static long unlockedValue;
120   private static long monitorValue;
121   private static long markedValue;
122   private static long biasedLockPattern;
123 
124   private static long noHash;
125 
126   private static long noHashInPlace;
127   private static long noLockInPlace;
128 
129   private static long maxAge;
130 
131   /* Constants in markWord used by CMS. */
132   private static long cmsShift;
133   private static long cmsMask;
134   private static long sizeShift;
135 
136   public static long getKlassShift() {
137     return klassShift;
138   }
139 
140   public Mark(Address addr) {
141     super(addr);
142   }
143 
144   public long value() {
145     return markField.getValue(addr);
146   }
147 
148   public Address valueAsAddress() {
149     return addr.getAddressAt(markField.getOffset());
150   }
151 
152   // Biased locking accessors
153   // These must be checked by all code which calls into the
154   // ObjectSynchoronizer and other code. The biasing is not understood
155   // by the lower-level CAS-based locking code, although the runtime
156   // fixes up biased locks to be compatible with it when a bias is
157   // revoked.
158   public boolean hasBiasPattern() {
159     return (Bits.maskBitsLong(value(), biasedLockMaskInPlace) == biasedLockPattern);

214       Assert.that(hasMonitor(), "check");
215     }
216     // Use xor instead of &~ to provide one extra tag-bit check.
217     Address monAddr = valueAsAddress().xorWithMask(monitorValue);
218     return new ObjectMonitor(monAddr);
219   }
220   public boolean hasDisplacedMarkHelper() {
221     return ((value() & unlockedValue) == 0);
222   }
223   public Mark displacedMarkHelper() {
224     if (Assert.ASSERTS_ENABLED) {
225       Assert.that(hasDisplacedMarkHelper(), "check");
226     }
227     Address addr = valueAsAddress().andWithMask(~monitorValue);
228     return new Mark(addr.getAddressAt(0));
229   }
230   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
231 
232   // hash operations
233   public long hash() {
234     if (VM.getVM().isCompactObjectHeadersEnabled()) {
235       return Bits.maskBitsLong(value() >> hashShiftCompact, hashMaskCompact);
236     } else {
237       return Bits.maskBitsLong(value() >> hashShift, hashMask);
238     }
239   }
240 
241   public boolean hasNoHash() {
242     return hash() == noHash;
243   }
244 
245   public Klass getKlass() {
246     assert(VM.getVM().isCompactObjectHeadersEnabled());
247     assert(!hasMonitor());
248     return (Klass)Metadata.instantiateWrapperFor(addr.getCompKlassAddressAt(0));
249   }
250 
251   // Debugging
252   public void printOn(PrintStream tty) {
253     if (isLocked()) {
254       tty.print("locked(0x" +
255                 Long.toHexString(value()) + ")->");
256       displacedMarkHelper().printOn(tty);
257     } else {
258       if (Assert.ASSERTS_ENABLED) {
259         Assert.that(isUnlocked(), "just checking");
260       }
261       tty.print("mark(");
262       tty.print("hash " + Long.toHexString(hash()) + ",");
263       tty.print("age " + age() + ")");
264     }
265   }
266 
267   public long getSize() { return (long)(value() >> sizeShift); }
268 }
< prev index next >