src/cpu/sparc/vm/c1_Runtime1_sparc.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2138
d5d065957597
child 2344
ac637b7220d1
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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

mercurial