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 "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"
31
32 #define __ masm->
33
34 #ifdef PRODUCT
35 #define BLOCK_COMMENT(str) /* nothing */
36 #else
37 #define BLOCK_COMMENT(str) __ block_comment(str)
38 #endif
39
40 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
41
42 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
43
44 void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
45 Register addr, Register count, Register tmp) {
46 BarrierSet *bs = BarrierSet::barrier_set();
47 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
48 CardTable* ct = ctbs->card_table();
49 intptr_t disp = (intptr_t) ct->byte_map_base();
50
51 Label L_loop, L_done;
52 const Register end = count;
53 assert_different_registers(addr, end);
54
55 __ testl(count, count);
56 __ jcc(Assembler::zero, L_done); // zero count - nothing to do
57
58
59 #ifdef _LP64
60 __ leaq(end, Address(addr, count, TIMES_OOP, 0)); // end == addr+count*oop_size
61 __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
62 __ shrptr(addr, CardTable::card_shift());
63 __ shrptr(end, CardTable::card_shift());
64 __ subptr(end, addr); // end --> cards count
65
66 __ 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 #else
73 __ 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 --> count
77 __ BIND(L_loop);
78 Address cardtable(addr, count, Address::times_1, disp);
79 __ movb(cardtable, 0);
80 __ decrement(count);
81 __ jcc(Assembler::greaterEqual, L_loop);
82 #endif
83
84 __ BIND(L_done);
85 }
86
87 void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst) {
88 // Does a store check for the oop in register obj. The content of
89 // register obj is destroyed afterwards.
90 BarrierSet* bs = BarrierSet::barrier_set();
91
92 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
93 CardTable* ct = ctbs->card_table();
94
95 __ shrptr(obj, CardTable::card_shift());
96
97 Address card_addr;
98
99 // 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 will
102 // never need to be relocated. On 64bit however the value may be too
103 // large for a 32bit displacement.
104 intptr_t byte_map_base = (intptr_t)ct->byte_map_base();
105 if (__ is_simm32(byte_map_base)) {
106 card_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-relative
109 // displacement and done in a single instruction given favorable mapping and a
110 // smarter version of as_Address. However, 'ExternalAddress' generates a relocation
111 // entry and that entry is not properly handled by the relocation code.
112 AddressLiteral cardtable((address)byte_map_base, relocInfo::none);
113 Address index(noreg, obj, Address::times_1);
114 card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch1);
115 }
116
117 int dirty = CardTable::dirty_card_val();
118 if (UseCondCardMark) {
119 Label L_already_dirty;
120 __ cmpb(card_addr, dirty);
121 __ jccb(Assembler::equal, L_already_dirty);
122 __ movb(card_addr, dirty);
123 __ bind(L_already_dirty);
124 } else {
|
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 "asm/macroAssembler.inline.hpp"
26 #include "code/SCCache.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/gc_globals.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 = BarrierSet::barrier_set();
48 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
49 CardTable* ct = ctbs->card_table();
50 intptr_t byte_map_base = (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 if (SCCache::is_on_for_write()) {
68 // SCA needs relocation info for this address
69 __ lea(tmp, ExternalAddress((address)byte_map_base));
70 } else {
71 __ mov64(tmp, byte_map_base);
72 }
73 __ addptr(addr, tmp);
74 __ BIND(L_loop);
75 __ movb(Address(addr, count, Address::times_1), 0);
76 __ decrement(count);
77 __ jcc(Assembler::greaterEqual, L_loop);
78 #else
79 __ lea(end, Address(addr, count, Address::times_ptr, -wordSize));
80 __ shrptr(addr, CardTable::card_shift());
81 __ shrptr(end, CardTable::card_shift());
82 __ subptr(end, addr); // end --> count
83 __ BIND(L_loop);
84 Address cardtable(addr, count, Address::times_1, byte_map_base);
85 __ movb(cardtable, 0);
86 __ decrement(count);
87 __ jcc(Assembler::greaterEqual, L_loop);
88 #endif
89
90 __ BIND(L_done);
91 }
92
93 void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst) {
94 // Does a store check for the oop in register obj. The content of
95 // register obj is destroyed afterwards.
96 BarrierSet* bs = BarrierSet::barrier_set();
97
98 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
99 CardTable* ct = ctbs->card_table();
100
101 __ shrptr(obj, CardTable::card_shift());
102
103 Address card_addr;
104
105 // The calculation for byte_map_base is as follows:
106 // byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
107 // So this essentially converts an address to a displacement and it will
108 // never need to be relocated. On 64bit however the value may be too
109 // large for a 32bit displacement.
110 intptr_t byte_map_base = (intptr_t)ct->byte_map_base();
111 if (SCCache::is_on_for_write()) {
112 // SCA needs relocation info for this address
113 ExternalAddress cardtable((address)byte_map_base);
114 Address index(noreg, obj, Address::times_1);
115 card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch1);
116 } else
117 if (__ is_simm32(byte_map_base)) {
118 card_addr = Address(noreg, obj, Address::times_1, byte_map_base);
119 } else {
120 // By doing it as an ExternalAddress 'byte_map_base' could be converted to a rip-relative
121 // displacement and done in a single instruction given favorable mapping and a
122 // smarter version of as_Address. However, 'ExternalAddress' generates a relocation
123 // entry and that entry is not properly handled by the relocation code.
124 AddressLiteral cardtable((address)byte_map_base, relocInfo::none);
125 Address index(noreg, obj, Address::times_1);
126 card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch1);
127 }
128
129 int dirty = CardTable::dirty_card_val();
130 if (UseCondCardMark) {
131 Label L_already_dirty;
132 __ cmpb(card_addr, dirty);
133 __ jccb(Assembler::equal, L_already_dirty);
134 __ movb(card_addr, dirty);
135 __ bind(L_already_dirty);
136 } else {
|