Path: blob/master/src/hotspot/cpu/arm/c1_CodeStubs_arm.cpp
40930 views
/*1* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.inline.hpp"26#include "c1/c1_CodeStubs.hpp"27#include "c1/c1_FrameMap.hpp"28#include "c1/c1_LIRAssembler.hpp"29#include "c1/c1_MacroAssembler.hpp"30#include "c1/c1_Runtime1.hpp"31#include "classfile/javaClasses.hpp"32#include "memory/universe.hpp"33#include "nativeInst_arm.hpp"34#include "runtime/sharedRuntime.hpp"35#include "utilities/macros.hpp"36#include "vmreg_arm.inline.hpp"3738#define __ ce->masm()->3940void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {41ShouldNotReachHere();42}4344void CounterOverflowStub::emit_code(LIR_Assembler* ce) {45__ bind(_entry);46ce->store_parameter(_bci, 0);47ce->store_parameter(_method->as_constant_ptr()->as_metadata(), 1);48__ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type);49ce->add_call_info_here(_info);50ce->verify_oop_map(_info);5152__ b(_continuation);53}545556// TODO: ARM - is it possible to inline these stubs into the main code stream?575859RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)60: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {61assert(info != NULL, "must have info");62_info = new CodeEmitInfo(info);63}6465RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)66: _index(index), _array(NULL), _throw_index_out_of_bounds_exception(true) {67assert(info != NULL, "must have info");68_info = new CodeEmitInfo(info);69}7071void RangeCheckStub::emit_code(LIR_Assembler* ce) {72__ bind(_entry);7374if (_info->deoptimize_on_exception()) {75__ call(Runtime1::entry_for(Runtime1::predicate_failed_trap_id), relocInfo::runtime_call_type);76ce->add_call_info_here(_info);77ce->verify_oop_map(_info);78debug_only(__ should_not_reach_here());79return;80}81// Pass the array index on stack because all registers must be preserved82ce->verify_reserved_argument_area_size(_throw_index_out_of_bounds_exception ? 1 : 2);83if (_index->is_cpu_register()) {84__ str_32(_index->as_register(), Address(SP));85} else {86__ mov_slow(Rtemp, _index->as_jint()); // Rtemp should be OK in C187__ str_32(Rtemp, Address(SP));88}8990if (_throw_index_out_of_bounds_exception) {91__ call(Runtime1::entry_for(Runtime1::throw_index_exception_id), relocInfo::runtime_call_type);92} else {93__ str(_array->as_pointer_register(), Address(SP, BytesPerWord)); // ??? Correct offset? Correct instruction?94__ call(Runtime1::entry_for(Runtime1::throw_range_check_failed_id), relocInfo::runtime_call_type);95}96ce->add_call_info_here(_info);97ce->verify_oop_map(_info);98DEBUG_ONLY(STOP("RangeCheck");)99}100101PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {102_info = new CodeEmitInfo(info);103}104105void PredicateFailedStub::emit_code(LIR_Assembler* ce) {106__ bind(_entry);107__ call(Runtime1::entry_for(Runtime1::predicate_failed_trap_id), relocInfo::runtime_call_type);108ce->add_call_info_here(_info);109ce->verify_oop_map(_info);110debug_only(__ should_not_reach_here());111}112113void DivByZeroStub::emit_code(LIR_Assembler* ce) {114if (_offset != -1) {115ce->compilation()->implicit_exception_table()->append(_offset, __ offset());116}117__ bind(_entry);118__ call(Runtime1::entry_for(Runtime1::throw_div0_exception_id),119relocInfo::runtime_call_type);120ce->add_call_info_here(_info);121DEBUG_ONLY(STOP("DivByZero");)122}123124125// Implementation of NewInstanceStub126127NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {128_result = result;129_klass = klass;130_klass_reg = klass_reg;131_info = new CodeEmitInfo(info);132assert(stub_id == Runtime1::new_instance_id ||133stub_id == Runtime1::fast_new_instance_id ||134stub_id == Runtime1::fast_new_instance_init_check_id,135"need new_instance id");136_stub_id = stub_id;137}138139140void NewInstanceStub::emit_code(LIR_Assembler* ce) {141assert(_result->as_register() == R0, "runtime call setup");142assert(_klass_reg->as_register() == R1, "runtime call setup");143__ bind(_entry);144__ call(Runtime1::entry_for(_stub_id), relocInfo::runtime_call_type);145ce->add_call_info_here(_info);146ce->verify_oop_map(_info);147__ b(_continuation);148}149150151// Implementation of NewTypeArrayStub152153NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {154_klass_reg = klass_reg;155_length = length;156_result = result;157_info = new CodeEmitInfo(info);158}159160161void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {162assert(_result->as_register() == R0, "runtime call setup");163assert(_klass_reg->as_register() == R1, "runtime call setup");164assert(_length->as_register() == R2, "runtime call setup");165__ bind(_entry);166__ call(Runtime1::entry_for(Runtime1::new_type_array_id), relocInfo::runtime_call_type);167ce->add_call_info_here(_info);168ce->verify_oop_map(_info);169__ b(_continuation);170}171172173// Implementation of NewObjectArrayStub174175NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {176_klass_reg = klass_reg;177_result = result;178_length = length;179_info = new CodeEmitInfo(info);180}181182183void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {184assert(_result->as_register() == R0, "runtime call setup");185assert(_klass_reg->as_register() == R1, "runtime call setup");186assert(_length->as_register() == R2, "runtime call setup");187__ bind(_entry);188__ call(Runtime1::entry_for(Runtime1::new_object_array_id), relocInfo::runtime_call_type);189ce->add_call_info_here(_info);190ce->verify_oop_map(_info);191__ b(_continuation);192}193194195// Implementation of MonitorAccessStubs196197MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)198: MonitorAccessStub(obj_reg, lock_reg)199{200_info = new CodeEmitInfo(info);201}202203204void MonitorEnterStub::emit_code(LIR_Assembler* ce) {205__ bind(_entry);206const Register obj_reg = _obj_reg->as_pointer_register();207const Register lock_reg = _lock_reg->as_pointer_register();208209ce->verify_reserved_argument_area_size(2);210if (obj_reg < lock_reg) {211__ stmia(SP, RegisterSet(obj_reg) | RegisterSet(lock_reg));212} else {213__ str(obj_reg, Address(SP));214__ str(lock_reg, Address(SP, BytesPerWord));215}216217Runtime1::StubID enter_id = ce->compilation()->has_fpu_code() ?218Runtime1::monitorenter_id :219Runtime1::monitorenter_nofpu_id;220__ call(Runtime1::entry_for(enter_id), relocInfo::runtime_call_type);221ce->add_call_info_here(_info);222ce->verify_oop_map(_info);223__ b(_continuation);224}225226227void MonitorExitStub::emit_code(LIR_Assembler* ce) {228__ bind(_entry);229if (_compute_lock) {230ce->monitor_address(_monitor_ix, _lock_reg);231}232const Register lock_reg = _lock_reg->as_pointer_register();233234ce->verify_reserved_argument_area_size(1);235__ str(lock_reg, Address(SP));236237// Non-blocking leaf routine - no call info needed238Runtime1::StubID exit_id = ce->compilation()->has_fpu_code() ?239Runtime1::monitorexit_id :240Runtime1::monitorexit_nofpu_id;241__ call(Runtime1::entry_for(exit_id), relocInfo::runtime_call_type);242__ b(_continuation);243}244245246// Call return is directly after patch word247int PatchingStub::_patch_info_offset = 0;248249void PatchingStub::align_patch_site(MacroAssembler* masm) {250#if 0251// TODO: investigate if we required to implement this252ShouldNotReachHere();253#endif254}255256void PatchingStub::emit_code(LIR_Assembler* ce) {257const int patchable_instruction_offset = 0;258259assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,260"not enough room for call");261assert((_bytes_to_copy & 3) == 0, "must copy a multiple of four bytes");262Label call_patch;263bool is_load = (_id == load_klass_id) || (_id == load_mirror_id) || (_id == load_appendix_id);264265266if (is_load && !VM_Version::supports_movw()) {267address start = __ pc();268269// The following sequence duplicates code provided in MacroAssembler::patchable_mov_oop()270// without creating relocation info entry.271272assert((__ pc() - start) == patchable_instruction_offset, "should be");273__ ldr(_obj, Address(PC));274// Extra nop to handle case of large offset of oop placeholder (see NativeMovConstReg::set_data).275__ nop();276277#ifdef ASSERT278for (int i = 0; i < _bytes_to_copy; i++) {279assert(((address)_pc_start)[i] == start[i], "should be the same code");280}281#endif // ASSERT282}283284address being_initialized_entry = __ pc();285if (CommentedAssembly) {286__ block_comment(" patch template");287}288if (is_load) {289address start = __ pc();290if (_id == load_mirror_id || _id == load_appendix_id) {291__ patchable_mov_oop(_obj, (jobject)Universe::non_oop_word(), _index);292} else {293__ patchable_mov_metadata(_obj, (Metadata*)Universe::non_oop_word(), _index);294}295#ifdef ASSERT296for (int i = 0; i < _bytes_to_copy; i++) {297assert(((address)_pc_start)[i] == start[i], "should be the same code");298}299#endif // ASSERT300} else {301int* start = (int*)_pc_start;302int* end = start + (_bytes_to_copy / BytesPerInt);303while (start < end) {304__ emit_int32(*start++);305}306}307address end_of_patch = __ pc();308309int bytes_to_skip = 0;310if (_id == load_mirror_id) {311int offset = __ offset();312if (CommentedAssembly) {313__ block_comment(" being_initialized check");314}315316assert(_obj != noreg, "must be a valid register");317// Rtemp should be OK in C1318__ ldr(Rtemp, Address(_obj, java_lang_Class::klass_offset()));319__ ldr(Rtemp, Address(Rtemp, InstanceKlass::init_thread_offset()));320__ cmp(Rtemp, Rthread);321__ b(call_patch, ne);322__ b(_patch_site_continuation);323324bytes_to_skip += __ offset() - offset;325}326327if (CommentedAssembly) {328__ block_comment("patch data - 3 high bytes of the word");329}330const int sizeof_patch_record = 4;331bytes_to_skip += sizeof_patch_record;332int being_initialized_entry_offset = __ pc() - being_initialized_entry + sizeof_patch_record;333__ emit_int32(0xff | being_initialized_entry_offset << 8 | bytes_to_skip << 16 | _bytes_to_copy << 24);334335address patch_info_pc = __ pc();336assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");337338// runtime call will return here339Label call_return;340__ bind(call_return);341ce->add_call_info_here(_info);342assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");343__ b(_patch_site_entry);344345address entry = __ pc();346NativeGeneralJump::insert_unconditional((address)_pc_start, entry);347address target = NULL;348relocInfo::relocType reloc_type = relocInfo::none;349switch (_id) {350case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;351case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;352case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;353case load_appendix_id: target = Runtime1::entry_for(Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;354default: ShouldNotReachHere();355}356__ bind(call_patch);357358if (CommentedAssembly) {359__ block_comment("patch entry point");360}361362// arrange for call to return just after patch word363__ adr(LR, call_return);364__ jump(target, relocInfo::runtime_call_type, Rtemp);365366if (is_load) {367CodeSection* cs = __ code_section();368address pc = (address)_pc_start;369RelocIterator iter(cs, pc, pc + 1);370relocInfo::change_reloc_info_for_address(&iter, pc, reloc_type, relocInfo::none);371}372}373374void DeoptimizeStub::emit_code(LIR_Assembler* ce) {375__ bind(_entry);376__ mov_slow(Rtemp, _trap_request);377ce->verify_reserved_argument_area_size(1);378__ str(Rtemp, Address(SP));379__ call(Runtime1::entry_for(Runtime1::deoptimize_id), relocInfo::runtime_call_type);380ce->add_call_info_here(_info);381DEBUG_ONLY(__ should_not_reach_here());382}383384385void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {386address a;387if (_info->deoptimize_on_exception()) {388// Deoptimize, do not throw the exception, because it is389// probably wrong to do it here.390a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);391} else {392a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);393}394ce->compilation()->implicit_exception_table()->append(_offset, __ offset());395__ bind(_entry);396__ call(a, relocInfo::runtime_call_type);397ce->add_call_info_here(_info);398ce->verify_oop_map(_info);399DEBUG_ONLY(STOP("ImplicitNullCheck");)400}401402403void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {404__ bind(_entry);405// Pass the object on stack because all registers must be preserved406if (_obj->is_cpu_register()) {407ce->verify_reserved_argument_area_size(1);408__ str(_obj->as_pointer_register(), Address(SP));409} else {410assert(_obj->is_illegal(), "should be");411}412__ call(Runtime1::entry_for(_stub), relocInfo::runtime_call_type);413ce->add_call_info_here(_info);414DEBUG_ONLY(STOP("SimpleException");)415}416417418void ArrayCopyStub::emit_code(LIR_Assembler* ce) {419__ bind(_entry);420421VMRegPair args[5];422BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT };423SharedRuntime::java_calling_convention(signature, args, 5);424425Register r[5];426r[0] = src()->as_pointer_register();427r[1] = src_pos()->as_register();428r[2] = dst()->as_pointer_register();429r[3] = dst_pos()->as_register();430r[4] = length()->as_register();431432for (int i = 0; i < 5; i++) {433VMReg arg = args[i].first();434if (arg->is_stack()) {435__ str(r[i], Address(SP, arg->reg2stack() * VMRegImpl::stack_slot_size));436} else {437assert(r[i] == arg->as_Register(), "Calling conventions must match");438}439}440441ce->emit_static_call_stub();442if (ce->compilation()->bailed_out()) {443return; // CodeCache is full444}445int ret_addr_offset = __ patchable_call(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type);446assert(ret_addr_offset == __ offset(), "embedded return address not allowed");447ce->add_call_info_here(info());448ce->verify_oop_map(info());449__ b(_continuation);450}451452#undef __453454455