1 /*
2 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2018, 2020, Red Hat, Inc. All rights reserved.
4 * Copyright (c) 2020, 2021, Huawei Technologies Co., Ltd. All rights reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 *
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
28 #include "gc/shenandoah/mode/shenandoahMode.hpp"
29 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
30 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
31 #include "gc/shenandoah/shenandoahForwarding.hpp"
32 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
33 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
34 #include "gc/shenandoah/shenandoahRuntime.hpp"
35 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
36 #include "interpreter/interp_masm.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "runtime/javaThread.hpp"
39 #include "runtime/sharedRuntime.hpp"
40 #ifdef COMPILER1
41 #include "c1/c1_LIRAssembler.hpp"
42 #include "c1/c1_MacroAssembler.hpp"
43 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
44 #endif
45 #ifdef COMPILER2
46 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
47 #include "opto/output.hpp"
48 #include "utilities/population_count.hpp"
49 #include "utilities/powerOfTwo.hpp"
50 #endif
51
52 #define __ masm->
53
54 void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
55 Register src, Register dst, Register count, RegSet saved_regs) {
56 if (is_oop) {
57 bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0;
58 if ((ShenandoahSATBBarrier && !dest_uninitialized) || ShenandoahLoadRefBarrier) {
59
60 Label done;
61
62 // Avoid calling runtime if count == 0
63 __ beqz(count, done);
64
65 // Is GC active?
66 Address gc_state(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
67 assert_different_registers(src, dst, count, t0);
68
69 __ lbu(t0, gc_state);
70 if (ShenandoahSATBBarrier && dest_uninitialized) {
71 __ test_bit(t0, t0, ShenandoahHeap::HAS_FORWARDED_BITPOS);
72 __ beqz(t0, done);
73 } else {
74 __ andi(t0, t0, ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::MARKING);
75 __ beqz(t0, done);
76 }
77
78 __ push_reg(saved_regs, sp);
79 if (UseCompressedOops) {
80 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop),
81 src, dst, count);
82 } else {
83 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop), src, dst, count);
84 }
85 __ pop_reg(saved_regs, sp);
86 __ bind(done);
87 }
88 }
89 }
90
91 void ShenandoahBarrierSetAssembler::arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
92 Register start, Register count, Register tmp) {
93 if (ShenandoahCardBarrier && is_oop) {
94 gen_write_ref_array_post_barrier(masm, decorators, start, count, tmp);
95 }
96 }
97
98 void ShenandoahBarrierSetAssembler::satb_barrier(MacroAssembler* masm,
99 Register obj,
100 Register pre_val,
101 Register thread,
102 Register tmp1,
103 Register tmp2,
104 bool tosca_live,
105 bool expand_call) {
106 assert(ShenandoahSATBBarrier, "Should be checked by caller");
107
108 // If expand_call is true then we expand the call_VM_leaf macro
109 // directly to skip generating the check by
110 // InterpreterMacroAssembler::call_VM_leaf_base that checks _last_sp.
111 assert(thread == xthread, "must be");
112
113 Label done;
114 Label runtime;
115
116 assert_different_registers(obj, pre_val, tmp1, tmp2);
117 assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register");
118
119 Address index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
120 Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
121
122 // Is marking active?
123 Address gc_state(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
124 __ lbu(t1, gc_state);
125 __ test_bit(t1, t1, ShenandoahHeap::MARKING_BITPOS);
126 __ beqz(t1, done);
127
128 // Do we need to load the previous value?
129 if (obj != noreg) {
130 __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW);
131 }
132
133 // Is the previous value null?
134 __ beqz(pre_val, done);
135
136 // Can we store original value in the thread's buffer?
137 // Is index == 0?
138 // (The index field is typed as size_t.)
139 __ ld(tmp1, index); // tmp := *index_adr
140 __ beqz(tmp1, runtime); // tmp == 0? If yes, goto runtime
141
142 __ subi(tmp1, tmp1, wordSize); // tmp := tmp - wordSize
143 __ sd(tmp1, index); // *index_adr := tmp
144 __ ld(tmp2, buffer);
145 __ add(tmp1, tmp1, tmp2); // tmp := tmp + *buffer_adr
146
147 // Record the previous value
148 __ sd(pre_val, Address(tmp1, 0));
149 __ j(done);
150
151 __ bind(runtime);
152 // save the live input values
153 RegSet saved = RegSet::of(pre_val);
154 if (tosca_live) saved += RegSet::of(x10);
155 if (obj != noreg) saved += RegSet::of(obj);
156
157 __ push_reg(saved, sp);
158
159 // Calling the runtime using the regular call_VM_leaf mechanism generates
160 // code (generated by InterpreterMacroAssember::call_VM_leaf_base)
161 // that checks that the *(rfp+frame::interpreter_frame_last_sp) is null.
162 //
163 // If we care generating the pre-barrier without a frame (e.g. in the
164 // intrinsified Reference.get() routine) then ebp might be pointing to
165 // the caller frame and so this check will most likely fail at runtime.
166 //
167 // Expanding the call directly bypasses the generation of the check.
168 // So when we do not have have a full interpreter frame on the stack
169 // expand_call should be passed true.
170 if (expand_call) {
171 assert(pre_val != c_rarg1, "smashed arg");
172 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), pre_val);
173 } else {
174 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), pre_val);
175 }
176
177 __ pop_reg(saved, sp);
178
179 __ bind(done);
180 }
181
182 void ShenandoahBarrierSetAssembler::resolve_forward_pointer(MacroAssembler* masm, Register dst, Register tmp) {
183 assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
184
185 Label is_null;
186 __ beqz(dst, is_null);
187 resolve_forward_pointer_not_null(masm, dst, tmp);
188 __ bind(is_null);
189 }
190
191 // IMPORTANT: This must preserve all registers, even t0 and t1, except those explicitly
192 // passed in.
193 void ShenandoahBarrierSetAssembler::resolve_forward_pointer_not_null(MacroAssembler* masm, Register dst, Register tmp) {
194 assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
195 // The below loads the mark word, checks if the lowest two bits are
196 // set, and if so, clear the lowest two bits and copy the result
197 // to dst. Otherwise it leaves dst alone.
198 // Implementing this is surprisingly awkward. I do it here by:
199 // - Inverting the mark word
200 // - Test lowest two bits == 0
201 // - If so, set the lowest two bits
202 // - Invert the result back, and copy to dst
203 RegSet saved_regs = RegSet::of(t2);
204 bool borrow_reg = (tmp == noreg);
205 if (borrow_reg) {
206 // No free registers available. Make one useful.
207 tmp = t0;
208 if (tmp == dst) {
209 tmp = t1;
210 }
211 saved_regs += RegSet::of(tmp);
212 }
213
214 assert_different_registers(tmp, dst, t2);
215 __ push_reg(saved_regs, sp);
216
217 Label done;
218 __ ld(tmp, Address(dst, oopDesc::mark_offset_in_bytes()));
219 __ xori(tmp, tmp, -1); // eon with 0 is equivalent to XOR with -1
220 __ andi(t2, tmp, markWord::lock_mask_in_place);
221 __ bnez(t2, done);
222 __ ori(tmp, tmp, markWord::marked_value);
223 __ xori(dst, tmp, -1); // eon with 0 is equivalent to XOR with -1
224 __ bind(done);
225
226 __ pop_reg(saved_regs, sp);
227 }
228
229 void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm,
230 Register dst,
231 Address load_addr,
232 DecoratorSet decorators) {
233 assert(ShenandoahLoadRefBarrier, "Should be enabled");
234 assert(dst != t1 && load_addr.base() != t1, "need t1");
235 assert_different_registers(load_addr.base(), t0, t1);
236
237 bool is_strong = ShenandoahBarrierSet::is_strong_access(decorators);
238 bool is_weak = ShenandoahBarrierSet::is_weak_access(decorators);
239 bool is_phantom = ShenandoahBarrierSet::is_phantom_access(decorators);
240 bool is_native = ShenandoahBarrierSet::is_native_access(decorators);
241 bool is_narrow = UseCompressedOops && !is_native;
242
243 Label heap_stable, not_cset;
244 __ enter();
245 Address gc_state(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
246 __ lbu(t1, gc_state);
247
248 // Check for heap stability
249 if (is_strong) {
250 __ test_bit(t1, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
251 __ beqz(t1, heap_stable);
252 } else {
253 Label lrb;
254 __ test_bit(t0, t1, ShenandoahHeap::WEAK_ROOTS_BITPOS);
255 __ bnez(t0, lrb);
256 __ test_bit(t0, t1, ShenandoahHeap::HAS_FORWARDED_BITPOS);
257 __ beqz(t0, heap_stable);
258 __ bind(lrb);
259 }
260
261 // use x11 for load address
262 Register result_dst = dst;
263 if (dst == x11) {
264 __ mv(t1, dst);
265 dst = t1;
266 }
267
268 // Save x10 and x11, unless it is an output register
269 RegSet saved_regs = RegSet::of(x10, x11) - result_dst;
270 __ push_reg(saved_regs, sp);
271 __ la(x11, load_addr);
272 __ mv(x10, dst);
273
274 // Test for in-cset
275 if (is_strong) {
276 __ mv(t1, ShenandoahHeap::in_cset_fast_test_addr());
277 __ srli(t0, x10, ShenandoahHeapRegion::region_size_bytes_shift_jint());
278 __ add(t1, t1, t0);
279 __ lbu(t1, Address(t1));
280 __ test_bit(t0, t1, 0);
281 __ beqz(t0, not_cset);
282 }
283
284 __ push_call_clobbered_registers();
285 address target = nullptr;
286 if (is_strong) {
287 if (is_narrow) {
288 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow);
289 } else {
290 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
291 }
292 } else if (is_weak) {
293 if (is_narrow) {
294 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow);
295 } else {
296 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
297 }
298 } else {
299 assert(is_phantom, "only remaining strength");
300 assert(!is_narrow, "phantom access cannot be narrow");
301 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
302 }
303 __ rt_call(target);
304 __ mv(t0, x10);
305 __ pop_call_clobbered_registers();
306 __ mv(x10, t0);
307 __ bind(not_cset);
308 __ mv(result_dst, x10);
309 __ pop_reg(saved_regs, sp);
310
311 __ bind(heap_stable);
312 __ leave();
313 }
314
315 //
316 // Arguments:
317 //
318 // Inputs:
319 // src: oop location to load from, might be clobbered
320 //
321 // Output:
322 // dst: oop loaded from src location
323 //
324 // Kill:
325 // x30 (tmp reg)
326 //
327 // Alias:
328 // dst: x30 (might use x30 as temporary output register to avoid clobbering src)
329 //
330 void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm,
331 DecoratorSet decorators,
332 BasicType type,
333 Register dst,
334 Address src,
335 Register tmp1,
336 Register tmp2) {
337 // 1: non-reference load, no additional barrier is needed
338 if (!is_reference_type(type)) {
339 BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp2);
340 return;
341 }
342
343 // 2: load a reference from src location and apply LRB if needed
344 if (ShenandoahBarrierSet::need_load_reference_barrier(decorators, type)) {
345 Register result_dst = dst;
346
347 // Preserve src location for LRB
348 RegSet saved_regs;
349 if (dst == src.base()) {
350 dst = (src.base() == x28) ? x29 : x28;
351 saved_regs = RegSet::of(dst);
352 __ push_reg(saved_regs, sp);
353 }
354 assert_different_registers(dst, src.base());
355
356 BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp2);
357
358 load_reference_barrier(masm, dst, src, decorators);
359
360 if (dst != result_dst) {
361 __ mv(result_dst, dst);
362 dst = result_dst;
363 }
364
365 if (saved_regs.bits() != 0) {
366 __ pop_reg(saved_regs, sp);
367 }
368 } else {
369 BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp2);
370 }
371
372 // 3: apply keep-alive barrier if needed
373 if (ShenandoahBarrierSet::need_keep_alive_barrier(decorators, type)) {
374 __ enter();
375 __ push_call_clobbered_registers();
376 satb_barrier(masm /* masm */,
377 noreg /* obj */,
378 dst /* pre_val */,
379 xthread /* thread */,
380 tmp1 /* tmp1 */,
381 tmp2 /* tmp2 */,
382 true /* tosca_live */,
383 true /* expand_call */);
384 __ pop_call_clobbered_registers();
385 __ leave();
386 }
387 }
388
389 void ShenandoahBarrierSetAssembler::card_barrier(MacroAssembler* masm, Register obj) {
390 assert(ShenandoahCardBarrier, "Should have been checked by caller");
391
392 __ srli(obj, obj, CardTable::card_shift());
393
394 assert(CardTable::dirty_card_val() == 0, "must be");
395
396 Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
397 __ ld(t1, curr_ct_holder_addr);
398 __ add(t1, obj, t1);
399
400 if (UseCondCardMark) {
401 Label L_already_dirty;
402 __ lbu(t0, Address(t1));
403 __ beqz(t0, L_already_dirty);
404 __ sb(zr, Address(t1));
405 __ bind(L_already_dirty);
406 } else {
407 __ sb(zr, Address(t1));
408 }
409 }
410
411 void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
412 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) {
413 // 1: non-reference types require no barriers
414 if (!is_reference_type(type)) {
415 BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2, tmp3);
416 return;
417 }
418
419 // Flatten object address right away for simplicity: likely needed by barriers
420 if (dst.offset() == 0) {
421 if (dst.base() != tmp3) {
422 __ mv(tmp3, dst.base());
423 }
424 } else {
425 __ la(tmp3, dst);
426 }
427
428 bool storing_non_null = (val != noreg);
429
430 // 2: pre-barrier: SATB needs the previous value
431 if (ShenandoahBarrierSet::need_satb_barrier(decorators, type)) {
432 satb_barrier(masm,
433 tmp3 /* obj */,
434 tmp2 /* pre_val */,
435 xthread /* thread */,
436 tmp1 /* tmp */,
437 t0 /* tmp2 */,
438 storing_non_null /* tosca_live */,
439 false /* expand_call */);
440 }
441
442 // Store!
443 BarrierSetAssembler::store_at(masm, decorators, type, Address(tmp3, 0), val, noreg, noreg, noreg);
444
445 // 3: post-barrier: card barrier needs store address
446 if (ShenandoahBarrierSet::need_card_barrier(decorators, type) && storing_non_null) {
447 card_barrier(masm, tmp3);
448 }
449 }
450
451 void ShenandoahBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
452 Register obj, Register tmp, Label& slowpath) {
453 Label done;
454 // Resolve jobject
455 BarrierSetAssembler::try_resolve_jobject_in_native(masm, jni_env, obj, tmp, slowpath);
456
457 // Check for null.
458 __ beqz(obj, done);
459
460 assert(obj != t1, "need t1");
461 Address gc_state(jni_env, ShenandoahThreadLocalData::gc_state_offset() - JavaThread::jni_environment_offset());
462 __ lbu(t1, gc_state);
463
464 // Check for heap in evacuation phase
465 __ test_bit(t0, t1, ShenandoahHeap::EVACUATION_BITPOS);
466 __ bnez(t0, slowpath);
467
468 __ bind(done);
469 }
470
471 #ifdef COMPILER2
472 void ShenandoahBarrierSetAssembler::try_resolve_weak_handle_in_c2(MacroAssembler *masm, Register obj,
473 Register tmp, Label& slow_path) {
474 assert_different_registers(obj, tmp);
475
476 Label done;
477
478 // Resolve weak handle using the standard implementation.
479 BarrierSetAssembler::try_resolve_weak_handle_in_c2(masm, obj, tmp, slow_path);
480
481 // Check if the reference is null, and if it is, take the fast path.
482 __ beqz(obj, done);
483
484 Address gc_state(xthread, ShenandoahThreadLocalData::gc_state_offset());
485 __ lbu(tmp, gc_state);
486
487 // Check if the heap is under weak-reference/roots processing, in
488 // which case we need to take the slow path.
489 __ test_bit(tmp, tmp, ShenandoahHeap::WEAK_ROOTS_BITPOS);
490 __ bnez(tmp, slow_path);
491 __ bind(done);
492 }
493 #endif
494
495 // Special Shenandoah CAS implementation that handles false negatives due
496 // to concurrent evacuation. The service is more complex than a
497 // traditional CAS operation because the CAS operation is intended to
498 // succeed if the reference at addr exactly matches expected or if the
499 // reference at addr holds a pointer to a from-space object that has
500 // been relocated to the location named by expected. There are two
501 // races that must be addressed:
502 // a) A parallel thread may mutate the contents of addr so that it points
503 // to a different object. In this case, the CAS operation should fail.
504 // b) A parallel thread may heal the contents of addr, replacing a
505 // from-space pointer held in addr with the to-space pointer
506 // representing the new location of the object.
507 // Upon entry to cmpxchg_oop, it is assured that new_val equals null
508 // or it refers to an object that is not being evacuated out of
509 // from-space, or it refers to the to-space version of an object that
510 // is being evacuated out of from-space.
511 //
512 // By default the value held in the result register following execution
513 // of the generated code sequence is 0 to indicate failure of CAS,
514 // non-zero to indicate success. If is_cae, the result is the value most
515 // recently fetched from addr rather than a boolean success indicator.
516 //
517 // Clobbers t0, t1
518 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm,
519 Register addr,
520 Register expected,
521 Register new_val,
522 Assembler::Aqrl acquire,
523 Assembler::Aqrl release,
524 bool is_cae,
525 Register result) {
526 bool is_narrow = UseCompressedOops;
527 Assembler::operand_size size = is_narrow ? Assembler::uint32 : Assembler::int64;
528
529 assert_different_registers(addr, expected, t0, t1);
530 assert_different_registers(addr, new_val, t0, t1);
531
532 Label retry, success, fail, done;
533
534 __ bind(retry);
535
536 // Step1: Try to CAS.
537 __ cmpxchg(addr, expected, new_val, size, acquire, release, /* result */ t1);
538
539 // If success, then we are done.
540 __ beq(expected, t1, success);
541
542 // Step2: CAS failed, check the forwarded pointer.
543 __ mv(t0, t1);
544
545 if (is_narrow) {
546 __ decode_heap_oop(t0, t0);
547 }
548 resolve_forward_pointer(masm, t0);
549
550 __ encode_heap_oop(t0, t0);
551
552 // Report failure when the forwarded oop was not expected.
553 __ bne(t0, expected, fail);
554
555 // Step 3: CAS again using the forwarded oop.
556 __ cmpxchg(addr, t1, new_val, size, acquire, release, /* result */ t0);
557
558 // Retry when failed.
559 __ bne(t0, t1, retry);
560
561 __ bind(success);
562 if (is_cae) {
563 __ mv(result, expected);
564 } else {
565 __ mv(result, 1);
566 }
567 __ j(done);
568
569 __ bind(fail);
570 if (is_cae) {
571 __ mv(result, t0);
572 } else {
573 __ mv(result, zr);
574 }
575
576 __ bind(done);
577 }
578
579 void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
580 Register start, Register count, Register tmp) {
581 assert(ShenandoahCardBarrier, "Did you mean to enable ShenandoahCardBarrier?");
582
583 Label L_loop, L_done;
584 const Register end = count;
585
586 // Zero count? Nothing to do.
587 __ beqz(count, L_done);
588
589 // end = start + count << LogBytesPerHeapOop
590 // last element address to make inclusive
591 __ shadd(end, count, start, tmp, LogBytesPerHeapOop);
592 __ subi(end, end, BytesPerHeapOop);
593 __ srli(start, start, CardTable::card_shift());
594 __ srli(end, end, CardTable::card_shift());
595
596 // number of bytes to copy
597 __ sub(count, end, start);
598
599 Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
600 __ ld(tmp, curr_ct_holder_addr);
601 __ add(start, start, tmp);
602
603 __ bind(L_loop);
604 __ add(tmp, start, count);
605 __ sb(zr, Address(tmp));
606 __ subi(count, count, 1);
607 __ bgez(count, L_loop);
608 __ bind(L_done);
609 }
610
611 #undef __
612
613 #ifdef COMPILER1
614
615 #define __ ce->masm()->
616
617 void ShenandoahBarrierSetAssembler::gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub) {
618 ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
619 // At this point we know that marking is in progress.
620 // If do_load() is true then we have to emit the
621 // load of the previous value; otherwise it has already
622 // been loaded into _pre_val.
623 __ bind(*stub->entry());
624
625 assert(stub->pre_val()->is_register(), "Precondition.");
626
627 Register pre_val_reg = stub->pre_val()->as_register();
628
629 if (stub->do_load()) {
630 ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /* wide */);
631 }
632 __ beqz(pre_val_reg, *stub->continuation(), /* is_far */ true);
633 ce->store_parameter(stub->pre_val()->as_register(), 0);
634 __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin()));
635 __ j(*stub->continuation());
636 }
637
638 void ShenandoahBarrierSetAssembler::gen_load_reference_barrier_stub(LIR_Assembler* ce,
639 ShenandoahLoadReferenceBarrierStub* stub) {
640 ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
641 __ bind(*stub->entry());
642
643 DecoratorSet decorators = stub->decorators();
644 bool is_strong = ShenandoahBarrierSet::is_strong_access(decorators);
645 bool is_weak = ShenandoahBarrierSet::is_weak_access(decorators);
646 bool is_phantom = ShenandoahBarrierSet::is_phantom_access(decorators);
647 bool is_native = ShenandoahBarrierSet::is_native_access(decorators);
648
649 Register obj = stub->obj()->as_register();
650 Register res = stub->result()->as_register();
651 Register addr = stub->addr()->as_pointer_register();
652 Register tmp1 = stub->tmp1()->as_register();
653 Register tmp2 = stub->tmp2()->as_register();
654
655 assert(res == x10, "result must arrive in x10");
656 assert_different_registers(tmp1, tmp2, t0);
657
658 if (res != obj) {
659 __ mv(res, obj);
660 }
661
662 if (is_strong) {
663 // Check for object in cset.
664 __ mv(tmp2, ShenandoahHeap::in_cset_fast_test_addr());
665 __ srli(tmp1, res, ShenandoahHeapRegion::region_size_bytes_shift_jint());
666 __ add(tmp2, tmp2, tmp1);
667 __ lbu(tmp2, Address(tmp2));
668 __ beqz(tmp2, *stub->continuation(), true /* is_far */);
669 }
670
671 ce->store_parameter(res, 0);
672 ce->store_parameter(addr, 1);
673
674 if (is_strong) {
675 if (is_native) {
676 __ far_call(RuntimeAddress(bs->load_reference_barrier_strong_native_rt_code_blob()->code_begin()));
677 } else {
678 __ far_call(RuntimeAddress(bs->load_reference_barrier_strong_rt_code_blob()->code_begin()));
679 }
680 } else if (is_weak) {
681 __ far_call(RuntimeAddress(bs->load_reference_barrier_weak_rt_code_blob()->code_begin()));
682 } else {
683 assert(is_phantom, "only remaining strength");
684 __ far_call(RuntimeAddress(bs->load_reference_barrier_phantom_rt_code_blob()->code_begin()));
685 }
686
687 __ j(*stub->continuation());
688 }
689
690 #undef __
691
692 #define __ sasm->
693
694 void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) {
695 __ prologue("shenandoah_pre_barrier", false);
696
697 // arg0 : previous value of memory
698
699 BarrierSet* bs = BarrierSet::barrier_set();
700
701 const Register pre_val = x10;
702 const Register thread = xthread;
703 const Register tmp = t0;
704
705 Address queue_index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
706 Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
707
708 Label done;
709 Label runtime;
710
711 // Is marking still active?
712 Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
713 __ lb(tmp, gc_state);
714 __ test_bit(tmp, tmp, ShenandoahHeap::MARKING_BITPOS);
715 __ beqz(tmp, done);
716
717 // Can we store original value in the thread's buffer?
718 __ ld(tmp, queue_index);
719 __ beqz(tmp, runtime);
720
721 __ subi(tmp, tmp, wordSize);
722 __ sd(tmp, queue_index);
723 __ ld(t1, buffer);
724 __ add(tmp, tmp, t1);
725 __ load_parameter(0, t1);
726 __ sd(t1, Address(tmp, 0));
727 __ j(done);
728
729 __ bind(runtime);
730 __ push_call_clobbered_registers();
731 __ load_parameter(0, pre_val);
732 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), pre_val);
733 __ pop_call_clobbered_registers();
734 __ bind(done);
735
736 __ epilogue();
737 }
738
739 void ShenandoahBarrierSetAssembler::generate_c1_load_reference_barrier_runtime_stub(StubAssembler* sasm,
740 DecoratorSet decorators) {
741 __ prologue("shenandoah_load_reference_barrier", false);
742 // arg0 : object to be resolved
743
744 __ push_call_clobbered_registers();
745 __ load_parameter(0, x10);
746 __ load_parameter(1, x11);
747
748 bool is_strong = ShenandoahBarrierSet::is_strong_access(decorators);
749 bool is_weak = ShenandoahBarrierSet::is_weak_access(decorators);
750 bool is_phantom = ShenandoahBarrierSet::is_phantom_access(decorators);
751 bool is_native = ShenandoahBarrierSet::is_native_access(decorators);
752 address target = nullptr;
753 if (is_strong) {
754 if (is_native) {
755 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
756 } else {
757 if (UseCompressedOops) {
758 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow);
759 } else {
760 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
761 }
762 }
763 } else if (is_weak) {
764 assert(!is_native, "weak must not be called off-heap");
765 if (UseCompressedOops) {
766 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow);
767 } else {
768 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
769 }
770 } else {
771 assert(is_phantom, "only remaining strength");
772 assert(is_native, "phantom must only be called off-heap");
773 target = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom);
774 }
775 __ rt_call(target);
776 __ mv(t0, x10);
777 __ pop_call_clobbered_registers();
778 __ mv(x10, t0);
779
780 __ epilogue();
781 }
782
783 #undef __
784
785 #endif // COMPILER1
786
787 #ifdef COMPILER2
788
789 #undef __
790 #define __ masm.
791
792 bool ShenandoahBarrierStubC2::push_save_register_if_live(MacroAssembler& masm, Register reg) {
793 if (is_live(reg)) {
794 push_save_register(masm, reg);
795 return true;
796 } else {
797 return false;
798 }
799 }
800
801 void ShenandoahBarrierStubC2::push_save_register(MacroAssembler& masm, Register reg) {
802 __ sw(reg, Address(sp, push_save_slot()));
803 }
804
805 void ShenandoahBarrierStubC2::pop_save_register(MacroAssembler& masm, Register reg) {
806 __ ld(reg, Address(sp, pop_save_slot()));
807 }
808
809 bool ShenandoahBarrierStubC2::has_live_vector_registers() {
810 // TODO: Implement; currently assumes vector registers.
811 return true;
812 }
813
814 bool ShenandoahBarrierStubC2::is_live(Register reg) {
815 // TODO: Precompute the generic register map for faster lookups.
816 RegMaskIterator rmi(preserve_set());
817 while (rmi.has_next()) {
818 const OptoReg::Name opto_reg = rmi.next();
819 const VMReg vm_reg = OptoReg::as_VMReg(opto_reg);
820 if (vm_reg->is_Register() && reg == vm_reg->as_Register()) {
821 return true;
822 }
823 }
824 return false;
825 }
826
827 Register ShenandoahBarrierStubC2::select_temp_register(bool& selected_live, Address addr, Register reg1) {
828 Register tmp = noreg;
829 Register fallback_live = noreg;
830
831 // Try to select non-live first:
832 for (int i = 0; i < Register::number_of_registers; i++) {
833 Register r = as_Register(i);
834 if (r != fp && r != sp &&
835 r != xheapbase && r != xthread &&
836 r != t0 && r != t1 && r != zr &&
837 r != reg1 && r != addr.base() && r != addr.index()) {
838 if (!is_live(r)) {
839 tmp = r;
840 break;
841 } else if (fallback_live == noreg) {
842 fallback_live = r;
843 }
844 }
845 }
846
847 // If we could not find a non-live register, select the live fallback:
848 if (tmp == noreg) {
849 tmp = fallback_live;
850 selected_live = true;
851 } else {
852 selected_live = false;
853 }
854
855 assert(tmp != noreg, "successfully selected");
856 assert_different_registers(tmp, reg1);
857 assert_different_registers(tmp, addr.base());
858 assert_different_registers(tmp, addr.index());
859 return tmp;
860 }
861
862 void ShenandoahBarrierStubC2::enter_if_gc_state(MacroAssembler& masm, const char test_state) {
863 int bit_to_check = ShenandoahThreadLocalData::gc_state_to_fast_bit(test_state);
864 Address gc_state_fast(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_fast_offset()));
865 __ lbu(t0, gc_state_fast);
866 __ test_bit(t0, t0, bit_to_check);
867
868 // The bnez cannot jumper further than +/-4Kb
869 __ beqz(t0, *continuation());
870 __ j(*entry());
871
872 // Fast path falls through here when the barrier is not needed.
873 __ bind(*continuation());
874 }
875
876 #undef __
877 #define __ masm->
878
879 void ShenandoahBarrierSetAssembler::compare_and_set_c2(const MachNode* node, MacroAssembler* masm, Register res, Register addr,
880 Register oldval, Register newval, Register tmp, bool exchange, bool maybe_null, bool narrow, bool weak, bool is_acquire) {
881 const Assembler::Aqrl acquire = is_acquire ? Assembler::aq : Assembler::relaxed;
882 const Assembler::Aqrl release = Assembler::rl;
883
884 // Pre-barrier covers several things:
885 // a. Avoids false positives from CAS encountering to-space memory values.
886 // b. Satisfies the need for LRB for the CAE result.
887 // c. Records old value for the sake of SATB.
888 //
889 // (a) and (b) are covered because load barrier does memory location fixup.
890 // (c) is covered by KA on the current memory value.
891 if (ShenandoahBarrierStubC2::needs_slow_barrier(node)) {
892 ShenandoahBarrierStubC2* const stub = ShenandoahBarrierStubC2::create(node, tmp, Address(addr, 0), narrow, /* do_load: */ true);
893 char check = 0;
894 check |= ShenandoahBarrierStubC2::needs_keep_alive_barrier(node) ? ShenandoahHeap::MARKING : 0;
895 check |= ShenandoahBarrierStubC2::needs_load_ref_barrier(node) ? ShenandoahHeap::HAS_FORWARDED : 0;
896 assert(!ShenandoahBarrierStubC2::needs_load_ref_barrier_weak(node), "Not supported for CAS/CAE");
897 stub->enter_if_gc_state(*masm, check);
898 }
899
900 // Existing RISCV cmpxchg_oop already handles Shenandoah forwarded-value retry logic.
901 // It returns:
902 // - boolean 0/1 for CAS (!exchange)
903 // - loaded/current value for CAE (exchange)
904 ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, addr, oldval, newval, acquire, release, exchange /* is_cae */, res);
905
906 // Post-barrier deals with card updates.
907 card_barrier_c2(node, masm, Address(addr, 0));
908 }
909
910 void ShenandoahBarrierSetAssembler::get_and_set_c2(const MachNode* node, MacroAssembler* masm, Register preval,
911 Register newval, Register addr, Register tmp, bool is_acquire) {
912 const bool narrow = node->bottom_type()->isa_narrowoop();
913
914 // Pre-barrier covers several things:
915 // a. Satisfies the need for LRB for the GAS result.
916 // b. Records old value for the sake of SATB.
917 //
918 // (a) is covered because load barrier does memory location fixup.
919 // (b) is covered by KA on the current memory value.
920 if (ShenandoahBarrierStubC2::needs_slow_barrier(node)) {
921 ShenandoahBarrierStubC2* const stub = ShenandoahBarrierStubC2::create(node, tmp, Address(addr, 0), narrow, /* do_load: */ true);
922 char check = 0;
923 check |= ShenandoahBarrierStubC2::needs_keep_alive_barrier(node) ? ShenandoahHeap::MARKING : 0;
924 check |= ShenandoahBarrierStubC2::needs_load_ref_barrier(node) ? ShenandoahHeap::HAS_FORWARDED : 0;
925 assert(!ShenandoahBarrierStubC2::needs_load_ref_barrier_weak(node), "Not supported for GAS");
926 stub->enter_if_gc_state(*masm, check);
927 }
928
929 if (narrow) {
930 if (is_acquire) {
931 __ atomic_xchgalwu(preval, newval, addr);
932 } else {
933 __ atomic_xchgwu(preval, newval, addr);
934 }
935 } else {
936 if (is_acquire) {
937 __ atomic_xchgal(preval, newval, addr);
938 } else {
939 __ atomic_xchg(preval, newval, addr);
940 }
941 }
942
943 // Post-barrier deals with card updates.
944 card_barrier_c2(node, masm, Address(addr, 0));
945 }
946
947 void ShenandoahBarrierSetAssembler::store_c2(const MachNode* node, MacroAssembler* masm, Address dst, bool dst_narrow,
948 Register src, bool src_narrow, Register tmp, bool is_volatile) {
949
950 // Pre-barrier: SATB / keep-alive on current value in memory.
951 if (ShenandoahBarrierStubC2::needs_slow_barrier(node)) {
952 assert(!ShenandoahBarrierStubC2::needs_load_ref_barrier(node), "Should not be required for stores");
953 ShenandoahBarrierStubC2* const stub = ShenandoahBarrierStubC2::create(node, tmp, dst, dst_narrow, /* do_load: */ true);
954 stub->enter_if_gc_state(*masm, ShenandoahHeap::MARKING);
955 }
956
957 // Do the actual store
958 if (dst_narrow) {
959 Register actual_src = src;
960 if (!src_narrow) {
961 assert(tmp != noreg, "need temp register");
962 __ mv(tmp, src);
963 if (ShenandoahBarrierStubC2::maybe_null(node)) {
964 __ encode_heap_oop(tmp, tmp);
965 } else {
966 __ encode_heap_oop_not_null(tmp, tmp);
967 }
968 actual_src = tmp;
969 }
970
971 if (is_volatile) {
972 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
973 __ sw(actual_src, dst);
974 } else {
975 __ sw(actual_src, dst);
976 }
977 } else {
978 if (is_volatile) {
979 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
980 __ sd(src, dst);
981 } else {
982 __ sd(src, dst);
983 }
984 }
985
986 // Post-barrier: card updates.
987 card_barrier_c2(node, masm, dst);
988 }
989
990 void ShenandoahBarrierSetAssembler::load_c2(const MachNode* node, MacroAssembler* masm, Register dst, Address src, bool is_acquire) {
991 const bool narrow = node->bottom_type()->isa_narrowoop();
992
993 // Do the actual load. This load is the candidate for implicit null check, and MUST come first.
994 if (narrow) {
995 __ lwu(dst, src);
996 if (is_acquire) {
997 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
998 }
999 } else {
1000 __ ld(dst, src);
1001 if (is_acquire) {
1002 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
1003 }
1004 }
1005
1006 // Post-barrier: LRB / KA / weak-root processing.
1007 if (ShenandoahBarrierStubC2::needs_slow_barrier(node)) {
1008 ShenandoahBarrierStubC2* const stub = ShenandoahBarrierStubC2::create(node, dst, src, narrow, /* do_load: */ false);
1009 char check = 0;
1010 check |= ShenandoahBarrierStubC2::needs_keep_alive_barrier(node) ? ShenandoahHeap::MARKING : 0;
1011 check |= ShenandoahBarrierStubC2::needs_load_ref_barrier(node) ? ShenandoahHeap::HAS_FORWARDED : 0;
1012 check |= ShenandoahBarrierStubC2::needs_load_ref_barrier_weak(node) ? ShenandoahHeap::WEAK_ROOTS : 0;
1013 stub->enter_if_gc_state(*masm, check);
1014 }
1015 }
1016
1017 void ShenandoahBarrierSetAssembler::card_barrier_c2(const MachNode* node, MacroAssembler* masm, Address address) {
1018 if (!ShenandoahBarrierStubC2::needs_card_barrier(node)) {
1019 return;
1020 }
1021
1022 assert(CardTable::dirty_card_val() == 0, "must be");
1023 Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
1024
1025 // t1 = effective address
1026 __ la(t1, address);
1027
1028 // t1 = card index
1029 __ srli(t1, t1, CardTable::card_shift());
1030
1031 // t0 = card table base
1032 Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
1033 __ ld(t0, curr_ct_holder_addr);
1034
1035 // t1 = &card_table[card_index]
1036 __ add(t1, t1, t0);
1037
1038 if (UseCondCardMark) {
1039 Label L_already_dirty;
1040 __ lbu(t0, Address(t1));
1041 __ beqz(t0, L_already_dirty);
1042 __ sb(zr, Address(t1));
1043 __ bind(L_already_dirty);
1044 } else {
1045 __ sb(zr, Address(t1));
1046 }
1047 }
1048
1049 #undef __
1050 #define __ masm.
1051
1052 void ShenandoahBarrierStubC2::emit_code(MacroAssembler& masm) {
1053 Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
1054
1055 assert(_needs_keep_alive_barrier || _needs_load_ref_barrier, "Why are you here?");
1056
1057 Label L_done;
1058
1059 // Stub entry
1060 __ bind(*BarrierStubC2::entry());
1061
1062 // If needed, perform the load here so stub logic sees the current oop value.
1063 if (_do_load) {
1064 __ load_heap_oop(_obj, _addr, noreg, noreg, AS_RAW);
1065 } else if (_narrow) {
1066 // Decode narrow oop before barrier processing.
1067 if (_maybe_null) {
1068 __ decode_heap_oop(_obj, _obj);
1069 } else {
1070 __ decode_heap_oop_not_null(_obj, _obj);
1071 }
1072 }
1073
1074 if (_do_load || _maybe_null) {
1075 __ beqz(_obj, L_done);
1076 }
1077
1078 keepalive(masm, _obj, t0);
1079
1080 lrb(masm, _obj, _addr, noreg);
1081
1082 // If object is narrow, we need to encode it before exiting.
1083 // For encoding, dst can only turn null if we are dealing with weak loads.
1084 // Otherwise, we have already null-checked. We can skip all this if we performed
1085 // the load ourselves, which means the value is not used by caller.
1086 if (_narrow && !_do_load) {
1087 if (_needs_load_ref_weak_barrier) {
1088 __ encode_heap_oop(_obj, _obj);
1089 } else {
1090 __ encode_heap_oop_not_null(_obj, _obj);
1091 }
1092 }
1093
1094 // Go back to fast path
1095 __ bind(L_done);
1096 __ j(*continuation());
1097 }
1098
1099 void ShenandoahBarrierStubC2::keepalive(MacroAssembler& masm, Register obj, Register tmp1, Label* L_done_unused) {
1100 Address index(xthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
1101 Address buffer(xthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
1102 Label L_runtime;
1103 Label L_done;
1104
1105 // The node doesn't even need keepalive barrier, just don't check anything else
1106 if (!_needs_keep_alive_barrier) {
1107 return;
1108 }
1109
1110 // If both LRB and KeepAlive barriers are required (rare), do a runtime check
1111 // for enabled barrier.
1112 if (_needs_load_ref_barrier) {
1113 Address gcs_addr(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
1114 __ lbu(t0, gcs_addr);
1115 __ test_bit(t0, t0, ShenandoahHeap::MARKING_BITPOS);
1116 __ beqz(t0, L_done);
1117 }
1118
1119 // If the queue is full, go to runtime.
1120 __ ld(tmp1, index);
1121 __ beqz(tmp1, L_runtime);
1122
1123 bool selected_live = false;
1124 Register tmp2 = select_temp_register(selected_live, _addr, obj);
1125 if (selected_live) {
1126 push_save_register(masm, tmp2);
1127 }
1128
1129 // Push into SATB queue.
1130 __ subi(tmp1, tmp1, wordSize);
1131 __ sd(tmp1, index);
1132 __ ld(tmp2, buffer);
1133 __ add(tmp1, tmp1, tmp2);
1134 __ sd(obj, Address(tmp1, 0));
1135 __ j(L_done);
1136
1137 // Runtime call
1138 __ bind(L_runtime);
1139
1140 preserve(obj);
1141 {
1142 SaveLiveRegisters save_registers(&masm, this);
1143 __ mv(c_rarg0, obj);
1144 __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), c_rarg0);
1145 }
1146
1147 __ bind(L_done);
1148
1149 if (selected_live) {
1150 pop_save_register(masm, tmp2);
1151 }
1152 }
1153
1154 void ShenandoahBarrierStubC2::lrb(MacroAssembler& masm, Register obj, Address addr, Register tmp, Label* L_done_unused) {
1155 Label L_done;
1156
1157 // The node doesn't even need LRB barrier, just don't check anything else
1158 if (!_needs_load_ref_barrier) {
1159 return;
1160 }
1161
1162 if ((_node->barrier_data() & ShenandoahBitStrong) != 0) {
1163 // If both LRB and KeepAlive barriers are required (rare), do a runtime
1164 // check for enabled barrier.
1165 if (_needs_keep_alive_barrier) {
1166 Address gcs_addr(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
1167 __ lbu(t0, gcs_addr);
1168
1169 if (_needs_load_ref_weak_barrier) {
1170 __ srli(t1, t0, ShenandoahHeap::WEAK_ROOTS_BITPOS);
1171 __ orr(t0, t0, t1);
1172 }
1173
1174 __ test_bit(t0, t0, ShenandoahHeap::HAS_FORWARDED_BITPOS);
1175 __ beqz(t0, L_done);
1176 }
1177
1178 // Weak/phantom loads always need to go to runtime. For strong refs we
1179 // check if the object in cset, if they are not, then we are done with LRB.
1180 __ mv(t1, ShenandoahHeap::in_cset_fast_test_addr());
1181 __ srli(t0, obj, ShenandoahHeapRegion::region_size_bytes_shift_jint());
1182 __ add(t1, t1, t0);
1183 __ lbu(t1, Address(t1));
1184 __ beqz(t1, L_done);
1185 }
1186
1187 dont_preserve(obj);
1188 {
1189 SaveLiveRegisters save_registers(&masm, this);
1190
1191 // Runtime call wants:
1192 // c_rarg0 <- obj
1193 // c_rarg1 <- lea(addr)
1194 if (c_rarg0 == obj) {
1195 __ la(c_rarg1, addr);
1196 } else if (c_rarg1 == obj) {
1197 // Set up arguments in reverse, and then flip them
1198 __ la(c_rarg0, addr);
1199 // flip them
1200 __ mv(t0, c_rarg0);
1201 __ mv(c_rarg0, c_rarg1);
1202 __ mv(c_rarg1, t0);
1203 } else {
1204 assert_different_registers(c_rarg1, obj);
1205 __ la(c_rarg1, addr);
1206 __ mv(c_rarg0, obj);
1207 }
1208
1209 // Get address of runtime LRB entry and call it
1210 __ rt_call(lrb_runtime_entry_addr());
1211
1212 // If we loaded the object in the stub it means we don't need to return it
1213 // to fastpath, so no need to make this mov.
1214 if (!_do_load) {
1215 __ mv(obj, x10);
1216 }
1217 }
1218
1219 __ bind(L_done);
1220 }
1221
1222 void ShenandoahBarrierStubC2::post_init(int offset) {
1223 // Do nothing.
1224 }
1225 #endif // COMPILER2