Path: blob/master/src/hotspot/cpu/x86/c1_Runtime1_x86.cpp
41144 views
/*1* Copyright (c) 1999, 2021, 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/assembler.hpp"26#include "c1/c1_Defs.hpp"27#include "c1/c1_MacroAssembler.hpp"28#include "c1/c1_Runtime1.hpp"29#include "ci/ciUtilities.hpp"30#include "compiler/oopMap.hpp"31#include "gc/shared/cardTable.hpp"32#include "gc/shared/cardTableBarrierSet.hpp"33#include "gc/shared/collectedHeap.hpp"34#include "gc/shared/tlab_globals.hpp"35#include "interpreter/interpreter.hpp"36#include "memory/universe.hpp"37#include "nativeInst_x86.hpp"38#include "oops/compiledICHolder.hpp"39#include "oops/oop.inline.hpp"40#include "prims/jvmtiExport.hpp"41#include "register_x86.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 "vmreg_x86.inline.hpp"4849// Implementation of StubAssembler5051int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, int args_size) {52// setup registers53const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread); // is callee-saved register (Visual C++ calling conventions)54assert(!(oop_result1->is_valid() || metadata_result->is_valid()) || oop_result1 != metadata_result, "registers must be different");55assert(oop_result1 != thread && metadata_result != thread, "registers must be different");56assert(args_size >= 0, "illegal args_size");57bool align_stack = false;58#ifdef _LP6459// At a method handle call, the stack may not be properly aligned60// when returning with an exception.61align_stack = (stub_id() == Runtime1::handle_exception_from_callee_id);62#endif6364#ifdef _LP6465mov(c_rarg0, thread);66set_num_rt_args(0); // Nothing on stack67#else68set_num_rt_args(1 + args_size);6970// push java thread (becomes first argument of C function)71get_thread(thread);72push(thread);73#endif // _LP647475int call_offset = -1;76if (!align_stack) {77set_last_Java_frame(thread, noreg, rbp, NULL);78} else {79address the_pc = pc();80call_offset = offset();81set_last_Java_frame(thread, noreg, rbp, the_pc);82andptr(rsp, -(StackAlignmentInBytes)); // Align stack83}8485// do the call86call(RuntimeAddress(entry));87if (!align_stack) {88call_offset = offset();89}90// verify callee-saved register91#ifdef ASSERT92guarantee(thread != rax, "change this code");93push(rax);94{ Label L;95get_thread(rax);96cmpptr(thread, rax);97jcc(Assembler::equal, L);98int3();99stop("StubAssembler::call_RT: rdi not callee saved?");100bind(L);101}102pop(rax);103#endif104reset_last_Java_frame(thread, true);105106// discard thread and arguments107NOT_LP64(addptr(rsp, num_rt_args()*BytesPerWord));108109// check for pending exceptions110{ Label L;111cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);112jcc(Assembler::equal, L);113// exception pending => remove activation and forward to exception handler114movptr(rax, Address(thread, Thread::pending_exception_offset()));115// make sure that the vm_results are cleared116if (oop_result1->is_valid()) {117movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);118}119if (metadata_result->is_valid()) {120movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);121}122if (frame_size() == no_frame_size) {123leave();124jump(RuntimeAddress(StubRoutines::forward_exception_entry()));125} else if (_stub_id == Runtime1::forward_exception_id) {126should_not_reach_here();127} else {128jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));129}130bind(L);131}132// get oop results if there are any and reset the values in the thread133if (oop_result1->is_valid()) {134get_vm_result(oop_result1, thread);135}136if (metadata_result->is_valid()) {137get_vm_result_2(metadata_result, thread);138}139140assert(call_offset >= 0, "Should be set");141return call_offset;142}143144145int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {146#ifdef _LP64147mov(c_rarg1, arg1);148#else149push(arg1);150#endif // _LP64151return call_RT(oop_result1, metadata_result, entry, 1);152}153154155int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {156#ifdef _LP64157if (c_rarg1 == arg2) {158if (c_rarg2 == arg1) {159xchgq(arg1, arg2);160} else {161mov(c_rarg2, arg2);162mov(c_rarg1, arg1);163}164} else {165mov(c_rarg1, arg1);166mov(c_rarg2, arg2);167}168#else169push(arg2);170push(arg1);171#endif // _LP64172return call_RT(oop_result1, metadata_result, entry, 2);173}174175176int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {177#ifdef _LP64178// if there is any conflict use the stack179if (arg1 == c_rarg2 || arg1 == c_rarg3 ||180arg2 == c_rarg1 || arg2 == c_rarg3 ||181arg3 == c_rarg1 || arg3 == c_rarg2) {182push(arg3);183push(arg2);184push(arg1);185pop(c_rarg1);186pop(c_rarg2);187pop(c_rarg3);188} else {189mov(c_rarg1, arg1);190mov(c_rarg2, arg2);191mov(c_rarg3, arg3);192}193#else194push(arg3);195push(arg2);196push(arg1);197#endif // _LP64198return call_RT(oop_result1, metadata_result, entry, 3);199}200201202// Implementation of StubFrame203204class StubFrame: public StackObj {205private:206StubAssembler* _sasm;207208public:209StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments);210void load_argument(int offset_in_words, Register reg);211212~StubFrame();213};214215void StubAssembler::prologue(const char* name, bool must_gc_arguments) {216set_info(name, must_gc_arguments);217enter();218}219220void StubAssembler::epilogue() {221leave();222ret(0);223}224225#define __ _sasm->226227StubFrame::StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments) {228_sasm = sasm;229__ prologue(name, must_gc_arguments);230}231232// load parameters that were stored with LIR_Assembler::store_parameter233// Note: offsets for store_parameter and load_argument must match234void StubFrame::load_argument(int offset_in_words, Register reg) {235__ load_parameter(offset_in_words, reg);236}237238239StubFrame::~StubFrame() {240__ epilogue();241}242243#undef __244245246// Implementation of Runtime1247248const int float_regs_as_doubles_size_in_slots = pd_nof_fpu_regs_frame_map * 2;249const int xmm_regs_as_doubles_size_in_slots = FrameMap::nof_xmm_regs * 2;250251// Stack layout for saving/restoring all the registers needed during a runtime252// call (this includes deoptimization)253// Note: note that users of this frame may well have arguments to some runtime254// while these values are on the stack. These positions neglect those arguments255// but the code in save_live_registers will take the argument count into256// account.257//258#ifdef _LP64259#define SLOT2(x) x,260#define SLOT_PER_WORD 2261#else262#define SLOT2(x)263#define SLOT_PER_WORD 1264#endif // _LP64265266enum reg_save_layout {267// 64bit needs to keep stack 16 byte aligned. So we add some alignment dummies to make that268// happen and will assert if the stack size we create is misaligned269#ifdef _LP64270align_dummy_0, align_dummy_1,271#endif // _LP64272#ifdef _WIN64273// Windows always allocates space for it's argument registers (see274// frame::arg_reg_save_area_bytes).275arg_reg_save_1, arg_reg_save_1H, // 0, 4276arg_reg_save_2, arg_reg_save_2H, // 8, 12277arg_reg_save_3, arg_reg_save_3H, // 16, 20278arg_reg_save_4, arg_reg_save_4H, // 24, 28279#endif // _WIN64280xmm_regs_as_doubles_off, // 32281float_regs_as_doubles_off = xmm_regs_as_doubles_off + xmm_regs_as_doubles_size_in_slots, // 160282fpu_state_off = float_regs_as_doubles_off + float_regs_as_doubles_size_in_slots, // 224283// fpu_state_end_off is exclusive284fpu_state_end_off = fpu_state_off + (FPUStateSizeInWords / SLOT_PER_WORD), // 352285marker = fpu_state_end_off, SLOT2(markerH) // 352, 356286extra_space_offset, // 360287#ifdef _LP64288r15_off = extra_space_offset, r15H_off, // 360, 364289r14_off, r14H_off, // 368, 372290r13_off, r13H_off, // 376, 380291r12_off, r12H_off, // 384, 388292r11_off, r11H_off, // 392, 396293r10_off, r10H_off, // 400, 404294r9_off, r9H_off, // 408, 412295r8_off, r8H_off, // 416, 420296rdi_off, rdiH_off, // 424, 428297#else298rdi_off = extra_space_offset,299#endif // _LP64300rsi_off, SLOT2(rsiH_off) // 432, 436301rbp_off, SLOT2(rbpH_off) // 440, 444302rsp_off, SLOT2(rspH_off) // 448, 452303rbx_off, SLOT2(rbxH_off) // 456, 460304rdx_off, SLOT2(rdxH_off) // 464, 468305rcx_off, SLOT2(rcxH_off) // 472, 476306rax_off, SLOT2(raxH_off) // 480, 484307saved_rbp_off, SLOT2(saved_rbpH_off) // 488, 492308return_off, SLOT2(returnH_off) // 496, 500309reg_save_frame_size // As noted: neglects any parameters to runtime // 504310};311312// Save off registers which might be killed by calls into the runtime.313// Tries to smart of about FP registers. In particular we separate314// saving and describing the FPU registers for deoptimization since we315// have to save the FPU registers twice if we describe them and on P4316// saving FPU registers which don't contain anything appears317// expensive. The deopt blob is the only thing which needs to318// describe FPU registers. In all other cases it should be sufficient319// to simply save their current value.320321static OopMap* generate_oop_map(StubAssembler* sasm, int num_rt_args,322bool save_fpu_registers = true) {323324// In 64bit all the args are in regs so there are no additional stack slots325LP64_ONLY(num_rt_args = 0);326LP64_ONLY(assert((reg_save_frame_size * VMRegImpl::stack_slot_size) % 16 == 0, "must be 16 byte aligned");)327int frame_size_in_slots = reg_save_frame_size + num_rt_args; // args + thread328sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word);329330// record saved value locations in an OopMap331// locations are offsets from sp after runtime call; num_rt_args is number of arguments in call, including thread332OopMap* map = new OopMap(frame_size_in_slots, 0);333map->set_callee_saved(VMRegImpl::stack2reg(rax_off + num_rt_args), rax->as_VMReg());334map->set_callee_saved(VMRegImpl::stack2reg(rcx_off + num_rt_args), rcx->as_VMReg());335map->set_callee_saved(VMRegImpl::stack2reg(rdx_off + num_rt_args), rdx->as_VMReg());336map->set_callee_saved(VMRegImpl::stack2reg(rbx_off + num_rt_args), rbx->as_VMReg());337map->set_callee_saved(VMRegImpl::stack2reg(rsi_off + num_rt_args), rsi->as_VMReg());338map->set_callee_saved(VMRegImpl::stack2reg(rdi_off + num_rt_args), rdi->as_VMReg());339#ifdef _LP64340map->set_callee_saved(VMRegImpl::stack2reg(r8_off + num_rt_args), r8->as_VMReg());341map->set_callee_saved(VMRegImpl::stack2reg(r9_off + num_rt_args), r9->as_VMReg());342map->set_callee_saved(VMRegImpl::stack2reg(r10_off + num_rt_args), r10->as_VMReg());343map->set_callee_saved(VMRegImpl::stack2reg(r11_off + num_rt_args), r11->as_VMReg());344map->set_callee_saved(VMRegImpl::stack2reg(r12_off + num_rt_args), r12->as_VMReg());345map->set_callee_saved(VMRegImpl::stack2reg(r13_off + num_rt_args), r13->as_VMReg());346map->set_callee_saved(VMRegImpl::stack2reg(r14_off + num_rt_args), r14->as_VMReg());347map->set_callee_saved(VMRegImpl::stack2reg(r15_off + num_rt_args), r15->as_VMReg());348349// This is stupid but needed.350map->set_callee_saved(VMRegImpl::stack2reg(raxH_off + num_rt_args), rax->as_VMReg()->next());351map->set_callee_saved(VMRegImpl::stack2reg(rcxH_off + num_rt_args), rcx->as_VMReg()->next());352map->set_callee_saved(VMRegImpl::stack2reg(rdxH_off + num_rt_args), rdx->as_VMReg()->next());353map->set_callee_saved(VMRegImpl::stack2reg(rbxH_off + num_rt_args), rbx->as_VMReg()->next());354map->set_callee_saved(VMRegImpl::stack2reg(rsiH_off + num_rt_args), rsi->as_VMReg()->next());355map->set_callee_saved(VMRegImpl::stack2reg(rdiH_off + num_rt_args), rdi->as_VMReg()->next());356357map->set_callee_saved(VMRegImpl::stack2reg(r8H_off + num_rt_args), r8->as_VMReg()->next());358map->set_callee_saved(VMRegImpl::stack2reg(r9H_off + num_rt_args), r9->as_VMReg()->next());359map->set_callee_saved(VMRegImpl::stack2reg(r10H_off + num_rt_args), r10->as_VMReg()->next());360map->set_callee_saved(VMRegImpl::stack2reg(r11H_off + num_rt_args), r11->as_VMReg()->next());361map->set_callee_saved(VMRegImpl::stack2reg(r12H_off + num_rt_args), r12->as_VMReg()->next());362map->set_callee_saved(VMRegImpl::stack2reg(r13H_off + num_rt_args), r13->as_VMReg()->next());363map->set_callee_saved(VMRegImpl::stack2reg(r14H_off + num_rt_args), r14->as_VMReg()->next());364map->set_callee_saved(VMRegImpl::stack2reg(r15H_off + num_rt_args), r15->as_VMReg()->next());365#endif // _LP64366367int xmm_bypass_limit = FrameMap::nof_xmm_regs;368#ifdef _LP64369if (UseAVX < 3) {370xmm_bypass_limit = xmm_bypass_limit / 2;371}372#endif373374if (save_fpu_registers) {375#ifndef _LP64376if (UseSSE < 2) {377int fpu_off = float_regs_as_doubles_off;378for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {379VMReg fpu_name_0 = FrameMap::fpu_regname(n);380map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + num_rt_args), fpu_name_0);381// %%% This is really a waste but we'll keep things as they were for now382if (true) {383map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + 1 + num_rt_args), fpu_name_0->next());384}385fpu_off += 2;386}387assert(fpu_off == fpu_state_off, "incorrect number of fpu stack slots");388389if (UseSSE == 1) {390int xmm_off = xmm_regs_as_doubles_off;391for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {392VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();393map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);394xmm_off += 2;395}396assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");397}398}399#endif // !LP64400401if (UseSSE >= 2) {402int xmm_off = xmm_regs_as_doubles_off;403for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {404if (n < xmm_bypass_limit) {405VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();406map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);407// %%% This is really a waste but we'll keep things as they were for now408if (true) {409map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + 1 + num_rt_args), xmm_name_0->next());410}411}412xmm_off += 2;413}414assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");415}416}417418return map;419}420421#define __ this->422423void C1_MacroAssembler::save_live_registers_no_oop_map(bool save_fpu_registers) {424__ block_comment("save_live_registers");425426__ pusha(); // integer registers427428// assert(float_regs_as_doubles_off % 2 == 0, "misaligned offset");429// assert(xmm_regs_as_doubles_off % 2 == 0, "misaligned offset");430431__ subptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);432433#ifdef ASSERT434__ movptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);435#endif436437if (save_fpu_registers) {438#ifndef _LP64439if (UseSSE < 2) {440// save FPU stack441__ fnsave(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));442__ fwait();443444#ifdef ASSERT445Label ok;446__ cmpw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::x86::fpu_cntrl_wrd_std());447__ jccb(Assembler::equal, ok);448__ stop("corrupted control word detected");449__ bind(ok);450#endif451452// Reset the control word to guard against exceptions being unmasked453// since fstp_d can cause FPU stack underflow exceptions. Write it454// into the on stack copy and then reload that to make sure that the455// current and future values are correct.456__ movw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::x86::fpu_cntrl_wrd_std());457__ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));458459// Save the FPU registers in de-opt-able form460int offset = 0;461for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {462__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset));463offset += 8;464}465466if (UseSSE == 1) {467// save XMM registers as float because double not supported without SSE2(num MMX == num fpu)468int offset = 0;469for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {470XMMRegister xmm_name = as_XMMRegister(n);471__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset), xmm_name);472offset += 8;473}474}475}476#endif // !_LP64477478if (UseSSE >= 2) {479// save XMM registers480// XMM registers can contain float or double values, but this is not known here,481// so always save them as doubles.482// note that float values are _not_ converted automatically, so for float values483// the second word contains only garbage data.484int xmm_bypass_limit = FrameMap::nof_xmm_regs;485int offset = 0;486#ifdef _LP64487if (UseAVX < 3) {488xmm_bypass_limit = xmm_bypass_limit / 2;489}490#endif491for (int n = 0; n < xmm_bypass_limit; n++) {492XMMRegister xmm_name = as_XMMRegister(n);493__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset), xmm_name);494offset += 8;495}496}497}498499// FPU stack must be empty now500NOT_LP64( __ verify_FPU(0, "save_live_registers"); )501}502503#undef __504#define __ sasm->505506static void restore_fpu(C1_MacroAssembler* sasm, bool restore_fpu_registers) {507#ifdef _LP64508if (restore_fpu_registers) {509// restore XMM registers510int xmm_bypass_limit = FrameMap::nof_xmm_regs;511if (UseAVX < 3) {512xmm_bypass_limit = xmm_bypass_limit / 2;513}514int offset = 0;515for (int n = 0; n < xmm_bypass_limit; n++) {516XMMRegister xmm_name = as_XMMRegister(n);517__ movdbl(xmm_name, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset));518offset += 8;519}520}521#else522if (restore_fpu_registers) {523if (UseSSE >= 2) {524// restore XMM registers525int xmm_bypass_limit = FrameMap::nof_xmm_regs;526int offset = 0;527for (int n = 0; n < xmm_bypass_limit; n++) {528XMMRegister xmm_name = as_XMMRegister(n);529__ movdbl(xmm_name, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset));530offset += 8;531}532} else if (UseSSE == 1) {533// restore XMM registers(num MMX == num fpu)534int offset = 0;535for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {536XMMRegister xmm_name = as_XMMRegister(n);537__ movflt(xmm_name, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + offset));538offset += 8;539}540}541542if (UseSSE < 2) {543__ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));544} else {545// check that FPU stack is really empty546__ verify_FPU(0, "restore_live_registers");547}548} else {549// check that FPU stack is really empty550__ verify_FPU(0, "restore_live_registers");551}552#endif // _LP64553554#ifdef ASSERT555{556Label ok;557__ cmpptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);558__ jcc(Assembler::equal, ok);559__ stop("bad offsets in frame");560__ bind(ok);561}562#endif // ASSERT563564__ addptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);565}566567#undef __568#define __ this->569570void C1_MacroAssembler::restore_live_registers(bool restore_fpu_registers) {571__ block_comment("restore_live_registers");572573restore_fpu(this, restore_fpu_registers);574__ popa();575}576577578void C1_MacroAssembler::restore_live_registers_except_rax(bool restore_fpu_registers) {579__ block_comment("restore_live_registers_except_rax");580581restore_fpu(this, restore_fpu_registers);582583#ifdef _LP64584__ movptr(r15, Address(rsp, 0));585__ movptr(r14, Address(rsp, wordSize));586__ movptr(r13, Address(rsp, 2 * wordSize));587__ movptr(r12, Address(rsp, 3 * wordSize));588__ movptr(r11, Address(rsp, 4 * wordSize));589__ movptr(r10, Address(rsp, 5 * wordSize));590__ movptr(r9, Address(rsp, 6 * wordSize));591__ movptr(r8, Address(rsp, 7 * wordSize));592__ movptr(rdi, Address(rsp, 8 * wordSize));593__ movptr(rsi, Address(rsp, 9 * wordSize));594__ movptr(rbp, Address(rsp, 10 * wordSize));595// skip rsp596__ movptr(rbx, Address(rsp, 12 * wordSize));597__ movptr(rdx, Address(rsp, 13 * wordSize));598__ movptr(rcx, Address(rsp, 14 * wordSize));599600__ addptr(rsp, 16 * wordSize);601#else602603__ pop(rdi);604__ pop(rsi);605__ pop(rbp);606__ pop(rbx); // skip this value607__ pop(rbx);608__ pop(rdx);609__ pop(rcx);610__ addptr(rsp, BytesPerWord);611#endif // _LP64612}613614#undef __615#define __ sasm->616617static OopMap* save_live_registers(StubAssembler* sasm, int num_rt_args,618bool save_fpu_registers = true) {619__ save_live_registers_no_oop_map(save_fpu_registers);620return generate_oop_map(sasm, num_rt_args, save_fpu_registers);621}622623static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {624__ restore_live_registers(restore_fpu_registers);625}626627static void restore_live_registers_except_rax(StubAssembler* sasm, bool restore_fpu_registers = true) {628sasm->restore_live_registers_except_rax(restore_fpu_registers);629}630631632void Runtime1::initialize_pd() {633// nothing to do634}635636637// Target: the entry point of the method that creates and posts the exception oop.638// has_argument: true if the exception needs arguments (passed on the stack because639// registers must be preserved).640OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {641// Preserve all registers.642int num_rt_args = has_argument ? (2 + 1) : 1;643OopMap* oop_map = save_live_registers(sasm, num_rt_args);644645// Now all registers are saved and can be used freely.646// Verify that no old value is used accidentally.647__ invalidate_registers(true, true, true, true, true, true);648649// Registers used by this stub.650const Register temp_reg = rbx;651652// Load arguments for exception that are passed as arguments into the stub.653if (has_argument) {654#ifdef _LP64655__ movptr(c_rarg1, Address(rbp, 2*BytesPerWord));656__ movptr(c_rarg2, Address(rbp, 3*BytesPerWord));657#else658__ movptr(temp_reg, Address(rbp, 3*BytesPerWord));659__ push(temp_reg);660__ movptr(temp_reg, Address(rbp, 2*BytesPerWord));661__ push(temp_reg);662#endif // _LP64663}664int call_offset = __ call_RT(noreg, noreg, target, num_rt_args - 1);665666OopMapSet* oop_maps = new OopMapSet();667oop_maps->add_gc_map(call_offset, oop_map);668669__ stop("should not reach here");670671return oop_maps;672}673674675OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler *sasm) {676__ block_comment("generate_handle_exception");677678// incoming parameters679const Register exception_oop = rax;680const Register exception_pc = rdx;681// other registers used in this stub682const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);683684// Save registers, if required.685OopMapSet* oop_maps = new OopMapSet();686OopMap* oop_map = NULL;687switch (id) {688case forward_exception_id:689// We're handling an exception in the context of a compiled frame.690// The registers have been saved in the standard places. Perform691// an exception lookup in the caller and dispatch to the handler692// if found. Otherwise unwind and dispatch to the callers693// exception handler.694oop_map = generate_oop_map(sasm, 1 /*thread*/);695696// load and clear pending exception oop into RAX697__ movptr(exception_oop, Address(thread, Thread::pending_exception_offset()));698__ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);699700// load issuing PC (the return address for this stub) into rdx701__ movptr(exception_pc, Address(rbp, 1*BytesPerWord));702703// make sure that the vm_results are cleared (may be unnecessary)704__ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);705__ movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);706break;707case handle_exception_nofpu_id:708case handle_exception_id:709// At this point all registers MAY be live.710oop_map = save_live_registers(sasm, 1 /*thread*/, id != handle_exception_nofpu_id);711break;712case handle_exception_from_callee_id: {713// At this point all registers except exception oop (RAX) and714// exception pc (RDX) are dead.715const int frame_size = 2 /*BP, return address*/ NOT_LP64(+ 1 /*thread*/) WIN64_ONLY(+ frame::arg_reg_save_area_bytes / BytesPerWord);716oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);717sasm->set_frame_size(frame_size);718WIN64_ONLY(__ subq(rsp, frame::arg_reg_save_area_bytes));719break;720}721default: ShouldNotReachHere();722}723724#if !defined(_LP64) && defined(COMPILER2)725if (UseSSE < 2 && !CompilerConfig::is_c1_only_no_jvmci()) {726// C2 can leave the fpu stack dirty727__ empty_FPU_stack();728}729#endif // !_LP64 && COMPILER2730731// verify that only rax, and rdx is valid at this time732__ invalidate_registers(false, true, true, false, true, true);733// verify that rax, contains a valid exception734__ verify_not_null_oop(exception_oop);735736// load address of JavaThread object for thread-local data737NOT_LP64(__ get_thread(thread);)738739#ifdef ASSERT740// check that fields in JavaThread for exception oop and issuing pc are741// empty before writing to them742Label oop_empty;743__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t) NULL_WORD);744__ jcc(Assembler::equal, oop_empty);745__ stop("exception oop already set");746__ bind(oop_empty);747748Label pc_empty;749__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);750__ jcc(Assembler::equal, pc_empty);751__ stop("exception pc already set");752__ bind(pc_empty);753#endif754755// save exception oop and issuing pc into JavaThread756// (exception handler will load it from here)757__ movptr(Address(thread, JavaThread::exception_oop_offset()), exception_oop);758__ movptr(Address(thread, JavaThread::exception_pc_offset()), exception_pc);759760// patch throwing pc into return address (has bci & oop map)761__ movptr(Address(rbp, 1*BytesPerWord), exception_pc);762763// compute the exception handler.764// the exception oop and the throwing pc are read from the fields in JavaThread765int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));766oop_maps->add_gc_map(call_offset, oop_map);767768// rax: handler address769// will be the deopt blob if nmethod was deoptimized while we looked up770// handler regardless of whether handler existed in the nmethod.771772// only rax, is valid at this time, all other registers have been destroyed by the runtime call773__ invalidate_registers(false, true, true, true, true, true);774775// patch the return address, this stub will directly return to the exception handler776__ movptr(Address(rbp, 1*BytesPerWord), rax);777778switch (id) {779case forward_exception_id:780case handle_exception_nofpu_id:781case handle_exception_id:782// Restore the registers that were saved at the beginning.783restore_live_registers(sasm, id != handle_exception_nofpu_id);784break;785case handle_exception_from_callee_id:786// WIN64_ONLY: No need to add frame::arg_reg_save_area_bytes to SP787// since we do a leave anyway.788789// Pop the return address.790__ leave();791__ pop(rcx);792__ jmp(rcx); // jump to exception handler793break;794default: ShouldNotReachHere();795}796797return oop_maps;798}799800801void Runtime1::generate_unwind_exception(StubAssembler *sasm) {802// incoming parameters803const Register exception_oop = rax;804// callee-saved copy of exception_oop during runtime call805const Register exception_oop_callee_saved = NOT_LP64(rsi) LP64_ONLY(r14);806// other registers used in this stub807const Register exception_pc = rdx;808const Register handler_addr = rbx;809const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);810811// verify that only rax, is valid at this time812__ invalidate_registers(false, true, true, true, true, true);813814#ifdef ASSERT815// check that fields in JavaThread for exception oop and issuing pc are empty816NOT_LP64(__ get_thread(thread);)817Label oop_empty;818__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), 0);819__ jcc(Assembler::equal, oop_empty);820__ stop("exception oop must be empty");821__ bind(oop_empty);822823Label pc_empty;824__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);825__ jcc(Assembler::equal, pc_empty);826__ stop("exception pc must be empty");827__ bind(pc_empty);828#endif829830// clear the FPU stack in case any FPU results are left behind831NOT_LP64( __ empty_FPU_stack(); )832833// save exception_oop in callee-saved register to preserve it during runtime calls834__ verify_not_null_oop(exception_oop);835__ movptr(exception_oop_callee_saved, exception_oop);836837NOT_LP64(__ get_thread(thread);)838// Get return address (is on top of stack after leave).839__ movptr(exception_pc, Address(rsp, 0));840841// search the exception handler address of the caller (using the return address)842__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc);843// rax: exception handler address of the caller844845// Only RAX and RSI are valid at this time, all other registers have been destroyed by the call.846__ invalidate_registers(false, true, true, true, false, true);847848// move result of call into correct register849__ movptr(handler_addr, rax);850851// Restore exception oop to RAX (required convention of exception handler).852__ movptr(exception_oop, exception_oop_callee_saved);853854// verify that there is really a valid exception in rax855__ verify_not_null_oop(exception_oop);856857// get throwing pc (= return address).858// rdx has been destroyed by the call, so it must be set again859// the pop is also necessary to simulate the effect of a ret(0)860__ pop(exception_pc);861862// continue at exception handler (return address removed)863// note: do *not* remove arguments when unwinding the864// activation since the caller assumes having865// all arguments on the stack when entering the866// runtime to determine the exception handler867// (GC happens at call site with arguments!)868// rax: exception oop869// rdx: throwing pc870// rbx: exception handler871__ jmp(handler_addr);872}873874875OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {876// use the maximum number of runtime-arguments here because it is difficult to877// distinguish each RT-Call.878// Note: This number affects also the RT-Call in generate_handle_exception because879// the oop-map is shared for all calls.880const int num_rt_args = 2; // thread + dummy881882DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();883assert(deopt_blob != NULL, "deoptimization blob must have been created");884885OopMap* oop_map = save_live_registers(sasm, num_rt_args);886887#ifdef _LP64888const Register thread = r15_thread;889// No need to worry about dummy890__ mov(c_rarg0, thread);891#else892__ push(rax); // push dummy893894const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)895// push java thread (becomes first argument of C function)896__ get_thread(thread);897__ push(thread);898#endif // _LP64899__ set_last_Java_frame(thread, noreg, rbp, NULL);900// do the call901__ call(RuntimeAddress(target));902OopMapSet* oop_maps = new OopMapSet();903oop_maps->add_gc_map(__ offset(), oop_map);904// verify callee-saved register905#ifdef ASSERT906guarantee(thread != rax, "change this code");907__ push(rax);908{ Label L;909__ get_thread(rax);910__ cmpptr(thread, rax);911__ jcc(Assembler::equal, L);912__ stop("StubAssembler::call_RT: rdi/r15 not callee saved?");913__ bind(L);914}915__ pop(rax);916#endif917__ reset_last_Java_frame(thread, true);918#ifndef _LP64919__ pop(rcx); // discard thread arg920__ pop(rcx); // discard dummy921#endif // _LP64922923// check for pending exceptions924{ Label L;925__ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);926__ jcc(Assembler::equal, L);927// exception pending => remove activation and forward to exception handler928929__ testptr(rax, rax); // have we deoptimized?930__ jump_cc(Assembler::equal,931RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));932933// the deopt blob expects exceptions in the special fields of934// JavaThread, so copy and clear pending exception.935936// load and clear pending exception937__ movptr(rax, Address(thread, Thread::pending_exception_offset()));938__ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);939940// check that there is really a valid exception941__ verify_not_null_oop(rax);942943// load throwing pc: this is the return address of the stub944__ movptr(rdx, Address(rsp, return_off * VMRegImpl::stack_slot_size));945946#ifdef ASSERT947// check that fields in JavaThread for exception oop and issuing pc are empty948Label oop_empty;949__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);950__ jcc(Assembler::equal, oop_empty);951__ stop("exception oop must be empty");952__ bind(oop_empty);953954Label pc_empty;955__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);956__ jcc(Assembler::equal, pc_empty);957__ stop("exception pc must be empty");958__ bind(pc_empty);959#endif960961// store exception oop and throwing pc to JavaThread962__ movptr(Address(thread, JavaThread::exception_oop_offset()), rax);963__ movptr(Address(thread, JavaThread::exception_pc_offset()), rdx);964965restore_live_registers(sasm);966967__ leave();968__ addptr(rsp, BytesPerWord); // remove return address from stack969970// Forward the exception directly to deopt blob. We can blow no971// registers and must leave throwing pc on the stack. A patch may972// have values live in registers so the entry point with the973// exception in tls.974__ jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls()));975976__ bind(L);977}978979980// Runtime will return true if the nmethod has been deoptimized during981// the patching process. In that case we must do a deopt reexecute instead.982983Label cont;984985__ testptr(rax, rax); // have we deoptimized?986__ jcc(Assembler::equal, cont); // no987988// Will reexecute. Proper return address is already on the stack we just restore989// registers, pop all of our frame but the return address and jump to the deopt blob990restore_live_registers(sasm);991__ leave();992__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));993994__ bind(cont);995restore_live_registers(sasm);996__ leave();997__ ret(0);998999return oop_maps;1000}100110021003OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {10041005// for better readability1006const bool must_gc_arguments = true;1007const bool dont_gc_arguments = false;10081009// default value; overwritten for some optimized stubs that are called from methods that do not use the fpu1010bool save_fpu_registers = true;10111012// stub code & info for the different stubs1013OopMapSet* oop_maps = NULL;1014switch (id) {1015case forward_exception_id:1016{1017oop_maps = generate_handle_exception(id, sasm);1018__ leave();1019__ ret(0);1020}1021break;10221023case new_instance_id:1024case fast_new_instance_id:1025case fast_new_instance_init_check_id:1026{1027Register klass = rdx; // Incoming1028Register obj = rax; // Result10291030if (id == new_instance_id) {1031__ set_info("new_instance", dont_gc_arguments);1032} else if (id == fast_new_instance_id) {1033__ set_info("fast new_instance", dont_gc_arguments);1034} else {1035assert(id == fast_new_instance_init_check_id, "bad StubID");1036__ set_info("fast new_instance init check", dont_gc_arguments);1037}10381039// If TLAB is disabled, see if there is support for inlining contiguous1040// allocations.1041// Otherwise, just go to the slow path.1042if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) && !UseTLAB1043&& Universe::heap()->supports_inline_contig_alloc()) {1044Label slow_path;1045Register obj_size = rcx;1046Register t1 = rbx;1047Register t2 = rsi;1048assert_different_registers(klass, obj, obj_size, t1, t2);10491050__ push(rdi);1051__ push(rbx);10521053if (id == fast_new_instance_init_check_id) {1054// make sure the klass is initialized1055__ cmpb(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);1056__ jcc(Assembler::notEqual, slow_path);1057}10581059#ifdef ASSERT1060// assert object can be fast path allocated1061{1062Label ok, not_ok;1063__ movl(obj_size, Address(klass, Klass::layout_helper_offset()));1064__ cmpl(obj_size, 0); // make sure it's an instance (LH > 0)1065__ jcc(Assembler::lessEqual, not_ok);1066__ testl(obj_size, Klass::_lh_instance_slow_path_bit);1067__ jcc(Assembler::zero, ok);1068__ bind(not_ok);1069__ stop("assert(can be fast path allocated)");1070__ should_not_reach_here();1071__ bind(ok);1072}1073#endif // ASSERT10741075const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);1076NOT_LP64(__ get_thread(thread));10771078// get the instance size (size is postive so movl is fine for 64bit)1079__ movl(obj_size, Address(klass, Klass::layout_helper_offset()));10801081__ eden_allocate(thread, obj, obj_size, 0, t1, slow_path);10821083__ initialize_object(obj, klass, obj_size, 0, t1, t2, /* is_tlab_allocated */ false);1084__ verify_oop(obj);1085__ pop(rbx);1086__ pop(rdi);1087__ ret(0);10881089__ bind(slow_path);1090__ pop(rbx);1091__ pop(rdi);1092}10931094__ enter();1095OopMap* map = save_live_registers(sasm, 2);1096int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);1097oop_maps = new OopMapSet();1098oop_maps->add_gc_map(call_offset, map);1099restore_live_registers_except_rax(sasm);1100__ verify_oop(obj);1101__ leave();1102__ ret(0);11031104// rax,: new instance1105}11061107break;11081109case counter_overflow_id:1110{1111Register bci = rax, method = rbx;1112__ enter();1113OopMap* map = save_live_registers(sasm, 3);1114// Retrieve bci1115__ movl(bci, Address(rbp, 2*BytesPerWord));1116// And a pointer to the Method*1117__ movptr(method, Address(rbp, 3*BytesPerWord));1118int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);1119oop_maps = new OopMapSet();1120oop_maps->add_gc_map(call_offset, map);1121restore_live_registers(sasm);1122__ leave();1123__ ret(0);1124}1125break;11261127case new_type_array_id:1128case new_object_array_id:1129{1130Register length = rbx; // Incoming1131Register klass = rdx; // Incoming1132Register obj = rax; // Result11331134if (id == new_type_array_id) {1135__ set_info("new_type_array", dont_gc_arguments);1136} else {1137__ set_info("new_object_array", dont_gc_arguments);1138}11391140#ifdef ASSERT1141// assert object type is really an array of the proper kind1142{1143Label ok;1144Register t0 = obj;1145__ movl(t0, Address(klass, Klass::layout_helper_offset()));1146__ sarl(t0, Klass::_lh_array_tag_shift);1147int tag = ((id == new_type_array_id)1148? Klass::_lh_array_tag_type_value1149: Klass::_lh_array_tag_obj_value);1150__ cmpl(t0, tag);1151__ jcc(Assembler::equal, ok);1152__ stop("assert(is an array klass)");1153__ should_not_reach_here();1154__ bind(ok);1155}1156#endif // ASSERT11571158// If TLAB is disabled, see if there is support for inlining contiguous1159// allocations.1160// Otherwise, just go to the slow path.1161if (!UseTLAB && Universe::heap()->supports_inline_contig_alloc()) {1162Register arr_size = rsi;1163Register t1 = rcx; // must be rcx for use as shift count1164Register t2 = rdi;1165Label slow_path;11661167// get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))1168// since size is positive movl does right thing on 64bit1169__ movl(t1, Address(klass, Klass::layout_helper_offset()));1170// since size is postive movl does right thing on 64bit1171__ movl(arr_size, length);1172assert(t1 == rcx, "fixed register usage");1173__ shlptr(arr_size /* by t1=rcx, mod 32 */);1174__ shrptr(t1, Klass::_lh_header_size_shift);1175__ andptr(t1, Klass::_lh_header_size_mask);1176__ addptr(arr_size, t1);1177__ addptr(arr_size, MinObjAlignmentInBytesMask); // align up1178__ andptr(arr_size, ~MinObjAlignmentInBytesMask);11791180// Using t2 for non 64-bit.1181const Register thread = NOT_LP64(t2) LP64_ONLY(r15_thread);1182NOT_LP64(__ get_thread(thread));1183__ eden_allocate(thread, obj, arr_size, 0, t1, slow_path); // preserves arr_size11841185__ initialize_header(obj, klass, length, t1, t2);1186__ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));1187assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");1188assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");1189__ andptr(t1, Klass::_lh_header_size_mask);1190__ subptr(arr_size, t1); // body length1191__ addptr(t1, obj); // body start1192__ initialize_body(t1, arr_size, 0, t2);1193__ verify_oop(obj);1194__ ret(0);11951196__ bind(slow_path);1197}11981199__ enter();1200OopMap* map = save_live_registers(sasm, 3);1201int call_offset;1202if (id == new_type_array_id) {1203call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);1204} else {1205call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);1206}12071208oop_maps = new OopMapSet();1209oop_maps->add_gc_map(call_offset, map);1210restore_live_registers_except_rax(sasm);12111212__ verify_oop(obj);1213__ leave();1214__ ret(0);12151216// rax,: new array1217}1218break;12191220case new_multi_array_id:1221{ StubFrame f(sasm, "new_multi_array", dont_gc_arguments);1222// rax,: klass1223// rbx,: rank1224// rcx: address of 1st dimension1225OopMap* map = save_live_registers(sasm, 4);1226int call_offset = __ call_RT(rax, noreg, CAST_FROM_FN_PTR(address, new_multi_array), rax, rbx, rcx);12271228oop_maps = new OopMapSet();1229oop_maps->add_gc_map(call_offset, map);1230restore_live_registers_except_rax(sasm);12311232// rax,: new multi array1233__ verify_oop(rax);1234}1235break;12361237case register_finalizer_id:1238{1239__ set_info("register_finalizer", dont_gc_arguments);12401241// This is called via call_runtime so the arguments1242// will be place in C abi locations12431244#ifdef _LP641245__ verify_oop(c_rarg0);1246__ mov(rax, c_rarg0);1247#else1248// The object is passed on the stack and we haven't pushed a1249// frame yet so it's one work away from top of stack.1250__ movptr(rax, Address(rsp, 1 * BytesPerWord));1251__ verify_oop(rax);1252#endif // _LP6412531254// load the klass and check the has finalizer flag1255Label register_finalizer;1256Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);1257Register t = rsi;1258__ load_klass(t, rax, tmp_load_klass);1259__ movl(t, Address(t, Klass::access_flags_offset()));1260__ testl(t, JVM_ACC_HAS_FINALIZER);1261__ jcc(Assembler::notZero, register_finalizer);1262__ ret(0);12631264__ bind(register_finalizer);1265__ enter();1266OopMap* oop_map = save_live_registers(sasm, 2 /*num_rt_args */);1267int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), rax);1268oop_maps = new OopMapSet();1269oop_maps->add_gc_map(call_offset, oop_map);12701271// Now restore all the live registers1272restore_live_registers(sasm);12731274__ leave();1275__ ret(0);1276}1277break;12781279case throw_range_check_failed_id:1280{ StubFrame f(sasm, "range_check_failed", dont_gc_arguments);1281oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);1282}1283break;12841285case throw_index_exception_id:1286{ StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments);1287oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);1288}1289break;12901291case throw_div0_exception_id:1292{ StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments);1293oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);1294}1295break;12961297case throw_null_pointer_exception_id:1298{ StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments);1299oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);1300}1301break;13021303case handle_exception_nofpu_id:1304case handle_exception_id:1305{ StubFrame f(sasm, "handle_exception", dont_gc_arguments);1306oop_maps = generate_handle_exception(id, sasm);1307}1308break;13091310case handle_exception_from_callee_id:1311{ StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);1312oop_maps = generate_handle_exception(id, sasm);1313}1314break;13151316case unwind_exception_id:1317{ __ set_info("unwind_exception", dont_gc_arguments);1318// note: no stubframe since we are about to leave the current1319// activation and we are calling a leaf VM function only.1320generate_unwind_exception(sasm);1321}1322break;13231324case throw_array_store_exception_id:1325{ StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments);1326// tos + 0: link1327// + 1: return address1328oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);1329}1330break;13311332case throw_class_cast_exception_id:1333{ StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments);1334oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);1335}1336break;13371338case throw_incompatible_class_change_error_id:1339{ StubFrame f(sasm, "throw_incompatible_class_cast_exception", dont_gc_arguments);1340oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);1341}1342break;13431344case slow_subtype_check_id:1345{1346// Typical calling sequence:1347// __ push(klass_RInfo); // object klass or other subclass1348// __ push(sup_k_RInfo); // array element klass or other superclass1349// __ call(slow_subtype_check);1350// Note that the subclass is pushed first, and is therefore deepest.1351// Previous versions of this code reversed the names 'sub' and 'super'.1352// This was operationally harmless but made the code unreadable.1353enum layout {1354rax_off, SLOT2(raxH_off)1355rcx_off, SLOT2(rcxH_off)1356rsi_off, SLOT2(rsiH_off)1357rdi_off, SLOT2(rdiH_off)1358// saved_rbp_off, SLOT2(saved_rbpH_off)1359return_off, SLOT2(returnH_off)1360sup_k_off, SLOT2(sup_kH_off)1361klass_off, SLOT2(superH_off)1362framesize,1363result_off = klass_off // deepest argument is also the return value1364};13651366__ set_info("slow_subtype_check", dont_gc_arguments);1367__ push(rdi);1368__ push(rsi);1369__ push(rcx);1370__ push(rax);13711372// This is called by pushing args and not with C abi1373__ movptr(rsi, Address(rsp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass1374__ movptr(rax, Address(rsp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass13751376Label miss;1377__ check_klass_subtype_slow_path(rsi, rax, rcx, rdi, NULL, &miss);13781379// fallthrough on success:1380__ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), 1); // result1381__ pop(rax);1382__ pop(rcx);1383__ pop(rsi);1384__ pop(rdi);1385__ ret(0);13861387__ bind(miss);1388__ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), NULL_WORD); // result1389__ pop(rax);1390__ pop(rcx);1391__ pop(rsi);1392__ pop(rdi);1393__ ret(0);1394}1395break;13961397case monitorenter_nofpu_id:1398save_fpu_registers = false;1399// fall through1400case monitorenter_id:1401{1402StubFrame f(sasm, "monitorenter", dont_gc_arguments);1403OopMap* map = save_live_registers(sasm, 3, save_fpu_registers);14041405// Called with store_parameter and not C abi14061407f.load_argument(1, rax); // rax,: object1408f.load_argument(0, rbx); // rbx,: lock address14091410int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), rax, rbx);14111412oop_maps = new OopMapSet();1413oop_maps->add_gc_map(call_offset, map);1414restore_live_registers(sasm, save_fpu_registers);1415}1416break;14171418case monitorexit_nofpu_id:1419save_fpu_registers = false;1420// fall through1421case monitorexit_id:1422{1423StubFrame f(sasm, "monitorexit", dont_gc_arguments);1424OopMap* map = save_live_registers(sasm, 2, save_fpu_registers);14251426// Called with store_parameter and not C abi14271428f.load_argument(0, rax); // rax,: lock address14291430// note: really a leaf routine but must setup last java sp1431// => use call_RT for now (speed can be improved by1432// doing last java sp setup manually)1433int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), rax);14341435oop_maps = new OopMapSet();1436oop_maps->add_gc_map(call_offset, map);1437restore_live_registers(sasm, save_fpu_registers);1438}1439break;14401441case deoptimize_id:1442{1443StubFrame f(sasm, "deoptimize", dont_gc_arguments);1444const int num_rt_args = 2; // thread, trap_request1445OopMap* oop_map = save_live_registers(sasm, num_rt_args);1446f.load_argument(0, rax);1447int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize), rax);1448oop_maps = new OopMapSet();1449oop_maps->add_gc_map(call_offset, oop_map);1450restore_live_registers(sasm);1451DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();1452assert(deopt_blob != NULL, "deoptimization blob must have been created");1453__ leave();1454__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));1455}1456break;14571458case access_field_patching_id:1459{ StubFrame f(sasm, "access_field_patching", dont_gc_arguments);1460// we should set up register map1461oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));1462}1463break;14641465case load_klass_patching_id:1466{ StubFrame f(sasm, "load_klass_patching", dont_gc_arguments);1467// we should set up register map1468oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));1469}1470break;14711472case load_mirror_patching_id:1473{ StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments);1474// we should set up register map1475oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));1476}1477break;14781479case load_appendix_patching_id:1480{ StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments);1481// we should set up register map1482oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));1483}1484break;14851486case dtrace_object_alloc_id:1487{ // rax,: object1488StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);1489// we can't gc here so skip the oopmap but make sure that all1490// the live registers get saved.1491save_live_registers(sasm, 1);14921493__ NOT_LP64(push(rax)) LP64_ONLY(mov(c_rarg0, rax));1494__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));1495NOT_LP64(__ pop(rax));14961497restore_live_registers(sasm);1498}1499break;15001501case fpu2long_stub_id:1502{1503#ifdef _LP641504Label done;1505__ cvttsd2siq(rax, Address(rsp, wordSize));1506__ cmp64(rax, ExternalAddress((address) StubRoutines::x86::double_sign_flip()));1507__ jccb(Assembler::notEqual, done);1508__ movq(rax, Address(rsp, wordSize));1509__ subptr(rsp, 8);1510__ movq(Address(rsp, 0), rax);1511__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::d2l_fixup())));1512__ pop(rax);1513__ bind(done);1514__ ret(0);1515#else1516// rax, and rdx are destroyed, but should be free since the result is returned there1517// preserve rsi,ecx1518__ push(rsi);1519__ push(rcx);15201521// check for NaN1522Label return0, do_return, return_min_jlong, do_convert;15231524Address value_high_word(rsp, wordSize + 4);1525Address value_low_word(rsp, wordSize);1526Address result_high_word(rsp, 3*wordSize + 4);1527Address result_low_word(rsp, 3*wordSize);15281529__ subptr(rsp, 32); // more than enough on 32bit1530__ fst_d(value_low_word);1531__ movl(rax, value_high_word);1532__ andl(rax, 0x7ff00000);1533__ cmpl(rax, 0x7ff00000);1534__ jcc(Assembler::notEqual, do_convert);1535__ movl(rax, value_high_word);1536__ andl(rax, 0xfffff);1537__ orl(rax, value_low_word);1538__ jcc(Assembler::notZero, return0);15391540__ bind(do_convert);1541__ fnstcw(Address(rsp, 0));1542__ movzwl(rax, Address(rsp, 0));1543__ orl(rax, 0xc00);1544__ movw(Address(rsp, 2), rax);1545__ fldcw(Address(rsp, 2));1546__ fwait();1547__ fistp_d(result_low_word);1548__ fldcw(Address(rsp, 0));1549__ fwait();1550// This gets the entire long in rax on 64bit1551__ movptr(rax, result_low_word);1552// testing of high bits1553__ movl(rdx, result_high_word);1554__ mov(rcx, rax);1555// What the heck is the point of the next instruction???1556__ xorl(rcx, 0x0);1557__ movl(rsi, 0x80000000);1558__ xorl(rsi, rdx);1559__ orl(rcx, rsi);1560__ jcc(Assembler::notEqual, do_return);1561__ fldz();1562__ fcomp_d(value_low_word);1563__ fnstsw_ax();1564__ sahf();1565__ jcc(Assembler::above, return_min_jlong);1566// return max_jlong1567__ movl(rdx, 0x7fffffff);1568__ movl(rax, 0xffffffff);1569__ jmp(do_return);15701571__ bind(return_min_jlong);1572__ movl(rdx, 0x80000000);1573__ xorl(rax, rax);1574__ jmp(do_return);15751576__ bind(return0);1577__ fpop();1578__ xorptr(rdx,rdx);1579__ xorptr(rax,rax);15801581__ bind(do_return);1582__ addptr(rsp, 32);1583__ pop(rcx);1584__ pop(rsi);1585__ ret(0);1586#endif // _LP641587}1588break;15891590case predicate_failed_trap_id:1591{1592StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments);15931594OopMap* map = save_live_registers(sasm, 1);15951596int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));1597oop_maps = new OopMapSet();1598oop_maps->add_gc_map(call_offset, map);1599restore_live_registers(sasm);1600__ leave();1601DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();1602assert(deopt_blob != NULL, "deoptimization blob must have been created");16031604__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));1605}1606break;16071608default:1609{ StubFrame f(sasm, "unimplemented entry", dont_gc_arguments);1610__ movptr(rax, (int)id);1611__ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);1612__ should_not_reach_here();1613}1614break;1615}1616return oop_maps;1617}16181619#undef __16201621const char *Runtime1::pd_name_for_address(address entry) {1622return "<unknown function>";1623}162416251626