rev 51052 : [mq]: eden

   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.inline.hpp"
  27 #include "c1/c1_Defs.hpp"
  28 #include "c1/c1_MacroAssembler.hpp"
  29 #include "c1/c1_Runtime1.hpp"
  30 #include "ci/ciUtilities.hpp"
  31 #include "gc/shared/cardTable.hpp"
  32 #include "gc/shared/cardTableBarrierSet.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "nativeInst_sparc.hpp"
  35 #include "oops/compiledICHolder.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "prims/jvmtiExport.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #include "runtime/signature.hpp"
  40 #include "runtime/vframeArray.hpp"
  41 #include "utilities/macros.hpp"
  42 #include "utilities/align.hpp"
  43 #include "vmreg_sparc.inline.hpp"
  44 
  45 // Implementation of StubAssembler
  46 
  47 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry_point, int number_of_arguments) {
  48   // for sparc changing the number of arguments doesn't change
  49   // anything about the frame size so we'll always lie and claim that
  50   // we are only passing 1 argument.
  51   set_num_rt_args(1);
  52 
  53   assert_not_delayed();
  54   // bang stack before going to runtime
  55   set(-os::vm_page_size() + STACK_BIAS, G3_scratch);
  56   st(G0, SP, G3_scratch);
  57 
  58   // debugging support
  59   assert(number_of_arguments >= 0   , "cannot have negative number of arguments");
  60 
  61   set_last_Java_frame(SP, noreg);
  62   if (VerifyThread)  mov(G2_thread, O0); // about to be smashed; pass early
  63   save_thread(L7_thread_cache);
  64   // do the call
  65   call(entry_point, relocInfo::runtime_call_type);
  66   if (!VerifyThread) {
  67     delayed()->mov(G2_thread, O0);  // pass thread as first argument
  68   } else {
  69     delayed()->nop();             // (thread already passed)
  70   }
  71   int call_offset = offset();  // offset of return address
  72   restore_thread(L7_thread_cache);
  73   reset_last_Java_frame();
  74 
  75   // check for pending exceptions
  76   { Label L;
  77     Address exception_addr(G2_thread, Thread::pending_exception_offset());
  78     ld_ptr(exception_addr, Gtemp);
  79     br_null_short(Gtemp, pt, L);
  80     Address vm_result_addr(G2_thread, JavaThread::vm_result_offset());
  81     st_ptr(G0, vm_result_addr);
  82     Address vm_result_addr_2(G2_thread, JavaThread::vm_result_2_offset());
  83     st_ptr(G0, vm_result_addr_2);
  84 
  85     if (frame_size() == no_frame_size) {
  86       // we use O7 linkage so that forward_exception_entry has the issuing PC
  87       call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
  88       delayed()->restore();
  89     } else if (_stub_id == Runtime1::forward_exception_id) {
  90       should_not_reach_here();
  91     } else {
  92       AddressLiteral exc(Runtime1::entry_for(Runtime1::forward_exception_id));
  93       jump_to(exc, G4);
  94       delayed()->nop();
  95     }
  96     bind(L);
  97   }
  98 
  99   // get oop result if there is one and reset the value in the thread
 100   if (oop_result1->is_valid()) {                    // get oop result if there is one and reset it in the thread
 101     get_vm_result  (oop_result1);
 102   } else {
 103     // be a little paranoid and clear the result
 104     Address vm_result_addr(G2_thread, JavaThread::vm_result_offset());
 105     st_ptr(G0, vm_result_addr);
 106   }
 107 
 108   // get second result if there is one and reset the value in the thread
 109   if (metadata_result->is_valid()) {
 110     get_vm_result_2  (metadata_result);
 111   } else {
 112     // be a little paranoid and clear the result
 113     Address vm_result_addr_2(G2_thread, JavaThread::vm_result_2_offset());
 114     st_ptr(G0, vm_result_addr_2);
 115   }
 116 
 117   return call_offset;
 118 }
 119 
 120 
 121 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {
 122   // O0 is reserved for the thread
 123   mov(arg1, O1);
 124   return call_RT(oop_result1, metadata_result, entry, 1);
 125 }
 126 
 127 
 128 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {
 129   // O0 is reserved for the thread
 130   mov(arg1, O1);
 131   mov(arg2, O2); assert(arg2 != O1, "smashed argument");
 132   return call_RT(oop_result1, metadata_result, entry, 2);
 133 }
 134 
 135 
 136 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {
 137   // O0 is reserved for the thread
 138   mov(arg1, O1);
 139   mov(arg2, O2); assert(arg2 != O1,               "smashed argument");
 140   mov(arg3, O3); assert(arg3 != O1 && arg3 != O2, "smashed argument");
 141   return call_RT(oop_result1, metadata_result, entry, 3);
 142 }
 143 
 144 void StubAssembler::prologue(const char* name, bool must_gc_arguments) {
 145   set_info(name, must_gc_arguments);
 146 }
 147 
 148 void StubAssembler::epilogue() {
 149   delayed()->restore();
 150 }
 151 
 152 // Implementation of Runtime1
 153 
 154 
 155 static int cpu_reg_save_offsets[FrameMap::nof_cpu_regs];
 156 static int fpu_reg_save_offsets[FrameMap::nof_fpu_regs];
 157 static int reg_save_size_in_words;
 158 static int frame_size_in_bytes = -1;
 159 
 160 static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) {
 161   assert(frame_size_in_bytes == sasm->total_frame_size_in_bytes(reg_save_size_in_words),
 162          "mismatch in calculation");
 163   sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
 164   int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
 165   OopMap* oop_map = new OopMap(frame_size_in_slots, 0);
 166 
 167   int i;
 168   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 169     Register r = as_Register(i);
 170     if (r == G1 || r == G3 || r == G4 || r == G5) {
 171       int sp_offset = cpu_reg_save_offsets[i];
 172       oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
 173                                 r->as_VMReg());
 174     }
 175   }
 176 
 177   if (save_fpu_registers) {
 178     for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 179       FloatRegister r = as_FloatRegister(i);
 180       int sp_offset = fpu_reg_save_offsets[i];
 181       oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
 182                                 r->as_VMReg());
 183     }
 184   }
 185   return oop_map;
 186 }
 187 
 188 #define __ this->
 189 
 190 void C1_MacroAssembler::save_live_registers_no_oop_map(bool save_fpu_registers) {
 191   assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
 192          "mismatch in calculation");
 193   __ save_frame_c1(frame_size_in_bytes);
 194 
 195   // Record volatile registers as callee-save values in an OopMap so their save locations will be
 196   // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for
 197   // deoptimization; see compiledVFrame::create_stack_value).  The caller's I, L and O registers
 198   // are saved in register windows - I's and L's in the caller's frame and O's in the stub frame
 199   // (as the stub's I's) when the runtime routine called by the stub creates its frame.
 200   // OopMap frame sizes are in c2 stack slot sizes (sizeof(jint))
 201 
 202   int i;
 203   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 204     Register r = as_Register(i);
 205     if (r == G1 || r == G3 || r == G4 || r == G5) {
 206       int sp_offset = cpu_reg_save_offsets[i];
 207       __ st_ptr(r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
 208     }
 209   }
 210 
 211   if (save_fpu_registers) {
 212     for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 213       FloatRegister r = as_FloatRegister(i);
 214       int sp_offset = fpu_reg_save_offsets[i];
 215       __ stf(FloatRegisterImpl::S, r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
 216     }
 217   }
 218 }
 219 
 220 void C1_MacroAssembler::restore_live_registers(bool restore_fpu_registers) {
 221   for (int i = 0; i < FrameMap::nof_cpu_regs; i++) {
 222     Register r = as_Register(i);
 223     if (r == G1 || r == G3 || r == G4 || r == G5) {
 224       __ ld_ptr(SP, (cpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
 225     }
 226   }
 227 
 228   if (restore_fpu_registers) {
 229     for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
 230       FloatRegister r = as_FloatRegister(i);
 231       __ ldf(FloatRegisterImpl::S, SP, (fpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
 232     }
 233   }
 234 }
 235 
 236 #undef __
 237 #define __ sasm->
 238 
 239 static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) {
 240   __ save_live_registers_no_oop_map(save_fpu_registers);
 241   return generate_oop_map(sasm, save_fpu_registers);
 242 }
 243 
 244 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
 245   __ restore_live_registers(restore_fpu_registers);
 246 }
 247 
 248 
 249 void Runtime1::initialize_pd() {
 250   // compute word offsets from SP at which live (non-windowed) registers are captured by stub routines
 251   //
 252   // A stub routine will have a frame that is at least large enough to hold
 253   // a register window save area (obviously) and the volatile g registers
 254   // and floating registers. A user of save_live_registers can have a frame
 255   // that has more scratch area in it (although typically they will use L-regs).
 256   // in that case the frame will look like this (stack growing down)
 257   //
 258   // FP -> |             |
 259   //       | scratch mem |
 260   //       |   "      "  |
 261   //       --------------
 262   //       | float regs  |
 263   //       |   "    "    |
 264   //       ---------------
 265   //       | G regs      |
 266   //       | "  "        |
 267   //       ---------------
 268   //       | abi reg.    |
 269   //       | window save |
 270   //       | area        |
 271   // SP -> ---------------
 272   //
 273   int i;
 274   int sp_offset = align_up((int)frame::register_save_words, 2); //  start doubleword aligned
 275 
 276   // only G int registers are saved explicitly; others are found in register windows
 277   for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
 278     Register r = as_Register(i);
 279     if (r == G1 || r == G3 || r == G4 || r == G5) {
 280       cpu_reg_save_offsets[i] = sp_offset;
 281       sp_offset++;
 282     }
 283   }
 284 
 285   // all float registers are saved explicitly
 286   assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here");
 287   for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
 288     fpu_reg_save_offsets[i] = sp_offset;
 289     sp_offset++;
 290   }
 291   reg_save_size_in_words = sp_offset - frame::memory_parameter_word_sp_offset;
 292   // this should match assembler::total_frame_size_in_bytes, which
 293   // isn't callable from this context.  It's checked by an assert when
 294   // it's used though.
 295   frame_size_in_bytes = align_up(sp_offset * wordSize, 8);
 296 }
 297 
 298 
 299 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
 300   // make a frame and preserve the caller's caller-save registers
 301   OopMap* oop_map = save_live_registers(sasm);
 302   int call_offset;
 303   if (!has_argument) {
 304     call_offset = __ call_RT(noreg, noreg, target);
 305   } else {
 306     call_offset = __ call_RT(noreg, noreg, target, G4, G5);
 307   }
 308   OopMapSet* oop_maps = new OopMapSet();
 309   oop_maps->add_gc_map(call_offset, oop_map);
 310 
 311   __ should_not_reach_here();
 312   return oop_maps;
 313 }
 314 
 315 
 316 OopMapSet* Runtime1::generate_stub_call(StubAssembler* sasm, Register result, address target,
 317                                         Register arg1, Register arg2, Register arg3) {
 318   // make a frame and preserve the caller's caller-save registers
 319   OopMap* oop_map = save_live_registers(sasm);
 320 
 321   int call_offset;
 322   if (arg1 == noreg) {
 323     call_offset = __ call_RT(result, noreg, target);
 324   } else if (arg2 == noreg) {
 325     call_offset = __ call_RT(result, noreg, target, arg1);
 326   } else if (arg3 == noreg) {
 327     call_offset = __ call_RT(result, noreg, target, arg1, arg2);
 328   } else {
 329     call_offset = __ call_RT(result, noreg, target, arg1, arg2, arg3);
 330   }
 331   OopMapSet* oop_maps = NULL;
 332 
 333   oop_maps = new OopMapSet();
 334   oop_maps->add_gc_map(call_offset, oop_map);
 335   restore_live_registers(sasm);
 336 
 337   __ ret();
 338   __ delayed()->restore();
 339 
 340   return oop_maps;
 341 }
 342 
 343 
 344 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
 345   // make a frame and preserve the caller's caller-save registers
 346   OopMap* oop_map = save_live_registers(sasm);
 347 
 348   // call the runtime patching routine, returns non-zero if nmethod got deopted.
 349   int call_offset = __ call_RT(noreg, noreg, target);
 350   OopMapSet* oop_maps = new OopMapSet();
 351   oop_maps->add_gc_map(call_offset, oop_map);
 352 
 353   // re-execute the patched instruction or, if the nmethod was deoptmized, return to the
 354   // deoptimization handler entry that will cause re-execution of the current bytecode
 355   DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 356   assert(deopt_blob != NULL, "deoptimization blob must have been created");
 357 
 358   Label no_deopt;
 359   __ br_null_short(O0, Assembler::pt, no_deopt);
 360 
 361   // return to the deoptimization handler entry for unpacking and rexecute
 362   // if we simply returned the we'd deopt as if any call we patched had just
 363   // returned.
 364 
 365   restore_live_registers(sasm);
 366 
 367   AddressLiteral dest(deopt_blob->unpack_with_reexecution());
 368   __ jump_to(dest, O0);
 369   __ delayed()->restore();
 370 
 371   __ bind(no_deopt);
 372   restore_live_registers(sasm);
 373   __ ret();
 374   __ delayed()->restore();
 375 
 376   return oop_maps;
 377 }
 378 
 379 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
 380 
 381   OopMapSet* oop_maps = NULL;
 382   // for better readability
 383   const bool must_gc_arguments = true;
 384   const bool dont_gc_arguments = false;
 385 
 386   // stub code & info for the different stubs
 387   switch (id) {
 388     case forward_exception_id:
 389       {
 390         oop_maps = generate_handle_exception(id, sasm);
 391       }
 392       break;
 393 
 394     case new_instance_id:
 395     case fast_new_instance_id:
 396     case fast_new_instance_init_check_id:
 397       {
 398         Register G5_klass = G5; // Incoming
 399         Register O0_obj   = O0; // Outgoing
 400 
 401         if (id == new_instance_id) {
 402           __ set_info("new_instance", dont_gc_arguments);
 403         } else if (id == fast_new_instance_id) {
 404           __ set_info("fast new_instance", dont_gc_arguments);
 405         } else {
 406           assert(id == fast_new_instance_init_check_id, "bad StubID");
 407           __ set_info("fast new_instance init check", dont_gc_arguments);
 408         }
 409 



 410         if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
 411             UseTLAB && Universe::heap()->supports_inline_contig_alloc()) {
 412           Label slow_path;
 413           Register G1_obj_size = G1;
 414           Register G3_t1 = G3;
 415           Register G4_t2 = G4;
 416           assert_different_registers(G5_klass, G1_obj_size, G3_t1, G4_t2);
 417 
 418           // Push a frame since we may do dtrace notification for the
 419           // allocation which requires calling out and we don't want
 420           // to stomp the real return address.
 421           __ save_frame(0);
 422 
 423           if (id == fast_new_instance_init_check_id) {
 424             // make sure the klass is initialized
 425             __ ldub(G5_klass, in_bytes(InstanceKlass::init_state_offset()), G3_t1);
 426             __ cmp(G3_t1, InstanceKlass::fully_initialized);
 427             __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
 428             __ delayed()->nop();
 429           }
 430 #ifdef ASSERT
 431           // assert object can be fast path allocated
 432           {
 433             Label ok, not_ok;
 434           __ ld(G5_klass, in_bytes(Klass::layout_helper_offset()), G1_obj_size);
 435           // make sure it's an instance (LH > 0)
 436           __ cmp_and_br_short(G1_obj_size, 0, Assembler::lessEqual, Assembler::pn, not_ok);
 437           __ btst(Klass::_lh_instance_slow_path_bit, G1_obj_size);
 438           __ br(Assembler::zero, false, Assembler::pn, ok);
 439           __ delayed()->nop();
 440           __ bind(not_ok);
 441           __ stop("assert(can be fast path allocated)");
 442           __ should_not_reach_here();
 443           __ bind(ok);
 444           }
 445 #endif // ASSERT
 446 
 447           // If we got here then the TLAB allocation failed, so try allocating directly from eden.
 448           // get the instance size
 449           __ ld(G5_klass, in_bytes(Klass::layout_helper_offset()), G1_obj_size);
 450           __ eden_allocate(O0_obj, G1_obj_size, 0, G3_t1, G4_t2, slow_path);
 451           __ incr_allocated_bytes(G1_obj_size, G3_t1, G4_t2);
 452 
 453           __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2, /* is_tlab_allocated */ false);
 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     case counter_overflow_id:
 472         // G4 contains bci, G5 contains method
 473       oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, counter_overflow), G4, G5);
 474       break;
 475 
 476     case new_type_array_id:
 477     case new_object_array_id:
 478       {
 479         Register G5_klass = G5; // Incoming
 480         Register G4_length = G4; // Incoming
 481         Register O0_obj   = O0; // Outgoing
 482 
 483         Address klass_lh(G5_klass, Klass::layout_helper_offset());
 484         assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
 485         assert(Klass::_lh_header_size_mask == 0xFF, "bytewise");
 486         // Use this offset to pick out an individual byte of the layout_helper:
 487         const int klass_lh_header_size_offset = ((BytesPerInt - 1)  // 3 - 2 selects byte {0,1,0,0}
 488                                                  - Klass::_lh_header_size_shift / BitsPerByte);
 489 
 490         if (id == new_type_array_id) {
 491           __ set_info("new_type_array", dont_gc_arguments);
 492         } else {
 493           __ set_info("new_object_array", dont_gc_arguments);
 494         }
 495 
 496 #ifdef ASSERT
 497         // assert object type is really an array of the proper kind
 498         {
 499           Label ok;
 500           Register G3_t1 = G3;
 501           __ ld(klass_lh, G3_t1);
 502           __ sra(G3_t1, Klass::_lh_array_tag_shift, G3_t1);
 503           int tag = ((id == new_type_array_id)
 504                      ? Klass::_lh_array_tag_type_value
 505                      : Klass::_lh_array_tag_obj_value);
 506           __ cmp_and_brx_short(G3_t1, tag, Assembler::equal, Assembler::pt, ok);
 507           __ stop("assert(is an array klass)");
 508           __ should_not_reach_here();
 509           __ bind(ok);
 510         }
 511 #endif // ASSERT
 512 
 513         if (id == new_type_array_id) {
 514           oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_type_array), G5_klass, G4_length);
 515         } else {
 516           oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_object_array), G5_klass, G4_length);
 517         }
 518         // I0 -> O0: new array
 519       }
 520       break;
 521 
 522     case new_multi_array_id:
 523       { // O0: klass
 524         // O1: rank
 525         // O2: address of 1st dimension
 526         __ set_info("new_multi_array", dont_gc_arguments);
 527         oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_multi_array), I0, I1, I2);
 528         // I0 -> O0: new multi array
 529       }
 530       break;
 531 
 532     case register_finalizer_id:
 533       {
 534         __ set_info("register_finalizer", dont_gc_arguments);
 535 
 536         // load the klass and check the has finalizer flag
 537         Label register_finalizer;
 538         Register t = O1;
 539         __ load_klass(O0, t);
 540         __ ld(t, in_bytes(Klass::access_flags_offset()), t);
 541         __ set(JVM_ACC_HAS_FINALIZER, G3);
 542         __ andcc(G3, t, G0);
 543         __ br(Assembler::notZero, false, Assembler::pt, register_finalizer);
 544         __ delayed()->nop();
 545 
 546         // do a leaf return
 547         __ retl();
 548         __ delayed()->nop();
 549 
 550         __ bind(register_finalizer);
 551         OopMap* oop_map = save_live_registers(sasm);
 552         int call_offset = __ call_RT(noreg, noreg,
 553                                      CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), I0);
 554         oop_maps = new OopMapSet();
 555         oop_maps->add_gc_map(call_offset, oop_map);
 556 
 557         // Now restore all the live registers
 558         restore_live_registers(sasm);
 559 
 560         __ ret();
 561         __ delayed()->restore();
 562       }
 563       break;
 564 
 565     case throw_range_check_failed_id:
 566       { __ set_info("range_check_failed", dont_gc_arguments); // arguments will be discarded
 567         // G4: index
 568         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
 569       }
 570       break;
 571 
 572     case throw_index_exception_id:
 573       { __ set_info("index_range_check_failed", dont_gc_arguments); // arguments will be discarded
 574         // G4: index
 575         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
 576       }
 577       break;
 578 
 579     case throw_div0_exception_id:
 580       { __ set_info("throw_div0_exception", dont_gc_arguments);
 581         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
 582       }
 583       break;
 584 
 585     case throw_null_pointer_exception_id:
 586       { __ set_info("throw_null_pointer_exception", dont_gc_arguments);
 587         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
 588       }
 589       break;
 590 
 591     case handle_exception_id:
 592       { __ set_info("handle_exception", dont_gc_arguments);
 593         oop_maps = generate_handle_exception(id, sasm);
 594       }
 595       break;
 596 
 597     case handle_exception_from_callee_id:
 598       { __ set_info("handle_exception_from_callee", dont_gc_arguments);
 599         oop_maps = generate_handle_exception(id, sasm);
 600       }
 601       break;
 602 
 603     case unwind_exception_id:
 604       {
 605         // O0: exception
 606         // I7: address of call to this method
 607 
 608         __ set_info("unwind_exception", dont_gc_arguments);
 609         __ mov(Oexception, Oexception->after_save());
 610         __ add(I7, frame::pc_return_offset, Oissuing_pc->after_save());
 611 
 612         __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
 613                         G2_thread, Oissuing_pc->after_save());
 614         __ verify_not_null_oop(Oexception->after_save());
 615 
 616         // Restore SP from L7 if the exception PC is a method handle call site.
 617         __ mov(O0, G5);  // Save the target address.
 618         __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0);
 619         __ tst(L0);  // Condition codes are preserved over the restore.
 620         __ restore();
 621 
 622         __ jmp(G5, 0);
 623         __ delayed()->movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP);  // Restore SP if required.
 624       }
 625       break;
 626 
 627     case throw_array_store_exception_id:
 628       {
 629         __ set_info("throw_array_store_exception", dont_gc_arguments);
 630         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);
 631       }
 632       break;
 633 
 634     case throw_class_cast_exception_id:
 635       {
 636         // G4: object
 637         __ set_info("throw_class_cast_exception", dont_gc_arguments);
 638         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
 639       }
 640       break;
 641 
 642     case throw_incompatible_class_change_error_id:
 643       {
 644         __ set_info("throw_incompatible_class_cast_exception", dont_gc_arguments);
 645         oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
 646       }
 647       break;
 648 
 649     case slow_subtype_check_id:
 650       { // Support for uint StubRoutine::partial_subtype_check( Klass sub, Klass super );
 651         // Arguments :
 652         //
 653         //      ret  : G3
 654         //      sub  : G3, argument, destroyed
 655         //      super: G1, argument, not changed
 656         //      raddr: O7, blown by call
 657         Label miss;
 658 
 659         __ save_frame(0);               // Blow no registers!
 660 
 661         __ check_klass_subtype_slow_path(G3, G1, L0, L1, L2, L4, NULL, &miss);
 662 
 663         __ mov(1, G3);
 664         __ ret();                       // Result in G5 is 'true'
 665         __ delayed()->restore();        // free copy or add can go here
 666 
 667         __ bind(miss);
 668         __ mov(0, G3);
 669         __ ret();                       // Result in G5 is 'false'
 670         __ delayed()->restore();        // free copy or add can go here
 671       }
 672 
 673     case monitorenter_nofpu_id:
 674     case monitorenter_id:
 675       { // G4: object
 676         // G5: lock address
 677         __ set_info("monitorenter", dont_gc_arguments);
 678 
 679         int save_fpu_registers = (id == monitorenter_id);
 680         // make a frame and preserve the caller's caller-save registers
 681         OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
 682 
 683         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), G4, G5);
 684 
 685         oop_maps = new OopMapSet();
 686         oop_maps->add_gc_map(call_offset, oop_map);
 687         restore_live_registers(sasm, save_fpu_registers);
 688 
 689         __ ret();
 690         __ delayed()->restore();
 691       }
 692       break;
 693 
 694     case monitorexit_nofpu_id:
 695     case monitorexit_id:
 696       { // G4: lock address
 697         // note: really a leaf routine but must setup last java sp
 698         //       => use call_RT for now (speed can be improved by
 699         //       doing last java sp setup manually)
 700         __ set_info("monitorexit", dont_gc_arguments);
 701 
 702         int save_fpu_registers = (id == monitorexit_id);
 703         // make a frame and preserve the caller's caller-save registers
 704         OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
 705 
 706         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), G4);
 707 
 708         oop_maps = new OopMapSet();
 709         oop_maps->add_gc_map(call_offset, oop_map);
 710         restore_live_registers(sasm, save_fpu_registers);
 711 
 712         __ ret();
 713         __ delayed()->restore();
 714       }
 715       break;
 716 
 717     case deoptimize_id:
 718       {
 719         __ set_info("deoptimize", dont_gc_arguments);
 720         OopMap* oop_map = save_live_registers(sasm);
 721         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize), G4);
 722         oop_maps = new OopMapSet();
 723         oop_maps->add_gc_map(call_offset, oop_map);
 724         restore_live_registers(sasm);
 725         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 726         assert(deopt_blob != NULL, "deoptimization blob must have been created");
 727         AddressLiteral dest(deopt_blob->unpack_with_reexecution());
 728         __ jump_to(dest, O0);
 729         __ delayed()->restore();
 730       }
 731       break;
 732 
 733     case access_field_patching_id:
 734       { __ set_info("access_field_patching", dont_gc_arguments);
 735         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
 736       }
 737       break;
 738 
 739     case load_klass_patching_id:
 740       { __ set_info("load_klass_patching", dont_gc_arguments);
 741         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
 742       }
 743       break;
 744 
 745     case load_mirror_patching_id:
 746       { __ set_info("load_mirror_patching", dont_gc_arguments);
 747         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
 748       }
 749       break;
 750 
 751     case load_appendix_patching_id:
 752       { __ set_info("load_appendix_patching", dont_gc_arguments);
 753         oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
 754       }
 755       break;
 756 
 757     case dtrace_object_alloc_id:
 758       { // O0: object
 759         __ set_info("dtrace_object_alloc", dont_gc_arguments);
 760         // we can't gc here so skip the oopmap but make sure that all
 761         // the live registers get saved.
 762         save_live_registers(sasm);
 763 
 764         __ save_thread(L7_thread_cache);
 765         __ call(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc),
 766                 relocInfo::runtime_call_type);
 767         __ delayed()->mov(I0, O0);
 768         __ restore_thread(L7_thread_cache);
 769 
 770         restore_live_registers(sasm);
 771         __ ret();
 772         __ delayed()->restore();
 773       }
 774       break;
 775 
 776     case predicate_failed_trap_id:
 777       {
 778         __ set_info("predicate_failed_trap", dont_gc_arguments);
 779         OopMap* oop_map = save_live_registers(sasm);
 780 
 781         int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));
 782 
 783         oop_maps = new OopMapSet();
 784         oop_maps->add_gc_map(call_offset, oop_map);
 785 
 786         DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
 787         assert(deopt_blob != NULL, "deoptimization blob must have been created");
 788         restore_live_registers(sasm);
 789 
 790         AddressLiteral dest(deopt_blob->unpack_with_reexecution());
 791         __ jump_to(dest, O0);
 792         __ delayed()->restore();
 793       }
 794       break;
 795 
 796     default:
 797       { __ set_info("unimplemented entry", dont_gc_arguments);
 798         __ save_frame(0);
 799         __ set((int)id, O1);
 800         __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), O1);
 801         __ should_not_reach_here();
 802       }
 803       break;
 804   }
 805   return oop_maps;
 806 }
 807 
 808 
 809 OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler* sasm) {
 810   __ block_comment("generate_handle_exception");
 811 
 812   // Save registers, if required.
 813   OopMapSet* oop_maps = new OopMapSet();
 814   OopMap* oop_map = NULL;
 815   switch (id) {
 816   case forward_exception_id:
 817     // We're handling an exception in the context of a compiled frame.
 818     // The registers have been saved in the standard places.  Perform
 819     // an exception lookup in the caller and dispatch to the handler
 820     // if found.  Otherwise unwind and dispatch to the callers
 821     // exception handler.
 822      oop_map = generate_oop_map(sasm, true);
 823 
 824      // transfer the pending exception to the exception_oop
 825      __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception);
 826      __ ld_ptr(Oexception, 0, G0);
 827      __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset()));
 828      __ add(I7, frame::pc_return_offset, Oissuing_pc);
 829     break;
 830   case handle_exception_id:
 831     // At this point all registers MAY be live.
 832     oop_map = save_live_registers(sasm);
 833     __ mov(Oexception->after_save(),  Oexception);
 834     __ mov(Oissuing_pc->after_save(), Oissuing_pc);
 835     break;
 836   case handle_exception_from_callee_id:
 837     // At this point all registers except exception oop (Oexception)
 838     // and exception pc (Oissuing_pc) are dead.
 839     oop_map = new OopMap(frame_size_in_bytes / sizeof(jint), 0);
 840     sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
 841     __ save_frame_c1(frame_size_in_bytes);
 842     __ mov(Oexception->after_save(),  Oexception);
 843     __ mov(Oissuing_pc->after_save(), Oissuing_pc);
 844     break;
 845   default:  ShouldNotReachHere();
 846   }
 847 
 848   __ verify_not_null_oop(Oexception);
 849 
 850 #ifdef ASSERT
 851   // check that fields in JavaThread for exception oop and issuing pc are
 852   // empty before writing to them
 853   Label oop_empty;
 854   Register scratch = I7;  // We can use I7 here because it's overwritten later anyway.
 855   __ ld_ptr(Address(G2_thread, JavaThread::exception_oop_offset()), scratch);
 856   __ br_null(scratch, false, Assembler::pt, oop_empty);
 857   __ delayed()->nop();
 858   __ stop("exception oop already set");
 859   __ bind(oop_empty);
 860 
 861   Label pc_empty;
 862   __ ld_ptr(Address(G2_thread, JavaThread::exception_pc_offset()), scratch);
 863   __ br_null(scratch, false, Assembler::pt, pc_empty);
 864   __ delayed()->nop();
 865   __ stop("exception pc already set");
 866   __ bind(pc_empty);
 867 #endif
 868 
 869   // save the exception and issuing pc in the thread
 870   __ st_ptr(Oexception,  G2_thread, in_bytes(JavaThread::exception_oop_offset()));
 871   __ st_ptr(Oissuing_pc, G2_thread, in_bytes(JavaThread::exception_pc_offset()));
 872 
 873   // use the throwing pc as the return address to lookup (has bci & oop map)
 874   __ mov(Oissuing_pc, I7);
 875   __ sub(I7, frame::pc_return_offset, I7);
 876   int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
 877   oop_maps->add_gc_map(call_offset, oop_map);
 878 
 879   // Note: if nmethod has been deoptimized then regardless of
 880   // whether it had a handler or not we will deoptimize
 881   // by entering the deopt blob with a pending exception.
 882 
 883   // Restore the registers that were saved at the beginning, remove
 884   // the frame and jump to the exception handler.
 885   switch (id) {
 886   case forward_exception_id:
 887   case handle_exception_id:
 888     restore_live_registers(sasm);
 889     __ jmp(O0, 0);
 890     __ delayed()->restore();
 891     break;
 892   case handle_exception_from_callee_id:
 893     // Restore SP from L7 if the exception PC is a method handle call site.
 894     __ mov(O0, G5);  // Save the target address.
 895     __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0);
 896     __ tst(L0);  // Condition codes are preserved over the restore.
 897     __ restore();
 898 
 899     __ jmp(G5, 0);  // jump to the exception handler
 900     __ delayed()->movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP);  // Restore SP if required.
 901     break;
 902   default:  ShouldNotReachHere();
 903   }
 904 
 905   return oop_maps;
 906 }
 907 
 908 
 909 #undef __
 910 
 911 const char *Runtime1::pd_name_for_address(address entry) {
 912   return "<unknown function>";
 913 }
--- EOF ---