interpreter_x86_32.cpp revision 3752
5394N/A/*
5394N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
5394N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5394N/A *
5394N/A * This code is free software; you can redistribute it and/or modify it
5394N/A * under the terms of the GNU General Public License version 2 only, as
5394N/A * published by the Free Software Foundation.
5394N/A *
5394N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5394N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5394N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5394N/A * version 2 for more details (a copy is included in the LICENSE file that
5394N/A * accompanied this code).
5394N/A *
5394N/A * You should have received a copy of the GNU General Public License version
5394N/A * 2 along with this work; if not, write to the Free Software Foundation,
5394N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5394N/A *
5394N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5394N/A * or visit www.oracle.com if you need additional information or have any
5394N/A * questions.
5394N/A *
5394N/A */
5394N/A
6238N/A#include "precompiled.hpp"
5394N/A#include "asm/assembler.hpp"
5394N/A#include "interpreter/bytecodeHistogram.hpp"
5394N/A#include "interpreter/interpreter.hpp"
5394N/A#include "interpreter/interpreterGenerator.hpp"
5394N/A#include "interpreter/interpreterRuntime.hpp"
5394N/A#include "interpreter/templateTable.hpp"
5394N/A#include "oops/arrayOop.hpp"
5394N/A#include "oops/methodDataOop.hpp"
5394N/A#include "oops/methodOop.hpp"
5394N/A#include "oops/oop.inline.hpp"
5394N/A#include "prims/jvmtiExport.hpp"
5394N/A#include "prims/jvmtiThreadState.hpp"
5394N/A#include "prims/methodHandles.hpp"
5394N/A#include "runtime/arguments.hpp"
6372N/A#include "runtime/deoptimization.hpp"
5394N/A#include "runtime/frame.inline.hpp"
5394N/A#include "runtime/sharedRuntime.hpp"
5394N/A#include "runtime/stubRoutines.hpp"
5394N/A#include "runtime/synchronizer.hpp"
5394N/A#include "runtime/timer.hpp"
5394N/A#include "runtime/vframeArray.hpp"
5394N/A#include "utilities/debug.hpp"
5394N/A#ifdef COMPILER1
5394N/A#include "c1/c1_Runtime1.hpp"
5714N/A#endif
5394N/A
5394N/A#define __ _masm->
5394N/A
5394N/A//------------------------------------------------------------------------------------------------------------------------
5394N/A
5394N/Aaddress AbstractInterpreterGenerator::generate_slow_signature_handler() {
5394N/A address entry = __ pc();
5394N/A // rbx,: method
5394N/A // rcx: temporary
5394N/A // rdi: pointer to locals
5394N/A // rsp: end of copied parameters area
5394N/A __ mov(rcx, rsp);
5394N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
5394N/A __ ret(0);
5394N/A return entry;
5394N/A}
5394N/A
5394N/A
5394N/A//
5394N/A// Various method entries (that c++ and asm interpreter agree upon)
6238N/A//------------------------------------------------------------------------------------------------------------------------
5947N/A//
5947N/A//
5947N/A
5947N/A// Empty method, generate a very fast return.
5947N/A
5947N/Aaddress InterpreterGenerator::generate_empty_entry(void) {
5947N/A
5947N/A // rbx,: methodOop
5947N/A // rcx: receiver (unused)
5947N/A // rsi: previous interpreter state (C++ interpreter) must preserve
5947N/A // rsi: sender sp must set sp to this value on return
5947N/A
5947N/A if (!UseFastEmptyMethods) return NULL;
5947N/A
5947N/A address entry_point = __ pc();
5947N/A
5947N/A // If we need a safepoint check, generate full interpreter entry.
5947N/A Label slow_path;
5947N/A ExternalAddress state(SafepointSynchronize::address_of_state());
5394N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
5394N/A SafepointSynchronize::_not_synchronized);
5395N/A __ jcc(Assembler::notEqual, slow_path);
6443N/A
6443N/A // do nothing for empty methods (do not even increment invocation counter)
6443N/A // Code: _return
6487N/A // _return
6443N/A // return w/o popping parameters
6443N/A __ pop(rax);
6443N/A __ mov(rsp, rsi);
6443N/A __ jmp(rax);
6443N/A
6443N/A __ bind(slow_path);
6443N/A (void) generate_normal_entry(false);
6443N/A return entry_point;
6443N/A}
6443N/A
6443N/Aaddress InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
6443N/A
6443N/A // rbx,: methodOop
6443N/A // rcx: scratrch
6443N/A // rsi: sender sp
6443N/A
6443N/A if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
6443N/A
6443N/A address entry_point = __ pc();
6443N/A
6443N/A // These don't need a safepoint check because they aren't virtually
6443N/A // callable. We won't enter these intrinsics from compiled code.
6443N/A // If in the future we added an intrinsic which was virtually callable
6443N/A // we'd have to worry about how to safepoint so that this code is used.
6443N/A
6443N/A // mathematical functions inlined by compiler
5394N/A // (interpreter must provide identical implementation
5394N/A // in order to avoid monotonicity bugs when switching
5394N/A // from interpreter to compiler in the middle of some
5394N/A // computation)
5394N/A //
5394N/A // stack: [ ret adr ] <-- rsp
5947N/A // [ lo(arg) ]
5394N/A // [ hi(arg) ]
5394N/A //
5394N/A
5394N/A // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
5394N/A // native methods. Interpreter::method_kind(...) does a check for
5394N/A // native methods first before checking for intrinsic methods and
5394N/A // thus will never select this entry point. Make sure it is not
5394N/A // called accidentally since the SharedRuntime entry points will
5394N/A // not work for JDK 1.2.
6443N/A //
5394N/A // We no longer need to check for JDK 1.2 since it's EOL'ed.
5394N/A // The following check existed in pre 1.6 implementation,
5394N/A // if (Universe::is_jdk12x_version()) {
5394N/A // __ should_not_reach_here();
5394N/A // }
5394N/A // Universe::is_jdk12x_version() always returns false since
5394N/A // the JDK version is not yet determined when this method is called.
5394N/A // This method is called during interpreter_init() whereas
5394N/A // JDK version is only determined when universe2_init() is called.
5394N/A
5394N/A // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
5394N/A // java methods. Interpreter::method_kind(...) will select
5394N/A // this entry point for the corresponding methods in JDK 1.3.
5394N/A // get argument
5457N/A __ fld_d(Address(rsp, 1*wordSize));
5394N/A switch (kind) {
5394N/A case Interpreter::java_lang_math_sin :
5394N/A __ trigfunc('s');
5423N/A break;
5443N/A case Interpreter::java_lang_math_cos :
5423N/A __ trigfunc('c');
5423N/A break;
5454N/A case Interpreter::java_lang_math_tan :
5423N/A __ trigfunc('t');
5423N/A break;
5454N/A case Interpreter::java_lang_math_sqrt:
5454N/A __ fsqrt();
5454N/A break;
6443N/A case Interpreter::java_lang_math_abs:
5454N/A __ fabs();
5423N/A break;
5423N/A case Interpreter::java_lang_math_log:
5423N/A __ flog();
5443N/A // Store to stack to convert 80bit precision back to 64bits
5443N/A __ push_fTOS();
5423N/A __ pop_fTOS();
5423N/A break;
5423N/A case Interpreter::java_lang_math_log10:
5423N/A __ flog10();
5423N/A // Store to stack to convert 80bit precision back to 64bits
5423N/A __ push_fTOS();
5423N/A __ pop_fTOS();
5423N/A break;
5443N/A case Interpreter::java_lang_math_pow:
5443N/A __ fld_d(Address(rsp, 3*wordSize)); // second argument
5443N/A __ pow_with_fallback(0);
5423N/A // Store to stack to convert 80bit precision back to 64bits
5423N/A __ push_fTOS();
5423N/A __ pop_fTOS();
5394N/A break;
5394N/A case Interpreter::java_lang_math_exp:
6428N/A __ exp_with_fallback(0);
6428N/A // Store to stack to convert 80bit precision back to 64bits
6443N/A __ push_fTOS();
6443N/A __ pop_fTOS();
6443N/A break;
6443N/A default :
6443N/A ShouldNotReachHere();
6443N/A }
6443N/A
6443N/A // return double result in xmm0 for interpreter and compilers.
6443N/A if (UseSSE >= 2) {
6443N/A __ subptr(rsp, 2*wordSize);
6443N/A __ fstp_d(Address(rsp, 0));
6443N/A __ movdbl(xmm0, Address(rsp, 0));
6443N/A __ addptr(rsp, 2*wordSize);
6443N/A }
6443N/A
6443N/A // done, result in FPU ST(0) or XMM0
6443N/A __ pop(rdi); // get return address
6443N/A __ mov(rsp, rsi); // set sp to sender sp
6443N/A __ jmp(rdi);
6443N/A
6443N/A return entry_point;
6443N/A}
6443N/A
6443N/A
6443N/A// Abstract method entry
6443N/A// Attempt to execute abstract method. Throw exception
6443N/Aaddress InterpreterGenerator::generate_abstract_entry(void) {
6443N/A
6443N/A // rbx,: methodOop
6443N/A // rcx: receiver (unused)
6443N/A // rsi: previous interpreter state (C++ interpreter) must preserve
6443N/A
6443N/A // rsi: sender SP
6443N/A
6443N/A address entry_point = __ pc();
6443N/A
6443N/A // abstract method entry
6443N/A
6443N/A // pop return address, reset last_sp to NULL
6443N/A __ empty_expression_stack();
6443N/A __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
6443N/A __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
6443N/A
6443N/A // throw exception
6443N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
6443N/A // the call_VM checks for exception, so we should never return here.
6443N/A __ should_not_reach_here();
6443N/A
6443N/A return entry_point;
6443N/A}
6443N/A
6443N/A
6443N/A// Method handle invoker
6443N/A// Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...)
6443N/Aaddress InterpreterGenerator::generate_method_handle_entry(void) {
6443N/A if (!EnableInvokeDynamic) {
6443N/A return generate_abstract_entry();
6443N/A }
6443N/A
6443N/A address entry_point = MethodHandles::generate_method_handle_interpreter_entry(_masm);
6443N/A
6443N/A return entry_point;
6443N/A}
6443N/A
6443N/Avoid Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
6443N/A
6443N/A // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
6443N/A // the days we had adapter frames. When we deoptimize a situation where a
6443N/A // compiled caller calls a compiled caller will have registers it expects
6443N/A // to survive the call to the callee. If we deoptimize the callee the only
6443N/A // way we can restore these registers is to have the oldest interpreter
6443N/A // frame that we create restore these values. That is what this routine
6428N/A // will accomplish.
6428N/A
6428N/A // At the moment we have modified c2 to not have any callee save registers
6428N/A // so this problem does not exist and this routine is just a place holder.
6428N/A
6428N/A assert(f->is_interpreted_frame(), "must be interpreted");
6428N/A}
6428N/A