0N/A/*
3790N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "asm/assembler.hpp"
1879N/A#include "interpreter/bytecodeHistogram.hpp"
1879N/A#include "interpreter/cppInterpreter.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/interpreterGenerator.hpp"
1879N/A#include "interpreter/interpreterRuntime.hpp"
1879N/A#include "oops/arrayOop.hpp"
1879N/A#include "oops/methodDataOop.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "prims/jvmtiExport.hpp"
1879N/A#include "prims/jvmtiThreadState.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/deoptimization.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "runtime/synchronizer.hpp"
1879N/A#include "runtime/timer.hpp"
1879N/A#include "runtime/vframeArray.hpp"
1879N/A#include "utilities/debug.hpp"
1879N/A#ifdef SHARK
1879N/A#include "shark/shark_globals.hpp"
1879N/A#endif
0N/A
0N/A#ifdef CC_INTERP
0N/A
0N/A// Routine exists to make tracebacks look decent in debugger
0N/A// while we are recursed in the frame manager/c++ interpreter.
0N/A// We could use an address in the frame manager but having
0N/A// frames look natural in the debugger is a plus.
0N/Aextern "C" void RecursiveInterpreterActivation(interpreterState istate )
0N/A{
0N/A //
0N/A ShouldNotReachHere();
0N/A}
0N/A
0N/A
0N/A#define __ _masm->
0N/A#define STATE(field_name) (Address(state, byte_offset_of(BytecodeInterpreter, field_name)))
0N/A
0N/ALabel fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized
0N/A // c++ interpreter entry point this holds that entry point label.
0N/A
304N/A// default registers for state and sender_sp
304N/A// state and sender_sp are the same on 32bit because we have no choice.
304N/A// state could be rsi on 64bit but it is an arg reg and not callee save
304N/A// so r13 is better choice.
304N/A
304N/Aconst Register state = NOT_LP64(rsi) LP64_ONLY(r13);
304N/Aconst Register sender_sp_on_entry = NOT_LP64(rsi) LP64_ONLY(r13);
304N/A
0N/A// NEEDED for JVMTI?
0N/A// address AbstractInterpreter::_remove_activation_preserving_args_entry;
0N/A
0N/Astatic address unctrap_frame_manager_entry = NULL;
0N/A
0N/Astatic address deopt_frame_manager_return_atos = NULL;
0N/Astatic address deopt_frame_manager_return_btos = NULL;
0N/Astatic address deopt_frame_manager_return_itos = NULL;
0N/Astatic address deopt_frame_manager_return_ltos = NULL;
0N/Astatic address deopt_frame_manager_return_ftos = NULL;
0N/Astatic address deopt_frame_manager_return_dtos = NULL;
0N/Astatic address deopt_frame_manager_return_vtos = NULL;
0N/A
0N/Aint AbstractInterpreter::BasicType_as_index(BasicType type) {
0N/A int i = 0;
0N/A switch (type) {
0N/A case T_BOOLEAN: i = 0; break;
0N/A case T_CHAR : i = 1; break;
0N/A case T_BYTE : i = 2; break;
0N/A case T_SHORT : i = 3; break;
0N/A case T_INT : i = 4; break;
0N/A case T_VOID : i = 5; break;
0N/A case T_FLOAT : i = 8; break;
0N/A case T_LONG : i = 9; break;
0N/A case T_DOUBLE : i = 6; break;
0N/A case T_OBJECT : // fall through
0N/A case T_ARRAY : i = 7; break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
0N/A return i;
0N/A}
0N/A
0N/A// Is this pc anywhere within code owned by the interpreter?
0N/A// This only works for pc that might possibly be exposed to frame
0N/A// walkers. It clearly misses all of the actual c++ interpreter
0N/A// implementation
0N/Abool CppInterpreter::contains(address pc) {
0N/A return (_code->contains(pc) ||
0N/A pc == CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
0N/A}
0N/A
0N/A
0N/Aaddress CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
0N/A address entry = __ pc();
0N/A switch (type) {
0N/A case T_BOOLEAN: __ c2bool(rax); break;
0N/A case T_CHAR : __ andl(rax, 0xFFFF); break;
0N/A case T_BYTE : __ sign_extend_byte (rax); break;
0N/A case T_SHORT : __ sign_extend_short(rax); break;
0N/A case T_VOID : // fall thru
0N/A case T_LONG : // fall thru
0N/A case T_INT : /* nothing to do */ break;
304N/A
0N/A case T_DOUBLE :
0N/A case T_FLOAT :
304N/A {
304N/A const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
304N/A __ pop(t); // remove return address first
0N/A // Must return a result for interpreter or compiler. In SSE
0N/A // mode, results are returned in xmm0 and the FPU stack must
0N/A // be empty.
0N/A if (type == T_FLOAT && UseSSE >= 1) {
304N/A#ifndef _LP64
0N/A // Load ST0
0N/A __ fld_d(Address(rsp, 0));
0N/A // Store as float and empty fpu stack
0N/A __ fstp_s(Address(rsp, 0));
304N/A#endif // !_LP64
0N/A // and reload
0N/A __ movflt(xmm0, Address(rsp, 0));
0N/A } else if (type == T_DOUBLE && UseSSE >= 2 ) {
0N/A __ movdbl(xmm0, Address(rsp, 0));
0N/A } else {
0N/A // restore ST0
0N/A __ fld_d(Address(rsp, 0));
0N/A }
0N/A // and pop the temp
304N/A __ addptr(rsp, 2 * wordSize);
304N/A __ push(t); // restore return address
0N/A }
0N/A break;
0N/A case T_OBJECT :
0N/A // retrieve result from frame
304N/A __ movptr(rax, STATE(_oop_temp));
0N/A // and verify it
0N/A __ verify_oop(rax);
0N/A break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A __ ret(0); // return from result handler
0N/A return entry;
0N/A}
0N/A
0N/A// tosca based result to c++ interpreter stack based result.
0N/A// Result goes to top of native stack.
0N/A
0N/A#undef EXTEND // SHOULD NOT BE NEEDED
0N/Aaddress CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
0N/A // A result is in the tosca (abi result) from either a native method call or compiled
0N/A // code. Place this result on the java expression stack so C++ interpreter can use it.
0N/A address entry = __ pc();
0N/A
0N/A const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
304N/A __ pop(t); // remove return address first
0N/A switch (type) {
0N/A case T_VOID:
0N/A break;
0N/A case T_BOOLEAN:
0N/A#ifdef EXTEND
0N/A __ c2bool(rax);
0N/A#endif
304N/A __ push(rax);
0N/A break;
0N/A case T_CHAR :
0N/A#ifdef EXTEND
0N/A __ andl(rax, 0xFFFF);
0N/A#endif
304N/A __ push(rax);
0N/A break;
0N/A case T_BYTE :
0N/A#ifdef EXTEND
0N/A __ sign_extend_byte (rax);
0N/A#endif
304N/A __ push(rax);
0N/A break;
0N/A case T_SHORT :
0N/A#ifdef EXTEND
0N/A __ sign_extend_short(rax);
0N/A#endif
304N/A __ push(rax);
0N/A break;
0N/A case T_LONG :
304N/A __ push(rdx); // pushes useless junk on 64bit
304N/A __ push(rax);
0N/A break;
0N/A case T_INT :
304N/A __ push(rax);
0N/A break;
0N/A case T_FLOAT :
304N/A // Result is in ST(0)/xmm0
304N/A __ subptr(rsp, wordSize);
0N/A if ( UseSSE < 1) {
304N/A __ fstp_s(Address(rsp, 0));
0N/A } else {
0N/A __ movflt(Address(rsp, 0), xmm0);
0N/A }
0N/A break;
0N/A case T_DOUBLE :
304N/A __ subptr(rsp, 2*wordSize);
0N/A if ( UseSSE < 2 ) {
304N/A __ fstp_d(Address(rsp, 0));
0N/A } else {
0N/A __ movdbl(Address(rsp, 0), xmm0);
0N/A }
0N/A break;
0N/A case T_OBJECT :
0N/A __ verify_oop(rax); // verify it
304N/A __ push(rax);
0N/A break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A __ jmp(t); // return from result handler
0N/A return entry;
0N/A}
0N/A
0N/Aaddress CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
0N/A // A result is in the java expression stack of the interpreted method that has just
0N/A // returned. Place this result on the java expression stack of the caller.
0N/A //
304N/A // The current interpreter activation in rsi/r13 is for the method just returning its
0N/A // result. So we know that the result of this method is on the top of the current
0N/A // execution stack (which is pre-pushed) and will be return to the top of the caller
0N/A // stack. The top of the callers stack is the bottom of the locals of the current
0N/A // activation.
0N/A // Because of the way activation are managed by the frame manager the value of rsp is
0N/A // below both the stack top of the current activation and naturally the stack top
0N/A // of the calling activation. This enable this routine to leave the return address
0N/A // to the frame manager on the stack and do a vanilla return.
0N/A //
304N/A // On entry: rsi/r13 - interpreter state of activation returning a (potential) result
304N/A // On Return: rsi/r13 - unchanged
0N/A // rax - new stack top for caller activation (i.e. activation in _prev_link)
0N/A //
0N/A // Can destroy rdx, rcx.
0N/A //
0N/A
0N/A address entry = __ pc();
0N/A const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
0N/A switch (type) {
0N/A case T_VOID:
304N/A __ movptr(rax, STATE(_locals)); // pop parameters get new stack value
304N/A __ addptr(rax, wordSize); // account for prepush before we return
0N/A break;
0N/A case T_FLOAT :
0N/A case T_BOOLEAN:
0N/A case T_CHAR :
0N/A case T_BYTE :
0N/A case T_SHORT :
0N/A case T_INT :
0N/A // 1 word result
304N/A __ movptr(rdx, STATE(_stack));
304N/A __ movptr(rax, STATE(_locals)); // address for result
0N/A __ movl(rdx, Address(rdx, wordSize)); // get result
304N/A __ movptr(Address(rax, 0), rdx); // and store it
0N/A break;
0N/A case T_LONG :
0N/A case T_DOUBLE :
0N/A // return top two words on current expression stack to caller's expression stack
0N/A // The caller's expression stack is adjacent to the current frame manager's intepretState
0N/A // except we allocated one extra word for this intepretState so we won't overwrite it
0N/A // when we return a two word result.
0N/A
304N/A __ movptr(rax, STATE(_locals)); // address for result
304N/A __ movptr(rcx, STATE(_stack));
304N/A __ subptr(rax, wordSize); // need addition word besides locals[0]
304N/A __ movptr(rdx, Address(rcx, 2*wordSize)); // get result word (junk in 64bit)
304N/A __ movptr(Address(rax, wordSize), rdx); // and store it
304N/A __ movptr(rdx, Address(rcx, wordSize)); // get result word
304N/A __ movptr(Address(rax, 0), rdx); // and store it
0N/A break;
0N/A case T_OBJECT :
304N/A __ movptr(rdx, STATE(_stack));
304N/A __ movptr(rax, STATE(_locals)); // address for result
304N/A __ movptr(rdx, Address(rdx, wordSize)); // get result
0N/A __ verify_oop(rdx); // verify it
304N/A __ movptr(Address(rax, 0), rdx); // and store it
0N/A break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A __ ret(0);
0N/A return entry;
0N/A}
0N/A
0N/Aaddress CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
0N/A // A result is in the java expression stack of the interpreted method that has just
0N/A // returned. Place this result in the native abi that the caller expects.
0N/A //
0N/A // Similar to generate_stack_to_stack_converter above. Called at a similar time from the
0N/A // frame manager execept in this situation the caller is native code (c1/c2/call_stub)
0N/A // and so rather than return result onto caller's java expression stack we return the
0N/A // result in the expected location based on the native abi.
304N/A // On entry: rsi/r13 - interpreter state of activation returning a (potential) result
304N/A // On Return: rsi/r13 - unchanged
0N/A // Other registers changed [rax/rdx/ST(0) as needed for the result returned]
0N/A
0N/A address entry = __ pc();
0N/A switch (type) {
0N/A case T_VOID:
0N/A break;
0N/A case T_BOOLEAN:
0N/A case T_CHAR :
0N/A case T_BYTE :
0N/A case T_SHORT :
0N/A case T_INT :
304N/A __ movptr(rdx, STATE(_stack)); // get top of stack
0N/A __ movl(rax, Address(rdx, wordSize)); // get result word 1
0N/A break;
0N/A case T_LONG :
304N/A __ movptr(rdx, STATE(_stack)); // get top of stack
304N/A __ movptr(rax, Address(rdx, wordSize)); // get result low word
304N/A NOT_LP64(__ movl(rdx, Address(rdx, 2*wordSize));) // get result high word
0N/A break;
0N/A case T_FLOAT :
304N/A __ movptr(rdx, STATE(_stack)); // get top of stack
0N/A if ( UseSSE >= 1) {
0N/A __ movflt(xmm0, Address(rdx, wordSize));
0N/A } else {
0N/A __ fld_s(Address(rdx, wordSize)); // pushd float result
0N/A }
0N/A break;
0N/A case T_DOUBLE :
304N/A __ movptr(rdx, STATE(_stack)); // get top of stack
0N/A if ( UseSSE > 1) {
0N/A __ movdbl(xmm0, Address(rdx, wordSize));
0N/A } else {
0N/A __ fld_d(Address(rdx, wordSize)); // push double result
0N/A }
0N/A break;
0N/A case T_OBJECT :
304N/A __ movptr(rdx, STATE(_stack)); // get top of stack
304N/A __ movptr(rax, Address(rdx, wordSize)); // get result word 1
0N/A __ verify_oop(rax); // verify it
0N/A break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A __ ret(0);
0N/A return entry;
0N/A}
0N/A
0N/Aaddress CppInterpreter::return_entry(TosState state, int length) {
0N/A // make it look good in the debugger
0N/A return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation);
0N/A}
0N/A
0N/Aaddress CppInterpreter::deopt_entry(TosState state, int length) {
0N/A address ret = NULL;
0N/A if (length != 0) {
0N/A switch (state) {
0N/A case atos: ret = deopt_frame_manager_return_atos; break;
0N/A case btos: ret = deopt_frame_manager_return_btos; break;
0N/A case ctos:
0N/A case stos:
0N/A case itos: ret = deopt_frame_manager_return_itos; break;
0N/A case ltos: ret = deopt_frame_manager_return_ltos; break;
0N/A case ftos: ret = deopt_frame_manager_return_ftos; break;
0N/A case dtos: ret = deopt_frame_manager_return_dtos; break;
0N/A case vtos: ret = deopt_frame_manager_return_vtos; break;
0N/A }
0N/A } else {
0N/A ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap)
0N/A }
0N/A assert(ret != NULL, "Not initialized");
0N/A return ret;
0N/A}
0N/A
0N/A// C++ Interpreter
0N/Avoid CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,
0N/A const Register locals,
0N/A const Register sender_sp,
0N/A bool native) {
0N/A
0N/A // On entry the "locals" argument points to locals[0] (or where it would be in case no locals in
0N/A // a static method). "state" contains any previous frame manager state which we must save a link
0N/A // to in the newly generated state object. On return "state" is a pointer to the newly allocated
0N/A // state object. We must allocate and initialize a new interpretState object and the method
0N/A // expression stack. Because the returned result (if any) of the method will be placed on the caller's
0N/A // expression stack and this will overlap with locals[0] (and locals[1] if double/long) we must
0N/A // be sure to leave space on the caller's stack so that this result will not overwrite values when
0N/A // locals[0] and locals[1] do not exist (and in fact are return address and saved rbp). So when
0N/A // we are non-native we in essence ensure that locals[0-1] exist. We play an extra trick in
0N/A // non-product builds and initialize this last local with the previous interpreterState as
0N/A // this makes things look real nice in the debugger.
0N/A
0N/A // State on entry
0N/A // Assumes locals == &locals[0]
0N/A // Assumes state == any previous frame manager state (assuming call path from c++ interpreter)
0N/A // Assumes rax = return address
0N/A // rcx == senders_sp
0N/A // rbx == method
0N/A // Modifies rcx, rdx, rax
0N/A // Returns:
0N/A // state == address of new interpreterState
0N/A // rsp == bottom of method's expression stack.
0N/A
0N/A const Address const_offset (rbx, methodOopDesc::const_offset());
0N/A
0N/A
0N/A // On entry sp is the sender's sp. This includes the space for the arguments
0N/A // that the sender pushed. If the sender pushed no args (a static) and the
0N/A // caller returns a long then we need two words on the sender's stack which
0N/A // are not present (although when we return a restore full size stack the
0N/A // space will be present). If we didn't allocate two words here then when
0N/A // we "push" the result of the caller's stack we would overwrite the return
0N/A // address and the saved rbp. Not good. So simply allocate 2 words now
0N/A // just to be safe. This is the "static long no_params() method" issue.
0N/A // See Lo.java for a testcase.
0N/A // We don't need this for native calls because they return result in
0N/A // register and the stack is expanded in the caller before we store
0N/A // the results on the stack.
0N/A
0N/A if (!native) {
0N/A#ifdef PRODUCT
304N/A __ subptr(rsp, 2*wordSize);
0N/A#else /* PRODUCT */
304N/A __ push((int32_t)NULL_WORD);
304N/A __ push(state); // make it look like a real argument
0N/A#endif /* PRODUCT */
0N/A }
0N/A
0N/A // Now that we are assure of space for stack result, setup typical linkage
0N/A
304N/A __ push(rax);
0N/A __ enter();
0N/A
304N/A __ mov(rax, state); // save current state
304N/A
304N/A __ lea(rsp, Address(rsp, -(int)sizeof(BytecodeInterpreter)));
304N/A __ mov(state, rsp);
304N/A
304N/A // rsi/r13 == state/locals rax == prevstate
0N/A
0N/A // initialize the "shadow" frame so that use since C++ interpreter not directly
0N/A // recursive. Simpler to recurse but we can't trim expression stack as we call
0N/A // new methods.
304N/A __ movptr(STATE(_locals), locals); // state->_locals = locals()
304N/A __ movptr(STATE(_self_link), state); // point to self
304N/A __ movptr(STATE(_prev_link), rax); // state->_link = state on entry (NULL or previous state)
304N/A __ movptr(STATE(_sender_sp), sender_sp); // state->_sender_sp = sender_sp
304N/A#ifdef _LP64
304N/A __ movptr(STATE(_thread), r15_thread); // state->_bcp = codes()
304N/A#else
0N/A __ get_thread(rax); // get vm's javathread*
304N/A __ movptr(STATE(_thread), rax); // state->_bcp = codes()
304N/A#endif // _LP64
304N/A __ movptr(rdx, Address(rbx, methodOopDesc::const_offset())); // get constantMethodOop
304N/A __ lea(rdx, Address(rdx, constMethodOopDesc::codes_offset())); // get code base
0N/A if (native) {
304N/A __ movptr(STATE(_bcp), (int32_t)NULL_WORD); // state->_bcp = NULL
0N/A } else {
304N/A __ movptr(STATE(_bcp), rdx); // state->_bcp = codes()
0N/A }
304N/A __ xorptr(rdx, rdx);
304N/A __ movptr(STATE(_oop_temp), rdx); // state->_oop_temp = NULL (only really needed for native)
304N/A __ movptr(STATE(_mdx), rdx); // state->_mdx = NULL
3790N/A __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rdx, Address(rdx, constMethodOopDesc::constants_offset()));
304N/A __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
304N/A __ movptr(STATE(_constants), rdx); // state->_constants = constants()
304N/A
304N/A __ movptr(STATE(_method), rbx); // state->_method = method()
304N/A __ movl(STATE(_msg), (int32_t) BytecodeInterpreter::method_entry); // state->_msg = initial method entry
304N/A __ movptr(STATE(_result._to_call._callee), (int32_t) NULL_WORD); // state->_result._to_call._callee_callee = NULL
304N/A
304N/A
304N/A __ movptr(STATE(_monitor_base), rsp); // set monitor block bottom (grows down) this would point to entry [0]
0N/A // entries run from -1..x where &monitor[x] ==
0N/A
0N/A {
0N/A // Must not attempt to lock method until we enter interpreter as gc won't be able to find the
0N/A // initial frame. However we allocate a free monitor so we don't have to shuffle the expression stack
0N/A // immediately.
0N/A
0N/A // synchronize method
0N/A const Address access_flags (rbx, methodOopDesc::access_flags_offset());
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
0N/A Label not_synced;
0N/A
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, not_synced);
0N/A
0N/A // Allocate initial monitor and pre initialize it
0N/A // get synchronization object
0N/A
0N/A Label done;
3042N/A const int mirror_offset = in_bytes(Klass::java_mirror_offset());
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_STATIC);
304N/A __ movptr(rax, Address(locals, 0)); // get receiver (assume this is frequent case)
0N/A __ jcc(Assembler::zero, done);
3790N/A __ movptr(rax, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rax, Address(rax, constMethodOopDesc::constants_offset()));
304N/A __ movptr(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
304N/A __ movptr(rax, Address(rax, mirror_offset));
0N/A __ bind(done);
0N/A // add space for monitor & lock
304N/A __ subptr(rsp, entry_size); // add space for a monitor entry
304N/A __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
0N/A __ bind(not_synced);
0N/A }
0N/A
304N/A __ movptr(STATE(_stack_base), rsp); // set expression stack base ( == &monitors[-count])
0N/A if (native) {
304N/A __ movptr(STATE(_stack), rsp); // set current expression stack tos
304N/A __ movptr(STATE(_stack_limit), rsp);
0N/A } else {
304N/A __ subptr(rsp, wordSize); // pre-push stack
304N/A __ movptr(STATE(_stack), rsp); // set current expression stack tos
0N/A
0N/A // compute full expression stack limit
0N/A
0N/A const Address size_of_stack (rbx, methodOopDesc::max_stack_offset());
710N/A const int extra_stack = 0; //6815692//methodOopDesc::extra_stack_words();
622N/A __ load_unsigned_short(rdx, size_of_stack); // get size of expression stack in words
304N/A __ negptr(rdx); // so we can subtract in next step
0N/A // Allocate expression stack
710N/A __ lea(rsp, Address(rsp, rdx, Address::times_ptr, -extra_stack));
304N/A __ movptr(STATE(_stack_limit), rsp);
0N/A }
0N/A
304N/A#ifdef _LP64
304N/A // Make sure stack is properly aligned and sized for the abi
304N/A __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
605N/A __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
304N/A#endif // _LP64
304N/A
304N/A
304N/A
0N/A}
0N/A
0N/A// Helpers for commoning out cases in the various type of method entries.
0N/A//
0N/A
0N/A// increment invocation count & check for overflow
0N/A//
0N/A// Note: checking for negative value instead of overflow
0N/A// so we have a 'sticky' overflow test
0N/A//
0N/A// rbx,: method
0N/A// rcx: invocation counter
0N/A//
0N/Avoid InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
0N/A
0N/A const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
0N/A const Address backedge_counter (rbx, methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset());
0N/A
0N/A if (ProfileInterpreter) { // %%% Merge this into methodDataOop
304N/A __ incrementl(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset()));
0N/A }
0N/A // Update standard invocation counters
0N/A __ movl(rax, backedge_counter); // load backedge counter
0N/A
0N/A __ increment(rcx, InvocationCounter::count_increment);
0N/A __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
0N/A
0N/A __ movl(invocation_counter, rcx); // save invocation count
0N/A __ addl(rcx, rax); // add both counters
0N/A
0N/A // profile_method is non-null only for interpreted method so
0N/A // profile_method != NULL == !native_call
0N/A // BytecodeInterpreter only calls for native so code is elided.
0N/A
0N/A __ cmp32(rcx,
0N/A ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
0N/A __ jcc(Assembler::aboveEqual, *overflow);
0N/A
0N/A}
0N/A
0N/Avoid InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
0N/A
0N/A // C++ interpreter on entry
304N/A // rsi/r13 - new interpreter state pointer
0N/A // rbp - interpreter frame pointer
0N/A // rbx - method
0N/A
0N/A // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
0N/A // rbx, - method
0N/A // rcx - rcvr (assuming there is one)
0N/A // top of stack return address of interpreter caller
0N/A // rsp - sender_sp
0N/A
0N/A // C++ interpreter only
304N/A // rsi/r13 - previous interpreter state pointer
0N/A
0N/A const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
0N/A
0N/A // InterpreterRuntime::frequency_counter_overflow takes one argument
0N/A // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
0N/A // The call returns the address of the verified entry point for the method or NULL
0N/A // if the compilation did not complete (either went background or bailed out).
304N/A __ movptr(rax, (int32_t)false);
0N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
0N/A
0N/A // for c++ interpreter can rsi really be munged?
520N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); // restore state
304N/A __ movptr(rbx, Address(state, byte_offset_of(BytecodeInterpreter, _method))); // restore method
304N/A __ movptr(rdi, Address(state, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer
304N/A
0N/A __ jmp(*do_continue, relocInfo::none);
0N/A
0N/A}
0N/A
0N/Avoid InterpreterGenerator::generate_stack_overflow_check(void) {
0N/A // see if we've got enough room on the stack for locals plus overhead.
0N/A // the expression stack grows down incrementally, so the normal guard
0N/A // page mechanism will work for that.
0N/A //
0N/A // Registers live on entry:
0N/A //
0N/A // Asm interpreter
0N/A // rdx: number of additional locals this frame needs (what we must check)
0N/A // rbx,: methodOop
0N/A
0N/A // C++ Interpreter
304N/A // rsi/r13: previous interpreter frame state object
0N/A // rdi: &locals[0]
0N/A // rcx: # of locals
0N/A // rdx: number of additional locals this frame needs (what we must check)
0N/A // rbx: methodOop
0N/A
0N/A // destroyed on exit
0N/A // rax,
0N/A
0N/A // NOTE: since the additional locals are also always pushed (wasn't obvious in
0N/A // generate_method_entry) so the guard should work for them too.
0N/A //
0N/A
0N/A // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
0N/A
0N/A // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
0N/A // be sure to change this if you add/subtract anything to/from the overhead area
0N/A const int overhead_size = (int)sizeof(BytecodeInterpreter);
0N/A
0N/A const int page_size = os::vm_page_size();
0N/A
0N/A Label after_frame_check;
0N/A
0N/A // compute rsp as if this were going to be the last frame on
0N/A // the stack before the red zone
0N/A
0N/A Label after_frame_check_pop;
0N/A
0N/A // save rsi == caller's bytecode ptr (c++ previous interp. state)
0N/A // QQQ problem here?? rsi overload????
304N/A __ push(state);
304N/A
304N/A const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rsi);
304N/A
304N/A NOT_LP64(__ get_thread(thread));
0N/A
0N/A const Address stack_base(thread, Thread::stack_base_offset());
0N/A const Address stack_size(thread, Thread::stack_size_offset());
0N/A
0N/A // locals + overhead, in bytes
0N/A const Address size_of_stack (rbx, methodOopDesc::max_stack_offset());
0N/A // Always give one monitor to allow us to start interp if sync method.
0N/A // Any additional monitors need a check when moving the expression stack
520N/A const int one_monitor = frame::interpreter_frame_monitor_size() * wordSize;
710N/A const int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries();
622N/A __ load_unsigned_short(rax, size_of_stack); // get size of expression stack in words
710N/A __ lea(rax, Address(noreg, rax, Interpreter::stackElementScale(), extra_stack + one_monitor));
304N/A __ lea(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));
0N/A
0N/A#ifdef ASSERT
0N/A Label stack_base_okay, stack_size_okay;
0N/A // verify that thread stack base is non-zero
304N/A __ cmpptr(stack_base, (int32_t)0);
0N/A __ jcc(Assembler::notEqual, stack_base_okay);
0N/A __ stop("stack base is zero");
0N/A __ bind(stack_base_okay);
0N/A // verify that thread stack size is non-zero
304N/A __ cmpptr(stack_size, (int32_t)0);
0N/A __ jcc(Assembler::notEqual, stack_size_okay);
0N/A __ stop("stack size is zero");
0N/A __ bind(stack_size_okay);
0N/A#endif
0N/A
0N/A // Add stack base to locals and subtract stack size
304N/A __ addptr(rax, stack_base);
304N/A __ subptr(rax, stack_size);
0N/A
0N/A // We should have a magic number here for the size of the c++ interpreter frame.
0N/A // We can't actually tell this ahead of time. The debug version size is around 3k
0N/A // product is 1k and fastdebug is 4k
0N/A const int slop = 6 * K;
0N/A
0N/A // Use the maximum number of pages we might bang.
0N/A const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
0N/A (StackRedPages+StackYellowPages);
0N/A // Only need this if we are stack banging which is temporary while
0N/A // we're debugging.
304N/A __ addptr(rax, slop + 2*max_pages * page_size);
0N/A
0N/A // check against the current stack bottom
304N/A __ cmpptr(rsp, rax);
0N/A __ jcc(Assembler::above, after_frame_check_pop);
0N/A
304N/A __ pop(state); // get c++ prev state.
0N/A
0N/A // throw exception return address becomes throwing pc
0N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
0N/A
0N/A // all done with frame size check
0N/A __ bind(after_frame_check_pop);
304N/A __ pop(state);
0N/A
0N/A __ bind(after_frame_check);
0N/A}
0N/A
0N/A// Find preallocated monitor and lock method (C++ interpreter)
0N/A// rbx - methodOop
0N/A//
0N/Avoid InterpreterGenerator::lock_method(void) {
304N/A // assumes state == rsi/r13 == pointer to current interpreterState
304N/A // minimally destroys rax, rdx|c_rarg1, rdi
0N/A //
0N/A // synchronize method
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
0N/A const Address access_flags (rbx, methodOopDesc::access_flags_offset());
0N/A
304N/A const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
304N/A
0N/A // find initial monitor i.e. monitors[-1]
304N/A __ movptr(monitor, STATE(_monitor_base)); // get monitor bottom limit
304N/A __ subptr(monitor, entry_size); // point to initial monitor
0N/A
0N/A#ifdef ASSERT
0N/A { Label L;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ stop("method doesn't need synchronization");
0N/A __ bind(L);
0N/A }
0N/A#endif // ASSERT
0N/A // get synchronization object
0N/A { Label done;
3042N/A const int mirror_offset = in_bytes(Klass::java_mirror_offset());
0N/A __ movl(rax, access_flags);
304N/A __ movptr(rdi, STATE(_locals)); // prepare to get receiver (assume common case)
0N/A __ testl(rax, JVM_ACC_STATIC);
304N/A __ movptr(rax, Address(rdi, 0)); // get receiver (assume this is frequent case)
0N/A __ jcc(Assembler::zero, done);
3790N/A __ movptr(rax, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rax, Address(rax, constMethodOopDesc::constants_offset()));
304N/A __ movptr(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
304N/A __ movptr(rax, Address(rax, mirror_offset));
0N/A __ bind(done);
0N/A }
0N/A#ifdef ASSERT
0N/A { Label L;
304N/A __ cmpptr(rax, Address(monitor, BasicObjectLock::obj_offset_in_bytes())); // correct object?
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("wrong synchronization lobject");
0N/A __ bind(L);
0N/A }
0N/A#endif // ASSERT
304N/A // can destroy rax, rdx|c_rarg1, rcx, and (via call_VM) rdi!
304N/A __ lock_object(monitor);
0N/A}
0N/A
0N/A// Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
0N/A
0N/Aaddress InterpreterGenerator::generate_accessor_entry(void) {
0N/A
304N/A // rbx: methodOop
304N/A
304N/A // rsi/r13: senderSP must preserved for slow path, set SP to it on fast path
0N/A
0N/A Label xreturn_path;
0N/A
0N/A // do fastpath for resolved accessor methods
0N/A if (UseFastAccessorMethods) {
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A Label slow_path;
0N/A // If we need a safepoint check, generate full interpreter entry.
0N/A ExternalAddress state(SafepointSynchronize::address_of_state());
0N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
0N/A SafepointSynchronize::_not_synchronized);
0N/A
0N/A __ jcc(Assembler::notEqual, slow_path);
0N/A // ASM/C++ Interpreter
0N/A // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
0N/A // Note: We can only use this code if the getfield has been resolved
0N/A // and if we don't have a null-pointer exception => check for
0N/A // these conditions first and use slow path if necessary.
0N/A // rbx,: method
0N/A // rcx: receiver
304N/A __ movptr(rax, Address(rsp, wordSize));
0N/A
0N/A // check if local 0 != NULL and read field
304N/A __ testptr(rax, rax);
0N/A __ jcc(Assembler::zero, slow_path);
0N/A
0N/A // read first instruction word and extract bytecode @ 1 and index @ 2
304N/A __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rdi, Address(rdx, constMethodOopDesc::constants_offset()));
0N/A __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
0N/A // Shift codes right to get the index on the right.
0N/A // The bytecode fetched looks like <index><0xb4><0x2a>
0N/A __ shrl(rdx, 2*BitsPerByte);
0N/A __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
304N/A __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
0N/A
0N/A // rax,: local 0
0N/A // rbx,: method
0N/A // rcx: receiver - do not destroy since it is needed for slow path!
0N/A // rcx: scratch
0N/A // rdx: constant pool cache index
0N/A // rdi: constant pool cache
304N/A // rsi/r13: sender sp
0N/A
0N/A // check if getfield has been resolved and read constant pool cache entry
0N/A // check the validity of the cache entry by testing whether _indices field
0N/A // contains Bytecode::_getfield in b1 byte.
0N/A assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
0N/A __ movl(rcx,
0N/A Address(rdi,
0N/A rdx,
304N/A Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
0N/A __ shrl(rcx, 2*BitsPerByte);
0N/A __ andl(rcx, 0xFF);
0N/A __ cmpl(rcx, Bytecodes::_getfield);
0N/A __ jcc(Assembler::notEqual, slow_path);
0N/A
0N/A // Note: constant pool entry is not valid before bytecode is resolved
304N/A __ movptr(rcx,
0N/A Address(rdi,
0N/A rdx,
304N/A Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset()));
0N/A __ movl(rdx,
0N/A Address(rdi,
0N/A rdx,
304N/A Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset()));
0N/A
0N/A Label notByte, notShort, notChar;
0N/A const Address field_address (rax, rcx, Address::times_1);
0N/A
0N/A // Need to differentiate between igetfield, agetfield, bgetfield etc.
0N/A // because they are different sizes.
0N/A // Use the type from the constant pool cache
3932N/A __ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift);
3932N/A // Make sure we don't need to mask rdx after the above shift
3932N/A ConstantPoolCacheEntry::verify_tos_state_shift();
304N/A#ifdef _LP64
304N/A Label notObj;
304N/A __ cmpl(rdx, atos);
304N/A __ jcc(Assembler::notEqual, notObj);
304N/A // atos
304N/A __ movptr(rax, field_address);
304N/A __ jmp(xreturn_path);
304N/A
304N/A __ bind(notObj);
304N/A#endif // _LP64
0N/A __ cmpl(rdx, btos);
0N/A __ jcc(Assembler::notEqual, notByte);
0N/A __ load_signed_byte(rax, field_address);
0N/A __ jmp(xreturn_path);
0N/A
0N/A __ bind(notByte);
0N/A __ cmpl(rdx, stos);
0N/A __ jcc(Assembler::notEqual, notShort);
622N/A __ load_signed_short(rax, field_address);
0N/A __ jmp(xreturn_path);
0N/A
0N/A __ bind(notShort);
0N/A __ cmpl(rdx, ctos);
0N/A __ jcc(Assembler::notEqual, notChar);
622N/A __ load_unsigned_short(rax, field_address);
0N/A __ jmp(xreturn_path);
0N/A
0N/A __ bind(notChar);
0N/A#ifdef ASSERT
0N/A Label okay;
304N/A#ifndef _LP64
0N/A __ cmpl(rdx, atos);
0N/A __ jcc(Assembler::equal, okay);
304N/A#endif // _LP64
0N/A __ cmpl(rdx, itos);
0N/A __ jcc(Assembler::equal, okay);
0N/A __ stop("what type is this?");
0N/A __ bind(okay);
0N/A#endif // ASSERT
0N/A // All the rest are a 32 bit wordsize
0N/A __ movl(rax, field_address);
0N/A
0N/A __ bind(xreturn_path);
0N/A
0N/A // _ireturn/_areturn
304N/A __ pop(rdi); // get return address
304N/A __ mov(rsp, sender_sp_on_entry); // set sp to sender sp
0N/A __ jmp(rdi);
0N/A
0N/A // generate a vanilla interpreter entry as the slow path
0N/A __ bind(slow_path);
0N/A // We will enter c++ interpreter looking like it was
0N/A // called by the call_stub this will cause it to return
0N/A // a tosca result to the invoker which might have been
0N/A // the c++ interpreter itself.
0N/A
0N/A __ jmp(fast_accessor_slow_entry_path);
0N/A return entry_point;
0N/A
0N/A } else {
0N/A return NULL;
0N/A }
0N/A
0N/A}
0N/A
2346N/Aaddress InterpreterGenerator::generate_Reference_get_entry(void) {
2346N/A#ifndef SERIALGC
2346N/A if (UseG1GC) {
2346N/A // We need to generate have a routine that generates code to:
2346N/A // * load the value in the referent field
2346N/A // * passes that value to the pre-barrier.
2346N/A //
2346N/A // In the case of G1 this will record the value of the
2346N/A // referent in an SATB buffer if marking is active.
2346N/A // This will cause concurrent marking to mark the referent
2346N/A // field as live.
2346N/A Unimplemented();
2346N/A }
2346N/A#endif // SERIALGC
2346N/A
2346N/A // If G1 is not enabled then attempt to go through the accessor entry point
2346N/A // Reference.get is an accessor
2346N/A return generate_accessor_entry();
2346N/A}
2346N/A
0N/A//
0N/A// C++ Interpreter stub for calling a native method.
0N/A// This sets up a somewhat different looking stack for calling the native method
0N/A// than the typical interpreter frame setup but still has the pointer to
0N/A// an interpreter state.
0N/A//
0N/A
0N/Aaddress InterpreterGenerator::generate_native_entry(bool synchronized) {
0N/A // determine code generation flags
0N/A bool inc_counter = UseCompiler || CountCompiledCalls;
0N/A
0N/A // rbx: methodOop
0N/A // rcx: receiver (unused)
304N/A // rsi/r13: previous interpreter state (if called from C++ interpreter) must preserve
304N/A // in any case. If called via c1/c2/call_stub rsi/r13 is junk (to use) but harmless
0N/A // to save/restore.
0N/A address entry_point = __ pc();
0N/A
0N/A const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
0N/A const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset());
0N/A const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
0N/A const Address access_flags (rbx, methodOopDesc::access_flags_offset());
0N/A
304N/A // rsi/r13 == state/locals rdi == prevstate
0N/A const Register locals = rdi;
0N/A
0N/A // get parameter size (always needed)
622N/A __ load_unsigned_short(rcx, size_of_parameters);
0N/A
0N/A // rbx: methodOop
0N/A // rcx: size of parameters
304N/A __ pop(rax); // get return address
0N/A // for natives the size of locals is zero
0N/A
0N/A // compute beginning of parameters /locals
304N/A __ lea(locals, Address(rsp, rcx, Address::times_ptr, -wordSize));
0N/A
0N/A // initialize fixed part of activation frame
0N/A
0N/A // Assumes rax = return address
0N/A
0N/A // allocate and initialize new interpreterState and method expression stack
0N/A // IN(locals) -> locals
0N/A // IN(state) -> previous frame manager state (NULL from stub/c1/c2)
0N/A // destroys rax, rcx, rdx
0N/A // OUT (state) -> new interpreterState
0N/A // OUT(rsp) -> bottom of methods expression stack
0N/A
0N/A // save sender_sp
304N/A __ mov(rcx, sender_sp_on_entry);
0N/A // start with NULL previous state
304N/A __ movptr(state, (int32_t)NULL_WORD);
0N/A generate_compute_interpreter_state(state, locals, rcx, true);
0N/A
0N/A#ifdef ASSERT
0N/A { Label L;
304N/A __ movptr(rax, STATE(_stack_base));
304N/A#ifdef _LP64
304N/A // duplicate the alignment rsp got after setting stack_base
304N/A __ subptr(rax, frame::arg_reg_save_area_bytes); // windows
605N/A __ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)
304N/A#endif // _LP64
304N/A __ cmpptr(rax, rsp);
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("broken stack frame setup in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
0N/A
304N/A const Register unlock_thread = LP64_ONLY(r15_thread) NOT_LP64(rax);
304N/A NOT_LP64(__ movptr(unlock_thread, STATE(_thread));) // get thread
0N/A // Since at this point in the method invocation the exception handler
0N/A // would try to exit the monitor of synchronized methods which hasn't
0N/A // been entered yet, we set the thread local variable
0N/A // _do_not_unlock_if_synchronized to true. The remove_activation will
0N/A // check this flag.
0N/A
304N/A const Address do_not_unlock_if_synchronized(unlock_thread,
0N/A in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
0N/A __ movbool(do_not_unlock_if_synchronized, true);
0N/A
0N/A // make sure method is native & not abstract
0N/A#ifdef ASSERT
0N/A __ movl(rax, access_flags);
0N/A {
0N/A Label L;
0N/A __ testl(rax, JVM_ACC_NATIVE);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ stop("tried to execute non-native method as native");
0N/A __ bind(L);
0N/A }
0N/A { Label L;
0N/A __ testl(rax, JVM_ACC_ABSTRACT);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("tried to execute abstract method in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A
0N/A // increment invocation count & check for overflow
0N/A Label invocation_counter_overflow;
0N/A if (inc_counter) {
0N/A generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
0N/A }
0N/A
0N/A Label continue_after_compile;
0N/A
0N/A __ bind(continue_after_compile);
0N/A
0N/A bang_stack_shadow_pages(true);
0N/A
0N/A // reset the _do_not_unlock_if_synchronized flag
304N/A NOT_LP64(__ movl(rax, STATE(_thread));) // get thread
0N/A __ movbool(do_not_unlock_if_synchronized, false);
0N/A
0N/A
0N/A // check for synchronized native methods
0N/A //
0N/A // Note: This must happen *after* invocation counter check, since
0N/A // when overflow happens, the method should not be locked.
0N/A if (synchronized) {
0N/A // potentially kills rax, rcx, rdx, rdi
0N/A lock_method();
0N/A } else {
0N/A // no synchronization necessary
0N/A#ifdef ASSERT
0N/A { Label L;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("method needs synchronization");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A }
0N/A
0N/A // start execution
0N/A
0N/A // jvmti support
0N/A __ notify_method_entry();
0N/A
0N/A // work registers
0N/A const Register method = rbx;
304N/A const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rdi);
304N/A const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); // rcx|rscratch1
0N/A
0N/A // allocate space for parameters
304N/A __ movptr(method, STATE(_method));
0N/A __ verify_oop(method);
622N/A __ load_unsigned_short(t, Address(method, methodOopDesc::size_of_parameters_offset()));
0N/A __ shll(t, 2);
304N/A#ifdef _LP64
304N/A __ subptr(rsp, t);
304N/A __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
605N/A __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
304N/A#else
304N/A __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror
304N/A __ subptr(rsp, t);
304N/A __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
304N/A#endif // _LP64
0N/A
0N/A // get signature handler
0N/A Label pending_exception_present;
0N/A
0N/A { Label L;
304N/A __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
304N/A __ testptr(t, t);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false);
304N/A __ movptr(method, STATE(_method));
304N/A __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
0N/A __ jcc(Assembler::notEqual, pending_exception_present);
0N/A __ verify_oop(method);
304N/A __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
0N/A __ bind(L);
0N/A }
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
304N/A __ push(t);
0N/A __ get_thread(t); // get vm's javathread*
304N/A __ cmpptr(t, STATE(_thread));
0N/A __ jcc(Assembler::equal, L);
0N/A __ int3();
0N/A __ bind(L);
304N/A __ pop(t);
0N/A }
0N/A#endif //
0N/A
304N/A const Register from_ptr = InterpreterRuntime::SignatureHandlerGenerator::from();
0N/A // call signature handler
0N/A assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");
304N/A
0N/A // The generated handlers do not touch RBX (the method oop).
0N/A // However, large signatures cannot be cached and are generated
0N/A // each time here. The slow-path generator will blow RBX
0N/A // sometime, so we must reload it after the call.
304N/A __ movptr(from_ptr, STATE(_locals)); // get the from pointer
0N/A __ call(t);
304N/A __ movptr(method, STATE(_method));
0N/A __ verify_oop(method);
0N/A
0N/A // result handler is in rax
0N/A // set result handler
304N/A __ movptr(STATE(_result_handler), rax);
304N/A
304N/A
304N/A // get native function entry point
304N/A { Label L;
304N/A __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
304N/A __ testptr(rax, rax);
304N/A __ jcc(Assembler::notZero, L);
304N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
304N/A __ movptr(method, STATE(_method));
304N/A __ verify_oop(method);
304N/A __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
304N/A __ bind(L);
304N/A }
0N/A
0N/A // pass mirror handle if static call
0N/A { Label L;
3042N/A const int mirror_offset = in_bytes(Klass::java_mirror_offset());
0N/A __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
0N/A __ testl(t, JVM_ACC_STATIC);
0N/A __ jcc(Assembler::zero, L);
0N/A // get mirror
3790N/A __ movptr(t, Address(method, methodOopDesc:: const_offset()));
3790N/A __ movptr(t, Address(t, constMethodOopDesc::constants_offset()));
304N/A __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
304N/A __ movptr(t, Address(t, mirror_offset));
0N/A // copy mirror into activation object
304N/A __ movptr(STATE(_oop_temp), t);
0N/A // pass handle to mirror
304N/A#ifdef _LP64
304N/A __ lea(c_rarg1, STATE(_oop_temp));
304N/A#else
304N/A __ lea(t, STATE(_oop_temp));
304N/A __ movptr(Address(rsp, wordSize), t);
304N/A#endif // _LP64
0N/A __ bind(L);
0N/A }
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
304N/A __ push(t);
0N/A __ get_thread(t); // get vm's javathread*
304N/A __ cmpptr(t, STATE(_thread));
0N/A __ jcc(Assembler::equal, L);
0N/A __ int3();
0N/A __ bind(L);
304N/A __ pop(t);
0N/A }
0N/A#endif //
0N/A
0N/A // pass JNIEnv
304N/A#ifdef _LP64
304N/A __ lea(c_rarg0, Address(thread, JavaThread::jni_environment_offset()));
304N/A#else
304N/A __ movptr(thread, STATE(_thread)); // get thread
304N/A __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
304N/A
304N/A __ movptr(Address(rsp, 0), t);
304N/A#endif // _LP64
304N/A
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
304N/A __ push(t);
0N/A __ get_thread(t); // get vm's javathread*
304N/A __ cmpptr(t, STATE(_thread));
0N/A __ jcc(Assembler::equal, L);
0N/A __ int3();
0N/A __ bind(L);
304N/A __ pop(t);
0N/A }
0N/A#endif //
0N/A
0N/A#ifdef ASSERT
0N/A { Label L;
0N/A __ movl(t, Address(thread, JavaThread::thread_state_offset()));
0N/A __ cmpl(t, _thread_in_Java);
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("Wrong thread state in native stub");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // Change state to native (we save the return address in the thread, since it might not
0N/A // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
0N/A // points into the right code segment. It does not have to be the correct return pc.
0N/A
0N/A __ set_last_Java_frame(thread, noreg, rbp, __ pc());
0N/A
0N/A __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
0N/A
0N/A __ call(rax);
0N/A
0N/A // result potentially in rdx:rax or ST0
304N/A __ movptr(method, STATE(_method));
304N/A NOT_LP64(__ movptr(thread, STATE(_thread));) // get thread
0N/A
0N/A // The potential result is in ST(0) & rdx:rax
0N/A // With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then
0N/A // we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about
0N/A // anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would
0N/A // be destroyed.
0N/A // It is safe to do these pushes because state is _thread_in_native and return address will be found
0N/A // via _last_native_pc and not via _last_jave_sp
0N/A
304N/A // Must save the value of ST(0)/xmm0 since it could be destroyed before we get to result handler
0N/A { Label Lpush, Lskip;
0N/A ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
0N/A ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
0N/A __ cmpptr(STATE(_result_handler), float_handler.addr());
0N/A __ jcc(Assembler::equal, Lpush);
0N/A __ cmpptr(STATE(_result_handler), double_handler.addr());
0N/A __ jcc(Assembler::notEqual, Lskip);
0N/A __ bind(Lpush);
304N/A __ subptr(rsp, 2*wordSize);
304N/A if ( UseSSE < 2 ) {
304N/A __ fstp_d(Address(rsp, 0));
304N/A } else {
304N/A __ movdbl(Address(rsp, 0), xmm0);
304N/A }
0N/A __ bind(Lskip);
0N/A }
0N/A
304N/A // save rax:rdx for potential use by result handler.
304N/A __ push(rax);
304N/A#ifndef _LP64
304N/A __ push(rdx);
304N/A#endif // _LP64
0N/A
4442N/A // Verify or restore cpu control state after JNI call
4442N/A __ restore_cpu_control_state_after_jni();
0N/A
0N/A // change thread state
0N/A __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
0N/A if(os::is_MP()) {
0N/A // Write serialization page so VM thread can do a pseudo remote membar.
0N/A // We use the current thread pointer to calculate a thread specific
0N/A // offset to write to within the page. This minimizes bus traffic
0N/A // due to cache line collision.
0N/A __ serialize_memory(thread, rcx);
0N/A }
0N/A
0N/A // check for safepoint operation in progress and/or pending suspend requests
0N/A { Label Continue;
0N/A
0N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
0N/A SafepointSynchronize::_not_synchronized);
0N/A
0N/A // threads running native code and they are expected to self-suspend
0N/A // when leaving the _thread_in_native state. We need to check for
0N/A // pending suspend requests here.
0N/A Label L;
0N/A __ jcc(Assembler::notEqual, L);
0N/A __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
0N/A __ jcc(Assembler::equal, Continue);
0N/A __ bind(L);
0N/A
0N/A // Don't use call_VM as it will see a possible pending exception and forward it
0N/A // and never return here preventing us from clearing _last_native_pc down below.
0N/A // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
304N/A // preserved and correspond to the bcp/locals pointers.
0N/A //
304N/A
304N/A ((MacroAssembler*)_masm)->call_VM_leaf(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
304N/A thread);
0N/A __ increment(rsp, wordSize);
0N/A
304N/A __ movptr(method, STATE(_method));
0N/A __ verify_oop(method);
304N/A __ movptr(thread, STATE(_thread)); // get thread
0N/A
0N/A __ bind(Continue);
0N/A }
0N/A
0N/A // change thread state
0N/A __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
0N/A
0N/A __ reset_last_Java_frame(thread, true, true);
0N/A
0N/A // reset handle block
304N/A __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
304N/A __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
0N/A
0N/A // If result was an oop then unbox and save it in the frame
0N/A { Label L;
0N/A Label no_oop, store_result;
0N/A ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT));
0N/A __ cmpptr(STATE(_result_handler), oop_handler.addr());
0N/A __ jcc(Assembler::notEqual, no_oop);
304N/A#ifndef _LP64
304N/A __ pop(rdx);
304N/A#endif // _LP64
304N/A __ pop(rax);
304N/A __ testptr(rax, rax);
0N/A __ jcc(Assembler::zero, store_result);
0N/A // unbox
304N/A __ movptr(rax, Address(rax, 0));
0N/A __ bind(store_result);
304N/A __ movptr(STATE(_oop_temp), rax);
0N/A // keep stack depth as expected by pushing oop which will eventually be discarded
304N/A __ push(rax);
304N/A#ifndef _LP64
304N/A __ push(rdx);
304N/A#endif // _LP64
0N/A __ bind(no_oop);
0N/A }
0N/A
0N/A {
0N/A Label no_reguard;
0N/A __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
0N/A __ jcc(Assembler::notEqual, no_reguard);
0N/A
304N/A __ pusha();
0N/A __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
304N/A __ popa();
0N/A
0N/A __ bind(no_reguard);
0N/A }
0N/A
0N/A
0N/A // QQQ Seems like for native methods we simply return and the caller will see the pending
0N/A // exception and do the right thing. Certainly the interpreter will, don't know about
0N/A // compiled methods.
0N/A // Seems that the answer to above is no this is wrong. The old code would see the exception
0N/A // and forward it before doing the unlocking and notifying jvmdi that method has exited.
0N/A // This seems wrong need to investigate the spec.
0N/A
0N/A // handle exceptions (exception handling will handle unlocking!)
0N/A { Label L;
304N/A __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
0N/A __ jcc(Assembler::zero, L);
0N/A __ bind(pending_exception_present);
0N/A
0N/A // There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply
0N/A // return and let caller deal with exception. This skips the unlocking here which
0N/A // seems wrong but seems to be what asm interpreter did. Can't find this in the spec.
0N/A // Note: must preverve method in rbx
0N/A //
0N/A
0N/A // remove activation
0N/A
304N/A __ movptr(t, STATE(_sender_sp));
0N/A __ leave(); // remove frame anchor
304N/A __ pop(rdi); // get return address
304N/A __ movptr(state, STATE(_prev_link)); // get previous state for return
304N/A __ mov(rsp, t); // set sp to sender sp
304N/A __ push(rdi); // push throwing pc
0N/A // The skips unlocking!! This seems to be what asm interpreter does but seems
0N/A // very wrong. Not clear if this violates the spec.
0N/A __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
0N/A __ bind(L);
0N/A }
0N/A
0N/A // do unlocking if necessary
0N/A { Label L;
0N/A __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
0N/A __ testl(t, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, L);
0N/A // the code below should be shared with interpreter macro assembler implementation
0N/A { Label unlock;
304N/A const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
0N/A // BasicObjectLock will be first in list, since this is a synchronized method. However, need
0N/A // to check that the object has not been unlocked by an explicit monitorexit bytecode.
304N/A __ movptr(monitor, STATE(_monitor_base));
304N/A __ subptr(monitor, frame::interpreter_frame_monitor_size() * wordSize); // address of initial monitor
304N/A
304N/A __ movptr(t, Address(monitor, BasicObjectLock::obj_offset_in_bytes()));
304N/A __ testptr(t, t);
0N/A __ jcc(Assembler::notZero, unlock);
0N/A
0N/A // Entry already unlocked, need to throw exception
0N/A __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
0N/A __ should_not_reach_here();
0N/A
0N/A __ bind(unlock);
304N/A __ unlock_object(monitor);
0N/A // unlock can blow rbx so restore it for path that needs it below
304N/A __ movptr(method, STATE(_method));
0N/A }
0N/A __ bind(L);
0N/A }
0N/A
0N/A // jvmti support
0N/A // Note: This must happen _after_ handling/throwing any exceptions since
0N/A // the exception handler code notifies the runtime of method exits
0N/A // too. If this happens before, method entry/exit notifications are
0N/A // not properly paired (was bug - gri 11/22/99).
0N/A __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
0N/A
0N/A // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
304N/A#ifndef _LP64
304N/A __ pop(rdx);
304N/A#endif // _LP64
304N/A __ pop(rax);
304N/A __ movptr(t, STATE(_result_handler)); // get result handler
0N/A __ call(t); // call result handler to convert to tosca form
0N/A
0N/A // remove activation
0N/A
304N/A __ movptr(t, STATE(_sender_sp));
0N/A
0N/A __ leave(); // remove frame anchor
304N/A __ pop(rdi); // get return address
304N/A __ movptr(state, STATE(_prev_link)); // get previous state for return (if c++ interpreter was caller)
304N/A __ mov(rsp, t); // set sp to sender sp
0N/A __ jmp(rdi);
0N/A
0N/A // invocation counter overflow
0N/A if (inc_counter) {
0N/A // Handle overflow of counter and compile method
0N/A __ bind(invocation_counter_overflow);
0N/A generate_counter_overflow(&continue_after_compile);
0N/A }
0N/A
0N/A return entry_point;
0N/A}
0N/A
0N/A// Generate entries that will put a result type index into rcx
0N/Avoid CppInterpreterGenerator::generate_deopt_handling() {
0N/A
0N/A Label return_from_deopt_common;
0N/A
0N/A // Generate entries that will put a result type index into rcx
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A deopt_frame_manager_return_atos = __ pc();
0N/A
0N/A // rax is live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A deopt_frame_manager_return_btos = __ pc();
0N/A
0N/A // rax is live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A deopt_frame_manager_return_itos = __ pc();
0N/A
0N/A // rax is live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A
0N/A deopt_frame_manager_return_ltos = __ pc();
0N/A // rax,rdx are live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A
0N/A deopt_frame_manager_return_ftos = __ pc();
0N/A // st(0) is live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A deopt_frame_manager_return_dtos = __ pc();
0N/A
0N/A // st(0) is live here
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
0N/A __ jmp(return_from_deopt_common);
0N/A
0N/A // deopt needs to jump to here to enter the interpreter (return a result)
0N/A deopt_frame_manager_return_vtos = __ pc();
0N/A
0N/A __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID));
0N/A
0N/A // Deopt return common
0N/A // an index is present in rcx that lets us move any possible result being
0N/A // return to the interpreter's stack
0N/A //
0N/A // Because we have a full sized interpreter frame on the youngest
0N/A // activation the stack is pushed too deep to share the tosca to
0N/A // stack converters directly. We shrink the stack to the desired
0N/A // amount and then push result and then re-extend the stack.
0N/A // We could have the code in size_activation layout a short
0N/A // frame for the top activation but that would look different
0N/A // than say sparc (which needs a full size activation because
0N/A // the windows are in the way. Really it could be short? QQQ
0N/A //
0N/A __ bind(return_from_deopt_common);
0N/A
304N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
0N/A
0N/A // setup rsp so we can push the "result" as needed.
304N/A __ movptr(rsp, STATE(_stack)); // trim stack (is prepushed)
304N/A __ addptr(rsp, wordSize); // undo prepush
0N/A
0N/A ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
304N/A // Address index(noreg, rcx, Address::times_ptr);
304N/A __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
304N/A // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
0N/A __ call(rcx); // call result converter
0N/A
0N/A __ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume);
304N/A __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
304N/A __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
0N/A // result if any on stack already )
304N/A __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
0N/A}
0N/A
0N/A// Generate the code to handle a more_monitors message from the c++ interpreter
0N/Avoid CppInterpreterGenerator::generate_more_monitors() {
0N/A
0N/A
0N/A Label entry, loop;
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
304N/A // 1. compute new pointers // rsp: old expression stack top
304N/A __ movptr(rdx, STATE(_stack_base)); // rdx: old expression stack bottom
304N/A __ subptr(rsp, entry_size); // move expression stack top limit
304N/A __ subptr(STATE(_stack), entry_size); // update interpreter stack top
304N/A __ subptr(STATE(_stack_limit), entry_size); // inform interpreter
304N/A __ subptr(rdx, entry_size); // move expression stack bottom
304N/A __ movptr(STATE(_stack_base), rdx); // inform interpreter
304N/A __ movptr(rcx, STATE(_stack)); // set start value for copy loop
0N/A __ jmp(entry);
0N/A // 2. move expression stack contents
0N/A __ bind(loop);
304N/A __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location
304N/A __ movptr(Address(rcx, 0), rbx); // and store it at new location
304N/A __ addptr(rcx, wordSize); // advance to next word
0N/A __ bind(entry);
304N/A __ cmpptr(rcx, rdx); // check if bottom reached
304N/A __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word
0N/A // now zero the slot so we can find it.
304N/A __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL_WORD);
0N/A __ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors);
0N/A}
0N/A
0N/A
0N/A// Initial entry to C++ interpreter from the call_stub.
0N/A// This entry point is called the frame manager since it handles the generation
0N/A// of interpreter activation frames via requests directly from the vm (via call_stub)
0N/A// and via requests from the interpreter. The requests from the call_stub happen
0N/A// directly thru the entry point. Requests from the interpreter happen via returning
0N/A// from the interpreter and examining the message the interpreter has returned to
0N/A// the frame manager. The frame manager can take the following requests:
0N/A
0N/A// NO_REQUEST - error, should never happen.
0N/A// MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
0N/A// allocate a new monitor.
0N/A// CALL_METHOD - setup a new activation to call a new method. Very similar to what
0N/A// happens during entry during the entry via the call stub.
0N/A// RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
0N/A//
0N/A// Arguments:
0N/A//
0N/A// rbx: methodOop
0N/A// rcx: receiver - unused (retrieved from stack as needed)
304N/A// rsi/r13: previous frame manager state (NULL from the call_stub/c1/c2)
0N/A//
0N/A//
0N/A// Stack layout at entry
0N/A//
0N/A// [ return address ] <--- rsp
0N/A// [ parameter n ]
0N/A// ...
0N/A// [ parameter 1 ]
0N/A// [ expression stack ]
0N/A//
0N/A//
0N/A// We are free to blow any registers we like because the call_stub which brought us here
0N/A// initially has preserved the callee save registers already.
0N/A//
0N/A//
0N/A
0N/Astatic address interpreter_frame_manager = NULL;
0N/A
0N/Aaddress InterpreterGenerator::generate_normal_entry(bool synchronized) {
0N/A
0N/A // rbx: methodOop
304N/A // rsi/r13: sender sp
0N/A
0N/A // Because we redispatch "recursive" interpreter entries thru this same entry point
0N/A // the "input" register usage is a little strange and not what you expect coming
0N/A // from the call_stub. From the call stub rsi/rdi (current/previous) interpreter
0N/A // state are NULL but on "recursive" dispatches they are what you'd expect.
0N/A // rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2)
0N/A
0N/A
0N/A // A single frame manager is plenty as we don't specialize for synchronized. We could and
0N/A // the code is pretty much ready. Would need to change the test below and for good measure
0N/A // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
0N/A // routines. Not clear this is worth it yet.
0N/A
0N/A if (interpreter_frame_manager) return interpreter_frame_manager;
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A // Fast accessor methods share this entry point.
0N/A // This works because frame manager is in the same codelet
0N/A if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path);
0N/A
0N/A Label dispatch_entry_2;
304N/A __ movptr(rcx, sender_sp_on_entry);
304N/A __ movptr(state, (int32_t)NULL_WORD); // no current activation
0N/A
0N/A __ jmp(dispatch_entry_2);
0N/A
0N/A const Register locals = rdi;
0N/A
0N/A Label re_dispatch;
0N/A
0N/A __ bind(re_dispatch);
0N/A
0N/A // save sender sp (doesn't include return address
304N/A __ lea(rcx, Address(rsp, wordSize));
0N/A
0N/A __ bind(dispatch_entry_2);
0N/A
0N/A // save sender sp
304N/A __ push(rcx);
0N/A
0N/A const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
0N/A const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset());
0N/A const Address access_flags (rbx, methodOopDesc::access_flags_offset());
0N/A
0N/A // const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
0N/A // const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
0N/A // const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
0N/A
0N/A // get parameter size (always needed)
622N/A __ load_unsigned_short(rcx, size_of_parameters);
0N/A
0N/A // rbx: methodOop
0N/A // rcx: size of parameters
622N/A __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
0N/A
304N/A __ subptr(rdx, rcx); // rdx = no. of additional locals
0N/A
0N/A // see if we've got enough room on the stack for locals plus overhead.
0N/A generate_stack_overflow_check(); // C++
0N/A
0N/A // c++ interpreter does not use stack banging or any implicit exceptions
0N/A // leave for now to verify that check is proper.
0N/A bang_stack_shadow_pages(false);
0N/A
0N/A
0N/A
0N/A // compute beginning of parameters (rdi)
304N/A __ lea(locals, Address(rsp, rcx, Address::times_ptr, wordSize));
0N/A
0N/A // save sender's sp
0N/A // __ movl(rcx, rsp);
0N/A
0N/A // get sender's sp
304N/A __ pop(rcx);
0N/A
0N/A // get return address
304N/A __ pop(rax);
0N/A
0N/A // rdx - # of additional locals
0N/A // allocate space for locals
0N/A // explicitly initialize locals
0N/A {
0N/A Label exit, loop;
304N/A __ testl(rdx, rdx); // (32bit ok)
0N/A __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
0N/A __ bind(loop);
304N/A __ push((int32_t)NULL_WORD); // initialize local variables
0N/A __ decrement(rdx); // until everything initialized
0N/A __ jcc(Assembler::greater, loop);
0N/A __ bind(exit);
0N/A }
0N/A
0N/A
0N/A // Assumes rax = return address
0N/A
0N/A // allocate and initialize new interpreterState and method expression stack
0N/A // IN(locals) -> locals
0N/A // IN(state) -> any current interpreter activation
0N/A // destroys rax, rcx, rdx, rdi
0N/A // OUT (state) -> new interpreterState
0N/A // OUT(rsp) -> bottom of methods expression stack
0N/A
0N/A generate_compute_interpreter_state(state, locals, rcx, false);
0N/A
0N/A // Call interpreter
0N/A
0N/A Label call_interpreter;
0N/A __ bind(call_interpreter);
0N/A
0N/A // c++ interpreter does not use stack banging or any implicit exceptions
0N/A // leave for now to verify that check is proper.
0N/A bang_stack_shadow_pages(false);
0N/A
0N/A
0N/A // Call interpreter enter here if message is
0N/A // set and we know stack size is valid
0N/A
0N/A Label call_interpreter_2;
0N/A
0N/A __ bind(call_interpreter_2);
0N/A
0N/A {
304N/A const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
304N/A
304N/A#ifdef _LP64
304N/A __ mov(c_rarg0, state);
304N/A#else
304N/A __ push(state); // push arg to interpreter
304N/A __ movptr(thread, STATE(_thread));
304N/A#endif // _LP64
0N/A
0N/A // We can setup the frame anchor with everything we want at this point
0N/A // as we are thread_in_Java and no safepoints can occur until we go to
0N/A // vm mode. We do have to clear flags on return from vm but that is it
0N/A //
304N/A __ movptr(Address(thread, JavaThread::last_Java_fp_offset()), rbp);
304N/A __ movptr(Address(thread, JavaThread::last_Java_sp_offset()), rsp);
0N/A
0N/A // Call the interpreter
0N/A
0N/A RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run));
0N/A RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks));
0N/A
0N/A __ call(JvmtiExport::can_post_interpreter_events() ? checking : normal);
304N/A NOT_LP64(__ pop(rax);) // discard parameter to run
0N/A //
0N/A // state is preserved since it is callee saved
0N/A //
0N/A
0N/A // reset_last_Java_frame
0N/A
304N/A NOT_LP64(__ movl(thread, STATE(_thread));)
0N/A __ reset_last_Java_frame(thread, true, true);
0N/A }
0N/A
0N/A // examine msg from interpreter to determine next action
0N/A
0N/A __ movl(rdx, STATE(_msg)); // Get new message
0N/A
0N/A Label call_method;
0N/A Label return_from_interpreted_method;
0N/A Label throw_exception;
0N/A Label bad_msg;
0N/A Label do_OSR;
0N/A
304N/A __ cmpl(rdx, (int32_t)BytecodeInterpreter::call_method);
0N/A __ jcc(Assembler::equal, call_method);
304N/A __ cmpl(rdx, (int32_t)BytecodeInterpreter::return_from_method);
0N/A __ jcc(Assembler::equal, return_from_interpreted_method);
304N/A __ cmpl(rdx, (int32_t)BytecodeInterpreter::do_osr);
0N/A __ jcc(Assembler::equal, do_OSR);
304N/A __ cmpl(rdx, (int32_t)BytecodeInterpreter::throwing_exception);
0N/A __ jcc(Assembler::equal, throw_exception);
304N/A __ cmpl(rdx, (int32_t)BytecodeInterpreter::more_monitors);
0N/A __ jcc(Assembler::notEqual, bad_msg);
0N/A
0N/A // Allocate more monitor space, shuffle expression stack....
0N/A
0N/A generate_more_monitors();
0N/A
0N/A __ jmp(call_interpreter);
0N/A
0N/A // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
0N/A unctrap_frame_manager_entry = __ pc();
0N/A //
0N/A // Load the registers we need.
304N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
304N/A __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
0N/A __ jmp(call_interpreter_2);
0N/A
0N/A
0N/A
0N/A //=============================================================================
0N/A // Returning from a compiled method into a deopted method. The bytecode at the
0N/A // bcp has completed. The result of the bytecode is in the native abi (the tosca
0N/A // for the template based interpreter). Any stack space that was used by the
0N/A // bytecode that has completed has been removed (e.g. parameters for an invoke)
0N/A // so all that we have to do is place any pending result on the expression stack
0N/A // and resume execution on the next bytecode.
0N/A
0N/A
0N/A generate_deopt_handling();
0N/A __ jmp(call_interpreter);
0N/A
0N/A
0N/A // Current frame has caught an exception we need to dispatch to the
0N/A // handler. We can get here because a native interpreter frame caught
0N/A // an exception in which case there is no handler and we must rethrow
0N/A // If it is a vanilla interpreted frame the we simply drop into the
0N/A // interpreter and let it do the lookup.
0N/A
0N/A Interpreter::_rethrow_exception_entry = __ pc();
0N/A // rax: exception
0N/A // rdx: return address/pc that threw exception
0N/A
0N/A Label return_with_exception;
0N/A Label unwind_and_forward;
0N/A
0N/A // restore state pointer.
520N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
304N/A
304N/A __ movptr(rbx, STATE(_method)); // get method
304N/A#ifdef _LP64
304N/A __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
304N/A#else
0N/A __ movl(rcx, STATE(_thread)); // get thread
0N/A
0N/A // Store exception with interpreter will expect it
304N/A __ movptr(Address(rcx, Thread::pending_exception_offset()), rax);
304N/A#endif // _LP64
0N/A
0N/A // is current frame vanilla or native?
0N/A
0N/A __ movl(rdx, access_flags);
0N/A __ testl(rdx, JVM_ACC_NATIVE);
0N/A __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly
0N/A
0N/A // We drop thru to unwind a native interpreted frame with a pending exception
0N/A // We jump here for the initial interpreter frame with exception pending
0N/A // We unwind the current acivation and forward it to our caller.
0N/A
0N/A __ bind(unwind_and_forward);
0N/A
0N/A // unwind rbp, return stack to unextended value and re-push return address
0N/A
304N/A __ movptr(rcx, STATE(_sender_sp));
0N/A __ leave();
304N/A __ pop(rdx);
304N/A __ mov(rsp, rcx);
304N/A __ push(rdx);
0N/A __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
0N/A
0N/A // Return point from a call which returns a result in the native abi
0N/A // (c1/c2/jni-native). This result must be processed onto the java
0N/A // expression stack.
0N/A //
0N/A // A pending exception may be present in which case there is no result present
0N/A
0N/A Label resume_interpreter;
0N/A Label do_float;
0N/A Label do_double;
0N/A Label done_conv;
0N/A
0N/A // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
0N/A if (UseSSE < 2) {
520N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
304N/A __ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed
0N/A __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
0N/A __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
0N/A __ jcc(Assembler::equal, do_float);
0N/A __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
0N/A __ jcc(Assembler::equal, do_double);
520N/A#if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)
0N/A __ empty_FPU_stack();
0N/A#endif // COMPILER2
0N/A __ jmp(done_conv);
0N/A
0N/A __ bind(do_float);
0N/A#ifdef COMPILER2
0N/A for (int i = 1; i < 8; i++) {
0N/A __ ffree(i);
0N/A }
0N/A#endif // COMPILER2
0N/A __ jmp(done_conv);
0N/A __ bind(do_double);
0N/A#ifdef COMPILER2
0N/A for (int i = 1; i < 8; i++) {
0N/A __ ffree(i);
0N/A }
0N/A#endif // COMPILER2
0N/A __ jmp(done_conv);
0N/A } else {
0N/A __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
0N/A __ jmp(done_conv);
0N/A }
0N/A
0N/A // Return point to interpreter from compiled/native method
0N/A InternalAddress return_from_native_method(__ pc());
0N/A
0N/A __ bind(done_conv);
0N/A
0N/A
0N/A // Result if any is in tosca. The java expression stack is in the state that the
0N/A // calling convention left it (i.e. params may or may not be present)
0N/A // Copy the result from tosca and place it on java expression stack.
0N/A
304N/A // Restore rsi/r13 as compiled code may not preserve it
304N/A
520N/A __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
0N/A
0N/A // restore stack to what we had when we left (in case i2c extended it)
0N/A
304N/A __ movptr(rsp, STATE(_stack));
304N/A __ lea(rsp, Address(rsp, wordSize));
0N/A
0N/A // If there is a pending exception then we don't really have a result to process
0N/A
304N/A#ifdef _LP64
304N/A __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
304N/A#else
304N/A __ movptr(rcx, STATE(_thread)); // get thread
304N/A __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
520N/A#endif // _LP64
0N/A __ jcc(Assembler::notZero, return_with_exception);
0N/A
0N/A // get method just executed
304N/A __ movptr(rbx, STATE(_result._to_call._callee));
0N/A
0N/A // callee left args on top of expression stack, remove them
622N/A __ load_unsigned_short(rcx, Address(rbx, methodOopDesc::size_of_parameters_offset()));
304N/A __ lea(rsp, Address(rsp, rcx, Address::times_ptr));
0N/A
0N/A __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
0N/A ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
304N/A // Address index(noreg, rax, Address::times_ptr);
304N/A __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
304N/A // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
0N/A __ call(rcx); // call result converter
0N/A __ jmp(resume_interpreter);
0N/A
0N/A // An exception is being caught on return to a vanilla interpreter frame.
0N/A // Empty the stack and resume interpreter
0N/A
0N/A __ bind(return_with_exception);
0N/A
0N/A // Exception present, empty stack
304N/A __ movptr(rsp, STATE(_stack_base));
0N/A __ jmp(resume_interpreter);
0N/A
0N/A // Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
0N/A // interpreter call, or native) and unwind this interpreter activation.
0N/A // All monitors should be unlocked.
0N/A
0N/A __ bind(return_from_interpreted_method);
0N/A
0N/A Label return_to_initial_caller;
0N/A
304N/A __ movptr(rbx, STATE(_method)); // get method just executed
304N/A __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
0N/A __ movl(rax, Address(rbx, methodOopDesc::result_index_offset())); // get result type index
0N/A __ jcc(Assembler::equal, return_to_initial_caller); // back to native code (call_stub/c1/c2)
0N/A
0N/A // Copy result to callers java stack
0N/A ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack);
304N/A // Address index(noreg, rax, Address::times_ptr);
304N/A
304N/A __ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_ptr)));
304N/A // __ movl(rax, Address(noreg, rax, Address::times_ptr, int(AbstractInterpreter::_stack_to_stack)));
0N/A __ call(rax); // call result converter
0N/A
0N/A Label unwind_recursive_activation;
0N/A __ bind(unwind_recursive_activation);
0N/A
0N/A // returning to interpreter method from "recursive" interpreter call
0N/A // result converter left rax pointing to top of the java stack for method we are returning
0N/A // to. Now all we must do is unwind the state from the completed call
0N/A
304N/A __ movptr(state, STATE(_prev_link)); // unwind state
0N/A __ leave(); // pop the frame
304N/A __ mov(rsp, rax); // unwind stack to remove args
0N/A
0N/A // Resume the interpreter. The current frame contains the current interpreter
0N/A // state object.
0N/A //
0N/A
0N/A __ bind(resume_interpreter);
0N/A
0N/A // state == interpreterState object for method we are resuming
0N/A
0N/A __ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume);
304N/A __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
304N/A __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
0N/A // result if any on stack already )
304N/A __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
0N/A __ jmp(call_interpreter_2); // No need to bang
0N/A
0N/A // interpreter returning to native code (call_stub/c1/c2)
0N/A // convert result and unwind initial activation
0N/A // rax - result index
0N/A
0N/A __ bind(return_to_initial_caller);
0N/A ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi);
304N/A // Address index(noreg, rax, Address::times_ptr);
304N/A
304N/A __ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_ptr)));
0N/A __ call(rax); // call result converter
0N/A
0N/A Label unwind_initial_activation;
0N/A __ bind(unwind_initial_activation);
0N/A
0N/A // RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0))
0N/A
0N/A /* Current stack picture
0N/A
0N/A [ incoming parameters ]
0N/A [ extra locals ]
0N/A [ return address to CALL_STUB/C1/C2]
0N/A fp -> [ CALL_STUB/C1/C2 fp ]
0N/A BytecodeInterpreter object
0N/A expression stack
0N/A sp ->
0N/A
0N/A */
0N/A
0N/A // return restoring the stack to the original sender_sp value
0N/A
304N/A __ movptr(rcx, STATE(_sender_sp));
0N/A __ leave();
304N/A __ pop(rdi); // get return address
0N/A // set stack to sender's sp
304N/A __ mov(rsp, rcx);
0N/A __ jmp(rdi); // return to call_stub
0N/A
0N/A // OSR request, adjust return address to make current frame into adapter frame
0N/A // and enter OSR nmethod
0N/A
0N/A __ bind(do_OSR);
0N/A
0N/A Label remove_initial_frame;
0N/A
0N/A // We are going to pop this frame. Is there another interpreter frame underneath
0N/A // it or is it callstub/compiled?
0N/A
0N/A // Move buffer to the expected parameter location
304N/A __ movptr(rcx, STATE(_result._osr._osr_buf));
304N/A
304N/A __ movptr(rax, STATE(_result._osr._osr_entry));
304N/A
304N/A __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
0N/A __ jcc(Assembler::equal, remove_initial_frame); // back to native code (call_stub/c1/c2)
0N/A
304N/A __ movptr(sender_sp_on_entry, STATE(_sender_sp)); // get sender's sp in expected register
0N/A __ leave(); // pop the frame
304N/A __ mov(rsp, sender_sp_on_entry); // trim any stack expansion
0N/A
0N/A
0N/A // We know we are calling compiled so push specialized return
0N/A // method uses specialized entry, push a return so we look like call stub setup
0N/A // this path will handle fact that result is returned in registers and not
0N/A // on the java stack.
0N/A
0N/A __ pushptr(return_from_native_method.addr());
0N/A
0N/A __ jmp(rax);
0N/A
0N/A __ bind(remove_initial_frame);
0N/A
304N/A __ movptr(rdx, STATE(_sender_sp));
0N/A __ leave();
0N/A // get real return
304N/A __ pop(rsi);
0N/A // set stack to sender's sp
304N/A __ mov(rsp, rdx);
0N/A // repush real return
304N/A __ push(rsi);
0N/A // Enter OSR nmethod
0N/A __ jmp(rax);
0N/A
0N/A
0N/A
0N/A
0N/A // Call a new method. All we do is (temporarily) trim the expression stack
0N/A // push a return address to bring us back to here and leap to the new entry.
0N/A
0N/A __ bind(call_method);
0N/A
0N/A // stack points to next free location and not top element on expression stack
0N/A // method expects sp to be pointing to topmost element
0N/A
304N/A __ movptr(rsp, STATE(_stack)); // pop args to c++ interpreter, set sp to java stack top
304N/A __ lea(rsp, Address(rsp, wordSize));
304N/A
304N/A __ movptr(rbx, STATE(_result._to_call._callee)); // get method to execute
0N/A
0N/A // don't need a return address if reinvoking interpreter
0N/A
0N/A // Make it look like call_stub calling conventions
0N/A
0N/A // Get (potential) receiver
622N/A __ load_unsigned_short(rcx, size_of_parameters); // get size of parameters in words
0N/A
0N/A ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
0N/A __ pushptr(recursive.addr()); // make it look good in the debugger
0N/A
0N/A InternalAddress entry(entry_point);
0N/A __ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter?
0N/A __ jcc(Assembler::equal, re_dispatch); // yes
0N/A
304N/A __ pop(rax); // pop dummy address
0N/A
0N/A
0N/A // get specialized entry
304N/A __ movptr(rax, STATE(_result._to_call._callee_entry_point));
0N/A // set sender SP
304N/A __ mov(sender_sp_on_entry, rsp);
0N/A
0N/A // method uses specialized entry, push a return so we look like call stub setup
0N/A // this path will handle fact that result is returned in registers and not
0N/A // on the java stack.
0N/A
0N/A __ pushptr(return_from_native_method.addr());
0N/A
0N/A __ jmp(rax);
0N/A
0N/A __ bind(bad_msg);
0N/A __ stop("Bad message from interpreter");
0N/A
0N/A // Interpreted method "returned" with an exception pass it on...
0N/A // Pass result, unwind activation and continue/return to interpreter/call_stub
0N/A // We handle result (if any) differently based on return to interpreter or call_stub
0N/A
0N/A Label unwind_initial_with_pending_exception;
0N/A
0N/A __ bind(throw_exception);
304N/A __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from recursive interpreter call?
0N/A __ jcc(Assembler::equal, unwind_initial_with_pending_exception); // no, back to native code (call_stub/c1/c2)
304N/A __ movptr(rax, STATE(_locals)); // pop parameters get new stack value
304N/A __ addptr(rax, wordSize); // account for prepush before we return
0N/A __ jmp(unwind_recursive_activation);
0N/A
0N/A __ bind(unwind_initial_with_pending_exception);
0N/A
0N/A // We will unwind the current (initial) interpreter frame and forward
0N/A // the exception to the caller. We must put the exception in the
0N/A // expected register and clear pending exception and then forward.
0N/A
0N/A __ jmp(unwind_and_forward);
0N/A
0N/A interpreter_frame_manager = entry_point;
0N/A return entry_point;
0N/A}
0N/A
0N/Aaddress AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
0N/A // determine code generation flags
0N/A bool synchronized = false;
0N/A address entry_point = NULL;
0N/A
0N/A switch (kind) {
0N/A case Interpreter::zerolocals : break;
0N/A case Interpreter::zerolocals_synchronized: synchronized = true; break;
0N/A case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
0N/A case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
0N/A case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
0N/A case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
0N/A case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
710N/A case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
0N/A
0N/A case Interpreter::java_lang_math_sin : // fall thru
0N/A case Interpreter::java_lang_math_cos : // fall thru
0N/A case Interpreter::java_lang_math_tan : // fall thru
0N/A case Interpreter::java_lang_math_abs : // fall thru
0N/A case Interpreter::java_lang_math_log : // fall thru
0N/A case Interpreter::java_lang_math_log10 : // fall thru
0N/A case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
2346N/A case Interpreter::java_lang_ref_reference_get
2346N/A : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
0N/A default : ShouldNotReachHere(); break;
0N/A }
0N/A
0N/A if (entry_point) return entry_point;
0N/A
0N/A return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
0N/A
0N/A}
0N/A
0N/AInterpreterGenerator::InterpreterGenerator(StubQueue* code)
0N/A : CppInterpreterGenerator(code) {
0N/A generate_all(); // down here so it can be "virtual"
0N/A}
0N/A
0N/A// Deoptimization helpers for C++ interpreter
0N/A
0N/A// How much stack a method activation needs in words.
0N/Aint AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
0N/A
0N/A const int stub_code = 4; // see generate_call_stub
0N/A // Save space for one monitor to get into the interpreted method in case
0N/A // the method is synchronized
0N/A int monitor_size = method->is_synchronized() ?
0N/A 1*frame::interpreter_frame_monitor_size() : 0;
0N/A
0N/A // total static overhead size. Account for interpreter state object, return
0N/A // address, saved rbp and 2 words for a "static long no_params() method" issue.
0N/A
0N/A const int overhead_size = sizeof(BytecodeInterpreter)/wordSize +
0N/A ( frame::sender_sp_offset - frame::link_offset) + 2;
0N/A
710N/A const int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries();
710N/A const int method_stack = (method->max_locals() + method->max_stack() + extra_stack) *
0N/A Interpreter::stackElementWords();
0N/A return overhead_size + method_stack + stub_code;
0N/A}
0N/A
0N/A// returns the activation size.
0N/Astatic int size_activation_helper(int extra_locals_size, int monitor_size) {
0N/A return (extra_locals_size + // the addition space for locals
0N/A 2*BytesPerWord + // return address and saved rbp
0N/A 2*BytesPerWord + // "static long no_params() method" issue
0N/A sizeof(BytecodeInterpreter) + // interpreterState
0N/A monitor_size); // monitors
0N/A}
0N/A
0N/Avoid BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
0N/A frame* caller,
0N/A frame* current,
0N/A methodOop method,
0N/A intptr_t* locals,
0N/A intptr_t* stack,
0N/A intptr_t* stack_base,
0N/A intptr_t* monitor_base,
0N/A intptr_t* frame_bottom,
0N/A bool is_top_frame
0N/A )
0N/A{
0N/A // What about any vtable?
0N/A //
0N/A to_fill->_thread = JavaThread::current();
0N/A // This gets filled in later but make it something recognizable for now
0N/A to_fill->_bcp = method->code_base();
0N/A to_fill->_locals = locals;
0N/A to_fill->_constants = method->constants()->cache();
0N/A to_fill->_method = method;
0N/A to_fill->_mdx = NULL;
0N/A to_fill->_stack = stack;
0N/A if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {
0N/A to_fill->_msg = deopt_resume2;
0N/A } else {
0N/A to_fill->_msg = method_resume;
0N/A }
0N/A to_fill->_result._to_call._bcp_advance = 0;
0N/A to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
0N/A to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
0N/A to_fill->_prev_link = NULL;
0N/A
0N/A to_fill->_sender_sp = caller->unextended_sp();
0N/A
0N/A if (caller->is_interpreted_frame()) {
0N/A interpreterState prev = caller->get_interpreterState();
0N/A to_fill->_prev_link = prev;
0N/A // *current->register_addr(GR_Iprev_state) = (intptr_t) prev;
0N/A // Make the prev callee look proper
0N/A prev->_result._to_call._callee = method;
0N/A if (*prev->_bcp == Bytecodes::_invokeinterface) {
0N/A prev->_result._to_call._bcp_advance = 5;
0N/A } else {
0N/A prev->_result._to_call._bcp_advance = 3;
0N/A }
0N/A }
0N/A to_fill->_oop_temp = NULL;
0N/A to_fill->_stack_base = stack_base;
0N/A // Need +1 here because stack_base points to the word just above the first expr stack entry
0N/A // and stack_limit is supposed to point to the word just below the last expr stack entry.
0N/A // See generate_compute_interpreter_state.
710N/A int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries();
710N/A to_fill->_stack_limit = stack_base - (method->max_stack() + extra_stack + 1);
0N/A to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
0N/A
0N/A to_fill->_self_link = to_fill;
0N/A assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
0N/A "Stack top out of range");
0N/A}
0N/A
0N/Aint AbstractInterpreter::layout_activation(methodOop method,
2466N/A int tempcount, //
2466N/A int popframe_extra_args,
2466N/A int moncount,
2466N/A int caller_actual_parameters,
2466N/A int callee_param_count,
2466N/A int callee_locals,
2466N/A frame* caller,
2466N/A frame* interpreter_frame,
4331N/A bool is_top_frame,
4331N/A bool is_bottom_frame) {
0N/A
0N/A assert(popframe_extra_args == 0, "FIX ME");
0N/A // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
0N/A // does as far as allocating an interpreter frame.
0N/A // If interpreter_frame!=NULL, set up the method, locals, and monitors.
0N/A // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
0N/A // as determined by a previous call to this method.
0N/A // It is also guaranteed to be walkable even though it is in a skeletal state
0N/A // NOTE: return size is in words not bytes
0N/A // NOTE: tempcount is the current size of the java expression stack. For top most
0N/A // frames we will allocate a full sized expression stack and not the curback
0N/A // version that non-top frames have.
0N/A
0N/A // Calculate the amount our frame will be adjust by the callee. For top frame
0N/A // this is zero.
0N/A
0N/A // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
0N/A // calculates the extra locals based on itself. Not what the callee does
0N/A // to it. So it ignores last_frame_adjust value. Seems suspicious as far
0N/A // as getting sender_sp correct.
0N/A
0N/A int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
0N/A int monitor_size = sizeof(BasicObjectLock) * moncount;
0N/A
0N/A // First calculate the frame size without any java expression stack
0N/A int short_frame_size = size_activation_helper(extra_locals_size,
0N/A monitor_size);
0N/A
0N/A // Now with full size expression stack
710N/A int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries();
710N/A int full_frame_size = short_frame_size + (method->max_stack() + extra_stack) * BytesPerWord;
0N/A
0N/A // and now with only live portion of the expression stack
0N/A short_frame_size = short_frame_size + tempcount * BytesPerWord;
0N/A
0N/A // the size the activation is right now. Only top frame is full size
0N/A int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
0N/A
0N/A if (interpreter_frame != NULL) {
0N/A#ifdef ASSERT
0N/A assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
0N/A#endif
0N/A
0N/A // MUCHO HACK
0N/A
0N/A intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
0N/A
0N/A /* Now fillin the interpreterState object */
0N/A
0N/A // The state object is the first thing on the frame and easily located
0N/A
0N/A interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
0N/A
0N/A
0N/A // Find the locals pointer. This is rather simple on x86 because there is no
0N/A // confusing rounding at the callee to account for. We can trivially locate
0N/A // our locals based on the current fp().
0N/A // Note: the + 2 is for handling the "static long no_params() method" issue.
0N/A // (too bad I don't really remember that issue well...)
0N/A
0N/A intptr_t* locals;
0N/A // If the caller is interpreted we need to make sure that locals points to the first
0N/A // argument that the caller passed and not in an area where the stack might have been extended.
0N/A // because the stack to stack to converter needs a proper locals value in order to remove the
0N/A // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
0N/A // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
0N/A // adjust the stack?? HMMM QQQ
0N/A //
0N/A if (caller->is_interpreted_frame()) {
0N/A // locals must agree with the caller because it will be used to set the
0N/A // caller's tos when we return.
0N/A interpreterState prev = caller->get_interpreterState();
0N/A // stack() is prepushed.
0N/A locals = prev->stack() + method->size_of_parameters();
0N/A // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
0N/A if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
0N/A // os::breakpoint();
0N/A }
0N/A } else {
0N/A // this is where a c2i would have placed locals (except for the +2)
0N/A locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
0N/A }
0N/A
0N/A intptr_t* monitor_base = (intptr_t*) cur_state;
0N/A intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
0N/A /* +1 because stack is always prepushed */
0N/A intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
0N/A
0N/A
0N/A BytecodeInterpreter::layout_interpreterState(cur_state,
0N/A caller,
0N/A interpreter_frame,
0N/A method,
0N/A locals,
0N/A stack,
0N/A stack_base,
0N/A monitor_base,
0N/A frame_bottom,
0N/A is_top_frame);
0N/A
0N/A // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
0N/A }
0N/A return frame_size/BytesPerWord;
0N/A}
0N/A
0N/A#endif // CC_INTERP (all)