author | rkennke |
Wed, 19 Sep 2018 21:31:33 +0200 | |
changeset 51806 | 1ecc914fb707 |
parent 51485 | 0c7040d1d1ca |
child 51826 | e777e997e7c1 |
permissions | -rw-r--r-- |
50180 | 1 |
/* |
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "gc/shared/c2/barrierSetC2.hpp" |
|
27 |
#include "opto/arraycopynode.hpp" |
|
28 |
#include "opto/graphKit.hpp" |
|
29 |
#include "opto/idealKit.hpp" |
|
51806 | 30 |
#include "opto/macro.hpp" |
50180 | 31 |
#include "opto/narrowptrnode.hpp" |
32 |
#include "utilities/macros.hpp" |
|
33 |
||
34 |
// By default this is a no-op. |
|
35 |
void BarrierSetC2::resolve_address(C2Access& access) const { } |
|
36 |
||
37 |
void* C2Access::barrier_set_state() const { |
|
38 |
return _kit->barrier_set_state(); |
|
39 |
} |
|
40 |
||
41 |
bool C2Access::needs_cpu_membar() const { |
|
42 |
bool mismatched = (_decorators & C2_MISMATCHED) != 0; |
|
43 |
bool is_unordered = (_decorators & MO_UNORDERED) != 0; |
|
44 |
bool anonymous = (_decorators & C2_UNSAFE_ACCESS) != 0; |
|
50599
ecc2af326b5f
8204939: Change Access nomenclature: root to native
kbarrett
parents:
50180
diff
changeset
|
45 |
bool in_heap = (_decorators & IN_HEAP) != 0; |
50180 | 46 |
|
47 |
bool is_write = (_decorators & C2_WRITE_ACCESS) != 0; |
|
48 |
bool is_read = (_decorators & C2_READ_ACCESS) != 0; |
|
49 |
bool is_atomic = is_read && is_write; |
|
50 |
||
51 |
if (is_atomic) { |
|
52 |
// Atomics always need to be wrapped in CPU membars |
|
53 |
return true; |
|
54 |
} |
|
55 |
||
56 |
if (anonymous) { |
|
57 |
// We will need memory barriers unless we can determine a unique |
|
58 |
// alias category for this reference. (Note: If for some reason |
|
59 |
// the barriers get omitted and the unsafe reference begins to "pollute" |
|
60 |
// the alias analysis of the rest of the graph, either Compile::can_alias |
|
61 |
// or Compile::must_alias will throw a diagnostic assert.) |
|
50599
ecc2af326b5f
8204939: Change Access nomenclature: root to native
kbarrett
parents:
50180
diff
changeset
|
62 |
if (!in_heap || !is_unordered || (mismatched && !_addr.type()->isa_aryptr())) { |
50180 | 63 |
return true; |
64 |
} |
|
65 |
} |
|
66 |
||
67 |
return false; |
|
68 |
} |
|
69 |
||
70 |
Node* BarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const { |
|
71 |
DecoratorSet decorators = access.decorators(); |
|
72 |
GraphKit* kit = access.kit(); |
|
73 |
||
74 |
bool mismatched = (decorators & C2_MISMATCHED) != 0; |
|
75 |
bool unaligned = (decorators & C2_UNALIGNED) != 0; |
|
76 |
bool requires_atomic_access = (decorators & MO_UNORDERED) == 0; |
|
77 |
||
50599
ecc2af326b5f
8204939: Change Access nomenclature: root to native
kbarrett
parents:
50180
diff
changeset
|
78 |
bool in_native = (decorators & IN_NATIVE) != 0; |
ecc2af326b5f
8204939: Change Access nomenclature: root to native
kbarrett
parents:
50180
diff
changeset
|
79 |
assert(!in_native, "not supported yet"); |
50180 | 80 |
|
81 |
if (access.type() == T_DOUBLE) { |
|
82 |
Node* new_val = kit->dstore_rounding(val.node()); |
|
83 |
val.set_node(new_val); |
|
84 |
} |
|
85 |
||
86 |
MemNode::MemOrd mo = access.mem_node_mo(); |
|
87 |
||
88 |
Node* store = kit->store_to_memory(kit->control(), access.addr().node(), val.node(), access.type(), |
|
89 |
access.addr().type(), mo, requires_atomic_access, unaligned, mismatched); |
|
90 |
access.set_raw_access(store); |
|
91 |
return store; |
|
92 |
} |
|
93 |
||
94 |
Node* BarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const { |
|
95 |
DecoratorSet decorators = access.decorators(); |
|
96 |
GraphKit* kit = access.kit(); |
|
97 |
||
98 |
Node* adr = access.addr().node(); |
|
99 |
const TypePtr* adr_type = access.addr().type(); |
|
100 |
||
101 |
bool mismatched = (decorators & C2_MISMATCHED) != 0; |
|
102 |
bool requires_atomic_access = (decorators & MO_UNORDERED) == 0; |
|
103 |
bool unaligned = (decorators & C2_UNALIGNED) != 0; |
|
104 |
bool control_dependent = (decorators & C2_CONTROL_DEPENDENT_LOAD) != 0; |
|
105 |
bool pinned = (decorators & C2_PINNED_LOAD) != 0; |
|
106 |
||
50599
ecc2af326b5f
8204939: Change Access nomenclature: root to native
kbarrett
parents:
50180
diff
changeset
|
107 |
bool in_native = (decorators & IN_NATIVE) != 0; |
50180 | 108 |
|
109 |
MemNode::MemOrd mo = access.mem_node_mo(); |
|
110 |
LoadNode::ControlDependency dep = pinned ? LoadNode::Pinned : LoadNode::DependsOnlyOnTest; |
|
111 |
Node* control = control_dependent ? kit->control() : NULL; |
|
112 |
||
51485
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
113 |
Node* load; |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
114 |
if (in_native) { |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
115 |
load = kit->make_load(control, adr, val_type, access.type(), mo); |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
116 |
} else { |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
117 |
load = kit->make_load(control, adr, val_type, access.type(), adr_type, mo, |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
118 |
dep, requires_atomic_access, unaligned, mismatched); |
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
51482
diff
changeset
|
119 |
} |
50180 | 120 |
access.set_raw_access(load); |
121 |
||
122 |
return load; |
|
123 |
} |
|
124 |
||
125 |
class C2AccessFence: public StackObj { |
|
126 |
C2Access& _access; |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
127 |
Node* _leading_membar; |
50180 | 128 |
|
129 |
public: |
|
130 |
C2AccessFence(C2Access& access) : |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
131 |
_access(access), _leading_membar(NULL) { |
50180 | 132 |
GraphKit* kit = access.kit(); |
133 |
DecoratorSet decorators = access.decorators(); |
|
134 |
||
135 |
bool is_write = (decorators & C2_WRITE_ACCESS) != 0; |
|
136 |
bool is_read = (decorators & C2_READ_ACCESS) != 0; |
|
137 |
bool is_atomic = is_read && is_write; |
|
138 |
||
139 |
bool is_volatile = (decorators & MO_SEQ_CST) != 0; |
|
140 |
bool is_release = (decorators & MO_RELEASE) != 0; |
|
141 |
||
142 |
if (is_atomic) { |
|
143 |
// Memory-model-wise, a LoadStore acts like a little synchronized |
|
144 |
// block, so needs barriers on each side. These don't translate |
|
145 |
// into actual barriers on most machines, but we still need rest of |
|
146 |
// compiler to respect ordering. |
|
147 |
if (is_release) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
148 |
_leading_membar = kit->insert_mem_bar(Op_MemBarRelease); |
50180 | 149 |
} else if (is_volatile) { |
150 |
if (support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
151 |
_leading_membar = kit->insert_mem_bar(Op_MemBarVolatile); |
50180 | 152 |
} else { |
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
153 |
_leading_membar = kit->insert_mem_bar(Op_MemBarRelease); |
50180 | 154 |
} |
155 |
} |
|
156 |
} else if (is_write) { |
|
157 |
// If reference is volatile, prevent following memory ops from |
|
158 |
// floating down past the volatile write. Also prevents commoning |
|
159 |
// another volatile read. |
|
160 |
if (is_volatile || is_release) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
161 |
_leading_membar = kit->insert_mem_bar(Op_MemBarRelease); |
50180 | 162 |
} |
163 |
} else { |
|
164 |
// Memory barrier to prevent normal and 'unsafe' accesses from |
|
165 |
// bypassing each other. Happens after null checks, so the |
|
166 |
// exception paths do not take memory state from the memory barrier, |
|
167 |
// so there's no problems making a strong assert about mixing users |
|
168 |
// of safe & unsafe memory. |
|
169 |
if (is_volatile && support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
170 |
_leading_membar = kit->insert_mem_bar(Op_MemBarVolatile); |
50180 | 171 |
} |
172 |
} |
|
173 |
||
174 |
if (access.needs_cpu_membar()) { |
|
175 |
kit->insert_mem_bar(Op_MemBarCPUOrder); |
|
176 |
} |
|
177 |
||
178 |
if (is_atomic) { |
|
179 |
// 4984716: MemBars must be inserted before this |
|
180 |
// memory node in order to avoid a false |
|
181 |
// dependency which will confuse the scheduler. |
|
182 |
access.set_memory(); |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
~C2AccessFence() { |
|
187 |
GraphKit* kit = _access.kit(); |
|
188 |
DecoratorSet decorators = _access.decorators(); |
|
189 |
||
190 |
bool is_write = (decorators & C2_WRITE_ACCESS) != 0; |
|
191 |
bool is_read = (decorators & C2_READ_ACCESS) != 0; |
|
192 |
bool is_atomic = is_read && is_write; |
|
193 |
||
194 |
bool is_volatile = (decorators & MO_SEQ_CST) != 0; |
|
195 |
bool is_acquire = (decorators & MO_ACQUIRE) != 0; |
|
196 |
||
197 |
// If reference is volatile, prevent following volatiles ops from |
|
198 |
// floating up before the volatile access. |
|
199 |
if (_access.needs_cpu_membar()) { |
|
200 |
kit->insert_mem_bar(Op_MemBarCPUOrder); |
|
201 |
} |
|
202 |
||
203 |
if (is_atomic) { |
|
204 |
if (is_acquire || is_volatile) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
205 |
Node* n = _access.raw_access(); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
206 |
Node* mb = kit->insert_mem_bar(Op_MemBarAcquire, n); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
207 |
if (_leading_membar != NULL) { |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
208 |
MemBarNode::set_load_store_pair(_leading_membar->as_MemBar(), mb->as_MemBar()); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
209 |
} |
50180 | 210 |
} |
211 |
} else if (is_write) { |
|
212 |
// If not multiple copy atomic, we do the MemBarVolatile before the load. |
|
213 |
if (is_volatile && !support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
214 |
Node* n = _access.raw_access(); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
215 |
Node* mb = kit->insert_mem_bar(Op_MemBarVolatile, n); // Use fat membar |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
216 |
if (_leading_membar != NULL) { |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
217 |
MemBarNode::set_store_pair(_leading_membar->as_MemBar(), mb->as_MemBar()); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
218 |
} |
50180 | 219 |
} |
220 |
} else { |
|
221 |
if (is_volatile || is_acquire) { |
|
51482
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
222 |
Node* n = _access.raw_access(); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
223 |
assert(_leading_membar == NULL || support_IRIW_for_not_multiple_copy_atomic_cpu, "no leading membar expected"); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
224 |
Node* mb = kit->insert_mem_bar(Op_MemBarAcquire, n); |
d7029542d67a
8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents:
50599
diff
changeset
|
225 |
mb->as_MemBar()->set_trailing_load(); |
50180 | 226 |
} |
227 |
} |
|
228 |
} |
|
229 |
}; |
|
230 |
||
231 |
Node* BarrierSetC2::store_at(C2Access& access, C2AccessValue& val) const { |
|
232 |
C2AccessFence fence(access); |
|
233 |
resolve_address(access); |
|
234 |
return store_at_resolved(access, val); |
|
235 |
} |
|
236 |
||
237 |
Node* BarrierSetC2::load_at(C2Access& access, const Type* val_type) const { |
|
238 |
C2AccessFence fence(access); |
|
239 |
resolve_address(access); |
|
240 |
return load_at_resolved(access, val_type); |
|
241 |
} |
|
242 |
||
243 |
MemNode::MemOrd C2Access::mem_node_mo() const { |
|
244 |
bool is_write = (_decorators & C2_WRITE_ACCESS) != 0; |
|
245 |
bool is_read = (_decorators & C2_READ_ACCESS) != 0; |
|
246 |
if ((_decorators & MO_SEQ_CST) != 0) { |
|
247 |
if (is_write && is_read) { |
|
248 |
// For atomic operations |
|
249 |
return MemNode::seqcst; |
|
250 |
} else if (is_write) { |
|
251 |
return MemNode::release; |
|
252 |
} else { |
|
253 |
assert(is_read, "what else?"); |
|
254 |
return MemNode::acquire; |
|
255 |
} |
|
256 |
} else if ((_decorators & MO_RELEASE) != 0) { |
|
257 |
return MemNode::release; |
|
258 |
} else if ((_decorators & MO_ACQUIRE) != 0) { |
|
259 |
return MemNode::acquire; |
|
260 |
} else if (is_write) { |
|
261 |
// Volatile fields need releasing stores. |
|
262 |
// Non-volatile fields also need releasing stores if they hold an |
|
263 |
// object reference, because the object reference might point to |
|
264 |
// a freshly created object. |
|
265 |
// Conservatively release stores of object references. |
|
266 |
return StoreNode::release_if_reference(_type); |
|
267 |
} else { |
|
268 |
return MemNode::unordered; |
|
269 |
} |
|
270 |
} |
|
271 |
||
272 |
void C2Access::fixup_decorators() { |
|
273 |
bool default_mo = (_decorators & MO_DECORATOR_MASK) == 0; |
|
274 |
bool is_unordered = (_decorators & MO_UNORDERED) != 0 || default_mo; |
|
275 |
bool anonymous = (_decorators & C2_UNSAFE_ACCESS) != 0; |
|
276 |
||
277 |
bool is_read = (_decorators & C2_READ_ACCESS) != 0; |
|
278 |
bool is_write = (_decorators & C2_WRITE_ACCESS) != 0; |
|
279 |
||
280 |
if (AlwaysAtomicAccesses && is_unordered) { |
|
281 |
_decorators &= ~MO_DECORATOR_MASK; // clear the MO bits |
|
282 |
_decorators |= MO_RELAXED; // Force the MO_RELAXED decorator with AlwaysAtomicAccess |
|
283 |
} |
|
284 |
||
285 |
_decorators = AccessInternal::decorator_fixup(_decorators); |
|
286 |
||
287 |
if (is_read && !is_write && anonymous) { |
|
288 |
// To be valid, unsafe loads may depend on other conditions than |
|
289 |
// the one that guards them: pin the Load node |
|
290 |
_decorators |= C2_CONTROL_DEPENDENT_LOAD; |
|
291 |
_decorators |= C2_PINNED_LOAD; |
|
292 |
const TypePtr* adr_type = _addr.type(); |
|
293 |
Node* adr = _addr.node(); |
|
294 |
if (!needs_cpu_membar() && adr_type->isa_instptr()) { |
|
295 |
assert(adr_type->meet(TypePtr::NULL_PTR) != adr_type->remove_speculative(), "should be not null"); |
|
296 |
intptr_t offset = Type::OffsetBot; |
|
297 |
AddPNode::Ideal_base_and_offset(adr, &_kit->gvn(), offset); |
|
298 |
if (offset >= 0) { |
|
299 |
int s = Klass::layout_helper_size_in_bytes(adr_type->isa_instptr()->klass()->layout_helper()); |
|
300 |
if (offset < s) { |
|
301 |
// Guaranteed to be a valid access, no need to pin it |
|
302 |
_decorators ^= C2_CONTROL_DEPENDENT_LOAD; |
|
303 |
_decorators ^= C2_PINNED_LOAD; |
|
304 |
} |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
//--------------------------- atomic operations--------------------------------- |
|
311 |
||
312 |
static void pin_atomic_op(C2AtomicAccess& access) { |
|
313 |
if (!access.needs_pinning()) { |
|
314 |
return; |
|
315 |
} |
|
316 |
// SCMemProjNodes represent the memory state of a LoadStore. Their |
|
317 |
// main role is to prevent LoadStore nodes from being optimized away |
|
318 |
// when their results aren't used. |
|
319 |
GraphKit* kit = access.kit(); |
|
320 |
Node* load_store = access.raw_access(); |
|
321 |
assert(load_store != NULL, "must pin atomic op"); |
|
322 |
Node* proj = kit->gvn().transform(new SCMemProjNode(load_store)); |
|
323 |
kit->set_memory(proj, access.alias_idx()); |
|
324 |
} |
|
325 |
||
326 |
void C2AtomicAccess::set_memory() { |
|
327 |
Node *mem = _kit->memory(_alias_idx); |
|
328 |
_memory = mem; |
|
329 |
} |
|
330 |
||
331 |
Node* BarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicAccess& access, Node* expected_val, |
|
332 |
Node* new_val, const Type* value_type) const { |
|
333 |
GraphKit* kit = access.kit(); |
|
334 |
MemNode::MemOrd mo = access.mem_node_mo(); |
|
335 |
Node* mem = access.memory(); |
|
336 |
||
337 |
Node* adr = access.addr().node(); |
|
338 |
const TypePtr* adr_type = access.addr().type(); |
|
339 |
||
340 |
Node* load_store = NULL; |
|
341 |
||
342 |
if (access.is_oop()) { |
|
343 |
#ifdef _LP64 |
|
344 |
if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
345 |
Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop())); |
|
346 |
Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop())); |
|
347 |
load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo)); |
|
348 |
} else |
|
349 |
#endif |
|
350 |
{ |
|
351 |
load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo)); |
|
352 |
} |
|
353 |
} else { |
|
354 |
switch (access.type()) { |
|
355 |
case T_BYTE: { |
|
356 |
load_store = kit->gvn().transform(new CompareAndExchangeBNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo)); |
|
357 |
break; |
|
358 |
} |
|
359 |
case T_SHORT: { |
|
360 |
load_store = kit->gvn().transform(new CompareAndExchangeSNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo)); |
|
361 |
break; |
|
362 |
} |
|
363 |
case T_INT: { |
|
364 |
load_store = kit->gvn().transform(new CompareAndExchangeINode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo)); |
|
365 |
break; |
|
366 |
} |
|
367 |
case T_LONG: { |
|
368 |
load_store = kit->gvn().transform(new CompareAndExchangeLNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo)); |
|
369 |
break; |
|
370 |
} |
|
371 |
default: |
|
372 |
ShouldNotReachHere(); |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
access.set_raw_access(load_store); |
|
377 |
pin_atomic_op(access); |
|
378 |
||
379 |
#ifdef _LP64 |
|
380 |
if (access.is_oop() && adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
381 |
return kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type())); |
|
382 |
} |
|
383 |
#endif |
|
384 |
||
385 |
return load_store; |
|
386 |
} |
|
387 |
||
388 |
Node* BarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicAccess& access, Node* expected_val, |
|
389 |
Node* new_val, const Type* value_type) const { |
|
390 |
GraphKit* kit = access.kit(); |
|
391 |
DecoratorSet decorators = access.decorators(); |
|
392 |
MemNode::MemOrd mo = access.mem_node_mo(); |
|
393 |
Node* mem = access.memory(); |
|
394 |
bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0; |
|
395 |
Node* load_store = NULL; |
|
396 |
Node* adr = access.addr().node(); |
|
397 |
||
398 |
if (access.is_oop()) { |
|
399 |
#ifdef _LP64 |
|
400 |
if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
401 |
Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop())); |
|
402 |
Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop())); |
|
403 |
if (is_weak_cas) { |
|
404 |
load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo)); |
|
405 |
} else { |
|
406 |
load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo)); |
|
407 |
} |
|
408 |
} else |
|
409 |
#endif |
|
410 |
{ |
|
411 |
if (is_weak_cas) { |
|
412 |
load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
413 |
} else { |
|
414 |
load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
415 |
} |
|
416 |
} |
|
417 |
} else { |
|
418 |
switch(access.type()) { |
|
419 |
case T_BYTE: { |
|
420 |
if (is_weak_cas) { |
|
421 |
load_store = kit->gvn().transform(new WeakCompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
422 |
} else { |
|
423 |
load_store = kit->gvn().transform(new CompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
424 |
} |
|
425 |
break; |
|
426 |
} |
|
427 |
case T_SHORT: { |
|
428 |
if (is_weak_cas) { |
|
429 |
load_store = kit->gvn().transform(new WeakCompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
430 |
} else { |
|
431 |
load_store = kit->gvn().transform(new CompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
432 |
} |
|
433 |
break; |
|
434 |
} |
|
435 |
case T_INT: { |
|
436 |
if (is_weak_cas) { |
|
437 |
load_store = kit->gvn().transform(new WeakCompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
438 |
} else { |
|
439 |
load_store = kit->gvn().transform(new CompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
440 |
} |
|
441 |
break; |
|
442 |
} |
|
443 |
case T_LONG: { |
|
444 |
if (is_weak_cas) { |
|
445 |
load_store = kit->gvn().transform(new WeakCompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
446 |
} else { |
|
447 |
load_store = kit->gvn().transform(new CompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo)); |
|
448 |
} |
|
449 |
break; |
|
450 |
} |
|
451 |
default: |
|
452 |
ShouldNotReachHere(); |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
access.set_raw_access(load_store); |
|
457 |
pin_atomic_op(access); |
|
458 |
||
459 |
return load_store; |
|
460 |
} |
|
461 |
||
462 |
Node* BarrierSetC2::atomic_xchg_at_resolved(C2AtomicAccess& access, Node* new_val, const Type* value_type) const { |
|
463 |
GraphKit* kit = access.kit(); |
|
464 |
Node* mem = access.memory(); |
|
465 |
Node* adr = access.addr().node(); |
|
466 |
const TypePtr* adr_type = access.addr().type(); |
|
467 |
Node* load_store = NULL; |
|
468 |
||
469 |
if (access.is_oop()) { |
|
470 |
#ifdef _LP64 |
|
471 |
if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
472 |
Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop())); |
|
473 |
load_store = kit->gvn().transform(new GetAndSetNNode(kit->control(), mem, adr, newval_enc, adr_type, value_type->make_narrowoop())); |
|
474 |
} else |
|
475 |
#endif |
|
476 |
{ |
|
477 |
load_store = kit->gvn().transform(new GetAndSetPNode(kit->control(), mem, adr, new_val, adr_type, value_type->is_oopptr())); |
|
478 |
} |
|
479 |
} else { |
|
480 |
switch (access.type()) { |
|
481 |
case T_BYTE: |
|
482 |
load_store = kit->gvn().transform(new GetAndSetBNode(kit->control(), mem, adr, new_val, adr_type)); |
|
483 |
break; |
|
484 |
case T_SHORT: |
|
485 |
load_store = kit->gvn().transform(new GetAndSetSNode(kit->control(), mem, adr, new_val, adr_type)); |
|
486 |
break; |
|
487 |
case T_INT: |
|
488 |
load_store = kit->gvn().transform(new GetAndSetINode(kit->control(), mem, adr, new_val, adr_type)); |
|
489 |
break; |
|
490 |
case T_LONG: |
|
491 |
load_store = kit->gvn().transform(new GetAndSetLNode(kit->control(), mem, adr, new_val, adr_type)); |
|
492 |
break; |
|
493 |
default: |
|
494 |
ShouldNotReachHere(); |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
access.set_raw_access(load_store); |
|
499 |
pin_atomic_op(access); |
|
500 |
||
501 |
#ifdef _LP64 |
|
502 |
if (access.is_oop() && adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
503 |
return kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type())); |
|
504 |
} |
|
505 |
#endif |
|
506 |
||
507 |
return load_store; |
|
508 |
} |
|
509 |
||
510 |
Node* BarrierSetC2::atomic_add_at_resolved(C2AtomicAccess& access, Node* new_val, const Type* value_type) const { |
|
511 |
Node* load_store = NULL; |
|
512 |
GraphKit* kit = access.kit(); |
|
513 |
Node* adr = access.addr().node(); |
|
514 |
const TypePtr* adr_type = access.addr().type(); |
|
515 |
Node* mem = access.memory(); |
|
516 |
||
517 |
switch(access.type()) { |
|
518 |
case T_BYTE: |
|
519 |
load_store = kit->gvn().transform(new GetAndAddBNode(kit->control(), mem, adr, new_val, adr_type)); |
|
520 |
break; |
|
521 |
case T_SHORT: |
|
522 |
load_store = kit->gvn().transform(new GetAndAddSNode(kit->control(), mem, adr, new_val, adr_type)); |
|
523 |
break; |
|
524 |
case T_INT: |
|
525 |
load_store = kit->gvn().transform(new GetAndAddINode(kit->control(), mem, adr, new_val, adr_type)); |
|
526 |
break; |
|
527 |
case T_LONG: |
|
528 |
load_store = kit->gvn().transform(new GetAndAddLNode(kit->control(), mem, adr, new_val, adr_type)); |
|
529 |
break; |
|
530 |
default: |
|
531 |
ShouldNotReachHere(); |
|
532 |
} |
|
533 |
||
534 |
access.set_raw_access(load_store); |
|
535 |
pin_atomic_op(access); |
|
536 |
||
537 |
return load_store; |
|
538 |
} |
|
539 |
||
540 |
Node* BarrierSetC2::atomic_cmpxchg_val_at(C2AtomicAccess& access, Node* expected_val, |
|
541 |
Node* new_val, const Type* value_type) const { |
|
542 |
C2AccessFence fence(access); |
|
543 |
resolve_address(access); |
|
544 |
return atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); |
|
545 |
} |
|
546 |
||
547 |
Node* BarrierSetC2::atomic_cmpxchg_bool_at(C2AtomicAccess& access, Node* expected_val, |
|
548 |
Node* new_val, const Type* value_type) const { |
|
549 |
C2AccessFence fence(access); |
|
550 |
resolve_address(access); |
|
551 |
return atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); |
|
552 |
} |
|
553 |
||
554 |
Node* BarrierSetC2::atomic_xchg_at(C2AtomicAccess& access, Node* new_val, const Type* value_type) const { |
|
555 |
C2AccessFence fence(access); |
|
556 |
resolve_address(access); |
|
557 |
return atomic_xchg_at_resolved(access, new_val, value_type); |
|
558 |
} |
|
559 |
||
560 |
Node* BarrierSetC2::atomic_add_at(C2AtomicAccess& access, Node* new_val, const Type* value_type) const { |
|
561 |
C2AccessFence fence(access); |
|
562 |
resolve_address(access); |
|
563 |
return atomic_add_at_resolved(access, new_val, value_type); |
|
564 |
} |
|
565 |
||
566 |
void BarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const { |
|
567 |
// Exclude the header but include array length to copy by 8 bytes words. |
|
568 |
// Can't use base_offset_in_bytes(bt) since basic type is unknown. |
|
569 |
int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() : |
|
570 |
instanceOopDesc::base_offset_in_bytes(); |
|
571 |
// base_off: |
|
572 |
// 8 - 32-bit VM |
|
573 |
// 12 - 64-bit VM, compressed klass |
|
574 |
// 16 - 64-bit VM, normal klass |
|
575 |
if (base_off % BytesPerLong != 0) { |
|
576 |
assert(UseCompressedClassPointers, ""); |
|
577 |
if (is_array) { |
|
578 |
// Exclude length to copy by 8 bytes words. |
|
579 |
base_off += sizeof(int); |
|
580 |
} else { |
|
581 |
// Include klass to copy by 8 bytes words. |
|
582 |
base_off = instanceOopDesc::klass_offset_in_bytes(); |
|
583 |
} |
|
584 |
assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment"); |
|
585 |
} |
|
586 |
Node* src_base = kit->basic_plus_adr(src, base_off); |
|
587 |
Node* dst_base = kit->basic_plus_adr(dst, base_off); |
|
588 |
||
589 |
// Compute the length also, if needed: |
|
590 |
Node* countx = size; |
|
591 |
countx = kit->gvn().transform(new SubXNode(countx, kit->MakeConX(base_off))); |
|
592 |
countx = kit->gvn().transform(new URShiftXNode(countx, kit->intcon(LogBytesPerLong) )); |
|
593 |
||
594 |
const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; |
|
595 |
||
596 |
ArrayCopyNode* ac = ArrayCopyNode::make(kit, false, src_base, NULL, dst_base, NULL, countx, false, false); |
|
597 |
ac->set_clonebasic(); |
|
598 |
Node* n = kit->gvn().transform(ac); |
|
599 |
if (n == ac) { |
|
600 |
kit->set_predefined_output_for_runtime_call(ac, ac->in(TypeFunc::Memory), raw_adr_type); |
|
601 |
} else { |
|
602 |
kit->set_all_memory(n); |
|
603 |
} |
|
604 |
} |
|
51806 | 605 |
|
606 |
Node* BarrierSetC2::obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes, |
|
607 |
Node*& i_o, Node*& needgc_ctrl, |
|
608 |
Node*& fast_oop_ctrl, Node*& fast_oop_rawmem, |
|
609 |
intx prefetch_lines) const { |
|
610 |
||
611 |
Node* eden_top_adr; |
|
612 |
Node* eden_end_adr; |
|
613 |
||
614 |
macro->set_eden_pointers(eden_top_adr, eden_end_adr); |
|
615 |
||
616 |
// Load Eden::end. Loop invariant and hoisted. |
|
617 |
// |
|
618 |
// Note: We set the control input on "eden_end" and "old_eden_top" when using |
|
619 |
// a TLAB to work around a bug where these values were being moved across |
|
620 |
// a safepoint. These are not oops, so they cannot be include in the oop |
|
621 |
// map, but they can be changed by a GC. The proper way to fix this would |
|
622 |
// be to set the raw memory state when generating a SafepointNode. However |
|
623 |
// this will require extensive changes to the loop optimization in order to |
|
624 |
// prevent a degradation of the optimization. |
|
625 |
// See comment in memnode.hpp, around line 227 in class LoadPNode. |
|
626 |
Node *eden_end = macro->make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS); |
|
627 |
||
628 |
// We need a Region for the loop-back contended case. |
|
629 |
enum { fall_in_path = 1, contended_loopback_path = 2 }; |
|
630 |
Node *contended_region; |
|
631 |
Node *contended_phi_rawmem; |
|
632 |
if (UseTLAB) { |
|
633 |
contended_region = toobig_false; |
|
634 |
contended_phi_rawmem = mem; |
|
635 |
} else { |
|
636 |
contended_region = new RegionNode(3); |
|
637 |
contended_phi_rawmem = new PhiNode(contended_region, Type::MEMORY, TypeRawPtr::BOTTOM); |
|
638 |
// Now handle the passing-too-big test. We fall into the contended |
|
639 |
// loop-back merge point. |
|
640 |
contended_region ->init_req(fall_in_path, toobig_false); |
|
641 |
contended_phi_rawmem->init_req(fall_in_path, mem); |
|
642 |
macro->transform_later(contended_region); |
|
643 |
macro->transform_later(contended_phi_rawmem); |
|
644 |
} |
|
645 |
||
646 |
// Load(-locked) the heap top. |
|
647 |
// See note above concerning the control input when using a TLAB |
|
648 |
Node *old_eden_top = UseTLAB |
|
649 |
? new LoadPNode (ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM, MemNode::unordered) |
|
650 |
: new LoadPLockedNode(contended_region, contended_phi_rawmem, eden_top_adr, MemNode::acquire); |
|
651 |
||
652 |
macro->transform_later(old_eden_top); |
|
653 |
// Add to heap top to get a new heap top |
|
654 |
Node *new_eden_top = new AddPNode(macro->top(), old_eden_top, size_in_bytes); |
|
655 |
macro->transform_later(new_eden_top); |
|
656 |
// Check for needing a GC; compare against heap end |
|
657 |
Node *needgc_cmp = new CmpPNode(new_eden_top, eden_end); |
|
658 |
macro->transform_later(needgc_cmp); |
|
659 |
Node *needgc_bol = new BoolNode(needgc_cmp, BoolTest::ge); |
|
660 |
macro->transform_later(needgc_bol); |
|
661 |
IfNode *needgc_iff = new IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN); |
|
662 |
macro->transform_later(needgc_iff); |
|
663 |
||
664 |
// Plug the failing-heap-space-need-gc test into the slow-path region |
|
665 |
Node *needgc_true = new IfTrueNode(needgc_iff); |
|
666 |
macro->transform_later(needgc_true); |
|
667 |
needgc_ctrl = needgc_true; |
|
668 |
||
669 |
// No need for a GC. Setup for the Store-Conditional |
|
670 |
Node *needgc_false = new IfFalseNode(needgc_iff); |
|
671 |
macro->transform_later(needgc_false); |
|
672 |
||
673 |
i_o = macro->prefetch_allocation(i_o, needgc_false, contended_phi_rawmem, |
|
674 |
old_eden_top, new_eden_top, prefetch_lines); |
|
675 |
||
676 |
Node* fast_oop = old_eden_top; |
|
677 |
||
678 |
// Store (-conditional) the modified eden top back down. |
|
679 |
// StorePConditional produces flags for a test PLUS a modified raw |
|
680 |
// memory state. |
|
681 |
if (UseTLAB) { |
|
682 |
Node* store_eden_top = |
|
683 |
new StorePNode(needgc_false, contended_phi_rawmem, eden_top_adr, |
|
684 |
TypeRawPtr::BOTTOM, new_eden_top, MemNode::unordered); |
|
685 |
macro->transform_later(store_eden_top); |
|
686 |
fast_oop_ctrl = needgc_false; // No contention, so this is the fast path |
|
687 |
fast_oop_rawmem = store_eden_top; |
|
688 |
} else { |
|
689 |
Node* store_eden_top = |
|
690 |
new StorePConditionalNode(needgc_false, contended_phi_rawmem, eden_top_adr, |
|
691 |
new_eden_top, fast_oop/*old_eden_top*/); |
|
692 |
macro->transform_later(store_eden_top); |
|
693 |
Node *contention_check = new BoolNode(store_eden_top, BoolTest::ne); |
|
694 |
macro->transform_later(contention_check); |
|
695 |
store_eden_top = new SCMemProjNode(store_eden_top); |
|
696 |
macro->transform_later(store_eden_top); |
|
697 |
||
698 |
// If not using TLABs, check to see if there was contention. |
|
699 |
IfNode *contention_iff = new IfNode (needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN); |
|
700 |
macro->transform_later(contention_iff); |
|
701 |
Node *contention_true = new IfTrueNode(contention_iff); |
|
702 |
macro->transform_later(contention_true); |
|
703 |
// If contention, loopback and try again. |
|
704 |
contended_region->init_req(contended_loopback_path, contention_true); |
|
705 |
contended_phi_rawmem->init_req(contended_loopback_path, store_eden_top); |
|
706 |
||
707 |
// Fast-path succeeded with no contention! |
|
708 |
Node *contention_false = new IfFalseNode(contention_iff); |
|
709 |
macro->transform_later(contention_false); |
|
710 |
fast_oop_ctrl = contention_false; |
|
711 |
||
712 |
// Bump total allocated bytes for this thread |
|
713 |
Node* thread = new ThreadLocalNode(); |
|
714 |
macro->transform_later(thread); |
|
715 |
Node* alloc_bytes_adr = macro->basic_plus_adr(macro->top()/*not oop*/, thread, |
|
716 |
in_bytes(JavaThread::allocated_bytes_offset())); |
|
717 |
Node* alloc_bytes = macro->make_load(fast_oop_ctrl, store_eden_top, alloc_bytes_adr, |
|
718 |
0, TypeLong::LONG, T_LONG); |
|
719 |
#ifdef _LP64 |
|
720 |
Node* alloc_size = size_in_bytes; |
|
721 |
#else |
|
722 |
Node* alloc_size = new ConvI2LNode(size_in_bytes); |
|
723 |
macro->transform_later(alloc_size); |
|
724 |
#endif |
|
725 |
Node* new_alloc_bytes = new AddLNode(alloc_bytes, alloc_size); |
|
726 |
macro->transform_later(new_alloc_bytes); |
|
727 |
fast_oop_rawmem = macro->make_store(fast_oop_ctrl, store_eden_top, alloc_bytes_adr, |
|
728 |
0, new_alloc_bytes, T_LONG); |
|
729 |
} |
|
730 |
return fast_oop; |
|
731 |
} |