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/cardTableBarrierSet.hpp"
30 #include "gc/shared/cardTableBarrierSetAssembler.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 CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
46                                                                     Register addr, Register count, Register tmp) {
47   BarrierSet *bs = Universe::heap()->barrier_set();
48   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
49   CardTable* ct = ctbs->card_table();
50   assert(sizeof(*ct->byte_map_base()) == sizeof(jbyte), "adjust this code");
51   intptr_t disp = (intptr_t) ct->byte_map_base();
52 
53   Label L_loop, L_done;
54   const Register end = count;
55   assert_different_registers(addr, end);
56 
57   __ testl(count, count);
58   __ jcc(Assembler::zero, L_done); // zero count - nothing to do
59 
60 
61 #ifdef _LP64
62   __ leaq(end, Address(addr, count, TIMES_OOP, 0));  // end == addr+count*oop_size
63   __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
64   __ shrptr(addr, CardTable::card_shift);
65   __ shrptr(end, CardTable::card_shift);
66   __ subptr(end, addr); // end --> cards count
67 
68   __ mov64(tmp, disp);
69   __ addptr(addr, tmp);
70 __ BIND(L_loop);
71   __ movb(Address(addr, count, Address::times_1), 0);
72   __ decrement(count);
73   __ jcc(Assembler::greaterEqual, L_loop);
74 #else
75   __ lea(end,  Address(addr, count, Address::times_ptr, -wordSize));
76   __ shrptr(addr, CardTable::card_shift);
77   __ shrptr(end,   CardTable::card_shift);
78   __ subptr(end, addr); // end --> count
79 __ BIND(L_loop);
80   Address cardtable(addr, count, Address::times_1, disp);
81   __ movb(cardtable, 0);
82   __ decrement(count);
83   __ jcc(Assembler::greaterEqual, L_loop);
84 #endif
85 
86 __ BIND(L_done);
87 }