< prev index next >

src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp

BarrierSetC1_v2

BarrierSetC1

6  * published by the Free Software Foundation.                                                                                        
7  *                                                                                                                                   
8  * This code is distributed in the hope that it will be useful, but WITHOUT                                                          
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or                                                             
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                             
11  * version 2 for more details (a copy is included in the LICENSE file that                                                           
12  * accompanied this code).                                                                                                           
13  *                                                                                                                                   
14  * You should have received a copy of the GNU General Public License version                                                         
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                            
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
25 #include "asm/macroAssembler.inline.hpp"                                                                                             
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
26 #include "gc/g1/g1BarrierSet.hpp"                                                                                                    
27 #include "gc/g1/g1BarrierSetAssembler.hpp"                                                                                           
28 #include "gc/g1/g1CardTable.hpp"                                                                                                     
29 #include "gc/g1/g1ThreadLocalData.hpp"                                                                                               
30 #include "gc/g1/heapRegion.hpp"                                                                                                      
31 #include "interpreter/interp_masm.hpp"                                                                                               
32 #include "runtime/sharedRuntime.hpp"                                                                                                 
33 
34 #define __ masm->                                                                                                                    
35 
36 void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators,                           
37                                                             Register addr, Register count, RegSet saved_regs) {                      
38   bool dest_uninitialized = (decorators & AS_DEST_NOT_INITIALIZED) != 0;                                                             
39   if (!dest_uninitialized) {                                                                                                         
40     __ push(saved_regs, sp);                                                                                                         
41     if (count == c_rarg0) {                                                                                                          
42       if (addr == c_rarg1) {                                                                                                         
43         // exactly backwards!!                                                                                                       
44         __ mov(rscratch1, c_rarg0);                                                                                                  

6  * published by the Free Software Foundation.
7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "asm/macroAssembler.inline.hpp"
26 #include "c1/c1_LIRAssembler.hpp"
27 #include "c1/c1_MacroAssembler.hpp"
28 #include "gc/g1/c1/g1BarrierSetC1.hpp"
29 #include "gc/g1/g1BarrierSet.hpp"
30 #include "gc/g1/g1BarrierSetAssembler.hpp"
31 #include "gc/g1/g1CardTable.hpp"
32 #include "gc/g1/g1ThreadLocalData.hpp"
33 #include "gc/g1/heapRegion.hpp"
34 #include "interpreter/interp_masm.hpp"
35 #include "runtime/sharedRuntime.hpp"
36 
37 #define __ masm->
38 
39 void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators,
40                                                             Register addr, Register count, RegSet saved_regs) {
41   bool dest_uninitialized = (decorators & AS_DEST_NOT_INITIALIZED) != 0;
42   if (!dest_uninitialized) {
43     __ push(saved_regs, sp);
44     if (count == c_rarg0) {
45       if (addr == c_rarg1) {
46         // exactly backwards!!
47         __ mov(rscratch1, c_rarg0);

286   if (val == noreg) {                                                                                                                
287     __ store_heap_oop_null(Address(r3, 0));                                                                                          
288   } else {                                                                                                                           
289     // G1 barrier needs uncompressed oop for region cross check.                                                                     
290     Register new_val = val;                                                                                                          
291     if (UseCompressedOops) {                                                                                                         
292       new_val = rscratch2;                                                                                                           
293       __ mov(new_val, val);                                                                                                          
294     }                                                                                                                                
295     __ store_heap_oop(Address(r3, 0), val);                                                                                          
296     g1_write_barrier_post(masm,                                                                                                      
297                           r3 /* store_adr */,                                                                                        
298                           new_val /* new_val */,                                                                                     
299                           rthread /* thread */,                                                                                      
300                           tmp1 /* tmp */,                                                                                            
301                           tmp2 /* tmp2 */);                                                                                          
302   }                                                                                                                                  
303 
304 }                                                                                                                                    
305 
                                                                                                                                     
                                                                                                                                     
306 #undef __                                                                                                                            
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     

289   if (val == noreg) {
290     __ store_heap_oop_null(Address(r3, 0));
291   } else {
292     // G1 barrier needs uncompressed oop for region cross check.
293     Register new_val = val;
294     if (UseCompressedOops) {
295       new_val = rscratch2;
296       __ mov(new_val, val);
297     }
298     __ store_heap_oop(Address(r3, 0), val);
299     g1_write_barrier_post(masm,
300                           r3 /* store_adr */,
301                           new_val /* new_val */,
302                           rthread /* thread */,
303                           tmp1 /* tmp */,
304                           tmp2 /* tmp2 */);
305   }
306 
307 }
308 
309 #ifdef COMPILER1
310 
311 #undef __
312 #define __ ce->masm()->
313 
314 void G1BarrierSetAssembler::gen_g1_pre_barrier_stub(LIR_Assembler* ce, G1PreBarrierStub* stub) {
315   G1BarrierSetC1* bs = (G1BarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
316   // At this point we know that marking is in progress.
317   // If do_load() is true then we have to emit the
318   // load of the previous value; otherwise it has already
319   // been loaded into _pre_val.
320 
321   __ bind(*stub->entry());
322 
323   assert(stub->pre_val()->is_register(), "Precondition.");
324 
325   Register pre_val_reg = stub->pre_val()->as_register();
326 
327   if (stub->do_load()) {
328     ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /*wide*/, false /*unaligned*/);
329   }
330   __ cbz(pre_val_reg, *stub->continuation());
331   ce->store_parameter(stub->pre_val()->as_register(), 0);
332   __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin()));
333   __ b(*stub->continuation());
334 }
335 
336 void G1BarrierSetAssembler::gen_g1_post_barrier_stub(LIR_Assembler* ce, G1PostBarrierStub* stub) {
337   G1BarrierSetC1* bs = (G1BarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
338   __ bind(*stub->entry());
339   assert(stub->addr()->is_register(), "Precondition.");
340   assert(stub->new_val()->is_register(), "Precondition.");
341   Register new_val_reg = stub->new_val()->as_register();
342   __ cbz(new_val_reg, *stub->continuation());
343   ce->store_parameter(stub->addr()->as_pointer_register(), 0);
344   __ far_call(RuntimeAddress(bs->post_barrier_c1_runtime_code_blob()->code_begin()));
345   __ b(*stub->continuation());
346 }
347 
348 #undef __
349 
350 #define __ sasm->
351 
352 void G1BarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) {
353   __ prologue("g1_pre_barrier", false);
354 
355   // arg0 : previous value of memory
356 
357   BarrierSet* bs = BarrierSet::barrier_set();
358 
359   const Register pre_val = r0;
360   const Register thread = rthread;
361   const Register tmp = rscratch1;
362 
363   Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()));
364   Address queue_index(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset()));
365   Address buffer(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset()));
366 
367   Label done;
368   Label runtime;
369 
370   // Is marking still active?
371   if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) {
372     __ ldrw(tmp, in_progress);
373   } else {
374     assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption");
375     __ ldrb(tmp, in_progress);
376   }
377   __ cbzw(tmp, done);
378 
379   // Can we store original value in the thread's buffer?
380   __ ldr(tmp, queue_index);
381   __ cbz(tmp, runtime);
382 
383   __ sub(tmp, tmp, wordSize);
384   __ str(tmp, queue_index);
385   __ ldr(rscratch2, buffer);
386   __ add(tmp, tmp, rscratch2);
387   __ load_parameter(0, rscratch2);
388   __ str(rscratch2, Address(tmp, 0));
389   __ b(done);
390 
391   __ bind(runtime);
392   __ push_call_clobbered_registers();
393   __ load_parameter(0, pre_val);
394   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), pre_val, thread);
395   __ pop_call_clobbered_registers();
396   __ bind(done);
397 
398   __ epilogue();
399 }
400 
401 void G1BarrierSetAssembler::generate_c1_post_barrier_runtime_stub(StubAssembler* sasm) {
402   __ prologue("g1_post_barrier", false);
403 
404   // arg0: store_address
405   Address store_addr(rfp, 2*BytesPerWord);
406 
407   BarrierSet* bs = BarrierSet::barrier_set();
408   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
409   CardTable* ct = ctbs->card_table();
410   assert(sizeof(*ct->byte_map_base()) == sizeof(jbyte), "adjust this code");
411 
412   Label done;
413   Label runtime;
414 
415   // At this point we know new_value is non-NULL and the new_value crosses regions.
416   // Must check to see if card is already dirty
417 
418   const Register thread = rthread;
419 
420   Address queue_index(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset()));
421   Address buffer(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset()));
422 
423   const Register card_offset = rscratch2;
424   // LR is free here, so we can use it to hold the byte_map_base.
425   const Register byte_map_base = lr;
426 
427   assert_different_registers(card_offset, byte_map_base, rscratch1);
428 
429   __ load_parameter(0, card_offset);
430   __ lsr(card_offset, card_offset, CardTable::card_shift);
431   __ load_byte_map_base(byte_map_base);
432   __ ldrb(rscratch1, Address(byte_map_base, card_offset));
433   __ cmpw(rscratch1, (int)G1CardTable::g1_young_card_val());
434   __ br(Assembler::EQ, done);
435 
436   assert((int)CardTable::dirty_card_val() == 0, "must be 0");
437 
438   __ membar(Assembler::StoreLoad);
439   __ ldrb(rscratch1, Address(byte_map_base, card_offset));
440   __ cbzw(rscratch1, done);
441 
442   // storing region crossing non-NULL, card is clean.
443   // dirty card and log.
444   __ strb(zr, Address(byte_map_base, card_offset));
445 
446   // Convert card offset into an address in card_addr
447   Register card_addr = card_offset;
448   __ add(card_addr, byte_map_base, card_addr);
449 
450   __ ldr(rscratch1, queue_index);
451   __ cbz(rscratch1, runtime);
452   __ sub(rscratch1, rscratch1, wordSize);
453   __ str(rscratch1, queue_index);
454 
455   // Reuse LR to hold buffer_addr
456   const Register buffer_addr = lr;
457 
458   __ ldr(buffer_addr, buffer);
459   __ str(card_addr, Address(buffer_addr, rscratch1));
460   __ b(done);
461 
462   __ bind(runtime);
463   __ push_call_clobbered_registers();
464   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread);
465   __ pop_call_clobbered_registers();
466   __ bind(done);
467   __ epilogue();
468 }
469 
470 #undef __
471 
472 #endif // COMPILER1
< prev index next >