src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp
changeset 52925 9c18c9d839d3
child 53244 9807daeb47c4
equal deleted inserted replaced
52924:420ff459906f 52925:9c18c9d839d3
       
     1 /*
       
     2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.
       
     7  *
       
     8  * This code is distributed in the hope that it will be useful, but WITHOUT
       
     9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    11  * version 2 for more details (a copy is included in the LICENSE file that
       
    12  * accompanied this code).
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License version
       
    15  * 2 along with this work; if not, write to the Free Software Foundation,
       
    16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    17  *
       
    18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    19  * or visit www.oracle.com if you need additional information or have any
       
    20  * questions.
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
       
    25 #define SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
       
    26 
       
    27 #include "gc/shared/c2/barrierSetC2.hpp"
       
    28 #include "gc/shenandoah/c2/shenandoahSupport.hpp"
       
    29 #include "utilities/growableArray.hpp"
       
    30 
       
    31 class ShenandoahBarrierSetC2State : public ResourceObj {
       
    32 private:
       
    33   GrowableArray<ShenandoahWriteBarrierNode*>* _shenandoah_barriers;
       
    34 
       
    35 public:
       
    36   ShenandoahBarrierSetC2State(Arena* comp_arena);
       
    37   int shenandoah_barriers_count() const;
       
    38   ShenandoahWriteBarrierNode* shenandoah_barrier(int idx) const;
       
    39   void add_shenandoah_barrier(ShenandoahWriteBarrierNode * n);
       
    40   void remove_shenandoah_barrier(ShenandoahWriteBarrierNode * n);
       
    41 };
       
    42 
       
    43 class ShenandoahBarrierSetC2 : public BarrierSetC2 {
       
    44 private:
       
    45   void shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const;
       
    46 
       
    47   bool satb_can_remove_pre_barrier(GraphKit* kit, PhaseTransform* phase, Node* adr,
       
    48                                    BasicType bt, uint adr_idx) const;
       
    49   void satb_write_barrier_pre(GraphKit* kit, bool do_load,
       
    50                               Node* obj,
       
    51                               Node* adr,
       
    52                               uint alias_idx,
       
    53                               Node* val,
       
    54                               const TypeOopPtr* val_type,
       
    55                               Node* pre_val,
       
    56                               BasicType bt) const;
       
    57 
       
    58   void shenandoah_write_barrier_pre(GraphKit* kit,
       
    59                                     bool do_load,
       
    60                                     Node* obj,
       
    61                                     Node* adr,
       
    62                                     uint alias_idx,
       
    63                                     Node* val,
       
    64                                     const TypeOopPtr* val_type,
       
    65                                     Node* pre_val,
       
    66                                     BasicType bt) const;
       
    67 
       
    68   Node* shenandoah_enqueue_barrier(GraphKit* kit, Node* val) const;
       
    69   Node* shenandoah_read_barrier(GraphKit* kit, Node* obj) const;
       
    70   Node* shenandoah_storeval_barrier(GraphKit* kit, Node* obj) const;
       
    71   Node* shenandoah_write_barrier(GraphKit* kit, Node* obj) const;
       
    72   Node* shenandoah_read_barrier_impl(GraphKit* kit, Node* obj, bool use_ctrl, bool use_mem, bool allow_fromspace) const;
       
    73   Node* shenandoah_write_barrier_impl(GraphKit* kit, Node* obj) const;
       
    74   Node* shenandoah_write_barrier_helper(GraphKit* kit, Node* obj, const TypePtr* adr_type) const;
       
    75 
       
    76   void insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
       
    77                           Node* pre_val, bool need_mem_bar) const;
       
    78 
       
    79   static bool clone_needs_postbarrier(ArrayCopyNode *ac, PhaseIterGVN& igvn);
       
    80 
       
    81 protected:
       
    82   virtual void resolve_address(C2Access& access) const;
       
    83   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
       
    84   virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;
       
    85   virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
       
    86                                                Node* new_val, const Type* val_type) const;
       
    87   virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
       
    88                                                 Node* new_val, const Type* value_type) const;
       
    89   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
       
    90 
       
    91 public:
       
    92   static ShenandoahBarrierSetC2* bsc2();
       
    93 
       
    94   static bool is_shenandoah_wb_pre_call(Node* call);
       
    95   static bool is_shenandoah_wb_call(Node* call);
       
    96   static bool is_shenandoah_marking_if(PhaseTransform *phase, Node* n);
       
    97   static bool is_shenandoah_state_load(Node* n);
       
    98   static bool has_only_shenandoah_wb_pre_uses(Node* n);
       
    99 
       
   100   ShenandoahBarrierSetC2State* state() const;
       
   101 
       
   102   static const TypeFunc* write_ref_field_pre_entry_Type();
       
   103   static const TypeFunc* shenandoah_clone_barrier_Type();
       
   104   static const TypeFunc* shenandoah_write_barrier_Type();
       
   105 
       
   106   // This is the entry-point for the backend to perform accesses through the Access API.
       
   107   virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const;
       
   108 
       
   109   virtual Node* resolve(GraphKit* kit, Node* n, DecoratorSet decorators) const;
       
   110 
       
   111   virtual Node* obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes,
       
   112                              Node*& i_o, Node*& needgc_ctrl,
       
   113                              Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,
       
   114                              intx prefetch_lines) const;
       
   115 
       
   116   // These are general helper methods used by C2
       
   117   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const;
       
   118   virtual void clone_barrier_at_expansion(ArrayCopyNode* ac, Node* call, PhaseIterGVN& igvn) const;
       
   119 
       
   120   // Support for GC barriers emitted during parsing
       
   121   virtual bool is_gc_barrier_node(Node* node) const;
       
   122   virtual Node* step_over_gc_barrier(Node* c) const;
       
   123   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
       
   124   virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const;
       
   125   virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand || mode == LoopOptsShenandoahPostExpand; }
       
   126   virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand || mode == LoopOptsShenandoahPostExpand; }
       
   127 
       
   128   // Support for macro expanded GC barriers
       
   129   virtual void register_potential_barrier_node(Node* node) const;
       
   130   virtual void unregister_potential_barrier_node(Node* node) const;
       
   131   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
       
   132   virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
       
   133   virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
       
   134   virtual void add_users_to_worklist(Unique_Node_List* worklist) const;
       
   135 
       
   136   // Allow barrier sets to have shared state that is preserved across a compilation unit.
       
   137   // This could for example comprise macro nodes to be expanded during macro expansion.
       
   138   virtual void* create_barrier_state(Arena* comp_arena) const;
       
   139   // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
       
   140   // expanded later, then now is the time to do so.
       
   141   virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const;
       
   142 
       
   143 #ifdef ASSERT
       
   144   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
       
   145 #endif
       
   146 
       
   147   virtual bool flatten_gc_alias_type(const TypePtr*& adr_type) const;
       
   148 #ifdef ASSERT
       
   149   virtual bool verify_gc_alias_type(const TypePtr* adr_type, int offset) const;
       
   150 #endif
       
   151 
       
   152   virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const;
       
   153   virtual Node* identity_node(PhaseGVN* phase, Node* n) const;
       
   154   virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode) 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   virtual bool escape_is_barrier_node(Node* n) const;
       
   160 
       
   161   virtual bool matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const;
       
   162   virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
       
   163   virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const;
       
   164 
       
   165   virtual void igvn_add_users_to_worklist(PhaseIterGVN* igvn, Node* use) const;
       
   166   virtual void ccp_analyze(PhaseCCP* ccp, Unique_Node_List& worklist, Node* use) const;
       
   167 
       
   168   virtual bool has_special_unique_user(const Node* node) const;
       
   169   virtual Node* split_if_pre(PhaseIdealLoop* phase, Node* n) const;
       
   170   virtual bool build_loop_late_post(PhaseIdealLoop* phase, Node* n) const;
       
   171   virtual bool sink_node(PhaseIdealLoop* phase, Node* n, Node* x, Node* x_ctrl, Node* n_ctrl) const;
       
   172 };
       
   173 
       
   174 #endif // SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP