@@ -86,23 +86,31 @@ void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm
8686 }
8787}
8888
89- void G1BarrierSetAssembler::gen_write_ref_array_post_barrier (MacroAssembler* masm, DecoratorSet decorators,
90- Register start, Register count, Register scratch, RegSet saved_regs) {
89+ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier (MacroAssembler* masm,
90+ DecoratorSet decorators,
91+ Register start,
92+ Register count,
93+ Register scratch,
94+ RegSet saved_regs) {
9195
9296 Label done;
9397 Label loop;
9498 Label next;
95- const Register end = count;
9699
97100 __ cbz (count, done);
98101
99- __ lea (end, Address (start, count, Address::lsl (LogBytesPerHeapOop))); // end = start + count << LogBytesPerHeapOop
100- __ sub (end, end, BytesPerHeapOop); // last element address to make inclusive
102+ // Calculate the number of card marks to set. Since the object might start and
103+ // end within a card, we need to calculate this via the card table indexes of
104+ // the actual start and last addresses covered by the object.
105+ // Temporarily use the count register for the last element address.
106+ __ lea (count, Address (start, count, Address::lsl (LogBytesPerHeapOop))); // end = start + count << LogBytesPerHeapOop
107+ __ sub (count, count, BytesPerHeapOop); // Use last element address for end.
101108
102109 __ lsr (start, start, CardTable::card_shift ());
103- __ lsr (end, end , CardTable::card_shift ());
104- __ sub (count, end , start); // Number of bytes to mark - 1
110+ __ lsr (count, count , CardTable::card_shift ());
111+ __ sub (count, count , start); // Number of bytes to mark - 1.
105112
113+ // Add card table base offset to start.
106114 __ ldr (scratch, Address (rthread, in_bytes (G1ThreadLocalData::card_table_base_offset ())));
107115 __ add (start, start, scratch);
108116
0 commit comments