Path: blob/master/src/hotspot/cpu/x86/gc/shared/cardTableBarrierSetAssembler_x86.cpp
41155 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.inline.hpp"26#include "gc/shared/barrierSet.hpp"27#include "gc/shared/cardTable.hpp"28#include "gc/shared/cardTableBarrierSet.hpp"29#include "gc/shared/cardTableBarrierSetAssembler.hpp"30#include "gc/shared/gc_globals.hpp"3132#define __ masm->3334#ifdef PRODUCT35#define BLOCK_COMMENT(str) /* nothing */36#else37#define BLOCK_COMMENT(str) __ block_comment(str)38#endif3940#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")4142#define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)4344void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,45Register addr, Register count, Register tmp) {46BarrierSet *bs = BarrierSet::barrier_set();47CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);48CardTable* ct = ctbs->card_table();49intptr_t disp = (intptr_t) ct->byte_map_base();5051Label L_loop, L_done;52const Register end = count;53assert_different_registers(addr, end);5455__ testl(count, count);56__ jcc(Assembler::zero, L_done); // zero count - nothing to do575859#ifdef _LP6460__ leaq(end, Address(addr, count, TIMES_OOP, 0)); // end == addr+count*oop_size61__ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive62__ shrptr(addr, CardTable::card_shift);63__ shrptr(end, CardTable::card_shift);64__ subptr(end, addr); // end --> cards count6566__ mov64(tmp, disp);67__ addptr(addr, tmp);68__ BIND(L_loop);69__ movb(Address(addr, count, Address::times_1), 0);70__ decrement(count);71__ jcc(Assembler::greaterEqual, L_loop);72#else73__ lea(end, Address(addr, count, Address::times_ptr, -wordSize));74__ shrptr(addr, CardTable::card_shift);75__ shrptr(end, CardTable::card_shift);76__ subptr(end, addr); // end --> count77__ BIND(L_loop);78Address cardtable(addr, count, Address::times_1, disp);79__ movb(cardtable, 0);80__ decrement(count);81__ jcc(Assembler::greaterEqual, L_loop);82#endif8384__ BIND(L_done);85}8687void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst) {88// Does a store check for the oop in register obj. The content of89// register obj is destroyed afterwards.90BarrierSet* bs = BarrierSet::barrier_set();9192CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);93CardTable* ct = ctbs->card_table();9495__ shrptr(obj, CardTable::card_shift);9697Address card_addr;9899// The calculation for byte_map_base is as follows:100// byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);101// So this essentially converts an address to a displacement and it will102// never need to be relocated. On 64bit however the value may be too103// large for a 32bit displacement.104intptr_t byte_map_base = (intptr_t)ct->byte_map_base();105if (__ is_simm32(byte_map_base)) {106card_addr = Address(noreg, obj, Address::times_1, byte_map_base);107} else {108// By doing it as an ExternalAddress 'byte_map_base' could be converted to a rip-relative109// displacement and done in a single instruction given favorable mapping and a110// smarter version of as_Address. However, 'ExternalAddress' generates a relocation111// entry and that entry is not properly handled by the relocation code.112AddressLiteral cardtable((address)byte_map_base, relocInfo::none);113Address index(noreg, obj, Address::times_1);114card_addr = __ as_Address(ArrayAddress(cardtable, index));115}116117int dirty = CardTable::dirty_card_val();118if (UseCondCardMark) {119Label L_already_dirty;120__ cmpb(card_addr, dirty);121__ jcc(Assembler::equal, L_already_dirty);122__ movb(card_addr, dirty);123__ bind(L_already_dirty);124} else {125__ movb(card_addr, dirty);126}127}128129void CardTableBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,130Address dst, Register val, Register tmp1, Register tmp2) {131bool in_heap = (decorators & IN_HEAP) != 0;132133bool is_array = (decorators & IS_ARRAY) != 0;134bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;135bool precise = is_array || on_anonymous;136137bool needs_post_barrier = val != noreg && in_heap;138139BarrierSetAssembler::store_at(masm, decorators, type, dst, val, noreg, noreg);140if (needs_post_barrier) {141// flatten object address if needed142if (!precise || (dst.index() == noreg && dst.disp() == 0)) {143store_check(masm, dst.base(), dst);144} else {145__ lea(tmp1, dst);146store_check(masm, tmp1, dst);147}148}149}150151152