duke@435: /* never@1609: * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_interpreter_sparc.cpp.incl" duke@435: duke@435: duke@435: duke@435: // Generation of Interpreter duke@435: // duke@435: // The InterpreterGenerator generates the interpreter into Interpreter::_code. duke@435: duke@435: duke@435: #define __ _masm-> duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: duke@435: duke@435: duke@435: duke@435: int AbstractInterpreter::BasicType_as_index(BasicType type) { duke@435: int i = 0; duke@435: switch (type) { duke@435: case T_BOOLEAN: i = 0; break; duke@435: case T_CHAR : i = 1; break; duke@435: case T_BYTE : i = 2; break; duke@435: case T_SHORT : i = 3; break; duke@435: case T_INT : i = 4; break; duke@435: case T_LONG : i = 5; break; duke@435: case T_VOID : i = 6; break; duke@435: case T_FLOAT : i = 7; break; duke@435: case T_DOUBLE : i = 8; break; duke@435: case T_OBJECT : i = 9; break; duke@435: case T_ARRAY : i = 9; break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds"); duke@435: return i; duke@435: } duke@435: duke@435: duke@435: #ifndef _LP64 duke@435: address AbstractInterpreterGenerator::generate_slow_signature_handler() { duke@435: address entry = __ pc(); duke@435: Argument argv(0, true); duke@435: duke@435: // We are in the jni transition frame. Save the last_java_frame corresponding to the duke@435: // outer interpreter frame duke@435: // duke@435: __ set_last_Java_frame(FP, noreg); duke@435: // make sure the interpreter frame we've pushed has a valid return pc duke@435: __ mov(O7, I7); duke@435: __ mov(Lmethod, G3_scratch); duke@435: __ mov(Llocals, G4_scratch); duke@435: __ save_frame(0); duke@435: __ mov(G2_thread, L7_thread_cache); duke@435: __ add(argv.address_in_frame(), O3); duke@435: __ mov(G2_thread, O0); duke@435: __ mov(G3_scratch, O1); duke@435: __ call(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), relocInfo::runtime_call_type); duke@435: __ delayed()->mov(G4_scratch, O2); duke@435: __ mov(L7_thread_cache, G2_thread); duke@435: __ reset_last_Java_frame(); duke@435: duke@435: // load the register arguments (the C code packed them as varargs) duke@435: for (Argument ldarg = argv.successor(); ldarg.is_register(); ldarg = ldarg.successor()) { duke@435: __ ld_ptr(ldarg.address_in_frame(), ldarg.as_register()); duke@435: } duke@435: __ ret(); duke@435: __ delayed()-> duke@435: restore(O0, 0, Lscratch); // caller's Lscratch gets the result handler duke@435: return entry; duke@435: } duke@435: duke@435: duke@435: #else duke@435: // LP64 passes floating point arguments in F1, F3, F5, etc. instead of duke@435: // O0, O1, O2 etc.. duke@435: // Doubles are passed in D0, D2, D4 duke@435: // We store the signature of the first 16 arguments in the first argument duke@435: // slot because it will be overwritten prior to calling the native duke@435: // function, with the pointer to the JNIEnv. duke@435: // If LP64 there can be up to 16 floating point arguments in registers duke@435: // or 6 integer registers. duke@435: address AbstractInterpreterGenerator::generate_slow_signature_handler() { duke@435: duke@435: enum { duke@435: non_float = 0, duke@435: float_sig = 1, duke@435: double_sig = 2, duke@435: sig_mask = 3 duke@435: }; duke@435: duke@435: address entry = __ pc(); duke@435: Argument argv(0, true); duke@435: duke@435: // We are in the jni transition frame. Save the last_java_frame corresponding to the duke@435: // outer interpreter frame duke@435: // duke@435: __ set_last_Java_frame(FP, noreg); duke@435: // make sure the interpreter frame we've pushed has a valid return pc duke@435: __ mov(O7, I7); duke@435: __ mov(Lmethod, G3_scratch); duke@435: __ mov(Llocals, G4_scratch); duke@435: __ save_frame(0); duke@435: __ mov(G2_thread, L7_thread_cache); duke@435: __ add(argv.address_in_frame(), O3); duke@435: __ mov(G2_thread, O0); duke@435: __ mov(G3_scratch, O1); duke@435: __ call(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), relocInfo::runtime_call_type); duke@435: __ delayed()->mov(G4_scratch, O2); duke@435: __ mov(L7_thread_cache, G2_thread); duke@435: __ reset_last_Java_frame(); duke@435: duke@435: duke@435: // load the register arguments (the C code packed them as varargs) duke@435: Address Sig = argv.address_in_frame(); // Argument 0 holds the signature duke@435: __ ld_ptr( Sig, G3_scratch ); // Get register argument signature word into G3_scratch duke@435: __ mov( G3_scratch, G4_scratch); duke@435: __ srl( G4_scratch, 2, G4_scratch); // Skip Arg 0 duke@435: Label done; duke@435: for (Argument ldarg = argv.successor(); ldarg.is_float_register(); ldarg = ldarg.successor()) { duke@435: Label NonFloatArg; duke@435: Label LoadFloatArg; duke@435: Label LoadDoubleArg; duke@435: Label NextArg; duke@435: Address a = ldarg.address_in_frame(); duke@435: __ andcc(G4_scratch, sig_mask, G3_scratch); duke@435: __ br(Assembler::zero, false, Assembler::pt, NonFloatArg); duke@435: __ delayed()->nop(); duke@435: duke@435: __ cmp(G3_scratch, float_sig ); duke@435: __ br(Assembler::equal, false, Assembler::pt, LoadFloatArg); duke@435: __ delayed()->nop(); duke@435: duke@435: __ cmp(G3_scratch, double_sig ); duke@435: __ br(Assembler::equal, false, Assembler::pt, LoadDoubleArg); duke@435: __ delayed()->nop(); duke@435: duke@435: __ bind(NonFloatArg); duke@435: // There are only 6 integer register arguments! duke@435: if ( ldarg.is_register() ) duke@435: __ ld_ptr(ldarg.address_in_frame(), ldarg.as_register()); duke@435: else { duke@435: // Optimization, see if there are any more args and get out prior to checking duke@435: // all 16 float registers. My guess is that this is rare. duke@435: // If is_register is false, then we are done the first six integer args. duke@435: __ tst(G4_scratch); duke@435: __ brx(Assembler::zero, false, Assembler::pt, done); duke@435: __ delayed()->nop(); duke@435: duke@435: } duke@435: __ ba(false, NextArg); duke@435: __ delayed()->srl( G4_scratch, 2, G4_scratch ); duke@435: duke@435: __ bind(LoadFloatArg); duke@435: __ ldf( FloatRegisterImpl::S, a, ldarg.as_float_register(), 4); duke@435: __ ba(false, NextArg); duke@435: __ delayed()->srl( G4_scratch, 2, G4_scratch ); duke@435: duke@435: __ bind(LoadDoubleArg); duke@435: __ ldf( FloatRegisterImpl::D, a, ldarg.as_double_register() ); duke@435: __ ba(false, NextArg); duke@435: __ delayed()->srl( G4_scratch, 2, G4_scratch ); duke@435: duke@435: __ bind(NextArg); duke@435: duke@435: } duke@435: duke@435: __ bind(done); duke@435: __ ret(); duke@435: __ delayed()-> duke@435: restore(O0, 0, Lscratch); // caller's Lscratch gets the result handler duke@435: return entry; duke@435: } duke@435: #endif duke@435: duke@435: void InterpreterGenerator::generate_counter_overflow(Label& Lcontinue) { duke@435: duke@435: // Generate code to initiate compilation on the counter overflow. duke@435: duke@435: // InterpreterRuntime::frequency_counter_overflow takes two arguments, duke@435: // the first indicates if the counter overflow occurs at a backwards branch (NULL bcp) duke@435: // and the second is only used when the first is true. We pass zero for both. duke@435: // The call returns the address of the verified entry point for the method or NULL duke@435: // if the compilation did not complete (either went background or bailed out). duke@435: __ set((int)false, O2); duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), O2, O2, true); duke@435: // returns verified_entry_point or NULL duke@435: // we ignore it in any case duke@435: __ ba(false, Lcontinue); duke@435: __ delayed()->nop(); duke@435: duke@435: } duke@435: duke@435: duke@435: // End of helpers duke@435: duke@435: // Various method entries duke@435: duke@435: // Abstract method entry duke@435: // Attempt to execute abstract method. Throw exception duke@435: // duke@435: address InterpreterGenerator::generate_abstract_entry(void) { duke@435: address entry = __ pc(); duke@435: // abstract method entry duke@435: // throw exception duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError)); duke@435: // the call_VM checks for exception, so we should never return here. duke@435: __ should_not_reach_here(); duke@435: return entry; duke@435: duke@435: } duke@435: duke@435: jrose@1145: // Method handle invoker jrose@1145: // Dispatch a method of the form java.dyn.MethodHandles::invoke(...) jrose@1145: address InterpreterGenerator::generate_method_handle_entry(void) { jrose@1145: if (!EnableMethodHandles) { jrose@1145: return generate_abstract_entry(); jrose@1145: } twisti@1858: twisti@1858: return MethodHandles::generate_method_handle_interpreter_entry(_masm); jrose@1145: } jrose@1145: jrose@1145: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Entry points & stack frame layout duke@435: // duke@435: // Here we generate the various kind of entries into the interpreter. duke@435: // The two main entry type are generic bytecode methods and native call method. duke@435: // These both come in synchronized and non-synchronized versions but the duke@435: // frame layout they create is very similar. The other method entry duke@435: // types are really just special purpose entries that are really entry duke@435: // and interpretation all in one. These are for trivial methods like duke@435: // accessor, empty, or special math methods. duke@435: // duke@435: // When control flow reaches any of the entry types for the interpreter duke@435: // the following holds -> duke@435: // duke@435: // C2 Calling Conventions: duke@435: // duke@435: // The entry code below assumes that the following registers are set duke@435: // when coming in: duke@435: // G5_method: holds the methodOop of the method to call duke@435: // Lesp: points to the TOS of the callers expression stack duke@435: // after having pushed all the parameters duke@435: // duke@435: // The entry code does the following to setup an interpreter frame duke@435: // pop parameters from the callers stack by adjusting Lesp duke@435: // set O0 to Lesp duke@435: // compute X = (max_locals - num_parameters) duke@435: // bump SP up by X to accomadate the extra locals duke@435: // compute X = max_expression_stack duke@435: // + vm_local_words duke@435: // + 16 words of register save area duke@435: // save frame doing a save sp, -X, sp growing towards lower addresses duke@435: // set Lbcp, Lmethod, LcpoolCache duke@435: // set Llocals to i0 duke@435: // set Lmonitors to FP - rounded_vm_local_words duke@435: // set Lesp to Lmonitors - 4 duke@435: // duke@435: // The frame has now been setup to do the rest of the entry code duke@435: duke@435: // Try this optimization: Most method entries could live in a duke@435: // "one size fits all" stack frame without all the dynamic size duke@435: // calculations. It might be profitable to do all this calculation duke@435: // statically and approximately for "small enough" methods. duke@435: duke@435: //----------------------------------------------------------------------------------------------- duke@435: duke@435: // C1 Calling conventions duke@435: // duke@435: // Upon method entry, the following registers are setup: duke@435: // duke@435: // g2 G2_thread: current thread duke@435: // g5 G5_method: method to activate duke@435: // g4 Gargs : pointer to last argument duke@435: // duke@435: // duke@435: // Stack: duke@435: // duke@435: // +---------------+ <--- sp duke@435: // | | duke@435: // : reg save area : duke@435: // | | duke@435: // +---------------+ <--- sp + 0x40 duke@435: // | | duke@435: // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later) duke@435: // | | duke@435: // +---------------+ <--- sp + 0x5c duke@435: // | | duke@435: // : free : duke@435: // | | duke@435: // +---------------+ <--- Gargs duke@435: // | | duke@435: // : arguments : duke@435: // | | duke@435: // +---------------+ duke@435: // | | duke@435: // duke@435: // duke@435: // duke@435: // AFTER FRAME HAS BEEN SETUP for method interpretation the stack looks like: duke@435: // duke@435: // +---------------+ <--- sp duke@435: // | | duke@435: // : reg save area : duke@435: // | | duke@435: // +---------------+ <--- sp + 0x40 duke@435: // | | duke@435: // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later) duke@435: // | | duke@435: // +---------------+ <--- sp + 0x5c duke@435: // | | duke@435: // : : duke@435: // | | <--- Lesp duke@435: // +---------------+ <--- Lmonitors (fp - 0x18) duke@435: // | VM locals | duke@435: // +---------------+ <--- fp duke@435: // | | duke@435: // : reg save area : duke@435: // | | duke@435: // +---------------+ <--- fp + 0x40 duke@435: // | | duke@435: // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later) duke@435: // | | duke@435: // +---------------+ <--- fp + 0x5c duke@435: // | | duke@435: // : free : duke@435: // | | duke@435: // +---------------+ duke@435: // | | duke@435: // : nonarg locals : duke@435: // | | duke@435: // +---------------+ duke@435: // | | duke@435: // : arguments : duke@435: // | | <--- Llocals duke@435: // +---------------+ <--- Gargs duke@435: // | | duke@435: duke@435: address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) { duke@435: // determine code generation flags duke@435: bool synchronized = false; duke@435: address entry_point = NULL; duke@435: duke@435: switch (kind) { duke@435: case Interpreter::zerolocals : break; duke@435: case Interpreter::zerolocals_synchronized: synchronized = true; break; duke@435: case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break; duke@435: case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break; duke@435: case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break; duke@435: case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break; duke@435: case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break; jrose@1145: case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break; duke@435: case Interpreter::java_lang_math_sin : break; duke@435: case Interpreter::java_lang_math_cos : break; duke@435: case Interpreter::java_lang_math_tan : break; duke@435: case Interpreter::java_lang_math_sqrt : break; duke@435: case Interpreter::java_lang_math_abs : break; duke@435: case Interpreter::java_lang_math_log : break; duke@435: case Interpreter::java_lang_math_log10 : break; duke@435: default : ShouldNotReachHere(); break; duke@435: } duke@435: duke@435: if (entry_point) return entry_point; duke@435: duke@435: return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized); duke@435: } duke@435: duke@435: never@1609: bool AbstractInterpreter::can_be_compiled(methodHandle m) { never@1609: // No special entry points that preclude compilation never@1609: return true; never@1609: } never@1609: duke@435: // This method tells the deoptimizer how big an interpreted frame must be: duke@435: int AbstractInterpreter::size_activation(methodOop method, duke@435: int tempcount, duke@435: int popframe_extra_args, duke@435: int moncount, duke@435: int callee_param_count, duke@435: int callee_locals, duke@435: bool is_top_frame) { duke@435: return layout_activation(method, duke@435: tempcount, duke@435: popframe_extra_args, duke@435: moncount, duke@435: callee_param_count, duke@435: callee_locals, duke@435: (frame*)NULL, duke@435: (frame*)NULL, duke@435: is_top_frame); duke@435: } duke@435: duke@435: void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { duke@435: duke@435: // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in duke@435: // the days we had adapter frames. When we deoptimize a situation where a duke@435: // compiled caller calls a compiled caller will have registers it expects duke@435: // to survive the call to the callee. If we deoptimize the callee the only duke@435: // way we can restore these registers is to have the oldest interpreter duke@435: // frame that we create restore these values. That is what this routine duke@435: // will accomplish. duke@435: duke@435: // At the moment we have modified c2 to not have any callee save registers duke@435: // so this problem does not exist and this routine is just a place holder. duke@435: duke@435: assert(f->is_interpreted_frame(), "must be interpreted"); duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Exceptions