< prev index next >

src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp

Print this page

  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, PhaseGVN* 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   static const TypeFunc* _write_barrier_pre_Type;
 86   static const TypeFunc* _clone_barrier_Type;
 87   static const TypeFunc* _load_reference_barrier_Type;
 88   static void make_write_barrier_pre_Type();
 89   static void make_clone_barrier_Type();
 90   static void make_load_reference_barrier_Type();
 91 
 92 protected:
 93   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
 94   virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
 95   virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
 96                                                Node* new_val, const Type* val_type) const;
 97   virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
 98                                                 Node* new_val, const Type* value_type) const;
 99   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
100 
101 public:
102   static ShenandoahBarrierSetC2* bsc2();
103 
104   static bool is_shenandoah_wb_pre_call(Node* call);
105   static bool is_shenandoah_clone_call(Node* call);
106   static bool is_shenandoah_lrb_call(Node* call);
107   static bool is_shenandoah_marking_if(PhaseValues* phase, Node* n);
108   static bool is_shenandoah_state_load(Node* n);
109   static bool has_only_shenandoah_wb_pre_uses(Node* n);
110 
111   ShenandoahBarrierSetC2State* state() const;
112 
113   static const TypeFunc* write_barrier_pre_Type();
114   static const TypeFunc* clone_barrier_Type();
115   static const TypeFunc* load_reference_barrier_Type();
116   static void init();
117 
118   virtual bool has_load_barrier_nodes() const { return true; }
119 
120   // This is the entry-point for the backend to perform accesses through the Access API.

121   virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
122 
123   // These are general helper methods used by C2
124   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const;

125 
126   // Support for GC barriers emitted during parsing
127   virtual bool is_gc_pre_barrier_node(Node* node) const;
128   virtual bool is_gc_barrier_node(Node* node) const;
129   virtual Node* step_over_gc_barrier(Node* c) const;
130   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
131   virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const;
132   virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
133   virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
134 
135   // Support for macro expanded GC barriers
136   virtual void register_potential_barrier_node(Node* node) const;
137   virtual void unregister_potential_barrier_node(Node* node) const;
138   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
139   virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
140   virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
141 
142   // Allow barrier sets to have shared state that is preserved across a compilation unit.
143   // This could for example comprise macro nodes to be expanded during macro expansion.
144   virtual void* create_barrier_state(Arena* comp_arena) const;
145   // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
146   // expanded later, then now is the time to do so.
147   virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const;
148 
149 #ifdef ASSERT
150   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;

151 #endif
152 
153   virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const;
154   virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const;




155 
156   virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const;
157   virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const;
158   virtual bool escape_has_out_with_unsafe_object(Node* n) const;

159 
160   virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
161   virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const;

162 };
163 






































































164 #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 
 30 static const uint8_t ShenandoahBitStrong    = 1 << 0; // Barrier: LRB, strong
 31 static const uint8_t ShenandoahBitWeak      = 1 << 1; // Barrier: LRB, weak
 32 static const uint8_t ShenandoahBitPhantom   = 1 << 2; // Barrier: LRB, phantom
 33 static const uint8_t ShenandoahBitKeepAlive = 1 << 3; // Barrier: KeepAlive (SATB for stores, KA for loads)
 34 static const uint8_t ShenandoahBitCardMark  = 1 << 4; // Barrier: CM
 35 static const uint8_t ShenandoahBitNotNull   = 1 << 5; // Metadata: src/dst is definitely not null
 36 static const uint8_t ShenandoahBitNative    = 1 << 6; // Metadata: access is in native, not in heap
 37 static const uint8_t ShenandoahBitElided    = 1 << 7; // Metadata: barrier is elided
 38 
 39 // Barrier data that implies real barriers, not additional metadata.
 40 static const uint8_t ShenandoahBitsReal = ShenandoahBitStrong | ShenandoahBitWeak | ShenandoahBitPhantom |
 41                                           ShenandoahBitKeepAlive |
 42                                           ShenandoahBitCardMark;
 43 
 44 class MachNode;
 45 class ShenandoahBarrierStubC2;
 46 
 47 class ShenandoahBarrierSetC2State : public BarrierSetC2State {
 48   GrowableArray<ShenandoahBarrierStubC2*>* _stubs;
 49   int _trampoline_stubs_count;
 50   int _stubs_start_offset;
 51 
 52 public:
 53   explicit ShenandoahBarrierSetC2State(Arena* comp_arena);
 54 
 55   bool needs_liveness_data(const MachNode* mach) const override;
 56   bool needs_livein_data() const override;
 57 
 58   GrowableArray<ShenandoahBarrierStubC2*>* stubs() {
 59     return _stubs;
 60   }
 61 
 62   void inc_trampoline_stubs_count() {
 63     assert(_trampoline_stubs_count != INT_MAX, "Overflow");
 64     ++_trampoline_stubs_count;
 65   }
 66 
 67   int trampoline_stubs_count() {
 68     return _trampoline_stubs_count;
 69   }
 70 
 71   void set_stubs_start_offset(int offset) {
 72     _stubs_start_offset = offset;
 73   }
 74 
 75   int stubs_start_offset() {
 76     return _stubs_start_offset;
 77   }
 78 };
 79 
 80 class ShenandoahBarrierSetC2 : public BarrierSetC2 {
 81 
 82   static bool clone_needs_barrier(const TypeOopPtr* src_type, bool& is_oop_array);
 83 
 84   static bool can_remove_load_barrier(Node* node);
 85 
 86   static uint8_t refine_load(Node* node, uint8_t bd);
 87   static uint8_t refine_store(Node* node, uint8_t bd);
 88 
 89   static bool is_Load(int opcode);
 90   static bool is_Store(int opcode);
 91   static bool is_LoadStore(int opcode);


































 92 
 93 protected:
 94   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
 95   virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
 96   virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
 97                                                Node* new_val, const Type* val_type) const;
 98   virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
 99                                                 Node* new_val, const Type* value_type) const;
100   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
101 
102 public:
103   static ShenandoahBarrierSetC2* bsc2();
104 







105   ShenandoahBarrierSetC2State* state() const;
106 







107   // This is the entry-point for the backend to perform accesses through the Access API.
108   virtual void clone(GraphKit* kit, Node* src_base, Node* dst_base, Node* size, bool is_array) const;
109   virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
110 
111   // These are general helper methods used by C2
112   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone,
113       bool is_clone_instance, ArrayCopyPhase phase) const;
114 
115   // Support for GC barriers emitted during parsing



116   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;



117 
118   // Support for macro expanded GC barriers


119   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
120   virtual void eliminate_gc_barrier_data(Node* node) const;

121 
122   // Allow barrier sets to have shared state that is preserved across a compilation unit.
123   // This could for example comprise macro nodes to be expanded during macro expansion.
124   virtual void* create_barrier_state(Arena* comp_arena) const;



125 
126 #ifdef ASSERT
127   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
128   static void verify_gc_barrier_assert(bool cond, const char* msg, uint8_t bd, Node* n);
129 #endif
130 
131   int estimate_stub_size() const /* override */;
132   void emit_stubs(CodeBuffer& cb) const /* override */;
133   void late_barrier_analysis() const /* override*/ {
134     compute_liveness_at_stubs();
135     analyze_dominating_barriers();
136   }
137 
138   void elide_dominated_barrier(MachNode* mach, MachNode* dominator) const;
139   void analyze_dominating_barriers() const;
140   void strip_extra_data(const Node* node) const;
141   void strip_extra_data(Node_List& accesses) const;
142 
143   virtual uint estimated_barrier_size(const Node* node) const;
144 
145   static void print_barrier_data(outputStream* os, uint8_t data);
146 };
147 
148 class ShenandoahBarrierStubC2 : public BarrierStubC2 {
149   Register _obj;
150   Address  const _addr;
151   const bool _do_load;
152   const bool _narrow;
153   const bool _maybe_null;
154   const bool _needs_load_ref_barrier;
155   const bool _needs_load_ref_weak_barrier;
156   const bool _needs_keep_alive_barrier;
157   bool _needs_far_jump;
158 
159   static void register_stub(ShenandoahBarrierStubC2* stub);
160 
161   int available_gp_registers();
162   bool is_live_register(Register reg);
163   bool is_special_register(Register reg);
164   Register select_temp_register(bool& selected_live, Register skip_reg1 = noreg);
165 
166   void keepalive(MacroAssembler& masm, Label* L_done = nullptr);
167   void lrb(MacroAssembler& masm, Label* L_done = nullptr);
168 
169   address keepalive_runtime_entry_addr();
170   address lrb_runtime_entry_addr();
171 
172   void maybe_far_jump_if_zero(MacroAssembler& masm, Register reg, Label* L_done);
173   void post_init();
174 
175 public:
176   ShenandoahBarrierStubC2(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load) :
177     BarrierStubC2(node),
178     _obj(obj),
179     _addr(addr),
180     _do_load(do_load),
181     _narrow(narrow),
182     _maybe_null(maybe_null(node)),
183     _needs_load_ref_barrier(needs_load_ref_barrier(node)),
184     _needs_load_ref_weak_barrier(needs_load_ref_barrier_weak(node)),
185     _needs_keep_alive_barrier(needs_keep_alive_barrier(node)),
186     _needs_far_jump() {
187     assert(!_narrow || is_heap_access(node), "Only heap accesses can be narrow");
188     post_init();
189   }
190 
191   static bool is_heap_access(const MachNode* node) {
192     return (node->barrier_data() & ShenandoahBitNative) == 0;
193   }
194   static bool needs_slow_barrier(const MachNode* node) {
195     return needs_load_ref_barrier(node) || needs_keep_alive_barrier(node);
196   }
197   static bool needs_load_ref_barrier(const MachNode* node) {
198     return (node->barrier_data() & (ShenandoahBitStrong | ShenandoahBitWeak | ShenandoahBitPhantom)) != 0;
199   }
200   static bool needs_load_ref_barrier_weak(const MachNode* node) {
201     return (node->barrier_data() & (ShenandoahBitWeak | ShenandoahBitPhantom)) != 0;
202   }
203   static bool needs_keep_alive_barrier(const MachNode* node) {
204     return (node->barrier_data() & ShenandoahBitKeepAlive) != 0;
205   }
206   static bool needs_card_barrier(const MachNode* node) {
207     return (node->barrier_data() & ShenandoahBitCardMark) != 0;
208   }
209   static bool maybe_null(const MachNode* node) {
210     return (node->barrier_data() & ShenandoahBitNotNull) == 0;
211   }
212 
213   static ShenandoahBarrierStubC2* create(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load);
214   void emit_code(MacroAssembler& masm);
215 
216   void enter_if_gc_state(MacroAssembler& masm, const char test_state, Register tmp = noreg);
217 };
218 #endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
< prev index next >