src/cpu/x86/vm/cppInterpreter_x86.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8368
32b682649973
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
kevinw@8368 2 * Copyright (c) 2007, 2016, 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/cppInterpreter.hpp"
aoqi@0 29 #include "interpreter/interpreter.hpp"
aoqi@0 30 #include "interpreter/interpreterGenerator.hpp"
aoqi@0 31 #include "interpreter/interpreterRuntime.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 "runtime/arguments.hpp"
aoqi@0 39 #include "runtime/deoptimization.hpp"
aoqi@0 40 #include "runtime/frame.inline.hpp"
aoqi@0 41 #include "runtime/interfaceSupport.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 #include "utilities/macros.hpp"
aoqi@0 49 #ifdef SHARK
aoqi@0 50 #include "shark/shark_globals.hpp"
aoqi@0 51 #endif
aoqi@0 52
aoqi@0 53 #ifdef CC_INTERP
aoqi@0 54
aoqi@0 55 // Routine exists to make tracebacks look decent in debugger
aoqi@0 56 // while we are recursed in the frame manager/c++ interpreter.
aoqi@0 57 // We could use an address in the frame manager but having
aoqi@0 58 // frames look natural in the debugger is a plus.
aoqi@0 59 extern "C" void RecursiveInterpreterActivation(interpreterState istate )
aoqi@0 60 {
aoqi@0 61 //
aoqi@0 62 ShouldNotReachHere();
aoqi@0 63 }
aoqi@0 64
aoqi@0 65
aoqi@0 66 #define __ _masm->
aoqi@0 67 #define STATE(field_name) (Address(state, byte_offset_of(BytecodeInterpreter, field_name)))
aoqi@0 68
aoqi@0 69 Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized
aoqi@0 70 // c++ interpreter entry point this holds that entry point label.
aoqi@0 71
aoqi@0 72 // default registers for state and sender_sp
aoqi@0 73 // state and sender_sp are the same on 32bit because we have no choice.
aoqi@0 74 // state could be rsi on 64bit but it is an arg reg and not callee save
aoqi@0 75 // so r13 is better choice.
aoqi@0 76
aoqi@0 77 const Register state = NOT_LP64(rsi) LP64_ONLY(r13);
aoqi@0 78 const Register sender_sp_on_entry = NOT_LP64(rsi) LP64_ONLY(r13);
aoqi@0 79
aoqi@0 80 // NEEDED for JVMTI?
aoqi@0 81 // address AbstractInterpreter::_remove_activation_preserving_args_entry;
aoqi@0 82
aoqi@0 83 static address unctrap_frame_manager_entry = NULL;
aoqi@0 84
aoqi@0 85 static address deopt_frame_manager_return_atos = NULL;
aoqi@0 86 static address deopt_frame_manager_return_btos = NULL;
aoqi@0 87 static address deopt_frame_manager_return_itos = NULL;
aoqi@0 88 static address deopt_frame_manager_return_ltos = NULL;
aoqi@0 89 static address deopt_frame_manager_return_ftos = NULL;
aoqi@0 90 static address deopt_frame_manager_return_dtos = NULL;
aoqi@0 91 static address deopt_frame_manager_return_vtos = NULL;
aoqi@0 92
aoqi@0 93 int AbstractInterpreter::BasicType_as_index(BasicType type) {
aoqi@0 94 int i = 0;
aoqi@0 95 switch (type) {
aoqi@0 96 case T_BOOLEAN: i = 0; break;
aoqi@0 97 case T_CHAR : i = 1; break;
aoqi@0 98 case T_BYTE : i = 2; break;
aoqi@0 99 case T_SHORT : i = 3; break;
aoqi@0 100 case T_INT : i = 4; break;
aoqi@0 101 case T_VOID : i = 5; break;
aoqi@0 102 case T_FLOAT : i = 8; break;
aoqi@0 103 case T_LONG : i = 9; break;
aoqi@0 104 case T_DOUBLE : i = 6; break;
aoqi@0 105 case T_OBJECT : // fall through
aoqi@0 106 case T_ARRAY : i = 7; break;
aoqi@0 107 default : ShouldNotReachHere();
aoqi@0 108 }
aoqi@0 109 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
aoqi@0 110 return i;
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 // Is this pc anywhere within code owned by the interpreter?
aoqi@0 114 // This only works for pc that might possibly be exposed to frame
aoqi@0 115 // walkers. It clearly misses all of the actual c++ interpreter
aoqi@0 116 // implementation
aoqi@0 117 bool CppInterpreter::contains(address pc) {
aoqi@0 118 return (_code->contains(pc) ||
aoqi@0 119 pc == CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
aoqi@0 120 }
aoqi@0 121
aoqi@0 122
aoqi@0 123 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
aoqi@0 124 address entry = __ pc();
aoqi@0 125 switch (type) {
aoqi@0 126 case T_BOOLEAN: __ c2bool(rax); break;
aoqi@0 127 case T_CHAR : __ andl(rax, 0xFFFF); break;
aoqi@0 128 case T_BYTE : __ sign_extend_byte (rax); break;
aoqi@0 129 case T_SHORT : __ sign_extend_short(rax); break;
aoqi@0 130 case T_VOID : // fall thru
aoqi@0 131 case T_LONG : // fall thru
aoqi@0 132 case T_INT : /* nothing to do */ break;
aoqi@0 133
aoqi@0 134 case T_DOUBLE :
aoqi@0 135 case T_FLOAT :
aoqi@0 136 {
aoqi@0 137 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
aoqi@0 138 __ pop(t); // remove return address first
aoqi@0 139 // Must return a result for interpreter or compiler. In SSE
aoqi@0 140 // mode, results are returned in xmm0 and the FPU stack must
aoqi@0 141 // be empty.
aoqi@0 142 if (type == T_FLOAT && UseSSE >= 1) {
aoqi@0 143 #ifndef _LP64
aoqi@0 144 // Load ST0
aoqi@0 145 __ fld_d(Address(rsp, 0));
aoqi@0 146 // Store as float and empty fpu stack
aoqi@0 147 __ fstp_s(Address(rsp, 0));
aoqi@0 148 #endif // !_LP64
aoqi@0 149 // and reload
aoqi@0 150 __ movflt(xmm0, Address(rsp, 0));
aoqi@0 151 } else if (type == T_DOUBLE && UseSSE >= 2 ) {
aoqi@0 152 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 153 } else {
aoqi@0 154 // restore ST0
aoqi@0 155 __ fld_d(Address(rsp, 0));
aoqi@0 156 }
aoqi@0 157 // and pop the temp
aoqi@0 158 __ addptr(rsp, 2 * wordSize);
aoqi@0 159 __ push(t); // restore return address
aoqi@0 160 }
aoqi@0 161 break;
aoqi@0 162 case T_OBJECT :
aoqi@0 163 // retrieve result from frame
aoqi@0 164 __ movptr(rax, STATE(_oop_temp));
aoqi@0 165 // and verify it
aoqi@0 166 __ verify_oop(rax);
aoqi@0 167 break;
aoqi@0 168 default : ShouldNotReachHere();
aoqi@0 169 }
aoqi@0 170 __ ret(0); // return from result handler
aoqi@0 171 return entry;
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // tosca based result to c++ interpreter stack based result.
aoqi@0 175 // Result goes to top of native stack.
aoqi@0 176
aoqi@0 177 #undef EXTEND // SHOULD NOT BE NEEDED
aoqi@0 178 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
aoqi@0 179 // A result is in the tosca (abi result) from either a native method call or compiled
aoqi@0 180 // code. Place this result on the java expression stack so C++ interpreter can use it.
aoqi@0 181 address entry = __ pc();
aoqi@0 182
aoqi@0 183 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
aoqi@0 184 __ pop(t); // remove return address first
aoqi@0 185 switch (type) {
aoqi@0 186 case T_VOID:
aoqi@0 187 break;
aoqi@0 188 case T_BOOLEAN:
aoqi@0 189 #ifdef EXTEND
aoqi@0 190 __ c2bool(rax);
aoqi@0 191 #endif
aoqi@0 192 __ push(rax);
aoqi@0 193 break;
aoqi@0 194 case T_CHAR :
aoqi@0 195 #ifdef EXTEND
aoqi@0 196 __ andl(rax, 0xFFFF);
aoqi@0 197 #endif
aoqi@0 198 __ push(rax);
aoqi@0 199 break;
aoqi@0 200 case T_BYTE :
aoqi@0 201 #ifdef EXTEND
aoqi@0 202 __ sign_extend_byte (rax);
aoqi@0 203 #endif
aoqi@0 204 __ push(rax);
aoqi@0 205 break;
aoqi@0 206 case T_SHORT :
aoqi@0 207 #ifdef EXTEND
aoqi@0 208 __ sign_extend_short(rax);
aoqi@0 209 #endif
aoqi@0 210 __ push(rax);
aoqi@0 211 break;
aoqi@0 212 case T_LONG :
aoqi@0 213 __ push(rdx); // pushes useless junk on 64bit
aoqi@0 214 __ push(rax);
aoqi@0 215 break;
aoqi@0 216 case T_INT :
aoqi@0 217 __ push(rax);
aoqi@0 218 break;
aoqi@0 219 case T_FLOAT :
aoqi@0 220 // Result is in ST(0)/xmm0
aoqi@0 221 __ subptr(rsp, wordSize);
aoqi@0 222 if ( UseSSE < 1) {
aoqi@0 223 __ fstp_s(Address(rsp, 0));
aoqi@0 224 } else {
aoqi@0 225 __ movflt(Address(rsp, 0), xmm0);
aoqi@0 226 }
aoqi@0 227 break;
aoqi@0 228 case T_DOUBLE :
aoqi@0 229 __ subptr(rsp, 2*wordSize);
aoqi@0 230 if ( UseSSE < 2 ) {
aoqi@0 231 __ fstp_d(Address(rsp, 0));
aoqi@0 232 } else {
aoqi@0 233 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 234 }
aoqi@0 235 break;
aoqi@0 236 case T_OBJECT :
aoqi@0 237 __ verify_oop(rax); // verify it
aoqi@0 238 __ push(rax);
aoqi@0 239 break;
aoqi@0 240 default : ShouldNotReachHere();
aoqi@0 241 }
aoqi@0 242 __ jmp(t); // return from result handler
aoqi@0 243 return entry;
aoqi@0 244 }
aoqi@0 245
aoqi@0 246 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
aoqi@0 247 // A result is in the java expression stack of the interpreted method that has just
aoqi@0 248 // returned. Place this result on the java expression stack of the caller.
aoqi@0 249 //
aoqi@0 250 // The current interpreter activation in rsi/r13 is for the method just returning its
aoqi@0 251 // result. So we know that the result of this method is on the top of the current
aoqi@0 252 // execution stack (which is pre-pushed) and will be return to the top of the caller
aoqi@0 253 // stack. The top of the callers stack is the bottom of the locals of the current
aoqi@0 254 // activation.
aoqi@0 255 // Because of the way activation are managed by the frame manager the value of rsp is
aoqi@0 256 // below both the stack top of the current activation and naturally the stack top
aoqi@0 257 // of the calling activation. This enable this routine to leave the return address
aoqi@0 258 // to the frame manager on the stack and do a vanilla return.
aoqi@0 259 //
aoqi@0 260 // On entry: rsi/r13 - interpreter state of activation returning a (potential) result
aoqi@0 261 // On Return: rsi/r13 - unchanged
aoqi@0 262 // rax - new stack top for caller activation (i.e. activation in _prev_link)
aoqi@0 263 //
aoqi@0 264 // Can destroy rdx, rcx.
aoqi@0 265 //
aoqi@0 266
aoqi@0 267 address entry = __ pc();
aoqi@0 268 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
aoqi@0 269 switch (type) {
aoqi@0 270 case T_VOID:
aoqi@0 271 __ movptr(rax, STATE(_locals)); // pop parameters get new stack value
aoqi@0 272 __ addptr(rax, wordSize); // account for prepush before we return
aoqi@0 273 break;
aoqi@0 274 case T_FLOAT :
aoqi@0 275 case T_BOOLEAN:
aoqi@0 276 case T_CHAR :
aoqi@0 277 case T_BYTE :
aoqi@0 278 case T_SHORT :
aoqi@0 279 case T_INT :
aoqi@0 280 // 1 word result
aoqi@0 281 __ movptr(rdx, STATE(_stack));
aoqi@0 282 __ movptr(rax, STATE(_locals)); // address for result
aoqi@0 283 __ movl(rdx, Address(rdx, wordSize)); // get result
aoqi@0 284 __ movptr(Address(rax, 0), rdx); // and store it
aoqi@0 285 break;
aoqi@0 286 case T_LONG :
aoqi@0 287 case T_DOUBLE :
aoqi@0 288 // return top two words on current expression stack to caller's expression stack
aoqi@0 289 // The caller's expression stack is adjacent to the current frame manager's intepretState
aoqi@0 290 // except we allocated one extra word for this intepretState so we won't overwrite it
aoqi@0 291 // when we return a two word result.
aoqi@0 292
aoqi@0 293 __ movptr(rax, STATE(_locals)); // address for result
aoqi@0 294 __ movptr(rcx, STATE(_stack));
aoqi@0 295 __ subptr(rax, wordSize); // need addition word besides locals[0]
aoqi@0 296 __ movptr(rdx, Address(rcx, 2*wordSize)); // get result word (junk in 64bit)
aoqi@0 297 __ movptr(Address(rax, wordSize), rdx); // and store it
aoqi@0 298 __ movptr(rdx, Address(rcx, wordSize)); // get result word
aoqi@0 299 __ movptr(Address(rax, 0), rdx); // and store it
aoqi@0 300 break;
aoqi@0 301 case T_OBJECT :
aoqi@0 302 __ movptr(rdx, STATE(_stack));
aoqi@0 303 __ movptr(rax, STATE(_locals)); // address for result
aoqi@0 304 __ movptr(rdx, Address(rdx, wordSize)); // get result
aoqi@0 305 __ verify_oop(rdx); // verify it
aoqi@0 306 __ movptr(Address(rax, 0), rdx); // and store it
aoqi@0 307 break;
aoqi@0 308 default : ShouldNotReachHere();
aoqi@0 309 }
aoqi@0 310 __ ret(0);
aoqi@0 311 return entry;
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
aoqi@0 315 // A result is in the java expression stack of the interpreted method that has just
aoqi@0 316 // returned. Place this result in the native abi that the caller expects.
aoqi@0 317 //
aoqi@0 318 // Similar to generate_stack_to_stack_converter above. Called at a similar time from the
aoqi@0 319 // frame manager execept in this situation the caller is native code (c1/c2/call_stub)
aoqi@0 320 // and so rather than return result onto caller's java expression stack we return the
aoqi@0 321 // result in the expected location based on the native abi.
aoqi@0 322 // On entry: rsi/r13 - interpreter state of activation returning a (potential) result
aoqi@0 323 // On Return: rsi/r13 - unchanged
aoqi@0 324 // Other registers changed [rax/rdx/ST(0) as needed for the result returned]
aoqi@0 325
aoqi@0 326 address entry = __ pc();
aoqi@0 327 switch (type) {
aoqi@0 328 case T_VOID:
aoqi@0 329 break;
aoqi@0 330 case T_BOOLEAN:
aoqi@0 331 case T_CHAR :
aoqi@0 332 case T_BYTE :
aoqi@0 333 case T_SHORT :
aoqi@0 334 case T_INT :
aoqi@0 335 __ movptr(rdx, STATE(_stack)); // get top of stack
aoqi@0 336 __ movl(rax, Address(rdx, wordSize)); // get result word 1
aoqi@0 337 break;
aoqi@0 338 case T_LONG :
aoqi@0 339 __ movptr(rdx, STATE(_stack)); // get top of stack
aoqi@0 340 __ movptr(rax, Address(rdx, wordSize)); // get result low word
aoqi@0 341 NOT_LP64(__ movl(rdx, Address(rdx, 2*wordSize));) // get result high word
aoqi@0 342 break;
aoqi@0 343 case T_FLOAT :
aoqi@0 344 __ movptr(rdx, STATE(_stack)); // get top of stack
aoqi@0 345 if ( UseSSE >= 1) {
aoqi@0 346 __ movflt(xmm0, Address(rdx, wordSize));
aoqi@0 347 } else {
aoqi@0 348 __ fld_s(Address(rdx, wordSize)); // pushd float result
aoqi@0 349 }
aoqi@0 350 break;
aoqi@0 351 case T_DOUBLE :
aoqi@0 352 __ movptr(rdx, STATE(_stack)); // get top of stack
aoqi@0 353 if ( UseSSE > 1) {
aoqi@0 354 __ movdbl(xmm0, Address(rdx, wordSize));
aoqi@0 355 } else {
aoqi@0 356 __ fld_d(Address(rdx, wordSize)); // push double result
aoqi@0 357 }
aoqi@0 358 break;
aoqi@0 359 case T_OBJECT :
aoqi@0 360 __ movptr(rdx, STATE(_stack)); // get top of stack
aoqi@0 361 __ movptr(rax, Address(rdx, wordSize)); // get result word 1
aoqi@0 362 __ verify_oop(rax); // verify it
aoqi@0 363 break;
aoqi@0 364 default : ShouldNotReachHere();
aoqi@0 365 }
aoqi@0 366 __ ret(0);
aoqi@0 367 return entry;
aoqi@0 368 }
aoqi@0 369
aoqi@0 370 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
aoqi@0 371 // make it look good in the debugger
aoqi@0 372 return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation);
aoqi@0 373 }
aoqi@0 374
aoqi@0 375 address CppInterpreter::deopt_entry(TosState state, int length) {
aoqi@0 376 address ret = NULL;
aoqi@0 377 if (length != 0) {
aoqi@0 378 switch (state) {
aoqi@0 379 case atos: ret = deopt_frame_manager_return_atos; break;
aoqi@0 380 case btos: ret = deopt_frame_manager_return_btos; break;
aoqi@0 381 case ctos:
aoqi@0 382 case stos:
aoqi@0 383 case itos: ret = deopt_frame_manager_return_itos; break;
aoqi@0 384 case ltos: ret = deopt_frame_manager_return_ltos; break;
aoqi@0 385 case ftos: ret = deopt_frame_manager_return_ftos; break;
aoqi@0 386 case dtos: ret = deopt_frame_manager_return_dtos; break;
aoqi@0 387 case vtos: ret = deopt_frame_manager_return_vtos; break;
aoqi@0 388 }
aoqi@0 389 } else {
aoqi@0 390 ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap)
aoqi@0 391 }
aoqi@0 392 assert(ret != NULL, "Not initialized");
aoqi@0 393 return ret;
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 // C++ Interpreter
aoqi@0 397 void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,
aoqi@0 398 const Register locals,
aoqi@0 399 const Register sender_sp,
aoqi@0 400 bool native) {
aoqi@0 401
aoqi@0 402 // On entry the "locals" argument points to locals[0] (or where it would be in case no locals in
aoqi@0 403 // a static method). "state" contains any previous frame manager state which we must save a link
aoqi@0 404 // to in the newly generated state object. On return "state" is a pointer to the newly allocated
aoqi@0 405 // state object. We must allocate and initialize a new interpretState object and the method
aoqi@0 406 // expression stack. Because the returned result (if any) of the method will be placed on the caller's
aoqi@0 407 // expression stack and this will overlap with locals[0] (and locals[1] if double/long) we must
aoqi@0 408 // be sure to leave space on the caller's stack so that this result will not overwrite values when
aoqi@0 409 // locals[0] and locals[1] do not exist (and in fact are return address and saved rbp). So when
aoqi@0 410 // we are non-native we in essence ensure that locals[0-1] exist. We play an extra trick in
aoqi@0 411 // non-product builds and initialize this last local with the previous interpreterState as
aoqi@0 412 // this makes things look real nice in the debugger.
aoqi@0 413
aoqi@0 414 // State on entry
aoqi@0 415 // Assumes locals == &locals[0]
aoqi@0 416 // Assumes state == any previous frame manager state (assuming call path from c++ interpreter)
aoqi@0 417 // Assumes rax = return address
aoqi@0 418 // rcx == senders_sp
aoqi@0 419 // rbx == method
aoqi@0 420 // Modifies rcx, rdx, rax
aoqi@0 421 // Returns:
aoqi@0 422 // state == address of new interpreterState
aoqi@0 423 // rsp == bottom of method's expression stack.
aoqi@0 424
aoqi@0 425 const Address const_offset (rbx, Method::const_offset());
aoqi@0 426
aoqi@0 427
aoqi@0 428 // On entry sp is the sender's sp. This includes the space for the arguments
aoqi@0 429 // that the sender pushed. If the sender pushed no args (a static) and the
aoqi@0 430 // caller returns a long then we need two words on the sender's stack which
aoqi@0 431 // are not present (although when we return a restore full size stack the
aoqi@0 432 // space will be present). If we didn't allocate two words here then when
aoqi@0 433 // we "push" the result of the caller's stack we would overwrite the return
aoqi@0 434 // address and the saved rbp. Not good. So simply allocate 2 words now
aoqi@0 435 // just to be safe. This is the "static long no_params() method" issue.
aoqi@0 436 // See Lo.java for a testcase.
aoqi@0 437 // We don't need this for native calls because they return result in
aoqi@0 438 // register and the stack is expanded in the caller before we store
aoqi@0 439 // the results on the stack.
aoqi@0 440
aoqi@0 441 if (!native) {
aoqi@0 442 #ifdef PRODUCT
aoqi@0 443 __ subptr(rsp, 2*wordSize);
aoqi@0 444 #else /* PRODUCT */
aoqi@0 445 __ push((int32_t)NULL_WORD);
aoqi@0 446 __ push(state); // make it look like a real argument
aoqi@0 447 #endif /* PRODUCT */
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 // Now that we are assure of space for stack result, setup typical linkage
aoqi@0 451
aoqi@0 452 __ push(rax);
aoqi@0 453 __ enter();
aoqi@0 454
aoqi@0 455 __ mov(rax, state); // save current state
aoqi@0 456
aoqi@0 457 __ lea(rsp, Address(rsp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 458 __ mov(state, rsp);
aoqi@0 459
aoqi@0 460 // rsi/r13 == state/locals rax == prevstate
aoqi@0 461
aoqi@0 462 // initialize the "shadow" frame so that use since C++ interpreter not directly
aoqi@0 463 // recursive. Simpler to recurse but we can't trim expression stack as we call
aoqi@0 464 // new methods.
aoqi@0 465 __ movptr(STATE(_locals), locals); // state->_locals = locals()
aoqi@0 466 __ movptr(STATE(_self_link), state); // point to self
aoqi@0 467 __ movptr(STATE(_prev_link), rax); // state->_link = state on entry (NULL or previous state)
aoqi@0 468 __ movptr(STATE(_sender_sp), sender_sp); // state->_sender_sp = sender_sp
aoqi@0 469 #ifdef _LP64
aoqi@0 470 __ movptr(STATE(_thread), r15_thread); // state->_bcp = codes()
aoqi@0 471 #else
aoqi@0 472 __ get_thread(rax); // get vm's javathread*
aoqi@0 473 __ movptr(STATE(_thread), rax); // state->_bcp = codes()
aoqi@0 474 #endif // _LP64
aoqi@0 475 __ movptr(rdx, Address(rbx, Method::const_offset())); // get constantMethodOop
aoqi@0 476 __ lea(rdx, Address(rdx, ConstMethod::codes_offset())); // get code base
aoqi@0 477 if (native) {
aoqi@0 478 __ movptr(STATE(_bcp), (int32_t)NULL_WORD); // state->_bcp = NULL
aoqi@0 479 } else {
aoqi@0 480 __ movptr(STATE(_bcp), rdx); // state->_bcp = codes()
aoqi@0 481 }
aoqi@0 482 __ xorptr(rdx, rdx);
aoqi@0 483 __ movptr(STATE(_oop_temp), rdx); // state->_oop_temp = NULL (only really needed for native)
aoqi@0 484 __ movptr(STATE(_mdx), rdx); // state->_mdx = NULL
aoqi@0 485 __ movptr(rdx, Address(rbx, Method::const_offset()));
aoqi@0 486 __ movptr(rdx, Address(rdx, ConstMethod::constants_offset()));
aoqi@0 487 __ movptr(rdx, Address(rdx, ConstantPool::cache_offset_in_bytes()));
aoqi@0 488 __ movptr(STATE(_constants), rdx); // state->_constants = constants()
aoqi@0 489
aoqi@0 490 __ movptr(STATE(_method), rbx); // state->_method = method()
aoqi@0 491 __ movl(STATE(_msg), (int32_t) BytecodeInterpreter::method_entry); // state->_msg = initial method entry
aoqi@0 492 __ movptr(STATE(_result._to_call._callee), (int32_t) NULL_WORD); // state->_result._to_call._callee_callee = NULL
aoqi@0 493
aoqi@0 494
aoqi@0 495 __ movptr(STATE(_monitor_base), rsp); // set monitor block bottom (grows down) this would point to entry [0]
aoqi@0 496 // entries run from -1..x where &monitor[x] ==
aoqi@0 497
aoqi@0 498 {
aoqi@0 499 // Must not attempt to lock method until we enter interpreter as gc won't be able to find the
aoqi@0 500 // initial frame. However we allocate a free monitor so we don't have to shuffle the expression stack
aoqi@0 501 // immediately.
aoqi@0 502
aoqi@0 503 // synchronize method
aoqi@0 504 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 505 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 506 Label not_synced;
aoqi@0 507
aoqi@0 508 __ movl(rax, access_flags);
aoqi@0 509 __ testl(rax, JVM_ACC_SYNCHRONIZED);
aoqi@0 510 __ jcc(Assembler::zero, not_synced);
aoqi@0 511
aoqi@0 512 // Allocate initial monitor and pre initialize it
aoqi@0 513 // get synchronization object
aoqi@0 514
aoqi@0 515 Label done;
aoqi@0 516 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 517 __ movl(rax, access_flags);
aoqi@0 518 __ testl(rax, JVM_ACC_STATIC);
aoqi@0 519 __ movptr(rax, Address(locals, 0)); // get receiver (assume this is frequent case)
aoqi@0 520 __ jcc(Assembler::zero, done);
aoqi@0 521 __ movptr(rax, Address(rbx, Method::const_offset()));
aoqi@0 522 __ movptr(rax, Address(rax, ConstMethod::constants_offset()));
aoqi@0 523 __ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes()));
aoqi@0 524 __ movptr(rax, Address(rax, mirror_offset));
aoqi@0 525 __ bind(done);
aoqi@0 526 // add space for monitor & lock
aoqi@0 527 __ subptr(rsp, entry_size); // add space for a monitor entry
aoqi@0 528 __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
aoqi@0 529 __ bind(not_synced);
aoqi@0 530 }
aoqi@0 531
aoqi@0 532 __ movptr(STATE(_stack_base), rsp); // set expression stack base ( == &monitors[-count])
aoqi@0 533 if (native) {
aoqi@0 534 __ movptr(STATE(_stack), rsp); // set current expression stack tos
aoqi@0 535 __ movptr(STATE(_stack_limit), rsp);
aoqi@0 536 } else {
aoqi@0 537 __ subptr(rsp, wordSize); // pre-push stack
aoqi@0 538 __ movptr(STATE(_stack), rsp); // set current expression stack tos
aoqi@0 539
aoqi@0 540 // compute full expression stack limit
aoqi@0 541
aoqi@0 542 __ movptr(rdx, Address(rbx, Method::const_offset()));
aoqi@0 543 __ load_unsigned_short(rdx, Address(rdx, ConstMethod::max_stack_offset())); // get size of expression stack in words
aoqi@0 544 __ negptr(rdx); // so we can subtract in next step
aoqi@0 545 // Allocate expression stack
aoqi@0 546 __ lea(rsp, Address(rsp, rdx, Address::times_ptr, -Method::extra_stack_words()));
aoqi@0 547 __ movptr(STATE(_stack_limit), rsp);
aoqi@0 548 }
aoqi@0 549
aoqi@0 550 #ifdef _LP64
aoqi@0 551 // Make sure stack is properly aligned and sized for the abi
aoqi@0 552 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 553 __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 554 #endif // _LP64
aoqi@0 555
aoqi@0 556
aoqi@0 557
aoqi@0 558 }
aoqi@0 559
aoqi@0 560 // Helpers for commoning out cases in the various type of method entries.
aoqi@0 561 //
aoqi@0 562
aoqi@0 563 // increment invocation count & check for overflow
aoqi@0 564 //
aoqi@0 565 // Note: checking for negative value instead of overflow
aoqi@0 566 // so we have a 'sticky' overflow test
aoqi@0 567 //
aoqi@0 568 // rbx,: method
aoqi@0 569 // rcx: invocation counter
aoqi@0 570 //
aoqi@0 571 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
aoqi@0 572 Label done;
aoqi@0 573 const Address invocation_counter(rax,
aoqi@0 574 MethodCounters::invocation_counter_offset() +
aoqi@0 575 InvocationCounter::counter_offset());
aoqi@0 576 const Address backedge_counter (rax,
aoqi@0 577 MethodCounter::backedge_counter_offset() +
aoqi@0 578 InvocationCounter::counter_offset());
aoqi@0 579
aoqi@0 580 __ get_method_counters(rbx, rax, done);
aoqi@0 581
aoqi@0 582 if (ProfileInterpreter) {
aoqi@0 583 __ incrementl(Address(rax,
aoqi@0 584 MethodCounters::interpreter_invocation_counter_offset()));
aoqi@0 585 }
aoqi@0 586 // Update standard invocation counters
aoqi@0 587 __ movl(rcx, invocation_counter);
aoqi@0 588 __ increment(rcx, InvocationCounter::count_increment);
aoqi@0 589 __ movl(invocation_counter, rcx); // save invocation count
aoqi@0 590
aoqi@0 591 __ movl(rax, backedge_counter); // load backedge counter
aoqi@0 592 __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
aoqi@0 593
aoqi@0 594 __ addl(rcx, rax); // add both counters
aoqi@0 595
aoqi@0 596 // profile_method is non-null only for interpreted method so
aoqi@0 597 // profile_method != NULL == !native_call
aoqi@0 598 // BytecodeInterpreter only calls for native so code is elided.
aoqi@0 599
aoqi@0 600 __ cmp32(rcx,
aoqi@0 601 ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
aoqi@0 602 __ jcc(Assembler::aboveEqual, *overflow);
aoqi@0 603 __ bind(done);
aoqi@0 604 }
aoqi@0 605
aoqi@0 606 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
aoqi@0 607
aoqi@0 608 // C++ interpreter on entry
aoqi@0 609 // rsi/r13 - new interpreter state pointer
aoqi@0 610 // rbp - interpreter frame pointer
aoqi@0 611 // rbx - method
aoqi@0 612
aoqi@0 613 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
aoqi@0 614 // rbx, - method
aoqi@0 615 // rcx - rcvr (assuming there is one)
aoqi@0 616 // top of stack return address of interpreter caller
aoqi@0 617 // rsp - sender_sp
aoqi@0 618
aoqi@0 619 // C++ interpreter only
aoqi@0 620 // rsi/r13 - previous interpreter state pointer
aoqi@0 621
aoqi@0 622 // InterpreterRuntime::frequency_counter_overflow takes one argument
aoqi@0 623 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
aoqi@0 624 // The call returns the address of the verified entry point for the method or NULL
aoqi@0 625 // if the compilation did not complete (either went background or bailed out).
aoqi@0 626 __ movptr(rax, (int32_t)false);
aoqi@0 627 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
aoqi@0 628
aoqi@0 629 // for c++ interpreter can rsi really be munged?
aoqi@0 630 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); // restore state
aoqi@0 631 __ movptr(rbx, Address(state, byte_offset_of(BytecodeInterpreter, _method))); // restore method
aoqi@0 632 __ movptr(rdi, Address(state, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer
aoqi@0 633
aoqi@0 634 __ jmp(*do_continue, relocInfo::none);
aoqi@0 635
aoqi@0 636 }
aoqi@0 637
aoqi@0 638 void InterpreterGenerator::generate_stack_overflow_check(void) {
aoqi@0 639 // see if we've got enough room on the stack for locals plus overhead.
aoqi@0 640 // the expression stack grows down incrementally, so the normal guard
aoqi@0 641 // page mechanism will work for that.
aoqi@0 642 //
aoqi@0 643 // Registers live on entry:
aoqi@0 644 //
aoqi@0 645 // Asm interpreter
aoqi@0 646 // rdx: number of additional locals this frame needs (what we must check)
aoqi@0 647 // rbx,: Method*
aoqi@0 648
aoqi@0 649 // C++ Interpreter
aoqi@0 650 // rsi/r13: previous interpreter frame state object
aoqi@0 651 // rdi: &locals[0]
aoqi@0 652 // rcx: # of locals
aoqi@0 653 // rdx: number of additional locals this frame needs (what we must check)
aoqi@0 654 // rbx: Method*
aoqi@0 655
aoqi@0 656 // destroyed on exit
aoqi@0 657 // rax,
aoqi@0 658
aoqi@0 659 // NOTE: since the additional locals are also always pushed (wasn't obvious in
aoqi@0 660 // generate_method_entry) so the guard should work for them too.
aoqi@0 661 //
aoqi@0 662
aoqi@0 663 // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
aoqi@0 664 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 665
aoqi@0 666 // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
aoqi@0 667 // be sure to change this if you add/subtract anything to/from the overhead area
aoqi@0 668 const int overhead_size = (int)sizeof(BytecodeInterpreter);
aoqi@0 669
aoqi@0 670 const int page_size = os::vm_page_size();
aoqi@0 671
aoqi@0 672 Label after_frame_check;
aoqi@0 673
aoqi@0 674 // compute rsp as if this were going to be the last frame on
aoqi@0 675 // the stack before the red zone
aoqi@0 676
aoqi@0 677 Label after_frame_check_pop;
aoqi@0 678
aoqi@0 679 // save rsi == caller's bytecode ptr (c++ previous interp. state)
aoqi@0 680 // QQQ problem here?? rsi overload????
aoqi@0 681 __ push(state);
aoqi@0 682
aoqi@0 683 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rsi);
aoqi@0 684
aoqi@0 685 NOT_LP64(__ get_thread(thread));
aoqi@0 686
aoqi@0 687 const Address stack_base(thread, Thread::stack_base_offset());
aoqi@0 688 const Address stack_size(thread, Thread::stack_size_offset());
aoqi@0 689
aoqi@0 690 // locals + overhead, in bytes
aoqi@0 691 // Always give one monitor to allow us to start interp if sync method.
aoqi@0 692 // Any additional monitors need a check when moving the expression stack
aoqi@0 693 const int one_monitor = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 694 __ movptr(rax, Address(rbx, Method::const_offset()));
aoqi@0 695 __ load_unsigned_short(rax, Address(rax, ConstMethod::max_stack_offset())); // get size of expression stack in words
aoqi@0 696 __ lea(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor+Method::extra_stack_words()));
aoqi@0 697 __ lea(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));
aoqi@0 698
aoqi@0 699 #ifdef ASSERT
aoqi@0 700 Label stack_base_okay, stack_size_okay;
aoqi@0 701 // verify that thread stack base is non-zero
aoqi@0 702 __ cmpptr(stack_base, (int32_t)0);
aoqi@0 703 __ jcc(Assembler::notEqual, stack_base_okay);
aoqi@0 704 __ stop("stack base is zero");
aoqi@0 705 __ bind(stack_base_okay);
aoqi@0 706 // verify that thread stack size is non-zero
aoqi@0 707 __ cmpptr(stack_size, (int32_t)0);
aoqi@0 708 __ jcc(Assembler::notEqual, stack_size_okay);
aoqi@0 709 __ stop("stack size is zero");
aoqi@0 710 __ bind(stack_size_okay);
aoqi@0 711 #endif
aoqi@0 712
aoqi@0 713 // Add stack base to locals and subtract stack size
aoqi@0 714 __ addptr(rax, stack_base);
aoqi@0 715 __ subptr(rax, stack_size);
aoqi@0 716
aoqi@0 717 // We should have a magic number here for the size of the c++ interpreter frame.
aoqi@0 718 // We can't actually tell this ahead of time. The debug version size is around 3k
aoqi@0 719 // product is 1k and fastdebug is 4k
aoqi@0 720 const int slop = 6 * K;
aoqi@0 721
aoqi@0 722 // Use the maximum number of pages we might bang.
aoqi@0 723 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
aoqi@0 724 (StackRedPages+StackYellowPages);
aoqi@0 725 // Only need this if we are stack banging which is temporary while
aoqi@0 726 // we're debugging.
aoqi@0 727 __ addptr(rax, slop + 2*max_pages * page_size);
aoqi@0 728
aoqi@0 729 // check against the current stack bottom
aoqi@0 730 __ cmpptr(rsp, rax);
aoqi@0 731 __ jcc(Assembler::above, after_frame_check_pop);
aoqi@0 732
aoqi@0 733 __ pop(state); // get c++ prev state.
aoqi@0 734
aoqi@0 735 // throw exception return address becomes throwing pc
aoqi@0 736 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
aoqi@0 737
aoqi@0 738 // all done with frame size check
aoqi@0 739 __ bind(after_frame_check_pop);
aoqi@0 740 __ pop(state);
aoqi@0 741
aoqi@0 742 __ bind(after_frame_check);
aoqi@0 743 }
aoqi@0 744
aoqi@0 745 // Find preallocated monitor and lock method (C++ interpreter)
aoqi@0 746 // rbx - Method*
aoqi@0 747 //
aoqi@0 748 void InterpreterGenerator::lock_method(void) {
aoqi@0 749 // assumes state == rsi/r13 == pointer to current interpreterState
aoqi@0 750 // minimally destroys rax, rdx|c_rarg1, rdi
aoqi@0 751 //
aoqi@0 752 // synchronize method
aoqi@0 753 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 754 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 755
aoqi@0 756 const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
aoqi@0 757
aoqi@0 758 // find initial monitor i.e. monitors[-1]
aoqi@0 759 __ movptr(monitor, STATE(_monitor_base)); // get monitor bottom limit
aoqi@0 760 __ subptr(monitor, entry_size); // point to initial monitor
aoqi@0 761
aoqi@0 762 #ifdef ASSERT
aoqi@0 763 { Label L;
aoqi@0 764 __ movl(rax, access_flags);
aoqi@0 765 __ testl(rax, JVM_ACC_SYNCHRONIZED);
aoqi@0 766 __ jcc(Assembler::notZero, L);
aoqi@0 767 __ stop("method doesn't need synchronization");
aoqi@0 768 __ bind(L);
aoqi@0 769 }
aoqi@0 770 #endif // ASSERT
aoqi@0 771 // get synchronization object
aoqi@0 772 { Label done;
aoqi@0 773 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 774 __ movl(rax, access_flags);
aoqi@0 775 __ movptr(rdi, STATE(_locals)); // prepare to get receiver (assume common case)
aoqi@0 776 __ testl(rax, JVM_ACC_STATIC);
aoqi@0 777 __ movptr(rax, Address(rdi, 0)); // get receiver (assume this is frequent case)
aoqi@0 778 __ jcc(Assembler::zero, done);
aoqi@0 779 __ movptr(rax, Address(rbx, Method::const_offset()));
aoqi@0 780 __ movptr(rax, Address(rax, ConstMethod::constants_offset()));
aoqi@0 781 __ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes()));
aoqi@0 782 __ movptr(rax, Address(rax, mirror_offset));
aoqi@0 783 __ bind(done);
aoqi@0 784 }
aoqi@0 785 #ifdef ASSERT
aoqi@0 786 { Label L;
aoqi@0 787 __ cmpptr(rax, Address(monitor, BasicObjectLock::obj_offset_in_bytes())); // correct object?
aoqi@0 788 __ jcc(Assembler::equal, L);
aoqi@0 789 __ stop("wrong synchronization lobject");
aoqi@0 790 __ bind(L);
aoqi@0 791 }
aoqi@0 792 #endif // ASSERT
aoqi@0 793 // can destroy rax, rdx|c_rarg1, rcx, and (via call_VM) rdi!
aoqi@0 794 __ lock_object(monitor);
aoqi@0 795 }
aoqi@0 796
aoqi@0 797 // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
aoqi@0 798
aoqi@0 799 address InterpreterGenerator::generate_accessor_entry(void) {
aoqi@0 800
aoqi@0 801 // rbx: Method*
aoqi@0 802
aoqi@0 803 // rsi/r13: senderSP must preserved for slow path, set SP to it on fast path
aoqi@0 804
aoqi@0 805 Label xreturn_path;
aoqi@0 806
aoqi@0 807 // do fastpath for resolved accessor methods
aoqi@0 808 if (UseFastAccessorMethods) {
aoqi@0 809
aoqi@0 810 address entry_point = __ pc();
aoqi@0 811
aoqi@0 812 Label slow_path;
aoqi@0 813 // If we need a safepoint check, generate full interpreter entry.
aoqi@0 814 ExternalAddress state(SafepointSynchronize::address_of_state());
aoqi@0 815 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
aoqi@0 816 SafepointSynchronize::_not_synchronized);
aoqi@0 817
aoqi@0 818 __ jcc(Assembler::notEqual, slow_path);
aoqi@0 819 // ASM/C++ Interpreter
aoqi@0 820 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
aoqi@0 821 // Note: We can only use this code if the getfield has been resolved
aoqi@0 822 // and if we don't have a null-pointer exception => check for
aoqi@0 823 // these conditions first and use slow path if necessary.
aoqi@0 824 // rbx,: method
aoqi@0 825 // rcx: receiver
aoqi@0 826 __ movptr(rax, Address(rsp, wordSize));
aoqi@0 827
aoqi@0 828 // check if local 0 != NULL and read field
aoqi@0 829 __ testptr(rax, rax);
aoqi@0 830 __ jcc(Assembler::zero, slow_path);
aoqi@0 831
aoqi@0 832 // read first instruction word and extract bytecode @ 1 and index @ 2
aoqi@0 833 __ movptr(rdx, Address(rbx, Method::const_offset()));
aoqi@0 834 __ movptr(rdi, Address(rdx, ConstMethod::constants_offset()));
aoqi@0 835 __ movl(rdx, Address(rdx, ConstMethod::codes_offset()));
aoqi@0 836 // Shift codes right to get the index on the right.
aoqi@0 837 // The bytecode fetched looks like <index><0xb4><0x2a>
aoqi@0 838 __ shrl(rdx, 2*BitsPerByte);
aoqi@0 839 __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
aoqi@0 840 __ movptr(rdi, Address(rdi, ConstantPool::cache_offset_in_bytes()));
aoqi@0 841
aoqi@0 842 // rax,: local 0
aoqi@0 843 // rbx,: method
aoqi@0 844 // rcx: receiver - do not destroy since it is needed for slow path!
aoqi@0 845 // rcx: scratch
aoqi@0 846 // rdx: constant pool cache index
aoqi@0 847 // rdi: constant pool cache
aoqi@0 848 // rsi/r13: sender sp
aoqi@0 849
aoqi@0 850 // check if getfield has been resolved and read constant pool cache entry
aoqi@0 851 // check the validity of the cache entry by testing whether _indices field
aoqi@0 852 // contains Bytecode::_getfield in b1 byte.
aoqi@0 853 assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
aoqi@0 854 __ movl(rcx,
aoqi@0 855 Address(rdi,
aoqi@0 856 rdx,
aoqi@0 857 Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
aoqi@0 858 __ shrl(rcx, 2*BitsPerByte);
aoqi@0 859 __ andl(rcx, 0xFF);
aoqi@0 860 __ cmpl(rcx, Bytecodes::_getfield);
aoqi@0 861 __ jcc(Assembler::notEqual, slow_path);
aoqi@0 862
aoqi@0 863 // Note: constant pool entry is not valid before bytecode is resolved
aoqi@0 864 __ movptr(rcx,
aoqi@0 865 Address(rdi,
aoqi@0 866 rdx,
aoqi@0 867 Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
aoqi@0 868 __ movl(rdx,
aoqi@0 869 Address(rdi,
aoqi@0 870 rdx,
aoqi@0 871 Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
aoqi@0 872
kevinw@8368 873 Label notByte, notBool, notShort, notChar;
aoqi@0 874 const Address field_address (rax, rcx, Address::times_1);
aoqi@0 875
aoqi@0 876 // Need to differentiate between igetfield, agetfield, bgetfield etc.
aoqi@0 877 // because they are different sizes.
aoqi@0 878 // Use the type from the constant pool cache
aoqi@0 879 __ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift);
aoqi@0 880 // Make sure we don't need to mask rdx after the above shift
aoqi@0 881 ConstantPoolCacheEntry::verify_tos_state_shift();
aoqi@0 882 #ifdef _LP64
aoqi@0 883 Label notObj;
aoqi@0 884 __ cmpl(rdx, atos);
aoqi@0 885 __ jcc(Assembler::notEqual, notObj);
aoqi@0 886 // atos
aoqi@0 887 __ movptr(rax, field_address);
aoqi@0 888 __ jmp(xreturn_path);
aoqi@0 889
aoqi@0 890 __ bind(notObj);
aoqi@0 891 #endif // _LP64
kevinw@8368 892 __ cmpl(rdx, ztos);
kevinw@8368 893 __ jcc(Assembler::notEqual, notBool);
kevinw@8368 894 __ load_signed_byte(rax, field_address);
kevinw@8368 895 __ jmp(xreturn_path);
kevinw@8368 896
aoqi@0 897 __ cmpl(rdx, btos);
aoqi@0 898 __ jcc(Assembler::notEqual, notByte);
aoqi@0 899 __ load_signed_byte(rax, field_address);
aoqi@0 900 __ jmp(xreturn_path);
aoqi@0 901
aoqi@0 902 __ bind(notByte);
aoqi@0 903 __ cmpl(rdx, stos);
aoqi@0 904 __ jcc(Assembler::notEqual, notShort);
aoqi@0 905 __ load_signed_short(rax, field_address);
aoqi@0 906 __ jmp(xreturn_path);
aoqi@0 907
aoqi@0 908 __ bind(notShort);
aoqi@0 909 __ cmpl(rdx, ctos);
aoqi@0 910 __ jcc(Assembler::notEqual, notChar);
aoqi@0 911 __ load_unsigned_short(rax, field_address);
aoqi@0 912 __ jmp(xreturn_path);
aoqi@0 913
aoqi@0 914 __ bind(notChar);
aoqi@0 915 #ifdef ASSERT
aoqi@0 916 Label okay;
aoqi@0 917 #ifndef _LP64
aoqi@0 918 __ cmpl(rdx, atos);
aoqi@0 919 __ jcc(Assembler::equal, okay);
aoqi@0 920 #endif // _LP64
aoqi@0 921 __ cmpl(rdx, itos);
aoqi@0 922 __ jcc(Assembler::equal, okay);
aoqi@0 923 __ stop("what type is this?");
aoqi@0 924 __ bind(okay);
aoqi@0 925 #endif // ASSERT
aoqi@0 926 // All the rest are a 32 bit wordsize
aoqi@0 927 __ movl(rax, field_address);
aoqi@0 928
aoqi@0 929 __ bind(xreturn_path);
aoqi@0 930
aoqi@0 931 // _ireturn/_areturn
aoqi@0 932 __ pop(rdi); // get return address
aoqi@0 933 __ mov(rsp, sender_sp_on_entry); // set sp to sender sp
aoqi@0 934 __ jmp(rdi);
aoqi@0 935
aoqi@0 936 // generate a vanilla interpreter entry as the slow path
aoqi@0 937 __ bind(slow_path);
aoqi@0 938 // We will enter c++ interpreter looking like it was
aoqi@0 939 // called by the call_stub this will cause it to return
aoqi@0 940 // a tosca result to the invoker which might have been
aoqi@0 941 // the c++ interpreter itself.
aoqi@0 942
aoqi@0 943 __ jmp(fast_accessor_slow_entry_path);
aoqi@0 944 return entry_point;
aoqi@0 945
aoqi@0 946 } else {
aoqi@0 947 return NULL;
aoqi@0 948 }
aoqi@0 949
aoqi@0 950 }
aoqi@0 951
aoqi@0 952 address InterpreterGenerator::generate_Reference_get_entry(void) {
aoqi@0 953 #if INCLUDE_ALL_GCS
aoqi@0 954 if (UseG1GC) {
aoqi@0 955 // We need to generate have a routine that generates code to:
aoqi@0 956 // * load the value in the referent field
aoqi@0 957 // * passes that value to the pre-barrier.
aoqi@0 958 //
aoqi@0 959 // In the case of G1 this will record the value of the
aoqi@0 960 // referent in an SATB buffer if marking is active.
aoqi@0 961 // This will cause concurrent marking to mark the referent
aoqi@0 962 // field as live.
aoqi@0 963 Unimplemented();
aoqi@0 964 }
aoqi@0 965 #endif // INCLUDE_ALL_GCS
aoqi@0 966
aoqi@0 967 // If G1 is not enabled then attempt to go through the accessor entry point
aoqi@0 968 // Reference.get is an accessor
aoqi@0 969 return generate_accessor_entry();
aoqi@0 970 }
aoqi@0 971
aoqi@0 972 //
aoqi@0 973 // C++ Interpreter stub for calling a native method.
aoqi@0 974 // This sets up a somewhat different looking stack for calling the native method
aoqi@0 975 // than the typical interpreter frame setup but still has the pointer to
aoqi@0 976 // an interpreter state.
aoqi@0 977 //
aoqi@0 978
aoqi@0 979 address InterpreterGenerator::generate_native_entry(bool synchronized) {
aoqi@0 980 // determine code generation flags
aoqi@0 981 bool inc_counter = UseCompiler || CountCompiledCalls;
aoqi@0 982
aoqi@0 983 // rbx: Method*
aoqi@0 984 // rcx: receiver (unused)
aoqi@0 985 // rsi/r13: previous interpreter state (if called from C++ interpreter) must preserve
aoqi@0 986 // in any case. If called via c1/c2/call_stub rsi/r13 is junk (to use) but harmless
aoqi@0 987 // to save/restore.
aoqi@0 988 address entry_point = __ pc();
aoqi@0 989
aoqi@0 990 const Address constMethod (rbx, Method::const_offset());
aoqi@0 991 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 992 const Address size_of_parameters(rcx, ConstMethod::size_of_parameters_offset());
aoqi@0 993
aoqi@0 994 // rsi/r13 == state/locals rdi == prevstate
aoqi@0 995 const Register locals = rdi;
aoqi@0 996
aoqi@0 997 // get parameter size (always needed)
aoqi@0 998 __ movptr(rcx, constMethod);
aoqi@0 999 __ load_unsigned_short(rcx, size_of_parameters);
aoqi@0 1000
aoqi@0 1001 // rbx: Method*
aoqi@0 1002 // rcx: size of parameters
aoqi@0 1003 __ pop(rax); // get return address
aoqi@0 1004 // for natives the size of locals is zero
aoqi@0 1005
aoqi@0 1006 // compute beginning of parameters /locals
aoqi@0 1007
aoqi@0 1008 __ lea(locals, Address(rsp, rcx, Address::times_ptr, -wordSize));
aoqi@0 1009
aoqi@0 1010 // initialize fixed part of activation frame
aoqi@0 1011
aoqi@0 1012 // Assumes rax = return address
aoqi@0 1013
aoqi@0 1014 // allocate and initialize new interpreterState and method expression stack
aoqi@0 1015 // IN(locals) -> locals
aoqi@0 1016 // IN(state) -> previous frame manager state (NULL from stub/c1/c2)
aoqi@0 1017 // destroys rax, rcx, rdx
aoqi@0 1018 // OUT (state) -> new interpreterState
aoqi@0 1019 // OUT(rsp) -> bottom of methods expression stack
aoqi@0 1020
aoqi@0 1021 // save sender_sp
aoqi@0 1022 __ mov(rcx, sender_sp_on_entry);
aoqi@0 1023 // start with NULL previous state
aoqi@0 1024 __ movptr(state, (int32_t)NULL_WORD);
aoqi@0 1025 generate_compute_interpreter_state(state, locals, rcx, true);
aoqi@0 1026
aoqi@0 1027 #ifdef ASSERT
aoqi@0 1028 { Label L;
aoqi@0 1029 __ movptr(rax, STATE(_stack_base));
aoqi@0 1030 #ifdef _LP64
aoqi@0 1031 // duplicate the alignment rsp got after setting stack_base
aoqi@0 1032 __ subptr(rax, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1033 __ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 1034 #endif // _LP64
aoqi@0 1035 __ cmpptr(rax, rsp);
aoqi@0 1036 __ jcc(Assembler::equal, L);
aoqi@0 1037 __ stop("broken stack frame setup in interpreter");
aoqi@0 1038 __ bind(L);
aoqi@0 1039 }
aoqi@0 1040 #endif
aoqi@0 1041
aoqi@0 1042 const Register unlock_thread = LP64_ONLY(r15_thread) NOT_LP64(rax);
aoqi@0 1043 NOT_LP64(__ movptr(unlock_thread, STATE(_thread));) // get thread
aoqi@0 1044 // Since at this point in the method invocation the exception handler
aoqi@0 1045 // would try to exit the monitor of synchronized methods which hasn't
aoqi@0 1046 // been entered yet, we set the thread local variable
aoqi@0 1047 // _do_not_unlock_if_synchronized to true. The remove_activation will
aoqi@0 1048 // check this flag.
aoqi@0 1049
aoqi@0 1050 const Address do_not_unlock_if_synchronized(unlock_thread,
aoqi@0 1051 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
aoqi@0 1052 __ movbool(do_not_unlock_if_synchronized, true);
aoqi@0 1053
aoqi@0 1054 // make sure method is native & not abstract
aoqi@0 1055 #ifdef ASSERT
aoqi@0 1056 __ movl(rax, access_flags);
aoqi@0 1057 {
aoqi@0 1058 Label L;
aoqi@0 1059 __ testl(rax, JVM_ACC_NATIVE);
aoqi@0 1060 __ jcc(Assembler::notZero, L);
aoqi@0 1061 __ stop("tried to execute non-native method as native");
aoqi@0 1062 __ bind(L);
aoqi@0 1063 }
aoqi@0 1064 { Label L;
aoqi@0 1065 __ testl(rax, JVM_ACC_ABSTRACT);
aoqi@0 1066 __ jcc(Assembler::zero, L);
aoqi@0 1067 __ stop("tried to execute abstract method in interpreter");
aoqi@0 1068 __ bind(L);
aoqi@0 1069 }
aoqi@0 1070 #endif
aoqi@0 1071
aoqi@0 1072
aoqi@0 1073 // increment invocation count & check for overflow
aoqi@0 1074 Label invocation_counter_overflow;
aoqi@0 1075 if (inc_counter) {
aoqi@0 1076 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
aoqi@0 1077 }
aoqi@0 1078
aoqi@0 1079 Label continue_after_compile;
aoqi@0 1080
aoqi@0 1081 __ bind(continue_after_compile);
aoqi@0 1082
aoqi@0 1083 bang_stack_shadow_pages(true);
aoqi@0 1084
aoqi@0 1085 // reset the _do_not_unlock_if_synchronized flag
aoqi@0 1086 NOT_LP64(__ movl(rax, STATE(_thread));) // get thread
aoqi@0 1087 __ movbool(do_not_unlock_if_synchronized, false);
aoqi@0 1088
aoqi@0 1089
aoqi@0 1090 // check for synchronized native methods
aoqi@0 1091 //
aoqi@0 1092 // Note: This must happen *after* invocation counter check, since
aoqi@0 1093 // when overflow happens, the method should not be locked.
aoqi@0 1094 if (synchronized) {
aoqi@0 1095 // potentially kills rax, rcx, rdx, rdi
aoqi@0 1096 lock_method();
aoqi@0 1097 } else {
aoqi@0 1098 // no synchronization necessary
aoqi@0 1099 #ifdef ASSERT
aoqi@0 1100 { Label L;
aoqi@0 1101 __ movl(rax, access_flags);
aoqi@0 1102 __ testl(rax, JVM_ACC_SYNCHRONIZED);
aoqi@0 1103 __ jcc(Assembler::zero, L);
aoqi@0 1104 __ stop("method needs synchronization");
aoqi@0 1105 __ bind(L);
aoqi@0 1106 }
aoqi@0 1107 #endif
aoqi@0 1108 }
aoqi@0 1109
aoqi@0 1110 // start execution
aoqi@0 1111
aoqi@0 1112 // jvmti support
aoqi@0 1113 __ notify_method_entry();
aoqi@0 1114
aoqi@0 1115 // work registers
aoqi@0 1116 const Register method = rbx;
aoqi@0 1117 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rdi);
aoqi@0 1118 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); // rcx|rscratch1
aoqi@0 1119 const Address constMethod (method, Method::const_offset());
aoqi@0 1120 const Address size_of_parameters(t, ConstMethod::size_of_parameters_offset());
aoqi@0 1121
aoqi@0 1122 // allocate space for parameters
aoqi@0 1123 __ movptr(method, STATE(_method));
aoqi@0 1124 __ verify_method_ptr(method);
aoqi@0 1125 __ movptr(t, constMethod);
aoqi@0 1126 __ load_unsigned_short(t, size_of_parameters);
aoqi@0 1127 __ shll(t, 2);
aoqi@0 1128 #ifdef _LP64
aoqi@0 1129 __ subptr(rsp, t);
aoqi@0 1130 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1131 __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 1132 #else
aoqi@0 1133 __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror
aoqi@0 1134 __ subptr(rsp, t);
aoqi@0 1135 __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
aoqi@0 1136 #endif // _LP64
aoqi@0 1137
aoqi@0 1138 // get signature handler
aoqi@0 1139 Label pending_exception_present;
aoqi@0 1140
aoqi@0 1141 { Label L;
aoqi@0 1142 __ movptr(t, Address(method, Method::signature_handler_offset()));
aoqi@0 1143 __ testptr(t, t);
aoqi@0 1144 __ jcc(Assembler::notZero, L);
aoqi@0 1145 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false);
aoqi@0 1146 __ movptr(method, STATE(_method));
aoqi@0 1147 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1148 __ jcc(Assembler::notEqual, pending_exception_present);
aoqi@0 1149 __ verify_method_ptr(method);
aoqi@0 1150 __ movptr(t, Address(method, Method::signature_handler_offset()));
aoqi@0 1151 __ bind(L);
aoqi@0 1152 }
aoqi@0 1153 #ifdef ASSERT
aoqi@0 1154 {
aoqi@0 1155 Label L;
aoqi@0 1156 __ push(t);
aoqi@0 1157 __ get_thread(t); // get vm's javathread*
aoqi@0 1158 __ cmpptr(t, STATE(_thread));
aoqi@0 1159 __ jcc(Assembler::equal, L);
aoqi@0 1160 __ int3();
aoqi@0 1161 __ bind(L);
aoqi@0 1162 __ pop(t);
aoqi@0 1163 }
aoqi@0 1164 #endif //
aoqi@0 1165
aoqi@0 1166 const Register from_ptr = InterpreterRuntime::SignatureHandlerGenerator::from();
aoqi@0 1167 // call signature handler
aoqi@0 1168 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");
aoqi@0 1169
aoqi@0 1170 // The generated handlers do not touch RBX (the method oop).
aoqi@0 1171 // However, large signatures cannot be cached and are generated
aoqi@0 1172 // each time here. The slow-path generator will blow RBX
aoqi@0 1173 // sometime, so we must reload it after the call.
aoqi@0 1174 __ movptr(from_ptr, STATE(_locals)); // get the from pointer
aoqi@0 1175 __ call(t);
aoqi@0 1176 __ movptr(method, STATE(_method));
aoqi@0 1177 __ verify_method_ptr(method);
aoqi@0 1178
aoqi@0 1179 // result handler is in rax
aoqi@0 1180 // set result handler
aoqi@0 1181 __ movptr(STATE(_result_handler), rax);
aoqi@0 1182
aoqi@0 1183
aoqi@0 1184 // get native function entry point
aoqi@0 1185 { Label L;
aoqi@0 1186 __ movptr(rax, Address(method, Method::native_function_offset()));
aoqi@0 1187 __ testptr(rax, rax);
aoqi@0 1188 __ jcc(Assembler::notZero, L);
aoqi@0 1189 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
aoqi@0 1190 __ movptr(method, STATE(_method));
aoqi@0 1191 __ verify_method_ptr(method);
aoqi@0 1192 __ movptr(rax, Address(method, Method::native_function_offset()));
aoqi@0 1193 __ bind(L);
aoqi@0 1194 }
aoqi@0 1195
aoqi@0 1196 // pass mirror handle if static call
aoqi@0 1197 { Label L;
aoqi@0 1198 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 1199 __ movl(t, Address(method, Method::access_flags_offset()));
aoqi@0 1200 __ testl(t, JVM_ACC_STATIC);
aoqi@0 1201 __ jcc(Assembler::zero, L);
aoqi@0 1202 // get mirror
aoqi@0 1203 __ movptr(t, Address(method, Method:: const_offset()));
aoqi@0 1204 __ movptr(t, Address(t, ConstMethod::constants_offset()));
aoqi@0 1205 __ movptr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes()));
aoqi@0 1206 __ movptr(t, Address(t, mirror_offset));
aoqi@0 1207 // copy mirror into activation object
aoqi@0 1208 __ movptr(STATE(_oop_temp), t);
aoqi@0 1209 // pass handle to mirror
aoqi@0 1210 #ifdef _LP64
aoqi@0 1211 __ lea(c_rarg1, STATE(_oop_temp));
aoqi@0 1212 #else
aoqi@0 1213 __ lea(t, STATE(_oop_temp));
aoqi@0 1214 __ movptr(Address(rsp, wordSize), t);
aoqi@0 1215 #endif // _LP64
aoqi@0 1216 __ bind(L);
aoqi@0 1217 }
aoqi@0 1218 #ifdef ASSERT
aoqi@0 1219 {
aoqi@0 1220 Label L;
aoqi@0 1221 __ push(t);
aoqi@0 1222 __ get_thread(t); // get vm's javathread*
aoqi@0 1223 __ cmpptr(t, STATE(_thread));
aoqi@0 1224 __ jcc(Assembler::equal, L);
aoqi@0 1225 __ int3();
aoqi@0 1226 __ bind(L);
aoqi@0 1227 __ pop(t);
aoqi@0 1228 }
aoqi@0 1229 #endif //
aoqi@0 1230
aoqi@0 1231 // pass JNIEnv
aoqi@0 1232 #ifdef _LP64
aoqi@0 1233 __ lea(c_rarg0, Address(thread, JavaThread::jni_environment_offset()));
aoqi@0 1234 #else
aoqi@0 1235 __ movptr(thread, STATE(_thread)); // get thread
aoqi@0 1236 __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
aoqi@0 1237
aoqi@0 1238 __ movptr(Address(rsp, 0), t);
aoqi@0 1239 #endif // _LP64
aoqi@0 1240
aoqi@0 1241 #ifdef ASSERT
aoqi@0 1242 {
aoqi@0 1243 Label L;
aoqi@0 1244 __ push(t);
aoqi@0 1245 __ get_thread(t); // get vm's javathread*
aoqi@0 1246 __ cmpptr(t, STATE(_thread));
aoqi@0 1247 __ jcc(Assembler::equal, L);
aoqi@0 1248 __ int3();
aoqi@0 1249 __ bind(L);
aoqi@0 1250 __ pop(t);
aoqi@0 1251 }
aoqi@0 1252 #endif //
aoqi@0 1253
aoqi@0 1254 #ifdef ASSERT
aoqi@0 1255 { Label L;
aoqi@0 1256 __ movl(t, Address(thread, JavaThread::thread_state_offset()));
aoqi@0 1257 __ cmpl(t, _thread_in_Java);
aoqi@0 1258 __ jcc(Assembler::equal, L);
aoqi@0 1259 __ stop("Wrong thread state in native stub");
aoqi@0 1260 __ bind(L);
aoqi@0 1261 }
aoqi@0 1262 #endif
aoqi@0 1263
aoqi@0 1264 // Change state to native (we save the return address in the thread, since it might not
aoqi@0 1265 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
aoqi@0 1266 // points into the right code segment. It does not have to be the correct return pc.
aoqi@0 1267
aoqi@0 1268 __ set_last_Java_frame(thread, noreg, rbp, __ pc());
aoqi@0 1269
aoqi@0 1270 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
aoqi@0 1271
aoqi@0 1272 __ call(rax);
aoqi@0 1273
aoqi@0 1274 // result potentially in rdx:rax or ST0
aoqi@0 1275 __ movptr(method, STATE(_method));
aoqi@0 1276 NOT_LP64(__ movptr(thread, STATE(_thread));) // get thread
aoqi@0 1277
aoqi@0 1278 // The potential result is in ST(0) & rdx:rax
aoqi@0 1279 // With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then
aoqi@0 1280 // we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about
aoqi@0 1281 // anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would
aoqi@0 1282 // be destroyed.
aoqi@0 1283 // It is safe to do these pushes because state is _thread_in_native and return address will be found
aoqi@0 1284 // via _last_native_pc and not via _last_jave_sp
aoqi@0 1285
aoqi@0 1286 // Must save the value of ST(0)/xmm0 since it could be destroyed before we get to result handler
aoqi@0 1287 { Label Lpush, Lskip;
aoqi@0 1288 ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
aoqi@0 1289 ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
aoqi@0 1290 __ cmpptr(STATE(_result_handler), float_handler.addr());
aoqi@0 1291 __ jcc(Assembler::equal, Lpush);
aoqi@0 1292 __ cmpptr(STATE(_result_handler), double_handler.addr());
aoqi@0 1293 __ jcc(Assembler::notEqual, Lskip);
aoqi@0 1294 __ bind(Lpush);
aoqi@0 1295 __ subptr(rsp, 2*wordSize);
aoqi@0 1296 if ( UseSSE < 2 ) {
aoqi@0 1297 __ fstp_d(Address(rsp, 0));
aoqi@0 1298 } else {
aoqi@0 1299 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 1300 }
aoqi@0 1301 __ bind(Lskip);
aoqi@0 1302 }
aoqi@0 1303
aoqi@0 1304 // save rax:rdx for potential use by result handler.
aoqi@0 1305 __ push(rax);
aoqi@0 1306 #ifndef _LP64
aoqi@0 1307 __ push(rdx);
aoqi@0 1308 #endif // _LP64
aoqi@0 1309
aoqi@0 1310 // Verify or restore cpu control state after JNI call
aoqi@0 1311 __ restore_cpu_control_state_after_jni();
aoqi@0 1312
aoqi@0 1313 // change thread state
aoqi@0 1314 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
aoqi@0 1315 if(os::is_MP()) {
aoqi@0 1316 // Write serialization page so VM thread can do a pseudo remote membar.
aoqi@0 1317 // We use the current thread pointer to calculate a thread specific
aoqi@0 1318 // offset to write to within the page. This minimizes bus traffic
aoqi@0 1319 // due to cache line collision.
aoqi@0 1320 __ serialize_memory(thread, rcx);
aoqi@0 1321 }
aoqi@0 1322
aoqi@0 1323 // check for safepoint operation in progress and/or pending suspend requests
aoqi@0 1324 { Label Continue;
aoqi@0 1325
aoqi@0 1326 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
aoqi@0 1327 SafepointSynchronize::_not_synchronized);
aoqi@0 1328
aoqi@0 1329 // threads running native code and they are expected to self-suspend
aoqi@0 1330 // when leaving the _thread_in_native state. We need to check for
aoqi@0 1331 // pending suspend requests here.
aoqi@0 1332 Label L;
aoqi@0 1333 __ jcc(Assembler::notEqual, L);
aoqi@0 1334 __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
aoqi@0 1335 __ jcc(Assembler::equal, Continue);
aoqi@0 1336 __ bind(L);
aoqi@0 1337
aoqi@0 1338 // Don't use call_VM as it will see a possible pending exception and forward it
aoqi@0 1339 // and never return here preventing us from clearing _last_native_pc down below.
aoqi@0 1340 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
aoqi@0 1341 // preserved and correspond to the bcp/locals pointers.
aoqi@0 1342 //
aoqi@0 1343
aoqi@0 1344 ((MacroAssembler*)_masm)->call_VM_leaf(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
aoqi@0 1345 thread);
aoqi@0 1346 __ increment(rsp, wordSize);
aoqi@0 1347
aoqi@0 1348 __ movptr(method, STATE(_method));
aoqi@0 1349 __ verify_method_ptr(method);
aoqi@0 1350 __ movptr(thread, STATE(_thread)); // get thread
aoqi@0 1351
aoqi@0 1352 __ bind(Continue);
aoqi@0 1353 }
aoqi@0 1354
aoqi@0 1355 // change thread state
aoqi@0 1356 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
aoqi@0 1357
aoqi@0 1358 __ reset_last_Java_frame(thread, true, true);
aoqi@0 1359
aoqi@0 1360 // reset handle block
aoqi@0 1361 __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
aoqi@0 1362 __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
aoqi@0 1363
aoqi@0 1364 // If result was an oop then unbox and save it in the frame
aoqi@0 1365 { Label L;
aoqi@0 1366 Label no_oop, store_result;
aoqi@0 1367 ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT));
aoqi@0 1368 __ cmpptr(STATE(_result_handler), oop_handler.addr());
aoqi@0 1369 __ jcc(Assembler::notEqual, no_oop);
aoqi@0 1370 #ifndef _LP64
aoqi@0 1371 __ pop(rdx);
aoqi@0 1372 #endif // _LP64
aoqi@0 1373 __ pop(rax);
aoqi@0 1374 __ testptr(rax, rax);
aoqi@0 1375 __ jcc(Assembler::zero, store_result);
aoqi@0 1376 // unbox
aoqi@0 1377 __ movptr(rax, Address(rax, 0));
aoqi@0 1378 __ bind(store_result);
aoqi@0 1379 __ movptr(STATE(_oop_temp), rax);
aoqi@0 1380 // keep stack depth as expected by pushing oop which will eventually be discarded
aoqi@0 1381 __ push(rax);
aoqi@0 1382 #ifndef _LP64
aoqi@0 1383 __ push(rdx);
aoqi@0 1384 #endif // _LP64
aoqi@0 1385 __ bind(no_oop);
aoqi@0 1386 }
aoqi@0 1387
aoqi@0 1388 {
aoqi@0 1389 Label no_reguard;
aoqi@0 1390 __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
aoqi@0 1391 __ jcc(Assembler::notEqual, no_reguard);
aoqi@0 1392
aoqi@0 1393 __ pusha();
aoqi@0 1394 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
aoqi@0 1395 __ popa();
aoqi@0 1396
aoqi@0 1397 __ bind(no_reguard);
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400
aoqi@0 1401 // QQQ Seems like for native methods we simply return and the caller will see the pending
aoqi@0 1402 // exception and do the right thing. Certainly the interpreter will, don't know about
aoqi@0 1403 // compiled methods.
aoqi@0 1404 // Seems that the answer to above is no this is wrong. The old code would see the exception
aoqi@0 1405 // and forward it before doing the unlocking and notifying jvmdi that method has exited.
aoqi@0 1406 // This seems wrong need to investigate the spec.
aoqi@0 1407
aoqi@0 1408 // handle exceptions (exception handling will handle unlocking!)
aoqi@0 1409 { Label L;
aoqi@0 1410 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1411 __ jcc(Assembler::zero, L);
aoqi@0 1412 __ bind(pending_exception_present);
aoqi@0 1413
aoqi@0 1414 // There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply
aoqi@0 1415 // return and let caller deal with exception. This skips the unlocking here which
aoqi@0 1416 // seems wrong but seems to be what asm interpreter did. Can't find this in the spec.
aoqi@0 1417 // Note: must preverve method in rbx
aoqi@0 1418 //
aoqi@0 1419
aoqi@0 1420 // remove activation
aoqi@0 1421
aoqi@0 1422 __ movptr(t, STATE(_sender_sp));
aoqi@0 1423 __ leave(); // remove frame anchor
aoqi@0 1424 __ pop(rdi); // get return address
aoqi@0 1425 __ movptr(state, STATE(_prev_link)); // get previous state for return
aoqi@0 1426 __ mov(rsp, t); // set sp to sender sp
aoqi@0 1427 __ push(rdi); // push throwing pc
aoqi@0 1428 // The skips unlocking!! This seems to be what asm interpreter does but seems
aoqi@0 1429 // very wrong. Not clear if this violates the spec.
aoqi@0 1430 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 1431 __ bind(L);
aoqi@0 1432 }
aoqi@0 1433
aoqi@0 1434 // do unlocking if necessary
aoqi@0 1435 { Label L;
aoqi@0 1436 __ movl(t, Address(method, Method::access_flags_offset()));
aoqi@0 1437 __ testl(t, JVM_ACC_SYNCHRONIZED);
aoqi@0 1438 __ jcc(Assembler::zero, L);
aoqi@0 1439 // the code below should be shared with interpreter macro assembler implementation
aoqi@0 1440 { Label unlock;
aoqi@0 1441 const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
aoqi@0 1442 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
aoqi@0 1443 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
aoqi@0 1444 __ movptr(monitor, STATE(_monitor_base));
aoqi@0 1445 __ subptr(monitor, frame::interpreter_frame_monitor_size() * wordSize); // address of initial monitor
aoqi@0 1446
aoqi@0 1447 __ movptr(t, Address(monitor, BasicObjectLock::obj_offset_in_bytes()));
aoqi@0 1448 __ testptr(t, t);
aoqi@0 1449 __ jcc(Assembler::notZero, unlock);
aoqi@0 1450
aoqi@0 1451 // Entry already unlocked, need to throw exception
aoqi@0 1452 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 1453 __ should_not_reach_here();
aoqi@0 1454
aoqi@0 1455 __ bind(unlock);
aoqi@0 1456 __ unlock_object(monitor);
aoqi@0 1457 // unlock can blow rbx so restore it for path that needs it below
aoqi@0 1458 __ movptr(method, STATE(_method));
aoqi@0 1459 }
aoqi@0 1460 __ bind(L);
aoqi@0 1461 }
aoqi@0 1462
aoqi@0 1463 // jvmti support
aoqi@0 1464 // Note: This must happen _after_ handling/throwing any exceptions since
aoqi@0 1465 // the exception handler code notifies the runtime of method exits
aoqi@0 1466 // too. If this happens before, method entry/exit notifications are
aoqi@0 1467 // not properly paired (was bug - gri 11/22/99).
aoqi@0 1468 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
aoqi@0 1469
aoqi@0 1470 // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
aoqi@0 1471 #ifndef _LP64
aoqi@0 1472 __ pop(rdx);
aoqi@0 1473 #endif // _LP64
aoqi@0 1474 __ pop(rax);
aoqi@0 1475 __ movptr(t, STATE(_result_handler)); // get result handler
aoqi@0 1476 __ call(t); // call result handler to convert to tosca form
aoqi@0 1477
aoqi@0 1478 // remove activation
aoqi@0 1479
aoqi@0 1480 __ movptr(t, STATE(_sender_sp));
aoqi@0 1481
aoqi@0 1482 __ leave(); // remove frame anchor
aoqi@0 1483 __ pop(rdi); // get return address
aoqi@0 1484 __ movptr(state, STATE(_prev_link)); // get previous state for return (if c++ interpreter was caller)
aoqi@0 1485 __ mov(rsp, t); // set sp to sender sp
aoqi@0 1486 __ jmp(rdi);
aoqi@0 1487
aoqi@0 1488 // invocation counter overflow
aoqi@0 1489 if (inc_counter) {
aoqi@0 1490 // Handle overflow of counter and compile method
aoqi@0 1491 __ bind(invocation_counter_overflow);
aoqi@0 1492 generate_counter_overflow(&continue_after_compile);
aoqi@0 1493 }
aoqi@0 1494
aoqi@0 1495 return entry_point;
aoqi@0 1496 }
aoqi@0 1497
aoqi@0 1498 // Generate entries that will put a result type index into rcx
aoqi@0 1499 void CppInterpreterGenerator::generate_deopt_handling() {
aoqi@0 1500
aoqi@0 1501 Label return_from_deopt_common;
aoqi@0 1502
aoqi@0 1503 // Generate entries that will put a result type index into rcx
aoqi@0 1504 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1505 deopt_frame_manager_return_atos = __ pc();
aoqi@0 1506
aoqi@0 1507 // rax is live here
aoqi@0 1508 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT)); // Result stub address array index
aoqi@0 1509 __ jmp(return_from_deopt_common);
aoqi@0 1510
aoqi@0 1511
aoqi@0 1512 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1513 deopt_frame_manager_return_btos = __ pc();
aoqi@0 1514
aoqi@0 1515 // rax is live here
aoqi@0 1516 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN)); // Result stub address array index
aoqi@0 1517 __ jmp(return_from_deopt_common);
aoqi@0 1518
aoqi@0 1519 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1520 deopt_frame_manager_return_itos = __ pc();
aoqi@0 1521
aoqi@0 1522 // rax is live here
aoqi@0 1523 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT)); // Result stub address array index
aoqi@0 1524 __ jmp(return_from_deopt_common);
aoqi@0 1525
aoqi@0 1526 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1527
aoqi@0 1528 deopt_frame_manager_return_ltos = __ pc();
aoqi@0 1529 // rax,rdx are live here
aoqi@0 1530 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG)); // Result stub address array index
aoqi@0 1531 __ jmp(return_from_deopt_common);
aoqi@0 1532
aoqi@0 1533 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1534
aoqi@0 1535 deopt_frame_manager_return_ftos = __ pc();
aoqi@0 1536 // st(0) is live here
aoqi@0 1537 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
aoqi@0 1538 __ jmp(return_from_deopt_common);
aoqi@0 1539
aoqi@0 1540 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1541 deopt_frame_manager_return_dtos = __ pc();
aoqi@0 1542
aoqi@0 1543 // st(0) is live here
aoqi@0 1544 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
aoqi@0 1545 __ jmp(return_from_deopt_common);
aoqi@0 1546
aoqi@0 1547 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1548 deopt_frame_manager_return_vtos = __ pc();
aoqi@0 1549
aoqi@0 1550 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID));
aoqi@0 1551
aoqi@0 1552 // Deopt return common
aoqi@0 1553 // an index is present in rcx that lets us move any possible result being
aoqi@0 1554 // return to the interpreter's stack
aoqi@0 1555 //
aoqi@0 1556 // Because we have a full sized interpreter frame on the youngest
aoqi@0 1557 // activation the stack is pushed too deep to share the tosca to
aoqi@0 1558 // stack converters directly. We shrink the stack to the desired
aoqi@0 1559 // amount and then push result and then re-extend the stack.
aoqi@0 1560 // We could have the code in size_activation layout a short
aoqi@0 1561 // frame for the top activation but that would look different
aoqi@0 1562 // than say sparc (which needs a full size activation because
aoqi@0 1563 // the windows are in the way. Really it could be short? QQQ
aoqi@0 1564 //
aoqi@0 1565 __ bind(return_from_deopt_common);
aoqi@0 1566
aoqi@0 1567 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1568
aoqi@0 1569 // setup rsp so we can push the "result" as needed.
aoqi@0 1570 __ movptr(rsp, STATE(_stack)); // trim stack (is prepushed)
aoqi@0 1571 __ addptr(rsp, wordSize); // undo prepush
aoqi@0 1572
aoqi@0 1573 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
aoqi@0 1574 // Address index(noreg, rcx, Address::times_ptr);
aoqi@0 1575 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
aoqi@0 1576 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
aoqi@0 1577 __ call(rcx); // call result converter
aoqi@0 1578
aoqi@0 1579 __ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume);
aoqi@0 1580 __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
aoqi@0 1581 __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
aoqi@0 1582 // result if any on stack already )
aoqi@0 1583 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 1584 }
aoqi@0 1585
aoqi@0 1586 // Generate the code to handle a more_monitors message from the c++ interpreter
aoqi@0 1587 void CppInterpreterGenerator::generate_more_monitors() {
aoqi@0 1588
aoqi@0 1589
aoqi@0 1590 Label entry, loop;
aoqi@0 1591 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 1592 // 1. compute new pointers // rsp: old expression stack top
aoqi@0 1593 __ movptr(rdx, STATE(_stack_base)); // rdx: old expression stack bottom
aoqi@0 1594 __ subptr(rsp, entry_size); // move expression stack top limit
aoqi@0 1595 __ subptr(STATE(_stack), entry_size); // update interpreter stack top
aoqi@0 1596 __ subptr(STATE(_stack_limit), entry_size); // inform interpreter
aoqi@0 1597 __ subptr(rdx, entry_size); // move expression stack bottom
aoqi@0 1598 __ movptr(STATE(_stack_base), rdx); // inform interpreter
aoqi@0 1599 __ movptr(rcx, STATE(_stack)); // set start value for copy loop
aoqi@0 1600 __ jmp(entry);
aoqi@0 1601 // 2. move expression stack contents
aoqi@0 1602 __ bind(loop);
aoqi@0 1603 __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location
aoqi@0 1604 __ movptr(Address(rcx, 0), rbx); // and store it at new location
aoqi@0 1605 __ addptr(rcx, wordSize); // advance to next word
aoqi@0 1606 __ bind(entry);
aoqi@0 1607 __ cmpptr(rcx, rdx); // check if bottom reached
aoqi@0 1608 __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word
aoqi@0 1609 // now zero the slot so we can find it.
aoqi@0 1610 __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL_WORD);
aoqi@0 1611 __ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors);
aoqi@0 1612 }
aoqi@0 1613
aoqi@0 1614
aoqi@0 1615 // Initial entry to C++ interpreter from the call_stub.
aoqi@0 1616 // This entry point is called the frame manager since it handles the generation
aoqi@0 1617 // of interpreter activation frames via requests directly from the vm (via call_stub)
aoqi@0 1618 // and via requests from the interpreter. The requests from the call_stub happen
aoqi@0 1619 // directly thru the entry point. Requests from the interpreter happen via returning
aoqi@0 1620 // from the interpreter and examining the message the interpreter has returned to
aoqi@0 1621 // the frame manager. The frame manager can take the following requests:
aoqi@0 1622
aoqi@0 1623 // NO_REQUEST - error, should never happen.
aoqi@0 1624 // MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
aoqi@0 1625 // allocate a new monitor.
aoqi@0 1626 // CALL_METHOD - setup a new activation to call a new method. Very similar to what
aoqi@0 1627 // happens during entry during the entry via the call stub.
aoqi@0 1628 // RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
aoqi@0 1629 //
aoqi@0 1630 // Arguments:
aoqi@0 1631 //
aoqi@0 1632 // rbx: Method*
aoqi@0 1633 // rcx: receiver - unused (retrieved from stack as needed)
aoqi@0 1634 // rsi/r13: previous frame manager state (NULL from the call_stub/c1/c2)
aoqi@0 1635 //
aoqi@0 1636 //
aoqi@0 1637 // Stack layout at entry
aoqi@0 1638 //
aoqi@0 1639 // [ return address ] <--- rsp
aoqi@0 1640 // [ parameter n ]
aoqi@0 1641 // ...
aoqi@0 1642 // [ parameter 1 ]
aoqi@0 1643 // [ expression stack ]
aoqi@0 1644 //
aoqi@0 1645 //
aoqi@0 1646 // We are free to blow any registers we like because the call_stub which brought us here
aoqi@0 1647 // initially has preserved the callee save registers already.
aoqi@0 1648 //
aoqi@0 1649 //
aoqi@0 1650
aoqi@0 1651 static address interpreter_frame_manager = NULL;
aoqi@0 1652
aoqi@0 1653 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
aoqi@0 1654
aoqi@0 1655 // rbx: Method*
aoqi@0 1656 // rsi/r13: sender sp
aoqi@0 1657
aoqi@0 1658 // Because we redispatch "recursive" interpreter entries thru this same entry point
aoqi@0 1659 // the "input" register usage is a little strange and not what you expect coming
aoqi@0 1660 // from the call_stub. From the call stub rsi/rdi (current/previous) interpreter
aoqi@0 1661 // state are NULL but on "recursive" dispatches they are what you'd expect.
aoqi@0 1662 // rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2)
aoqi@0 1663
aoqi@0 1664
aoqi@0 1665 // A single frame manager is plenty as we don't specialize for synchronized. We could and
aoqi@0 1666 // the code is pretty much ready. Would need to change the test below and for good measure
aoqi@0 1667 // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
aoqi@0 1668 // routines. Not clear this is worth it yet.
aoqi@0 1669
aoqi@0 1670 if (interpreter_frame_manager) return interpreter_frame_manager;
aoqi@0 1671
aoqi@0 1672 address entry_point = __ pc();
aoqi@0 1673
aoqi@0 1674 // Fast accessor methods share this entry point.
aoqi@0 1675 // This works because frame manager is in the same codelet
aoqi@0 1676 if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path);
aoqi@0 1677
aoqi@0 1678 Label dispatch_entry_2;
aoqi@0 1679 __ movptr(rcx, sender_sp_on_entry);
aoqi@0 1680 __ movptr(state, (int32_t)NULL_WORD); // no current activation
aoqi@0 1681
aoqi@0 1682 __ jmp(dispatch_entry_2);
aoqi@0 1683
aoqi@0 1684 const Register locals = rdi;
aoqi@0 1685
aoqi@0 1686 Label re_dispatch;
aoqi@0 1687
aoqi@0 1688 __ bind(re_dispatch);
aoqi@0 1689
aoqi@0 1690 // save sender sp (doesn't include return address
aoqi@0 1691 __ lea(rcx, Address(rsp, wordSize));
aoqi@0 1692
aoqi@0 1693 __ bind(dispatch_entry_2);
aoqi@0 1694
aoqi@0 1695 // save sender sp
aoqi@0 1696 __ push(rcx);
aoqi@0 1697
aoqi@0 1698 const Address constMethod (rbx, Method::const_offset());
aoqi@0 1699 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 1700 const Address size_of_parameters(rdx, ConstMethod::size_of_parameters_offset());
aoqi@0 1701 const Address size_of_locals (rdx, ConstMethod::size_of_locals_offset());
aoqi@0 1702
aoqi@0 1703 // const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
aoqi@0 1704 // const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
aoqi@0 1705 // const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
aoqi@0 1706
aoqi@0 1707 // get parameter size (always needed)
aoqi@0 1708 __ movptr(rdx, constMethod);
aoqi@0 1709 __ load_unsigned_short(rcx, size_of_parameters);
aoqi@0 1710
aoqi@0 1711 // rbx: Method*
aoqi@0 1712 // rcx: size of parameters
aoqi@0 1713 __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
aoqi@0 1714
aoqi@0 1715 __ subptr(rdx, rcx); // rdx = no. of additional locals
aoqi@0 1716
aoqi@0 1717 // see if we've got enough room on the stack for locals plus overhead.
aoqi@0 1718 generate_stack_overflow_check(); // C++
aoqi@0 1719
aoqi@0 1720 // c++ interpreter does not use stack banging or any implicit exceptions
aoqi@0 1721 // leave for now to verify that check is proper.
aoqi@0 1722 bang_stack_shadow_pages(false);
aoqi@0 1723
aoqi@0 1724
aoqi@0 1725
aoqi@0 1726 // compute beginning of parameters (rdi)
aoqi@0 1727 __ lea(locals, Address(rsp, rcx, Address::times_ptr, wordSize));
aoqi@0 1728
aoqi@0 1729 // save sender's sp
aoqi@0 1730 // __ movl(rcx, rsp);
aoqi@0 1731
aoqi@0 1732 // get sender's sp
aoqi@0 1733 __ pop(rcx);
aoqi@0 1734
aoqi@0 1735 // get return address
aoqi@0 1736 __ pop(rax);
aoqi@0 1737
aoqi@0 1738 // rdx - # of additional locals
aoqi@0 1739 // allocate space for locals
aoqi@0 1740 // explicitly initialize locals
aoqi@0 1741 {
aoqi@0 1742 Label exit, loop;
aoqi@0 1743 __ testl(rdx, rdx); // (32bit ok)
aoqi@0 1744 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
aoqi@0 1745 __ bind(loop);
aoqi@0 1746 __ push((int32_t)NULL_WORD); // initialize local variables
aoqi@0 1747 __ decrement(rdx); // until everything initialized
aoqi@0 1748 __ jcc(Assembler::greater, loop);
aoqi@0 1749 __ bind(exit);
aoqi@0 1750 }
aoqi@0 1751
aoqi@0 1752
aoqi@0 1753 // Assumes rax = return address
aoqi@0 1754
aoqi@0 1755 // allocate and initialize new interpreterState and method expression stack
aoqi@0 1756 // IN(locals) -> locals
aoqi@0 1757 // IN(state) -> any current interpreter activation
aoqi@0 1758 // destroys rax, rcx, rdx, rdi
aoqi@0 1759 // OUT (state) -> new interpreterState
aoqi@0 1760 // OUT(rsp) -> bottom of methods expression stack
aoqi@0 1761
aoqi@0 1762 generate_compute_interpreter_state(state, locals, rcx, false);
aoqi@0 1763
aoqi@0 1764 // Call interpreter
aoqi@0 1765
aoqi@0 1766 Label call_interpreter;
aoqi@0 1767 __ bind(call_interpreter);
aoqi@0 1768
aoqi@0 1769 // c++ interpreter does not use stack banging or any implicit exceptions
aoqi@0 1770 // leave for now to verify that check is proper.
aoqi@0 1771 bang_stack_shadow_pages(false);
aoqi@0 1772
aoqi@0 1773
aoqi@0 1774 // Call interpreter enter here if message is
aoqi@0 1775 // set and we know stack size is valid
aoqi@0 1776
aoqi@0 1777 Label call_interpreter_2;
aoqi@0 1778
aoqi@0 1779 __ bind(call_interpreter_2);
aoqi@0 1780
aoqi@0 1781 {
aoqi@0 1782 const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
aoqi@0 1783
aoqi@0 1784 #ifdef _LP64
aoqi@0 1785 __ mov(c_rarg0, state);
aoqi@0 1786 #else
aoqi@0 1787 __ push(state); // push arg to interpreter
aoqi@0 1788 __ movptr(thread, STATE(_thread));
aoqi@0 1789 #endif // _LP64
aoqi@0 1790
aoqi@0 1791 // We can setup the frame anchor with everything we want at this point
aoqi@0 1792 // as we are thread_in_Java and no safepoints can occur until we go to
aoqi@0 1793 // vm mode. We do have to clear flags on return from vm but that is it
aoqi@0 1794 //
aoqi@0 1795 __ movptr(Address(thread, JavaThread::last_Java_fp_offset()), rbp);
aoqi@0 1796 __ movptr(Address(thread, JavaThread::last_Java_sp_offset()), rsp);
aoqi@0 1797
aoqi@0 1798 // Call the interpreter
aoqi@0 1799
aoqi@0 1800 RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run));
aoqi@0 1801 RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks));
aoqi@0 1802
aoqi@0 1803 __ call(JvmtiExport::can_post_interpreter_events() ? checking : normal);
aoqi@0 1804 NOT_LP64(__ pop(rax);) // discard parameter to run
aoqi@0 1805 //
aoqi@0 1806 // state is preserved since it is callee saved
aoqi@0 1807 //
aoqi@0 1808
aoqi@0 1809 // reset_last_Java_frame
aoqi@0 1810
aoqi@0 1811 NOT_LP64(__ movl(thread, STATE(_thread));)
aoqi@0 1812 __ reset_last_Java_frame(thread, true, true);
aoqi@0 1813 }
aoqi@0 1814
aoqi@0 1815 // examine msg from interpreter to determine next action
aoqi@0 1816
aoqi@0 1817 __ movl(rdx, STATE(_msg)); // Get new message
aoqi@0 1818
aoqi@0 1819 Label call_method;
aoqi@0 1820 Label return_from_interpreted_method;
aoqi@0 1821 Label throw_exception;
aoqi@0 1822 Label bad_msg;
aoqi@0 1823 Label do_OSR;
aoqi@0 1824
aoqi@0 1825 __ cmpl(rdx, (int32_t)BytecodeInterpreter::call_method);
aoqi@0 1826 __ jcc(Assembler::equal, call_method);
aoqi@0 1827 __ cmpl(rdx, (int32_t)BytecodeInterpreter::return_from_method);
aoqi@0 1828 __ jcc(Assembler::equal, return_from_interpreted_method);
aoqi@0 1829 __ cmpl(rdx, (int32_t)BytecodeInterpreter::do_osr);
aoqi@0 1830 __ jcc(Assembler::equal, do_OSR);
aoqi@0 1831 __ cmpl(rdx, (int32_t)BytecodeInterpreter::throwing_exception);
aoqi@0 1832 __ jcc(Assembler::equal, throw_exception);
aoqi@0 1833 __ cmpl(rdx, (int32_t)BytecodeInterpreter::more_monitors);
aoqi@0 1834 __ jcc(Assembler::notEqual, bad_msg);
aoqi@0 1835
aoqi@0 1836 // Allocate more monitor space, shuffle expression stack....
aoqi@0 1837
aoqi@0 1838 generate_more_monitors();
aoqi@0 1839
aoqi@0 1840 __ jmp(call_interpreter);
aoqi@0 1841
aoqi@0 1842 // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
aoqi@0 1843 unctrap_frame_manager_entry = __ pc();
aoqi@0 1844 //
aoqi@0 1845 // Load the registers we need.
aoqi@0 1846 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1847 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 1848 __ jmp(call_interpreter_2);
aoqi@0 1849
aoqi@0 1850
aoqi@0 1851
aoqi@0 1852 //=============================================================================
aoqi@0 1853 // Returning from a compiled method into a deopted method. The bytecode at the
aoqi@0 1854 // bcp has completed. The result of the bytecode is in the native abi (the tosca
aoqi@0 1855 // for the template based interpreter). Any stack space that was used by the
aoqi@0 1856 // bytecode that has completed has been removed (e.g. parameters for an invoke)
aoqi@0 1857 // so all that we have to do is place any pending result on the expression stack
aoqi@0 1858 // and resume execution on the next bytecode.
aoqi@0 1859
aoqi@0 1860
aoqi@0 1861 generate_deopt_handling();
aoqi@0 1862 __ jmp(call_interpreter);
aoqi@0 1863
aoqi@0 1864
aoqi@0 1865 // Current frame has caught an exception we need to dispatch to the
aoqi@0 1866 // handler. We can get here because a native interpreter frame caught
aoqi@0 1867 // an exception in which case there is no handler and we must rethrow
aoqi@0 1868 // If it is a vanilla interpreted frame the we simply drop into the
aoqi@0 1869 // interpreter and let it do the lookup.
aoqi@0 1870
aoqi@0 1871 Interpreter::_rethrow_exception_entry = __ pc();
aoqi@0 1872 // rax: exception
aoqi@0 1873 // rdx: return address/pc that threw exception
aoqi@0 1874
aoqi@0 1875 Label return_with_exception;
aoqi@0 1876 Label unwind_and_forward;
aoqi@0 1877
aoqi@0 1878 // restore state pointer.
aoqi@0 1879 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1880
aoqi@0 1881 __ movptr(rbx, STATE(_method)); // get method
aoqi@0 1882 #ifdef _LP64
aoqi@0 1883 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
aoqi@0 1884 #else
aoqi@0 1885 __ movl(rcx, STATE(_thread)); // get thread
aoqi@0 1886
aoqi@0 1887 // Store exception with interpreter will expect it
aoqi@0 1888 __ movptr(Address(rcx, Thread::pending_exception_offset()), rax);
aoqi@0 1889 #endif // _LP64
aoqi@0 1890
aoqi@0 1891 // is current frame vanilla or native?
aoqi@0 1892
aoqi@0 1893 __ movl(rdx, access_flags);
aoqi@0 1894 __ testl(rdx, JVM_ACC_NATIVE);
aoqi@0 1895 __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly
aoqi@0 1896
aoqi@0 1897 // We drop thru to unwind a native interpreted frame with a pending exception
aoqi@0 1898 // We jump here for the initial interpreter frame with exception pending
aoqi@0 1899 // We unwind the current acivation and forward it to our caller.
aoqi@0 1900
aoqi@0 1901 __ bind(unwind_and_forward);
aoqi@0 1902
aoqi@0 1903 // unwind rbp, return stack to unextended value and re-push return address
aoqi@0 1904
aoqi@0 1905 __ movptr(rcx, STATE(_sender_sp));
aoqi@0 1906 __ leave();
aoqi@0 1907 __ pop(rdx);
aoqi@0 1908 __ mov(rsp, rcx);
aoqi@0 1909 __ push(rdx);
aoqi@0 1910 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 1911
aoqi@0 1912 // Return point from a call which returns a result in the native abi
aoqi@0 1913 // (c1/c2/jni-native). This result must be processed onto the java
aoqi@0 1914 // expression stack.
aoqi@0 1915 //
aoqi@0 1916 // A pending exception may be present in which case there is no result present
aoqi@0 1917
aoqi@0 1918 Label resume_interpreter;
aoqi@0 1919 Label do_float;
aoqi@0 1920 Label do_double;
aoqi@0 1921 Label done_conv;
aoqi@0 1922
aoqi@0 1923 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
aoqi@0 1924 if (UseSSE < 2) {
aoqi@0 1925 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1926 __ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed
aoqi@0 1927 __ movl(rcx, Address(rbx, Method::result_index_offset()));
aoqi@0 1928 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
aoqi@0 1929 __ jcc(Assembler::equal, do_float);
aoqi@0 1930 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
aoqi@0 1931 __ jcc(Assembler::equal, do_double);
aoqi@0 1932 #if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)
aoqi@0 1933 __ empty_FPU_stack();
aoqi@0 1934 #endif // COMPILER2
aoqi@0 1935 __ jmp(done_conv);
aoqi@0 1936
aoqi@0 1937 __ bind(do_float);
aoqi@0 1938 #ifdef COMPILER2
aoqi@0 1939 for (int i = 1; i < 8; i++) {
aoqi@0 1940 __ ffree(i);
aoqi@0 1941 }
aoqi@0 1942 #endif // COMPILER2
aoqi@0 1943 __ jmp(done_conv);
aoqi@0 1944 __ bind(do_double);
aoqi@0 1945 #ifdef COMPILER2
aoqi@0 1946 for (int i = 1; i < 8; i++) {
aoqi@0 1947 __ ffree(i);
aoqi@0 1948 }
aoqi@0 1949 #endif // COMPILER2
aoqi@0 1950 __ jmp(done_conv);
aoqi@0 1951 } else {
aoqi@0 1952 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
aoqi@0 1953 __ jmp(done_conv);
aoqi@0 1954 }
aoqi@0 1955
aoqi@0 1956 // Return point to interpreter from compiled/native method
aoqi@0 1957 InternalAddress return_from_native_method(__ pc());
aoqi@0 1958
aoqi@0 1959 __ bind(done_conv);
aoqi@0 1960
aoqi@0 1961
aoqi@0 1962 // Result if any is in tosca. The java expression stack is in the state that the
aoqi@0 1963 // calling convention left it (i.e. params may or may not be present)
aoqi@0 1964 // Copy the result from tosca and place it on java expression stack.
aoqi@0 1965
aoqi@0 1966 // Restore rsi/r13 as compiled code may not preserve it
aoqi@0 1967
aoqi@0 1968 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1969
aoqi@0 1970 // restore stack to what we had when we left (in case i2c extended it)
aoqi@0 1971
aoqi@0 1972 __ movptr(rsp, STATE(_stack));
aoqi@0 1973 __ lea(rsp, Address(rsp, wordSize));
aoqi@0 1974
aoqi@0 1975 // If there is a pending exception then we don't really have a result to process
aoqi@0 1976
aoqi@0 1977 #ifdef _LP64
aoqi@0 1978 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1979 #else
aoqi@0 1980 __ movptr(rcx, STATE(_thread)); // get thread
aoqi@0 1981 __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1982 #endif // _LP64
aoqi@0 1983 __ jcc(Assembler::notZero, return_with_exception);
aoqi@0 1984
aoqi@0 1985 // get method just executed
aoqi@0 1986 __ movptr(rbx, STATE(_result._to_call._callee));
aoqi@0 1987
aoqi@0 1988 // callee left args on top of expression stack, remove them
aoqi@0 1989 __ movptr(rcx, constMethod);
aoqi@0 1990 __ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));
aoqi@0 1991
aoqi@0 1992 __ lea(rsp, Address(rsp, rcx, Address::times_ptr));
aoqi@0 1993
aoqi@0 1994 __ movl(rcx, Address(rbx, Method::result_index_offset()));
aoqi@0 1995 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
aoqi@0 1996 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 1997 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
aoqi@0 1998 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
aoqi@0 1999 __ call(rcx); // call result converter
aoqi@0 2000 __ jmp(resume_interpreter);
aoqi@0 2001
aoqi@0 2002 // An exception is being caught on return to a vanilla interpreter frame.
aoqi@0 2003 // Empty the stack and resume interpreter
aoqi@0 2004
aoqi@0 2005 __ bind(return_with_exception);
aoqi@0 2006
aoqi@0 2007 // Exception present, empty stack
aoqi@0 2008 __ movptr(rsp, STATE(_stack_base));
aoqi@0 2009 __ jmp(resume_interpreter);
aoqi@0 2010
aoqi@0 2011 // Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
aoqi@0 2012 // interpreter call, or native) and unwind this interpreter activation.
aoqi@0 2013 // All monitors should be unlocked.
aoqi@0 2014
aoqi@0 2015 __ bind(return_from_interpreted_method);
aoqi@0 2016
aoqi@0 2017 Label return_to_initial_caller;
aoqi@0 2018
aoqi@0 2019 __ movptr(rbx, STATE(_method)); // get method just executed
aoqi@0 2020 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
aoqi@0 2021 __ movl(rax, Address(rbx, Method::result_index_offset())); // get result type index
aoqi@0 2022 __ jcc(Assembler::equal, return_to_initial_caller); // back to native code (call_stub/c1/c2)
aoqi@0 2023
aoqi@0 2024 // Copy result to callers java stack
aoqi@0 2025 ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack);
aoqi@0 2026 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 2027
aoqi@0 2028 __ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_ptr)));
aoqi@0 2029 // __ movl(rax, Address(noreg, rax, Address::times_ptr, int(AbstractInterpreter::_stack_to_stack)));
aoqi@0 2030 __ call(rax); // call result converter
aoqi@0 2031
aoqi@0 2032 Label unwind_recursive_activation;
aoqi@0 2033 __ bind(unwind_recursive_activation);
aoqi@0 2034
aoqi@0 2035 // returning to interpreter method from "recursive" interpreter call
aoqi@0 2036 // result converter left rax pointing to top of the java stack for method we are returning
aoqi@0 2037 // to. Now all we must do is unwind the state from the completed call
aoqi@0 2038
aoqi@0 2039 __ movptr(state, STATE(_prev_link)); // unwind state
aoqi@0 2040 __ leave(); // pop the frame
aoqi@0 2041 __ mov(rsp, rax); // unwind stack to remove args
aoqi@0 2042
aoqi@0 2043 // Resume the interpreter. The current frame contains the current interpreter
aoqi@0 2044 // state object.
aoqi@0 2045 //
aoqi@0 2046
aoqi@0 2047 __ bind(resume_interpreter);
aoqi@0 2048
aoqi@0 2049 // state == interpreterState object for method we are resuming
aoqi@0 2050
aoqi@0 2051 __ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume);
aoqi@0 2052 __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
aoqi@0 2053 __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
aoqi@0 2054 // result if any on stack already )
aoqi@0 2055 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 2056 __ jmp(call_interpreter_2); // No need to bang
aoqi@0 2057
aoqi@0 2058 // interpreter returning to native code (call_stub/c1/c2)
aoqi@0 2059 // convert result and unwind initial activation
aoqi@0 2060 // rax - result index
aoqi@0 2061
aoqi@0 2062 __ bind(return_to_initial_caller);
aoqi@0 2063 ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi);
aoqi@0 2064 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 2065
aoqi@0 2066 __ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_ptr)));
aoqi@0 2067 __ call(rax); // call result converter
aoqi@0 2068
aoqi@0 2069 Label unwind_initial_activation;
aoqi@0 2070 __ bind(unwind_initial_activation);
aoqi@0 2071
aoqi@0 2072 // RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0))
aoqi@0 2073
aoqi@0 2074 /* Current stack picture
aoqi@0 2075
aoqi@0 2076 [ incoming parameters ]
aoqi@0 2077 [ extra locals ]
aoqi@0 2078 [ return address to CALL_STUB/C1/C2]
aoqi@0 2079 fp -> [ CALL_STUB/C1/C2 fp ]
aoqi@0 2080 BytecodeInterpreter object
aoqi@0 2081 expression stack
aoqi@0 2082 sp ->
aoqi@0 2083
aoqi@0 2084 */
aoqi@0 2085
aoqi@0 2086 // return restoring the stack to the original sender_sp value
aoqi@0 2087
aoqi@0 2088 __ movptr(rcx, STATE(_sender_sp));
aoqi@0 2089 __ leave();
aoqi@0 2090 __ pop(rdi); // get return address
aoqi@0 2091 // set stack to sender's sp
aoqi@0 2092 __ mov(rsp, rcx);
aoqi@0 2093 __ jmp(rdi); // return to call_stub
aoqi@0 2094
aoqi@0 2095 // OSR request, adjust return address to make current frame into adapter frame
aoqi@0 2096 // and enter OSR nmethod
aoqi@0 2097
aoqi@0 2098 __ bind(do_OSR);
aoqi@0 2099
aoqi@0 2100 Label remove_initial_frame;
aoqi@0 2101
aoqi@0 2102 // We are going to pop this frame. Is there another interpreter frame underneath
aoqi@0 2103 // it or is it callstub/compiled?
aoqi@0 2104
aoqi@0 2105 // Move buffer to the expected parameter location
aoqi@0 2106 __ movptr(rcx, STATE(_result._osr._osr_buf));
aoqi@0 2107
aoqi@0 2108 __ movptr(rax, STATE(_result._osr._osr_entry));
aoqi@0 2109
aoqi@0 2110 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
aoqi@0 2111 __ jcc(Assembler::equal, remove_initial_frame); // back to native code (call_stub/c1/c2)
aoqi@0 2112
aoqi@0 2113 __ movptr(sender_sp_on_entry, STATE(_sender_sp)); // get sender's sp in expected register
aoqi@0 2114 __ leave(); // pop the frame
aoqi@0 2115 __ mov(rsp, sender_sp_on_entry); // trim any stack expansion
aoqi@0 2116
aoqi@0 2117
aoqi@0 2118 // We know we are calling compiled so push specialized return
aoqi@0 2119 // method uses specialized entry, push a return so we look like call stub setup
aoqi@0 2120 // this path will handle fact that result is returned in registers and not
aoqi@0 2121 // on the java stack.
aoqi@0 2122
aoqi@0 2123 __ pushptr(return_from_native_method.addr());
aoqi@0 2124
aoqi@0 2125 __ jmp(rax);
aoqi@0 2126
aoqi@0 2127 __ bind(remove_initial_frame);
aoqi@0 2128
aoqi@0 2129 __ movptr(rdx, STATE(_sender_sp));
aoqi@0 2130 __ leave();
aoqi@0 2131 // get real return
aoqi@0 2132 __ pop(rsi);
aoqi@0 2133 // set stack to sender's sp
aoqi@0 2134 __ mov(rsp, rdx);
aoqi@0 2135 // repush real return
aoqi@0 2136 __ push(rsi);
aoqi@0 2137 // Enter OSR nmethod
aoqi@0 2138 __ jmp(rax);
aoqi@0 2139
aoqi@0 2140
aoqi@0 2141
aoqi@0 2142
aoqi@0 2143 // Call a new method. All we do is (temporarily) trim the expression stack
aoqi@0 2144 // push a return address to bring us back to here and leap to the new entry.
aoqi@0 2145
aoqi@0 2146 __ bind(call_method);
aoqi@0 2147
aoqi@0 2148 // stack points to next free location and not top element on expression stack
aoqi@0 2149 // method expects sp to be pointing to topmost element
aoqi@0 2150
aoqi@0 2151 __ movptr(rsp, STATE(_stack)); // pop args to c++ interpreter, set sp to java stack top
aoqi@0 2152 __ lea(rsp, Address(rsp, wordSize));
aoqi@0 2153
aoqi@0 2154 __ movptr(rbx, STATE(_result._to_call._callee)); // get method to execute
aoqi@0 2155
aoqi@0 2156 // don't need a return address if reinvoking interpreter
aoqi@0 2157
aoqi@0 2158 // Make it look like call_stub calling conventions
aoqi@0 2159
aoqi@0 2160 // Get (potential) receiver
aoqi@0 2161 // get size of parameters in words
aoqi@0 2162 __ movptr(rcx, constMethod);
aoqi@0 2163 __ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));
aoqi@0 2164
aoqi@0 2165 ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
aoqi@0 2166 __ pushptr(recursive.addr()); // make it look good in the debugger
aoqi@0 2167
aoqi@0 2168 InternalAddress entry(entry_point);
aoqi@0 2169 __ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter?
aoqi@0 2170 __ jcc(Assembler::equal, re_dispatch); // yes
aoqi@0 2171
aoqi@0 2172 __ pop(rax); // pop dummy address
aoqi@0 2173
aoqi@0 2174
aoqi@0 2175 // get specialized entry
aoqi@0 2176 __ movptr(rax, STATE(_result._to_call._callee_entry_point));
aoqi@0 2177 // set sender SP
aoqi@0 2178 __ mov(sender_sp_on_entry, rsp);
aoqi@0 2179
aoqi@0 2180 // method uses specialized entry, push a return so we look like call stub setup
aoqi@0 2181 // this path will handle fact that result is returned in registers and not
aoqi@0 2182 // on the java stack.
aoqi@0 2183
aoqi@0 2184 __ pushptr(return_from_native_method.addr());
aoqi@0 2185
aoqi@0 2186 __ jmp(rax);
aoqi@0 2187
aoqi@0 2188 __ bind(bad_msg);
aoqi@0 2189 __ stop("Bad message from interpreter");
aoqi@0 2190
aoqi@0 2191 // Interpreted method "returned" with an exception pass it on...
aoqi@0 2192 // Pass result, unwind activation and continue/return to interpreter/call_stub
aoqi@0 2193 // We handle result (if any) differently based on return to interpreter or call_stub
aoqi@0 2194
aoqi@0 2195 Label unwind_initial_with_pending_exception;
aoqi@0 2196
aoqi@0 2197 __ bind(throw_exception);
aoqi@0 2198 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from recursive interpreter call?
aoqi@0 2199 __ jcc(Assembler::equal, unwind_initial_with_pending_exception); // no, back to native code (call_stub/c1/c2)
aoqi@0 2200 __ movptr(rax, STATE(_locals)); // pop parameters get new stack value
aoqi@0 2201 __ addptr(rax, wordSize); // account for prepush before we return
aoqi@0 2202 __ jmp(unwind_recursive_activation);
aoqi@0 2203
aoqi@0 2204 __ bind(unwind_initial_with_pending_exception);
aoqi@0 2205
aoqi@0 2206 // We will unwind the current (initial) interpreter frame and forward
aoqi@0 2207 // the exception to the caller. We must put the exception in the
aoqi@0 2208 // expected register and clear pending exception and then forward.
aoqi@0 2209
aoqi@0 2210 __ jmp(unwind_and_forward);
aoqi@0 2211
aoqi@0 2212 interpreter_frame_manager = entry_point;
aoqi@0 2213 return entry_point;
aoqi@0 2214 }
aoqi@0 2215
aoqi@0 2216 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
aoqi@0 2217 // determine code generation flags
aoqi@0 2218 bool synchronized = false;
aoqi@0 2219 address entry_point = NULL;
aoqi@0 2220
aoqi@0 2221 switch (kind) {
aoqi@0 2222 case Interpreter::zerolocals : break;
aoqi@0 2223 case Interpreter::zerolocals_synchronized: synchronized = true; break;
aoqi@0 2224 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
aoqi@0 2225 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
aoqi@0 2226 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
aoqi@0 2227 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
aoqi@0 2228 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
aoqi@0 2229 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
aoqi@0 2230
aoqi@0 2231 case Interpreter::java_lang_math_sin : // fall thru
aoqi@0 2232 case Interpreter::java_lang_math_cos : // fall thru
aoqi@0 2233 case Interpreter::java_lang_math_tan : // fall thru
aoqi@0 2234 case Interpreter::java_lang_math_abs : // fall thru
aoqi@0 2235 case Interpreter::java_lang_math_log : // fall thru
aoqi@0 2236 case Interpreter::java_lang_math_log10 : // fall thru
aoqi@0 2237 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
aoqi@0 2238 case Interpreter::java_lang_ref_reference_get
aoqi@0 2239 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
aoqi@0 2240 default : ShouldNotReachHere(); break;
aoqi@0 2241 }
aoqi@0 2242
aoqi@0 2243 if (entry_point) return entry_point;
aoqi@0 2244
aoqi@0 2245 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
aoqi@0 2246
aoqi@0 2247 }
aoqi@0 2248
aoqi@0 2249 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
aoqi@0 2250 : CppInterpreterGenerator(code) {
aoqi@0 2251 generate_all(); // down here so it can be "virtual"
aoqi@0 2252 }
aoqi@0 2253
aoqi@0 2254 // Deoptimization helpers for C++ interpreter
aoqi@0 2255
aoqi@0 2256 // How much stack a method activation needs in words.
aoqi@0 2257 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
aoqi@0 2258
aoqi@0 2259 const int stub_code = 4; // see generate_call_stub
aoqi@0 2260 // Save space for one monitor to get into the interpreted method in case
aoqi@0 2261 // the method is synchronized
aoqi@0 2262 int monitor_size = method->is_synchronized() ?
aoqi@0 2263 1*frame::interpreter_frame_monitor_size() : 0;
aoqi@0 2264
aoqi@0 2265 // total static overhead size. Account for interpreter state object, return
aoqi@0 2266 // address, saved rbp and 2 words for a "static long no_params() method" issue.
aoqi@0 2267
aoqi@0 2268 const int overhead_size = sizeof(BytecodeInterpreter)/wordSize +
aoqi@0 2269 ( frame::sender_sp_offset - frame::link_offset) + 2;
aoqi@0 2270
aoqi@0 2271 const int method_stack = (method->max_locals() + method->max_stack()) *
aoqi@0 2272 Interpreter::stackElementWords;
aoqi@0 2273 return overhead_size + method_stack + stub_code;
aoqi@0 2274 }
aoqi@0 2275
aoqi@0 2276 // returns the activation size.
aoqi@0 2277 static int size_activation_helper(int extra_locals_size, int monitor_size) {
aoqi@0 2278 return (extra_locals_size + // the addition space for locals
aoqi@0 2279 2*BytesPerWord + // return address and saved rbp
aoqi@0 2280 2*BytesPerWord + // "static long no_params() method" issue
aoqi@0 2281 sizeof(BytecodeInterpreter) + // interpreterState
aoqi@0 2282 monitor_size); // monitors
aoqi@0 2283 }
aoqi@0 2284
aoqi@0 2285 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
aoqi@0 2286 frame* caller,
aoqi@0 2287 frame* current,
aoqi@0 2288 Method* method,
aoqi@0 2289 intptr_t* locals,
aoqi@0 2290 intptr_t* stack,
aoqi@0 2291 intptr_t* stack_base,
aoqi@0 2292 intptr_t* monitor_base,
aoqi@0 2293 intptr_t* frame_bottom,
aoqi@0 2294 bool is_top_frame
aoqi@0 2295 )
aoqi@0 2296 {
aoqi@0 2297 // What about any vtable?
aoqi@0 2298 //
aoqi@0 2299 to_fill->_thread = JavaThread::current();
aoqi@0 2300 // This gets filled in later but make it something recognizable for now
aoqi@0 2301 to_fill->_bcp = method->code_base();
aoqi@0 2302 to_fill->_locals = locals;
aoqi@0 2303 to_fill->_constants = method->constants()->cache();
aoqi@0 2304 to_fill->_method = method;
aoqi@0 2305 to_fill->_mdx = NULL;
aoqi@0 2306 to_fill->_stack = stack;
aoqi@0 2307 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {
aoqi@0 2308 to_fill->_msg = deopt_resume2;
aoqi@0 2309 } else {
aoqi@0 2310 to_fill->_msg = method_resume;
aoqi@0 2311 }
aoqi@0 2312 to_fill->_result._to_call._bcp_advance = 0;
aoqi@0 2313 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
aoqi@0 2314 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
aoqi@0 2315 to_fill->_prev_link = NULL;
aoqi@0 2316
aoqi@0 2317 to_fill->_sender_sp = caller->unextended_sp();
aoqi@0 2318
aoqi@0 2319 if (caller->is_interpreted_frame()) {
aoqi@0 2320 interpreterState prev = caller->get_interpreterState();
aoqi@0 2321 to_fill->_prev_link = prev;
aoqi@0 2322 // *current->register_addr(GR_Iprev_state) = (intptr_t) prev;
aoqi@0 2323 // Make the prev callee look proper
aoqi@0 2324 prev->_result._to_call._callee = method;
aoqi@0 2325 if (*prev->_bcp == Bytecodes::_invokeinterface) {
aoqi@0 2326 prev->_result._to_call._bcp_advance = 5;
aoqi@0 2327 } else {
aoqi@0 2328 prev->_result._to_call._bcp_advance = 3;
aoqi@0 2329 }
aoqi@0 2330 }
aoqi@0 2331 to_fill->_oop_temp = NULL;
aoqi@0 2332 to_fill->_stack_base = stack_base;
aoqi@0 2333 // Need +1 here because stack_base points to the word just above the first expr stack entry
aoqi@0 2334 // and stack_limit is supposed to point to the word just below the last expr stack entry.
aoqi@0 2335 // See generate_compute_interpreter_state.
aoqi@0 2336 to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
aoqi@0 2337 to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
aoqi@0 2338
aoqi@0 2339 to_fill->_self_link = to_fill;
aoqi@0 2340 assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
aoqi@0 2341 "Stack top out of range");
aoqi@0 2342 }
aoqi@0 2343
aoqi@0 2344
aoqi@0 2345 static int frame_size_helper(int max_stack,
aoqi@0 2346 int tempcount,
aoqi@0 2347 int moncount,
aoqi@0 2348 int callee_param_count,
aoqi@0 2349 int callee_locals,
aoqi@0 2350 bool is_top_frame,
aoqi@0 2351 int& monitor_size,
aoqi@0 2352 int& full_frame_size) {
aoqi@0 2353 int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
aoqi@0 2354 monitor_size = sizeof(BasicObjectLock) * moncount;
aoqi@0 2355
aoqi@0 2356 // First calculate the frame size without any java expression stack
aoqi@0 2357 int short_frame_size = size_activation_helper(extra_locals_size,
aoqi@0 2358 monitor_size);
aoqi@0 2359
aoqi@0 2360 // Now with full size expression stack
aoqi@0 2361 full_frame_size = short_frame_size + max_stack * BytesPerWord;
aoqi@0 2362
aoqi@0 2363 // and now with only live portion of the expression stack
aoqi@0 2364 short_frame_size = short_frame_size + tempcount * BytesPerWord;
aoqi@0 2365
aoqi@0 2366 // the size the activation is right now. Only top frame is full size
aoqi@0 2367 int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
aoqi@0 2368 return frame_size;
aoqi@0 2369 }
aoqi@0 2370
aoqi@0 2371 int AbstractInterpreter::size_activation(int max_stack,
aoqi@0 2372 int tempcount,
aoqi@0 2373 int extra_args,
aoqi@0 2374 int moncount,
aoqi@0 2375 int callee_param_count,
aoqi@0 2376 int callee_locals,
aoqi@0 2377 bool is_top_frame) {
aoqi@0 2378 assert(extra_args == 0, "FIX ME");
aoqi@0 2379 // NOTE: return size is in words not bytes
aoqi@0 2380
aoqi@0 2381 // Calculate the amount our frame will be adjust by the callee. For top frame
aoqi@0 2382 // this is zero.
aoqi@0 2383
aoqi@0 2384 // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
aoqi@0 2385 // calculates the extra locals based on itself. Not what the callee does
aoqi@0 2386 // to it. So it ignores last_frame_adjust value. Seems suspicious as far
aoqi@0 2387 // as getting sender_sp correct.
aoqi@0 2388
aoqi@0 2389 int unused_monitor_size = 0;
aoqi@0 2390 int unused_full_frame_size = 0;
aoqi@0 2391 return frame_size_helper(max_stack, tempcount, moncount, callee_param_count, callee_locals,
aoqi@0 2392 is_top_frame, unused_monitor_size, unused_full_frame_size)/BytesPerWord;
aoqi@0 2393 }
aoqi@0 2394
aoqi@0 2395 void AbstractInterpreter::layout_activation(Method* method,
aoqi@0 2396 int tempcount, //
aoqi@0 2397 int popframe_extra_args,
aoqi@0 2398 int moncount,
aoqi@0 2399 int caller_actual_parameters,
aoqi@0 2400 int callee_param_count,
aoqi@0 2401 int callee_locals,
aoqi@0 2402 frame* caller,
aoqi@0 2403 frame* interpreter_frame,
aoqi@0 2404 bool is_top_frame,
aoqi@0 2405 bool is_bottom_frame) {
aoqi@0 2406
aoqi@0 2407 assert(popframe_extra_args == 0, "FIX ME");
aoqi@0 2408 // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
aoqi@0 2409 // does as far as allocating an interpreter frame.
aoqi@0 2410 // Set up the method, locals, and monitors.
aoqi@0 2411 // The frame interpreter_frame is guaranteed to be the right size,
aoqi@0 2412 // as determined by a previous call to the size_activation() method.
aoqi@0 2413 // It is also guaranteed to be walkable even though it is in a skeletal state
aoqi@0 2414 // NOTE: tempcount is the current size of the java expression stack. For top most
aoqi@0 2415 // frames we will allocate a full sized expression stack and not the curback
aoqi@0 2416 // version that non-top frames have.
aoqi@0 2417
aoqi@0 2418 int monitor_size = 0;
aoqi@0 2419 int full_frame_size = 0;
aoqi@0 2420 int frame_size = frame_size_helper(method->max_stack(), tempcount, moncount, callee_param_count, callee_locals,
aoqi@0 2421 is_top_frame, monitor_size, full_frame_size);
aoqi@0 2422
aoqi@0 2423 #ifdef ASSERT
aoqi@0 2424 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
aoqi@0 2425 #endif
aoqi@0 2426
aoqi@0 2427 // MUCHO HACK
aoqi@0 2428
aoqi@0 2429 intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
aoqi@0 2430
aoqi@0 2431 /* Now fillin the interpreterState object */
aoqi@0 2432
aoqi@0 2433 // The state object is the first thing on the frame and easily located
aoqi@0 2434
aoqi@0 2435 interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
aoqi@0 2436
aoqi@0 2437
aoqi@0 2438 // Find the locals pointer. This is rather simple on x86 because there is no
aoqi@0 2439 // confusing rounding at the callee to account for. We can trivially locate
aoqi@0 2440 // our locals based on the current fp().
aoqi@0 2441 // Note: the + 2 is for handling the "static long no_params() method" issue.
aoqi@0 2442 // (too bad I don't really remember that issue well...)
aoqi@0 2443
aoqi@0 2444 intptr_t* locals;
aoqi@0 2445 // If the caller is interpreted we need to make sure that locals points to the first
aoqi@0 2446 // argument that the caller passed and not in an area where the stack might have been extended.
aoqi@0 2447 // because the stack to stack to converter needs a proper locals value in order to remove the
aoqi@0 2448 // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
aoqi@0 2449 // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
aoqi@0 2450 // adjust the stack?? HMMM QQQ
aoqi@0 2451 //
aoqi@0 2452 if (caller->is_interpreted_frame()) {
aoqi@0 2453 // locals must agree with the caller because it will be used to set the
aoqi@0 2454 // caller's tos when we return.
aoqi@0 2455 interpreterState prev = caller->get_interpreterState();
aoqi@0 2456 // stack() is prepushed.
aoqi@0 2457 locals = prev->stack() + method->size_of_parameters();
aoqi@0 2458 // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
aoqi@0 2459 if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
aoqi@0 2460 // os::breakpoint();
aoqi@0 2461 }
aoqi@0 2462 } else {
aoqi@0 2463 // this is where a c2i would have placed locals (except for the +2)
aoqi@0 2464 locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
aoqi@0 2465 }
aoqi@0 2466
aoqi@0 2467 intptr_t* monitor_base = (intptr_t*) cur_state;
aoqi@0 2468 intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
aoqi@0 2469 /* +1 because stack is always prepushed */
aoqi@0 2470 intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
aoqi@0 2471
aoqi@0 2472
aoqi@0 2473 BytecodeInterpreter::layout_interpreterState(cur_state,
aoqi@0 2474 caller,
aoqi@0 2475 interpreter_frame,
aoqi@0 2476 method,
aoqi@0 2477 locals,
aoqi@0 2478 stack,
aoqi@0 2479 stack_base,
aoqi@0 2480 monitor_base,
aoqi@0 2481 frame_bottom,
aoqi@0 2482 is_top_frame);
aoqi@0 2483
aoqi@0 2484 // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
aoqi@0 2485 }
aoqi@0 2486
aoqi@0 2487 #endif // CC_INTERP (all)

mercurial