src/cpu/x86/vm/interpreter_x86_32.cpp

Thu, 03 Nov 2011 04:12:49 -0700

author
twisti
date
Thu, 03 Nov 2011 04:12:49 -0700
changeset 3252
448691f285a5
parent 2901
3d2ab563047a
child 3787
6759698e3140
permissions
-rw-r--r--

7106944: assert(_pc == *pc_addr) failed may be too strong
Reviewed-by: kvn, never

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

mercurial