Path: blob/master/src/hotspot/cpu/aarch64/c1_CodeStubs_aarch64.cpp
40930 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2014, Red Hat 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 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_aarch64.hpp"34#include "runtime/sharedRuntime.hpp"35#include "vmreg_aarch64.inline.hpp"363738#define __ ce->masm()->3940void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {41__ bind(_entry);42InternalAddress safepoint_pc(ce->masm()->pc() - ce->masm()->offset() + safepoint_offset());43__ adr(rscratch1, safepoint_pc);44__ str(rscratch1, Address(rthread, JavaThread::saved_exception_pc_offset()));4546assert(SharedRuntime::polling_page_return_handler_blob() != NULL,47"polling page return stub not created yet");48address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();4950__ far_jump(RuntimeAddress(stub));51}5253void CounterOverflowStub::emit_code(LIR_Assembler* ce) {54__ bind(_entry);55Metadata *m = _method->as_constant_ptr()->as_metadata();56__ mov_metadata(rscratch1, m);57ce->store_parameter(rscratch1, 1);58ce->store_parameter(_bci, 0);59__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));60ce->add_call_info_here(_info);61ce->verify_oop_map(_info);62__ b(_continuation);63}6465RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)66: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {67assert(info != NULL, "must have info");68_info = new CodeEmitInfo(info);69}7071RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)72: _index(index), _array(NULL), _throw_index_out_of_bounds_exception(true) {73assert(info != NULL, "must have info");74_info = new CodeEmitInfo(info);75}7677void RangeCheckStub::emit_code(LIR_Assembler* ce) {78__ bind(_entry);79if (_info->deoptimize_on_exception()) {80address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);81__ far_call(RuntimeAddress(a));82ce->add_call_info_here(_info);83ce->verify_oop_map(_info);84debug_only(__ should_not_reach_here());85return;86}8788if (_index->is_cpu_register()) {89__ mov(rscratch1, _index->as_register());90} else {91__ mov(rscratch1, _index->as_jint());92}93Runtime1::StubID stub_id;94if (_throw_index_out_of_bounds_exception) {95stub_id = Runtime1::throw_index_exception_id;96} else {97assert(_array != NULL, "sanity");98__ mov(rscratch2, _array->as_pointer_register());99stub_id = Runtime1::throw_range_check_failed_id;100}101__ lea(lr, RuntimeAddress(Runtime1::entry_for(stub_id)));102__ blr(lr);103ce->add_call_info_here(_info);104ce->verify_oop_map(_info);105debug_only(__ should_not_reach_here());106}107108PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {109_info = new CodeEmitInfo(info);110}111112void PredicateFailedStub::emit_code(LIR_Assembler* ce) {113__ bind(_entry);114address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);115__ far_call(RuntimeAddress(a));116ce->add_call_info_here(_info);117ce->verify_oop_map(_info);118debug_only(__ should_not_reach_here());119}120121void DivByZeroStub::emit_code(LIR_Assembler* ce) {122if (_offset != -1) {123ce->compilation()->implicit_exception_table()->append(_offset, __ offset());124}125__ bind(_entry);126__ far_call(Address(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type));127ce->add_call_info_here(_info);128ce->verify_oop_map(_info);129#ifdef ASSERT130__ should_not_reach_here();131#endif132}133134135136// Implementation of NewInstanceStub137138NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {139_result = result;140_klass = klass;141_klass_reg = klass_reg;142_info = new CodeEmitInfo(info);143assert(stub_id == Runtime1::new_instance_id ||144stub_id == Runtime1::fast_new_instance_id ||145stub_id == Runtime1::fast_new_instance_init_check_id,146"need new_instance id");147_stub_id = stub_id;148}149150151152void NewInstanceStub::emit_code(LIR_Assembler* ce) {153assert(__ rsp_offset() == 0, "frame size should be fixed");154__ bind(_entry);155__ mov(r3, _klass_reg->as_register());156__ far_call(RuntimeAddress(Runtime1::entry_for(_stub_id)));157ce->add_call_info_here(_info);158ce->verify_oop_map(_info);159assert(_result->as_register() == r0, "result must in r0,");160__ b(_continuation);161}162163164// Implementation of NewTypeArrayStub165166// Implementation of NewTypeArrayStub167168NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {169_klass_reg = klass_reg;170_length = length;171_result = result;172_info = new CodeEmitInfo(info);173}174175176void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {177assert(__ rsp_offset() == 0, "frame size should be fixed");178__ bind(_entry);179assert(_length->as_register() == r19, "length must in r19,");180assert(_klass_reg->as_register() == r3, "klass_reg must in r3");181__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));182ce->add_call_info_here(_info);183ce->verify_oop_map(_info);184assert(_result->as_register() == r0, "result must in r0");185__ b(_continuation);186}187188189// Implementation of NewObjectArrayStub190191NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {192_klass_reg = klass_reg;193_result = result;194_length = length;195_info = new CodeEmitInfo(info);196}197198199void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {200assert(__ rsp_offset() == 0, "frame size should be fixed");201__ bind(_entry);202assert(_length->as_register() == r19, "length must in r19,");203assert(_klass_reg->as_register() == r3, "klass_reg must in r3");204__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));205ce->add_call_info_here(_info);206ce->verify_oop_map(_info);207assert(_result->as_register() == r0, "result must in r0");208__ b(_continuation);209}210// Implementation of MonitorAccessStubs211212MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)213: MonitorAccessStub(obj_reg, lock_reg)214{215_info = new CodeEmitInfo(info);216}217218219void MonitorEnterStub::emit_code(LIR_Assembler* ce) {220assert(__ rsp_offset() == 0, "frame size should be fixed");221__ bind(_entry);222ce->store_parameter(_obj_reg->as_register(), 1);223ce->store_parameter(_lock_reg->as_register(), 0);224Runtime1::StubID enter_id;225if (ce->compilation()->has_fpu_code()) {226enter_id = Runtime1::monitorenter_id;227} else {228enter_id = Runtime1::monitorenter_nofpu_id;229}230__ far_call(RuntimeAddress(Runtime1::entry_for(enter_id)));231ce->add_call_info_here(_info);232ce->verify_oop_map(_info);233__ b(_continuation);234}235236237void MonitorExitStub::emit_code(LIR_Assembler* ce) {238__ bind(_entry);239if (_compute_lock) {240// lock_reg was destroyed by fast unlocking attempt => recompute it241ce->monitor_address(_monitor_ix, _lock_reg);242}243ce->store_parameter(_lock_reg->as_register(), 0);244// note: non-blocking leaf routine => no call info needed245Runtime1::StubID exit_id;246if (ce->compilation()->has_fpu_code()) {247exit_id = Runtime1::monitorexit_id;248} else {249exit_id = Runtime1::monitorexit_nofpu_id;250}251__ adr(lr, _continuation);252__ far_jump(RuntimeAddress(Runtime1::entry_for(exit_id)));253}254255256// Implementation of patching:257// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)258// - Replace original code with a call to the stub259// At Runtime:260// - call to stub, jump to runtime261// - in runtime: preserve all registers (rspecially objects, i.e., source and destination object)262// - in runtime: after initializing class, restore original code, reexecute instruction263264int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;265266void PatchingStub::align_patch_site(MacroAssembler* masm) {267}268269void PatchingStub::emit_code(LIR_Assembler* ce) {270assert(false, "AArch64 should not use C1 runtime patching");271}272273274void DeoptimizeStub::emit_code(LIR_Assembler* ce) {275__ bind(_entry);276ce->store_parameter(_trap_request, 0);277__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));278ce->add_call_info_here(_info);279DEBUG_ONLY(__ should_not_reach_here());280}281282283void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {284address a;285if (_info->deoptimize_on_exception()) {286// Deoptimize, do not throw the exception, because it is probably wrong to do it here.287a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);288} else {289a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);290}291292ce->compilation()->implicit_exception_table()->append(_offset, __ offset());293__ bind(_entry);294__ far_call(RuntimeAddress(a));295ce->add_call_info_here(_info);296ce->verify_oop_map(_info);297debug_only(__ should_not_reach_here());298}299300301void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {302assert(__ rsp_offset() == 0, "frame size should be fixed");303304__ bind(_entry);305// pass the object in a scratch register because all other registers306// must be preserved307if (_obj->is_cpu_register()) {308__ mov(rscratch1, _obj->as_register());309}310__ far_call(RuntimeAddress(Runtime1::entry_for(_stub)), NULL, rscratch2);311ce->add_call_info_here(_info);312debug_only(__ should_not_reach_here());313}314315316void ArrayCopyStub::emit_code(LIR_Assembler* ce) {317//---------------slow case: call to native-----------------318__ bind(_entry);319// Figure out where the args should go320// This should really convert the IntrinsicID to the Method* and signature321// but I don't know how to do that.322//323VMRegPair args[5];324BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};325SharedRuntime::java_calling_convention(signature, args, 5);326327// push parameters328// (src, src_pos, dest, destPos, length)329Register r[5];330r[0] = src()->as_register();331r[1] = src_pos()->as_register();332r[2] = dst()->as_register();333r[3] = dst_pos()->as_register();334r[4] = length()->as_register();335336// next registers will get stored on the stack337for (int i = 0; i < 5 ; i++ ) {338VMReg r_1 = args[i].first();339if (r_1->is_stack()) {340int st_off = r_1->reg2stack() * wordSize;341__ str (r[i], Address(sp, st_off));342} else {343assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");344}345}346347ce->align_call(lir_static_call);348349ce->emit_static_call_stub();350if (ce->compilation()->bailed_out()) {351return; // CodeCache is full352}353Address resolve(SharedRuntime::get_resolve_static_call_stub(),354relocInfo::static_call_type);355address call = __ trampoline_call(resolve);356if (call == NULL) {357ce->bailout("trampoline stub overflow");358return;359}360ce->add_call_info_here(info());361362#ifndef PRODUCT363__ lea(rscratch2, ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));364__ incrementw(Address(rscratch2));365#endif366367__ b(_continuation);368}369370#undef __371372373