1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/interpreter_x86_64.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,375 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "asm/macroAssembler.hpp" 1.30 +#include "interpreter/bytecodeHistogram.hpp" 1.31 +#include "interpreter/interpreter.hpp" 1.32 +#include "interpreter/interpreterGenerator.hpp" 1.33 +#include "interpreter/interpreterRuntime.hpp" 1.34 +#include "interpreter/templateTable.hpp" 1.35 +#include "oops/arrayOop.hpp" 1.36 +#include "oops/methodData.hpp" 1.37 +#include "oops/method.hpp" 1.38 +#include "oops/oop.inline.hpp" 1.39 +#include "prims/jvmtiExport.hpp" 1.40 +#include "prims/jvmtiThreadState.hpp" 1.41 +#include "prims/methodHandles.hpp" 1.42 +#include "runtime/arguments.hpp" 1.43 +#include "runtime/deoptimization.hpp" 1.44 +#include "runtime/frame.inline.hpp" 1.45 +#include "runtime/sharedRuntime.hpp" 1.46 +#include "runtime/stubRoutines.hpp" 1.47 +#include "runtime/synchronizer.hpp" 1.48 +#include "runtime/timer.hpp" 1.49 +#include "runtime/vframeArray.hpp" 1.50 +#include "utilities/debug.hpp" 1.51 +#ifdef COMPILER1 1.52 +#include "c1/c1_Runtime1.hpp" 1.53 +#endif 1.54 + 1.55 +#define __ _masm-> 1.56 + 1.57 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.58 + 1.59 +#ifdef _WIN64 1.60 +address AbstractInterpreterGenerator::generate_slow_signature_handler() { 1.61 + address entry = __ pc(); 1.62 + 1.63 + // rbx: method 1.64 + // r14: pointer to locals 1.65 + // c_rarg3: first stack arg - wordSize 1.66 + __ mov(c_rarg3, rsp); 1.67 + // adjust rsp 1.68 + __ subptr(rsp, 4 * wordSize); 1.69 + __ call_VM(noreg, 1.70 + CAST_FROM_FN_PTR(address, 1.71 + InterpreterRuntime::slow_signature_handler), 1.72 + rbx, r14, c_rarg3); 1.73 + 1.74 + // rax: result handler 1.75 + 1.76 + // Stack layout: 1.77 + // rsp: 3 integer or float args (if static first is unused) 1.78 + // 1 float/double identifiers 1.79 + // return address 1.80 + // stack args 1.81 + // garbage 1.82 + // expression stack bottom 1.83 + // bcp (NULL) 1.84 + // ... 1.85 + 1.86 + // Do FP first so we can use c_rarg3 as temp 1.87 + __ movl(c_rarg3, Address(rsp, 3 * wordSize)); // float/double identifiers 1.88 + 1.89 + for ( int i= 0; i < Argument::n_int_register_parameters_c-1; i++ ) { 1.90 + XMMRegister floatreg = as_XMMRegister(i+1); 1.91 + Label isfloatordouble, isdouble, next; 1.92 + 1.93 + __ testl(c_rarg3, 1 << (i*2)); // Float or Double? 1.94 + __ jcc(Assembler::notZero, isfloatordouble); 1.95 + 1.96 + // Do Int register here 1.97 + switch ( i ) { 1.98 + case 0: 1.99 + __ movl(rscratch1, Address(rbx, Method::access_flags_offset())); 1.100 + __ testl(rscratch1, JVM_ACC_STATIC); 1.101 + __ cmovptr(Assembler::zero, c_rarg1, Address(rsp, 0)); 1.102 + break; 1.103 + case 1: 1.104 + __ movptr(c_rarg2, Address(rsp, wordSize)); 1.105 + break; 1.106 + case 2: 1.107 + __ movptr(c_rarg3, Address(rsp, 2 * wordSize)); 1.108 + break; 1.109 + default: 1.110 + break; 1.111 + } 1.112 + 1.113 + __ jmp (next); 1.114 + 1.115 + __ bind(isfloatordouble); 1.116 + __ testl(c_rarg3, 1 << ((i*2)+1)); // Double? 1.117 + __ jcc(Assembler::notZero, isdouble); 1.118 + 1.119 +// Do Float Here 1.120 + __ movflt(floatreg, Address(rsp, i * wordSize)); 1.121 + __ jmp(next); 1.122 + 1.123 +// Do Double here 1.124 + __ bind(isdouble); 1.125 + __ movdbl(floatreg, Address(rsp, i * wordSize)); 1.126 + 1.127 + __ bind(next); 1.128 + } 1.129 + 1.130 + 1.131 + // restore rsp 1.132 + __ addptr(rsp, 4 * wordSize); 1.133 + 1.134 + __ ret(0); 1.135 + 1.136 + return entry; 1.137 +} 1.138 +#else 1.139 +address AbstractInterpreterGenerator::generate_slow_signature_handler() { 1.140 + address entry = __ pc(); 1.141 + 1.142 + // rbx: method 1.143 + // r14: pointer to locals 1.144 + // c_rarg3: first stack arg - wordSize 1.145 + __ mov(c_rarg3, rsp); 1.146 + // adjust rsp 1.147 + __ subptr(rsp, 14 * wordSize); 1.148 + __ call_VM(noreg, 1.149 + CAST_FROM_FN_PTR(address, 1.150 + InterpreterRuntime::slow_signature_handler), 1.151 + rbx, r14, c_rarg3); 1.152 + 1.153 + // rax: result handler 1.154 + 1.155 + // Stack layout: 1.156 + // rsp: 5 integer args (if static first is unused) 1.157 + // 1 float/double identifiers 1.158 + // 8 double args 1.159 + // return address 1.160 + // stack args 1.161 + // garbage 1.162 + // expression stack bottom 1.163 + // bcp (NULL) 1.164 + // ... 1.165 + 1.166 + // Do FP first so we can use c_rarg3 as temp 1.167 + __ movl(c_rarg3, Address(rsp, 5 * wordSize)); // float/double identifiers 1.168 + 1.169 + for (int i = 0; i < Argument::n_float_register_parameters_c; i++) { 1.170 + const XMMRegister r = as_XMMRegister(i); 1.171 + 1.172 + Label d, done; 1.173 + 1.174 + __ testl(c_rarg3, 1 << i); 1.175 + __ jcc(Assembler::notZero, d); 1.176 + __ movflt(r, Address(rsp, (6 + i) * wordSize)); 1.177 + __ jmp(done); 1.178 + __ bind(d); 1.179 + __ movdbl(r, Address(rsp, (6 + i) * wordSize)); 1.180 + __ bind(done); 1.181 + } 1.182 + 1.183 + // Now handle integrals. Only do c_rarg1 if not static. 1.184 + __ movl(c_rarg3, Address(rbx, Method::access_flags_offset())); 1.185 + __ testl(c_rarg3, JVM_ACC_STATIC); 1.186 + __ cmovptr(Assembler::zero, c_rarg1, Address(rsp, 0)); 1.187 + 1.188 + __ movptr(c_rarg2, Address(rsp, wordSize)); 1.189 + __ movptr(c_rarg3, Address(rsp, 2 * wordSize)); 1.190 + __ movptr(c_rarg4, Address(rsp, 3 * wordSize)); 1.191 + __ movptr(c_rarg5, Address(rsp, 4 * wordSize)); 1.192 + 1.193 + // restore rsp 1.194 + __ addptr(rsp, 14 * wordSize); 1.195 + 1.196 + __ ret(0); 1.197 + 1.198 + return entry; 1.199 +} 1.200 +#endif 1.201 + 1.202 + 1.203 +// 1.204 +// Various method entries 1.205 +// 1.206 + 1.207 +address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 1.208 + 1.209 + // rbx,: Method* 1.210 + // rcx: scratrch 1.211 + // r13: sender sp 1.212 + 1.213 + if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 1.214 + 1.215 + address entry_point = __ pc(); 1.216 + 1.217 + // These don't need a safepoint check because they aren't virtually 1.218 + // callable. We won't enter these intrinsics from compiled code. 1.219 + // If in the future we added an intrinsic which was virtually callable 1.220 + // we'd have to worry about how to safepoint so that this code is used. 1.221 + 1.222 + // mathematical functions inlined by compiler 1.223 + // (interpreter must provide identical implementation 1.224 + // in order to avoid monotonicity bugs when switching 1.225 + // from interpreter to compiler in the middle of some 1.226 + // computation) 1.227 + // 1.228 + // stack: [ ret adr ] <-- rsp 1.229 + // [ lo(arg) ] 1.230 + // [ hi(arg) ] 1.231 + // 1.232 + 1.233 + // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are 1.234 + // native methods. Interpreter::method_kind(...) does a check for 1.235 + // native methods first before checking for intrinsic methods and 1.236 + // thus will never select this entry point. Make sure it is not 1.237 + // called accidentally since the SharedRuntime entry points will 1.238 + // not work for JDK 1.2. 1.239 + // 1.240 + // We no longer need to check for JDK 1.2 since it's EOL'ed. 1.241 + // The following check existed in pre 1.6 implementation, 1.242 + // if (Universe::is_jdk12x_version()) { 1.243 + // __ should_not_reach_here(); 1.244 + // } 1.245 + // Universe::is_jdk12x_version() always returns false since 1.246 + // the JDK version is not yet determined when this method is called. 1.247 + // This method is called during interpreter_init() whereas 1.248 + // JDK version is only determined when universe2_init() is called. 1.249 + 1.250 + // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are 1.251 + // java methods. Interpreter::method_kind(...) will select 1.252 + // this entry point for the corresponding methods in JDK 1.3. 1.253 + // get argument 1.254 + 1.255 + if (kind == Interpreter::java_lang_math_sqrt) { 1.256 + __ sqrtsd(xmm0, Address(rsp, wordSize)); 1.257 + } else { 1.258 + __ fld_d(Address(rsp, wordSize)); 1.259 + switch (kind) { 1.260 + case Interpreter::java_lang_math_sin : 1.261 + __ trigfunc('s'); 1.262 + break; 1.263 + case Interpreter::java_lang_math_cos : 1.264 + __ trigfunc('c'); 1.265 + break; 1.266 + case Interpreter::java_lang_math_tan : 1.267 + __ trigfunc('t'); 1.268 + break; 1.269 + case Interpreter::java_lang_math_abs: 1.270 + __ fabs(); 1.271 + break; 1.272 + case Interpreter::java_lang_math_log: 1.273 + __ flog(); 1.274 + break; 1.275 + case Interpreter::java_lang_math_log10: 1.276 + __ flog10(); 1.277 + break; 1.278 + case Interpreter::java_lang_math_pow: 1.279 + __ fld_d(Address(rsp, 3*wordSize)); // second argument (one 1.280 + // empty stack slot) 1.281 + __ pow_with_fallback(0); 1.282 + break; 1.283 + case Interpreter::java_lang_math_exp: 1.284 + __ exp_with_fallback(0); 1.285 + break; 1.286 + default : 1.287 + ShouldNotReachHere(); 1.288 + } 1.289 + 1.290 + // return double result in xmm0 for interpreter and compilers. 1.291 + __ subptr(rsp, 2*wordSize); 1.292 + // Round to 64bit precision 1.293 + __ fstp_d(Address(rsp, 0)); 1.294 + __ movdbl(xmm0, Address(rsp, 0)); 1.295 + __ addptr(rsp, 2*wordSize); 1.296 + } 1.297 + 1.298 + 1.299 + __ pop(rax); 1.300 + __ mov(rsp, r13); 1.301 + __ jmp(rax); 1.302 + 1.303 + return entry_point; 1.304 +} 1.305 + 1.306 + 1.307 +// Abstract method entry 1.308 +// Attempt to execute abstract method. Throw exception 1.309 +address InterpreterGenerator::generate_abstract_entry(void) { 1.310 + // rbx: Method* 1.311 + // r13: sender SP 1.312 + 1.313 + address entry_point = __ pc(); 1.314 + 1.315 + // abstract method entry 1.316 + 1.317 + // pop return address, reset last_sp to NULL 1.318 + __ empty_expression_stack(); 1.319 + __ restore_bcp(); // rsi must be correct for exception handler (was destroyed) 1.320 + __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 1.321 + 1.322 + // throw exception 1.323 + __ call_VM(noreg, CAST_FROM_FN_PTR(address, 1.324 + InterpreterRuntime::throw_AbstractMethodError)); 1.325 + // the call_VM checks for exception, so we should never return here. 1.326 + __ should_not_reach_here(); 1.327 + 1.328 + return entry_point; 1.329 +} 1.330 + 1.331 + 1.332 +// Empty method, generate a very fast return. 1.333 + 1.334 +address InterpreterGenerator::generate_empty_entry(void) { 1.335 + // rbx: Method* 1.336 + // r13: sender sp must set sp to this value on return 1.337 + 1.338 + if (!UseFastEmptyMethods) { 1.339 + return NULL; 1.340 + } 1.341 + 1.342 + address entry_point = __ pc(); 1.343 + 1.344 + // If we need a safepoint check, generate full interpreter entry. 1.345 + Label slow_path; 1.346 + __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 1.347 + SafepointSynchronize::_not_synchronized); 1.348 + __ jcc(Assembler::notEqual, slow_path); 1.349 + 1.350 + // do nothing for empty methods (do not even increment invocation counter) 1.351 + // Code: _return 1.352 + // _return 1.353 + // return w/o popping parameters 1.354 + __ pop(rax); 1.355 + __ mov(rsp, r13); 1.356 + __ jmp(rax); 1.357 + 1.358 + __ bind(slow_path); 1.359 + (void) generate_normal_entry(false); 1.360 + return entry_point; 1.361 + 1.362 +} 1.363 + 1.364 +void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { 1.365 + 1.366 + // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in 1.367 + // the days we had adapter frames. When we deoptimize a situation where a 1.368 + // compiled caller calls a compiled caller will have registers it expects 1.369 + // to survive the call to the callee. If we deoptimize the callee the only 1.370 + // way we can restore these registers is to have the oldest interpreter 1.371 + // frame that we create restore these values. That is what this routine 1.372 + // will accomplish. 1.373 + 1.374 + // At the moment we have modified c2 to not have any callee save registers 1.375 + // so this problem does not exist and this routine is just a place holder. 1.376 + 1.377 + assert(f->is_interpreted_frame(), "must be interpreted"); 1.378 +}