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_SHENANDOAHBASEBARRIERSETC2_HPP 25 #define SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBASEBARRIERSETC2_HPP 26 27 #include "gc/shared/c2/barrierSetC2.hpp" 28 29 class ShenandoahBarrierSetC2State : public ResourceObj { 30 private: 31 GrowableArray<ShenandoahWriteBarrierNode*>* _shenandoah_barriers; 32 33 public: 34 ShenandoahBarrierSetC2State(Arena* comp_arena); 35 int shenandoah_barriers_count() const; 36 ShenandoahWriteBarrierNode* shenandoah_barrier(int idx) const; 37 void add_shenandoah_barrier(ShenandoahWriteBarrierNode * n); 38 void remove_shenandoah_barrier(ShenandoahWriteBarrierNode * n); 39 }; 40 41 class ShenandoahBaseBarrierSetC2 : public BarrierSetC2 { 42 private: 43 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 49 Node* shenandoah_read_barrier_impl(GraphKit* kit, Node* obj, bool use_ctrl, bool use_mem, bool allow_fromspace) const; 50 Node* shenandoah_write_barrier_impl(GraphKit* kit, Node* obj) const; 51 Node* shenandoah_write_barrier_helper(GraphKit* kit, Node* obj, const TypePtr* adr_type) const; 52 53 protected: 54 Node* shenandoah_read_barrier(GraphKit* kit, Node* obj) const; 55 Node* shenandoah_write_barrier(GraphKit* kit, Node* obj) const; 56 Node* shenandoah_storeval_barrier(GraphKit* kit, Node* obj) const; 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 void satb_write_barrier_pre(GraphKit* kit, bool do_load, 68 Node* obj, 69 Node* adr, 70 uint alias_idx, 71 Node* val, 72 const TypeOopPtr* val_type, 73 Node* pre_val, 74 BasicType bt) 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 Node* shenandoah_enqueue_barrier(GraphKit* kit, Node* val) const; 80 81 public: 82 static ShenandoahBaseBarrierSetC2* bsc2(); 83 84 static bool is_shenandoah_wb_pre_call(Node* call); 85 static bool is_shenandoah_marking_if(PhaseTransform *phase, Node* n); 86 static bool is_shenandoah_state_load(Node* n); 87 static bool has_only_shenandoah_wb_pre_uses(Node* n); 88 89 ShenandoahBarrierSetC2State* state() const; 90 91 static const TypeFunc* write_ref_field_pre_entry_Type(); 92 static const TypeFunc* shenandoah_clone_barrier_Type(); 93 static const TypeFunc* shenandoah_write_barrier_Type(); 94 95 // This is the entry-point for the backend to perform accesses through the Access API. 96 virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const; 97 98 // These are general helper methods used by C2 99 virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const; 100 101 // Support for GC barriers emitted during parsing 102 virtual bool is_gc_barrier_node(Node* node) const; 103 virtual Node* step_over_gc_barrier(Node* c) const; 104 virtual Node* peek_thru_gc_barrier(Node* v) const; 105 106 // Support for macro expanded GC barriers 107 virtual void register_potential_barrier_node(Node* node) const; 108 virtual void unregister_potential_barrier_node(Node* node) const; 109 virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const; 110 virtual void enqueue_useful_gc_barrier(Unique_Node_List &worklist, Node* node) const; 111 virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful) const; 112 virtual void add_users_to_worklist(Unique_Node_List* worklist) const; 113 114 // Allow barrier sets to have shared state that is preserved across a compilation unit. 115 // This could for example comprise macro nodes to be expanded during macro expansion. 116 virtual void* create_barrier_state(Arena* comp_arena) const; 117 // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be 118 // expanded later, then now is the time to do so. 119 virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const; 120 virtual void verify_gc_barriers(bool post_parse) const; 121 122 virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const; 123 }; 124 125 #endif // SHARE_VM_GC_SHENANDOAH_C2_SHENANDOAHBASEBARRIERSETC2_HPP