Path: blob/master/src/hotspot/cpu/arm/gc/shared/cardTableBarrierSetAssembler_arm.cpp
40948 views
/*1* Copyright (c) 2018, 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/collectedHeap.hpp"31#include "runtime/globals.hpp"3233#define __ masm->3435#ifdef PRODUCT36#define BLOCK_COMMENT(str) /* nothing */37#else38#define BLOCK_COMMENT(str) __ block_comment(str)39#endif4041#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")4243void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,44Register addr, Register count, Register tmp) {45BLOCK_COMMENT("CardTablePostBarrier");46BarrierSet* bs = BarrierSet::barrier_set();47CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);48CardTable* ct = ctbs->card_table();4950Label L_cardtable_loop, L_done;5152__ cbz_32(count, L_done); // zero count - nothing to do5354__ add_ptr_scaled_int32(count, addr, count, LogBytesPerHeapOop);55__ sub(count, count, BytesPerHeapOop); // last addr5657__ logical_shift_right(addr, addr, CardTable::card_shift);58__ logical_shift_right(count, count, CardTable::card_shift);59__ sub(count, count, addr); // nb of cards6061// warning: Rthread has not been preserved62__ mov_address(tmp, (address) ct->byte_map_base());63__ add(addr,tmp, addr);6465Register zero = __ zero_register(tmp);6667__ BIND(L_cardtable_loop);68__ strb(zero, Address(addr, 1, post_indexed));69__ subs(count, count, 1);70__ b(L_cardtable_loop, ge);71__ BIND(L_done);72}7374void CardTableBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,75Address obj, Register new_val, Register tmp1, Register tmp2, Register tmp3, bool is_null) {76bool is_array = (decorators & IS_ARRAY) != 0;77bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;78bool precise = is_array || on_anonymous;7980if (is_null) {81BarrierSetAssembler::store_at(masm, decorators, type, obj, new_val, tmp1, tmp2, tmp3, true);82} else {83assert (!precise || (obj.index() == noreg && obj.disp() == 0),84"store check address should be calculated beforehand");8586store_check_part1(masm, tmp1);87BarrierSetAssembler::store_at(masm, decorators, type, obj, new_val, tmp1, tmp2, tmp3, false);88new_val = noreg;89store_check_part2(masm, obj.base(), tmp1, tmp2);90}91}9293// The 1st part of the store check.94// Sets card_table_base register.95void CardTableBarrierSetAssembler::store_check_part1(MacroAssembler* masm, Register card_table_base) {96// Check barrier set type (should be card table) and element size97BarrierSet* bs = BarrierSet::barrier_set();98assert(bs->kind() == BarrierSet::CardTableBarrierSet,99"Wrong barrier set kind");100101CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);102CardTable* ct = ctbs->card_table();103104// Load card table base address.105106/* Performance note.107108There is an alternative way of loading card table base address109from thread descriptor, which may look more efficient:110111ldr(card_table_base, Address(Rthread, JavaThread::card_table_base_offset()));112113However, performance measurements of micro benchmarks and specJVM98114showed that loading of card table base from thread descriptor is1157-18% slower compared to loading of literal embedded into the code.116Possible cause is a cache miss (card table base address resides in a117rarely accessed area of thread descriptor).118*/119__ mov_address(card_table_base, (address)ct->byte_map_base());120}121122// The 2nd part of the store check.123void CardTableBarrierSetAssembler::store_check_part2(MacroAssembler* masm, Register obj, Register card_table_base, Register tmp) {124assert_different_registers(obj, card_table_base, tmp);125126BarrierSet* bs = BarrierSet::barrier_set();127assert(bs->kind() == BarrierSet::CardTableBarrierSet,128"Wrong barrier set kind");129130assert(CardTable::dirty_card_val() == 0, "Dirty card value must be 0 due to optimizations.");131Address card_table_addr(card_table_base, obj, lsr, CardTable::card_shift);132133if (UseCondCardMark) {134Label already_dirty;135136__ ldrb(tmp, card_table_addr);137__ cbz(tmp, already_dirty);138139set_card(masm, card_table_base, card_table_addr, tmp);140__ bind(already_dirty);141142} else {143set_card(masm, card_table_base, card_table_addr, tmp);144}145}146147void CardTableBarrierSetAssembler::set_card(MacroAssembler* masm, Register card_table_base, Address card_table_addr, Register tmp) {148CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());149CardTable* ct = ctbs->card_table();150if ((((uintptr_t)ct->byte_map_base() & 0xff) == 0)) {151// Card table is aligned so the lowest byte of the table address base is zero.152// This works only if the code is not saved for later use, possibly153// in a context where the base would no longer be aligned.154__ strb(card_table_base, card_table_addr);155} else {156__ mov(tmp, 0);157__ strb(tmp, card_table_addr);158}159}160161162