1 /*
 2  * Copyright (c) 2018, 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 "asm/macroAssembler.inline.hpp"
27 #include "gc/shared/barrierSet.hpp"
28 #include "gc/shared/cardTable.hpp"
29 #include "gc/shared/cardTableModRefBS.hpp"
30 #include "gc/shared/cardTableModRefBSCodeGen.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 
33 #define __ masm->
34 
35 #ifdef PRODUCT
36 #define BLOCK_COMMENT(str) /* nothing */
37 #else
38 #define BLOCK_COMMENT(str) __ block_comment(str)
39 #endif
40 
41 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
42 
43 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
44 
45 void CardTableModRefBSCodeGen::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators, Register addr, Register count, Register tmp) {
46   BarrierSet *bs = Universe::heap()->barrier_set();
47   CardTableModRefBS* ctbs = barrier_set_cast<CardTableModRefBS>(bs);
48   CardTable* ct = ctbs->card_table();
49   assert(sizeof(*ct->byte_map_base()) == sizeof(jbyte), "adjust this code");
50   intptr_t disp = (intptr_t) ct->byte_map_base();
51 
52   Label L_loop, L_done;
53   const Register end = count;
54   assert_different_registers(addr, end);
55 
56   __ testl(count, count);
57   __ jcc(Assembler::zero, L_done); // zero count - nothing to do
58 
59 
60 #ifdef _LP64
61   __ leaq(end, Address(addr, count, TIMES_OOP, 0));  // end == addr+count*oop_size
62   __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
63   __ shrptr(addr, CardTable::card_shift);
64   __ shrptr(end, CardTable::card_shift);
65   __ subptr(end, addr); // end --> cards count
66 
67   __ mov64(tmp, disp);
68   __ addptr(addr, tmp);
69 __ BIND(L_loop);
70   __ movb(Address(addr, count, Address::times_1), 0);
71   __ decrement(count);
72   __ jcc(Assembler::greaterEqual, L_loop);
73 #else
74   __ lea(end,  Address(addr, count, Address::times_ptr, -wordSize));
75   __ shrptr(addr, CardTable::card_shift);
76   __ shrptr(end,   CardTable::card_shift);
77   __ subptr(end, addr); // end --> count
78 __ BIND(L_loop);
79   Address cardtable(addr, count, Address::times_1, disp);
80   __ movb(cardtable, 0);
81   __ decrement(count);
82   __ jcc(Assembler::greaterEqual, L_loop);
83 #endif
84 
85 __ BIND(L_done);
86 }