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 #include "precompiled.hpp" 26 #include "opto/arraycopynode.hpp" 27 #include "opto/graphKit.hpp" 28 #include "opto/idealKit.hpp" 29 #include "opto/narrowptrnode.hpp" 30 #include "gc/shared/c2/modRefBarrierSetC2.hpp" 31 #include "utilities/macros.hpp" 32 33 Node* ModRefBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const { 34 DecoratorSet decorators = access.decorators(); 35 GraphKit* kit = access.kit(); 36 37 const TypePtr* adr_type = access.addr().type(); 38 Node* adr = access.addr().node(); 39 40 bool is_array = (decorators & IS_ARRAY) != 0; 41 bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0; 42 bool in_heap = (decorators & IN_HEAP) != 0; 43 bool use_precise = is_array || anonymous; 44 45 if (!access.is_oop() || (!in_heap && !anonymous)) { 46 return BarrierSetC2::store_at_resolved(access, val); 47 } 48 49 uint adr_idx = kit->C->get_alias_index(adr_type); 50 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" ); 51 52 pre_barrier(kit, true /* do_load */, kit->control(), access.base(), adr, adr_idx, val.node(), 53 static_cast<const TypeOopPtr*>(val.type()), NULL /* pre_val */, access.type()); 54 Node* store = BarrierSetC2::store_at_resolved(access, val); 55 post_barrier(kit, kit->control(), access.raw_access(), access.base(), adr, adr_idx, val.node(), 56 access.type(), use_precise); 57 58 return store; 59 } 60 61 Node* ModRefBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicAccess& access, Node* expected_val, 62 Node* new_val, const Type* value_type) const { 63 GraphKit* kit = access.kit(); 64 65 if (!access.is_oop()) { 66 return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); 67 } 68 69 pre_barrier(kit, false /* do_load */, 70 kit->control(), NULL, NULL, max_juint, NULL, NULL, 71 expected_val /* pre_val */, T_OBJECT); 72 73 Node* result = BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); 74 75 post_barrier(kit, kit->control(), access.raw_access(), access.base(), 76 access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true); 77 78 return result; 79 } 80 81 Node* ModRefBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicAccess& access, Node* expected_val, 82 Node* new_val, const Type* value_type) const { 83 GraphKit* kit = access.kit(); 84 85 if (!access.is_oop()) { 86 return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); 87 } 88 89 pre_barrier(kit, false /* do_load */, 90 kit->control(), NULL, NULL, max_juint, NULL, NULL, 91 expected_val /* pre_val */, T_OBJECT); 92 93 Node* load_store = BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); 94 95 // Emit the post barrier only when the actual store happened. This makes sense 96 // to check only for LS_cmp_* that can fail to set the value. 97 // LS_cmp_exchange does not produce any branches by default, so there is no 98 // boolean result to piggyback on. TODO: When we merge CompareAndSwap with 99 // CompareAndExchange and move branches here, it would make sense to conditionalize 100 // post_barriers for LS_cmp_exchange as well. 101 // 102 // CAS success path is marked more likely since we anticipate this is a performance 103 // critical path, while CAS failure path can use the penalty for going through unlikely 104 // path as backoff. Which is still better than doing a store barrier there. 105 IdealKit ideal(kit); 106 ideal.if_then(load_store, BoolTest::ne, ideal.ConI(0), PROB_STATIC_FREQUENT); { 107 kit->sync_kit(ideal); 108 post_barrier(kit, ideal.ctrl(), access.raw_access(), access.base(), 109 access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true); 110 ideal.sync_kit(kit); 111 } ideal.end_if(); 112 kit->final_sync(ideal); 113 114 return load_store; 115 } 116 117 Node* ModRefBarrierSetC2::atomic_xchg_at_resolved(C2AtomicAccess& access, Node* new_val, const Type* value_type) const { 118 GraphKit* kit = access.kit(); 119 120 Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, new_val, value_type); 121 if (!access.is_oop()) { 122 return result; 123 } 124 125 // Don't need to load pre_val. The old value is returned by load_store. 126 // The pre_barrier can execute after the xchg as long as no safepoint 127 // gets inserted between them. 128 pre_barrier(kit, false /* do_load */, 129 kit->control(), NULL, NULL, max_juint, NULL, NULL, 130 result /* pre_val */, T_OBJECT); 131 post_barrier(kit, kit->control(), access.raw_access(), access.base(), access.addr().node(), 132 access.alias_idx(), new_val, T_OBJECT, true); 133 134 return result; 135 } | 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 #include "precompiled.hpp" 26 #include "opto/arraycopynode.hpp" 27 #include "opto/graphKit.hpp" 28 #include "opto/idealKit.hpp" 29 #include "opto/narrowptrnode.hpp" 30 #include "gc/shared/c2/modRefBarrierSetC2.hpp" 31 #include "utilities/macros.hpp" 32 33 Node* ModRefBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const { 34 DecoratorSet decorators = access.decorators(); 35 36 const TypePtr* adr_type = access.addr().type(); 37 Node* adr = access.addr().node(); 38 39 bool is_array = (decorators & IS_ARRAY) != 0; 40 bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0; 41 bool in_heap = (decorators & IN_HEAP) != 0; 42 bool use_precise = is_array || anonymous; 43 bool tighly_coupled_alloc = (decorators & C2_TIGHLY_COUPLED_ALLOC) != 0; 44 45 if (!access.is_oop() || tighly_coupled_alloc || (!in_heap && !anonymous)) { 46 return BarrierSetC2::store_at_resolved(access, val); 47 } 48 49 assert(access.is_parse_access(), "entry not supported at optimization time"); 50 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access); 51 GraphKit* kit = parse_access.kit(); 52 53 uint adr_idx = kit->C->get_alias_index(adr_type); 54 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" ); 55 56 pre_barrier(kit, true /* do_load */, kit->control(), access.base(), adr, adr_idx, val.node(), 57 static_cast<const TypeOopPtr*>(val.type()), NULL /* pre_val */, access.type()); 58 Node* store = BarrierSetC2::store_at_resolved(access, val); 59 post_barrier(kit, kit->control(), access.raw_access(), access.base(), adr, adr_idx, val.node(), 60 access.type(), use_precise); 61 62 return store; 63 } 64 65 Node* ModRefBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val, 66 Node* new_val, const Type* value_type) const { 67 GraphKit* kit = access.kit(); 68 69 if (!access.is_oop()) { 70 return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); 71 } 72 73 pre_barrier(kit, false /* do_load */, 74 kit->control(), NULL, NULL, max_juint, NULL, NULL, 75 expected_val /* pre_val */, T_OBJECT); 76 77 Node* result = BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); 78 79 post_barrier(kit, kit->control(), access.raw_access(), access.base(), 80 access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true); 81 82 return result; 83 } 84 85 Node* ModRefBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val, 86 Node* new_val, const Type* value_type) const { 87 GraphKit* kit = access.kit(); 88 89 if (!access.is_oop()) { 90 return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); 91 } 92 93 pre_barrier(kit, false /* do_load */, 94 kit->control(), NULL, NULL, max_juint, NULL, NULL, 95 expected_val /* pre_val */, T_OBJECT); 96 97 Node* load_store = BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); 98 99 // Emit the post barrier only when the actual store happened. This makes sense 100 // to check only for LS_cmp_* that can fail to set the value. 101 // LS_cmp_exchange does not produce any branches by default, so there is no 102 // boolean result to piggyback on. TODO: When we merge CompareAndSwap with 103 // CompareAndExchange and move branches here, it would make sense to conditionalize 104 // post_barriers for LS_cmp_exchange as well. 105 // 106 // CAS success path is marked more likely since we anticipate this is a performance 107 // critical path, while CAS failure path can use the penalty for going through unlikely 108 // path as backoff. Which is still better than doing a store barrier there. 109 IdealKit ideal(kit); 110 ideal.if_then(load_store, BoolTest::ne, ideal.ConI(0), PROB_STATIC_FREQUENT); { 111 kit->sync_kit(ideal); 112 post_barrier(kit, ideal.ctrl(), access.raw_access(), access.base(), 113 access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true); 114 ideal.sync_kit(kit); 115 } ideal.end_if(); 116 kit->final_sync(ideal); 117 118 return load_store; 119 } 120 121 Node* ModRefBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const { 122 GraphKit* kit = access.kit(); 123 124 Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, new_val, value_type); 125 if (!access.is_oop()) { 126 return result; 127 } 128 129 // Don't need to load pre_val. The old value is returned by load_store. 130 // The pre_barrier can execute after the xchg as long as no safepoint 131 // gets inserted between them. 132 pre_barrier(kit, false /* do_load */, 133 kit->control(), NULL, NULL, max_juint, NULL, NULL, 134 result /* pre_val */, T_OBJECT); 135 post_barrier(kit, kit->control(), access.raw_access(), access.base(), access.addr().node(), 136 access.alias_idx(), new_val, T_OBJECT, true); 137 138 return result; 139 } |