Path: blob/master/src/hotspot/cpu/s390/c1_CodeStubs_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2018 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_s390.hpp"34#include "runtime/sharedRuntime.hpp"35#include "utilities/align.hpp"36#include "utilities/macros.hpp"37#include "vmreg_s390.inline.hpp"3839#define __ ce->masm()->40#undef CHECK_BAILOUT41#define CHECK_BAILOUT() { if (ce->compilation()->bailed_out()) return; }4243void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {44ShouldNotReachHere();45}4647RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)48: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {49assert(info != NULL, "must have info");50_info = new CodeEmitInfo(info);51}5253RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)54: _index(index), _array(NULL), _throw_index_out_of_bounds_exception(true) {55assert(info != NULL, "must have info");56_info = new CodeEmitInfo(info);57}5859void RangeCheckStub::emit_code(LIR_Assembler* ce) {60__ bind(_entry);61if (_info->deoptimize_on_exception()) {62address a = Runtime1::entry_for (Runtime1::predicate_failed_trap_id);63ce->emit_call_c(a);64CHECK_BAILOUT();65ce->add_call_info_here(_info);66ce->verify_oop_map(_info);67debug_only(__ should_not_reach_here());68return;69}7071// Pass the array index in Z_R1_scratch which is not managed by linear scan.72if (_index->is_cpu_register()) {73__ lgr_if_needed(Z_R1_scratch, _index->as_register());74} else {75__ load_const_optimized(Z_R1_scratch, _index->as_jint());76}7778Runtime1::StubID stub_id;79if (_throw_index_out_of_bounds_exception) {80stub_id = Runtime1::throw_index_exception_id;81} else {82stub_id = Runtime1::throw_range_check_failed_id;83__ lgr_if_needed(Z_R0_scratch, _array->as_pointer_register());84}85ce->emit_call_c(Runtime1::entry_for (stub_id));86CHECK_BAILOUT();87ce->add_call_info_here(_info);88ce->verify_oop_map(_info);89debug_only(__ should_not_reach_here());90}9192PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {93_info = new CodeEmitInfo(info);94}9596void PredicateFailedStub::emit_code(LIR_Assembler* ce) {97__ bind(_entry);98address a = Runtime1::entry_for (Runtime1::predicate_failed_trap_id);99ce->emit_call_c(a);100CHECK_BAILOUT();101ce->add_call_info_here(_info);102ce->verify_oop_map(_info);103debug_only(__ should_not_reach_here());104}105106void CounterOverflowStub::emit_code(LIR_Assembler* ce) {107__ bind(_entry);108Metadata *m = _method->as_constant_ptr()->as_metadata();109bool success = __ set_metadata_constant(m, Z_R1_scratch);110if (!success) {111ce->compilation()->bailout("const section overflow");112return;113}114ce->store_parameter(/*_method->as_register()*/ Z_R1_scratch, 1);115ce->store_parameter(_bci, 0);116ce->emit_call_c(Runtime1::entry_for (Runtime1::counter_overflow_id));117CHECK_BAILOUT();118ce->add_call_info_here(_info);119ce->verify_oop_map(_info);120__ branch_optimized(Assembler::bcondAlways, _continuation);121}122123void DivByZeroStub::emit_code(LIR_Assembler* ce) {124if (_offset != -1) {125ce->compilation()->implicit_exception_table()->append(_offset, __ offset());126}127__ bind(_entry);128ce->emit_call_c(Runtime1::entry_for (Runtime1::throw_div0_exception_id));129CHECK_BAILOUT();130ce->add_call_info_here(_info);131debug_only(__ should_not_reach_here());132}133134void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {135address a;136if (_info->deoptimize_on_exception()) {137// Deoptimize, do not throw the exception, because it is probably wrong to do it here.138a = Runtime1::entry_for (Runtime1::predicate_failed_trap_id);139} else {140a = Runtime1::entry_for (Runtime1::throw_null_pointer_exception_id);141}142143ce->compilation()->implicit_exception_table()->append(_offset, __ offset());144__ bind(_entry);145ce->emit_call_c(a);146CHECK_BAILOUT();147ce->add_call_info_here(_info);148ce->verify_oop_map(_info);149debug_only(__ should_not_reach_here());150}151152// Note: pass object in Z_R1_scratch153void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {154__ bind(_entry);155if (_obj->is_valid()) {156__ z_lgr(Z_R1_scratch, _obj->as_register()); // _obj contains the optional argument to the stub157}158address a = Runtime1::entry_for (_stub);159ce->emit_call_c(a);160CHECK_BAILOUT();161ce->add_call_info_here(_info);162debug_only(__ should_not_reach_here());163}164165NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {166_result = result;167_klass = klass;168_klass_reg = klass_reg;169_info = new CodeEmitInfo(info);170assert(stub_id == Runtime1::new_instance_id ||171stub_id == Runtime1::fast_new_instance_id ||172stub_id == Runtime1::fast_new_instance_init_check_id,173"need new_instance id");174_stub_id = stub_id;175}176177void NewInstanceStub::emit_code(LIR_Assembler* ce) {178__ bind(_entry);179assert(_klass_reg->as_register() == Z_R11, "call target expects klass in Z_R11");180address a = Runtime1::entry_for (_stub_id);181ce->emit_call_c(a);182CHECK_BAILOUT();183ce->add_call_info_here(_info);184ce->verify_oop_map(_info);185assert(_result->as_register() == Z_R2, "callee returns result in Z_R2,");186__ z_brul(_continuation);187}188189NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {190_klass_reg = klass_reg;191_length = length;192_result = result;193_info = new CodeEmitInfo(info);194}195196void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {197__ bind(_entry);198assert(_klass_reg->as_register() == Z_R11, "call target expects klass in Z_R11");199__ lgr_if_needed(Z_R13, _length->as_register());200address a = Runtime1::entry_for (Runtime1::new_type_array_id);201ce->emit_call_c(a);202CHECK_BAILOUT();203ce->add_call_info_here(_info);204ce->verify_oop_map(_info);205assert(_result->as_register() == Z_R2, "callee returns result in Z_R2,");206__ z_brul(_continuation);207}208209NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {210_klass_reg = klass_reg;211_length = length;212_result = result;213_info = new CodeEmitInfo(info);214}215216void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {217__ bind(_entry);218assert(_klass_reg->as_register() == Z_R11, "call target expects klass in Z_R11");219__ lgr_if_needed(Z_R13, _length->as_register());220address a = Runtime1::entry_for (Runtime1::new_object_array_id);221ce->emit_call_c(a);222CHECK_BAILOUT();223ce->add_call_info_here(_info);224ce->verify_oop_map(_info);225assert(_result->as_register() == Z_R2, "callee returns result in Z_R2,");226__ z_brul(_continuation);227}228229MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)230: MonitorAccessStub(obj_reg, lock_reg) {231_info = new CodeEmitInfo(info);232}233234void MonitorEnterStub::emit_code(LIR_Assembler* ce) {235__ bind(_entry);236Runtime1::StubID enter_id;237if (ce->compilation()->has_fpu_code()) {238enter_id = Runtime1::monitorenter_id;239} else {240enter_id = Runtime1::monitorenter_nofpu_id;241}242__ lgr_if_needed(Z_R1_scratch, _obj_reg->as_register());243__ lgr_if_needed(Z_R13, _lock_reg->as_register()); // See LIRGenerator::syncTempOpr().244ce->emit_call_c(Runtime1::entry_for (enter_id));245CHECK_BAILOUT();246ce->add_call_info_here(_info);247ce->verify_oop_map(_info);248__ branch_optimized(Assembler::bcondAlways, _continuation);249}250251void MonitorExitStub::emit_code(LIR_Assembler* ce) {252__ bind(_entry);253// Move address of the BasicObjectLock into Z_R1_scratch.254if (_compute_lock) {255// Lock_reg was destroyed by fast unlocking attempt => recompute it.256ce->monitor_address(_monitor_ix, FrameMap::as_opr(Z_R1_scratch));257} else {258__ lgr_if_needed(Z_R1_scratch, _lock_reg->as_register());259}260// Note: non-blocking leaf routine => no call info needed.261Runtime1::StubID exit_id;262if (ce->compilation()->has_fpu_code()) {263exit_id = Runtime1::monitorexit_id;264} else {265exit_id = Runtime1::monitorexit_nofpu_id;266}267ce->emit_call_c(Runtime1::entry_for (exit_id));268CHECK_BAILOUT();269__ branch_optimized(Assembler::bcondAlways, _continuation);270}271272// Implementation of patching:273// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes).274// - Replace original code with a call to the stub.275// At Runtime:276// - call to stub, jump to runtime.277// - in runtime: Preserve all registers (especially objects, i.e., source and destination object).278// - in runtime: After initializing class, restore original code, reexecute instruction.279280int PatchingStub::_patch_info_offset = - (12 /* load const */ + 2 /*BASR*/);281282void PatchingStub::align_patch_site(MacroAssembler* masm) {283#ifndef PRODUCT284const char* bc;285switch (_id) {286case access_field_id: bc = "patch site (access_field)"; break;287case load_klass_id: bc = "patch site (load_klass)"; break;288case load_mirror_id: bc = "patch site (load_mirror)"; break;289case load_appendix_id: bc = "patch site (load_appendix)"; break;290default: bc = "patch site (unknown patch id)"; break;291}292masm->block_comment(bc);293#endif294295masm->align(align_up((int)NativeGeneralJump::instruction_size, wordSize));296}297298void PatchingStub::emit_code(LIR_Assembler* ce) {299// Copy original code here.300assert(NativeGeneralJump::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,301"not enough room for call, need %d", _bytes_to_copy);302303NearLabel call_patch;304305int being_initialized_entry = __ offset();306307if (_id == load_klass_id) {308// Produce a copy of the load klass instruction for use by the case being initialized.309#ifdef ASSERT310address start = __ pc();311#endif312AddressLiteral addrlit((intptr_t)0, metadata_Relocation::spec(_index));313__ load_const(_obj, addrlit);314315#ifdef ASSERT316for (int i = 0; i < _bytes_to_copy; i++) {317address ptr = (address)(_pc_start + i);318int a_byte = (*ptr) & 0xFF;319assert(a_byte == *start++, "should be the same code");320}321#endif322} else if (_id == load_mirror_id || _id == load_appendix_id) {323// Produce a copy of the load mirror instruction for use by the case being initialized.324#ifdef ASSERT325address start = __ pc();326#endif327AddressLiteral addrlit((intptr_t)0, oop_Relocation::spec(_index));328__ load_const(_obj, addrlit);329330#ifdef ASSERT331for (int i = 0; i < _bytes_to_copy; i++) {332address ptr = (address)(_pc_start + i);333int a_byte = (*ptr) & 0xFF;334assert(a_byte == *start++, "should be the same code");335}336#endif337} else {338// Make a copy of the code which is going to be patched.339for (int i = 0; i < _bytes_to_copy; i++) {340address ptr = (address)(_pc_start + i);341int a_byte = (*ptr) & 0xFF;342__ emit_int8 (a_byte);343}344}345346address end_of_patch = __ pc();347int bytes_to_skip = 0;348if (_id == load_mirror_id) {349int offset = __ offset();350if (CommentedAssembly) {351__ block_comment(" being_initialized check");352}353354// Static field accesses have special semantics while the class355// initializer is being run, so we emit a test which can be used to356// check that this code is being executed by the initializing357// thread.358assert(_obj != noreg, "must be a valid register");359assert(_index >= 0, "must have oop index");360__ z_lg(Z_R1_scratch, java_lang_Class::klass_offset(), _obj);361__ z_cg(Z_thread, Address(Z_R1_scratch, InstanceKlass::init_thread_offset()));362__ branch_optimized(Assembler::bcondNotEqual, call_patch);363364// Load_klass patches may execute the patched code before it's365// copied back into place so we need to jump back into the main366// code of the nmethod to continue execution.367__ branch_optimized(Assembler::bcondAlways, _patch_site_continuation);368369// Make sure this extra code gets skipped.370bytes_to_skip += __ offset() - offset;371}372373// Now emit the patch record telling the runtime how to find the374// pieces of the patch. We only need 3 bytes but to help the disassembler375// we make the data look like a the following add instruction:376// A R1, D2(X2, B2)377// which requires 4 bytes.378int sizeof_patch_record = 4;379bytes_to_skip += sizeof_patch_record;380381// Emit the offsets needed to find the code to patch.382int being_initialized_entry_offset = __ offset() - being_initialized_entry + sizeof_patch_record;383384// Emit the patch record: opcode of the add followed by 3 bytes patch record data.385__ emit_int8((int8_t)(A_ZOPC>>24));386__ emit_int8(being_initialized_entry_offset);387__ emit_int8(bytes_to_skip);388__ emit_int8(_bytes_to_copy);389address patch_info_pc = __ pc();390assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");391392address entry = __ pc();393NativeGeneralJump::insert_unconditional((address)_pc_start, entry);394address target = NULL;395relocInfo::relocType reloc_type = relocInfo::none;396switch (_id) {397case access_field_id: target = Runtime1::entry_for (Runtime1::access_field_patching_id); break;398case load_klass_id: target = Runtime1::entry_for (Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;399case load_mirror_id: target = Runtime1::entry_for (Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;400case load_appendix_id: target = Runtime1::entry_for (Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;401default: ShouldNotReachHere();402}403__ bind(call_patch);404405if (CommentedAssembly) {406__ block_comment("patch entry point");407}408// Cannot use call_c_opt() because its size is not constant.409__ load_const(Z_R1_scratch, target); // Must not optimize in order to keep constant _patch_info_offset constant.410__ z_basr(Z_R14, Z_R1_scratch);411assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");412ce->add_call_info_here(_info);413__ z_brcl(Assembler::bcondAlways, _patch_site_entry);414if (_id == load_klass_id || _id == load_mirror_id || _id == load_appendix_id) {415CodeSection* cs = __ code_section();416address pc = (address)_pc_start;417RelocIterator iter(cs, pc, pc + 1);418relocInfo::change_reloc_info_for_address(&iter, (address) pc, reloc_type, relocInfo::none);419}420}421422void DeoptimizeStub::emit_code(LIR_Assembler* ce) {423__ bind(_entry);424__ load_const_optimized(Z_R1_scratch, _trap_request); // Pass trap request in Z_R1_scratch.425ce->emit_call_c(Runtime1::entry_for (Runtime1::deoptimize_id));426CHECK_BAILOUT();427ce->add_call_info_here(_info);428DEBUG_ONLY(__ should_not_reach_here());429}430431void ArrayCopyStub::emit_code(LIR_Assembler* ce) {432// Slow case: call to native.433__ bind(_entry);434__ lgr_if_needed(Z_ARG1, src()->as_register());435__ lgr_if_needed(Z_ARG2, src_pos()->as_register());436__ lgr_if_needed(Z_ARG3, dst()->as_register());437__ lgr_if_needed(Z_ARG4, dst_pos()->as_register());438__ lgr_if_needed(Z_ARG5, length()->as_register());439440// Must align calls sites, otherwise they can't be updated atomically on MP hardware.441ce->align_call(lir_static_call);442443assert((__ offset() + NativeCall::call_far_pcrelative_displacement_offset) % NativeCall::call_far_pcrelative_displacement_alignment == 0,444"must be aligned");445446ce->emit_static_call_stub();447448// Prepend each BRASL with a nop.449__ relocate(relocInfo::static_call_type);450__ z_nop();451__ z_brasl(Z_R14, SharedRuntime::get_resolve_static_call_stub());452ce->add_call_info_here(info());453ce->verify_oop_map(info());454455#ifndef PRODUCT456__ load_const_optimized(Z_R1_scratch, (address)&Runtime1::_arraycopy_slowcase_cnt);457__ add2mem_32(Address(Z_R1_scratch), 1, Z_R0_scratch);458#endif459460__ branch_optimized(Assembler::bcondAlways, _continuation);461}462463#undef __464465466