1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)c1_Runtime1_sparc.cpp        1.149 07/05/17 15:48:01 JVM"
   3 #endif
   4 /*
   5  * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 #include "incls/_precompiled.incl"
  29 #include "incls/_c1_Runtime1_sparc.cpp.incl"
  30 
  31 // Implementation of StubAssembler
  32 
  33 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry_point, int number_of_arguments) {
  34   // for sparc changing the number of arguments doesn't change
  35   // anything about the frame size so we'll always lie and claim that
  36   // we are only passing 1 argument.
  37   set_num_rt_args(1);
  38 
  39   assert_not_delayed();
  40   // bang stack before going to runtime
  41   set(-os::vm_page_size() + STACK_BIAS, G3_scratch);
  42   st(G0, SP, G3_scratch);
  43 
  44   // debugging support
  45   assert(number_of_arguments >= 0   , "cannot have negative number of arguments");
  46 
  47   set_last_Java_frame(SP, noreg);
  48   if (VerifyThread)  mov(G2_thread, O0); // about to be smashed; pass early
  49   save_thread(L7_thread_cache);
  50   // do the call
  51   call(entry_point, relocInfo::runtime_call_type);
  52   if (!VerifyThread) {
  53     delayed()->mov(G2_thread, O0);  // pass thread as first argument
  54   } else {
  55     delayed()->nop();             // (thread already passed)
  56   }
  57   int call_offset = offset();  // offset of return address
  58   restore_thread(L7_thread_cache);
  59   reset_last_Java_frame();
  60 
  61   // check for pending exceptions
  62   { Label L;
  63     Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset()));
  64     ld_ptr(exception_addr, Gtemp);
  65     br_null(Gtemp, false, pt, L);
  66     delayed()->nop();
  67     Address vm_result_addr(G2_thread, 0, in_bytes(JavaThread::vm_result_offset()));
  68     st_ptr(G0, vm_result_addr);
  69     Address vm_result_addr_2(G2_thread, 0, in_bytes(JavaThread::vm_result_2_offset()));
  70     st_ptr(G0, vm_result_addr_2);
  71 
  72     if (frame_size() == no_frame_size) {
  73       // we use O7 linkage so that forward_exception_entry has the issuing PC
  74       call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
  75       delayed()->restore();
  76     } else if (_stub_id == Runtime1::forward_exception_id) {
  77       should_not_reach_here();
  78     } else {
  79       Address exc(G4, Runtime1::entry_for(Runtime1::forward_exception_id));
  80       jump_to(exc, 0);
  81       delayed()->nop();
  82     }
  83     bind(L);
  84   }
  85 
  86   // get oop result if there is one and reset the value in the thread
  87   if (oop_result1->is_valid()) {                    // get oop result if there is one and reset it in the thread
  88     get_vm_result  (oop_result1);
  89   } else {
  90     // be a little paranoid and clear the result
  91     Address vm_result_addr(G2_thread, 0, in_bytes(JavaThread::vm_result_offset()));
  92     st_ptr(G0, vm_result_addr);
  93   }
  94 
  95   if (oop_result2->is_valid()) {
  96     get_vm_result_2(oop_result2);
  97   } else {
  98     // be a little paranoid and clear the result
  99     Address vm_result_addr_2(G2_thread, 0, in_bytes(JavaThread::vm_result_2_offset()));
 100     st_ptr(G0, vm_result_addr_2);
 101   }
 102 
 103   return call_offset;
 104 }
 105 
 106 
 107 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1) {
 108   // O0 is reserved for the thread
 109   mov(arg1, O1);
 110   return call_RT(oop_result1, oop_result2, entry, 1);
 111 }
 112 
 113 
 114 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2) {
 115   // O0 is reserved for the thread
 116   mov(arg1, O1);
 117   mov(arg2, O2); assert(arg2 != O1, "smashed argument");
 118   return call_RT(oop_result1, oop_result2, entry, 2);
 119 }
 120 
 121 
 122 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2, Register arg3) {
 123   // O0 is reserved for the thread
 124   mov(arg1, O1);
 125   mov(arg2, O2); assert(arg2 != O1,               "smashed argument");
 126   mov(arg3, O3); assert(arg3 != O1 && arg3 != O2, "smashed argument");
 127   return call_RT(oop_result1, oop_result2, entry, 3);
 128 }
 129 
 130 
 131 // Implementation of Runtime1
 132 
 133 #define __ sasm->
 134 
 135 static int cpu_reg_save_offsets[FrameMap::nof_cpu_regs];
 136 static int fpu_reg_save_offsets[FrameMap::nof_fpu_regs];
 137 static int reg_save_size_in_words;
 138 static int frame_size_in_bytes = -1;
 139 
 140 static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) {
 141   assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
 142          " mismatch in calculation");
 143   sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
 144   int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
 145   OopMap* oop_map = new OopMap(frame_size_in_slots, 0);
 146 
 147   int i;
 148   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 149     Register r = as_Register(i);
 150     if (r == G1 || r == G3 || r == G4 || r == G5) {
 151       int sp_offset = cpu_reg_save_offsets[i];
 152       oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
 153                                 r->as_VMReg());
 154     }
 155   }
 156 
 157   if (save_fpu_registers) {
 158     for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 159       FloatRegister r = as_FloatRegister(i);
 160       int sp_offset = fpu_reg_save_offsets[i];
 161       oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
 162                                 r->as_VMReg());
 163     }
 164   }
 165   return oop_map;
 166 }
 167 
 168 static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) {
 169   assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
 170          " mismatch in calculation");
 171   __ save_frame_c1(frame_size_in_bytes);
 172   sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
 173 
 174   // Record volatile registers as callee-save values in an OopMap so their save locations will be
 175   // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for
 176   // deoptimization; see compiledVFrame::create_stack_value).  The caller's I, L and O registers
 177   // are saved in register windows - I's and L's in the caller's frame and O's in the stub frame
 178   // (as the stub's I's) when the runtime routine called by the stub creates its frame.
 179   // OopMap frame sizes are in c2 stack slot sizes (sizeof(jint))
 180 
 181   int i;
 182   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 183     Register r = as_Register(i);
 184     if (r == G1 || r == G3 || r == G4 || r == G5) {
 185       int sp_offset = cpu_reg_save_offsets[i];
 186       __ st_ptr(r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
 187     }
 188   }
 189 
 190   if (save_fpu_registers) {
 191     for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 192       FloatRegister r = as_FloatRegister(i);
 193       int sp_offset = fpu_reg_save_offsets[i];
 194       __ stf(FloatRegisterImpl::S, r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
 195     }
 196   }
 197 
 198   return generate_oop_map(sasm, save_fpu_registers);
 199 }
 200 
 201 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
 202   for (int i = 0; i < FrameMap::nof_cpu_regs; i++) {
 203     Register r = as_Register(i);
 204     if (r == G1 || r == G3 || r == G4 || r == G5) {
 205       __ ld_ptr(SP, (cpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
 206     }
 207   }
 208 
 209   if (restore_fpu_registers) {
 210     for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
 211       FloatRegister r = as_FloatRegister(i);
 212       __ ldf(FloatRegisterImpl::S, SP, (fpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
 213     }
 214   }
 215 }
 216 
 217 
 218 void Runtime1::initialize_pd() {
 219   // compute word offsets from SP at which live (non-windowed) registers are captured by stub routines
 220   //
 221   // A stub routine will have a frame that is at least large enough to hold
 222   // a register window save area (obviously) and the volatile g registers
 223   // and floating registers. A user of save_live_registers can have a frame
 224   // that has more scratch area in it (although typically they will use L-regs).
 225   // in that case the frame will look like this (stack growing down)
 226   //
 227   // FP -> |             |
 228   //       | scratch mem |
 229   //       |   "      "  |
 230   //       --------------
 231   //       | float regs  |
 232   //       |   "    "    |
 233   //       ---------------
 234   //       | G regs      |
 235   //       | "  "        |
 236   //       ---------------
 237   //       | abi reg.    |
 238   //       | window save |
 239   //       | area        |
 240   // SP -> ---------------
 241   //
 242   int i;
 243   int sp_offset = round_to(frame::register_save_words, 2); //  start doubleword aligned
 244 
 245   // only G int registers are saved explicitly; others are found in register windows
 246   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 247     Register r = as_Register(i);
 248     if (r == G1 || r == G3 || r == G4 || r == G5) {
 249       cpu_reg_save_offsets[i] = sp_offset;
 250       sp_offset++;
 251     }
 252   }
 253 
 254   // all float registers are saved explicitly
 255   assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here");
 256   for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 257     fpu_reg_save_offsets[i] = sp_offset;
 258     sp_offset++;
 259   }
 260   reg_save_size_in_words = sp_offset - frame::memory_parameter_word_sp_offset;
 261   // this should match assembler::total_frame_size_in_bytes, which
 262   // isn't callable from this context.  It's checked by an assert when
 263   // it's used though.
 264   frame_size_in_bytes = align_size_up(sp_offset * wordSize, 8);
 265 }
 266 
 267 
 268 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
 269   // make a frame and preserve the caller's caller-save registers
 270   OopMap* oop_map = save_live_registers(sasm);
 271   int call_offset;
 272   if (!has_argument) {
 273     call_offset = __ call_RT(noreg, noreg, target);
 274   } else {
 275     call_offset = __ call_RT(noreg, noreg, target, G4);
 276   }
 277   OopMapSet* oop_maps = new OopMapSet();
 278   oop_maps->add_gc_map(call_offset, oop_map);
 279 
 280   __ should_not_reach_here();
 281   return oop_maps;
 282 }
 283 
 284 
 285 OopMapSet* Runtime1::generate_stub_call(StubAssembler* sasm, Register result, address target,
 286                                         Register arg1, Register arg2, Register arg3) {
 287   // make a frame and preserve the caller's caller-save registers
 288   OopMap* oop_map = save_live_registers(sasm);
 289 
 290   int call_offset;
 291   if (arg1 == noreg) {
 292     call_offset = __ call_RT(result, noreg, target);
 293   } else if (arg2 == noreg) {
 294     call_offset = __ call_RT(result, noreg, target, arg1);
 295   } else if (arg3 == noreg) {
 296     call_offset = __ call_RT(result, noreg, target, arg1, arg2);
 297   } else {
 298     call_offset = __ call_RT(result, noreg, target, arg1, arg2, arg3);
 299   }
 300   OopMapSet* oop_maps = NULL;
 301 
 302   oop_maps = new OopMapSet();
 303   oop_maps->add_gc_map(call_offset, oop_map);
 304   restore_live_registers(sasm);
 305 
 306   __ ret();
 307   __ delayed()->restore();
 308 
 309   return oop_maps;
 310 }
 311 
 312 
 313 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
 314   // make a frame and preserve the caller's caller-save registers
 315   OopMap* oop_map = save_live_registers(sasm);
 316 
 317   // call the runtime patching routine, returns non-zero if nmethod got deopted.
 318   int call_offset = __ call_RT(noreg, noreg, target);
 319   OopMapSet* oop_maps = new OopMapSet();
 320   oop_maps->add_gc_map(call_offset, oop_map);
 321 
 322   // re-execute the patched instruction or, if the nmethod was deoptmized, return to the
 323   // deoptimization handler entry that will cause re-execution of the current bytecode
 324   DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 325   assert(deopt_blob != NULL, "deoptimization blob must have been created");
 326 
 327   Label no_deopt;
 328   __ tst(O0);
 329   __ brx(Assembler::equal, false, Assembler::pt, no_deopt);
 330   __ delayed()->nop();
 331 
 332   // return to the deoptimization handler entry for unpacking and rexecute
 333   // if we simply returned the we'd deopt as if any call we patched had just
 334   // returned.
 335 
 336   restore_live_registers(sasm);
 337   __ restore();
 338   __ br(Assembler::always, false, Assembler::pt, deopt_blob->unpack_with_reexecution(), relocInfo::runtime_call_type);
 339   __ delayed()->nop();
 340 
 341   __ bind(no_deopt);
 342   restore_live_registers(sasm);
 343   __ ret();
 344   __ delayed()->restore();
 345 
 346   return oop_maps;
 347 }
 348 
 349 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
 350 
 351   OopMapSet* oop_maps = NULL;
 352   // for better readability
 353   const bool must_gc_arguments = true;
 354   const bool dont_gc_arguments = false;
 355 
 356   // stub code & info for the different stubs
 357   switch (id) {
 358     case forward_exception_id:
 359       {
 360         // we're handling an exception in the context of a compiled
 361         // frame.  The registers have been saved in the standard
 362         // places.  Perform an exception lookup in the caller and
 363         // dispatch to the handler if found.  Otherwise unwind and
 364         // dispatch to the callers exception handler.
 365         
 366         oop_maps = new OopMapSet();
 367         OopMap* oop_map = generate_oop_map(sasm, true);
 368 
 369         // transfer the pending exception to the exception_oop
 370         __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception);
 371         __ ld_ptr(Oexception, 0, G0);
 372         __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset()));
 373         __ add(I7, frame::pc_return_offset, Oissuing_pc);
 374   
 375         generate_handle_exception(sasm, oop_maps, oop_map);
 376         __ should_not_reach_here();
 377       }
 378       break;
 379 
 380     case new_instance_id:
 381     case fast_new_instance_id:
 382     case fast_new_instance_init_check_id:
 383       {
 384         Register G5_klass = G5; // Incoming
 385         Register O0_obj   = O0; // Outgoing
 386 
 387         if (id == new_instance_id) {
 388           __ set_info("new_instance", dont_gc_arguments);
 389         } else if (id == fast_new_instance_id) {
 390           __ set_info("fast new_instance", dont_gc_arguments);
 391         } else {
 392           assert(id == fast_new_instance_init_check_id, "bad StubID");
 393           __ set_info("fast new_instance init check", dont_gc_arguments);
 394         }
 395         
 396         if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
 397             UseTLAB && FastTLABRefill) {
 398           Label slow_path;
 399           Register G1_obj_size = G1;
 400           Register G3_t1 = G3;
 401           Register G4_t2 = G4;
 402           assert_different_registers(G5_klass, G1_obj_size, G3_t1, G4_t2);
 403         
 404           // Push a frame since we may do dtrace notification for the
 405           // allocation which requires calling out and we don't want
 406           // to stomp the real return address.
 407           __ save_frame(0);
 408 
 409           if (id == fast_new_instance_init_check_id) {
 410             // make sure the klass is initialized
 411             __ ld(G5_klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_t1);
 412             __ cmp(G3_t1, instanceKlass::fully_initialized);
 413             __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
 414             __ delayed()->nop();
 415           }
 416 #ifdef ASSERT
 417           // assert object can be fast path allocated
 418           {
 419             Label ok, not_ok;
 420           __ ld(G5_klass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc), G1_obj_size);
 421           __ cmp(G1_obj_size, 0);  // make sure it's an instance (LH > 0)
 422           __ br(Assembler::lessEqual, false, Assembler::pn, not_ok);
 423           __ delayed()->nop();
 424           __ btst(Klass::_lh_instance_slow_path_bit, G1_obj_size);
 425           __ br(Assembler::zero, false, Assembler::pn, ok);
 426           __ delayed()->nop();
 427           __ bind(not_ok);
 428           __ stop("assert(can be fast path allocated)");
 429           __ should_not_reach_here();
 430           __ bind(ok);
 431           }
 432 #endif // ASSERT
 433           // if we got here then the TLAB allocation failed, so try
 434           // refilling the TLAB or allocating directly from eden.
 435           Label retry_tlab, try_eden;
 436           __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G5_klass
 437 
 438           __ bind(retry_tlab);
 439 
 440           // get the instance size
 441           __ ld(G5_klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes(), G1_obj_size);
 442           __ tlab_allocate(O0_obj, G1_obj_size, 0, G3_t1, slow_path);
 443           __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2);
 444           __ verify_oop(O0_obj);
 445           __ mov(O0, I0);
 446           __ ret();
 447           __ delayed()->restore();
 448 
 449           __ bind(try_eden);
 450           // get the instance size
 451           __ ld(G5_klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes(), G1_obj_size);
 452           __ eden_allocate(O0_obj, G1_obj_size, 0, G3_t1, G4_t2, slow_path);
 453           __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2);
 454           __ verify_oop(O0_obj);
 455           __ mov(O0, I0);
 456           __ ret();
 457           __ delayed()->restore();
 458 
 459           __ bind(slow_path);
 460 
 461           // pop this frame so generate_stub_call can push it's own
 462           __ restore();
 463         }
 464         
 465         oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_instance), G5_klass);
 466         // I0->O0: new instance
 467       }
 468 
 469       break;
 470 
 471 #ifdef TIERED
 472     case counter_overflow_id:
 473         // G4 contains bci
 474       oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, counter_overflow), G4);
 475       break;
 476 #endif // TIERED
 477 
 478     case new_type_array_id:
 479     case new_object_array_id:
 480       {
 481         Register G5_klass = G5; // Incoming
 482         Register G4_length = G4; // Incoming
 483         Register O0_obj   = O0; // Outgoing
 484 
 485         Address klass_lh(G5_klass, 0, ((klassOopDesc::header_size() * HeapWordSize)
 486                                        + Klass::layout_helper_offset_in_bytes()));
 487         assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
 488         assert(Klass::_lh_header_size_mask == 0xFF, "bytewise");
 489         // Use this offset to pick out an individual byte of the layout_helper:
 490         const int klass_lh_header_size_offset = ((BytesPerInt - 1)  // 3 - 2 selects byte {0,1,0,0}
 491                                                  - Klass::_lh_header_size_shift / BitsPerByte);
 492 
 493         if (id == new_type_array_id) {
 494           __ set_info("new_type_array", dont_gc_arguments);
 495         } else {
 496           __ set_info("new_object_array", dont_gc_arguments);
 497         }
 498 
 499 #ifdef ASSERT
 500         // assert object type is really an array of the proper kind
 501         {
 502           Label ok;
 503           Register G3_t1 = G3;
 504           __ ld(klass_lh, G3_t1);
 505           __ sra(G3_t1, Klass::_lh_array_tag_shift, G3_t1);
 506           int tag = ((id == new_type_array_id)
 507                      ? Klass::_lh_array_tag_type_value
 508                      : Klass::_lh_array_tag_obj_value);
 509           __ cmp(G3_t1, tag);
 510           __ brx(Assembler::equal, false, Assembler::pt, ok);
 511           __ delayed()->nop();
 512           __ stop("assert(is an array klass)");
 513           __ should_not_reach_here();
 514           __ bind(ok);
 515         }
 516 #endif // ASSERT
 517 
 518         if (UseTLAB && FastTLABRefill) {
 519           Label slow_path;
 520           Register G1_arr_size = G1;
 521           Register G3_t1 = G3;
 522           Register O1_t2 = O1;
 523           assert_different_registers(G5_klass, G4_length, G1_arr_size, G3_t1, O1_t2);
 524 
 525           // check that array length is small enough for fast path
 526           __ set(C1_MacroAssembler::max_array_allocation_length, G3_t1);
 527           __ cmp(G4_length, G3_t1);
 528           __ br(Assembler::greaterUnsigned, false, Assembler::pn, slow_path);
 529           __ delayed()->nop();
 530 
 531           // if we got here then the TLAB allocation failed, so try
 532           // refilling the TLAB or allocating directly from eden.
 533           Label retry_tlab, try_eden;
 534           __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G4_length and G5_klass
 535           
 536           __ bind(retry_tlab);
 537 
 538           // get the allocation size: (length << (layout_helper & 0x1F)) + header_size
 539           __ ld(klass_lh, G3_t1);
 540           __ sll(G4_length, G3_t1, G1_arr_size);
 541           __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1);
 542           __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1);
 543           __ add(G1_arr_size, G3_t1, G1_arr_size);
 544           __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size);  // align up
 545           __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size);
 546 
 547           __ tlab_allocate(O0_obj, G1_arr_size, 0, G3_t1, slow_path);  // preserves G1_arr_size
 548 
 549           __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2);
 550           __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset);
 551           __ sub(G1_arr_size, G3_t1, O1_t2);  // body length
 552           __ add(O0_obj, G3_t1, G3_t1);       // body start
 553           __ initialize_body(G3_t1, O1_t2);
 554           __ verify_oop(O0_obj);
 555           __ retl();
 556           __ delayed()->nop();
 557 
 558           __ bind(try_eden);
 559           // get the allocation size: (length << (layout_helper & 0x1F)) + header_size
 560           __ ld(klass_lh, G3_t1);
 561           __ sll(G4_length, G3_t1, G1_arr_size);
 562           __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1);
 563           __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1);
 564           __ add(G1_arr_size, G3_t1, G1_arr_size);
 565           __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size);
 566           __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size);
 567 
 568           __ eden_allocate(O0_obj, G1_arr_size, 0, G3_t1, O1_t2, slow_path);  // preserves G1_arr_size
 569 
 570           __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2);
 571           __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset);
 572           __ sub(G1_arr_size, G3_t1, O1_t2);  // body length
 573           __ add(O0_obj, G3_t1, G3_t1);       // body start
 574           __ initialize_body(G3_t1, O1_t2);
 575           __ verify_oop(O0_obj);
 576           __ retl();
 577           __ delayed()->nop();
 578 
 579           __ bind(slow_path);
 580         }
 581 
 582         if (id == new_type_array_id) {
 583           oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_type_array), G5_klass, G4_length);
 584         } else {
 585           oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_object_array), G5_klass, G4_length);
 586         }
 587         // I0 -> O0: new array
 588       }
 589       break;
 590 
 591     case new_multi_array_id:
 592       { // O0: klass
 593         // O1: rank
 594         // O2: address of 1st dimension
 595         __ set_info("new_multi_array", dont_gc_arguments);
 596         oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_multi_array), I0, I1, I2);
 597         // I0 -> O0: new multi array
 598       }
 599       break;
 600 
 601     case register_finalizer_id:
 602       { 
 603         __ set_info("register_finalizer", dont_gc_arguments);
 604 
 605         // load the klass and check the has finalizer flag
 606         Label register_finalizer;
 607         Register t = O1;
 608         __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), t);
 609         __ ld(t, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc), t);
 610         __ set(JVM_ACC_HAS_FINALIZER, G3);
 611         __ andcc(G3, t, G0);
 612         __ br(Assembler::notZero, false, Assembler::pt, register_finalizer);
 613         __ delayed()->nop();
 614 
 615         // do a leaf return
 616         __ retl();
 617         __ delayed()->nop();
 618 
 619         __ bind(register_finalizer);
 620         OopMap* oop_map = save_live_registers(sasm);
 621         int call_offset = __ call_RT(noreg, noreg,
 622                                      CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), I0);
 623         oop_maps = new OopMapSet();
 624         oop_maps->add_gc_map(call_offset, oop_map);
 625 
 626         // Now restore all the live registers
 627         restore_live_registers(sasm);
 628 
 629         __ ret();
 630         __ delayed()->restore();
 631       }
 632       break;
 633 
 634     case throw_range_check_failed_id:
 635       { __ set_info("range_check_failed", dont_gc_arguments); // arguments will be discarded
 636         // G4: index
 637         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
 638       }
 639       break;
 640 
 641     case throw_index_exception_id:
 642       { __ set_info("index_range_check_failed", dont_gc_arguments); // arguments will be discarded
 643         // G4: index
 644         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
 645       }
 646       break;
 647 
 648     case throw_div0_exception_id:
 649       { __ set_info("throw_div0_exception", dont_gc_arguments);
 650         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
 651       }
 652       break;
 653 
 654     case throw_null_pointer_exception_id:
 655       { __ set_info("throw_null_pointer_exception", dont_gc_arguments);
 656         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
 657       }
 658       break;
 659 
 660     case handle_exception_id:
 661       {
 662         __ set_info("handle_exception", dont_gc_arguments);
 663         // make a frame and preserve the caller's caller-save registers
 664 
 665         oop_maps = new OopMapSet();
 666         OopMap* oop_map = save_live_registers(sasm);
 667         __ mov(Oexception->after_save(),  Oexception);
 668         __ mov(Oissuing_pc->after_save(), Oissuing_pc);
 669         generate_handle_exception(sasm, oop_maps, oop_map);
 670       }
 671       break;
 672 
 673     case unwind_exception_id:
 674       {
 675         // O0: exception
 676         // I7: address of call to this method
 677 
 678         __ set_info("unwind_exception", dont_gc_arguments);
 679         __ mov(Oexception, Oexception->after_save());
 680         __ add(I7, frame::pc_return_offset, Oissuing_pc->after_save());
 681 
 682         __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
 683                         Oissuing_pc->after_save()); 
 684         __ verify_not_null_oop(Oexception->after_save());
 685         __ jmp(O0, 0);
 686         __ delayed()->restore();
 687       }
 688       break;
 689 
 690     case throw_array_store_exception_id:
 691       {
 692         __ set_info("throw_array_store_exception", dont_gc_arguments);
 693         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), false);
 694       }
 695       break;
 696 
 697     case throw_class_cast_exception_id:
 698       {
 699         // G4: object
 700         __ set_info("throw_class_cast_exception", dont_gc_arguments);
 701         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
 702       }
 703       break;
 704 
 705     case throw_incompatible_class_change_error_id:
 706       {
 707         __ set_info("throw_incompatible_class_cast_exception", dont_gc_arguments);
 708         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
 709       }
 710       break;
 711 
 712     case slow_subtype_check_id:
 713       { // Support for uint StubRoutine::partial_subtype_check( Klass sub, Klass super );
 714         // Arguments :
 715         //
 716         //      ret  : G3
 717         //      sub  : G3, argument, destroyed
 718         //      super: G1, argument, not changed
 719         //      raddr: O7, blown by call
 720         Label loop, miss;
 721         
 722         __ save_frame(0);               // Blow no registers!
 723         
 724         __ ld_ptr( G3, sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes(), L3 );
 725         __ lduw(L3,arrayOopDesc::length_offset_in_bytes(),L0); // length in l0
 726         __ add(L3,arrayOopDesc::base_offset_in_bytes(T_OBJECT),L1); // ptr into array
 727         __ clr(L4);                     // Index
 728         // Load a little early; will load 1 off the end of the array.
 729         // Ok for now; revisit if we have other uses of this routine.
 730         __ ld_ptr(L1,0,L2);             // Will load a little early
 731         
 732         // The scan loop
 733         __ bind(loop);
 734         __ add(L1,wordSize,L1); // Bump by OOP size
 735         __ cmp(L4,L0); 
 736         __ br(Assembler::equal,false,Assembler::pn,miss);
 737         __ delayed()->inc(L4);       // Bump index
 738         __ subcc(L2,G1,L3);             // Check for match; zero in L3 for a hit
 739         __ brx( Assembler::notEqual, false, Assembler::pt, loop );
 740         __ delayed()->ld_ptr(L1,0,L2); // Will load a little early
 741         
 742         // Got a hit; report success; set cache
 743         __ st_ptr( G1, G3, sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() );
 744         
 745         __ mov(1, G3);
 746         __ ret();                       // Result in G5 is ok; flags set
 747         __ delayed()->restore();     // free copy or add can go here
 748 
 749         __ bind(miss);
 750         __ mov(0, G3);
 751         __ ret();                       // Result in G5 is ok; flags set
 752         __ delayed()->restore();     // free copy or add can go here
 753       }
 754 
 755     case monitorenter_nofpu_id:
 756     case monitorenter_id:
 757       { // G4: object
 758         // G5: lock address
 759         __ set_info("monitorenter", dont_gc_arguments);
 760 
 761         int save_fpu_registers = (id == monitorenter_id);
 762         // make a frame and preserve the caller's caller-save registers
 763         OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
 764         
 765         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), G4, G5);
 766         
 767         oop_maps = new OopMapSet();
 768         oop_maps->add_gc_map(call_offset, oop_map);
 769         restore_live_registers(sasm, save_fpu_registers);
 770         
 771         __ ret();
 772         __ delayed()->restore();
 773       }
 774       break;
 775 
 776     case monitorexit_nofpu_id:
 777     case monitorexit_id:
 778       { // G4: lock address
 779         // note: really a leaf routine but must setup last java sp
 780         //       => use call_RT for now (speed can be improved by
 781         //       doing last java sp setup manually)
 782         __ set_info("monitorexit", dont_gc_arguments);
 783 
 784         int save_fpu_registers = (id == monitorexit_id);
 785         // make a frame and preserve the caller's caller-save registers
 786         OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
 787         
 788         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), G4);
 789         
 790         oop_maps = new OopMapSet();
 791         oop_maps->add_gc_map(call_offset, oop_map);
 792         restore_live_registers(sasm, save_fpu_registers);
 793         
 794         __ ret();
 795         __ delayed()->restore();
 796 
 797       }
 798       break;
 799 
 800     case access_field_patching_id:
 801       { __ set_info("access_field_patching", dont_gc_arguments);
 802         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
 803       }
 804       break;
 805 
 806     case load_klass_patching_id:
 807       { __ set_info("load_klass_patching", dont_gc_arguments);
 808         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
 809       }
 810       break;
 811 
 812     case jvmti_exception_throw_id:
 813       { // Oexception : exception
 814         __ set_info("jvmti_exception_throw", dont_gc_arguments);
 815         oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, Runtime1::post_jvmti_exception_throw), I0);
 816       }
 817       break;
 818 
 819     case dtrace_object_alloc_id:
 820       { // O0: object
 821         __ set_info("dtrace_object_alloc", dont_gc_arguments);
 822         // we can't gc here so skip the oopmap but make sure that all
 823         // the live registers get saved.
 824         save_live_registers(sasm);
 825 
 826         __ save_thread(L7_thread_cache);
 827         __ call(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc),
 828                 relocInfo::runtime_call_type);
 829         __ delayed()->mov(I0, O0);
 830         __ restore_thread(L7_thread_cache);
 831 
 832         restore_live_registers(sasm);
 833         __ ret();
 834         __ delayed()->restore();
 835       }
 836       break;
 837 
 838 #ifndef SERIALGC
 839     case g1_pre_barrier_slow_id:
 840       { // G4: previous value of memory
 841         BarrierSet* bs = Universe::heap()->barrier_set();
 842         if (bs->kind() != BarrierSet::G1SATBCTLogging) {
 843           __ save_frame(0);
 844           __ set((int)id, O1);
 845           __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), I0);
 846           __ should_not_reach_here();
 847           break;
 848         }
 849 
 850         __ set_info("g1_pre_barrier_slow_id", dont_gc_arguments);
 851 
 852         Register pre_val = G4;
 853         Register tmp  = G1_scratch;
 854         Register tmp2 = G3_scratch;
 855 
 856         Label refill, restart;
 857         bool with_frame = false; // I don't know if we can do with-frame.
 858         int satb_q_index_byte_offset =
 859           in_bytes(JavaThread::satb_mark_queue_offset() +
 860                    PtrQueue::byte_offset_of_index());
 861         int satb_q_buf_byte_offset =
 862           in_bytes(JavaThread::satb_mark_queue_offset() +
 863                    PtrQueue::byte_offset_of_buf());
 864         __ bind(restart);
 865         __ ld_ptr(G2_thread, satb_q_index_byte_offset, tmp);
 866 
 867         __ br_on_reg_cond(Assembler::rc_z, /*annul*/false,
 868                           Assembler::pn, tmp, refill);
 869 
 870         // If the branch is taken, no harm in executing this in the delay slot.
 871         __ delayed()->ld_ptr(G2_thread, satb_q_buf_byte_offset, tmp2);
 872         __ sub(tmp, oopSize, tmp);
 873 
 874         __ st_ptr(pre_val, tmp2, tmp);  // [_buf + index] := <address_of_card>
 875         // Use return-from-leaf
 876         __ retl();
 877         __ delayed()->st_ptr(tmp, G2_thread, satb_q_index_byte_offset);
 878 
 879         __ bind(refill);
 880         __ save_frame(0);
 881 
 882         __ mov(pre_val, L0);
 883         __ mov(tmp,     L1);
 884         __ mov(tmp2,    L2);
 885 
 886         __ call_VM_leaf(L7_thread_cache,
 887                         CAST_FROM_FN_PTR(address,
 888                                          SATBMarkQueueSet::handle_zero_index_for_thread),
 889                                          G2_thread);
 890 
 891         __ mov(L0, pre_val);
 892         __ mov(L1, tmp);
 893         __ mov(L2, tmp2);
 894 
 895         __ br(Assembler::always, /*annul*/false, Assembler::pt, restart);
 896         __ delayed()->restore();
 897       }
 898       break;
 899 
 900     case g1_post_barrier_slow_id:
 901       {
 902         BarrierSet* bs = Universe::heap()->barrier_set();
 903         if (bs->kind() != BarrierSet::G1SATBCTLogging) {
 904           __ save_frame(0);
 905           __ set((int)id, O1);
 906           __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), I0);
 907           __ should_not_reach_here();
 908           break;
 909         }
 910 
 911         __ set_info("g1_post_barrier_slow_id", dont_gc_arguments);
 912 
 913         Register addr = G4;
 914         Register cardtable = G5;
 915         Register tmp  = G1_scratch;
 916         Register tmp2 = G3_scratch;
 917         jbyte* byte_map_base = ((CardTableModRefBS*)bs)->byte_map_base;
 918 
 919         Label not_already_dirty, restart, refill;
 920 
 921 #ifdef _LP64
 922         __ srlx(addr, CardTableModRefBS::card_shift, addr);
 923 #else
 924         __ srl(addr, CardTableModRefBS::card_shift, addr);
 925 #endif
 926 
 927         Address rs(cardtable, (address)byte_map_base);
 928         __ load_address(rs); // cardtable := <card table base>
 929         __ ldub(addr, cardtable, tmp); // tmp := [addr + cardtable]
 930 
 931         __ br_on_reg_cond(Assembler::rc_nz, /*annul*/false, Assembler::pt,
 932                           tmp, not_already_dirty);
 933         // Get cardtable + tmp into a reg by itself -- useful in the take-the-branch
 934         // case, harmless if not.
 935         __ delayed()->add(addr, cardtable, tmp2);
 936 
 937         // We didn't take the branch, so we're already dirty: return.
 938         // Use return-from-leaf
 939         __ retl();
 940         __ delayed()->nop();
 941 
 942         // Not dirty.
 943         __ bind(not_already_dirty);
 944         // First, dirty it.
 945         __ stb(G0, tmp2, 0);  // [cardPtr] := 0  (i.e., dirty).
 946 
 947         Register tmp3 = cardtable;
 948         Register tmp4 = tmp;
 949 
 950         // these registers are now dead
 951         addr = cardtable = tmp = noreg;
 952 
 953         int dirty_card_q_index_byte_offset =
 954           in_bytes(JavaThread::dirty_card_queue_offset() +
 955                    PtrQueue::byte_offset_of_index());
 956         int dirty_card_q_buf_byte_offset =
 957           in_bytes(JavaThread::dirty_card_queue_offset() +
 958                    PtrQueue::byte_offset_of_buf());
 959         __ bind(restart);
 960         __ ld_ptr(G2_thread, dirty_card_q_index_byte_offset, tmp3);
 961 
 962         __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pn,
 963                           tmp3, refill);
 964         // If the branch is taken, no harm in executing this in the delay slot.
 965         __ delayed()->ld_ptr(G2_thread, dirty_card_q_buf_byte_offset, tmp4);
 966         __ sub(tmp3, oopSize, tmp3);
 967 
 968         __ st_ptr(tmp2, tmp4, tmp3);  // [_buf + index] := <address_of_card>
 969         // Use return-from-leaf
 970         __ retl();
 971         __ delayed()->st_ptr(tmp3, G2_thread, dirty_card_q_index_byte_offset);
 972 
 973         __ bind(refill);
 974         __ save_frame(0);
 975 
 976         __ mov(tmp2, L0);
 977         __ mov(tmp3, L1);
 978         __ mov(tmp4, L2);
 979 
 980         __ call_VM_leaf(L7_thread_cache,
 981                         CAST_FROM_FN_PTR(address,
 982                                          DirtyCardQueueSet::handle_zero_index_for_thread),
 983                                          G2_thread);
 984 
 985         __ mov(L0, tmp2);
 986         __ mov(L1, tmp3);
 987         __ mov(L2, tmp4);
 988 
 989         __ br(Assembler::always, /*annul*/false, Assembler::pt, restart);
 990         __ delayed()->restore();
 991       }
 992       break;
 993 #endif // !SERIALGC
 994 
 995     default:
 996       { __ set_info("unimplemented entry", dont_gc_arguments);
 997         __ save_frame(0);
 998         __ set((int)id, O1);
 999         __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), O1);
1000         __ should_not_reach_here();
1001       }
1002       break;
1003   }
1004   return oop_maps;
1005 }
1006 
1007 
1008 void Runtime1::generate_handle_exception(StubAssembler* sasm, OopMapSet* oop_maps, OopMap* oop_map, bool) {
1009   Label no_deopt;
1010   Label no_handler;
1011 
1012   __ verify_not_null_oop(Oexception);
1013 
1014   // save the exception and issuing pc in the thread
1015   __ st_ptr(Oexception, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
1016   __ st_ptr(Oissuing_pc, G2_thread, in_bytes(JavaThread::exception_pc_offset()));
1017 
1018   // save the real return address and use the throwing pc as the return address to lookup (has bci & oop map)
1019   __ mov(I7, L0);
1020   __ mov(Oissuing_pc, I7);
1021   __ sub(I7, frame::pc_return_offset, I7);
1022   int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
1023 
1024   // Note: if nmethod has been deoptimized then regardless of
1025   // whether it had a handler or not we will deoptimize
1026   // by entering the deopt blob with a pending exception.
1027 
1028   __ tst(O0);
1029   __ br(Assembler::zero, false, Assembler::pn, no_handler);
1030   __ delayed()->nop();
1031 
1032   // restore the registers that were saved at the beginning and jump to the exception handler.
1033   restore_live_registers(sasm);
1034 
1035   __ jmp(O0, 0);
1036   __ delayed()->restore();
1037 
1038   __ bind(no_handler);
1039   __ mov(L0, I7); // restore return address
1040 
1041   // restore exception oop
1042   __ ld_ptr(G2_thread, in_bytes(JavaThread::exception_oop_offset()), Oexception->after_save());
1043   __ st_ptr(G0, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
1044 
1045   __ restore();
1046   
1047   Address exc(G4, Runtime1::entry_for(Runtime1::unwind_exception_id));
1048   __ jump_to(exc, 0);
1049   __ delayed()->nop();
1050 
1051 
1052   oop_maps->add_gc_map(call_offset, oop_map);
1053 }
1054 
1055 
1056 #undef __
1057 
1058 #define __ masm->
1059