goetz@6458: /* dbuck@8997: * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. goetz@6512: * Copyright 2012, 2014 SAP AG. All rights reserved. goetz@6458: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. goetz@6458: * goetz@6458: * This code is free software; you can redistribute it and/or modify it goetz@6458: * under the terms of the GNU General Public License version 2 only, as goetz@6458: * published by the Free Software Foundation. goetz@6458: * goetz@6458: * This code is distributed in the hope that it will be useful, but WITHOUT goetz@6458: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or goetz@6458: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License goetz@6458: * version 2 for more details (a copy is included in the LICENSE file that goetz@6458: * accompanied this code). goetz@6458: * goetz@6458: * You should have received a copy of the GNU General Public License version goetz@6458: * 2 along with this work; if not, write to the Free Software Foundation, goetz@6458: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. goetz@6458: * goetz@6458: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA goetz@6458: * or visit www.oracle.com if you need additional information or have any goetz@6458: * questions. goetz@6458: * goetz@6458: */ goetz@6458: goetz@6458: #include "precompiled.hpp" goetz@6458: #include "asm/macroAssembler.inline.hpp" goetz@6458: #include "code/debugInfoRec.hpp" goetz@6458: #include "code/icBuffer.hpp" goetz@6458: #include "code/vtableStubs.hpp" goetz@6458: #include "interpreter/interpreter.hpp" goetz@6458: #include "oops/compiledICHolder.hpp" goetz@6458: #include "prims/jvmtiRedefineClassesTrace.hpp" goetz@6458: #include "runtime/sharedRuntime.hpp" goetz@6458: #include "runtime/vframeArray.hpp" goetz@6458: #include "vmreg_ppc.inline.hpp" goetz@6517: #include "adfiles/ad_ppc_64.hpp" goetz@6458: #ifdef COMPILER1 goetz@6458: #include "c1/c1_Runtime1.hpp" goetz@6458: #endif goetz@6458: #ifdef COMPILER2 goetz@6458: #include "opto/runtime.hpp" goetz@6458: #endif goetz@6458: goetz@6458: #define __ masm-> goetz@6458: goetz@6458: #ifdef PRODUCT goetz@6458: #define BLOCK_COMMENT(str) // nothing goetz@6458: #else goetz@6458: #define BLOCK_COMMENT(str) __ block_comment(str) goetz@6458: #endif goetz@6458: goetz@6458: #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") goetz@6458: goetz@6458: goetz@6458: class RegisterSaver { goetz@6458: // Used for saving volatile registers. goetz@6458: public: goetz@6458: goetz@6458: // Support different return pc locations. goetz@6458: enum ReturnPCLocation { goetz@6458: return_pc_is_lr, goetz@6458: return_pc_is_r4, goetz@6458: return_pc_is_thread_saved_exception_pc goetz@6458: }; goetz@6458: goetz@6511: static OopMap* push_frame_reg_args_and_save_live_registers(MacroAssembler* masm, goetz@6458: int* out_frame_size_in_bytes, goetz@6458: bool generate_oop_map, goetz@6458: int return_pc_adjustment, goetz@6458: ReturnPCLocation return_pc_location); goetz@6458: static void restore_live_registers_and_pop_frame(MacroAssembler* masm, goetz@6458: int frame_size_in_bytes, goetz@6458: bool restore_ctr); goetz@6458: goetz@6458: static void push_frame_and_save_argument_registers(MacroAssembler* masm, goetz@6458: Register r_temp, goetz@6458: int frame_size, goetz@6458: int total_args, goetz@6458: const VMRegPair *regs, const VMRegPair *regs2 = NULL); goetz@6458: static void restore_argument_registers_and_pop_frame(MacroAssembler*masm, goetz@6458: int frame_size, goetz@6458: int total_args, goetz@6458: const VMRegPair *regs, const VMRegPair *regs2 = NULL); goetz@6458: goetz@6458: // During deoptimization only the result registers need to be restored goetz@6458: // all the other values have already been extracted. goetz@6458: static void restore_result_registers(MacroAssembler* masm, int frame_size_in_bytes); goetz@6458: goetz@6458: // Constants and data structures: goetz@6458: goetz@6458: typedef enum { goetz@6458: int_reg = 0, goetz@6458: float_reg = 1, goetz@6458: special_reg = 2 goetz@6458: } RegisterType; goetz@6458: goetz@6458: typedef enum { goetz@6458: reg_size = 8, goetz@6458: half_reg_size = reg_size / 2, goetz@6458: } RegisterConstants; goetz@6458: goetz@6458: typedef struct { goetz@6458: RegisterType reg_type; goetz@6458: int reg_num; goetz@6458: VMReg vmreg; goetz@6458: } LiveRegType; goetz@6458: }; goetz@6458: goetz@6458: goetz@6458: #define RegisterSaver_LiveSpecialReg(regname) \ goetz@6458: { RegisterSaver::special_reg, regname->encoding(), regname->as_VMReg() } goetz@6458: goetz@6458: #define RegisterSaver_LiveIntReg(regname) \ goetz@6458: { RegisterSaver::int_reg, regname->encoding(), regname->as_VMReg() } goetz@6458: goetz@6458: #define RegisterSaver_LiveFloatReg(regname) \ goetz@6458: { RegisterSaver::float_reg, regname->encoding(), regname->as_VMReg() } goetz@6458: goetz@6458: static const RegisterSaver::LiveRegType RegisterSaver_LiveRegs[] = { goetz@6458: // Live registers which get spilled to the stack. Register goetz@6458: // positions in this array correspond directly to the stack layout. goetz@6458: goetz@6458: // goetz@6458: // live special registers: goetz@6458: // goetz@6458: RegisterSaver_LiveSpecialReg(SR_CTR), goetz@6458: // goetz@6458: // live float registers: goetz@6458: // goetz@6458: RegisterSaver_LiveFloatReg( F0 ), goetz@6458: RegisterSaver_LiveFloatReg( F1 ), goetz@6458: RegisterSaver_LiveFloatReg( F2 ), goetz@6458: RegisterSaver_LiveFloatReg( F3 ), goetz@6458: RegisterSaver_LiveFloatReg( F4 ), goetz@6458: RegisterSaver_LiveFloatReg( F5 ), goetz@6458: RegisterSaver_LiveFloatReg( F6 ), goetz@6458: RegisterSaver_LiveFloatReg( F7 ), goetz@6458: RegisterSaver_LiveFloatReg( F8 ), goetz@6458: RegisterSaver_LiveFloatReg( F9 ), goetz@6458: RegisterSaver_LiveFloatReg( F10 ), goetz@6458: RegisterSaver_LiveFloatReg( F11 ), goetz@6458: RegisterSaver_LiveFloatReg( F12 ), goetz@6458: RegisterSaver_LiveFloatReg( F13 ), goetz@6458: RegisterSaver_LiveFloatReg( F14 ), goetz@6458: RegisterSaver_LiveFloatReg( F15 ), goetz@6458: RegisterSaver_LiveFloatReg( F16 ), goetz@6458: RegisterSaver_LiveFloatReg( F17 ), goetz@6458: RegisterSaver_LiveFloatReg( F18 ), goetz@6458: RegisterSaver_LiveFloatReg( F19 ), goetz@6458: RegisterSaver_LiveFloatReg( F20 ), goetz@6458: RegisterSaver_LiveFloatReg( F21 ), goetz@6458: RegisterSaver_LiveFloatReg( F22 ), goetz@6458: RegisterSaver_LiveFloatReg( F23 ), goetz@6458: RegisterSaver_LiveFloatReg( F24 ), goetz@6458: RegisterSaver_LiveFloatReg( F25 ), goetz@6458: RegisterSaver_LiveFloatReg( F26 ), goetz@6458: RegisterSaver_LiveFloatReg( F27 ), goetz@6458: RegisterSaver_LiveFloatReg( F28 ), goetz@6458: RegisterSaver_LiveFloatReg( F29 ), goetz@6458: RegisterSaver_LiveFloatReg( F30 ), goetz@6458: RegisterSaver_LiveFloatReg( F31 ), goetz@6458: // goetz@6458: // live integer registers: goetz@6458: // goetz@6458: RegisterSaver_LiveIntReg( R0 ), goetz@6458: //RegisterSaver_LiveIntReg( R1 ), // stack pointer goetz@6458: RegisterSaver_LiveIntReg( R2 ), goetz@6458: RegisterSaver_LiveIntReg( R3 ), goetz@6458: RegisterSaver_LiveIntReg( R4 ), goetz@6458: RegisterSaver_LiveIntReg( R5 ), goetz@6458: RegisterSaver_LiveIntReg( R6 ), goetz@6458: RegisterSaver_LiveIntReg( R7 ), goetz@6458: RegisterSaver_LiveIntReg( R8 ), goetz@6458: RegisterSaver_LiveIntReg( R9 ), goetz@6458: RegisterSaver_LiveIntReg( R10 ), goetz@6458: RegisterSaver_LiveIntReg( R11 ), goetz@6458: RegisterSaver_LiveIntReg( R12 ), goetz@6458: //RegisterSaver_LiveIntReg( R13 ), // system thread id goetz@6458: RegisterSaver_LiveIntReg( R14 ), goetz@6458: RegisterSaver_LiveIntReg( R15 ), goetz@6458: RegisterSaver_LiveIntReg( R16 ), goetz@6458: RegisterSaver_LiveIntReg( R17 ), goetz@6458: RegisterSaver_LiveIntReg( R18 ), goetz@6458: RegisterSaver_LiveIntReg( R19 ), goetz@6458: RegisterSaver_LiveIntReg( R20 ), goetz@6458: RegisterSaver_LiveIntReg( R21 ), goetz@6458: RegisterSaver_LiveIntReg( R22 ), goetz@6458: RegisterSaver_LiveIntReg( R23 ), goetz@6458: RegisterSaver_LiveIntReg( R24 ), goetz@6458: RegisterSaver_LiveIntReg( R25 ), goetz@6458: RegisterSaver_LiveIntReg( R26 ), goetz@6458: RegisterSaver_LiveIntReg( R27 ), goetz@6458: RegisterSaver_LiveIntReg( R28 ), goetz@6458: RegisterSaver_LiveIntReg( R29 ), goetz@6458: RegisterSaver_LiveIntReg( R31 ), goetz@6458: RegisterSaver_LiveIntReg( R30 ), // r30 must be the last register goetz@6458: }; goetz@6458: goetz@6511: OopMap* RegisterSaver::push_frame_reg_args_and_save_live_registers(MacroAssembler* masm, goetz@6458: int* out_frame_size_in_bytes, goetz@6458: bool generate_oop_map, goetz@6458: int return_pc_adjustment, goetz@6458: ReturnPCLocation return_pc_location) { goetz@6511: // Push an abi_reg_args-frame and store all registers which may be live. goetz@6458: // If requested, create an OopMap: Record volatile registers as goetz@6458: // callee-save values in an OopMap so their save locations will be goetz@6458: // propagated to the RegisterMap of the caller frame during goetz@6458: // StackFrameStream construction (needed for deoptimization; see goetz@6458: // compiledVFrame::create_stack_value). goetz@6458: // If return_pc_adjustment != 0 adjust the return pc by return_pc_adjustment. goetz@6458: goetz@6458: int i; goetz@6458: int offset; goetz@6458: goetz@6458: // calcualte frame size goetz@6458: const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / goetz@6458: sizeof(RegisterSaver::LiveRegType); goetz@6458: const int register_save_size = regstosave_num * reg_size; goetz@6458: const int frame_size_in_bytes = round_to(register_save_size, frame::alignment_in_bytes) goetz@6511: + frame::abi_reg_args_size; goetz@6458: *out_frame_size_in_bytes = frame_size_in_bytes; goetz@6458: const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); goetz@6458: const int register_save_offset = frame_size_in_bytes - register_save_size; goetz@6458: goetz@6458: // OopMap frame size is in c2 stack slots (sizeof(jint)) not bytes or words. goetz@6458: OopMap* map = generate_oop_map ? new OopMap(frame_size_in_slots, 0) : NULL; goetz@6458: goetz@6511: BLOCK_COMMENT("push_frame_reg_args_and_save_live_registers {"); goetz@6458: goetz@6458: // Save r30 in the last slot of the not yet pushed frame so that we goetz@6458: // can use it as scratch reg. goetz@6458: __ std(R30, -reg_size, R1_SP); goetz@6458: assert(-reg_size == register_save_offset - frame_size_in_bytes + ((regstosave_num-1)*reg_size), goetz@6458: "consistency check"); goetz@6458: goetz@6458: // save the flags goetz@6458: // Do the save_LR_CR by hand and adjust the return pc if requested. goetz@6458: __ mfcr(R30); goetz@6458: __ std(R30, _abi(cr), R1_SP); goetz@6458: switch (return_pc_location) { goetz@6458: case return_pc_is_lr: __ mflr(R30); break; goetz@6458: case return_pc_is_r4: __ mr(R30, R4); break; goetz@6458: case return_pc_is_thread_saved_exception_pc: goetz@6458: __ ld(R30, thread_(saved_exception_pc)); break; goetz@6458: default: ShouldNotReachHere(); goetz@6458: } goetz@6458: if (return_pc_adjustment != 0) goetz@6458: __ addi(R30, R30, return_pc_adjustment); goetz@6458: __ std(R30, _abi(lr), R1_SP); goetz@6458: goetz@6458: // push a new frame goetz@6458: __ push_frame(frame_size_in_bytes, R30); goetz@6458: goetz@6458: // save all registers (ints and floats) goetz@6458: offset = register_save_offset; goetz@6458: for (int i = 0; i < regstosave_num; i++) { goetz@6458: int reg_num = RegisterSaver_LiveRegs[i].reg_num; goetz@6458: int reg_type = RegisterSaver_LiveRegs[i].reg_type; goetz@6458: goetz@6458: switch (reg_type) { goetz@6458: case RegisterSaver::int_reg: { goetz@6458: if (reg_num != 30) { // We spilled R30 right at the beginning. goetz@6458: __ std(as_Register(reg_num), offset, R1_SP); goetz@6458: } goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::float_reg: { goetz@6458: __ stfd(as_FloatRegister(reg_num), offset, R1_SP); goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::special_reg: { goetz@6458: if (reg_num == SR_CTR_SpecialRegisterEnumValue) { goetz@6458: __ mfctr(R30); goetz@6458: __ std(R30, offset, R1_SP); goetz@6458: } else { goetz@6458: Unimplemented(); goetz@6458: } goetz@6458: break; goetz@6458: } goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: } goetz@6458: goetz@6458: if (generate_oop_map) { goetz@6458: map->set_callee_saved(VMRegImpl::stack2reg(offset>>2), goetz@6458: RegisterSaver_LiveRegs[i].vmreg); goetz@6458: map->set_callee_saved(VMRegImpl::stack2reg((offset + half_reg_size)>>2), goetz@6458: RegisterSaver_LiveRegs[i].vmreg->next()); goetz@6458: } goetz@6458: offset += reg_size; goetz@6458: } goetz@6458: goetz@6511: BLOCK_COMMENT("} push_frame_reg_args_and_save_live_registers"); goetz@6458: goetz@6458: // And we're done. goetz@6458: return map; goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Pop the current frame and restore all the registers that we goetz@6458: // saved. goetz@6458: void RegisterSaver::restore_live_registers_and_pop_frame(MacroAssembler* masm, goetz@6458: int frame_size_in_bytes, goetz@6458: bool restore_ctr) { goetz@6458: int i; goetz@6458: int offset; goetz@6458: const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / goetz@6458: sizeof(RegisterSaver::LiveRegType); goetz@6458: const int register_save_size = regstosave_num * reg_size; goetz@6458: const int register_save_offset = frame_size_in_bytes - register_save_size; goetz@6458: goetz@6458: BLOCK_COMMENT("restore_live_registers_and_pop_frame {"); goetz@6458: goetz@6458: // restore all registers (ints and floats) goetz@6458: offset = register_save_offset; goetz@6458: for (int i = 0; i < regstosave_num; i++) { goetz@6458: int reg_num = RegisterSaver_LiveRegs[i].reg_num; goetz@6458: int reg_type = RegisterSaver_LiveRegs[i].reg_type; goetz@6458: goetz@6458: switch (reg_type) { goetz@6458: case RegisterSaver::int_reg: { goetz@6458: if (reg_num != 30) // R30 restored at the end, it's the tmp reg! goetz@6458: __ ld(as_Register(reg_num), offset, R1_SP); goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::float_reg: { goetz@6458: __ lfd(as_FloatRegister(reg_num), offset, R1_SP); goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::special_reg: { goetz@6458: if (reg_num == SR_CTR_SpecialRegisterEnumValue) { goetz@6458: if (restore_ctr) { // Nothing to do here if ctr already contains the next address. goetz@6458: __ ld(R30, offset, R1_SP); goetz@6458: __ mtctr(R30); goetz@6458: } goetz@6458: } else { goetz@6458: Unimplemented(); goetz@6458: } goetz@6458: break; goetz@6458: } goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: } goetz@6458: offset += reg_size; goetz@6458: } goetz@6458: goetz@6458: // pop the frame goetz@6458: __ pop_frame(); goetz@6458: goetz@6458: // restore the flags goetz@6458: __ restore_LR_CR(R30); goetz@6458: goetz@6458: // restore scratch register's value goetz@6458: __ ld(R30, -reg_size, R1_SP); goetz@6458: goetz@6458: BLOCK_COMMENT("} restore_live_registers_and_pop_frame"); goetz@6458: } goetz@6458: goetz@6458: void RegisterSaver::push_frame_and_save_argument_registers(MacroAssembler* masm, Register r_temp, goetz@6458: int frame_size,int total_args, const VMRegPair *regs, goetz@6458: const VMRegPair *regs2) { goetz@6458: __ push_frame(frame_size, r_temp); goetz@6458: int st_off = frame_size - wordSize; goetz@6458: for (int i = 0; i < total_args; i++) { goetz@6458: VMReg r_1 = regs[i].first(); goetz@6458: VMReg r_2 = regs[i].second(); goetz@6458: if (!r_1->is_valid()) { goetz@6458: assert(!r_2->is_valid(), ""); goetz@6458: continue; goetz@6458: } goetz@6458: if (r_1->is_Register()) { goetz@6458: Register r = r_1->as_Register(); goetz@6458: __ std(r, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } else if (r_1->is_FloatRegister()) { goetz@6458: FloatRegister f = r_1->as_FloatRegister(); goetz@6458: __ stfd(f, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } goetz@6458: } goetz@6458: if (regs2 != NULL) { goetz@6458: for (int i = 0; i < total_args; i++) { goetz@6458: VMReg r_1 = regs2[i].first(); goetz@6458: VMReg r_2 = regs2[i].second(); goetz@6458: if (!r_1->is_valid()) { goetz@6458: assert(!r_2->is_valid(), ""); goetz@6458: continue; goetz@6458: } goetz@6458: if (r_1->is_Register()) { goetz@6458: Register r = r_1->as_Register(); goetz@6458: __ std(r, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } else if (r_1->is_FloatRegister()) { goetz@6458: FloatRegister f = r_1->as_FloatRegister(); goetz@6458: __ stfd(f, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: void RegisterSaver::restore_argument_registers_and_pop_frame(MacroAssembler*masm, int frame_size, goetz@6458: int total_args, const VMRegPair *regs, goetz@6458: const VMRegPair *regs2) { goetz@6458: int st_off = frame_size - wordSize; goetz@6458: for (int i = 0; i < total_args; i++) { goetz@6458: VMReg r_1 = regs[i].first(); goetz@6458: VMReg r_2 = regs[i].second(); goetz@6458: if (r_1->is_Register()) { goetz@6458: Register r = r_1->as_Register(); goetz@6458: __ ld(r, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } else if (r_1->is_FloatRegister()) { goetz@6458: FloatRegister f = r_1->as_FloatRegister(); goetz@6458: __ lfd(f, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } goetz@6458: } goetz@6458: if (regs2 != NULL) goetz@6458: for (int i = 0; i < total_args; i++) { goetz@6458: VMReg r_1 = regs2[i].first(); goetz@6458: VMReg r_2 = regs2[i].second(); goetz@6458: if (r_1->is_Register()) { goetz@6458: Register r = r_1->as_Register(); goetz@6458: __ ld(r, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } else if (r_1->is_FloatRegister()) { goetz@6458: FloatRegister f = r_1->as_FloatRegister(); goetz@6458: __ lfd(f, st_off, R1_SP); goetz@6458: st_off -= wordSize; goetz@6458: } goetz@6458: } goetz@6458: __ pop_frame(); goetz@6458: } goetz@6458: goetz@6458: // Restore the registers that might be holding a result. goetz@6458: void RegisterSaver::restore_result_registers(MacroAssembler* masm, int frame_size_in_bytes) { goetz@6458: int i; goetz@6458: int offset; goetz@6458: const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / goetz@6458: sizeof(RegisterSaver::LiveRegType); goetz@6458: const int register_save_size = regstosave_num * reg_size; goetz@6458: const int register_save_offset = frame_size_in_bytes - register_save_size; goetz@6458: goetz@6458: // restore all result registers (ints and floats) goetz@6458: offset = register_save_offset; goetz@6458: for (int i = 0; i < regstosave_num; i++) { goetz@6458: int reg_num = RegisterSaver_LiveRegs[i].reg_num; goetz@6458: int reg_type = RegisterSaver_LiveRegs[i].reg_type; goetz@6458: switch (reg_type) { goetz@6458: case RegisterSaver::int_reg: { goetz@6458: if (as_Register(reg_num)==R3_RET) // int result_reg goetz@6458: __ ld(as_Register(reg_num), offset, R1_SP); goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::float_reg: { goetz@6458: if (as_FloatRegister(reg_num)==F1_RET) // float result_reg goetz@6458: __ lfd(as_FloatRegister(reg_num), offset, R1_SP); goetz@6458: break; goetz@6458: } goetz@6458: case RegisterSaver::special_reg: { goetz@6458: // Special registers don't hold a result. goetz@6458: break; goetz@6458: } goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: } goetz@6458: offset += reg_size; goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Is vector's size (in bytes) bigger than a size saved by default? goetz@6458: bool SharedRuntime::is_wide_vector(int size) { goetz@6458: ResourceMark rm; goetz@6458: // Note, MaxVectorSize == 8 on PPC64. goetz@6458: assert(size <= 8, err_msg_res("%d bytes vectors are not supported", size)); goetz@6458: return size > 8; goetz@6458: } goetz@6458: #ifdef COMPILER2 goetz@6458: static int reg2slot(VMReg r) { goetz@6458: return r->reg2stack() + SharedRuntime::out_preserve_stack_slots(); goetz@6458: } goetz@6458: goetz@6458: static int reg2offset(VMReg r) { goetz@6458: return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size; goetz@6458: } goetz@6458: #endif goetz@6458: goetz@6458: // --------------------------------------------------------------------------- goetz@6458: // Read the array of BasicTypes from a signature, and compute where the goetz@6458: // arguments should go. Values in the VMRegPair regs array refer to 4-byte goetz@6458: // quantities. Values less than VMRegImpl::stack0 are registers, those above goetz@6458: // refer to 4-byte stack slots. All stack slots are based off of the stack pointer goetz@6458: // as framesizes are fixed. goetz@6458: // VMRegImpl::stack0 refers to the first slot 0(sp). goetz@6458: // and VMRegImpl::stack0+1 refers to the memory word 4-bytes higher. Register goetz@6458: // up to RegisterImpl::number_of_registers) are the 64-bit goetz@6458: // integer registers. goetz@6458: goetz@6458: // Note: the INPUTS in sig_bt are in units of Java argument words, which are goetz@6458: // either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit goetz@6458: // units regardless of build. Of course for i486 there is no 64 bit build goetz@6458: goetz@6458: // The Java calling convention is a "shifted" version of the C ABI. goetz@6458: // By skipping the first C ABI register we can call non-static jni methods goetz@6458: // with small numbers of arguments without having to shuffle the arguments goetz@6458: // at all. Since we control the java ABI we ought to at least get some goetz@6458: // advantage out of it. goetz@6458: goetz@6458: const VMReg java_iarg_reg[8] = { goetz@6458: R3->as_VMReg(), goetz@6458: R4->as_VMReg(), goetz@6458: R5->as_VMReg(), goetz@6458: R6->as_VMReg(), goetz@6458: R7->as_VMReg(), goetz@6458: R8->as_VMReg(), goetz@6458: R9->as_VMReg(), goetz@6458: R10->as_VMReg() goetz@6458: }; goetz@6458: goetz@6458: const VMReg java_farg_reg[13] = { goetz@6458: F1->as_VMReg(), goetz@6458: F2->as_VMReg(), goetz@6458: F3->as_VMReg(), goetz@6458: F4->as_VMReg(), goetz@6458: F5->as_VMReg(), goetz@6458: F6->as_VMReg(), goetz@6458: F7->as_VMReg(), goetz@6458: F8->as_VMReg(), goetz@6458: F9->as_VMReg(), goetz@6458: F10->as_VMReg(), goetz@6458: F11->as_VMReg(), goetz@6458: F12->as_VMReg(), goetz@6458: F13->as_VMReg() goetz@6458: }; goetz@6458: goetz@6458: const int num_java_iarg_registers = sizeof(java_iarg_reg) / sizeof(java_iarg_reg[0]); goetz@6458: const int num_java_farg_registers = sizeof(java_farg_reg) / sizeof(java_farg_reg[0]); goetz@6458: goetz@6458: int SharedRuntime::java_calling_convention(const BasicType *sig_bt, goetz@6458: VMRegPair *regs, goetz@6458: int total_args_passed, goetz@6458: int is_outgoing) { goetz@6458: // C2c calling conventions for compiled-compiled calls. goetz@6458: // Put 8 ints/longs into registers _AND_ 13 float/doubles into goetz@6458: // registers _AND_ put the rest on the stack. goetz@6458: goetz@6458: const int inc_stk_for_intfloat = 1; // 1 slots for ints and floats goetz@6458: const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles goetz@6458: goetz@6458: int i; goetz@6458: VMReg reg; goetz@6458: int stk = 0; goetz@6458: int ireg = 0; goetz@6458: int freg = 0; goetz@6458: goetz@6458: // We put the first 8 arguments into registers and the rest on the goetz@6458: // stack, float arguments are already in their argument registers goetz@6458: // due to c2c calling conventions (see calling_convention). goetz@6458: for (int i = 0; i < total_args_passed; ++i) { goetz@6458: switch(sig_bt[i]) { goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: goetz@6458: if (ireg < num_java_iarg_registers) { goetz@6458: // Put int/ptr in register goetz@6458: reg = java_iarg_reg[ireg]; goetz@6458: ++ireg; goetz@6458: } else { goetz@6458: // Put int/ptr on stack. goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_intfloat; goetz@6458: } goetz@6458: regs[i].set1(reg); goetz@6458: break; goetz@6458: case T_LONG: goetz@6458: assert(sig_bt[i+1] == T_VOID, "expecting half"); goetz@6458: if (ireg < num_java_iarg_registers) { goetz@6458: // Put long in register. goetz@6458: reg = java_iarg_reg[ireg]; goetz@6458: ++ireg; goetz@6458: } else { goetz@6458: // Put long on stack. They must be aligned to 2 slots. goetz@6458: if (stk & 0x1) ++stk; goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_longdouble; goetz@6458: } goetz@6458: regs[i].set2(reg); goetz@6458: break; goetz@6458: case T_OBJECT: goetz@6458: case T_ARRAY: goetz@6458: case T_ADDRESS: goetz@6458: if (ireg < num_java_iarg_registers) { goetz@6458: // Put ptr in register. goetz@6458: reg = java_iarg_reg[ireg]; goetz@6458: ++ireg; goetz@6458: } else { goetz@6458: // Put ptr on stack. Objects must be aligned to 2 slots too, goetz@6458: // because "64-bit pointers record oop-ishness on 2 aligned goetz@6458: // adjacent registers." (see OopFlow::build_oop_map). goetz@6458: if (stk & 0x1) ++stk; goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_longdouble; goetz@6458: } goetz@6458: regs[i].set2(reg); goetz@6458: break; goetz@6458: case T_FLOAT: goetz@6458: if (freg < num_java_farg_registers) { goetz@6458: // Put float in register. goetz@6458: reg = java_farg_reg[freg]; goetz@6458: ++freg; goetz@6458: } else { goetz@6458: // Put float on stack. goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_intfloat; goetz@6458: } goetz@6458: regs[i].set1(reg); goetz@6458: break; goetz@6458: case T_DOUBLE: goetz@6458: assert(sig_bt[i+1] == T_VOID, "expecting half"); goetz@6458: if (freg < num_java_farg_registers) { goetz@6458: // Put double in register. goetz@6458: reg = java_farg_reg[freg]; goetz@6458: ++freg; goetz@6458: } else { goetz@6458: // Put double on stack. They must be aligned to 2 slots. goetz@6458: if (stk & 0x1) ++stk; goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_longdouble; goetz@6458: } goetz@6458: regs[i].set2(reg); goetz@6458: break; goetz@6458: case T_VOID: goetz@6458: // Do not count halves. goetz@6458: regs[i].set_bad(); goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: } goetz@6458: } goetz@6458: return round_to(stk, 2); goetz@6458: } goetz@6458: goetz@6458: #ifdef COMPILER2 goetz@6458: // Calling convention for calling C code. goetz@6458: int SharedRuntime::c_calling_convention(const BasicType *sig_bt, goetz@6458: VMRegPair *regs, goetz@6458: VMRegPair *regs2, goetz@6458: int total_args_passed) { goetz@6458: // Calling conventions for C runtime calls and calls to JNI native methods. goetz@6458: // goetz@6458: // PPC64 convention: Hoist the first 8 int/ptr/long's in the first 8 goetz@6458: // int regs, leaving int regs undefined if the arg is flt/dbl. Hoist goetz@6458: // the first 13 flt/dbl's in the first 13 fp regs but additionally goetz@6458: // copy flt/dbl to the stack if they are beyond the 8th argument. goetz@6458: goetz@6458: const VMReg iarg_reg[8] = { goetz@6458: R3->as_VMReg(), goetz@6458: R4->as_VMReg(), goetz@6458: R5->as_VMReg(), goetz@6458: R6->as_VMReg(), goetz@6458: R7->as_VMReg(), goetz@6458: R8->as_VMReg(), goetz@6458: R9->as_VMReg(), goetz@6458: R10->as_VMReg() goetz@6458: }; goetz@6458: goetz@6458: const VMReg farg_reg[13] = { goetz@6458: F1->as_VMReg(), goetz@6458: F2->as_VMReg(), goetz@6458: F3->as_VMReg(), goetz@6458: F4->as_VMReg(), goetz@6458: F5->as_VMReg(), goetz@6458: F6->as_VMReg(), goetz@6458: F7->as_VMReg(), goetz@6458: F8->as_VMReg(), goetz@6458: F9->as_VMReg(), goetz@6458: F10->as_VMReg(), goetz@6458: F11->as_VMReg(), goetz@6458: F12->as_VMReg(), goetz@6458: F13->as_VMReg() goetz@6458: }; goetz@6458: goetz@6458: // Check calling conventions consistency. goetz@6495: assert(sizeof(iarg_reg) / sizeof(iarg_reg[0]) == Argument::n_int_register_parameters_c && goetz@6495: sizeof(farg_reg) / sizeof(farg_reg[0]) == Argument::n_float_register_parameters_c, goetz@6458: "consistency"); goetz@6458: goetz@6458: // `Stk' counts stack slots. Due to alignment, 32 bit values occupy goetz@6458: // 2 such slots, like 64 bit values do. goetz@6458: const int inc_stk_for_intfloat = 2; // 2 slots for ints and floats goetz@6458: const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles goetz@6458: goetz@6458: int i; goetz@6458: VMReg reg; goetz@6511: // Leave room for C-compatible ABI_REG_ARGS. goetz@6511: int stk = (frame::abi_reg_args_size - frame::jit_out_preserve_size) / VMRegImpl::stack_slot_size; goetz@6458: int arg = 0; goetz@6458: int freg = 0; goetz@6458: goetz@6458: // Avoid passing C arguments in the wrong stack slots. goetz@6511: #if defined(ABI_ELFv2) goetz@6511: assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 96, goetz@6511: "passing C arguments in wrong stack slots"); goetz@6511: #else goetz@6458: assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 112, goetz@6458: "passing C arguments in wrong stack slots"); goetz@6511: #endif goetz@6458: // We fill-out regs AND regs2 if an argument must be passed in a goetz@6458: // register AND in a stack slot. If regs2 is NULL in such a goetz@6458: // situation, we bail-out with a fatal error. goetz@6458: for (int i = 0; i < total_args_passed; ++i, ++arg) { goetz@6458: // Initialize regs2 to BAD. goetz@6458: if (regs2 != NULL) regs2[i].set_bad(); goetz@6458: goetz@6458: switch(sig_bt[i]) { goetz@6495: goetz@6495: // goetz@6495: // If arguments 0-7 are integers, they are passed in integer registers. goetz@6495: // Argument i is placed in iarg_reg[i]. goetz@6495: // goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: goetz@6458: // We must cast ints to longs and use full 64 bit stack slots goetz@6458: // here. We do the cast in GraphKit::gen_stub() and just guard goetz@6458: // here against loosing that change. goetz@6468: assert(CCallingConventionRequiresIntsAsLongs, goetz@6458: "argument of type int should be promoted to type long"); goetz@6458: guarantee(i > 0 && sig_bt[i-1] == T_LONG, goetz@6458: "argument of type (bt) should have been promoted to type (T_LONG,bt) for bt in " goetz@6458: "{T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); goetz@6458: // Do not count halves. goetz@6458: regs[i].set_bad(); goetz@6458: --arg; goetz@6458: break; goetz@6458: case T_LONG: goetz@6458: guarantee(sig_bt[i+1] == T_VOID || goetz@6458: sig_bt[i+1] == T_BOOLEAN || sig_bt[i+1] == T_CHAR || goetz@6458: sig_bt[i+1] == T_BYTE || sig_bt[i+1] == T_SHORT || goetz@6458: sig_bt[i+1] == T_INT, goetz@6458: "expecting type (T_LONG,half) or type (T_LONG,bt) with bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); goetz@6458: case T_OBJECT: goetz@6458: case T_ARRAY: goetz@6458: case T_ADDRESS: goetz@6458: case T_METADATA: goetz@6458: // Oops are already boxed if required (JNI). goetz@6495: if (arg < Argument::n_int_register_parameters_c) { goetz@6458: reg = iarg_reg[arg]; goetz@6458: } else { goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_longdouble; goetz@6458: } goetz@6458: regs[i].set2(reg); goetz@6458: break; goetz@6495: goetz@6495: // goetz@6495: // Floats are treated differently from int regs: The first 13 float arguments goetz@6495: // are passed in registers (not the float args among the first 13 args). goetz@6495: // Thus argument i is NOT passed in farg_reg[i] if it is float. It is passed goetz@6495: // in farg_reg[j] if argument i is the j-th float argument of this call. goetz@6495: // goetz@6458: case T_FLOAT: goetz@8182: #if defined(LINUX) goetz@8182: // Linux uses ELF ABI. Both original ELF and ELFv2 ABIs have float goetz@8182: // in the least significant word of an argument slot. goetz@8182: #if defined(VM_LITTLE_ENDIAN) goetz@8182: #define FLOAT_WORD_OFFSET_IN_SLOT 0 goetz@8182: #else goetz@8182: #define FLOAT_WORD_OFFSET_IN_SLOT 1 goetz@8182: #endif goetz@8182: #elif defined(AIX) goetz@8182: // Although AIX runs on big endian CPU, float is in the most goetz@8182: // significant word of an argument slot. goetz@8182: #define FLOAT_WORD_OFFSET_IN_SLOT 0 goetz@8182: #else goetz@8182: #error "unknown OS" goetz@8182: #endif goetz@6495: if (freg < Argument::n_float_register_parameters_c) { goetz@6495: // Put float in register ... goetz@6458: reg = farg_reg[freg]; goetz@6495: ++freg; goetz@6495: goetz@6495: // Argument i for i > 8 is placed on the stack even if it's goetz@6495: // placed in a register (if it's a float arg). Aix disassembly goetz@6495: // shows that xlC places these float args on the stack AND in goetz@6495: // a register. This is not documented, but we follow this goetz@6495: // convention, too. goetz@6495: if (arg >= Argument::n_regs_not_on_stack_c) { goetz@6495: // ... and on the stack. goetz@6495: guarantee(regs2 != NULL, "must pass float in register and stack slot"); goetz@8182: VMReg reg2 = VMRegImpl::stack2reg(stk + FLOAT_WORD_OFFSET_IN_SLOT); goetz@6495: regs2[i].set1(reg2); goetz@6495: stk += inc_stk_for_intfloat; goetz@6495: } goetz@6495: goetz@6458: } else { goetz@6495: // Put float on stack. goetz@8182: reg = VMRegImpl::stack2reg(stk + FLOAT_WORD_OFFSET_IN_SLOT); goetz@6458: stk += inc_stk_for_intfloat; goetz@6458: } goetz@6458: regs[i].set1(reg); goetz@6458: break; goetz@6458: case T_DOUBLE: goetz@6458: assert(sig_bt[i+1] == T_VOID, "expecting half"); goetz@6495: if (freg < Argument::n_float_register_parameters_c) { goetz@6495: // Put double in register ... goetz@6458: reg = farg_reg[freg]; goetz@6495: ++freg; goetz@6495: goetz@6495: // Argument i for i > 8 is placed on the stack even if it's goetz@6495: // placed in a register (if it's a double arg). Aix disassembly goetz@6495: // shows that xlC places these float args on the stack AND in goetz@6495: // a register. This is not documented, but we follow this goetz@6495: // convention, too. goetz@6495: if (arg >= Argument::n_regs_not_on_stack_c) { goetz@6495: // ... and on the stack. goetz@6495: guarantee(regs2 != NULL, "must pass float in register and stack slot"); goetz@6495: VMReg reg2 = VMRegImpl::stack2reg(stk); goetz@6495: regs2[i].set2(reg2); goetz@6495: stk += inc_stk_for_longdouble; goetz@6495: } goetz@6458: } else { goetz@6458: // Put double on stack. goetz@6458: reg = VMRegImpl::stack2reg(stk); goetz@6458: stk += inc_stk_for_longdouble; goetz@6458: } goetz@6458: regs[i].set2(reg); goetz@6458: break; goetz@6495: goetz@6458: case T_VOID: goetz@6458: // Do not count halves. goetz@6458: regs[i].set_bad(); goetz@6458: --arg; goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: return round_to(stk, 2); goetz@6458: } goetz@6458: #endif // COMPILER2 goetz@6458: goetz@6458: static address gen_c2i_adapter(MacroAssembler *masm, goetz@6458: int total_args_passed, goetz@6458: int comp_args_on_stack, goetz@6458: const BasicType *sig_bt, goetz@6458: const VMRegPair *regs, goetz@6458: Label& call_interpreter, goetz@6458: const Register& ientry) { goetz@6458: goetz@6458: address c2i_entrypoint; goetz@6458: goetz@6458: const Register sender_SP = R21_sender_SP; // == R21_tmp1 goetz@6458: const Register code = R22_tmp2; goetz@6458: //const Register ientry = R23_tmp3; goetz@6458: const Register value_regs[] = { R24_tmp4, R25_tmp5, R26_tmp6 }; goetz@6458: const int num_value_regs = sizeof(value_regs) / sizeof(Register); goetz@6458: int value_regs_index = 0; goetz@6458: goetz@6458: const Register return_pc = R27_tmp7; goetz@6458: const Register tmp = R28_tmp8; goetz@6458: goetz@6458: assert_different_registers(sender_SP, code, ientry, return_pc, tmp); goetz@6458: goetz@6458: // Adapter needs TOP_IJAVA_FRAME_ABI. goetz@6458: const int adapter_size = frame::top_ijava_frame_abi_size + goetz@6458: round_to(total_args_passed * wordSize, frame::alignment_in_bytes); goetz@6458: goetz@6458: // regular (verified) c2i entry point goetz@6458: c2i_entrypoint = __ pc(); goetz@6458: goetz@6458: // Does compiled code exists? If yes, patch the caller's callsite. goetz@6458: __ ld(code, method_(code)); goetz@6458: __ cmpdi(CCR0, code, 0); goetz@6458: __ ld(ientry, method_(interpreter_entry)); // preloaded goetz@6458: __ beq(CCR0, call_interpreter); goetz@6458: goetz@6458: goetz@6458: // Patch caller's callsite, method_(code) was not NULL which means that goetz@6458: // compiled code exists. goetz@6458: __ mflr(return_pc); goetz@6458: __ std(return_pc, _abi(lr), R1_SP); goetz@6458: RegisterSaver::push_frame_and_save_argument_registers(masm, tmp, adapter_size, total_args_passed, regs); goetz@6458: goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite), R19_method, return_pc); goetz@6458: goetz@6458: RegisterSaver::restore_argument_registers_and_pop_frame(masm, adapter_size, total_args_passed, regs); goetz@6458: __ ld(return_pc, _abi(lr), R1_SP); goetz@6458: __ ld(ientry, method_(interpreter_entry)); // preloaded goetz@6458: __ mtlr(return_pc); goetz@6458: goetz@6458: goetz@6495: // Call the interpreter. goetz@6458: __ BIND(call_interpreter); goetz@6458: __ mtctr(ientry); goetz@6458: goetz@6458: // Get a copy of the current SP for loading caller's arguments. goetz@6458: __ mr(sender_SP, R1_SP); goetz@6458: goetz@6458: // Add space for the adapter. goetz@6458: __ resize_frame(-adapter_size, R12_scratch2); goetz@6458: goetz@6458: int st_off = adapter_size - wordSize; goetz@6458: goetz@6458: // Write the args into the outgoing interpreter space. goetz@6458: for (int i = 0; i < total_args_passed; i++) { goetz@6458: VMReg r_1 = regs[i].first(); goetz@6458: VMReg r_2 = regs[i].second(); goetz@6458: if (!r_1->is_valid()) { goetz@6458: assert(!r_2->is_valid(), ""); goetz@6458: continue; goetz@6458: } goetz@6458: if (r_1->is_stack()) { goetz@6458: Register tmp_reg = value_regs[value_regs_index]; goetz@6458: value_regs_index = (value_regs_index + 1) % num_value_regs; goetz@6458: // The calling convention produces OptoRegs that ignore the out goetz@6458: // preserve area (JIT's ABI). We must account for it here. goetz@6458: int ld_off = (r_1->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size; goetz@6458: if (!r_2->is_valid()) { goetz@6458: __ lwz(tmp_reg, ld_off, sender_SP); goetz@6458: } else { goetz@6458: __ ld(tmp_reg, ld_off, sender_SP); goetz@6458: } goetz@6458: // Pretend stack targets were loaded into tmp_reg. goetz@6458: r_1 = tmp_reg->as_VMReg(); goetz@6458: } goetz@6458: goetz@6458: if (r_1->is_Register()) { goetz@6458: Register r = r_1->as_Register(); goetz@6458: if (!r_2->is_valid()) { goetz@6458: __ stw(r, st_off, R1_SP); goetz@6458: st_off-=wordSize; goetz@6458: } else { goetz@6458: // Longs are given 2 64-bit slots in the interpreter, but the goetz@6458: // data is passed in only 1 slot. goetz@6458: if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { goetz@6458: DEBUG_ONLY( __ li(tmp, 0); __ std(tmp, st_off, R1_SP); ) goetz@6458: st_off-=wordSize; goetz@6458: } goetz@6458: __ std(r, st_off, R1_SP); goetz@6458: st_off-=wordSize; goetz@6458: } goetz@6458: } else { goetz@6458: assert(r_1->is_FloatRegister(), ""); goetz@6458: FloatRegister f = r_1->as_FloatRegister(); goetz@6458: if (!r_2->is_valid()) { goetz@6458: __ stfs(f, st_off, R1_SP); goetz@6458: st_off-=wordSize; goetz@6458: } else { goetz@6458: // In 64bit, doubles are given 2 64-bit slots in the interpreter, but the goetz@6458: // data is passed in only 1 slot. goetz@6458: // One of these should get known junk... goetz@6458: DEBUG_ONLY( __ li(tmp, 0); __ std(tmp, st_off, R1_SP); ) goetz@6458: st_off-=wordSize; goetz@6458: __ stfd(f, st_off, R1_SP); goetz@6458: st_off-=wordSize; goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Jump to the interpreter just as if interpreter was doing it. goetz@6458: goetz@6495: #ifdef CC_INTERP goetz@6495: const Register tos = R17_tos; goetz@6512: #else goetz@6512: const Register tos = R15_esp; goetz@6512: __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1); goetz@6495: #endif goetz@6495: goetz@6458: // load TOS goetz@6495: __ addi(tos, R1_SP, st_off); goetz@6458: goetz@6458: // Frame_manager expects initial_caller_sp (= SP without resize by c2i) in R21_tmp1. goetz@6458: assert(sender_SP == R21_sender_SP, "passing initial caller's SP in wrong register"); goetz@6458: __ bctr(); goetz@6458: goetz@6458: return c2i_entrypoint; goetz@6458: } goetz@6458: goetz@6458: static void gen_i2c_adapter(MacroAssembler *masm, goetz@6458: int total_args_passed, goetz@6458: int comp_args_on_stack, goetz@6458: const BasicType *sig_bt, goetz@6458: const VMRegPair *regs) { goetz@6458: goetz@6512: // Load method's entry-point from method. goetz@6458: __ ld(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method); goetz@6458: __ mtctr(R12_scratch2); goetz@6458: goetz@6458: // We will only enter here from an interpreted frame and never from after goetz@6458: // passing thru a c2i. Azul allowed this but we do not. If we lose the goetz@6458: // race and use a c2i we will remain interpreted for the race loser(s). goetz@6458: // This removes all sorts of headaches on the x86 side and also eliminates goetz@6458: // the possibility of having c2i -> i2c -> c2i -> ... endless transitions. goetz@6458: goetz@6458: // Note: r13 contains the senderSP on entry. We must preserve it since goetz@6458: // we may do a i2c -> c2i transition if we lose a race where compiled goetz@6458: // code goes non-entrant while we get args ready. goetz@6458: // In addition we use r13 to locate all the interpreter args as goetz@6458: // we must align the stack to 16 bytes on an i2c entry else we goetz@6458: // lose alignment we expect in all compiled code and register goetz@6458: // save code can segv when fxsave instructions find improperly goetz@6458: // aligned stack pointer. goetz@6458: goetz@6495: #ifdef CC_INTERP goetz@6458: const Register ld_ptr = R17_tos; goetz@6512: #else goetz@6512: const Register ld_ptr = R15_esp; goetz@6495: #endif goetz@6512: goetz@6458: const Register value_regs[] = { R22_tmp2, R23_tmp3, R24_tmp4, R25_tmp5, R26_tmp6 }; goetz@6458: const int num_value_regs = sizeof(value_regs) / sizeof(Register); goetz@6458: int value_regs_index = 0; goetz@6458: goetz@6458: int ld_offset = total_args_passed*wordSize; goetz@6458: goetz@6458: // Cut-out for having no stack args. Since up to 2 int/oop args are passed goetz@6458: // in registers, we will occasionally have no stack args. goetz@6458: int comp_words_on_stack = 0; goetz@6458: if (comp_args_on_stack) { goetz@6458: // Sig words on the stack are greater-than VMRegImpl::stack0. Those in goetz@6458: // registers are below. By subtracting stack0, we either get a negative goetz@6458: // number (all values in registers) or the maximum stack slot accessed. goetz@6458: goetz@6458: // Convert 4-byte c2 stack slots to words. goetz@6458: comp_words_on_stack = round_to(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord; goetz@6458: // Round up to miminum stack alignment, in wordSize. goetz@6458: comp_words_on_stack = round_to(comp_words_on_stack, 2); goetz@6458: __ resize_frame(-comp_words_on_stack * wordSize, R11_scratch1); goetz@6458: } goetz@6458: goetz@6458: // Now generate the shuffle code. Pick up all register args and move the goetz@6458: // rest through register value=Z_R12. goetz@6458: BLOCK_COMMENT("Shuffle arguments"); goetz@6458: for (int i = 0; i < total_args_passed; i++) { goetz@6458: if (sig_bt[i] == T_VOID) { goetz@6458: assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half"); goetz@6458: continue; goetz@6458: } goetz@6458: goetz@6458: // Pick up 0, 1 or 2 words from ld_ptr. goetz@6458: assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(), goetz@6458: "scrambled load targets?"); goetz@6458: VMReg r_1 = regs[i].first(); goetz@6458: VMReg r_2 = regs[i].second(); goetz@6458: if (!r_1->is_valid()) { goetz@6458: assert(!r_2->is_valid(), ""); goetz@6458: continue; goetz@6458: } goetz@6458: if (r_1->is_FloatRegister()) { goetz@6458: if (!r_2->is_valid()) { goetz@6458: __ lfs(r_1->as_FloatRegister(), ld_offset, ld_ptr); goetz@6458: ld_offset-=wordSize; goetz@6458: } else { goetz@6458: // Skip the unused interpreter slot. goetz@6458: __ lfd(r_1->as_FloatRegister(), ld_offset-wordSize, ld_ptr); goetz@6458: ld_offset-=2*wordSize; goetz@6458: } goetz@6458: } else { goetz@6458: Register r; goetz@6458: if (r_1->is_stack()) { goetz@6458: // Must do a memory to memory move thru "value". goetz@6458: r = value_regs[value_regs_index]; goetz@6458: value_regs_index = (value_regs_index + 1) % num_value_regs; goetz@6458: } else { goetz@6458: r = r_1->as_Register(); goetz@6458: } goetz@6458: if (!r_2->is_valid()) { goetz@6458: // Not sure we need to do this but it shouldn't hurt. goetz@6458: if (sig_bt[i] == T_OBJECT || sig_bt[i] == T_ADDRESS || sig_bt[i] == T_ARRAY) { goetz@6458: __ ld(r, ld_offset, ld_ptr); goetz@6458: ld_offset-=wordSize; goetz@6458: } else { goetz@6458: __ lwz(r, ld_offset, ld_ptr); goetz@6458: ld_offset-=wordSize; goetz@6458: } goetz@6458: } else { goetz@6458: // In 64bit, longs are given 2 64-bit slots in the interpreter, but the goetz@6458: // data is passed in only 1 slot. goetz@6458: if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { goetz@6458: ld_offset-=wordSize; goetz@6458: } goetz@6458: __ ld(r, ld_offset, ld_ptr); goetz@6458: ld_offset-=wordSize; goetz@6458: } goetz@6458: goetz@6458: if (r_1->is_stack()) { goetz@6458: // Now store value where the compiler expects it goetz@6458: int st_off = (r_1->reg2stack() + SharedRuntime::out_preserve_stack_slots())*VMRegImpl::stack_slot_size; goetz@6458: goetz@6458: if (sig_bt[i] == T_INT || sig_bt[i] == T_FLOAT ||sig_bt[i] == T_BOOLEAN || goetz@6458: sig_bt[i] == T_SHORT || sig_bt[i] == T_CHAR || sig_bt[i] == T_BYTE) { goetz@6458: __ stw(r, st_off, R1_SP); goetz@6458: } else { goetz@6458: __ std(r, st_off, R1_SP); goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6512: BLOCK_COMMENT("Store method"); goetz@6512: // Store method into thread->callee_target. goetz@6458: // We might end up in handle_wrong_method if the callee is goetz@6458: // deoptimized as we race thru here. If that happens we don't want goetz@6458: // to take a safepoint because the caller frame will look goetz@6458: // interpreted and arguments are now "compiled" so it is much better goetz@6458: // to make this transition invisible to the stack walking goetz@6458: // code. Unfortunately if we try and find the callee by normal means goetz@6458: // a safepoint is possible. So we stash the desired callee in the goetz@6458: // thread and the vm will find there should this case occur. goetz@6458: __ std(R19_method, thread_(callee_target)); goetz@6458: goetz@6458: // Jump to the compiled code just as if compiled code was doing it. goetz@6458: __ bctr(); goetz@6458: } goetz@6458: goetz@6458: AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm, goetz@6458: int total_args_passed, goetz@6458: int comp_args_on_stack, goetz@6458: const BasicType *sig_bt, goetz@6458: const VMRegPair *regs, goetz@6458: AdapterFingerPrint* fingerprint) { goetz@6458: address i2c_entry; goetz@6458: address c2i_unverified_entry; goetz@6458: address c2i_entry; goetz@6458: goetz@6458: goetz@6458: // entry: i2c goetz@6458: goetz@6458: __ align(CodeEntryAlignment); goetz@6458: i2c_entry = __ pc(); goetz@6458: gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs); goetz@6458: goetz@6458: goetz@6458: // entry: c2i unverified goetz@6458: goetz@6458: __ align(CodeEntryAlignment); goetz@6458: BLOCK_COMMENT("c2i unverified entry"); goetz@6458: c2i_unverified_entry = __ pc(); goetz@6458: goetz@6458: // inline_cache contains a compiledICHolder goetz@6458: const Register ic = R19_method; goetz@6458: const Register ic_klass = R11_scratch1; goetz@6458: const Register receiver_klass = R12_scratch2; goetz@6458: const Register code = R21_tmp1; goetz@6458: const Register ientry = R23_tmp3; goetz@6458: goetz@6458: assert_different_registers(ic, ic_klass, receiver_klass, R3_ARG1, code, ientry); goetz@6458: assert(R11_scratch1 == R11, "need prologue scratch register"); goetz@6458: goetz@6458: Label call_interpreter; goetz@6458: goetz@6458: assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), goetz@6458: "klass offset should reach into any page"); goetz@6458: // Check for NULL argument if we don't have implicit null checks. goetz@6486: if (!ImplicitNullChecks || !os::zero_page_read_protected()) { goetz@6458: if (TrapBasedNullChecks) { goetz@6458: __ trap_null_check(R3_ARG1); goetz@6458: } else { goetz@6458: Label valid; goetz@6458: __ cmpdi(CCR0, R3_ARG1, 0); goetz@6458: __ bne_predict_taken(CCR0, valid); goetz@6458: // We have a null argument, branch to ic_miss_stub. goetz@6458: __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), goetz@6495: relocInfo::runtime_call_type); goetz@6458: __ BIND(valid); goetz@6458: } goetz@6458: } goetz@6458: // Assume argument is not NULL, load klass from receiver. goetz@6458: __ load_klass(receiver_klass, R3_ARG1); goetz@6458: goetz@6458: __ ld(ic_klass, CompiledICHolder::holder_klass_offset(), ic); goetz@6458: goetz@6458: if (TrapBasedICMissChecks) { goetz@6458: __ trap_ic_miss_check(receiver_klass, ic_klass); goetz@6458: } else { goetz@6458: Label valid; goetz@6458: __ cmpd(CCR0, receiver_klass, ic_klass); goetz@6458: __ beq_predict_taken(CCR0, valid); goetz@6458: // We have an unexpected klass, branch to ic_miss_stub. goetz@6458: __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), goetz@6495: relocInfo::runtime_call_type); goetz@6458: __ BIND(valid); goetz@6458: } goetz@6458: goetz@6458: // Argument is valid and klass is as expected, continue. goetz@6458: goetz@6458: // Extract method from inline cache, verified entry point needs it. dbuck@8997: __ ld(R19_method, CompiledICHolder::holder_metadata_offset(), ic); goetz@6458: assert(R19_method == ic, "the inline cache register is dead here"); goetz@6458: goetz@6458: __ ld(code, method_(code)); goetz@6458: __ cmpdi(CCR0, code, 0); goetz@6458: __ ld(ientry, method_(interpreter_entry)); // preloaded goetz@6458: __ beq_predict_taken(CCR0, call_interpreter); goetz@6458: goetz@6458: // Branch to ic_miss_stub. goetz@6495: __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), relocInfo::runtime_call_type); goetz@6458: goetz@6458: // entry: c2i goetz@6458: goetz@6458: c2i_entry = gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, call_interpreter, ientry); goetz@6458: goetz@6458: return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry); goetz@6458: } goetz@6458: goetz@6458: #ifdef COMPILER2 goetz@6458: // An oop arg. Must pass a handle not the oop itself. goetz@6458: static void object_move(MacroAssembler* masm, goetz@6458: int frame_size_in_slots, goetz@6458: OopMap* oop_map, int oop_handle_offset, goetz@6458: bool is_receiver, int* receiver_offset, goetz@6458: VMRegPair src, VMRegPair dst, goetz@6458: Register r_caller_sp, Register r_temp_1, Register r_temp_2) { goetz@6458: assert(!is_receiver || (is_receiver && (*receiver_offset == -1)), goetz@6458: "receiver has already been moved"); goetz@6458: goetz@6458: // We must pass a handle. First figure out the location we use as a handle. goetz@6458: goetz@6458: if (src.first()->is_stack()) { goetz@6458: // stack to stack or reg goetz@6458: goetz@6458: const Register r_handle = dst.first()->is_stack() ? r_temp_1 : dst.first()->as_Register(); goetz@6458: Label skip; goetz@6458: const int oop_slot_in_callers_frame = reg2slot(src.first()); goetz@6458: goetz@6458: guarantee(!is_receiver, "expecting receiver in register"); goetz@6458: oop_map->set_oop(VMRegImpl::stack2reg(oop_slot_in_callers_frame + frame_size_in_slots)); goetz@6458: goetz@6458: __ addi(r_handle, r_caller_sp, reg2offset(src.first())); goetz@6458: __ ld( r_temp_2, reg2offset(src.first()), r_caller_sp); goetz@6458: __ cmpdi(CCR0, r_temp_2, 0); goetz@6458: __ bne(CCR0, skip); goetz@6458: // Use a NULL handle if oop is NULL. goetz@6458: __ li(r_handle, 0); goetz@6458: __ bind(skip); goetz@6458: goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ std(r_handle, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: // Nothing to do, r_handle is already the dst register. goetz@6458: } goetz@6458: } else { goetz@6458: // reg to stack or reg goetz@6458: const Register r_oop = src.first()->as_Register(); goetz@6458: const Register r_handle = dst.first()->is_stack() ? r_temp_1 : dst.first()->as_Register(); goetz@6458: const int oop_slot = (r_oop->encoding()-R3_ARG1->encoding()) * VMRegImpl::slots_per_word goetz@6458: + oop_handle_offset; // in slots goetz@6458: const int oop_offset = oop_slot * VMRegImpl::stack_slot_size; goetz@6458: Label skip; goetz@6458: goetz@6458: if (is_receiver) { goetz@6458: *receiver_offset = oop_offset; goetz@6458: } goetz@6458: oop_map->set_oop(VMRegImpl::stack2reg(oop_slot)); goetz@6458: goetz@6458: __ std( r_oop, oop_offset, R1_SP); goetz@6458: __ addi(r_handle, R1_SP, oop_offset); goetz@6458: goetz@6458: __ cmpdi(CCR0, r_oop, 0); goetz@6458: __ bne(CCR0, skip); goetz@6458: // Use a NULL handle if oop is NULL. goetz@6458: __ li(r_handle, 0); goetz@6458: __ bind(skip); goetz@6458: goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ std(r_handle, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // reg to reg goetz@6458: // Nothing to do, r_handle is already the dst register. goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void int_move(MacroAssembler*masm, goetz@6458: VMRegPair src, VMRegPair dst, goetz@6458: Register r_caller_sp, Register r_temp) { goetz@6458: assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be long-int"); goetz@6458: assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be long"); goetz@6458: goetz@6458: if (src.first()->is_stack()) { goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ lwa(r_temp, reg2offset(src.first()), r_caller_sp); goetz@6458: __ std(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: __ lwa(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); goetz@6458: } goetz@6458: } else if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ extsw(r_temp, src.first()->as_Register()); goetz@6458: __ std(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // reg to reg goetz@6458: __ extsw(dst.first()->as_Register(), src.first()->as_Register()); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void long_move(MacroAssembler*masm, goetz@6458: VMRegPair src, VMRegPair dst, goetz@6458: Register r_caller_sp, Register r_temp) { goetz@6458: assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be long"); goetz@6458: assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be long"); goetz@6458: goetz@6458: if (src.first()->is_stack()) { goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ ld( r_temp, reg2offset(src.first()), r_caller_sp); goetz@6458: __ std(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: __ ld(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); goetz@6458: } goetz@6458: } else if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ std(src.first()->as_Register(), reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // reg to reg goetz@6458: if (dst.first()->as_Register() != src.first()->as_Register()) goetz@6458: __ mr(dst.first()->as_Register(), src.first()->as_Register()); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void float_move(MacroAssembler*masm, goetz@6458: VMRegPair src, VMRegPair dst, goetz@6458: Register r_caller_sp, Register r_temp) { goetz@6458: assert(src.first()->is_valid() && !src.second()->is_valid(), "incoming must be float"); goetz@6458: assert(dst.first()->is_valid() && !dst.second()->is_valid(), "outgoing must be float"); goetz@6458: goetz@6458: if (src.first()->is_stack()) { goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ lwz(r_temp, reg2offset(src.first()), r_caller_sp); goetz@6458: __ stw(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: __ lfs(dst.first()->as_FloatRegister(), reg2offset(src.first()), r_caller_sp); goetz@6458: } goetz@6458: } else if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ stfs(src.first()->as_FloatRegister(), reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // reg to reg goetz@6458: if (dst.first()->as_FloatRegister() != src.first()->as_FloatRegister()) goetz@6458: __ fmr(dst.first()->as_FloatRegister(), src.first()->as_FloatRegister()); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void double_move(MacroAssembler*masm, goetz@6458: VMRegPair src, VMRegPair dst, goetz@6458: Register r_caller_sp, Register r_temp) { goetz@6458: assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be double"); goetz@6458: assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be double"); goetz@6458: goetz@6458: if (src.first()->is_stack()) { goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ ld( r_temp, reg2offset(src.first()), r_caller_sp); goetz@6458: __ std(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: __ lfd(dst.first()->as_FloatRegister(), reg2offset(src.first()), r_caller_sp); goetz@6458: } goetz@6458: } else if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ stfd(src.first()->as_FloatRegister(), reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // reg to reg goetz@6458: if (dst.first()->as_FloatRegister() != src.first()->as_FloatRegister()) goetz@6458: __ fmr(dst.first()->as_FloatRegister(), src.first()->as_FloatRegister()); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { goetz@6458: switch (ret_type) { goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: goetz@6458: __ stw (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_ARRAY: goetz@6458: case T_OBJECT: goetz@6458: case T_LONG: goetz@6458: __ std (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_FLOAT: goetz@6458: __ stfs(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_DOUBLE: goetz@6458: __ stfd(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_VOID: goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: break; goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { goetz@6458: switch (ret_type) { goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: goetz@6458: __ lwz(R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_ARRAY: goetz@6458: case T_OBJECT: goetz@6458: case T_LONG: goetz@6458: __ ld (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_FLOAT: goetz@6458: __ lfs(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_DOUBLE: goetz@6458: __ lfd(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); goetz@6458: break; goetz@6458: case T_VOID: goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: break; goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void save_or_restore_arguments(MacroAssembler* masm, goetz@6458: const int stack_slots, goetz@6458: const int total_in_args, goetz@6458: const int arg_save_area, goetz@6458: OopMap* map, goetz@6458: VMRegPair* in_regs, goetz@6458: BasicType* in_sig_bt) { goetz@6458: // If map is non-NULL then the code should store the values, goetz@6458: // otherwise it should load them. goetz@6458: int slot = arg_save_area; goetz@6458: // Save down double word first. goetz@6458: for (int i = 0; i < total_in_args; i++) { goetz@6458: if (in_regs[i].first()->is_FloatRegister() && in_sig_bt[i] == T_DOUBLE) { goetz@6458: int offset = slot * VMRegImpl::stack_slot_size; goetz@6458: slot += VMRegImpl::slots_per_word; goetz@6458: assert(slot <= stack_slots, "overflow (after DOUBLE stack slot)"); goetz@6458: if (map != NULL) { goetz@6458: __ stfd(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); goetz@6458: } else { goetz@6458: __ lfd(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); goetz@6458: } goetz@6458: } else if (in_regs[i].first()->is_Register() && goetz@6458: (in_sig_bt[i] == T_LONG || in_sig_bt[i] == T_ARRAY)) { goetz@6458: int offset = slot * VMRegImpl::stack_slot_size; goetz@6458: if (map != NULL) { goetz@6458: __ std(in_regs[i].first()->as_Register(), offset, R1_SP); goetz@6458: if (in_sig_bt[i] == T_ARRAY) { goetz@6458: map->set_oop(VMRegImpl::stack2reg(slot)); goetz@6458: } goetz@6458: } else { goetz@6458: __ ld(in_regs[i].first()->as_Register(), offset, R1_SP); goetz@6458: } goetz@6458: slot += VMRegImpl::slots_per_word; goetz@6458: assert(slot <= stack_slots, "overflow (after LONG/ARRAY stack slot)"); goetz@6458: } goetz@6458: } goetz@6458: // Save or restore single word registers. goetz@6458: for (int i = 0; i < total_in_args; i++) { goetz@6458: // PPC64: pass ints as longs: must only deal with floats here. goetz@6458: if (in_regs[i].first()->is_FloatRegister()) { goetz@6458: if (in_sig_bt[i] == T_FLOAT) { goetz@6458: int offset = slot * VMRegImpl::stack_slot_size; goetz@6458: slot++; goetz@6458: assert(slot <= stack_slots, "overflow (after FLOAT stack slot)"); goetz@6458: if (map != NULL) { goetz@6458: __ stfs(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); goetz@6458: } else { goetz@6458: __ lfs(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); goetz@6458: } goetz@6458: } goetz@6458: } else if (in_regs[i].first()->is_stack()) { goetz@6458: if (in_sig_bt[i] == T_ARRAY && map != NULL) { goetz@6458: int offset_in_older_frame = in_regs[i].first()->reg2stack() + SharedRuntime::out_preserve_stack_slots(); goetz@6458: map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + stack_slots)); goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Check GC_locker::needs_gc and enter the runtime if it's true. This goetz@6458: // keeps a new JNI critical region from starting until a GC has been goetz@6458: // forced. Save down any oops in registers and describe them in an goetz@6458: // OopMap. goetz@6458: static void check_needs_gc_for_critical_native(MacroAssembler* masm, goetz@6458: const int stack_slots, goetz@6458: const int total_in_args, goetz@6458: const int arg_save_area, goetz@6458: OopMapSet* oop_maps, goetz@6458: VMRegPair* in_regs, goetz@6458: BasicType* in_sig_bt, goetz@6458: Register tmp_reg ) { goetz@6458: __ block_comment("check GC_locker::needs_gc"); goetz@6458: Label cont; goetz@6458: __ lbz(tmp_reg, (RegisterOrConstant)(intptr_t)GC_locker::needs_gc_address()); goetz@6458: __ cmplwi(CCR0, tmp_reg, 0); goetz@6458: __ beq(CCR0, cont); goetz@6458: goetz@6458: // Save down any values that are live in registers and call into the goetz@6458: // runtime to halt for a GC. goetz@6458: OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); goetz@6458: save_or_restore_arguments(masm, stack_slots, total_in_args, goetz@6458: arg_save_area, map, in_regs, in_sig_bt); goetz@6458: goetz@6458: __ mr(R3_ARG1, R16_thread); goetz@6458: __ set_last_Java_frame(R1_SP, noreg); goetz@6458: goetz@6458: __ block_comment("block_for_jni_critical"); goetz@6458: address entry_point = CAST_FROM_FN_PTR(address, SharedRuntime::block_for_jni_critical); goetz@6511: #if defined(ABI_ELFv2) goetz@6511: __ call_c(entry_point, relocInfo::runtime_call_type); goetz@6511: #else goetz@6458: __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, entry_point), relocInfo::runtime_call_type); goetz@6511: #endif goetz@6458: address start = __ pc() - __ offset(), goetz@6458: calls_return_pc = __ last_calls_return_pc(); goetz@6458: oop_maps->add_gc_map(calls_return_pc - start, map); goetz@6458: goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: // Reload all the register arguments. goetz@6458: save_or_restore_arguments(masm, stack_slots, total_in_args, goetz@6458: arg_save_area, NULL, in_regs, in_sig_bt); goetz@6458: goetz@6458: __ BIND(cont); goetz@6458: goetz@6458: #ifdef ASSERT goetz@6458: if (StressCriticalJNINatives) { goetz@6458: // Stress register saving. goetz@6458: OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); goetz@6458: save_or_restore_arguments(masm, stack_slots, total_in_args, goetz@6458: arg_save_area, map, in_regs, in_sig_bt); goetz@6458: // Destroy argument registers. goetz@6458: for (int i = 0; i < total_in_args; i++) { goetz@6458: if (in_regs[i].first()->is_Register()) { goetz@6458: const Register reg = in_regs[i].first()->as_Register(); goetz@6458: __ neg(reg, reg); goetz@6458: } else if (in_regs[i].first()->is_FloatRegister()) { goetz@6458: __ fneg(in_regs[i].first()->as_FloatRegister(), in_regs[i].first()->as_FloatRegister()); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: save_or_restore_arguments(masm, stack_slots, total_in_args, goetz@6458: arg_save_area, NULL, in_regs, in_sig_bt); goetz@6458: } goetz@6458: #endif goetz@6458: } goetz@6458: goetz@6458: static void move_ptr(MacroAssembler* masm, VMRegPair src, VMRegPair dst, Register r_caller_sp, Register r_temp) { goetz@6458: if (src.first()->is_stack()) { goetz@6458: if (dst.first()->is_stack()) { goetz@6458: // stack to stack goetz@6458: __ ld(r_temp, reg2offset(src.first()), r_caller_sp); goetz@6458: __ std(r_temp, reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: // stack to reg goetz@6458: __ ld(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); goetz@6458: } goetz@6458: } else if (dst.first()->is_stack()) { goetz@6458: // reg to stack goetz@6458: __ std(src.first()->as_Register(), reg2offset(dst.first()), R1_SP); goetz@6458: } else { goetz@6458: if (dst.first() != src.first()) { goetz@6458: __ mr(dst.first()->as_Register(), src.first()->as_Register()); goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Unpack an array argument into a pointer to the body and the length goetz@6458: // if the array is non-null, otherwise pass 0 for both. goetz@6458: static void unpack_array_argument(MacroAssembler* masm, VMRegPair reg, BasicType in_elem_type, goetz@6458: VMRegPair body_arg, VMRegPair length_arg, Register r_caller_sp, goetz@6458: Register tmp_reg, Register tmp2_reg) { goetz@6458: assert(!body_arg.first()->is_Register() || body_arg.first()->as_Register() != tmp_reg, goetz@6458: "possible collision"); goetz@6458: assert(!length_arg.first()->is_Register() || length_arg.first()->as_Register() != tmp_reg, goetz@6458: "possible collision"); goetz@6458: goetz@6458: // Pass the length, ptr pair. goetz@6458: Label set_out_args; goetz@6458: VMRegPair tmp, tmp2; goetz@6458: tmp.set_ptr(tmp_reg->as_VMReg()); goetz@6458: tmp2.set_ptr(tmp2_reg->as_VMReg()); goetz@6458: if (reg.first()->is_stack()) { goetz@6458: // Load the arg up from the stack. goetz@6458: move_ptr(masm, reg, tmp, r_caller_sp, /*unused*/ R0); goetz@6458: reg = tmp; goetz@6458: } goetz@6458: __ li(tmp2_reg, 0); // Pass zeros if Array=null. goetz@6458: if (tmp_reg != reg.first()->as_Register()) __ li(tmp_reg, 0); goetz@6458: __ cmpdi(CCR0, reg.first()->as_Register(), 0); goetz@6458: __ beq(CCR0, set_out_args); goetz@6458: __ lwa(tmp2_reg, arrayOopDesc::length_offset_in_bytes(), reg.first()->as_Register()); goetz@6458: __ addi(tmp_reg, reg.first()->as_Register(), arrayOopDesc::base_offset_in_bytes(in_elem_type)); goetz@6458: __ bind(set_out_args); goetz@6458: move_ptr(masm, tmp, body_arg, r_caller_sp, /*unused*/ R0); goetz@6458: move_ptr(masm, tmp2, length_arg, r_caller_sp, /*unused*/ R0); // Same as move32_64 on PPC64. goetz@6458: } goetz@6458: goetz@6458: static void verify_oop_args(MacroAssembler* masm, goetz@6458: methodHandle method, goetz@6458: const BasicType* sig_bt, goetz@6458: const VMRegPair* regs) { goetz@6458: Register temp_reg = R19_method; // not part of any compiled calling seq goetz@6458: if (VerifyOops) { goetz@6458: for (int i = 0; i < method->size_of_parameters(); i++) { goetz@6458: if (sig_bt[i] == T_OBJECT || goetz@6458: sig_bt[i] == T_ARRAY) { goetz@6458: VMReg r = regs[i].first(); goetz@6458: assert(r->is_valid(), "bad oop arg"); goetz@6458: if (r->is_stack()) { goetz@6458: __ ld(temp_reg, reg2offset(r), R1_SP); goetz@6458: __ verify_oop(temp_reg); goetz@6458: } else { goetz@6458: __ verify_oop(r->as_Register()); goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: static void gen_special_dispatch(MacroAssembler* masm, goetz@6458: methodHandle method, goetz@6458: const BasicType* sig_bt, goetz@6458: const VMRegPair* regs) { goetz@6458: verify_oop_args(masm, method, sig_bt, regs); goetz@6458: vmIntrinsics::ID iid = method->intrinsic_id(); goetz@6458: goetz@6458: // Now write the args into the outgoing interpreter space goetz@6458: bool has_receiver = false; goetz@6458: Register receiver_reg = noreg; goetz@6458: int member_arg_pos = -1; goetz@6458: Register member_reg = noreg; goetz@6458: int ref_kind = MethodHandles::signature_polymorphic_intrinsic_ref_kind(iid); goetz@6458: if (ref_kind != 0) { goetz@6458: member_arg_pos = method->size_of_parameters() - 1; // trailing MemberName argument goetz@6458: member_reg = R19_method; // known to be free at this point goetz@6458: has_receiver = MethodHandles::ref_kind_has_receiver(ref_kind); goetz@6458: } else if (iid == vmIntrinsics::_invokeBasic) { goetz@6458: has_receiver = true; goetz@6458: } else { goetz@6458: fatal(err_msg_res("unexpected intrinsic id %d", iid)); goetz@6458: } goetz@6458: goetz@6458: if (member_reg != noreg) { goetz@6458: // Load the member_arg into register, if necessary. goetz@6458: SharedRuntime::check_member_name_argument_is_last_argument(method, sig_bt, regs); goetz@6458: VMReg r = regs[member_arg_pos].first(); goetz@6458: if (r->is_stack()) { goetz@6458: __ ld(member_reg, reg2offset(r), R1_SP); goetz@6458: } else { goetz@6458: // no data motion is needed goetz@6458: member_reg = r->as_Register(); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: if (has_receiver) { goetz@6458: // Make sure the receiver is loaded into a register. goetz@6458: assert(method->size_of_parameters() > 0, "oob"); goetz@6458: assert(sig_bt[0] == T_OBJECT, "receiver argument must be an object"); goetz@6458: VMReg r = regs[0].first(); goetz@6458: assert(r->is_valid(), "bad receiver arg"); goetz@6458: if (r->is_stack()) { goetz@6458: // Porting note: This assumes that compiled calling conventions always goetz@6458: // pass the receiver oop in a register. If this is not true on some goetz@6458: // platform, pick a temp and load the receiver from stack. goetz@6458: fatal("receiver always in a register"); goetz@6458: receiver_reg = R11_scratch1; // TODO (hs24): is R11_scratch1 really free at this point? goetz@6458: __ ld(receiver_reg, reg2offset(r), R1_SP); goetz@6458: } else { goetz@6458: // no data motion is needed goetz@6458: receiver_reg = r->as_Register(); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Figure out which address we are really jumping to: goetz@6458: MethodHandles::generate_method_handle_dispatch(masm, iid, goetz@6458: receiver_reg, member_reg, /*for_compiler_entry:*/ true); goetz@6458: } goetz@6458: goetz@6458: #endif // COMPILER2 goetz@6458: goetz@6458: // --------------------------------------------------------------------------- goetz@6458: // Generate a native wrapper for a given method. The method takes arguments goetz@6458: // in the Java compiled code convention, marshals them to the native goetz@6458: // convention (handlizes oops, etc), transitions to native, makes the call, goetz@6458: // returns to java state (possibly blocking), unhandlizes any result and goetz@6458: // returns. goetz@6458: // goetz@6458: // Critical native functions are a shorthand for the use of goetz@6458: // GetPrimtiveArrayCritical and disallow the use of any other JNI goetz@6458: // functions. The wrapper is expected to unpack the arguments before goetz@6458: // passing them to the callee and perform checks before and after the goetz@6458: // native call to ensure that they GC_locker goetz@6458: // lock_critical/unlock_critical semantics are followed. Some other goetz@6458: // parts of JNI setup are skipped like the tear down of the JNI handle goetz@6458: // block and the check for pending exceptions it's impossible for them goetz@6458: // to be thrown. goetz@6458: // goetz@6458: // They are roughly structured like this: goetz@6458: // if (GC_locker::needs_gc()) goetz@6458: // SharedRuntime::block_for_jni_critical(); goetz@6458: // tranistion to thread_in_native goetz@6458: // unpack arrray arguments and call native entry point goetz@6458: // check for safepoint in progress goetz@6458: // check if any thread suspend flags are set goetz@6458: // call into JVM and possible unlock the JNI critical goetz@6458: // if a GC was suppressed while in the critical native. goetz@6458: // transition back to thread_in_Java goetz@6458: // return to caller goetz@6458: // goetz@6458: nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm, goetz@6458: methodHandle method, goetz@6458: int compile_id, goetz@6458: BasicType *in_sig_bt, goetz@6458: VMRegPair *in_regs, goetz@6458: BasicType ret_type) { goetz@6458: #ifdef COMPILER2 goetz@6458: if (method->is_method_handle_intrinsic()) { goetz@6458: vmIntrinsics::ID iid = method->intrinsic_id(); goetz@6458: intptr_t start = (intptr_t)__ pc(); goetz@6458: int vep_offset = ((intptr_t)__ pc()) - start; goetz@6458: gen_special_dispatch(masm, goetz@6458: method, goetz@6458: in_sig_bt, goetz@6458: in_regs); goetz@6458: int frame_complete = ((intptr_t)__ pc()) - start; // not complete, period goetz@6458: __ flush(); goetz@6458: int stack_slots = SharedRuntime::out_preserve_stack_slots(); // no out slots at all, actually goetz@6458: return nmethod::new_native_nmethod(method, goetz@6458: compile_id, goetz@6458: masm->code(), goetz@6458: vep_offset, goetz@6458: frame_complete, goetz@6458: stack_slots / VMRegImpl::slots_per_word, goetz@6458: in_ByteSize(-1), goetz@6458: in_ByteSize(-1), goetz@6458: (OopMapSet*)NULL); goetz@6458: } goetz@6458: goetz@6458: bool is_critical_native = true; goetz@6458: address native_func = method->critical_native_function(); goetz@6458: if (native_func == NULL) { goetz@6458: native_func = method->native_function(); goetz@6458: is_critical_native = false; goetz@6458: } goetz@6458: assert(native_func != NULL, "must have function"); goetz@6458: goetz@6458: // First, create signature for outgoing C call goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: int total_in_args = method->size_of_parameters(); goetz@6458: // We have received a description of where all the java args are located goetz@6458: // on entry to the wrapper. We need to convert these args to where goetz@6458: // the jni function will expect them. To figure out where they go goetz@6458: // we convert the java signature to a C signature by inserting goetz@6458: // the hidden arguments as arg[0] and possibly arg[1] (static method) goetz@6458: // goetz@6458: // Additionally, on ppc64 we must convert integers to longs in the C goetz@6458: // signature. We do this in advance in order to have no trouble with goetz@6458: // indexes into the bt-arrays. goetz@6458: // So convert the signature and registers now, and adjust the total number goetz@6458: // of in-arguments accordingly. goetz@6458: int i2l_argcnt = convert_ints_to_longints_argcnt(total_in_args, in_sig_bt); // PPC64: pass ints as longs. goetz@6458: goetz@6458: // Calculate the total number of C arguments and create arrays for the goetz@6458: // signature and the outgoing registers. goetz@6458: // On ppc64, we have two arrays for the outgoing registers, because goetz@6458: // some floating-point arguments must be passed in registers _and_ goetz@6458: // in stack locations. goetz@6458: bool method_is_static = method->is_static(); goetz@6458: int total_c_args = i2l_argcnt; goetz@6458: goetz@6458: if (!is_critical_native) { goetz@6458: int n_hidden_args = method_is_static ? 2 : 1; goetz@6458: total_c_args += n_hidden_args; goetz@6458: } else { goetz@6458: // No JNIEnv*, no this*, but unpacked arrays (base+length). goetz@6458: for (int i = 0; i < total_in_args; i++) { goetz@6458: if (in_sig_bt[i] == T_ARRAY) { goetz@6458: total_c_args += 2; // PPC64: T_LONG, T_INT, T_ADDRESS (see convert_ints_to_longints and c_calling_convention) goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: BasicType *out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args); goetz@6458: VMRegPair *out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args); goetz@6458: VMRegPair *out_regs2 = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args); goetz@6458: BasicType* in_elem_bt = NULL; goetz@6458: goetz@6458: // Create the signature for the C call: goetz@6458: // 1) add the JNIEnv* goetz@6458: // 2) add the class if the method is static goetz@6458: // 3) copy the rest of the incoming signature (shifted by the number of goetz@6458: // hidden arguments). goetz@6458: goetz@6458: int argc = 0; goetz@6458: if (!is_critical_native) { goetz@6458: convert_ints_to_longints(i2l_argcnt, total_in_args, in_sig_bt, in_regs); // PPC64: pass ints as longs. goetz@6458: goetz@6458: out_sig_bt[argc++] = T_ADDRESS; goetz@6458: if (method->is_static()) { goetz@6458: out_sig_bt[argc++] = T_OBJECT; goetz@6458: } goetz@6458: goetz@6458: for (int i = 0; i < total_in_args ; i++ ) { goetz@6458: out_sig_bt[argc++] = in_sig_bt[i]; goetz@6458: } goetz@6458: } else { goetz@6458: Thread* THREAD = Thread::current(); goetz@6458: in_elem_bt = NEW_RESOURCE_ARRAY(BasicType, i2l_argcnt); goetz@6458: SignatureStream ss(method->signature()); goetz@6458: int o = 0; goetz@6458: for (int i = 0; i < total_in_args ; i++, o++) { goetz@6458: if (in_sig_bt[i] == T_ARRAY) { goetz@6458: // Arrays are passed as int, elem* pair goetz@6458: Symbol* atype = ss.as_symbol(CHECK_NULL); goetz@6458: const char* at = atype->as_C_string(); goetz@6458: if (strlen(at) == 2) { goetz@6458: assert(at[0] == '[', "must be"); goetz@6458: switch (at[1]) { goetz@6458: case 'B': in_elem_bt[o] = T_BYTE; break; goetz@6458: case 'C': in_elem_bt[o] = T_CHAR; break; goetz@6458: case 'D': in_elem_bt[o] = T_DOUBLE; break; goetz@6458: case 'F': in_elem_bt[o] = T_FLOAT; break; goetz@6458: case 'I': in_elem_bt[o] = T_INT; break; goetz@6458: case 'J': in_elem_bt[o] = T_LONG; break; goetz@6458: case 'S': in_elem_bt[o] = T_SHORT; break; goetz@6458: case 'Z': in_elem_bt[o] = T_BOOLEAN; break; goetz@6458: default: ShouldNotReachHere(); goetz@6458: } goetz@6458: } goetz@6458: } else { goetz@6458: in_elem_bt[o] = T_VOID; goetz@6458: switch(in_sig_bt[i]) { // PPC64: pass ints as longs. goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: in_elem_bt[++o] = T_VOID; break; goetz@6458: default: break; goetz@6458: } goetz@6458: } goetz@6458: if (in_sig_bt[i] != T_VOID) { goetz@6458: assert(in_sig_bt[i] == ss.type(), "must match"); goetz@6458: ss.next(); goetz@6458: } goetz@6458: } goetz@6458: assert(i2l_argcnt==o, "must match"); goetz@6458: goetz@6458: convert_ints_to_longints(i2l_argcnt, total_in_args, in_sig_bt, in_regs); // PPC64: pass ints as longs. goetz@6458: goetz@6458: for (int i = 0; i < total_in_args ; i++ ) { goetz@6458: if (in_sig_bt[i] == T_ARRAY) { goetz@6458: // Arrays are passed as int, elem* pair. goetz@6458: out_sig_bt[argc++] = T_LONG; // PPC64: pass ints as longs. goetz@6458: out_sig_bt[argc++] = T_INT; goetz@6458: out_sig_bt[argc++] = T_ADDRESS; goetz@6458: } else { goetz@6458: out_sig_bt[argc++] = in_sig_bt[i]; goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Compute the wrapper's frame size. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Now figure out where the args must be stored and how much stack space goetz@6458: // they require. goetz@6458: // goetz@6458: // Compute framesize for the wrapper. We need to handlize all oops in goetz@6458: // incoming registers. goetz@6458: // goetz@6458: // Calculate the total number of stack slots we will need: goetz@6458: // 1) abi requirements goetz@6458: // 2) outgoing arguments goetz@6458: // 3) space for inbound oop handle area goetz@6458: // 4) space for handlizing a klass if static method goetz@6458: // 5) space for a lock if synchronized method goetz@6458: // 6) workspace for saving return values, int <-> float reg moves, etc. goetz@6458: // 7) alignment goetz@6458: // goetz@6458: // Layout of the native wrapper frame: goetz@6458: // (stack grows upwards, memory grows downwards) goetz@6458: // goetz@6511: // NW [ABI_REG_ARGS] <-- 1) R1_SP goetz@6458: // [outgoing arguments] <-- 2) R1_SP + out_arg_slot_offset goetz@6458: // [oopHandle area] <-- 3) R1_SP + oop_handle_offset (save area for critical natives) goetz@6458: // klass <-- 4) R1_SP + klass_offset goetz@6458: // lock <-- 5) R1_SP + lock_offset goetz@6458: // [workspace] <-- 6) R1_SP + workspace_offset goetz@6458: // [alignment] (optional) <-- 7) goetz@6458: // caller [JIT_TOP_ABI_48] <-- r_callers_sp goetz@6458: // goetz@6458: // - *_slot_offset Indicates offset from SP in number of stack slots. goetz@6458: // - *_offset Indicates offset from SP in bytes. goetz@6458: goetz@6458: int stack_slots = c_calling_convention(out_sig_bt, out_regs, out_regs2, total_c_args) // 1+2) goetz@6458: + SharedRuntime::out_preserve_stack_slots(); // See c_calling_convention. goetz@6458: goetz@6458: // Now the space for the inbound oop handle area. goetz@6458: int total_save_slots = num_java_iarg_registers * VMRegImpl::slots_per_word; goetz@6458: if (is_critical_native) { goetz@6458: // Critical natives may have to call out so they need a save area goetz@6458: // for register arguments. goetz@6458: int double_slots = 0; goetz@6458: int single_slots = 0; goetz@6458: for (int i = 0; i < total_in_args; i++) { goetz@6458: if (in_regs[i].first()->is_Register()) { goetz@6458: const Register reg = in_regs[i].first()->as_Register(); goetz@6458: switch (in_sig_bt[i]) { goetz@6458: case T_BOOLEAN: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_CHAR: goetz@6458: case T_INT: /*single_slots++;*/ break; // PPC64: pass ints as longs. goetz@6458: case T_ARRAY: goetz@6458: case T_LONG: double_slots++; break; goetz@6458: default: ShouldNotReachHere(); goetz@6458: } goetz@6458: } else if (in_regs[i].first()->is_FloatRegister()) { goetz@6458: switch (in_sig_bt[i]) { goetz@6458: case T_FLOAT: single_slots++; break; goetz@6458: case T_DOUBLE: double_slots++; break; goetz@6458: default: ShouldNotReachHere(); goetz@6458: } goetz@6458: } goetz@6458: } goetz@6458: total_save_slots = double_slots * 2 + round_to(single_slots, 2); // round to even goetz@6458: } goetz@6458: goetz@6458: int oop_handle_slot_offset = stack_slots; goetz@6458: stack_slots += total_save_slots; // 3) goetz@6458: goetz@6458: int klass_slot_offset = 0; goetz@6458: int klass_offset = -1; goetz@6458: if (method_is_static && !is_critical_native) { // 4) goetz@6458: klass_slot_offset = stack_slots; goetz@6458: klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size; goetz@6458: stack_slots += VMRegImpl::slots_per_word; goetz@6458: } goetz@6458: goetz@6458: int lock_slot_offset = 0; goetz@6458: int lock_offset = -1; goetz@6458: if (method->is_synchronized()) { // 5) goetz@6458: lock_slot_offset = stack_slots; goetz@6458: lock_offset = lock_slot_offset * VMRegImpl::stack_slot_size; goetz@6458: stack_slots += VMRegImpl::slots_per_word; goetz@6458: } goetz@6458: goetz@6458: int workspace_slot_offset = stack_slots; // 6) goetz@6458: stack_slots += 2; goetz@6458: goetz@6458: // Now compute actual number of stack words we need. goetz@6458: // Rounding to make stack properly aligned. goetz@6458: stack_slots = round_to(stack_slots, // 7) goetz@6458: frame::alignment_in_bytes / VMRegImpl::stack_slot_size); goetz@6458: int frame_size_in_bytes = stack_slots * VMRegImpl::stack_slot_size; goetz@6458: goetz@6458: goetz@6458: // Now we can start generating code. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: intptr_t start_pc = (intptr_t)__ pc(); goetz@6458: intptr_t vep_start_pc; goetz@6458: intptr_t frame_done_pc; goetz@6458: intptr_t oopmap_pc; goetz@6458: goetz@6458: Label ic_miss; goetz@6458: Label handle_pending_exception; goetz@6458: goetz@6458: Register r_callers_sp = R21; goetz@6458: Register r_temp_1 = R22; goetz@6458: Register r_temp_2 = R23; goetz@6458: Register r_temp_3 = R24; goetz@6458: Register r_temp_4 = R25; goetz@6458: Register r_temp_5 = R26; goetz@6458: Register r_temp_6 = R27; goetz@6458: Register r_return_pc = R28; goetz@6458: goetz@6458: Register r_carg1_jnienv = noreg; goetz@6458: Register r_carg2_classorobject = noreg; goetz@6458: if (!is_critical_native) { goetz@6458: r_carg1_jnienv = out_regs[0].first()->as_Register(); goetz@6458: r_carg2_classorobject = out_regs[1].first()->as_Register(); goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Generate the Unverified Entry Point (UEP). goetz@6458: // -------------------------------------------------------------------------- goetz@6458: assert(start_pc == (intptr_t)__ pc(), "uep must be at start"); goetz@6458: goetz@6458: // Check ic: object class == cached class? goetz@6458: if (!method_is_static) { goetz@6458: Register ic = as_Register(Matcher::inline_cache_reg_encode()); goetz@6458: Register receiver_klass = r_temp_1; goetz@6458: goetz@6458: __ cmpdi(CCR0, R3_ARG1, 0); goetz@6458: __ beq(CCR0, ic_miss); goetz@6458: __ verify_oop(R3_ARG1); goetz@6458: __ load_klass(receiver_klass, R3_ARG1); goetz@6458: goetz@6458: __ cmpd(CCR0, receiver_klass, ic); goetz@6458: __ bne(CCR0, ic_miss); goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Generate the Verified Entry Point (VEP). goetz@6458: // -------------------------------------------------------------------------- goetz@6458: vep_start_pc = (intptr_t)__ pc(); goetz@6458: goetz@6458: __ save_LR_CR(r_temp_1); goetz@6458: __ generate_stack_overflow_check(frame_size_in_bytes); // Check before creating frame. goetz@6458: __ mr(r_callers_sp, R1_SP); // Remember frame pointer. goetz@6458: __ push_frame(frame_size_in_bytes, r_temp_1); // Push the c2n adapter's frame. goetz@6458: frame_done_pc = (intptr_t)__ pc(); goetz@6458: goetz@6458: // Native nmethod wrappers never take possesion of the oop arguments. goetz@6458: // So the caller will gc the arguments. goetz@6458: // The only thing we need an oopMap for is if the call is static. goetz@6458: // goetz@6458: // An OopMap for lock (and class if static), and one for the VM call itself. goetz@6458: OopMapSet *oop_maps = new OopMapSet(); goetz@6458: OopMap *oop_map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); goetz@6458: goetz@6458: if (is_critical_native) { goetz@6458: check_needs_gc_for_critical_native(masm, stack_slots, total_in_args, oop_handle_slot_offset, oop_maps, in_regs, in_sig_bt, r_temp_1); goetz@6458: } goetz@6458: goetz@6458: // Move arguments from register/stack to register/stack. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: // goetz@6458: // We immediately shuffle the arguments so that for any vm call we have goetz@6458: // to make from here on out (sync slow path, jvmti, etc.) we will have goetz@6458: // captured the oops from our caller and have a valid oopMap for them. goetz@6458: // goetz@6458: // Natives require 1 or 2 extra arguments over the normal ones: the JNIEnv* goetz@6458: // (derived from JavaThread* which is in R16_thread) and, if static, goetz@6458: // the class mirror instead of a receiver. This pretty much guarantees that goetz@6458: // register layout will not match. We ignore these extra arguments during goetz@6458: // the shuffle. The shuffle is described by the two calling convention goetz@6458: // vectors we have in our possession. We simply walk the java vector to goetz@6458: // get the source locations and the c vector to get the destinations. goetz@6458: goetz@6458: // Record sp-based slot for receiver on stack for non-static methods. goetz@6458: int receiver_offset = -1; goetz@6458: goetz@6458: // We move the arguments backward because the floating point registers goetz@6458: // destination will always be to a register with a greater or equal goetz@6458: // register number or the stack. goetz@6458: // in is the index of the incoming Java arguments goetz@6458: // out is the index of the outgoing C arguments goetz@6458: goetz@6458: #ifdef ASSERT goetz@6458: bool reg_destroyed[RegisterImpl::number_of_registers]; goetz@6458: bool freg_destroyed[FloatRegisterImpl::number_of_registers]; goetz@6458: for (int r = 0 ; r < RegisterImpl::number_of_registers ; r++) { goetz@6458: reg_destroyed[r] = false; goetz@6458: } goetz@6458: for (int f = 0 ; f < FloatRegisterImpl::number_of_registers ; f++) { goetz@6458: freg_destroyed[f] = false; goetz@6458: } goetz@6458: #endif // ASSERT goetz@6458: goetz@6458: for (int in = total_in_args - 1, out = total_c_args - 1; in >= 0 ; in--, out--) { goetz@6458: goetz@6458: #ifdef ASSERT goetz@6458: if (in_regs[in].first()->is_Register()) { goetz@6458: assert(!reg_destroyed[in_regs[in].first()->as_Register()->encoding()], "ack!"); goetz@6458: } else if (in_regs[in].first()->is_FloatRegister()) { goetz@6458: assert(!freg_destroyed[in_regs[in].first()->as_FloatRegister()->encoding()], "ack!"); goetz@6458: } goetz@6458: if (out_regs[out].first()->is_Register()) { goetz@6458: reg_destroyed[out_regs[out].first()->as_Register()->encoding()] = true; goetz@6458: } else if (out_regs[out].first()->is_FloatRegister()) { goetz@6458: freg_destroyed[out_regs[out].first()->as_FloatRegister()->encoding()] = true; goetz@6458: } goetz@6458: if (out_regs2[out].first()->is_Register()) { goetz@6458: reg_destroyed[out_regs2[out].first()->as_Register()->encoding()] = true; goetz@6458: } else if (out_regs2[out].first()->is_FloatRegister()) { goetz@6458: freg_destroyed[out_regs2[out].first()->as_FloatRegister()->encoding()] = true; goetz@6458: } goetz@6458: #endif // ASSERT goetz@6458: goetz@6458: switch (in_sig_bt[in]) { goetz@6458: case T_BOOLEAN: goetz@6458: case T_CHAR: goetz@6458: case T_BYTE: goetz@6458: case T_SHORT: goetz@6458: case T_INT: goetz@6458: guarantee(in > 0 && in_sig_bt[in-1] == T_LONG, goetz@6458: "expecting type (T_LONG,bt) for bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); goetz@6458: break; goetz@6458: case T_LONG: goetz@6458: if (in_sig_bt[in+1] == T_VOID) { goetz@6458: long_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); goetz@6458: } else { goetz@6458: guarantee(in_sig_bt[in+1] == T_BOOLEAN || in_sig_bt[in+1] == T_CHAR || goetz@6458: in_sig_bt[in+1] == T_BYTE || in_sig_bt[in+1] == T_SHORT || goetz@6458: in_sig_bt[in+1] == T_INT, goetz@6458: "expecting type (T_LONG,bt) for bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); goetz@6458: int_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); goetz@6458: } goetz@6458: break; goetz@6458: case T_ARRAY: goetz@6458: if (is_critical_native) { goetz@6458: int body_arg = out; goetz@6458: out -= 2; // Point to length arg. PPC64: pass ints as longs. goetz@6458: unpack_array_argument(masm, in_regs[in], in_elem_bt[in], out_regs[body_arg], out_regs[out], goetz@6458: r_callers_sp, r_temp_1, r_temp_2); goetz@6458: break; goetz@6458: } goetz@6458: case T_OBJECT: goetz@6458: assert(!is_critical_native, "no oop arguments"); goetz@6458: object_move(masm, stack_slots, goetz@6458: oop_map, oop_handle_slot_offset, goetz@6458: ((in == 0) && (!method_is_static)), &receiver_offset, goetz@6458: in_regs[in], out_regs[out], goetz@6458: r_callers_sp, r_temp_1, r_temp_2); goetz@6458: break; goetz@6458: case T_VOID: goetz@6458: break; goetz@6458: case T_FLOAT: goetz@6458: float_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); goetz@6458: if (out_regs2[out].first()->is_valid()) { goetz@6458: float_move(masm, in_regs[in], out_regs2[out], r_callers_sp, r_temp_1); goetz@6458: } goetz@6458: break; goetz@6458: case T_DOUBLE: goetz@6458: double_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); goetz@6458: if (out_regs2[out].first()->is_valid()) { goetz@6458: double_move(masm, in_regs[in], out_regs2[out], r_callers_sp, r_temp_1); goetz@6458: } goetz@6458: break; goetz@6458: case T_ADDRESS: goetz@6458: fatal("found type (T_ADDRESS) in java args"); goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: break; goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: // Pre-load a static method's oop into ARG2. goetz@6458: // Used both by locking code and the normal JNI call code. goetz@6458: if (method_is_static && !is_critical_native) { goetz@6458: __ set_oop_constant(JNIHandles::make_local(method->method_holder()->java_mirror()), goetz@6458: r_carg2_classorobject); goetz@6458: goetz@6458: // Now handlize the static class mirror in carg2. It's known not-null. goetz@6458: __ std(r_carg2_classorobject, klass_offset, R1_SP); goetz@6458: oop_map->set_oop(VMRegImpl::stack2reg(klass_slot_offset)); goetz@6458: __ addi(r_carg2_classorobject, R1_SP, klass_offset); goetz@6458: } goetz@6458: goetz@6458: // Get JNIEnv* which is first argument to native. goetz@6458: if (!is_critical_native) { goetz@6458: __ addi(r_carg1_jnienv, R16_thread, in_bytes(JavaThread::jni_environment_offset())); goetz@6458: } goetz@6458: goetz@6458: // NOTE: goetz@6458: // goetz@6458: // We have all of the arguments setup at this point. goetz@6458: // We MUST NOT touch any outgoing regs from this point on. goetz@6458: // So if we must call out we must push a new frame. goetz@6458: goetz@6458: // Get current pc for oopmap, and load it patchable relative to global toc. goetz@6458: oopmap_pc = (intptr_t) __ pc(); goetz@6458: __ calculate_address_from_global_toc(r_return_pc, (address)oopmap_pc, true, true, true, true); goetz@6458: goetz@6458: // We use the same pc/oopMap repeatedly when we call out. goetz@6458: oop_maps->add_gc_map(oopmap_pc - start_pc, oop_map); goetz@6458: goetz@6458: // r_return_pc now has the pc loaded that we will use when we finally call goetz@6458: // to native. goetz@6458: goetz@6458: // Make sure that thread is non-volatile; it crosses a bunch of VM calls below. goetz@6458: assert(R16_thread->is_nonvolatile(), "thread must be in non-volatile register"); goetz@6458: goetz@6458: goetz@6458: # if 0 goetz@6458: // DTrace method entry goetz@6458: # endif goetz@6458: goetz@6458: // Lock a synchronized method. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: if (method->is_synchronized()) { goetz@6458: assert(!is_critical_native, "unhandled"); goetz@6458: ConditionRegister r_flag = CCR1; goetz@6458: Register r_oop = r_temp_4; goetz@6458: const Register r_box = r_temp_5; goetz@6458: Label done, locked; goetz@6458: goetz@6458: // Load the oop for the object or class. r_carg2_classorobject contains goetz@6458: // either the handlized oop from the incoming arguments or the handlized goetz@6458: // class mirror (if the method is static). goetz@6458: __ ld(r_oop, 0, r_carg2_classorobject); goetz@6458: goetz@6458: // Get the lock box slot's address. goetz@6458: __ addi(r_box, R1_SP, lock_offset); goetz@6458: goetz@6458: # ifdef ASSERT goetz@6458: if (UseBiasedLocking) { goetz@6458: // Making the box point to itself will make it clear it went unused goetz@6458: // but also be obviously invalid. goetz@6458: __ std(r_box, 0, r_box); goetz@6458: } goetz@6458: # endif // ASSERT goetz@6458: goetz@6458: // Try fastpath for locking. goetz@6458: // fast_lock kills r_temp_1, r_temp_2, r_temp_3. goetz@6458: __ compiler_fast_lock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3); goetz@6458: __ beq(r_flag, locked); goetz@6458: goetz@6458: // None of the above fast optimizations worked so we have to get into the goetz@6458: // slow case of monitor enter. Inline a special case of call_VM that goetz@6458: // disallows any pending_exception. goetz@6458: goetz@6511: // Save argument registers and leave room for C-compatible ABI_REG_ARGS. goetz@6511: int frame_size = frame::abi_reg_args_size + goetz@6458: round_to(total_c_args * wordSize, frame::alignment_in_bytes); goetz@6458: __ mr(R11_scratch1, R1_SP); goetz@6458: RegisterSaver::push_frame_and_save_argument_registers(masm, R12_scratch2, frame_size, total_c_args, out_regs, out_regs2); goetz@6458: goetz@6458: // Do the call. goetz@6458: __ set_last_Java_frame(R11_scratch1, r_return_pc); goetz@6458: assert(r_return_pc->is_nonvolatile(), "expecting return pc to be in non-volatile register"); goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), r_oop, r_box, R16_thread); goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: RegisterSaver::restore_argument_registers_and_pop_frame(masm, frame_size, total_c_args, out_regs, out_regs2); goetz@6458: goetz@6458: __ asm_assert_mem8_is_zero(thread_(pending_exception), goetz@6458: "no pending exception allowed on exit from SharedRuntime::complete_monitor_locking_C", 0); goetz@6458: goetz@6458: __ bind(locked); goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Publish thread state goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Use that pc we placed in r_return_pc a while back as the current frame anchor. goetz@6458: __ set_last_Java_frame(R1_SP, r_return_pc); goetz@6458: goetz@6458: // Transition from _thread_in_Java to _thread_in_native. goetz@6458: __ li(R0, _thread_in_native); goetz@6458: __ release(); goetz@6458: // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); goetz@6458: __ stw(R0, thread_(thread_state)); goetz@6458: if (UseMembar) { goetz@6458: __ fence(); goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // The JNI call goetz@6458: // -------------------------------------------------------------------------- goetz@6511: #if defined(ABI_ELFv2) goetz@6511: __ call_c(native_func, relocInfo::runtime_call_type); goetz@6511: #else goetz@6458: FunctionDescriptor* fd_native_method = (FunctionDescriptor*) native_func; goetz@6458: __ call_c(fd_native_method, relocInfo::runtime_call_type); goetz@6511: #endif goetz@6458: goetz@6458: goetz@6458: // Now, we are back from the native code. goetz@6458: goetz@6458: goetz@6458: // Unpack the native result. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // For int-types, we do any needed sign-extension required. goetz@6458: // Care must be taken that the return values (R3_RET and F1_RET) goetz@6458: // will survive any VM calls for blocking or unlocking. goetz@6458: // An OOP result (handle) is done specially in the slow-path code. goetz@6458: goetz@6458: switch (ret_type) { goetz@6458: case T_VOID: break; // Nothing to do! goetz@6458: case T_FLOAT: break; // Got it where we want it (unless slow-path). goetz@6458: case T_DOUBLE: break; // Got it where we want it (unless slow-path). goetz@6458: case T_LONG: break; // Got it where we want it (unless slow-path). goetz@6458: case T_OBJECT: break; // Really a handle. goetz@6458: // Cannot de-handlize until after reclaiming jvm_lock. goetz@6458: case T_ARRAY: break; goetz@6458: goetz@6458: case T_BOOLEAN: { // 0 -> false(0); !0 -> true(1) goetz@6458: Label skip_modify; goetz@6458: __ cmpwi(CCR0, R3_RET, 0); goetz@6458: __ beq(CCR0, skip_modify); goetz@6458: __ li(R3_RET, 1); goetz@6458: __ bind(skip_modify); goetz@6458: break; goetz@6458: } goetz@6458: case T_BYTE: { // sign extension goetz@6458: __ extsb(R3_RET, R3_RET); goetz@6458: break; goetz@6458: } goetz@6458: case T_CHAR: { // unsigned result goetz@6458: __ andi(R3_RET, R3_RET, 0xffff); goetz@6458: break; goetz@6458: } goetz@6458: case T_SHORT: { // sign extension goetz@6458: __ extsh(R3_RET, R3_RET); goetz@6458: break; goetz@6458: } goetz@6458: case T_INT: // nothing to do goetz@6458: break; goetz@6458: default: goetz@6458: ShouldNotReachHere(); goetz@6458: break; goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Publish thread state goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Switch thread to "native transition" state before reading the goetz@6458: // synchronization state. This additional state is necessary because reading goetz@6458: // and testing the synchronization state is not atomic w.r.t. GC, as this goetz@6458: // scenario demonstrates: goetz@6458: // - Java thread A, in _thread_in_native state, loads _not_synchronized goetz@6458: // and is preempted. goetz@6458: // - VM thread changes sync state to synchronizing and suspends threads goetz@6458: // for GC. goetz@6458: // - Thread A is resumed to finish this native method, but doesn't block goetz@6458: // here since it didn't see any synchronization in progress, and escapes. goetz@6458: goetz@6458: // Transition from _thread_in_native to _thread_in_native_trans. goetz@6458: __ li(R0, _thread_in_native_trans); goetz@6458: __ release(); goetz@6458: // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); goetz@6458: __ stw(R0, thread_(thread_state)); goetz@6458: goetz@6458: goetz@6458: // Must we block? goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Block, if necessary, before resuming in _thread_in_Java state. goetz@6458: // In order for GC to work, don't clear the last_Java_sp until after blocking. goetz@6458: Label after_transition; goetz@6458: { goetz@6458: Label no_block, sync; goetz@6458: goetz@6458: if (os::is_MP()) { goetz@6458: if (UseMembar) { goetz@6458: // Force this write out before the read below. goetz@6458: __ fence(); goetz@6458: } else { goetz@6458: // Write serialization page so VM thread can do a pseudo remote membar. goetz@6458: // We use the current thread pointer to calculate a thread specific goetz@6458: // offset to write to within the page. This minimizes bus traffic goetz@6458: // due to cache line collision. goetz@6458: __ serialize_memory(R16_thread, r_temp_4, r_temp_5); goetz@6458: } goetz@6458: } goetz@6458: goetz@6458: Register sync_state_addr = r_temp_4; goetz@6458: Register sync_state = r_temp_5; goetz@6458: Register suspend_flags = r_temp_6; goetz@6458: goetz@6458: __ load_const(sync_state_addr, SafepointSynchronize::address_of_state(), /*temp*/ sync_state); goetz@6458: goetz@6458: // TODO: PPC port assert(4 == SafepointSynchronize::sz_state(), "unexpected field size"); goetz@6458: __ lwz(sync_state, 0, sync_state_addr); goetz@6458: goetz@6458: // TODO: PPC port assert(4 == Thread::sz_suspend_flags(), "unexpected field size"); goetz@6458: __ lwz(suspend_flags, thread_(suspend_flags)); goetz@6458: goetz@6458: __ acquire(); goetz@6458: goetz@6458: Label do_safepoint; goetz@6458: // No synchronization in progress nor yet synchronized. goetz@6458: __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized); goetz@6458: // Not suspended. goetz@6458: __ cmpwi(CCR1, suspend_flags, 0); goetz@6458: goetz@6458: __ bne(CCR0, sync); goetz@6458: __ beq(CCR1, no_block); goetz@6458: goetz@6458: // Block. Save any potential method result value before the operation and goetz@6458: // use a leaf call to leave the last_Java_frame setup undisturbed. Doing this goetz@6458: // lets us share the oopMap we used when we went native rather than create goetz@6458: // a distinct one for this pc. goetz@6458: __ bind(sync); goetz@6458: goetz@6458: address entry_point = is_critical_native goetz@6458: ? CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition) goetz@6458: : CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans); goetz@6458: save_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: __ call_VM_leaf(entry_point, R16_thread); goetz@6458: restore_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: goetz@6458: if (is_critical_native) { goetz@6458: __ b(after_transition); // No thread state transition here. goetz@6458: } goetz@6458: __ bind(no_block); goetz@6458: } goetz@6458: goetz@6458: // Publish thread state. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Thread state is thread_in_native_trans. Any safepoint blocking has goetz@6458: // already happened so we can now change state to _thread_in_Java. goetz@6458: goetz@6458: // Transition from _thread_in_native_trans to _thread_in_Java. goetz@6458: __ li(R0, _thread_in_Java); goetz@6458: __ release(); goetz@6458: // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); goetz@6458: __ stw(R0, thread_(thread_state)); goetz@6458: if (UseMembar) { goetz@6458: __ fence(); goetz@6458: } goetz@6458: __ bind(after_transition); goetz@6458: goetz@6458: // Reguard any pages if necessary. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: Label no_reguard; goetz@6458: __ lwz(r_temp_1, thread_(stack_guard_state)); goetz@6458: __ cmpwi(CCR0, r_temp_1, JavaThread::stack_guard_yellow_disabled); goetz@6458: __ bne(CCR0, no_reguard); goetz@6458: goetz@6458: save_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)); goetz@6458: restore_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: goetz@6458: __ bind(no_reguard); goetz@6458: goetz@6458: goetz@6458: // Unlock goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: if (method->is_synchronized()) { goetz@6458: goetz@6458: ConditionRegister r_flag = CCR1; goetz@6458: const Register r_oop = r_temp_4; goetz@6458: const Register r_box = r_temp_5; goetz@6458: const Register r_exception = r_temp_6; goetz@6458: Label done; goetz@6458: goetz@6458: // Get oop and address of lock object box. goetz@6458: if (method_is_static) { goetz@6458: assert(klass_offset != -1, ""); goetz@6458: __ ld(r_oop, klass_offset, R1_SP); goetz@6458: } else { goetz@6458: assert(receiver_offset != -1, ""); goetz@6458: __ ld(r_oop, receiver_offset, R1_SP); goetz@6458: } goetz@6458: __ addi(r_box, R1_SP, lock_offset); goetz@6458: goetz@6458: // Try fastpath for unlocking. goetz@6458: __ compiler_fast_unlock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3); goetz@6458: __ beq(r_flag, done); goetz@6458: goetz@6458: // Save and restore any potential method result value around the unlocking operation. goetz@6458: save_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: goetz@6458: // Must save pending exception around the slow-path VM call. Since it's a goetz@6458: // leaf call, the pending exception (if any) can be kept in a register. goetz@6458: __ ld(r_exception, thread_(pending_exception)); goetz@6458: assert(r_exception->is_nonvolatile(), "exception register must be non-volatile"); goetz@6458: __ li(R0, 0); goetz@6458: __ std(R0, thread_(pending_exception)); goetz@6458: goetz@6458: // Slow case of monitor enter. goetz@6458: // Inline a special case of call_VM that disallows any pending_exception. goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), r_oop, r_box); goetz@6458: goetz@6458: __ asm_assert_mem8_is_zero(thread_(pending_exception), goetz@6458: "no pending exception allowed on exit from SharedRuntime::complete_monitor_unlocking_C", 0); goetz@6458: goetz@6458: restore_native_result(masm, ret_type, workspace_slot_offset); goetz@6458: goetz@6458: // Check_forward_pending_exception jump to forward_exception if any pending goetz@6458: // exception is set. The forward_exception routine expects to see the goetz@6458: // exception in pending_exception and not in a register. Kind of clumsy, goetz@6458: // since all folks who branch to forward_exception must have tested goetz@6458: // pending_exception first and hence have it in a register already. goetz@6458: __ std(r_exception, thread_(pending_exception)); goetz@6458: goetz@6458: __ bind(done); goetz@6458: } goetz@6458: goetz@6458: # if 0 goetz@6458: // DTrace method exit goetz@6458: # endif goetz@6458: goetz@6458: // Clear "last Java frame" SP and PC. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: // Unpack oop result. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: if (ret_type == T_OBJECT || ret_type == T_ARRAY) { goetz@6458: Label skip_unboxing; goetz@6458: __ cmpdi(CCR0, R3_RET, 0); goetz@6458: __ beq(CCR0, skip_unboxing); goetz@6458: __ ld(R3_RET, 0, R3_RET); goetz@6458: __ bind(skip_unboxing); goetz@6458: __ verify_oop(R3_RET); goetz@6458: } goetz@6458: goetz@6458: goetz@6458: // Reset handle block. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: if (!is_critical_native) { goetz@6458: __ ld(r_temp_1, thread_(active_handles)); goetz@6458: // TODO: PPC port assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size"); goetz@6458: __ li(r_temp_2, 0); goetz@6458: __ stw(r_temp_2, JNIHandleBlock::top_offset_in_bytes(), r_temp_1); goetz@6458: goetz@6458: goetz@6458: // Check for pending exceptions. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: __ ld(r_temp_2, thread_(pending_exception)); goetz@6458: __ cmpdi(CCR0, r_temp_2, 0); goetz@6458: __ bne(CCR0, handle_pending_exception); goetz@6458: } goetz@6458: goetz@6458: // Return goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: __ pop_frame(); goetz@6458: __ restore_LR_CR(R11); goetz@6458: __ blr(); goetz@6458: goetz@6458: goetz@6458: // Handler for pending exceptions (out-of-line). goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: // Since this is a native call, we know the proper exception handler goetz@6458: // is the empty function. We just pop this frame and then jump to goetz@6458: // forward_exception_entry. goetz@6458: if (!is_critical_native) { goetz@6458: __ align(InteriorEntryAlignment); goetz@6458: __ bind(handle_pending_exception); goetz@6458: goetz@6458: __ pop_frame(); goetz@6458: __ restore_LR_CR(R11); goetz@6458: __ b64_patchable((address)StubRoutines::forward_exception_entry(), goetz@6458: relocInfo::runtime_call_type); goetz@6458: } goetz@6458: goetz@6458: // Handler for a cache miss (out-of-line). goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: if (!method_is_static) { goetz@6458: __ align(InteriorEntryAlignment); goetz@6458: __ bind(ic_miss); goetz@6458: goetz@6458: __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), goetz@6458: relocInfo::runtime_call_type); goetz@6458: } goetz@6458: goetz@6458: // Done. goetz@6458: // -------------------------------------------------------------------------- goetz@6458: goetz@6458: __ flush(); goetz@6458: goetz@6458: nmethod *nm = nmethod::new_native_nmethod(method, goetz@6458: compile_id, goetz@6458: masm->code(), goetz@6458: vep_start_pc-start_pc, goetz@6458: frame_done_pc-start_pc, goetz@6458: stack_slots / VMRegImpl::slots_per_word, goetz@6458: (method_is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)), goetz@6458: in_ByteSize(lock_offset), goetz@6458: oop_maps); goetz@6458: goetz@6458: if (is_critical_native) { goetz@6458: nm->set_lazy_critical_native(true); goetz@6458: } goetz@6458: goetz@6458: return nm; goetz@6458: #else goetz@6458: ShouldNotReachHere(); goetz@6458: return NULL; goetz@6458: #endif // COMPILER2 goetz@6458: } goetz@6458: goetz@6458: // This function returns the adjust size (in number of words) to a c2i adapter goetz@6458: // activation for use during deoptimization. goetz@6458: int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals) { goetz@6458: return round_to((callee_locals - callee_parameters) * Interpreter::stackElementWords, frame::alignment_in_bytes); goetz@6458: } goetz@6458: goetz@6458: uint SharedRuntime::out_preserve_stack_slots() { goetz@6458: #ifdef COMPILER2 goetz@6458: return frame::jit_out_preserve_size / VMRegImpl::stack_slot_size; goetz@6458: #else goetz@6458: return 0; goetz@6458: #endif goetz@6458: } goetz@6458: goetz@6458: #ifdef COMPILER2 goetz@6458: // Frame generation for deopt and uncommon trap blobs. goetz@6458: static void push_skeleton_frame(MacroAssembler* masm, bool deopt, goetz@6458: /* Read */ goetz@6458: Register unroll_block_reg, goetz@6458: /* Update */ goetz@6458: Register frame_sizes_reg, goetz@6458: Register number_of_frames_reg, goetz@6458: Register pcs_reg, goetz@6458: /* Invalidate */ goetz@6458: Register frame_size_reg, goetz@6458: Register pc_reg) { goetz@6458: goetz@6458: __ ld(pc_reg, 0, pcs_reg); goetz@6458: __ ld(frame_size_reg, 0, frame_sizes_reg); goetz@6458: __ std(pc_reg, _abi(lr), R1_SP); goetz@6458: __ push_frame(frame_size_reg, R0/*tmp*/); goetz@6495: #ifdef CC_INTERP goetz@6458: __ std(R1_SP, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); goetz@6495: #else goetz@6512: #ifdef ASSERT goetz@6512: __ load_const_optimized(pc_reg, 0x5afe); goetz@6512: __ std(pc_reg, _ijava_state_neg(ijava_reserved), R1_SP); goetz@6495: #endif goetz@6512: __ std(R1_SP, _ijava_state_neg(sender_sp), R1_SP); goetz@6512: #endif // CC_INTERP goetz@6458: __ addi(number_of_frames_reg, number_of_frames_reg, -1); goetz@6458: __ addi(frame_sizes_reg, frame_sizes_reg, wordSize); goetz@6458: __ addi(pcs_reg, pcs_reg, wordSize); goetz@6458: } goetz@6458: goetz@6458: // Loop through the UnrollBlock info and create new frames. goetz@6458: static void push_skeleton_frames(MacroAssembler* masm, bool deopt, goetz@6458: /* read */ goetz@6458: Register unroll_block_reg, goetz@6458: /* invalidate */ goetz@6458: Register frame_sizes_reg, goetz@6458: Register number_of_frames_reg, goetz@6458: Register pcs_reg, goetz@6458: Register frame_size_reg, goetz@6458: Register pc_reg) { goetz@6458: Label loop; goetz@6458: goetz@6458: // _number_of_frames is of type int (deoptimization.hpp) goetz@6458: __ lwa(number_of_frames_reg, goetz@6458: Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes(), goetz@6458: unroll_block_reg); goetz@6458: __ ld(pcs_reg, goetz@6458: Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes(), goetz@6458: unroll_block_reg); goetz@6458: __ ld(frame_sizes_reg, goetz@6458: Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes(), goetz@6458: unroll_block_reg); goetz@6458: goetz@6458: // stack: (caller_of_deoptee, ...). goetz@6458: goetz@6458: // At this point we either have an interpreter frame or a compiled goetz@6458: // frame on top of stack. If it is a compiled frame we push a new c2i goetz@6458: // adapter here goetz@6458: goetz@6458: // Memorize top-frame stack-pointer. goetz@6458: __ mr(frame_size_reg/*old_sp*/, R1_SP); goetz@6458: goetz@6458: // Resize interpreter top frame OR C2I adapter. goetz@6458: goetz@6458: // At this moment, the top frame (which is the caller of the deoptee) is goetz@6458: // an interpreter frame or a newly pushed C2I adapter or an entry frame. goetz@6458: // The top frame has a TOP_IJAVA_FRAME_ABI and the frame contains the goetz@6458: // outgoing arguments. goetz@6458: // goetz@6458: // In order to push the interpreter frame for the deoptee, we need to goetz@6458: // resize the top frame such that we are able to place the deoptee's goetz@6458: // locals in the frame. goetz@6458: // Additionally, we have to turn the top frame's TOP_IJAVA_FRAME_ABI goetz@6458: // into a valid PARENT_IJAVA_FRAME_ABI. goetz@6458: goetz@6458: __ lwa(R11_scratch1, goetz@6458: Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes(), goetz@6458: unroll_block_reg); goetz@6458: __ neg(R11_scratch1, R11_scratch1); goetz@6458: goetz@6458: // R11_scratch1 contains size of locals for frame resizing. goetz@6458: // R12_scratch2 contains top frame's lr. goetz@6458: goetz@6458: // Resize frame by complete frame size prevents TOC from being goetz@6458: // overwritten by locals. A more stack space saving way would be goetz@6458: // to copy the TOC to its location in the new abi. goetz@6458: __ addi(R11_scratch1, R11_scratch1, - frame::parent_ijava_frame_abi_size); goetz@6458: goetz@6458: // now, resize the frame goetz@6458: __ resize_frame(R11_scratch1, pc_reg/*tmp*/); goetz@6458: goetz@6458: // In the case where we have resized a c2i frame above, the optional goetz@6458: // alignment below the locals has size 32 (why?). goetz@6458: __ std(R12_scratch2, _abi(lr), R1_SP); goetz@6458: goetz@6458: // Initialize initial_caller_sp. goetz@6512: #ifdef CC_INTERP goetz@6458: __ std(frame_size_reg/*old_sp*/, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); goetz@6512: #else goetz@6512: #ifdef ASSERT goetz@6512: __ load_const_optimized(pc_reg, 0x5afe); goetz@6512: __ std(pc_reg, _ijava_state_neg(ijava_reserved), R1_SP); goetz@6512: #endif goetz@6512: __ std(frame_size_reg, _ijava_state_neg(sender_sp), R1_SP); goetz@6512: #endif // CC_INTERP goetz@6458: goetz@6458: #ifdef ASSERT goetz@6458: // Make sure that there is at least one entry in the array. goetz@6458: __ cmpdi(CCR0, number_of_frames_reg, 0); goetz@6458: __ asm_assert_ne("array_size must be > 0", 0x205); goetz@6458: #endif goetz@6458: goetz@6458: // Now push the new interpreter frames. goetz@6458: // goetz@6458: __ bind(loop); goetz@6458: // Allocate a new frame, fill in the pc. goetz@6458: push_skeleton_frame(masm, deopt, goetz@6458: unroll_block_reg, goetz@6458: frame_sizes_reg, goetz@6458: number_of_frames_reg, goetz@6458: pcs_reg, goetz@6458: frame_size_reg, goetz@6458: pc_reg); goetz@6458: __ cmpdi(CCR0, number_of_frames_reg, 0); goetz@6458: __ bne(CCR0, loop); goetz@6458: goetz@6458: // Get the return address pointing into the frame manager. goetz@6458: __ ld(R0, 0, pcs_reg); goetz@6458: // Store it in the top interpreter frame. goetz@6458: __ std(R0, _abi(lr), R1_SP); goetz@6458: // Initialize frame_manager_lr of interpreter top frame. goetz@6495: #ifdef CC_INTERP goetz@6458: __ std(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP); goetz@6495: #endif goetz@6458: } goetz@6458: #endif goetz@6458: goetz@6458: void SharedRuntime::generate_deopt_blob() { goetz@6458: // Allocate space for the code goetz@6458: ResourceMark rm; goetz@6458: // Setup code generation tools goetz@6458: CodeBuffer buffer("deopt_blob", 2048, 1024); goetz@6458: InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer); goetz@6458: Label exec_mode_initialized; goetz@6458: int frame_size_in_words; goetz@6458: OopMap* map = NULL; goetz@6458: OopMapSet *oop_maps = new OopMapSet(); goetz@6458: goetz@6458: // size of ABI112 plus spill slots for R3_RET and F1_RET. goetz@6511: const int frame_size_in_bytes = frame::abi_reg_args_spill_size; goetz@6458: const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); goetz@6458: int first_frame_size_in_bytes = 0; // frame size of "unpack frame" for call to fetch_unroll_info. goetz@6458: goetz@6458: const Register exec_mode_reg = R21_tmp1; goetz@6458: goetz@6458: const address start = __ pc(); goetz@6458: goetz@6458: #ifdef COMPILER2 goetz@6458: // -------------------------------------------------------------------------- goetz@6458: // Prolog for non exception case! goetz@6458: goetz@6458: // We have been called from the deopt handler of the deoptee. goetz@6458: // goetz@6458: // deoptee: goetz@6458: // ... goetz@6458: // call X goetz@6458: // ... goetz@6458: // deopt_handler: call_deopt_stub goetz@6458: // cur. return pc --> ... goetz@6458: // goetz@6458: // So currently SR_LR points behind the call in the deopt handler. goetz@6458: // We adjust it such that it points to the start of the deopt handler. goetz@6458: // The return_pc has been stored in the frame of the deoptee and goetz@6458: // will replace the address of the deopt_handler in the call goetz@6458: // to Deoptimization::fetch_unroll_info below. goetz@6458: // We can't grab a free register here, because all registers may goetz@6458: // contain live values, so let the RegisterSaver do the adjustment goetz@6458: // of the return pc. goetz@6517: const int return_pc_adjustment_no_exception = -HandlerImpl::size_deopt_handler(); goetz@6458: goetz@6458: // Push the "unpack frame" goetz@6458: // Save everything in sight. goetz@6511: map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm, goetz@6511: &first_frame_size_in_bytes, goetz@6511: /*generate_oop_map=*/ true, goetz@6511: return_pc_adjustment_no_exception, goetz@6511: RegisterSaver::return_pc_is_lr); goetz@6458: assert(map != NULL, "OopMap must have been created"); goetz@6458: goetz@6458: __ li(exec_mode_reg, Deoptimization::Unpack_deopt); goetz@6458: // Save exec mode for unpack_frames. goetz@6458: __ b(exec_mode_initialized); goetz@6458: goetz@6458: // -------------------------------------------------------------------------- goetz@6458: // Prolog for exception case goetz@6458: goetz@6458: // An exception is pending. goetz@6458: // We have been called with a return (interpreter) or a jump (exception blob). goetz@6458: // goetz@6458: // - R3_ARG1: exception oop goetz@6458: // - R4_ARG2: exception pc goetz@6458: goetz@6458: int exception_offset = __ pc() - start; goetz@6458: goetz@6458: BLOCK_COMMENT("Prolog for exception case"); goetz@6458: goetz@6458: // The RegisterSaves doesn't need to adjust the return pc for this situation. goetz@6458: const int return_pc_adjustment_exception = 0; goetz@6458: goetz@6458: // Push the "unpack frame". goetz@6458: // Save everything in sight. goetz@6458: assert(R4 == R4_ARG2, "exception pc must be in r4"); goetz@6511: RegisterSaver::push_frame_reg_args_and_save_live_registers(masm, goetz@6511: &first_frame_size_in_bytes, goetz@6511: /*generate_oop_map=*/ false, goetz@6511: return_pc_adjustment_exception, goetz@6511: RegisterSaver::return_pc_is_r4); goetz@6458: goetz@6458: // Deopt during an exception. Save exec mode for unpack_frames. goetz@6458: __ li(exec_mode_reg, Deoptimization::Unpack_exception); goetz@6458: goetz@6458: // Store exception oop and pc in thread (location known to GC). goetz@6458: // This is needed since the call to "fetch_unroll_info()" may safepoint. goetz@6458: __ std(R3_ARG1, in_bytes(JavaThread::exception_oop_offset()), R16_thread); goetz@6458: __ std(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread); goetz@6458: goetz@6458: // fall through goetz@6458: goetz@6458: // -------------------------------------------------------------------------- goetz@6458: __ BIND(exec_mode_initialized); goetz@6458: goetz@6458: { goetz@6458: const Register unroll_block_reg = R22_tmp2; goetz@6458: goetz@6458: // We need to set `last_Java_frame' because `fetch_unroll_info' will goetz@6458: // call `last_Java_frame()'. The value of the pc in the frame is not goetz@6458: // particularly important. It just needs to identify this blob. goetz@6458: __ set_last_Java_frame(R1_SP, noreg); goetz@6458: goetz@6458: // With EscapeAnalysis turned on, this call may safepoint! goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), R16_thread); goetz@6458: address calls_return_pc = __ last_calls_return_pc(); goetz@6458: // Set an oopmap for the call site that describes all our saved registers. goetz@6458: oop_maps->add_gc_map(calls_return_pc - start, map); goetz@6458: goetz@6458: __ reset_last_Java_frame(); goetz@6458: // Save the return value. goetz@6458: __ mr(unroll_block_reg, R3_RET); goetz@6458: goetz@6458: // Restore only the result registers that have been saved goetz@6458: // by save_volatile_registers(...). goetz@6458: RegisterSaver::restore_result_registers(masm, first_frame_size_in_bytes); goetz@6458: goetz@6458: // In excp_deopt_mode, restore and clear exception oop which we goetz@6458: // stored in the thread during exception entry above. The exception goetz@6458: // oop will be the return value of this stub. goetz@6458: Label skip_restore_excp; goetz@6458: __ cmpdi(CCR0, exec_mode_reg, Deoptimization::Unpack_exception); goetz@6458: __ bne(CCR0, skip_restore_excp); goetz@6458: __ ld(R3_RET, in_bytes(JavaThread::exception_oop_offset()), R16_thread); goetz@6458: __ ld(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread); goetz@6458: __ li(R0, 0); goetz@6458: __ std(R0, in_bytes(JavaThread::exception_pc_offset()), R16_thread); goetz@6458: __ std(R0, in_bytes(JavaThread::exception_oop_offset()), R16_thread); goetz@6458: __ BIND(skip_restore_excp); goetz@6458: goetz@6458: // reload narrro_oop_base goetz@6458: if (UseCompressedOops && Universe::narrow_oop_base() != 0) { goetz@6458: __ load_const_optimized(R30, Universe::narrow_oop_base()); goetz@6458: } goetz@6458: goetz@6458: __ pop_frame(); goetz@6458: goetz@6458: // stack: (deoptee, optional i2c, caller of deoptee, ...). goetz@6458: goetz@6458: // pop the deoptee's frame goetz@6458: __ pop_frame(); goetz@6458: goetz@6458: // stack: (caller_of_deoptee, ...). goetz@6458: goetz@6458: // Loop through the `UnrollBlock' info and create interpreter frames. goetz@6458: push_skeleton_frames(masm, true/*deopt*/, goetz@6458: unroll_block_reg, goetz@6458: R23_tmp3, goetz@6458: R24_tmp4, goetz@6458: R25_tmp5, goetz@6458: R26_tmp6, goetz@6458: R27_tmp7); goetz@6458: goetz@6458: // stack: (skeletal interpreter frame, ..., optional skeletal goetz@6458: // interpreter frame, optional c2i, caller of deoptee, ...). goetz@6458: } goetz@6458: goetz@6458: // push an `unpack_frame' taking care of float / int return values. goetz@6458: __ push_frame(frame_size_in_bytes, R0/*tmp*/); goetz@6458: goetz@6458: // stack: (unpack frame, skeletal interpreter frame, ..., optional goetz@6458: // skeletal interpreter frame, optional c2i, caller of deoptee, goetz@6458: // ...). goetz@6458: goetz@6458: // Spill live volatile registers since we'll do a call. goetz@6511: __ std( R3_RET, _abi_reg_args_spill(spill_ret), R1_SP); goetz@6511: __ stfd(F1_RET, _abi_reg_args_spill(spill_fret), R1_SP); goetz@6458: goetz@6458: // Let the unpacker layout information in the skeletal frames just goetz@6458: // allocated. goetz@6458: __ get_PC_trash_LR(R3_RET); goetz@6458: __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R3_RET); goetz@6458: // This is a call to a LEAF method, so no oop map is required. goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), goetz@6458: R16_thread/*thread*/, exec_mode_reg/*exec_mode*/); goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: // Restore the volatiles saved above. goetz@6511: __ ld( R3_RET, _abi_reg_args_spill(spill_ret), R1_SP); goetz@6511: __ lfd(F1_RET, _abi_reg_args_spill(spill_fret), R1_SP); goetz@6458: goetz@6458: // Pop the unpack frame. goetz@6458: __ pop_frame(); goetz@6458: __ restore_LR_CR(R0); goetz@6458: goetz@6458: // stack: (top interpreter frame, ..., optional interpreter frame, goetz@6458: // optional c2i, caller of deoptee, ...). goetz@6458: goetz@6458: // Initialize R14_state. goetz@6512: #ifdef CC_INTERP goetz@6458: __ ld(R14_state, 0, R1_SP); goetz@6495: __ addi(R14_state, R14_state, -frame::interpreter_frame_cinterpreterstate_size_in_bytes()); goetz@6458: // Also inititialize R15_prev_state. goetz@6458: __ restore_prev_state(); goetz@6512: #else goetz@6512: __ restore_interpreter_state(R11_scratch1); goetz@6512: __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1); goetz@6512: #endif // CC_INTERP goetz@6512: goetz@6458: goetz@6458: // Return to the interpreter entry point. goetz@6458: __ blr(); goetz@6458: __ flush(); goetz@6458: #else // COMPILER2 goetz@6458: __ unimplemented("deopt blob needed only with compiler"); goetz@6458: int exception_offset = __ pc() - start; goetz@6458: #endif // COMPILER2 goetz@6458: goetz@6458: _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, 0, first_frame_size_in_bytes / wordSize); goetz@6458: } goetz@6458: goetz@6458: #ifdef COMPILER2 goetz@6458: void SharedRuntime::generate_uncommon_trap_blob() { goetz@6458: // Allocate space for the code. goetz@6458: ResourceMark rm; goetz@6458: // Setup code generation tools. goetz@6458: CodeBuffer buffer("uncommon_trap_blob", 2048, 1024); goetz@6458: InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer); goetz@6458: address start = __ pc(); goetz@6458: goetz@6458: Register unroll_block_reg = R21_tmp1; goetz@6458: Register klass_index_reg = R22_tmp2; goetz@6458: Register unc_trap_reg = R23_tmp3; goetz@6458: goetz@6458: OopMapSet* oop_maps = new OopMapSet(); goetz@6511: int frame_size_in_bytes = frame::abi_reg_args_size; goetz@6458: OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); goetz@6458: goetz@6458: // stack: (deoptee, optional i2c, caller_of_deoptee, ...). goetz@6458: goetz@6458: // Push a dummy `unpack_frame' and call goetz@6458: // `Deoptimization::uncommon_trap' to pack the compiled frame into a goetz@6458: // vframe array and return the `UnrollBlock' information. goetz@6458: goetz@6458: // Save LR to compiled frame. goetz@6458: __ save_LR_CR(R11_scratch1); goetz@6458: goetz@6458: // Push an "uncommon_trap" frame. goetz@6511: __ push_frame_reg_args(0, R11_scratch1); goetz@6458: goetz@6458: // stack: (unpack frame, deoptee, optional i2c, caller_of_deoptee, ...). goetz@6458: goetz@6458: // Set the `unpack_frame' as last_Java_frame. goetz@6458: // `Deoptimization::uncommon_trap' expects it and considers its goetz@6458: // sender frame as the deoptee frame. goetz@6458: // Remember the offset of the instruction whose address will be goetz@6458: // moved to R11_scratch1. goetz@6458: address gc_map_pc = __ get_PC_trash_LR(R11_scratch1); goetz@6458: goetz@6458: __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R11_scratch1); goetz@6458: goetz@6458: __ mr(klass_index_reg, R3); goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::uncommon_trap), goetz@6458: R16_thread, klass_index_reg); goetz@6458: goetz@6458: // Set an oopmap for the call site. goetz@6458: oop_maps->add_gc_map(gc_map_pc - start, map); goetz@6458: goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: // Pop the `unpack frame'. goetz@6458: __ pop_frame(); goetz@6458: goetz@6458: // stack: (deoptee, optional i2c, caller_of_deoptee, ...). goetz@6458: goetz@6458: // Save the return value. goetz@6458: __ mr(unroll_block_reg, R3_RET); goetz@6458: goetz@6458: // Pop the uncommon_trap frame. goetz@6458: __ pop_frame(); goetz@6458: goetz@6458: // stack: (caller_of_deoptee, ...). goetz@6458: goetz@6458: // Allocate new interpreter frame(s) and possibly a c2i adapter goetz@6458: // frame. goetz@6458: push_skeleton_frames(masm, false/*deopt*/, goetz@6458: unroll_block_reg, goetz@6458: R22_tmp2, goetz@6458: R23_tmp3, goetz@6458: R24_tmp4, goetz@6458: R25_tmp5, goetz@6458: R26_tmp6); goetz@6458: goetz@6458: // stack: (skeletal interpreter frame, ..., optional skeletal goetz@6458: // interpreter frame, optional c2i, caller of deoptee, ...). goetz@6458: goetz@6458: // Push a dummy `unpack_frame' taking care of float return values. goetz@6458: // Call `Deoptimization::unpack_frames' to layout information in the goetz@6458: // interpreter frames just created. goetz@6458: goetz@6458: // Push a simple "unpack frame" here. goetz@6511: __ push_frame_reg_args(0, R11_scratch1); goetz@6458: goetz@6458: // stack: (unpack frame, skeletal interpreter frame, ..., optional goetz@6458: // skeletal interpreter frame, optional c2i, caller of deoptee, goetz@6458: // ...). goetz@6458: goetz@6458: // Set the "unpack_frame" as last_Java_frame. goetz@6458: __ get_PC_trash_LR(R11_scratch1); goetz@6458: __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R11_scratch1); goetz@6458: goetz@6458: // Indicate it is the uncommon trap case. goetz@6458: __ li(unc_trap_reg, Deoptimization::Unpack_uncommon_trap); goetz@6458: // Let the unpacker layout information in the skeletal frames just goetz@6458: // allocated. goetz@6458: __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), goetz@6458: R16_thread, unc_trap_reg); goetz@6458: goetz@6458: __ reset_last_Java_frame(); goetz@6458: // Pop the `unpack frame'. goetz@6458: __ pop_frame(); goetz@6458: // Restore LR from top interpreter frame. goetz@6458: __ restore_LR_CR(R11_scratch1); goetz@6458: goetz@6458: // stack: (top interpreter frame, ..., optional interpreter frame, goetz@6458: // optional c2i, caller of deoptee, ...). goetz@6458: goetz@6512: #ifdef CC_INTERP goetz@6458: // Initialize R14_state, ... goetz@6458: __ ld(R11_scratch1, 0, R1_SP); goetz@6495: __ addi(R14_state, R11_scratch1, -frame::interpreter_frame_cinterpreterstate_size_in_bytes()); goetz@6458: // also initialize R15_prev_state. goetz@6458: __ restore_prev_state(); goetz@6512: #else goetz@6512: __ restore_interpreter_state(R11_scratch1); goetz@6512: __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1); goetz@6512: #endif // CC_INTERP goetz@6512: goetz@6458: // Return to the interpreter entry point. goetz@6458: __ blr(); goetz@6458: goetz@6458: masm->flush(); goetz@6458: goetz@6458: _uncommon_trap_blob = UncommonTrapBlob::create(&buffer, oop_maps, frame_size_in_bytes/wordSize); goetz@6458: } goetz@6458: #endif // COMPILER2 goetz@6458: goetz@6458: // Generate a special Compile2Runtime blob that saves all registers, and setup oopmap. goetz@6458: SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_type) { goetz@6458: assert(StubRoutines::forward_exception_entry() != NULL, goetz@6458: "must be generated before"); goetz@6458: goetz@6458: ResourceMark rm; goetz@6458: OopMapSet *oop_maps = new OopMapSet(); goetz@6458: OopMap* map; goetz@6458: goetz@6458: // Allocate space for the code. Setup code generation tools. goetz@6458: CodeBuffer buffer("handler_blob", 2048, 1024); goetz@6458: MacroAssembler* masm = new MacroAssembler(&buffer); goetz@6458: goetz@6458: address start = __ pc(); goetz@6458: int frame_size_in_bytes = 0; goetz@6458: goetz@6458: RegisterSaver::ReturnPCLocation return_pc_location; goetz@6458: bool cause_return = (poll_type == POLL_AT_RETURN); goetz@6458: if (cause_return) { goetz@6458: // Nothing to do here. The frame has already been popped in MachEpilogNode. goetz@6458: // Register LR already contains the return pc. goetz@6458: return_pc_location = RegisterSaver::return_pc_is_lr; goetz@6458: } else { goetz@6458: // Use thread()->saved_exception_pc() as return pc. goetz@6458: return_pc_location = RegisterSaver::return_pc_is_thread_saved_exception_pc; goetz@6458: } goetz@6458: goetz@6458: // Save registers, fpu state, and flags. goetz@6511: map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm, goetz@6511: &frame_size_in_bytes, goetz@6511: /*generate_oop_map=*/ true, goetz@6511: /*return_pc_adjustment=*/0, goetz@6511: return_pc_location); goetz@6458: goetz@6458: // The following is basically a call_VM. However, we need the precise goetz@6458: // address of the call in order to generate an oopmap. Hence, we do all the goetz@6458: // work outselves. goetz@6458: __ set_last_Java_frame(/*sp=*/R1_SP, /*pc=*/noreg); goetz@6458: goetz@6458: // The return address must always be correct so that the frame constructor goetz@6458: // never sees an invalid pc. goetz@6458: goetz@6458: // Do the call goetz@6458: __ call_VM_leaf(call_ptr, R16_thread); goetz@6458: address calls_return_pc = __ last_calls_return_pc(); goetz@6458: goetz@6458: // Set an oopmap for the call site. This oopmap will map all goetz@6458: // oop-registers and debug-info registers as callee-saved. This goetz@6458: // will allow deoptimization at this safepoint to find all possible goetz@6458: // debug-info recordings, as well as let GC find all oops. goetz@6458: oop_maps->add_gc_map(calls_return_pc - start, map); goetz@6458: goetz@6458: Label noException; goetz@6458: goetz@6458: // Clear the last Java frame. goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: BLOCK_COMMENT(" Check pending exception."); goetz@6458: const Register pending_exception = R0; goetz@6458: __ ld(pending_exception, thread_(pending_exception)); goetz@6458: __ cmpdi(CCR0, pending_exception, 0); goetz@6458: __ beq(CCR0, noException); goetz@6458: goetz@6458: // Exception pending goetz@6458: RegisterSaver::restore_live_registers_and_pop_frame(masm, goetz@6458: frame_size_in_bytes, goetz@6458: /*restore_ctr=*/true); goetz@6458: goetz@6458: BLOCK_COMMENT(" Jump to forward_exception_entry."); goetz@6458: // Jump to forward_exception_entry, with the issuing PC in LR goetz@6458: // so it looks like the original nmethod called forward_exception_entry. goetz@6458: __ b64_patchable(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); goetz@6458: goetz@6458: // No exception case. goetz@6458: __ BIND(noException); goetz@6458: goetz@6458: goetz@6458: // Normal exit, restore registers and exit. goetz@6458: RegisterSaver::restore_live_registers_and_pop_frame(masm, goetz@6458: frame_size_in_bytes, goetz@6458: /*restore_ctr=*/true); goetz@6458: goetz@6458: __ blr(); goetz@6458: goetz@6458: // Make sure all code is generated goetz@6458: masm->flush(); goetz@6458: goetz@6458: // Fill-out other meta info goetz@6458: // CodeBlob frame size is in words. goetz@6458: return SafepointBlob::create(&buffer, oop_maps, frame_size_in_bytes / wordSize); goetz@6458: } goetz@6458: goetz@6458: // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss) goetz@6458: // goetz@6458: // Generate a stub that calls into the vm to find out the proper destination goetz@6458: // of a java call. All the argument registers are live at this point goetz@6458: // but since this is generic code we don't know what they are and the caller goetz@6458: // must do any gc of the args. goetz@6458: // goetz@6458: RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) { goetz@6458: goetz@6458: // allocate space for the code goetz@6458: ResourceMark rm; goetz@6458: goetz@6458: CodeBuffer buffer(name, 1000, 512); goetz@6458: MacroAssembler* masm = new MacroAssembler(&buffer); goetz@6458: goetz@6458: int frame_size_in_bytes; goetz@6458: goetz@6458: OopMapSet *oop_maps = new OopMapSet(); goetz@6458: OopMap* map = NULL; goetz@6458: goetz@6458: address start = __ pc(); goetz@6458: goetz@6511: map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm, goetz@6511: &frame_size_in_bytes, goetz@6511: /*generate_oop_map*/ true, goetz@6511: /*return_pc_adjustment*/ 0, goetz@6511: RegisterSaver::return_pc_is_lr); goetz@6458: goetz@6458: // Use noreg as last_Java_pc, the return pc will be reconstructed goetz@6458: // from the physical frame. goetz@6458: __ set_last_Java_frame(/*sp*/R1_SP, noreg); goetz@6458: goetz@6458: int frame_complete = __ offset(); goetz@6458: goetz@6458: // Pass R19_method as 2nd (optional) argument, used by goetz@6458: // counter_overflow_stub. goetz@6458: __ call_VM_leaf(destination, R16_thread, R19_method); goetz@6458: address calls_return_pc = __ last_calls_return_pc(); goetz@6458: // Set an oopmap for the call site. goetz@6458: // We need this not only for callee-saved registers, but also for volatile goetz@6458: // registers that the compiler might be keeping live across a safepoint. goetz@6458: // Create the oopmap for the call's return pc. goetz@6458: oop_maps->add_gc_map(calls_return_pc - start, map); goetz@6458: goetz@6458: // R3_RET contains the address we are going to jump to assuming no exception got installed. goetz@6458: goetz@6458: // clear last_Java_sp goetz@6458: __ reset_last_Java_frame(); goetz@6458: goetz@6458: // Check for pending exceptions. goetz@6458: BLOCK_COMMENT("Check for pending exceptions."); goetz@6458: Label pending; goetz@6458: __ ld(R11_scratch1, thread_(pending_exception)); goetz@6458: __ cmpdi(CCR0, R11_scratch1, 0); goetz@6458: __ bne(CCR0, pending); goetz@6458: goetz@6458: __ mtctr(R3_RET); // Ctr will not be touched by restore_live_registers_and_pop_frame. goetz@6458: goetz@6458: RegisterSaver::restore_live_registers_and_pop_frame(masm, frame_size_in_bytes, /*restore_ctr*/ false); goetz@6458: goetz@6512: // Get the returned method. goetz@6458: __ get_vm_result_2(R19_method); goetz@6458: goetz@6458: __ bctr(); goetz@6458: goetz@6458: goetz@6458: // Pending exception after the safepoint. goetz@6458: __ BIND(pending); goetz@6458: goetz@6458: RegisterSaver::restore_live_registers_and_pop_frame(masm, frame_size_in_bytes, /*restore_ctr*/ true); goetz@6458: goetz@6458: // exception pending => remove activation and forward to exception handler goetz@6458: goetz@6458: __ li(R11_scratch1, 0); goetz@6458: __ ld(R3_ARG1, thread_(pending_exception)); goetz@6458: __ std(R11_scratch1, in_bytes(JavaThread::vm_result_offset()), R16_thread); goetz@6458: __ b64_patchable(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); goetz@6458: goetz@6458: // ------------- goetz@6458: // Make sure all code is generated. goetz@6458: masm->flush(); goetz@6458: goetz@6458: // return the blob goetz@6458: // frame_size_words or bytes?? goetz@6458: return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_bytes/wordSize, goetz@6458: oop_maps, true); goetz@6458: }