Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch32/vm/c1_CodeStubs_aarch32.cpp
32285 views
/*1* Copyright (c) 1999, 2015, 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*/24// This file is a derivative work resulting from (and including) modifications25// made by Azul Systems, Inc. The dates of such changes are 2013-2016.26// Copyright 2013-2016 Azul Systems, Inc. All Rights Reserved.27//28// Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale,29// CA 94089 USA or visit www.azul.com if you need additional information or30// have any questions.3132#include "precompiled.hpp"33#include "c1/c1_CodeStubs.hpp"34#include "c1/c1_FrameMap.hpp"35#include "c1/c1_LIRAssembler.hpp"36#include "c1/c1_MacroAssembler.hpp"37#include "c1/c1_Runtime1.hpp"38#include "nativeInst_aarch32.hpp"39#include "runtime/sharedRuntime.hpp"40#include "vmreg_aarch32.inline.hpp"41#if INCLUDE_ALL_GCS42#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"43#endif4445#define __ ce->masm()->4647#define should_not_reach_here() should_not_reach_here_line(__FILE__, __LINE__)4849void CounterOverflowStub::emit_code(LIR_Assembler* ce) {50__ bind(_entry);51ce->store_parameter(_method->as_register(), 1);52ce->store_parameter(_bci, 0);53__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));54ce->add_call_info_here(_info);55ce->verify_oop_map(_info);56__ b(_continuation);57}5859RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,60bool throw_index_out_of_bounds_exception)61: _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)62, _index(index)63{64assert(info != NULL, "must have info");65_info = new CodeEmitInfo(info);66}6768void RangeCheckStub::emit_code(LIR_Assembler* ce) {69__ bind(_entry);70if (_info->deoptimize_on_exception()) {71address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);72__ far_call(RuntimeAddress(a));73ce->add_call_info_here(_info);74ce->verify_oop_map(_info);75debug_only(__ should_not_reach_here());76return;77}7879if (_index->is_cpu_register()) {80__ mov(rscratch1, _index->as_register());81} else {82__ mov(rscratch1, _index->as_jint());83}84Runtime1::StubID stub_id;85if (_throw_index_out_of_bounds_exception) {86stub_id = Runtime1::throw_index_exception_id;87} else {88stub_id = Runtime1::throw_range_check_failed_id;89}90__ far_call(RuntimeAddress(Runtime1::entry_for(stub_id)), NULL, rscratch2);91ce->add_call_info_here(_info);92ce->verify_oop_map(_info);93debug_only(__ should_not_reach_here());94}9596PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {97_info = new CodeEmitInfo(info);98}99100void PredicateFailedStub::emit_code(LIR_Assembler* ce) {101__ bind(_entry);102address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);103__ far_call(RuntimeAddress(a));104ce->add_call_info_here(_info);105ce->verify_oop_map(_info);106debug_only(__ should_not_reach_here());107}108109void DivByZeroStub::emit_code(LIR_Assembler* ce) {110if (_offset != -1) {111ce->compilation()->implicit_exception_table()->append(_offset, __ offset());112}113__ bind(_entry);114__ far_call(Address(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type));115ce->add_call_info_here(_info);116ce->verify_oop_map(_info);117#ifdef ASSERT118__ should_not_reach_here();119#endif120}121122123124// Implementation of NewInstanceStub125126NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {127_result = result;128_klass = klass;129_klass_reg = klass_reg;130_info = new CodeEmitInfo(info);131assert(stub_id == Runtime1::new_instance_id ||132stub_id == Runtime1::fast_new_instance_id ||133stub_id == Runtime1::fast_new_instance_init_check_id,134"need new_instance id");135_stub_id = stub_id;136}137138139140void NewInstanceStub::emit_code(LIR_Assembler* ce) {141assert(__ rsp_offset() == 0, "frame size should be fixed");142__ bind(_entry);143__ mov(r3, _klass_reg->as_register());144__ far_call(RuntimeAddress(Runtime1::entry_for(_stub_id)));145ce->add_call_info_here(_info);146ce->verify_oop_map(_info);147assert(_result->as_register() == r0, "result must in r0,");148__ b(_continuation);149}150151152// Implementation of NewTypeArrayStub153154// Implementation of NewTypeArrayStub155156NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {157_klass_reg = klass_reg;158_length = length;159_result = result;160_info = new CodeEmitInfo(info);161}162163164void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {165assert(__ rsp_offset() == 0, "frame size should be fixed");166__ bind(_entry);167assert(_length->as_register() == r6, "length must in r6,");168assert(_klass_reg->as_register() == r3, "klass_reg must in r3");169__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));170ce->add_call_info_here(_info);171ce->verify_oop_map(_info);172assert(_result->as_register() == r0, "result must in r0");173__ b(_continuation);174}175176177// Implementation of NewObjectArrayStub178179NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {180_klass_reg = klass_reg;181_result = result;182_length = length;183_info = new CodeEmitInfo(info);184}185186187void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {188assert(__ rsp_offset() == 0, "frame size should be fixed");189__ bind(_entry);190assert(_length->as_register() == r6, "length must in r6");191assert(_klass_reg->as_register() == r3, "klass_reg must in r3");192__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));193ce->add_call_info_here(_info);194ce->verify_oop_map(_info);195assert(_result->as_register() == r0, "result must in r0");196__ b(_continuation);197}198// Implementation of MonitorAccessStubs199200MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)201: MonitorAccessStub(obj_reg, lock_reg)202{203_info = new CodeEmitInfo(info);204}205206207void MonitorEnterStub::emit_code(LIR_Assembler* ce) {208assert(__ rsp_offset() == 0, "frame size should be fixed");209__ bind(_entry);210ce->store_parameter(_obj_reg->as_register(), 1);211ce->store_parameter(_lock_reg->as_register(), 0);212Runtime1::StubID enter_id;213if (ce->compilation()->has_fpu_code()) {214enter_id = Runtime1::monitorenter_id;215} else {216enter_id = Runtime1::monitorenter_nofpu_id;217}218__ far_call(RuntimeAddress(Runtime1::entry_for(enter_id)));219ce->add_call_info_here(_info);220ce->verify_oop_map(_info);221__ b(_continuation);222}223224225void MonitorExitStub::emit_code(LIR_Assembler* ce) {226__ bind(_entry);227if (_compute_lock) {228// lock_reg was destroyed by fast unlocking attempt => recompute it229ce->monitor_address(_monitor_ix, _lock_reg);230}231ce->store_parameter(_lock_reg->as_register(), 0);232// note: non-blocking leaf routine => no call info needed233Runtime1::StubID exit_id;234if (ce->compilation()->has_fpu_code()) {235exit_id = Runtime1::monitorexit_id;236} else {237exit_id = Runtime1::monitorexit_nofpu_id;238}239__ adr(lr, _continuation);240__ far_jump(RuntimeAddress(Runtime1::entry_for(exit_id)));241}242243244// Implementation of patching:245// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)246// - Replace original code with a call to the stub247// At Runtime:248// - call to stub, jump to runtime249// - in runtime: preserve all registers (rspecially objects, i.e., source and destination object)250// - in runtime: after initializing class, restore original code, reexecute instruction251252int PatchingStub::_patch_info_offset = 0;253254void PatchingStub::align_patch_site(MacroAssembler* masm) {255}256257void PatchingStub::emit_code(LIR_Assembler* ce) {258// NativeCall::instruction_size is dynamically calculated based on CPU,259// armv7 -> 3 instructions, armv6 -> 5 instructions. Initialize _patch_info_offset260// here, when CPU is determined already.261if (!_patch_info_offset)262_patch_info_offset = -NativeCall::instruction_size;263assert(_patch_info_offset == -NativeCall::instruction_size, "must not change");264assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, "not enough room for call");265266Label call_patch;267268// static field accesses have special semantics while the class269// initializer is being run so we emit a test which can be used to270// check that this code is being executed by the initializing271// thread.272address being_initialized_entry = __ pc();273if (CommentedAssembly) {274__ block_comment(" patch template");275}276address start = __ pc();277if (_id == load_klass_id) {278// produce a copy of the load klass instruction for use by the being initialized case279int metadata_index = -1;280CodeSection* cs = __ code_section();281RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);282while (iter.next()) {283if (iter.type() == relocInfo::metadata_type) {284metadata_Relocation* r = iter.metadata_reloc();285assert(metadata_index == -1, "uninitalized yet");286metadata_index = r->metadata_index();287break;288}289}290assert(metadata_index != -1, "initialized");291__ relocate(metadata_Relocation::spec(metadata_index));292__ patchable_load(_obj, __ pc());293while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {294__ nop();295}296#ifdef ASSERT297for (int i = 0; i < _bytes_to_copy; i++) {298assert(*(_pc_start + i) == *(start + i), "should be the same code");299}300#endif301} else if (_id == load_mirror_id || _id == load_appendix_id) {302// produce a copy of the load mirror instruction for use by the being303// initialized case304int oop_index = -1;305CodeSection* cs = __ code_section();306RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);307while (iter.next()) {308if (iter.type() == relocInfo::oop_type) {309oop_Relocation* r = iter.oop_reloc();310assert(oop_index == -1, "uninitalized yet");311oop_index = r->oop_index();312break;313}314}315assert(oop_index != -1, "initialized");316__ relocate(oop_Relocation::spec(oop_index));317__ patchable_load(_obj, __ pc());318while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {319__ nop();320}321#ifdef ASSERT322for (int i = 0; i < _bytes_to_copy; i++) {323assert(*(_pc_start + i) == *(start + i), "should be the same code");324}325#endif326} else if (_id == access_field_id) {327// make a copy the code which is going to be patched.328address const_addr = (address) -1;329CodeSection* cs = __ code_section();330RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);331while (iter.next()) {332if (iter.type() == relocInfo::section_word_type) {333section_word_Relocation* r = iter.section_word_reloc();334assert(const_addr == (address) -1, "uninitalized yet");335const_addr = r->target();336break;337}338}339assert(const_addr != (address) -1, "initialized");340__ relocate(section_word_Relocation::spec(const_addr, CodeBuffer::SECT_CONSTS));341__ patchable_load(rscratch1, const_addr);342while ((intx) __ pc() - (intx) start < NativeCall::instruction_size) {343__ nop();344}345#ifdef ASSERT346intptr_t* from = (intptr_t*) start;347intptr_t* to = (intptr_t*) _pc_start;348349assert(NativeFarLdr::from((address) (from))->data_addr()350== NativeFarLdr::from((address) (to))->data_addr(),351"should load from one addr)");352353address next_from = NativeFarLdr::from(start)->next_instruction_address();354address next_to = NativeFarLdr::from(_pc_start)->next_instruction_address();355356assert(sizeof(*start) == sizeof(char), "Correct below");357address end = start + _bytes_to_copy;358while (next_from < end) {359assert(*next_from == *next_to, "should be the same code");360next_from++;361next_to++;362}363#endif364} else {365ShouldNotReachHere();366}367368int bytes_to_skip = _bytes_to_copy;369370if (_id == load_mirror_id) {371int offset = __ offset();372if (CommentedAssembly) {373__ block_comment(" being_initialized check");374}375assert(_obj != noreg, "must be a valid register");376// Load without verification to keep code size small. We need it because377// begin_initialized_entry_offset has to fit in a byte. Also, we know it's not null.378__ ldr(rscratch1, Address(_obj, java_lang_Class::klass_offset_in_bytes()));379__ ldr(rscratch1, Address(rscratch1, InstanceKlass::init_thread_offset()));380__ cmp(rthread, rscratch1);381__ b(call_patch, Assembler::NE);382383// access_field patches may execute the patched code before it's384// copied back into place so we need to jump back into the main385// code of the nmethod to continue execution.386__ b(_patch_site_continuation);387// make sure this extra code gets skipped388bytes_to_skip += __ offset() - offset;389}390391// Now emit the patch record telling the runtime how to find the392// pieces of the patch. We only need 3 bytes but it has to be393// aligned as an instruction so emit 4 bytes.394int sizeof_patch_record = 4;395bytes_to_skip += sizeof_patch_record;396397// emit the offsets needed to find the code to patch398int being_initialized_entry_offset = __ pc() - being_initialized_entry + sizeof_patch_record;399400__ emit_int8(0);401__ emit_int8(being_initialized_entry_offset);402__ emit_int8(bytes_to_skip);403__ emit_int8(0);404405address patch_info_pc = __ pc();406407address entry = __ pc();408NativeGeneralJump::insert_unconditional((address)_pc_start, entry);409address target = NULL;410relocInfo::relocType reloc_type = relocInfo::none;411switch (_id) {412case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); reloc_type = relocInfo::section_word_type; break;413case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;414case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;415case load_appendix_id: target = Runtime1::entry_for(Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;416default: ShouldNotReachHere();417}418__ bind(call_patch);419420if (CommentedAssembly) {421__ block_comment("patch entry point");422}423__ mov(rscratch1, RuntimeAddress(target));424__ bl(rscratch1);425// pad with nops to globally known upper bound of patch site size426while (patch_info_pc - __ pc() < _patch_info_offset)427__ nop();428assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change, required by shared code");429ce->add_call_info_here(_info);430int jmp_off = __ offset();431__ b(_patch_site_entry);432// Add enough nops so deoptimization can overwrite the jmp above with a call433// and not destroy the world.434for (int j = __ offset() ; j < jmp_off + NativeCall::instruction_size; j += NativeInstruction::arm_insn_sz) {435__ nop();436}437438CodeSection* cs = __ code_section();439RelocIterator iter(cs, (address)_pc_start, (address)_pc_start+1);440relocInfo::change_reloc_info_for_address(&iter, (address)_pc_start, reloc_type, relocInfo::none);441}442443444void DeoptimizeStub::emit_code(LIR_Assembler* ce) {445__ bind(_entry);446__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));447ce->add_call_info_here(_info);448DEBUG_ONLY(__ should_not_reach_here());449}450451452void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {453address a;454if (_info->deoptimize_on_exception()) {455// Deoptimize, do not throw the exception, because it is probably wrong to do it here.456a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);457} else {458a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);459}460461ce->compilation()->implicit_exception_table()->append(_offset, __ offset());462__ bind(_entry);463__ far_call(RuntimeAddress(a));464ce->add_call_info_here(_info);465ce->verify_oop_map(_info);466debug_only(__ should_not_reach_here());467}468469470void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {471assert(__ rsp_offset() == 0, "frame size should be fixed");472473__ bind(_entry);474// pass the object in a scratch register because all other registers475// must be preserved476if (_obj->is_cpu_register()) {477__ mov(rscratch1, _obj->as_register());478}479__ far_call(RuntimeAddress(Runtime1::entry_for(_stub)), NULL, rscratch2);480ce->add_call_info_here(_info);481debug_only(__ should_not_reach_here());482}483484485void ArrayCopyStub::emit_code(LIR_Assembler* ce) {486//---------------slow case: call to native-----------------487__ bind(_entry);488// Figure out where the args should go489// This should really convert the IntrinsicID to the Method* and signature490// but I don't know how to do that.491//492VMRegPair args[5];493BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};494SharedRuntime::java_calling_convention(signature, args, 5, true);495496// push parameters497// (src, src_pos, dest, destPos, length)498Register r[5];499r[0] = src()->as_register();500r[1] = src_pos()->as_register();501r[2] = dst()->as_register();502r[3] = dst_pos()->as_register();503r[4] = length()->as_register();504505// next registers will get stored on the stack506for (int i = 0; i < 5 ; i++ ) {507VMReg r_1 = args[i].first();508if (r_1->is_stack()) {509int st_off = r_1->reg2stack() * wordSize;510__ str (r[i], Address(sp, st_off));511} else {512assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");513}514}515516ce->align_call(lir_static_call);517518ce->emit_static_call_stub();519Address resolve(SharedRuntime::get_resolve_static_call_stub(),520relocInfo::static_call_type);521__ trampoline_call(resolve);522ce->add_call_info_here(info());523524#ifndef PRODUCT525__ lea(rscratch2, ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));526__ increment(Address(rscratch2));527#endif528529__ b(_continuation);530}531532533/////////////////////////////////////////////////////////////////////////////534#if INCLUDE_ALL_GCS535536void G1PreBarrierStub::emit_code(LIR_Assembler* ce) {537// At this point we know that marking is in progress.538// If do_load() is true then we have to emit the539// load of the previous value; otherwise it has already540// been loaded into _pre_val.541542__ bind(_entry);543assert(pre_val()->is_register(), "Precondition.");544545Register pre_val_reg = pre_val()->as_register();546547if (do_load()) {548ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false /*wide*/, false /*unaligned*/);549}550__ cbz(pre_val_reg, _continuation);551ce->store_parameter(pre_val()->as_register(), 0);552__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_pre_barrier_slow_id)));553__ b(_continuation);554}555556void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {557__ bind(_entry);558assert(addr()->is_register(), "Precondition.");559assert(new_val()->is_register(), "Precondition.");560Register new_val_reg = new_val()->as_register();561__ cbz(new_val_reg, _continuation);562ce->store_parameter(addr()->as_pointer_register(), 0);563__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_post_barrier_slow_id)));564__ b(_continuation);565}566567#endif // INCLUDE_ALL_GCS568/////////////////////////////////////////////////////////////////////////////569570#undef __571572573