1 /*
   2  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "asm/assembler.hpp"
  27 #include "c1/c1_CodeStubs.hpp"
  28 #include "c1/c1_Defs.hpp"
  29 #include "c1/c1_MacroAssembler.hpp"
  30 #include "c1/c1_Runtime1.hpp"
  31 #include "compiler/disassembler.hpp"
  32 #include "compiler/oopMap.hpp"
  33 #include "gc/shared/cardTable.hpp"
  34 #include "gc/shared/cardTableBarrierSet.hpp"
  35 #include "gc/shared/collectedHeap.hpp"
  36 #include "gc/shared/tlab_globals.hpp"
  37 #include "interpreter/interpreter.hpp"
  38 #include "memory/universe.hpp"
  39 #include "nativeInst_aarch64.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/jvmtiExport.hpp"
  42 #include "register_aarch64.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/signature.hpp"
  45 #include "runtime/stubRoutines.hpp"
  46 #include "runtime/vframe.hpp"
  47 #include "runtime/vframeArray.hpp"
  48 #include "utilities/powerOfTwo.hpp"
  49 #include "vmreg_aarch64.inline.hpp"
  50 
  51 
  52 // Implementation of StubAssembler
  53 
  54 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, int args_size) {
  55   // setup registers
  56   assert(!(oop_result1->is_valid() || metadata_result->is_valid()) || oop_result1 != metadata_result, "registers must be different");
  57   assert(oop_result1 != rthread && metadata_result != rthread, "registers must be different");
  58   assert(args_size >= 0, "illegal args_size");
  59   bool align_stack = false;
  60 
  61   mov(c_rarg0, rthread);
  62   set_num_rt_args(0); // Nothing on stack
  63 
  64   Label retaddr;
  65   set_last_Java_frame(sp, rfp, retaddr, rscratch1);
  66 
  67   // do the call
  68   lea(rscratch1, RuntimeAddress(entry));
  69   blr(rscratch1);
  70   bind(retaddr);
  71   int call_offset = offset();
  72   // verify callee-saved register
  73 #ifdef ASSERT
  74   push(r0, sp);
  75   { Label L;
  76     get_thread(r0);
  77     cmp(rthread, r0);
  78     br(Assembler::EQ, L);
  79     stop("StubAssembler::call_RT: rthread not callee saved?");
  80     bind(L);
  81   }
  82   pop(r0, sp);
  83 #endif
  84   reset_last_Java_frame(true);
  85 
  86   // check for pending exceptions
  87   { Label L;
  88     // check for pending exceptions (java_thread is set upon return)
  89     ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset())));
  90     cbz(rscratch1, L);
  91     // exception pending => remove activation and forward to exception handler
  92     // make sure that the vm_results are cleared
  93     if (oop_result1->is_valid()) {
  94       str(zr, Address(rthread, JavaThread::vm_result_oop_offset()));
  95     }
  96     if (metadata_result->is_valid()) {
  97       str(zr, Address(rthread, JavaThread::vm_result_metadata_offset()));
  98     }
  99     if (frame_size() == no_frame_size) {
 100       leave();
 101       far_jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
 102     } else if (_stub_id == (int)StubId::c1_forward_exception_id) {
 103       should_not_reach_here();
 104     } else {
 105       far_jump(RuntimeAddress(Runtime1::entry_for(StubId::c1_forward_exception_id)));
 106     }
 107     bind(L);
 108   }
 109   // get oop results if there are any and reset the values in the thread
 110   if (oop_result1->is_valid()) {
 111     get_vm_result_oop(oop_result1, rthread);
 112   }
 113   if (metadata_result->is_valid()) {
 114     get_vm_result_metadata(metadata_result, rthread);
 115   }
 116   return call_offset;
 117 }
 118 
 119 
 120 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {
 121   mov(c_rarg1, arg1);
 122   return call_RT(oop_result1, metadata_result, entry, 1);
 123 }
 124 
 125 
 126 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {
 127   if (c_rarg1 == arg2) {
 128     if (c_rarg2 == arg1) {
 129       mov(rscratch1, arg1);
 130       mov(arg1, arg2);
 131       mov(arg2, rscratch1);
 132     } else {
 133       mov(c_rarg2, arg2);
 134       mov(c_rarg1, arg1);
 135     }
 136   } else {
 137     mov(c_rarg1, arg1);
 138     mov(c_rarg2, arg2);
 139   }
 140   return call_RT(oop_result1, metadata_result, entry, 2);
 141 }
 142 
 143 
 144 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {
 145   // if there is any conflict use the stack
 146   if (arg1 == c_rarg2 || arg1 == c_rarg3 ||
 147       arg2 == c_rarg1 || arg2 == c_rarg3 ||
 148       arg3 == c_rarg1 || arg3 == c_rarg2) {
 149     stp(arg3, arg2, Address(pre(sp, -2 * wordSize)));
 150     stp(arg1, zr, Address(pre(sp, -2 * wordSize)));
 151     ldp(c_rarg1, zr, Address(post(sp, 2 * wordSize)));
 152     ldp(c_rarg3, c_rarg2, Address(post(sp, 2 * wordSize)));
 153   } else {
 154     mov(c_rarg1, arg1);
 155     mov(c_rarg2, arg2);
 156     mov(c_rarg3, arg3);
 157   }
 158   return call_RT(oop_result1, metadata_result, entry, 3);
 159 }
 160 
 161 enum return_state_t {
 162   does_not_return, requires_return, requires_pop_epilogue_return
 163 };
 164 
 165 // Implementation of StubFrame
 166 
 167 class StubFrame: public StackObj {
 168  private:
 169   StubAssembler* _sasm;
 170   return_state_t _return_state;
 171 
 172  public:
 173   StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments, return_state_t return_state=requires_return);
 174   void load_argument(int offset_in_words, Register reg);
 175 
 176   ~StubFrame();
 177 };;
 178 
 179 void StubAssembler::prologue(const char* name, bool must_gc_arguments) {
 180   set_info(name, must_gc_arguments);
 181   enter();
 182 }
 183 
 184 void StubAssembler::epilogue(bool use_pop) {
 185   // Avoid using a leave instruction when this frame may
 186   // have been frozen, since the current value of rfp
 187   // restored from the stub would be invalid. We still
 188   // must restore the rfp value saved on enter though.
 189   if (use_pop) {
 190     ldp(rfp, lr, Address(post(sp, 2 * wordSize)));
 191     authenticate_return_address();
 192   } else {
 193     leave();
 194   }
 195   ret(lr);
 196 }
 197 
 198 #define __ _sasm->
 199 
 200 StubFrame::StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments, return_state_t return_state) {
 201   _sasm = sasm;
 202   _return_state = return_state;
 203   __ prologue(name, must_gc_arguments);
 204 }
 205 
 206 // load parameters that were stored with LIR_Assembler::store_parameter
 207 // Note: offsets for store_parameter and load_argument must match
 208 void StubFrame::load_argument(int offset_in_words, Register reg) {
 209   __ load_parameter(offset_in_words, reg);
 210 }
 211 
 212 StubFrame::~StubFrame() {
 213   if (_return_state == does_not_return) {
 214     __ should_not_reach_here();
 215   } else {
 216     __ epilogue(_return_state == requires_pop_epilogue_return);
 217   }
 218 }
 219 
 220 #undef __
 221 
 222 
 223 // Implementation of Runtime1
 224 
 225 #define __ sasm->
 226 
 227 const int float_regs_as_doubles_size_in_slots = pd_nof_fpu_regs_frame_map * 2;
 228 
 229 // Stack layout for saving/restoring  all the registers needed during a runtime
 230 // call (this includes deoptimization)
 231 // Note: note that users of this frame may well have arguments to some runtime
 232 // while these values are on the stack. These positions neglect those arguments
 233 // but the code in save_live_registers will take the argument count into
 234 // account.
 235 //
 236 
 237 enum reg_save_layout {
 238   reg_save_frame_size = 32 /* float */ + 32 /* integer */
 239 };
 240 
 241 // Save off registers which might be killed by calls into the runtime.
 242 // Tries to smart of about FP registers.  In particular we separate
 243 // saving and describing the FPU registers for deoptimization since we
 244 // have to save the FPU registers twice if we describe them.  The
 245 // deopt blob is the only thing which needs to describe FPU registers.
 246 // In all other cases it should be sufficient to simply save their
 247 // current value.
 248 
 249 static int cpu_reg_save_offsets[FrameMap::nof_cpu_regs];
 250 static int fpu_reg_save_offsets[FrameMap::nof_fpu_regs];
 251 static int reg_save_size_in_words;
 252 static int frame_size_in_bytes = -1;
 253 
 254 static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) {
 255   int frame_size_in_bytes = reg_save_frame_size * BytesPerWord;
 256   sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
 257   int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
 258   OopMap* oop_map = new OopMap(frame_size_in_slots, 0);
 259 
 260   for (int i = 0; i < FrameMap::nof_caller_save_cpu_regs(); i++) {
 261     LIR_Opr opr = FrameMap::caller_save_cpu_reg_at(i);
 262     Register r = opr->as_register();
 263     int reg_num = r->encoding();
 264     int sp_offset = cpu_reg_save_offsets[reg_num];
 265     oop_map->set_callee_saved(VMRegImpl::stack2reg(cpu_reg_save_offsets[reg_num]), r->as_VMReg());
 266   }
 267 
 268   Register r = rthread;
 269   int reg_num = r->encoding();
 270   oop_map->set_callee_saved(VMRegImpl::stack2reg(cpu_reg_save_offsets[reg_num]), r->as_VMReg());
 271 
 272   if (save_fpu_registers) {
 273     for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
 274       FloatRegister r = as_FloatRegister(i);
 275       {
 276         int sp_offset = fpu_reg_save_offsets[i];
 277         oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
 278                                   r->as_VMReg());
 279       }
 280     }
 281   }
 282   return oop_map;
 283 }
 284 
 285 static OopMap* save_live_registers(StubAssembler* sasm,
 286                                    bool save_fpu_registers = true) {
 287   __ block_comment("save_live_registers");
 288 
 289   __ push(RegSet::range(r0, r29), sp);         // integer registers except lr & sp
 290 
 291   if (save_fpu_registers) {
 292     for (int i = 31; i>= 0; i -= 4) {
 293       __ sub(sp, sp, 4 * wordSize); // no pre-increment for st1. Emulate it without modifying other registers
 294       __ st1(as_FloatRegister(i-3), as_FloatRegister(i-2), as_FloatRegister(i-1),
 295           as_FloatRegister(i), __ T1D, Address(sp));
 296     }
 297   } else {
 298     __ add(sp, sp, -32 * wordSize);
 299   }
 300 
 301   return generate_oop_map(sasm, save_fpu_registers);
 302 }
 303 
 304 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
 305   if (restore_fpu_registers) {
 306     for (int i = 0; i < 32; i += 4)
 307       __ ld1(as_FloatRegister(i), as_FloatRegister(i+1), as_FloatRegister(i+2),
 308           as_FloatRegister(i+3), __ T1D, Address(__ post(sp, 4 * wordSize)));
 309   } else {
 310     __ add(sp, sp, 32 * wordSize);
 311   }
 312 
 313 #ifdef R18_RESERVED
 314   /*
 315   Do not modify r18_tls when restoring registers if it is a reserved register. On Windows,
 316   for example, r18_tls is used to store the pointer to the current thread's TEB (where TLS
 317   variables are stored). Therefore, modifying r18_tls would corrupt the TEB pointer.
 318   */
 319   __ pop(RegSet::range(r0, r17), sp);
 320   __ ldp(zr, r19, Address(__ post(sp, 2 * wordSize)));
 321   __ pop(RegSet::range(r20, r29), sp);
 322 #else
 323   __ pop(RegSet::range(r0, r29), sp);
 324 #endif
 325 }
 326 
 327 static void restore_live_registers_except_r0(StubAssembler* sasm, bool restore_fpu_registers = true)  {
 328 
 329   if (restore_fpu_registers) {
 330     for (int i = 0; i < 32; i += 4)
 331       __ ld1(as_FloatRegister(i), as_FloatRegister(i+1), as_FloatRegister(i+2),
 332           as_FloatRegister(i+3), __ T1D, Address(__ post(sp, 4 * wordSize)));
 333   } else {
 334     __ add(sp, sp, 32 * wordSize);
 335   }
 336 
 337 #ifdef R18_RESERVED
 338   /*
 339   Do not modify r18_tls when restoring registers if it is a reserved register. On Windows,
 340   for example, r18_tls is used to store the pointer to the current thread's TEB (where TLS
 341   variables are stored). Therefore, modifying r18_tls would corrupt the TEB pointer.
 342   */
 343   __ ldp(zr, r1, Address(__ post(sp, 2 * wordSize)));
 344   __ pop(RegSet::range(r2, r17), sp);
 345   __ ldp(zr, r19, Address(__ post(sp, 2 * wordSize)));
 346   __ pop(RegSet::range(r20, r29), sp);
 347 #else
 348   __ ldp(zr, r1, Address(__ post(sp, 16)));
 349   __ pop(RegSet::range(r2, r29), sp);
 350 #endif
 351 }
 352 
 353 
 354 
 355 void Runtime1::initialize_pd() {
 356   int i;
 357   int sp_offset = 0;
 358 
 359   // all float registers are saved explicitly
 360   assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here");
 361   for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 362     fpu_reg_save_offsets[i] = sp_offset;
 363     sp_offset += 2;   // SP offsets are in halfwords
 364   }
 365 
 366   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 367     Register r = as_Register(i);
 368     cpu_reg_save_offsets[i] = sp_offset;
 369     sp_offset += 2;   // SP offsets are in halfwords
 370   }
 371 }
 372 
 373 // return: offset in 64-bit words.
 374 uint Runtime1::runtime_blob_current_thread_offset(frame f) {
 375   CodeBlob* cb = f.cb();
 376   assert(cb == Runtime1::blob_for(StubId::c1_monitorenter_id) ||
 377          cb == Runtime1::blob_for(StubId::c1_monitorenter_nofpu_id), "must be");
 378   assert(cb != nullptr && cb->is_runtime_stub(), "invalid frame");
 379   int offset = cpu_reg_save_offsets[rthread->encoding()];
 380   return offset / 2;   // SP offsets are in halfwords
 381 }
 382 
 383 // target: the entry point of the method that creates and posts the exception oop
 384 // has_argument: true if the exception needs arguments (passed in rscratch1 and rscratch2)
 385 
 386 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
 387   // make a frame and preserve the caller's caller-save registers
 388   OopMap* oop_map = save_live_registers(sasm);
 389   int call_offset;
 390   if (!has_argument) {
 391     call_offset = __ call_RT(noreg, noreg, target);
 392   } else {
 393     __ mov(c_rarg1, rscratch1);
 394     __ mov(c_rarg2, rscratch2);
 395     call_offset = __ call_RT(noreg, noreg, target);
 396   }
 397   OopMapSet* oop_maps = new OopMapSet();
 398   oop_maps->add_gc_map(call_offset, oop_map);
 399   return oop_maps;
 400 }
 401 
 402 
 403 OopMapSet* Runtime1::generate_handle_exception(StubId id, StubAssembler *sasm) {
 404   __ block_comment("generate_handle_exception");
 405 
 406   // incoming parameters
 407   const Register exception_oop = r0;
 408   const Register exception_pc  = r3;
 409   // other registers used in this stub
 410 
 411   // Save registers, if required.
 412   OopMapSet* oop_maps = new OopMapSet();
 413   OopMap* oop_map = nullptr;
 414   switch (id) {
 415   case StubId::c1_forward_exception_id:
 416     // We're handling an exception in the context of a compiled frame.
 417     // The registers have been saved in the standard places.  Perform
 418     // an exception lookup in the caller and dispatch to the handler
 419     // if found.  Otherwise unwind and dispatch to the callers
 420     // exception handler.
 421     oop_map = generate_oop_map(sasm, 1 /*thread*/);
 422 
 423     // load and clear pending exception oop into r0
 424     __ ldr(exception_oop, Address(rthread, Thread::pending_exception_offset()));
 425     __ str(zr, Address(rthread, Thread::pending_exception_offset()));
 426 
 427     // load issuing PC (the return address for this stub) into r3
 428     __ ldr(exception_pc, Address(rfp, 1*BytesPerWord));
 429     __ authenticate_return_address(exception_pc);
 430 
 431     // make sure that the vm_results are cleared (may be unnecessary)
 432     __ str(zr, Address(rthread, JavaThread::vm_result_oop_offset()));
 433     __ str(zr, Address(rthread, JavaThread::vm_result_metadata_offset()));
 434     break;
 435   case StubId::c1_handle_exception_nofpu_id:
 436   case StubId::c1_handle_exception_id:
 437     // At this point all registers MAY be live.
 438     oop_map = save_live_registers(sasm, id != StubId::c1_handle_exception_nofpu_id);
 439     break;
 440   case StubId::c1_handle_exception_from_callee_id: {
 441     // At this point all registers except exception oop (r0) and
 442     // exception pc (lr) are dead.
 443     const int frame_size = 2 /*fp, return address*/;
 444     oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);
 445     sasm->set_frame_size(frame_size);
 446     break;
 447   }
 448   default: ShouldNotReachHere();
 449   }
 450 
 451   // verify that only r0 and r3 are valid at this time
 452   __ invalidate_registers(false, true, true, false, true, true);
 453   // verify that r0 contains a valid exception
 454   __ verify_not_null_oop(exception_oop);
 455 
 456 #ifdef ASSERT
 457   // check that fields in JavaThread for exception oop and issuing pc are
 458   // empty before writing to them
 459   Label oop_empty;
 460   __ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
 461   __ cbz(rscratch1, oop_empty);
 462   __ stop("exception oop already set");
 463   __ bind(oop_empty);
 464 
 465   Label pc_empty;
 466   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 467   __ cbz(rscratch1, pc_empty);
 468   __ stop("exception pc already set");
 469   __ bind(pc_empty);
 470 #endif
 471 
 472   // save exception oop and issuing pc into JavaThread
 473   // (exception handler will load it from here)
 474   __ str(exception_oop, Address(rthread, JavaThread::exception_oop_offset()));
 475   __ str(exception_pc, Address(rthread, JavaThread::exception_pc_offset()));
 476 
 477   // patch throwing pc into return address (has bci & oop map)
 478   __ protect_return_address(exception_pc);
 479   __ str(exception_pc, Address(rfp, 1*BytesPerWord));
 480 
 481   // compute the exception handler.
 482   // the exception oop and the throwing pc are read from the fields in JavaThread
 483   int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
 484   oop_maps->add_gc_map(call_offset, oop_map);
 485 
 486   // r0: handler address
 487   //      will be the deopt blob if nmethod was deoptimized while we looked up
 488   //      handler regardless of whether handler existed in the nmethod.
 489 
 490   // only r0 is valid at this time, all other registers have been destroyed by the runtime call
 491   __ invalidate_registers(false, true, true, true, true, true);
 492 
 493   // patch the return address, this stub will directly return to the exception handler
 494   __ protect_return_address(r0);
 495   __ str(r0, Address(rfp, 1*BytesPerWord));
 496 
 497   switch (id) {
 498   case StubId::c1_forward_exception_id:
 499   case StubId::c1_handle_exception_nofpu_id:
 500   case StubId::c1_handle_exception_id:
 501     // Restore the registers that were saved at the beginning.
 502     restore_live_registers(sasm, id != StubId::c1_handle_exception_nofpu_id);
 503     break;
 504   case StubId::c1_handle_exception_from_callee_id:
 505     break;
 506   default:  ShouldNotReachHere();
 507   }
 508 
 509   return oop_maps;
 510 }
 511 
 512 
 513 void Runtime1::generate_unwind_exception(StubAssembler *sasm) {
 514   // incoming parameters
 515   const Register exception_oop = r0;
 516   // callee-saved copy of exception_oop during runtime call
 517   const Register exception_oop_callee_saved = r19;
 518   // other registers used in this stub
 519   const Register exception_pc = r3;
 520   const Register handler_addr = r1;
 521 
 522   if (AbortVMOnException) {
 523     __ mov(rscratch1, exception_oop);
 524     __ enter();
 525     save_live_registers(sasm);
 526     __ call_VM_leaf(CAST_FROM_FN_PTR(address, check_abort_on_vm_exception), rscratch1);
 527     restore_live_registers(sasm);
 528     __ leave();
 529   }
 530 
 531   // verify that only r0, is valid at this time
 532   __ invalidate_registers(false, true, true, true, true, true);
 533 
 534 #ifdef ASSERT
 535   // check that fields in JavaThread for exception oop and issuing pc are empty
 536   Label oop_empty;
 537   __ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
 538   __ cbz(rscratch1, oop_empty);
 539   __ stop("exception oop must be empty");
 540   __ bind(oop_empty);
 541 
 542   Label pc_empty;
 543   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 544   __ cbz(rscratch1, pc_empty);
 545   __ stop("exception pc must be empty");
 546   __ bind(pc_empty);
 547 #endif
 548 
 549   // Save our return address because
 550   // exception_handler_for_return_address will destroy it.  We also
 551   // save exception_oop
 552   __ mov(r3, lr);
 553   __ protect_return_address();
 554   __ stp(lr, exception_oop, Address(__ pre(sp, -2 * wordSize)));
 555 
 556   // search the exception handler address of the caller (using the return address)
 557   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), rthread, r3);
 558   // r0: exception handler address of the caller
 559 
 560   // Only R0 is valid at this time; all other registers have been
 561   // destroyed by the call.
 562   __ invalidate_registers(false, true, true, true, false, true);
 563 
 564   // move result of call into correct register
 565   __ mov(handler_addr, r0);
 566 
 567   // get throwing pc (= return address).
 568   // lr has been destroyed by the call
 569   __ ldp(lr, exception_oop, Address(__ post(sp, 2 * wordSize)));
 570   __ authenticate_return_address();
 571   __ mov(r3, lr);
 572 
 573   __ verify_not_null_oop(exception_oop);
 574 
 575   // continue at exception handler (return address removed)
 576   // note: do *not* remove arguments when unwinding the
 577   //       activation since the caller assumes having
 578   //       all arguments on the stack when entering the
 579   //       runtime to determine the exception handler
 580   //       (GC happens at call site with arguments!)
 581   // r0: exception oop
 582   // r3: throwing pc
 583   // r1: exception handler
 584   __ br(handler_addr);
 585 }
 586 
 587 
 588 
 589 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
 590   // use the maximum number of runtime-arguments here because it is difficult to
 591   // distinguish each RT-Call.
 592   // Note: This number affects also the RT-Call in generate_handle_exception because
 593   //       the oop-map is shared for all calls.
 594   DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 595   assert(deopt_blob != nullptr, "deoptimization blob must have been created");
 596 
 597   OopMap* oop_map = save_live_registers(sasm);
 598 
 599   __ mov(c_rarg0, rthread);
 600   Label retaddr;
 601   __ set_last_Java_frame(sp, rfp, retaddr, rscratch1);
 602   // do the call
 603   __ lea(rscratch1, RuntimeAddress(target));
 604   __ blr(rscratch1);
 605   __ bind(retaddr);
 606   OopMapSet* oop_maps = new OopMapSet();
 607   oop_maps->add_gc_map(__ offset(), oop_map);
 608   // verify callee-saved register
 609 #ifdef ASSERT
 610   { Label L;
 611     __ get_thread(rscratch1);
 612     __ cmp(rthread, rscratch1);
 613     __ br(Assembler::EQ, L);
 614     __ stop("StubAssembler::call_RT: rthread not callee saved?");
 615     __ bind(L);
 616   }
 617 #endif
 618 
 619   __ reset_last_Java_frame(true);
 620 
 621 #ifdef ASSERT
 622   // check that fields in JavaThread for exception oop and issuing pc are empty
 623   Label oop_empty;
 624   __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
 625   __ cbz(rscratch1, oop_empty);
 626   __ stop("exception oop must be empty");
 627   __ bind(oop_empty);
 628 
 629   Label pc_empty;
 630   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 631   __ cbz(rscratch1, pc_empty);
 632   __ stop("exception pc must be empty");
 633   __ bind(pc_empty);
 634 #endif
 635 
 636   // Runtime will return true if the nmethod has been deoptimized, this is the
 637   // expected scenario and anything else is  an error. Note that we maintain a
 638   // check on the result purely as a defensive measure.
 639   Label no_deopt;
 640   __ cbz(r0, no_deopt);                                // Have we deoptimized?
 641 
 642   // Perform a re-execute. The proper return  address is already on the stack,
 643   // we just need  to restore registers, pop  all of our frame  but the return
 644   // address and jump to the deopt blob.
 645   restore_live_registers(sasm);
 646   __ leave();
 647   __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
 648 
 649   __ bind(no_deopt);
 650   __ stop("deopt not performed");
 651 
 652   return oop_maps;
 653 }
 654 
 655 
 656 OopMapSet* Runtime1::generate_code_for(StubId id, StubAssembler* sasm) {
 657 
 658   const Register exception_oop = r0;
 659   const Register exception_pc  = r3;
 660 
 661   // for better readability
 662   const bool must_gc_arguments = true;
 663   const bool dont_gc_arguments = false;
 664 
 665   // default value; overwritten for some optimized stubs that are called from methods that do not use the fpu
 666   bool save_fpu_registers = true;
 667 
 668   // stub code & info for the different stubs
 669   OopMapSet* oop_maps = nullptr;
 670   OopMap* oop_map = nullptr;
 671   switch (id) {
 672     {
 673     case StubId::c1_forward_exception_id:
 674       {
 675         oop_maps = generate_handle_exception(id, sasm);
 676         __ leave();
 677         __ ret(lr);
 678       }
 679       break;
 680 
 681     case StubId::c1_throw_div0_exception_id:
 682       { StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments, does_not_return);
 683         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
 684       }
 685       break;
 686 
 687     case StubId::c1_throw_null_pointer_exception_id:
 688       { StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments, does_not_return);
 689         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
 690       }
 691       break;
 692 
 693     case StubId::c1_new_instance_id:
 694     case StubId::c1_fast_new_instance_id:
 695     case StubId::c1_fast_new_instance_init_check_id:
 696       {
 697         Register klass = r3; // Incoming
 698         Register obj   = r0; // Result
 699 
 700         if (id == StubId::c1_new_instance_id) {
 701           __ set_info("new_instance", dont_gc_arguments);
 702         } else if (id == StubId::c1_fast_new_instance_id) {
 703           __ set_info("fast new_instance", dont_gc_arguments);
 704         } else {
 705           assert(id == StubId::c1_fast_new_instance_init_check_id, "bad StubId");
 706           __ set_info("fast new_instance init check", dont_gc_arguments);
 707         }
 708 
 709         __ enter();
 710         OopMap* map = save_live_registers(sasm);
 711         int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);
 712         oop_maps = new OopMapSet();
 713         oop_maps->add_gc_map(call_offset, map);
 714         restore_live_registers_except_r0(sasm);
 715         __ verify_oop(obj);
 716         __ leave();
 717         __ ret(lr);
 718 
 719         // r0,: new instance
 720       }
 721 
 722       break;
 723 
 724     case StubId::c1_counter_overflow_id:
 725       {
 726         Register bci = r0, method = r1;
 727         __ enter();
 728         OopMap* map = save_live_registers(sasm);
 729         // Retrieve bci
 730         __ ldrw(bci, Address(rfp, 2*BytesPerWord));
 731         // And a pointer to the Method*
 732         __ ldr(method, Address(rfp, 3*BytesPerWord));
 733         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);
 734         oop_maps = new OopMapSet();
 735         oop_maps->add_gc_map(call_offset, map);
 736         restore_live_registers(sasm);
 737         __ leave();
 738         __ ret(lr);
 739       }
 740       break;
 741 
 742     case StubId::c1_new_type_array_id:
 743     case StubId::c1_new_object_array_id:
 744     case StubId::c1_new_null_free_array_id:
 745       {
 746         Register length   = r19; // Incoming
 747         Register klass    = r3; // Incoming
 748         Register obj      = r0; // Result
 749 
 750         if (id == StubId::c1_new_type_array_id) {
 751           __ set_info("new_type_array", dont_gc_arguments);
 752         } else if (id == StubId::c1_new_object_array_id) {
 753           __ set_info("new_object_array", dont_gc_arguments);
 754         } else {
 755           __ set_info("new_null_free_array", dont_gc_arguments);
 756         }
 757 
 758 #ifdef ASSERT
 759         // assert object type is really an array of the proper kind
 760         {
 761           Label ok;
 762           Register t0 = obj;
 763           __ ldrw(t0, Address(klass, Klass::layout_helper_offset()));
 764           __ asrw(t0, t0, Klass::_lh_array_tag_shift);
 765           switch (id) {
 766           case StubId::c1_new_type_array_id:
 767             __ cmpw(t0, Klass::_lh_array_tag_type_value);
 768             __ br(Assembler::EQ, ok);
 769             __ stop("assert(is a type array klass)");
 770             break;
 771           case StubId::c1_new_object_array_id:
 772             __ cmpw(t0, Klass::_lh_array_tag_ref_value); // new "[Ljava/lang/Object;"
 773             __ br(Assembler::EQ, ok);
 774             __ cmpw(t0, Klass::_lh_array_tag_flat_value);  // new "[LVT;"
 775             __ br(Assembler::EQ, ok);
 776             __ stop("assert(is an object or inline type array klass)");
 777             break;
 778           case StubId::c1_new_null_free_array_id:
 779             __ cmpw(t0, Klass::_lh_array_tag_flat_value);  // the array can be a flat array.
 780             __ br(Assembler::EQ, ok);
 781             __ cmpw(t0, Klass::_lh_array_tag_ref_value); // the array cannot be a flat array (due to the InlineArrayElementMaxFlatSize, etc.)
 782             __ br(Assembler::EQ, ok);
 783             __ stop("assert(is an object or inline type array klass)");
 784             break;
 785           default:  ShouldNotReachHere();
 786           }
 787           __ should_not_reach_here();
 788           __ bind(ok);
 789         }
 790 #endif // ASSERT
 791 
 792         __ enter();
 793         OopMap* map = save_live_registers(sasm);
 794         int call_offset;
 795         if (id == StubId::c1_new_type_array_id) {
 796           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);
 797         } else if (id == StubId::c1_new_object_array_id) {
 798           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);
 799         } else {
 800           assert(id == StubId::c1_new_null_free_array_id, "must be");
 801           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_null_free_array), klass, length);
 802         }
 803 
 804         oop_maps = new OopMapSet();
 805         oop_maps->add_gc_map(call_offset, map);
 806         restore_live_registers_except_r0(sasm);
 807 
 808         __ verify_oop(obj);
 809         __ leave();
 810         __ ret(lr);
 811 
 812         // r0: new array
 813       }
 814       break;
 815 
 816     case StubId::c1_new_multi_array_id:
 817       { StubFrame f(sasm, "new_multi_array", dont_gc_arguments);
 818         // r0,: klass
 819         // r19,: rank
 820         // r2: address of 1st dimension
 821         OopMap* map = save_live_registers(sasm);
 822         __ mov(c_rarg1, r0);
 823         __ mov(c_rarg3, r2);
 824         __ mov(c_rarg2, r19);
 825         int call_offset = __ call_RT(r0, noreg, CAST_FROM_FN_PTR(address, new_multi_array), r1, r2, r3);
 826 
 827         oop_maps = new OopMapSet();
 828         oop_maps->add_gc_map(call_offset, map);
 829         restore_live_registers_except_r0(sasm);
 830 
 831         // r0,: new multi array
 832         __ verify_oop(r0);
 833       }
 834       break;
 835 
 836     case StubId::c1_buffer_inline_args_id:
 837     case StubId::c1_buffer_inline_args_no_receiver_id:
 838       {
 839         const char* name = (id == StubId::c1_buffer_inline_args_id) ?
 840           "buffer_inline_args" : "buffer_inline_args_no_receiver";
 841         StubFrame f(sasm, name, dont_gc_arguments);
 842         OopMap* map = save_live_registers(sasm);
 843         Register method = r19;   // Incoming
 844         address entry = (id == StubId::c1_buffer_inline_args_id) ?
 845           CAST_FROM_FN_PTR(address, buffer_inline_args) :
 846           CAST_FROM_FN_PTR(address, buffer_inline_args_no_receiver);
 847         // This is called from a C1 method's scalarized entry point
 848         // where r0-r7 may be holding live argument values so we can't
 849         // return the result in r0 as the other stubs do. LR is used as
 850         // a temporary below to avoid the result being clobbered by
 851         // restore_live_registers. It's saved and restored by
 852         // StubAssembler::prologue and epilogue anyway.
 853         int call_offset = __ call_RT(lr, noreg, entry, method);
 854         oop_maps = new OopMapSet();
 855         oop_maps->add_gc_map(call_offset, map);
 856         restore_live_registers(sasm);
 857         __ mov(r20, lr);
 858         __ verify_oop(r20);  // r20: an array of buffered value objects
 859      }
 860      break;
 861 
 862     case StubId::c1_load_flat_array_id:
 863       {
 864         StubFrame f(sasm, "load_flat_array", dont_gc_arguments);
 865         OopMap* map = save_live_registers(sasm);
 866 
 867         // Called with store_parameter and not C abi
 868 
 869         f.load_argument(1, r0); // r0,: array
 870         f.load_argument(0, r1); // r1,: index
 871         int call_offset = __ call_RT(r0, noreg, CAST_FROM_FN_PTR(address, load_flat_array), r0, r1);
 872 
 873         // Ensure the stores that initialize the buffer are visible
 874         // before any subsequent store that publishes this reference.
 875         __ membar(Assembler::StoreStore);
 876 
 877         oop_maps = new OopMapSet();
 878         oop_maps->add_gc_map(call_offset, map);
 879         restore_live_registers_except_r0(sasm);
 880 
 881         // r0: loaded element at array[index]
 882         __ verify_oop(r0);
 883       }
 884       break;
 885 
 886     case StubId::c1_store_flat_array_id:
 887       {
 888         StubFrame f(sasm, "store_flat_array", dont_gc_arguments);
 889         OopMap* map = save_live_registers(sasm);
 890 
 891         // Called with store_parameter and not C abi
 892 
 893         f.load_argument(2, r0); // r0: array
 894         f.load_argument(1, r1); // r1: index
 895         f.load_argument(0, r2); // r2: value
 896         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, store_flat_array), r0, r1, r2);
 897 
 898         oop_maps = new OopMapSet();
 899         oop_maps->add_gc_map(call_offset, map);
 900         restore_live_registers_except_r0(sasm);
 901       }
 902       break;
 903 
 904     case StubId::c1_substitutability_check_id:
 905       {
 906         StubFrame f(sasm, "substitutability_check", dont_gc_arguments);
 907         OopMap* map = save_live_registers(sasm);
 908 
 909         // Called with store_parameter and not C abi
 910 
 911         f.load_argument(1, r1); // r1,: left
 912         f.load_argument(0, r2); // r2,: right
 913         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, substitutability_check), r1, r2);
 914 
 915         oop_maps = new OopMapSet();
 916         oop_maps->add_gc_map(call_offset, map);
 917         restore_live_registers_except_r0(sasm);
 918 
 919         // r0,: are the two operands substitutable
 920       }
 921       break;
 922 
 923     case StubId::c1_register_finalizer_id:
 924       {
 925         __ set_info("register_finalizer", dont_gc_arguments);
 926 
 927         // This is called via call_runtime so the arguments
 928         // will be place in C abi locations
 929 
 930         __ verify_oop(c_rarg0);
 931 
 932         // load the klass and check the has finalizer flag
 933         Label register_finalizer;
 934         Register t = r5;
 935         __ load_klass(t, r0);
 936         __ ldrb(t, Address(t, Klass::misc_flags_offset()));
 937         __ tbnz(t, exact_log2(KlassFlags::_misc_has_finalizer), register_finalizer);
 938         __ ret(lr);
 939 
 940         __ bind(register_finalizer);
 941         __ enter();
 942         OopMap* oop_map = save_live_registers(sasm);
 943         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), r0);
 944         oop_maps = new OopMapSet();
 945         oop_maps->add_gc_map(call_offset, oop_map);
 946 
 947         // Now restore all the live registers
 948         restore_live_registers(sasm);
 949 
 950         __ leave();
 951         __ ret(lr);
 952       }
 953       break;
 954 
 955     case StubId::c1_throw_class_cast_exception_id:
 956       { StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments, does_not_return);
 957         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
 958       }
 959       break;
 960 
 961     case StubId::c1_throw_incompatible_class_change_error_id:
 962       { StubFrame f(sasm, "throw_incompatible_class_change_error", dont_gc_arguments, does_not_return);
 963         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
 964       }
 965       break;
 966 
 967     case StubId::c1_throw_illegal_monitor_state_exception_id:
 968       { StubFrame f(sasm, "throw_illegal_monitor_state_exception", dont_gc_arguments);
 969         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_illegal_monitor_state_exception), false);
 970       }
 971       break;
 972 
 973     case StubId::c1_throw_identity_exception_id:
 974       { StubFrame f(sasm, "throw_identity_exception", dont_gc_arguments);
 975         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_identity_exception), true);
 976       }
 977       break;
 978 
 979     case StubId::c1_slow_subtype_check_id:
 980       {
 981         // Typical calling sequence:
 982         // __ push(klass_RInfo);  // object klass or other subclass
 983         // __ push(sup_k_RInfo);  // array element klass or other superclass
 984         // __ bl(slow_subtype_check);
 985         // Note that the subclass is pushed first, and is therefore deepest.
 986         enum layout {
 987           r0_off, r0_off_hi,
 988           r2_off, r2_off_hi,
 989           r4_off, r4_off_hi,
 990           r5_off, r5_off_hi,
 991           sup_k_off, sup_k_off_hi,
 992           klass_off, klass_off_hi,
 993           framesize,
 994           result_off = sup_k_off
 995         };
 996 
 997         __ set_info("slow_subtype_check", dont_gc_arguments);
 998         __ push(RegSet::of(r0, r2, r4, r5), sp);
 999 
1000         // This is called by pushing args and not with C abi
1001         // __ ldr(r4, Address(sp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass
1002         // __ ldr(r0, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass
1003 
1004         __ ldp(r4, r0, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size));
1005 
1006         Label miss;
1007         __ check_klass_subtype_slow_path(/*sub_klass*/r4,
1008                                          /*super_klass*/r0,
1009                                          /*temp_reg*/r2,
1010                                          /*temp2_reg*/r5,
1011                                          /*L_success*/nullptr,
1012                                          /*L_failure*/&miss);
1013         // Need extras for table lookup: r1, r3, vtemp
1014 
1015         // fallthrough on success:
1016         __ mov(rscratch1, 1);
1017         __ str(rscratch1, Address(sp, (result_off) * VMRegImpl::stack_slot_size)); // result
1018         __ pop(RegSet::of(r0, r2, r4, r5), sp);
1019         __ ret(lr);
1020 
1021         __ bind(miss);
1022         __ str(zr, Address(sp, (result_off) * VMRegImpl::stack_slot_size)); // result
1023         __ pop(RegSet::of(r0, r2, r4, r5), sp);
1024         __ ret(lr);
1025       }
1026       break;
1027 
1028     case StubId::c1_monitorenter_nofpu_id:
1029       save_fpu_registers = false;
1030       // fall through
1031     case StubId::c1_monitorenter_id:
1032       {
1033         StubFrame f(sasm, "monitorenter", dont_gc_arguments, requires_pop_epilogue_return);
1034         OopMap* map = save_live_registers(sasm, save_fpu_registers);
1035 
1036         // Called with store_parameter and not C abi
1037 
1038         f.load_argument(1, r0); // r0,: object
1039         f.load_argument(0, r1); // r1,: lock address
1040 
1041         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), r0, r1);
1042 
1043         oop_maps = new OopMapSet();
1044         oop_maps->add_gc_map(call_offset, map);
1045         restore_live_registers(sasm, save_fpu_registers);
1046       }
1047       break;
1048 
1049     case StubId::c1_is_instance_of_id:
1050       {
1051         // Mirror: c_rarg0
1052         // Object: c_rarg1
1053         // Temps: r3, r4, r5, r6
1054         // Result: r0
1055 
1056         // Get the Klass* into c_rarg6
1057         Register klass = c_rarg6, obj = c_rarg1, result = r0;
1058         __ ldr(klass, Address(c_rarg0, java_lang_Class::klass_offset()));
1059 
1060         Label fail, is_secondary, success;
1061 
1062         __ cbz(klass, fail); // Klass is null
1063         __ cbz(obj, fail); // obj is null
1064 
1065         __ ldrw(r3, Address(klass, in_bytes(Klass::super_check_offset_offset())));
1066         __ cmpw(r3, in_bytes(Klass::secondary_super_cache_offset()));
1067         __ br(Assembler::EQ, is_secondary); // Klass is a secondary superclass
1068 
1069         // Klass is a concrete class
1070         __ load_klass(r5, obj);
1071         __ ldr(rscratch1, Address(r5, r3));
1072         __ cmp(klass, rscratch1);
1073         __ cset(result, Assembler::EQ);
1074         __ ret(lr);
1075 
1076         __ bind(is_secondary);
1077 
1078         __ load_klass(obj, obj);
1079 
1080         // This is necessary because I am never in my own secondary_super list.
1081         __ cmp(obj, klass);
1082         __ br(Assembler::EQ, success);
1083 
1084         __ lookup_secondary_supers_table_var(obj, klass,
1085                                              /*temps*/r3, r4, r5, v0,
1086                                              result,
1087                                              &success);
1088         __ bind(fail);
1089         __ mov(result, 0);
1090         __ ret(lr);
1091 
1092         __ bind(success);
1093         __ mov(result, 1);
1094         __ ret(lr);
1095       }
1096       break;
1097 
1098     case StubId::c1_monitorexit_nofpu_id:
1099       save_fpu_registers = false;
1100       // fall through
1101     case StubId::c1_monitorexit_id:
1102       {
1103         StubFrame f(sasm, "monitorexit", dont_gc_arguments);
1104         OopMap* map = save_live_registers(sasm, save_fpu_registers);
1105 
1106         // Called with store_parameter and not C abi
1107 
1108         f.load_argument(0, r0); // r0,: lock address
1109 
1110         // note: really a leaf routine but must setup last java sp
1111         //       => use call_RT for now (speed can be improved by
1112         //       doing last java sp setup manually)
1113         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), r0);
1114 
1115         oop_maps = new OopMapSet();
1116         oop_maps->add_gc_map(call_offset, map);
1117         restore_live_registers(sasm, save_fpu_registers);
1118       }
1119       break;
1120 
1121     case StubId::c1_deoptimize_id:
1122       {
1123         StubFrame f(sasm, "deoptimize", dont_gc_arguments, does_not_return);
1124         OopMap* oop_map = save_live_registers(sasm);
1125         f.load_argument(0, c_rarg1);
1126         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize), c_rarg1);
1127 
1128         oop_maps = new OopMapSet();
1129         oop_maps->add_gc_map(call_offset, oop_map);
1130         restore_live_registers(sasm);
1131         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
1132         assert(deopt_blob != nullptr, "deoptimization blob must have been created");
1133         __ leave();
1134         __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
1135       }
1136       break;
1137 
1138     case StubId::c1_throw_range_check_failed_id:
1139       { StubFrame f(sasm, "range_check_failed", dont_gc_arguments, does_not_return);
1140         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
1141       }
1142       break;
1143 
1144     case StubId::c1_unwind_exception_id:
1145       { __ set_info("unwind_exception", dont_gc_arguments);
1146         // note: no stubframe since we are about to leave the current
1147         //       activation and we are calling a leaf VM function only.
1148         generate_unwind_exception(sasm);
1149       }
1150       break;
1151 
1152     case StubId::c1_access_field_patching_id:
1153       { StubFrame f(sasm, "access_field_patching", dont_gc_arguments, does_not_return);
1154         // we should set up register map
1155         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
1156       }
1157       break;
1158 
1159     case StubId::c1_load_klass_patching_id:
1160       { StubFrame f(sasm, "load_klass_patching", dont_gc_arguments, does_not_return);
1161         // we should set up register map
1162         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
1163       }
1164       break;
1165 
1166     case StubId::c1_load_mirror_patching_id:
1167       { StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments, does_not_return);
1168         // we should set up register map
1169         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
1170       }
1171       break;
1172 
1173     case StubId::c1_load_appendix_patching_id:
1174       { StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments, does_not_return);
1175         // we should set up register map
1176         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
1177       }
1178       break;
1179 
1180     case StubId::c1_handle_exception_nofpu_id:
1181     case StubId::c1_handle_exception_id:
1182       { StubFrame f(sasm, "handle_exception", dont_gc_arguments);
1183         oop_maps = generate_handle_exception(id, sasm);
1184       }
1185       break;
1186 
1187     case StubId::c1_handle_exception_from_callee_id:
1188       { StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);
1189         oop_maps = generate_handle_exception(id, sasm);
1190       }
1191       break;
1192 
1193     case StubId::c1_throw_index_exception_id:
1194       { StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments, does_not_return);
1195         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
1196       }
1197       break;
1198 
1199     case StubId::c1_throw_array_store_exception_id:
1200       { StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments, does_not_return);
1201         // tos + 0: link
1202         //     + 1: return address
1203         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);
1204       }
1205       break;
1206 
1207     case StubId::c1_predicate_failed_trap_id:
1208       {
1209         StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments, does_not_return);
1210 
1211         OopMap* map = save_live_registers(sasm);
1212 
1213         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));
1214         oop_maps = new OopMapSet();
1215         oop_maps->add_gc_map(call_offset, map);
1216         restore_live_registers(sasm);
1217         __ leave();
1218         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
1219         assert(deopt_blob != nullptr, "deoptimization blob must have been created");
1220 
1221         __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
1222       }
1223       break;
1224 
1225     case StubId::c1_dtrace_object_alloc_id:
1226       { // c_rarg0: object
1227         StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);
1228         save_live_registers(sasm);
1229 
1230         __ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), c_rarg0);
1231 
1232         restore_live_registers(sasm);
1233       }
1234       break;
1235 
1236     default:
1237       { StubFrame f(sasm, "unimplemented entry", dont_gc_arguments, does_not_return);
1238         __ mov(r0, (int)id);
1239         __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), r0);
1240       }
1241       break;
1242     }
1243   }
1244   return oop_maps;
1245 }
1246 
1247 #undef __
1248 
1249 const char *Runtime1::pd_name_for_address(address entry) { Unimplemented(); }