1 /*
  2  * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include "precompiled.hpp"
 25 #include "asm/macroAssembler.inline.hpp"
 26 #include "code/codeBlob.hpp"
 27 #include "code/vmreg.inline.hpp"
 28 #include "gc/z/zBarrier.inline.hpp"
 29 #include "gc/z/zBarrierSet.hpp"
 30 #include "gc/z/zBarrierSetAssembler.hpp"
 31 #include "gc/z/zBarrierSetRuntime.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "runtime/sharedRuntime.hpp"
 34 #include "utilities/macros.hpp"
 35 #ifdef COMPILER1
 36 #include "c1/c1_LIRAssembler.hpp"
 37 #include "c1/c1_MacroAssembler.hpp"
 38 #include "gc/z/c1/zBarrierSetC1.hpp"
 39 #endif // COMPILER1
 40 #ifdef COMPILER2
 41 #include "gc/z/c2/zBarrierSetC2.hpp"
 42 #endif // COMPILER2
 43 
 44 #ifdef PRODUCT
 45 #define BLOCK_COMMENT(str) /* nothing */
 46 #else
 47 #define BLOCK_COMMENT(str) __ block_comment(str)
 48 #endif
 49 
 50 #undef __
 51 #define __ masm->
 52 
 53 static void call_vm(MacroAssembler* masm,
 54                     address entry_point,
 55                     Register arg0,
 56                     Register arg1) {
 57   // Setup arguments
 58   if (arg1 == c_rarg0) {
 59     if (arg0 == c_rarg1) {
 60       __ xchgptr(c_rarg1, c_rarg0);
 61     } else {
 62       __ movptr(c_rarg1, arg1);
 63       __ movptr(c_rarg0, arg0);
 64     }
 65   } else {
 66     if (arg0 != c_rarg0) {
 67       __ movptr(c_rarg0, arg0);
 68     }
 69     if (arg1 != c_rarg1) {
 70       __ movptr(c_rarg1, arg1);
 71     }
 72   }
 73 
 74   // Call VM
 75   __ MacroAssembler::call_VM_leaf_base(entry_point, 2);
 76 }
 77 
 78 void ZBarrierSetAssembler::load_at(MacroAssembler* masm,
 79                                    DecoratorSet decorators,
 80                                    BasicType type,
 81                                    Register dst,
 82                                    Address src,
 83                                    Register tmp1,
 84                                    Register tmp_thread) {
 85   if (!ZBarrierSet::barrier_needed(decorators, type)) {
 86     // Barrier not needed
 87     BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 88     return;
 89   }
 90 
 91   BLOCK_COMMENT("ZBarrierSetAssembler::load_at {");
 92 
 93   // Allocate scratch register
 94   Register scratch = tmp1;
 95   if (tmp1 == noreg) {
 96     scratch = r12;
 97     __ push(scratch);
 98   }
 99 
100   assert_different_registers(dst, scratch);
101 
102   Label done;
103 
104   //
105   // Fast Path
106   //
107 
108   // Load address
109   __ lea(scratch, src);
110 
111   // Load oop at address
112   __ movptr(dst, Address(scratch, 0));
113 
114   // Test address bad mask
115   __ testptr(dst, address_bad_mask_from_thread(r15_thread));
116   __ jcc(Assembler::zero, done);
117 
118   //
119   // Slow path
120   //
121 
122   // Save registers
123   __ push(rax);
124   __ push(rcx);
125   __ push(rdx);
126   __ push(rdi);
127   __ push(rsi);
128   __ push(r8);
129   __ push(r9);
130   __ push(r10);
131   __ push(r11);
132 
133   // We may end up here from generate_native_wrapper, then the method may have
134   // floats as arguments, and we must spill them before calling the VM runtime
135   // leaf. From the interpreter all floats are passed on the stack.
136   assert(Argument::n_float_register_parameters_j == 8, "Assumption");
137   const int xmm_size = wordSize * 2;
138   const int xmm_spill_size = xmm_size * Argument::n_float_register_parameters_j;
139   __ subptr(rsp, xmm_spill_size);
140   __ movdqu(Address(rsp, xmm_size * 7), xmm7);
141   __ movdqu(Address(rsp, xmm_size * 6), xmm6);
142   __ movdqu(Address(rsp, xmm_size * 5), xmm5);
143   __ movdqu(Address(rsp, xmm_size * 4), xmm4);
144   __ movdqu(Address(rsp, xmm_size * 3), xmm3);
145   __ movdqu(Address(rsp, xmm_size * 2), xmm2);
146   __ movdqu(Address(rsp, xmm_size * 1), xmm1);
147   __ movdqu(Address(rsp, xmm_size * 0), xmm0);
148 
149   // Call VM
150   call_vm(masm, ZBarrierSetRuntime::load_barrier_on_oop_field_preloaded_addr(decorators), dst, scratch);
151 
152   __ movdqu(xmm0, Address(rsp, xmm_size * 0));
153   __ movdqu(xmm1, Address(rsp, xmm_size * 1));
154   __ movdqu(xmm2, Address(rsp, xmm_size * 2));
155   __ movdqu(xmm3, Address(rsp, xmm_size * 3));
156   __ movdqu(xmm4, Address(rsp, xmm_size * 4));
157   __ movdqu(xmm5, Address(rsp, xmm_size * 5));
158   __ movdqu(xmm6, Address(rsp, xmm_size * 6));
159   __ movdqu(xmm7, Address(rsp, xmm_size * 7));
160   __ addptr(rsp, xmm_spill_size);
161 
162   __ pop(r11);
163   __ pop(r10);
164   __ pop(r9);
165   __ pop(r8);
166   __ pop(rsi);
167   __ pop(rdi);
168   __ pop(rdx);
169   __ pop(rcx);
170 
171   if (dst == rax) {
172     __ addptr(rsp, wordSize);
173   } else {
174     __ movptr(dst, rax);
175     __ pop(rax);
176   }
177 
178   __ bind(done);
179 
180   // Restore scratch register
181   if (tmp1 == noreg) {
182     __ pop(scratch);
183   }
184 
185   BLOCK_COMMENT("} ZBarrierSetAssembler::load_at");
186 }
187 
188 #ifdef ASSERT
189 
190 void ZBarrierSetAssembler::store_at(MacroAssembler* masm,
191                                     DecoratorSet decorators,
192                                     BasicType type,
193                                     Address dst,
194                                     Register src,
195                                     Register tmp1,
196                                     Register tmp2,
197                                     Register tmp3) {
198   BLOCK_COMMENT("ZBarrierSetAssembler::store_at {");
199 
200   // Verify oop store
201   if (is_reference_type(type)) {
202     // Note that src could be noreg, which means we
203     // are storing null and can skip verification.
204     if (src != noreg) {
205       Label done;
206       __ testptr(src, address_bad_mask_from_thread(r15_thread));
207       __ jcc(Assembler::zero, done);
208       __ stop("Verify oop store failed");
209       __ should_not_reach_here();
210       __ bind(done);
211     }
212   }
213 
214   // Store value
215   BarrierSetAssembler::store_at(masm, decorators, type, dst, src, tmp1, tmp2, tmp3);
216 
217   BLOCK_COMMENT("} ZBarrierSetAssembler::store_at");
218 }
219 
220 #endif // ASSERT
221 
222 void ZBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm,
223                                               DecoratorSet decorators,
224                                               BasicType type,
225                                               Register src,
226                                               Register dst,
227                                               Register count) {
228   if (!ZBarrierSet::barrier_needed(decorators, type)) {
229     // Barrier not needed
230     return;
231   }
232 
233   BLOCK_COMMENT("ZBarrierSetAssembler::arraycopy_prologue {");
234 
235   // Save registers
236   __ pusha();
237 
238   // Call VM
239   call_vm(masm, ZBarrierSetRuntime::load_barrier_on_oop_array_addr(), src, count);
240 
241   // Restore registers
242   __ popa();
243 
244   BLOCK_COMMENT("} ZBarrierSetAssembler::arraycopy_prologue");
245 }
246 
247 void ZBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm,
248                                                          Register jni_env,
249                                                          Register obj,
250                                                          Register tmp,
251                                                          Label& slowpath) {
252   BLOCK_COMMENT("ZBarrierSetAssembler::try_resolve_jobject_in_native {");
253 
254   // Resolve jobject
255   BarrierSetAssembler::try_resolve_jobject_in_native(masm, jni_env, obj, tmp, slowpath);
256 
257   // Test address bad mask
258   __ testptr(obj, address_bad_mask_from_jni_env(jni_env));
259   __ jcc(Assembler::notZero, slowpath);
260 
261   BLOCK_COMMENT("} ZBarrierSetAssembler::try_resolve_jobject_in_native");
262 }
263 
264 #ifdef COMPILER1
265 
266 #undef __
267 #define __ ce->masm()->
268 
269 void ZBarrierSetAssembler::generate_c1_load_barrier_test(LIR_Assembler* ce,
270                                                          LIR_Opr ref) const {
271   __ testptr(ref->as_register(), address_bad_mask_from_thread(r15_thread));
272 }
273 
274 void ZBarrierSetAssembler::generate_c1_load_barrier_stub(LIR_Assembler* ce,
275                                                          ZLoadBarrierStubC1* stub) const {
276   // Stub entry
277   __ bind(*stub->entry());
278 
279   Register ref = stub->ref()->as_register();
280   Register ref_addr = noreg;
281   Register tmp = noreg;
282 
283   if (stub->tmp()->is_valid()) {
284     // Load address into tmp register
285     ce->leal(stub->ref_addr(), stub->tmp());
286     ref_addr = tmp = stub->tmp()->as_pointer_register();
287   } else {
288     // Address already in register
289     ref_addr = stub->ref_addr()->as_address_ptr()->base()->as_pointer_register();
290   }
291 
292   assert_different_registers(ref, ref_addr, noreg);
293 
294   // Save rax unless it is the result or tmp register
295   if (ref != rax && tmp != rax) {
296     __ push(rax);
297   }
298 
299   // Setup arguments and call runtime stub
300   __ subptr(rsp, 2 * BytesPerWord);
301   ce->store_parameter(ref_addr, 1);
302   ce->store_parameter(ref, 0);
303   __ call(RuntimeAddress(stub->runtime_stub()));
304   __ addptr(rsp, 2 * BytesPerWord);
305 
306   // Verify result
307   __ verify_oop(rax);
308 
309   // Move result into place
310   if (ref != rax) {
311     __ movptr(ref, rax);
312   }
313 
314   // Restore rax unless it is the result or tmp register
315   if (ref != rax && tmp != rax) {
316     __ pop(rax);
317   }
318 
319   // Stub exit
320   __ jmp(*stub->continuation());
321 }
322 
323 #undef __
324 #define __ sasm->
325 
326 void ZBarrierSetAssembler::generate_c1_load_barrier_runtime_stub(StubAssembler* sasm,
327                                                                  DecoratorSet decorators) const {
328   // Enter and save registers
329   __ enter();
330   __ save_live_registers_no_oop_map(true /* save_fpu_registers */);
331 
332   // Setup arguments
333   __ load_parameter(1, c_rarg1);
334   __ load_parameter(0, c_rarg0);
335 
336   // Call VM
337   __ call_VM_leaf(ZBarrierSetRuntime::load_barrier_on_oop_field_preloaded_addr(decorators), c_rarg0, c_rarg1);
338 
339   // Restore registers and return
340   __ restore_live_registers_except_rax(true /* restore_fpu_registers */);
341   __ leave();
342   __ ret(0);
343 }
344 
345 #endif // COMPILER1
346 
347 #ifdef COMPILER2
348 
349 OptoReg::Name ZBarrierSetAssembler::refine_register(const Node* node, OptoReg::Name opto_reg) {
350   if (!OptoReg::is_reg(opto_reg)) {
351     return OptoReg::Bad;
352   }
353 
354   const VMReg vm_reg = OptoReg::as_VMReg(opto_reg);
355   if (vm_reg->is_XMMRegister()) {
356     opto_reg &= ~15;
357     switch (node->ideal_reg()) {
358       case Op_VecX:
359         opto_reg |= 2;
360         break;
361       case Op_VecY:
362         opto_reg |= 4;
363         break;
364       case Op_VecZ:
365         opto_reg |= 8;
366         break;
367       default:
368         opto_reg |= 1;
369         break;
370     }
371   }
372 
373   return opto_reg;
374 }
375 
376 // We use the vec_spill_helper from the x86.ad file to avoid reinventing this wheel
377 extern void vec_spill_helper(CodeBuffer *cbuf, bool is_load,
378                             int stack_offset, int reg, uint ireg, outputStream* st);
379 
380 #undef __
381 #define __ _masm->
382 
383 class ZSaveLiveRegisters {
384 private:
385   struct XMMRegisterData {
386     XMMRegister _reg;
387     int         _size;
388 
389     // Used by GrowableArray::find()
390     bool operator == (const XMMRegisterData& other) {
391       return _reg == other._reg;
392     }
393   };
394 
395   MacroAssembler* const          _masm;
396   GrowableArray<Register>        _gp_registers;
397   GrowableArray<KRegister>       _opmask_registers;
398   GrowableArray<XMMRegisterData> _xmm_registers;
399   int                            _spill_size;
400   int                            _spill_offset;
401 
402   static int xmm_compare_register_size(XMMRegisterData* left, XMMRegisterData* right) {
403     if (left->_size == right->_size) {
404       return 0;
405     }
406 
407     return (left->_size < right->_size) ? -1 : 1;
408   }
409 
410   static int xmm_slot_size(OptoReg::Name opto_reg) {
411     // The low order 4 bytes denote what size of the XMM register is live
412     return (opto_reg & 15) << 3;
413   }
414 
415   static uint xmm_ideal_reg_for_size(int reg_size) {
416     switch (reg_size) {
417     case 8:
418       return Op_VecD;
419     case 16:
420       return Op_VecX;
421     case 32:
422       return Op_VecY;
423     case 64:
424       return Op_VecZ;
425     default:
426       fatal("Invalid register size %d", reg_size);
427       return 0;
428     }
429   }
430 
431   bool xmm_needs_vzeroupper() const {
432     return _xmm_registers.is_nonempty() && _xmm_registers.at(0)._size > 16;
433   }
434 
435   void xmm_register_save(const XMMRegisterData& reg_data) {
436     const OptoReg::Name opto_reg = OptoReg::as_OptoReg(reg_data._reg->as_VMReg());
437     const uint ideal_reg = xmm_ideal_reg_for_size(reg_data._size);
438     _spill_offset -= reg_data._size;
439     vec_spill_helper(__ code(), false /* is_load */, _spill_offset, opto_reg, ideal_reg, tty);
440   }
441 
442   void xmm_register_restore(const XMMRegisterData& reg_data) {
443     const OptoReg::Name opto_reg = OptoReg::as_OptoReg(reg_data._reg->as_VMReg());
444     const uint ideal_reg = xmm_ideal_reg_for_size(reg_data._size);
445     vec_spill_helper(__ code(), true /* is_load */, _spill_offset, opto_reg, ideal_reg, tty);
446     _spill_offset += reg_data._size;
447   }
448 
449   void gp_register_save(Register reg) {
450     _spill_offset -= 8;
451     __ movq(Address(rsp, _spill_offset), reg);
452   }
453 
454   void opmask_register_save(KRegister reg) {
455     _spill_offset -= 8;
456     __ kmov(Address(rsp, _spill_offset), reg);
457   }
458 
459   void gp_register_restore(Register reg) {
460     __ movq(reg, Address(rsp, _spill_offset));
461     _spill_offset += 8;
462   }
463 
464   void opmask_register_restore(KRegister reg) {
465     __ kmov(reg, Address(rsp, _spill_offset));
466     _spill_offset += 8;
467   }
468 
469 // Register is a class, but it would be assigned numerical value.
470 // "0" is assigned for rax. Thus we need to ignore -Wnonnull.
471 PRAGMA_DIAG_PUSH
472 PRAGMA_NONNULL_IGNORED
473   void initialize(ZLoadBarrierStubC2* stub) {
474     // Create mask of caller saved registers that need to
475     // be saved/restored if live
476     RegMask caller_saved;
477     caller_saved.Insert(OptoReg::as_OptoReg(rax->as_VMReg()));
478     caller_saved.Insert(OptoReg::as_OptoReg(rcx->as_VMReg()));
479     caller_saved.Insert(OptoReg::as_OptoReg(rdx->as_VMReg()));
480     caller_saved.Insert(OptoReg::as_OptoReg(rsi->as_VMReg()));
481     caller_saved.Insert(OptoReg::as_OptoReg(rdi->as_VMReg()));
482     caller_saved.Insert(OptoReg::as_OptoReg(r8->as_VMReg()));
483     caller_saved.Insert(OptoReg::as_OptoReg(r9->as_VMReg()));
484     caller_saved.Insert(OptoReg::as_OptoReg(r10->as_VMReg()));
485     caller_saved.Insert(OptoReg::as_OptoReg(r11->as_VMReg()));
486     caller_saved.Remove(OptoReg::as_OptoReg(stub->ref()->as_VMReg()));
487 
488     // Create mask of live registers
489     RegMask live = stub->live();
490     if (stub->tmp() != noreg) {
491       live.Insert(OptoReg::as_OptoReg(stub->tmp()->as_VMReg()));
492     }
493 
494     int gp_spill_size = 0;
495     int opmask_spill_size = 0;
496     int xmm_spill_size = 0;
497 
498     // Record registers that needs to be saved/restored
499     RegMaskIterator rmi(live);
500     while (rmi.has_next()) {
501       const OptoReg::Name opto_reg = rmi.next();
502       const VMReg vm_reg = OptoReg::as_VMReg(opto_reg);
503 
504       if (vm_reg->is_Register()) {
505         if (caller_saved.Member(opto_reg)) {
506           _gp_registers.append(vm_reg->as_Register());
507           gp_spill_size += 8;
508         }
509       } else if (vm_reg->is_KRegister()) {
510         // All opmask registers are caller saved, thus spill the ones
511         // which are live.
512         if (_opmask_registers.find(vm_reg->as_KRegister()) == -1) {
513           _opmask_registers.append(vm_reg->as_KRegister());
514           opmask_spill_size += 8;
515         }
516       } else if (vm_reg->is_XMMRegister()) {
517         // We encode in the low order 4 bits of the opto_reg, how large part of the register is live
518         const VMReg vm_reg_base = OptoReg::as_VMReg(opto_reg & ~15);
519         const int reg_size = xmm_slot_size(opto_reg);
520         const XMMRegisterData reg_data = { vm_reg_base->as_XMMRegister(), reg_size };
521         const int reg_index = _xmm_registers.find(reg_data);
522         if (reg_index == -1) {
523           // Not previously appended
524           _xmm_registers.append(reg_data);
525           xmm_spill_size += reg_size;
526         } else {
527           // Previously appended, update size
528           const int reg_size_prev = _xmm_registers.at(reg_index)._size;
529           if (reg_size > reg_size_prev) {
530             _xmm_registers.at_put(reg_index, reg_data);
531             xmm_spill_size += reg_size - reg_size_prev;
532           }
533         }
534       } else {
535         fatal("Unexpected register type");
536       }
537     }
538 
539     // Sort by size, largest first
540     _xmm_registers.sort(xmm_compare_register_size);
541 
542     // On Windows, the caller reserves stack space for spilling register arguments
543     const int arg_spill_size = frame::arg_reg_save_area_bytes;
544 
545     // Stack pointer must be 16 bytes aligned for the call
546     _spill_offset = _spill_size = align_up(xmm_spill_size + gp_spill_size + opmask_spill_size + arg_spill_size, 16);
547   }
548 PRAGMA_DIAG_POP
549 
550 public:
551   ZSaveLiveRegisters(MacroAssembler* masm, ZLoadBarrierStubC2* stub) :
552       _masm(masm),
553       _gp_registers(),
554       _opmask_registers(),
555       _xmm_registers(),
556       _spill_size(0),
557       _spill_offset(0) {
558 
559     //
560     // Stack layout after registers have been spilled:
561     //
562     // | ...            | original rsp, 16 bytes aligned
563     // ------------------
564     // | zmm0 high      |
565     // | ...            |
566     // | zmm0 low       | 16 bytes aligned
567     // | ...            |
568     // | ymm1 high      |
569     // | ...            |
570     // | ymm1 low       | 16 bytes aligned
571     // | ...            |
572     // | xmmN high      |
573     // | ...            |
574     // | xmmN low       | 8 bytes aligned
575     // | reg0           | 8 bytes aligned
576     // | reg1           |
577     // | ...            |
578     // | regN           | new rsp, if 16 bytes aligned
579     // | <padding>      | else new rsp, 16 bytes aligned
580     // ------------------
581     //
582 
583     // Figure out what registers to save/restore
584     initialize(stub);
585 
586     // Allocate stack space
587     if (_spill_size > 0) {
588       __ subptr(rsp, _spill_size);
589     }
590 
591     // Save XMM/YMM/ZMM registers
592     for (int i = 0; i < _xmm_registers.length(); i++) {
593       xmm_register_save(_xmm_registers.at(i));
594     }
595 
596     if (xmm_needs_vzeroupper()) {
597       __ vzeroupper();
598     }
599 
600     // Save general purpose registers
601     for (int i = 0; i < _gp_registers.length(); i++) {
602       gp_register_save(_gp_registers.at(i));
603     }
604 
605     // Save opmask registers
606     for (int i = 0; i < _opmask_registers.length(); i++) {
607       opmask_register_save(_opmask_registers.at(i));
608     }
609   }
610 
611   ~ZSaveLiveRegisters() {
612     // Restore opmask registers
613     for (int i = _opmask_registers.length() - 1; i >= 0; i--) {
614       opmask_register_restore(_opmask_registers.at(i));
615     }
616 
617     // Restore general purpose registers
618     for (int i = _gp_registers.length() - 1; i >= 0; i--) {
619       gp_register_restore(_gp_registers.at(i));
620     }
621 
622     __ vzeroupper();
623 
624     // Restore XMM/YMM/ZMM registers
625     for (int i = _xmm_registers.length() - 1; i >= 0; i--) {
626       xmm_register_restore(_xmm_registers.at(i));
627     }
628 
629     // Free stack space
630     if (_spill_size > 0) {
631       __ addptr(rsp, _spill_size);
632     }
633   }
634 };
635 
636 class ZSetupArguments {
637 private:
638   MacroAssembler* const _masm;
639   const Register        _ref;
640   const Address         _ref_addr;
641 
642 public:
643   ZSetupArguments(MacroAssembler* masm, ZLoadBarrierStubC2* stub) :
644       _masm(masm),
645       _ref(stub->ref()),
646       _ref_addr(stub->ref_addr()) {
647 
648     // Setup arguments
649     if (_ref_addr.base() == noreg) {
650       // No self healing
651       if (_ref != c_rarg0) {
652         __ movq(c_rarg0, _ref);
653       }
654       __ xorq(c_rarg1, c_rarg1);
655     } else {
656       // Self healing
657       if (_ref == c_rarg0) {
658         __ lea(c_rarg1, _ref_addr);
659       } else if (_ref != c_rarg1) {
660         __ lea(c_rarg1, _ref_addr);
661         __ movq(c_rarg0, _ref);
662       } else if (_ref_addr.base() != c_rarg0 && _ref_addr.index() != c_rarg0) {
663         __ movq(c_rarg0, _ref);
664         __ lea(c_rarg1, _ref_addr);
665       } else {
666         __ xchgq(c_rarg0, c_rarg1);
667         if (_ref_addr.base() == c_rarg0) {
668           __ lea(c_rarg1, Address(c_rarg1, _ref_addr.index(), _ref_addr.scale(), _ref_addr.disp()));
669         } else if (_ref_addr.index() == c_rarg0) {
670           __ lea(c_rarg1, Address(_ref_addr.base(), c_rarg1, _ref_addr.scale(), _ref_addr.disp()));
671         } else {
672           ShouldNotReachHere();
673         }
674       }
675     }
676   }
677 
678   ~ZSetupArguments() {
679     // Transfer result
680     if (_ref != rax) {
681       __ movq(_ref, rax);
682     }
683   }
684 };
685 
686 #undef __
687 #define __ masm->
688 
689 void ZBarrierSetAssembler::generate_c2_load_barrier_stub(MacroAssembler* masm, ZLoadBarrierStubC2* stub) const {
690   BLOCK_COMMENT("ZLoadBarrierStubC2");
691 
692   // Stub entry
693   __ bind(*stub->entry());
694 
695   {
696     ZSaveLiveRegisters save_live_registers(masm, stub);
697     ZSetupArguments setup_arguments(masm, stub);
698     __ call(RuntimeAddress(stub->slow_path()));
699   }
700 
701   // Stub exit
702   __ jmp(*stub->continuation());
703 }
704 
705 #undef __
706 
707 #endif // COMPILER2