Path: blob/master/src/hotspot/cpu/aarch64/gc/shenandoah/c1/shenandoahBarrierSetC1_aarch64.cpp
41155 views
/*1* Copyright (c) 2018, 2021, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_LIRAssembler.hpp"26#include "c1/c1_MacroAssembler.hpp"27#include "gc/shared/gc_globals.hpp"28#include "gc/shenandoah/shenandoahBarrierSet.hpp"29#include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"30#include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"3132#define __ masm->masm()->3334void LIR_OpShenandoahCompareAndSwap::emit_code(LIR_Assembler* masm) {35Register addr = _addr->as_register_lo();36Register newval = _new_value->as_register();37Register cmpval = _cmp_value->as_register();38Register tmp1 = _tmp1->as_register();39Register tmp2 = _tmp2->as_register();40Register result = result_opr()->as_register();4142ShenandoahBarrierSet::assembler()->iu_barrier(masm->masm(), newval, rscratch2);4344if (UseCompressedOops) {45__ encode_heap_oop(tmp1, cmpval);46cmpval = tmp1;47__ encode_heap_oop(tmp2, newval);48newval = tmp2;49}5051ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm->masm(), addr, cmpval, newval, /*acquire*/ true, /*release*/ true, /*is_cae*/ false, result);5253if (CompilerConfig::is_c1_only_no_jvmci()) {54// The membar here is necessary to prevent reordering between the55// release store in the CAS above and a subsequent volatile load.56// However for tiered compilation C1 inserts a full barrier before57// volatile loads which means we don't need an additional barrier58// here (see LIRGenerator::volatile_field_load()).59__ membar(__ AnyAny);60}61}6263#undef __6465#ifdef ASSERT66#define __ gen->lir(__FILE__, __LINE__)->67#else68#define __ gen->lir()->69#endif7071LIR_Opr ShenandoahBarrierSetC1::atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value) {72BasicType bt = access.type();73if (access.is_oop()) {74LIRGenerator *gen = access.gen();75if (ShenandoahSATBBarrier) {76pre_barrier(gen, access.access_emit_info(), access.decorators(), access.resolved_addr(),77LIR_OprFact::illegalOpr /* pre_val */);78}79if (ShenandoahCASBarrier) {80cmp_value.load_item();81new_value.load_item();8283LIR_Opr t1 = gen->new_register(T_OBJECT);84LIR_Opr t2 = gen->new_register(T_OBJECT);85LIR_Opr addr = access.resolved_addr()->as_address_ptr()->base();86LIR_Opr result = gen->new_register(T_INT);8788__ append(new LIR_OpShenandoahCompareAndSwap(addr, cmp_value.result(), new_value.result(), t1, t2, result));89return result;90}91}92return BarrierSetC1::atomic_cmpxchg_at_resolved(access, cmp_value, new_value);93}9495LIR_Opr ShenandoahBarrierSetC1::atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value) {96LIRGenerator* gen = access.gen();97BasicType type = access.type();9899LIR_Opr result = gen->new_register(type);100value.load_item();101LIR_Opr value_opr = value.result();102103if (access.is_oop()) {104value_opr = iu_barrier(access.gen(), value_opr, access.access_emit_info(), access.decorators());105}106107assert(type == T_INT || is_reference_type(type) LP64_ONLY( || type == T_LONG ), "unexpected type");108LIR_Opr tmp = gen->new_register(T_INT);109__ xchg(access.resolved_addr(), value_opr, result, tmp);110111if (access.is_oop()) {112result = load_reference_barrier(access.gen(), result, LIR_OprFact::addressConst(0), access.decorators());113LIR_Opr tmp = gen->new_register(type);114__ move(result, tmp);115result = tmp;116if (ShenandoahSATBBarrier) {117pre_barrier(access.gen(), access.access_emit_info(), access.decorators(), LIR_OprFact::illegalOpr,118result /* pre_val */);119}120}121122return result;123}124125126