Path: blob/master/src/hotspot/cpu/s390/c1_Runtime1_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016 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_Defs.hpp"28#include "c1/c1_MacroAssembler.hpp"29#include "c1/c1_Runtime1.hpp"30#include "ci/ciUtilities.hpp"31#include "compiler/oopMap.hpp"32#include "gc/shared/cardTable.hpp"33#include "gc/shared/cardTableBarrierSet.hpp"34#include "interpreter/interpreter.hpp"35#include "memory/universe.hpp"36#include "nativeInst_s390.hpp"37#include "oops/compiledICHolder.hpp"38#include "oops/oop.inline.hpp"39#include "prims/jvmtiExport.hpp"40#include "register_s390.hpp"41#include "registerSaver_s390.hpp"42#include "runtime/sharedRuntime.hpp"43#include "runtime/signature.hpp"44#include "runtime/stubRoutines.hpp"45#include "runtime/vframeArray.hpp"46#include "utilities/macros.hpp"47#include "utilities/powerOfTwo.hpp"48#include "vmreg_s390.inline.hpp"4950// Implementation of StubAssembler5152int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry_point, int number_of_arguments) {53set_num_rt_args(0); // Nothing on stack.54assert(!(oop_result1->is_valid() || metadata_result->is_valid()) || oop_result1 != metadata_result, "registers must be different");5556// We cannot trust that code generated by the C++ compiler saves R1457// to z_abi_160.return_pc, because sometimes it spills R14 using stmg at58// z_abi_160.gpr14 (e.g. InterpreterRuntime::_new()).59// Therefore we load the PC into Z_R1_scratch and let set_last_Java_frame() save60// it into the frame anchor.61address pc = get_PC(Z_R1_scratch);62int call_offset = (int)(pc - addr_at(0));63set_last_Java_frame(Z_SP, Z_R1_scratch);6465// ARG1 must hold thread address.66z_lgr(Z_ARG1, Z_thread);6768address return_pc = NULL;69align_call_far_patchable(this->pc());70return_pc = call_c_opt(entry_point);71assert(return_pc != NULL, "const section overflow");7273reset_last_Java_frame();7475// Check for pending exceptions.76{77load_and_test_long(Z_R0_scratch, Address(Z_thread, Thread::pending_exception_offset()));7879// This used to conditionally jump to forward_exception however it is80// possible if we relocate that the branch will not reach. So we must jump81// around so we can always reach.8283Label ok;84z_bre(ok); // Bcondequal is the same as bcondZero.8586// exception pending => forward to exception handler8788// Make sure that the vm_results are cleared.89if (oop_result1->is_valid()) {90clear_mem(Address(Z_thread, JavaThread::vm_result_offset()), sizeof(jlong));91}92if (metadata_result->is_valid()) {93clear_mem(Address(Z_thread, JavaThread::vm_result_2_offset()), sizeof(jlong));94}95if (frame_size() == no_frame_size) {96// Pop the stub frame.97pop_frame();98restore_return_pc();99load_const_optimized(Z_R1, StubRoutines::forward_exception_entry());100z_br(Z_R1);101} else if (_stub_id == Runtime1::forward_exception_id) {102should_not_reach_here();103} else {104load_const_optimized(Z_R1, Runtime1::entry_for (Runtime1::forward_exception_id));105z_br(Z_R1);106}107108bind(ok);109}110111// Get oop results if there are any and reset the values in the thread.112if (oop_result1->is_valid()) {113get_vm_result(oop_result1);114}115if (metadata_result->is_valid()) {116get_vm_result_2(metadata_result);117}118119return call_offset;120}121122123int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {124// Z_ARG1 is reserved for the thread.125lgr_if_needed(Z_ARG2, arg1);126return call_RT(oop_result1, metadata_result, entry, 1);127}128129130int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {131// Z_ARG1 is reserved for the thread.132lgr_if_needed(Z_ARG2, arg1);133assert(arg2 != Z_ARG2, "smashed argument");134lgr_if_needed(Z_ARG3, arg2);135return call_RT(oop_result1, metadata_result, entry, 2);136}137138139int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {140// Z_ARG1 is reserved for the thread.141lgr_if_needed(Z_ARG2, arg1);142assert(arg2 != Z_ARG2, "smashed argument");143lgr_if_needed(Z_ARG3, arg2);144assert(arg3 != Z_ARG3, "smashed argument");145lgr_if_needed(Z_ARG4, arg3);146return call_RT(oop_result1, metadata_result, entry, 3);147}148149150// Implementation of Runtime1151152#define __ sasm->153154#ifndef PRODUCT155#undef __156#define __ (Verbose ? (sasm->block_comment(FILE_AND_LINE),sasm):sasm)->157#endif // !PRODUCT158159#define BLOCK_COMMENT(str) if (PrintAssembly) __ block_comment(str)160#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")161162static OopMap* generate_oop_map(StubAssembler* sasm) {163RegisterSaver::RegisterSet reg_set = RegisterSaver::all_registers;164int frame_size_in_slots =165RegisterSaver::live_reg_frame_size(reg_set) / VMRegImpl::stack_slot_size;166sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word);167return RegisterSaver::generate_oop_map(sasm, reg_set);168}169170static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true, Register return_pc = Z_R14) {171__ block_comment("save_live_registers");172RegisterSaver::RegisterSet reg_set =173save_fpu_registers ? RegisterSaver::all_registers : RegisterSaver::all_integer_registers;174int frame_size_in_slots =175RegisterSaver::live_reg_frame_size(reg_set) / VMRegImpl::stack_slot_size;176sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word);177return RegisterSaver::save_live_registers(sasm, reg_set, return_pc);178}179180static OopMap* save_live_registers_except_r2(StubAssembler* sasm, bool save_fpu_registers = true) {181if (!save_fpu_registers) {182__ unimplemented(FILE_AND_LINE);183}184__ block_comment("save_live_registers");185RegisterSaver::RegisterSet reg_set = RegisterSaver::all_registers_except_r2;186int frame_size_in_slots =187RegisterSaver::live_reg_frame_size(reg_set) / VMRegImpl::stack_slot_size;188sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word);189return RegisterSaver::save_live_registers(sasm, reg_set);190}191192static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {193__ block_comment("restore_live_registers");194RegisterSaver::RegisterSet reg_set =195restore_fpu_registers ? RegisterSaver::all_registers : RegisterSaver::all_integer_registers;196RegisterSaver::restore_live_registers(sasm, reg_set);197}198199static void restore_live_registers_except_r2(StubAssembler* sasm, bool restore_fpu_registers = true) {200if (!restore_fpu_registers) {201__ unimplemented(FILE_AND_LINE);202}203__ block_comment("restore_live_registers_except_r2");204RegisterSaver::restore_live_registers(sasm, RegisterSaver::all_registers_except_r2);205}206207void Runtime1::initialize_pd() {208// Nothing to do.209}210211OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {212// Make a frame and preserve the caller's caller-save registers.213OopMap* oop_map = save_live_registers(sasm);214int call_offset;215if (!has_argument) {216call_offset = __ call_RT(noreg, noreg, target);217} else {218call_offset = __ call_RT(noreg, noreg, target, Z_R1_scratch, Z_R0_scratch);219}220OopMapSet* oop_maps = new OopMapSet();221oop_maps->add_gc_map(call_offset, oop_map);222223__ should_not_reach_here();224return oop_maps;225}226227void Runtime1::generate_unwind_exception(StubAssembler *sasm) {228// Incoming parameters: Z_EXC_OOP and Z_EXC_PC.229// Keep copies in callee-saved registers during runtime call.230const Register exception_oop_callee_saved = Z_R11;231const Register exception_pc_callee_saved = Z_R12;232// Other registers used in this stub.233const Register handler_addr = Z_R4;234235// Verify that only exception_oop, is valid at this time.236__ invalidate_registers(Z_EXC_OOP, Z_EXC_PC);237238// Check that fields in JavaThread for exception oop and issuing pc are set.239__ asm_assert_mem8_is_zero(in_bytes(JavaThread::exception_oop_offset()), Z_thread, "exception oop already set : " FILE_AND_LINE, 0);240__ asm_assert_mem8_is_zero(in_bytes(JavaThread::exception_pc_offset()), Z_thread, "exception pc already set : " FILE_AND_LINE, 0);241242// Save exception_oop and pc in callee-saved register to preserve it243// during runtime calls.244__ verify_not_null_oop(Z_EXC_OOP);245__ lgr_if_needed(exception_oop_callee_saved, Z_EXC_OOP);246__ lgr_if_needed(exception_pc_callee_saved, Z_EXC_PC);247248__ push_frame_abi160(0); // Runtime code needs the z_abi_160.249250// Search the exception handler address of the caller (using the return address).251__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), Z_thread, Z_EXC_PC);252// Z_RET(Z_R2): exception handler address of the caller.253254__ pop_frame();255256__ invalidate_registers(exception_oop_callee_saved, exception_pc_callee_saved, Z_RET);257258// Move result of call into correct register.259__ lgr_if_needed(handler_addr, Z_RET);260261// Restore exception oop and pc to Z_EXC_OOP and Z_EXC_PC (required convention of exception handler).262__ lgr_if_needed(Z_EXC_OOP, exception_oop_callee_saved);263__ lgr_if_needed(Z_EXC_PC, exception_pc_callee_saved);264265// Verify that there is really a valid exception in Z_EXC_OOP.266__ verify_not_null_oop(Z_EXC_OOP);267268__ z_br(handler_addr); // Jump to exception handler.269}270271OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {272// Make a frame and preserve the caller's caller-save registers.273OopMap* oop_map = save_live_registers(sasm);274275// Call the runtime patching routine, returns non-zero if nmethod got deopted.276int call_offset = __ call_RT(noreg, noreg, target);277OopMapSet* oop_maps = new OopMapSet();278oop_maps->add_gc_map(call_offset, oop_map);279280// Re-execute the patched instruction or, if the nmethod was281// deoptmized, return to the deoptimization handler entry that will282// cause re-execution of the current bytecode.283DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();284assert(deopt_blob != NULL, "deoptimization blob must have been created");285286__ z_ltr(Z_RET, Z_RET); // return value == 0287288restore_live_registers(sasm);289290__ z_bcr(Assembler::bcondZero, Z_R14);291292// Return to the deoptimization handler entry for unpacking and293// rexecute if we simply returned then we'd deopt as if any call we294// patched had just returned.295AddressLiteral dest(deopt_blob->unpack_with_reexecution());296__ load_const_optimized(Z_R1_scratch, dest);297__ z_br(Z_R1_scratch);298299return oop_maps;300}301302OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {303304// for better readability305const bool must_gc_arguments = true;306const bool dont_gc_arguments = false;307308// Default value; overwritten for some optimized stubs that are309// called from methods that do not use the fpu.310bool save_fpu_registers = true;311312// Stub code and info for the different stubs.313OopMapSet* oop_maps = NULL;314switch (id) {315case forward_exception_id:316{317oop_maps = generate_handle_exception(id, sasm);318// will not return319}320break;321322case new_instance_id:323case fast_new_instance_id:324case fast_new_instance_init_check_id:325{326Register klass = Z_R11; // Incoming327Register obj = Z_R2; // Result328329if (id == new_instance_id) {330__ set_info("new_instance", dont_gc_arguments);331} else if (id == fast_new_instance_id) {332__ set_info("fast new_instance", dont_gc_arguments);333} else {334assert(id == fast_new_instance_init_check_id, "bad StubID");335__ set_info("fast new_instance init check", dont_gc_arguments);336}337338OopMap* map = save_live_registers_except_r2(sasm);339int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);340oop_maps = new OopMapSet();341oop_maps->add_gc_map(call_offset, map);342restore_live_registers_except_r2(sasm);343344__ verify_oop(obj, FILE_AND_LINE);345__ z_br(Z_R14);346}347break;348349case counter_overflow_id:350{351// Arguments :352// bci : stack param 0353// method : stack param 1354//355Register bci = Z_ARG2, method = Z_ARG3;356// frame size in bytes357OopMap* map = save_live_registers(sasm);358const int frame_size = sasm->frame_size() * VMRegImpl::slots_per_word * VMRegImpl::stack_slot_size;359__ z_lg(bci, 0*BytesPerWord + FrameMap::first_available_sp_in_frame + frame_size, Z_SP);360__ z_lg(method, 1*BytesPerWord + FrameMap::first_available_sp_in_frame + frame_size, Z_SP);361int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);362oop_maps = new OopMapSet();363oop_maps->add_gc_map(call_offset, map);364restore_live_registers(sasm);365__ z_br(Z_R14);366}367break;368case new_type_array_id:369case new_object_array_id:370{371Register length = Z_R13; // Incoming372Register klass = Z_R11; // Incoming373Register obj = Z_R2; // Result374375if (id == new_type_array_id) {376__ set_info("new_type_array", dont_gc_arguments);377} else {378__ set_info("new_object_array", dont_gc_arguments);379}380381#ifdef ASSERT382// Assert object type is really an array of the proper kind.383{384NearLabel ok;385Register t0 = obj;386__ mem2reg_opt(t0, Address(klass, Klass::layout_helper_offset()), false);387__ z_sra(t0, Klass::_lh_array_tag_shift);388int tag = ((id == new_type_array_id)389? Klass::_lh_array_tag_type_value390: Klass::_lh_array_tag_obj_value);391__ compare32_and_branch(t0, tag, Assembler::bcondEqual, ok);392__ stop("assert(is an array klass)");393__ should_not_reach_here();394__ bind(ok);395}396#endif // ASSERT397398OopMap* map = save_live_registers_except_r2(sasm);399int call_offset;400if (id == new_type_array_id) {401call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);402} else {403call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);404}405406oop_maps = new OopMapSet();407oop_maps->add_gc_map(call_offset, map);408restore_live_registers_except_r2(sasm);409410__ verify_oop(obj, FILE_AND_LINE);411__ z_br(Z_R14);412}413break;414415case new_multi_array_id:416{ __ set_info("new_multi_array", dont_gc_arguments);417// Z_R3,: klass418// Z_R4,: rank419// Z_R5: address of 1st dimension420OopMap* map = save_live_registers(sasm);421int call_offset = __ call_RT(Z_R2, noreg, CAST_FROM_FN_PTR(address, new_multi_array), Z_R3, Z_R4, Z_R5);422423oop_maps = new OopMapSet();424oop_maps->add_gc_map(call_offset, map);425restore_live_registers_except_r2(sasm);426427// Z_R2,: new multi array428__ verify_oop(Z_R2, FILE_AND_LINE);429__ z_br(Z_R14);430}431break;432433case register_finalizer_id:434{435__ set_info("register_finalizer", dont_gc_arguments);436437// Load the klass and check the has finalizer flag.438Register klass = Z_ARG2;439__ load_klass(klass, Z_ARG1);440__ testbit(Address(klass, Klass::access_flags_offset()), exact_log2(JVM_ACC_HAS_FINALIZER));441__ z_bcr(Assembler::bcondAllZero, Z_R14); // Return if bit is not set.442443OopMap* oop_map = save_live_registers(sasm);444int call_offset = __ call_RT(noreg, noreg,445CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), Z_ARG1);446oop_maps = new OopMapSet();447oop_maps->add_gc_map(call_offset, oop_map);448449// Now restore all the live registers.450restore_live_registers(sasm);451452__ z_br(Z_R14);453}454break;455456case throw_range_check_failed_id:457{ __ set_info("range_check_failed", dont_gc_arguments);458oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);459}460break;461462case throw_index_exception_id:463{ __ set_info("index_range_check_failed", dont_gc_arguments);464oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);465}466break;467case throw_div0_exception_id:468{ __ set_info("throw_div0_exception", dont_gc_arguments);469oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);470}471break;472case throw_null_pointer_exception_id:473{ __ set_info("throw_null_pointer_exception", dont_gc_arguments);474oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);475}476break;477case handle_exception_nofpu_id:478case handle_exception_id:479{ __ set_info("handle_exception", dont_gc_arguments);480oop_maps = generate_handle_exception(id, sasm);481}482break;483case handle_exception_from_callee_id:484{ __ set_info("handle_exception_from_callee", dont_gc_arguments);485oop_maps = generate_handle_exception(id, sasm);486}487break;488case unwind_exception_id:489{ __ set_info("unwind_exception", dont_gc_arguments);490// Note: no stubframe since we are about to leave the current491// activation and we are calling a leaf VM function only.492generate_unwind_exception(sasm);493}494break;495case throw_array_store_exception_id:496{ __ set_info("throw_array_store_exception", dont_gc_arguments);497oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);498}499break;500case throw_class_cast_exception_id:501{ // Z_R1_scratch: object502__ set_info("throw_class_cast_exception", dont_gc_arguments);503oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);504}505break;506case throw_incompatible_class_change_error_id:507{ __ set_info("throw_incompatible_class_cast_exception", dont_gc_arguments);508oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);509}510break;511case slow_subtype_check_id:512{513// Arguments :514// sub : stack param 0515// super: stack param 1516// raddr: Z_R14, blown by call517//518// Result : condition code 0 for match (bcondEqual will be true),519// condition code 2 for miss (bcondNotEqual will be true)520NearLabel miss;521const Register Rsubklass = Z_ARG2; // sub522const Register Rsuperklass = Z_ARG3; // super523524// No args, but tmp registers that are killed.525const Register Rlength = Z_ARG4; // cache array length526const Register Rarray_ptr = Z_ARG5; // Current value from cache array.527528if (UseCompressedOops) {529assert(Universe::heap() != NULL, "java heap must be initialized to generate partial_subtype_check stub");530}531532const int frame_size = 4*BytesPerWord + frame::z_abi_160_size;533// Save return pc. This is not necessary, but could be helpful534// in the case of crashes.535__ save_return_pc();536__ push_frame(frame_size);537// Save registers before changing them.538int i = 0;539__ z_stg(Rsubklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);540__ z_stg(Rsuperklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);541__ z_stg(Rlength, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);542__ z_stg(Rarray_ptr, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);543assert(i*BytesPerWord + frame::z_abi_160_size == frame_size, "check");544545// Get sub and super from stack.546__ z_lg(Rsubklass, 0*BytesPerWord + FrameMap::first_available_sp_in_frame + frame_size, Z_SP);547__ z_lg(Rsuperklass, 1*BytesPerWord + FrameMap::first_available_sp_in_frame + frame_size, Z_SP);548549__ check_klass_subtype_slow_path(Rsubklass, Rsuperklass, Rarray_ptr, Rlength, NULL, &miss);550551// Match falls through here.552i = 0;553__ z_lg(Rsubklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);554__ z_lg(Rsuperklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);555__ z_lg(Rlength, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);556__ z_lg(Rarray_ptr, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);557assert(i*BytesPerWord + frame::z_abi_160_size == frame_size, "check");558__ pop_frame();559// Return pc is still in R_14.560__ clear_reg(Z_R0_scratch); // Zero indicates a match. Set CC 0 (bcondEqual will be true)561__ z_br(Z_R14);562563__ BIND(miss);564i = 0;565__ z_lg(Rsubklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);566__ z_lg(Rsuperklass, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);567__ z_lg(Rlength, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);568__ z_lg(Rarray_ptr, (i++)*BytesPerWord + frame::z_abi_160_size, Z_SP);569assert(i*BytesPerWord + frame::z_abi_160_size == frame_size, "check");570__ pop_frame();571// return pc is still in R_14572__ load_const_optimized(Z_R0_scratch, 1); // One indicates a miss.573__ z_ltgr(Z_R0_scratch, Z_R0_scratch); // Set CC 2 (bcondNotEqual will be true).574__ z_br(Z_R14);575}576break;577case monitorenter_nofpu_id:578case monitorenter_id:579{ // Z_R1_scratch : object580// Z_R13 : lock address (see LIRGenerator::syncTempOpr())581__ set_info("monitorenter", dont_gc_arguments);582583int save_fpu_registers = (id == monitorenter_id);584// Make a frame and preserve the caller's caller-save registers.585OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);586587int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), Z_R1_scratch, Z_R13);588589oop_maps = new OopMapSet();590oop_maps->add_gc_map(call_offset, oop_map);591restore_live_registers(sasm, save_fpu_registers);592593__ z_br(Z_R14);594}595break;596597case monitorexit_nofpu_id:598case monitorexit_id:599{ // Z_R1_scratch : lock address600// Note: really a leaf routine but must setup last java sp601// => Use call_RT for now (speed can be improved by602// doing last java sp setup manually).603__ set_info("monitorexit", dont_gc_arguments);604605int save_fpu_registers = (id == monitorexit_id);606// Make a frame and preserve the caller's caller-save registers.607OopMap* oop_map = save_live_registers(sasm, save_fpu_registers);608609int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), Z_R1_scratch);610611oop_maps = new OopMapSet();612oop_maps->add_gc_map(call_offset, oop_map);613restore_live_registers(sasm, save_fpu_registers);614615__ z_br(Z_R14);616}617break;618619case deoptimize_id:620{ // Args: Z_R1_scratch: trap request621__ set_info("deoptimize", dont_gc_arguments);622Register trap_request = Z_R1_scratch;623OopMap* oop_map = save_live_registers(sasm);624int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize), trap_request);625oop_maps = new OopMapSet();626oop_maps->add_gc_map(call_offset, oop_map);627restore_live_registers(sasm);628DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();629assert(deopt_blob != NULL, "deoptimization blob must have been created");630AddressLiteral dest(deopt_blob->unpack_with_reexecution());631__ load_const_optimized(Z_R1_scratch, dest);632__ z_br(Z_R1_scratch);633}634break;635636case access_field_patching_id:637{ __ set_info("access_field_patching", dont_gc_arguments);638oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));639}640break;641642case load_klass_patching_id:643{ __ set_info("load_klass_patching", dont_gc_arguments);644// We should set up register map.645oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));646}647break;648649case load_mirror_patching_id:650{ __ set_info("load_mirror_patching", dont_gc_arguments);651oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));652}653break;654655case load_appendix_patching_id:656{ __ set_info("load_appendix_patching", dont_gc_arguments);657oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));658}659break;660#if 0661case dtrace_object_alloc_id:662{ // rax,: object663StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);664// We can't gc here so skip the oopmap but make sure that all665// the live registers get saved.666save_live_registers(sasm, 1);667668__ NOT_LP64(push(rax)) LP64_ONLY(mov(c_rarg0, rax));669__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));670NOT_LP64(__ pop(rax));671672restore_live_registers(sasm);673}674break;675676case fpu2long_stub_id:677{678// rax, and rdx are destroyed, but should be free since the result is returned there679// preserve rsi,ecx680__ push(rsi);681__ push(rcx);682LP64_ONLY(__ push(rdx);)683684// check for NaN685Label return0, do_return, return_min_jlong, do_convert;686687Address value_high_word(rsp, wordSize + 4);688Address value_low_word(rsp, wordSize);689Address result_high_word(rsp, 3*wordSize + 4);690Address result_low_word(rsp, 3*wordSize);691692__ subptr(rsp, 32); // more than enough on 32bit693__ fst_d(value_low_word);694__ movl(rax, value_high_word);695__ andl(rax, 0x7ff00000);696__ cmpl(rax, 0x7ff00000);697__ jcc(Assembler::notEqual, do_convert);698__ movl(rax, value_high_word);699__ andl(rax, 0xfffff);700__ orl(rax, value_low_word);701__ jcc(Assembler::notZero, return0);702703__ bind(do_convert);704__ fnstcw(Address(rsp, 0));705__ movzwl(rax, Address(rsp, 0));706__ orl(rax, 0xc00);707__ movw(Address(rsp, 2), rax);708__ fldcw(Address(rsp, 2));709__ fwait();710__ fistp_d(result_low_word);711__ fldcw(Address(rsp, 0));712__ fwait();713// This gets the entire long in rax on 64bit714__ movptr(rax, result_low_word);715// testing of high bits716__ movl(rdx, result_high_word);717__ mov(rcx, rax);718// What the heck is the point of the next instruction???719__ xorl(rcx, 0x0);720__ movl(rsi, 0x80000000);721__ xorl(rsi, rdx);722__ orl(rcx, rsi);723__ jcc(Assembler::notEqual, do_return);724__ fldz();725__ fcomp_d(value_low_word);726__ fnstsw_ax();727__ testl(rax, 0x4100); // ZF & CF == 0728__ jcc(Assembler::equal, return_min_jlong);729// return max_jlong730__ mov64(rax, CONST64(0x7fffffffffffffff));731__ jmp(do_return);732733__ bind(return_min_jlong);734__ mov64(rax, UCONST64(0x8000000000000000));735__ jmp(do_return);736737__ bind(return0);738__ fpop();739__ xorptr(rax, rax);740741__ bind(do_return);742__ addptr(rsp, 32);743LP64_ONLY(__ pop(rdx);)744__ pop(rcx);745__ pop(rsi);746__ ret(0);747}748break;749#endif // TODO750751case predicate_failed_trap_id:752{753__ set_info("predicate_failed_trap", dont_gc_arguments);754755OopMap* map = save_live_registers(sasm);756757int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));758oop_maps = new OopMapSet();759oop_maps->add_gc_map(call_offset, map);760restore_live_registers(sasm);761762DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();763assert(deopt_blob != NULL, "deoptimization blob must have been created");764765__ load_const_optimized(Z_R1_scratch, deopt_blob->unpack_with_reexecution());766__ z_br(Z_R1_scratch);767}768break;769770default:771{772__ should_not_reach_here(FILE_AND_LINE, id);773}774break;775}776return oop_maps;777}778779OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler *sasm) {780__ block_comment("generate_handle_exception");781782// incoming parameters: Z_EXC_OOP, Z_EXC_PC783784// Save registers if required.785OopMapSet* oop_maps = new OopMapSet();786OopMap* oop_map = NULL;787Register reg_fp = Z_R1_scratch;788789switch (id) {790case forward_exception_id: {791// We're handling an exception in the context of a compiled frame.792// The registers have been saved in the standard places. Perform793// an exception lookup in the caller and dispatch to the handler794// if found. Otherwise unwind and dispatch to the callers795// exception handler.796oop_map = generate_oop_map(sasm);797798// Load and clear pending exception oop into.799__ z_lg(Z_EXC_OOP, Address(Z_thread, Thread::pending_exception_offset()));800__ clear_mem(Address(Z_thread, Thread::pending_exception_offset()), 8);801802// Different stubs forward their exceptions; they should all have similar frame layouts803// (a) to find their return address (b) for a correct oop_map generated above.804assert(RegisterSaver::live_reg_frame_size(RegisterSaver::all_registers) ==805RegisterSaver::live_reg_frame_size(RegisterSaver::all_registers_except_r2), "requirement");806807// Load issuing PC (the return address for this stub).808const int frame_size_in_bytes = sasm->frame_size() * VMRegImpl::slots_per_word * VMRegImpl::stack_slot_size;809__ z_lg(Z_EXC_PC, Address(Z_SP, frame_size_in_bytes + _z_abi16(return_pc)));810DEBUG_ONLY(__ z_lay(reg_fp, Address(Z_SP, frame_size_in_bytes));)811812// Make sure that the vm_results are cleared (may be unnecessary).813__ clear_mem(Address(Z_thread, JavaThread::vm_result_offset()), sizeof(oop));814__ clear_mem(Address(Z_thread, JavaThread::vm_result_2_offset()), sizeof(Metadata*));815break;816}817case handle_exception_nofpu_id:818case handle_exception_id:819// At this point all registers MAY be live.820DEBUG_ONLY(__ z_lgr(reg_fp, Z_SP);)821oop_map = save_live_registers(sasm, id != handle_exception_nofpu_id, Z_EXC_PC);822break;823case handle_exception_from_callee_id: {824// At this point all registers except Z_EXC_OOP and Z_EXC_PC are dead.825DEBUG_ONLY(__ z_lgr(reg_fp, Z_SP);)826__ save_return_pc(Z_EXC_PC);827const int frame_size_in_bytes = __ push_frame_abi160(0);828oop_map = new OopMap(frame_size_in_bytes / VMRegImpl::stack_slot_size, 0);829sasm->set_frame_size(frame_size_in_bytes / BytesPerWord);830break;831}832default: ShouldNotReachHere();833}834835// Verify that only Z_EXC_OOP, and Z_EXC_PC are valid at this time.836__ invalidate_registers(Z_EXC_OOP, Z_EXC_PC, reg_fp);837// Verify that Z_EXC_OOP, contains a valid exception.838__ verify_not_null_oop(Z_EXC_OOP);839840// Check that fields in JavaThread for exception oop and issuing pc841// are empty before writing to them.842__ asm_assert_mem8_is_zero(in_bytes(JavaThread::exception_oop_offset()), Z_thread, "exception oop already set : " FILE_AND_LINE, 0);843__ asm_assert_mem8_is_zero(in_bytes(JavaThread::exception_pc_offset()), Z_thread, "exception pc already set : " FILE_AND_LINE, 0);844845// Save exception oop and issuing pc into JavaThread.846// (Exception handler will load it from here.)847__ z_stg(Z_EXC_OOP, Address(Z_thread, JavaThread::exception_oop_offset()));848__ z_stg(Z_EXC_PC, Address(Z_thread, JavaThread::exception_pc_offset()));849850#ifdef ASSERT851{ NearLabel ok;852__ z_cg(Z_EXC_PC, Address(reg_fp, _z_abi16(return_pc)));853__ branch_optimized(Assembler::bcondEqual, ok);854__ stop("use throwing pc as return address (has bci & oop map)");855__ bind(ok);856}857#endif858859// Compute the exception handler.860// The exception oop and the throwing pc are read from the fields in JavaThread.861int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));862oop_maps->add_gc_map(call_offset, oop_map);863864// Z_RET(Z_R2): handler address865// will be the deopt blob if nmethod was deoptimized while we looked up866// handler regardless of whether handler existed in the nmethod.867868// Only Z_R2, is valid at this time, all other registers have been destroyed by the runtime call.869__ invalidate_registers(Z_R2);870871switch(id) {872case forward_exception_id:873case handle_exception_nofpu_id:874case handle_exception_id:875// Restore the registers that were saved at the beginning.876__ z_lgr(Z_R1_scratch, Z_R2); // Restoring live registers kills Z_R2.877restore_live_registers(sasm, id != handle_exception_nofpu_id); // Pops as well the frame.878__ z_br(Z_R1_scratch);879break;880case handle_exception_from_callee_id: {881__ pop_frame();882__ z_br(Z_R2); // Jump to exception handler.883}884break;885default: ShouldNotReachHere();886}887888return oop_maps;889}890891892#undef __893894const char *Runtime1::pd_name_for_address(address entry) {895return "<unknown function>";896}897898899