Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/ppc/vm/cppInterpreter_ppc.cpp
32285 views
1/*2* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.3* Copyright 2012, 2014 SAP AG. All rights reserved.4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5*6* This code is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License version 2 only, as8* published by the Free Software Foundation.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*24*/2526#include "precompiled.hpp"27#include "asm/assembler.hpp"28#include "asm/macroAssembler.inline.hpp"29#include "interpreter/bytecodeHistogram.hpp"30#include "interpreter/cppInterpreter.hpp"31#include "interpreter/interpreter.hpp"32#include "interpreter/interpreterGenerator.hpp"33#include "interpreter/interpreterRuntime.hpp"34#include "oops/arrayOop.hpp"35#include "oops/methodData.hpp"36#include "oops/method.hpp"37#include "oops/oop.inline.hpp"38#include "prims/jvmtiExport.hpp"39#include "prims/jvmtiThreadState.hpp"40#include "runtime/arguments.hpp"41#include "runtime/deoptimization.hpp"42#include "runtime/frame.inline.hpp"43#include "runtime/interfaceSupport.hpp"44#include "runtime/sharedRuntime.hpp"45#include "runtime/stubRoutines.hpp"46#include "runtime/synchronizer.hpp"47#include "runtime/timer.hpp"48#include "runtime/vframeArray.hpp"49#include "utilities/debug.hpp"50#ifdef SHARK51#include "shark/shark_globals.hpp"52#endif5354#ifdef CC_INTERP5556#define __ _masm->5758// Contains is used for identifying interpreter frames during a stack-walk.59// A frame with a PC in InterpretMethod must be identified as a normal C frame.60bool CppInterpreter::contains(address pc) {61return _code->contains(pc);62}6364#ifdef PRODUCT65#define BLOCK_COMMENT(str) // nothing66#else67#define BLOCK_COMMENT(str) __ block_comment(str)68#endif6970#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")7172static address interpreter_frame_manager = NULL;73static address frame_manager_specialized_return = NULL;74static address native_entry = NULL;7576static address interpreter_return_address = NULL;7778static address unctrap_frame_manager_entry = NULL;7980static address deopt_frame_manager_return_atos = NULL;81static address deopt_frame_manager_return_btos = NULL;82static address deopt_frame_manager_return_itos = NULL;83static address deopt_frame_manager_return_ltos = NULL;84static address deopt_frame_manager_return_ftos = NULL;85static address deopt_frame_manager_return_dtos = NULL;86static address deopt_frame_manager_return_vtos = NULL;8788// A result handler converts/unboxes a native call result into89// a java interpreter/compiler result. The current frame is an90// interpreter frame.91address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {92return AbstractInterpreterGenerator::generate_result_handler_for(type);93}9495// tosca based result to c++ interpreter stack based result.96address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {97//98// A result is in the native abi result register from a native99// method call. We need to return this result to the interpreter by100// pushing the result on the interpreter's stack.101//102// Registers alive:103// R3_ARG1(R3_RET)/F1_ARG1(F1_RET) - result to move104// R4_ARG2 - address of tos105// LR106//107// Registers updated:108// R3_RET(R3_ARG1) - address of new tos (== R17_tos for T_VOID)109//110111int number_of_used_slots = 1;112113const Register tos = R4_ARG2;114Label done;115Label is_false;116117address entry = __ pc();118119switch (type) {120case T_BOOLEAN:121__ cmpwi(CCR0, R3_RET, 0);122__ beq(CCR0, is_false);123__ li(R3_RET, 1);124__ stw(R3_RET, 0, tos);125__ b(done);126__ bind(is_false);127__ li(R3_RET, 0);128__ stw(R3_RET, 0, tos);129break;130case T_BYTE:131case T_CHAR:132case T_SHORT:133case T_INT:134__ stw(R3_RET, 0, tos);135break;136case T_LONG:137number_of_used_slots = 2;138// mark unused slot for debugging139// long goes to topmost slot140__ std(R3_RET, -BytesPerWord, tos);141__ li(R3_RET, 0);142__ std(R3_RET, 0, tos);143break;144case T_OBJECT:145__ verify_oop(R3_RET);146__ std(R3_RET, 0, tos);147break;148case T_FLOAT:149__ stfs(F1_RET, 0, tos);150break;151case T_DOUBLE:152number_of_used_slots = 2;153// mark unused slot for debugging154__ li(R3_RET, 0);155__ std(R3_RET, 0, tos);156// double goes to topmost slot157__ stfd(F1_RET, -BytesPerWord, tos);158break;159case T_VOID:160number_of_used_slots = 0;161break;162default:163ShouldNotReachHere();164}165166__ BIND(done);167168// new expression stack top169__ addi(R3_RET, tos, -BytesPerWord * number_of_used_slots);170171__ blr();172173return entry;174}175176address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {177//178// Copy the result from the callee's stack to the caller's stack,179// caller and callee both being interpreted.180//181// Registers alive182// R3_ARG1 - address of callee's tos + BytesPerWord183// R4_ARG2 - address of caller's tos [i.e. free location]184// LR185//186// stack grows upwards, memory grows downwards.187//188// [ free ] <-- callee's tos189// [ optional result ] <-- R3_ARG1190// [ optional dummy ]191// ...192// [ free ] <-- caller's tos, R4_ARG2193// ...194// Registers updated195// R3_RET(R3_ARG1) - address of caller's new tos196//197// stack grows upwards, memory grows downwards.198//199// [ free ] <-- current tos, R3_RET200// [ optional result ]201// [ optional dummy ]202// ...203//204205const Register from = R3_ARG1;206const Register ret = R3_ARG1;207const Register tos = R4_ARG2;208const Register tmp1 = R21_tmp1;209const Register tmp2 = R22_tmp2;210211address entry = __ pc();212213switch (type) {214case T_BOOLEAN:215case T_BYTE:216case T_CHAR:217case T_SHORT:218case T_INT:219case T_FLOAT:220__ lwz(tmp1, 0, from);221__ stw(tmp1, 0, tos);222// New expression stack top.223__ addi(ret, tos, - BytesPerWord);224break;225case T_LONG:226case T_DOUBLE:227// Move both entries for debug purposes even though only one is live.228__ ld(tmp1, BytesPerWord, from);229__ ld(tmp2, 0, from);230__ std(tmp1, 0, tos);231__ std(tmp2, -BytesPerWord, tos);232// New expression stack top.233__ addi(ret, tos, - 2 * BytesPerWord); // two slots234break;235case T_OBJECT:236__ ld(tmp1, 0, from);237__ verify_oop(tmp1);238__ std(tmp1, 0, tos);239// New expression stack top.240__ addi(ret, tos, - BytesPerWord);241break;242case T_VOID:243// New expression stack top.244__ mr(ret, tos);245break;246default:247ShouldNotReachHere();248}249250__ blr();251252return entry;253}254255address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {256//257// Load a result from the callee's stack into the caller's expecting258// return register, callee being interpreted, caller being call stub259// or jit code.260//261// Registers alive262// R3_ARG1 - callee expression tos + BytesPerWord263// LR264//265// stack grows upwards, memory grows downwards.266//267// [ free ] <-- callee's tos268// [ optional result ] <-- R3_ARG1269// [ optional dummy ]270// ...271//272// Registers updated273// R3_RET(R3_ARG1)/F1_RET - result274//275276const Register from = R3_ARG1;277const Register ret = R3_ARG1;278const FloatRegister fret = F1_ARG1;279280address entry = __ pc();281282// Implemented uniformly for both kinds of endianness. The interpreter283// implements boolean, byte, char, and short as jint (4 bytes).284switch (type) {285case T_BOOLEAN:286case T_CHAR:287// zero extension288__ lwz(ret, 0, from);289break;290case T_BYTE:291case T_SHORT:292case T_INT:293// sign extension294__ lwa(ret, 0, from);295break;296case T_LONG:297__ ld(ret, 0, from);298break;299case T_OBJECT:300__ ld(ret, 0, from);301__ verify_oop(ret);302break;303case T_FLOAT:304__ lfs(fret, 0, from);305break;306case T_DOUBLE:307__ lfd(fret, 0, from);308break;309case T_VOID:310break;311default:312ShouldNotReachHere();313}314315__ blr();316317return entry;318}319320address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {321assert(interpreter_return_address != NULL, "Not initialized");322return interpreter_return_address;323}324325address CppInterpreter::deopt_entry(TosState state, int length) {326address ret = NULL;327if (length != 0) {328switch (state) {329case atos: ret = deopt_frame_manager_return_atos; break;330case btos: ret = deopt_frame_manager_return_itos; break;331case ctos:332case stos:333case itos: ret = deopt_frame_manager_return_itos; break;334case ltos: ret = deopt_frame_manager_return_ltos; break;335case ftos: ret = deopt_frame_manager_return_ftos; break;336case dtos: ret = deopt_frame_manager_return_dtos; break;337case vtos: ret = deopt_frame_manager_return_vtos; break;338default: ShouldNotReachHere();339}340} else {341ret = unctrap_frame_manager_entry; // re-execute the bytecode (e.g. uncommon trap, popframe)342}343assert(ret != NULL, "Not initialized");344return ret;345}346347//348// Helpers for commoning out cases in the various type of method entries.349//350351//352// Registers alive353// R16_thread - JavaThread*354// R1_SP - old stack pointer355// R19_method - callee's Method356// R17_tos - address of caller's tos (prepushed)357// R15_prev_state - address of caller's BytecodeInterpreter or 0358// return_pc in R21_tmp15 (only when called within generate_native_entry)359//360// Registers updated361// R14_state - address of callee's interpreter state362// R1_SP - new stack pointer363// CCR4_is_synced - current method is synchronized364//365void CppInterpreterGenerator::generate_compute_interpreter_state(Label& stack_overflow_return) {366//367// Stack layout at this point:368//369// F1 [TOP_IJAVA_FRAME_ABI] <-- R1_SP370// alignment (optional)371// [F1's outgoing Java arguments] <-- R17_tos372// ...373// F2 [PARENT_IJAVA_FRAME_ABI]374// ...375376//=============================================================================377// Allocate space for locals other than the parameters, the378// interpreter state, monitors, and the expression stack.379380const Register local_count = R21_tmp1;381const Register parameter_count = R22_tmp2;382const Register max_stack = R23_tmp3;383// Must not be overwritten within this method!384// const Register return_pc = R29_tmp9;385386const ConditionRegister is_synced = CCR4_is_synced;387const ConditionRegister is_native = CCR6;388const ConditionRegister is_static = CCR7;389390assert(is_synced != is_native, "condition code registers must be distinct");391assert(is_synced != is_static, "condition code registers must be distinct");392assert(is_native != is_static, "condition code registers must be distinct");393394{395396// Local registers397const Register top_frame_size = R24_tmp4;398const Register access_flags = R25_tmp5;399const Register state_offset = R26_tmp6;400Register mem_stack_limit = R27_tmp7;401const Register page_size = R28_tmp8;402403BLOCK_COMMENT("compute_interpreter_state {");404405// access_flags = method->access_flags();406// TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");407__ lwa(access_flags, method_(access_flags));408409// parameter_count = method->constMethod->size_of_parameters();410// TODO: PPC port: assert(2 == ConstMethod::sz_size_of_parameters(), "unexpected field size");411__ ld(max_stack, in_bytes(Method::const_offset()), R19_method); // Max_stack holds constMethod for a while.412__ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), max_stack);413414// local_count = method->constMethod()->max_locals();415// TODO: PPC port: assert(2 == ConstMethod::sz_max_locals(), "unexpected field size");416__ lhz(local_count, in_bytes(ConstMethod::size_of_locals_offset()), max_stack);417418// max_stack = method->constMethod()->max_stack();419// TODO: PPC port: assert(2 == ConstMethod::sz_max_stack(), "unexpected field size");420__ lhz(max_stack, in_bytes(ConstMethod::max_stack_offset()), max_stack);421422if (EnableInvokeDynamic) {423// Take into account 'extra_stack_entries' needed by method handles (see method.hpp).424__ addi(max_stack, max_stack, Method::extra_stack_entries());425}426427// mem_stack_limit = thread->stack_limit();428__ ld(mem_stack_limit, thread_(stack_overflow_limit));429430// Point locals at the first argument. Method's locals are the431// parameters on top of caller's expression stack.432433// tos points past last Java argument434__ sldi(R18_locals, parameter_count, Interpreter::logStackElementSize);435__ add(R18_locals, R17_tos, R18_locals);436437// R18_locals - i*BytesPerWord points to i-th Java local (i starts at 0)438439// Set is_native, is_synced, is_static - will be used later.440__ testbitdi(is_native, R0, access_flags, JVM_ACC_NATIVE_BIT);441__ testbitdi(is_synced, R0, access_flags, JVM_ACC_SYNCHRONIZED_BIT);442assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");443__ testbitdi(is_static, R0, access_flags, JVM_ACC_STATIC_BIT);444445// PARENT_IJAVA_FRAME_ABI446//447// frame_size =448// round_to((local_count - parameter_count)*BytesPerWord +449// 2*BytesPerWord +450// alignment +451// frame::interpreter_frame_cinterpreterstate_size_in_bytes()452// sizeof(PARENT_IJAVA_FRAME_ABI)453// method->is_synchronized() ? sizeof(BasicObjectLock) : 0 +454// max_stack*BytesPerWord,455// 16)456//457// Note that this calculation is exactly mirrored by458// AbstractInterpreter::layout_activation_impl() [ and459// AbstractInterpreter::size_activation() ]. Which is used by460// deoptimization so that it can allocate the proper sized461// frame. This only happens for interpreted frames so the extra462// notes below about max_stack below are not important. The other463// thing to note is that for interpreter frames other than the464// current activation the size of the stack is the size of the live465// portion of the stack at the particular bcp and NOT the maximum466// stack that the method might use.467//468// If we're calling a native method, we replace max_stack (which is469// zero) with space for the worst-case signature handler varargs470// vector, which is:471//472// max_stack = max(Argument::n_register_parameters, parameter_count+2);473//474// We add two slots to the parameter_count, one for the jni475// environment and one for a possible native mirror. We allocate476// space for at least the number of ABI registers, even though477// InterpreterRuntime::slow_signature_handler won't write more than478// parameter_count+2 words when it creates the varargs vector at the479// top of the stack. The generated slow signature handler will just480// load trash into registers beyond the necessary number. We're481// still going to cut the stack back by the ABI register parameter482// count so as to get SP+16 pointing at the ABI outgoing parameter483// area, so we need to allocate at least that much even though we're484// going to throw it away.485//486487// Adjust max_stack for native methods:488Label skip_native_calculate_max_stack;489__ bfalse(is_native, skip_native_calculate_max_stack);490// if (is_native) {491// max_stack = max(Argument::n_register_parameters, parameter_count+2);492__ addi(max_stack, parameter_count, 2*Interpreter::stackElementWords);493__ cmpwi(CCR0, max_stack, Argument::n_register_parameters);494__ bge(CCR0, skip_native_calculate_max_stack);495__ li(max_stack, Argument::n_register_parameters);496// }497__ bind(skip_native_calculate_max_stack);498// max_stack is now in bytes499__ slwi(max_stack, max_stack, Interpreter::logStackElementSize);500501// Calculate number of non-parameter locals (in slots):502Label not_java;503__ btrue(is_native, not_java);504// if (!is_native) {505// local_count = non-parameter local count506__ sub(local_count, local_count, parameter_count);507// } else {508// // nothing to do: method->max_locals() == 0 for native methods509// }510__ bind(not_java);511512513// Calculate top_frame_size and parent_frame_resize.514{515const Register parent_frame_resize = R12_scratch2;516517BLOCK_COMMENT("Compute top_frame_size.");518// top_frame_size = TOP_IJAVA_FRAME_ABI519// + size of interpreter state520__ li(top_frame_size, frame::top_ijava_frame_abi_size521+ frame::interpreter_frame_cinterpreterstate_size_in_bytes());522// + max_stack523__ add(top_frame_size, top_frame_size, max_stack);524// + stack slots for a BasicObjectLock for synchronized methods525{526Label not_synced;527__ bfalse(is_synced, not_synced);528__ addi(top_frame_size, top_frame_size, frame::interpreter_frame_monitor_size_in_bytes());529__ bind(not_synced);530}531// align532__ round_to(top_frame_size, frame::alignment_in_bytes);533534535BLOCK_COMMENT("Compute parent_frame_resize.");536// parent_frame_resize = R1_SP - R17_tos537__ sub(parent_frame_resize, R1_SP, R17_tos);538//__ li(parent_frame_resize, 0);539// + PARENT_IJAVA_FRAME_ABI540// + extra two slots for the no-parameter/no-locals541// method result542__ addi(parent_frame_resize, parent_frame_resize,543frame::parent_ijava_frame_abi_size544+ 2*Interpreter::stackElementSize);545// + (locals_count - params_count)546__ sldi(R0, local_count, Interpreter::logStackElementSize);547__ add(parent_frame_resize, parent_frame_resize, R0);548// align549__ round_to(parent_frame_resize, frame::alignment_in_bytes);550551//552// Stack layout at this point:553//554// The new frame F0 hasn't yet been pushed, F1 is still the top frame.555//556// F0 [TOP_IJAVA_FRAME_ABI]557// alignment (optional)558// [F0's full operand stack]559// [F0's monitors] (optional)560// [F0's BytecodeInterpreter object]561// F1 [PARENT_IJAVA_FRAME_ABI]562// alignment (optional)563// [F0's Java result]564// [F0's non-arg Java locals]565// [F1's outgoing Java arguments] <-- R17_tos566// ...567// F2 [PARENT_IJAVA_FRAME_ABI]568// ...569570571// Calculate new R14_state572// and573// test that the new memory stack pointer is above the limit,574// throw a StackOverflowError otherwise.575__ sub(R11_scratch1/*F1's SP*/, R1_SP, parent_frame_resize);576__ addi(R14_state, R11_scratch1/*F1's SP*/,577-frame::interpreter_frame_cinterpreterstate_size_in_bytes());578__ sub(R11_scratch1/*F0's SP*/,579R11_scratch1/*F1's SP*/, top_frame_size);580581BLOCK_COMMENT("Test for stack overflow:");582__ cmpld(CCR0/*is_stack_overflow*/, R11_scratch1, mem_stack_limit);583__ blt(CCR0/*is_stack_overflow*/, stack_overflow_return);584585586//=============================================================================587// Frame_size doesn't overflow the stack. Allocate new frame and588// initialize interpreter state.589590// Register state591//592// R15 - local_count593// R16 - parameter_count594// R17 - max_stack595//596// R18 - frame_size597// R19 - access_flags598// CCR4_is_synced - is_synced599//600// GR_Lstate - pointer to the uninitialized new BytecodeInterpreter.601602// _last_Java_pc just needs to be close enough that we can identify603// the frame as an interpreted frame. It does not need to be the604// exact return address from either calling605// BytecodeInterpreter::InterpretMethod or the call to a jni native method.606// So we can initialize it here with a value of a bundle in this607// code fragment. We only do this initialization for java frames608// where InterpretMethod needs a a way to get a good pc value to609// store in the thread state. For interpreter frames used to call610// jni native code we just zero the value in the state and move an611// ip as needed in the native entry code.612//613// const Register last_Java_pc_addr = GR24_SCRATCH; // QQQ 27614// const Register last_Java_pc = GR26_SCRATCH;615616// Must reference stack before setting new SP since Windows617// will not be able to deliver the exception on a bad SP.618// Windows also insists that we bang each page one at a time in order619// for the OS to map in the reserved pages. If we bang only620// the final page, Windows stops delivering exceptions to our621// VectoredExceptionHandler and terminates our program.622// Linux only requires a single bang but it's rare to have623// to bang more than 1 page so the code is enabled for both OS's.624625// BANG THE STACK626//627// Nothing to do for PPC, because updating the SP will automatically628// bang the page.629630// Up to here we have calculated the delta for the new C-frame and631// checked for a stack-overflow. Now we can savely update SP and632// resize the C-frame.633634// R14_state has already been calculated.635__ push_interpreter_frame(top_frame_size, parent_frame_resize,636R25_tmp5, R26_tmp6, R27_tmp7, R28_tmp8);637638}639640//641// Stack layout at this point:642//643// F0 has been been pushed!644//645// F0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP646// alignment (optional) (now it's here, if required)647// [F0's full operand stack]648// [F0's monitors] (optional)649// [F0's BytecodeInterpreter object]650// F1 [PARENT_IJAVA_FRAME_ABI]651// alignment (optional) (now it's here, if required)652// [F0's Java result]653// [F0's non-arg Java locals]654// [F1's outgoing Java arguments]655// ...656// F2 [PARENT_IJAVA_FRAME_ABI]657// ...658//659// R14_state points to F0's BytecodeInterpreter object.660//661662}663664//=============================================================================665// new BytecodeInterpreter-object is save, let's initialize it:666BLOCK_COMMENT("New BytecodeInterpreter-object is save.");667668{669// Locals670const Register bytecode_addr = R24_tmp4;671const Register constants = R25_tmp5;672const Register tos = R26_tmp6;673const Register stack_base = R27_tmp7;674const Register local_addr = R28_tmp8;675{676Label L;677__ btrue(is_native, L);678// if (!is_native) {679// bytecode_addr = constMethod->codes();680__ ld(bytecode_addr, method_(const));681__ addi(bytecode_addr, bytecode_addr, in_bytes(ConstMethod::codes_offset()));682// }683__ bind(L);684}685686__ ld(constants, in_bytes(Method::const_offset()), R19_method);687__ ld(constants, in_bytes(ConstMethod::constants_offset()), constants);688689// state->_prev_link = prev_state;690__ std(R15_prev_state, state_(_prev_link));691692// For assertions only.693// TODO: not needed anyway because it coincides with `_monitor_base'. remove!694// state->_self_link = state;695DEBUG_ONLY(__ std(R14_state, state_(_self_link));)696697// state->_thread = thread;698__ std(R16_thread, state_(_thread));699700// state->_method = method;701__ std(R19_method, state_(_method));702703// state->_locals = locals;704__ std(R18_locals, state_(_locals));705706// state->_oop_temp = NULL;707__ li(R0, 0);708__ std(R0, state_(_oop_temp));709710// state->_last_Java_fp = *R1_SP // Use *R1_SP as fp711__ ld(R0, _abi(callers_sp), R1_SP);712__ std(R0, state_(_last_Java_fp));713714BLOCK_COMMENT("load Stack base:");715{716// Stack_base.717// if (!method->synchronized()) {718// stack_base = state;719// } else {720// stack_base = (uintptr_t)state - sizeof(BasicObjectLock);721// }722Label L;723__ mr(stack_base, R14_state);724__ bfalse(is_synced, L);725__ addi(stack_base, stack_base, -frame::interpreter_frame_monitor_size_in_bytes());726__ bind(L);727}728729// state->_mdx = NULL;730__ li(R0, 0);731__ std(R0, state_(_mdx));732733{734// if (method->is_native()) state->_bcp = NULL;735// else state->_bcp = bytecode_addr;736Label label1, label2;737__ bfalse(is_native, label1);738__ std(R0, state_(_bcp));739__ b(label2);740__ bind(label1);741__ std(bytecode_addr, state_(_bcp));742__ bind(label2);743}744745746// state->_result._to_call._callee = NULL;747__ std(R0, state_(_result._to_call._callee));748749// state->_monitor_base = state;750__ std(R14_state, state_(_monitor_base));751752// state->_msg = BytecodeInterpreter::method_entry;753__ li(R0, BytecodeInterpreter::method_entry);754__ stw(R0, state_(_msg));755756// state->_last_Java_sp = R1_SP;757__ std(R1_SP, state_(_last_Java_sp));758759// state->_stack_base = stack_base;760__ std(stack_base, state_(_stack_base));761762// tos = stack_base - 1 slot (prepushed);763// state->_stack.Tos(tos);764__ addi(tos, stack_base, - Interpreter::stackElementSize);765__ std(tos, state_(_stack));766767768{769BLOCK_COMMENT("get last_Java_pc:");770// if (!is_native) state->_last_Java_pc = <some_ip_in_this_code_buffer>;771// else state->_last_Java_pc = NULL; (just for neatness)772Label label1, label2;773__ btrue(is_native, label1);774__ get_PC_trash_LR(R0);775__ std(R0, state_(_last_Java_pc));776__ b(label2);777__ bind(label1);778__ li(R0, 0);779__ std(R0, state_(_last_Java_pc));780__ bind(label2);781}782783784// stack_limit = tos - max_stack;785__ sub(R0, tos, max_stack);786// state->_stack_limit = stack_limit;787__ std(R0, state_(_stack_limit));788789790// cache = method->constants()->cache();791__ ld(R0, ConstantPool::cache_offset_in_bytes(), constants);792// state->_constants = method->constants()->cache();793__ std(R0, state_(_constants));794795796797//=============================================================================798// synchronized method, allocate and initialize method object lock.799// if (!method->is_synchronized()) goto fill_locals_with_0x0s;800Label fill_locals_with_0x0s;801__ bfalse(is_synced, fill_locals_with_0x0s);802803// pool_holder = method->constants()->pool_holder();804const int mirror_offset = in_bytes(Klass::java_mirror_offset());805{806Label label1, label2;807// lockee = NULL; for java methods, correct value will be inserted in BytecodeInterpretMethod.hpp808__ li(R0,0);809__ bfalse(is_native, label2);810811__ bfalse(is_static, label1);812// if (method->is_static()) lockee =813// pool_holder->klass_part()->java_mirror();814__ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(), constants);815__ ld(R0/*lockee*/, mirror_offset, R11_scratch1/*pool_holder*/);816__ b(label2);817818__ bind(label1);819// else lockee = *(oop*)locals;820__ ld(R0/*lockee*/, 0, R18_locals);821__ bind(label2);822823// monitor->set_obj(lockee);824__ std(R0/*lockee*/, BasicObjectLock::obj_offset_in_bytes(), stack_base);825}826827// See if we need to zero the locals828__ BIND(fill_locals_with_0x0s);829830831//=============================================================================832// fill locals with 0x0s833Label locals_zeroed;834__ btrue(is_native, locals_zeroed);835836if (true /* zerolocals */ || ClearInterpreterLocals) {837// local_count is already num_locals_slots - num_param_slots838__ sldi(R0, parameter_count, Interpreter::logStackElementSize);839__ sub(local_addr, R18_locals, R0);840__ cmpdi(CCR0, local_count, 0);841__ ble(CCR0, locals_zeroed);842843__ mtctr(local_count);844//__ ld_const_addr(R0, (address) 0xcafe0000babe);845__ li(R0, 0);846847Label zero_slot;848__ bind(zero_slot);849850// first local is at local_addr851__ std(R0, 0, local_addr);852__ addi(local_addr, local_addr, -BytesPerWord);853__ bdnz(zero_slot);854}855856__ BIND(locals_zeroed);857858}859BLOCK_COMMENT("} compute_interpreter_state");860}861862// Generate code to initiate compilation on invocation counter overflow.863void CppInterpreterGenerator::generate_counter_overflow(Label& continue_entry) {864// Registers alive865// R14_state866// R16_thread867//868// Registers updated869// R14_state870// R3_ARG1 (=R3_RET)871// R4_ARG2872873// After entering the vm we remove the activation and retry the874// entry point in case the compilation is complete.875876// InterpreterRuntime::frequency_counter_overflow takes one argument877// that indicates if the counter overflow occurs at a backwards878// branch (NULL bcp). We pass zero. The call returns the address879// of the verified entry point for the method or NULL if the880// compilation did not complete (either went background or bailed881// out).882__ li(R4_ARG2, 0);883884// Pass false to call_VM so it doesn't check for pending exceptions,885// since at this point in the method invocation the exception886// handler would try to exit the monitor of synchronized methods887// which haven't been entered yet.888//889// Returns verified_entry_point or NULL, we don't care which.890//891// Do not use the variant `frequency_counter_overflow' that returns892// a structure, because this will change the argument list by a893// hidden parameter (gcc 4.1).894895__ call_VM(noreg,896CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow),897R4_ARG2,898false);899// Returns verified_entry_point or NULL, we don't care which as we ignore it900// and run interpreted.901902// Reload method, it may have moved.903__ ld(R19_method, state_(_method));904905// We jump now to the label "continue_after_compile".906__ b(continue_entry);907}908909// Increment invocation count and check for overflow.910//911// R19_method must contain Method* of method to profile.912void CppInterpreterGenerator::generate_counter_incr(Label& overflow) {913Label done;914const Register Rcounters = R12_scratch2;915const Register iv_be_count = R11_scratch1;916const Register invocation_limit = R12_scratch2;917const Register invocation_limit_addr = invocation_limit;918919// Load and ev. allocate MethodCounters object.920__ get_method_counters(R19_method, Rcounters, done);921922// Update standard invocation counters.923__ increment_invocation_counter(Rcounters, iv_be_count, R0);924925// Compare against limit.926BLOCK_COMMENT("Compare counter against limit:");927assert(4 == sizeof(InvocationCounter::InterpreterInvocationLimit),928"must be 4 bytes");929__ load_const(invocation_limit_addr, (address)&InvocationCounter::InterpreterInvocationLimit);930__ lwa(invocation_limit, 0, invocation_limit_addr);931__ cmpw(CCR0, iv_be_count, invocation_limit);932__ bge(CCR0, overflow);933__ bind(done);934}935936//937// Call a JNI method.938//939// Interpreter stub for calling a native method. (C++ interpreter)940// This sets up a somewhat different looking stack for calling the native method941// than the typical interpreter frame setup.942//943address CppInterpreterGenerator::generate_native_entry(void) {944if (native_entry != NULL) return native_entry;945address entry = __ pc();946947// Read948// R16_thread949// R15_prev_state - address of caller's BytecodeInterpreter, if this snippet950// gets called by the frame manager.951// R19_method - callee's Method952// R17_tos - address of caller's tos953// R1_SP - caller's stack pointer954// R21_sender_SP - initial caller sp955//956// Update957// R14_state - address of caller's BytecodeInterpreter958// R3_RET - integer result, if any.959// F1_RET - float result, if any.960//961//962// Stack layout at this point:963//964// 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP965// alignment (optional)966// [outgoing Java arguments] <-- R17_tos967// ...968// PARENT [PARENT_IJAVA_FRAME_ABI]969// ...970//971972const bool inc_counter = UseCompiler || CountCompiledCalls;973974const Register signature_handler_fd = R21_tmp1;975const Register pending_exception = R22_tmp2;976const Register result_handler_addr = R23_tmp3;977const Register native_method_fd = R24_tmp4;978const Register access_flags = R25_tmp5;979const Register active_handles = R26_tmp6;980const Register sync_state = R27_tmp7;981const Register sync_state_addr = sync_state; // Address is dead after use.982const Register suspend_flags = R24_tmp4;983984const Register return_pc = R28_tmp8; // Register will be locked for some time.985986const ConditionRegister is_synced = CCR4_is_synced; // Live-on-exit from compute_interpreter_state.987988989// R1_SP still points to caller's SP at this point.990991// Save initial_caller_sp to caller's abi. The caller frame must be992// resized before returning to get rid of the c2i arguments (if993// any).994// Override the saved SP with the senderSP so we can pop c2i995// arguments (if any) off when we return996__ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);997998// Save LR to caller's frame. We don't use _abi(lr) here, because it is not safe.999__ mflr(return_pc);1000__ std(return_pc, _top_ijava_frame_abi(frame_manager_lr), R1_SP);10011002assert(return_pc->is_nonvolatile(), "return_pc must be a non-volatile register");10031004__ verify_method_ptr(R19_method);10051006//=============================================================================10071008// If this snippet gets called by the frame manager (at label1009// `call_special'), then R15_prev_state is valid. If this snippet1010// is not called by the frame manager, but e.g. by the call stub or1011// by compiled code, then R15_prev_state is invalid.1012{1013// Set R15_prev_state to 0 if we don't return to the frame1014// manager; we will return to the call_stub or to compiled code1015// instead. If R15_prev_state is 0 there will be only one1016// interpreter frame (we will set this up later) in this C frame!1017// So we must take care about retrieving prev_state_(_prev_link)1018// and restoring R1_SP when popping that interpreter.1019Label prev_state_is_valid;10201021__ load_const(R11_scratch1/*frame_manager_returnpc_addr*/, (address)&frame_manager_specialized_return);1022__ ld(R12_scratch2/*frame_manager_returnpc*/, 0, R11_scratch1/*frame_manager_returnpc_addr*/);1023__ cmpd(CCR0, return_pc, R12_scratch2/*frame_manager_returnpc*/);1024__ beq(CCR0, prev_state_is_valid);10251026__ li(R15_prev_state, 0);10271028__ BIND(prev_state_is_valid);1029}10301031//=============================================================================1032// Allocate new frame and initialize interpreter state.10331034Label exception_return;1035Label exception_return_sync_check;1036Label stack_overflow_return;10371038// Generate new interpreter state and jump to stack_overflow_return in case of1039// a stack overflow.1040generate_compute_interpreter_state(stack_overflow_return);10411042//=============================================================================1043// Increment invocation counter. On overflow, entry to JNI method1044// will be compiled.1045Label invocation_counter_overflow;1046if (inc_counter) {1047generate_counter_incr(invocation_counter_overflow);1048}10491050Label continue_after_compile;1051__ BIND(continue_after_compile);10521053// access_flags = method->access_flags();1054// Load access flags.1055assert(access_flags->is_nonvolatile(),1056"access_flags must be in a non-volatile register");1057// Type check.1058// TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");1059__ lwz(access_flags, method_(access_flags));10601061// We don't want to reload R19_method and access_flags after calls1062// to some helper functions.1063assert(R19_method->is_nonvolatile(), "R19_method must be a non-volatile register");10641065// Check for synchronized methods. Must happen AFTER invocation counter1066// check, so method is not locked if counter overflows.10671068{1069Label method_is_not_synced;1070// Is_synced is still alive.1071assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");1072__ bfalse(is_synced, method_is_not_synced);10731074lock_method();1075// Reload method, it may have moved.1076__ ld(R19_method, state_(_method));10771078__ BIND(method_is_not_synced);1079}10801081// jvmti/jvmpi support1082__ notify_method_entry();10831084// Reload method, it may have moved.1085__ ld(R19_method, state_(_method));10861087//=============================================================================1088// Get and call the signature handler10891090__ ld(signature_handler_fd, method_(signature_handler));1091Label call_signature_handler;10921093__ cmpdi(CCR0, signature_handler_fd, 0);1094__ bne(CCR0, call_signature_handler);10951096// Method has never been called. Either generate a specialized1097// handler or point to the slow one.1098//1099// Pass parameter 'false' to avoid exception check in call_VM.1100__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);11011102// Check for an exception while looking up the target method. If we1103// incurred one, bail.1104__ ld(pending_exception, thread_(pending_exception));1105__ cmpdi(CCR0, pending_exception, 0);1106__ bne(CCR0, exception_return_sync_check); // has pending exception11071108// reload method1109__ ld(R19_method, state_(_method));11101111// Reload signature handler, it may have been created/assigned in the meanwhile1112__ ld(signature_handler_fd, method_(signature_handler));11131114__ BIND(call_signature_handler);11151116// Before we call the signature handler we push a new frame to1117// protect the interpreter frame volatile registers when we return1118// from jni but before we can get back to Java.11191120// First set the frame anchor while the SP/FP registers are1121// convenient and the slow signature handler can use this same frame1122// anchor.11231124// We have a TOP_IJAVA_FRAME here, which belongs to us.1125__ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);11261127// Now the interpreter frame (and its call chain) have been1128// invalidated and flushed. We are now protected against eager1129// being enabled in native code. Even if it goes eager the1130// registers will be reloaded as clean and we will invalidate after1131// the call so no spurious flush should be possible.11321133// Call signature handler and pass locals address.1134//1135// Our signature handlers copy required arguments to the C stack1136// (outgoing C args), R3_ARG1 to R10_ARG8, and F1_ARG1 to1137// F13_ARG13.1138__ mr(R3_ARG1, R18_locals);1139#if !defined(ABI_ELFv2)1140__ ld(signature_handler_fd, 0, signature_handler_fd);1141#endif1142__ call_stub(signature_handler_fd);1143// reload method1144__ ld(R19_method, state_(_method));11451146// Remove the register parameter varargs slots we allocated in1147// compute_interpreter_state. SP+16 ends up pointing to the ABI1148// outgoing argument area.1149//1150// Not needed on PPC64.1151//__ add(SP, SP, Argument::n_register_parameters*BytesPerWord);11521153assert(result_handler_addr->is_nonvolatile(), "result_handler_addr must be in a non-volatile register");1154// Save across call to native method.1155__ mr(result_handler_addr, R3_RET);11561157// Set up fixed parameters and call the native method.1158// If the method is static, get mirror into R4_ARG2.11591160{1161Label method_is_not_static;1162// access_flags is non-volatile and still, no need to restore it11631164// restore access flags1165__ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);1166__ bfalse(CCR0, method_is_not_static);11671168// constants = method->constants();1169__ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);1170__ ld(R11_scratch1/*constants*/, in_bytes(ConstMethod::constants_offset()), R11_scratch1);1171// pool_holder = method->constants()->pool_holder();1172__ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),1173R11_scratch1/*constants*/);11741175const int mirror_offset = in_bytes(Klass::java_mirror_offset());11761177// mirror = pool_holder->klass_part()->java_mirror();1178__ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);1179// state->_native_mirror = mirror;1180__ std(R0/*mirror*/, state_(_oop_temp));1181// R4_ARG2 = &state->_oop_temp;1182__ addir(R4_ARG2, state_(_oop_temp));11831184__ BIND(method_is_not_static);1185}11861187// At this point, arguments have been copied off the stack into1188// their JNI positions. Oops are boxed in-place on the stack, with1189// handles copied to arguments. The result handler address is in a1190// register.11911192// pass JNIEnv address as first parameter1193__ addir(R3_ARG1, thread_(jni_environment));11941195// Load the native_method entry before we change the thread state.1196__ ld(native_method_fd, method_(native_function));11971198//=============================================================================1199// Transition from _thread_in_Java to _thread_in_native. As soon as1200// we make this change the safepoint code needs to be certain that1201// the last Java frame we established is good. The pc in that frame1202// just needs to be near here not an actual return address.12031204// We use release_store_fence to update values like the thread state, where1205// we don't want the current thread to continue until all our prior memory1206// accesses (including the new thread state) are visible to other threads.1207__ li(R0, _thread_in_native);1208__ release();12091210// TODO: PPC port: assert(4 == JavaThread::sz_thread_state(), "unexpected field size");1211__ stw(R0, thread_(thread_state));12121213if (UseMembar) {1214__ fence();1215}12161217//=============================================================================1218// Call the native method. Argument registers must not have been1219// overwritten since "__ call_stub(signature_handler);" (except for1220// ARG1 and ARG2 for static methods)1221__ call_c(native_method_fd);12221223__ std(R3_RET, state_(_native_lresult));1224__ stfd(F1_RET, state_(_native_fresult));12251226// The frame_manager_lr field, which we use for setting the last1227// java frame, gets overwritten by the signature handler. Restore1228// it now.1229__ get_PC_trash_LR(R11_scratch1);1230__ std(R11_scratch1, _top_ijava_frame_abi(frame_manager_lr), R1_SP);12311232// Because of GC R19_method may no longer be valid.12331234// Block, if necessary, before resuming in _thread_in_Java state.1235// In order for GC to work, don't clear the last_Java_sp until after1236// blocking.1237123812391240//=============================================================================1241// Switch thread to "native transition" state before reading the1242// synchronization state. This additional state is necessary1243// because reading and testing the synchronization state is not1244// atomic w.r.t. GC, as this scenario demonstrates: Java thread A,1245// in _thread_in_native state, loads _not_synchronized and is1246// preempted. VM thread changes sync state to synchronizing and1247// suspends threads for GC. Thread A is resumed to finish this1248// native method, but doesn't block here since it didn't see any1249// synchronization in progress, and escapes.12501251// We use release_store_fence to update values like the thread state, where1252// we don't want the current thread to continue until all our prior memory1253// accesses (including the new thread state) are visible to other threads.1254__ li(R0/*thread_state*/, _thread_in_native_trans);1255__ release();1256__ stw(R0/*thread_state*/, thread_(thread_state));1257if (UseMembar) {1258__ fence();1259}1260// Write serialization page so that the VM thread can do a pseudo remote1261// membar. We use the current thread pointer to calculate a thread1262// specific offset to write to within the page. This minimizes bus1263// traffic due to cache line collision.1264else {1265__ serialize_memory(R16_thread, R11_scratch1, R12_scratch2);1266}12671268// Now before we return to java we must look for a current safepoint1269// (a new safepoint can not start since we entered native_trans).1270// We must check here because a current safepoint could be modifying1271// the callers registers right this moment.12721273// Acquire isn't strictly necessary here because of the fence, but1274// sync_state is declared to be volatile, so we do it anyway.1275__ load_const(sync_state_addr, SafepointSynchronize::address_of_state());12761277// TODO: PPC port: assert(4 == SafepointSynchronize::sz_state(), "unexpected field size");1278__ lwz(sync_state, 0, sync_state_addr);12791280// TODO: PPC port: assert(4 == Thread::sz_suspend_flags(), "unexpected field size");1281__ lwz(suspend_flags, thread_(suspend_flags));12821283__ acquire();12841285Label sync_check_done;1286Label do_safepoint;1287// No synchronization in progress nor yet synchronized1288__ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);1289// not suspended1290__ cmpwi(CCR1, suspend_flags, 0);12911292__ bne(CCR0, do_safepoint);1293__ beq(CCR1, sync_check_done);1294__ bind(do_safepoint);1295// Block. We do the call directly and leave the current1296// last_Java_frame setup undisturbed. We must save any possible1297// native result acrosss the call. No oop is present12981299__ mr(R3_ARG1, R16_thread);1300#if defined(ABI_ELFv2)1301__ call_c(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),1302relocInfo::none);1303#else1304__ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, JavaThread::check_special_condition_for_native_trans),1305relocInfo::none);1306#endif1307__ bind(sync_check_done);13081309//=============================================================================1310// <<<<<< Back in Interpreter Frame >>>>>13111312// We are in thread_in_native_trans here and back in the normal1313// interpreter frame. We don't have to do anything special about1314// safepoints and we can switch to Java mode anytime we are ready.13151316// Note: frame::interpreter_frame_result has a dependency on how the1317// method result is saved across the call to post_method_exit. For1318// native methods it assumes that the non-FPU/non-void result is1319// saved in _native_lresult and a FPU result in _native_fresult. If1320// this changes then the interpreter_frame_result implementation1321// will need to be updated too.13221323// On PPC64, we have stored the result directly after the native call.13241325//=============================================================================1326// back in Java13271328// We use release_store_fence to update values like the thread state, where1329// we don't want the current thread to continue until all our prior memory1330// accesses (including the new thread state) are visible to other threads.1331__ li(R0/*thread_state*/, _thread_in_Java);1332__ release();1333__ stw(R0/*thread_state*/, thread_(thread_state));1334if (UseMembar) {1335__ fence();1336}13371338__ reset_last_Java_frame();13391340// Reload GR27_method, call killed it. We can't look at1341// state->_method until we're back in java state because in java1342// state gc can't happen until we get to a safepoint.1343//1344// We've set thread_state to _thread_in_Java already, so restoring1345// R19_method from R14_state works; R19_method is invalid, because1346// GC may have happened.1347__ ld(R19_method, state_(_method)); // reload method, may have moved13481349// jvmdi/jvmpi support. Whether we've got an exception pending or1350// not, and whether unlocking throws an exception or not, we notify1351// on native method exit. If we do have an exception, we'll end up1352// in the caller's context to handle it, so if we don't do the1353// notify here, we'll drop it on the floor.13541355__ notify_method_exit(true/*native method*/,1356ilgl /*illegal state (not used for native methods)*/,1357InterpreterMacroAssembler::NotifyJVMTI,1358false /*check_exceptions*/);13591360//=============================================================================1361// Handle exceptions13621363// See if we must unlock.1364//1365{1366Label method_is_not_synced;1367// is_synced is still alive1368assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");1369__ bfalse(is_synced, method_is_not_synced);13701371unlock_method();13721373__ bind(method_is_not_synced);1374}13751376// Reset active handles after returning from native.1377// thread->active_handles()->clear();1378__ ld(active_handles, thread_(active_handles));1379// JNIHandleBlock::_top is an int.1380// TODO: PPC port: assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size");1381__ li(R0, 0);1382__ stw(R0, JNIHandleBlock::top_offset_in_bytes(), active_handles);13831384Label no_pending_exception_from_native_method;1385__ ld(R0/*pending_exception*/, thread_(pending_exception));1386__ cmpdi(CCR0, R0/*pending_exception*/, 0);1387__ beq(CCR0, no_pending_exception_from_native_method);138813891390//-----------------------------------------------------------------------------1391// An exception is pending. We call into the runtime only if the1392// caller was not interpreted. If it was interpreted the1393// interpreter will do the correct thing. If it isn't interpreted1394// (call stub/compiled code) we will change our return and continue.1395__ BIND(exception_return);13961397Label return_to_initial_caller_with_pending_exception;1398__ cmpdi(CCR0, R15_prev_state, 0);1399__ beq(CCR0, return_to_initial_caller_with_pending_exception);14001401// We are returning to an interpreter activation, just pop the state,1402// pop our frame, leave the exception pending, and return.1403__ pop_interpreter_state(/*prev_state_may_be_0=*/false);1404__ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);1405__ mtlr(R21_tmp1);1406__ blr();14071408__ BIND(exception_return_sync_check);14091410assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");1411__ bfalse(is_synced, exception_return);1412unlock_method();1413__ b(exception_return);141414151416__ BIND(return_to_initial_caller_with_pending_exception);1417// We are returning to a c2i-adapter / call-stub, get the address of the1418// exception handler, pop the frame and return to the handler.14191420// First, pop to caller's frame.1421__ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);14221423__ push_frame_reg_args(0, R11_scratch1);1424// Get the address of the exception handler.1425__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),1426R16_thread,1427R21_tmp1 /* return pc */);1428__ pop_frame();14291430// Load the PC of the the exception handler into LR.1431__ mtlr(R3_RET);14321433// Load exception into R3_ARG1 and clear pending exception in thread.1434__ ld(R3_ARG1/*exception*/, thread_(pending_exception));1435__ li(R4_ARG2, 0);1436__ std(R4_ARG2, thread_(pending_exception));14371438// Load the original return pc into R4_ARG2.1439__ mr(R4_ARG2/*issuing_pc*/, R21_tmp1);14401441// Resize frame to get rid of a potential extension.1442__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);14431444// Return to exception handler.1445__ blr();144614471448//-----------------------------------------------------------------------------1449// No exception pending.1450__ BIND(no_pending_exception_from_native_method);14511452// Move native method result back into proper registers and return.1453// Invoke result handler (may unbox/promote).1454__ ld(R3_RET, state_(_native_lresult));1455__ lfd(F1_RET, state_(_native_fresult));1456__ call_stub(result_handler_addr);14571458// We have created a new BytecodeInterpreter object, now we must destroy it.1459//1460// Restore previous R14_state and caller's SP. R15_prev_state may1461// be 0 here, because our caller may be the call_stub or compiled1462// code.1463__ pop_interpreter_state(/*prev_state_may_be_0=*/true);1464__ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);1465// Resize frame to get rid of a potential extension.1466__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);14671468// Must use the return pc which was loaded from the caller's frame1469// as the VM uses return-pc-patching for deoptimization.1470__ mtlr(R21_tmp1);1471__ blr();1472147314741475//=============================================================================1476// We encountered an exception while computing the interpreter1477// state, so R14_state isn't valid. Act as if we just returned from1478// the callee method with a pending exception.1479__ BIND(stack_overflow_return);14801481//1482// Register state:1483// R14_state invalid; trashed by compute_interpreter_state1484// R15_prev_state valid, but may be 01485//1486// R1_SP valid, points to caller's SP; wasn't yet updated by1487// compute_interpreter_state1488//14891490// Create exception oop and make it pending.14911492// Throw the exception via RuntimeStub "throw_StackOverflowError_entry".1493//1494// Previously, we called C-Code directly. As a consequence, a1495// possible GC tried to process the argument oops of the top frame1496// (see RegisterMap::clear, which sets the corresponding flag to1497// true). This lead to crashes because:1498// 1. The top register map did not contain locations for the argument registers1499// 2. The arguments are dead anyway, could be already overwritten in the worst case1500// Solution: Call via special runtime stub that pushes it's own1501// frame. This runtime stub has the flag "CodeBlob::caller_must_gc_arguments()"1502// set to "false", what prevents the dead arguments getting GC'd.1503//1504// 2 cases exist:1505// 1. We were called by the c2i adapter / call stub1506// 2. We were called by the frame manager1507//1508// Both cases are handled by this code:1509// 1. - initial_caller_sp was saved in both cases on entry, so it's safe to load it back even if it was not changed.1510// - control flow will be:1511// throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of caller method1512// 2. - control flow will be:1513// throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->rethrow_excp_entry of frame manager->resume_method1514// Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state1515// registers using the stack and resume the calling method with a pending excp.15161517// Pop any c2i extension from the stack, restore LR just to be sure1518__ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);1519__ mtlr(R0);1520// Resize frame to get rid of a potential extension.1521__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);15221523assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");1524// Load target address of the runtime stub.1525__ load_const(R12_scratch2, (StubRoutines::throw_StackOverflowError_entry()));1526__ mtctr(R12_scratch2);1527__ bctr();152815291530//=============================================================================1531// Counter overflow.15321533if (inc_counter) {1534// Handle invocation counter overflow1535__ bind(invocation_counter_overflow);15361537generate_counter_overflow(continue_after_compile);1538}15391540native_entry = entry;1541return entry;1542}15431544bool AbstractInterpreter::can_be_compiled(methodHandle m) {1545// No special entry points that preclude compilation.1546return true;1547}15481549// Unlock the current method.1550//1551void CppInterpreterGenerator::unlock_method(void) {1552// Find preallocated monitor and unlock method. Method monitor is1553// the first one.15541555// Registers alive1556// R14_state1557//1558// Registers updated1559// volatiles1560//1561const Register monitor = R4_ARG2;15621563// Pass address of initial monitor we allocated.1564//1565// First monitor.1566__ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());15671568// Unlock method1569__ unlock_object(monitor);1570}15711572// Lock the current method.1573//1574void CppInterpreterGenerator::lock_method(void) {1575// Find preallocated monitor and lock method. Method monitor is the1576// first one.15771578//1579// Registers alive1580// R14_state1581//1582// Registers updated1583// volatiles1584//15851586const Register monitor = R4_ARG2;1587const Register object = R5_ARG3;15881589// Pass address of initial monitor we allocated.1590__ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());15911592// Pass object address.1593__ ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);15941595// Lock method.1596__ lock_object(monitor, object);1597}15981599// Generate code for handling resuming a deopted method.1600void CppInterpreterGenerator::generate_deopt_handling(Register result_index) {16011602//=============================================================================1603// Returning from a compiled method into a deopted method. The1604// bytecode at the bcp has completed. The result of the bytecode is1605// in the native abi (the tosca for the template based1606// interpreter). Any stack space that was used by the bytecode that1607// has completed has been removed (e.g. parameters for an invoke) so1608// all that we have to do is place any pending result on the1609// expression stack and resume execution on the next bytecode.16101611Label return_from_deopt_common;16121613// R3_RET and F1_RET are live here! Load the array index of the1614// required result stub address and continue at return_from_deopt_common.16151616// Deopt needs to jump to here to enter the interpreter (return a result).1617deopt_frame_manager_return_atos = __ pc();1618__ li(result_index, AbstractInterpreter::BasicType_as_index(T_OBJECT));1619__ b(return_from_deopt_common);16201621deopt_frame_manager_return_btos = __ pc();1622__ li(result_index, AbstractInterpreter::BasicType_as_index(T_BOOLEAN));1623__ b(return_from_deopt_common);16241625deopt_frame_manager_return_itos = __ pc();1626__ li(result_index, AbstractInterpreter::BasicType_as_index(T_INT));1627__ b(return_from_deopt_common);16281629deopt_frame_manager_return_ltos = __ pc();1630__ li(result_index, AbstractInterpreter::BasicType_as_index(T_LONG));1631__ b(return_from_deopt_common);16321633deopt_frame_manager_return_ftos = __ pc();1634__ li(result_index, AbstractInterpreter::BasicType_as_index(T_FLOAT));1635__ b(return_from_deopt_common);16361637deopt_frame_manager_return_dtos = __ pc();1638__ li(result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));1639__ b(return_from_deopt_common);16401641deopt_frame_manager_return_vtos = __ pc();1642__ li(result_index, AbstractInterpreter::BasicType_as_index(T_VOID));1643// Last one, fall-through to return_from_deopt_common.16441645// Deopt return common. An index is present that lets us move any1646// possible result being return to the interpreter's stack.1647//1648__ BIND(return_from_deopt_common);16491650}16511652// Generate the code to handle a more_monitors message from the c++ interpreter.1653void CppInterpreterGenerator::generate_more_monitors() {16541655//1656// Registers alive1657// R16_thread - JavaThread*1658// R15_prev_state - previous BytecodeInterpreter or 01659// R14_state - BytecodeInterpreter* address of receiver's interpreter state1660// R1_SP - old stack pointer1661//1662// Registers updated1663// R1_SP - new stack pointer1664//16651666// Very-local scratch registers.1667const Register old_tos = R21_tmp1;1668const Register new_tos = R22_tmp2;1669const Register stack_base = R23_tmp3;1670const Register stack_limit = R24_tmp4;1671const Register slot = R25_tmp5;1672const Register n_slots = R25_tmp5;16731674// Interpreter state fields.1675const Register msg = R24_tmp4;16761677// Load up relevant interpreter state.16781679__ ld(stack_base, state_(_stack_base)); // Old stack_base1680__ ld(old_tos, state_(_stack)); // Old tos1681__ ld(stack_limit, state_(_stack_limit)); // Old stack_limit16821683// extracted monitor_size1684int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();1685assert(Assembler::is_aligned((unsigned int)monitor_size,1686(unsigned int)frame::alignment_in_bytes),1687"size of a monitor must respect alignment of SP");16881689// Save and restore top LR1690__ ld(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);1691__ resize_frame(-monitor_size, R11_scratch1);// Allocate space for new monitor1692__ std(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);1693// Initial_caller_sp is used as unextended_sp for non initial callers.1694__ std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);1695__ addi(stack_base, stack_base, -monitor_size); // New stack_base1696__ addi(new_tos, old_tos, -monitor_size); // New tos1697__ addi(stack_limit, stack_limit, -monitor_size); // New stack_limit16981699__ std(R1_SP, state_(_last_Java_sp)); // Update frame_bottom17001701__ std(stack_base, state_(_stack_base)); // Update stack_base1702__ std(new_tos, state_(_stack)); // Update tos1703__ std(stack_limit, state_(_stack_limit)); // Update stack_limit17041705__ li(msg, BytecodeInterpreter::got_monitors); // Tell interpreter we allocated the lock1706__ stw(msg, state_(_msg));17071708// Shuffle expression stack down. Recall that stack_base points1709// just above the new expression stack bottom. Old_tos and new_tos1710// are used to scan thru the old and new expression stacks.17111712Label copy_slot, copy_slot_finished;1713__ sub(n_slots, stack_base, new_tos);1714__ srdi_(n_slots, n_slots, LogBytesPerWord); // compute number of slots to copy1715assert(LogBytesPerWord == 3, "conflicts assembler instructions");1716__ beq(CCR0, copy_slot_finished); // nothing to copy17171718__ mtctr(n_slots);17191720// loop1721__ bind(copy_slot);1722__ ldu(slot, BytesPerWord, old_tos); // slot = *++old_tos;1723__ stdu(slot, BytesPerWord, new_tos); // *++new_tos = slot;1724__ bdnz(copy_slot);17251726__ bind(copy_slot_finished);17271728// Restart interpreter1729__ li(R0, 0);1730__ std(R0, BasicObjectLock::obj_offset_in_bytes(), stack_base); // Mark lock as unused1731}17321733address CppInterpreterGenerator::generate_normal_entry(void) {1734if (interpreter_frame_manager != NULL) return interpreter_frame_manager;17351736address entry = __ pc();17371738address return_from_native_pc = (address) NULL;17391740// Initial entry to frame manager (from call_stub or c2i_adapter)17411742//1743// Registers alive1744// R16_thread - JavaThread*1745// R19_method - callee's Method (method to be invoked)1746// R17_tos - address of sender tos (prepushed)1747// R1_SP - SP prepared by call stub such that caller's outgoing args are near top1748// LR - return address to caller (call_stub or c2i_adapter)1749// R21_sender_SP - initial caller sp1750//1751// Registers updated1752// R15_prev_state - 01753//1754// Stack layout at this point:1755//1756// 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP1757// alignment (optional)1758// [outgoing Java arguments] <-- R17_tos1759// ...1760// PARENT [PARENT_IJAVA_FRAME_ABI]1761// ...1762//17631764// Save initial_caller_sp to caller's abi.1765// The caller frame must be resized before returning to get rid of1766// the c2i part on top of the calling compiled frame (if any).1767// R21_tmp1 must match sender_sp in gen_c2i_adapter.1768// Now override the saved SP with the senderSP so we can pop c2i1769// arguments (if any) off when we return.1770__ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);17711772// Save LR to caller's frame. We don't use _abi(lr) here,1773// because it is not safe.1774__ mflr(R0);1775__ std(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);17761777// If we come here, it is the first invocation of the frame manager.1778// So there is no previous interpreter state.1779__ li(R15_prev_state, 0);178017811782// Fall through to where "recursive" invocations go.17831784//=============================================================================1785// Dispatch an instance of the interpreter. Recursive activations1786// come here.17871788Label re_dispatch;1789__ BIND(re_dispatch);17901791//1792// Registers alive1793// R16_thread - JavaThread*1794// R19_method - callee's Method1795// R17_tos - address of caller's tos (prepushed)1796// R15_prev_state - address of caller's BytecodeInterpreter or 01797// R1_SP - caller's SP trimmed such that caller's outgoing args are near top.1798//1799// Stack layout at this point:1800//1801// 0 [TOP_IJAVA_FRAME_ABI]1802// alignment (optional)1803// [outgoing Java arguments]1804// ...1805// PARENT [PARENT_IJAVA_FRAME_ABI]1806// ...18071808// fall through to interpreted execution18091810//=============================================================================1811// Allocate a new Java frame and initialize the new interpreter state.18121813Label stack_overflow_return;18141815// Create a suitable new Java frame plus a new BytecodeInterpreter instance1816// in the current (frame manager's) C frame.1817generate_compute_interpreter_state(stack_overflow_return);18181819// fall through18201821//=============================================================================1822// Interpreter dispatch.18231824Label call_interpreter;1825__ BIND(call_interpreter);18261827//1828// Registers alive1829// R16_thread - JavaThread*1830// R15_prev_state - previous BytecodeInterpreter or 01831// R14_state - address of receiver's BytecodeInterpreter1832// R1_SP - receiver's stack pointer1833//18341835// Thread fields.1836const Register pending_exception = R21_tmp1;18371838// Interpreter state fields.1839const Register msg = R24_tmp4;18401841// Method fields.1842const Register parameter_count = R25_tmp5;1843const Register result_index = R26_tmp6;18441845const Register dummy = R28_tmp8;18461847// Address of various interpreter stubs.1848// R29_tmp9 is reserved.1849const Register stub_addr = R27_tmp7;18501851// Uncommon trap needs to jump to here to enter the interpreter1852// (re-execute current bytecode).1853unctrap_frame_manager_entry = __ pc();18541855// If we are profiling, store our fp (BSP) in the thread so we can1856// find it during a tick.1857if (Arguments::has_profile()) {1858// On PPC64 we store the pointer to the current BytecodeInterpreter,1859// instead of the bsp of ia64. This should suffice to be able to1860// find all interesting information.1861__ std(R14_state, thread_(last_interpreter_fp));1862}18631864// R16_thread, R14_state and R15_prev_state are nonvolatile1865// registers. There is no need to save these. If we needed to save1866// some state in the current Java frame, this could be a place to do1867// so.18681869// Call Java bytecode dispatcher passing "BytecodeInterpreter* istate".1870__ call_VM_leaf(CAST_FROM_FN_PTR(address,1871JvmtiExport::can_post_interpreter_events()1872? BytecodeInterpreter::runWithChecks1873: BytecodeInterpreter::run),1874R14_state);18751876interpreter_return_address = __ last_calls_return_pc();18771878// R16_thread, R14_state and R15_prev_state have their values preserved.18791880// If we are profiling, clear the fp in the thread to tell1881// the profiler that we are no longer in the interpreter.1882if (Arguments::has_profile()) {1883__ li(R11_scratch1, 0);1884__ std(R11_scratch1, thread_(last_interpreter_fp));1885}18861887// Load message from bytecode dispatcher.1888// TODO: PPC port: guarantee(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");1889__ lwz(msg, state_(_msg));189018911892Label more_monitors;1893Label return_from_native;1894Label return_from_native_common;1895Label return_from_native_no_exception;1896Label return_from_interpreted_method;1897Label return_from_recursive_activation;1898Label unwind_recursive_activation;1899Label resume_interpreter;1900Label return_to_initial_caller;1901Label unwind_initial_activation;1902Label unwind_initial_activation_pending_exception;1903Label call_method;1904Label call_special;1905Label retry_method;1906Label retry_method_osr;1907Label popping_frame;1908Label throwing_exception;19091910// Branch according to the received message19111912__ cmpwi(CCR1, msg, BytecodeInterpreter::call_method);1913__ cmpwi(CCR2, msg, BytecodeInterpreter::return_from_method);19141915__ beq(CCR1, call_method);1916__ beq(CCR2, return_from_interpreted_method);19171918__ cmpwi(CCR3, msg, BytecodeInterpreter::more_monitors);1919__ cmpwi(CCR4, msg, BytecodeInterpreter::throwing_exception);19201921__ beq(CCR3, more_monitors);1922__ beq(CCR4, throwing_exception);19231924__ cmpwi(CCR5, msg, BytecodeInterpreter::popping_frame);1925__ cmpwi(CCR6, msg, BytecodeInterpreter::do_osr);19261927__ beq(CCR5, popping_frame);1928__ beq(CCR6, retry_method_osr);19291930__ stop("bad message from interpreter");193119321933//=============================================================================1934// Add a monitor just below the existing one(s). State->_stack_base1935// points to the lowest existing one, so we insert the new one just1936// below it and shuffle the expression stack down. Ref. the above1937// stack layout picture, we must update _stack_base, _stack, _stack_limit1938// and _last_Java_sp in the interpreter state.19391940__ BIND(more_monitors);19411942generate_more_monitors();1943__ b(call_interpreter);19441945generate_deopt_handling(result_index);19461947// Restoring the R14_state is already done by the deopt_blob.19481949// Current tos includes no parameter slots.1950__ ld(R17_tos, state_(_stack));1951__ li(msg, BytecodeInterpreter::deopt_resume);1952__ b(return_from_native_common);19531954// We are sent here when we are unwinding from a native method or1955// adapter with an exception pending. We need to notify the interpreter1956// that there is an exception to process.1957// We arrive here also if the frame manager called an (interpreted) target1958// which returns with a StackOverflow exception.1959// The control flow is in this case is:1960// frame_manager->throw_excp_stub->forward_excp->rethrow_excp_entry19611962AbstractInterpreter::_rethrow_exception_entry = __ pc();19631964// Restore R14_state.1965__ ld(R14_state, 0, R1_SP);1966__ addi(R14_state, R14_state,1967-frame::interpreter_frame_cinterpreterstate_size_in_bytes());19681969// Store exception oop into thread object.1970__ std(R3_RET, thread_(pending_exception));1971__ li(msg, BytecodeInterpreter::method_resume /*rethrow_exception*/);1972//1973// NOTE: the interpreter frame as setup be deopt does NOT include1974// any parameter slots (good thing since we have no callee here1975// and couldn't remove them) so we don't have to do any calculations1976// here to figure it out.1977//1978__ ld(R17_tos, state_(_stack));1979__ b(return_from_native_common);198019811982//=============================================================================1983// Returning from a native method. Result is in the native abi1984// location so we must move it to the java expression stack.19851986__ BIND(return_from_native);1987guarantee(return_from_native_pc == (address) NULL, "precondition");1988return_from_native_pc = __ pc();19891990// Restore R14_state.1991__ ld(R14_state, 0, R1_SP);1992__ addi(R14_state, R14_state, -frame::interpreter_frame_cinterpreterstate_size_in_bytes());19931994//1995// Registers alive1996// R16_thread1997// R14_state - address of caller's BytecodeInterpreter.1998// R3_RET - integer result, if any.1999// F1_RET - float result, if any.2000//2001// Registers updated2002// R19_method - callee's Method2003// R17_tos - caller's tos, with outgoing args popped2004// result_index - index of result handler.2005// msg - message for resuming interpreter.2006//20072008// Very-local scratch registers.20092010const ConditionRegister have_pending_exception = CCR0;20112012// Load callee Method, gc may have moved it.2013__ ld(R19_method, state_(_result._to_call._callee));20142015// Load address of caller's tos. includes parameter slots.2016__ ld(R17_tos, state_(_stack));20172018// Pop callee's parameters.20192020__ ld(parameter_count, in_bytes(Method::const_offset()), R19_method);2021__ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), parameter_count);2022__ sldi(parameter_count, parameter_count, Interpreter::logStackElementSize);2023__ add(R17_tos, R17_tos, parameter_count);20242025// Result stub address array index2026// TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");2027__ lwa(result_index, method_(result_index));20282029__ li(msg, BytecodeInterpreter::method_resume);20302031//2032// Registers alive2033// R16_thread2034// R14_state - address of caller's BytecodeInterpreter.2035// R17_tos - address of caller's tos with outgoing args already popped2036// R3_RET - integer return value, if any.2037// F1_RET - float return value, if any.2038// result_index - index of result handler.2039// msg - message for resuming interpreter.2040//2041// Registers updated2042// R3_RET - new address of caller's tos, including result, if any2043//20442045__ BIND(return_from_native_common);20462047// Check for pending exception2048__ ld(pending_exception, thread_(pending_exception));2049__ cmpdi(CCR0, pending_exception, 0);2050__ beq(CCR0, return_from_native_no_exception);20512052// If there's a pending exception, we really have no result, so2053// R3_RET is dead. Resume_interpreter assumes the new tos is in2054// R3_RET.2055__ mr(R3_RET, R17_tos);2056// `resume_interpreter' expects R15_prev_state to be alive.2057__ ld(R15_prev_state, state_(_prev_link));2058__ b(resume_interpreter);20592060__ BIND(return_from_native_no_exception);20612062// No pending exception, copy method result from native ABI register2063// to tos.20642065// Address of stub descriptor address array.2066__ load_const(stub_addr, CppInterpreter::tosca_result_to_stack());20672068// Pass address of tos to stub.2069__ mr(R4_ARG2, R17_tos);20702071// Address of stub descriptor address.2072__ sldi(result_index, result_index, LogBytesPerWord);2073__ add(stub_addr, stub_addr, result_index);20742075// Stub descriptor address.2076__ ld(stub_addr, 0, stub_addr);20772078// TODO: don't do this via a call, do it in place!2079//2080// call stub via descriptor2081// in R3_ARG1/F1_ARG1: result value (R3_RET or F1_RET)2082__ call_stub(stub_addr);20832084// new tos = result of call in R3_RET20852086// `resume_interpreter' expects R15_prev_state to be alive.2087__ ld(R15_prev_state, state_(_prev_link));2088__ b(resume_interpreter);20892090//=============================================================================2091// We encountered an exception while computing the interpreter2092// state, so R14_state isn't valid. Act as if we just returned from2093// the callee method with a pending exception.2094__ BIND(stack_overflow_return);20952096//2097// Registers alive2098// R16_thread - JavaThread*2099// R1_SP - old stack pointer2100// R19_method - callee's Method2101// R17_tos - address of caller's tos (prepushed)2102// R15_prev_state - address of caller's BytecodeInterpreter or 02103// R18_locals - address of callee's locals array2104//2105// Registers updated2106// R3_RET - address of resuming tos, if recursive unwind21072108Label Lskip_unextend_SP;21092110{2111const ConditionRegister is_initial_call = CCR0;2112const Register tos_save = R21_tmp1;2113const Register tmp = R22_tmp2;21142115assert(tos_save->is_nonvolatile(), "need a nonvolatile");21162117// Is the exception thrown in the initial Java frame of this frame2118// manager frame?2119__ cmpdi(is_initial_call, R15_prev_state, 0);2120__ bne(is_initial_call, Lskip_unextend_SP);21212122// Pop any c2i extension from the stack. This is necessary in the2123// non-recursive case (that is we were called by the c2i adapter,2124// meaning we have to prev state). In this case we entered the frame2125// manager through a special entry which pushes the orignal2126// unextended SP to the stack. Here we load it back.2127__ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);2128__ mtlr(R0);2129// Resize frame to get rid of a potential extension.2130__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);21312132// Fall through21332134__ bind(Lskip_unextend_SP);21352136// Throw the exception via RuntimeStub "throw_StackOverflowError_entry".2137//2138// Previously, we called C-Code directly. As a consequence, a2139// possible GC tried to process the argument oops of the top frame2140// (see RegisterMap::clear, which sets the corresponding flag to2141// true). This lead to crashes because:2142// 1. The top register map did not contain locations for the argument registers2143// 2. The arguments are dead anyway, could be already overwritten in the worst case2144// Solution: Call via special runtime stub that pushes it's own frame. This runtime stub has the flag2145// "CodeBlob::caller_must_gc_arguments()" set to "false", what prevents the dead arguments getting GC'd.2146//2147// 2 cases exist:2148// 1. We were called by the c2i adapter / call stub2149// 2. We were called by the frame manager2150//2151// Both cases are handled by this code:2152// 1. - initial_caller_sp was saved on stack => Load it back and we're ok2153// - control flow will be:2154// throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of calling method2155// 2. - control flow will be:2156// throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->2157// ->rethrow_excp_entry of frame manager->resume_method2158// Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state2159// registers using the stack and resume the calling method with a pending excp.21602161assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");2162__ load_const(R3_ARG1, (StubRoutines::throw_StackOverflowError_entry()));2163__ mtctr(R3_ARG1);2164__ bctr();2165}2166//=============================================================================2167// We have popped a frame from an interpreted call. We are assured2168// of returning to an interpreted call by the popframe abi. We have2169// no return value all we have to do is pop the current frame and2170// then make sure that the top of stack (of the caller) gets set to2171// where it was when we entered the callee (i.e. the args are still2172// in place). Or we are returning to the interpreter. In the first2173// case we must extract result (if any) from the java expression2174// stack and store it in the location the native abi would expect2175// for a call returning this type. In the second case we must simply2176// do a stack to stack move as we unwind.21772178__ BIND(popping_frame);21792180// Registers alive2181// R14_state2182// R15_prev_state2183// R17_tos2184//2185// Registers updated2186// R19_method2187// R3_RET2188// msg2189{2190Label L;21912192// Reload callee method, gc may have moved it.2193__ ld(R19_method, state_(_method));21942195// We may be returning to a deoptimized frame in which case the2196// usual assumption of a recursive return is not true.21972198// not equal = is recursive call2199__ cmpdi(CCR0, R15_prev_state, 0);22002201__ bne(CCR0, L);22022203// Pop_frame capability.2204// The pop_frame api says that the underlying frame is a Java frame, in this case2205// (prev_state==null) it must be a compiled frame:2206//2207// Stack at this point: I, C2I + C, ...2208//2209// The outgoing arguments of the call have just been copied (popframe_preserve_args).2210// By the pop_frame api, we must end up in an interpreted frame. So the compiled frame2211// will be deoptimized. Deoptimization will restore the outgoing arguments from2212// popframe_preserve_args, adjust the tos such that it includes the popframe_preserve_args,2213// and adjust the bci such that the call will be executed again.2214// We have no results, just pop the interpreter frame, resize the compiled frame to get rid2215// of the c2i extension and return to the deopt_handler.2216__ b(unwind_initial_activation);22172218// is recursive call2219__ bind(L);22202221// Resume_interpreter expects the original tos in R3_RET.2222__ ld(R3_RET, prev_state_(_stack));22232224// We're done.2225__ li(msg, BytecodeInterpreter::popping_frame);22262227__ b(unwind_recursive_activation);2228}222922302231//=============================================================================22322233// We have finished an interpreted call. We are either returning to2234// native (call_stub/c2) or we are returning to the interpreter.2235// When returning to native, we must extract the result (if any)2236// from the java expression stack and store it in the location the2237// native abi expects. When returning to the interpreter we must2238// simply do a stack to stack move as we unwind.22392240__ BIND(return_from_interpreted_method);22412242//2243// Registers alive2244// R16_thread - JavaThread*2245// R15_prev_state - address of caller's BytecodeInterpreter or 02246// R14_state - address of callee's interpreter state2247// R1_SP - callee's stack pointer2248//2249// Registers updated2250// R19_method - callee's method2251// R3_RET - address of result (new caller's tos),2252//2253// if returning to interpreted2254// msg - message for interpreter,2255// if returning to interpreted2256//22572258// Check if this is the initial invocation of the frame manager.2259// If so, R15_prev_state will be null.2260__ cmpdi(CCR0, R15_prev_state, 0);22612262// Reload callee method, gc may have moved it.2263__ ld(R19_method, state_(_method));22642265// Load the method's result type.2266__ lwz(result_index, method_(result_index));22672268// Go to return_to_initial_caller if R15_prev_state is null.2269__ beq(CCR0, return_to_initial_caller);22702271// Copy callee's result to caller's expression stack via inline stack-to-stack2272// converters.2273{2274Register new_tos = R3_RET;2275Register from_temp = R4_ARG2;2276Register from = R5_ARG3;2277Register tos = R6_ARG4;2278Register tmp1 = R7_ARG5;2279Register tmp2 = R8_ARG6;22802281ConditionRegister result_type_is_void = CCR1;2282ConditionRegister result_type_is_long = CCR2;2283ConditionRegister result_type_is_double = CCR3;22842285Label stack_to_stack_void;2286Label stack_to_stack_double_slot; // T_LONG, T_DOUBLE2287Label stack_to_stack_single_slot; // T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT2288Label stack_to_stack_done;22892290// Pass callee's address of tos + BytesPerWord2291__ ld(from_temp, state_(_stack));22922293// result type: void2294__ cmpwi(result_type_is_void, result_index, AbstractInterpreter::BasicType_as_index(T_VOID));22952296// Pass caller's tos == callee's locals address2297__ ld(tos, state_(_locals));22982299// result type: long2300__ cmpwi(result_type_is_long, result_index, AbstractInterpreter::BasicType_as_index(T_LONG));23012302__ addi(from, from_temp, Interpreter::stackElementSize);23032304// !! don't branch above this line !!23052306// handle void2307__ beq(result_type_is_void, stack_to_stack_void);23082309// result type: double2310__ cmpwi(result_type_is_double, result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));23112312// handle long or double2313__ beq(result_type_is_long, stack_to_stack_double_slot);2314__ beq(result_type_is_double, stack_to_stack_double_slot);23152316// fall through to single slot types (incl. object)23172318{2319__ BIND(stack_to_stack_single_slot);2320// T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT23212322__ ld(tmp1, 0, from);2323__ std(tmp1, 0, tos);2324// New expression stack top2325__ addi(new_tos, tos, - BytesPerWord);23262327__ b(stack_to_stack_done);2328}23292330{2331__ BIND(stack_to_stack_double_slot);2332// T_LONG, T_DOUBLE23332334// Move both entries for debug purposes even though only one is live2335__ ld(tmp1, BytesPerWord, from);2336__ ld(tmp2, 0, from);2337__ std(tmp1, 0, tos);2338__ std(tmp2, -BytesPerWord, tos);23392340// new expression stack top2341__ addi(new_tos, tos, - 2 * BytesPerWord); // two slots2342__ b(stack_to_stack_done);2343}23442345{2346__ BIND(stack_to_stack_void);2347// T_VOID23482349// new expression stack top2350__ mr(new_tos, tos);2351// fall through to stack_to_stack_done2352}23532354__ BIND(stack_to_stack_done);2355}23562357// new tos = R3_RET23582359// Get the message for the interpreter2360__ li(msg, BytecodeInterpreter::method_resume);23612362// And fall thru236323642365//=============================================================================2366// Restore caller's interpreter state and pass pointer to caller's2367// new tos to caller.23682369__ BIND(unwind_recursive_activation);23702371//2372// Registers alive2373// R15_prev_state - address of caller's BytecodeInterpreter2374// R3_RET - address of caller's tos2375// msg - message for caller's BytecodeInterpreter2376// R1_SP - callee's stack pointer2377//2378// Registers updated2379// R14_state - address of caller's BytecodeInterpreter2380// R15_prev_state - address of its parent or 02381//23822383// Pop callee's interpreter and set R14_state to caller's interpreter.2384__ pop_interpreter_state(/*prev_state_may_be_0=*/false);23852386// And fall thru238723882389//=============================================================================2390// Resume the (calling) interpreter after a call.23912392__ BIND(resume_interpreter);23932394//2395// Registers alive2396// R14_state - address of resuming BytecodeInterpreter2397// R15_prev_state - address of its parent or 02398// R3_RET - address of resuming tos2399// msg - message for resuming interpreter2400// R1_SP - callee's stack pointer2401//2402// Registers updated2403// R1_SP - caller's stack pointer2404//24052406// Restore C stack pointer of caller (resuming interpreter),2407// R14_state already points to the resuming BytecodeInterpreter.2408__ pop_interpreter_frame_to_state(R14_state, R21_tmp1, R11_scratch1, R12_scratch2);24092410// Store new address of tos (holding return value) in interpreter state.2411__ std(R3_RET, state_(_stack));24122413// Store message for interpreter.2414__ stw(msg, state_(_msg));24152416__ b(call_interpreter);24172418//=============================================================================2419// Interpreter returning to native code (call_stub/c1/c2) from2420// initial activation. Convert stack result and unwind activation.24212422__ BIND(return_to_initial_caller);24232424//2425// Registers alive2426// R19_method - callee's Method2427// R14_state - address of callee's interpreter state2428// R16_thread - JavaThread2429// R1_SP - callee's stack pointer2430//2431// Registers updated2432// R3_RET/F1_RET - result in expected output register2433//24342435// If we have an exception pending we have no result and we2436// must figure out where to really return to.2437//2438__ ld(pending_exception, thread_(pending_exception));2439__ cmpdi(CCR0, pending_exception, 0);2440__ bne(CCR0, unwind_initial_activation_pending_exception);24412442__ lwa(result_index, method_(result_index));24432444// Address of stub descriptor address array.2445__ load_const(stub_addr, CppInterpreter::stack_result_to_native());24462447// Pass address of callee's tos + BytesPerWord.2448// Will then point directly to result.2449__ ld(R3_ARG1, state_(_stack));2450__ addi(R3_ARG1, R3_ARG1, Interpreter::stackElementSize);24512452// Address of stub descriptor address2453__ sldi(result_index, result_index, LogBytesPerWord);2454__ add(stub_addr, stub_addr, result_index);24552456// Stub descriptor address2457__ ld(stub_addr, 0, stub_addr);24582459// TODO: don't do this via a call, do it in place!2460//2461// call stub via descriptor2462__ call_stub(stub_addr);24632464__ BIND(unwind_initial_activation);24652466// Unwind from initial activation. No exception is pending.24672468//2469// Stack layout at this point:2470//2471// 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP2472// ...2473// CALLER [PARENT_IJAVA_FRAME_ABI]2474// ...2475// CALLER [unextended ABI]2476// ...2477//2478// The CALLER frame has a C2I adapter or is an entry-frame.2479//24802481// An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and2482// turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.2483// But, we simply restore the return pc from the caller's frame and2484// use the caller's initial_caller_sp as the new SP which pops the2485// interpreter frame and "resizes" the caller's frame to its "unextended"2486// size.24872488// get rid of top frame2489__ pop_frame();24902491// Load return PC from parent frame.2492__ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);24932494// Resize frame to get rid of a potential extension.2495__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);24962497// update LR2498__ mtlr(R21_tmp1);24992500// return2501__ blr();25022503//=============================================================================2504// Unwind from initial activation. An exception is pending25052506__ BIND(unwind_initial_activation_pending_exception);25072508//2509// Stack layout at this point:2510//2511// 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP2512// ...2513// CALLER [PARENT_IJAVA_FRAME_ABI]2514// ...2515// CALLER [unextended ABI]2516// ...2517//2518// The CALLER frame has a C2I adapter or is an entry-frame.2519//25202521// An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and2522// turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.2523// But, we just pop the current TOP_IJAVA_FRAME and fall through25242525__ pop_frame();2526__ ld(R3_ARG1, _top_ijava_frame_abi(lr), R1_SP);25272528//2529// Stack layout at this point:2530//2531// CALLER [PARENT_IJAVA_FRAME_ABI] <-- R1_SP2532// ...2533// CALLER [unextended ABI]2534// ...2535//2536// The CALLER frame has a C2I adapter or is an entry-frame.2537//2538// Registers alive2539// R16_thread2540// R3_ARG1 - return address to caller2541//2542// Registers updated2543// R3_ARG1 - address of pending exception2544// R4_ARG2 - issuing pc = return address to caller2545// LR - address of exception handler stub2546//25472548// Resize frame to get rid of a potential extension.2549__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);25502551__ mr(R14, R3_ARG1); // R14 := ARG12552__ mr(R4_ARG2, R3_ARG1); // ARG2 := ARG125532554// Find the address of the "catch_exception" stub.2555__ push_frame_reg_args(0, R11_scratch1);2556__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),2557R16_thread,2558R4_ARG2);2559__ pop_frame();25602561// Load continuation address into LR.2562__ mtlr(R3_RET);25632564// Load address of pending exception and clear it in thread object.2565__ ld(R3_ARG1/*R3_RET*/, thread_(pending_exception));2566__ li(R4_ARG2, 0);2567__ std(R4_ARG2, thread_(pending_exception));25682569// re-load issuing pc2570__ mr(R4_ARG2, R14);25712572// Branch to found exception handler.2573__ blr();25742575//=============================================================================2576// Call a new method. Compute new args and trim the expression stack2577// to only what we are currently using and then recurse.25782579__ BIND(call_method);25802581//2582// Registers alive2583// R16_thread2584// R14_state - address of caller's BytecodeInterpreter2585// R1_SP - caller's stack pointer2586//2587// Registers updated2588// R15_prev_state - address of caller's BytecodeInterpreter2589// R17_tos - address of caller's tos2590// R19_method - callee's Method2591// R1_SP - trimmed back2592//25932594// Very-local scratch registers.25952596const Register offset = R21_tmp1;2597const Register tmp = R22_tmp2;2598const Register self_entry = R23_tmp3;2599const Register stub_entry = R24_tmp4;26002601const ConditionRegister cr = CCR0;26022603// Load the address of the frame manager.2604__ load_const(self_entry, &interpreter_frame_manager);2605__ ld(self_entry, 0, self_entry);26062607// Load BytecodeInterpreter._result._to_call._callee (callee's Method).2608__ ld(R19_method, state_(_result._to_call._callee));2609// Load BytecodeInterpreter._stack (outgoing tos).2610__ ld(R17_tos, state_(_stack));26112612// Save address of caller's BytecodeInterpreter.2613__ mr(R15_prev_state, R14_state);26142615// Load the callee's entry point.2616// Load BytecodeInterpreter._result._to_call._callee_entry_point.2617__ ld(stub_entry, state_(_result._to_call._callee_entry_point));26182619// Check whether stub_entry is equal to self_entry.2620__ cmpd(cr, self_entry, stub_entry);2621// if (self_entry == stub_entry)2622// do a re-dispatch2623__ beq(cr, re_dispatch);2624// else2625// call the specialized entry (adapter for jni or compiled code)2626__ BIND(call_special);26272628//2629// Call the entry generated by `InterpreterGenerator::generate_native_entry'.2630//2631// Registers alive2632// R16_thread2633// R15_prev_state - address of caller's BytecodeInterpreter2634// R19_method - callee's Method2635// R17_tos - address of caller's tos2636// R1_SP - caller's stack pointer2637//26382639// Mark return from specialized entry for generate_native_entry.2640guarantee(return_from_native_pc != (address) NULL, "precondition");2641frame_manager_specialized_return = return_from_native_pc;26422643// Set sender_SP in case we call interpreter native wrapper which2644// will expect it. Compiled code should not care.2645__ mr(R21_sender_SP, R1_SP);26462647// Do a tail call here, and let the link register point to2648// frame_manager_specialized_return which is return_from_native_pc.2649__ load_const(tmp, frame_manager_specialized_return);2650__ call_stub_and_return_to(stub_entry, tmp /* return_pc=tmp */);265126522653//=============================================================================2654//2655// InterpretMethod triggered OSR compilation of some Java method M2656// and now asks to run the compiled code. We call this code the2657// `callee'.2658//2659// This is our current idea on how OSR should look like on PPC64:2660//2661// While interpreting a Java method M the stack is:2662//2663// (InterpretMethod (M), IJAVA_FRAME (M), ANY_FRAME, ...).2664//2665// After having OSR compiled M, `InterpretMethod' returns to the2666// frame manager, sending the message `retry_method_osr'. The stack2667// is:2668//2669// (IJAVA_FRAME (M), ANY_FRAME, ...).2670//2671// The compiler will have generated an `nmethod' suitable for2672// continuing execution of M at the bytecode index at which OSR took2673// place. So now the frame manager calls the OSR entry. The OSR2674// entry sets up a JIT_FRAME for M and continues execution of M with2675// initial state determined by the IJAVA_FRAME.2676//2677// (JIT_FRAME (M), IJAVA_FRAME (M), ANY_FRAME, ...).2678//26792680__ BIND(retry_method_osr);2681{2682//2683// Registers alive2684// R16_thread2685// R15_prev_state - address of caller's BytecodeInterpreter2686// R14_state - address of callee's BytecodeInterpreter2687// R1_SP - callee's SP before call to InterpretMethod2688//2689// Registers updated2690// R17 - pointer to callee's locals array2691// (declared via `interpreter_arg_ptr_reg' in the AD file)2692// R19_method - callee's Method2693// R1_SP - callee's SP (will become SP of OSR adapter frame)2694//26952696// Provide a debugger breakpoint in the frame manager if breakpoints2697// in osr'd methods are requested.2698#ifdef COMPILER22699NOT_PRODUCT( if (OptoBreakpointOSR) { __ illtrap(); } )2700#endif27012702// Load callee's pointer to locals array from callee's state.2703// __ ld(R17, state_(_locals));27042705// Load osr entry.2706__ ld(R12_scratch2, state_(_result._osr._osr_entry));27072708// Load address of temporary osr buffer to arg1.2709__ ld(R3_ARG1, state_(_result._osr._osr_buf));2710__ mtctr(R12_scratch2);27112712// Load method, gc may move it during execution of osr'd method.2713__ ld(R22_tmp2, state_(_method));2714// Load message 'call_method'.2715__ li(R23_tmp3, BytecodeInterpreter::call_method);27162717{2718// Pop the IJAVA frame of the method which we are going to call osr'd.2719Label no_state, skip_no_state;2720__ pop_interpreter_state(/*prev_state_may_be_0=*/true);2721__ cmpdi(CCR0, R14_state,0);2722__ beq(CCR0, no_state);2723// return to interpreter2724__ pop_interpreter_frame_to_state(R14_state, R11_scratch1, R12_scratch2, R21_tmp1);27252726// Init _result._to_call._callee and tell gc that it contains a valid oop2727// by setting _msg to 'call_method'.2728__ std(R22_tmp2, state_(_result._to_call._callee));2729// TODO: PPC port: assert(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");2730__ stw(R23_tmp3, state_(_msg));27312732__ load_const(R21_tmp1, frame_manager_specialized_return);2733__ b(skip_no_state);2734__ bind(no_state);27352736// Return to initial caller.27372738// Get rid of top frame.2739__ pop_frame();27402741// Load return PC from parent frame.2742__ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);27432744// Resize frame to get rid of a potential extension.2745__ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);27462747__ bind(skip_no_state);27482749// Update LR with return pc.2750__ mtlr(R21_tmp1);2751}2752// Jump to the osr entry point.2753__ bctr();27542755}27562757//=============================================================================2758// Interpreted method "returned" with an exception, pass it on.2759// Pass no result, unwind activation and continue/return to2760// interpreter/call_stub/c2.27612762__ BIND(throwing_exception);27632764// Check if this is the initial invocation of the frame manager. If2765// so, previous interpreter state in R15_prev_state will be null.27662767// New tos of caller is callee's first parameter address, that is2768// callee's incoming arguments are popped.2769__ ld(R3_RET, state_(_locals));27702771// Check whether this is an initial call.2772__ cmpdi(CCR0, R15_prev_state, 0);2773// Yes, called from the call stub or from generated code via a c2i frame.2774__ beq(CCR0, unwind_initial_activation_pending_exception);27752776// Send resume message, interpreter will see the exception first.27772778__ li(msg, BytecodeInterpreter::method_resume);2779__ b(unwind_recursive_activation);278027812782//=============================================================================2783// Push the last instruction out to the code buffer.27842785{2786__ unimplemented("end of InterpreterGenerator::generate_normal_entry", 128);2787}27882789interpreter_frame_manager = entry;2790return interpreter_frame_manager;2791}27922793// Generate code for various sorts of method entries2794//2795address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {2796address entry_point = NULL;27972798switch (kind) {2799case Interpreter::zerolocals : break;2800case Interpreter::zerolocals_synchronized : break;2801case Interpreter::native : // Fall thru2802case Interpreter::native_synchronized : entry_point = ((CppInterpreterGenerator*)this)->generate_native_entry(); break;2803case Interpreter::empty : break;2804case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;2805case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;2806// These are special interpreter intrinsics which we don't support so far.2807case Interpreter::java_lang_math_sin : break;2808case Interpreter::java_lang_math_cos : break;2809case Interpreter::java_lang_math_tan : break;2810case Interpreter::java_lang_math_abs : break;2811case Interpreter::java_lang_math_log : break;2812case Interpreter::java_lang_math_log10 : break;2813case Interpreter::java_lang_math_sqrt : break;2814case Interpreter::java_lang_math_pow : break;2815case Interpreter::java_lang_math_exp : break;2816case Interpreter::java_lang_ref_reference_get: entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;2817default : ShouldNotReachHere(); break;2818}28192820if (entry_point) {2821return entry_point;2822}2823return ((InterpreterGenerator*)this)->generate_normal_entry();2824}28252826InterpreterGenerator::InterpreterGenerator(StubQueue* code)2827: CppInterpreterGenerator(code) {2828generate_all(); // down here so it can be "virtual"2829}28302831// How much stack a topmost interpreter method activation needs in words.2832int AbstractInterpreter::size_top_interpreter_activation(Method* method) {2833// Computation is in bytes not words to match layout_activation_impl2834// below, but the return is in words.28352836//2837// 0 [TOP_IJAVA_FRAME_ABI] \2838// alignment (optional) \ |2839// [operand stack / Java parameters] > stack | |2840// [monitors] (optional) > monitors | |2841// [PARENT_IJAVA_FRAME_ABI] \ | |2842// [BytecodeInterpreter object] > interpreter \ | | |2843// alignment (optional) | round | parent | round | top2844// [Java result] (2 slots) > result | | | |2845// [Java non-arg locals] \ locals | | | |2846// [arg locals] / / / / /2847//28482849int locals = method->max_locals() * BytesPerWord;2850int interpreter = frame::interpreter_frame_cinterpreterstate_size_in_bytes();2851int result = 2 * BytesPerWord;28522853int parent = round_to(interpreter + result + locals, 16) + frame::parent_ijava_frame_abi_size;28542855int stack = method->max_stack() * BytesPerWord;2856int monitors = method->is_synchronized() ? frame::interpreter_frame_monitor_size_in_bytes() : 0;2857int top = round_to(parent + monitors + stack, 16) + frame::top_ijava_frame_abi_size;28582859return (top / BytesPerWord);2860}28612862void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,2863frame* caller,2864frame* current,2865Method* method,2866intptr_t* locals,2867intptr_t* stack,2868intptr_t* stack_base,2869intptr_t* monitor_base,2870intptr_t* frame_sp,2871bool is_top_frame) {2872// What about any vtable?2873//2874to_fill->_thread = JavaThread::current();2875// This gets filled in later but make it something recognizable for now.2876to_fill->_bcp = method->code_base();2877to_fill->_locals = locals;2878to_fill->_constants = method->constants()->cache();2879to_fill->_method = method;2880to_fill->_mdx = NULL;2881to_fill->_stack = stack;28822883if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution()) {2884to_fill->_msg = deopt_resume2;2885} else {2886to_fill->_msg = method_resume;2887}2888to_fill->_result._to_call._bcp_advance = 0;2889to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone2890to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone2891to_fill->_prev_link = NULL;28922893if (caller->is_interpreted_frame()) {2894interpreterState prev = caller->get_interpreterState();28952896// Support MH calls. Make sure the interpreter will return the right address:2897// 1. Caller did ordinary interpreted->compiled call call: Set a prev_state2898// which makes the CPP interpreter return to frame manager "return_from_interpreted_method"2899// entry after finishing execution.2900// 2. Caller did a MH call: If the caller has a MethodHandleInvoke in it's2901// state (invariant: must be the caller of the bottom vframe) we used the2902// "call_special" entry to do the call, meaning the arguments have not been2903// popped from the stack. Therefore, don't enter a prev state in this case2904// in order to return to "return_from_native" frame manager entry which takes2905// care of popping arguments. Also, don't overwrite the MH.invoke Method in2906// the prev_state in order to be able to figure out the number of arguments to2907// pop.2908// The parameter method can represent MethodHandle.invokeExact(...).2909// The MethodHandleCompiler generates these synthetic Methods,2910// including bytecodes, if an invokedynamic call gets inlined. In2911// this case we want to return like from any other interpreted2912// Java call, so we set _prev_link.2913to_fill->_prev_link = prev;29142915if (*prev->_bcp == Bytecodes::_invokeinterface || *prev->_bcp == Bytecodes::_invokedynamic) {2916prev->_result._to_call._bcp_advance = 5;2917} else {2918prev->_result._to_call._bcp_advance = 3;2919}2920}2921to_fill->_oop_temp = NULL;2922to_fill->_stack_base = stack_base;2923// Need +1 here because stack_base points to the word just above the2924// first expr stack entry and stack_limit is supposed to point to2925// the word just below the last expr stack entry. See2926// generate_compute_interpreter_state.2927to_fill->_stack_limit = stack_base - (method->max_stack() + 1);2928to_fill->_monitor_base = (BasicObjectLock*) monitor_base;29292930to_fill->_frame_bottom = frame_sp;29312932// PPC64 specific2933to_fill->_last_Java_pc = NULL;2934to_fill->_last_Java_fp = NULL;2935to_fill->_last_Java_sp = frame_sp;2936#ifdef ASSERT2937to_fill->_self_link = to_fill;2938to_fill->_native_fresult = 123456.789;2939to_fill->_native_lresult = CONST64(0xdeafcafedeadc0de);2940#endif2941}29422943void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate,2944address last_Java_pc,2945intptr_t* last_Java_fp) {2946istate->_last_Java_pc = last_Java_pc;2947istate->_last_Java_fp = last_Java_fp;2948}29492950// Computes monitor_size and top_frame_size in bytes.2951static void frame_size_helper(int max_stack,2952int monitors,2953int& monitor_size,2954int& top_frame_size) {2955monitor_size = frame::interpreter_frame_monitor_size_in_bytes() * monitors;2956top_frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()2957+ monitor_size2958+ max_stack * Interpreter::stackElementSize2959+ 2 * Interpreter::stackElementSize,2960frame::alignment_in_bytes)2961+ frame::top_ijava_frame_abi_size;2962}29632964// Returns number of stackElementWords needed for the interpreter frame with the2965// given sections.2966int AbstractInterpreter::size_activation(int max_stack,2967int temps,2968int extra_args,2969int monitors,2970int callee_params,2971int callee_locals,2972bool is_top_frame) {2973int monitor_size = 0;2974int top_frame_size = 0;2975frame_size_helper(max_stack, monitors, monitor_size, top_frame_size);29762977int frame_size;2978if (is_top_frame) {2979frame_size = top_frame_size;2980} else {2981frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()2982+ monitor_size2983+ (temps - callee_params + callee_locals) * Interpreter::stackElementSize2984+ 2 * Interpreter::stackElementSize,2985frame::alignment_in_bytes)2986+ frame::parent_ijava_frame_abi_size;2987assert(extra_args == 0, "non-zero for top_frame only");2988}29892990return frame_size / Interpreter::stackElementSize;2991}29922993void AbstractInterpreter::layout_activation(Method* method,2994int temps, // Number of slots on java expression stack in use.2995int popframe_args,2996int monitors, // Number of active monitors.2997int caller_actual_parameters,2998int callee_params,// Number of slots for callee parameters.2999int callee_locals,// Number of slots for locals.3000frame* caller,3001frame* interpreter_frame,3002bool is_top_frame,3003bool is_bottom_frame) {30043005// NOTE this code must exactly mimic what3006// InterpreterGenerator::generate_compute_interpreter_state() does3007// as far as allocating an interpreter frame. However there is an3008// exception. With the C++ based interpreter only the top most frame3009// has a full sized expression stack. The 16 byte slop factor is3010// both the abi scratch area and a place to hold a result from a3011// callee on its way to the callers stack.30123013int monitor_size = 0;3014int top_frame_size = 0;3015frame_size_helper(method->max_stack(), monitors, monitor_size, top_frame_size);30163017intptr_t sp = (intptr_t)interpreter_frame->sp();3018intptr_t fp = *(intptr_t *)sp;3019assert(fp == (intptr_t)caller->sp(), "fp must match");3020interpreterState cur_state =3021(interpreterState)(fp - frame::interpreter_frame_cinterpreterstate_size_in_bytes());30223023// Now fill in the interpreterState object.30243025intptr_t* locals;3026if (caller->is_interpreted_frame()) {3027// Locals must agree with the caller because it will be used to set the3028// caller's tos when we return.3029interpreterState prev = caller->get_interpreterState();3030// Calculate start of "locals" for MH calls. For MH calls, the3031// current method() (= MH target) and prev->callee() (=3032// MH.invoke*()) are different and especially have different3033// signatures. To pop the argumentsof the caller, we must use3034// the prev->callee()->size_of_arguments() because that's what3035// the caller actually pushed. Currently, for synthetic MH3036// calls (deoptimized from inlined MH calls), detected by3037// is_method_handle_invoke(), we use the callee's arguments3038// because here, the caller's and callee's signature match.3039if (true /*!caller->is_at_mh_callsite()*/) {3040locals = prev->stack() + method->size_of_parameters();3041} else {3042// Normal MH call.3043locals = prev->stack() + prev->callee()->size_of_parameters();3044}3045} else {3046bool is_deopted;3047locals = (intptr_t*) (fp + ((method->max_locals() - 1) * BytesPerWord) +3048frame::parent_ijava_frame_abi_size);3049}30503051intptr_t* monitor_base = (intptr_t*) cur_state;3052intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);30533054// Provide pop_frame capability on PPC64, add popframe_args.3055// +1 because stack is always prepushed.3056intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (temps + popframe_args + 1) * BytesPerWord);30573058BytecodeInterpreter::layout_interpreterState(cur_state,3059caller,3060interpreter_frame,3061method,3062locals,3063stack,3064stack_base,3065monitor_base,3066(intptr_t*)(((intptr_t)fp) - top_frame_size),3067is_top_frame);30683069BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address,3070interpreter_frame->fp());3071}30723073#endif // CC_INTERP307430753076