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