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