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