Path: blob/master/src/hotspot/cpu/ppc/c1_CodeStubs_ppc.cpp
64440 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2021 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "c1/c1_CodeStubs.hpp"28#include "c1/c1_FrameMap.hpp"29#include "c1/c1_LIRAssembler.hpp"30#include "c1/c1_MacroAssembler.hpp"31#include "c1/c1_Runtime1.hpp"32#include "classfile/javaClasses.hpp"33#include "nativeInst_ppc.hpp"34#include "runtime/sharedRuntime.hpp"35#include "utilities/macros.hpp"36#include "vmreg_ppc.inline.hpp"3738#define __ ce->masm()->3940void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {41if (UseSIGTRAP) {42DEBUG_ONLY( __ should_not_reach_here("C1SafepointPollStub::emit_code"); )43} else {44assert(SharedRuntime::polling_page_return_handler_blob() != NULL,45"polling page return stub not created yet");46address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();4748__ bind(_entry);49// Using pc relative address computation.50{51Label next_pc;52__ bl(next_pc);53__ bind(next_pc);54}55int current_offset = __ offset();56__ mflr(R12);57__ add_const_optimized(R12, R12, safepoint_offset() - current_offset);58__ std(R12, in_bytes(JavaThread::saved_exception_pc_offset()), R16_thread);5960__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));61__ mtctr(R0);62__ bctr();63}64}6566RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)67: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {68assert(info != NULL, "must have info");69_info = new CodeEmitInfo(info);70}7172RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)73: _index(index), _array(NULL), _throw_index_out_of_bounds_exception(true) {74assert(info != NULL, "must have info");75_info = new CodeEmitInfo(info);76}7778void RangeCheckStub::emit_code(LIR_Assembler* ce) {79__ bind(_entry);8081if (_info->deoptimize_on_exception()) {82address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);83//__ load_const_optimized(R0, a);84__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(a));85__ mtctr(R0);86__ bctrl();87ce->add_call_info_here(_info);88ce->verify_oop_map(_info);89debug_only(__ illtrap());90return;91}9293address stub = _throw_index_out_of_bounds_exception ? Runtime1::entry_for(Runtime1::throw_index_exception_id)94: Runtime1::entry_for(Runtime1::throw_range_check_failed_id);95//__ load_const_optimized(R0, stub);96__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));97__ mtctr(R0);9899Register index = R0;100if (_index->is_register()) {101__ extsw(index, _index->as_register());102} else {103__ load_const_optimized(index, _index->as_jint());104}105if (_array) {106__ std(_array->as_pointer_register(), -8, R1_SP);107}108__ std(index, -16, R1_SP);109110__ bctrl();111ce->add_call_info_here(_info);112ce->verify_oop_map(_info);113debug_only(__ illtrap());114}115116117PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {118_info = new CodeEmitInfo(info);119}120121void PredicateFailedStub::emit_code(LIR_Assembler* ce) {122__ bind(_entry);123address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);124//__ load_const_optimized(R0, a);125__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(a));126__ mtctr(R0);127__ bctrl();128ce->add_call_info_here(_info);129ce->verify_oop_map(_info);130debug_only(__ illtrap());131}132133134void CounterOverflowStub::emit_code(LIR_Assembler* ce) {135__ bind(_entry);136137// Parameter 1: bci138__ load_const_optimized(R0, _bci);139__ std(R0, -16, R1_SP);140141// Parameter 2: Method*142Metadata *m = _method->as_constant_ptr()->as_metadata();143AddressLiteral md = __ constant_metadata_address(m); // Notify OOP recorder (don't need the relocation).144__ load_const_optimized(R0, md.value());145__ std(R0, -8, R1_SP);146147address a = Runtime1::entry_for(Runtime1::counter_overflow_id);148//__ load_const_optimized(R0, a);149__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(a));150__ mtctr(R0);151__ bctrl();152ce->add_call_info_here(_info);153ce->verify_oop_map(_info);154155__ b(_continuation);156}157158159void DivByZeroStub::emit_code(LIR_Assembler* ce) {160if (_offset != -1) {161ce->compilation()->implicit_exception_table()->append(_offset, __ offset());162}163__ bind(_entry);164address stub = Runtime1::entry_for(Runtime1::throw_div0_exception_id);165//__ load_const_optimized(R0, stub);166__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));167__ mtctr(R0);168__ bctrl();169ce->add_call_info_here(_info);170ce->verify_oop_map(_info);171debug_only(__ illtrap());172}173174175void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {176address a;177if (_info->deoptimize_on_exception()) {178// Deoptimize, do not throw the exception, because it is probably wrong to do it here.179a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);180} else {181a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);182}183184if (ImplicitNullChecks || TrapBasedNullChecks) {185ce->compilation()->implicit_exception_table()->append(_offset, __ offset());186}187__ bind(_entry);188//__ load_const_optimized(R0, a);189__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(a));190__ mtctr(R0);191__ bctrl();192ce->add_call_info_here(_info);193ce->verify_oop_map(_info);194debug_only(__ illtrap());195}196197198// Implementation of SimpleExceptionStub199void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {200__ bind(_entry);201address stub = Runtime1::entry_for(_stub);202//__ load_const_optimized(R0, stub);203__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));204if (_obj->is_valid()) { __ mr_if_needed(/*tmp1 in do_CheckCast*/ R4_ARG2, _obj->as_register()); }205__ mtctr(R0);206__ bctrl();207ce->add_call_info_here(_info);208debug_only( __ illtrap(); )209}210211212// Implementation of NewInstanceStub213NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {214_result = result;215_klass = klass;216_klass_reg = klass_reg;217_info = new CodeEmitInfo(info);218assert(stub_id == Runtime1::new_instance_id ||219stub_id == Runtime1::fast_new_instance_id ||220stub_id == Runtime1::fast_new_instance_init_check_id,221"need new_instance id");222_stub_id = stub_id;223}224225void NewInstanceStub::emit_code(LIR_Assembler* ce) {226__ bind(_entry);227228address entry = Runtime1::entry_for(_stub_id);229//__ load_const_optimized(R0, entry);230__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(entry));231__ mtctr(R0);232__ bctrl();233ce->add_call_info_here(_info);234ce->verify_oop_map(_info);235__ b(_continuation);236}237238239// Implementation of NewTypeArrayStub240NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {241_klass_reg = klass_reg;242_length = length;243_result = result;244_info = new CodeEmitInfo(info);245}246247void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {248__ bind(_entry);249250address entry = Runtime1::entry_for(Runtime1::new_type_array_id);251//__ load_const_optimized(R0, entry);252__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(entry));253__ mr_if_needed(/*op->tmp1()->as_register()*/ R5_ARG3, _length->as_register()); // already sign-extended254__ mtctr(R0);255__ bctrl();256ce->add_call_info_here(_info);257ce->verify_oop_map(_info);258__ b(_continuation);259}260261262// Implementation of NewObjectArrayStub263NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {264_klass_reg = klass_reg;265_length = length;266_result = result;267_info = new CodeEmitInfo(info);268}269270void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {271__ bind(_entry);272273address entry = Runtime1::entry_for(Runtime1::new_object_array_id);274//__ load_const_optimized(R0, entry);275__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(entry));276__ mr_if_needed(/*op->tmp1()->as_register()*/ R5_ARG3, _length->as_register()); // already sign-extended277__ mtctr(R0);278__ bctrl();279ce->add_call_info_here(_info);280ce->verify_oop_map(_info);281__ b(_continuation);282}283284285// Implementation of MonitorAccessStubs286MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)287: MonitorAccessStub(obj_reg, lock_reg) {288_info = new CodeEmitInfo(info);289}290291void MonitorEnterStub::emit_code(LIR_Assembler* ce) {292__ bind(_entry);293address stub = Runtime1::entry_for(ce->compilation()->has_fpu_code() ? Runtime1::monitorenter_id : Runtime1::monitorenter_nofpu_id);294//__ load_const_optimized(R0, stub);295__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));296__ mr_if_needed(/*scratch_opr()->as_register()*/ R4_ARG2, _obj_reg->as_register());297assert(_lock_reg->as_register() == R5_ARG3, "");298__ mtctr(R0);299__ bctrl();300ce->add_call_info_here(_info);301ce->verify_oop_map(_info);302__ b(_continuation);303}304305void MonitorExitStub::emit_code(LIR_Assembler* ce) {306__ bind(_entry);307if (_compute_lock) {308ce->monitor_address(_monitor_ix, _lock_reg);309}310address stub = Runtime1::entry_for(ce->compilation()->has_fpu_code() ? Runtime1::monitorexit_id : Runtime1::monitorexit_nofpu_id);311//__ load_const_optimized(R0, stub);312__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));313assert(_lock_reg->as_register() == R4_ARG2, "");314__ mtctr(R0);315__ bctrl();316__ b(_continuation);317}318319320// Implementation of patching:321// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes).322// - Replace original code with a call to the stub.323// At Runtime:324// - call to stub, jump to runtime325// - in runtime: preserve all registers (especially objects, i.e., source and destination object)326// - in runtime: after initializing class, restore original code, reexecute instruction327328int PatchingStub::_patch_info_offset = -(5 * BytesPerInstWord);329330void PatchingStub::align_patch_site(MacroAssembler* ) {331// Patch sites on ppc are always properly aligned.332}333334#ifdef ASSERT335inline void compare_with_patch_site(address template_start, address pc_start, int bytes_to_copy) {336address start = template_start;337for (int i = 0; i < bytes_to_copy; i++) {338address ptr = (address)(pc_start + i);339int a_byte = (*ptr) & 0xFF;340assert(a_byte == *start++, "should be the same code");341}342}343#endif344345void PatchingStub::emit_code(LIR_Assembler* ce) {346// copy original code here347assert(NativeGeneralJump::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,348"not enough room for call, need %d", _bytes_to_copy);349assert((_bytes_to_copy & 0x3) == 0, "must copy a multiple of four bytes");350351Label call_patch;352353int being_initialized_entry = __ offset();354355if (_id == load_klass_id) {356// Produce a copy of the load klass instruction for use by the being initialized case.357AddressLiteral addrlit((address)NULL, metadata_Relocation::spec(_index));358__ load_const(_obj, addrlit, R0);359DEBUG_ONLY( compare_with_patch_site(__ code_section()->start() + being_initialized_entry, _pc_start, _bytes_to_copy); )360} else if (_id == load_mirror_id || _id == load_appendix_id) {361// Produce a copy of the load mirror instruction for use by the being initialized case.362AddressLiteral addrlit((address)NULL, oop_Relocation::spec(_index));363__ load_const(_obj, addrlit, R0);364DEBUG_ONLY( compare_with_patch_site(__ code_section()->start() + being_initialized_entry, _pc_start, _bytes_to_copy); )365} else {366// Make a copy of the code which is going to be patched.367for (int i = 0; i < _bytes_to_copy; i++) {368address ptr = (address)(_pc_start + i);369int a_byte = (*ptr) & 0xFF;370__ emit_int8 (a_byte);371}372}373374address end_of_patch = __ pc();375int bytes_to_skip = 0;376if (_id == load_mirror_id) {377int offset = __ offset();378__ block_comment(" being_initialized check");379380// Static field accesses have special semantics while the class381// initializer is being run so we emit a test which can be used to382// check that this code is being executed by the initializing383// thread.384assert(_obj != noreg, "must be a valid register");385assert(_index >= 0, "must have oop index");386__ mr(R0, _obj); // spill387__ ld(_obj, java_lang_Class::klass_offset(), _obj);388__ ld(_obj, in_bytes(InstanceKlass::init_thread_offset()), _obj);389__ cmpd(CCR0, _obj, R16_thread);390__ mr(_obj, R0); // restore391__ bne(CCR0, call_patch);392393// Load_klass patches may execute the patched code before it's394// copied back into place so we need to jump back into the main395// code of the nmethod to continue execution.396__ b(_patch_site_continuation);397398// Make sure this extra code gets skipped.399bytes_to_skip += __ offset() - offset;400}401402// Now emit the patch record telling the runtime how to find the403// pieces of the patch. We only need 3 bytes but it has to be404// aligned as an instruction so emit 4 bytes.405int sizeof_patch_record = 4;406bytes_to_skip += sizeof_patch_record;407408// Emit the offsets needed to find the code to patch.409int being_initialized_entry_offset = __ offset() - being_initialized_entry + sizeof_patch_record;410411// Emit the patch record. We need to emit a full word, so emit an extra empty byte.412__ emit_int8(0);413__ emit_int8(being_initialized_entry_offset);414__ emit_int8(bytes_to_skip);415__ emit_int8(_bytes_to_copy);416address patch_info_pc = __ pc();417assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");418419address entry = __ pc();420NativeGeneralJump::insert_unconditional((address)_pc_start, entry);421address target = NULL;422relocInfo::relocType reloc_type = relocInfo::none;423switch (_id) {424case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;425case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id);426reloc_type = relocInfo::metadata_type; break;427case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id);428reloc_type = relocInfo::oop_type; break;429case load_appendix_id: target = Runtime1::entry_for(Runtime1::load_appendix_patching_id);430reloc_type = relocInfo::oop_type; break;431default: ShouldNotReachHere();432}433__ bind(call_patch);434435__ block_comment("patch entry point");436//__ load_const(R0, target); + mtctr + bctrl must have size -_patch_info_offset437__ load_const32(R0, MacroAssembler::offset_to_global_toc(target));438__ add(R0, R29_TOC, R0);439__ mtctr(R0);440__ bctrl();441assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");442ce->add_call_info_here(_info);443__ b(_patch_site_entry);444if (_id == load_klass_id || _id == load_mirror_id || _id == load_appendix_id) {445CodeSection* cs = __ code_section();446address pc = (address)_pc_start;447RelocIterator iter(cs, pc, pc + 1);448relocInfo::change_reloc_info_for_address(&iter, (address) pc, reloc_type, relocInfo::none);449}450}451452453void DeoptimizeStub::emit_code(LIR_Assembler* ce) {454__ bind(_entry);455address stub = Runtime1::entry_for(Runtime1::deoptimize_id);456//__ load_const_optimized(R0, stub);457__ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));458__ mtctr(R0);459460__ load_const_optimized(R0, _trap_request); // Pass trap request in R0.461__ bctrl();462ce->add_call_info_here(_info);463debug_only(__ illtrap());464}465466467void ArrayCopyStub::emit_code(LIR_Assembler* ce) {468//---------------slow case: call to native-----------------469__ bind(_entry);470__ mr(R3_ARG1, src()->as_register());471__ extsw(R4_ARG2, src_pos()->as_register());472__ mr(R5_ARG3, dst()->as_register());473__ extsw(R6_ARG4, dst_pos()->as_register());474__ extsw(R7_ARG5, length()->as_register());475476ce->emit_static_call_stub();477478bool success = ce->emit_trampoline_stub_for_call(SharedRuntime::get_resolve_static_call_stub());479if (!success) { return; }480481__ relocate(relocInfo::static_call_type);482// Note: At this point we do not have the address of the trampoline483// stub, and the entry point might be too far away for bl, so __ pc()484// serves as dummy and the bl will be patched later.485__ code()->set_insts_mark();486__ bl(__ pc());487ce->add_call_info_here(info());488ce->verify_oop_map(info());489490#ifndef PRODUCT491const address counter = (address)&Runtime1::_arraycopy_slowcase_cnt;492const Register tmp = R3, tmp2 = R4;493int simm16_offs = __ load_const_optimized(tmp, counter, tmp2, true);494__ lwz(tmp2, simm16_offs, tmp);495__ addi(tmp2, tmp2, 1);496__ stw(tmp2, simm16_offs, tmp);497#endif498499__ b(_continuation);500}501502#undef __503504505