1 /* 2 * Copyright (c) 2015, Red Hat, Inc. and/or its affiliates. 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/brooksPointer.hpp" 25 #include "gc_implementation/shenandoah/shenandoahBarrierSet.inline.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, BrooksPointer::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 __ membar(Assembler::LoadLoad); 61 62 // Now check if evacuation is in progress. 63 interpreter_read_barrier_not_null(masm, dst); 64 65 __ tbz(rscratch1, ShenandoahHeap::EVACUATION_BITPOS, done); 66 67 __ lsr(rscratch1, dst, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 68 __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr()); 69 __ ldrb(rscratch2, Address(rscratch2, rscratch1)); 70 __ tst(rscratch2, 0x1); 71 __ br(Assembler::EQ, done); 72 73 // Save possibly live regs. 74 RegSet live_regs = RegSet::range(r0, r4) - dst; 75 __ push(live_regs, sp); 76 __ strd(v0, __ pre(sp, 2 * -wordSize)); 77 78 // Call into runtime 79 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahBarrierSet::write_barrier_IRT), dst); 80 81 // Move result into dst reg. 82 __ mov(dst, r0); 83 84 // Restore possibly live regs. 85 __ ldrd(v0, __ post(sp, 2 * wordSize)); 86 __ pop(live_regs, sp); 87 88 __ bind(done); 89 } 90 91 void ShenandoahHeap::compile_prepare_oop(MacroAssembler* masm, Register obj) { 92 __ add(obj, obj, BrooksPointer::byte_size()); 93 __ str(obj, Address(obj, -1 * HeapWordSize)); 94 } 95 96 void ShenandoahBarrierSet::asm_acmp_barrier(MacroAssembler* masm, 97 Register op1, Register op2) { 98 assert(UseShenandoahGC, "Should be enabled"); 99 if (ShenandoahAcmpBarrier) { 100 Label done; 101 __ br(Assembler::EQ, done); 102 // The object may have been evacuated, but we won't see it without a 103 // membar here. 104 __ membar(Assembler::LoadStore|Assembler::LoadLoad); 105 interpreter_read_barrier(masm, op1); 106 interpreter_read_barrier(masm, op2); 107 __ cmp(op1, op2); 108 __ bind(done); 109 } 110 } 111 112 #endif