0N/A/*
2117N/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#define __ _masm->
0N/A
0N/A//------------------------------------------------------------------------------------------------------------------------
0N/A
0N/Aaddress AbstractInterpreterGenerator::generate_slow_signature_handler() {
0N/A address entry = __ pc();
0N/A // rbx,: method
0N/A // rcx: temporary
0N/A // rdi: pointer to locals
0N/A // rsp: end of copied parameters area
304N/A __ mov(rcx, rsp);
0N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
0N/A __ ret(0);
0N/A return entry;
0N/A}
0N/A
0N/A
0N/A//
0N/A// Various method entries (that c++ and asm interpreter agree upon)
0N/A//------------------------------------------------------------------------------------------------------------------------
0N/A//
0N/A//
0N/A
0N/A// Empty method, generate a very fast return.
0N/A
0N/Aaddress InterpreterGenerator::generate_empty_entry(void) {
0N/A
0N/A // rbx,: methodOop
0N/A // rcx: receiver (unused)
0N/A // rsi: previous interpreter state (C++ interpreter) must preserve
0N/A // rsi: sender sp must set sp to this value on return
0N/A
0N/A if (!UseFastEmptyMethods) return NULL;
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A // If we need a safepoint check, generate full interpreter entry.
0N/A Label slow_path;
0N/A ExternalAddress state(SafepointSynchronize::address_of_state());
0N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
0N/A SafepointSynchronize::_not_synchronized);
0N/A __ jcc(Assembler::notEqual, slow_path);
0N/A
0N/A // do nothing for empty methods (do not even increment invocation counter)
0N/A // Code: _return
0N/A // _return
0N/A // return w/o popping parameters
304N/A __ pop(rax);
304N/A __ mov(rsp, rsi);
0N/A __ jmp(rax);
0N/A
0N/A __ bind(slow_path);
0N/A (void) generate_normal_entry(false);
0N/A return entry_point;
0N/A}
0N/A
0N/Aaddress InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
0N/A
0N/A // rbx,: methodOop
0N/A // rcx: scratrch
0N/A // rsi: sender sp
0N/A
0N/A if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A // These don't need a safepoint check because they aren't virtually
0N/A // callable. We won't enter these intrinsics from compiled code.
0N/A // If in the future we added an intrinsic which was virtually callable
0N/A // we'd have to worry about how to safepoint so that this code is used.
0N/A
0N/A // mathematical functions inlined by compiler
0N/A // (interpreter must provide identical implementation
0N/A // in order to avoid monotonicity bugs when switching
0N/A // from interpreter to compiler in the middle of some
0N/A // computation)
0N/A //
0N/A // stack: [ ret adr ] <-- rsp
0N/A // [ lo(arg) ]
0N/A // [ hi(arg) ]
0N/A //
0N/A
0N/A // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
0N/A // native methods. Interpreter::method_kind(...) does a check for
0N/A // native methods first before checking for intrinsic methods and
0N/A // thus will never select this entry point. Make sure it is not
0N/A // called accidentally since the SharedRuntime entry points will
0N/A // not work for JDK 1.2.
0N/A //
0N/A // We no longer need to check for JDK 1.2 since it's EOL'ed.
0N/A // The following check existed in pre 1.6 implementation,
0N/A // if (Universe::is_jdk12x_version()) {
0N/A // __ should_not_reach_here();
0N/A // }
0N/A // Universe::is_jdk12x_version() always returns false since
0N/A // the JDK version is not yet determined when this method is called.
0N/A // This method is called during interpreter_init() whereas
0N/A // JDK version is only determined when universe2_init() is called.
0N/A
0N/A // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
0N/A // java methods. Interpreter::method_kind(...) will select
0N/A // this entry point for the corresponding methods in JDK 1.3.
0N/A // get argument
1426N/A __ fld_d(Address(rsp, 1*wordSize));
0N/A switch (kind) {
0N/A case Interpreter::java_lang_math_sin :
0N/A __ trigfunc('s');
0N/A break;
0N/A case Interpreter::java_lang_math_cos :
0N/A __ trigfunc('c');
0N/A break;
0N/A case Interpreter::java_lang_math_tan :
0N/A __ trigfunc('t');
0N/A break;
0N/A case Interpreter::java_lang_math_sqrt:
0N/A __ fsqrt();
0N/A break;
0N/A case Interpreter::java_lang_math_abs:
0N/A __ fabs();
0N/A break;
0N/A case Interpreter::java_lang_math_log:
0N/A __ flog();
0N/A // Store to stack to convert 80bit precision back to 64bits
0N/A __ push_fTOS();
0N/A __ pop_fTOS();
0N/A break;
0N/A case Interpreter::java_lang_math_log10:
0N/A __ flog10();
0N/A // Store to stack to convert 80bit precision back to 64bits
0N/A __ push_fTOS();
0N/A __ pop_fTOS();
0N/A break;
3752N/A case Interpreter::java_lang_math_pow:
3752N/A __ fld_d(Address(rsp, 3*wordSize)); // second argument
3752N/A __ pow_with_fallback(0);
3752N/A // Store to stack to convert 80bit precision back to 64bits
3752N/A __ push_fTOS();
3752N/A __ pop_fTOS();
3752N/A break;
3752N/A case Interpreter::java_lang_math_exp:
3752N/A __ exp_with_fallback(0);
3752N/A // Store to stack to convert 80bit precision back to 64bits
3752N/A __ push_fTOS();
3752N/A __ pop_fTOS();
3752N/A break;
0N/A default :
0N/A ShouldNotReachHere();
0N/A }
0N/A
0N/A // return double result in xmm0 for interpreter and compilers.
0N/A if (UseSSE >= 2) {
304N/A __ subptr(rsp, 2*wordSize);
0N/A __ fstp_d(Address(rsp, 0));
0N/A __ movdbl(xmm0, Address(rsp, 0));
304N/A __ addptr(rsp, 2*wordSize);
0N/A }
0N/A
0N/A // done, result in FPU ST(0) or XMM0
304N/A __ pop(rdi); // get return address
304N/A __ mov(rsp, rsi); // set sp to sender sp
0N/A __ jmp(rdi);
0N/A
0N/A return entry_point;
0N/A}
0N/A
0N/A
0N/A// Abstract method entry
0N/A// Attempt to execute abstract method. Throw exception
0N/Aaddress InterpreterGenerator::generate_abstract_entry(void) {
0N/A
0N/A // rbx,: methodOop
0N/A // rcx: receiver (unused)
0N/A // rsi: previous interpreter state (C++ interpreter) must preserve
0N/A
0N/A // rsi: sender SP
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A // abstract method entry
0N/A
710N/A // pop return address, reset last_sp to NULL
710N/A __ empty_expression_stack();
710N/A __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
710N/A __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
710N/A
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
0N/A return entry_point;
0N/A}
0N/A
710N/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}