1 /* 2 * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates. 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 "utilities/growableArray.hpp" 29 30 class ShenandoahBarrierSetC2State : public ResourceObj { 31 private: 32 GrowableArray<ShenandoahWriteBarrierNode*>* _shenandoah_barriers; 33 34 public: 35 ShenandoahBarrierSetC2State(Arena* comp_arena); 36 int shenandoah_barriers_count() const; 37 ShenandoahWriteBarrierNode* shenandoah_barrier(int idx) const; 38 void add_shenandoah_barrier(ShenandoahWriteBarrierNode * n); 39 void remove_shenandoah_barrier(ShenandoahWriteBarrierNode * n); 40 }; 41 42 class ShenandoahBarrierSetC2 : public BarrierSetC2 { 43 private: 44 void shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const; 45 46 bool satb_can_remove_pre_barrier(GraphKit* kit, PhaseTransform* phase, Node* adr, 47 BasicType bt, uint adr_idx) const; 48 void satb_write_barrier_pre(GraphKit* kit, bool do_load, 49 Node* obj, 50 Node* adr, 51 uint alias_idx, 52 Node* val, 53 const TypeOopPtr* val_type, 54 Node* pre_val, 55 BasicType bt) const; 56 57 void shenandoah_write_barrier_pre(GraphKit* kit, 58 bool do_load, 59 Node* obj, 60 Node* adr, 61 uint alias_idx, 62 Node* val, 63 const TypeOopPtr* val_type, 64 Node* pre_val, 65 BasicType bt) const; 66 67 Node* shenandoah_enqueue_barrier(GraphKit* kit, Node* val) const; 68 Node* shenandoah_read_barrier(GraphKit* kit, Node* obj) const; 69 Node* shenandoah_storeval_barrier(GraphKit* kit, Node* obj) const; 70 Node* shenandoah_write_barrier(GraphKit* kit, Node* obj) const; 71 Node* shenandoah_read_barrier_impl(GraphKit* kit, Node* obj, bool use_ctrl, bool use_mem, bool allow_fromspace) const; 72 Node* shenandoah_write_barrier_impl(GraphKit* kit, Node* obj) const; 73 Node* shenandoah_write_barrier_helper(GraphKit* kit, Node* obj, const TypePtr* adr_type) const; 74 75 void insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset, 76 Node* pre_val, bool need_mem_bar) const; 77 78 protected: 79 virtual void resolve_address(C2Access& access) const; 80 virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const; 81 virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const; 82 virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicAccess& access, Node* expected_val, 83 Node* new_val, const Type* val_type) const; 84 virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicAccess& access, Node* expected_val, 85 Node* new_val, const Type* value_type) const; 86 virtual Node* atomic_xchg_at_resolved(C2AtomicAccess& access, Node* new_val, const Type* val_type) const; 87 88 public: 89 static ShenandoahBarrierSetC2* bsc2(); 90 91 static bool is_shenandoah_wb_pre_call(Node* call); 92 static bool is_shenandoah_marking_if(PhaseTransform *phase, Node* n); 93 static bool is_shenandoah_state_load(Node* n); 94 static bool has_only_shenandoah_wb_pre_uses(Node* n); 95 96 ShenandoahBarrierSetC2State* state() const; 97 98 Node* shenandoah_read_barrier_acmp(GraphKit* kit, Node* obj); 99 100 static const TypeFunc* write_ref_field_pre_entry_Type(); 101 static const TypeFunc* shenandoah_clone_barrier_Type(); 102 static const TypeFunc* shenandoah_write_barrier_Type(); 103 104 // This is the entry-point for the backend to perform accesses through the Access API. 105 virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const; 106 107 virtual Node* resolve(GraphKit* kit, Node* n, DecoratorSet decorators) const; 108 109 virtual Node* obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes, 110 Node*& i_o, Node*& needgc_ctrl, 111 Node*& fast_oop_ctrl, Node*& fast_oop_rawmem, 112 intx prefetch_lines) 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, ArrayCopyPhase phase) const; 116 virtual Node* array_copy_load_store_barrier(PhaseGVN *phase, bool can_reshape, Node* v, MergeMemNode* mem, Node*& ctl) const; 117 virtual void array_copy_post_barrier_at_expansion(ArrayCopyNode* ac, Node*& c, Node*& m, PhaseIterGVN& igvn) const; 118 119 // Support for GC barriers emitted during parsing 120 virtual bool is_gc_barrier_node(Node* node) const; 121 virtual Node* step_over_gc_barrier(Node* c) const; 122 123 // Support for macro expanded GC barriers 124 virtual void register_potential_barrier_node(Node* node) const; 125 virtual void unregister_potential_barrier_node(Node* node) const; 126 virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const; 127 virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const; 128 virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const; 129 virtual void add_users_to_worklist(Unique_Node_List* worklist) const; 130 131 // Allow barrier sets to have shared state that is preserved across a compilation unit. 132 // This could for example comprise macro nodes to be expanded during macro expansion. 133 virtual void* create_barrier_state(Arena* comp_arena) const; 134 // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be 135 // expanded later, then now is the time to do so. 136 virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const; 137 virtual void verify_gc_barriers(bool post_parse) const; 138 139 virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const; 140 141 virtual bool flatten_gc_alias_type(const TypePtr*& adr_type) const; 142 }; 143 144 #endif // SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP