duke@435: /* jrose@2639: * Copyright (c) 2007, 2011, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "asm/assembler.hpp" stefank@2314: #include "interpreter/bytecodeHistogram.hpp" stefank@2314: #include "interpreter/cppInterpreter.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/interpreterGenerator.hpp" stefank@2314: #include "interpreter/interpreterRuntime.hpp" stefank@2314: #include "oops/arrayOop.hpp" stefank@2314: #include "oops/methodDataOop.hpp" stefank@2314: #include "oops/methodOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "prims/jvmtiExport.hpp" stefank@2314: #include "prims/jvmtiThreadState.hpp" stefank@2314: #include "runtime/arguments.hpp" stefank@2314: #include "runtime/deoptimization.hpp" stefank@2314: #include "runtime/frame.inline.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: #include "runtime/synchronizer.hpp" stefank@2314: #include "runtime/timer.hpp" stefank@2314: #include "runtime/vframeArray.hpp" stefank@2314: #include "utilities/debug.hpp" stefank@2314: #ifdef SHARK stefank@2314: #include "shark/shark_globals.hpp" stefank@2314: #endif duke@435: duke@435: #ifdef CC_INTERP duke@435: duke@435: // Routine exists to make tracebacks look decent in debugger duke@435: // while "shadow" interpreter frames are on stack. It is also duke@435: // used to distinguish interpreter frames. duke@435: duke@435: extern "C" void RecursiveInterpreterActivation(interpreterState istate) { duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: bool CppInterpreter::contains(address pc) { duke@435: return ( _code->contains(pc) || duke@435: ( pc == (CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset))); duke@435: } duke@435: duke@435: #define STATE(field_name) Lstate, in_bytes(byte_offset_of(BytecodeInterpreter, field_name)) duke@435: #define __ _masm-> duke@435: duke@435: Label frame_manager_entry; 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: duke@435: static address unctrap_frame_manager_entry = NULL; duke@435: duke@435: static address interpreter_return_address = NULL; 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: const Register prevState = G1_scratch; duke@435: duke@435: void InterpreterGenerator::save_native_result(void) { duke@435: // result potentially in O0/O1: save it across calls duke@435: __ stf(FloatRegisterImpl::D, F0, STATE(_native_fresult)); duke@435: #ifdef _LP64 duke@435: __ stx(O0, STATE(_native_lresult)); duke@435: #else duke@435: __ std(O0, STATE(_native_lresult)); duke@435: #endif duke@435: } duke@435: duke@435: void InterpreterGenerator::restore_native_result(void) { duke@435: duke@435: // Restore any method result value duke@435: __ ldf(FloatRegisterImpl::D, STATE(_native_fresult), F0); duke@435: #ifdef _LP64 duke@435: __ ldx(STATE(_native_lresult), O0); duke@435: #else duke@435: __ ldd(STATE(_native_lresult), O0); duke@435: #endif duke@435: } duke@435: duke@435: // A result handler converts/unboxes a native call result into duke@435: // a java interpreter/compiler result. The current frame is an duke@435: // interpreter frame. The activation frame unwind code must be duke@435: // consistent with that of TemplateTable::_return(...). In the duke@435: // case of native methods, the caller's SP was not modified. duke@435: address CppInterpreterGenerator::generate_result_handler_for(BasicType type) { duke@435: address entry = __ pc(); duke@435: Register Itos_i = Otos_i ->after_save(); duke@435: Register Itos_l = Otos_l ->after_save(); duke@435: Register Itos_l1 = Otos_l1->after_save(); duke@435: Register Itos_l2 = Otos_l2->after_save(); duke@435: switch (type) { duke@435: case T_BOOLEAN: __ subcc(G0, O0, G0); __ addc(G0, 0, Itos_i); break; // !0 => true; 0 => false duke@435: case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value! duke@435: case T_BYTE : __ sll(O0, 24, O0); __ sra(O0, 24, Itos_i); break; duke@435: case T_SHORT : __ sll(O0, 16, O0); __ sra(O0, 16, Itos_i); break; duke@435: case T_LONG : duke@435: #ifndef _LP64 duke@435: __ mov(O1, Itos_l2); // move other half of long duke@435: #endif // ifdef or no ifdef, fall through to the T_INT case duke@435: case T_INT : __ mov(O0, Itos_i); break; duke@435: case T_VOID : /* nothing to do */ break; duke@435: case T_FLOAT : assert(F0 == Ftos_f, "fix this code" ); break; duke@435: case T_DOUBLE : assert(F0 == Ftos_d, "fix this code" ); break; duke@435: case T_OBJECT : duke@435: __ ld_ptr(STATE(_oop_temp), Itos_i); duke@435: __ verify_oop(Itos_i); duke@435: break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ ret(); // return from interpreter activation duke@435: __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame duke@435: NOT_PRODUCT(__ emit_long(0);) // marker for disassembly duke@435: return entry; duke@435: } duke@435: duke@435: // tosca based result to c++ interpreter stack based result. duke@435: // Result goes to address in L1_scratch duke@435: duke@435: address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) { duke@435: // A result is in the native abi result register from a native method call. duke@435: // We need to return this result to the interpreter by pushing the result on the interpreter's duke@435: // stack. This is relatively simple the destination is in L1_scratch duke@435: // i.e. L1_scratch is the first free element on the stack. If we "push" a return value we must duke@435: // adjust L1_scratch duke@435: address entry = __ pc(); duke@435: switch (type) { duke@435: case T_BOOLEAN: duke@435: // !0 => true; 0 => false duke@435: __ subcc(G0, O0, G0); duke@435: __ addc(G0, 0, O0); duke@435: __ st(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: duke@435: // cannot use and3, 0xFFFF too big as immediate value! duke@435: case T_CHAR : duke@435: __ sll(O0, 16, O0); duke@435: __ srl(O0, 16, O0); duke@435: __ st(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: duke@435: case T_BYTE : duke@435: __ sll(O0, 24, O0); duke@435: __ sra(O0, 24, O0); duke@435: __ st(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: duke@435: case T_SHORT : duke@435: __ sll(O0, 16, O0); duke@435: __ sra(O0, 16, O0); duke@435: __ st(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: case T_LONG : duke@435: #ifndef _LP64 sgoldman@558: #if defined(COMPILER2) duke@435: // All return values are where we want them, except for Longs. C2 returns duke@435: // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1. duke@435: // Since the interpreter will return longs in G1 and O0/O1 in the 32bit duke@435: // build even if we are returning from interpreted we just do a little duke@435: // stupid shuffing. duke@435: // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to duke@435: // do this here. Unfortunately if we did a rethrow we'd see an machepilog node duke@435: // first which would move g1 -> O0/O1 and destroy the exception we were throwing. duke@435: __ stx(G1, L1_scratch, -wordSize); duke@435: #else duke@435: // native result is in O0, O1 duke@435: __ st(O1, L1_scratch, 0); // Low order duke@435: __ st(O0, L1_scratch, -wordSize); // High order sgoldman@558: #endif /* COMPILER2 */ duke@435: #else sgoldman@558: __ stx(O0, L1_scratch, -wordSize); duke@435: #endif duke@435: __ sub(L1_scratch, 2*wordSize, L1_scratch); duke@435: break; duke@435: duke@435: case T_INT : duke@435: __ st(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: duke@435: case T_VOID : /* nothing to do */ duke@435: break; duke@435: duke@435: case T_FLOAT : duke@435: __ stf(FloatRegisterImpl::S, F0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: duke@435: case T_DOUBLE : duke@435: // Every stack slot is aligned on 64 bit, However is this duke@435: // the correct stack slot on 64bit?? QQQ duke@435: __ stf(FloatRegisterImpl::D, F0, L1_scratch, -wordSize); duke@435: __ sub(L1_scratch, 2*wordSize, L1_scratch); duke@435: break; duke@435: case T_OBJECT : duke@435: __ verify_oop(O0); duke@435: __ st_ptr(O0, L1_scratch, 0); duke@435: __ sub(L1_scratch, wordSize, L1_scratch); duke@435: break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ retl(); // return from interpreter activation duke@435: __ delayed()->nop(); // schedule this better duke@435: NOT_PRODUCT(__ emit_long(0);) // marker for disassembly 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: // duke@435: // The current interpreter activation in Lstate 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 esp 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: // duke@435: // On entry: O0 - points to source (callee stack top) duke@435: // O1 - points to destination (caller stack top [i.e. free location]) duke@435: // destroys O2, O3 duke@435: // duke@435: duke@435: address entry = __ pc(); duke@435: switch (type) { duke@435: case T_VOID: break; 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 duke@435: __ ld(O0, 0, O2); duke@435: __ st(O2, O1, 0); duke@435: __ sub(O1, wordSize, O1); duke@435: break; duke@435: case T_DOUBLE : duke@435: case T_LONG : 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: #ifdef _LP64 duke@435: __ ld_ptr(O0, 0, O2); duke@435: __ st_ptr(O2, O1, -wordSize); duke@435: #else duke@435: __ ld(O0, 0, O2); duke@435: __ ld(O0, wordSize, O3); duke@435: __ st(O3, O1, 0); duke@435: __ st(O2, O1, -wordSize); duke@435: #endif duke@435: __ sub(O1, 2*wordSize, O1); duke@435: break; duke@435: case T_OBJECT : duke@435: __ ld_ptr(O0, 0, O2); duke@435: __ verify_oop(O2); // verify it duke@435: __ st_ptr(O2, O1, 0); duke@435: __ sub(O1, wordSize, O1); duke@435: break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ retl(); duke@435: __ delayed()->nop(); // QQ schedule this better 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: // We are in a new frame registers we set must be in caller (i.e. callstub) frame. 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. duke@435: // On entry: O0 - source (stack top) duke@435: // On exit result in expected output register duke@435: // QQQ schedule this better duke@435: duke@435: address entry = __ pc(); duke@435: switch (type) { duke@435: case T_VOID: break; duke@435: break; duke@435: case T_FLOAT : duke@435: __ ldf(FloatRegisterImpl::S, O0, 0, F0); 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 : duke@435: // 1 word result duke@435: __ ld(O0, 0, O0->after_save()); duke@435: break; duke@435: case T_DOUBLE : duke@435: __ ldf(FloatRegisterImpl::D, O0, 0, F0); duke@435: break; duke@435: case T_LONG : 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 interpretState 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: #ifdef _LP64 duke@435: __ ld_ptr(O0, 0, O0->after_save()); duke@435: #else duke@435: __ ld(O0, wordSize, O1->after_save()); duke@435: __ ld(O0, 0, O0->after_save()); duke@435: #endif duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: // C2 expects long results in G1 we can't tell if we're returning to interpreted duke@435: // or compiled so just be safe use G1 and O0/O1 duke@435: duke@435: // Shift bits into high (msb) of G1 duke@435: __ sllx(Otos_l1->after_save(), 32, G1); duke@435: // Zero extend low bits duke@435: __ srl (Otos_l2->after_save(), 0, Otos_l2->after_save()); duke@435: __ or3 (Otos_l2->after_save(), G1, G1); duke@435: #endif /* COMPILER2 */ duke@435: break; duke@435: case T_OBJECT : duke@435: __ ld_ptr(O0, 0, O0->after_save()); duke@435: __ verify_oop(O0->after_save()); // verify it duke@435: break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ retl(); duke@435: __ delayed()->nop(); 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) + frame::pc_return_offset; 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: // 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: // Lmethod: method duke@435: // ??: invocation counter duke@435: // duke@435: void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { duke@435: // Update standard invocation counters duke@435: __ increment_invocation_counter(O0, G3_scratch); duke@435: if (ProfileInterpreter) { // %%% Merge this into methodDataOop duke@435: __ ld_ptr(STATE(_method), G3_scratch); duke@435: Address interpreter_invocation_counter(G3_scratch, 0, in_bytes(methodOopDesc::interpreter_invocation_counter_offset())); duke@435: __ ld(interpreter_invocation_counter, G3_scratch); duke@435: __ inc(G3_scratch); duke@435: __ st(G3_scratch, interpreter_invocation_counter); duke@435: } duke@435: duke@435: Address invocation_limit(G3_scratch, (address)&InvocationCounter::InterpreterInvocationLimit); duke@435: __ sethi(invocation_limit); duke@435: __ ld(invocation_limit, G3_scratch); duke@435: __ cmp(O0, G3_scratch); duke@435: __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow); duke@435: __ delayed()->nop(); duke@435: duke@435: } duke@435: duke@435: address InterpreterGenerator::generate_empty_entry(void) { duke@435: duke@435: // A method that does nothing but return... duke@435: duke@435: address entry = __ pc(); duke@435: Label slow_path; duke@435: duke@435: __ verify_oop(G5_method); duke@435: duke@435: // do nothing for empty methods (do not even increment invocation counter) duke@435: if ( UseFastEmptyMethods) { duke@435: // If we need a safepoint check, generate full interpreter entry. duke@435: Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); duke@435: __ load_contents(sync_state, G3_scratch); duke@435: __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, frame_manager_entry); duke@435: __ delayed()->nop(); duke@435: duke@435: // Code: _return duke@435: __ retl(); duke@435: __ delayed()->mov(O5_savedSP, SP); duke@435: return entry; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: // Call an accessor method (assuming it is resolved, otherwise drop into duke@435: // vanilla (slow path) entry duke@435: duke@435: // Generates code to elide accessor methods duke@435: // Uses G3_scratch and G1_scratch as scratch duke@435: address InterpreterGenerator::generate_accessor_entry(void) { duke@435: duke@435: // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; duke@435: // 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: address entry = __ pc(); duke@435: Label slow_path; duke@435: duke@435: if ( UseFastAccessorMethods) { duke@435: // Check if we need to reach a safepoint and generate full interpreter duke@435: // frame if so. duke@435: Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); duke@435: __ load_contents(sync_state, G3_scratch); duke@435: __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, slow_path); duke@435: __ delayed()->nop(); duke@435: duke@435: // Check if local 0 != NULL duke@435: __ ld_ptr(Gargs, G0, Otos_i ); // get local 0 duke@435: __ tst(Otos_i); // check if local 0 == NULL and go the slow path duke@435: __ brx(Assembler::zero, false, Assembler::pn, slow_path); duke@435: __ delayed()->nop(); duke@435: duke@435: duke@435: // read first instruction word and extract bytecode @ 1 and index @ 2 duke@435: // get first 4 bytes of the bytecodes (big endian!) duke@435: __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::const_offset())), G1_scratch); duke@435: __ ld(Address(G1_scratch, 0, in_bytes(constMethodOopDesc::codes_offset())), G1_scratch); duke@435: duke@435: // move index @ 2 far left then to the right most two bytes. duke@435: __ sll(G1_scratch, 2*BitsPerByte, G1_scratch); duke@435: __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words( duke@435: ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch); duke@435: duke@435: // get constant pool cache duke@435: __ ld_ptr(G5_method, in_bytes(methodOopDesc::constants_offset()), G3_scratch); duke@435: __ ld_ptr(G3_scratch, constantPoolOopDesc::cache_offset_in_bytes(), G3_scratch); duke@435: duke@435: // get specific constant pool cache entry duke@435: __ add(G3_scratch, G1_scratch, G3_scratch); duke@435: duke@435: // Check the constant Pool cache entry to see if it has been resolved. duke@435: // If not, need the slow path. duke@435: ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset(); duke@435: __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::indices_offset()), G1_scratch); duke@435: __ srl(G1_scratch, 2*BitsPerByte, G1_scratch); duke@435: __ and3(G1_scratch, 0xFF, G1_scratch); duke@435: __ cmp(G1_scratch, Bytecodes::_getfield); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, slow_path); duke@435: __ delayed()->nop(); duke@435: duke@435: // Get the type and return field offset from the constant pool cache duke@435: __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()), G1_scratch); duke@435: __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()), G3_scratch); duke@435: duke@435: Label xreturn_path; duke@435: // Need to differentiate between igetfield, agetfield, bgetfield etc. duke@435: // because they are different sizes. duke@435: // Get the type from the constant pool cache duke@435: __ srl(G1_scratch, ConstantPoolCacheEntry::tosBits, G1_scratch); duke@435: // Make sure we don't need to mask G1_scratch for tosBits after the above shift duke@435: ConstantPoolCacheEntry::verify_tosBits(); duke@435: __ cmp(G1_scratch, atos ); duke@435: __ br(Assembler::equal, true, Assembler::pt, xreturn_path); duke@435: __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i); duke@435: __ cmp(G1_scratch, itos); duke@435: __ br(Assembler::equal, true, Assembler::pt, xreturn_path); duke@435: __ delayed()->ld(Otos_i, G3_scratch, Otos_i); duke@435: __ cmp(G1_scratch, stos); duke@435: __ br(Assembler::equal, true, Assembler::pt, xreturn_path); duke@435: __ delayed()->ldsh(Otos_i, G3_scratch, Otos_i); duke@435: __ cmp(G1_scratch, ctos); duke@435: __ br(Assembler::equal, true, Assembler::pt, xreturn_path); duke@435: __ delayed()->lduh(Otos_i, G3_scratch, Otos_i); duke@435: #ifdef ASSERT duke@435: __ cmp(G1_scratch, btos); duke@435: __ br(Assembler::equal, true, Assembler::pt, xreturn_path); duke@435: __ delayed()->ldsb(Otos_i, G3_scratch, Otos_i); duke@435: __ should_not_reach_here(); duke@435: #endif duke@435: __ ldsb(Otos_i, G3_scratch, Otos_i); duke@435: __ bind(xreturn_path); duke@435: duke@435: // _ireturn/_areturn duke@435: __ retl(); // return from leaf routine duke@435: __ delayed()->mov(O5_savedSP, SP); duke@435: duke@435: // Generate regular method entry duke@435: __ bind(slow_path); duke@435: __ ba(false, fast_accessor_slow_entry_path); duke@435: __ delayed()->nop(); duke@435: return entry; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: // duke@435: // Interpreter stub for calling a native method. (C++ interpreter) duke@435: // This sets up a somewhat different looking stack for calling the native method duke@435: // than the typical interpreter frame setup. duke@435: // duke@435: duke@435: address InterpreterGenerator::generate_native_entry(bool synchronized) { duke@435: address entry = __ pc(); duke@435: duke@435: // the following temporary registers are used during frame creation duke@435: const Register Gtmp1 = G3_scratch ; duke@435: const Register Gtmp2 = G1_scratch; duke@435: const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); duke@435: duke@435: bool inc_counter = UseCompiler || CountCompiledCalls; duke@435: duke@435: // make sure registers are different! duke@435: assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2); duke@435: duke@435: const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); duke@435: duke@435: Label Lentry; duke@435: __ bind(Lentry); duke@435: duke@435: __ verify_oop(G5_method); duke@435: duke@435: const Register Glocals_size = G3; duke@435: assert_different_registers(Glocals_size, G4_scratch, Gframe_size); duke@435: duke@435: // make sure method is native & not abstract duke@435: // rethink these assertions - they can be simplified and shared (gri 2/25/2000) duke@435: #ifdef ASSERT duke@435: __ ld(access_flags, Gtmp1); duke@435: { duke@435: Label L; duke@435: __ btst(JVM_ACC_NATIVE, Gtmp1); duke@435: __ br(Assembler::notZero, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("tried to execute non-native method as native"); duke@435: __ bind(L); duke@435: } duke@435: { Label L; duke@435: __ btst(JVM_ACC_ABSTRACT, Gtmp1); duke@435: __ br(Assembler::zero, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("tried to execute abstract method as non-abstract"); duke@435: __ bind(L); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: __ lduh(size_of_parameters, Gtmp1); duke@435: __ sll(Gtmp1, LogBytesPerWord, Gtmp2); // parameter size in bytes duke@435: __ add(Gargs, Gtmp2, Gargs); // points to first local + BytesPerWord duke@435: // NEW duke@435: __ add(Gargs, -wordSize, Gargs); // points to first local[0] duke@435: // generate the code to allocate the interpreter stack frame duke@435: // NEW FRAME ALLOCATED HERE duke@435: // save callers original sp duke@435: // __ mov(SP, I5_savedSP->after_restore()); duke@435: duke@435: generate_compute_interpreter_state(Lstate, G0, true); duke@435: duke@435: // At this point Lstate points to new interpreter state duke@435: // duke@435: duke@435: const Address do_not_unlock_if_synchronized(G2_thread, 0, duke@435: in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 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. If any exception was thrown by duke@435: // runtime, exception handling i.e. unlock_if_synchronized_method will duke@435: // check this thread local flag. duke@435: // This flag has two effects, one is to force an unwind in the topmost duke@435: // interpreter frame and not perform an unlock while doing so. duke@435: duke@435: __ movbool(true, G3_scratch); duke@435: __ stbool(G3_scratch, do_not_unlock_if_synchronized); duke@435: duke@435: duke@435: // increment invocation counter and check for overflow duke@435: // duke@435: // Note: checking for negative value instead of overflow duke@435: // so we have a 'sticky' overflow test (may be of duke@435: // importance as soon as we have true MT/MP) 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: Label Lcontinue; duke@435: __ bind(Lcontinue); duke@435: duke@435: bang_stack_shadow_pages(true); duke@435: // reset the _do_not_unlock_if_synchronized flag duke@435: __ stbool(G0, do_not_unlock_if_synchronized); duke@435: duke@435: // check for synchronized methods duke@435: // Must happen AFTER invocation_counter check, so method is not locked duke@435: // if counter overflows. duke@435: duke@435: if (synchronized) { duke@435: lock_method(); duke@435: // Don't see how G2_thread is preserved here... duke@435: // __ verify_thread(); QQQ destroys L0,L1 can't use duke@435: } else { duke@435: #ifdef ASSERT duke@435: { Label ok; duke@435: __ ld_ptr(STATE(_method), G5_method); duke@435: __ ld(access_flags, O0); duke@435: __ btst(JVM_ACC_SYNCHRONIZED, O0); duke@435: __ br( Assembler::zero, false, Assembler::pt, ok); duke@435: __ delayed()->nop(); duke@435: __ stop("method needs synchronization"); duke@435: __ bind(ok); duke@435: } duke@435: #endif // ASSERT duke@435: } duke@435: duke@435: // start execution duke@435: duke@435: // __ verify_thread(); kills L1,L2 can't use at the moment duke@435: duke@435: // jvmti/jvmpi support duke@435: __ notify_method_entry(); duke@435: duke@435: // native call duke@435: duke@435: // (note that O0 is never an oop--at most it is a handle) duke@435: // It is important not to smash any handles created by this call, duke@435: // until any oop handle in O0 is dereferenced. duke@435: duke@435: // (note that the space for outgoing params is preallocated) duke@435: duke@435: // get signature handler duke@435: duke@435: Label pending_exception_present; duke@435: duke@435: { Label L; duke@435: __ ld_ptr(STATE(_method), G5_method); duke@435: __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::signature_handler_offset())), G3_scratch); duke@435: __ tst(G3_scratch); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), G5_method, false); duke@435: __ ld_ptr(STATE(_method), G5_method); duke@435: duke@435: Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset())); duke@435: __ ld_ptr(exception_addr, G3_scratch); duke@435: __ br_notnull(G3_scratch, false, Assembler::pn, pending_exception_present); duke@435: __ delayed()->nop(); duke@435: __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::signature_handler_offset())), G3_scratch); duke@435: __ bind(L); duke@435: } duke@435: duke@435: // Push a new frame so that the args will really be stored in duke@435: // Copy a few locals across so the new frame has the variables duke@435: // we need but these values will be dead at the jni call and duke@435: // therefore not gc volatile like the values in the current duke@435: // frame (Lstate in particular) duke@435: duke@435: // Flush the state pointer to the register save area duke@435: // Which is the only register we need for a stack walk. duke@435: __ st_ptr(Lstate, SP, (Lstate->sp_offset_in_saved_window() * wordSize) + STACK_BIAS); duke@435: duke@435: __ mov(Lstate, O1); // Need to pass the state pointer across the frame duke@435: duke@435: // Calculate current frame size duke@435: __ sub(SP, FP, O3); // Calculate negative of current frame size duke@435: __ save(SP, O3, SP); // Allocate an identical sized frame duke@435: duke@435: __ mov(I1, Lstate); // In the "natural" register. duke@435: duke@435: // Note I7 has leftover trash. Slow signature handler will fill it in duke@435: // should we get there. Normal jni call will set reasonable last_Java_pc duke@435: // below (and fix I7 so the stack trace doesn't have a meaningless frame duke@435: // in it). duke@435: duke@435: duke@435: // call signature handler duke@435: __ ld_ptr(STATE(_method), Lmethod); duke@435: __ ld_ptr(STATE(_locals), Llocals); duke@435: duke@435: __ callr(G3_scratch, 0); duke@435: __ delayed()->nop(); duke@435: __ ld_ptr(STATE(_thread), G2_thread); // restore thread (shouldn't be needed) duke@435: duke@435: { Label not_static; duke@435: duke@435: __ ld_ptr(STATE(_method), G5_method); duke@435: __ ld(access_flags, O0); duke@435: __ btst(JVM_ACC_STATIC, O0); duke@435: __ br( Assembler::zero, false, Assembler::pt, not_static); duke@435: __ delayed()-> duke@435: // get native function entry point(O0 is a good temp until the very end) duke@435: ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc::native_function_offset())), O0); duke@435: // for static methods insert the mirror argument duke@435: const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); duke@435: duke@435: __ ld_ptr(Address(G5_method, 0, in_bytes(methodOopDesc:: constants_offset())), O1); duke@435: __ ld_ptr(Address(O1, 0, constantPoolOopDesc::pool_holder_offset_in_bytes()), O1); duke@435: __ ld_ptr(O1, mirror_offset, O1); duke@435: // where the mirror handle body is allocated: duke@435: #ifdef ASSERT duke@435: if (!PrintSignatureHandlers) // do not dirty the output with this duke@435: { Label L; duke@435: __ tst(O1); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("mirror is missing"); duke@435: __ bind(L); duke@435: } duke@435: #endif // ASSERT duke@435: __ st_ptr(O1, STATE(_oop_temp)); duke@435: __ add(STATE(_oop_temp), O1); // this is really an LEA not an add duke@435: __ bind(not_static); duke@435: } duke@435: duke@435: // At this point, arguments have been copied off of stack into duke@435: // their JNI positions, which are O1..O5 and SP[68..]. duke@435: // Oops are boxed in-place on the stack, with handles copied to arguments. duke@435: // The result handler is in Lscratch. O0 will shortly hold the JNIEnv*. duke@435: duke@435: #ifdef ASSERT duke@435: { Label L; duke@435: __ tst(O0); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("native entry point is missing"); duke@435: __ bind(L); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // duke@435: // setup the java frame anchor duke@435: // duke@435: // The scavenge function only needs to know that the PC of this frame is duke@435: // in the interpreter method entry code, it doesn't need to know the exact duke@435: // PC and hence we can use O7 which points to the return address from the duke@435: // previous call in the code stream (signature handler function) duke@435: // duke@435: // The other trick is we set last_Java_sp to FP instead of the usual SP because duke@435: // we have pushed the extra frame in order to protect the volatile register(s) duke@435: // in that frame when we return from the jni call duke@435: // duke@435: duke@435: duke@435: __ set_last_Java_frame(FP, O7); duke@435: __ mov(O7, I7); // make dummy interpreter frame look like one above, duke@435: // not meaningless information that'll confuse me. duke@435: duke@435: // flush the windows now. We don't care about the current (protection) frame duke@435: // only the outer frames duke@435: duke@435: __ flush_windows(); duke@435: duke@435: // mark windows as flushed duke@435: Address flags(G2_thread, duke@435: 0, duke@435: in_bytes(JavaThread::frame_anchor_offset()) + in_bytes(JavaFrameAnchor::flags_offset())); duke@435: __ set(JavaFrameAnchor::flushed, G3_scratch); duke@435: __ st(G3_scratch, flags); duke@435: duke@435: // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready. duke@435: duke@435: Address thread_state(G2_thread, 0, in_bytes(JavaThread::thread_state_offset())); duke@435: #ifdef ASSERT duke@435: { Label L; duke@435: __ ld(thread_state, G3_scratch); duke@435: __ cmp(G3_scratch, _thread_in_Java); duke@435: __ br(Assembler::equal, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("Wrong thread state in native stub"); duke@435: __ bind(L); duke@435: } duke@435: #endif // ASSERT duke@435: __ set(_thread_in_native, G3_scratch); duke@435: __ st(G3_scratch, thread_state); duke@435: duke@435: // Call the jni method, using the delay slot to set the JNIEnv* argument. duke@435: __ callr(O0, 0); duke@435: __ delayed()-> duke@435: add(G2_thread, in_bytes(JavaThread::jni_environment_offset()), O0); duke@435: __ ld_ptr(STATE(_thread), G2_thread); // restore thread duke@435: duke@435: // must we block? duke@435: duke@435: // Block, if necessary, before resuming in _thread_in_Java state. duke@435: // In order for GC to work, don't clear the last_Java_sp until after blocking. duke@435: { Label no_block; duke@435: Address sync_state(G3_scratch, SafepointSynchronize::address_of_state()); duke@435: duke@435: // Switch thread to "native transition" state before reading the synchronization state. duke@435: // This additional state is necessary because reading and testing the synchronization duke@435: // state is not atomic w.r.t. GC, as this scenario demonstrates: duke@435: // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted. duke@435: // VM thread changes sync state to synchronizing and suspends threads for GC. duke@435: // Thread A is resumed to finish this native method, but doesn't block here since it duke@435: // didn't see any synchronization is progress, and escapes. duke@435: __ set(_thread_in_native_trans, G3_scratch); duke@435: __ st(G3_scratch, thread_state); 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(G2_thread, G1_scratch, G3_scratch); duke@435: } duke@435: __ load_contents(sync_state, G3_scratch); duke@435: __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized); duke@435: duke@435: duke@435: Label L; duke@435: Address suspend_state(G2_thread, 0, in_bytes(JavaThread::suspend_flags_offset())); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, L); duke@435: __ delayed()-> duke@435: ld(suspend_state, G3_scratch); duke@435: __ cmp(G3_scratch, 0); duke@435: __ br(Assembler::equal, false, Assembler::pt, no_block); duke@435: __ delayed()->nop(); duke@435: __ bind(L); duke@435: duke@435: // Block. Save any potential method result value before the operation and duke@435: // use a leaf call to leave the last_Java_frame setup undisturbed. duke@435: save_native_result(); duke@435: __ call_VM_leaf(noreg, duke@435: CAST_FROM_FN_PTR(address, JavaThread::check_safepoint_and_suspend_for_native_trans), duke@435: G2_thread); duke@435: __ ld_ptr(STATE(_thread), G2_thread); // restore thread duke@435: // Restore any method result value duke@435: restore_native_result(); duke@435: __ bind(no_block); duke@435: } duke@435: duke@435: // Clear the frame anchor now duke@435: duke@435: __ reset_last_Java_frame(); duke@435: duke@435: // Move the result handler address duke@435: __ mov(Lscratch, G3_scratch); duke@435: // return possible result to the outer frame duke@435: #ifndef __LP64 duke@435: __ mov(O0, I0); duke@435: __ restore(O1, G0, O1); duke@435: #else duke@435: __ restore(O0, G0, O0); duke@435: #endif /* __LP64 */ duke@435: duke@435: // Move result handler to expected register duke@435: __ mov(G3_scratch, Lscratch); duke@435: duke@435: duke@435: // thread state is thread_in_native_trans. Any safepoint blocking has duke@435: // happened in the trampoline we are ready to switch to thread_in_Java. duke@435: duke@435: __ set(_thread_in_Java, G3_scratch); duke@435: __ st(G3_scratch, thread_state); duke@435: duke@435: // If we have an oop result store it where it will be safe for any further gc duke@435: // until we return now that we've released the handle it might be protected by duke@435: duke@435: { duke@435: Label no_oop, store_result; duke@435: duke@435: __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch); duke@435: __ cmp(G3_scratch, Lscratch); duke@435: __ brx(Assembler::notEqual, false, Assembler::pt, no_oop); duke@435: __ delayed()->nop(); duke@435: __ addcc(G0, O0, O0); duke@435: __ brx(Assembler::notZero, true, Assembler::pt, store_result); // if result is not NULL: duke@435: __ delayed()->ld_ptr(O0, 0, O0); // unbox it duke@435: __ mov(G0, O0); duke@435: duke@435: __ bind(store_result); duke@435: // Store it where gc will look for it and result handler expects it. duke@435: __ st_ptr(O0, STATE(_oop_temp)); duke@435: duke@435: __ bind(no_oop); duke@435: duke@435: } duke@435: duke@435: // reset handle block duke@435: __ ld_ptr(G2_thread, in_bytes(JavaThread::active_handles_offset()), G3_scratch); duke@435: __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes()); duke@435: duke@435: duke@435: // handle exceptions (exception handling will handle unlocking!) duke@435: { Label L; duke@435: Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset())); duke@435: duke@435: __ ld_ptr(exception_addr, Gtemp); duke@435: __ tst(Gtemp); duke@435: __ brx(Assembler::equal, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ bind(pending_exception_present); duke@435: // With c++ interpreter we just leave it pending caller will do the correct thing. However... duke@435: // Like x86 we ignore the result of the native call and leave the method locked. This duke@435: // seems wrong to leave things locked. duke@435: duke@435: __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); duke@435: __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame duke@435: duke@435: __ bind(L); duke@435: } duke@435: duke@435: // jvmdi/jvmpi support (preserves thread register) duke@435: __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI); duke@435: duke@435: if (synchronized) { duke@435: // save and restore any potential method result value around the unlocking operation duke@435: save_native_result(); duke@435: duke@435: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; duke@435: // Get the initial monitor we allocated duke@435: __ sub(Lstate, entry_size, O1); // initial monitor duke@435: __ unlock_object(O1); duke@435: restore_native_result(); duke@435: } duke@435: duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: duke@435: // C2 expects long results in G1 we can't tell if we're returning to interpreted duke@435: // or compiled so just be safe. duke@435: duke@435: __ sllx(O0, 32, G1); // Shift bits into high G1 duke@435: __ srl (O1, 0, O1); // Zero extend O1 duke@435: __ or3 (O1, G1, G1); // OR 64 bits into G1 duke@435: duke@435: #endif /* COMPILER2 && !_LP64 */ duke@435: duke@435: #ifdef ASSERT duke@435: { duke@435: Label ok; duke@435: __ cmp(I5_savedSP, FP); duke@435: __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok); duke@435: __ delayed()->nop(); duke@435: __ stop("bad I5_savedSP value"); duke@435: __ should_not_reach_here(); duke@435: __ bind(ok); duke@435: } duke@435: #endif duke@435: // Calls result handler which POPS FRAME duke@435: if (TraceJumps) { duke@435: // Move target to register that is recordable duke@435: __ mov(Lscratch, G3_scratch); duke@435: __ JMP(G3_scratch, 0); duke@435: } else { duke@435: __ jmp(Lscratch, 0); duke@435: } duke@435: __ delayed()->nop(); duke@435: duke@435: if (inc_counter) { duke@435: // handle invocation counter overflow duke@435: __ bind(invocation_counter_overflow); duke@435: generate_counter_overflow(Lcontinue); duke@435: } duke@435: duke@435: duke@435: return entry; duke@435: } duke@435: duke@435: void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state, duke@435: const Register prev_state, duke@435: bool native) { duke@435: duke@435: // On entry duke@435: // G5_method - caller's method duke@435: // Gargs - points to initial parameters (i.e. locals[0]) duke@435: // G2_thread - valid? (C1 only??) duke@435: // "prev_state" - contains any previous frame manager state which we must save a link duke@435: // duke@435: // On return duke@435: // "state" is a pointer to the newly allocated state object. We must allocate and initialize duke@435: // a new interpretState object and the method expression stack. duke@435: duke@435: assert_different_registers(state, prev_state); duke@435: assert_different_registers(prev_state, G3_scratch); duke@435: const Register Gtmp = G3_scratch; duke@435: const Address constants (G5_method, 0, in_bytes(methodOopDesc::constants_offset())); duke@435: const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); duke@435: const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); duke@435: const Address max_stack (G5_method, 0, in_bytes(methodOopDesc::max_stack_offset())); duke@435: const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); duke@435: duke@435: // slop factor is two extra slots on the expression stack so that duke@435: // we always have room to store a result when returning from a call without parameters duke@435: // that returns a result. duke@435: duke@435: const int slop_factor = 2*wordSize; duke@435: duke@435: const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor? jrose@1145: //6815692//methodOopDesc::extra_stack_words() + // extra push slots for MH adapters duke@435: frame::memory_parameter_word_sp_offset + // register save area + param window duke@435: (native ? frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class duke@435: duke@435: // XXX G5_method valid duke@435: duke@435: // Now compute new frame size duke@435: duke@435: if (native) { duke@435: __ lduh( size_of_parameters, Gtmp ); duke@435: __ calc_mem_param_words(Gtmp, Gtmp); // space for native call parameters passed on the stack in words duke@435: } else { duke@435: __ lduh(max_stack, Gtmp); // Full size expression stack duke@435: } duke@435: __ add(Gtmp, fixed_size, Gtmp); // plus the fixed portion duke@435: duke@435: __ neg(Gtmp); // negative space for stack/parameters in words duke@435: __ and3(Gtmp, -WordsPerLong, Gtmp); // make multiple of 2 (SP must be 2-word aligned) duke@435: __ sll(Gtmp, LogBytesPerWord, Gtmp); // negative space for frame in bytes duke@435: duke@435: // Need to do stack size check here before we fault on large frames duke@435: duke@435: Label stack_ok; duke@435: duke@435: const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : duke@435: (StackRedPages+StackYellowPages); duke@435: duke@435: duke@435: __ ld_ptr(G2_thread, in_bytes(Thread::stack_base_offset()), O0); duke@435: __ ld_ptr(G2_thread, in_bytes(Thread::stack_size_offset()), O1); duke@435: // compute stack bottom duke@435: __ sub(O0, O1, O0); duke@435: duke@435: // Avoid touching the guard pages duke@435: // Also a fudge for frame size of BytecodeInterpreter::run duke@435: // It varies from 1k->4k depending on build type duke@435: const int fudge = 6 * K; duke@435: duke@435: __ set(fudge + (max_pages * os::vm_page_size()), O1); duke@435: duke@435: __ add(O0, O1, O0); duke@435: __ sub(O0, Gtmp, O0); duke@435: __ cmp(SP, O0); duke@435: __ brx(Assembler::greaterUnsigned, false, Assembler::pt, stack_ok); duke@435: __ delayed()->nop(); duke@435: duke@435: // throw exception return address becomes throwing pc duke@435: duke@435: __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); duke@435: __ stop("never reached"); duke@435: duke@435: __ bind(stack_ok); duke@435: duke@435: __ save(SP, Gtmp, SP); // setup new frame and register window duke@435: duke@435: // New window I7 call_stub or previous activation duke@435: // O6 - register save area, BytecodeInterpreter just below it, args/locals just above that duke@435: // duke@435: __ sub(FP, sizeof(BytecodeInterpreter), state); // Point to new Interpreter state duke@435: __ add(state, STACK_BIAS, state ); // Account for 64bit bias duke@435: duke@435: #define XXX_STATE(field_name) state, in_bytes(byte_offset_of(BytecodeInterpreter, field_name)) duke@435: duke@435: // Initialize a new Interpreter state duke@435: // orig_sp - caller's original sp duke@435: // G2_thread - thread duke@435: // Gargs - &locals[0] (unbiased?) duke@435: // G5_method - method duke@435: // SP (biased) - accounts for full size java stack, BytecodeInterpreter object, register save area, and register parameter save window duke@435: duke@435: duke@435: __ set(0xdead0004, O1); duke@435: duke@435: duke@435: __ st_ptr(Gargs, XXX_STATE(_locals)); duke@435: __ st_ptr(G0, XXX_STATE(_oop_temp)); duke@435: duke@435: __ st_ptr(state, XXX_STATE(_self_link)); // point to self duke@435: __ st_ptr(prev_state->after_save(), XXX_STATE(_prev_link)); // Chain interpreter states duke@435: __ st_ptr(G2_thread, XXX_STATE(_thread)); // Store javathread duke@435: duke@435: if (native) { duke@435: __ st_ptr(G0, XXX_STATE(_bcp)); duke@435: } else { duke@435: __ ld_ptr(G5_method, in_bytes(methodOopDesc::const_offset()), O2); // get constMethodOop duke@435: __ add(O2, in_bytes(constMethodOopDesc::codes_offset()), O2); // get bcp duke@435: __ st_ptr(O2, XXX_STATE(_bcp)); duke@435: } duke@435: duke@435: __ st_ptr(G0, XXX_STATE(_mdx)); duke@435: __ st_ptr(G5_method, XXX_STATE(_method)); duke@435: duke@435: __ set((int) BytecodeInterpreter::method_entry, O1); duke@435: __ st(O1, XXX_STATE(_msg)); duke@435: duke@435: __ ld_ptr(constants, O3); duke@435: __ ld_ptr(O3, constantPoolOopDesc::cache_offset_in_bytes(), O2); duke@435: __ st_ptr(O2, XXX_STATE(_constants)); duke@435: duke@435: __ st_ptr(G0, XXX_STATE(_result._to_call._callee)); duke@435: duke@435: // Monitor base is just start of BytecodeInterpreter object; duke@435: __ mov(state, O2); duke@435: __ st_ptr(O2, XXX_STATE(_monitor_base)); duke@435: duke@435: // Do we need a monitor for synchonized method? duke@435: { duke@435: __ ld(access_flags, O1); duke@435: Label done; duke@435: Label got_obj; duke@435: __ btst(JVM_ACC_SYNCHRONIZED, O1); duke@435: __ br( Assembler::zero, false, Assembler::pt, done); duke@435: duke@435: const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); duke@435: __ delayed()->btst(JVM_ACC_STATIC, O1); duke@435: __ ld_ptr(XXX_STATE(_locals), O1); duke@435: __ br( Assembler::zero, true, Assembler::pt, got_obj); duke@435: __ delayed()->ld_ptr(O1, 0, O1); // get receiver for not-static case duke@435: __ ld_ptr(constants, O1); duke@435: __ ld_ptr( O1, constantPoolOopDesc::pool_holder_offset_in_bytes(), O1); duke@435: // lock the mirror, not the klassOop duke@435: __ ld_ptr( O1, mirror_offset, O1); duke@435: duke@435: __ bind(got_obj); duke@435: duke@435: #ifdef ASSERT duke@435: __ tst(O1); duke@435: __ breakpoint_trap(Assembler::zero); duke@435: #endif // ASSERT duke@435: duke@435: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; duke@435: __ sub(SP, entry_size, SP); // account for initial monitor duke@435: __ sub(O2, entry_size, O2); // initial monitor duke@435: __ st_ptr(O1, O2, BasicObjectLock::obj_offset_in_bytes()); // and allocate it for interpreter use duke@435: __ bind(done); duke@435: } duke@435: duke@435: // Remember initial frame bottom duke@435: duke@435: __ st_ptr(SP, XXX_STATE(_frame_bottom)); duke@435: duke@435: __ st_ptr(O2, XXX_STATE(_stack_base)); duke@435: duke@435: __ sub(O2, wordSize, O2); // prepush duke@435: __ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH duke@435: duke@435: __ lduh(max_stack, O3); // Full size expression stack jrose@2639: guarantee(!EnableMethodHandles, "no support yet for java.lang.invoke.MethodHandle"); //6815692 jrose@1145: //6815692//if (EnableMethodHandles) jrose@1145: //6815692// __ inc(O3, methodOopDesc::extra_stack_entries()); duke@435: __ sll(O3, LogBytesPerWord, O3); duke@435: __ sub(O2, O3, O3); duke@435: // __ sub(O3, wordSize, O3); // so prepush doesn't look out of bounds duke@435: __ st_ptr(O3, XXX_STATE(_stack_limit)); duke@435: duke@435: if (!native) { duke@435: // duke@435: // Code to initialize locals duke@435: // duke@435: Register init_value = noreg; // will be G0 if we must clear locals duke@435: // Now zero locals duke@435: if (true /* zerolocals */ || ClearInterpreterLocals) { duke@435: // explicitly initialize locals duke@435: init_value = G0; duke@435: } else { duke@435: #ifdef ASSERT duke@435: // initialize locals to a garbage pattern for better debugging duke@435: init_value = O3; duke@435: __ set( 0x0F0F0F0F, init_value ); duke@435: #endif // ASSERT duke@435: } duke@435: if (init_value != noreg) { duke@435: Label clear_loop; duke@435: duke@435: // NOTE: If you change the frame layout, this code will need to duke@435: // be updated! duke@435: __ lduh( size_of_locals, O2 ); duke@435: __ lduh( size_of_parameters, O1 ); duke@435: __ sll( O2, LogBytesPerWord, O2); duke@435: __ sll( O1, LogBytesPerWord, O1 ); duke@435: __ ld_ptr(XXX_STATE(_locals), L2_scratch); duke@435: __ sub( L2_scratch, O2, O2 ); duke@435: __ sub( L2_scratch, O1, O1 ); duke@435: duke@435: __ bind( clear_loop ); duke@435: __ inc( O2, wordSize ); duke@435: duke@435: __ cmp( O2, O1 ); duke@435: __ br( Assembler::lessEqualUnsigned, true, Assembler::pt, clear_loop ); duke@435: __ delayed()->st_ptr( init_value, O2, 0 ); duke@435: } duke@435: } duke@435: } duke@435: // Find preallocated monitor and lock method (C++ interpreter) duke@435: // duke@435: void InterpreterGenerator::lock_method(void) { duke@435: // Lock the current method. duke@435: // Destroys registers L2_scratch, L3_scratch, O0 duke@435: // duke@435: // Find everything relative to Lstate duke@435: duke@435: #ifdef ASSERT duke@435: __ ld_ptr(STATE(_method), L2_scratch); duke@435: __ ld(L2_scratch, in_bytes(methodOopDesc::access_flags_offset()), O0); duke@435: duke@435: { Label ok; duke@435: __ btst(JVM_ACC_SYNCHRONIZED, O0); duke@435: __ br( Assembler::notZero, false, Assembler::pt, ok); duke@435: __ delayed()->nop(); duke@435: __ stop("method doesn't need synchronization"); duke@435: __ bind(ok); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // monitor is already allocated at stack base duke@435: // and the lockee is already present duke@435: __ ld_ptr(STATE(_stack_base), L2_scratch); duke@435: __ ld_ptr(L2_scratch, BasicObjectLock::obj_offset_in_bytes(), O0); // get object duke@435: __ lock_object(L2_scratch, O0); duke@435: duke@435: } duke@435: duke@435: // Generate code for handling resuming a deopted method duke@435: void CppInterpreterGenerator::generate_deopt_handling() { duke@435: duke@435: Label 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_atos = __ pc(); duke@435: duke@435: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_OBJECT), L3_scratch); // Result stub address array index 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: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_BOOLEAN), L3_scratch); // Result stub address array index 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: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_INT), L3_scratch); // Result stub address array index 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: #if !defined(_LP64) && defined(COMPILER2) duke@435: // All return values are where we want them, except for Longs. C2 returns duke@435: // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1. duke@435: // Since the interpreter will return longs in G1 and O0/O1 in the 32bit duke@435: // build even if we are returning from interpreted we just do a little duke@435: // stupid shuffing. duke@435: // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to duke@435: // do this here. Unfortunately if we did a rethrow we'd see an machepilog node duke@435: // first which would move g1 -> O0/O1 and destroy the exception we were throwing. duke@435: duke@435: __ srl (G1, 0,O1); duke@435: __ srlx(G1,32,O0); duke@435: #endif /* !_LP64 && COMPILER2 */ duke@435: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_LONG), L3_scratch); // Result stub address array index 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: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_FLOAT), L3_scratch); // Result stub address array index 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: // O0/O1 live duke@435: __ ba(false, return_from_deopt_common); duke@435: __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_DOUBLE), L3_scratch); // Result stub address array index 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: // O0/O1 live duke@435: __ set(AbstractInterpreter::BasicType_as_index(T_VOID), L3_scratch); duke@435: duke@435: // Deopt return common duke@435: // an index is present that lets us move any possible result being duke@435: // return to the interpreter's stack duke@435: // duke@435: __ bind(return_from_deopt_common); duke@435: duke@435: // Result if any is in native abi result (O0..O1/F0..F1). The java expression duke@435: // stack is in the state that the calling convention left it. duke@435: // Copy the result from native abi result and place it on java expression stack. duke@435: duke@435: // Current interpreter state is present in Lstate duke@435: duke@435: // Get current pre-pushed top of interpreter stack duke@435: // Any result (if any) is in native abi duke@435: // result type index is in L3_scratch duke@435: duke@435: __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack duke@435: duke@435: __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch); duke@435: __ sll(L3_scratch, LogBytesPerWord, L3_scratch); duke@435: __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address duke@435: __ jmpl(Lscratch, G0, O7); // and convert it duke@435: __ delayed()->nop(); duke@435: duke@435: // L1_scratch points to top of stack (prepushed) duke@435: __ st_ptr(L1_scratch, STATE(_stack)); 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: Label entry, loop; duke@435: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; duke@435: // 1. compute new pointers // esp: old expression stack top duke@435: __ delayed()->ld_ptr(STATE(_stack_base), L4_scratch); // current expression stack bottom duke@435: __ sub(L4_scratch, entry_size, L4_scratch); duke@435: __ st_ptr(L4_scratch, STATE(_stack_base)); duke@435: duke@435: __ sub(SP, entry_size, SP); // Grow stack duke@435: __ st_ptr(SP, STATE(_frame_bottom)); duke@435: duke@435: __ ld_ptr(STATE(_stack_limit), L2_scratch); duke@435: __ sub(L2_scratch, entry_size, L2_scratch); duke@435: __ st_ptr(L2_scratch, STATE(_stack_limit)); duke@435: duke@435: __ ld_ptr(STATE(_stack), L1_scratch); // Get current stack top duke@435: __ sub(L1_scratch, entry_size, L1_scratch); duke@435: __ st_ptr(L1_scratch, STATE(_stack)); duke@435: __ ba(false, entry); duke@435: __ delayed()->add(L1_scratch, wordSize, L1_scratch); // first real entry (undo prepush) duke@435: duke@435: // 2. move expression stack duke@435: duke@435: __ bind(loop); duke@435: __ st_ptr(L3_scratch, Address(L1_scratch, 0)); duke@435: __ add(L1_scratch, wordSize, L1_scratch); duke@435: __ bind(entry); duke@435: __ cmp(L1_scratch, L4_scratch); duke@435: __ br(Assembler::notEqual, false, Assembler::pt, loop); duke@435: __ delayed()->ld_ptr(L1_scratch, entry_size, L3_scratch); duke@435: duke@435: // now zero the slot so we can find it. sgoldman@558: __ st_ptr(G0, L4_scratch, BasicObjectLock::obj_offset_in_bytes()); 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: // ebx: methodOop duke@435: // ecx: receiver - unused (retrieved from stack as needed) duke@435: // esi: 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 ] <--- esp 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: #ifdef ASSERT duke@435: #define VALIDATE_STATE(scratch, marker) \ duke@435: { \ duke@435: Label skip; \ duke@435: __ ld_ptr(STATE(_self_link), scratch); \ duke@435: __ cmp(Lstate, scratch); \ duke@435: __ brx(Assembler::equal, false, Assembler::pt, skip); \ duke@435: __ delayed()->nop(); \ duke@435: __ breakpoint_trap(); \ duke@435: __ emit_long(marker); \ duke@435: __ bind(skip); \ duke@435: } duke@435: #else duke@435: #define VALIDATE_STATE(scratch, marker) duke@435: #endif /* ASSERT */ duke@435: duke@435: void CppInterpreterGenerator::adjust_callers_stack(Register args) { duke@435: // duke@435: // Adjust caller's stack so that all the locals can be contiguous with duke@435: // the parameters. duke@435: // Worries about stack overflow make this a pain. duke@435: // duke@435: // Destroys args, G3_scratch, G3_scratch duke@435: // In/Out O5_savedSP (sender's original SP) duke@435: // duke@435: // assert_different_registers(state, prev_state); duke@435: const Register Gtmp = G3_scratch; duke@435: const Register tmp = O2; duke@435: const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); duke@435: const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); duke@435: duke@435: __ lduh(size_of_parameters, tmp); duke@435: __ sll(tmp, LogBytesPerWord, Gtmp); // parameter size in bytes duke@435: __ add(args, Gtmp, Gargs); // points to first local + BytesPerWord duke@435: // NEW duke@435: __ add(Gargs, -wordSize, Gargs); // points to first local[0] duke@435: // determine extra space for non-argument locals & adjust caller's SP duke@435: // Gtmp1: parameter size in words duke@435: __ lduh(size_of_locals, Gtmp); duke@435: __ compute_extra_locals_size_in_bytes(tmp, Gtmp, Gtmp); duke@435: duke@435: #if 1 duke@435: // c2i adapters place the final interpreter argument in the register save area for O0/I0 duke@435: // the call_stub will place the final interpreter argument at duke@435: // frame::memory_parameter_word_sp_offset. This is mostly not noticable for either asm duke@435: // or c++ interpreter. However with the c++ interpreter when we do a recursive call duke@435: // and try to make it look good in the debugger we will store the argument to duke@435: // RecursiveInterpreterActivation in the register argument save area. Without allocating duke@435: // extra space for the compiler this will overwrite locals in the local array of the duke@435: // interpreter. duke@435: // QQQ still needed with frameless adapters??? duke@435: duke@435: const int c2i_adjust_words = frame::memory_parameter_word_sp_offset - frame::callee_register_argument_save_area_sp_offset; duke@435: duke@435: __ add(Gtmp, c2i_adjust_words*wordSize, Gtmp); duke@435: #endif // 1 duke@435: duke@435: duke@435: __ sub(SP, Gtmp, SP); // just caller's frame for the additional space we need. duke@435: } duke@435: duke@435: address InterpreterGenerator::generate_normal_entry(bool synchronized) { duke@435: duke@435: // G5_method: methodOop duke@435: // G2_thread: thread (unused) duke@435: // Gargs: bottom of args (sender_sp) duke@435: // O5: sender's sp 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) { duke@435: return interpreter_frame_manager; duke@435: } duke@435: duke@435: __ bind(frame_manager_entry); duke@435: duke@435: // the following temporary registers are used during frame creation duke@435: const Register Gtmp1 = G3_scratch; duke@435: // const Register Lmirror = L1; // native mirror (native calls only) duke@435: duke@435: const Address constants (G5_method, 0, in_bytes(methodOopDesc::constants_offset())); duke@435: const Address access_flags (G5_method, 0, in_bytes(methodOopDesc::access_flags_offset())); duke@435: const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset())); duke@435: const Address max_stack (G5_method, 0, in_bytes(methodOopDesc::max_stack_offset())); duke@435: const Address size_of_locals (G5_method, 0, in_bytes(methodOopDesc::size_of_locals_offset())); duke@435: duke@435: address entry_point = __ pc(); duke@435: __ mov(G0, prevState); // no current activation duke@435: duke@435: duke@435: Label re_dispatch; duke@435: duke@435: __ bind(re_dispatch); duke@435: duke@435: // Interpreter needs to have locals completely contiguous. In order to do that duke@435: // We must adjust the caller's stack pointer for any locals beyond just the duke@435: // parameters duke@435: adjust_callers_stack(Gargs); duke@435: duke@435: // O5_savedSP still contains sender's sp duke@435: duke@435: // NEW FRAME duke@435: duke@435: generate_compute_interpreter_state(Lstate, prevState, false); duke@435: duke@435: // At this point a new interpreter frame and state object are created and initialized duke@435: // Lstate has the pointer to the new activation duke@435: // Any stack banging or limit check should already be done. duke@435: duke@435: Label call_interpreter; duke@435: duke@435: __ bind(call_interpreter); duke@435: duke@435: duke@435: #if 1 duke@435: __ set(0xdead002, Lmirror); duke@435: __ set(0xdead002, L2_scratch); duke@435: __ set(0xdead003, L3_scratch); duke@435: __ set(0xdead004, L4_scratch); duke@435: __ set(0xdead005, Lscratch); duke@435: __ set(0xdead006, Lscratch2); duke@435: __ set(0xdead007, L7_scratch); duke@435: duke@435: __ set(0xdeaf002, O2); duke@435: __ set(0xdeaf003, O3); duke@435: __ set(0xdeaf004, O4); duke@435: __ set(0xdeaf005, O5); duke@435: #endif duke@435: duke@435: // Call interpreter (stack bang complete) 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: #ifdef ASSERT duke@435: { duke@435: Label skip; duke@435: __ ld_ptr(STATE(_frame_bottom), G3_scratch); duke@435: __ cmp(G3_scratch, SP); duke@435: __ brx(Assembler::equal, false, Assembler::pt, skip); duke@435: __ delayed()->nop(); duke@435: __ stop("SP not restored to frame bottom"); duke@435: __ bind(skip); duke@435: } duke@435: #endif duke@435: duke@435: VALIDATE_STATE(G3_scratch, 4); duke@435: __ set_last_Java_frame(SP, noreg); duke@435: __ mov(Lstate, O0); // (arg) pointer to current state duke@435: duke@435: __ call(CAST_FROM_FN_PTR(address, duke@435: JvmtiExport::can_post_interpreter_events() ? duke@435: BytecodeInterpreter::runWithChecks duke@435: : BytecodeInterpreter::run), duke@435: relocInfo::runtime_call_type); duke@435: duke@435: __ delayed()->nop(); duke@435: duke@435: __ ld_ptr(STATE(_thread), G2_thread); duke@435: __ reset_last_Java_frame(); duke@435: duke@435: // examine msg from interpreter to determine next action duke@435: __ ld_ptr(STATE(_thread), G2_thread); // restore G2_thread duke@435: duke@435: __ ld(STATE(_msg), L1_scratch); // 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 do_OSR; duke@435: Label bad_msg; duke@435: Label resume_interpreter; duke@435: duke@435: __ cmp(L1_scratch, (int)BytecodeInterpreter::call_method); duke@435: __ br(Assembler::equal, false, Assembler::pt, call_method); duke@435: __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::return_from_method); duke@435: __ br(Assembler::equal, false, Assembler::pt, return_from_interpreted_method); duke@435: __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::throwing_exception); duke@435: __ br(Assembler::equal, false, Assembler::pt, throw_exception); duke@435: __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::do_osr); duke@435: __ br(Assembler::equal, false, Assembler::pt, do_OSR); duke@435: __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::more_monitors); duke@435: __ br(Assembler::notEqual, false, Assembler::pt, bad_msg); duke@435: duke@435: // Allocate more monitor space, shuffle expression stack.... duke@435: duke@435: generate_more_monitors(); duke@435: duke@435: // new monitor slot allocated, resume the interpreter. duke@435: duke@435: __ set((int)BytecodeInterpreter::got_monitors, L1_scratch); duke@435: VALIDATE_STATE(G3_scratch, 5); duke@435: __ ba(false, call_interpreter); duke@435: __ delayed()->st(L1_scratch, STATE(_msg)); 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: // QQQ what message do we send duke@435: duke@435: __ ba(false, call_interpreter); duke@435: __ delayed()->ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame 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: generate_deopt_handling(); duke@435: duke@435: // ready to resume the interpreter duke@435: duke@435: __ set((int)BytecodeInterpreter::deopt_resume, L1_scratch); duke@435: __ ba(false, call_interpreter); duke@435: __ delayed()->st(L1_scratch, STATE(_msg)); 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: duke@435: Label return_with_exception; duke@435: Label unwind_and_forward; duke@435: duke@435: // O0: exception duke@435: // O7: throwing pc duke@435: duke@435: // We want exception in the thread no matter what we ultimately decide about frame type. duke@435: duke@435: Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset())); duke@435: __ verify_thread(); duke@435: __ st_ptr(O0, exception_addr); duke@435: duke@435: // get the methodOop duke@435: __ ld_ptr(STATE(_method), G5_method); duke@435: duke@435: // if this current frame vanilla or native? duke@435: duke@435: __ ld(access_flags, Gtmp1); duke@435: __ btst(JVM_ACC_NATIVE, Gtmp1); duke@435: __ br(Assembler::zero, false, Assembler::pt, return_with_exception); // vanilla interpreted frame handle directly duke@435: __ delayed()->nop(); 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 frame and jump to forward exception. unwinding will place throwing pc in O7 duke@435: // as expected by forward_exception. duke@435: duke@435: __ restore(FP, G0, SP); // unwind interpreter state frame duke@435: __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); duke@435: __ delayed()->mov(I5_savedSP->after_restore(), SP); 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: address return_from_native_method = __ pc(); duke@435: duke@435: VALIDATE_STATE(G3_scratch, 6); duke@435: duke@435: // Result if any is in native abi result (O0..O1/F0..F1). The java expression duke@435: // stack is in the state that the calling convention left it. duke@435: // Copy the result from native abi result and place it on java expression stack. duke@435: duke@435: // Current interpreter state is present in Lstate duke@435: duke@435: // Exception pending? duke@435: duke@435: __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame duke@435: __ ld_ptr(exception_addr, Lscratch); // get any pending exception duke@435: __ tst(Lscratch); // exception pending? duke@435: __ brx(Assembler::notZero, false, Assembler::pt, return_with_exception); duke@435: __ delayed()->nop(); duke@435: duke@435: // Process the native abi result to java expression stack duke@435: duke@435: __ ld_ptr(STATE(_result._to_call._callee), L4_scratch); // called method duke@435: __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack duke@435: __ lduh(L4_scratch, in_bytes(methodOopDesc::size_of_parameters_offset()), L2_scratch); // get parameter size duke@435: __ sll(L2_scratch, LogBytesPerWord, L2_scratch ); // parameter size in bytes duke@435: __ add(L1_scratch, L2_scratch, L1_scratch); // stack destination for result sgoldman@558: __ ld(L4_scratch, in_bytes(methodOopDesc::result_index_offset()), L3_scratch); // called method result type index duke@435: duke@435: // tosca is really just native abi duke@435: __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch); duke@435: __ sll(L3_scratch, LogBytesPerWord, L3_scratch); duke@435: __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address duke@435: __ jmpl(Lscratch, G0, O7); // and convert it duke@435: __ delayed()->nop(); duke@435: duke@435: // L1_scratch points to top of stack (prepushed) duke@435: duke@435: __ ba(false, resume_interpreter); duke@435: __ delayed()->mov(L1_scratch, O1); 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: __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame duke@435: __ ld_ptr(STATE(_stack_base), O1); // empty java expression stack duke@435: __ ba(false, resume_interpreter); duke@435: __ delayed()->sub(O1, wordSize, O1); // account for prepush 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: VALIDATE_STATE(G3_scratch, 7); duke@435: duke@435: Label return_to_initial_caller; duke@435: duke@435: // Interpreted result is on the top of the completed activation expression stack. duke@435: // We must return it to the top of the callers stack if caller was interpreted duke@435: // otherwise we convert to native abi result and return to call_stub/c1/c2 duke@435: // The caller's expression stack was truncated by the call however the current activation duke@435: // has enough stuff on the stack that we have usable space there no matter what. The duke@435: // other thing that makes it easy is that the top of the caller's stack is stored in STATE(_locals) duke@435: // for the current activation duke@435: duke@435: __ ld_ptr(STATE(_prev_link), L1_scratch); duke@435: __ ld_ptr(STATE(_method), L2_scratch); // get method just executed sgoldman@558: __ ld(L2_scratch, in_bytes(methodOopDesc::result_index_offset()), L2_scratch); duke@435: __ tst(L1_scratch); duke@435: __ brx(Assembler::zero, false, Assembler::pt, return_to_initial_caller); duke@435: __ delayed()->sll(L2_scratch, LogBytesPerWord, L2_scratch); duke@435: duke@435: // Copy result to callers java stack duke@435: duke@435: __ set((intptr_t)CppInterpreter::_stack_to_stack, L4_scratch); duke@435: __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address duke@435: __ ld_ptr(STATE(_stack), O0); // current top (prepushed) duke@435: __ ld_ptr(STATE(_locals), O1); // stack destination duke@435: duke@435: // O0 - will be source, O1 - will be destination (preserved) duke@435: __ jmpl(Lscratch, G0, O7); // and convert it duke@435: __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack) duke@435: duke@435: // O1 == &locals[0] duke@435: duke@435: // Result is now on caller's stack. Just unwind current activation and resume duke@435: duke@435: Label unwind_recursive_activation; duke@435: duke@435: duke@435: __ bind(unwind_recursive_activation); duke@435: duke@435: // O1 == &locals[0] (really callers stacktop) for activation now returning duke@435: // returning to interpreter method from "recursive" interpreter call duke@435: // result converter left O1 pointing to top of the( prepushed) 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: duke@435: // Must restore stack duke@435: VALIDATE_STATE(G3_scratch, 8); duke@435: duke@435: // Return to interpreter method after a method call (interpreted/native/c1/c2) has completed. duke@435: // Result if any is already on the caller's stack. All we must do now is remove the now dead duke@435: // frame and tell interpreter to resume. duke@435: duke@435: duke@435: __ mov(O1, I1); // pass back new stack top across activation duke@435: // POP FRAME HERE ================================== duke@435: __ restore(FP, G0, SP); // unwind interpreter state frame duke@435: __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame duke@435: duke@435: duke@435: // Resume the interpreter. The current frame contains the current interpreter duke@435: // state object. duke@435: // duke@435: // O1 == new java stack pointer duke@435: duke@435: __ bind(resume_interpreter); duke@435: VALIDATE_STATE(G3_scratch, 10); duke@435: duke@435: // A frame we have already used before so no need to bang stack so use call_interpreter_2 entry duke@435: duke@435: __ set((int)BytecodeInterpreter::method_resume, L1_scratch); duke@435: __ st(L1_scratch, STATE(_msg)); duke@435: __ ba(false, call_interpreter_2); duke@435: __ delayed()->st_ptr(O1, STATE(_stack)); duke@435: 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: // This can either be an entry via call_stub/c1/c2 or a recursive interpreter call duke@435: // we need to do a little register fixup here once we distinguish the two of them duke@435: if (UseFastAccessorMethods && !synchronized) { duke@435: // Call stub_return address still in O7 duke@435: __ bind(fast_accessor_slow_entry_path); duke@435: __ set((intptr_t)return_from_native_method - 8, Gtmp1); duke@435: __ cmp(Gtmp1, O7); // returning to interpreter? duke@435: __ brx(Assembler::equal, true, Assembler::pt, re_dispatch); // yep duke@435: __ delayed()->nop(); duke@435: __ ba(false, re_dispatch); duke@435: __ delayed()->mov(G0, prevState); // initial entry duke@435: duke@435: } duke@435: duke@435: // interpreter returning to native code (call_stub/c1/c2) duke@435: // convert result and unwind initial activation duke@435: // L2_scratch - scaled result type index duke@435: duke@435: __ bind(return_to_initial_caller); duke@435: duke@435: __ set((intptr_t)CppInterpreter::_stack_to_native_abi, L4_scratch); duke@435: __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address duke@435: __ ld_ptr(STATE(_stack), O0); // current top (prepushed) duke@435: __ jmpl(Lscratch, G0, O7); // and convert it duke@435: __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack) 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 I0..I1/(F0/..F1) duke@435: // we can return here with an exception that wasn't handled by interpreted code duke@435: // how does c1/c2 see it on return? duke@435: duke@435: // compute resulting sp before/after args popped depending upon calling convention duke@435: // __ ld_ptr(STATE(_saved_sp), Gtmp1); duke@435: // duke@435: // POP FRAME HERE ================================== duke@435: __ restore(FP, G0, SP); duke@435: __ retl(); duke@435: __ delayed()->mov(I5_savedSP->after_restore(), SP); duke@435: duke@435: // OSR request, unwind the current frame and transfer to the OSR entry duke@435: // and enter OSR nmethod duke@435: duke@435: __ bind(do_OSR); duke@435: Label remove_initial_frame; duke@435: __ ld_ptr(STATE(_prev_link), L1_scratch); duke@435: __ ld_ptr(STATE(_result._osr._osr_buf), G1_scratch); 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: __ tst(L1_scratch); duke@435: __ brx(Assembler::zero, false, Assembler::pt, remove_initial_frame); duke@435: __ delayed()->ld_ptr(STATE(_result._osr._osr_entry), G3_scratch); duke@435: duke@435: // Frame underneath is an interpreter frame simply unwind duke@435: // POP FRAME HERE ================================== duke@435: __ restore(FP, G0, SP); // unwind interpreter state frame duke@435: __ mov(I5_savedSP->after_restore(), SP); duke@435: duke@435: // Since we are now calling native need to change our "return address" from the duke@435: // dummy RecursiveInterpreterActivation to a return from native duke@435: duke@435: __ set((intptr_t)return_from_native_method - 8, O7); duke@435: duke@435: __ jmpl(G3_scratch, G0, G0); duke@435: __ delayed()->mov(G1_scratch, O0); duke@435: duke@435: __ bind(remove_initial_frame); duke@435: duke@435: // POP FRAME HERE ================================== duke@435: __ restore(FP, G0, SP); duke@435: __ mov(I5_savedSP->after_restore(), SP); duke@435: __ jmpl(G3_scratch, G0, G0); duke@435: __ delayed()->mov(G1_scratch, O0); 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: // At this point we have a topmost frame that was allocated by the frame manager duke@435: // which contains the current method interpreted state. We trim this frame duke@435: // of excess java expression stack entries and then recurse. 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: duke@435: __ ld_ptr(STATE(_thread), G2_thread); duke@435: __ ld_ptr(STATE(_result._to_call._callee), G5_method); duke@435: duke@435: duke@435: // SP already takes in to account the 2 extra words we use for slop duke@435: // when we call a "static long no_params()" method. So if duke@435: // we trim back sp by the amount of unused java expression stack duke@435: // there will be automagically the 2 extra words we need. duke@435: // We also have to worry about keeping SP aligned. duke@435: duke@435: __ ld_ptr(STATE(_stack), Gargs); duke@435: __ ld_ptr(STATE(_stack_limit), L1_scratch); duke@435: duke@435: // compute the unused java stack size duke@435: __ sub(Gargs, L1_scratch, L2_scratch); // compute unused space duke@435: sgoldman@558: // Round down the unused space to that stack is always 16-byte aligned sgoldman@558: // by making the unused space a multiple of the size of two longs. duke@435: sgoldman@558: __ and3(L2_scratch, -2*BytesPerLong, L2_scratch); duke@435: duke@435: // Now trim the stack duke@435: __ add(SP, L2_scratch, SP); duke@435: duke@435: duke@435: // Now point to the final argument (account for prepush) duke@435: __ add(Gargs, wordSize, Gargs); duke@435: #ifdef ASSERT duke@435: // Make sure we have space for the window duke@435: __ sub(Gargs, SP, L1_scratch); duke@435: __ cmp(L1_scratch, 16*wordSize); duke@435: { duke@435: Label skip; duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, skip); duke@435: __ delayed()->nop(); duke@435: __ stop("killed stack"); duke@435: __ bind(skip); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // Create a new frame where we can store values that make it look like the interpreter duke@435: // really recursed. duke@435: duke@435: // prepare to recurse or call specialized entry duke@435: duke@435: // First link the registers we need duke@435: duke@435: // make the pc look good in debugger duke@435: __ set(CAST_FROM_FN_PTR(intptr_t, RecursiveInterpreterActivation), O7); duke@435: // argument too duke@435: __ mov(Lstate, I0); duke@435: duke@435: // Record our sending SP duke@435: __ mov(SP, O5_savedSP); duke@435: duke@435: __ ld_ptr(STATE(_result._to_call._callee_entry_point), L2_scratch); duke@435: __ set((intptr_t) entry_point, L1_scratch); duke@435: __ cmp(L1_scratch, L2_scratch); duke@435: __ brx(Assembler::equal, false, Assembler::pt, re_dispatch); duke@435: __ delayed()->mov(Lstate, prevState); // link activations 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: __ set((intptr_t)return_from_native_method - 8, O7); duke@435: __ jmpl(L2_scratch, G0, G0); // Do specialized entry duke@435: __ delayed()->nop(); duke@435: duke@435: // duke@435: // Bad Message from interpreter 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: __ bind(throw_exception); duke@435: __ ld_ptr(STATE(_prev_link), L1_scratch); duke@435: __ tst(L1_scratch); duke@435: __ brx(Assembler::zero, false, Assembler::pt, unwind_and_forward); duke@435: __ delayed()->nop(); duke@435: duke@435: __ ld_ptr(STATE(_locals), O1); // get result of popping callee's args duke@435: __ ba(false, unwind_recursive_activation); duke@435: __ delayed()->nop(); duke@435: duke@435: interpreter_frame_manager = entry_point; duke@435: return entry_point; 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: duke@435: static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) { duke@435: duke@435: // Figure out the size of an interpreter frame (in words) given that we have a fully allocated duke@435: // expression stack, the callee will have callee_extra_locals (so we can account for duke@435: // frame extension) and monitor_size for monitors. Basically we need to calculate duke@435: // this exactly like generate_fixed_frame/generate_compute_interpreter_state. duke@435: // duke@435: // duke@435: // The big complicating thing here is that we must ensure that the stack stays properly duke@435: // aligned. This would be even uglier if monitor size wasn't modulo what the stack duke@435: // needs to be aligned for). We are given that the sp (fp) is already aligned by duke@435: // the caller so we must ensure that it is properly aligned for our callee. duke@435: // duke@435: // Ths c++ interpreter always makes sure that we have a enough extra space on the duke@435: // stack at all times to deal with the "stack long no_params()" method issue. This duke@435: // is "slop_factor" here. duke@435: const int slop_factor = 2; duke@435: duke@435: const int fixed_size = sizeof(BytecodeInterpreter)/wordSize + // interpreter state object duke@435: frame::memory_parameter_word_sp_offset; // register save area + param window jrose@1145: const int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries(); duke@435: return (round_to(max_stack + jrose@1145: extra_stack + duke@435: slop_factor + duke@435: fixed_size + duke@435: monitor_size + duke@435: (callee_extra_locals * Interpreter::stackElementWords()), WordsPerLong)); duke@435: duke@435: } duke@435: duke@435: int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { duke@435: duke@435: // See call_stub code duke@435: int call_stub_size = round_to(7 + frame::memory_parameter_word_sp_offset, duke@435: WordsPerLong); // 7 + register save area duke@435: 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: return size_activation_helper(method->max_locals(), method->max_stack(), duke@435: monitor_size) + call_stub_size; 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: // Fill in the registers for the frame duke@435: duke@435: // Need to install _sender_sp. Actually not too hard in C++! duke@435: // When the skeletal frames are layed out we fill in a value duke@435: // for _sender_sp. That value is only correct for the oldest duke@435: // skeletal frame constructed (because there is only a single duke@435: // entry for "caller_adjustment". While the skeletal frames duke@435: // exist that is good enough. We correct that calculation duke@435: // here and get all the frames correct. duke@435: duke@435: // to_fill->_sender_sp = locals - (method->size_of_parameters() - 1); duke@435: duke@435: *current->register_addr(Lstate) = (intptr_t) to_fill; duke@435: // skeletal already places a useful value here and this doesn't account duke@435: // for alignment so don't bother. duke@435: // *current->register_addr(I5_savedSP) = (intptr_t) locals - (method->size_of_parameters() - 1); 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: // 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. jrose@1145: int extra_stack = 0; //6815692//methodOopDesc::extra_stack_entries(); jrose@1145: to_fill->_stack_limit = stack_base - (method->max_stack() + 1 + extra_stack); duke@435: to_fill->_monitor_base = (BasicObjectLock*) monitor_base; duke@435: duke@435: // sparc specific duke@435: to_fill->_frame_bottom = frame_bottom; duke@435: to_fill->_self_link = to_fill; duke@435: #ifdef ASSERT duke@435: to_fill->_native_fresult = 123456.789; duke@435: to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe); duke@435: #endif duke@435: } duke@435: duke@435: void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) { duke@435: istate->_last_Java_pc = (intptr_t*) last_Java_pc; duke@435: } duke@435: duke@435: duke@435: int AbstractInterpreter::layout_activation(methodOop method, duke@435: int tempcount, // Number of slots on java expression stack in use duke@435: int popframe_extra_args, duke@435: int moncount, // Number of active monitors duke@435: int callee_param_size, duke@435: int callee_locals_size, duke@435: frame* caller, duke@435: frame* interpreter_frame, duke@435: bool is_top_frame) { duke@435: duke@435: assert(popframe_extra_args == 0, "NEED TO FIX"); 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_size - callee_param_size; duke@435: int monitor_size = (sizeof(BasicObjectLock) * moncount) / wordSize; duke@435: int full_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size); duke@435: int short_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size); duke@435: int frame_words = is_top_frame ? full_frame_words : short_frame_words; duke@435: duke@435: duke@435: /* duke@435: if we actually have a frame to layout we must now fill in all the pieces. This means both duke@435: the interpreterState and the registers. duke@435: */ duke@435: if (interpreter_frame != NULL) { duke@435: duke@435: // MUCHO HACK duke@435: duke@435: intptr_t* frame_bottom = interpreter_frame->sp() - (full_frame_words - frame_words); sgoldman@558: // 'interpreter_frame->sp()' is unbiased while 'frame_bottom' must be a biased value in 64bit mode. sgoldman@558: assert(((intptr_t)frame_bottom & 0xf) == 0, "SP biased in layout_activation"); sgoldman@558: frame_bottom = (intptr_t*)((intptr_t)frame_bottom - STACK_BIAS); duke@435: duke@435: /* Now fillin the interpreterState object */ duke@435: duke@435: interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter)); duke@435: duke@435: duke@435: intptr_t* locals; duke@435: duke@435: // Calculate the postion of locals[0]. This is painful because of duke@435: // stack alignment (same as ia64). The problem is that we can duke@435: // not compute the location of locals from fp(). fp() will account duke@435: // for the extra locals but it also accounts for aligning the stack duke@435: // and we can't determine if the locals[0] was misaligned but max_locals duke@435: // was enough to have the duke@435: // calculate postion of locals. fp already accounts for extra locals. duke@435: // +2 for the static long no_params() issue. 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: } else { duke@435: // Lay out locals block in the caller adjacent to the register window save area. duke@435: // duke@435: // Compiled frames do not allocate a varargs area which is why this if duke@435: // statement is needed. duke@435: // duke@435: intptr_t* fp = interpreter_frame->fp(); duke@435: int local_words = method->max_locals() * Interpreter::stackElementWords(); duke@435: duke@435: if (caller->is_compiled_frame()) { duke@435: locals = fp + frame::register_save_words + local_words - 1; duke@435: } else { duke@435: locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1; duke@435: } duke@435: duke@435: } duke@435: // END MUCHO HACK duke@435: duke@435: intptr_t* monitor_base = (intptr_t*) cur_state; duke@435: intptr_t* stack_base = monitor_base - monitor_size; duke@435: /* +1 because stack is always prepushed */ duke@435: intptr_t* stack = stack_base - (tempcount + 1); 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: } duke@435: return frame_words; duke@435: } duke@435: duke@435: #endif // CC_INTERP