< 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) {

 94 }
 95 
 96 void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
 97                                                                     Register addr, Register count, Register tmp) {
 98   CardTableBarrierSet* ctbs = CardTableBarrierSet::barrier_set();
 99 
100   Label L_loop, L_done;
101   const Register end = count;
102   assert_different_registers(addr, end);
103 
104   __ testl(count, count);
105   __ jcc(Assembler::zero, L_done); // zero count - nothing to do
106 
107 
108   __ leaq(end, Address(addr, count, TIMES_OOP, 0));  // end == addr+count*oop_size
109   __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
110   __ shrptr(addr, CardTable::card_shift());
111   __ shrptr(end, CardTable::card_shift());
112   __ subptr(end, addr); // end --> cards count
113 
114   __ mov64(tmp, (intptr_t)ctbs->card_table_base_const());







115   __ addptr(addr, tmp);
116 __ BIND(L_loop);
117   __ movb(Address(addr, count, Address::times_1), 0);
118   __ decrement(count);
119   __ jcc(Assembler::greaterEqual, L_loop);
120 
121 __ BIND(L_done);
122 }
123 
124 void CardTableBarrierSetAssembler::store_check(MacroAssembler* masm, Register obj, Address dst) {
125   // Does a store check for the oop in register obj. The content of
126   // register obj is destroyed afterwards.
127   CardTableBarrierSet* ctbs = CardTableBarrierSet::barrier_set();
128 
129   __ shrptr(obj, CardTable::card_shift());
130 
131   Address card_addr;

132 
133   // The calculation for byte_map_base is as follows:
134   // byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
135   // So this essentially converts an address to a displacement and it will
136   // never need to be relocated. On 64bit however the value may be too
137   // large for a 32bit displacement.
138   intptr_t byte_map_base = (intptr_t)ctbs->card_table_base_const();






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

  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) {

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