duke@435: /* duke@435: * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_c1_CodeStubs_sparc.cpp.incl" duke@435: duke@435: #define __ ce->masm()-> duke@435: duke@435: RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, duke@435: bool throw_index_out_of_bounds_exception) duke@435: : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception) duke@435: , _index(index) duke@435: { duke@435: _info = new CodeEmitInfo(info); duke@435: } duke@435: duke@435: duke@435: void RangeCheckStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: duke@435: if (_index->is_register()) { duke@435: __ mov(_index->as_register(), G4); duke@435: } else { duke@435: __ set(_index->as_jint(), G4); duke@435: } duke@435: if (_throw_index_out_of_bounds_exception) { duke@435: __ call(Runtime1::entry_for(Runtime1::throw_index_exception_id), relocInfo::runtime_call_type); duke@435: } else { duke@435: __ call(Runtime1::entry_for(Runtime1::throw_range_check_failed_id), relocInfo::runtime_call_type); duke@435: } duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: #ifdef ASSERT duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: } duke@435: duke@435: #ifdef TIERED duke@435: duke@435: void CounterOverflowStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: __ set(_bci, G4); duke@435: __ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: duke@435: __ br(Assembler::always, true, Assembler::pt, _continuation); duke@435: __ delayed()->nop(); duke@435: } duke@435: duke@435: #endif // TIERED duke@435: duke@435: void DivByZeroStub::emit_code(LIR_Assembler* ce) { duke@435: if (_offset != -1) { duke@435: ce->compilation()->implicit_exception_table()->append(_offset, __ offset()); duke@435: } duke@435: __ bind(_entry); duke@435: __ call(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: #ifdef ASSERT duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) { duke@435: ce->compilation()->implicit_exception_table()->append(_offset, __ offset()); duke@435: __ bind(_entry); duke@435: __ call(Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id), duke@435: relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: #ifdef ASSERT duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: // Implementation of SimpleExceptionStub duke@435: // Note: %g1 and %g3 are already in use duke@435: void SimpleExceptionStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: __ call(Runtime1::entry_for(_stub), relocInfo::runtime_call_type); duke@435: duke@435: if (_obj->is_valid()) { duke@435: __ delayed()->mov(_obj->as_register(), G4); // _obj contains the optional argument to the stub duke@435: } else { duke@435: __ delayed()->mov(G0, G4); duke@435: } duke@435: ce->add_call_info_here(_info); duke@435: #ifdef ASSERT duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: // Implementation of ArrayStoreExceptionStub duke@435: duke@435: ArrayStoreExceptionStub::ArrayStoreExceptionStub(CodeEmitInfo* info): duke@435: _info(info) { duke@435: } duke@435: duke@435: duke@435: void ArrayStoreExceptionStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: __ call(Runtime1::entry_for(Runtime1::throw_array_store_exception_id), relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: #ifdef ASSERT duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: duke@435: duke@435: // Implementation of NewInstanceStub duke@435: duke@435: NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) { duke@435: _result = result; duke@435: _klass = klass; duke@435: _klass_reg = klass_reg; duke@435: _info = new CodeEmitInfo(info); duke@435: assert(stub_id == Runtime1::new_instance_id || duke@435: stub_id == Runtime1::fast_new_instance_id || duke@435: stub_id == Runtime1::fast_new_instance_init_check_id, duke@435: "need new_instance id"); duke@435: _stub_id = stub_id; duke@435: } duke@435: duke@435: duke@435: void NewInstanceStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: __ call(Runtime1::entry_for(_stub_id), relocInfo::runtime_call_type); duke@435: __ delayed()->mov_or_nop(_klass_reg->as_register(), G5); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: __ br(Assembler::always, false, Assembler::pt, _continuation); duke@435: __ delayed()->mov_or_nop(O0, _result->as_register()); duke@435: } duke@435: duke@435: duke@435: // Implementation of NewTypeArrayStub duke@435: NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) { duke@435: _klass_reg = klass_reg; duke@435: _length = length; duke@435: _result = result; duke@435: _info = new CodeEmitInfo(info); duke@435: } duke@435: duke@435: duke@435: void NewTypeArrayStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: duke@435: __ mov(_length->as_register(), G4); duke@435: __ call(Runtime1::entry_for(Runtime1::new_type_array_id), relocInfo::runtime_call_type); duke@435: __ delayed()->mov_or_nop(_klass_reg->as_register(), G5); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: __ br(Assembler::always, false, Assembler::pt, _continuation); duke@435: __ delayed()->mov_or_nop(O0, _result->as_register()); duke@435: } duke@435: duke@435: duke@435: // Implementation of NewObjectArrayStub duke@435: duke@435: NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) { duke@435: _klass_reg = klass_reg; duke@435: _length = length; duke@435: _result = result; duke@435: _info = new CodeEmitInfo(info); duke@435: } duke@435: duke@435: duke@435: void NewObjectArrayStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: duke@435: __ mov(_length->as_register(), G4); duke@435: __ call(Runtime1::entry_for(Runtime1::new_object_array_id), relocInfo::runtime_call_type); duke@435: __ delayed()->mov_or_nop(_klass_reg->as_register(), G5); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: __ br(Assembler::always, false, Assembler::pt, _continuation); duke@435: __ delayed()->mov_or_nop(O0, _result->as_register()); duke@435: } duke@435: duke@435: duke@435: // Implementation of MonitorAccessStubs duke@435: MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info) duke@435: : MonitorAccessStub(obj_reg, lock_reg) { duke@435: _info = new CodeEmitInfo(info); duke@435: } duke@435: duke@435: duke@435: void MonitorEnterStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: __ mov(_obj_reg->as_register(), G4); duke@435: if (ce->compilation()->has_fpu_code()) { duke@435: __ call(Runtime1::entry_for(Runtime1::monitorenter_id), relocInfo::runtime_call_type); duke@435: } else { duke@435: __ call(Runtime1::entry_for(Runtime1::monitorenter_nofpu_id), relocInfo::runtime_call_type); duke@435: } duke@435: __ delayed()->mov_or_nop(_lock_reg->as_register(), G5); duke@435: ce->add_call_info_here(_info); duke@435: ce->verify_oop_map(_info); duke@435: __ br(Assembler::always, true, Assembler::pt, _continuation); duke@435: __ delayed()->nop(); duke@435: } duke@435: duke@435: duke@435: void MonitorExitStub::emit_code(LIR_Assembler* ce) { duke@435: __ bind(_entry); duke@435: if (_compute_lock) { duke@435: ce->monitor_address(_monitor_ix, _lock_reg); duke@435: } duke@435: if (ce->compilation()->has_fpu_code()) { duke@435: __ call(Runtime1::entry_for(Runtime1::monitorexit_id), relocInfo::runtime_call_type); duke@435: } else { duke@435: __ call(Runtime1::entry_for(Runtime1::monitorexit_nofpu_id), relocInfo::runtime_call_type); duke@435: } duke@435: duke@435: __ delayed()->mov_or_nop(_lock_reg->as_register(), G4); duke@435: __ br(Assembler::always, true, Assembler::pt, _continuation); duke@435: __ delayed()->nop(); duke@435: } duke@435: duke@435: // Implementation of patching: duke@435: // - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes) duke@435: // - Replace original code with a call to the stub duke@435: // At Runtime: duke@435: // - call to stub, jump to runtime duke@435: // - in runtime: preserve all registers (especially objects, i.e., source and destination object) duke@435: // - in runtime: after initializing class, restore original code, reexecute instruction duke@435: duke@435: int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size; duke@435: duke@435: void PatchingStub::align_patch_site(MacroAssembler* ) { duke@435: // patch sites on sparc are always properly aligned. duke@435: } duke@435: duke@435: void PatchingStub::emit_code(LIR_Assembler* ce) { duke@435: // copy original code here duke@435: assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, duke@435: "not enough room for call"); duke@435: assert((_bytes_to_copy & 0x3) == 0, "must copy a multiple of four bytes"); duke@435: duke@435: Label call_patch; duke@435: duke@435: int being_initialized_entry = __ offset(); duke@435: duke@435: if (_id == load_klass_id) { duke@435: // produce a copy of the load klass instruction for use by the being initialized case duke@435: address start = __ pc(); duke@435: Address addr = Address(_obj, address(NULL), oop_Relocation::spec(_oop_index)); duke@435: __ sethi(addr, true); duke@435: __ add(addr, _obj, 0); duke@435: duke@435: #ifdef ASSERT duke@435: for (int i = 0; i < _bytes_to_copy; i++) { duke@435: address ptr = (address)(_pc_start + i); duke@435: int a_byte = (*ptr) & 0xFF; duke@435: assert(a_byte == *start++, "should be the same code"); duke@435: } duke@435: #endif duke@435: } else { duke@435: // make a copy the code which is going to be patched. duke@435: for (int i = 0; i < _bytes_to_copy; i++) { duke@435: address ptr = (address)(_pc_start + i); duke@435: int a_byte = (*ptr) & 0xFF; duke@435: __ a_byte (a_byte); duke@435: } duke@435: } duke@435: duke@435: address end_of_patch = __ pc(); duke@435: int bytes_to_skip = 0; duke@435: if (_id == load_klass_id) { duke@435: int offset = __ offset(); duke@435: if (CommentedAssembly) { duke@435: __ block_comment(" being_initialized check"); duke@435: } duke@435: duke@435: // static field accesses have special semantics while the class duke@435: // initializer is being run so we emit a test which can be used to duke@435: // check that this code is being executed by the initializing duke@435: // thread. duke@435: assert(_obj != noreg, "must be a valid register"); duke@435: assert(_oop_index >= 0, "must have oop index"); duke@435: __ ld_ptr(_obj, instanceKlass::init_thread_offset_in_bytes() + sizeof(klassOopDesc), G3); duke@435: __ cmp(G2_thread, G3); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, call_patch); duke@435: __ delayed()->nop(); duke@435: duke@435: // load_klass patches may execute the patched code before it's duke@435: // copied back into place so we need to jump back into the main duke@435: // code of the nmethod to continue execution. duke@435: __ br(Assembler::always, false, Assembler::pt, _patch_site_continuation); duke@435: __ delayed()->nop(); duke@435: duke@435: // make sure this extra code gets skipped duke@435: bytes_to_skip += __ offset() - offset; duke@435: } duke@435: duke@435: // Now emit the patch record telling the runtime how to find the duke@435: // pieces of the patch. We only need 3 bytes but it has to be duke@435: // aligned as an instruction so emit 4 bytes. duke@435: int sizeof_patch_record = 4; duke@435: bytes_to_skip += sizeof_patch_record; duke@435: duke@435: // emit the offsets needed to find the code to patch duke@435: int being_initialized_entry_offset = __ offset() - being_initialized_entry + sizeof_patch_record; duke@435: duke@435: // Emit the patch record. We need to emit a full word, so emit an extra empty byte duke@435: __ a_byte(0); duke@435: __ a_byte(being_initialized_entry_offset); duke@435: __ a_byte(bytes_to_skip); duke@435: __ a_byte(_bytes_to_copy); duke@435: address patch_info_pc = __ pc(); duke@435: assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info"); duke@435: duke@435: address entry = __ pc(); duke@435: NativeGeneralJump::insert_unconditional((address)_pc_start, entry); duke@435: address target = NULL; duke@435: switch (_id) { duke@435: case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break; duke@435: case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); break; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: __ bind(call_patch); duke@435: duke@435: if (CommentedAssembly) { duke@435: __ block_comment("patch entry point"); duke@435: } duke@435: __ call(target, relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change"); duke@435: ce->add_call_info_here(_info); duke@435: __ br(Assembler::always, false, Assembler::pt, _patch_site_entry); duke@435: __ delayed()->nop(); duke@435: if (_id == load_klass_id) { duke@435: CodeSection* cs = __ code_section(); duke@435: address pc = (address)_pc_start; duke@435: RelocIterator iter(cs, pc, pc + 1); duke@435: relocInfo::change_reloc_info_for_address(&iter, (address) pc, relocInfo::oop_type, relocInfo::none); duke@435: duke@435: pc = (address)(_pc_start + NativeMovConstReg::add_offset); duke@435: RelocIterator iter2(cs, pc, pc+1); duke@435: relocInfo::change_reloc_info_for_address(&iter2, (address) pc, relocInfo::oop_type, relocInfo::none); duke@435: } duke@435: duke@435: } duke@435: duke@435: void ArrayCopyStub::emit_code(LIR_Assembler* ce) { duke@435: //---------------slow case: call to native----------------- duke@435: __ bind(_entry); duke@435: __ mov(src()->as_register(), O0); duke@435: __ mov(src_pos()->as_register(), O1); duke@435: __ mov(dst()->as_register(), O2); duke@435: __ mov(dst_pos()->as_register(), O3); duke@435: __ mov(length()->as_register(), O4); duke@435: duke@435: ce->emit_static_call_stub(); duke@435: duke@435: __ call(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type); duke@435: __ delayed()->nop(); duke@435: ce->add_call_info_here(info()); duke@435: ce->verify_oop_map(info()); duke@435: duke@435: #ifndef PRODUCT duke@435: __ set((intptr_t)&Runtime1::_arraycopy_slowcase_cnt, O0); duke@435: __ ld(O0, 0, O1); duke@435: __ inc(O1); duke@435: __ st(O1, 0, O0); duke@435: #endif duke@435: duke@435: __ br(Assembler::always, false, Assembler::pt, _continuation); duke@435: __ delayed()->nop(); duke@435: } duke@435: duke@435: ysr@777: /////////////////////////////////////////////////////////////////////////////////// ysr@777: #ifndef SERIALGC ysr@777: ysr@777: void G1PreBarrierStub::emit_code(LIR_Assembler* ce) { ysr@777: __ bind(_entry); ysr@777: ysr@777: assert(pre_val()->is_register(), "Precondition."); ysr@777: ysr@777: Register pre_val_reg = pre_val()->as_register(); ysr@777: ysr@777: ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false); ysr@777: __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pt, ysr@777: pre_val_reg, _continuation); ysr@777: __ delayed()->nop(); ysr@777: ysr@777: __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_pre_barrier_slow_id)); ysr@777: __ delayed()->mov(pre_val_reg, G4); ysr@777: __ br(Assembler::always, false, Assembler::pt, _continuation); ysr@777: __ delayed()->nop(); ysr@777: ysr@777: } ysr@777: ysr@777: jbyte* G1PostBarrierStub::_byte_map_base = NULL; ysr@777: ysr@777: jbyte* G1PostBarrierStub::byte_map_base_slow() { ysr@777: BarrierSet* bs = Universe::heap()->barrier_set(); ysr@777: assert(bs->is_a(BarrierSet::G1SATBCTLogging), ysr@777: "Must be if we're using this."); ysr@777: return ((G1SATBCardTableModRefBS*)bs)->byte_map_base; ysr@777: } ysr@777: ysr@777: void G1PostBarrierStub::emit_code(LIR_Assembler* ce) { ysr@777: __ bind(_entry); ysr@777: ysr@777: assert(addr()->is_register(), "Precondition."); ysr@777: assert(new_val()->is_register(), "Precondition."); ysr@777: Register addr_reg = addr()->as_pointer_register(); ysr@777: Register new_val_reg = new_val()->as_register(); ysr@777: __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pt, ysr@777: new_val_reg, _continuation); ysr@777: __ delayed()->nop(); ysr@777: ysr@777: __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_post_barrier_slow_id)); ysr@777: __ delayed()->mov(addr_reg, G4); ysr@777: __ br(Assembler::always, false, Assembler::pt, _continuation); ysr@777: __ delayed()->nop(); ysr@777: } ysr@777: ysr@777: #endif // SERIALGC ysr@777: /////////////////////////////////////////////////////////////////////////////////// ysr@777: duke@435: #undef __