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