/* * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates. * * 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 "gc/shenandoah/brooksPointer.hpp" #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp" #include "gc/shenandoah/shenandoahHeap.hpp" #include "gc/shenandoah/shenandoahHeapRegion.hpp" #include "gc/shenandoah/shenandoahHeuristics.hpp" #include "gc/shenandoah/shenandoahRuntime.hpp" #include "gc/shenandoah/shenandoahThreadLocalData.hpp" #include "interpreter/interpreter.hpp" #include "interpreter/interp_masm.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.hpp" #include "utilities/macros.hpp" #ifdef COMPILER1 #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp" #endif #define __ masm-> void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp_thread) { bool on_oop = type == T_OBJECT || type == T_ARRAY; bool in_heap = (decorators & IN_HEAP) != 0; bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0; bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0; bool on_reference = on_weak || on_phantom; if (in_heap) { read_barrier_not_null(masm, src.base()); } BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread); if (ShenandoahKeepAliveBarrier && on_oop && on_reference) { NOT_LP64(__ get_thread(thread)); // Generate the SATB pre-barrier code to log the value of // the referent field in an SATB buffer. shenandoah_write_barrier_pre(masm /* masm */, noreg /* obj */, dst /* pre_val */, tmp_thread /* thread */, tmp1 /* tmp */, true /* tosca_live */, true /* expand_call */); } } void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Address dst, Register val, Register tmp1, Register tmp2) { bool in_heap = (decorators & IN_HEAP) != 0; bool as_normal = (decorators & AS_NORMAL) != 0; if (in_heap) { write_barrier(masm, dst.base()); } if (type == T_OBJECT || type == T_ARRAY) { bool needs_pre_barrier = as_normal; Register tmp3 = LP64_ONLY(r8) NOT_LP64(rsi); Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx); // flatten object address if needed // We do it regardless of precise because we need the registers if (dst.index() == noreg && dst.disp() == 0) { if (dst.base() != tmp1) { __ movptr(tmp1, dst.base()); } } else { __ lea(tmp1, dst); } #ifndef _LP64 InterpreterMacroAssembler *imasm = static_cast(masm); #endif NOT_LP64(__ get_thread(rcx)); NOT_LP64(imasm->save_bcp()); if (needs_pre_barrier) { shenandoah_write_barrier_pre(masm /*masm*/, tmp1 /* obj */, tmp2 /* pre_val */, rthread /* thread */, tmp3 /* tmp */, val != noreg /* tosca_live */, false /* expand_call */); } if (val == noreg) { BarrierSetAssembler::store_at(masm, decorators, type, Address(tmp1, 0), val, noreg, noreg); } else { storeval_barrier(masm, val, tmp3); BarrierSetAssembler::store_at(masm, decorators, type, Address(tmp1, 0), val, noreg, noreg); } NOT_LP64(imasm->restore_bcp()); } else { BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2); } } #ifndef _LP64 void ShenandoahBarrierSetAssembler::obj_equals(MacroAssembler* masm, Address obj1, jobject obj2) { Unimplemented(); } void ShenandoahBarrierSetAssembler::obj_equals(MacroAssembler* masm, Register obj1, jobject obj2) { Unimplemented(); } #endif void ShenandoahBarrierSetAssembler::obj_equals(MacroAssembler* masm, Register op1, Register op2) { __ cmpptr(op1, op2); if (ShenandoahAcmpBarrier) { Label done; __ jccb(Assembler::equal, done); read_barrier(masm, op1); read_barrier(masm, op2); __ cmpptr(op1, op2); __ bind(done); } } void ShenandoahBarrierSetAssembler::obj_equals(MacroAssembler* masm, Register src1, Address src2) { __ cmpptr(src1, src2); if (ShenandoahAcmpBarrier) { Label done; __ jccb(Assembler::equal, done); __ movptr(rscratch2, src2); read_barrier(masm, src1); read_barrier(masm, rscratch2); __ cmpptr(src1, rscratch2); __ bind(done); } } void ShenandoahBarrierSetAssembler::resolve(MacroAssembler* masm, DecoratorSet decorators, Register obj) { bool oop_not_null = (decorators & IS_NOT_NULL) != 0; bool is_write = (decorators & ACCESS_WRITE) != 0; if (is_write) { if (oop_not_null) { write_barrier(masm, obj); } else { Label done; __ testptr(obj, obj); __ jcc(Assembler::zero, done); write_barrier(masm, obj); __ bind(done); } } else { if (oop_not_null) { read_barrier_not_null(masm, obj); } else { read_barrier(masm, obj); } } } void ShenandoahBarrierSetAssembler::xchg_oop(MacroAssembler* masm, DecoratorSet decorators, Register obj, Address addr, Register tmp) { storeval_barrier(masm, obj, tmp); BarrierSetAssembler::xchg_oop(masm, decorators, obj, addr, tmp); }