< prev index next >

src/hotspot/share/gc/z/c2/zBarrierSetC2.hpp

Print this page




  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 #ifndef SHARE_GC_Z_C2_ZBARRIERSETC2_HPP
  25 #define SHARE_GC_Z_C2_ZBARRIERSETC2_HPP
  26 
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "memory/allocation.hpp"
  29 #include "opto/node.hpp"
  30 #include "utilities/growableArray.hpp"
  31 
  32 class ZCompareAndSwapPNode : public CompareAndSwapPNode {
  33 public:
  34     ZCompareAndSwapPNode(Node* c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }
  35     virtual int Opcode() const;
  36 };
  37 
  38 class ZWeakCompareAndSwapPNode : public WeakCompareAndSwapPNode {
  39 public:
  40     ZWeakCompareAndSwapPNode(Node* c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : WeakCompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }
  41     virtual int Opcode() const;
  42 };
  43 
  44 class ZCompareAndExchangePNode : public CompareAndExchangePNode {
  45 public:
  46     ZCompareAndExchangePNode(Node* c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord) : CompareAndExchangePNode(c, mem, adr, val, ex, at, t, mem_ord) { }
  47     virtual int Opcode() const;
  48 };
  49 
  50 class ZGetAndSetPNode : public GetAndSetPNode {
  51 public:
  52     ZGetAndSetPNode(Node* c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t) : GetAndSetPNode(c, mem, adr, val, at, t) { }
  53     virtual int Opcode() const;
  54 };
  55 
  56 class LoadBarrierNode : public MultiNode {
  57 private:
  58   bool _weak;               // On strong or weak oop reference






  59   static bool is_dominator(PhaseIdealLoop* phase, bool linear_only, Node *d, Node *n);
  60   void push_dominated_barriers(PhaseIterGVN* igvn) const;
  61 
  62 public:
  63   enum {
  64     Control,
  65     Memory,
  66     Oop,
  67     Address,
  68     Number_of_Outputs = Address,
  69     Similar,
  70     Number_of_Inputs
  71   };
  72 
  73   LoadBarrierNode(Compile* C,
  74                   Node* c,
  75                   Node* mem,
  76                   Node* val,
  77                   Node* adr,
  78                   bool weak);


  79 
  80   virtual int Opcode() const;
  81   virtual uint size_of() const;
  82   virtual bool cmp(const Node& n) const;
  83   virtual const Type *bottom_type() const;
  84   virtual const TypePtr* adr_type() const;
  85   virtual const Type *Value(PhaseGVN *phase) const;
  86   virtual Node *Identity(PhaseGVN *phase);
  87   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  88   virtual uint match_edge(uint idx) const;
  89 
  90   LoadBarrierNode* has_dominating_barrier(PhaseIdealLoop* phase,
  91                                           bool linear_only,
  92                                           bool look_for_similar);
  93 
  94   void fix_similar_in_uses(PhaseIterGVN* igvn);
  95 
  96   bool has_true_uses() const;
  97 
  98   bool can_be_eliminated() const {
  99     return !in(Similar)->is_top();
 100   }
 101 
 102   bool is_weak() const {
 103     return _weak;
 104   }








 105 };
 106 
 107 class LoadBarrierSlowRegNode : public LoadPNode {
 108 private:
 109     bool _is_weak;
 110 public:
 111   LoadBarrierSlowRegNode(Node *c,
 112                          Node *mem,
 113                          Node *adr,
 114                          const TypePtr *at,
 115                          const TypePtr* t,
 116                          MemOrd mo,
 117                          bool weak = false,
 118                          ControlDependency control_dependency = DependsOnlyOnTest) :
 119       LoadPNode(c, mem, adr, at, t, mo, control_dependency), _is_weak(weak) {
 120     init_class_id(Class_LoadBarrierSlowReg);
 121   }
 122 
 123   virtual const char * name() {
 124     return "LoadBarrierSlowRegNode";
 125   }
 126 
 127   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
 128     return NULL;
 129   }
 130 
 131   virtual int Opcode() const;


















 132 
 133   bool is_weak() { return _is_weak; }




 134 };
 135 
 136 class ZBarrierSetC2State : public ResourceObj {
 137 private:
 138   // List of load barrier nodes which need to be expanded before matching
 139   GrowableArray<LoadBarrierNode*>* _load_barrier_nodes;
 140 
 141 public:
 142   ZBarrierSetC2State(Arena* comp_arena);
 143   int load_barrier_count() const;
 144   void add_load_barrier_node(LoadBarrierNode* n);
 145   void remove_load_barrier_node(LoadBarrierNode* n);
 146   LoadBarrierNode* load_barrier_node(int idx) const;
 147 };
 148 
 149 enum BarrierInfo {
 150     NoBarrier       = 0,
 151     RequireBarrier  = 1,
 152     WeakBarrier     = 3,  // Inclusive with RequireBarrier
 153     ExpandedBarrier = 4
 154 };
 155 
 156 class ZBarrierSetC2 : public BarrierSetC2 {
 157 private:
 158   ZBarrierSetC2State* state() const;



 159   void expand_loadbarrier_node(PhaseMacroExpand* phase, LoadBarrierNode* barrier) const;


 160 
 161 #ifdef ASSERT
 162   void verify_gc_barriers(bool post_parse) const;
 163 #endif
 164 
 165 protected:
 166   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
 167   virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access,
 168                                                Node* expected_val,
 169                                                Node* new_val,
 170                                                const Type* val_type) const;
 171   virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access,
 172                                                 Node* expected_val,
 173                                                 Node* new_val,
 174                                                 const Type* value_type) const;
 175   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access,
 176                                         Node* new_val,
 177                                         const Type* val_type) const;
 178 
 179 public:
 180   virtual void* create_barrier_state(Arena* comp_arena) const;





 181 

 182   virtual bool has_load_barriers() const { return true; }
 183   virtual bool is_gc_barrier_node(Node* node) const;
 184   virtual Node* step_over_gc_barrier(Node* c) const;
 185 
 186   virtual void register_potential_barrier_node(Node* node) const;
 187   virtual void unregister_potential_barrier_node(Node* node) const;
 188   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { }
 189   virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
 190   virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
 191 



 192   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const;
 193 


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




 195   virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode) const;

 196   virtual bool matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const;
 197   virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
 198   virtual bool needs_anti_dependence_check(const Node* node) const;
 199 
 200 #ifdef ASSERT
 201   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
 202 #endif
 203 
 204   // Load barrier insertion and expansion external
 205   virtual void barrier_insertion_phase(Compile* C, PhaseIterGVN &igvn) const;
 206   virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const;
 207   virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return (mode == LoopOptsZBarrierInsertion); }
 208 
 209 private:
 210   // Load barrier insertion and expansion internal
 211   void insert_barriers_on_unsafe(PhaseIdealLoop* phase) const;
 212   void clean_catch_blocks(PhaseIdealLoop* phase) const;
 213   void insert_load_barriers(PhaseIdealLoop* phase) const;
 214   LoadNode* insert_one_loadbarrier(PhaseIdealLoop* phase, LoadNode* load, Node* ctrl) const;
 215   void insert_one_loadbarrier_inner(PhaseIdealLoop* phase, LoadNode* load, Node* ctrl, VectorSet visited) const;
 216 };
 217 
 218 #endif // SHARE_GC_Z_C2_ZBARRIERSETC2_HPP


  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 #ifndef SHARE_GC_Z_C2_ZBARRIERSETC2_HPP
  25 #define SHARE_GC_Z_C2_ZBARRIERSETC2_HPP
  26 
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "memory/allocation.hpp"
  29 #include "opto/node.hpp"
  30 #include "utilities/growableArray.hpp"
  31 
























  32 class LoadBarrierNode : public MultiNode {
  33 private:
  34   bool _weak;               // On strong or weak oop reference
  35   bool _writeback;          // Controls if the barrier writes the healed oop back to memory
  36                             // A swap on a memory location must never write back the healed oop
  37   bool _oop_reload_allowed; // Controls if the barrier are allowed to reload the oop from memory
  38                             // before healing, otherwise both the oop and the address must be
  39                             // passed to the barrier from the oop
  40 
  41   static bool is_dominator(PhaseIdealLoop* phase, bool linear_only, Node *d, Node *n);
  42   void push_dominated_barriers(PhaseIterGVN* igvn) const;
  43 
  44 public:
  45   enum {
  46     Control,
  47     Memory,
  48     Oop,
  49     Address,
  50     Number_of_Outputs = Address,
  51     Similar,
  52     Number_of_Inputs
  53   };
  54 
  55   LoadBarrierNode(Compile* C,
  56                   Node* c,
  57                   Node* mem,
  58                   Node* val,
  59                   Node* adr,
  60                   bool weak,
  61                   bool writeback,
  62                   bool oop_reload_allowed);
  63 
  64   virtual int Opcode() const;
  65   virtual uint size_of() const;
  66   virtual bool cmp(const Node& n) const;
  67   virtual const Type *bottom_type() const;
  68   virtual const TypePtr* adr_type() const;
  69   virtual const Type *Value(PhaseGVN *phase) const;
  70   virtual Node *Identity(PhaseGVN *phase);
  71   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  72   virtual uint match_edge(uint idx) const;
  73 
  74   LoadBarrierNode* has_dominating_barrier(PhaseIdealLoop* phase,
  75                                           bool linear_only,
  76                                           bool look_for_similar);
  77 
  78   void fix_similar_in_uses(PhaseIterGVN* igvn);
  79 
  80   bool has_true_uses() const;
  81 
  82   bool can_be_eliminated() const {
  83     return !in(Similar)->is_top();
  84   }
  85 
  86   bool is_weak() const {
  87     return _weak;
  88   }
  89 
  90   bool is_writeback() const {
  91     return _writeback;
  92   }
  93 
  94   bool oop_reload_allowed() const {
  95     return _oop_reload_allowed;
  96   }
  97 };
  98 
  99 class LoadBarrierSlowRegNode : public LoadPNode {


 100 public:
 101   LoadBarrierSlowRegNode(Node *c,
 102                          Node *mem,
 103                          Node *adr,
 104                          const TypePtr *at,
 105                          const TypePtr* t,
 106                          MemOrd mo,

 107                          ControlDependency control_dependency = DependsOnlyOnTest) :
 108       LoadPNode(c, mem, adr, at, t, mo, control_dependency) {
 109     init_class_id(Class_LoadBarrierSlowReg);
 110   }
 111 
 112   virtual const char * name() {
 113     return "LoadBarrierSlowRegNode";
 114   }
 115 
 116   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
 117     return NULL;
 118   }
 119 
 120   virtual int Opcode() const;
 121 };
 122 
 123 class LoadBarrierWeakSlowRegNode : public LoadPNode {
 124 public:
 125   LoadBarrierWeakSlowRegNode(Node *c,
 126                              Node *mem,
 127                              Node *adr,
 128                              const TypePtr *at,
 129                              const TypePtr* t,
 130                              MemOrd mo,
 131                              ControlDependency control_dependency = DependsOnlyOnTest) :
 132       LoadPNode(c, mem, adr, at, t, mo, control_dependency) {
 133     init_class_id(Class_LoadBarrierWeakSlowReg);
 134   }
 135 
 136   virtual const char * name() {
 137     return "LoadBarrierWeakSlowRegNode";
 138   }
 139 
 140   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
 141     return NULL;
 142   }
 143 
 144   virtual int Opcode() const;
 145 };
 146 
 147 class ZBarrierSetC2State : public ResourceObj {
 148 private:
 149   // List of load barrier nodes which need to be expanded before matching
 150   GrowableArray<LoadBarrierNode*>* _load_barrier_nodes;
 151 
 152 public:
 153   ZBarrierSetC2State(Arena* comp_arena);
 154   int load_barrier_count() const;
 155   void add_load_barrier_node(LoadBarrierNode* n);
 156   void remove_load_barrier_node(LoadBarrierNode* n);
 157   LoadBarrierNode* load_barrier_node(int idx) const;
 158 };
 159 







 160 class ZBarrierSetC2 : public BarrierSetC2 {
 161 private:
 162   ZBarrierSetC2State* state() const;
 163   Node* make_cas_loadbarrier(C2AtomicParseAccess& access) const;
 164   Node* make_cmpx_loadbarrier(C2AtomicParseAccess& access) const;
 165   void expand_loadbarrier_basic(PhaseMacroExpand* phase, LoadBarrierNode *barrier) const;
 166   void expand_loadbarrier_node(PhaseMacroExpand* phase, LoadBarrierNode* barrier) const;
 167   void expand_loadbarrier_optimized(PhaseMacroExpand* phase, LoadBarrierNode *barrier) const;
 168   const TypeFunc* load_barrier_Type() const;
 169 
 170 #ifdef ASSERT
 171   void verify_gc_barriers(bool post_parse) const;
 172 #endif
 173 
 174 protected:
 175   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
 176   virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access,
 177                                                Node* expected_val,
 178                                                Node* new_val,
 179                                                const Type* val_type) const;
 180   virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access,
 181                                                 Node* expected_val,
 182                                                 Node* new_val,
 183                                                 const Type* value_type) const;
 184   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access,
 185                                         Node* new_val,
 186                                         const Type* val_type) const;
 187 
 188 public:
 189   Node* load_barrier(GraphKit* kit,
 190                      Node* val,
 191                      Node* adr,
 192                      bool weak = false,
 193                      bool writeback = true,
 194                      bool oop_reload_allowed = true) const;
 195 
 196   virtual void* create_barrier_state(Arena* comp_arena) const;
 197   virtual bool has_load_barriers() const { return true; }
 198   virtual bool is_gc_barrier_node(Node* node) const;




 199   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { }

 200   virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
 201   virtual void add_users_to_worklist(Unique_Node_List* worklist) const;
 202   virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
 203   virtual void register_potential_barrier_node(Node* node) const;
 204   virtual void unregister_potential_barrier_node(Node* node) const;
 205   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const;
 206   virtual Node* step_over_gc_barrier(Node* c) const;
 207   // If the BarrierSetC2 state has kept barrier nodes in its compilation unit state to be
 208   // expanded later, then now is the time to do so.
 209   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
 210 
 211   static void find_dominating_barriers(PhaseIterGVN& igvn);
 212   static void loop_optimize_gc_barrier(PhaseIdealLoop* phase, Node* node, bool last_round);
 213 
 214   virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode) const;
 215 
 216   virtual bool matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const;


 217 
 218 #ifdef ASSERT
 219   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
 220 #endif
 221 
 222   virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const;
 223   virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const;










 224 };
 225 
 226 #endif // SHARE_GC_Z_C2_ZBARRIERSETC2_HPP
< prev index next >