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/shenandoah/brooksPointer.hpp" 25 #include "gc/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 assert(dst != rscratch1, "different regs"); 51 assert(dst != rscratch2, "Need rscratch2"); 52 53 Label done; 54 55 Address gc_phase_in_progress = Address(rthread, in_bytes(JavaThread::gc_phase_in_progress_offset())); 56 57 __ ldrb(rscratch1, gc_phase_in_progress); 58 __ membar(Assembler::LoadLoad); 59 60 // Now check if evacuation is in progress. 61 interpreter_read_barrier_not_null(masm, dst); 62 63 __ tbz(rscratch1, ShenandoahHeap::EVACUATION_BITPOS, done); 64 65 __ lsr(rscratch1, dst, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 66 __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr()); 67 __ ldrb(rscratch2, Address(rscratch2, rscratch1)); 68 __ tst(rscratch2, 0x1); 69 __ br(Assembler::EQ, done); 70 71 // Save possibly live regs. 72 RegSet live_regs = RegSet::range(r0, r4) - dst; 73 __ push(live_regs, sp); 74 __ strd(v0, __ pre(sp, 2 * -wordSize)); 75 76 // Call into runtime 77 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahBarrierSet::write_barrier_IRT), dst); 78 79 // Move result into dst reg. 80 __ mov(dst, r0); 81 82 // Restore possibly live regs. 83 __ ldrd(v0, __ post(sp, 2 * wordSize)); 84 __ pop(live_regs, sp); 85 86 __ bind(done); 87 } 88 } 89 90 void ShenandoahHeap::compile_prepare_oop(MacroAssembler* masm, Register obj) { 91 __ add(obj, obj, BrooksPointer::byte_size()); 92 __ str(obj, Address(obj, BrooksPointer::byte_offset())); 93 } 94 95 void ShenandoahBarrierSet::interpreter_storeval_barrier(MacroAssembler* masm, Register dst) { 96 if (ShenandoahStoreValBarrier) { 97 interpreter_read_barrier(masm, dst); 98 } 99 } 100 101 void ShenandoahBarrierSet::asm_acmp_barrier(MacroAssembler* masm, 102 Register op1, Register op2) { 103 if (ShenandoahAcmpBarrier) { 104 Label done; 105 __ br(Assembler::EQ, done); 106 // The object may have been evacuated, but we won't see it without a 107 // membar here. 108 __ membar(Assembler::LoadStore| Assembler::LoadLoad); 109 interpreter_read_barrier(masm, op1); 110 interpreter_read_barrier(masm, op2); 111 __ cmp(op1, op2); 112 __ bind(done); 113 } 114 } 115 116 #endif