Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/cppInterpreter_x86.cpp
32285 views
/*1* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.hpp"26#include "interpreter/bytecodeHistogram.hpp"27#include "interpreter/cppInterpreter.hpp"28#include "interpreter/interpreter.hpp"29#include "interpreter/interpreterGenerator.hpp"30#include "interpreter/interpreterRuntime.hpp"31#include "oops/arrayOop.hpp"32#include "oops/methodData.hpp"33#include "oops/method.hpp"34#include "oops/oop.inline.hpp"35#include "prims/jvmtiExport.hpp"36#include "prims/jvmtiThreadState.hpp"37#include "runtime/arguments.hpp"38#include "runtime/deoptimization.hpp"39#include "runtime/frame.inline.hpp"40#include "runtime/interfaceSupport.hpp"41#include "runtime/sharedRuntime.hpp"42#include "runtime/stubRoutines.hpp"43#include "runtime/synchronizer.hpp"44#include "runtime/timer.hpp"45#include "runtime/vframeArray.hpp"46#include "utilities/debug.hpp"47#include "utilities/macros.hpp"48#ifdef SHARK49#include "shark/shark_globals.hpp"50#endif5152#ifdef CC_INTERP5354// Routine exists to make tracebacks look decent in debugger55// while we are recursed in the frame manager/c++ interpreter.56// We could use an address in the frame manager but having57// frames look natural in the debugger is a plus.58extern "C" void RecursiveInterpreterActivation(interpreterState istate )59{60//61ShouldNotReachHere();62}636465#define __ _masm->66#define STATE(field_name) (Address(state, byte_offset_of(BytecodeInterpreter, field_name)))6768Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized69// c++ interpreter entry point this holds that entry point label.7071// default registers for state and sender_sp72// state and sender_sp are the same on 32bit because we have no choice.73// state could be rsi on 64bit but it is an arg reg and not callee save74// so r13 is better choice.7576const Register state = NOT_LP64(rsi) LP64_ONLY(r13);77const Register sender_sp_on_entry = NOT_LP64(rsi) LP64_ONLY(r13);7879// NEEDED for JVMTI?80// address AbstractInterpreter::_remove_activation_preserving_args_entry;8182static address unctrap_frame_manager_entry = NULL;8384static address deopt_frame_manager_return_atos = NULL;85static address deopt_frame_manager_return_btos = NULL;86static address deopt_frame_manager_return_itos = NULL;87static address deopt_frame_manager_return_ltos = NULL;88static address deopt_frame_manager_return_ftos = NULL;89static address deopt_frame_manager_return_dtos = NULL;90static address deopt_frame_manager_return_vtos = NULL;9192int AbstractInterpreter::BasicType_as_index(BasicType type) {93int i = 0;94switch (type) {95case T_BOOLEAN: i = 0; break;96case T_CHAR : i = 1; break;97case T_BYTE : i = 2; break;98case T_SHORT : i = 3; break;99case T_INT : i = 4; break;100case T_VOID : i = 5; break;101case T_FLOAT : i = 8; break;102case T_LONG : i = 9; break;103case T_DOUBLE : i = 6; break;104case T_OBJECT : // fall through105case T_ARRAY : i = 7; break;106default : ShouldNotReachHere();107}108assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");109return i;110}111112// Is this pc anywhere within code owned by the interpreter?113// This only works for pc that might possibly be exposed to frame114// walkers. It clearly misses all of the actual c++ interpreter115// implementation116bool CppInterpreter::contains(address pc) {117return (_code->contains(pc) ||118pc == CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));119}120121122address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {123address entry = __ pc();124switch (type) {125case T_BOOLEAN: __ c2bool(rax); break;126case T_CHAR : __ andl(rax, 0xFFFF); break;127case T_BYTE : __ sign_extend_byte (rax); break;128case T_SHORT : __ sign_extend_short(rax); break;129case T_VOID : // fall thru130case T_LONG : // fall thru131case T_INT : /* nothing to do */ break;132133case T_DOUBLE :134case T_FLOAT :135{136const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();137__ pop(t); // remove return address first138// Must return a result for interpreter or compiler. In SSE139// mode, results are returned in xmm0 and the FPU stack must140// be empty.141if (type == T_FLOAT && UseSSE >= 1) {142#ifndef _LP64143// Load ST0144__ fld_d(Address(rsp, 0));145// Store as float and empty fpu stack146__ fstp_s(Address(rsp, 0));147#endif // !_LP64148// and reload149__ movflt(xmm0, Address(rsp, 0));150} else if (type == T_DOUBLE && UseSSE >= 2 ) {151__ movdbl(xmm0, Address(rsp, 0));152} else {153// restore ST0154__ fld_d(Address(rsp, 0));155}156// and pop the temp157__ addptr(rsp, 2 * wordSize);158__ push(t); // restore return address159}160break;161case T_OBJECT :162// retrieve result from frame163__ movptr(rax, STATE(_oop_temp));164// and verify it165__ verify_oop(rax);166break;167default : ShouldNotReachHere();168}169__ ret(0); // return from result handler170return entry;171}172173// tosca based result to c++ interpreter stack based result.174// Result goes to top of native stack.175176#undef EXTEND // SHOULD NOT BE NEEDED177address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {178// A result is in the tosca (abi result) from either a native method call or compiled179// code. Place this result on the java expression stack so C++ interpreter can use it.180address entry = __ pc();181182const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();183__ pop(t); // remove return address first184switch (type) {185case T_VOID:186break;187case T_BOOLEAN:188#ifdef EXTEND189__ c2bool(rax);190#endif191__ push(rax);192break;193case T_CHAR :194#ifdef EXTEND195__ andl(rax, 0xFFFF);196#endif197__ push(rax);198break;199case T_BYTE :200#ifdef EXTEND201__ sign_extend_byte (rax);202#endif203__ push(rax);204break;205case T_SHORT :206#ifdef EXTEND207__ sign_extend_short(rax);208#endif209__ push(rax);210break;211case T_LONG :212__ push(rdx); // pushes useless junk on 64bit213__ push(rax);214break;215case T_INT :216__ push(rax);217break;218case T_FLOAT :219// Result is in ST(0)/xmm0220__ subptr(rsp, wordSize);221if ( UseSSE < 1) {222__ fstp_s(Address(rsp, 0));223} else {224__ movflt(Address(rsp, 0), xmm0);225}226break;227case T_DOUBLE :228__ subptr(rsp, 2*wordSize);229if ( UseSSE < 2 ) {230__ fstp_d(Address(rsp, 0));231} else {232__ movdbl(Address(rsp, 0), xmm0);233}234break;235case T_OBJECT :236__ verify_oop(rax); // verify it237__ push(rax);238break;239default : ShouldNotReachHere();240}241__ jmp(t); // return from result handler242return entry;243}244245address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {246// A result is in the java expression stack of the interpreted method that has just247// returned. Place this result on the java expression stack of the caller.248//249// The current interpreter activation in rsi/r13 is for the method just returning its250// result. So we know that the result of this method is on the top of the current251// execution stack (which is pre-pushed) and will be return to the top of the caller252// stack. The top of the callers stack is the bottom of the locals of the current253// activation.254// Because of the way activation are managed by the frame manager the value of rsp is255// below both the stack top of the current activation and naturally the stack top256// of the calling activation. This enable this routine to leave the return address257// to the frame manager on the stack and do a vanilla return.258//259// On entry: rsi/r13 - interpreter state of activation returning a (potential) result260// On Return: rsi/r13 - unchanged261// rax - new stack top for caller activation (i.e. activation in _prev_link)262//263// Can destroy rdx, rcx.264//265266address entry = __ pc();267const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();268switch (type) {269case T_VOID:270__ movptr(rax, STATE(_locals)); // pop parameters get new stack value271__ addptr(rax, wordSize); // account for prepush before we return272break;273case T_FLOAT :274case T_BOOLEAN:275case T_CHAR :276case T_BYTE :277case T_SHORT :278case T_INT :279// 1 word result280__ movptr(rdx, STATE(_stack));281__ movptr(rax, STATE(_locals)); // address for result282__ movl(rdx, Address(rdx, wordSize)); // get result283__ movptr(Address(rax, 0), rdx); // and store it284break;285case T_LONG :286case T_DOUBLE :287// return top two words on current expression stack to caller's expression stack288// The caller's expression stack is adjacent to the current frame manager's intepretState289// except we allocated one extra word for this intepretState so we won't overwrite it290// when we return a two word result.291292__ movptr(rax, STATE(_locals)); // address for result293__ movptr(rcx, STATE(_stack));294__ subptr(rax, wordSize); // need addition word besides locals[0]295__ movptr(rdx, Address(rcx, 2*wordSize)); // get result word (junk in 64bit)296__ movptr(Address(rax, wordSize), rdx); // and store it297__ movptr(rdx, Address(rcx, wordSize)); // get result word298__ movptr(Address(rax, 0), rdx); // and store it299break;300case T_OBJECT :301__ movptr(rdx, STATE(_stack));302__ movptr(rax, STATE(_locals)); // address for result303__ movptr(rdx, Address(rdx, wordSize)); // get result304__ verify_oop(rdx); // verify it305__ movptr(Address(rax, 0), rdx); // and store it306break;307default : ShouldNotReachHere();308}309__ ret(0);310return entry;311}312313address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {314// A result is in the java expression stack of the interpreted method that has just315// returned. Place this result in the native abi that the caller expects.316//317// Similar to generate_stack_to_stack_converter above. Called at a similar time from the318// frame manager execept in this situation the caller is native code (c1/c2/call_stub)319// and so rather than return result onto caller's java expression stack we return the320// result in the expected location based on the native abi.321// On entry: rsi/r13 - interpreter state of activation returning a (potential) result322// On Return: rsi/r13 - unchanged323// Other registers changed [rax/rdx/ST(0) as needed for the result returned]324325address entry = __ pc();326switch (type) {327case T_VOID:328break;329case T_BOOLEAN:330case T_CHAR :331case T_BYTE :332case T_SHORT :333case T_INT :334__ movptr(rdx, STATE(_stack)); // get top of stack335__ movl(rax, Address(rdx, wordSize)); // get result word 1336break;337case T_LONG :338__ movptr(rdx, STATE(_stack)); // get top of stack339__ movptr(rax, Address(rdx, wordSize)); // get result low word340NOT_LP64(__ movl(rdx, Address(rdx, 2*wordSize));) // get result high word341break;342case T_FLOAT :343__ movptr(rdx, STATE(_stack)); // get top of stack344if ( UseSSE >= 1) {345__ movflt(xmm0, Address(rdx, wordSize));346} else {347__ fld_s(Address(rdx, wordSize)); // pushd float result348}349break;350case T_DOUBLE :351__ movptr(rdx, STATE(_stack)); // get top of stack352if ( UseSSE > 1) {353__ movdbl(xmm0, Address(rdx, wordSize));354} else {355__ fld_d(Address(rdx, wordSize)); // push double result356}357break;358case T_OBJECT :359__ movptr(rdx, STATE(_stack)); // get top of stack360__ movptr(rax, Address(rdx, wordSize)); // get result word 1361__ verify_oop(rax); // verify it362break;363default : ShouldNotReachHere();364}365__ ret(0);366return entry;367}368369address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {370// make it look good in the debugger371return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation);372}373374address CppInterpreter::deopt_entry(TosState state, int length) {375address ret = NULL;376if (length != 0) {377switch (state) {378case atos: ret = deopt_frame_manager_return_atos; break;379case btos: ret = deopt_frame_manager_return_btos; break;380case ctos:381case stos:382case itos: ret = deopt_frame_manager_return_itos; break;383case ltos: ret = deopt_frame_manager_return_ltos; break;384case ftos: ret = deopt_frame_manager_return_ftos; break;385case dtos: ret = deopt_frame_manager_return_dtos; break;386case vtos: ret = deopt_frame_manager_return_vtos; break;387}388} else {389ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap)390}391assert(ret != NULL, "Not initialized");392return ret;393}394395// C++ Interpreter396void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,397const Register locals,398const Register sender_sp,399bool native) {400401// On entry the "locals" argument points to locals[0] (or where it would be in case no locals in402// a static method). "state" contains any previous frame manager state which we must save a link403// to in the newly generated state object. On return "state" is a pointer to the newly allocated404// state object. We must allocate and initialize a new interpretState object and the method405// expression stack. Because the returned result (if any) of the method will be placed on the caller's406// expression stack and this will overlap with locals[0] (and locals[1] if double/long) we must407// be sure to leave space on the caller's stack so that this result will not overwrite values when408// locals[0] and locals[1] do not exist (and in fact are return address and saved rbp). So when409// we are non-native we in essence ensure that locals[0-1] exist. We play an extra trick in410// non-product builds and initialize this last local with the previous interpreterState as411// this makes things look real nice in the debugger.412413// State on entry414// Assumes locals == &locals[0]415// Assumes state == any previous frame manager state (assuming call path from c++ interpreter)416// Assumes rax = return address417// rcx == senders_sp418// rbx == method419// Modifies rcx, rdx, rax420// Returns:421// state == address of new interpreterState422// rsp == bottom of method's expression stack.423424const Address const_offset (rbx, Method::const_offset());425426427// On entry sp is the sender's sp. This includes the space for the arguments428// that the sender pushed. If the sender pushed no args (a static) and the429// caller returns a long then we need two words on the sender's stack which430// are not present (although when we return a restore full size stack the431// space will be present). If we didn't allocate two words here then when432// we "push" the result of the caller's stack we would overwrite the return433// address and the saved rbp. Not good. So simply allocate 2 words now434// just to be safe. This is the "static long no_params() method" issue.435// See Lo.java for a testcase.436// We don't need this for native calls because they return result in437// register and the stack is expanded in the caller before we store438// the results on the stack.439440if (!native) {441#ifdef PRODUCT442__ subptr(rsp, 2*wordSize);443#else /* PRODUCT */444__ push((int32_t)NULL_WORD);445__ push(state); // make it look like a real argument446#endif /* PRODUCT */447}448449// Now that we are assure of space for stack result, setup typical linkage450451__ push(rax);452__ enter();453454__ mov(rax, state); // save current state455456__ lea(rsp, Address(rsp, -(int)sizeof(BytecodeInterpreter)));457__ mov(state, rsp);458459// rsi/r13 == state/locals rax == prevstate460461// initialize the "shadow" frame so that use since C++ interpreter not directly462// recursive. Simpler to recurse but we can't trim expression stack as we call463// new methods.464__ movptr(STATE(_locals), locals); // state->_locals = locals()465__ movptr(STATE(_self_link), state); // point to self466__ movptr(STATE(_prev_link), rax); // state->_link = state on entry (NULL or previous state)467__ movptr(STATE(_sender_sp), sender_sp); // state->_sender_sp = sender_sp468#ifdef _LP64469__ movptr(STATE(_thread), r15_thread); // state->_bcp = codes()470#else471__ get_thread(rax); // get vm's javathread*472__ movptr(STATE(_thread), rax); // state->_bcp = codes()473#endif // _LP64474__ movptr(rdx, Address(rbx, Method::const_offset())); // get constantMethodOop475__ lea(rdx, Address(rdx, ConstMethod::codes_offset())); // get code base476if (native) {477__ movptr(STATE(_bcp), (int32_t)NULL_WORD); // state->_bcp = NULL478} else {479__ movptr(STATE(_bcp), rdx); // state->_bcp = codes()480}481__ xorptr(rdx, rdx);482__ movptr(STATE(_oop_temp), rdx); // state->_oop_temp = NULL (only really needed for native)483__ movptr(STATE(_mdx), rdx); // state->_mdx = NULL484__ movptr(rdx, Address(rbx, Method::const_offset()));485__ movptr(rdx, Address(rdx, ConstMethod::constants_offset()));486__ movptr(rdx, Address(rdx, ConstantPool::cache_offset_in_bytes()));487__ movptr(STATE(_constants), rdx); // state->_constants = constants()488489__ movptr(STATE(_method), rbx); // state->_method = method()490__ movl(STATE(_msg), (int32_t) BytecodeInterpreter::method_entry); // state->_msg = initial method entry491__ movptr(STATE(_result._to_call._callee), (int32_t) NULL_WORD); // state->_result._to_call._callee_callee = NULL492493494__ movptr(STATE(_monitor_base), rsp); // set monitor block bottom (grows down) this would point to entry [0]495// entries run from -1..x where &monitor[x] ==496497{498// Must not attempt to lock method until we enter interpreter as gc won't be able to find the499// initial frame. However we allocate a free monitor so we don't have to shuffle the expression stack500// immediately.501502// synchronize method503const Address access_flags (rbx, Method::access_flags_offset());504const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;505Label not_synced;506507__ movl(rax, access_flags);508__ testl(rax, JVM_ACC_SYNCHRONIZED);509__ jcc(Assembler::zero, not_synced);510511// Allocate initial monitor and pre initialize it512// get synchronization object513514Label done;515const int mirror_offset = in_bytes(Klass::java_mirror_offset());516__ movl(rax, access_flags);517__ testl(rax, JVM_ACC_STATIC);518__ movptr(rax, Address(locals, 0)); // get receiver (assume this is frequent case)519__ jcc(Assembler::zero, done);520__ movptr(rax, Address(rbx, Method::const_offset()));521__ movptr(rax, Address(rax, ConstMethod::constants_offset()));522__ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes()));523__ movptr(rax, Address(rax, mirror_offset));524__ bind(done);525// add space for monitor & lock526__ subptr(rsp, entry_size); // add space for a monitor entry527__ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object528__ bind(not_synced);529}530531__ movptr(STATE(_stack_base), rsp); // set expression stack base ( == &monitors[-count])532if (native) {533__ movptr(STATE(_stack), rsp); // set current expression stack tos534__ movptr(STATE(_stack_limit), rsp);535} else {536__ subptr(rsp, wordSize); // pre-push stack537__ movptr(STATE(_stack), rsp); // set current expression stack tos538539// compute full expression stack limit540541__ movptr(rdx, Address(rbx, Method::const_offset()));542__ load_unsigned_short(rdx, Address(rdx, ConstMethod::max_stack_offset())); // get size of expression stack in words543__ negptr(rdx); // so we can subtract in next step544// Allocate expression stack545__ lea(rsp, Address(rsp, rdx, Address::times_ptr, -Method::extra_stack_words()));546__ movptr(STATE(_stack_limit), rsp);547}548549#ifdef _LP64550// Make sure stack is properly aligned and sized for the abi551__ subptr(rsp, frame::arg_reg_save_area_bytes); // windows552__ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)553#endif // _LP64554555556557}558559// Helpers for commoning out cases in the various type of method entries.560//561562// increment invocation count & check for overflow563//564// Note: checking for negative value instead of overflow565// so we have a 'sticky' overflow test566//567// rbx,: method568// rcx: invocation counter569//570void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {571Label done;572const Address invocation_counter(rax,573MethodCounters::invocation_counter_offset() +574InvocationCounter::counter_offset());575const Address backedge_counter (rax,576MethodCounter::backedge_counter_offset() +577InvocationCounter::counter_offset());578579__ get_method_counters(rbx, rax, done);580581if (ProfileInterpreter) {582__ incrementl(Address(rax,583MethodCounters::interpreter_invocation_counter_offset()));584}585// Update standard invocation counters586__ movl(rcx, invocation_counter);587__ increment(rcx, InvocationCounter::count_increment);588__ movl(invocation_counter, rcx); // save invocation count589590__ movl(rax, backedge_counter); // load backedge counter591__ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits592593__ addl(rcx, rax); // add both counters594595// profile_method is non-null only for interpreted method so596// profile_method != NULL == !native_call597// BytecodeInterpreter only calls for native so code is elided.598599__ cmp32(rcx,600ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));601__ jcc(Assembler::aboveEqual, *overflow);602__ bind(done);603}604605void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {606607// C++ interpreter on entry608// rsi/r13 - new interpreter state pointer609// rbp - interpreter frame pointer610// rbx - method611612// On return (i.e. jump to entry_point) [ back to invocation of interpreter ]613// rbx, - method614// rcx - rcvr (assuming there is one)615// top of stack return address of interpreter caller616// rsp - sender_sp617618// C++ interpreter only619// rsi/r13 - previous interpreter state pointer620621// InterpreterRuntime::frequency_counter_overflow takes one argument622// indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).623// The call returns the address of the verified entry point for the method or NULL624// if the compilation did not complete (either went background or bailed out).625__ movptr(rax, (int32_t)false);626__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);627628// for c++ interpreter can rsi really be munged?629__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); // restore state630__ movptr(rbx, Address(state, byte_offset_of(BytecodeInterpreter, _method))); // restore method631__ movptr(rdi, Address(state, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer632633__ jmp(*do_continue, relocInfo::none);634635}636637void InterpreterGenerator::generate_stack_overflow_check(void) {638// see if we've got enough room on the stack for locals plus overhead.639// the expression stack grows down incrementally, so the normal guard640// page mechanism will work for that.641//642// Registers live on entry:643//644// Asm interpreter645// rdx: number of additional locals this frame needs (what we must check)646// rbx,: Method*647648// C++ Interpreter649// rsi/r13: previous interpreter frame state object650// rdi: &locals[0]651// rcx: # of locals652// rdx: number of additional locals this frame needs (what we must check)653// rbx: Method*654655// destroyed on exit656// rax,657658// NOTE: since the additional locals are also always pushed (wasn't obvious in659// generate_method_entry) so the guard should work for them too.660//661662// monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp663const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;664665// total overhead size: entry_size + (saved rbp, thru expr stack bottom).666// be sure to change this if you add/subtract anything to/from the overhead area667const int overhead_size = (int)sizeof(BytecodeInterpreter);668669const int page_size = os::vm_page_size();670671Label after_frame_check;672673// compute rsp as if this were going to be the last frame on674// the stack before the red zone675676Label after_frame_check_pop;677678// save rsi == caller's bytecode ptr (c++ previous interp. state)679// QQQ problem here?? rsi overload????680__ push(state);681682const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rsi);683684NOT_LP64(__ get_thread(thread));685686const Address stack_base(thread, Thread::stack_base_offset());687const Address stack_size(thread, Thread::stack_size_offset());688689// locals + overhead, in bytes690// Always give one monitor to allow us to start interp if sync method.691// Any additional monitors need a check when moving the expression stack692const int one_monitor = frame::interpreter_frame_monitor_size() * wordSize;693__ movptr(rax, Address(rbx, Method::const_offset()));694__ load_unsigned_short(rax, Address(rax, ConstMethod::max_stack_offset())); // get size of expression stack in words695__ lea(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor+Method::extra_stack_words()));696__ lea(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));697698#ifdef ASSERT699Label stack_base_okay, stack_size_okay;700// verify that thread stack base is non-zero701__ cmpptr(stack_base, (int32_t)0);702__ jcc(Assembler::notEqual, stack_base_okay);703__ stop("stack base is zero");704__ bind(stack_base_okay);705// verify that thread stack size is non-zero706__ cmpptr(stack_size, (int32_t)0);707__ jcc(Assembler::notEqual, stack_size_okay);708__ stop("stack size is zero");709__ bind(stack_size_okay);710#endif711712// Add stack base to locals and subtract stack size713__ addptr(rax, stack_base);714__ subptr(rax, stack_size);715716// We should have a magic number here for the size of the c++ interpreter frame.717// We can't actually tell this ahead of time. The debug version size is around 3k718// product is 1k and fastdebug is 4k719const int slop = 6 * K;720721// Use the maximum number of pages we might bang.722const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :723(StackRedPages+StackYellowPages);724// Only need this if we are stack banging which is temporary while725// we're debugging.726__ addptr(rax, slop + 2*max_pages * page_size);727728// check against the current stack bottom729__ cmpptr(rsp, rax);730__ jcc(Assembler::above, after_frame_check_pop);731732__ pop(state); // get c++ prev state.733734// throw exception return address becomes throwing pc735__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));736737// all done with frame size check738__ bind(after_frame_check_pop);739__ pop(state);740741__ bind(after_frame_check);742}743744// Find preallocated monitor and lock method (C++ interpreter)745// rbx - Method*746//747void InterpreterGenerator::lock_method(void) {748// assumes state == rsi/r13 == pointer to current interpreterState749// minimally destroys rax, rdx|c_rarg1, rdi750//751// synchronize method752const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;753const Address access_flags (rbx, Method::access_flags_offset());754755const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);756757// find initial monitor i.e. monitors[-1]758__ movptr(monitor, STATE(_monitor_base)); // get monitor bottom limit759__ subptr(monitor, entry_size); // point to initial monitor760761#ifdef ASSERT762{ Label L;763__ movl(rax, access_flags);764__ testl(rax, JVM_ACC_SYNCHRONIZED);765__ jcc(Assembler::notZero, L);766__ stop("method doesn't need synchronization");767__ bind(L);768}769#endif // ASSERT770// get synchronization object771{ Label done;772const int mirror_offset = in_bytes(Klass::java_mirror_offset());773__ movl(rax, access_flags);774__ movptr(rdi, STATE(_locals)); // prepare to get receiver (assume common case)775__ testl(rax, JVM_ACC_STATIC);776__ movptr(rax, Address(rdi, 0)); // get receiver (assume this is frequent case)777__ jcc(Assembler::zero, done);778__ movptr(rax, Address(rbx, Method::const_offset()));779__ movptr(rax, Address(rax, ConstMethod::constants_offset()));780__ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes()));781__ movptr(rax, Address(rax, mirror_offset));782__ bind(done);783}784#ifdef ASSERT785{ Label L;786__ cmpptr(rax, Address(monitor, BasicObjectLock::obj_offset_in_bytes())); // correct object?787__ jcc(Assembler::equal, L);788__ stop("wrong synchronization lobject");789__ bind(L);790}791#endif // ASSERT792// can destroy rax, rdx|c_rarg1, rcx, and (via call_VM) rdi!793__ lock_object(monitor);794}795796// Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry797798address InterpreterGenerator::generate_accessor_entry(void) {799800// rbx: Method*801802// rsi/r13: senderSP must preserved for slow path, set SP to it on fast path803804Label xreturn_path;805806// do fastpath for resolved accessor methods807if (UseFastAccessorMethods) {808809address entry_point = __ pc();810811Label slow_path;812// If we need a safepoint check, generate full interpreter entry.813ExternalAddress state(SafepointSynchronize::address_of_state());814__ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),815SafepointSynchronize::_not_synchronized);816817__ jcc(Assembler::notEqual, slow_path);818// ASM/C++ Interpreter819// Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1820// Note: We can only use this code if the getfield has been resolved821// and if we don't have a null-pointer exception => check for822// these conditions first and use slow path if necessary.823// rbx,: method824// rcx: receiver825__ movptr(rax, Address(rsp, wordSize));826827// check if local 0 != NULL and read field828__ testptr(rax, rax);829__ jcc(Assembler::zero, slow_path);830831// read first instruction word and extract bytecode @ 1 and index @ 2832__ movptr(rdx, Address(rbx, Method::const_offset()));833__ movptr(rdi, Address(rdx, ConstMethod::constants_offset()));834__ movl(rdx, Address(rdx, ConstMethod::codes_offset()));835// Shift codes right to get the index on the right.836// The bytecode fetched looks like <index><0xb4><0x2a>837__ shrl(rdx, 2*BitsPerByte);838__ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));839__ movptr(rdi, Address(rdi, ConstantPool::cache_offset_in_bytes()));840841// rax,: local 0842// rbx,: method843// rcx: receiver - do not destroy since it is needed for slow path!844// rcx: scratch845// rdx: constant pool cache index846// rdi: constant pool cache847// rsi/r13: sender sp848849// check if getfield has been resolved and read constant pool cache entry850// check the validity of the cache entry by testing whether _indices field851// contains Bytecode::_getfield in b1 byte.852assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");853__ movl(rcx,854Address(rdi,855rdx,856Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));857__ shrl(rcx, 2*BitsPerByte);858__ andl(rcx, 0xFF);859__ cmpl(rcx, Bytecodes::_getfield);860__ jcc(Assembler::notEqual, slow_path);861862// Note: constant pool entry is not valid before bytecode is resolved863__ movptr(rcx,864Address(rdi,865rdx,866Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));867__ movl(rdx,868Address(rdi,869rdx,870Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));871872Label notByte, notBool, notShort, notChar;873const Address field_address (rax, rcx, Address::times_1);874875// Need to differentiate between igetfield, agetfield, bgetfield etc.876// because they are different sizes.877// Use the type from the constant pool cache878__ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift);879// Make sure we don't need to mask rdx after the above shift880ConstantPoolCacheEntry::verify_tos_state_shift();881#ifdef _LP64882Label notObj;883__ cmpl(rdx, atos);884__ jcc(Assembler::notEqual, notObj);885// atos886__ movptr(rax, field_address);887__ jmp(xreturn_path);888889__ bind(notObj);890#endif // _LP64891__ cmpl(rdx, ztos);892__ jcc(Assembler::notEqual, notBool);893__ load_signed_byte(rax, field_address);894__ jmp(xreturn_path);895896__ cmpl(rdx, btos);897__ jcc(Assembler::notEqual, notByte);898__ load_signed_byte(rax, field_address);899__ jmp(xreturn_path);900901__ bind(notByte);902__ cmpl(rdx, stos);903__ jcc(Assembler::notEqual, notShort);904__ load_signed_short(rax, field_address);905__ jmp(xreturn_path);906907__ bind(notShort);908__ cmpl(rdx, ctos);909__ jcc(Assembler::notEqual, notChar);910__ load_unsigned_short(rax, field_address);911__ jmp(xreturn_path);912913__ bind(notChar);914#ifdef ASSERT915Label okay;916#ifndef _LP64917__ cmpl(rdx, atos);918__ jcc(Assembler::equal, okay);919#endif // _LP64920__ cmpl(rdx, itos);921__ jcc(Assembler::equal, okay);922__ stop("what type is this?");923__ bind(okay);924#endif // ASSERT925// All the rest are a 32 bit wordsize926__ movl(rax, field_address);927928__ bind(xreturn_path);929930// _ireturn/_areturn931__ pop(rdi); // get return address932__ mov(rsp, sender_sp_on_entry); // set sp to sender sp933__ jmp(rdi);934935// generate a vanilla interpreter entry as the slow path936__ bind(slow_path);937// We will enter c++ interpreter looking like it was938// called by the call_stub this will cause it to return939// a tosca result to the invoker which might have been940// the c++ interpreter itself.941942__ jmp(fast_accessor_slow_entry_path);943return entry_point;944945} else {946return NULL;947}948949}950951address InterpreterGenerator::generate_Reference_get_entry(void) {952#if INCLUDE_ALL_GCS953if (UseG1GC) {954// We need to generate have a routine that generates code to:955// * load the value in the referent field956// * passes that value to the pre-barrier.957//958// In the case of G1 this will record the value of the959// referent in an SATB buffer if marking is active.960// This will cause concurrent marking to mark the referent961// field as live.962Unimplemented();963}964#endif // INCLUDE_ALL_GCS965966// If G1 is not enabled then attempt to go through the accessor entry point967// Reference.get is an accessor968return generate_accessor_entry();969}970971//972// C++ Interpreter stub for calling a native method.973// This sets up a somewhat different looking stack for calling the native method974// than the typical interpreter frame setup but still has the pointer to975// an interpreter state.976//977978address InterpreterGenerator::generate_native_entry(bool synchronized) {979// determine code generation flags980bool inc_counter = UseCompiler || CountCompiledCalls;981982// rbx: Method*983// rcx: receiver (unused)984// rsi/r13: previous interpreter state (if called from C++ interpreter) must preserve985// in any case. If called via c1/c2/call_stub rsi/r13 is junk (to use) but harmless986// to save/restore.987address entry_point = __ pc();988989const Address constMethod (rbx, Method::const_offset());990const Address access_flags (rbx, Method::access_flags_offset());991const Address size_of_parameters(rcx, ConstMethod::size_of_parameters_offset());992993// rsi/r13 == state/locals rdi == prevstate994const Register locals = rdi;995996// get parameter size (always needed)997__ movptr(rcx, constMethod);998__ load_unsigned_short(rcx, size_of_parameters);9991000// rbx: Method*1001// rcx: size of parameters1002__ pop(rax); // get return address1003// for natives the size of locals is zero10041005// compute beginning of parameters /locals10061007__ lea(locals, Address(rsp, rcx, Address::times_ptr, -wordSize));10081009// initialize fixed part of activation frame10101011// Assumes rax = return address10121013// allocate and initialize new interpreterState and method expression stack1014// IN(locals) -> locals1015// IN(state) -> previous frame manager state (NULL from stub/c1/c2)1016// destroys rax, rcx, rdx1017// OUT (state) -> new interpreterState1018// OUT(rsp) -> bottom of methods expression stack10191020// save sender_sp1021__ mov(rcx, sender_sp_on_entry);1022// start with NULL previous state1023__ movptr(state, (int32_t)NULL_WORD);1024generate_compute_interpreter_state(state, locals, rcx, true);10251026#ifdef ASSERT1027{ Label L;1028__ movptr(rax, STATE(_stack_base));1029#ifdef _LP641030// duplicate the alignment rsp got after setting stack_base1031__ subptr(rax, frame::arg_reg_save_area_bytes); // windows1032__ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)1033#endif // _LP641034__ cmpptr(rax, rsp);1035__ jcc(Assembler::equal, L);1036__ stop("broken stack frame setup in interpreter");1037__ bind(L);1038}1039#endif10401041const Register unlock_thread = LP64_ONLY(r15_thread) NOT_LP64(rax);1042NOT_LP64(__ movptr(unlock_thread, STATE(_thread));) // get thread1043// Since at this point in the method invocation the exception handler1044// would try to exit the monitor of synchronized methods which hasn't1045// been entered yet, we set the thread local variable1046// _do_not_unlock_if_synchronized to true. The remove_activation will1047// check this flag.10481049const Address do_not_unlock_if_synchronized(unlock_thread,1050in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));1051__ movbool(do_not_unlock_if_synchronized, true);10521053// make sure method is native & not abstract1054#ifdef ASSERT1055__ movl(rax, access_flags);1056{1057Label L;1058__ testl(rax, JVM_ACC_NATIVE);1059__ jcc(Assembler::notZero, L);1060__ stop("tried to execute non-native method as native");1061__ bind(L);1062}1063{ Label L;1064__ testl(rax, JVM_ACC_ABSTRACT);1065__ jcc(Assembler::zero, L);1066__ stop("tried to execute abstract method in interpreter");1067__ bind(L);1068}1069#endif107010711072// increment invocation count & check for overflow1073Label invocation_counter_overflow;1074if (inc_counter) {1075generate_counter_incr(&invocation_counter_overflow, NULL, NULL);1076}10771078Label continue_after_compile;10791080__ bind(continue_after_compile);10811082bang_stack_shadow_pages(true);10831084// reset the _do_not_unlock_if_synchronized flag1085NOT_LP64(__ movl(rax, STATE(_thread));) // get thread1086__ movbool(do_not_unlock_if_synchronized, false);108710881089// check for synchronized native methods1090//1091// Note: This must happen *after* invocation counter check, since1092// when overflow happens, the method should not be locked.1093if (synchronized) {1094// potentially kills rax, rcx, rdx, rdi1095lock_method();1096} else {1097// no synchronization necessary1098#ifdef ASSERT1099{ Label L;1100__ movl(rax, access_flags);1101__ testl(rax, JVM_ACC_SYNCHRONIZED);1102__ jcc(Assembler::zero, L);1103__ stop("method needs synchronization");1104__ bind(L);1105}1106#endif1107}11081109// start execution11101111// jvmti support1112__ notify_method_entry();11131114// work registers1115const Register method = rbx;1116const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rdi);1117const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); // rcx|rscratch11118const Address constMethod (method, Method::const_offset());1119const Address size_of_parameters(t, ConstMethod::size_of_parameters_offset());11201121// allocate space for parameters1122__ movptr(method, STATE(_method));1123__ verify_method_ptr(method);1124__ movptr(t, constMethod);1125__ load_unsigned_short(t, size_of_parameters);1126__ shll(t, 2);1127#ifdef _LP641128__ subptr(rsp, t);1129__ subptr(rsp, frame::arg_reg_save_area_bytes); // windows1130__ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)1131#else1132__ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror1133__ subptr(rsp, t);1134__ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics1135#endif // _LP6411361137// get signature handler1138Label pending_exception_present;11391140{ Label L;1141__ movptr(t, Address(method, Method::signature_handler_offset()));1142__ testptr(t, t);1143__ jcc(Assembler::notZero, L);1144__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false);1145__ movptr(method, STATE(_method));1146__ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);1147__ jcc(Assembler::notEqual, pending_exception_present);1148__ verify_method_ptr(method);1149__ movptr(t, Address(method, Method::signature_handler_offset()));1150__ bind(L);1151}1152#ifdef ASSERT1153{1154Label L;1155__ push(t);1156__ get_thread(t); // get vm's javathread*1157__ cmpptr(t, STATE(_thread));1158__ jcc(Assembler::equal, L);1159__ int3();1160__ bind(L);1161__ pop(t);1162}1163#endif //11641165const Register from_ptr = InterpreterRuntime::SignatureHandlerGenerator::from();1166// call signature handler1167assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");11681169// The generated handlers do not touch RBX (the method oop).1170// However, large signatures cannot be cached and are generated1171// each time here. The slow-path generator will blow RBX1172// sometime, so we must reload it after the call.1173__ movptr(from_ptr, STATE(_locals)); // get the from pointer1174__ call(t);1175__ movptr(method, STATE(_method));1176__ verify_method_ptr(method);11771178// result handler is in rax1179// set result handler1180__ movptr(STATE(_result_handler), rax);118111821183// get native function entry point1184{ Label L;1185__ movptr(rax, Address(method, Method::native_function_offset()));1186__ testptr(rax, rax);1187__ jcc(Assembler::notZero, L);1188__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);1189__ movptr(method, STATE(_method));1190__ verify_method_ptr(method);1191__ movptr(rax, Address(method, Method::native_function_offset()));1192__ bind(L);1193}11941195// pass mirror handle if static call1196{ Label L;1197const int mirror_offset = in_bytes(Klass::java_mirror_offset());1198__ movl(t, Address(method, Method::access_flags_offset()));1199__ testl(t, JVM_ACC_STATIC);1200__ jcc(Assembler::zero, L);1201// get mirror1202__ movptr(t, Address(method, Method:: const_offset()));1203__ movptr(t, Address(t, ConstMethod::constants_offset()));1204__ movptr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes()));1205__ movptr(t, Address(t, mirror_offset));1206// copy mirror into activation object1207__ movptr(STATE(_oop_temp), t);1208// pass handle to mirror1209#ifdef _LP641210__ lea(c_rarg1, STATE(_oop_temp));1211#else1212__ lea(t, STATE(_oop_temp));1213__ movptr(Address(rsp, wordSize), t);1214#endif // _LP641215__ bind(L);1216}1217#ifdef ASSERT1218{1219Label L;1220__ push(t);1221__ get_thread(t); // get vm's javathread*1222__ cmpptr(t, STATE(_thread));1223__ jcc(Assembler::equal, L);1224__ int3();1225__ bind(L);1226__ pop(t);1227}1228#endif //12291230// pass JNIEnv1231#ifdef _LP641232__ lea(c_rarg0, Address(thread, JavaThread::jni_environment_offset()));1233#else1234__ movptr(thread, STATE(_thread)); // get thread1235__ lea(t, Address(thread, JavaThread::jni_environment_offset()));12361237__ movptr(Address(rsp, 0), t);1238#endif // _LP6412391240#ifdef ASSERT1241{1242Label L;1243__ push(t);1244__ get_thread(t); // get vm's javathread*1245__ cmpptr(t, STATE(_thread));1246__ jcc(Assembler::equal, L);1247__ int3();1248__ bind(L);1249__ pop(t);1250}1251#endif //12521253#ifdef ASSERT1254{ Label L;1255__ movl(t, Address(thread, JavaThread::thread_state_offset()));1256__ cmpl(t, _thread_in_Java);1257__ jcc(Assembler::equal, L);1258__ stop("Wrong thread state in native stub");1259__ bind(L);1260}1261#endif12621263// Change state to native (we save the return address in the thread, since it might not1264// be pushed on the stack when we do a a stack traversal). It is enough that the pc()1265// points into the right code segment. It does not have to be the correct return pc.12661267__ set_last_Java_frame(thread, noreg, rbp, __ pc());12681269__ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);12701271__ call(rax);12721273// result potentially in rdx:rax or ST01274__ movptr(method, STATE(_method));1275NOT_LP64(__ movptr(thread, STATE(_thread));) // get thread12761277// The potential result is in ST(0) & rdx:rax1278// With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then1279// we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about1280// anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would1281// be destroyed.1282// It is safe to do these pushes because state is _thread_in_native and return address will be found1283// via _last_native_pc and not via _last_jave_sp12841285// Must save the value of ST(0)/xmm0 since it could be destroyed before we get to result handler1286{ Label Lpush, Lskip;1287ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));1288ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));1289__ cmpptr(STATE(_result_handler), float_handler.addr());1290__ jcc(Assembler::equal, Lpush);1291__ cmpptr(STATE(_result_handler), double_handler.addr());1292__ jcc(Assembler::notEqual, Lskip);1293__ bind(Lpush);1294__ subptr(rsp, 2*wordSize);1295if ( UseSSE < 2 ) {1296__ fstp_d(Address(rsp, 0));1297} else {1298__ movdbl(Address(rsp, 0), xmm0);1299}1300__ bind(Lskip);1301}13021303// save rax:rdx for potential use by result handler.1304__ push(rax);1305#ifndef _LP641306__ push(rdx);1307#endif // _LP6413081309// Verify or restore cpu control state after JNI call1310__ restore_cpu_control_state_after_jni();13111312// change thread state1313__ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);1314if(os::is_MP()) {1315// Write serialization page so VM thread can do a pseudo remote membar.1316// We use the current thread pointer to calculate a thread specific1317// offset to write to within the page. This minimizes bus traffic1318// due to cache line collision.1319__ serialize_memory(thread, rcx);1320}13211322// check for safepoint operation in progress and/or pending suspend requests1323{ Label Continue;13241325__ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),1326SafepointSynchronize::_not_synchronized);13271328// threads running native code and they are expected to self-suspend1329// when leaving the _thread_in_native state. We need to check for1330// pending suspend requests here.1331Label L;1332__ jcc(Assembler::notEqual, L);1333__ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);1334__ jcc(Assembler::equal, Continue);1335__ bind(L);13361337// Don't use call_VM as it will see a possible pending exception and forward it1338// and never return here preventing us from clearing _last_native_pc down below.1339// Also can't use call_VM_leaf either as it will check to see if rsi & rdi are1340// preserved and correspond to the bcp/locals pointers.1341//13421343((MacroAssembler*)_masm)->call_VM_leaf(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),1344thread);1345__ increment(rsp, wordSize);13461347__ movptr(method, STATE(_method));1348__ verify_method_ptr(method);1349__ movptr(thread, STATE(_thread)); // get thread13501351__ bind(Continue);1352}13531354// change thread state1355__ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);13561357__ reset_last_Java_frame(thread, true, true);13581359// reset handle block1360__ movptr(t, Address(thread, JavaThread::active_handles_offset()));1361__ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);13621363// If result was an oop then unbox and save it in the frame1364{ Label L;1365Label no_oop, store_result;1366ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT));1367__ cmpptr(STATE(_result_handler), oop_handler.addr());1368__ jcc(Assembler::notEqual, no_oop);1369#ifndef _LP641370__ pop(rdx);1371#endif // _LP641372__ pop(rax);1373__ testptr(rax, rax);1374__ jcc(Assembler::zero, store_result);1375// unbox1376__ movptr(rax, Address(rax, 0));1377__ bind(store_result);1378__ movptr(STATE(_oop_temp), rax);1379// keep stack depth as expected by pushing oop which will eventually be discarded1380__ push(rax);1381#ifndef _LP641382__ push(rdx);1383#endif // _LP641384__ bind(no_oop);1385}13861387{1388Label no_reguard;1389__ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);1390__ jcc(Assembler::notEqual, no_reguard);13911392__ pusha();1393__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));1394__ popa();13951396__ bind(no_reguard);1397}139813991400// QQQ Seems like for native methods we simply return and the caller will see the pending1401// exception and do the right thing. Certainly the interpreter will, don't know about1402// compiled methods.1403// Seems that the answer to above is no this is wrong. The old code would see the exception1404// and forward it before doing the unlocking and notifying jvmdi that method has exited.1405// This seems wrong need to investigate the spec.14061407// handle exceptions (exception handling will handle unlocking!)1408{ Label L;1409__ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);1410__ jcc(Assembler::zero, L);1411__ bind(pending_exception_present);14121413// There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply1414// return and let caller deal with exception. This skips the unlocking here which1415// seems wrong but seems to be what asm interpreter did. Can't find this in the spec.1416// Note: must preverve method in rbx1417//14181419// remove activation14201421__ movptr(t, STATE(_sender_sp));1422__ leave(); // remove frame anchor1423__ pop(rdi); // get return address1424__ movptr(state, STATE(_prev_link)); // get previous state for return1425__ mov(rsp, t); // set sp to sender sp1426__ push(rdi); // push throwing pc1427// The skips unlocking!! This seems to be what asm interpreter does but seems1428// very wrong. Not clear if this violates the spec.1429__ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));1430__ bind(L);1431}14321433// do unlocking if necessary1434{ Label L;1435__ movl(t, Address(method, Method::access_flags_offset()));1436__ testl(t, JVM_ACC_SYNCHRONIZED);1437__ jcc(Assembler::zero, L);1438// the code below should be shared with interpreter macro assembler implementation1439{ Label unlock;1440const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);1441// BasicObjectLock will be first in list, since this is a synchronized method. However, need1442// to check that the object has not been unlocked by an explicit monitorexit bytecode.1443__ movptr(monitor, STATE(_monitor_base));1444__ subptr(monitor, frame::interpreter_frame_monitor_size() * wordSize); // address of initial monitor14451446__ movptr(t, Address(monitor, BasicObjectLock::obj_offset_in_bytes()));1447__ testptr(t, t);1448__ jcc(Assembler::notZero, unlock);14491450// Entry already unlocked, need to throw exception1451__ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));1452__ should_not_reach_here();14531454__ bind(unlock);1455__ unlock_object(monitor);1456// unlock can blow rbx so restore it for path that needs it below1457__ movptr(method, STATE(_method));1458}1459__ bind(L);1460}14611462// jvmti support1463// Note: This must happen _after_ handling/throwing any exceptions since1464// the exception handler code notifies the runtime of method exits1465// too. If this happens before, method entry/exit notifications are1466// not properly paired (was bug - gri 11/22/99).1467__ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);14681469// restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result1470#ifndef _LP641471__ pop(rdx);1472#endif // _LP641473__ pop(rax);1474__ movptr(t, STATE(_result_handler)); // get result handler1475__ call(t); // call result handler to convert to tosca form14761477// remove activation14781479__ movptr(t, STATE(_sender_sp));14801481__ leave(); // remove frame anchor1482__ pop(rdi); // get return address1483__ movptr(state, STATE(_prev_link)); // get previous state for return (if c++ interpreter was caller)1484__ mov(rsp, t); // set sp to sender sp1485__ jmp(rdi);14861487// invocation counter overflow1488if (inc_counter) {1489// Handle overflow of counter and compile method1490__ bind(invocation_counter_overflow);1491generate_counter_overflow(&continue_after_compile);1492}14931494return entry_point;1495}14961497// Generate entries that will put a result type index into rcx1498void CppInterpreterGenerator::generate_deopt_handling() {14991500Label return_from_deopt_common;15011502// Generate entries that will put a result type index into rcx1503// deopt needs to jump to here to enter the interpreter (return a result)1504deopt_frame_manager_return_atos = __ pc();15051506// rax is live here1507__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT)); // Result stub address array index1508__ jmp(return_from_deopt_common);150915101511// deopt needs to jump to here to enter the interpreter (return a result)1512deopt_frame_manager_return_btos = __ pc();15131514// rax is live here1515__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN)); // Result stub address array index1516__ jmp(return_from_deopt_common);15171518// deopt needs to jump to here to enter the interpreter (return a result)1519deopt_frame_manager_return_itos = __ pc();15201521// rax is live here1522__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT)); // Result stub address array index1523__ jmp(return_from_deopt_common);15241525// deopt needs to jump to here to enter the interpreter (return a result)15261527deopt_frame_manager_return_ltos = __ pc();1528// rax,rdx are live here1529__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG)); // Result stub address array index1530__ jmp(return_from_deopt_common);15311532// deopt needs to jump to here to enter the interpreter (return a result)15331534deopt_frame_manager_return_ftos = __ pc();1535// st(0) is live here1536__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index1537__ jmp(return_from_deopt_common);15381539// deopt needs to jump to here to enter the interpreter (return a result)1540deopt_frame_manager_return_dtos = __ pc();15411542// st(0) is live here1543__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index1544__ jmp(return_from_deopt_common);15451546// deopt needs to jump to here to enter the interpreter (return a result)1547deopt_frame_manager_return_vtos = __ pc();15481549__ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID));15501551// Deopt return common1552// an index is present in rcx that lets us move any possible result being1553// return to the interpreter's stack1554//1555// Because we have a full sized interpreter frame on the youngest1556// activation the stack is pushed too deep to share the tosca to1557// stack converters directly. We shrink the stack to the desired1558// amount and then push result and then re-extend the stack.1559// We could have the code in size_activation layout a short1560// frame for the top activation but that would look different1561// than say sparc (which needs a full size activation because1562// the windows are in the way. Really it could be short? QQQ1563//1564__ bind(return_from_deopt_common);15651566__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));15671568// setup rsp so we can push the "result" as needed.1569__ movptr(rsp, STATE(_stack)); // trim stack (is prepushed)1570__ addptr(rsp, wordSize); // undo prepush15711572ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);1573// Address index(noreg, rcx, Address::times_ptr);1574__ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));1575// __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));1576__ call(rcx); // call result converter15771578__ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume);1579__ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)1580__ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,1581// result if any on stack already )1582__ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth1583}15841585// Generate the code to handle a more_monitors message from the c++ interpreter1586void CppInterpreterGenerator::generate_more_monitors() {158715881589Label entry, loop;1590const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;1591// 1. compute new pointers // rsp: old expression stack top1592__ movptr(rdx, STATE(_stack_base)); // rdx: old expression stack bottom1593__ subptr(rsp, entry_size); // move expression stack top limit1594__ subptr(STATE(_stack), entry_size); // update interpreter stack top1595__ subptr(STATE(_stack_limit), entry_size); // inform interpreter1596__ subptr(rdx, entry_size); // move expression stack bottom1597__ movptr(STATE(_stack_base), rdx); // inform interpreter1598__ movptr(rcx, STATE(_stack)); // set start value for copy loop1599__ jmp(entry);1600// 2. move expression stack contents1601__ bind(loop);1602__ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location1603__ movptr(Address(rcx, 0), rbx); // and store it at new location1604__ addptr(rcx, wordSize); // advance to next word1605__ bind(entry);1606__ cmpptr(rcx, rdx); // check if bottom reached1607__ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word1608// now zero the slot so we can find it.1609__ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL_WORD);1610__ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors);1611}161216131614// Initial entry to C++ interpreter from the call_stub.1615// This entry point is called the frame manager since it handles the generation1616// of interpreter activation frames via requests directly from the vm (via call_stub)1617// and via requests from the interpreter. The requests from the call_stub happen1618// directly thru the entry point. Requests from the interpreter happen via returning1619// from the interpreter and examining the message the interpreter has returned to1620// the frame manager. The frame manager can take the following requests:16211622// NO_REQUEST - error, should never happen.1623// MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and1624// allocate a new monitor.1625// CALL_METHOD - setup a new activation to call a new method. Very similar to what1626// happens during entry during the entry via the call stub.1627// RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.1628//1629// Arguments:1630//1631// rbx: Method*1632// rcx: receiver - unused (retrieved from stack as needed)1633// rsi/r13: previous frame manager state (NULL from the call_stub/c1/c2)1634//1635//1636// Stack layout at entry1637//1638// [ return address ] <--- rsp1639// [ parameter n ]1640// ...1641// [ parameter 1 ]1642// [ expression stack ]1643//1644//1645// We are free to blow any registers we like because the call_stub which brought us here1646// initially has preserved the callee save registers already.1647//1648//16491650static address interpreter_frame_manager = NULL;16511652address InterpreterGenerator::generate_normal_entry(bool synchronized) {16531654// rbx: Method*1655// rsi/r13: sender sp16561657// Because we redispatch "recursive" interpreter entries thru this same entry point1658// the "input" register usage is a little strange and not what you expect coming1659// from the call_stub. From the call stub rsi/rdi (current/previous) interpreter1660// state are NULL but on "recursive" dispatches they are what you'd expect.1661// rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2)166216631664// A single frame manager is plenty as we don't specialize for synchronized. We could and1665// the code is pretty much ready. Would need to change the test below and for good measure1666// modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized1667// routines. Not clear this is worth it yet.16681669if (interpreter_frame_manager) return interpreter_frame_manager;16701671address entry_point = __ pc();16721673// Fast accessor methods share this entry point.1674// This works because frame manager is in the same codelet1675if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path);16761677Label dispatch_entry_2;1678__ movptr(rcx, sender_sp_on_entry);1679__ movptr(state, (int32_t)NULL_WORD); // no current activation16801681__ jmp(dispatch_entry_2);16821683const Register locals = rdi;16841685Label re_dispatch;16861687__ bind(re_dispatch);16881689// save sender sp (doesn't include return address1690__ lea(rcx, Address(rsp, wordSize));16911692__ bind(dispatch_entry_2);16931694// save sender sp1695__ push(rcx);16961697const Address constMethod (rbx, Method::const_offset());1698const Address access_flags (rbx, Method::access_flags_offset());1699const Address size_of_parameters(rdx, ConstMethod::size_of_parameters_offset());1700const Address size_of_locals (rdx, ConstMethod::size_of_locals_offset());17011702// const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);1703// const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset * wordSize);1704// const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));17051706// get parameter size (always needed)1707__ movptr(rdx, constMethod);1708__ load_unsigned_short(rcx, size_of_parameters);17091710// rbx: Method*1711// rcx: size of parameters1712__ load_unsigned_short(rdx, size_of_locals); // get size of locals in words17131714__ subptr(rdx, rcx); // rdx = no. of additional locals17151716// see if we've got enough room on the stack for locals plus overhead.1717generate_stack_overflow_check(); // C++17181719// c++ interpreter does not use stack banging or any implicit exceptions1720// leave for now to verify that check is proper.1721bang_stack_shadow_pages(false);1722172317241725// compute beginning of parameters (rdi)1726__ lea(locals, Address(rsp, rcx, Address::times_ptr, wordSize));17271728// save sender's sp1729// __ movl(rcx, rsp);17301731// get sender's sp1732__ pop(rcx);17331734// get return address1735__ pop(rax);17361737// rdx - # of additional locals1738// allocate space for locals1739// explicitly initialize locals1740{1741Label exit, loop;1742__ testl(rdx, rdx); // (32bit ok)1743__ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 01744__ bind(loop);1745__ push((int32_t)NULL_WORD); // initialize local variables1746__ decrement(rdx); // until everything initialized1747__ jcc(Assembler::greater, loop);1748__ bind(exit);1749}175017511752// Assumes rax = return address17531754// allocate and initialize new interpreterState and method expression stack1755// IN(locals) -> locals1756// IN(state) -> any current interpreter activation1757// destroys rax, rcx, rdx, rdi1758// OUT (state) -> new interpreterState1759// OUT(rsp) -> bottom of methods expression stack17601761generate_compute_interpreter_state(state, locals, rcx, false);17621763// Call interpreter17641765Label call_interpreter;1766__ bind(call_interpreter);17671768// c++ interpreter does not use stack banging or any implicit exceptions1769// leave for now to verify that check is proper.1770bang_stack_shadow_pages(false);177117721773// Call interpreter enter here if message is1774// set and we know stack size is valid17751776Label call_interpreter_2;17771778__ bind(call_interpreter_2);17791780{1781const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);17821783#ifdef _LP641784__ mov(c_rarg0, state);1785#else1786__ push(state); // push arg to interpreter1787__ movptr(thread, STATE(_thread));1788#endif // _LP6417891790// We can setup the frame anchor with everything we want at this point1791// as we are thread_in_Java and no safepoints can occur until we go to1792// vm mode. We do have to clear flags on return from vm but that is it1793//1794__ movptr(Address(thread, JavaThread::last_Java_fp_offset()), rbp);1795__ movptr(Address(thread, JavaThread::last_Java_sp_offset()), rsp);17961797// Call the interpreter17981799RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run));1800RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks));18011802__ call(JvmtiExport::can_post_interpreter_events() ? checking : normal);1803NOT_LP64(__ pop(rax);) // discard parameter to run1804//1805// state is preserved since it is callee saved1806//18071808// reset_last_Java_frame18091810NOT_LP64(__ movl(thread, STATE(_thread));)1811__ reset_last_Java_frame(thread, true, true);1812}18131814// examine msg from interpreter to determine next action18151816__ movl(rdx, STATE(_msg)); // Get new message18171818Label call_method;1819Label return_from_interpreted_method;1820Label throw_exception;1821Label bad_msg;1822Label do_OSR;18231824__ cmpl(rdx, (int32_t)BytecodeInterpreter::call_method);1825__ jcc(Assembler::equal, call_method);1826__ cmpl(rdx, (int32_t)BytecodeInterpreter::return_from_method);1827__ jcc(Assembler::equal, return_from_interpreted_method);1828__ cmpl(rdx, (int32_t)BytecodeInterpreter::do_osr);1829__ jcc(Assembler::equal, do_OSR);1830__ cmpl(rdx, (int32_t)BytecodeInterpreter::throwing_exception);1831__ jcc(Assembler::equal, throw_exception);1832__ cmpl(rdx, (int32_t)BytecodeInterpreter::more_monitors);1833__ jcc(Assembler::notEqual, bad_msg);18341835// Allocate more monitor space, shuffle expression stack....18361837generate_more_monitors();18381839__ jmp(call_interpreter);18401841// uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)1842unctrap_frame_manager_entry = __ pc();1843//1844// Load the registers we need.1845__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));1846__ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth1847__ jmp(call_interpreter_2);1848184918501851//=============================================================================1852// Returning from a compiled method into a deopted method. The bytecode at the1853// bcp has completed. The result of the bytecode is in the native abi (the tosca1854// for the template based interpreter). Any stack space that was used by the1855// bytecode that has completed has been removed (e.g. parameters for an invoke)1856// so all that we have to do is place any pending result on the expression stack1857// and resume execution on the next bytecode.185818591860generate_deopt_handling();1861__ jmp(call_interpreter);186218631864// Current frame has caught an exception we need to dispatch to the1865// handler. We can get here because a native interpreter frame caught1866// an exception in which case there is no handler and we must rethrow1867// If it is a vanilla interpreted frame the we simply drop into the1868// interpreter and let it do the lookup.18691870Interpreter::_rethrow_exception_entry = __ pc();1871// rax: exception1872// rdx: return address/pc that threw exception18731874Label return_with_exception;1875Label unwind_and_forward;18761877// restore state pointer.1878__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));18791880__ movptr(rbx, STATE(_method)); // get method1881#ifdef _LP641882__ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);1883#else1884__ movl(rcx, STATE(_thread)); // get thread18851886// Store exception with interpreter will expect it1887__ movptr(Address(rcx, Thread::pending_exception_offset()), rax);1888#endif // _LP6418891890// is current frame vanilla or native?18911892__ movl(rdx, access_flags);1893__ testl(rdx, JVM_ACC_NATIVE);1894__ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly18951896// We drop thru to unwind a native interpreted frame with a pending exception1897// We jump here for the initial interpreter frame with exception pending1898// We unwind the current acivation and forward it to our caller.18991900__ bind(unwind_and_forward);19011902// unwind rbp, return stack to unextended value and re-push return address19031904__ movptr(rcx, STATE(_sender_sp));1905__ leave();1906__ pop(rdx);1907__ mov(rsp, rcx);1908__ push(rdx);1909__ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));19101911// Return point from a call which returns a result in the native abi1912// (c1/c2/jni-native). This result must be processed onto the java1913// expression stack.1914//1915// A pending exception may be present in which case there is no result present19161917Label resume_interpreter;1918Label do_float;1919Label do_double;1920Label done_conv;19211922// The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases1923if (UseSSE < 2) {1924__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));1925__ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed1926__ movl(rcx, Address(rbx, Method::result_index_offset()));1927__ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index1928__ jcc(Assembler::equal, do_float);1929__ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index1930__ jcc(Assembler::equal, do_double);1931#if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)1932__ empty_FPU_stack();1933#endif // COMPILER21934__ jmp(done_conv);19351936__ bind(do_float);1937#ifdef COMPILER21938for (int i = 1; i < 8; i++) {1939__ ffree(i);1940}1941#endif // COMPILER21942__ jmp(done_conv);1943__ bind(do_double);1944#ifdef COMPILER21945for (int i = 1; i < 8; i++) {1946__ ffree(i);1947}1948#endif // COMPILER21949__ jmp(done_conv);1950} else {1951__ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");1952__ jmp(done_conv);1953}19541955// Return point to interpreter from compiled/native method1956InternalAddress return_from_native_method(__ pc());19571958__ bind(done_conv);195919601961// Result if any is in tosca. The java expression stack is in the state that the1962// calling convention left it (i.e. params may or may not be present)1963// Copy the result from tosca and place it on java expression stack.19641965// Restore rsi/r13 as compiled code may not preserve it19661967__ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));19681969// restore stack to what we had when we left (in case i2c extended it)19701971__ movptr(rsp, STATE(_stack));1972__ lea(rsp, Address(rsp, wordSize));19731974// If there is a pending exception then we don't really have a result to process19751976#ifdef _LP641977__ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);1978#else1979__ movptr(rcx, STATE(_thread)); // get thread1980__ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);1981#endif // _LP641982__ jcc(Assembler::notZero, return_with_exception);19831984// get method just executed1985__ movptr(rbx, STATE(_result._to_call._callee));19861987// callee left args on top of expression stack, remove them1988__ movptr(rcx, constMethod);1989__ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));19901991__ lea(rsp, Address(rsp, rcx, Address::times_ptr));19921993__ movl(rcx, Address(rbx, Method::result_index_offset()));1994ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);1995// Address index(noreg, rax, Address::times_ptr);1996__ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));1997// __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));1998__ call(rcx); // call result converter1999__ jmp(resume_interpreter);20002001// An exception is being caught on return to a vanilla interpreter frame.2002// Empty the stack and resume interpreter20032004__ bind(return_with_exception);20052006// Exception present, empty stack2007__ movptr(rsp, STATE(_stack_base));2008__ jmp(resume_interpreter);20092010// Return from interpreted method we return result appropriate to the caller (i.e. "recursive"2011// interpreter call, or native) and unwind this interpreter activation.2012// All monitors should be unlocked.20132014__ bind(return_from_interpreted_method);20152016Label return_to_initial_caller;20172018__ movptr(rbx, STATE(_method)); // get method just executed2019__ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?2020__ movl(rax, Address(rbx, Method::result_index_offset())); // get result type index2021__ jcc(Assembler::equal, return_to_initial_caller); // back to native code (call_stub/c1/c2)20222023// Copy result to callers java stack2024ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack);2025// Address index(noreg, rax, Address::times_ptr);20262027__ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_ptr)));2028// __ movl(rax, Address(noreg, rax, Address::times_ptr, int(AbstractInterpreter::_stack_to_stack)));2029__ call(rax); // call result converter20302031Label unwind_recursive_activation;2032__ bind(unwind_recursive_activation);20332034// returning to interpreter method from "recursive" interpreter call2035// result converter left rax pointing to top of the java stack for method we are returning2036// to. Now all we must do is unwind the state from the completed call20372038__ movptr(state, STATE(_prev_link)); // unwind state2039__ leave(); // pop the frame2040__ mov(rsp, rax); // unwind stack to remove args20412042// Resume the interpreter. The current frame contains the current interpreter2043// state object.2044//20452046__ bind(resume_interpreter);20472048// state == interpreterState object for method we are resuming20492050__ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume);2051__ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)2052__ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,2053// result if any on stack already )2054__ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth2055__ jmp(call_interpreter_2); // No need to bang20562057// interpreter returning to native code (call_stub/c1/c2)2058// convert result and unwind initial activation2059// rax - result index20602061__ bind(return_to_initial_caller);2062ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi);2063// Address index(noreg, rax, Address::times_ptr);20642065__ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_ptr)));2066__ call(rax); // call result converter20672068Label unwind_initial_activation;2069__ bind(unwind_initial_activation);20702071// RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0))20722073/* Current stack picture20742075[ incoming parameters ]2076[ extra locals ]2077[ return address to CALL_STUB/C1/C2]2078fp -> [ CALL_STUB/C1/C2 fp ]2079BytecodeInterpreter object2080expression stack2081sp ->20822083*/20842085// return restoring the stack to the original sender_sp value20862087__ movptr(rcx, STATE(_sender_sp));2088__ leave();2089__ pop(rdi); // get return address2090// set stack to sender's sp2091__ mov(rsp, rcx);2092__ jmp(rdi); // return to call_stub20932094// OSR request, adjust return address to make current frame into adapter frame2095// and enter OSR nmethod20962097__ bind(do_OSR);20982099Label remove_initial_frame;21002101// We are going to pop this frame. Is there another interpreter frame underneath2102// it or is it callstub/compiled?21032104// Move buffer to the expected parameter location2105__ movptr(rcx, STATE(_result._osr._osr_buf));21062107__ movptr(rax, STATE(_result._osr._osr_entry));21082109__ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?2110__ jcc(Assembler::equal, remove_initial_frame); // back to native code (call_stub/c1/c2)21112112__ movptr(sender_sp_on_entry, STATE(_sender_sp)); // get sender's sp in expected register2113__ leave(); // pop the frame2114__ mov(rsp, sender_sp_on_entry); // trim any stack expansion211521162117// We know we are calling compiled so push specialized return2118// method uses specialized entry, push a return so we look like call stub setup2119// this path will handle fact that result is returned in registers and not2120// on the java stack.21212122__ pushptr(return_from_native_method.addr());21232124__ jmp(rax);21252126__ bind(remove_initial_frame);21272128__ movptr(rdx, STATE(_sender_sp));2129__ leave();2130// get real return2131__ pop(rsi);2132// set stack to sender's sp2133__ mov(rsp, rdx);2134// repush real return2135__ push(rsi);2136// Enter OSR nmethod2137__ jmp(rax);21382139214021412142// Call a new method. All we do is (temporarily) trim the expression stack2143// push a return address to bring us back to here and leap to the new entry.21442145__ bind(call_method);21462147// stack points to next free location and not top element on expression stack2148// method expects sp to be pointing to topmost element21492150__ movptr(rsp, STATE(_stack)); // pop args to c++ interpreter, set sp to java stack top2151__ lea(rsp, Address(rsp, wordSize));21522153__ movptr(rbx, STATE(_result._to_call._callee)); // get method to execute21542155// don't need a return address if reinvoking interpreter21562157// Make it look like call_stub calling conventions21582159// Get (potential) receiver2160// get size of parameters in words2161__ movptr(rcx, constMethod);2162__ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));21632164ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));2165__ pushptr(recursive.addr()); // make it look good in the debugger21662167InternalAddress entry(entry_point);2168__ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter?2169__ jcc(Assembler::equal, re_dispatch); // yes21702171__ pop(rax); // pop dummy address217221732174// get specialized entry2175__ movptr(rax, STATE(_result._to_call._callee_entry_point));2176// set sender SP2177__ mov(sender_sp_on_entry, rsp);21782179// method uses specialized entry, push a return so we look like call stub setup2180// this path will handle fact that result is returned in registers and not2181// on the java stack.21822183__ pushptr(return_from_native_method.addr());21842185__ jmp(rax);21862187__ bind(bad_msg);2188__ stop("Bad message from interpreter");21892190// Interpreted method "returned" with an exception pass it on...2191// Pass result, unwind activation and continue/return to interpreter/call_stub2192// We handle result (if any) differently based on return to interpreter or call_stub21932194Label unwind_initial_with_pending_exception;21952196__ bind(throw_exception);2197__ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from recursive interpreter call?2198__ jcc(Assembler::equal, unwind_initial_with_pending_exception); // no, back to native code (call_stub/c1/c2)2199__ movptr(rax, STATE(_locals)); // pop parameters get new stack value2200__ addptr(rax, wordSize); // account for prepush before we return2201__ jmp(unwind_recursive_activation);22022203__ bind(unwind_initial_with_pending_exception);22042205// We will unwind the current (initial) interpreter frame and forward2206// the exception to the caller. We must put the exception in the2207// expected register and clear pending exception and then forward.22082209__ jmp(unwind_and_forward);22102211interpreter_frame_manager = entry_point;2212return entry_point;2213}22142215address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {2216// determine code generation flags2217bool synchronized = false;2218address entry_point = NULL;22192220switch (kind) {2221case Interpreter::zerolocals : break;2222case Interpreter::zerolocals_synchronized: synchronized = true; break;2223case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;2224case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;2225case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;2226case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;2227case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;2228case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;22292230case Interpreter::java_lang_math_sin : // fall thru2231case Interpreter::java_lang_math_cos : // fall thru2232case Interpreter::java_lang_math_tan : // fall thru2233case Interpreter::java_lang_math_abs : // fall thru2234case Interpreter::java_lang_math_log : // fall thru2235case Interpreter::java_lang_math_log10 : // fall thru2236case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;2237case Interpreter::java_lang_ref_reference_get2238: entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;2239default : ShouldNotReachHere(); break;2240}22412242if (entry_point) return entry_point;22432244return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);22452246}22472248InterpreterGenerator::InterpreterGenerator(StubQueue* code)2249: CppInterpreterGenerator(code) {2250generate_all(); // down here so it can be "virtual"2251}22522253// Deoptimization helpers for C++ interpreter22542255// How much stack a method activation needs in words.2256int AbstractInterpreter::size_top_interpreter_activation(Method* method) {22572258const int stub_code = 4; // see generate_call_stub2259// Save space for one monitor to get into the interpreted method in case2260// the method is synchronized2261int monitor_size = method->is_synchronized() ?22621*frame::interpreter_frame_monitor_size() : 0;22632264// total static overhead size. Account for interpreter state object, return2265// address, saved rbp and 2 words for a "static long no_params() method" issue.22662267const int overhead_size = sizeof(BytecodeInterpreter)/wordSize +2268( frame::sender_sp_offset - frame::link_offset) + 2;22692270const int method_stack = (method->max_locals() + method->max_stack()) *2271Interpreter::stackElementWords;2272return overhead_size + method_stack + stub_code;2273}22742275// returns the activation size.2276static int size_activation_helper(int extra_locals_size, int monitor_size) {2277return (extra_locals_size + // the addition space for locals22782*BytesPerWord + // return address and saved rbp22792*BytesPerWord + // "static long no_params() method" issue2280sizeof(BytecodeInterpreter) + // interpreterState2281monitor_size); // monitors2282}22832284void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,2285frame* caller,2286frame* current,2287Method* method,2288intptr_t* locals,2289intptr_t* stack,2290intptr_t* stack_base,2291intptr_t* monitor_base,2292intptr_t* frame_bottom,2293bool is_top_frame2294)2295{2296// What about any vtable?2297//2298to_fill->_thread = JavaThread::current();2299// This gets filled in later but make it something recognizable for now2300to_fill->_bcp = method->code_base();2301to_fill->_locals = locals;2302to_fill->_constants = method->constants()->cache();2303to_fill->_method = method;2304to_fill->_mdx = NULL;2305to_fill->_stack = stack;2306if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {2307to_fill->_msg = deopt_resume2;2308} else {2309to_fill->_msg = method_resume;2310}2311to_fill->_result._to_call._bcp_advance = 0;2312to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone2313to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone2314to_fill->_prev_link = NULL;23152316to_fill->_sender_sp = caller->unextended_sp();23172318if (caller->is_interpreted_frame()) {2319interpreterState prev = caller->get_interpreterState();2320to_fill->_prev_link = prev;2321// *current->register_addr(GR_Iprev_state) = (intptr_t) prev;2322// Make the prev callee look proper2323prev->_result._to_call._callee = method;2324if (*prev->_bcp == Bytecodes::_invokeinterface) {2325prev->_result._to_call._bcp_advance = 5;2326} else {2327prev->_result._to_call._bcp_advance = 3;2328}2329}2330to_fill->_oop_temp = NULL;2331to_fill->_stack_base = stack_base;2332// Need +1 here because stack_base points to the word just above the first expr stack entry2333// and stack_limit is supposed to point to the word just below the last expr stack entry.2334// See generate_compute_interpreter_state.2335to_fill->_stack_limit = stack_base - (method->max_stack() + 1);2336to_fill->_monitor_base = (BasicObjectLock*) monitor_base;23372338to_fill->_self_link = to_fill;2339assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,2340"Stack top out of range");2341}234223432344static int frame_size_helper(int max_stack,2345int tempcount,2346int moncount,2347int callee_param_count,2348int callee_locals,2349bool is_top_frame,2350int& monitor_size,2351int& full_frame_size) {2352int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;2353monitor_size = sizeof(BasicObjectLock) * moncount;23542355// First calculate the frame size without any java expression stack2356int short_frame_size = size_activation_helper(extra_locals_size,2357monitor_size);23582359// Now with full size expression stack2360full_frame_size = short_frame_size + max_stack * BytesPerWord;23612362// and now with only live portion of the expression stack2363short_frame_size = short_frame_size + tempcount * BytesPerWord;23642365// the size the activation is right now. Only top frame is full size2366int frame_size = (is_top_frame ? full_frame_size : short_frame_size);2367return frame_size;2368}23692370int AbstractInterpreter::size_activation(int max_stack,2371int tempcount,2372int extra_args,2373int moncount,2374int callee_param_count,2375int callee_locals,2376bool is_top_frame) {2377assert(extra_args == 0, "FIX ME");2378// NOTE: return size is in words not bytes23792380// Calculate the amount our frame will be adjust by the callee. For top frame2381// this is zero.23822383// NOTE: ia64 seems to do this wrong (or at least backwards) in that it2384// calculates the extra locals based on itself. Not what the callee does2385// to it. So it ignores last_frame_adjust value. Seems suspicious as far2386// as getting sender_sp correct.23872388int unused_monitor_size = 0;2389int unused_full_frame_size = 0;2390return frame_size_helper(max_stack, tempcount, moncount, callee_param_count, callee_locals,2391is_top_frame, unused_monitor_size, unused_full_frame_size)/BytesPerWord;2392}23932394void AbstractInterpreter::layout_activation(Method* method,2395int tempcount, //2396int popframe_extra_args,2397int moncount,2398int caller_actual_parameters,2399int callee_param_count,2400int callee_locals,2401frame* caller,2402frame* interpreter_frame,2403bool is_top_frame,2404bool is_bottom_frame) {24052406assert(popframe_extra_args == 0, "FIX ME");2407// NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()2408// does as far as allocating an interpreter frame.2409// Set up the method, locals, and monitors.2410// The frame interpreter_frame is guaranteed to be the right size,2411// as determined by a previous call to the size_activation() method.2412// It is also guaranteed to be walkable even though it is in a skeletal state2413// NOTE: tempcount is the current size of the java expression stack. For top most2414// frames we will allocate a full sized expression stack and not the curback2415// version that non-top frames have.24162417int monitor_size = 0;2418int full_frame_size = 0;2419int frame_size = frame_size_helper(method->max_stack(), tempcount, moncount, callee_param_count, callee_locals,2420is_top_frame, monitor_size, full_frame_size);24212422#ifdef ASSERT2423assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");2424#endif24252426// MUCHO HACK24272428intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));24292430/* Now fillin the interpreterState object */24312432// The state object is the first thing on the frame and easily located24332434interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));243524362437// Find the locals pointer. This is rather simple on x86 because there is no2438// confusing rounding at the callee to account for. We can trivially locate2439// our locals based on the current fp().2440// Note: the + 2 is for handling the "static long no_params() method" issue.2441// (too bad I don't really remember that issue well...)24422443intptr_t* locals;2444// If the caller is interpreted we need to make sure that locals points to the first2445// argument that the caller passed and not in an area where the stack might have been extended.2446// because the stack to stack to converter needs a proper locals value in order to remove the2447// arguments from the caller and place the result in the proper location. Hmm maybe it'd be2448// simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code2449// adjust the stack?? HMMM QQQ2450//2451if (caller->is_interpreted_frame()) {2452// locals must agree with the caller because it will be used to set the2453// caller's tos when we return.2454interpreterState prev = caller->get_interpreterState();2455// stack() is prepushed.2456locals = prev->stack() + method->size_of_parameters();2457// locals = caller->unextended_sp() + (method->size_of_parameters() - 1);2458if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {2459// os::breakpoint();2460}2461} else {2462// this is where a c2i would have placed locals (except for the +2)2463locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;2464}24652466intptr_t* monitor_base = (intptr_t*) cur_state;2467intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);2468/* +1 because stack is always prepushed */2469intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);247024712472BytecodeInterpreter::layout_interpreterState(cur_state,2473caller,2474interpreter_frame,2475method,2476locals,2477stack,2478stack_base,2479monitor_base,2480frame_bottom,2481is_top_frame);24822483// BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());2484}24852486#endif // CC_INTERP (all)248724882489