1 /* 2 * Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved. 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 #include "gc_implementation/shenandoah/shenandoahBarrierSet.inline.hpp" 25 #include "gc_implementation/shenandoah/shenandoahBrooksPointer.hpp" 26 27 #include "asm/macroAssembler.hpp" 28 #include "interpreter/interpreter.hpp" 29 30 #define __ masm-> 31 32 #ifndef CC_INTERP 33 void ShenandoahBarrierSet::interpreter_read_barrier(MacroAssembler* masm, Register dst) { 34 if (ShenandoahReadBarrier) { 35 Label is_null; 36 __ cbz(dst, is_null); 37 interpreter_read_barrier_not_null(masm, dst); 38 __ bind(is_null); 39 } 40 } 41 42 void ShenandoahBarrierSet::interpreter_read_barrier_not_null(MacroAssembler* masm, Register dst) { 43 if (ShenandoahReadBarrier) { 44 __ ldr(dst, Address(dst, ShenandoahBrooksPointer::byte_offset())); 45 } 46 } 47 48 void ShenandoahBarrierSet::interpreter_write_barrier(MacroAssembler* masm, Register dst) { 49 if (! ShenandoahWriteBarrier) { 50 return interpreter_read_barrier(masm, dst); 51 } 52 53 assert(dst != rscratch1, "different regs"); 54 assert(dst != rscratch2, "Need rscratch2"); 55 56 Label done; 57 58 Address gc_state(rthread, in_bytes(JavaThread::gc_state_offset())); 59 __ ldrb(rscratch1, gc_state); 60 61 // Check for heap stability 62 __ mov(rscratch2, ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::EVACUATION); 63 __ tst(rscratch1, rscratch2); 64 __ br(Assembler::EQ, done); 65 66 // Heap is unstable, need to perform the read-barrier even if WB is inactive 67 __ ldr(dst, Address(dst, ShenandoahBrooksPointer::byte_offset())); 68 69 // Check for evacuation-in-progress and jump to WB slow-path if needed 70 __ mov(rscratch2, ShenandoahHeap::EVACUATION); 71 __ tst(rscratch1, rscratch2); 72 __ br(Assembler::EQ, done); 73 74 __ lsr(rscratch1, dst, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 75 __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr()); 76 __ ldrb(rscratch2, Address(rscratch2, rscratch1)); 77 __ tst(rscratch2, 0x1); 78 __ br(Assembler::EQ, done); 79 80 // Save possibly live regs. 81 RegSet live_regs = RegSet::range(r0, r4) - dst; 82 __ push(live_regs, sp); 83 __ strd(v0, __ pre(sp, 2 * -wordSize)); 84 85 // Call into runtime 86 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahBarrierSet::write_barrier_IRT), dst); 87 88 // Move result into dst reg. 89 __ mov(dst, r0); 90 91 // Restore possibly live regs. 92 __ ldrd(v0, __ post(sp, 2 * wordSize)); 93 __ pop(live_regs, sp); 94 95 __ bind(done); 96 } 97 98 void ShenandoahHeap::compile_prepare_oop(MacroAssembler* masm, Register obj) { 99 __ add(obj, obj, ShenandoahBrooksPointer::byte_size()); 100 __ str(obj, Address(obj, -1 * HeapWordSize)); 101 } 102 103 void ShenandoahBarrierSet::asm_acmp_barrier(MacroAssembler* masm, 104 Register op1, Register op2) { 105 assert(UseShenandoahGC, "Should be enabled"); 106 if (ShenandoahAcmpBarrier) { 107 Label done; 108 __ br(Assembler::EQ, done); 109 // The object may have been evacuated, but we won't see it without a 110 // membar here. 111 __ membar(Assembler::LoadStore|Assembler::LoadLoad); 112 interpreter_read_barrier(masm, op1); 113 interpreter_read_barrier(masm, op2); 114 __ cmp(op1, op2); 115 __ bind(done); 116 } 117 } 118 119 #endif