Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp
32285 views
/*1* Copyright (c) 1999, 2018, 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 "interpreter/interpreter.hpp"30#include "nativeInst_x86.hpp"31#include "oops/compiledICHolder.hpp"32#include "oops/oop.inline.hpp"33#include "prims/jvmtiExport.hpp"34#include "register_x86.hpp"35#include "runtime/sharedRuntime.hpp"36#include "runtime/signature.hpp"37#include "runtime/vframeArray.hpp"38#include "utilities/macros.hpp"39#include "vmreg_x86.inline.hpp"40#if INCLUDE_ALL_GCS41#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"42#include "gc_implementation/shenandoah/shenandoahRuntime.hpp"43#endif444546// Implementation of StubAssembler4748int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, int args_size) {49// setup registers50const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread); // is callee-saved register (Visual C++ calling conventions)51assert(!(oop_result1->is_valid() || metadata_result->is_valid()) || oop_result1 != metadata_result, "registers must be different");52assert(oop_result1 != thread && metadata_result != thread, "registers must be different");53assert(args_size >= 0, "illegal args_size");54bool align_stack = false;55#ifdef _LP6456// At a method handle call, the stack may not be properly aligned57// when returning with an exception.58align_stack = (stub_id() == Runtime1::handle_exception_from_callee_id);59#endif6061#ifdef _LP6462mov(c_rarg0, thread);63set_num_rt_args(0); // Nothing on stack64#else65set_num_rt_args(1 + args_size);6667// push java thread (becomes first argument of C function)68get_thread(thread);69push(thread);70#endif // _LP647172int call_offset;73if (!align_stack) {74set_last_Java_frame(thread, noreg, rbp, NULL);75} else {76address the_pc = pc();77call_offset = offset();78set_last_Java_frame(thread, noreg, rbp, the_pc);79andptr(rsp, -(StackAlignmentInBytes)); // Align stack80}8182// do the call83call(RuntimeAddress(entry));84if (!align_stack) {85call_offset = offset();86}87// verify callee-saved register88#ifdef ASSERT89guarantee(thread != rax, "change this code");90push(rax);91{ Label L;92get_thread(rax);93cmpptr(thread, rax);94jcc(Assembler::equal, L);95int3();96stop("StubAssembler::call_RT: rdi not callee saved?");97bind(L);98}99pop(rax);100#endif101reset_last_Java_frame(thread, true);102103// discard thread and arguments104NOT_LP64(addptr(rsp, num_rt_args()*BytesPerWord));105106// check for pending exceptions107{ Label L;108cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);109jcc(Assembler::equal, L);110// exception pending => remove activation and forward to exception handler111movptr(rax, Address(thread, Thread::pending_exception_offset()));112// make sure that the vm_results are cleared113if (oop_result1->is_valid()) {114movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);115}116if (metadata_result->is_valid()) {117movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);118}119if (frame_size() == no_frame_size) {120leave();121jump(RuntimeAddress(StubRoutines::forward_exception_entry()));122} else if (_stub_id == Runtime1::forward_exception_id) {123should_not_reach_here();124} else {125jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));126}127bind(L);128}129// get oop results if there are any and reset the values in the thread130if (oop_result1->is_valid()) {131get_vm_result(oop_result1, thread);132}133if (metadata_result->is_valid()) {134get_vm_result_2(metadata_result, thread);135}136return call_offset;137}138139140int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {141#ifdef _LP64142mov(c_rarg1, arg1);143#else144push(arg1);145#endif // _LP64146return call_RT(oop_result1, metadata_result, entry, 1);147}148149150int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {151#ifdef _LP64152if (c_rarg1 == arg2) {153if (c_rarg2 == arg1) {154xchgq(arg1, arg2);155} else {156mov(c_rarg2, arg2);157mov(c_rarg1, arg1);158}159} else {160mov(c_rarg1, arg1);161mov(c_rarg2, arg2);162}163#else164push(arg2);165push(arg1);166#endif // _LP64167return call_RT(oop_result1, metadata_result, entry, 2);168}169170171int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {172#ifdef _LP64173// if there is any conflict use the stack174if (arg1 == c_rarg2 || arg1 == c_rarg3 ||175arg2 == c_rarg1 || arg2 == c_rarg3 ||176arg3 == c_rarg1 || arg3 == c_rarg2) {177push(arg3);178push(arg2);179push(arg1);180pop(c_rarg1);181pop(c_rarg2);182pop(c_rarg3);183} else {184mov(c_rarg1, arg1);185mov(c_rarg2, arg2);186mov(c_rarg3, arg3);187}188#else189push(arg3);190push(arg2);191push(arg1);192#endif // _LP64193return call_RT(oop_result1, metadata_result, entry, 3);194}195196197// Implementation of StubFrame198199class StubFrame: public StackObj {200private:201StubAssembler* _sasm;202203public:204StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments);205void load_argument(int offset_in_words, Register reg);206207~StubFrame();208};209210211#define __ _sasm->212213StubFrame::StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments) {214_sasm = sasm;215__ set_info(name, must_gc_arguments);216__ enter();217}218219// load parameters that were stored with LIR_Assembler::store_parameter220// Note: offsets for store_parameter and load_argument must match221void StubFrame::load_argument(int offset_in_words, Register reg) {222// rbp, + 0: link223// + 1: return address224// + 2: argument with offset 0225// + 3: argument with offset 1226// + 4: ...227228__ movptr(reg, Address(rbp, (offset_in_words + 2) * BytesPerWord));229}230231232StubFrame::~StubFrame() {233__ leave();234__ ret(0);235}236237#undef __238239240// Implementation of Runtime1241242#define __ sasm->243244const int float_regs_as_doubles_size_in_slots = pd_nof_fpu_regs_frame_map * 2;245const int xmm_regs_as_doubles_size_in_slots = FrameMap::nof_xmm_regs * 2;246247// Stack layout for saving/restoring all the registers needed during a runtime248// call (this includes deoptimization)249// Note: note that users of this frame may well have arguments to some runtime250// while these values are on the stack. These positions neglect those arguments251// but the code in save_live_registers will take the argument count into252// account.253//254#ifdef _LP64255#define SLOT2(x) x,256#define SLOT_PER_WORD 2257#else258#define SLOT2(x)259#define SLOT_PER_WORD 1260#endif // _LP64261262enum reg_save_layout {263// 64bit needs to keep stack 16 byte aligned. So we add some alignment dummies to make that264// happen and will assert if the stack size we create is misaligned265#ifdef _LP64266align_dummy_0, align_dummy_1,267#endif // _LP64268#ifdef _WIN64269// Windows always allocates space for it's argument registers (see270// frame::arg_reg_save_area_bytes).271arg_reg_save_1, arg_reg_save_1H, // 0, 4272arg_reg_save_2, arg_reg_save_2H, // 8, 12273arg_reg_save_3, arg_reg_save_3H, // 16, 20274arg_reg_save_4, arg_reg_save_4H, // 24, 28275#endif // _WIN64276xmm_regs_as_doubles_off, // 32277float_regs_as_doubles_off = xmm_regs_as_doubles_off + xmm_regs_as_doubles_size_in_slots, // 160278fpu_state_off = float_regs_as_doubles_off + float_regs_as_doubles_size_in_slots, // 224279// fpu_state_end_off is exclusive280fpu_state_end_off = fpu_state_off + (FPUStateSizeInWords / SLOT_PER_WORD), // 352281marker = fpu_state_end_off, SLOT2(markerH) // 352, 356282extra_space_offset, // 360283#ifdef _LP64284r15_off = extra_space_offset, r15H_off, // 360, 364285r14_off, r14H_off, // 368, 372286r13_off, r13H_off, // 376, 380287r12_off, r12H_off, // 384, 388288r11_off, r11H_off, // 392, 396289r10_off, r10H_off, // 400, 404290r9_off, r9H_off, // 408, 412291r8_off, r8H_off, // 416, 420292rdi_off, rdiH_off, // 424, 428293#else294rdi_off = extra_space_offset,295#endif // _LP64296rsi_off, SLOT2(rsiH_off) // 432, 436297rbp_off, SLOT2(rbpH_off) // 440, 444298rsp_off, SLOT2(rspH_off) // 448, 452299rbx_off, SLOT2(rbxH_off) // 456, 460300rdx_off, SLOT2(rdxH_off) // 464, 468301rcx_off, SLOT2(rcxH_off) // 472, 476302rax_off, SLOT2(raxH_off) // 480, 484303saved_rbp_off, SLOT2(saved_rbpH_off) // 488, 492304return_off, SLOT2(returnH_off) // 496, 500305reg_save_frame_size // As noted: neglects any parameters to runtime // 504306};307308309310// Save off registers which might be killed by calls into the runtime.311// Tries to smart of about FP registers. In particular we separate312// saving and describing the FPU registers for deoptimization since we313// have to save the FPU registers twice if we describe them and on P4314// saving FPU registers which don't contain anything appears315// expensive. The deopt blob is the only thing which needs to316// describe FPU registers. In all other cases it should be sufficient317// to simply save their current value.318319static OopMap* generate_oop_map(StubAssembler* sasm, int num_rt_args,320bool save_fpu_registers = true) {321322// In 64bit all the args are in regs so there are no additional stack slots323LP64_ONLY(num_rt_args = 0);324LP64_ONLY(assert((reg_save_frame_size * VMRegImpl::stack_slot_size) % 16 == 0, "must be 16 byte aligned");)325int frame_size_in_slots = reg_save_frame_size + num_rt_args; // args + thread326sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word );327328// record saved value locations in an OopMap329// locations are offsets from sp after runtime call; num_rt_args is number of arguments in call, including thread330OopMap* map = new OopMap(frame_size_in_slots, 0);331map->set_callee_saved(VMRegImpl::stack2reg(rax_off + num_rt_args), rax->as_VMReg());332map->set_callee_saved(VMRegImpl::stack2reg(rcx_off + num_rt_args), rcx->as_VMReg());333map->set_callee_saved(VMRegImpl::stack2reg(rdx_off + num_rt_args), rdx->as_VMReg());334map->set_callee_saved(VMRegImpl::stack2reg(rbx_off + num_rt_args), rbx->as_VMReg());335map->set_callee_saved(VMRegImpl::stack2reg(rsi_off + num_rt_args), rsi->as_VMReg());336map->set_callee_saved(VMRegImpl::stack2reg(rdi_off + num_rt_args), rdi->as_VMReg());337#ifdef _LP64338map->set_callee_saved(VMRegImpl::stack2reg(r8_off + num_rt_args), r8->as_VMReg());339map->set_callee_saved(VMRegImpl::stack2reg(r9_off + num_rt_args), r9->as_VMReg());340map->set_callee_saved(VMRegImpl::stack2reg(r10_off + num_rt_args), r10->as_VMReg());341map->set_callee_saved(VMRegImpl::stack2reg(r11_off + num_rt_args), r11->as_VMReg());342map->set_callee_saved(VMRegImpl::stack2reg(r12_off + num_rt_args), r12->as_VMReg());343map->set_callee_saved(VMRegImpl::stack2reg(r13_off + num_rt_args), r13->as_VMReg());344map->set_callee_saved(VMRegImpl::stack2reg(r14_off + num_rt_args), r14->as_VMReg());345map->set_callee_saved(VMRegImpl::stack2reg(r15_off + num_rt_args), r15->as_VMReg());346347// This is stupid but needed.348map->set_callee_saved(VMRegImpl::stack2reg(raxH_off + num_rt_args), rax->as_VMReg()->next());349map->set_callee_saved(VMRegImpl::stack2reg(rcxH_off + num_rt_args), rcx->as_VMReg()->next());350map->set_callee_saved(VMRegImpl::stack2reg(rdxH_off + num_rt_args), rdx->as_VMReg()->next());351map->set_callee_saved(VMRegImpl::stack2reg(rbxH_off + num_rt_args), rbx->as_VMReg()->next());352map->set_callee_saved(VMRegImpl::stack2reg(rsiH_off + num_rt_args), rsi->as_VMReg()->next());353map->set_callee_saved(VMRegImpl::stack2reg(rdiH_off + num_rt_args), rdi->as_VMReg()->next());354355map->set_callee_saved(VMRegImpl::stack2reg(r8H_off + num_rt_args), r8->as_VMReg()->next());356map->set_callee_saved(VMRegImpl::stack2reg(r9H_off + num_rt_args), r9->as_VMReg()->next());357map->set_callee_saved(VMRegImpl::stack2reg(r10H_off + num_rt_args), r10->as_VMReg()->next());358map->set_callee_saved(VMRegImpl::stack2reg(r11H_off + num_rt_args), r11->as_VMReg()->next());359map->set_callee_saved(VMRegImpl::stack2reg(r12H_off + num_rt_args), r12->as_VMReg()->next());360map->set_callee_saved(VMRegImpl::stack2reg(r13H_off + num_rt_args), r13->as_VMReg()->next());361map->set_callee_saved(VMRegImpl::stack2reg(r14H_off + num_rt_args), r14->as_VMReg()->next());362map->set_callee_saved(VMRegImpl::stack2reg(r15H_off + num_rt_args), r15->as_VMReg()->next());363#endif // _LP64364365if (save_fpu_registers) {366if (UseSSE < 2) {367int fpu_off = float_regs_as_doubles_off;368for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {369VMReg fpu_name_0 = FrameMap::fpu_regname(n);370map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + num_rt_args), fpu_name_0);371// %%% This is really a waste but we'll keep things as they were for now372if (true) {373map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + 1 + num_rt_args), fpu_name_0->next());374}375fpu_off += 2;376}377assert(fpu_off == fpu_state_off, "incorrect number of fpu stack slots");378}379380if (UseSSE >= 2) {381int xmm_off = xmm_regs_as_doubles_off;382for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {383VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();384map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);385// %%% This is really a waste but we'll keep things as they were for now386if (true) {387map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + 1 + num_rt_args), xmm_name_0->next());388}389xmm_off += 2;390}391assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");392393} else if (UseSSE == 1) {394int xmm_off = xmm_regs_as_doubles_off;395for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {396VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();397map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);398xmm_off += 2;399}400assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");401}402}403404return map;405}406407static OopMap* save_live_registers(StubAssembler* sasm, int num_rt_args,408bool save_fpu_registers = true) {409__ block_comment("save_live_registers");410411__ pusha(); // integer registers412413// assert(float_regs_as_doubles_off % 2 == 0, "misaligned offset");414// assert(xmm_regs_as_doubles_off % 2 == 0, "misaligned offset");415416__ subptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);417418#ifdef ASSERT419__ movptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);420#endif421422if (save_fpu_registers) {423if (UseSSE < 2) {424// save FPU stack425__ fnsave(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));426__ fwait();427428#ifdef ASSERT429Label ok;430__ cmpw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::fpu_cntrl_wrd_std());431__ jccb(Assembler::equal, ok);432__ stop("corrupted control word detected");433__ bind(ok);434#endif435436// Reset the control word to guard against exceptions being unmasked437// since fstp_d can cause FPU stack underflow exceptions. Write it438// into the on stack copy and then reload that to make sure that the439// current and future values are correct.440__ movw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::fpu_cntrl_wrd_std());441__ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));442443// Save the FPU registers in de-opt-able form444__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));445__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));446__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));447__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));448__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));449__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));450__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));451__ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));452}453454if (UseSSE >= 2) {455// save XMM registers456// XMM registers can contain float or double values, but this is not known here,457// so always save them as doubles.458// note that float values are _not_ converted automatically, so for float values459// the second word contains only garbage data.460__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0), xmm0);461__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8), xmm1);462__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16), xmm2);463__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24), xmm3);464__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32), xmm4);465__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40), xmm5);466__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48), xmm6);467__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56), xmm7);468#ifdef _LP64469__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 64), xmm8);470__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 72), xmm9);471__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 80), xmm10);472__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 88), xmm11);473__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 96), xmm12);474__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 104), xmm13);475__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 112), xmm14);476__ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 120), xmm15);477#endif // _LP64478} else if (UseSSE == 1) {479// save XMM registers as float because double not supported without SSE2480__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0), xmm0);481__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8), xmm1);482__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16), xmm2);483__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24), xmm3);484__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32), xmm4);485__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40), xmm5);486__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48), xmm6);487__ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56), xmm7);488}489}490491// FPU stack must be empty now492__ verify_FPU(0, "save_live_registers");493494return generate_oop_map(sasm, num_rt_args, save_fpu_registers);495}496497498static void restore_fpu(StubAssembler* sasm, bool restore_fpu_registers = true) {499if (restore_fpu_registers) {500if (UseSSE >= 2) {501// restore XMM registers502__ movdbl(xmm0, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));503__ movdbl(xmm1, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));504__ movdbl(xmm2, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));505__ movdbl(xmm3, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));506__ movdbl(xmm4, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));507__ movdbl(xmm5, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));508__ movdbl(xmm6, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));509__ movdbl(xmm7, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));510#ifdef _LP64511__ movdbl(xmm8, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 64));512__ movdbl(xmm9, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 72));513__ movdbl(xmm10, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 80));514__ movdbl(xmm11, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 88));515__ movdbl(xmm12, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 96));516__ movdbl(xmm13, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 104));517__ movdbl(xmm14, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 112));518__ movdbl(xmm15, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 120));519#endif // _LP64520} else if (UseSSE == 1) {521// restore XMM registers522__ movflt(xmm0, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));523__ movflt(xmm1, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));524__ movflt(xmm2, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));525__ movflt(xmm3, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));526__ movflt(xmm4, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));527__ movflt(xmm5, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));528__ movflt(xmm6, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));529__ movflt(xmm7, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));530}531532if (UseSSE < 2) {533__ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));534} else {535// check that FPU stack is really empty536__ verify_FPU(0, "restore_live_registers");537}538539} else {540// check that FPU stack is really empty541__ verify_FPU(0, "restore_live_registers");542}543544#ifdef ASSERT545{546Label ok;547__ cmpptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);548__ jcc(Assembler::equal, ok);549__ stop("bad offsets in frame");550__ bind(ok);551}552#endif // ASSERT553554__ addptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);555}556557558static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {559__ block_comment("restore_live_registers");560561restore_fpu(sasm, restore_fpu_registers);562__ popa();563}564565566static void restore_live_registers_except_rax(StubAssembler* sasm, bool restore_fpu_registers = true) {567__ block_comment("restore_live_registers_except_rax");568569restore_fpu(sasm, restore_fpu_registers);570571#ifdef _LP64572__ movptr(r15, Address(rsp, 0));573__ movptr(r14, Address(rsp, wordSize));574__ movptr(r13, Address(rsp, 2 * wordSize));575__ movptr(r12, Address(rsp, 3 * wordSize));576__ movptr(r11, Address(rsp, 4 * wordSize));577__ movptr(r10, Address(rsp, 5 * wordSize));578__ movptr(r9, Address(rsp, 6 * wordSize));579__ movptr(r8, Address(rsp, 7 * wordSize));580__ movptr(rdi, Address(rsp, 8 * wordSize));581__ movptr(rsi, Address(rsp, 9 * wordSize));582__ movptr(rbp, Address(rsp, 10 * wordSize));583// skip rsp584__ movptr(rbx, Address(rsp, 12 * wordSize));585__ movptr(rdx, Address(rsp, 13 * wordSize));586__ movptr(rcx, Address(rsp, 14 * wordSize));587588__ addptr(rsp, 16 * wordSize);589#else590591__ pop(rdi);592__ pop(rsi);593__ pop(rbp);594__ pop(rbx); // skip this value595__ pop(rbx);596__ pop(rdx);597__ pop(rcx);598__ addptr(rsp, BytesPerWord);599#endif // _LP64600}601602603void Runtime1::initialize_pd() {604// nothing to do605}606607608// target: the entry point of the method that creates and posts the exception oop609// has_argument: true if the exception needs an argument (passed on stack because registers must be preserved)610611OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {612// preserve all registers613int num_rt_args = has_argument ? 2 : 1;614OopMap* oop_map = save_live_registers(sasm, num_rt_args);615616// now all registers are saved and can be used freely617// verify that no old value is used accidentally618__ invalidate_registers(true, true, true, true, true, true);619620// registers used by this stub621const Register temp_reg = rbx;622623// load argument for exception that is passed as an argument into the stub624if (has_argument) {625#ifdef _LP64626__ movptr(c_rarg1, Address(rbp, 2*BytesPerWord));627#else628__ movptr(temp_reg, Address(rbp, 2*BytesPerWord));629__ push(temp_reg);630#endif // _LP64631}632int call_offset = __ call_RT(noreg, noreg, target, num_rt_args - 1);633634OopMapSet* oop_maps = new OopMapSet();635oop_maps->add_gc_map(call_offset, oop_map);636637__ stop("should not reach here");638639return oop_maps;640}641642643OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler *sasm) {644__ block_comment("generate_handle_exception");645646// incoming parameters647const Register exception_oop = rax;648const Register exception_pc = rdx;649// other registers used in this stub650const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);651652// Save registers, if required.653OopMapSet* oop_maps = new OopMapSet();654OopMap* oop_map = NULL;655switch (id) {656case forward_exception_id:657// We're handling an exception in the context of a compiled frame.658// The registers have been saved in the standard places. Perform659// an exception lookup in the caller and dispatch to the handler660// if found. Otherwise unwind and dispatch to the callers661// exception handler.662oop_map = generate_oop_map(sasm, 1 /*thread*/);663664// load and clear pending exception oop into RAX665__ movptr(exception_oop, Address(thread, Thread::pending_exception_offset()));666__ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);667668// load issuing PC (the return address for this stub) into rdx669__ movptr(exception_pc, Address(rbp, 1*BytesPerWord));670671// make sure that the vm_results are cleared (may be unnecessary)672__ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);673__ movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);674break;675case handle_exception_nofpu_id:676case handle_exception_id:677// At this point all registers MAY be live.678oop_map = save_live_registers(sasm, 1 /*thread*/, id != handle_exception_nofpu_id);679break;680case handle_exception_from_callee_id: {681// At this point all registers except exception oop (RAX) and682// exception pc (RDX) are dead.683const int frame_size = 2 /*BP, return address*/ NOT_LP64(+ 1 /*thread*/) WIN64_ONLY(+ frame::arg_reg_save_area_bytes / BytesPerWord);684oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);685sasm->set_frame_size(frame_size);686WIN64_ONLY(__ subq(rsp, frame::arg_reg_save_area_bytes));687break;688}689default: ShouldNotReachHere();690}691692#ifdef TIERED693// C2 can leave the fpu stack dirty694if (UseSSE < 2) {695__ empty_FPU_stack();696}697#endif // TIERED698699// verify that only rax, and rdx is valid at this time700__ invalidate_registers(false, true, true, false, true, true);701// verify that rax, contains a valid exception702__ verify_not_null_oop(exception_oop);703704// load address of JavaThread object for thread-local data705NOT_LP64(__ get_thread(thread);)706707#ifdef ASSERT708// check that fields in JavaThread for exception oop and issuing pc are709// empty before writing to them710Label oop_empty;711__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t) NULL_WORD);712__ jcc(Assembler::equal, oop_empty);713__ stop("exception oop already set");714__ bind(oop_empty);715716Label pc_empty;717__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);718__ jcc(Assembler::equal, pc_empty);719__ stop("exception pc already set");720__ bind(pc_empty);721#endif722723// save exception oop and issuing pc into JavaThread724// (exception handler will load it from here)725__ movptr(Address(thread, JavaThread::exception_oop_offset()), exception_oop);726__ movptr(Address(thread, JavaThread::exception_pc_offset()), exception_pc);727728// patch throwing pc into return address (has bci & oop map)729__ movptr(Address(rbp, 1*BytesPerWord), exception_pc);730731// compute the exception handler.732// the exception oop and the throwing pc are read from the fields in JavaThread733int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));734oop_maps->add_gc_map(call_offset, oop_map);735736// rax: handler address737// will be the deopt blob if nmethod was deoptimized while we looked up738// handler regardless of whether handler existed in the nmethod.739740// only rax, is valid at this time, all other registers have been destroyed by the runtime call741__ invalidate_registers(false, true, true, true, true, true);742743// patch the return address, this stub will directly return to the exception handler744__ movptr(Address(rbp, 1*BytesPerWord), rax);745746switch (id) {747case forward_exception_id:748case handle_exception_nofpu_id:749case handle_exception_id:750// Restore the registers that were saved at the beginning.751restore_live_registers(sasm, id != handle_exception_nofpu_id);752break;753case handle_exception_from_callee_id:754// WIN64_ONLY: No need to add frame::arg_reg_save_area_bytes to SP755// since we do a leave anyway.756757// Pop the return address.758__ leave();759__ pop(rcx);760__ jmp(rcx); // jump to exception handler761break;762default: ShouldNotReachHere();763}764765return oop_maps;766}767768769void Runtime1::generate_unwind_exception(StubAssembler *sasm) {770// incoming parameters771const Register exception_oop = rax;772// callee-saved copy of exception_oop during runtime call773const Register exception_oop_callee_saved = NOT_LP64(rsi) LP64_ONLY(r14);774// other registers used in this stub775const Register exception_pc = rdx;776const Register handler_addr = rbx;777const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);778779// verify that only rax, is valid at this time780__ invalidate_registers(false, true, true, true, true, true);781782#ifdef ASSERT783// check that fields in JavaThread for exception oop and issuing pc are empty784NOT_LP64(__ get_thread(thread);)785Label oop_empty;786__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), 0);787__ jcc(Assembler::equal, oop_empty);788__ stop("exception oop must be empty");789__ bind(oop_empty);790791Label pc_empty;792__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);793__ jcc(Assembler::equal, pc_empty);794__ stop("exception pc must be empty");795__ bind(pc_empty);796#endif797798// clear the FPU stack in case any FPU results are left behind799__ empty_FPU_stack();800801// save exception_oop in callee-saved register to preserve it during runtime calls802__ verify_not_null_oop(exception_oop);803__ movptr(exception_oop_callee_saved, exception_oop);804805NOT_LP64(__ get_thread(thread);)806// Get return address (is on top of stack after leave).807__ movptr(exception_pc, Address(rsp, 0));808809// search the exception handler address of the caller (using the return address)810__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc);811// rax: exception handler address of the caller812813// Only RAX and RSI are valid at this time, all other registers have been destroyed by the call.814__ invalidate_registers(false, true, true, true, false, true);815816// move result of call into correct register817__ movptr(handler_addr, rax);818819// Restore exception oop to RAX (required convention of exception handler).820__ movptr(exception_oop, exception_oop_callee_saved);821822// verify that there is really a valid exception in rax823__ verify_not_null_oop(exception_oop);824825// get throwing pc (= return address).826// rdx has been destroyed by the call, so it must be set again827// the pop is also necessary to simulate the effect of a ret(0)828__ pop(exception_pc);829830// continue at exception handler (return address removed)831// note: do *not* remove arguments when unwinding the832// activation since the caller assumes having833// all arguments on the stack when entering the834// runtime to determine the exception handler835// (GC happens at call site with arguments!)836// rax: exception oop837// rdx: throwing pc838// rbx: exception handler839__ jmp(handler_addr);840}841842843OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {844// use the maximum number of runtime-arguments here because it is difficult to845// distinguish each RT-Call.846// Note: This number affects also the RT-Call in generate_handle_exception because847// the oop-map is shared for all calls.848const int num_rt_args = 2; // thread + dummy849850DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();851assert(deopt_blob != NULL, "deoptimization blob must have been created");852853OopMap* oop_map = save_live_registers(sasm, num_rt_args);854855#ifdef _LP64856const Register thread = r15_thread;857// No need to worry about dummy858__ mov(c_rarg0, thread);859#else860__ push(rax); // push dummy861862const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)863// push java thread (becomes first argument of C function)864__ get_thread(thread);865__ push(thread);866#endif // _LP64867__ set_last_Java_frame(thread, noreg, rbp, NULL);868// do the call869__ call(RuntimeAddress(target));870OopMapSet* oop_maps = new OopMapSet();871oop_maps->add_gc_map(__ offset(), oop_map);872// verify callee-saved register873#ifdef ASSERT874guarantee(thread != rax, "change this code");875__ push(rax);876{ Label L;877__ get_thread(rax);878__ cmpptr(thread, rax);879__ jcc(Assembler::equal, L);880__ stop("StubAssembler::call_RT: rdi/r15 not callee saved?");881__ bind(L);882}883__ pop(rax);884#endif885__ reset_last_Java_frame(thread, true);886#ifndef _LP64887__ pop(rcx); // discard thread arg888__ pop(rcx); // discard dummy889#endif // _LP64890891// check for pending exceptions892{ Label L;893__ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);894__ jcc(Assembler::equal, L);895// exception pending => remove activation and forward to exception handler896897__ testptr(rax, rax); // have we deoptimized?898__ jump_cc(Assembler::equal,899RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));900901// the deopt blob expects exceptions in the special fields of902// JavaThread, so copy and clear pending exception.903904// load and clear pending exception905__ movptr(rax, Address(thread, Thread::pending_exception_offset()));906__ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);907908// check that there is really a valid exception909__ verify_not_null_oop(rax);910911// load throwing pc: this is the return address of the stub912__ movptr(rdx, Address(rsp, return_off * VMRegImpl::stack_slot_size));913914#ifdef ASSERT915// check that fields in JavaThread for exception oop and issuing pc are empty916Label oop_empty;917__ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);918__ jcc(Assembler::equal, oop_empty);919__ stop("exception oop must be empty");920__ bind(oop_empty);921922Label pc_empty;923__ cmpptr(Address(thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);924__ jcc(Assembler::equal, pc_empty);925__ stop("exception pc must be empty");926__ bind(pc_empty);927#endif928929// store exception oop and throwing pc to JavaThread930__ movptr(Address(thread, JavaThread::exception_oop_offset()), rax);931__ movptr(Address(thread, JavaThread::exception_pc_offset()), rdx);932933restore_live_registers(sasm);934935__ leave();936__ addptr(rsp, BytesPerWord); // remove return address from stack937938// Forward the exception directly to deopt blob. We can blow no939// registers and must leave throwing pc on the stack. A patch may940// have values live in registers so the entry point with the941// exception in tls.942__ jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls()));943944__ bind(L);945}946947948// Runtime will return true if the nmethod has been deoptimized during949// the patching process. In that case we must do a deopt reexecute instead.950951Label reexecuteEntry, cont;952953__ testptr(rax, rax); // have we deoptimized?954__ jcc(Assembler::equal, cont); // no955956// Will reexecute. Proper return address is already on the stack we just restore957// registers, pop all of our frame but the return address and jump to the deopt blob958restore_live_registers(sasm);959__ leave();960__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));961962__ bind(cont);963restore_live_registers(sasm);964__ leave();965__ ret(0);966967return oop_maps;968}969970971OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {972973// for better readability974const bool must_gc_arguments = true;975const bool dont_gc_arguments = false;976977// default value; overwritten for some optimized stubs that are called from methods that do not use the fpu978bool save_fpu_registers = true;979980// stub code & info for the different stubs981OopMapSet* oop_maps = NULL;982switch (id) {983case forward_exception_id:984{985oop_maps = generate_handle_exception(id, sasm);986__ leave();987__ ret(0);988}989break;990991case new_instance_id:992case fast_new_instance_id:993case fast_new_instance_init_check_id:994{995Register klass = rdx; // Incoming996Register obj = rax; // Result997998if (id == new_instance_id) {999__ set_info("new_instance", dont_gc_arguments);1000} else if (id == fast_new_instance_id) {1001__ set_info("fast new_instance", dont_gc_arguments);1002} else {1003assert(id == fast_new_instance_init_check_id, "bad StubID");1004__ set_info("fast new_instance init check", dont_gc_arguments);1005}10061007if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&1008UseTLAB && FastTLABRefill) {1009Label slow_path;1010Register obj_size = rcx;1011Register t1 = rbx;1012Register t2 = rsi;1013assert_different_registers(klass, obj, obj_size, t1, t2);10141015__ push(rdi);1016__ push(rbx);10171018if (id == fast_new_instance_init_check_id) {1019// make sure the klass is initialized1020__ cmpb(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);1021__ jcc(Assembler::notEqual, slow_path);1022}10231024#ifdef ASSERT1025// assert object can be fast path allocated1026{1027Label ok, not_ok;1028__ movl(obj_size, Address(klass, Klass::layout_helper_offset()));1029__ cmpl(obj_size, 0); // make sure it's an instance (LH > 0)1030__ jcc(Assembler::lessEqual, not_ok);1031__ testl(obj_size, Klass::_lh_instance_slow_path_bit);1032__ jcc(Assembler::zero, ok);1033__ bind(not_ok);1034__ stop("assert(can be fast path allocated)");1035__ should_not_reach_here();1036__ bind(ok);1037}1038#endif // ASSERT10391040// if we got here then the TLAB allocation failed, so try1041// refilling the TLAB or allocating directly from eden.1042Label retry_tlab, try_eden;1043const Register thread =1044__ tlab_refill(retry_tlab, try_eden, slow_path); // does not destroy rdx (klass), returns rdi10451046__ bind(retry_tlab);10471048// get the instance size (size is postive so movl is fine for 64bit)1049__ movl(obj_size, Address(klass, Klass::layout_helper_offset()));10501051__ tlab_allocate(obj, obj_size, 0, t1, t2, slow_path);10521053__ initialize_object(obj, klass, obj_size, 0, t1, t2);1054__ verify_oop(obj);1055__ pop(rbx);1056__ pop(rdi);1057__ ret(0);10581059__ bind(try_eden);1060// get the instance size (size is postive so movl is fine for 64bit)1061__ movl(obj_size, Address(klass, Klass::layout_helper_offset()));10621063__ eden_allocate(obj, obj_size, 0, t1, slow_path);1064__ incr_allocated_bytes(thread, obj_size, 0);10651066__ initialize_object(obj, klass, obj_size, 0, t1, t2);1067__ verify_oop(obj);1068__ pop(rbx);1069__ pop(rdi);1070__ ret(0);10711072__ bind(slow_path);1073__ pop(rbx);1074__ pop(rdi);1075}10761077__ enter();1078OopMap* map = save_live_registers(sasm, 2);1079int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);1080oop_maps = new OopMapSet();1081oop_maps->add_gc_map(call_offset, map);1082restore_live_registers_except_rax(sasm);1083__ verify_oop(obj);1084__ leave();1085__ ret(0);10861087// rax,: new instance1088}10891090break;10911092case counter_overflow_id:1093{1094Register bci = rax, method = rbx;1095__ enter();1096OopMap* map = save_live_registers(sasm, 3);1097// Retrieve bci1098__ movl(bci, Address(rbp, 2*BytesPerWord));1099// And a pointer to the Method*1100__ movptr(method, Address(rbp, 3*BytesPerWord));1101int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);1102oop_maps = new OopMapSet();1103oop_maps->add_gc_map(call_offset, map);1104restore_live_registers(sasm);1105__ leave();1106__ ret(0);1107}1108break;11091110case new_type_array_id:1111case new_object_array_id:1112{1113Register length = rbx; // Incoming1114Register klass = rdx; // Incoming1115Register obj = rax; // Result11161117if (id == new_type_array_id) {1118__ set_info("new_type_array", dont_gc_arguments);1119} else {1120__ set_info("new_object_array", dont_gc_arguments);1121}11221123#ifdef ASSERT1124// assert object type is really an array of the proper kind1125{1126Label ok;1127Register t0 = obj;1128__ movl(t0, Address(klass, Klass::layout_helper_offset()));1129__ sarl(t0, Klass::_lh_array_tag_shift);1130int tag = ((id == new_type_array_id)1131? Klass::_lh_array_tag_type_value1132: Klass::_lh_array_tag_obj_value);1133__ cmpl(t0, tag);1134__ jcc(Assembler::equal, ok);1135__ stop("assert(is an array klass)");1136__ should_not_reach_here();1137__ bind(ok);1138}1139#endif // ASSERT11401141if (UseTLAB && FastTLABRefill) {1142Register arr_size = rsi;1143Register t1 = rcx; // must be rcx for use as shift count1144Register t2 = rdi;1145Label slow_path;1146assert_different_registers(length, klass, obj, arr_size, t1, t2);11471148// check that array length is small enough for fast path.1149__ cmpl(length, C1_MacroAssembler::max_array_allocation_length);1150__ jcc(Assembler::above, slow_path);11511152// if we got here then the TLAB allocation failed, so try1153// refilling the TLAB or allocating directly from eden.1154Label retry_tlab, try_eden;1155const Register thread =1156__ tlab_refill(retry_tlab, try_eden, slow_path); // preserves rbx & rdx, returns rdi11571158__ bind(retry_tlab);11591160// get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))1161// since size is positive movl does right thing on 64bit1162__ movl(t1, Address(klass, Klass::layout_helper_offset()));1163// since size is postive movl does right thing on 64bit1164__ movl(arr_size, length);1165assert(t1 == rcx, "fixed register usage");1166__ shlptr(arr_size /* by t1=rcx, mod 32 */);1167__ shrptr(t1, Klass::_lh_header_size_shift);1168__ andptr(t1, Klass::_lh_header_size_mask);1169__ addptr(arr_size, t1);1170__ addptr(arr_size, MinObjAlignmentInBytesMask); // align up1171__ andptr(arr_size, ~MinObjAlignmentInBytesMask);11721173__ tlab_allocate(obj, arr_size, 0, t1, t2, slow_path); // preserves arr_size11741175__ initialize_header(obj, klass, length, t1, t2);1176__ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));1177assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");1178assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");1179__ andptr(t1, Klass::_lh_header_size_mask);1180__ subptr(arr_size, t1); // body length1181__ addptr(t1, obj); // body start1182__ initialize_body(t1, arr_size, 0, t2);1183__ verify_oop(obj);1184__ ret(0);11851186__ bind(try_eden);1187// get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))1188// since size is positive movl does right thing on 64bit1189__ movl(t1, Address(klass, Klass::layout_helper_offset()));1190// since size is postive movl does right thing on 64bit1191__ movl(arr_size, length);1192assert(t1 == rcx, "fixed register usage");1193__ shlptr(arr_size /* by t1=rcx, mod 32 */);1194__ shrptr(t1, Klass::_lh_header_size_shift);1195__ andptr(t1, Klass::_lh_header_size_mask);1196__ addptr(arr_size, t1);1197__ addptr(arr_size, MinObjAlignmentInBytesMask); // align up1198__ andptr(arr_size, ~MinObjAlignmentInBytesMask);11991200__ eden_allocate(obj, arr_size, 0, t1, slow_path); // preserves arr_size1201__ incr_allocated_bytes(thread, arr_size, 0);12021203__ initialize_header(obj, klass, length, t1, t2);1204__ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));1205assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");1206assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");1207__ andptr(t1, Klass::_lh_header_size_mask);1208__ subptr(arr_size, t1); // body length1209__ addptr(t1, obj); // body start1210__ initialize_body(t1, arr_size, 0, t2);1211__ verify_oop(obj);1212__ ret(0);12131214__ bind(slow_path);1215}12161217__ enter();1218OopMap* map = save_live_registers(sasm, 3);1219int call_offset;1220if (id == new_type_array_id) {1221call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);1222} else {1223call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);1224}12251226oop_maps = new OopMapSet();1227oop_maps->add_gc_map(call_offset, map);1228restore_live_registers_except_rax(sasm);12291230__ verify_oop(obj);1231__ leave();1232__ ret(0);12331234// rax,: new array1235}1236break;12371238case new_multi_array_id:1239{ StubFrame f(sasm, "new_multi_array", dont_gc_arguments);1240// rax,: klass1241// rbx,: rank1242// rcx: address of 1st dimension1243OopMap* map = save_live_registers(sasm, 4);1244int call_offset = __ call_RT(rax, noreg, CAST_FROM_FN_PTR(address, new_multi_array), rax, rbx, rcx);12451246oop_maps = new OopMapSet();1247oop_maps->add_gc_map(call_offset, map);1248restore_live_registers_except_rax(sasm);12491250// rax,: new multi array1251__ verify_oop(rax);1252}1253break;12541255case register_finalizer_id:1256{1257__ set_info("register_finalizer", dont_gc_arguments);12581259// This is called via call_runtime so the arguments1260// will be place in C abi locations12611262#ifdef _LP641263__ verify_oop(c_rarg0);1264__ mov(rax, c_rarg0);1265#else1266// The object is passed on the stack and we haven't pushed a1267// frame yet so it's one work away from top of stack.1268__ movptr(rax, Address(rsp, 1 * BytesPerWord));1269__ verify_oop(rax);1270#endif // _LP6412711272// load the klass and check the has finalizer flag1273Label register_finalizer;1274Register t = rsi;1275__ load_klass(t, rax);1276__ movl(t, Address(t, Klass::access_flags_offset()));1277__ testl(t, JVM_ACC_HAS_FINALIZER);1278__ jcc(Assembler::notZero, register_finalizer);1279__ ret(0);12801281__ bind(register_finalizer);1282__ enter();1283OopMap* oop_map = save_live_registers(sasm, 2 /*num_rt_args */);1284int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), rax);1285oop_maps = new OopMapSet();1286oop_maps->add_gc_map(call_offset, oop_map);12871288// Now restore all the live registers1289restore_live_registers(sasm);12901291__ leave();1292__ ret(0);1293}1294break;12951296case throw_range_check_failed_id:1297{ StubFrame f(sasm, "range_check_failed", dont_gc_arguments);1298oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);1299}1300break;13011302case throw_index_exception_id:1303{ StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments);1304oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);1305}1306break;13071308case throw_div0_exception_id:1309{ StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments);1310oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);1311}1312break;13131314case throw_null_pointer_exception_id:1315{ StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments);1316oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);1317}1318break;13191320case handle_exception_nofpu_id:1321case handle_exception_id:1322{ StubFrame f(sasm, "handle_exception", dont_gc_arguments);1323oop_maps = generate_handle_exception(id, sasm);1324}1325break;13261327case handle_exception_from_callee_id:1328{ StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);1329oop_maps = generate_handle_exception(id, sasm);1330}1331break;13321333case unwind_exception_id:1334{ __ set_info("unwind_exception", dont_gc_arguments);1335// note: no stubframe since we are about to leave the current1336// activation and we are calling a leaf VM function only.1337generate_unwind_exception(sasm);1338}1339break;13401341case throw_array_store_exception_id:1342{ StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments);1343// tos + 0: link1344// + 1: return address1345oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);1346}1347break;13481349case throw_class_cast_exception_id:1350{ StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments);1351oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);1352}1353break;13541355case throw_incompatible_class_change_error_id:1356{ StubFrame f(sasm, "throw_incompatible_class_cast_exception", dont_gc_arguments);1357oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);1358}1359break;13601361case slow_subtype_check_id:1362{1363// Typical calling sequence:1364// __ push(klass_RInfo); // object klass or other subclass1365// __ push(sup_k_RInfo); // array element klass or other superclass1366// __ call(slow_subtype_check);1367// Note that the subclass is pushed first, and is therefore deepest.1368// Previous versions of this code reversed the names 'sub' and 'super'.1369// This was operationally harmless but made the code unreadable.1370enum layout {1371rax_off, SLOT2(raxH_off)1372rcx_off, SLOT2(rcxH_off)1373rsi_off, SLOT2(rsiH_off)1374rdi_off, SLOT2(rdiH_off)1375// saved_rbp_off, SLOT2(saved_rbpH_off)1376return_off, SLOT2(returnH_off)1377sup_k_off, SLOT2(sup_kH_off)1378klass_off, SLOT2(superH_off)1379framesize,1380result_off = klass_off // deepest argument is also the return value1381};13821383__ set_info("slow_subtype_check", dont_gc_arguments);1384__ push(rdi);1385__ push(rsi);1386__ push(rcx);1387__ push(rax);13881389// This is called by pushing args and not with C abi1390__ movptr(rsi, Address(rsp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass1391__ movptr(rax, Address(rsp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass13921393Label miss;1394__ check_klass_subtype_slow_path(rsi, rax, rcx, rdi, NULL, &miss);13951396// fallthrough on success:1397__ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), 1); // result1398__ pop(rax);1399__ pop(rcx);1400__ pop(rsi);1401__ pop(rdi);1402__ ret(0);14031404__ bind(miss);1405__ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), NULL_WORD); // result1406__ pop(rax);1407__ pop(rcx);1408__ pop(rsi);1409__ pop(rdi);1410__ ret(0);1411}1412break;14131414case monitorenter_nofpu_id:1415save_fpu_registers = false;1416// fall through1417case monitorenter_id:1418{1419StubFrame f(sasm, "monitorenter", dont_gc_arguments);1420OopMap* map = save_live_registers(sasm, 3, save_fpu_registers);14211422// Called with store_parameter and not C abi14231424f.load_argument(1, rax); // rax,: object1425f.load_argument(0, rbx); // rbx,: lock address14261427int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), rax, rbx);14281429oop_maps = new OopMapSet();1430oop_maps->add_gc_map(call_offset, map);1431restore_live_registers(sasm, save_fpu_registers);1432}1433break;14341435case monitorexit_nofpu_id:1436save_fpu_registers = false;1437// fall through1438case monitorexit_id:1439{1440StubFrame f(sasm, "monitorexit", dont_gc_arguments);1441OopMap* map = save_live_registers(sasm, 2, save_fpu_registers);14421443// Called with store_parameter and not C abi14441445f.load_argument(0, rax); // rax,: lock address14461447// note: really a leaf routine but must setup last java sp1448// => use call_RT for now (speed can be improved by1449// doing last java sp setup manually)1450int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), rax);14511452oop_maps = new OopMapSet();1453oop_maps->add_gc_map(call_offset, map);1454restore_live_registers(sasm, save_fpu_registers);1455}1456break;14571458case deoptimize_id:1459{1460StubFrame f(sasm, "deoptimize", dont_gc_arguments);1461const int num_rt_args = 1; // thread1462OopMap* oop_map = save_live_registers(sasm, num_rt_args);1463int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize));1464oop_maps = new OopMapSet();1465oop_maps->add_gc_map(call_offset, oop_map);1466restore_live_registers(sasm);1467DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();1468assert(deopt_blob != NULL, "deoptimization blob must have been created");1469__ leave();1470__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));1471}1472break;14731474case access_field_patching_id:1475{ StubFrame f(sasm, "access_field_patching", dont_gc_arguments);1476// we should set up register map1477oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));1478}1479break;14801481case load_klass_patching_id:1482{ StubFrame f(sasm, "load_klass_patching", dont_gc_arguments);1483// we should set up register map1484oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));1485}1486break;14871488case load_mirror_patching_id:1489{ StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments);1490// we should set up register map1491oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));1492}1493break;14941495case load_appendix_patching_id:1496{ StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments);1497// we should set up register map1498oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));1499}1500break;15011502case dtrace_object_alloc_id:1503{ // rax,: object1504StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);1505// we can't gc here so skip the oopmap but make sure that all1506// the live registers get saved.1507save_live_registers(sasm, 1);15081509__ NOT_LP64(push(rax)) LP64_ONLY(mov(c_rarg0, rax));1510__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));1511NOT_LP64(__ pop(rax));15121513restore_live_registers(sasm);1514}1515break;15161517case fpu2long_stub_id:1518{1519// rax, and rdx are destroyed, but should be free since the result is returned there1520// preserve rsi,ecx1521__ push(rsi);1522__ push(rcx);1523LP64_ONLY(__ push(rdx);)15241525// check for NaN1526Label return0, do_return, return_min_jlong, do_convert;15271528Address value_high_word(rsp, wordSize + 4);1529Address value_low_word(rsp, wordSize);1530Address result_high_word(rsp, 3*wordSize + 4);1531Address result_low_word(rsp, 3*wordSize);15321533__ subptr(rsp, 32); // more than enough on 32bit1534__ fst_d(value_low_word);1535__ movl(rax, value_high_word);1536__ andl(rax, 0x7ff00000);1537__ cmpl(rax, 0x7ff00000);1538__ jcc(Assembler::notEqual, do_convert);1539__ movl(rax, value_high_word);1540__ andl(rax, 0xfffff);1541__ orl(rax, value_low_word);1542__ jcc(Assembler::notZero, return0);15431544__ bind(do_convert);1545__ fnstcw(Address(rsp, 0));1546__ movzwl(rax, Address(rsp, 0));1547__ orl(rax, 0xc00);1548__ movw(Address(rsp, 2), rax);1549__ fldcw(Address(rsp, 2));1550__ fwait();1551__ fistp_d(result_low_word);1552__ fldcw(Address(rsp, 0));1553__ fwait();1554// This gets the entire long in rax on 64bit1555__ movptr(rax, result_low_word);1556// testing of high bits1557__ movl(rdx, result_high_word);1558__ mov(rcx, rax);1559// What the heck is the point of the next instruction???1560__ xorl(rcx, 0x0);1561__ movl(rsi, 0x80000000);1562__ xorl(rsi, rdx);1563__ orl(rcx, rsi);1564__ jcc(Assembler::notEqual, do_return);1565__ fldz();1566__ fcomp_d(value_low_word);1567__ fnstsw_ax();1568#ifdef _LP641569__ testl(rax, 0x4100); // ZF & CF == 01570__ jcc(Assembler::equal, return_min_jlong);1571#else1572__ sahf();1573__ jcc(Assembler::above, return_min_jlong);1574#endif // _LP641575// return max_jlong1576#ifndef _LP641577__ movl(rdx, 0x7fffffff);1578__ movl(rax, 0xffffffff);1579#else1580__ mov64(rax, CONST64(0x7fffffffffffffff));1581#endif // _LP641582__ jmp(do_return);15831584__ bind(return_min_jlong);1585#ifndef _LP641586__ movl(rdx, 0x80000000);1587__ xorl(rax, rax);1588#else1589__ mov64(rax, CONST64(0x8000000000000000));1590#endif // _LP641591__ jmp(do_return);15921593__ bind(return0);1594__ fpop();1595#ifndef _LP641596__ xorptr(rdx,rdx);1597__ xorptr(rax,rax);1598#else1599__ xorptr(rax, rax);1600#endif // _LP6416011602__ bind(do_return);1603__ addptr(rsp, 32);1604LP64_ONLY(__ pop(rdx);)1605__ pop(rcx);1606__ pop(rsi);1607__ ret(0);1608}1609break;16101611#if INCLUDE_ALL_GCS1612case g1_pre_barrier_slow_id:1613{1614StubFrame f(sasm, "g1_pre_barrier", dont_gc_arguments);1615// arg0 : previous value of memory16161617BarrierSet* bs = Universe::heap()->barrier_set();1618if (bs->kind() != BarrierSet::G1SATBCTLogging && bs->kind() != BarrierSet::ShenandoahBarrierSet) {1619__ movptr(rax, (int)id);1620__ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);1621__ should_not_reach_here();1622break;1623}1624__ push(rax);1625__ push(rdx);16261627const Register pre_val = rax;1628const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);1629const Register tmp = rdx;16301631NOT_LP64(__ get_thread(thread);)16321633Address in_progress(thread, in_bytes(JavaThread::satb_mark_queue_offset() +1634PtrQueue::byte_offset_of_active()));16351636Address queue_index(thread, in_bytes(JavaThread::satb_mark_queue_offset() +1637PtrQueue::byte_offset_of_index()));1638Address buffer(thread, in_bytes(JavaThread::satb_mark_queue_offset() +1639PtrQueue::byte_offset_of_buf()));164016411642Label done;1643Label runtime;16441645// Can we store original value in the thread's buffer?16461647#ifdef _LP641648__ movslq(tmp, queue_index);1649__ cmpq(tmp, 0);1650#else1651__ cmpl(queue_index, 0);1652#endif1653__ jcc(Assembler::equal, runtime);1654#ifdef _LP641655__ subq(tmp, wordSize);1656__ movl(queue_index, tmp);1657__ addq(tmp, buffer);1658#else1659__ subl(queue_index, wordSize);1660__ movl(tmp, buffer);1661__ addl(tmp, queue_index);1662#endif16631664// prev_val (rax)1665f.load_argument(0, pre_val);1666__ movptr(Address(tmp, 0), pre_val);1667__ jmp(done);16681669__ bind(runtime);16701671save_live_registers(sasm, 3);16721673// load the pre-value1674f.load_argument(0, rcx);1675__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), rcx, thread);16761677restore_live_registers(sasm);16781679__ bind(done);16801681__ pop(rdx);1682__ pop(rax);1683}1684break;16851686case g1_post_barrier_slow_id:1687{1688StubFrame f(sasm, "g1_post_barrier", dont_gc_arguments);168916901691// arg0: store_address1692Address store_addr(rbp, 2*BytesPerWord);16931694BarrierSet* bs = Universe::heap()->barrier_set();1695if (bs->kind() == BarrierSet::ShenandoahBarrierSet) {1696__ movptr(rax, (int)id);1697__ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);1698__ should_not_reach_here();1699break;1700}1701CardTableModRefBS* ct = (CardTableModRefBS*)bs;1702assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");17031704Label done;1705Label runtime;17061707// At this point we know new_value is non-NULL and the new_value crosses regions.1708// Must check to see if card is already dirty17091710const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);17111712Address queue_index(thread, in_bytes(JavaThread::dirty_card_queue_offset() +1713PtrQueue::byte_offset_of_index()));1714Address buffer(thread, in_bytes(JavaThread::dirty_card_queue_offset() +1715PtrQueue::byte_offset_of_buf()));17161717__ push(rax);1718__ push(rcx);17191720const Register cardtable = rax;1721const Register card_addr = rcx;17221723f.load_argument(0, card_addr);1724__ shrptr(card_addr, CardTableModRefBS::card_shift);1725// Do not use ExternalAddress to load 'byte_map_base', since 'byte_map_base' is NOT1726// a valid address and therefore is not properly handled by the relocation code.1727__ movptr(cardtable, (intptr_t)ct->byte_map_base);1728__ addptr(card_addr, cardtable);17291730NOT_LP64(__ get_thread(thread);)17311732__ cmpb(Address(card_addr, 0), (int)G1SATBCardTableModRefBS::g1_young_card_val());1733__ jcc(Assembler::equal, done);17341735__ membar(Assembler::Membar_mask_bits(Assembler::StoreLoad));1736__ cmpb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());1737__ jcc(Assembler::equal, done);17381739// storing region crossing non-NULL, card is clean.1740// dirty card and log.17411742__ movb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());17431744__ cmpl(queue_index, 0);1745__ jcc(Assembler::equal, runtime);1746__ subl(queue_index, wordSize);17471748const Register buffer_addr = rbx;1749__ push(rbx);17501751__ movptr(buffer_addr, buffer);17521753#ifdef _LP641754__ movslq(rscratch1, queue_index);1755__ addptr(buffer_addr, rscratch1);1756#else1757__ addptr(buffer_addr, queue_index);1758#endif1759__ movptr(Address(buffer_addr, 0), card_addr);17601761__ pop(rbx);1762__ jmp(done);17631764__ bind(runtime);1765__ push(rdx);17661767save_live_registers(sasm, 3);17681769__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread);17701771restore_live_registers(sasm);17721773__ pop(rdx);1774__ bind(done);17751776__ pop(rcx);1777__ pop(rax);17781779}1780break;1781case shenandoah_lrb_slow_id:1782{1783StubFrame f(sasm, "shenandoah_load_reference_barrier", dont_gc_arguments);1784// arg0 : object to be resolved17851786save_live_registers(sasm, 1);1787#ifdef _LP641788f.load_argument(0, c_rarg0);1789f.load_argument(1, c_rarg1);1790if (UseCompressedOops) {1791__ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_narrow), c_rarg0, c_rarg1);1792} else {1793__ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier), c_rarg0, c_rarg1);1794}1795#else1796f.load_argument(0, rax);1797f.load_argument(1, rbx);1798__ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier), rax, rbx);1799#endif1800restore_live_registers_except_rax(sasm, true);18011802}1803break;1804#endif // INCLUDE_ALL_GCS18051806case predicate_failed_trap_id:1807{1808StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments);18091810OopMap* map = save_live_registers(sasm, 1);18111812int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));1813oop_maps = new OopMapSet();1814oop_maps->add_gc_map(call_offset, map);1815restore_live_registers(sasm);1816__ leave();1817DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();1818assert(deopt_blob != NULL, "deoptimization blob must have been created");18191820__ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));1821}1822break;18231824default:1825{ StubFrame f(sasm, "unimplemented entry", dont_gc_arguments);1826__ movptr(rax, (int)id);1827__ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);1828__ should_not_reach_here();1829}1830break;1831}1832return oop_maps;1833}18341835#undef __18361837const char *Runtime1::pd_name_for_address(address entry) {1838return "<unknown function>";1839}184018411842