--- /dev/null 2017-03-07 11:44:12.271151064 +0100 +++ new/src/share/vm/gc/shared/c1CardTableModRefBSCodeGen.cpp 2017-04-25 16:46:25.243171353 +0200 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "gc/shared/c1CardTableModRefBSCodeGen.hpp" +#include "utilities/macros.hpp" + +#ifdef ASSERT +#define __ lir_generator->lir(__FILE__, __LINE__)-> +#else +#define __ lir_generator->lir()-> +#endif + +void C1CardTableModRefBSCodeGen::post_barrier(LIRGenerator *lir_generator, C1DecoratorSet decorators, + LIR_OprDesc* addr, LIR_OprDesc* new_val) { + BarrierSet *bs = Universe::heap()->barrier_set(); + CardTableModRefBS* ct = barrier_set_cast(bs); + assert(sizeof(*(ct->card_table()->byte_map_base())) == sizeof(jbyte), "adjust this code"); + LIR_Const* card_table_base = new LIR_Const(ct->card_table()->byte_map_base()); + if (addr->is_address()) { + LIR_Address* address = addr->as_address_ptr(); + // ptr cannot be an object because we use this barrier for array card marks + // and addr can point in the middle of an array. + LIR_Opr ptr = lir_generator->new_pointer_register(); + if (!address->index()->is_valid() && address->disp() == 0) { + __ move(address->base(), ptr); + } else { + assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); + __ leal(addr, ptr); + } + addr = ptr; + } + assert(addr->is_register(), "must be a register at this point"); + +#ifdef CARDTABLEMODREF_POST_BARRIER_HELPER + CardTableModRef_post_barrier_helper(addr, card_table_base); +#else + LIR_Opr tmp = lir_generator->new_pointer_register(); + if (TwoOperandLIRForm) { + __ move(addr, tmp); + __ unsigned_shift_right(tmp, CardTable::card_shift, tmp); + } else { + __ unsigned_shift_right(addr, CardTable::card_shift, tmp); + } + + LIR_Address* card_addr; + if (lir_generator->can_inline_as_constant(card_table_base)) { + card_addr = new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE); + } else { + card_addr = new LIR_Address(tmp, lir_generator->load_constant(card_table_base), T_BYTE); + } + + LIR_Opr dirty = LIR_OprFact::intConst(CardTable::dirty_card_val()); + if (UseCondCardMark) { + LIR_Opr cur_value = lir_generator->new_register(T_INT); + if (UseConcMarkSweepGC) { + __ membar_storeload(); + } + __ move(card_addr, cur_value); + + LabelObj* L_already_dirty = new LabelObj(); + __ cmp(lir_cond_equal, cur_value, dirty); + __ branch(lir_cond_equal, T_BYTE, L_already_dirty->label()); + __ move(dirty, card_addr); + __ branch_destination(L_already_dirty->label()); + } else { + if (UseConcMarkSweepGC && CMSPrecleaningEnabled) { + __ membar_storestore(); + } + __ move(dirty, card_addr); + } +#endif +}