src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp

Fri, 30 Apr 2010 08:37:24 -0700

author
twisti
date
Fri, 30 Apr 2010 08:37:24 -0700
changeset 1861
2338d41fbd81
parent 1730
3cf667df43ef
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6943304: remove tagged stack interpreter
Reviewed-by: coleenp, never, gbenson

     1 /*
     2  * Copyright 1999-2010 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_c1_CodeStubs_sparc.cpp.incl"
    28 #define __ ce->masm()->
    30 RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
    31                                bool throw_index_out_of_bounds_exception)
    32   : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
    33   , _index(index)
    34 {
    35   _info = new CodeEmitInfo(info);
    36 }
    39 void RangeCheckStub::emit_code(LIR_Assembler* ce) {
    40   __ bind(_entry);
    42   if (_index->is_register()) {
    43     __ mov(_index->as_register(), G4);
    44   } else {
    45     __ set(_index->as_jint(), G4);
    46   }
    47   if (_throw_index_out_of_bounds_exception) {
    48     __ call(Runtime1::entry_for(Runtime1::throw_index_exception_id), relocInfo::runtime_call_type);
    49   } else {
    50     __ call(Runtime1::entry_for(Runtime1::throw_range_check_failed_id), relocInfo::runtime_call_type);
    51   }
    52   __ delayed()->nop();
    53   ce->add_call_info_here(_info);
    54   ce->verify_oop_map(_info);
    55 #ifdef ASSERT
    56   __ should_not_reach_here();
    57 #endif
    58 }
    60 #ifdef TIERED
    62 void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
    63   __ bind(_entry);
    64   __ set(_bci, G4);
    65   __ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type);
    66   __ delayed()->nop();
    67   ce->add_call_info_here(_info);
    68   ce->verify_oop_map(_info);
    70   __ br(Assembler::always, true, Assembler::pt, _continuation);
    71   __ delayed()->nop();
    72 }
    74 #endif // TIERED
    76 void DivByZeroStub::emit_code(LIR_Assembler* ce) {
    77   if (_offset != -1) {
    78     ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
    79   }
    80   __ bind(_entry);
    81   __ call(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type);
    82   __ delayed()->nop();
    83   ce->add_call_info_here(_info);
    84   ce->verify_oop_map(_info);
    85 #ifdef ASSERT
    86   __ should_not_reach_here();
    87 #endif
    88 }
    91 void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
    92   ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
    93   __ bind(_entry);
    94   __ call(Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id),
    95           relocInfo::runtime_call_type);
    96   __ delayed()->nop();
    97   ce->add_call_info_here(_info);
    98   ce->verify_oop_map(_info);
    99 #ifdef ASSERT
   100   __ should_not_reach_here();
   101 #endif
   102 }
   105 // Implementation of SimpleExceptionStub
   106 // Note: %g1 and %g3 are already in use
   107 void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
   108   __ bind(_entry);
   109   __ call(Runtime1::entry_for(_stub), relocInfo::runtime_call_type);
   111   if (_obj->is_valid()) {
   112     __ delayed()->mov(_obj->as_register(), G4); // _obj contains the optional argument to the stub
   113   } else {
   114     __ delayed()->mov(G0, G4);
   115   }
   116   ce->add_call_info_here(_info);
   117 #ifdef ASSERT
   118   __ should_not_reach_here();
   119 #endif
   120 }
   123 // Implementation of ArrayStoreExceptionStub
   125 ArrayStoreExceptionStub::ArrayStoreExceptionStub(CodeEmitInfo* info):
   126   _info(info) {
   127 }
   130 void ArrayStoreExceptionStub::emit_code(LIR_Assembler* ce) {
   131   __ bind(_entry);
   132   __ call(Runtime1::entry_for(Runtime1::throw_array_store_exception_id), relocInfo::runtime_call_type);
   133   __ delayed()->nop();
   134   ce->add_call_info_here(_info);
   135   ce->verify_oop_map(_info);
   136 #ifdef ASSERT
   137   __ should_not_reach_here();
   138 #endif
   139 }
   144 // Implementation of NewInstanceStub
   146 NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
   147   _result = result;
   148   _klass = klass;
   149   _klass_reg = klass_reg;
   150   _info = new CodeEmitInfo(info);
   151   assert(stub_id == Runtime1::new_instance_id                 ||
   152          stub_id == Runtime1::fast_new_instance_id            ||
   153          stub_id == Runtime1::fast_new_instance_init_check_id,
   154          "need new_instance id");
   155   _stub_id   = stub_id;
   156 }
   159 void NewInstanceStub::emit_code(LIR_Assembler* ce) {
   160   __ bind(_entry);
   161   __ call(Runtime1::entry_for(_stub_id), relocInfo::runtime_call_type);
   162   __ delayed()->mov_or_nop(_klass_reg->as_register(), G5);
   163   ce->add_call_info_here(_info);
   164   ce->verify_oop_map(_info);
   165   __ br(Assembler::always, false, Assembler::pt, _continuation);
   166   __ delayed()->mov_or_nop(O0, _result->as_register());
   167 }
   170 // Implementation of NewTypeArrayStub
   171 NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
   172   _klass_reg = klass_reg;
   173   _length = length;
   174   _result = result;
   175   _info = new CodeEmitInfo(info);
   176 }
   179 void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
   180   __ bind(_entry);
   182   __ mov(_length->as_register(), G4);
   183   __ call(Runtime1::entry_for(Runtime1::new_type_array_id), relocInfo::runtime_call_type);
   184   __ delayed()->mov_or_nop(_klass_reg->as_register(), G5);
   185   ce->add_call_info_here(_info);
   186   ce->verify_oop_map(_info);
   187   __ br(Assembler::always, false, Assembler::pt, _continuation);
   188   __ delayed()->mov_or_nop(O0, _result->as_register());
   189 }
   192 // Implementation of NewObjectArrayStub
   194 NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
   195   _klass_reg = klass_reg;
   196   _length = length;
   197   _result = result;
   198   _info = new CodeEmitInfo(info);
   199 }
   202 void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
   203   __ bind(_entry);
   205   __ mov(_length->as_register(), G4);
   206   __ call(Runtime1::entry_for(Runtime1::new_object_array_id), relocInfo::runtime_call_type);
   207   __ delayed()->mov_or_nop(_klass_reg->as_register(), G5);
   208   ce->add_call_info_here(_info);
   209   ce->verify_oop_map(_info);
   210   __ br(Assembler::always, false, Assembler::pt, _continuation);
   211   __ delayed()->mov_or_nop(O0, _result->as_register());
   212 }
   215 // Implementation of MonitorAccessStubs
   216 MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
   217   : MonitorAccessStub(obj_reg, lock_reg) {
   218   _info = new CodeEmitInfo(info);
   219 }
   222 void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
   223   __ bind(_entry);
   224   __ mov(_obj_reg->as_register(), G4);
   225   if (ce->compilation()->has_fpu_code()) {
   226     __ call(Runtime1::entry_for(Runtime1::monitorenter_id), relocInfo::runtime_call_type);
   227   } else {
   228     __ call(Runtime1::entry_for(Runtime1::monitorenter_nofpu_id), relocInfo::runtime_call_type);
   229   }
   230   __ delayed()->mov_or_nop(_lock_reg->as_register(), G5);
   231   ce->add_call_info_here(_info);
   232   ce->verify_oop_map(_info);
   233   __ br(Assembler::always, true, Assembler::pt, _continuation);
   234   __ delayed()->nop();
   235 }
   238 void MonitorExitStub::emit_code(LIR_Assembler* ce) {
   239   __ bind(_entry);
   240   if (_compute_lock) {
   241     ce->monitor_address(_monitor_ix, _lock_reg);
   242   }
   243   if (ce->compilation()->has_fpu_code()) {
   244     __ call(Runtime1::entry_for(Runtime1::monitorexit_id), relocInfo::runtime_call_type);
   245   } else {
   246     __ call(Runtime1::entry_for(Runtime1::monitorexit_nofpu_id), relocInfo::runtime_call_type);
   247   }
   249   __ delayed()->mov_or_nop(_lock_reg->as_register(), G4);
   250   __ br(Assembler::always, true, Assembler::pt, _continuation);
   251   __ delayed()->nop();
   252 }
   254 // Implementation of patching:
   255 // - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)
   256 // - Replace original code with a call to the stub
   257 // At Runtime:
   258 // - call to stub, jump to runtime
   259 // - in runtime: preserve all registers (especially objects, i.e., source and destination object)
   260 // - in runtime: after initializing class, restore original code, reexecute instruction
   262 int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;
   264 void PatchingStub::align_patch_site(MacroAssembler* ) {
   265   // patch sites on sparc are always properly aligned.
   266 }
   268 void PatchingStub::emit_code(LIR_Assembler* ce) {
   269   // copy original code here
   270   assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,
   271          "not enough room for call");
   272   assert((_bytes_to_copy & 0x3) == 0, "must copy a multiple of four bytes");
   274   Label call_patch;
   276   int being_initialized_entry = __ offset();
   278   if (_id == load_klass_id) {
   279     // produce a copy of the load klass instruction for use by the being initialized case
   280 #ifdef ASSERT
   281     address start = __ pc();
   282 #endif
   283     AddressLiteral addrlit(NULL, oop_Relocation::spec(_oop_index));
   284     __ patchable_set(addrlit, _obj);
   286 #ifdef ASSERT
   287     for (int i = 0; i < _bytes_to_copy; i++) {
   288       address ptr = (address)(_pc_start + i);
   289       int a_byte = (*ptr) & 0xFF;
   290       assert(a_byte == *start++, "should be the same code");
   291     }
   292 #endif
   293   } else {
   294     // make a copy the code which is going to be patched.
   295     for (int i = 0; i < _bytes_to_copy; i++) {
   296       address ptr = (address)(_pc_start + i);
   297       int a_byte = (*ptr) & 0xFF;
   298       __ a_byte (a_byte);
   299     }
   300   }
   302   address end_of_patch = __ pc();
   303   int bytes_to_skip = 0;
   304   if (_id == load_klass_id) {
   305     int offset = __ offset();
   306     if (CommentedAssembly) {
   307       __ block_comment(" being_initialized check");
   308     }
   310     // static field accesses have special semantics while the class
   311     // initializer is being run so we emit a test which can be used to
   312     // check that this code is being executed by the initializing
   313     // thread.
   314     assert(_obj != noreg, "must be a valid register");
   315     assert(_oop_index >= 0, "must have oop index");
   316     __ ld_ptr(_obj, instanceKlass::init_thread_offset_in_bytes() + sizeof(klassOopDesc), G3);
   317     __ cmp(G2_thread, G3);
   318     __ br(Assembler::notEqual, false, Assembler::pn, call_patch);
   319     __ delayed()->nop();
   321     // load_klass patches may execute the patched code before it's
   322     // copied back into place so we need to jump back into the main
   323     // code of the nmethod to continue execution.
   324     __ br(Assembler::always, false, Assembler::pt, _patch_site_continuation);
   325     __ delayed()->nop();
   327     // make sure this extra code gets skipped
   328     bytes_to_skip += __ offset() - offset;
   329   }
   331   // Now emit the patch record telling the runtime how to find the
   332   // pieces of the patch.  We only need 3 bytes but it has to be
   333   // aligned as an instruction so emit 4 bytes.
   334   int sizeof_patch_record = 4;
   335   bytes_to_skip += sizeof_patch_record;
   337   // emit the offsets needed to find the code to patch
   338   int being_initialized_entry_offset = __ offset() - being_initialized_entry + sizeof_patch_record;
   340   // Emit the patch record.  We need to emit a full word, so emit an extra empty byte
   341   __ a_byte(0);
   342   __ a_byte(being_initialized_entry_offset);
   343   __ a_byte(bytes_to_skip);
   344   __ a_byte(_bytes_to_copy);
   345   address patch_info_pc = __ pc();
   346   assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");
   348   address entry = __ pc();
   349   NativeGeneralJump::insert_unconditional((address)_pc_start, entry);
   350   address target = NULL;
   351   switch (_id) {
   352     case access_field_id:  target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;
   353     case load_klass_id:    target = Runtime1::entry_for(Runtime1::load_klass_patching_id); break;
   354     default: ShouldNotReachHere();
   355   }
   356   __ bind(call_patch);
   358   if (CommentedAssembly) {
   359     __ block_comment("patch entry point");
   360   }
   361   __ call(target, relocInfo::runtime_call_type);
   362   __ delayed()->nop();
   363   assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");
   364   ce->add_call_info_here(_info);
   365   __ br(Assembler::always, false, Assembler::pt, _patch_site_entry);
   366   __ delayed()->nop();
   367   if (_id == load_klass_id) {
   368     CodeSection* cs = __ code_section();
   369     address pc = (address)_pc_start;
   370     RelocIterator iter(cs, pc, pc + 1);
   371     relocInfo::change_reloc_info_for_address(&iter, (address) pc, relocInfo::oop_type, relocInfo::none);
   373     pc = (address)(_pc_start + NativeMovConstReg::add_offset);
   374     RelocIterator iter2(cs, pc, pc+1);
   375     relocInfo::change_reloc_info_for_address(&iter2, (address) pc, relocInfo::oop_type, relocInfo::none);
   376   }
   378 }
   381 void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
   382   __ bind(_entry);
   383   __ call(SharedRuntime::deopt_blob()->unpack_with_reexecution());
   384   __ delayed()->nop();
   385   ce->add_call_info_here(_info);
   386   debug_only(__ should_not_reach_here());
   387 }
   390 void ArrayCopyStub::emit_code(LIR_Assembler* ce) {
   391   //---------------slow case: call to native-----------------
   392   __ bind(_entry);
   393   __ mov(src()->as_register(),     O0);
   394   __ mov(src_pos()->as_register(), O1);
   395   __ mov(dst()->as_register(),     O2);
   396   __ mov(dst_pos()->as_register(), O3);
   397   __ mov(length()->as_register(),  O4);
   399   ce->emit_static_call_stub();
   401   __ call(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type);
   402   __ delayed()->nop();
   403   ce->add_call_info_here(info());
   404   ce->verify_oop_map(info());
   406 #ifndef PRODUCT
   407   __ set((intptr_t)&Runtime1::_arraycopy_slowcase_cnt, O0);
   408   __ ld(O0, 0, O1);
   409   __ inc(O1);
   410   __ st(O1, 0, O0);
   411 #endif
   413   __ br(Assembler::always, false, Assembler::pt, _continuation);
   414   __ delayed()->nop();
   415 }
   418 ///////////////////////////////////////////////////////////////////////////////////
   419 #ifndef SERIALGC
   421 void G1PreBarrierStub::emit_code(LIR_Assembler* ce) {
   422   __ bind(_entry);
   424   assert(pre_val()->is_register(), "Precondition.");
   426   Register pre_val_reg = pre_val()->as_register();
   428   ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false);
   429   __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pt,
   430                     pre_val_reg, _continuation);
   431   __ delayed()->nop();
   433   __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_pre_barrier_slow_id));
   434   __ delayed()->mov(pre_val_reg, G4);
   435   __ br(Assembler::always, false, Assembler::pt, _continuation);
   436   __ delayed()->nop();
   438 }
   440 jbyte* G1PostBarrierStub::_byte_map_base = NULL;
   442 jbyte* G1PostBarrierStub::byte_map_base_slow() {
   443   BarrierSet* bs = Universe::heap()->barrier_set();
   444   assert(bs->is_a(BarrierSet::G1SATBCTLogging),
   445          "Must be if we're using this.");
   446   return ((G1SATBCardTableModRefBS*)bs)->byte_map_base;
   447 }
   449 void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
   450   __ bind(_entry);
   452   assert(addr()->is_register(), "Precondition.");
   453   assert(new_val()->is_register(), "Precondition.");
   454   Register addr_reg = addr()->as_pointer_register();
   455   Register new_val_reg = new_val()->as_register();
   456   __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pt,
   457                     new_val_reg, _continuation);
   458   __ delayed()->nop();
   460   __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_post_barrier_slow_id));
   461   __ delayed()->mov(addr_reg, G4);
   462   __ br(Assembler::always, false, Assembler::pt, _continuation);
   463   __ delayed()->nop();
   464 }
   466 #endif // SERIALGC
   467 ///////////////////////////////////////////////////////////////////////////////////
   469 #undef __

mercurial