author | stefank |
Mon, 19 Aug 2019 11:30:03 +0200 | |
changeset 57811 | 947252a54b98 |
parent 57777 | src/hotspot/share/oops/markOop.hpp@90ead0febf56 |
child 57812 | 9bb28ccc6106 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5541
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5541
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5541
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
57811 | 25 |
#ifndef SHARE_OOPS_MARKWORD_HPP |
26 |
#define SHARE_OOPS_MARKWORD_HPP |
|
7397 | 27 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
28 |
#include "metaprogramming/integralConstant.hpp" |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
29 |
#include "metaprogramming/primitiveConversions.hpp" |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
30 |
#include "oops/oopsHierarchy.hpp" |
7397 | 31 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
32 |
// The markWord describes the header of an object. |
1 | 33 |
// |
5541
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
34 |
// Bit-format of an object header (most significant first, big endian layout below): |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
35 |
// |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
36 |
// 32 bits: |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
37 |
// -------- |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
38 |
// hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
39 |
// JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
40 |
// size:32 ------------------------------------------>| (CMS free block) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
41 |
// PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) |
1 | 42 |
// |
5541
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
43 |
// 64 bits: |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
44 |
// -------- |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
45 |
// unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
46 |
// JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
47 |
// PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
48 |
// size:64 ----------------------------------------------------->| (CMS free block) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
49 |
// |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
50 |
// unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
51 |
// JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
52 |
// narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
53 |
// unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block) |
1 | 54 |
// |
55 |
// - hash contains the identity hash value: largest value is |
|
56 |
// 31 bits, see os::random(). Also, 64-bit vm's require |
|
57 |
// a hash value no bigger than 32 bits because they will not |
|
58 |
// properly generate a mask larger than that: see library_call.cpp |
|
59 |
// and c1_CodePatterns_sparc.cpp. |
|
60 |
// |
|
61 |
// - the biased lock pattern is used to bias a lock toward a given |
|
62 |
// thread. When this pattern is set in the low three bits, the lock |
|
63 |
// is either biased toward a given thread or "anonymously" biased, |
|
64 |
// indicating that it is possible for it to be biased. When the |
|
65 |
// lock is biased toward a given thread, locking and unlocking can |
|
66 |
// be performed by that thread without using atomic operations. |
|
67 |
// When a lock's bias is revoked, it reverts back to the normal |
|
68 |
// locking scheme described below. |
|
69 |
// |
|
70 |
// Note that we are overloading the meaning of the "unlocked" state |
|
71 |
// of the header. Because we steal a bit from the age we can |
|
72 |
// guarantee that the bias pattern will never be seen for a truly |
|
73 |
// unlocked object. |
|
74 |
// |
|
75 |
// Note also that the biased state contains the age bits normally |
|
76 |
// contained in the object header. Large increases in scavenge |
|
77 |
// times were seen when these bits were absent and an arbitrary age |
|
78 |
// assigned to all biased objects, because they tended to consume a |
|
79 |
// significant fraction of the eden semispaces and were not |
|
80 |
// promoted promptly, causing an increase in the amount of copying |
|
81 |
// performed. The runtime system aligns all JavaThread* pointers to |
|
5541
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
82 |
// a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
83 |
// to make room for the age bits & the epoch bits (used in support of |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
84 |
// biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). |
1 | 85 |
// |
86 |
// [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread |
|
87 |
// [0 | epoch | age | 1 | 01] lock is anonymously biased |
|
88 |
// |
|
89 |
// - the two lock bits are used to describe three states: locked/unlocked and monitor. |
|
90 |
// |
|
91 |
// [ptr | 00] locked ptr points to real header on stack |
|
92 |
// [header | 0 | 01] unlocked regular object header |
|
93 |
// [ptr | 10] monitor inflated lock (header is wapped out) |
|
94 |
// [ptr | 11] marked used by markSweep to mark an object |
|
95 |
// not valid at any other time |
|
96 |
// |
|
97 |
// We assume that stack/thread pointers have the lowest two bits cleared. |
|
98 |
||
99 |
class BasicLock; |
|
100 |
class ObjectMonitor; |
|
101 |
class JavaThread; |
|
102 |
||
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
103 |
class markWord { |
1 | 104 |
private: |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
105 |
uintptr_t _value; |
1 | 106 |
|
107 |
public: |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
108 |
explicit markWord(uintptr_t value) : _value(value) {} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
109 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
110 |
markWord() { /* uninitialized */} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
111 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
112 |
// It is critical for performance that this class be trivially |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
113 |
// destructable, copyable, and assignable. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
114 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
115 |
static markWord from_pointer(void* ptr) { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
116 |
return markWord((uintptr_t)ptr); |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
117 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
118 |
void* to_pointer() const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
119 |
return (void*)_value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
120 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
121 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
122 |
bool operator==(const markWord& other) const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
123 |
return _value == other._value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
124 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
125 |
bool operator!=(const markWord& other) const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
126 |
return !operator==(other); |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
127 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
128 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
129 |
// Conversion |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
130 |
uintptr_t value() const { return _value; } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
131 |
|
1 | 132 |
// Constants |
133 |
enum { age_bits = 4, |
|
134 |
lock_bits = 2, |
|
135 |
biased_lock_bits = 1, |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
221
diff
changeset
|
136 |
max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits, |
1 | 137 |
hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits, |
613 | 138 |
cms_bits = LP64_ONLY(1) NOT_LP64(0), |
1 | 139 |
epoch_bits = 2 |
140 |
}; |
|
141 |
||
142 |
// The biased locking code currently requires that the age bits be |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
143 |
// contiguous to the lock bits. |
1 | 144 |
enum { lock_shift = 0, |
145 |
biased_lock_shift = lock_bits, |
|
146 |
age_shift = lock_bits + biased_lock_bits, |
|
613 | 147 |
cms_shift = age_shift + age_bits, |
148 |
hash_shift = cms_shift + cms_bits, |
|
1 | 149 |
epoch_shift = hash_shift |
150 |
}; |
|
151 |
||
152 |
enum { lock_mask = right_n_bits(lock_bits), |
|
153 |
lock_mask_in_place = lock_mask << lock_shift, |
|
154 |
biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits), |
|
155 |
biased_lock_mask_in_place= biased_lock_mask << lock_shift, |
|
156 |
biased_lock_bit_in_place = 1 << biased_lock_shift, |
|
157 |
age_mask = right_n_bits(age_bits), |
|
158 |
age_mask_in_place = age_mask << age_shift, |
|
159 |
epoch_mask = right_n_bits(epoch_bits), |
|
613 | 160 |
epoch_mask_in_place = epoch_mask << epoch_shift, |
161 |
cms_mask = right_n_bits(cms_bits), |
|
162 |
cms_mask_in_place = cms_mask << cms_shift |
|
1 | 163 |
}; |
164 |
||
54335
d9f6d16299b1
8221408: Windows 32bit build build errors/warnings in hotspot
stuefe
parents:
53244
diff
changeset
|
165 |
const static uintptr_t hash_mask = right_n_bits(hash_bits); |
d9f6d16299b1
8221408: Windows 32bit build build errors/warnings in hotspot
stuefe
parents:
53244
diff
changeset
|
166 |
const static uintptr_t hash_mask_in_place = hash_mask << hash_shift; |
d9f6d16299b1
8221408: Windows 32bit build build errors/warnings in hotspot
stuefe
parents:
53244
diff
changeset
|
167 |
|
1 | 168 |
// Alignment of JavaThread pointers encoded in object header required by biased locking |
169 |
enum { biased_lock_alignment = 2 << (epoch_shift + epoch_bits) |
|
170 |
}; |
|
171 |
||
172 |
enum { locked_value = 0, |
|
173 |
unlocked_value = 1, |
|
174 |
monitor_value = 2, |
|
175 |
marked_value = 3, |
|
176 |
biased_lock_pattern = 5 |
|
177 |
}; |
|
178 |
||
179 |
enum { no_hash = 0 }; // no hash value assigned |
|
180 |
||
181 |
enum { no_hash_in_place = (address_word)no_hash << hash_shift, |
|
182 |
no_lock_in_place = unlocked_value |
|
183 |
}; |
|
184 |
||
185 |
enum { max_age = age_mask }; |
|
186 |
||
187 |
enum { max_bias_epoch = epoch_mask }; |
|
188 |
||
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
189 |
// Creates a markWord with all bits set to zero. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
190 |
static markWord zero() { return markWord(uintptr_t(0)); } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
191 |
|
1 | 192 |
// Biased Locking accessors. |
193 |
// These must be checked by all code which calls into the |
|
194 |
// ObjectSynchronizer and other code. The biasing is not understood |
|
195 |
// by the lower-level CAS-based locking code, although the runtime |
|
196 |
// fixes up biased locks to be compatible with it when a bias is |
|
197 |
// revoked. |
|
198 |
bool has_bias_pattern() const { |
|
199 |
return (mask_bits(value(), biased_lock_mask_in_place) == biased_lock_pattern); |
|
200 |
} |
|
201 |
JavaThread* biased_locker() const { |
|
202 |
assert(has_bias_pattern(), "should not call this otherwise"); |
|
203 |
return (JavaThread*) ((intptr_t) (mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place)))); |
|
204 |
} |
|
205 |
// Indicates that the mark has the bias bit set but that it has not |
|
206 |
// yet been biased toward a particular thread |
|
207 |
bool is_biased_anonymously() const { |
|
208 |
return (has_bias_pattern() && (biased_locker() == NULL)); |
|
209 |
} |
|
210 |
// Indicates epoch in which this bias was acquired. If the epoch |
|
211 |
// changes due to too many bias revocations occurring, the biases |
|
212 |
// from the previous epochs are all considered invalid. |
|
213 |
int bias_epoch() const { |
|
214 |
assert(has_bias_pattern(), "should not call this otherwise"); |
|
215 |
return (mask_bits(value(), epoch_mask_in_place) >> epoch_shift); |
|
216 |
} |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
217 |
markWord set_bias_epoch(int epoch) { |
1 | 218 |
assert(has_bias_pattern(), "should not call this otherwise"); |
219 |
assert((epoch & (~epoch_mask)) == 0, "epoch overflow"); |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
220 |
return markWord(mask_bits(value(), ~epoch_mask_in_place) | (epoch << epoch_shift)); |
1 | 221 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
222 |
markWord incr_bias_epoch() { |
1 | 223 |
return set_bias_epoch((1 + bias_epoch()) & epoch_mask); |
224 |
} |
|
225 |
// Prototype mark for initialization |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
226 |
static markWord biased_locking_prototype() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
227 |
return markWord( biased_lock_pattern ); |
1 | 228 |
} |
229 |
||
230 |
// lock accessors (note that these assume lock_shift == 0) |
|
231 |
bool is_locked() const { |
|
232 |
return (mask_bits(value(), lock_mask_in_place) != unlocked_value); |
|
233 |
} |
|
234 |
bool is_unlocked() const { |
|
235 |
return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); |
|
236 |
} |
|
237 |
bool is_marked() const { |
|
238 |
return (mask_bits(value(), lock_mask_in_place) == marked_value); |
|
239 |
} |
|
240 |
bool is_neutral() const { return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); } |
|
241 |
||
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
242 |
// Special temporary state of the markWord while being inflated. |
1 | 243 |
// Code that looks at mark outside a lock need to take this into account. |
244 |
bool is_being_inflated() const { return (value() == 0); } |
|
245 |
||
246 |
// Distinguished markword value - used when inflating over |
|
247 |
// an existing stacklock. 0 indicates the markword is "BUSY". |
|
248 |
// Lockword mutators that use a LD...CAS idiom should always |
|
249 |
// check for and avoid overwriting a 0 value installed by some |
|
250 |
// other thread. (They should spin or block instead. The 0 value |
|
251 |
// is transient and *should* be short-lived). |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
252 |
static markWord INFLATING() { return zero(); } // inflate-in-progress |
1 | 253 |
|
254 |
// Should this header be preserved during GC? |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
255 |
inline bool must_be_preserved(oop obj_containing_mark) const; |
1 | 256 |
inline bool must_be_preserved_with_bias(oop obj_containing_mark) const; |
257 |
||
258 |
// Should this header (including its age bits) be preserved in the |
|
259 |
// case of a promotion failure during scavenge? |
|
260 |
// Note that we special case this situation. We want to avoid |
|
261 |
// calling BiasedLocking::preserve_marks()/restore_marks() (which |
|
262 |
// decrease the number of mark words that need to be preserved |
|
263 |
// during GC) during each scavenge. During scavenges in which there |
|
264 |
// is no promotion failure, we actually don't need to call the above |
|
265 |
// routines at all, since we don't mutate and re-initialize the |
|
266 |
// marks of promoted objects using init_mark(). However, during |
|
267 |
// scavenges which result in promotion failure, we do re-initialize |
|
268 |
// the mark words of objects, meaning that we should have called |
|
269 |
// these mark word preservation routines. Currently there's no good |
|
270 |
// place in which to call them in any of the scavengers (although |
|
271 |
// guarded by appropriate locks we could make one), but the |
|
272 |
// observation is that promotion failures are quite rare and |
|
273 |
// reducing the number of mark words preserved during them isn't a |
|
274 |
// high priority. |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
275 |
inline bool must_be_preserved_for_promotion_failure(oop obj_containing_mark) const; |
1 | 276 |
inline bool must_be_preserved_with_bias_for_promotion_failure(oop obj_containing_mark) const; |
277 |
||
278 |
// Should this header be preserved during a scavenge where CMS is |
|
279 |
// the old generation? |
|
280 |
// (This is basically the same body as must_be_preserved_for_promotion_failure(), |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
281 |
// but takes the Klass* as argument instead) |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
282 |
inline bool must_be_preserved_for_cms_scavenge(Klass* klass_of_obj_containing_mark) const; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
283 |
inline bool must_be_preserved_with_bias_for_cms_scavenge(Klass* klass_of_obj_containing_mark) const; |
1 | 284 |
|
285 |
// WARNING: The following routines are used EXCLUSIVELY by |
|
286 |
// synchronization functions. They are not really gc safe. |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
287 |
// They must get updated if markWord layout get changed. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
288 |
markWord set_unlocked() const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
289 |
return markWord(value() | unlocked_value); |
1 | 290 |
} |
291 |
bool has_locker() const { |
|
292 |
return ((value() & lock_mask_in_place) == locked_value); |
|
293 |
} |
|
294 |
BasicLock* locker() const { |
|
295 |
assert(has_locker(), "check"); |
|
296 |
return (BasicLock*) value(); |
|
297 |
} |
|
298 |
bool has_monitor() const { |
|
299 |
return ((value() & monitor_value) != 0); |
|
300 |
} |
|
301 |
ObjectMonitor* monitor() const { |
|
302 |
assert(has_monitor(), "check"); |
|
303 |
// Use xor instead of &~ to provide one extra tag-bit check. |
|
304 |
return (ObjectMonitor*) (value() ^ monitor_value); |
|
305 |
} |
|
306 |
bool has_displaced_mark_helper() const { |
|
307 |
return ((value() & unlocked_value) == 0); |
|
308 |
} |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
309 |
markWord displaced_mark_helper() const { |
1 | 310 |
assert(has_displaced_mark_helper(), "check"); |
311 |
intptr_t ptr = (value() & ~monitor_value); |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
312 |
return *(markWord*)ptr; |
1 | 313 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
314 |
void set_displaced_mark_helper(markWord m) const { |
1 | 315 |
assert(has_displaced_mark_helper(), "check"); |
316 |
intptr_t ptr = (value() & ~monitor_value); |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
317 |
((markWord*)ptr)->_value = m._value; |
1 | 318 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
319 |
markWord copy_set_hash(intptr_t hash) const { |
1 | 320 |
intptr_t tmp = value() & (~hash_mask_in_place); |
321 |
tmp |= ((hash & hash_mask) << hash_shift); |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
322 |
return markWord(tmp); |
1 | 323 |
} |
324 |
// it is only used to be stored into BasicLock as the |
|
325 |
// indicator that the lock is using heavyweight monitor |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
326 |
static markWord unused_mark() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
327 |
return markWord(marked_value); |
1 | 328 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
329 |
// the following two functions create the markWord to be |
1 | 330 |
// stored into object header, it encodes monitor info |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
331 |
static markWord encode(BasicLock* lock) { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
332 |
return from_pointer(lock); |
1 | 333 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
334 |
static markWord encode(ObjectMonitor* monitor) { |
1 | 335 |
intptr_t tmp = (intptr_t) monitor; |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
336 |
return markWord(tmp | monitor_value); |
1 | 337 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
338 |
static markWord encode(JavaThread* thread, uint age, int bias_epoch) { |
1 | 339 |
intptr_t tmp = (intptr_t) thread; |
340 |
assert(UseBiasedLocking && ((tmp & (epoch_mask_in_place | age_mask_in_place | biased_lock_mask_in_place)) == 0), "misaligned JavaThread pointer"); |
|
341 |
assert(age <= max_age, "age too large"); |
|
342 |
assert(bias_epoch <= max_bias_epoch, "bias epoch too large"); |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
343 |
return markWord(tmp | (bias_epoch << epoch_shift) | (age << age_shift) | biased_lock_pattern); |
1 | 344 |
} |
345 |
||
346 |
// used to encode pointers during GC |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
347 |
markWord clear_lock_bits() { return markWord(value() & ~lock_mask_in_place); } |
1 | 348 |
|
349 |
// age operations |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
350 |
markWord set_marked() { return markWord((value() & ~lock_mask_in_place) | marked_value); } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
351 |
markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); } |
1 | 352 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
353 |
uint age() const { return mask_bits(value() >> age_shift, age_mask); } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
354 |
markWord set_age(uint v) const { |
1 | 355 |
assert((v & ~age_mask) == 0, "shouldn't overflow age field"); |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
356 |
return markWord((value() & ~age_mask_in_place) | (((uintptr_t)v & age_mask) << age_shift)); |
1 | 357 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
358 |
markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); } |
1 | 359 |
|
360 |
// hash operations |
|
361 |
intptr_t hash() const { |
|
362 |
return mask_bits(value() >> hash_shift, hash_mask); |
|
363 |
} |
|
364 |
||
365 |
bool has_no_hash() const { |
|
366 |
return hash() == no_hash; |
|
367 |
} |
|
368 |
||
369 |
// Prototype mark for initialization |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
370 |
static markWord prototype() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
371 |
return markWord( no_hash_in_place | no_lock_in_place ); |
1 | 372 |
} |
373 |
||
374 |
// Helper function for restoration of unmarked mark oops during GC |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
375 |
static inline markWord prototype_for_object(oop obj); |
1 | 376 |
|
377 |
// Debugging |
|
378 |
void print_on(outputStream* st) const; |
|
379 |
||
380 |
// Prepare address of oop for placement into mark |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
381 |
inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); } |
1 | 382 |
|
383 |
// Recover address of oop from encoded form used in mark |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
384 |
inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); } |
221
ec745a0fe922
6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents:
1
diff
changeset
|
385 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
386 |
// These markWords indicate cms free chunk blocks and not objects. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
387 |
// In 64 bit, the markWord is set to distinguish them from oops. |
613 | 388 |
// These are defined in 32 bit mode for vmStructs. |
389 |
const static uintptr_t cms_free_chunk_pattern = 0x1; |
|
390 |
||
391 |
// Constants for the size field. |
|
392 |
enum { size_shift = cms_shift + cms_bits, |
|
393 |
size_bits = 35 // need for compressed oops 32G |
|
394 |
}; |
|
395 |
// These values are too big for Win64 |
|
396 |
const static uintptr_t size_mask = LP64_ONLY(right_n_bits(size_bits)) |
|
397 |
NOT_LP64(0); |
|
398 |
const static uintptr_t size_mask_in_place = |
|
399 |
(address_word)size_mask << size_shift; |
|
400 |
||
401 |
#ifdef _LP64 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
402 |
static markWord cms_free_prototype() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
403 |
return markWord(((intptr_t)prototype().value() & ~cms_mask_in_place) | |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
404 |
((cms_free_chunk_pattern & cms_mask) << cms_shift)); |
613 | 405 |
} |
406 |
uintptr_t cms_encoding() const { |
|
407 |
return mask_bits(value() >> cms_shift, cms_mask); |
|
408 |
} |
|
409 |
bool is_cms_free_chunk() const { |
|
410 |
return is_neutral() && |
|
411 |
(cms_encoding() & cms_free_chunk_pattern) == cms_free_chunk_pattern; |
|
412 |
} |
|
413 |
||
414 |
size_t get_size() const { return (size_t)(value() >> size_shift); } |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
415 |
static markWord set_size_and_free(size_t size) { |
613 | 416 |
assert((size & ~size_mask) == 0, "shouldn't overflow size field"); |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
417 |
return markWord(((intptr_t)cms_free_prototype().value() & ~size_mask_in_place) | |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
418 |
(((intptr_t)size & size_mask) << size_shift)); |
613 | 419 |
} |
420 |
#endif // _LP64 |
|
1 | 421 |
}; |
7397 | 422 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
423 |
// Support atomic operations. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
424 |
template<> |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
425 |
struct PrimitiveConversions::Translate<markWord> : public TrueType { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
426 |
typedef markWord Value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
427 |
typedef uintptr_t Decayed; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
428 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
429 |
static Decayed decay(const Value& x) { return x.value(); } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
430 |
static Value recover(Decayed x) { return Value(x); } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
431 |
}; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
432 |
|
57811 | 433 |
#endif // SHARE_OOPS_MARKWORD_HPP |