author | neliasso |
Mon, 01 Jul 2019 10:49:58 +0200 | |
changeset 55536 | 8313c42345d5 |
parent 55394 | b444bbe5c45c |
child 55543 | 448d63614b6b |
permissions | -rw-r--r-- |
50180 | 1 |
/* |
54048
744dc9c33676
8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC
kbarrett
parents:
52925
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50180 | 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 |
#ifndef SHARE_GC_SHARED_C2_BARRIERSETC2_HPP |
|
26 |
#define SHARE_GC_SHARED_C2_BARRIERSETC2_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "oops/accessDecorators.hpp" |
|
30 |
#include "opto/loopnode.hpp" |
|
52627 | 31 |
#include "opto/matcher.hpp" |
50180 | 32 |
#include "opto/memnode.hpp" |
33 |
#include "utilities/globalDefinitions.hpp" |
|
34 |
||
35 |
// This means the access is mismatched. This means the value of an access |
|
36 |
// is not equivalent to the value pointed to by the address. |
|
37 |
const DecoratorSet C2_MISMATCHED = DECORATOR_LAST << 1; |
|
38 |
// The access may not be aligned to its natural size. |
|
39 |
const DecoratorSet C2_UNALIGNED = DECORATOR_LAST << 2; |
|
40 |
// The atomic cmpxchg is weak, meaning that spurious false negatives are allowed, |
|
41 |
// but never false positives. |
|
42 |
const DecoratorSet C2_WEAK_CMPXCHG = DECORATOR_LAST << 3; |
|
43 |
// This denotes that a load has control dependency. |
|
44 |
const DecoratorSet C2_CONTROL_DEPENDENT_LOAD = DECORATOR_LAST << 4; |
|
45 |
// This denotes that a load that must be pinned. |
|
46 |
const DecoratorSet C2_PINNED_LOAD = DECORATOR_LAST << 5; |
|
47 |
// This denotes that the access is produced from the sun.misc.Unsafe intrinsics. |
|
48 |
const DecoratorSet C2_UNSAFE_ACCESS = DECORATOR_LAST << 6; |
|
49 |
// This denotes that the access mutates state. |
|
50 |
const DecoratorSet C2_WRITE_ACCESS = DECORATOR_LAST << 7; |
|
51 |
// This denotes that the access reads state. |
|
52 |
const DecoratorSet C2_READ_ACCESS = DECORATOR_LAST << 8; |
|
52424 | 53 |
// A nearby allocation? |
54048
744dc9c33676
8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC
kbarrett
parents:
52925
diff
changeset
|
54 |
const DecoratorSet C2_TIGHTLY_COUPLED_ALLOC = DECORATOR_LAST << 9; |
52424 | 55 |
// Loads and stores from an arraycopy being optimized |
56 |
const DecoratorSet C2_ARRAY_COPY = DECORATOR_LAST << 10; |
|
50180 | 57 |
|
52426
38bf0c9c4e64
8213384: Move G1/C2 barrier verification into G1BarrierSetC2
rkennke
parents:
52424
diff
changeset
|
58 |
class Compile; |
52568 | 59 |
class ConnectionGraph; |
50180 | 60 |
class GraphKit; |
61 |
class IdealKit; |
|
62 |
class Node; |
|
52712
d17e09494308
8214362: C2: gc interface entry point for split if
roland
parents:
52711
diff
changeset
|
63 |
class PhaseGVN; |
52711 | 64 |
class PhaseIdealLoop; |
52568 | 65 |
class PhaseMacroExpand; |
50180 | 66 |
class Type; |
67 |
class TypePtr; |
|
52568 | 68 |
class Unique_Node_List; |
50180 | 69 |
|
70 |
// This class wraps a node and a type. |
|
71 |
class C2AccessValue: public StackObj { |
|
72 |
protected: |
|
73 |
Node* _node; |
|
74 |
const Type* _type; |
|
75 |
||
76 |
public: |
|
77 |
C2AccessValue(Node* node, const Type* type) : |
|
78 |
_node(node), |
|
79 |
_type(type) {} |
|
80 |
||
81 |
Node* node() const { return _node; } |
|
82 |
const Type* type() const { return _type; } |
|
83 |
||
84 |
void set_node(Node* node) { _node = node; } |
|
85 |
}; |
|
86 |
||
87 |
// This class wraps a node and a pointer type. |
|
88 |
class C2AccessValuePtr: public C2AccessValue { |
|
89 |
||
90 |
public: |
|
91 |
C2AccessValuePtr(Node* node, const TypePtr* type) : |
|
92 |
C2AccessValue(node, reinterpret_cast<const Type*>(type)) {} |
|
93 |
||
94 |
const TypePtr* type() const { return reinterpret_cast<const TypePtr*>(_type); } |
|
95 |
}; |
|
96 |
||
97 |
// This class wraps a bunch of context parameters thare are passed around in the |
|
98 |
// BarrierSetC2 backend hierarchy, for loads and stores, to reduce boiler plate. |
|
99 |
class C2Access: public StackObj { |
|
100 |
protected: |
|
101 |
DecoratorSet _decorators; |
|
102 |
BasicType _type; |
|
103 |
Node* _base; |
|
104 |
C2AccessValuePtr& _addr; |
|
105 |
Node* _raw_access; |
|
106 |
||
107 |
void fixup_decorators(); |
|
108 |
||
109 |
public: |
|
52424 | 110 |
C2Access(DecoratorSet decorators, |
50180 | 111 |
BasicType type, Node* base, C2AccessValuePtr& addr) : |
112 |
_decorators(decorators), |
|
113 |
_type(type), |
|
114 |
_base(base), |
|
115 |
_addr(addr), |
|
116 |
_raw_access(NULL) |
|
52424 | 117 |
{} |
50180 | 118 |
|
119 |
DecoratorSet decorators() const { return _decorators; } |
|
120 |
Node* base() const { return _base; } |
|
121 |
C2AccessValuePtr& addr() const { return _addr; } |
|
122 |
BasicType type() const { return _type; } |
|
123 |
bool is_oop() const { return _type == T_OBJECT || _type == T_ARRAY; } |
|
124 |
bool is_raw() const { return (_decorators & AS_RAW) != 0; } |
|
125 |
Node* raw_access() const { return _raw_access; } |
|
126 |
||
127 |
void set_raw_access(Node* raw_access) { _raw_access = raw_access; } |
|
128 |
virtual void set_memory() {} // no-op for normal accesses, but not for atomic accesses. |
|
129 |
||
130 |
MemNode::MemOrd mem_node_mo() const; |
|
131 |
bool needs_cpu_membar() const; |
|
132 |
||
52424 | 133 |
virtual PhaseGVN& gvn() const = 0; |
134 |
virtual bool is_parse_access() const { return false; } |
|
135 |
virtual bool is_opt_access() const { return false; } |
|
136 |
}; |
|
137 |
||
138 |
// C2Access for parse time calls to the BarrierSetC2 backend. |
|
139 |
class C2ParseAccess: public C2Access { |
|
140 |
protected: |
|
141 |
GraphKit* _kit; |
|
142 |
||
143 |
void* barrier_set_state() const; |
|
144 |
||
145 |
public: |
|
146 |
C2ParseAccess(GraphKit* kit, DecoratorSet decorators, |
|
147 |
BasicType type, Node* base, C2AccessValuePtr& addr) : |
|
148 |
C2Access(decorators, type, base, addr), |
|
149 |
_kit(kit) { |
|
150 |
fixup_decorators(); |
|
151 |
} |
|
152 |
||
153 |
GraphKit* kit() const { return _kit; } |
|
154 |
||
50180 | 155 |
template <typename T> |
156 |
T barrier_set_state_as() const { |
|
157 |
return reinterpret_cast<T>(barrier_set_state()); |
|
158 |
} |
|
52424 | 159 |
|
160 |
virtual PhaseGVN& gvn() const; |
|
161 |
virtual bool is_parse_access() const { return true; } |
|
50180 | 162 |
}; |
163 |
||
164 |
// This class wraps a bunch of context parameters thare are passed around in the |
|
165 |
// BarrierSetC2 backend hierarchy, for atomic accesses, to reduce boiler plate. |
|
52424 | 166 |
class C2AtomicParseAccess: public C2ParseAccess { |
50180 | 167 |
Node* _memory; |
168 |
uint _alias_idx; |
|
169 |
bool _needs_pinning; |
|
170 |
||
171 |
public: |
|
52424 | 172 |
C2AtomicParseAccess(GraphKit* kit, DecoratorSet decorators, BasicType type, |
50180 | 173 |
Node* base, C2AccessValuePtr& addr, uint alias_idx) : |
52424 | 174 |
C2ParseAccess(kit, decorators, type, base, addr), |
50180 | 175 |
_memory(NULL), |
176 |
_alias_idx(alias_idx), |
|
177 |
_needs_pinning(true) {} |
|
178 |
||
179 |
// Set the memory node based on the current memory slice. |
|
180 |
virtual void set_memory(); |
|
181 |
||
182 |
Node* memory() const { return _memory; } |
|
183 |
uint alias_idx() const { return _alias_idx; } |
|
184 |
bool needs_pinning() const { return _needs_pinning; } |
|
185 |
||
186 |
void set_needs_pinning(bool value) { _needs_pinning = value; } |
|
187 |
}; |
|
188 |
||
52424 | 189 |
// C2Access for optimization time calls to the BarrierSetC2 backend. |
190 |
class C2OptAccess: public C2Access { |
|
191 |
PhaseGVN& _gvn; |
|
192 |
MergeMemNode* _mem; |
|
193 |
Node* _ctl; |
|
194 |
||
195 |
public: |
|
196 |
C2OptAccess(PhaseGVN& gvn, Node* ctl, MergeMemNode* mem, DecoratorSet decorators, |
|
197 |
BasicType type, Node* base, C2AccessValuePtr& addr) : |
|
198 |
C2Access(decorators, type, base, addr), |
|
199 |
_gvn(gvn), _mem(mem), _ctl(ctl) { |
|
200 |
fixup_decorators(); |
|
201 |
} |
|
202 |
||
203 |
||
204 |
MergeMemNode* mem() const { return _mem; } |
|
205 |
Node* ctl() const { return _ctl; } |
|
206 |
// void set_mem(Node* mem) { _mem = mem; } |
|
207 |
void set_ctl(Node* ctl) { _ctl = ctl; } |
|
208 |
||
209 |
virtual PhaseGVN& gvn() const { return _gvn; } |
|
210 |
virtual bool is_opt_access() const { return true; } |
|
211 |
}; |
|
212 |
||
213 |
||
50180 | 214 |
// This is the top-level class for the backend of the Access API in C2. |
215 |
// The top-level class is responsible for performing raw accesses. The |
|
216 |
// various GC barrier sets inherit from the BarrierSetC2 class to sprinkle |
|
217 |
// barriers into the accesses. |
|
218 |
class BarrierSetC2: public CHeapObj<mtGC> { |
|
219 |
protected: |
|
220 |
virtual void resolve_address(C2Access& access) const; |
|
221 |
virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const; |
|
222 |
virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const; |
|
223 |
||
52424 | 224 |
virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val, |
50180 | 225 |
Node* new_val, const Type* val_type) const; |
52424 | 226 |
virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val, |
50180 | 227 |
Node* new_val, const Type* value_type) const; |
52424 | 228 |
virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const; |
229 |
virtual Node* atomic_add_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const; |
|
230 |
void pin_atomic_op(C2AtomicParseAccess& access) const; |
|
50180 | 231 |
|
232 |
public: |
|
233 |
// This is the entry-point for the backend to perform accesses through the Access API. |
|
234 |
virtual Node* store_at(C2Access& access, C2AccessValue& val) const; |
|
235 |
virtual Node* load_at(C2Access& access, const Type* val_type) const; |
|
236 |
||
52424 | 237 |
virtual Node* atomic_cmpxchg_val_at(C2AtomicParseAccess& access, Node* expected_val, |
50180 | 238 |
Node* new_val, const Type* val_type) const; |
52424 | 239 |
virtual Node* atomic_cmpxchg_bool_at(C2AtomicParseAccess& access, Node* expected_val, |
50180 | 240 |
Node* new_val, const Type* val_type) const; |
52424 | 241 |
virtual Node* atomic_xchg_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const; |
242 |
virtual Node* atomic_add_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const; |
|
50180 | 243 |
|
244 |
virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const; |
|
245 |
||
51705 | 246 |
virtual Node* resolve(GraphKit* kit, Node* n, DecoratorSet decorators) const { return n; } |
247 |
||
51806 | 248 |
virtual Node* obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes, |
249 |
Node*& i_o, Node*& needgc_ctrl, |
|
250 |
Node*& fast_oop_ctrl, Node*& fast_oop_rawmem, |
|
251 |
intx prefetch_lines) const; |
|
252 |
||
52429
b64514ff68fd
8213381: Hook to allow GC to inject Node::Ideal() calls
rkennke
parents:
52426
diff
changeset
|
253 |
virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const { return NULL; } |
b64514ff68fd
8213381: Hook to allow GC to inject Node::Ideal() calls
rkennke
parents:
52426
diff
changeset
|
254 |
virtual Node* identity_node(PhaseGVN* phase, Node* n) const { return n; } |
b64514ff68fd
8213381: Hook to allow GC to inject Node::Ideal() calls
rkennke
parents:
52426
diff
changeset
|
255 |
|
50180 | 256 |
// These are general helper methods used by C2 |
51984 | 257 |
enum ArrayCopyPhase { |
258 |
Parsing, |
|
259 |
Optimization, |
|
260 |
Expansion |
|
261 |
}; |
|
55307 | 262 |
|
51984 | 263 |
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const { return false; } |
52424 | 264 |
virtual void clone_barrier_at_expansion(ArrayCopyNode* ac, Node* call, PhaseIterGVN& igvn) const; |
50180 | 265 |
|
266 |
// Support for GC barriers emitted during parsing |
|
51485
0c7040d1d1ca
8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents:
50180
diff
changeset
|
267 |
virtual bool has_load_barriers() const { return false; } |
50180 | 268 |
virtual bool is_gc_barrier_node(Node* node) const { return false; } |
269 |
virtual Node* step_over_gc_barrier(Node* c) const { return c; } |
|
55536
8313c42345d5
8226287: Make process_users_of_allocation handle gc barriers
neliasso
parents:
55394
diff
changeset
|
270 |
virtual Node* step_over_gc_barrier_ctrl(Node* c) const { return c; } |
50180 | 271 |
|
272 |
// Support for macro expanded GC barriers |
|
273 |
virtual void register_potential_barrier_node(Node* node) const { } |
|
274 |
virtual void unregister_potential_barrier_node(Node* node) const { } |
|
275 |
virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { } |
|
52224
4f2215a00ed1
8212611: Small collection of simple changes from shenandoah
roland
parents:
51984
diff
changeset
|
276 |
virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {} |
4f2215a00ed1
8212611: Small collection of simple changes from shenandoah
roland
parents:
51984
diff
changeset
|
277 |
virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {} |
50180 | 278 |
|
279 |
// Allow barrier sets to have shared state that is preserved across a compilation unit. |
|
280 |
// This could for example comprise macro nodes to be expanded during macro expansion. |
|
281 |
virtual void* create_barrier_state(Arena* comp_arena) const { return NULL; } |
|
52711 | 282 |
// If the BarrierSetC2 state has barrier nodes in its compilation |
283 |
// unit state to be expanded later, then now is the time to do so. |
|
284 |
virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const { return false; } |
|
285 |
virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const { return false; } |
|
286 |
virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return false; } |
|
287 |
virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return false; } |
|
52426
38bf0c9c4e64
8213384: Move G1/C2 barrier verification into G1BarrierSetC2
rkennke
parents:
52424
diff
changeset
|
288 |
|
52655
c88468bc7690
8214057: GC/C2 abstraction for Node::has_special_unique_user()
rkennke
parents:
52654
diff
changeset
|
289 |
virtual bool has_special_unique_user(const Node* node) const { return false; } |
55307 | 290 |
virtual bool needs_anti_dependence_check(const Node* node) const { return true; } |
291 |
||
292 |
virtual void barrier_insertion_phase(Compile* C, PhaseIterGVN &igvn) const { } |
|
52655
c88468bc7690
8214057: GC/C2 abstraction for Node::has_special_unique_user()
rkennke
parents:
52654
diff
changeset
|
293 |
|
52426
38bf0c9c4e64
8213384: Move G1/C2 barrier verification into G1BarrierSetC2
rkennke
parents:
52424
diff
changeset
|
294 |
enum CompilePhase { |
55307 | 295 |
BeforeOptimize, |
296 |
BeforeLateInsertion, |
|
297 |
BeforeMacroExpand, |
|
52426
38bf0c9c4e64
8213384: Move G1/C2 barrier verification into G1BarrierSetC2
rkennke
parents:
52424
diff
changeset
|
298 |
BeforeCodeGen |
38bf0c9c4e64
8213384: Move G1/C2 barrier verification into G1BarrierSetC2
rkennke
parents:
52424
diff
changeset
|
299 |
}; |
52441
6082c529aed8
8213371: GC/C2 abstraction and cleanup to handle custom offset for GC memory accesses
rkennke
parents:
52429
diff
changeset
|
300 |
|
6082c529aed8
8213371: GC/C2 abstraction and cleanup to handle custom offset for GC memory accesses
rkennke
parents:
52429
diff
changeset
|
301 |
virtual bool flatten_gc_alias_type(const TypePtr*& adr_type) const { return false; } |
6082c529aed8
8213371: GC/C2 abstraction and cleanup to handle custom offset for GC memory accesses
rkennke
parents:
52429
diff
changeset
|
302 |
#ifdef ASSERT |
6082c529aed8
8213371: GC/C2 abstraction and cleanup to handle custom offset for GC memory accesses
rkennke
parents:
52429
diff
changeset
|
303 |
virtual bool verify_gc_alias_type(const TypePtr* adr_type, int offset) const { return false; } |
55307 | 304 |
virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const {} |
52441
6082c529aed8
8213371: GC/C2 abstraction and cleanup to handle custom offset for GC memory accesses
rkennke
parents:
52429
diff
changeset
|
305 |
#endif |
52471
04d7e790aa2e
8213489: GC/C2 abstraction for Compile::final_graph_reshaping()
rkennke
parents:
52441
diff
changeset
|
306 |
|
04d7e790aa2e
8213489: GC/C2 abstraction for Compile::final_graph_reshaping()
rkennke
parents:
52441
diff
changeset
|
307 |
virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode) const { return false; } |
04d7e790aa2e
8213489: GC/C2 abstraction for Compile::final_graph_reshaping()
rkennke
parents:
52441
diff
changeset
|
308 |
|
52568 | 309 |
virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const { return false; } |
310 |
virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const { return false; } |
|
311 |
virtual bool escape_has_out_with_unsafe_object(Node* n) const { return false; } |
|
52627 | 312 |
|
313 |
virtual bool matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const { return false; }; |
|
314 |
virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const { return false; }; |
|
315 |
virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const { return false; } |
|
52654 | 316 |
|
55307 | 317 |
virtual void igvn_add_users_to_worklist(PhaseIterGVN* igvn, Node* use) const { } |
318 |
virtual void ccp_analyze(PhaseCCP* ccp, Unique_Node_List& worklist, Node* use) const { } |
|
52654 | 319 |
|
52712
d17e09494308
8214362: C2: gc interface entry point for split if
roland
parents:
52711
diff
changeset
|
320 |
virtual Node* split_if_pre(PhaseIdealLoop* phase, Node* n) const { return NULL; } |
52925
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
52712
diff
changeset
|
321 |
virtual bool build_loop_late_post(PhaseIdealLoop* phase, Node* n) const { return false; } |
9c18c9d839d3
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents:
52712
diff
changeset
|
322 |
virtual bool sink_node(PhaseIdealLoop* phase, Node* n, Node* x, Node* x_ctrl, Node* n_ctrl) const { return false; } |
50180 | 323 |
}; |
324 |
||
325 |
#endif // SHARE_GC_SHARED_C2_BARRIERSETC2_HPP |