author | coleenp |
Wed, 13 Nov 2019 08:23:23 -0500 | |
changeset 59056 | 15936b142f86 |
parent 59053 | ba6c248cae19 |
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" |
57875
427b38332f20
8229836: Remove include of globals.hpp from allocation.hpp
stefank
parents:
57812
diff
changeset
|
31 |
#include "runtime/globals.hpp" |
7397 | 32 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
33 |
// The markWord describes the header of an object. |
1 | 34 |
// |
5541
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
35 |
// 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
|
36 |
// |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
37 |
// 32 bits: |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
38 |
// -------- |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
39 |
// 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
|
40 |
// JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) |
1 | 41 |
// |
5541
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
42 |
// 64 bits: |
19c39d42a747
6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents:
1388
diff
changeset
|
43 |
// -------- |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
44 |
// unused:25 hash:31 -->| unused_gap:1 age:4 biased_lock:1 lock:2 (normal object) |
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
45 |
// JavaThread*:54 epoch:2 unused_gap:1 age:4 biased_lock:1 lock:2 (biased object) |
1 | 46 |
// |
47 |
// - hash contains the identity hash value: largest value is |
|
48 |
// 31 bits, see os::random(). Also, 64-bit vm's require |
|
49 |
// a hash value no bigger than 32 bits because they will not |
|
50 |
// properly generate a mask larger than that: see library_call.cpp |
|
51 |
// and c1_CodePatterns_sparc.cpp. |
|
52 |
// |
|
53 |
// - the biased lock pattern is used to bias a lock toward a given |
|
54 |
// thread. When this pattern is set in the low three bits, the lock |
|
55 |
// is either biased toward a given thread or "anonymously" biased, |
|
56 |
// indicating that it is possible for it to be biased. When the |
|
57 |
// lock is biased toward a given thread, locking and unlocking can |
|
58 |
// be performed by that thread without using atomic operations. |
|
59 |
// When a lock's bias is revoked, it reverts back to the normal |
|
60 |
// locking scheme described below. |
|
61 |
// |
|
62 |
// Note that we are overloading the meaning of the "unlocked" state |
|
63 |
// of the header. Because we steal a bit from the age we can |
|
64 |
// guarantee that the bias pattern will never be seen for a truly |
|
65 |
// unlocked object. |
|
66 |
// |
|
67 |
// Note also that the biased state contains the age bits normally |
|
68 |
// contained in the object header. Large increases in scavenge |
|
69 |
// times were seen when these bits were absent and an arbitrary age |
|
70 |
// assigned to all biased objects, because they tended to consume a |
|
71 |
// significant fraction of the eden semispaces and were not |
|
72 |
// promoted promptly, causing an increase in the amount of copying |
|
73 |
// 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
|
74 |
// 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
|
75 |
// to make room for the age bits & the epoch bits (used in support of |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
76 |
// biased locking). |
1 | 77 |
// |
78 |
// [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread |
|
79 |
// [0 | epoch | age | 1 | 01] lock is anonymously biased |
|
80 |
// |
|
81 |
// - the two lock bits are used to describe three states: locked/unlocked and monitor. |
|
82 |
// |
|
83 |
// [ptr | 00] locked ptr points to real header on stack |
|
84 |
// [header | 0 | 01] unlocked regular object header |
|
85 |
// [ptr | 10] monitor inflated lock (header is wapped out) |
|
86 |
// [ptr | 11] marked used by markSweep to mark an object |
|
87 |
// not valid at any other time |
|
88 |
// |
|
89 |
// We assume that stack/thread pointers have the lowest two bits cleared. |
|
90 |
||
91 |
class BasicLock; |
|
92 |
class ObjectMonitor; |
|
93 |
class JavaThread; |
|
94 |
||
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
95 |
class markWord { |
1 | 96 |
private: |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
97 |
uintptr_t _value; |
1 | 98 |
|
99 |
public: |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
100 |
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
|
101 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
102 |
markWord() { /* uninitialized */} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
103 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
104 |
// 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
|
105 |
// destructable, copyable, and assignable. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
106 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
107 |
static markWord from_pointer(void* ptr) { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
108 |
return markWord((uintptr_t)ptr); |
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 |
void* to_pointer() const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
111 |
return (void*)_value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
112 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
113 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
114 |
bool operator==(const markWord& other) const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
115 |
return _value == other._value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
116 |
} |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
117 |
bool operator!=(const markWord& other) const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
118 |
return !operator==(other); |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
119 |
} |
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 |
// Conversion |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
122 |
uintptr_t value() const { return _value; } |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
123 |
|
1 | 124 |
// Constants |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
125 |
static const int age_bits = 4; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
126 |
static const int lock_bits = 2; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
127 |
static const int biased_lock_bits = 1; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
128 |
static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
129 |
static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits; |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
130 |
static const int unused_gap_bits = LP64_ONLY(1) NOT_LP64(0); |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
131 |
static const int epoch_bits = 2; |
1 | 132 |
|
133 |
// 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
|
134 |
// contiguous to the lock bits. |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
135 |
static const int lock_shift = 0; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
136 |
static const int biased_lock_shift = lock_bits; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
137 |
static const int age_shift = lock_bits + biased_lock_bits; |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
138 |
static const int unused_gap_shift = age_shift + age_bits; |
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
57959
diff
changeset
|
139 |
static const int hash_shift = unused_gap_shift + unused_gap_bits; |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
140 |
static const int epoch_shift = hash_shift; |
1 | 141 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
142 |
static const uintptr_t lock_mask = right_n_bits(lock_bits); |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
143 |
static const uintptr_t lock_mask_in_place = lock_mask << lock_shift; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
144 |
static const uintptr_t biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits); |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
145 |
static const uintptr_t biased_lock_mask_in_place= biased_lock_mask << lock_shift; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
146 |
static const uintptr_t biased_lock_bit_in_place = 1 << biased_lock_shift; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
147 |
static const uintptr_t age_mask = right_n_bits(age_bits); |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
148 |
static const uintptr_t age_mask_in_place = age_mask << age_shift; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
149 |
static const uintptr_t epoch_mask = right_n_bits(epoch_bits); |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
150 |
static const uintptr_t epoch_mask_in_place = epoch_mask << epoch_shift; |
1 | 151 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
152 |
static const uintptr_t hash_mask = right_n_bits(hash_bits); |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
153 |
static const uintptr_t hash_mask_in_place = hash_mask << hash_shift; |
54335
d9f6d16299b1
8221408: Windows 32bit build build errors/warnings in hotspot
stuefe
parents:
53244
diff
changeset
|
154 |
|
1 | 155 |
// Alignment of JavaThread pointers encoded in object header required by biased locking |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
156 |
static const size_t biased_lock_alignment = 2 << (epoch_shift + epoch_bits); |
1 | 157 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
158 |
static const uintptr_t locked_value = 0; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
159 |
static const uintptr_t unlocked_value = 1; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
160 |
static const uintptr_t monitor_value = 2; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
161 |
static const uintptr_t marked_value = 3; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
162 |
static const uintptr_t biased_lock_pattern = 5; |
1 | 163 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
164 |
static const uintptr_t no_hash = 0 ; // no hash value assigned |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
165 |
static const uintptr_t no_hash_in_place = (address_word)no_hash << hash_shift; |
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
166 |
static const uintptr_t no_lock_in_place = unlocked_value; |
1 | 167 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
168 |
static const uint max_age = age_mask; |
1 | 169 |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
170 |
static const int max_bias_epoch = epoch_mask; |
1 | 171 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
172 |
// 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
|
173 |
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
|
174 |
|
1 | 175 |
// Biased Locking accessors. |
176 |
// These must be checked by all code which calls into the |
|
177 |
// ObjectSynchronizer and other code. The biasing is not understood |
|
178 |
// by the lower-level CAS-based locking code, although the runtime |
|
179 |
// fixes up biased locks to be compatible with it when a bias is |
|
180 |
// revoked. |
|
181 |
bool has_bias_pattern() const { |
|
182 |
return (mask_bits(value(), biased_lock_mask_in_place) == biased_lock_pattern); |
|
183 |
} |
|
184 |
JavaThread* biased_locker() const { |
|
185 |
assert(has_bias_pattern(), "should not call this otherwise"); |
|
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
186 |
return (JavaThread*) mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place)); |
1 | 187 |
} |
188 |
// Indicates that the mark has the bias bit set but that it has not |
|
189 |
// yet been biased toward a particular thread |
|
190 |
bool is_biased_anonymously() const { |
|
191 |
return (has_bias_pattern() && (biased_locker() == NULL)); |
|
192 |
} |
|
193 |
// Indicates epoch in which this bias was acquired. If the epoch |
|
194 |
// changes due to too many bias revocations occurring, the biases |
|
195 |
// from the previous epochs are all considered invalid. |
|
196 |
int bias_epoch() const { |
|
197 |
assert(has_bias_pattern(), "should not call this otherwise"); |
|
198 |
return (mask_bits(value(), epoch_mask_in_place) >> epoch_shift); |
|
199 |
} |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
200 |
markWord set_bias_epoch(int epoch) { |
1 | 201 |
assert(has_bias_pattern(), "should not call this otherwise"); |
202 |
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
|
203 |
return markWord(mask_bits(value(), ~epoch_mask_in_place) | (epoch << epoch_shift)); |
1 | 204 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
205 |
markWord incr_bias_epoch() { |
1 | 206 |
return set_bias_epoch((1 + bias_epoch()) & epoch_mask); |
207 |
} |
|
208 |
// Prototype mark for initialization |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
209 |
static markWord biased_locking_prototype() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
210 |
return markWord( biased_lock_pattern ); |
1 | 211 |
} |
212 |
||
213 |
// lock accessors (note that these assume lock_shift == 0) |
|
214 |
bool is_locked() const { |
|
215 |
return (mask_bits(value(), lock_mask_in_place) != unlocked_value); |
|
216 |
} |
|
217 |
bool is_unlocked() const { |
|
218 |
return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); |
|
219 |
} |
|
220 |
bool is_marked() const { |
|
221 |
return (mask_bits(value(), lock_mask_in_place) == marked_value); |
|
222 |
} |
|
223 |
bool is_neutral() const { return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); } |
|
224 |
||
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
225 |
// Special temporary state of the markWord while being inflated. |
1 | 226 |
// Code that looks at mark outside a lock need to take this into account. |
227 |
bool is_being_inflated() const { return (value() == 0); } |
|
228 |
||
229 |
// Distinguished markword value - used when inflating over |
|
230 |
// an existing stacklock. 0 indicates the markword is "BUSY". |
|
231 |
// Lockword mutators that use a LD...CAS idiom should always |
|
232 |
// check for and avoid overwriting a 0 value installed by some |
|
233 |
// other thread. (They should spin or block instead. The 0 value |
|
234 |
// 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
|
235 |
static markWord INFLATING() { return zero(); } // inflate-in-progress |
1 | 236 |
|
237 |
// Should this header be preserved during GC? |
|
57812
9bb28ccc6106
8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents:
57811
diff
changeset
|
238 |
template <typename KlassProxy> |
9bb28ccc6106
8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents:
57811
diff
changeset
|
239 |
inline bool must_be_preserved(KlassProxy klass) const; |
1 | 240 |
|
241 |
// Should this header (including its age bits) be preserved in the |
|
242 |
// case of a promotion failure during scavenge? |
|
243 |
// Note that we special case this situation. We want to avoid |
|
244 |
// calling BiasedLocking::preserve_marks()/restore_marks() (which |
|
245 |
// decrease the number of mark words that need to be preserved |
|
246 |
// during GC) during each scavenge. During scavenges in which there |
|
247 |
// is no promotion failure, we actually don't need to call the above |
|
248 |
// routines at all, since we don't mutate and re-initialize the |
|
249 |
// marks of promoted objects using init_mark(). However, during |
|
250 |
// scavenges which result in promotion failure, we do re-initialize |
|
251 |
// the mark words of objects, meaning that we should have called |
|
252 |
// these mark word preservation routines. Currently there's no good |
|
253 |
// place in which to call them in any of the scavengers (although |
|
254 |
// guarded by appropriate locks we could make one), but the |
|
255 |
// observation is that promotion failures are quite rare and |
|
256 |
// reducing the number of mark words preserved during them isn't a |
|
257 |
// high priority. |
|
57812
9bb28ccc6106
8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents:
57811
diff
changeset
|
258 |
template <typename KlassProxy> |
9bb28ccc6106
8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents:
57811
diff
changeset
|
259 |
inline bool must_be_preserved_for_promotion_failure(KlassProxy klass) const; |
1 | 260 |
|
261 |
// WARNING: The following routines are used EXCLUSIVELY by |
|
262 |
// 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
|
263 |
// 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
|
264 |
markWord set_unlocked() const { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
265 |
return markWord(value() | unlocked_value); |
1 | 266 |
} |
267 |
bool has_locker() const { |
|
268 |
return ((value() & lock_mask_in_place) == locked_value); |
|
269 |
} |
|
270 |
BasicLock* locker() const { |
|
271 |
assert(has_locker(), "check"); |
|
272 |
return (BasicLock*) value(); |
|
273 |
} |
|
274 |
bool has_monitor() const { |
|
275 |
return ((value() & monitor_value) != 0); |
|
276 |
} |
|
277 |
ObjectMonitor* monitor() const { |
|
278 |
assert(has_monitor(), "check"); |
|
279 |
// Use xor instead of &~ to provide one extra tag-bit check. |
|
280 |
return (ObjectMonitor*) (value() ^ monitor_value); |
|
281 |
} |
|
282 |
bool has_displaced_mark_helper() const { |
|
283 |
return ((value() & unlocked_value) == 0); |
|
284 |
} |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
285 |
markWord displaced_mark_helper() const { |
1 | 286 |
assert(has_displaced_mark_helper(), "check"); |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
287 |
uintptr_t ptr = (value() & ~monitor_value); |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
288 |
return *(markWord*)ptr; |
1 | 289 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
290 |
void set_displaced_mark_helper(markWord m) const { |
1 | 291 |
assert(has_displaced_mark_helper(), "check"); |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
292 |
uintptr_t ptr = (value() & ~monitor_value); |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
293 |
((markWord*)ptr)->_value = m._value; |
1 | 294 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
295 |
markWord copy_set_hash(intptr_t hash) const { |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
296 |
uintptr_t tmp = value() & (~hash_mask_in_place); |
1 | 297 |
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
|
298 |
return markWord(tmp); |
1 | 299 |
} |
300 |
// it is only used to be stored into BasicLock as the |
|
301 |
// 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
|
302 |
static markWord unused_mark() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
303 |
return markWord(marked_value); |
1 | 304 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
305 |
// the following two functions create the markWord to be |
1 | 306 |
// 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
|
307 |
static markWord encode(BasicLock* lock) { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
308 |
return from_pointer(lock); |
1 | 309 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
310 |
static markWord encode(ObjectMonitor* monitor) { |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
311 |
uintptr_t tmp = (uintptr_t) monitor; |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
312 |
return markWord(tmp | monitor_value); |
1 | 313 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
314 |
static markWord encode(JavaThread* thread, uint age, int bias_epoch) { |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
315 |
uintptr_t tmp = (uintptr_t) thread; |
1 | 316 |
assert(UseBiasedLocking && ((tmp & (epoch_mask_in_place | age_mask_in_place | biased_lock_mask_in_place)) == 0), "misaligned JavaThread pointer"); |
317 |
assert(age <= max_age, "age too large"); |
|
318 |
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
|
319 |
return markWord(tmp | (bias_epoch << epoch_shift) | (age << age_shift) | biased_lock_pattern); |
1 | 320 |
} |
321 |
||
322 |
// 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
|
323 |
markWord clear_lock_bits() { return markWord(value() & ~lock_mask_in_place); } |
1 | 324 |
|
325 |
// age operations |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
326 |
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
|
327 |
markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); } |
1 | 328 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
329 |
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
|
330 |
markWord set_age(uint v) const { |
1 | 331 |
assert((v & ~age_mask) == 0, "shouldn't overflow age field"); |
57959
6b539901e79e
8230203: Replace markWord enums with typed constants
stefank
parents:
57875
diff
changeset
|
332 |
return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift)); |
1 | 333 |
} |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
334 |
markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); } |
1 | 335 |
|
336 |
// hash operations |
|
337 |
intptr_t hash() const { |
|
338 |
return mask_bits(value() >> hash_shift, hash_mask); |
|
339 |
} |
|
340 |
||
341 |
bool has_no_hash() const { |
|
342 |
return hash() == no_hash; |
|
343 |
} |
|
344 |
||
345 |
// Prototype mark for initialization |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
346 |
static markWord prototype() { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
347 |
return markWord( no_hash_in_place | no_lock_in_place ); |
1 | 348 |
} |
349 |
||
350 |
// Helper function for restoration of unmarked mark oops during GC |
|
57812
9bb28ccc6106
8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents:
57811
diff
changeset
|
351 |
static inline markWord prototype_for_klass(const Klass* klass); |
1 | 352 |
|
353 |
// Debugging |
|
354 |
void print_on(outputStream* st) const; |
|
355 |
||
356 |
// 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
|
357 |
inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); } |
1 | 358 |
|
359 |
// 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
|
360 |
inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); } |
1 | 361 |
}; |
7397 | 362 |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
363 |
// Support atomic operations. |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
364 |
template<> |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
365 |
struct PrimitiveConversions::Translate<markWord> : public TrueType { |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
366 |
typedef markWord Value; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
367 |
typedef uintptr_t Decayed; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
368 |
|
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
}; |
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
54335
diff
changeset
|
372 |
|
57811 | 373 |
#endif // SHARE_OOPS_MARKWORD_HPP |