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_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
26 #define SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
27
28 #include "gc/shared/c2/barrierSetC2.hpp"
29 #include "gc/shenandoah/c2/shenandoahSupport.hpp"
30 #include "utilities/growableArray.hpp"
31
32 class ShenandoahBarrierSetC2State : public ArenaObj {
33 private:
34 GrowableArray<ShenandoahLoadReferenceBarrierNode*>* _load_reference_barriers;
35
36 public:
37 ShenandoahBarrierSetC2State(Arena* comp_arena);
38
39 int load_reference_barriers_count() const;
40 ShenandoahLoadReferenceBarrierNode* load_reference_barrier(int idx) const;
41 void add_load_reference_barrier(ShenandoahLoadReferenceBarrierNode* n);
42 void remove_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n);
43 };
44
45 class ShenandoahBarrierSetC2 : public BarrierSetC2 {
46 private:
47 void shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const;
48
49 bool satb_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, Node* adr,
50 BasicType bt, uint adr_idx) const;
51 void satb_write_barrier_pre(GraphKit* kit, bool do_load,
52 Node* obj,
53 Node* adr,
54 uint alias_idx,
55 Node* val,
56 const TypeOopPtr* val_type,
57 Node* pre_val,
58 BasicType bt) const;
59
60 void shenandoah_write_barrier_pre(GraphKit* kit,
61 bool do_load,
62 Node* obj,
63 Node* adr,
64 uint alias_idx,
65 Node* val,
66 const TypeOopPtr* val_type,
67 Node* pre_val,
68 BasicType bt) const;
69
70 void post_barrier(GraphKit* kit,
71 Node* ctl,
72 Node* store,
73 Node* obj,
74 Node* adr,
75 uint adr_idx,
76 Node* val,
77 BasicType bt,
78 bool use_precise) const;
79
80 void insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
81 Node* pre_val, bool need_mem_bar) const;
82
83 static bool clone_needs_barrier(Node* src, PhaseGVN& gvn);
84
85 protected:
86 virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
87 virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
88 virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
89 Node* new_val, const Type* val_type) const;
90 virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
91 Node* new_val, const Type* value_type) const;
92 virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
93
94 public:
95 static ShenandoahBarrierSetC2* bsc2();
96
97 static bool is_shenandoah_wb_pre_call(Node* call);
98 static bool is_shenandoah_clone_call(Node* call);
99 static bool is_shenandoah_lrb_call(Node* call);
100 static bool is_shenandoah_marking_if(PhaseValues* phase, Node* n);
101 static bool is_shenandoah_state_load(Node* n);
102 static bool has_only_shenandoah_wb_pre_uses(Node* n);
103
104 ShenandoahBarrierSetC2State* state() const;
105
106 static const TypeFunc* write_barrier_pre_Type();
107 static const TypeFunc* clone_barrier_Type();
108 static const TypeFunc* load_reference_barrier_Type();
109 virtual bool has_load_barrier_nodes() const { return true; }
110
111 // This is the entry-point for the backend to perform accesses through the Access API.
112 virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
113
114 // These are general helper methods used by C2
115 virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const;
116
117 // Support for GC barriers emitted during parsing
118 virtual bool is_gc_pre_barrier_node(Node* node) const;
119 virtual bool is_gc_barrier_node(Node* node) const;
120 virtual Node* step_over_gc_barrier(Node* c) const;
121 virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
122 virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const;
123 virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
124 virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
125
126 // Support for macro expanded GC barriers
127 virtual void register_potential_barrier_node(Node* node) const;
128 virtual void unregister_potential_barrier_node(Node* node) const;
129 virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
130 virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
131 virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
132
133 // Allow barrier sets to have shared state that is preserved across a compilation unit.
134 // This could for example comprise macro nodes to be expanded during macro expansion.
135 virtual void* create_barrier_state(Arena* comp_arena) const;
136 // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
137 // expanded later, then now is the time to do so.
138 virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const;
139
140 #ifdef ASSERT
141 virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
142 #endif
143
144 virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const;
145 virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const;
146
147 virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const;
148 virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const;
149 virtual bool escape_has_out_with_unsafe_object(Node* n) const;
150
151 virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
152 virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const;
153 };
154
155 #endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
|
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_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
26 #define SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
27
28 #include "gc/shared/c2/barrierSetC2.hpp"
29 #include "gc/shared/gc_globals.hpp"
30 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
31 #include "gc/shenandoah/shenandoahRuntime.hpp"
32 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
33 #include "opto/machnode.hpp"
34 #include "utilities/growableArray.hpp"
35
36 static const uint8_t ShenandoahBitStrong = 1 << 0; // Barrier: LRB, strong
37 static const uint8_t ShenandoahBitWeak = 1 << 1; // Barrier: LRB, weak
38 static const uint8_t ShenandoahBitPhantom = 1 << 2; // Barrier: LRB, phantom
39 static const uint8_t ShenandoahBitKeepAlive = 1 << 3; // Barrier: KeepAlive (SATB for stores, KA for loads)
40 static const uint8_t ShenandoahBitCardMark = 1 << 4; // Barrier: CM
41 static const uint8_t ShenandoahBitNotNull = 1 << 5; // Metadata: src/dst is not null
42 static const uint8_t ShenandoahBitNative = 1 << 6; // Metadata: access is in native, not in heap
43 static const uint8_t ShenandoahBitElided = 1 << 7; // Metadata: barrier is elided
44
45 // Barrier data that implies real barriers, not additional metadata.
46 static const uint8_t ShenandoahBitsReal = ShenandoahBitStrong | ShenandoahBitWeak | ShenandoahBitPhantom |
47 ShenandoahBitKeepAlive |
48 ShenandoahBitCardMark;
49
50 class ShenandoahBarrierStubC2;
51
52 class ShenandoahBarrierSetC2State : public BarrierSetC2State {
53 GrowableArray<ShenandoahBarrierStubC2*>* _stubs;
54 int _trampoline_stubs_count;
55 int _stubs_start_offset;
56 int _save_slots_offset;
57
58 public:
59 explicit ShenandoahBarrierSetC2State(Arena* comp_arena);
60
61 bool needs_liveness_data(const MachNode* mach) const override;
62 bool needs_livein_data() const override;
63
64 GrowableArray<ShenandoahBarrierStubC2*>* stubs() {
65 return _stubs;
66 }
67
68 void inc_trampoline_stubs_count() {
69 assert(_trampoline_stubs_count != INT_MAX, "Overflow");
70 ++_trampoline_stubs_count;
71 }
72
73 int trampoline_stubs_count() {
74 return _trampoline_stubs_count;
75 }
76
77 void set_stubs_start_offset(int offset) {
78 _stubs_start_offset = offset;
79 }
80
81 int stubs_start_offset() {
82 return _stubs_start_offset;
83 }
84
85 void set_save_slots_stack_offset(int offset) {
86 _save_slots_offset = offset;
87 }
88
89 int save_slots_stack_offset() {
90 assert(_save_slots_offset >= 0, "should be set");
91 return _save_slots_offset;
92 }
93 };
94
95 class ShenandoahBarrierSetC2 : public BarrierSetC2 {
96
97 static bool clone_needs_barrier(const TypeOopPtr* src_type, bool& is_oop_array);
98
99 static bool can_remove_load_barrier(Node* node);
100
101 static void refine_load(Node* node);
102 static void refine_store(const Node* node);
103
104 protected:
105 virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
106 virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
107 virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
108 Node* new_val, const Type* val_type) const;
109 virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
110 Node* new_val, const Type* value_type) const;
111 virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
112
113 public:
114 static ShenandoahBarrierSetC2* bsc2();
115
116 ShenandoahBarrierSetC2State* state() const;
117
118 // This is the entry-point for the backend to perform accesses through the Access API.
119 virtual void clone(GraphKit* kit, Node* src_base, Node* dst_base, Node* size, bool is_array) const;
120 virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
121
122 // These are general helper methods used by C2
123 virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone,
124 bool is_clone_instance, ArrayCopyPhase phase) const;
125
126 // Support for GC barriers emitted during parsing
127 virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
128
129 // Support for macro expanded GC barriers
130 virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
131 virtual void eliminate_gc_barrier_data(Node* node) const;
132
133 // Allow barrier sets to have shared state that is preserved across a compilation unit.
134 // This could for example comprise macro nodes to be expanded during macro expansion.
135 virtual void* create_barrier_state(Arena* comp_arena) const;
136
137 #ifdef ASSERT
138 virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
139 static void verify_gc_barrier_assert(bool cond, const char* msg, uint8_t bd, Node* n);
140 #endif
141
142 int reserved_slots() const { return 4; }
143 int estimate_stub_size() const /* override */;
144 void emit_stubs(CodeBuffer& cb) const /* override */;
145 void late_barrier_analysis() const /* override*/ {
146 compute_liveness_at_stubs();
147 analyze_dominating_barriers();
148 }
149
150 void elide_dominated_barrier(MachNode* mach) const;
151 void analyze_dominating_barriers() const;
152 void strip_extra_data(const Node* node) const;
153 void strip_extra_data(Node_List& accesses) const;
154
155 virtual uint estimated_barrier_size(const Node* node) const;
156
157 static void print_barrier_data(outputStream* os, uint8_t data);
158 };
159
160 class ShenandoahBarrierStubC2 : public BarrierStubC2 {
161 Register const _obj;
162 Address const _addr;
163 const bool _do_load;
164 const bool _narrow;
165 const bool _maybe_null;
166 const bool _needs_load_ref_barrier;
167 const bool _needs_load_ref_weak_barrier;
168 const bool _needs_keep_alive_barrier;
169 const int _fastpath_branch_offset;
170 bool _test_and_branch_reachable;
171 bool _skip_trampoline;
172 Label _test_and_branch_reachable_entry;
173 int _save_slots_idx;
174
175 static void register_stub(ShenandoahBarrierStubC2* stub);
176 static void inc_trampoline_stubs_count();
177 static int trampoline_stubs_count();
178 static int stubs_start_offset();
179 static int save_slots_stack_offset();
180
181 // Manage save slots on stack. We cannot move SP freely when in statically-sized
182 // C2 frame. These methods emulate the stack where a stub can save registers temporarily
183 // without moving SP.
184 void push_save_register(MacroAssembler* masm, Register reg);
185 void pop_save_register(MacroAssembler* masm, Register reg);
186 bool push_save_register_if_live(MacroAssembler* masm, Register reg);
187 int push_save_slot();
188 int pop_save_slot();
189
190 bool is_live(Register reg);
191 Register select_temp_register(bool& selected_live, Address addr, Register reg1);
192
193 void keepalive(MacroAssembler* masm, Register obj, Register tmp1, Register tmp2);
194 void lrb(MacroAssembler* masm, Register obj, Address addr, Register tmp);
195
196 address keepalive_runtime_entry_addr();
197 address lrb_runtime_entry_addr();
198
199 public:
200 ShenandoahBarrierStubC2(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load) :
201 BarrierStubC2(node),
202 _obj(obj),
203 _addr(addr),
204 _do_load(do_load),
205 _narrow(narrow),
206 _maybe_null(!src_not_null(node)),
207 _needs_load_ref_barrier(needs_load_ref_barrier(node)),
208 _needs_load_ref_weak_barrier(needs_load_ref_barrier_weak(node)),
209 _needs_keep_alive_barrier(needs_keep_alive_barrier(node)),
210 _fastpath_branch_offset(),
211 _test_and_branch_reachable(),
212 _skip_trampoline(),
213 _test_and_branch_reachable_entry(),
214 _save_slots_idx(0) {
215
216 assert(!ShenandoahSkipBarriers, "Do not touch stubs when disabled");
217 assert(!_narrow || is_heap_access(node), "Only heap accesses can be narrow");
218 }
219
220 ShenandoahBarrierStubC2(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load, int offset);
221
222 static bool is_heap_access(const MachNode* node) {
223 return (node->barrier_data() & ShenandoahBitNative) == 0;
224 }
225 static bool needs_slow_barrier(const MachNode* node) {
226 return !ShenandoahSkipBarriers && (needs_load_ref_barrier(node) || needs_keep_alive_barrier(node));
227 }
228 static bool needs_load_ref_barrier(const MachNode* node) {
229 return (node->barrier_data() & (ShenandoahBitStrong | ShenandoahBitWeak | ShenandoahBitPhantom)) != 0;
230 }
231 static bool needs_load_ref_barrier_weak(const MachNode* node) {
232 return (node->barrier_data() & (ShenandoahBitWeak | ShenandoahBitPhantom)) != 0;
233 }
234 static bool needs_keep_alive_barrier(const MachNode* node) {
235 return (node->barrier_data() & ShenandoahBitKeepAlive) != 0;
236 }
237 static bool needs_card_barrier(const MachNode* node) {
238 return !ShenandoahSkipBarriers && ((node->barrier_data() & ShenandoahBitCardMark) != 0);
239 }
240 static bool src_not_null(const MachNode* node) {
241 return (node->barrier_data() & ShenandoahBitNotNull) != 0;
242 }
243
244 static void gc_state_check_c2(MacroAssembler* masm, Register rscratch, const unsigned char test_state, ShenandoahBarrierStubC2* slow_stub);
245 static ShenandoahBarrierStubC2* create(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load);
246 static ShenandoahBarrierStubC2* create(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load, int offset);
247 void emit_code(MacroAssembler& masm);
248 void emit_code_actual(MacroAssembler& masm);
249 int get_stub_size();
250 Label* entry();
251 };
252 #endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
|