1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/cardTableModRefBSCodeGen.hpp" 27 28 #define __ masm-> 29 30 void CardTableModRefBSCodeGen::store_check(MacroAssembler* masm, Register obj, Address dst) { 31 // Does a store check for the oop in register obj. The content of 32 // register obj is destroyed afterwards. 33 34 BarrierSet* bs = Universe::heap()->barrier_set(); 35 assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind"); 36 37 CardTableModRefBS* ctbs = barrier_set_cast<CardTableModRefBS>(bs); 38 CardTable* ct = ctbs->card_table(); 39 assert(sizeof(*ct->byte_map_base()) == sizeof(jbyte), "adjust this code"); 40 41 __ lsr(obj, obj, CardTable::card_shift); 42 43 assert(CardTable::dirty_card_val() == 0, "must be"); 44 45 __ load_byte_map_base(rscratch1); 46 47 if (UseCondCardMark) { 48 Label L_already_dirty; 49 __ membar(Assembler::StoreLoad); 50 __ ldrb(rscratch2, Address(obj, rscratch1)); 51 __ cbz(rscratch2, L_already_dirty); 52 __ strb(zr, Address(obj, rscratch1)); 53 __ bind(L_already_dirty); 54 } else { 55 if (UseConcMarkSweepGC && CMSPrecleaningEnabled) { 56 __ membar(Assembler::StoreStore); 57 } 58 __ strb(zr, Address(obj, rscratch1)); 59 } 60 } 61 62 void CardTableModRefBSCodeGen::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators, 63 Register start, Register end, Register scratch, RegSet saved_regs) { 64 65 BarrierSet* bs = Universe::heap()->barrier_set(); 66 CardTableModRefBS* ctbs = barrier_set_cast<CardTableModRefBS>(bs); 67 CardTable* ct = ctbs->card_table(); 68 assert(sizeof(*ct->byte_map_base()) == sizeof(jbyte), "adjust this code"); 69 70 Label L_loop; 71 72 __ lsr(start, start, CardTable::card_shift); 73 __ lsr(end, end, CardTable::card_shift); 74 __ sub(end, end, start); // number of bytes to copy 75 76 const Register count = end; // 'end' register contains bytes count now 77 __ load_byte_map_base(scratch); 78 __ add(start, start, scratch); 79 if (UseConcMarkSweepGC) { 80 __ membar(__ StoreStore); 81 } 82 __ bind(L_loop); 83 __ strb(zr, Address(start, count)); 84 __ subs(count, count, 1); 85 __ br(Assembler::GE, L_loop); 86 } 87 88 void CardTableModRefBSCodeGen::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, 89 Address dst, Register val, Register tmp1, Register tmp2) { 90 91 bool on_array = (decorators & ACCESS_IN_HEAP_ARRAY) != 0; 92 bool on_anonymous = (decorators & ACCESS_ON_UNKNOWN_OOP_REF) != 0; 93 bool precise = on_array || on_anonymous; 94 if (val == noreg) { 95 __ store_heap_oop_null(dst); 96 } else { 97 __ store_heap_oop(dst, val); 98 // flatten object address if needed 99 if (!precise || (dst.index() == noreg && dst.offset() == 0)) { 100 store_check(masm, dst.base(), dst); 101 } else { 102 __ lea(r3, dst); 103 store_check(masm, r3, dst); 104 } 105 } 106 } 107