annotate agent/src/share/classes/sun/jvm/hotspot/oops/Mark.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 790e66e5fbac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 /** Mark is the analogue of the VM's markOop. In this system it does
a61af66fc99e Initial load
duke
parents:
diff changeset
36 not subclass Oop but VMObject. For a mark on the stack, the mark's
a61af66fc99e Initial load
duke
parents:
diff changeset
37 address will be an Address; for a mark in the header of an object,
a61af66fc99e Initial load
duke
parents:
diff changeset
38 it will be an OopHandle. It is assumed in a couple of places in
a61af66fc99e Initial load
duke
parents:
diff changeset
39 this code that the mark is the first word in an object. */
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public class Mark extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47 });
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 Type type = db.lookupType("oopDesc");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 markField = type.getCIntegerField("_mark");
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ageBits = db.lookupLongConstant("markOopDesc::age_bits").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 lockBits = db.lookupLongConstant("markOopDesc::lock_bits").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 biasedLockBits = db.lookupLongConstant("markOopDesc::biased_lock_bits").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 maxHashBits = db.lookupLongConstant("markOopDesc::max_hash_bits").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 hashBits = db.lookupLongConstant("markOopDesc::hash_bits").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 lockShift = db.lookupLongConstant("markOopDesc::lock_shift").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 biasedLockShift = db.lookupLongConstant("markOopDesc::biased_lock_shift").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ageShift = db.lookupLongConstant("markOopDesc::age_shift").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 hashShift = db.lookupLongConstant("markOopDesc::hash_shift").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 lockMask = db.lookupLongConstant("markOopDesc::lock_mask").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 lockMaskInPlace = db.lookupLongConstant("markOopDesc::lock_mask_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 biasedLockMask = db.lookupLongConstant("markOopDesc::biased_lock_mask").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 biasedLockMaskInPlace = db.lookupLongConstant("markOopDesc::biased_lock_mask_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 biasedLockBitInPlace = db.lookupLongConstant("markOopDesc::biased_lock_bit_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 ageMask = db.lookupLongConstant("markOopDesc::age_mask").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 ageMaskInPlace = db.lookupLongConstant("markOopDesc::age_mask_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 hashMask = db.lookupLongConstant("markOopDesc::hash_mask").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 hashMaskInPlace = db.lookupLongConstant("markOopDesc::hash_mask_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 biasedLockAlignment = db.lookupLongConstant("markOopDesc::biased_lock_alignment").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 lockedValue = db.lookupLongConstant("markOopDesc::locked_value").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 unlockedValue = db.lookupLongConstant("markOopDesc::unlocked_value").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 monitorValue = db.lookupLongConstant("markOopDesc::monitor_value").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 markedValue = db.lookupLongConstant("markOopDesc::marked_value").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 biasedLockPattern = db.lookupLongConstant("markOopDesc::biased_lock_pattern").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 noHash = db.lookupLongConstant("markOopDesc::no_hash").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 noHashInPlace = db.lookupLongConstant("markOopDesc::no_hash_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 noLockInPlace = db.lookupLongConstant("markOopDesc::no_lock_in_place").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 maxAge = db.lookupLongConstant("markOopDesc::max_age").longValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Field accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
85 private static CIntegerField markField;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Constants -- read from VM
a61af66fc99e Initial load
duke
parents:
diff changeset
88 private static long ageBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 private static long lockBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 private static long biasedLockBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private static long maxHashBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 private static long hashBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private static long lockShift;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 private static long biasedLockShift;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 private static long ageShift;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 private static long hashShift;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 private static long lockMask;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 private static long lockMaskInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 private static long biasedLockMask;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 private static long biasedLockMaskInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 private static long biasedLockBitInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 private static long ageMask;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 private static long ageMaskInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 private static long hashMask;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private static long hashMaskInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 private static long biasedLockAlignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 private static long lockedValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 private static long unlockedValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private static long monitorValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private static long markedValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private static long biasedLockPattern;
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 private static long noHash;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 private static long noHashInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 private static long noLockInPlace;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 private static long maxAge;
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public Mark(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public long value() {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return markField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public Address valueAsAddress() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return addr.getAddressAt(markField.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Biased locking accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // These must be checked by all code which calls into the
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // ObjectSynchoronizer and other code. The biasing is not understood
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // by the lower-level CAS-based locking code, although the runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // fixes up biased locks to be compatible with it when a bias is
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // revoked.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public boolean hasBiasPattern() {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return (Bits.maskBitsLong(value(), biasedLockMaskInPlace) == biasedLockPattern);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public JavaThread biasedLocker() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 Address addr = valueAsAddress().andWithMask(~(biasedLockMaskInPlace & ageMaskInPlace));
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return threads.createJavaThreadWrapper(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // Indicates that the mark gas the bias bit set but that it has not
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // yet been biased toward a particular thread
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public boolean isBiasedAnonymously() {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return hasBiasPattern() && (biasedLocker() == null);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // lock accessors (note that these assume lock_shift == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public boolean isLocked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return (Bits.maskBitsLong(value(), lockMaskInPlace) != unlockedValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public boolean isUnlocked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return (Bits.maskBitsLong(value(), biasedLockMaskInPlace) == unlockedValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 public boolean isMarked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return (Bits.maskBitsLong(value(), lockMaskInPlace) == markedValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Special temporary state of the markOop while being inflated.
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Code that looks at mark outside a lock need to take this into account.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public boolean isBeingInflated() {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return (value() == 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Should this header be preserved during GC?
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean mustBePreserved() {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return (!isUnlocked() || !hasNoHash());
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // WARNING: The following routines are used EXCLUSIVELY by
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // synchronization functions. They are not really gc safe.
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // They must get updated if markOop layout get changed.
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // markOop set_unlocked() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // return markOop(value() | unlocked_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 public boolean hasLocker() {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return ((value() & lockMaskInPlace) == lockedValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public BasicLock locker() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 Assert.that(hasLocker(), "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return new BasicLock(valueAsAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public boolean hasMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return ((value() & monitorValue) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public ObjectMonitor monitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Assert.that(hasMonitor(), "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Use xor instead of &~ to provide one extra tag-bit check.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Address monAddr = valueAsAddress().xorWithMask(monitorValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 return new ObjectMonitor(monAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 public boolean hasDisplacedMarkHelper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return ((value() & unlockedValue) == 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 public Mark displacedMarkHelper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 Assert.that(hasDisplacedMarkHelper(), "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 Address addr = valueAsAddress().andWithMask(~monitorValue);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return new Mark(addr.getAddressAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // void set_displaced_mark_helper(markOop m) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // assert(has_displaced_mark_helper(), "check");
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // intptr_t ptr = (value() & ~monitor_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // *(markOop*)ptr = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // markOop copy_set_hash(intptr_t hash) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // intptr_t tmp = value() & (~hash_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // tmp |= ((hash & hash_mask) << hash_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // return (markOop)tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // it is only used to be stored into BasicLock as the
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // indicator that the lock is using heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // static markOop unused_mark() {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // return (markOop) marked_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // // the following two functions create the markOop to be
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // // stored into object header, it encodes monitor info
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // static markOop encode(BasicLock* lock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // return (markOop) lock;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // static markOop encode(ObjectMonitor* monitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // intptr_t tmp = (intptr_t) monitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // return (markOop) (tmp | monitor_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // used for alignment-based marking to reuse the busy state to encode pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // (see markOop_alignment.hpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // markOop clear_lock_bits() { return markOop(value() & ~lock_mask_in_place); }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 //
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // // age operations
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // markOop set_marked() { return markOop((value() & ~lock_mask_in_place) | marked_value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 //
a61af66fc99e Initial load
duke
parents:
diff changeset
249 public int age() { return (int) Bits.maskBitsLong(value() >> ageShift, ageMask); }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // markOop set_age(int v) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // assert((v & ~age_mask) == 0, "shouldn't overflow age field");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // return markOop((value() & ~age_mask_in_place) | (((intptr_t)v & age_mask) << age_shift));
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // markOop incr_age() const { return age() == max_age ? markOop(this) : set_age(age() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // hash operations
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public long hash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return Bits.maskBitsLong(value() >> hashShift, hashMask);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 public boolean hasNoHash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 return hash() == noHash;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // Prototype mark for initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // static markOop prototype() {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // return markOop( no_hash_in_place | no_lock_in_place );
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
272 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (isLocked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 tty.print("locked(0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
275 Long.toHexString(value()) + ")->");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 displacedMarkHelper().printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 Assert.that(isUnlocked(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 tty.print("mark(");
a61af66fc99e Initial load
duke
parents:
diff changeset
282 tty.print("hash " + Long.toHexString(hash()) + ",");
a61af66fc99e Initial load
duke
parents:
diff changeset
283 tty.print("age " + age() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // FIXME
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // // Prepare address of oop for placement into mark
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // inline static markOop encode_pointer_as_mark(void* p) { return markOop(p)->set_marked(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 //
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // // Recover address of oop from encoded form used in mark
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // inline void* decode_pointer() { return clear_lock_bits(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }