src/cpu/sparc/vm/c1_Runtime1_sparc.cpp

changeset 435
a61af66fc99e
child 777
37f87013dfd8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,898 @@
     1.4 +/*
     1.5 + * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_c1_Runtime1_sparc.cpp.incl"
    1.30 +
    1.31 +// Implementation of StubAssembler
    1.32 +
    1.33 +int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry_point, int number_of_arguments) {
    1.34 +  // for sparc changing the number of arguments doesn't change
    1.35 +  // anything about the frame size so we'll always lie and claim that
    1.36 +  // we are only passing 1 argument.
    1.37 +  set_num_rt_args(1);
    1.38 +
    1.39 +  assert_not_delayed();
    1.40 +  // bang stack before going to runtime
    1.41 +  set(-os::vm_page_size() + STACK_BIAS, G3_scratch);
    1.42 +  st(G0, SP, G3_scratch);
    1.43 +
    1.44 +  // debugging support
    1.45 +  assert(number_of_arguments >= 0   , "cannot have negative number of arguments");
    1.46 +
    1.47 +  set_last_Java_frame(SP, noreg);
    1.48 +  if (VerifyThread)  mov(G2_thread, O0); // about to be smashed; pass early
    1.49 +  save_thread(L7_thread_cache);
    1.50 +  // do the call
    1.51 +  call(entry_point, relocInfo::runtime_call_type);
    1.52 +  if (!VerifyThread) {
    1.53 +    delayed()->mov(G2_thread, O0);  // pass thread as first argument
    1.54 +  } else {
    1.55 +    delayed()->nop();             // (thread already passed)
    1.56 +  }
    1.57 +  int call_offset = offset();  // offset of return address
    1.58 +  restore_thread(L7_thread_cache);
    1.59 +  reset_last_Java_frame();
    1.60 +
    1.61 +  // check for pending exceptions
    1.62 +  { Label L;
    1.63 +    Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset()));
    1.64 +    ld_ptr(exception_addr, Gtemp);
    1.65 +    br_null(Gtemp, false, pt, L);
    1.66 +    delayed()->nop();
    1.67 +    Address vm_result_addr(G2_thread, 0, in_bytes(JavaThread::vm_result_offset()));
    1.68 +    st_ptr(G0, vm_result_addr);
    1.69 +    Address vm_result_addr_2(G2_thread, 0, in_bytes(JavaThread::vm_result_2_offset()));
    1.70 +    st_ptr(G0, vm_result_addr_2);
    1.71 +
    1.72 +    if (frame_size() == no_frame_size) {
    1.73 +      // we use O7 linkage so that forward_exception_entry has the issuing PC
    1.74 +      call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
    1.75 +      delayed()->restore();
    1.76 +    } else if (_stub_id == Runtime1::forward_exception_id) {
    1.77 +      should_not_reach_here();
    1.78 +    } else {
    1.79 +      Address exc(G4, Runtime1::entry_for(Runtime1::forward_exception_id));
    1.80 +      jump_to(exc, 0);
    1.81 +      delayed()->nop();
    1.82 +    }
    1.83 +    bind(L);
    1.84 +  }
    1.85 +
    1.86 +  // get oop result if there is one and reset the value in the thread
    1.87 +  if (oop_result1->is_valid()) {                    // get oop result if there is one and reset it in the thread
    1.88 +    get_vm_result  (oop_result1);
    1.89 +  } else {
    1.90 +    // be a little paranoid and clear the result
    1.91 +    Address vm_result_addr(G2_thread, 0, in_bytes(JavaThread::vm_result_offset()));
    1.92 +    st_ptr(G0, vm_result_addr);
    1.93 +  }
    1.94 +
    1.95 +  if (oop_result2->is_valid()) {
    1.96 +    get_vm_result_2(oop_result2);
    1.97 +  } else {
    1.98 +    // be a little paranoid and clear the result
    1.99 +    Address vm_result_addr_2(G2_thread, 0, in_bytes(JavaThread::vm_result_2_offset()));
   1.100 +    st_ptr(G0, vm_result_addr_2);
   1.101 +  }
   1.102 +
   1.103 +  return call_offset;
   1.104 +}
   1.105 +
   1.106 +
   1.107 +int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1) {
   1.108 +  // O0 is reserved for the thread
   1.109 +  mov(arg1, O1);
   1.110 +  return call_RT(oop_result1, oop_result2, entry, 1);
   1.111 +}
   1.112 +
   1.113 +
   1.114 +int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2) {
   1.115 +  // O0 is reserved for the thread
   1.116 +  mov(arg1, O1);
   1.117 +  mov(arg2, O2); assert(arg2 != O1, "smashed argument");
   1.118 +  return call_RT(oop_result1, oop_result2, entry, 2);
   1.119 +}
   1.120 +
   1.121 +
   1.122 +int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2, Register arg3) {
   1.123 +  // O0 is reserved for the thread
   1.124 +  mov(arg1, O1);
   1.125 +  mov(arg2, O2); assert(arg2 != O1,               "smashed argument");
   1.126 +  mov(arg3, O3); assert(arg3 != O1 && arg3 != O2, "smashed argument");
   1.127 +  return call_RT(oop_result1, oop_result2, entry, 3);
   1.128 +}
   1.129 +
   1.130 +
   1.131 +// Implementation of Runtime1
   1.132 +
   1.133 +#define __ sasm->
   1.134 +
   1.135 +static int cpu_reg_save_offsets[FrameMap::nof_cpu_regs];
   1.136 +static int fpu_reg_save_offsets[FrameMap::nof_fpu_regs];
   1.137 +static int reg_save_size_in_words;
   1.138 +static int frame_size_in_bytes = -1;
   1.139 +
   1.140 +static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) {
   1.141 +  assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
   1.142 +         " mismatch in calculation");
   1.143 +  sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
   1.144 +  int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
   1.145 +  OopMap* oop_map = new OopMap(frame_size_in_slots, 0);
   1.146 +
   1.147 +  int i;
   1.148 +  for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
   1.149 +    Register r = as_Register(i);
   1.150 +    if (r == G1 || r == G3 || r == G4 || r == G5) {
   1.151 +      int sp_offset = cpu_reg_save_offsets[i];
   1.152 +      oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
   1.153 +                                r->as_VMReg());
   1.154 +    }
   1.155 +  }
   1.156 +
   1.157 +  if (save_fpu_registers) {
   1.158 +    for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
   1.159 +      FloatRegister r = as_FloatRegister(i);
   1.160 +      int sp_offset = fpu_reg_save_offsets[i];
   1.161 +      oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
   1.162 +                                r->as_VMReg());
   1.163 +    }
   1.164 +  }
   1.165 +  return oop_map;
   1.166 +}
   1.167 +
   1.168 +static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) {
   1.169 +  assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
   1.170 +         " mismatch in calculation");
   1.171 +  __ save_frame_c1(frame_size_in_bytes);
   1.172 +  sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);
   1.173 +
   1.174 +  // Record volatile registers as callee-save values in an OopMap so their save locations will be
   1.175 +  // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for
   1.176 +  // deoptimization; see compiledVFrame::create_stack_value).  The caller's I, L and O registers
   1.177 +  // are saved in register windows - I's and L's in the caller's frame and O's in the stub frame
   1.178 +  // (as the stub's I's) when the runtime routine called by the stub creates its frame.
   1.179 +  // OopMap frame sizes are in c2 stack slot sizes (sizeof(jint))
   1.180 +
   1.181 +  int i;
   1.182 +  for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
   1.183 +    Register r = as_Register(i);
   1.184 +    if (r == G1 || r == G3 || r == G4 || r == G5) {
   1.185 +      int sp_offset = cpu_reg_save_offsets[i];
   1.186 +      __ st_ptr(r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
   1.187 +    }
   1.188 +  }
   1.189 +
   1.190 +  if (save_fpu_registers) {
   1.191 +    for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
   1.192 +      FloatRegister r = as_FloatRegister(i);
   1.193 +      int sp_offset = fpu_reg_save_offsets[i];
   1.194 +      __ stf(FloatRegisterImpl::S, r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
   1.195 +    }
   1.196 +  }
   1.197 +
   1.198 +  return generate_oop_map(sasm, save_fpu_registers);
   1.199 +}
   1.200 +
   1.201 +static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
   1.202 +  for (int i = 0; i < FrameMap::nof_cpu_regs; i++) {
   1.203 +    Register r = as_Register(i);
   1.204 +    if (r == G1 || r == G3 || r == G4 || r == G5) {
   1.205 +      __ ld_ptr(SP, (cpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
   1.206 +    }
   1.207 +  }
   1.208 +
   1.209 +  if (restore_fpu_registers) {
   1.210 +    for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
   1.211 +      FloatRegister r = as_FloatRegister(i);
   1.212 +      __ ldf(FloatRegisterImpl::S, SP, (fpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r);
   1.213 +    }
   1.214 +  }
   1.215 +}
   1.216 +
   1.217 +
   1.218 +void Runtime1::initialize_pd() {
   1.219 +  // compute word offsets from SP at which live (non-windowed) registers are captured by stub routines
   1.220 +  //
   1.221 +  // A stub routine will have a frame that is at least large enough to hold
   1.222 +  // a register window save area (obviously) and the volatile g registers
   1.223 +  // and floating registers. A user of save_live_registers can have a frame
   1.224 +  // that has more scratch area in it (although typically they will use L-regs).
   1.225 +  // in that case the frame will look like this (stack growing down)
   1.226 +  //
   1.227 +  // FP -> |             |
   1.228 +  //       | scratch mem |
   1.229 +  //       |   "      "  |
   1.230 +  //       --------------
   1.231 +  //       | float regs  |
   1.232 +  //       |   "    "    |
   1.233 +  //       ---------------
   1.234 +  //       | G regs      |
   1.235 +  //       | "  "        |
   1.236 +  //       ---------------
   1.237 +  //       | abi reg.    |
   1.238 +  //       | window save |
   1.239 +  //       | area        |
   1.240 +  // SP -> ---------------
   1.241 +  //
   1.242 +  int i;
   1.243 +  int sp_offset = round_to(frame::register_save_words, 2); //  start doubleword aligned
   1.244 +
   1.245 +  // only G int registers are saved explicitly; others are found in register windows
   1.246 +  for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
   1.247 +    Register r = as_Register(i);
   1.248 +    if (r == G1 || r == G3 || r == G4 || r == G5) {
   1.249 +      cpu_reg_save_offsets[i] = sp_offset;
   1.250 +      sp_offset++;
   1.251 +    }
   1.252 +  }
   1.253 +
   1.254 +  // all float registers are saved explicitly
   1.255 +  assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here");
   1.256 +  for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
   1.257 +    fpu_reg_save_offsets[i] = sp_offset;
   1.258 +    sp_offset++;
   1.259 +  }
   1.260 +  reg_save_size_in_words = sp_offset - frame::memory_parameter_word_sp_offset;
   1.261 +  // this should match assembler::total_frame_size_in_bytes, which
   1.262 +  // isn't callable from this context.  It's checked by an assert when
   1.263 +  // it's used though.
   1.264 +  frame_size_in_bytes = align_size_up(sp_offset * wordSize, 8);
   1.265 +}
   1.266 +
   1.267 +
   1.268 +OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
   1.269 +  // make a frame and preserve the caller's caller-save registers
   1.270 +  OopMap* oop_map = save_live_registers(sasm);
   1.271 +  int call_offset;
   1.272 +  if (!has_argument) {
   1.273 +    call_offset = __ call_RT(noreg, noreg, target);
   1.274 +  } else {
   1.275 +    call_offset = __ call_RT(noreg, noreg, target, G4);
   1.276 +  }
   1.277 +  OopMapSet* oop_maps = new OopMapSet();
   1.278 +  oop_maps->add_gc_map(call_offset, oop_map);
   1.279 +
   1.280 +  __ should_not_reach_here();
   1.281 +  return oop_maps;
   1.282 +}
   1.283 +
   1.284 +
   1.285 +OopMapSet* Runtime1::generate_stub_call(StubAssembler* sasm, Register result, address target,
   1.286 +                                        Register arg1, Register arg2, Register arg3) {
   1.287 +  // make a frame and preserve the caller's caller-save registers
   1.288 +  OopMap* oop_map = save_live_registers(sasm);
   1.289 +
   1.290 +  int call_offset;
   1.291 +  if (arg1 == noreg) {
   1.292 +    call_offset = __ call_RT(result, noreg, target);
   1.293 +  } else if (arg2 == noreg) {
   1.294 +    call_offset = __ call_RT(result, noreg, target, arg1);
   1.295 +  } else if (arg3 == noreg) {
   1.296 +    call_offset = __ call_RT(result, noreg, target, arg1, arg2);
   1.297 +  } else {
   1.298 +    call_offset = __ call_RT(result, noreg, target, arg1, arg2, arg3);
   1.299 +  }
   1.300 +  OopMapSet* oop_maps = NULL;
   1.301 +
   1.302 +  oop_maps = new OopMapSet();
   1.303 +  oop_maps->add_gc_map(call_offset, oop_map);
   1.304 +  restore_live_registers(sasm);
   1.305 +
   1.306 +  __ ret();
   1.307 +  __ delayed()->restore();
   1.308 +
   1.309 +  return oop_maps;
   1.310 +}
   1.311 +
   1.312 +
   1.313 +OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
   1.314 +  // make a frame and preserve the caller's caller-save registers
   1.315 +  OopMap* oop_map = save_live_registers(sasm);
   1.316 +
   1.317 +  // call the runtime patching routine, returns non-zero if nmethod got deopted.
   1.318 +  int call_offset = __ call_RT(noreg, noreg, target);
   1.319 +  OopMapSet* oop_maps = new OopMapSet();
   1.320 +  oop_maps->add_gc_map(call_offset, oop_map);
   1.321 +
   1.322 +  // re-execute the patched instruction or, if the nmethod was deoptmized, return to the
   1.323 +  // deoptimization handler entry that will cause re-execution of the current bytecode
   1.324 +  DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
   1.325 +  assert(deopt_blob != NULL, "deoptimization blob must have been created");
   1.326 +
   1.327 +  Label no_deopt;
   1.328 +  __ tst(O0);
   1.329 +  __ brx(Assembler::equal, false, Assembler::pt, no_deopt);
   1.330 +  __ delayed()->nop();
   1.331 +
   1.332 +  // return to the deoptimization handler entry for unpacking and rexecute
   1.333 +  // if we simply returned the we'd deopt as if any call we patched had just
   1.334 +  // returned.
   1.335 +
   1.336 +  restore_live_registers(sasm);
   1.337 +  __ restore();
   1.338 +  __ br(Assembler::always, false, Assembler::pt, deopt_blob->unpack_with_reexecution(), relocInfo::runtime_call_type);
   1.339 +  __ delayed()->nop();
   1.340 +
   1.341 +  __ bind(no_deopt);
   1.342 +  restore_live_registers(sasm);
   1.343 +  __ ret();
   1.344 +  __ delayed()->restore();
   1.345 +
   1.346 +  return oop_maps;
   1.347 +}
   1.348 +
   1.349 +OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
   1.350 +
   1.351 +  OopMapSet* oop_maps = NULL;
   1.352 +  // for better readability
   1.353 +  const bool must_gc_arguments = true;
   1.354 +  const bool dont_gc_arguments = false;
   1.355 +
   1.356 +  // stub code & info for the different stubs
   1.357 +  switch (id) {
   1.358 +    case forward_exception_id:
   1.359 +      {
   1.360 +        // we're handling an exception in the context of a compiled
   1.361 +        // frame.  The registers have been saved in the standard
   1.362 +        // places.  Perform an exception lookup in the caller and
   1.363 +        // dispatch to the handler if found.  Otherwise unwind and
   1.364 +        // dispatch to the callers exception handler.
   1.365 +
   1.366 +        oop_maps = new OopMapSet();
   1.367 +        OopMap* oop_map = generate_oop_map(sasm, true);
   1.368 +
   1.369 +        // transfer the pending exception to the exception_oop
   1.370 +        __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception);
   1.371 +        __ ld_ptr(Oexception, 0, G0);
   1.372 +        __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset()));
   1.373 +        __ add(I7, frame::pc_return_offset, Oissuing_pc);
   1.374 +
   1.375 +        generate_handle_exception(sasm, oop_maps, oop_map);
   1.376 +        __ should_not_reach_here();
   1.377 +      }
   1.378 +      break;
   1.379 +
   1.380 +    case new_instance_id:
   1.381 +    case fast_new_instance_id:
   1.382 +    case fast_new_instance_init_check_id:
   1.383 +      {
   1.384 +        Register G5_klass = G5; // Incoming
   1.385 +        Register O0_obj   = O0; // Outgoing
   1.386 +
   1.387 +        if (id == new_instance_id) {
   1.388 +          __ set_info("new_instance", dont_gc_arguments);
   1.389 +        } else if (id == fast_new_instance_id) {
   1.390 +          __ set_info("fast new_instance", dont_gc_arguments);
   1.391 +        } else {
   1.392 +          assert(id == fast_new_instance_init_check_id, "bad StubID");
   1.393 +          __ set_info("fast new_instance init check", dont_gc_arguments);
   1.394 +        }
   1.395 +
   1.396 +        if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
   1.397 +            UseTLAB && FastTLABRefill) {
   1.398 +          Label slow_path;
   1.399 +          Register G1_obj_size = G1;
   1.400 +          Register G3_t1 = G3;
   1.401 +          Register G4_t2 = G4;
   1.402 +          assert_different_registers(G5_klass, G1_obj_size, G3_t1, G4_t2);
   1.403 +
   1.404 +          // Push a frame since we may do dtrace notification for the
   1.405 +          // allocation which requires calling out and we don't want
   1.406 +          // to stomp the real return address.
   1.407 +          __ save_frame(0);
   1.408 +
   1.409 +          if (id == fast_new_instance_init_check_id) {
   1.410 +            // make sure the klass is initialized
   1.411 +            __ ld(G5_klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_t1);
   1.412 +            __ cmp(G3_t1, instanceKlass::fully_initialized);
   1.413 +            __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
   1.414 +            __ delayed()->nop();
   1.415 +          }
   1.416 +#ifdef ASSERT
   1.417 +          // assert object can be fast path allocated
   1.418 +          {
   1.419 +            Label ok, not_ok;
   1.420 +          __ ld(G5_klass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc), G1_obj_size);
   1.421 +          __ cmp(G1_obj_size, 0);  // make sure it's an instance (LH > 0)
   1.422 +          __ br(Assembler::lessEqual, false, Assembler::pn, not_ok);
   1.423 +          __ delayed()->nop();
   1.424 +          __ btst(Klass::_lh_instance_slow_path_bit, G1_obj_size);
   1.425 +          __ br(Assembler::zero, false, Assembler::pn, ok);
   1.426 +          __ delayed()->nop();
   1.427 +          __ bind(not_ok);
   1.428 +          __ stop("assert(can be fast path allocated)");
   1.429 +          __ should_not_reach_here();
   1.430 +          __ bind(ok);
   1.431 +          }
   1.432 +#endif // ASSERT
   1.433 +          // if we got here then the TLAB allocation failed, so try
   1.434 +          // refilling the TLAB or allocating directly from eden.
   1.435 +          Label retry_tlab, try_eden;
   1.436 +          __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G5_klass
   1.437 +
   1.438 +          __ bind(retry_tlab);
   1.439 +
   1.440 +          // get the instance size
   1.441 +          __ ld(G5_klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes(), G1_obj_size);
   1.442 +          __ tlab_allocate(O0_obj, G1_obj_size, 0, G3_t1, slow_path);
   1.443 +          __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2);
   1.444 +          __ verify_oop(O0_obj);
   1.445 +          __ mov(O0, I0);
   1.446 +          __ ret();
   1.447 +          __ delayed()->restore();
   1.448 +
   1.449 +          __ bind(try_eden);
   1.450 +          // get the instance size
   1.451 +          __ ld(G5_klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes(), G1_obj_size);
   1.452 +          __ eden_allocate(O0_obj, G1_obj_size, 0, G3_t1, G4_t2, slow_path);
   1.453 +          __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2);
   1.454 +          __ verify_oop(O0_obj);
   1.455 +          __ mov(O0, I0);
   1.456 +          __ ret();
   1.457 +          __ delayed()->restore();
   1.458 +
   1.459 +          __ bind(slow_path);
   1.460 +
   1.461 +          // pop this frame so generate_stub_call can push it's own
   1.462 +          __ restore();
   1.463 +        }
   1.464 +
   1.465 +        oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_instance), G5_klass);
   1.466 +        // I0->O0: new instance
   1.467 +      }
   1.468 +
   1.469 +      break;
   1.470 +
   1.471 +#ifdef TIERED
   1.472 +    case counter_overflow_id:
   1.473 +        // G4 contains bci
   1.474 +      oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, counter_overflow), G4);
   1.475 +      break;
   1.476 +#endif // TIERED
   1.477 +
   1.478 +    case new_type_array_id:
   1.479 +    case new_object_array_id:
   1.480 +      {
   1.481 +        Register G5_klass = G5; // Incoming
   1.482 +        Register G4_length = G4; // Incoming
   1.483 +        Register O0_obj   = O0; // Outgoing
   1.484 +
   1.485 +        Address klass_lh(G5_klass, 0, ((klassOopDesc::header_size() * HeapWordSize)
   1.486 +                                       + Klass::layout_helper_offset_in_bytes()));
   1.487 +        assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
   1.488 +        assert(Klass::_lh_header_size_mask == 0xFF, "bytewise");
   1.489 +        // Use this offset to pick out an individual byte of the layout_helper:
   1.490 +        const int klass_lh_header_size_offset = ((BytesPerInt - 1)  // 3 - 2 selects byte {0,1,0,0}
   1.491 +                                                 - Klass::_lh_header_size_shift / BitsPerByte);
   1.492 +
   1.493 +        if (id == new_type_array_id) {
   1.494 +          __ set_info("new_type_array", dont_gc_arguments);
   1.495 +        } else {
   1.496 +          __ set_info("new_object_array", dont_gc_arguments);
   1.497 +        }
   1.498 +
   1.499 +#ifdef ASSERT
   1.500 +        // assert object type is really an array of the proper kind
   1.501 +        {
   1.502 +          Label ok;
   1.503 +          Register G3_t1 = G3;
   1.504 +          __ ld(klass_lh, G3_t1);
   1.505 +          __ sra(G3_t1, Klass::_lh_array_tag_shift, G3_t1);
   1.506 +          int tag = ((id == new_type_array_id)
   1.507 +                     ? Klass::_lh_array_tag_type_value
   1.508 +                     : Klass::_lh_array_tag_obj_value);
   1.509 +          __ cmp(G3_t1, tag);
   1.510 +          __ brx(Assembler::equal, false, Assembler::pt, ok);
   1.511 +          __ delayed()->nop();
   1.512 +          __ stop("assert(is an array klass)");
   1.513 +          __ should_not_reach_here();
   1.514 +          __ bind(ok);
   1.515 +        }
   1.516 +#endif // ASSERT
   1.517 +
   1.518 +        if (UseTLAB && FastTLABRefill) {
   1.519 +          Label slow_path;
   1.520 +          Register G1_arr_size = G1;
   1.521 +          Register G3_t1 = G3;
   1.522 +          Register O1_t2 = O1;
   1.523 +          assert_different_registers(G5_klass, G4_length, G1_arr_size, G3_t1, O1_t2);
   1.524 +
   1.525 +          // check that array length is small enough for fast path
   1.526 +          __ set(C1_MacroAssembler::max_array_allocation_length, G3_t1);
   1.527 +          __ cmp(G4_length, G3_t1);
   1.528 +          __ br(Assembler::greaterUnsigned, false, Assembler::pn, slow_path);
   1.529 +          __ delayed()->nop();
   1.530 +
   1.531 +          // if we got here then the TLAB allocation failed, so try
   1.532 +          // refilling the TLAB or allocating directly from eden.
   1.533 +          Label retry_tlab, try_eden;
   1.534 +          __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G4_length and G5_klass
   1.535 +
   1.536 +          __ bind(retry_tlab);
   1.537 +
   1.538 +          // get the allocation size: (length << (layout_helper & 0x1F)) + header_size
   1.539 +          __ ld(klass_lh, G3_t1);
   1.540 +          __ sll(G4_length, G3_t1, G1_arr_size);
   1.541 +          __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1);
   1.542 +          __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1);
   1.543 +          __ add(G1_arr_size, G3_t1, G1_arr_size);
   1.544 +          __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size);  // align up
   1.545 +          __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size);
   1.546 +
   1.547 +          __ tlab_allocate(O0_obj, G1_arr_size, 0, G3_t1, slow_path);  // preserves G1_arr_size
   1.548 +
   1.549 +          __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2);
   1.550 +          __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset);
   1.551 +          __ sub(G1_arr_size, G3_t1, O1_t2);  // body length
   1.552 +          __ add(O0_obj, G3_t1, G3_t1);       // body start
   1.553 +          __ initialize_body(G3_t1, O1_t2);
   1.554 +          __ verify_oop(O0_obj);
   1.555 +          __ retl();
   1.556 +          __ delayed()->nop();
   1.557 +
   1.558 +          __ bind(try_eden);
   1.559 +          // get the allocation size: (length << (layout_helper & 0x1F)) + header_size
   1.560 +          __ ld(klass_lh, G3_t1);
   1.561 +          __ sll(G4_length, G3_t1, G1_arr_size);
   1.562 +          __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1);
   1.563 +          __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1);
   1.564 +          __ add(G1_arr_size, G3_t1, G1_arr_size);
   1.565 +          __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size);
   1.566 +          __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size);
   1.567 +
   1.568 +          __ eden_allocate(O0_obj, G1_arr_size, 0, G3_t1, O1_t2, slow_path);  // preserves G1_arr_size
   1.569 +
   1.570 +          __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2);
   1.571 +          __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset);
   1.572 +          __ sub(G1_arr_size, G3_t1, O1_t2);  // body length
   1.573 +          __ add(O0_obj, G3_t1, G3_t1);       // body start
   1.574 +          __ initialize_body(G3_t1, O1_t2);
   1.575 +          __ verify_oop(O0_obj);
   1.576 +          __ retl();
   1.577 +          __ delayed()->nop();
   1.578 +
   1.579 +          __ bind(slow_path);
   1.580 +        }
   1.581 +
   1.582 +        if (id == new_type_array_id) {
   1.583 +          oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_type_array), G5_klass, G4_length);
   1.584 +        } else {
   1.585 +          oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_object_array), G5_klass, G4_length);
   1.586 +        }
   1.587 +        // I0 -> O0: new array
   1.588 +      }
   1.589 +      break;
   1.590 +
   1.591 +    case new_multi_array_id:
   1.592 +      { // O0: klass
   1.593 +        // O1: rank
   1.594 +        // O2: address of 1st dimension
   1.595 +        __ set_info("new_multi_array", dont_gc_arguments);
   1.596 +        oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_multi_array), I0, I1, I2);
   1.597 +        // I0 -> O0: new multi array
   1.598 +      }
   1.599 +      break;
   1.600 +
   1.601 +    case register_finalizer_id:
   1.602 +      {
   1.603 +        __ set_info("register_finalizer", dont_gc_arguments);
   1.604 +
   1.605 +        // load the klass and check the has finalizer flag
   1.606 +        Label register_finalizer;
   1.607 +        Register t = O1;
   1.608 +        __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), t);
   1.609 +        __ ld(t, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc), t);
   1.610 +        __ set(JVM_ACC_HAS_FINALIZER, G3);
   1.611 +        __ andcc(G3, t, G0);
   1.612 +        __ br(Assembler::notZero, false, Assembler::pt, register_finalizer);
   1.613 +        __ delayed()->nop();
   1.614 +
   1.615 +        // do a leaf return
   1.616 +        __ retl();
   1.617 +        __ delayed()->nop();
   1.618 +
   1.619 +        __ bind(register_finalizer);
   1.620 +        OopMap* oop_map = save_live_registers(sasm);
   1.621 +        int call_offset = __ call_RT(noreg, noreg,
   1.622 +                                     CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), I0);
   1.623 +        oop_maps = new OopMapSet();
   1.624 +        oop_maps->add_gc_map(call_offset, oop_map);
   1.625 +
   1.626 +        // Now restore all the live registers
   1.627 +        restore_live_registers(sasm);
   1.628 +
   1.629 +        __ ret();
   1.630 +        __ delayed()->restore();
   1.631 +      }
   1.632 +      break;
   1.633 +
   1.634 +    case throw_range_check_failed_id:
   1.635 +      { __ set_info("range_check_failed", dont_gc_arguments); // arguments will be discarded
   1.636 +        // G4: index
   1.637 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
   1.638 +      }
   1.639 +      break;
   1.640 +
   1.641 +    case throw_index_exception_id:
   1.642 +      { __ set_info("index_range_check_failed", dont_gc_arguments); // arguments will be discarded
   1.643 +        // G4: index
   1.644 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
   1.645 +      }
   1.646 +      break;
   1.647 +
   1.648 +    case throw_div0_exception_id:
   1.649 +      { __ set_info("throw_div0_exception", dont_gc_arguments);
   1.650 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
   1.651 +      }
   1.652 +      break;
   1.653 +
   1.654 +    case throw_null_pointer_exception_id:
   1.655 +      { __ set_info("throw_null_pointer_exception", dont_gc_arguments);
   1.656 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
   1.657 +      }
   1.658 +      break;
   1.659 +
   1.660 +    case handle_exception_id:
   1.661 +      {
   1.662 +        __ set_info("handle_exception", dont_gc_arguments);
   1.663 +        // make a frame and preserve the caller's caller-save registers
   1.664 +
   1.665 +        oop_maps = new OopMapSet();
   1.666 +        OopMap* oop_map = save_live_registers(sasm);
   1.667 +        __ mov(Oexception->after_save(),  Oexception);
   1.668 +        __ mov(Oissuing_pc->after_save(), Oissuing_pc);
   1.669 +        generate_handle_exception(sasm, oop_maps, oop_map);
   1.670 +      }
   1.671 +      break;
   1.672 +
   1.673 +    case unwind_exception_id:
   1.674 +      {
   1.675 +        // O0: exception
   1.676 +        // I7: address of call to this method
   1.677 +
   1.678 +        __ set_info("unwind_exception", dont_gc_arguments);
   1.679 +        __ mov(Oexception, Oexception->after_save());
   1.680 +        __ add(I7, frame::pc_return_offset, Oissuing_pc->after_save());
   1.681 +
   1.682 +        __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
   1.683 +                        Oissuing_pc->after_save());
   1.684 +        __ verify_not_null_oop(Oexception->after_save());
   1.685 +        __ jmp(O0, 0);
   1.686 +        __ delayed()->restore();
   1.687 +      }
   1.688 +      break;
   1.689 +
   1.690 +    case throw_array_store_exception_id:
   1.691 +      {
   1.692 +        __ set_info("throw_array_store_exception", dont_gc_arguments);
   1.693 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), false);
   1.694 +      }
   1.695 +      break;
   1.696 +
   1.697 +    case throw_class_cast_exception_id:
   1.698 +      {
   1.699 +        // G4: object
   1.700 +        __ set_info("throw_class_cast_exception", dont_gc_arguments);
   1.701 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
   1.702 +      }
   1.703 +      break;
   1.704 +
   1.705 +    case throw_incompatible_class_change_error_id:
   1.706 +      {
   1.707 +        __ set_info("throw_incompatible_class_cast_exception", dont_gc_arguments);
   1.708 +        oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
   1.709 +      }
   1.710 +      break;
   1.711 +
   1.712 +    case slow_subtype_check_id:
   1.713 +      { // Support for uint StubRoutine::partial_subtype_check( Klass sub, Klass super );
   1.714 +        // Arguments :
   1.715 +        //
   1.716 +        //      ret  : G3
   1.717 +        //      sub  : G3, argument, destroyed
   1.718 +        //      super: G1, argument, not changed
   1.719 +        //      raddr: O7, blown by call
   1.720 +        Label loop, miss;
   1.721 +
   1.722 +        __ save_frame(0);               // Blow no registers!
   1.723 +
   1.724 +        __ ld_ptr( G3, sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes(), L3 );
   1.725 +        __ lduw(L3,arrayOopDesc::length_offset_in_bytes(),L0); // length in l0
   1.726 +        __ add(L3,arrayOopDesc::base_offset_in_bytes(T_OBJECT),L1); // ptr into array
   1.727 +        __ clr(L4);                     // Index
   1.728 +        // Load a little early; will load 1 off the end of the array.
   1.729 +        // Ok for now; revisit if we have other uses of this routine.
   1.730 +        __ ld_ptr(L1,0,L2);             // Will load a little early
   1.731 +
   1.732 +        // The scan loop
   1.733 +        __ bind(loop);
   1.734 +        __ add(L1,wordSize,L1); // Bump by OOP size
   1.735 +        __ cmp(L4,L0);
   1.736 +        __ br(Assembler::equal,false,Assembler::pn,miss);
   1.737 +        __ delayed()->inc(L4);  // Bump index
   1.738 +        __ subcc(L2,G1,L3);             // Check for match; zero in L3 for a hit
   1.739 +        __ brx( Assembler::notEqual, false, Assembler::pt, loop );
   1.740 +        __ delayed()->ld_ptr(L1,0,L2); // Will load a little early
   1.741 +
   1.742 +        // Got a hit; report success; set cache
   1.743 +        __ st_ptr( G1, G3, sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() );
   1.744 +
   1.745 +        __ mov(1, G3);
   1.746 +        __ ret();                       // Result in G5 is ok; flags set
   1.747 +        __ delayed()->restore();        // free copy or add can go here
   1.748 +
   1.749 +        __ bind(miss);
   1.750 +        __ mov(0, G3);
   1.751 +        __ ret();                       // Result in G5 is ok; flags set
   1.752 +        __ delayed()->restore();        // free copy or add can go here
   1.753 +      }
   1.754 +
   1.755 +    case monitorenter_nofpu_id:
   1.756 +    case monitorenter_id:
   1.757 +      { // G4: object
   1.758 +        // G5: lock address
   1.759 +        __ set_info("monitorenter", dont_gc_arguments);
   1.760 +
   1.761 +        int save_fpu_registers = (id == monitorenter_id);
   1.762 +        // make a frame and preserve the caller's caller-save registers
   1.763 +        OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
   1.764 +
   1.765 +        int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), G4, G5);
   1.766 +
   1.767 +        oop_maps = new OopMapSet();
   1.768 +        oop_maps->add_gc_map(call_offset, oop_map);
   1.769 +        restore_live_registers(sasm, save_fpu_registers);
   1.770 +
   1.771 +        __ ret();
   1.772 +        __ delayed()->restore();
   1.773 +      }
   1.774 +      break;
   1.775 +
   1.776 +    case monitorexit_nofpu_id:
   1.777 +    case monitorexit_id:
   1.778 +      { // G4: lock address
   1.779 +        // note: really a leaf routine but must setup last java sp
   1.780 +        //       => use call_RT for now (speed can be improved by
   1.781 +        //       doing last java sp setup manually)
   1.782 +        __ set_info("monitorexit", dont_gc_arguments);
   1.783 +
   1.784 +        int save_fpu_registers = (id == monitorexit_id);
   1.785 +        // make a frame and preserve the caller's caller-save registers
   1.786 +        OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);
   1.787 +
   1.788 +        int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), G4);
   1.789 +
   1.790 +        oop_maps = new OopMapSet();
   1.791 +        oop_maps->add_gc_map(call_offset, oop_map);
   1.792 +        restore_live_registers(sasm, save_fpu_registers);
   1.793 +
   1.794 +        __ ret();
   1.795 +        __ delayed()->restore();
   1.796 +
   1.797 +      }
   1.798 +      break;
   1.799 +
   1.800 +    case access_field_patching_id:
   1.801 +      { __ set_info("access_field_patching", dont_gc_arguments);
   1.802 +        oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
   1.803 +      }
   1.804 +      break;
   1.805 +
   1.806 +    case load_klass_patching_id:
   1.807 +      { __ set_info("load_klass_patching", dont_gc_arguments);
   1.808 +        oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
   1.809 +      }
   1.810 +      break;
   1.811 +
   1.812 +    case jvmti_exception_throw_id:
   1.813 +      { // Oexception : exception
   1.814 +        __ set_info("jvmti_exception_throw", dont_gc_arguments);
   1.815 +        oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, Runtime1::post_jvmti_exception_throw), I0);
   1.816 +      }
   1.817 +      break;
   1.818 +
   1.819 +    case dtrace_object_alloc_id:
   1.820 +      { // O0: object
   1.821 +        __ set_info("dtrace_object_alloc", dont_gc_arguments);
   1.822 +        // we can't gc here so skip the oopmap but make sure that all
   1.823 +        // the live registers get saved.
   1.824 +        save_live_registers(sasm);
   1.825 +
   1.826 +        __ save_thread(L7_thread_cache);
   1.827 +        __ call(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc),
   1.828 +                relocInfo::runtime_call_type);
   1.829 +        __ delayed()->mov(I0, O0);
   1.830 +        __ restore_thread(L7_thread_cache);
   1.831 +
   1.832 +        restore_live_registers(sasm);
   1.833 +        __ ret();
   1.834 +        __ delayed()->restore();
   1.835 +      }
   1.836 +      break;
   1.837 +
   1.838 +    default:
   1.839 +      { __ set_info("unimplemented entry", dont_gc_arguments);
   1.840 +        __ save_frame(0);
   1.841 +        __ set((int)id, O1);
   1.842 +        __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), O1);
   1.843 +        __ should_not_reach_here();
   1.844 +      }
   1.845 +      break;
   1.846 +  }
   1.847 +  return oop_maps;
   1.848 +}
   1.849 +
   1.850 +
   1.851 +void Runtime1::generate_handle_exception(StubAssembler* sasm, OopMapSet* oop_maps, OopMap* oop_map, bool) {
   1.852 +  Label no_deopt;
   1.853 +  Label no_handler;
   1.854 +
   1.855 +  __ verify_not_null_oop(Oexception);
   1.856 +
   1.857 +  // save the exception and issuing pc in the thread
   1.858 +  __ st_ptr(Oexception, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
   1.859 +  __ st_ptr(Oissuing_pc, G2_thread, in_bytes(JavaThread::exception_pc_offset()));
   1.860 +
   1.861 +  // save the real return address and use the throwing pc as the return address to lookup (has bci & oop map)
   1.862 +  __ mov(I7, L0);
   1.863 +  __ mov(Oissuing_pc, I7);
   1.864 +  __ sub(I7, frame::pc_return_offset, I7);
   1.865 +  int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
   1.866 +
   1.867 +  // Note: if nmethod has been deoptimized then regardless of
   1.868 +  // whether it had a handler or not we will deoptimize
   1.869 +  // by entering the deopt blob with a pending exception.
   1.870 +
   1.871 +  __ tst(O0);
   1.872 +  __ br(Assembler::zero, false, Assembler::pn, no_handler);
   1.873 +  __ delayed()->nop();
   1.874 +
   1.875 +  // restore the registers that were saved at the beginning and jump to the exception handler.
   1.876 +  restore_live_registers(sasm);
   1.877 +
   1.878 +  __ jmp(O0, 0);
   1.879 +  __ delayed()->restore();
   1.880 +
   1.881 +  __ bind(no_handler);
   1.882 +  __ mov(L0, I7); // restore return address
   1.883 +
   1.884 +  // restore exception oop
   1.885 +  __ ld_ptr(G2_thread, in_bytes(JavaThread::exception_oop_offset()), Oexception->after_save());
   1.886 +  __ st_ptr(G0, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
   1.887 +
   1.888 +  __ restore();
   1.889 +
   1.890 +  Address exc(G4, Runtime1::entry_for(Runtime1::unwind_exception_id));
   1.891 +  __ jump_to(exc, 0);
   1.892 +  __ delayed()->nop();
   1.893 +
   1.894 +
   1.895 +  oop_maps->add_gc_map(call_offset, oop_map);
   1.896 +}
   1.897 +
   1.898 +
   1.899 +#undef __
   1.900 +
   1.901 +#define __ masm->

mercurial