1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018, SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "gc/g1/g1BarrierSet.hpp" 29 #include "gc/g1/g1CardTable.hpp" 30 #include "gc/g1/g1BSCodeGen.hpp" 31 #include "gc/g1/heapRegion.hpp" 32 #include "gc/shared/collectedHeap.hpp" 33 #include "runtime/thread.hpp" 34 #include "interpreter/interp_masm.hpp" 35 36 #define __ masm-> 37 38 void G1BSCodeGen::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators, Register from, Register to, Register count, 39 Register preserve1, Register preserve2) { 40 bool dest_uninitialized = (decorators & AS_DEST_NOT_INITIALIZED) != 0; 41 // With G1, don't generate the call if we statically know that the target in uninitialized 42 if (!dest_uninitialized) { 43 int spill_slots = 3; 44 if (preserve1 != noreg) { spill_slots++; } 45 if (preserve2 != noreg) { spill_slots++; } 46 const int frame_size = align_up(frame::abi_reg_args_size + spill_slots * BytesPerWord, frame::alignment_in_bytes); 47 Label filtered; 48 49 // Is marking active? 50 if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { 51 __ lwz(R0, in_bytes(JavaThread::satb_mark_queue_offset() + SATBMarkQueue::byte_offset_of_active()), R16_thread); 52 } else { 53 guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); 54 __ lbz(R0, in_bytes(JavaThread::satb_mark_queue_offset() + SATBMarkQueue::byte_offset_of_active()), R16_thread); 55 } 56 __ cmpdi(CCR0, R0, 0); 57 __ beq(CCR0, filtered); 58 59 __ save_LR_CR(R0); 60 __ push_frame(frame_size, R0); 61 int slot_nr = 0; 62 __ std(from, frame_size - (++slot_nr) * wordSize, R1_SP); 63 __ std(to, frame_size - (++slot_nr) * wordSize, R1_SP); 64 __ std(count, frame_size - (++slot_nr) * wordSize, R1_SP); 65 if (preserve1 != noreg) { __ std(preserve1, frame_size - (++slot_nr) * wordSize, R1_SP); } 66 if (preserve2 != noreg) { __ std(preserve2, frame_size - (++slot_nr) * wordSize, R1_SP); } 67 68 if (UseCompressedOops) { 69 __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_pre_narrow_oop_entry), to, count); 70 } else { 71 __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_pre_oop_entry), to, count); 72 } 73 74 slot_nr = 0; 75 __ ld(from, frame_size - (++slot_nr) * wordSize, R1_SP); 76 __ ld(to, frame_size - (++slot_nr) * wordSize, R1_SP); 77 __ ld(count, frame_size - (++slot_nr) * wordSize, R1_SP); 78 if (preserve1 != noreg) { __ ld(preserve1, frame_size - (++slot_nr) * wordSize, R1_SP); } 79 if (preserve2 != noreg) { __ ld(preserve2, frame_size - (++slot_nr) * wordSize, R1_SP); } 80 __ addi(R1_SP, R1_SP, frame_size); // pop_frame() 81 __ restore_LR_CR(R0); 82 83 __ bind(filtered); 84 } 85 } 86 87 void G1BSCodeGen::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators, Register addr, Register count, Register preserve) { 88 int spill_slots = (preserve != noreg) ? 1 : 0; 89 const int frame_size = align_up(frame::abi_reg_args_size + spill_slots * BytesPerWord, frame::alignment_in_bytes); 90 91 __ save_LR_CR(R0); 92 __ push_frame(frame_size, R0); 93 if (preserve != noreg) { __ std(preserve, frame_size - 1 * wordSize, R1_SP); } 94 __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_post_entry), addr, count); 95 if (preserve != noreg) { __ ld(preserve, frame_size - 1 * wordSize, R1_SP); } 96 __ addi(R1_SP, R1_SP, frame_size); // pop_frame(); 97 __ restore_LR_CR(R0); 98 }