1 /* 2 * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 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 "gc/shenandoah/brooksPointer.hpp" 26 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp" 27 #include "gc/shenandoah/shenandoahConnectionMatrix.hpp" 28 #include "gc/shenandoah/shenandoahHeap.hpp" 29 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 30 #include "gc/shenandoah/shenandoahHeuristics.hpp" 31 #include "gc/shenandoah/shenandoahRuntime.hpp" 32 #include "gc/shenandoah/shenandoahThreadLocalData.hpp" 33 #include "interpreter/interpreter.hpp" 34 #include "interpreter/interp_masm.hpp" 35 #include "runtime/sharedRuntime.hpp" 36 #include "runtime/thread.hpp" 37 #ifdef COMPILER1 38 #include "c1/c1_LIRAssembler.hpp" 39 #include "c1/c1_MacroAssembler.hpp" 40 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp" 41 #endif 42 43 #define __ masm-> 44 45 address ShenandoahBarrierSetAssembler::_shenandoah_wb = NULL; 46 address ShenandoahBarrierSetAssembler::_shenandoah_wb_C = NULL; 47 48 void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop, 49 Register addr, Register count, RegSet saved_regs) { 50 if (is_oop) { 51 bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0; 52 if (!dest_uninitialized && !ShenandoahHeap::heap()->heuristics()->can_do_traversal_gc()) { 53 __ push(saved_regs, sp); 54 if (count == c_rarg0) { 55 if (addr == c_rarg1) { 56 // exactly backwards!! 57 __ mov(rscratch1, c_rarg0); 58 __ mov(c_rarg0, c_rarg1); 59 __ mov(c_rarg1, rscratch1); 60 } else { 61 __ mov(c_rarg1, count); 62 __ mov(c_rarg0, addr); 63 } 64 } else { 65 __ mov(c_rarg0, addr); 66 __ mov(c_rarg1, count); 67 } 68 if (UseCompressedOops) { 69 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_narrow_oop_entry), 2); 70 } else { 71 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_oop_entry), 2); 72 } 73 __ pop(saved_regs, sp); 74 } 75 } 76 } 77 78 void ShenandoahBarrierSetAssembler::arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop, 79 Register start, Register end, Register scratch, RegSet saved_regs) { 80 if (is_oop) { 81 __ push(saved_regs, sp); 82 // must compute element count unless barrier set interface is changed (other platforms supply count) 83 assert_different_registers(start, end, scratch); 84 __ lea(scratch, Address(end, BytesPerHeapOop)); 85 __ sub(scratch, scratch, start); // subtract start to get #bytes 86 __ lsr(scratch, scratch, LogBytesPerHeapOop); // convert to element count 87 __ mov(c_rarg0, start); 88 __ mov(c_rarg1, scratch); 89 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_post_entry), 2); 90 __ pop(saved_regs, sp); 91 } 92 } 93 94 void ShenandoahBarrierSetAssembler::shenandoah_write_barrier_pre(MacroAssembler* masm, 95 Register obj, 96 Register pre_val, 97 Register thread, 98 Register tmp, 99 bool tosca_live, 100 bool expand_call) { 101 if (ShenandoahSATBBarrier) { 102 satb_write_barrier_pre(masm, obj, pre_val, thread, tmp, tosca_live, expand_call); 103 } 104 } 105 106 void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm, 107 Register obj, 108 Register pre_val, 109 Register thread, 110 Register tmp, 111 bool tosca_live, 112 bool expand_call) { 113 // If expand_call is true then we expand the call_VM_leaf macro 114 // directly to skip generating the check by 115 // InterpreterMacroAssembler::call_VM_leaf_base that checks _last_sp. 116 117 assert(thread == rthread, "must be"); 118 119 Label done; 120 Label runtime; 121 122 assert_different_registers(obj, pre_val, tmp, rscratch1); 123 assert(pre_val != noreg && tmp != noreg, "expecting a register"); 124 125 Address in_progress(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset())); 126 Address index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset())); 127 Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset())); 128 129 // Is marking active? 130 if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { 131 __ ldrw(tmp, in_progress); 132 } else { 133 assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); 134 __ ldrb(tmp, in_progress); 135 } 136 __ cbzw(tmp, done); 137 138 // Do we need to load the previous value? 139 if (obj != noreg) { 140 __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); 141 } 142 143 // Is the previous value null? 144 __ cbz(pre_val, done); 145 146 // Can we store original value in the thread's buffer? 147 // Is index == 0? 148 // (The index field is typed as size_t.) 149 150 __ ldr(tmp, index); // tmp := *index_adr 151 __ cbz(tmp, runtime); // tmp == 0? 152 // If yes, goto runtime 153 154 __ sub(tmp, tmp, wordSize); // tmp := tmp - wordSize 155 __ str(tmp, index); // *index_adr := tmp 156 __ ldr(rscratch1, buffer); 157 __ add(tmp, tmp, rscratch1); // tmp := tmp + *buffer_adr 158 159 // Record the previous value 160 __ str(pre_val, Address(tmp, 0)); 161 __ b(done); 162 163 __ bind(runtime); 164 // save the live input values 165 RegSet saved = RegSet::of(pre_val); 166 if (tosca_live) saved += RegSet::of(r0); 167 if (obj != noreg) saved += RegSet::of(obj); 168 169 __ push(saved, sp); 170 171 // Calling the runtime using the regular call_VM_leaf mechanism generates 172 // code (generated by InterpreterMacroAssember::call_VM_leaf_base) 173 // that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL. 174 // 175 // If we care generating the pre-barrier without a frame (e.g. in the 176 // intrinsified Reference.get() routine) then ebp might be pointing to 177 // the caller frame and so this check will most likely fail at runtime. 178 // 179 // Expanding the call directly bypasses the generation of the check. 180 // So when we do not have have a full interpreter frame on the stack 181 // expand_call should be passed true. 182 183 if (expand_call) { 184 assert(pre_val != c_rarg1, "smashed arg"); 185 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); 186 } else { 187 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); 188 } 189 190 __ pop(saved, sp); 191 192 __ bind(done); 193 } 194 195 void ShenandoahBarrierSetAssembler::shenandoah_write_barrier_post(MacroAssembler* masm, 196 Register store_addr, 197 Register new_val, 198 Register thread, 199 Register tmp, 200 Register tmp2) { 201 assert(thread == rthread, "must be"); 202 assert(UseShenandoahGC, "expect Shenandoah GC"); 203 204 if (! UseShenandoahMatrix) { 205 // No need for that barrier if not using matrix. 206 return; 207 } 208 209 assert_different_registers(store_addr, new_val, thread, tmp, tmp2, rscratch1); 210 211 Label done; 212 __ cbz(new_val, done); 213 214 ShenandoahConnectionMatrix* matrix = ShenandoahHeap::heap()->connection_matrix(); 215 216 // Compute to-region index 217 __ lsr(tmp, new_val, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 218 219 // Compute from-region index 220 __ lsr(tmp2, store_addr, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 221 222 // Compute matrix index 223 __ mov(rscratch1, matrix->stride_jint()); 224 // Address is _matrix[to * stride + from] 225 __ madd(tmp, tmp, rscratch1, tmp2); 226 __ mov(rscratch1, matrix->magic_offset()); 227 Address loc(tmp, rscratch1); 228 229 __ ldrb(tmp2, loc); 230 __ cbnz(tmp2, done); 231 __ mov(tmp2, 1); 232 __ strb(tmp2, loc); 233 __ bind(done); 234 } 235 236 void ShenandoahBarrierSetAssembler::read_barrier(MacroAssembler* masm, Register dst) { 237 if (ShenandoahReadBarrier) { 238 read_barrier_impl(masm, dst); 239 } 240 } 241 242 void ShenandoahBarrierSetAssembler::read_barrier_impl(MacroAssembler* masm, Register dst) { 243 assert(UseShenandoahGC && (ShenandoahReadBarrier || ShenandoahStoreValReadBarrier), "should be enabled"); 244 Label is_null; 245 __ cbz(dst, is_null); 246 read_barrier_not_null_impl(masm, dst); 247 __ bind(is_null); 248 } 249 250 void ShenandoahBarrierSetAssembler::read_barrier_not_null(MacroAssembler* masm, Register dst) { 251 if (ShenandoahReadBarrier) { 252 read_barrier_not_null_impl(masm, dst); 253 } 254 } 255 256 257 void ShenandoahBarrierSetAssembler::read_barrier_not_null_impl(MacroAssembler* masm, Register dst) { 258 assert(UseShenandoahGC && (ShenandoahReadBarrier || ShenandoahStoreValReadBarrier), "should be enabled"); 259 __ ldr(dst, Address(dst, BrooksPointer::byte_offset())); 260 } 261 262 void ShenandoahBarrierSetAssembler::write_barrier(MacroAssembler* masm, Register dst) { 263 if (ShenandoahWriteBarrier) { 264 write_barrier_impl(masm, dst); 265 } 266 } 267 268 void ShenandoahBarrierSetAssembler::write_barrier_impl(MacroAssembler* masm, Register dst) { 269 assert(UseShenandoahGC && (ShenandoahWriteBarrier || ShenandoahStoreValEnqueueBarrier), "Should be enabled"); 270 assert(dst != rscratch1, "need rscratch1"); 271 assert(dst != rscratch2, "need rscratch2"); 272 273 Label done; 274 275 Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset())); 276 __ ldrb(rscratch1, gc_state); 277 278 // Check for heap stability 279 __ mov(rscratch2, ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL); 280 __ tst(rscratch1, rscratch2); 281 __ br(Assembler::EQ, done); 282 283 // Heap is unstable, need to perform the read-barrier even if WB is inactive 284 if (ShenandoahWriteBarrierRB) { 285 __ ldr(dst, Address(dst, BrooksPointer::byte_offset())); 286 } 287 288 // Check for evacuation-in-progress and jump to WB slow-path if needed 289 __ mov(rscratch2, ShenandoahHeap::EVACUATION | ShenandoahHeap::TRAVERSAL); 290 __ tst(rscratch1, rscratch2); 291 __ br(Assembler::EQ, done); 292 293 RegSet to_save = RegSet::of(r0); 294 if (dst != r0) { 295 __ push(to_save, sp); 296 __ mov(r0, dst); 297 } 298 299 __ far_call(RuntimeAddress(CAST_FROM_FN_PTR(address, ShenandoahBarrierSetAssembler::shenandoah_wb()))); 300 301 if (dst != r0) { 302 __ mov(dst, r0); 303 __ pop(to_save, sp); 304 } 305 306 __ bind(done); 307 } 308 309 void ShenandoahBarrierSetAssembler::storeval_barrier(MacroAssembler* masm, Register dst, Register tmp) { 310 if (ShenandoahStoreValEnqueueBarrier) { 311 Label is_null; 312 __ cbz(dst, is_null); 313 write_barrier_impl(masm, dst); 314 __ bind(is_null); 315 // Save possibly live regs. 316 RegSet live_regs = RegSet::range(r0, r4) - dst; 317 __ push(live_regs, sp); 318 __ strd(v0, __ pre(sp, 2 * -wordSize)); 319 320 satb_write_barrier_pre(masm, noreg, dst, rthread, tmp, true, false); 321 322 // Restore possibly live regs. 323 __ ldrd(v0, __ post(sp, 2 * wordSize)); 324 __ pop(live_regs, sp); 325 } 326 if (ShenandoahStoreValReadBarrier) { 327 read_barrier_impl(masm, dst); 328 } 329 } 330 331 void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, 332 Register dst, Address src, Register tmp1, Register tmp_thread) { 333 bool on_oop = type == T_OBJECT || type == T_ARRAY; 334 bool in_heap = (decorators & IN_HEAP) != 0; 335 bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0; 336 bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0; 337 bool on_reference = on_weak || on_phantom; 338 339 if (in_heap) { 340 read_barrier_not_null(masm, src.base()); 341 } 342 343 BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread); 344 if (ShenandoahKeepAliveBarrier && on_oop && on_reference) { 345 __ enter(); 346 satb_write_barrier_pre(masm /* masm */, 347 noreg /* obj */, 348 dst /* pre_val */, 349 rthread /* thread */, 350 tmp1 /* tmp */, 351 true /* tosca_live */, 352 true /* expand_call */); 353 __ leave(); 354 } 355 } 356 357 void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, 358 Address dst, Register val, Register tmp1, Register tmp2) { 359 bool on_oop = type == T_OBJECT || type == T_ARRAY; 360 bool in_heap = (decorators & IN_HEAP) != 0; 361 if (in_heap) { 362 write_barrier(masm, dst.base()); 363 } 364 if (!on_oop) { 365 BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2); 366 return; 367 } 368 369 // flatten object address if needed 370 if (dst.index() == noreg && dst.offset() == 0) { 371 if (dst.base() != r3) { 372 __ mov(r3, dst.base()); 373 } 374 } else { 375 __ lea(r3, dst); 376 } 377 378 shenandoah_write_barrier_pre(masm, 379 r3 /* obj */, 380 tmp2 /* pre_val */, 381 rthread /* thread */, 382 tmp1 /* tmp */, 383 val != noreg /* tosca_live */, 384 false /* expand_call */); 385 386 if (val == noreg) { 387 BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), noreg, noreg, noreg); 388 } else { 389 storeval_barrier(masm, val, tmp1); 390 // G1 barrier needs uncompressed oop for region cross check. 391 Register new_val = val; 392 if (UseCompressedOops) { 393 new_val = rscratch2; 394 __ mov(new_val, val); 395 } 396 BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), val, noreg, noreg); 397 shenandoah_write_barrier_post(masm, 398 r3 /* store_adr */, 399 new_val /* new_val */, 400 rthread /* thread */, 401 tmp1 /* tmp */, 402 tmp2 /* tmp2 */); 403 } 404 405 } 406 407 void ShenandoahBarrierSetAssembler::obj_equals(MacroAssembler* masm, Register op1, Register op2) { 408 __ cmp(op1, op2); 409 if (ShenandoahAcmpBarrier) { 410 Label done; 411 __ br(Assembler::EQ, done); 412 // The object may have been evacuated, but we won't see it without a 413 // membar here. 414 __ membar(Assembler::LoadStore| Assembler::LoadLoad); 415 read_barrier(masm, op1); 416 read_barrier(masm, op2); 417 __ cmp(op1, op2); 418 __ bind(done); 419 } 420 } 421 422 void ShenandoahBarrierSetAssembler::tlab_allocate(MacroAssembler* masm, Register obj, 423 Register var_size_in_bytes, 424 int con_size_in_bytes, 425 Register t1, 426 Register t2, 427 Label& slow_case) { 428 429 assert_different_registers(obj, t2); 430 assert_different_registers(obj, var_size_in_bytes); 431 Register end = t2; 432 433 int oop_extra_words = Universe::heap()->oop_extra_words(); 434 435 __ ldr(obj, Address(rthread, JavaThread::tlab_top_offset())); 436 if (var_size_in_bytes == noreg) { 437 __ lea(end, Address(obj, (int) (con_size_in_bytes + BrooksPointer::byte_size()))); 438 } else { 439 __ add(var_size_in_bytes, var_size_in_bytes, BrooksPointer::byte_size()); 440 __ lea(end, Address(obj, var_size_in_bytes)); 441 } 442 __ ldr(rscratch1, Address(rthread, JavaThread::tlab_end_offset())); 443 __ cmp(end, rscratch1); 444 __ br(Assembler::HI, slow_case); 445 446 // update the tlab top pointer 447 __ str(end, Address(rthread, JavaThread::tlab_top_offset())); 448 449 __ add(obj, obj, BrooksPointer::byte_size()); 450 __ str(obj, Address(obj, BrooksPointer::byte_offset())); 451 452 // recover var_size_in_bytes if necessary 453 if (var_size_in_bytes == end) { 454 __ sub(var_size_in_bytes, var_size_in_bytes, obj); 455 } 456 } 457 458 void ShenandoahBarrierSetAssembler::resolve_for_read(MacroAssembler* masm, DecoratorSet decorators, Register obj) { 459 bool oop_not_null = (decorators & IS_NOT_NULL) != 0; 460 if (oop_not_null) { 461 read_barrier_not_null(masm, obj); 462 } else { 463 read_barrier(masm, obj); 464 } 465 } 466 467 void ShenandoahBarrierSetAssembler::resolve_for_write(MacroAssembler* masm, DecoratorSet decorators, Register obj) { 468 write_barrier(masm, obj); 469 } 470 471 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, Register addr, Register expected, Register new_val, 472 bool acquire, bool release, bool weak, bool encode, 473 Register tmp1, Register tmp2, Register tmp3, 474 Register result) { 475 476 if (encode) { 477 storeval_barrier(masm, new_val, tmp3); 478 } 479 480 if (UseCompressedOops) { 481 if (encode) { 482 __ encode_heap_oop(tmp1, expected); 483 expected = tmp1; 484 __ encode_heap_oop(tmp2, new_val); 485 new_val = tmp2; 486 } 487 } 488 bool is_cae = (result != noreg); 489 bool is_narrow = UseCompressedOops; 490 Assembler::operand_size size = is_narrow ? Assembler::word : Assembler::xword; 491 if (! is_cae) result = rscratch1; 492 493 assert_different_registers(addr, expected, new_val, result, tmp3); 494 495 Label retry, done, fail; 496 497 // CAS, using LL/SC pair. 498 __ bind(retry); 499 __ load_exclusive(result, addr, size, acquire); 500 if (is_narrow) { 501 __ cmpw(result, expected); 502 } else { 503 __ cmp(result, expected); 504 } 505 __ br(Assembler::NE, fail); 506 __ store_exclusive(tmp3, new_val, addr, size, release); 507 if (weak) { 508 __ cmpw(tmp3, 0u); // If the store fails, return NE to our caller 509 } else { 510 __ cbnzw(tmp3, retry); 511 } 512 __ b(done); 513 514 __ bind(fail); 515 // Check if rb(expected)==rb(result) 516 // Shuffle registers so that we have memory value ready for next expected. 517 __ mov(tmp3, expected); 518 __ mov(expected, result); 519 if (is_narrow) { 520 __ decode_heap_oop(result, result); 521 __ decode_heap_oop(tmp3, tmp3); 522 } 523 __ resolve_for_read(0, result); 524 __ resolve_for_read(0, tmp3); 525 __ cmp(result, tmp3); 526 // Retry with expected now being the value we just loaded from addr. 527 __ br(Assembler::EQ, retry); 528 if (is_narrow && is_cae) { 529 // For cmp-and-exchange and narrow oops, we need to restore 530 // the compressed old-value. We moved it to 'expected' a few lines up. 531 __ mov(result, expected); 532 } 533 __ bind(done); 534 535 } 536 537 #ifdef COMPILER1 538 539 #undef __ 540 #define __ ce->masm()-> 541 542 void ShenandoahBarrierSetAssembler::gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub) { 543 ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1(); 544 // At this point we know that marking is in progress. 545 // If do_load() is true then we have to emit the 546 // load of the previous value; otherwise it has already 547 // been loaded into _pre_val. 548 549 __ bind(*stub->entry()); 550 551 assert(stub->pre_val()->is_register(), "Precondition."); 552 553 Register pre_val_reg = stub->pre_val()->as_register(); 554 555 if (stub->do_load()) { 556 ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /*wide*/, false /*unaligned*/); 557 } 558 __ cbz(pre_val_reg, *stub->continuation()); 559 ce->store_parameter(stub->pre_val()->as_register(), 0); 560 __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin())); 561 __ b(*stub->continuation()); 562 } 563 564 void ShenandoahBarrierSetAssembler::gen_write_barrier_stub(LIR_Assembler* ce, ShenandoahWriteBarrierStub* stub) { 565 566 Register obj = stub->obj()->as_register(); 567 Register res = stub->result()->as_register(); 568 569 Label done; 570 571 __ bind(*stub->entry()); 572 573 if (res != obj) { 574 __ mov(res, obj); 575 } 576 // Check for null. 577 if (stub->needs_null_check()) { 578 __ cbz(res, done); 579 } 580 581 write_barrier(ce->masm(), res); 582 583 __ bind(done); 584 __ b(*stub->continuation()); 585 } 586 587 #undef __ 588 589 #define __ sasm-> 590 591 void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) { 592 __ prologue("shenandoah_pre_barrier", false); 593 594 // arg0 : previous value of memory 595 596 BarrierSet* bs = BarrierSet::barrier_set(); 597 598 const Register pre_val = r0; 599 const Register thread = rthread; 600 const Register tmp = rscratch1; 601 602 Address queue_index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset())); 603 Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset())); 604 605 Label done; 606 Label runtime; 607 608 // Is marking still active? 609 Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset())); 610 __ ldrb(tmp, gc_state); 611 __ mov(rscratch2, ShenandoahHeap::MARKING | ShenandoahHeap::TRAVERSAL); 612 __ tst(tmp, rscratch2); 613 __ br(Assembler::EQ, done); 614 615 // Can we store original value in the thread's buffer? 616 __ ldr(tmp, queue_index); 617 __ cbz(tmp, runtime); 618 619 __ sub(tmp, tmp, wordSize); 620 __ str(tmp, queue_index); 621 __ ldr(rscratch2, buffer); 622 __ add(tmp, tmp, rscratch2); 623 __ load_parameter(0, rscratch2); 624 __ str(rscratch2, Address(tmp, 0)); 625 __ b(done); 626 627 __ bind(runtime); 628 __ push_call_clobbered_registers(); 629 __ load_parameter(0, pre_val); 630 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); 631 __ pop_call_clobbered_registers(); 632 __ bind(done); 633 634 __ epilogue(); 635 } 636 637 #undef __ 638 639 #endif // COMPILER1 640 641 address ShenandoahBarrierSetAssembler::shenandoah_wb() { 642 assert(_shenandoah_wb != NULL, "need write barrier stub"); 643 return _shenandoah_wb; 644 } 645 646 address ShenandoahBarrierSetAssembler::shenandoah_wb_C() { 647 assert(_shenandoah_wb_C != NULL, "need write barrier stub"); 648 return _shenandoah_wb_C; 649 } 650 651 #define __ cgen->assembler()-> 652 653 // Shenandoah write barrier. 654 // 655 // Input: 656 // r0: OOP to evacuate. Not null. 657 // 658 // Output: 659 // r0: Pointer to evacuated OOP. 660 // 661 // Trash rscratch1, rscratch2. Preserve everything else. 662 address ShenandoahBarrierSetAssembler::generate_shenandoah_wb(StubCodeGenerator* cgen, bool c_abi, bool do_cset_test) { 663 664 __ align(6); 665 StubCodeMark mark(cgen, "StubRoutines", "shenandoah_wb"); 666 address start = __ pc(); 667 668 if (do_cset_test) { 669 Label work; 670 __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr()); 671 __ lsr(rscratch1, r0, ShenandoahHeapRegion::region_size_bytes_shift_jint()); 672 __ ldrb(rscratch2, Address(rscratch2, rscratch1)); 673 __ tbnz(rscratch2, 0, work); 674 __ ret(lr); 675 __ bind(work); 676 } 677 678 Register obj = r0; 679 680 __ enter(); // required for proper stackwalking of RuntimeStub frame 681 682 if (!c_abi) { 683 __ push_call_clobbered_registers(); 684 } else { 685 __ push_call_clobbered_fp_registers(); 686 } 687 688 __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_JRT)); 689 __ blrt(lr, 1, 0, MacroAssembler::ret_type_integral); 690 if (!c_abi) { 691 __ mov(rscratch1, obj); 692 __ pop_call_clobbered_registers(); 693 __ mov(obj, rscratch1); 694 } else { 695 __ pop_call_clobbered_fp_registers(); 696 } 697 698 __ leave(); // required for proper stackwalking of RuntimeStub frame 699 __ ret(lr); 700 701 return start; 702 } 703 704 #undef __ 705 706 void ShenandoahBarrierSetAssembler::barrier_stubs_init() { 707 if (ShenandoahWriteBarrier || ShenandoahStoreValEnqueueBarrier) { 708 int stub_code_size = 2048; 709 ResourceMark rm; 710 BufferBlob* bb = BufferBlob::create("shenandoah_barrier_stubs", stub_code_size); 711 CodeBuffer buf(bb); 712 StubCodeGenerator cgen(&buf); 713 _shenandoah_wb = generate_shenandoah_wb(&cgen, false, true); 714 _shenandoah_wb_C = generate_shenandoah_wb(&cgen, true, !ShenandoahWriteBarrierCsetTestInIR); 715 } 716 }