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