< prev index next >

src/hotspot/cpu/x86/gc/shared/cardTableBarrierSetAssembler_x86.cpp

Print this page

  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::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 45                                                       Register src, Register dst, Register count) {

 81       tmp = rscratch1;
 82     }
 83     gen_write_ref_array_post_barrier(masm, decorators, dst, count, tmp);
 84   }
 85 }
 86 
 87 void CardTableBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 88                                             Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
 89   if (is_reference_type(type)) {
 90     oop_store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
 91   } else {
 92     BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
 93   }
 94 }
 95 
 96 void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
 97                                                                     Register addr, Register count, Register tmp) {
 98   BarrierSet *bs = BarrierSet::barrier_set();
 99   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
100   CardTable* ct = ctbs->card_table();
101   intptr_t disp = (intptr_t) ct->byte_map_base();
102   SHENANDOAHGC_ONLY(assert(!UseShenandoahGC, "Shenandoah byte_map_base is not constant.");)
103 
104   Label L_loop, L_done;
105   const Register end = count;
106   assert_different_registers(addr, end);
107 
108   __ testl(count, count);
109   __ jcc(Assembler::zero, L_done); // zero count - nothing to do
110 
111 
112   __ leaq(end, Address(addr, count, TIMES_OOP, 0));  // end == addr+count*oop_size
113   __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
114   __ shrptr(addr, CardTable::card_shift());
115   __ shrptr(end, CardTable::card_shift());
116   __ subptr(end, addr); // end --> cards count
117 
118   __ mov64(tmp, disp);







119   __ addptr(addr, tmp);
120 __ BIND(L_loop);
121   __ movb(Address(addr, count, Address::times_1), 0);
122   __ decrement(count);
123   __ jcc(Assembler::greaterEqual, L_loop);
124 
125 __ BIND(L_done);
126 }
127 
128 void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst) {
129   // Does a store check for the oop in register obj. The content of
130   // register obj is destroyed afterwards.
131   BarrierSet* bs = BarrierSet::barrier_set();
132 
133   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
134   CardTable* ct = ctbs->card_table();
135 
136   __ shrptr(obj, CardTable::card_shift());
137 
138   Address card_addr;

139 
140   // The calculation for byte_map_base is as follows:
141   // byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
142   // So this essentially converts an address to a displacement and it will
143   // never need to be relocated. On 64bit however the value may be too
144   // large for a 32bit displacement.
145   intptr_t byte_map_base = (intptr_t)ct->byte_map_base();






146   if (__ is_simm32(byte_map_base)) {
147     card_addr = Address(noreg, obj, Address::times_1, byte_map_base);
148   } else {
149     // By doing it as an ExternalAddress 'byte_map_base' could be converted to a rip-relative
150     // displacement and done in a single instruction given favorable mapping and a
151     // smarter version of as_Address. However, 'ExternalAddress' generates a relocation
152     // entry and that entry is not properly handled by the relocation code.
153     AddressLiteral cardtable((address)byte_map_base, relocInfo::none);
154     Address index(noreg, obj, Address::times_1);
155     card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch1);
156   }
157 
158   int dirty = CardTable::dirty_card_val();
159   if (UseCondCardMark) {
160     Label L_already_dirty;
161     __ cmpb(card_addr, dirty);
162     __ jccb(Assembler::equal, L_already_dirty);
163     __ movb(card_addr, dirty);
164     __ bind(L_already_dirty);
165   } else {
166     __ movb(card_addr, dirty);
167   }
168 }
169 
170 void CardTableBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
171                                                 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
172   bool in_heap = (decorators & IN_HEAP) != 0;
173 
174   bool is_array = (decorators & IS_ARRAY) != 0;
175   bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
176   bool precise = is_array || on_anonymous;
177 
178   bool needs_post_barrier = val != noreg && in_heap;
179 
180   BarrierSetAssembler::store_at(masm, decorators, type, dst, val, noreg, noreg, noreg);
181   if (needs_post_barrier) {
182     // flatten object address if needed
183     if (!precise || (dst.index() == noreg && dst.disp() == 0)) {
184       store_check(masm, dst.base(), dst);
185     } else {
186       __ lea(tmp1, dst);
187       store_check(masm, tmp1, dst);
188     }
189   }
190 }

  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/aotCodeCache.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::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 46                                                       Register src, Register dst, Register count) {

 82       tmp = rscratch1;
 83     }
 84     gen_write_ref_array_post_barrier(masm, decorators, dst, count, tmp);
 85   }
 86 }
 87 
 88 void CardTableBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 89                                             Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
 90   if (is_reference_type(type)) {
 91     oop_store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
 92   } else {
 93     BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
 94   }
 95 }
 96 
 97 void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
 98                                                                     Register addr, Register count, Register tmp) {
 99   BarrierSet *bs = BarrierSet::barrier_set();
100   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
101   CardTable* ct = ctbs->card_table();
102   intptr_t byte_map_base = (intptr_t) ct->byte_map_base();
103   SHENANDOAHGC_ONLY(assert(!UseShenandoahGC, "Shenandoah byte_map_base is not constant.");)
104 
105   Label L_loop, L_done;
106   const Register end = count;
107   assert_different_registers(addr, end);
108 
109   __ testl(count, count);
110   __ jcc(Assembler::zero, L_done); // zero count - nothing to do
111 
112 
113   __ leaq(end, Address(addr, count, TIMES_OOP, 0));  // end == addr+count*oop_size
114   __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
115   __ shrptr(addr, CardTable::card_shift());
116   __ shrptr(end, CardTable::card_shift());
117   __ subptr(end, addr); // end --> cards count
118 
119 #if INCLUDE_CDS
120   if (AOTCodeCache::is_on_for_dump()) {
121     __ movptr(tmp, ExternalAddress(AOTRuntimeConstants::card_table_address()));
122   } else
123 #endif
124   {
125     __ mov64(tmp, byte_map_base);
126   }
127   __ addptr(addr, tmp);
128 __ BIND(L_loop);
129   __ movb(Address(addr, count, Address::times_1), 0);
130   __ decrement(count);
131   __ jcc(Assembler::greaterEqual, L_loop);
132 
133 __ BIND(L_done);
134 }
135 
136 void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst, Register rscratch) {
137   // Does a store check for the oop in register obj. The content of
138   // register obj is destroyed afterwards.
139   BarrierSet* bs = BarrierSet::barrier_set();
140 
141   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
142   CardTable* ct = ctbs->card_table();
143 
144   __ shrptr(obj, CardTable::card_shift());
145 
146   Address card_addr;
147   precond(rscratch != noreg);
148 
149   // The calculation for byte_map_base is as follows:
150   // byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
151   // So this essentially converts an address to a displacement and it will
152   // never need to be relocated. On 64bit however the value may be too
153   // large for a 32bit displacement.
154   intptr_t byte_map_base = (intptr_t)ct->byte_map_base();
155 #if INCLUDE_CDS
156   if (AOTCodeCache::is_on_for_dump()) {
157     __ movptr(rscratch, ExternalAddress(AOTRuntimeConstants::card_table_address()));
158     card_addr = Address(rscratch, obj, Address::times_1, 0);
159   } else
160 #endif
161   if (__ is_simm32(byte_map_base)) {
162     card_addr = Address(noreg, obj, Address::times_1, byte_map_base);
163   } else {
164     // By doing it as an ExternalAddress 'byte_map_base' could be converted to a rip-relative
165     // displacement and done in a single instruction given favorable mapping and a
166     // smarter version of as_Address. However, 'ExternalAddress' generates a relocation
167     // entry and that entry is not properly handled by the relocation code.
168     AddressLiteral cardtable((address)byte_map_base, relocInfo::none);
169     Address index(noreg, obj, Address::times_1);
170     card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch);
171   }
172 
173   int dirty = CardTable::dirty_card_val();
174   if (UseCondCardMark) {
175     Label L_already_dirty;
176     __ cmpb(card_addr, dirty);
177     __ jccb(Assembler::equal, L_already_dirty);
178     __ movb(card_addr, dirty);
179     __ bind(L_already_dirty);
180   } else {
181     __ movb(card_addr, dirty);
182   }
183 }
184 
185 void CardTableBarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
186                                                 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
187   bool in_heap = (decorators & IN_HEAP) != 0;
188 
189   bool is_array = (decorators & IS_ARRAY) != 0;
190   bool on_anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
191   bool precise = is_array || on_anonymous;
192 
193   bool needs_post_barrier = val != noreg && in_heap;
194 
195   BarrierSetAssembler::store_at(masm, decorators, type, dst, val, noreg, noreg, noreg);
196   if (needs_post_barrier) {
197     // flatten object address if needed
198     if (!precise || (dst.index() == noreg && dst.disp() == 0)) {
199       store_check(masm, dst.base(), dst, tmp2);
200     } else {
201       __ lea(tmp1, dst);
202       store_check(masm, tmp1, dst, tmp2);
203     }
204   }
205 }
< prev index next >