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