< prev index next >

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

Print this page

 34 import sun.jvm.hotspot.utilities.Observable;
 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     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   public Mark(Address addr) {
106     super(addr);
107   }
108 
109   public long value() {
110     return markField.getValue(addr);
111   }
112 
113   public Address valueAsAddress() {
114     return addr.getAddressAt(markField.getOffset());
115   }
116 
117   // lock accessors (note that these assume lock_shift == 0)
118   public boolean isLocked() {
119     return (Bits.maskBitsLong(value(), lockMaskInPlace) != unlockedValue);
120   }
121   public boolean isUnlocked() {
122     return (Bits.maskBitsLong(value(), lockMaskInPlace) == unlockedValue);
123   }
124   public boolean isMarked() {

139   // WARNING: The following routines are used EXCLUSIVELY by
140   // synchronization functions. They are not really gc safe.
141   // They must get updated if markWord layout get changed.
142 
143   public boolean hasLocker() {
144     return ((value() & lockMaskInPlace) == lockedValue);
145   }
146   public BasicLock locker() {
147     if (Assert.ASSERTS_ENABLED) {
148       Assert.that(hasLocker(), "check");
149     }
150     return new BasicLock(valueAsAddress());
151   }
152   public boolean hasMonitor() {
153     return ((value() & monitorValue) != 0);
154   }
155   public ObjectMonitor monitor() {
156     if (Assert.ASSERTS_ENABLED) {
157       Assert.that(hasMonitor(), "check");
158     }










159     // Use xor instead of &~ to provide one extra tag-bit check.
160     Address monAddr = valueAsAddress().xorWithMask(monitorValue);
161     return new ObjectMonitor(monAddr);
162   }
163   public boolean hasDisplacedMarkHelper() {
164     return ((value() & unlockedValue) == 0);
165   }
166   public Mark displacedMarkHelper() {
167     if (Assert.ASSERTS_ENABLED) {
168       Assert.that(hasDisplacedMarkHelper(), "check");
169     }
170     Address addr = valueAsAddress().andWithMask(~monitorValue);
171     return new Mark(addr.getAddressAt(0));
172   }
173   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
174 
175   // hash operations
176   public long hash() {
177     return Bits.maskBitsLong(value() >> hashShift, hashMask);




178   }
179 
180   public boolean hasNoHash() {
181     return hash() == noHash;
182   }
183 





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

 34 import sun.jvm.hotspot.utilities.Observable;
 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     maxHashBits         = db.lookupLongConstant("markWord::max_hash_bits").longValue();
 53     hashBits            = db.lookupLongConstant("markWord::hash_bits").longValue();
 54     hashBitsCompact     = db.lookupLongConstant("markWord::hash_bits_compact").longValue();
 55     lockShift           = db.lookupLongConstant("markWord::lock_shift").longValue();
 56     ageShift            = db.lookupLongConstant("markWord::age_shift").longValue();
 57     hashShift           = db.lookupLongConstant("markWord::hash_shift").longValue();
 58     hashShiftCompact    = db.lookupLongConstant("markWord::hash_shift_compact").longValue();
 59     if (VM.getVM().isLP64()) {
 60       klassShift          = db.lookupLongConstant("markWord::klass_shift").longValue();
 61     }
 62     lockMask            = db.lookupLongConstant("markWord::lock_mask").longValue();
 63     lockMaskInPlace     = db.lookupLongConstant("markWord::lock_mask_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     hashMaskCompact     = db.lookupLongConstant("markWord::hash_mask_compact").longValue();
 69     hashMaskCompactInPlace = db.lookupLongConstant("markWord::hash_mask_compact_in_place").longValue();
 70     lockedValue         = db.lookupLongConstant("markWord::locked_value").longValue();
 71     unlockedValue       = db.lookupLongConstant("markWord::unlocked_value").longValue();
 72     monitorValue        = db.lookupLongConstant("markWord::monitor_value").longValue();
 73     markedValue         = db.lookupLongConstant("markWord::marked_value").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 maxHashBits;
 87   private static long hashBits;
 88   private static long hashBitsCompact;
 89 
 90   private static long lockShift;
 91   private static long ageShift;
 92   private static long hashShift;
 93   private static long hashShiftCompact;
 94   private static long klassShift;
 95 
 96   private static long lockMask;
 97   private static long lockMaskInPlace;
 98   private static long ageMask;
 99   private static long ageMaskInPlace;
100   private static long hashMask;
101   private static long hashMaskInPlace;
102   private static long hashMaskCompact;
103   private static long hashMaskCompactInPlace;
104 
105   private static long lockedValue;
106   private static long unlockedValue;
107   private static long monitorValue;
108   private static long markedValue;
109 
110   private static long noHash;
111 
112   private static long noHashInPlace;
113   private static long noLockInPlace;
114 
115   private static long maxAge;
116 
117   public static long getKlassShift() {
118     return klassShift;
119   }
120 
121   public Mark(Address addr) {
122     super(addr);
123   }
124 
125   public long value() {
126     return markField.getValue(addr);
127   }
128 
129   public Address valueAsAddress() {
130     return addr.getAddressAt(markField.getOffset());
131   }
132 
133   // lock accessors (note that these assume lock_shift == 0)
134   public boolean isLocked() {
135     return (Bits.maskBitsLong(value(), lockMaskInPlace) != unlockedValue);
136   }
137   public boolean isUnlocked() {
138     return (Bits.maskBitsLong(value(), lockMaskInPlace) == unlockedValue);
139   }
140   public boolean isMarked() {

155   // WARNING: The following routines are used EXCLUSIVELY by
156   // synchronization functions. They are not really gc safe.
157   // They must get updated if markWord layout get changed.
158 
159   public boolean hasLocker() {
160     return ((value() & lockMaskInPlace) == lockedValue);
161   }
162   public BasicLock locker() {
163     if (Assert.ASSERTS_ENABLED) {
164       Assert.that(hasLocker(), "check");
165     }
166     return new BasicLock(valueAsAddress());
167   }
168   public boolean hasMonitor() {
169     return ((value() & monitorValue) != 0);
170   }
171   public ObjectMonitor monitor() {
172     if (Assert.ASSERTS_ENABLED) {
173       Assert.that(hasMonitor(), "check");
174     }
175     if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
176       Iterator it = ObjectSynchronizer.objectMonitorIterator();
177       while (it != null && it.hasNext()) {
178         ObjectMonitor mon = (ObjectMonitor)it.next();
179         if (getAddress().equals(mon.object())) {
180           return mon;
181         }
182       }
183       return null;
184     }
185     // Use xor instead of &~ to provide one extra tag-bit check.
186     Address monAddr = valueAsAddress().xorWithMask(monitorValue);
187     return new ObjectMonitor(monAddr);
188   }
189   public boolean hasDisplacedMarkHelper() {
190     return ((value() & unlockedValue) == 0);
191   }
192   public Mark displacedMarkHelper() {
193     if (Assert.ASSERTS_ENABLED) {
194       Assert.that(hasDisplacedMarkHelper(), "check");
195     }
196     Address addr = valueAsAddress().andWithMask(~monitorValue);
197     return new Mark(addr.getAddressAt(0));
198   }
199   public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
200 
201   // hash operations
202   public long hash() {
203     if (VM.getVM().isCompactObjectHeadersEnabled()) {
204       return Bits.maskBitsLong(value() >> hashShiftCompact, hashMaskCompact);
205     } else {
206       return Bits.maskBitsLong(value() >> hashShift, hashMask);
207     }
208   }
209 
210   public boolean hasNoHash() {
211     return hash() == noHash;
212   }
213 
214   public Klass getKlass() {
215     assert(VM.getVM().isCompactObjectHeadersEnabled());
216     return (Klass)Metadata.instantiateWrapperFor(addr.getCompKlassAddressAt(0));
217   }
218 
219   // Debugging
220   public void printOn(PrintStream tty) {
221     if (isLocked()) {
222       tty.print("locked(0x" +
223                 Long.toHexString(value()) + ")->");
224       displacedMarkHelper().printOn(tty);
225     } else {
226       if (Assert.ASSERTS_ENABLED) {
227         Assert.that(isUnlocked(), "just checking");
228       }
229       tty.print("mark(");
230       tty.print("hash " + Long.toHexString(hash()) + ",");
231       tty.print("age " + age() + ")");
232     }
233   }
234 
235   public long getSize() { return (long)value(); }
236 }
< prev index next >