src/cpu/x86/vm/interpreter_x86_32.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "interpreter/bytecodeHistogram.hpp"
aoqi@0 28 #include "interpreter/interpreter.hpp"
aoqi@0 29 #include "interpreter/interpreterGenerator.hpp"
aoqi@0 30 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 31 #include "interpreter/templateTable.hpp"
aoqi@0 32 #include "oops/arrayOop.hpp"
aoqi@0 33 #include "oops/methodData.hpp"
aoqi@0 34 #include "oops/method.hpp"
aoqi@0 35 #include "oops/oop.inline.hpp"
aoqi@0 36 #include "prims/jvmtiExport.hpp"
aoqi@0 37 #include "prims/jvmtiThreadState.hpp"
aoqi@0 38 #include "prims/methodHandles.hpp"
aoqi@0 39 #include "runtime/arguments.hpp"
aoqi@0 40 #include "runtime/deoptimization.hpp"
aoqi@0 41 #include "runtime/frame.inline.hpp"
aoqi@0 42 #include "runtime/sharedRuntime.hpp"
aoqi@0 43 #include "runtime/stubRoutines.hpp"
aoqi@0 44 #include "runtime/synchronizer.hpp"
aoqi@0 45 #include "runtime/timer.hpp"
aoqi@0 46 #include "runtime/vframeArray.hpp"
aoqi@0 47 #include "utilities/debug.hpp"
aoqi@0 48 #ifdef COMPILER1
aoqi@0 49 #include "c1/c1_Runtime1.hpp"
aoqi@0 50 #endif
aoqi@0 51
aoqi@0 52 #define __ _masm->
aoqi@0 53
aoqi@0 54 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 55
aoqi@0 56 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
aoqi@0 57 address entry = __ pc();
aoqi@0 58 // rbx,: method
aoqi@0 59 // rcx: temporary
aoqi@0 60 // rdi: pointer to locals
aoqi@0 61 // rsp: end of copied parameters area
aoqi@0 62 __ mov(rcx, rsp);
aoqi@0 63 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
aoqi@0 64 __ ret(0);
aoqi@0 65 return entry;
aoqi@0 66 }
aoqi@0 67
aoqi@0 68
aoqi@0 69 //
aoqi@0 70 // Various method entries (that c++ and asm interpreter agree upon)
aoqi@0 71 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 72 //
aoqi@0 73 //
aoqi@0 74
aoqi@0 75 // Empty method, generate a very fast return.
aoqi@0 76
aoqi@0 77 address InterpreterGenerator::generate_empty_entry(void) {
aoqi@0 78
aoqi@0 79 // rbx,: Method*
aoqi@0 80 // rcx: receiver (unused)
aoqi@0 81 // rsi: previous interpreter state (C++ interpreter) must preserve
aoqi@0 82 // rsi: sender sp must set sp to this value on return
aoqi@0 83
aoqi@0 84 if (!UseFastEmptyMethods) return NULL;
aoqi@0 85
aoqi@0 86 address entry_point = __ pc();
aoqi@0 87
aoqi@0 88 // If we need a safepoint check, generate full interpreter entry.
aoqi@0 89 Label slow_path;
aoqi@0 90 ExternalAddress state(SafepointSynchronize::address_of_state());
aoqi@0 91 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
aoqi@0 92 SafepointSynchronize::_not_synchronized);
aoqi@0 93 __ jcc(Assembler::notEqual, slow_path);
aoqi@0 94
aoqi@0 95 // do nothing for empty methods (do not even increment invocation counter)
aoqi@0 96 // Code: _return
aoqi@0 97 // _return
aoqi@0 98 // return w/o popping parameters
aoqi@0 99 __ pop(rax);
aoqi@0 100 __ mov(rsp, rsi);
aoqi@0 101 __ jmp(rax);
aoqi@0 102
aoqi@0 103 __ bind(slow_path);
aoqi@0 104 (void) generate_normal_entry(false);
aoqi@0 105 return entry_point;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
aoqi@0 109
aoqi@0 110 // rbx,: Method*
aoqi@0 111 // rcx: scratrch
aoqi@0 112 // rsi: sender sp
aoqi@0 113
aoqi@0 114 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
aoqi@0 115
aoqi@0 116 address entry_point = __ pc();
aoqi@0 117
aoqi@0 118 // These don't need a safepoint check because they aren't virtually
aoqi@0 119 // callable. We won't enter these intrinsics from compiled code.
aoqi@0 120 // If in the future we added an intrinsic which was virtually callable
aoqi@0 121 // we'd have to worry about how to safepoint so that this code is used.
aoqi@0 122
aoqi@0 123 // mathematical functions inlined by compiler
aoqi@0 124 // (interpreter must provide identical implementation
aoqi@0 125 // in order to avoid monotonicity bugs when switching
aoqi@0 126 // from interpreter to compiler in the middle of some
aoqi@0 127 // computation)
aoqi@0 128 //
aoqi@0 129 // stack: [ ret adr ] <-- rsp
aoqi@0 130 // [ lo(arg) ]
aoqi@0 131 // [ hi(arg) ]
aoqi@0 132 //
aoqi@0 133
aoqi@0 134 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
aoqi@0 135 // native methods. Interpreter::method_kind(...) does a check for
aoqi@0 136 // native methods first before checking for intrinsic methods and
aoqi@0 137 // thus will never select this entry point. Make sure it is not
aoqi@0 138 // called accidentally since the SharedRuntime entry points will
aoqi@0 139 // not work for JDK 1.2.
aoqi@0 140 //
aoqi@0 141 // We no longer need to check for JDK 1.2 since it's EOL'ed.
aoqi@0 142 // The following check existed in pre 1.6 implementation,
aoqi@0 143 // if (Universe::is_jdk12x_version()) {
aoqi@0 144 // __ should_not_reach_here();
aoqi@0 145 // }
aoqi@0 146 // Universe::is_jdk12x_version() always returns false since
aoqi@0 147 // the JDK version is not yet determined when this method is called.
aoqi@0 148 // This method is called during interpreter_init() whereas
aoqi@0 149 // JDK version is only determined when universe2_init() is called.
aoqi@0 150
aoqi@0 151 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
aoqi@0 152 // java methods. Interpreter::method_kind(...) will select
aoqi@0 153 // this entry point for the corresponding methods in JDK 1.3.
aoqi@0 154 // get argument
aoqi@0 155 __ fld_d(Address(rsp, 1*wordSize));
aoqi@0 156 switch (kind) {
aoqi@0 157 case Interpreter::java_lang_math_sin :
aoqi@0 158 __ trigfunc('s');
aoqi@0 159 break;
aoqi@0 160 case Interpreter::java_lang_math_cos :
aoqi@0 161 __ trigfunc('c');
aoqi@0 162 break;
aoqi@0 163 case Interpreter::java_lang_math_tan :
aoqi@0 164 __ trigfunc('t');
aoqi@0 165 break;
aoqi@0 166 case Interpreter::java_lang_math_sqrt:
aoqi@0 167 __ fsqrt();
aoqi@0 168 break;
aoqi@0 169 case Interpreter::java_lang_math_abs:
aoqi@0 170 __ fabs();
aoqi@0 171 break;
aoqi@0 172 case Interpreter::java_lang_math_log:
aoqi@0 173 __ flog();
aoqi@0 174 // Store to stack to convert 80bit precision back to 64bits
aoqi@0 175 __ push_fTOS();
aoqi@0 176 __ pop_fTOS();
aoqi@0 177 break;
aoqi@0 178 case Interpreter::java_lang_math_log10:
aoqi@0 179 __ flog10();
aoqi@0 180 // Store to stack to convert 80bit precision back to 64bits
aoqi@0 181 __ push_fTOS();
aoqi@0 182 __ pop_fTOS();
aoqi@0 183 break;
aoqi@0 184 case Interpreter::java_lang_math_pow:
aoqi@0 185 __ fld_d(Address(rsp, 3*wordSize)); // second argument
aoqi@0 186 __ pow_with_fallback(0);
aoqi@0 187 // Store to stack to convert 80bit precision back to 64bits
aoqi@0 188 __ push_fTOS();
aoqi@0 189 __ pop_fTOS();
aoqi@0 190 break;
aoqi@0 191 case Interpreter::java_lang_math_exp:
aoqi@0 192 __ exp_with_fallback(0);
aoqi@0 193 // Store to stack to convert 80bit precision back to 64bits
aoqi@0 194 __ push_fTOS();
aoqi@0 195 __ pop_fTOS();
aoqi@0 196 break;
aoqi@0 197 default :
aoqi@0 198 ShouldNotReachHere();
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 // return double result in xmm0 for interpreter and compilers.
aoqi@0 202 if (UseSSE >= 2) {
aoqi@0 203 __ subptr(rsp, 2*wordSize);
aoqi@0 204 __ fstp_d(Address(rsp, 0));
aoqi@0 205 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 206 __ addptr(rsp, 2*wordSize);
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 // done, result in FPU ST(0) or XMM0
aoqi@0 210 __ pop(rdi); // get return address
aoqi@0 211 __ mov(rsp, rsi); // set sp to sender sp
aoqi@0 212 __ jmp(rdi);
aoqi@0 213
aoqi@0 214 return entry_point;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217
aoqi@0 218 // Abstract method entry
aoqi@0 219 // Attempt to execute abstract method. Throw exception
aoqi@0 220 address InterpreterGenerator::generate_abstract_entry(void) {
aoqi@0 221
aoqi@0 222 // rbx,: Method*
aoqi@0 223 // rcx: receiver (unused)
aoqi@0 224 // rsi: previous interpreter state (C++ interpreter) must preserve
aoqi@0 225
aoqi@0 226 // rsi: sender SP
aoqi@0 227
aoqi@0 228 address entry_point = __ pc();
aoqi@0 229
aoqi@0 230 // abstract method entry
aoqi@0 231
aoqi@0 232 // pop return address, reset last_sp to NULL
aoqi@0 233 __ empty_expression_stack();
aoqi@0 234 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
aoqi@0 235 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
aoqi@0 236
aoqi@0 237 // throw exception
aoqi@0 238 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
aoqi@0 239 // the call_VM checks for exception, so we should never return here.
aoqi@0 240 __ should_not_reach_here();
aoqi@0 241
aoqi@0 242 return entry_point;
aoqi@0 243 }
aoqi@0 244
aoqi@0 245
aoqi@0 246 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
aoqi@0 247
aoqi@0 248 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
aoqi@0 249 // the days we had adapter frames. When we deoptimize a situation where a
aoqi@0 250 // compiled caller calls a compiled caller will have registers it expects
aoqi@0 251 // to survive the call to the callee. If we deoptimize the callee the only
aoqi@0 252 // way we can restore these registers is to have the oldest interpreter
aoqi@0 253 // frame that we create restore these values. That is what this routine
aoqi@0 254 // will accomplish.
aoqi@0 255
aoqi@0 256 // At the moment we have modified c2 to not have any callee save registers
aoqi@0 257 // so this problem does not exist and this routine is just a place holder.
aoqi@0 258
aoqi@0 259 assert(f->is_interpreted_frame(), "must be interpreted");
aoqi@0 260 }

mercurial