1 /*
   2  * Copyright (c) 1999, 2025, 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_offset()));
  95     }
  96     if (metadata_result->is_valid()) {
  97       str(zr, Address(rthread, JavaThread::vm_result_2_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)C1StubId::forward_exception_id) {
 103       should_not_reach_here();
 104     } else {
 105       far_jump(RuntimeAddress(Runtime1::entry_for(C1StubId::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_result1, rthread);
 112   }
 113   if (metadata_result->is_valid()) {
 114     get_vm_result_2(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   __ pop(RegSet::range(r0, r29), sp);
 314 }
 315 
 316 static void restore_live_registers_except_r0(StubAssembler* sasm, bool restore_fpu_registers = true)  {
 317 
 318   if (restore_fpu_registers) {
 319     for (int i = 0; i < 32; i += 4)
 320       __ ld1(as_FloatRegister(i), as_FloatRegister(i+1), as_FloatRegister(i+2),
 321           as_FloatRegister(i+3), __ T1D, Address(__ post(sp, 4 * wordSize)));
 322   } else {
 323     __ add(sp, sp, 32 * wordSize);
 324   }
 325 
 326   __ ldp(zr, r1, Address(__ post(sp, 16)));
 327   __ pop(RegSet::range(r2, r29), sp);
 328 }
 329 
 330 
 331 
 332 void Runtime1::initialize_pd() {
 333   int i;
 334   int sp_offset = 0;
 335 
 336   // all float registers are saved explicitly
 337   assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here");
 338   for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 339     fpu_reg_save_offsets[i] = sp_offset;
 340     sp_offset += 2;   // SP offsets are in halfwords
 341   }
 342 
 343   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 344     Register r = as_Register(i);
 345     cpu_reg_save_offsets[i] = sp_offset;
 346     sp_offset += 2;   // SP offsets are in halfwords
 347   }
 348 }
 349 
 350 // return: offset in 64-bit words.
 351 uint Runtime1::runtime_blob_current_thread_offset(frame f) {
 352   CodeBlob* cb = f.cb();
 353   assert(cb == Runtime1::blob_for(C1StubId::monitorenter_id) ||
 354          cb == Runtime1::blob_for(C1StubId::monitorenter_nofpu_id), "must be");
 355   assert(cb != nullptr && cb->is_runtime_stub(), "invalid frame");
 356   int offset = cpu_reg_save_offsets[rthread->encoding()];
 357   return offset / 2;   // SP offsets are in halfwords
 358 }
 359 
 360 // target: the entry point of the method that creates and posts the exception oop
 361 // has_argument: true if the exception needs arguments (passed in rscratch1 and rscratch2)
 362 
 363 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
 364   // make a frame and preserve the caller's caller-save registers
 365   OopMap* oop_map = save_live_registers(sasm);
 366   int call_offset;
 367   if (!has_argument) {
 368     call_offset = __ call_RT(noreg, noreg, target);
 369   } else {
 370     __ mov(c_rarg1, rscratch1);
 371     __ mov(c_rarg2, rscratch2);
 372     call_offset = __ call_RT(noreg, noreg, target);
 373   }
 374   OopMapSet* oop_maps = new OopMapSet();
 375   oop_maps->add_gc_map(call_offset, oop_map);
 376   return oop_maps;
 377 }
 378 
 379 
 380 OopMapSet* Runtime1::generate_handle_exception(C1StubId id, StubAssembler *sasm) {
 381   __ block_comment("generate_handle_exception");
 382 
 383   // incoming parameters
 384   const Register exception_oop = r0;
 385   const Register exception_pc  = r3;
 386   // other registers used in this stub
 387 
 388   // Save registers, if required.
 389   OopMapSet* oop_maps = new OopMapSet();
 390   OopMap* oop_map = nullptr;
 391   switch (id) {
 392   case C1StubId::forward_exception_id:
 393     // We're handling an exception in the context of a compiled frame.
 394     // The registers have been saved in the standard places.  Perform
 395     // an exception lookup in the caller and dispatch to the handler
 396     // if found.  Otherwise unwind and dispatch to the callers
 397     // exception handler.
 398     oop_map = generate_oop_map(sasm, 1 /*thread*/);
 399 
 400     // load and clear pending exception oop into r0
 401     __ ldr(exception_oop, Address(rthread, Thread::pending_exception_offset()));
 402     __ str(zr, Address(rthread, Thread::pending_exception_offset()));
 403 
 404     // load issuing PC (the return address for this stub) into r3
 405     __ ldr(exception_pc, Address(rfp, 1*BytesPerWord));
 406     __ authenticate_return_address(exception_pc);
 407 
 408     // make sure that the vm_results are cleared (may be unnecessary)
 409     __ str(zr, Address(rthread, JavaThread::vm_result_offset()));
 410     __ str(zr, Address(rthread, JavaThread::vm_result_2_offset()));
 411     break;
 412   case C1StubId::handle_exception_nofpu_id:
 413   case C1StubId::handle_exception_id:
 414     // At this point all registers MAY be live.
 415     oop_map = save_live_registers(sasm, id != C1StubId::handle_exception_nofpu_id);
 416     break;
 417   case C1StubId::handle_exception_from_callee_id: {
 418     // At this point all registers except exception oop (r0) and
 419     // exception pc (lr) are dead.
 420     const int frame_size = 2 /*fp, return address*/;
 421     oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);
 422     sasm->set_frame_size(frame_size);
 423     break;
 424   }
 425   default: ShouldNotReachHere();
 426   }
 427 
 428   // verify that only r0 and r3 are valid at this time
 429   __ invalidate_registers(false, true, true, false, true, true);
 430   // verify that r0 contains a valid exception
 431   __ verify_not_null_oop(exception_oop);
 432 
 433 #ifdef ASSERT
 434   // check that fields in JavaThread for exception oop and issuing pc are
 435   // empty before writing to them
 436   Label oop_empty;
 437   __ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
 438   __ cbz(rscratch1, oop_empty);
 439   __ stop("exception oop already set");
 440   __ bind(oop_empty);
 441 
 442   Label pc_empty;
 443   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 444   __ cbz(rscratch1, pc_empty);
 445   __ stop("exception pc already set");
 446   __ bind(pc_empty);
 447 #endif
 448 
 449   // save exception oop and issuing pc into JavaThread
 450   // (exception handler will load it from here)
 451   __ str(exception_oop, Address(rthread, JavaThread::exception_oop_offset()));
 452   __ str(exception_pc, Address(rthread, JavaThread::exception_pc_offset()));
 453 
 454   // patch throwing pc into return address (has bci & oop map)
 455   __ protect_return_address(exception_pc);
 456   __ str(exception_pc, Address(rfp, 1*BytesPerWord));
 457 
 458   // compute the exception handler.
 459   // the exception oop and the throwing pc are read from the fields in JavaThread
 460   int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
 461   oop_maps->add_gc_map(call_offset, oop_map);
 462 
 463   // r0: handler address
 464   //      will be the deopt blob if nmethod was deoptimized while we looked up
 465   //      handler regardless of whether handler existed in the nmethod.
 466 
 467   // only r0 is valid at this time, all other registers have been destroyed by the runtime call
 468   __ invalidate_registers(false, true, true, true, true, true);
 469 
 470   // patch the return address, this stub will directly return to the exception handler
 471   __ protect_return_address(r0);
 472   __ str(r0, Address(rfp, 1*BytesPerWord));
 473 
 474   switch (id) {
 475   case C1StubId::forward_exception_id:
 476   case C1StubId::handle_exception_nofpu_id:
 477   case C1StubId::handle_exception_id:
 478     // Restore the registers that were saved at the beginning.
 479     restore_live_registers(sasm, id != C1StubId::handle_exception_nofpu_id);
 480     break;
 481   case C1StubId::handle_exception_from_callee_id:
 482     break;
 483   default:  ShouldNotReachHere();
 484   }
 485 
 486   return oop_maps;
 487 }
 488 
 489 
 490 void Runtime1::generate_unwind_exception(StubAssembler *sasm) {
 491   // incoming parameters
 492   const Register exception_oop = r0;
 493   // callee-saved copy of exception_oop during runtime call
 494   const Register exception_oop_callee_saved = r19;
 495   // other registers used in this stub
 496   const Register exception_pc = r3;
 497   const Register handler_addr = r1;
 498 
 499   if (AbortVMOnException) {
 500     __ mov(rscratch1, exception_oop);
 501     __ enter();
 502     save_live_registers(sasm);
 503     __ call_VM_leaf(CAST_FROM_FN_PTR(address, check_abort_on_vm_exception), rscratch1);
 504     restore_live_registers(sasm);
 505     __ leave();
 506   }
 507 
 508   // verify that only r0, is valid at this time
 509   __ invalidate_registers(false, true, true, true, true, true);
 510 
 511 #ifdef ASSERT
 512   // check that fields in JavaThread for exception oop and issuing pc are empty
 513   Label oop_empty;
 514   __ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
 515   __ cbz(rscratch1, oop_empty);
 516   __ stop("exception oop must be empty");
 517   __ bind(oop_empty);
 518 
 519   Label pc_empty;
 520   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 521   __ cbz(rscratch1, pc_empty);
 522   __ stop("exception pc must be empty");
 523   __ bind(pc_empty);
 524 #endif
 525 
 526   // Save our return address because
 527   // exception_handler_for_return_address will destroy it.  We also
 528   // save exception_oop
 529   __ mov(r3, lr);
 530   __ protect_return_address();
 531   __ stp(lr, exception_oop, Address(__ pre(sp, -2 * wordSize)));
 532 
 533   // search the exception handler address of the caller (using the return address)
 534   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), rthread, r3);
 535   // r0: exception handler address of the caller
 536 
 537   // Only R0 is valid at this time; all other registers have been
 538   // destroyed by the call.
 539   __ invalidate_registers(false, true, true, true, false, true);
 540 
 541   // move result of call into correct register
 542   __ mov(handler_addr, r0);
 543 
 544   // get throwing pc (= return address).
 545   // lr has been destroyed by the call
 546   __ ldp(lr, exception_oop, Address(__ post(sp, 2 * wordSize)));
 547   __ authenticate_return_address();
 548   __ mov(r3, lr);
 549 
 550   __ verify_not_null_oop(exception_oop);
 551 
 552   // continue at exception handler (return address removed)
 553   // note: do *not* remove arguments when unwinding the
 554   //       activation since the caller assumes having
 555   //       all arguments on the stack when entering the
 556   //       runtime to determine the exception handler
 557   //       (GC happens at call site with arguments!)
 558   // r0: exception oop
 559   // r3: throwing pc
 560   // r1: exception handler
 561   __ br(handler_addr);
 562 }
 563 
 564 
 565 
 566 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
 567   // use the maximum number of runtime-arguments here because it is difficult to
 568   // distinguish each RT-Call.
 569   // Note: This number affects also the RT-Call in generate_handle_exception because
 570   //       the oop-map is shared for all calls.
 571   DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 572   assert(deopt_blob != nullptr, "deoptimization blob must have been created");
 573 
 574   OopMap* oop_map = save_live_registers(sasm);
 575 
 576   __ mov(c_rarg0, rthread);
 577   Label retaddr;
 578   __ set_last_Java_frame(sp, rfp, retaddr, rscratch1);
 579   // do the call
 580   __ lea(rscratch1, RuntimeAddress(target));
 581   __ blr(rscratch1);
 582   __ bind(retaddr);
 583   OopMapSet* oop_maps = new OopMapSet();
 584   oop_maps->add_gc_map(__ offset(), oop_map);
 585   // verify callee-saved register
 586 #ifdef ASSERT
 587   { Label L;
 588     __ get_thread(rscratch1);
 589     __ cmp(rthread, rscratch1);
 590     __ br(Assembler::EQ, L);
 591     __ stop("StubAssembler::call_RT: rthread not callee saved?");
 592     __ bind(L);
 593   }
 594 #endif
 595 
 596   __ reset_last_Java_frame(true);
 597 
 598 #ifdef ASSERT
 599   // check that fields in JavaThread for exception oop and issuing pc are empty
 600   Label oop_empty;
 601   __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
 602   __ cbz(rscratch1, oop_empty);
 603   __ stop("exception oop must be empty");
 604   __ bind(oop_empty);
 605 
 606   Label pc_empty;
 607   __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
 608   __ cbz(rscratch1, pc_empty);
 609   __ stop("exception pc must be empty");
 610   __ bind(pc_empty);
 611 #endif
 612 
 613   // Runtime will return true if the nmethod has been deoptimized, this is the
 614   // expected scenario and anything else is  an error. Note that we maintain a
 615   // check on the result purely as a defensive measure.
 616   Label no_deopt;
 617   __ cbz(r0, no_deopt);                                // Have we deoptimized?
 618 
 619   // Perform a re-execute. The proper return  address is already on the stack,
 620   // we just need  to restore registers, pop  all of our frame  but the return
 621   // address and jump to the deopt blob.
 622   restore_live_registers(sasm);
 623   __ leave();
 624   __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
 625 
 626   __ bind(no_deopt);
 627   __ stop("deopt not performed");
 628 
 629   return oop_maps;
 630 }
 631 
 632 
 633 OopMapSet* Runtime1::generate_code_for(C1StubId id, StubAssembler* sasm) {
 634 
 635   const Register exception_oop = r0;
 636   const Register exception_pc  = r3;
 637 
 638   // for better readability
 639   const bool must_gc_arguments = true;
 640   const bool dont_gc_arguments = false;
 641 
 642   // default value; overwritten for some optimized stubs that are called from methods that do not use the fpu
 643   bool save_fpu_registers = true;
 644 
 645   // stub code & info for the different stubs
 646   OopMapSet* oop_maps = nullptr;
 647   OopMap* oop_map = nullptr;
 648   switch (id) {
 649     {
 650     case C1StubId::forward_exception_id:
 651       {
 652         oop_maps = generate_handle_exception(id, sasm);
 653         __ leave();
 654         __ ret(lr);
 655       }
 656       break;
 657 
 658     case C1StubId::throw_div0_exception_id:
 659       { StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments, does_not_return);
 660         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
 661       }
 662       break;
 663 
 664     case C1StubId::throw_null_pointer_exception_id:
 665       { StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments, does_not_return);
 666         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
 667       }
 668       break;
 669 
 670     case C1StubId::new_instance_id:
 671     case C1StubId::fast_new_instance_id:
 672     case C1StubId::fast_new_instance_init_check_id:
 673       {
 674         Register klass = r3; // Incoming
 675         Register obj   = r0; // Result
 676 
 677         if (id == C1StubId::new_instance_id) {
 678           __ set_info("new_instance", dont_gc_arguments);
 679         } else if (id == C1StubId::fast_new_instance_id) {
 680           __ set_info("fast new_instance", dont_gc_arguments);
 681         } else {
 682           assert(id == C1StubId::fast_new_instance_init_check_id, "bad C1StubId");
 683           __ set_info("fast new_instance init check", dont_gc_arguments);
 684         }
 685 
 686         __ enter();
 687         OopMap* map = save_live_registers(sasm);
 688         int call_offset;
 689         call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);
 690         oop_maps = new OopMapSet();
 691         oop_maps->add_gc_map(call_offset, map);
 692         restore_live_registers_except_r0(sasm);
 693         __ verify_oop(obj);
 694         __ leave();
 695         __ ret(lr);
 696 
 697         // r0,: new instance
 698       }
 699 
 700       break;
 701 
 702     case C1StubId::counter_overflow_id:
 703       {
 704         Register bci = r0, method = r1;
 705         __ enter();
 706         OopMap* map = save_live_registers(sasm);
 707         // Retrieve bci
 708         __ ldrw(bci, Address(rfp, 2*BytesPerWord));
 709         // And a pointer to the Method*
 710         __ ldr(method, Address(rfp, 3*BytesPerWord));
 711         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);
 712         oop_maps = new OopMapSet();
 713         oop_maps->add_gc_map(call_offset, map);
 714         restore_live_registers(sasm);
 715         __ leave();
 716         __ ret(lr);
 717       }
 718       break;
 719 
 720     case C1StubId::new_type_array_id:
 721     case C1StubId::new_object_array_id:
 722     case C1StubId::new_null_free_array_id:
 723       {
 724         Register length   = r19; // Incoming
 725         Register klass    = r3; // Incoming
 726         Register obj      = r0; // Result
 727 
 728         if (id == C1StubId::new_type_array_id) {
 729           __ set_info("new_type_array", dont_gc_arguments);
 730         } else if (id == C1StubId::new_object_array_id) {
 731           __ set_info("new_object_array", dont_gc_arguments);
 732         } else {
 733           __ set_info("new_null_free_array", dont_gc_arguments);
 734         }
 735 
 736 #ifdef ASSERT
 737         // assert object type is really an array of the proper kind
 738         {
 739           Label ok;
 740           Register t0 = obj;
 741           __ ldrw(t0, Address(klass, Klass::layout_helper_offset()));
 742           __ asrw(t0, t0, Klass::_lh_array_tag_shift);
 743           switch (id) {
 744           case C1StubId::new_type_array_id:
 745             __ cmpw(t0, Klass::_lh_array_tag_type_value);
 746             __ br(Assembler::EQ, ok);
 747             __ stop("assert(is a type array klass)");
 748             break;
 749           case C1StubId::new_object_array_id:
 750             __ cmpw(t0, Klass::_lh_array_tag_obj_value); // new "[Ljava/lang/Object;"
 751             __ br(Assembler::EQ, ok);
 752             __ cmpw(t0, Klass::_lh_array_tag_vt_value);  // new "[LVT;"
 753             __ br(Assembler::EQ, ok);
 754             __ stop("assert(is an object or inline type array klass)");
 755             break;
 756           case C1StubId::new_null_free_array_id:
 757             __ cmpw(t0, Klass::_lh_array_tag_vt_value);  // the array can be a flat array.
 758             __ br(Assembler::EQ, ok);
 759             __ cmpw(t0, Klass::_lh_array_tag_obj_value); // the array cannot be a flat array (due to InlineArrayElementMaxFlatSize, etc)
 760             __ br(Assembler::EQ, ok);
 761             __ stop("assert(is an object or inline type array klass)");
 762             break;
 763           default:  ShouldNotReachHere();
 764           }
 765           __ should_not_reach_here();
 766           __ bind(ok);
 767         }
 768 #endif // ASSERT
 769 
 770         __ enter();
 771         OopMap* map = save_live_registers(sasm);
 772         int call_offset;
 773         if (id == C1StubId::new_type_array_id) {
 774           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);
 775         } else if (id == C1StubId::new_object_array_id) {
 776           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);
 777         } else {
 778           assert(id == C1StubId::new_null_free_array_id, "must be");
 779           call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_null_free_array), klass, length);
 780         }
 781 
 782         oop_maps = new OopMapSet();
 783         oop_maps->add_gc_map(call_offset, map);
 784         restore_live_registers_except_r0(sasm);
 785 
 786         __ verify_oop(obj);
 787         __ leave();
 788         __ ret(lr);
 789 
 790         // r0: new array
 791       }
 792       break;
 793 
 794     case C1StubId::new_multi_array_id:
 795       { StubFrame f(sasm, "new_multi_array", dont_gc_arguments);
 796         // r0,: klass
 797         // r19,: rank
 798         // r2: address of 1st dimension
 799         OopMap* map = save_live_registers(sasm);
 800         __ mov(c_rarg1, r0);
 801         __ mov(c_rarg3, r2);
 802         __ mov(c_rarg2, r19);
 803         int call_offset = __ call_RT(r0, noreg, CAST_FROM_FN_PTR(address, new_multi_array), r1, r2, r3);
 804 
 805         oop_maps = new OopMapSet();
 806         oop_maps->add_gc_map(call_offset, map);
 807         restore_live_registers_except_r0(sasm);
 808 
 809         // r0,: new multi array
 810         __ verify_oop(r0);
 811       }
 812       break;
 813 
 814     case C1StubId::buffer_inline_args_id:
 815     case C1StubId::buffer_inline_args_no_receiver_id:
 816       {
 817         const char* name = (id == C1StubId::buffer_inline_args_id) ?
 818           "buffer_inline_args" : "buffer_inline_args_no_receiver";
 819         StubFrame f(sasm, name, dont_gc_arguments);
 820         OopMap* map = save_live_registers(sasm);
 821         Register method = r19;   // Incoming
 822         address entry = (id == C1StubId::buffer_inline_args_id) ?
 823           CAST_FROM_FN_PTR(address, buffer_inline_args) :
 824           CAST_FROM_FN_PTR(address, buffer_inline_args_no_receiver);
 825         // This is called from a C1 method's scalarized entry point
 826         // where r0-r7 may be holding live argument values so we can't
 827         // return the result in r0 as the other stubs do. LR is used as
 828         // a temporay below to avoid the result being clobbered by
 829         // restore_live_registers.
 830         int call_offset = __ call_RT(lr, noreg, entry, method);
 831         oop_maps = new OopMapSet();
 832         oop_maps->add_gc_map(call_offset, map);
 833         restore_live_registers(sasm);
 834         __ mov(r20, lr);
 835         __ verify_oop(r20);  // r20: an array of buffered value objects
 836      }
 837      break;
 838 
 839     case C1StubId::load_flat_array_id:
 840       {
 841         StubFrame f(sasm, "load_flat_array", dont_gc_arguments);
 842         OopMap* map = save_live_registers(sasm);
 843 
 844         // Called with store_parameter and not C abi
 845 
 846         f.load_argument(1, r0); // r0,: array
 847         f.load_argument(0, r1); // r1,: index
 848         int call_offset = __ call_RT(r0, noreg, CAST_FROM_FN_PTR(address, load_flat_array), r0, r1);
 849 
 850         // Ensure the stores that initialize the buffer are visible
 851         // before any subsequent store that publishes this reference.
 852         __ membar(Assembler::StoreStore);
 853 
 854         oop_maps = new OopMapSet();
 855         oop_maps->add_gc_map(call_offset, map);
 856         restore_live_registers_except_r0(sasm);
 857 
 858         // r0: loaded element at array[index]
 859         __ verify_oop(r0);
 860       }
 861       break;
 862 
 863     case C1StubId::store_flat_array_id:
 864       {
 865         StubFrame f(sasm, "store_flat_array", dont_gc_arguments);
 866         OopMap* map = save_live_registers(sasm, 4);
 867 
 868         // Called with store_parameter and not C abi
 869 
 870         f.load_argument(2, r0); // r0: array
 871         f.load_argument(1, r1); // r1: index
 872         f.load_argument(0, r2); // r2: value
 873         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, store_flat_array), r0, r1, r2);
 874 
 875         oop_maps = new OopMapSet();
 876         oop_maps->add_gc_map(call_offset, map);
 877         restore_live_registers_except_r0(sasm);
 878       }
 879       break;
 880 
 881     case C1StubId::substitutability_check_id:
 882       {
 883         StubFrame f(sasm, "substitutability_check", dont_gc_arguments);
 884         OopMap* map = save_live_registers(sasm);
 885 
 886         // Called with store_parameter and not C abi
 887 
 888         f.load_argument(1, r1); // r1,: left
 889         f.load_argument(0, r2); // r2,: right
 890         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, substitutability_check), r1, r2);
 891 
 892         oop_maps = new OopMapSet();
 893         oop_maps->add_gc_map(call_offset, map);
 894         restore_live_registers_except_r0(sasm);
 895 
 896         // r0,: are the two operands substitutable
 897       }
 898       break;
 899 
 900     case C1StubId::register_finalizer_id:
 901       {
 902         __ set_info("register_finalizer", dont_gc_arguments);
 903 
 904         // This is called via call_runtime so the arguments
 905         // will be place in C abi locations
 906 
 907         __ verify_oop(c_rarg0);
 908 
 909         // load the klass and check the has finalizer flag
 910         Label register_finalizer;
 911         Register t = r5;
 912         __ load_klass(t, r0);
 913         __ ldrb(t, Address(t, Klass::misc_flags_offset()));
 914         __ tbnz(t, exact_log2(KlassFlags::_misc_has_finalizer), register_finalizer);
 915         __ ret(lr);
 916 
 917         __ bind(register_finalizer);
 918         __ enter();
 919         OopMap* oop_map = save_live_registers(sasm);
 920         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), r0);
 921         oop_maps = new OopMapSet();
 922         oop_maps->add_gc_map(call_offset, oop_map);
 923 
 924         // Now restore all the live registers
 925         restore_live_registers(sasm);
 926 
 927         __ leave();
 928         __ ret(lr);
 929       }
 930       break;
 931 
 932     case C1StubId::throw_class_cast_exception_id:
 933       { StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments, does_not_return);
 934         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
 935       }
 936       break;
 937 
 938     case C1StubId::throw_incompatible_class_change_error_id:
 939       { StubFrame f(sasm, "throw_incompatible_class_change_error", dont_gc_arguments, does_not_return);
 940         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
 941       }
 942       break;
 943 
 944     case C1StubId::throw_illegal_monitor_state_exception_id:
 945       { StubFrame f(sasm, "throw_illegal_monitor_state_exception", dont_gc_arguments);
 946         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_illegal_monitor_state_exception), false);
 947       }
 948       break;
 949 
 950     case C1StubId::throw_identity_exception_id:
 951       { StubFrame f(sasm, "throw_identity_exception", dont_gc_arguments);
 952         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_identity_exception), true);
 953       }
 954       break;
 955 
 956     case C1StubId::slow_subtype_check_id:
 957       {
 958         // Typical calling sequence:
 959         // __ push(klass_RInfo);  // object klass or other subclass
 960         // __ push(sup_k_RInfo);  // array element klass or other superclass
 961         // __ bl(slow_subtype_check);
 962         // Note that the subclass is pushed first, and is therefore deepest.
 963         enum layout {
 964           r0_off, r0_off_hi,
 965           r2_off, r2_off_hi,
 966           r4_off, r4_off_hi,
 967           r5_off, r5_off_hi,
 968           sup_k_off, sup_k_off_hi,
 969           klass_off, klass_off_hi,
 970           framesize,
 971           result_off = sup_k_off
 972         };
 973 
 974         __ set_info("slow_subtype_check", dont_gc_arguments);
 975         __ push(RegSet::of(r0, r2, r4, r5), sp);
 976 
 977         // This is called by pushing args and not with C abi
 978         // __ ldr(r4, Address(sp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass
 979         // __ ldr(r0, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass
 980 
 981         __ ldp(r4, r0, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size));
 982 
 983         Label miss;
 984         __ check_klass_subtype_slow_path(/*sub_klass*/r4,
 985                                          /*super_klass*/r0,
 986                                          /*temp_reg*/r2,
 987                                          /*temp2_reg*/r5,
 988                                          /*L_success*/nullptr,
 989                                          /*L_failure*/&miss);
 990         // Need extras for table lookup: r1, r3, vtemp
 991 
 992         // fallthrough on success:
 993         __ mov(rscratch1, 1);
 994         __ str(rscratch1, Address(sp, (result_off) * VMRegImpl::stack_slot_size)); // result
 995         __ pop(RegSet::of(r0, r2, r4, r5), sp);
 996         __ ret(lr);
 997 
 998         __ bind(miss);
 999         __ str(zr, Address(sp, (result_off) * VMRegImpl::stack_slot_size)); // result
1000         __ pop(RegSet::of(r0, r2, r4, r5), sp);
1001         __ ret(lr);
1002       }
1003       break;
1004 
1005     case C1StubId::monitorenter_nofpu_id:
1006       save_fpu_registers = false;
1007       // fall through
1008     case C1StubId::monitorenter_id:
1009       {
1010         StubFrame f(sasm, "monitorenter", dont_gc_arguments, requires_pop_epilogue_return);
1011         OopMap* map = save_live_registers(sasm, save_fpu_registers);
1012 
1013         // Called with store_parameter and not C abi
1014 
1015         f.load_argument(1, r0); // r0,: object
1016         f.load_argument(0, r1); // r1,: lock address
1017 
1018         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), r0, r1);
1019 
1020         oop_maps = new OopMapSet();
1021         oop_maps->add_gc_map(call_offset, map);
1022         restore_live_registers(sasm, save_fpu_registers);
1023       }
1024       break;
1025 
1026     case C1StubId::is_instance_of_id:
1027       {
1028         // Mirror: c_rarg0
1029         // Object: c_rarg1
1030         // Temps: r3, r4, r5, r6
1031         // Result: r0
1032 
1033         // Get the Klass* into c_rarg6
1034         Register klass = c_rarg6, obj = c_rarg1, result = r0;
1035         __ ldr(klass, Address(c_rarg0, java_lang_Class::klass_offset()));
1036 
1037         Label fail, is_secondary, success;
1038 
1039         __ cbz(klass, fail); // Klass is null
1040         __ cbz(obj, fail); // obj is null
1041 
1042         __ ldrw(r3, Address(klass, in_bytes(Klass::super_check_offset_offset())));
1043         __ cmpw(r3, in_bytes(Klass::secondary_super_cache_offset()));
1044         __ br(Assembler::EQ, is_secondary); // Klass is a secondary superclass
1045 
1046         // Klass is a concrete class
1047         __ load_klass(r5, obj);
1048         __ ldr(rscratch1, Address(r5, r3));
1049         __ cmp(klass, rscratch1);
1050         __ cset(result, Assembler::EQ);
1051         __ ret(lr);
1052 
1053         __ bind(is_secondary);
1054 
1055         __ load_klass(obj, obj);
1056 
1057         // This is necessary because I am never in my own secondary_super list.
1058         __ cmp(obj, klass);
1059         __ br(Assembler::EQ, success);
1060 
1061         __ lookup_secondary_supers_table_var(obj, klass,
1062                                              /*temps*/r3, r4, r5, v0,
1063                                              result,
1064                                              &success);
1065         __ bind(fail);
1066         __ mov(result, 0);
1067         __ ret(lr);
1068 
1069         __ bind(success);
1070         __ mov(result, 1);
1071         __ ret(lr);
1072       }
1073       break;
1074 
1075     case C1StubId::monitorexit_nofpu_id:
1076       save_fpu_registers = false;
1077       // fall through
1078     case C1StubId::monitorexit_id:
1079       {
1080         StubFrame f(sasm, "monitorexit", dont_gc_arguments);
1081         OopMap* map = save_live_registers(sasm, save_fpu_registers);
1082 
1083         // Called with store_parameter and not C abi
1084 
1085         f.load_argument(0, r0); // r0,: lock address
1086 
1087         // note: really a leaf routine but must setup last java sp
1088         //       => use call_RT for now (speed can be improved by
1089         //       doing last java sp setup manually)
1090         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), r0);
1091 
1092         oop_maps = new OopMapSet();
1093         oop_maps->add_gc_map(call_offset, map);
1094         restore_live_registers(sasm, save_fpu_registers);
1095       }
1096       break;
1097 
1098     case C1StubId::deoptimize_id:
1099       {
1100         StubFrame f(sasm, "deoptimize", dont_gc_arguments, does_not_return);
1101         OopMap* oop_map = save_live_registers(sasm);
1102         f.load_argument(0, c_rarg1);
1103         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize), c_rarg1);
1104 
1105         oop_maps = new OopMapSet();
1106         oop_maps->add_gc_map(call_offset, oop_map);
1107         restore_live_registers(sasm);
1108         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
1109         assert(deopt_blob != nullptr, "deoptimization blob must have been created");
1110         __ leave();
1111         __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
1112       }
1113       break;
1114 
1115     case C1StubId::throw_range_check_failed_id:
1116       { StubFrame f(sasm, "range_check_failed", dont_gc_arguments, does_not_return);
1117         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
1118       }
1119       break;
1120 
1121     case C1StubId::unwind_exception_id:
1122       { __ set_info("unwind_exception", dont_gc_arguments);
1123         // note: no stubframe since we are about to leave the current
1124         //       activation and we are calling a leaf VM function only.
1125         generate_unwind_exception(sasm);
1126       }
1127       break;
1128 
1129     case C1StubId::access_field_patching_id:
1130       { StubFrame f(sasm, "access_field_patching", dont_gc_arguments, does_not_return);
1131         // we should set up register map
1132         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
1133       }
1134       break;
1135 
1136     case C1StubId::load_klass_patching_id:
1137       { StubFrame f(sasm, "load_klass_patching", dont_gc_arguments, does_not_return);
1138         // we should set up register map
1139         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
1140       }
1141       break;
1142 
1143     case C1StubId::load_mirror_patching_id:
1144       { StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments, does_not_return);
1145         // we should set up register map
1146         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
1147       }
1148       break;
1149 
1150     case C1StubId::load_appendix_patching_id:
1151       { StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments, does_not_return);
1152         // we should set up register map
1153         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
1154       }
1155       break;
1156 
1157     case C1StubId::handle_exception_nofpu_id:
1158     case C1StubId::handle_exception_id:
1159       { StubFrame f(sasm, "handle_exception", dont_gc_arguments);
1160         oop_maps = generate_handle_exception(id, sasm);
1161       }
1162       break;
1163 
1164     case C1StubId::handle_exception_from_callee_id:
1165       { StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);
1166         oop_maps = generate_handle_exception(id, sasm);
1167       }
1168       break;
1169 
1170     case C1StubId::throw_index_exception_id:
1171       { StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments, does_not_return);
1172         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
1173       }
1174       break;
1175 
1176     case C1StubId::throw_array_store_exception_id:
1177       { StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments, does_not_return);
1178         // tos + 0: link
1179         //     + 1: return address
1180         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);
1181       }
1182       break;
1183 
1184     case C1StubId::predicate_failed_trap_id:
1185       {
1186         StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments, does_not_return);
1187 
1188         OopMap* map = save_live_registers(sasm);
1189 
1190         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));
1191         oop_maps = new OopMapSet();
1192         oop_maps->add_gc_map(call_offset, map);
1193         restore_live_registers(sasm);
1194         __ leave();
1195         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
1196         assert(deopt_blob != nullptr, "deoptimization blob must have been created");
1197 
1198         __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
1199       }
1200       break;
1201 
1202     case C1StubId::dtrace_object_alloc_id:
1203       { // c_rarg0: object
1204         StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);
1205         save_live_registers(sasm);
1206 
1207         __ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), c_rarg0);
1208 
1209         restore_live_registers(sasm);
1210       }
1211       break;
1212 
1213     default:
1214       // FIXME: For unhandled trap_id this code fails with assert during vm intialization
1215       // rather than insert a call to unimplemented_entry
1216       { StubFrame f(sasm, "unimplemented entry", dont_gc_arguments, does_not_return);
1217         __ mov(r0, (int)id);
1218         __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), r0);
1219       }
1220       break;
1221     }
1222   }
1223 
1224 
1225   return oop_maps;
1226 }
1227 
1228 #undef __
1229 
1230 const char *Runtime1::pd_name_for_address(address entry) { Unimplemented(); }