/* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "opto/arraycopynode.hpp" #include "opto/graphKit.hpp" #include "opto/idealKit.hpp" #include "opto/narrowptrnode.hpp" #include "gc/shared/c2ModRefBSCodeGen.hpp" #include "utilities/macros.hpp" Node* C2ModRefBSCodeGen::store_at_resolved(GraphKit* kit, Node* obj, Node* adr, const TypePtr* adr_type, Node* val, const Type* val_type, BasicType bt, C2DecoratorSet decorators) { bool on_array = (decorators & C2_ACCESS_ON_ARRAY) != 0; bool anonymous = (decorators & C2_ACCESS_ON_ANONYMOUS) != 0; bool on_heap = (decorators & C2_ACCESS_ON_HEAP) != 0; bool use_precise = on_array || anonymous; bool is_obj = bt == T_OBJECT || bt == T_ARRAY; if (!is_obj || (!on_heap && !anonymous)) { return C2BarrierSetCodeGen::store_at_resolved(kit, obj, adr, adr_type, val, val_type, bt, decorators); } uint adr_idx = kit->C->get_alias_index(adr_type); assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" ); pre_barrier(kit, true /* do_load */, kit->control(), obj, adr, adr_idx, val, static_cast(val_type), NULL /* pre_val */, bt); Node* store = C2BarrierSetCodeGen::store_at_resolved(kit, obj, adr, adr_type, val, val_type, bt, decorators); post_barrier(kit, kit->control(), store, obj, adr, adr_idx, val, bt, use_precise); return store; } Node* C2ModRefBSCodeGen::cas_val_at_resolved(GraphKit* kit, Node* obj, Node* adr, const TypePtr* adr_type, int alias_idx, Node* expected_val, Node* new_val, const Type* value_type, Node* mem, Node*& load_store, BasicType bt, C2DecoratorSet decorators) { bool is_obj = bt == T_OBJECT || bt == T_ARRAY; if (!is_obj) { return C2BarrierSetCodeGen::cas_val_at_resolved(kit, obj, adr, adr_type, alias_idx, expected_val, new_val, value_type, mem, load_store, bt, decorators); } pre_barrier(kit, false /* do_load */, kit->control(), NULL, NULL, max_juint, NULL, NULL, expected_val /* pre_val */, T_OBJECT); Node* result = C2BarrierSetCodeGen::cas_val_at_resolved(kit, obj, adr, adr_type, alias_idx, expected_val, new_val, value_type, mem, load_store, bt, decorators); post_barrier(kit, kit->control(), load_store, obj, adr, alias_idx, new_val, T_OBJECT, true); return result; } Node* C2ModRefBSCodeGen::cas_bool_at_resolved(GraphKit* kit, Node* obj, Node* adr, const TypePtr* adr_type, int alias_idx, Node* expected_val, Node* new_val, const Type* value_type, Node* mem, BasicType bt, C2DecoratorSet decorators) { bool is_obj = bt == T_OBJECT || bt == T_ARRAY; if (!is_obj) { return C2BarrierSetCodeGen::cas_bool_at_resolved(kit, obj, adr, adr_type, alias_idx, expected_val, new_val, value_type, mem, bt, decorators); } pre_barrier(kit, false /* do_load */, kit->control(), NULL, NULL, max_juint, NULL, NULL, expected_val /* pre_val */, T_OBJECT); Node* load_store = C2BarrierSetCodeGen::cas_bool_at_resolved(kit, obj, adr, adr_type, alias_idx, expected_val, new_val, value_type, mem, bt, decorators); // Emit the post barrier only when the actual store happened. This makes sense // to check only for LS_cmp_* that can fail to set the value. // LS_cmp_exchange does not produce any branches by default, so there is no // boolean result to piggyback on. TODO: When we merge CompareAndSwap with // CompareAndExchange and move branches here, it would make sense to conditionalize // post_barriers for LS_cmp_exchange as well. // // CAS success path is marked more likely since we anticipate this is a performance // critical path, while CAS failure path can use the penalty for going through unlikely // path as backoff. Which is still better than doing a store barrier there. IdealKit ideal(kit); ideal.if_then(load_store, BoolTest::ne, ideal.ConI(0), PROB_STATIC_FREQUENT); { kit->sync_kit(ideal); post_barrier(kit, ideal.ctrl(), load_store, obj, adr, alias_idx, new_val, T_OBJECT, true); ideal.sync_kit(kit); } ideal.end_if(); kit->final_sync(ideal); return load_store; } Node* C2ModRefBSCodeGen::swap_at_resolved(GraphKit* kit, Node* obj, Node* adr, const TypePtr* adr_type, int alias_idx, Node* new_val, const Type* value_type, Node* mem, Node*& load_store, BasicType bt, C2DecoratorSet decorators) { bool is_obj = bt == T_OBJECT || bt == T_ARRAY; Node* result = C2BarrierSetCodeGen::swap_at_resolved(kit, obj, adr, adr_type, alias_idx, new_val, value_type, mem, load_store, bt, decorators); if (!is_obj) { return result; } // Don't need to load pre_val. The old value is returned by load_store. // The pre_barrier can execute after the xchg as long as no safepoint // gets inserted between them. pre_barrier(kit, false /* do_load */, kit->control(), NULL, NULL, max_juint, NULL, NULL, result /* pre_val */, T_OBJECT); post_barrier(kit, kit->control(), load_store, obj, adr, alias_idx, new_val, T_OBJECT, true); return result; }