src/cpu/x86/vm/cppInterpreter_x86.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6723
0bf37f737702
parent 0
f90c822e73f8
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2007, 2013, 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
aoqi@0 873 Label notByte, 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
aoqi@0 892 __ cmpl(rdx, btos);
aoqi@0 893 __ jcc(Assembler::notEqual, notByte);
aoqi@0 894 __ load_signed_byte(rax, field_address);
aoqi@0 895 __ jmp(xreturn_path);
aoqi@0 896
aoqi@0 897 __ bind(notByte);
aoqi@0 898 __ cmpl(rdx, stos);
aoqi@0 899 __ jcc(Assembler::notEqual, notShort);
aoqi@0 900 __ load_signed_short(rax, field_address);
aoqi@0 901 __ jmp(xreturn_path);
aoqi@0 902
aoqi@0 903 __ bind(notShort);
aoqi@0 904 __ cmpl(rdx, ctos);
aoqi@0 905 __ jcc(Assembler::notEqual, notChar);
aoqi@0 906 __ load_unsigned_short(rax, field_address);
aoqi@0 907 __ jmp(xreturn_path);
aoqi@0 908
aoqi@0 909 __ bind(notChar);
aoqi@0 910 #ifdef ASSERT
aoqi@0 911 Label okay;
aoqi@0 912 #ifndef _LP64
aoqi@0 913 __ cmpl(rdx, atos);
aoqi@0 914 __ jcc(Assembler::equal, okay);
aoqi@0 915 #endif // _LP64
aoqi@0 916 __ cmpl(rdx, itos);
aoqi@0 917 __ jcc(Assembler::equal, okay);
aoqi@0 918 __ stop("what type is this?");
aoqi@0 919 __ bind(okay);
aoqi@0 920 #endif // ASSERT
aoqi@0 921 // All the rest are a 32 bit wordsize
aoqi@0 922 __ movl(rax, field_address);
aoqi@0 923
aoqi@0 924 __ bind(xreturn_path);
aoqi@0 925
aoqi@0 926 // _ireturn/_areturn
aoqi@0 927 __ pop(rdi); // get return address
aoqi@0 928 __ mov(rsp, sender_sp_on_entry); // set sp to sender sp
aoqi@0 929 __ jmp(rdi);
aoqi@0 930
aoqi@0 931 // generate a vanilla interpreter entry as the slow path
aoqi@0 932 __ bind(slow_path);
aoqi@0 933 // We will enter c++ interpreter looking like it was
aoqi@0 934 // called by the call_stub this will cause it to return
aoqi@0 935 // a tosca result to the invoker which might have been
aoqi@0 936 // the c++ interpreter itself.
aoqi@0 937
aoqi@0 938 __ jmp(fast_accessor_slow_entry_path);
aoqi@0 939 return entry_point;
aoqi@0 940
aoqi@0 941 } else {
aoqi@0 942 return NULL;
aoqi@0 943 }
aoqi@0 944
aoqi@0 945 }
aoqi@0 946
aoqi@0 947 address InterpreterGenerator::generate_Reference_get_entry(void) {
aoqi@0 948 #if INCLUDE_ALL_GCS
aoqi@0 949 if (UseG1GC) {
aoqi@0 950 // We need to generate have a routine that generates code to:
aoqi@0 951 // * load the value in the referent field
aoqi@0 952 // * passes that value to the pre-barrier.
aoqi@0 953 //
aoqi@0 954 // In the case of G1 this will record the value of the
aoqi@0 955 // referent in an SATB buffer if marking is active.
aoqi@0 956 // This will cause concurrent marking to mark the referent
aoqi@0 957 // field as live.
aoqi@0 958 Unimplemented();
aoqi@0 959 }
aoqi@0 960 #endif // INCLUDE_ALL_GCS
aoqi@0 961
aoqi@0 962 // If G1 is not enabled then attempt to go through the accessor entry point
aoqi@0 963 // Reference.get is an accessor
aoqi@0 964 return generate_accessor_entry();
aoqi@0 965 }
aoqi@0 966
aoqi@0 967 //
aoqi@0 968 // C++ Interpreter stub for calling a native method.
aoqi@0 969 // This sets up a somewhat different looking stack for calling the native method
aoqi@0 970 // than the typical interpreter frame setup but still has the pointer to
aoqi@0 971 // an interpreter state.
aoqi@0 972 //
aoqi@0 973
aoqi@0 974 address InterpreterGenerator::generate_native_entry(bool synchronized) {
aoqi@0 975 // determine code generation flags
aoqi@0 976 bool inc_counter = UseCompiler || CountCompiledCalls;
aoqi@0 977
aoqi@0 978 // rbx: Method*
aoqi@0 979 // rcx: receiver (unused)
aoqi@0 980 // rsi/r13: previous interpreter state (if called from C++ interpreter) must preserve
aoqi@0 981 // in any case. If called via c1/c2/call_stub rsi/r13 is junk (to use) but harmless
aoqi@0 982 // to save/restore.
aoqi@0 983 address entry_point = __ pc();
aoqi@0 984
aoqi@0 985 const Address constMethod (rbx, Method::const_offset());
aoqi@0 986 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 987 const Address size_of_parameters(rcx, ConstMethod::size_of_parameters_offset());
aoqi@0 988
aoqi@0 989 // rsi/r13 == state/locals rdi == prevstate
aoqi@0 990 const Register locals = rdi;
aoqi@0 991
aoqi@0 992 // get parameter size (always needed)
aoqi@0 993 __ movptr(rcx, constMethod);
aoqi@0 994 __ load_unsigned_short(rcx, size_of_parameters);
aoqi@0 995
aoqi@0 996 // rbx: Method*
aoqi@0 997 // rcx: size of parameters
aoqi@0 998 __ pop(rax); // get return address
aoqi@0 999 // for natives the size of locals is zero
aoqi@0 1000
aoqi@0 1001 // compute beginning of parameters /locals
aoqi@0 1002
aoqi@0 1003 __ lea(locals, Address(rsp, rcx, Address::times_ptr, -wordSize));
aoqi@0 1004
aoqi@0 1005 // initialize fixed part of activation frame
aoqi@0 1006
aoqi@0 1007 // Assumes rax = return address
aoqi@0 1008
aoqi@0 1009 // allocate and initialize new interpreterState and method expression stack
aoqi@0 1010 // IN(locals) -> locals
aoqi@0 1011 // IN(state) -> previous frame manager state (NULL from stub/c1/c2)
aoqi@0 1012 // destroys rax, rcx, rdx
aoqi@0 1013 // OUT (state) -> new interpreterState
aoqi@0 1014 // OUT(rsp) -> bottom of methods expression stack
aoqi@0 1015
aoqi@0 1016 // save sender_sp
aoqi@0 1017 __ mov(rcx, sender_sp_on_entry);
aoqi@0 1018 // start with NULL previous state
aoqi@0 1019 __ movptr(state, (int32_t)NULL_WORD);
aoqi@0 1020 generate_compute_interpreter_state(state, locals, rcx, true);
aoqi@0 1021
aoqi@0 1022 #ifdef ASSERT
aoqi@0 1023 { Label L;
aoqi@0 1024 __ movptr(rax, STATE(_stack_base));
aoqi@0 1025 #ifdef _LP64
aoqi@0 1026 // duplicate the alignment rsp got after setting stack_base
aoqi@0 1027 __ subptr(rax, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1028 __ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 1029 #endif // _LP64
aoqi@0 1030 __ cmpptr(rax, rsp);
aoqi@0 1031 __ jcc(Assembler::equal, L);
aoqi@0 1032 __ stop("broken stack frame setup in interpreter");
aoqi@0 1033 __ bind(L);
aoqi@0 1034 }
aoqi@0 1035 #endif
aoqi@0 1036
aoqi@0 1037 const Register unlock_thread = LP64_ONLY(r15_thread) NOT_LP64(rax);
aoqi@0 1038 NOT_LP64(__ movptr(unlock_thread, STATE(_thread));) // get thread
aoqi@0 1039 // Since at this point in the method invocation the exception handler
aoqi@0 1040 // would try to exit the monitor of synchronized methods which hasn't
aoqi@0 1041 // been entered yet, we set the thread local variable
aoqi@0 1042 // _do_not_unlock_if_synchronized to true. The remove_activation will
aoqi@0 1043 // check this flag.
aoqi@0 1044
aoqi@0 1045 const Address do_not_unlock_if_synchronized(unlock_thread,
aoqi@0 1046 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
aoqi@0 1047 __ movbool(do_not_unlock_if_synchronized, true);
aoqi@0 1048
aoqi@0 1049 // make sure method is native & not abstract
aoqi@0 1050 #ifdef ASSERT
aoqi@0 1051 __ movl(rax, access_flags);
aoqi@0 1052 {
aoqi@0 1053 Label L;
aoqi@0 1054 __ testl(rax, JVM_ACC_NATIVE);
aoqi@0 1055 __ jcc(Assembler::notZero, L);
aoqi@0 1056 __ stop("tried to execute non-native method as native");
aoqi@0 1057 __ bind(L);
aoqi@0 1058 }
aoqi@0 1059 { Label L;
aoqi@0 1060 __ testl(rax, JVM_ACC_ABSTRACT);
aoqi@0 1061 __ jcc(Assembler::zero, L);
aoqi@0 1062 __ stop("tried to execute abstract method in interpreter");
aoqi@0 1063 __ bind(L);
aoqi@0 1064 }
aoqi@0 1065 #endif
aoqi@0 1066
aoqi@0 1067
aoqi@0 1068 // increment invocation count & check for overflow
aoqi@0 1069 Label invocation_counter_overflow;
aoqi@0 1070 if (inc_counter) {
aoqi@0 1071 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
aoqi@0 1072 }
aoqi@0 1073
aoqi@0 1074 Label continue_after_compile;
aoqi@0 1075
aoqi@0 1076 __ bind(continue_after_compile);
aoqi@0 1077
aoqi@0 1078 bang_stack_shadow_pages(true);
aoqi@0 1079
aoqi@0 1080 // reset the _do_not_unlock_if_synchronized flag
aoqi@0 1081 NOT_LP64(__ movl(rax, STATE(_thread));) // get thread
aoqi@0 1082 __ movbool(do_not_unlock_if_synchronized, false);
aoqi@0 1083
aoqi@0 1084
aoqi@0 1085 // check for synchronized native methods
aoqi@0 1086 //
aoqi@0 1087 // Note: This must happen *after* invocation counter check, since
aoqi@0 1088 // when overflow happens, the method should not be locked.
aoqi@0 1089 if (synchronized) {
aoqi@0 1090 // potentially kills rax, rcx, rdx, rdi
aoqi@0 1091 lock_method();
aoqi@0 1092 } else {
aoqi@0 1093 // no synchronization necessary
aoqi@0 1094 #ifdef ASSERT
aoqi@0 1095 { Label L;
aoqi@0 1096 __ movl(rax, access_flags);
aoqi@0 1097 __ testl(rax, JVM_ACC_SYNCHRONIZED);
aoqi@0 1098 __ jcc(Assembler::zero, L);
aoqi@0 1099 __ stop("method needs synchronization");
aoqi@0 1100 __ bind(L);
aoqi@0 1101 }
aoqi@0 1102 #endif
aoqi@0 1103 }
aoqi@0 1104
aoqi@0 1105 // start execution
aoqi@0 1106
aoqi@0 1107 // jvmti support
aoqi@0 1108 __ notify_method_entry();
aoqi@0 1109
aoqi@0 1110 // work registers
aoqi@0 1111 const Register method = rbx;
aoqi@0 1112 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rdi);
aoqi@0 1113 const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); // rcx|rscratch1
aoqi@0 1114 const Address constMethod (method, Method::const_offset());
aoqi@0 1115 const Address size_of_parameters(t, ConstMethod::size_of_parameters_offset());
aoqi@0 1116
aoqi@0 1117 // allocate space for parameters
aoqi@0 1118 __ movptr(method, STATE(_method));
aoqi@0 1119 __ verify_method_ptr(method);
aoqi@0 1120 __ movptr(t, constMethod);
aoqi@0 1121 __ load_unsigned_short(t, size_of_parameters);
aoqi@0 1122 __ shll(t, 2);
aoqi@0 1123 #ifdef _LP64
aoqi@0 1124 __ subptr(rsp, t);
aoqi@0 1125 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1126 __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 1127 #else
aoqi@0 1128 __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror
aoqi@0 1129 __ subptr(rsp, t);
aoqi@0 1130 __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
aoqi@0 1131 #endif // _LP64
aoqi@0 1132
aoqi@0 1133 // get signature handler
aoqi@0 1134 Label pending_exception_present;
aoqi@0 1135
aoqi@0 1136 { Label L;
aoqi@0 1137 __ movptr(t, Address(method, Method::signature_handler_offset()));
aoqi@0 1138 __ testptr(t, t);
aoqi@0 1139 __ jcc(Assembler::notZero, L);
aoqi@0 1140 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false);
aoqi@0 1141 __ movptr(method, STATE(_method));
aoqi@0 1142 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1143 __ jcc(Assembler::notEqual, pending_exception_present);
aoqi@0 1144 __ verify_method_ptr(method);
aoqi@0 1145 __ movptr(t, Address(method, Method::signature_handler_offset()));
aoqi@0 1146 __ bind(L);
aoqi@0 1147 }
aoqi@0 1148 #ifdef ASSERT
aoqi@0 1149 {
aoqi@0 1150 Label L;
aoqi@0 1151 __ push(t);
aoqi@0 1152 __ get_thread(t); // get vm's javathread*
aoqi@0 1153 __ cmpptr(t, STATE(_thread));
aoqi@0 1154 __ jcc(Assembler::equal, L);
aoqi@0 1155 __ int3();
aoqi@0 1156 __ bind(L);
aoqi@0 1157 __ pop(t);
aoqi@0 1158 }
aoqi@0 1159 #endif //
aoqi@0 1160
aoqi@0 1161 const Register from_ptr = InterpreterRuntime::SignatureHandlerGenerator::from();
aoqi@0 1162 // call signature handler
aoqi@0 1163 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");
aoqi@0 1164
aoqi@0 1165 // The generated handlers do not touch RBX (the method oop).
aoqi@0 1166 // However, large signatures cannot be cached and are generated
aoqi@0 1167 // each time here. The slow-path generator will blow RBX
aoqi@0 1168 // sometime, so we must reload it after the call.
aoqi@0 1169 __ movptr(from_ptr, STATE(_locals)); // get the from pointer
aoqi@0 1170 __ call(t);
aoqi@0 1171 __ movptr(method, STATE(_method));
aoqi@0 1172 __ verify_method_ptr(method);
aoqi@0 1173
aoqi@0 1174 // result handler is in rax
aoqi@0 1175 // set result handler
aoqi@0 1176 __ movptr(STATE(_result_handler), rax);
aoqi@0 1177
aoqi@0 1178
aoqi@0 1179 // get native function entry point
aoqi@0 1180 { Label L;
aoqi@0 1181 __ movptr(rax, Address(method, Method::native_function_offset()));
aoqi@0 1182 __ testptr(rax, rax);
aoqi@0 1183 __ jcc(Assembler::notZero, L);
aoqi@0 1184 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
aoqi@0 1185 __ movptr(method, STATE(_method));
aoqi@0 1186 __ verify_method_ptr(method);
aoqi@0 1187 __ movptr(rax, Address(method, Method::native_function_offset()));
aoqi@0 1188 __ bind(L);
aoqi@0 1189 }
aoqi@0 1190
aoqi@0 1191 // pass mirror handle if static call
aoqi@0 1192 { Label L;
aoqi@0 1193 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 1194 __ movl(t, Address(method, Method::access_flags_offset()));
aoqi@0 1195 __ testl(t, JVM_ACC_STATIC);
aoqi@0 1196 __ jcc(Assembler::zero, L);
aoqi@0 1197 // get mirror
aoqi@0 1198 __ movptr(t, Address(method, Method:: const_offset()));
aoqi@0 1199 __ movptr(t, Address(t, ConstMethod::constants_offset()));
aoqi@0 1200 __ movptr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes()));
aoqi@0 1201 __ movptr(t, Address(t, mirror_offset));
aoqi@0 1202 // copy mirror into activation object
aoqi@0 1203 __ movptr(STATE(_oop_temp), t);
aoqi@0 1204 // pass handle to mirror
aoqi@0 1205 #ifdef _LP64
aoqi@0 1206 __ lea(c_rarg1, STATE(_oop_temp));
aoqi@0 1207 #else
aoqi@0 1208 __ lea(t, STATE(_oop_temp));
aoqi@0 1209 __ movptr(Address(rsp, wordSize), t);
aoqi@0 1210 #endif // _LP64
aoqi@0 1211 __ bind(L);
aoqi@0 1212 }
aoqi@0 1213 #ifdef ASSERT
aoqi@0 1214 {
aoqi@0 1215 Label L;
aoqi@0 1216 __ push(t);
aoqi@0 1217 __ get_thread(t); // get vm's javathread*
aoqi@0 1218 __ cmpptr(t, STATE(_thread));
aoqi@0 1219 __ jcc(Assembler::equal, L);
aoqi@0 1220 __ int3();
aoqi@0 1221 __ bind(L);
aoqi@0 1222 __ pop(t);
aoqi@0 1223 }
aoqi@0 1224 #endif //
aoqi@0 1225
aoqi@0 1226 // pass JNIEnv
aoqi@0 1227 #ifdef _LP64
aoqi@0 1228 __ lea(c_rarg0, Address(thread, JavaThread::jni_environment_offset()));
aoqi@0 1229 #else
aoqi@0 1230 __ movptr(thread, STATE(_thread)); // get thread
aoqi@0 1231 __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
aoqi@0 1232
aoqi@0 1233 __ movptr(Address(rsp, 0), t);
aoqi@0 1234 #endif // _LP64
aoqi@0 1235
aoqi@0 1236 #ifdef ASSERT
aoqi@0 1237 {
aoqi@0 1238 Label L;
aoqi@0 1239 __ push(t);
aoqi@0 1240 __ get_thread(t); // get vm's javathread*
aoqi@0 1241 __ cmpptr(t, STATE(_thread));
aoqi@0 1242 __ jcc(Assembler::equal, L);
aoqi@0 1243 __ int3();
aoqi@0 1244 __ bind(L);
aoqi@0 1245 __ pop(t);
aoqi@0 1246 }
aoqi@0 1247 #endif //
aoqi@0 1248
aoqi@0 1249 #ifdef ASSERT
aoqi@0 1250 { Label L;
aoqi@0 1251 __ movl(t, Address(thread, JavaThread::thread_state_offset()));
aoqi@0 1252 __ cmpl(t, _thread_in_Java);
aoqi@0 1253 __ jcc(Assembler::equal, L);
aoqi@0 1254 __ stop("Wrong thread state in native stub");
aoqi@0 1255 __ bind(L);
aoqi@0 1256 }
aoqi@0 1257 #endif
aoqi@0 1258
aoqi@0 1259 // Change state to native (we save the return address in the thread, since it might not
aoqi@0 1260 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
aoqi@0 1261 // points into the right code segment. It does not have to be the correct return pc.
aoqi@0 1262
aoqi@0 1263 __ set_last_Java_frame(thread, noreg, rbp, __ pc());
aoqi@0 1264
aoqi@0 1265 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
aoqi@0 1266
aoqi@0 1267 __ call(rax);
aoqi@0 1268
aoqi@0 1269 // result potentially in rdx:rax or ST0
aoqi@0 1270 __ movptr(method, STATE(_method));
aoqi@0 1271 NOT_LP64(__ movptr(thread, STATE(_thread));) // get thread
aoqi@0 1272
aoqi@0 1273 // The potential result is in ST(0) & rdx:rax
aoqi@0 1274 // With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then
aoqi@0 1275 // we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about
aoqi@0 1276 // anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would
aoqi@0 1277 // be destroyed.
aoqi@0 1278 // It is safe to do these pushes because state is _thread_in_native and return address will be found
aoqi@0 1279 // via _last_native_pc and not via _last_jave_sp
aoqi@0 1280
aoqi@0 1281 // Must save the value of ST(0)/xmm0 since it could be destroyed before we get to result handler
aoqi@0 1282 { Label Lpush, Lskip;
aoqi@0 1283 ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
aoqi@0 1284 ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
aoqi@0 1285 __ cmpptr(STATE(_result_handler), float_handler.addr());
aoqi@0 1286 __ jcc(Assembler::equal, Lpush);
aoqi@0 1287 __ cmpptr(STATE(_result_handler), double_handler.addr());
aoqi@0 1288 __ jcc(Assembler::notEqual, Lskip);
aoqi@0 1289 __ bind(Lpush);
aoqi@0 1290 __ subptr(rsp, 2*wordSize);
aoqi@0 1291 if ( UseSSE < 2 ) {
aoqi@0 1292 __ fstp_d(Address(rsp, 0));
aoqi@0 1293 } else {
aoqi@0 1294 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 1295 }
aoqi@0 1296 __ bind(Lskip);
aoqi@0 1297 }
aoqi@0 1298
aoqi@0 1299 // save rax:rdx for potential use by result handler.
aoqi@0 1300 __ push(rax);
aoqi@0 1301 #ifndef _LP64
aoqi@0 1302 __ push(rdx);
aoqi@0 1303 #endif // _LP64
aoqi@0 1304
aoqi@0 1305 // Verify or restore cpu control state after JNI call
aoqi@0 1306 __ restore_cpu_control_state_after_jni();
aoqi@0 1307
aoqi@0 1308 // change thread state
aoqi@0 1309 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
aoqi@0 1310 if(os::is_MP()) {
aoqi@0 1311 // Write serialization page so VM thread can do a pseudo remote membar.
aoqi@0 1312 // We use the current thread pointer to calculate a thread specific
aoqi@0 1313 // offset to write to within the page. This minimizes bus traffic
aoqi@0 1314 // due to cache line collision.
aoqi@0 1315 __ serialize_memory(thread, rcx);
aoqi@0 1316 }
aoqi@0 1317
aoqi@0 1318 // check for safepoint operation in progress and/or pending suspend requests
aoqi@0 1319 { Label Continue;
aoqi@0 1320
aoqi@0 1321 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
aoqi@0 1322 SafepointSynchronize::_not_synchronized);
aoqi@0 1323
aoqi@0 1324 // threads running native code and they are expected to self-suspend
aoqi@0 1325 // when leaving the _thread_in_native state. We need to check for
aoqi@0 1326 // pending suspend requests here.
aoqi@0 1327 Label L;
aoqi@0 1328 __ jcc(Assembler::notEqual, L);
aoqi@0 1329 __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
aoqi@0 1330 __ jcc(Assembler::equal, Continue);
aoqi@0 1331 __ bind(L);
aoqi@0 1332
aoqi@0 1333 // Don't use call_VM as it will see a possible pending exception and forward it
aoqi@0 1334 // and never return here preventing us from clearing _last_native_pc down below.
aoqi@0 1335 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
aoqi@0 1336 // preserved and correspond to the bcp/locals pointers.
aoqi@0 1337 //
aoqi@0 1338
aoqi@0 1339 ((MacroAssembler*)_masm)->call_VM_leaf(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
aoqi@0 1340 thread);
aoqi@0 1341 __ increment(rsp, wordSize);
aoqi@0 1342
aoqi@0 1343 __ movptr(method, STATE(_method));
aoqi@0 1344 __ verify_method_ptr(method);
aoqi@0 1345 __ movptr(thread, STATE(_thread)); // get thread
aoqi@0 1346
aoqi@0 1347 __ bind(Continue);
aoqi@0 1348 }
aoqi@0 1349
aoqi@0 1350 // change thread state
aoqi@0 1351 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
aoqi@0 1352
aoqi@0 1353 __ reset_last_Java_frame(thread, true, true);
aoqi@0 1354
aoqi@0 1355 // reset handle block
aoqi@0 1356 __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
aoqi@0 1357 __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
aoqi@0 1358
aoqi@0 1359 // If result was an oop then unbox and save it in the frame
aoqi@0 1360 { Label L;
aoqi@0 1361 Label no_oop, store_result;
aoqi@0 1362 ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT));
aoqi@0 1363 __ cmpptr(STATE(_result_handler), oop_handler.addr());
aoqi@0 1364 __ jcc(Assembler::notEqual, no_oop);
aoqi@0 1365 #ifndef _LP64
aoqi@0 1366 __ pop(rdx);
aoqi@0 1367 #endif // _LP64
aoqi@0 1368 __ pop(rax);
aoqi@0 1369 __ testptr(rax, rax);
aoqi@0 1370 __ jcc(Assembler::zero, store_result);
aoqi@0 1371 // unbox
aoqi@0 1372 __ movptr(rax, Address(rax, 0));
aoqi@0 1373 __ bind(store_result);
aoqi@0 1374 __ movptr(STATE(_oop_temp), rax);
aoqi@0 1375 // keep stack depth as expected by pushing oop which will eventually be discarded
aoqi@0 1376 __ push(rax);
aoqi@0 1377 #ifndef _LP64
aoqi@0 1378 __ push(rdx);
aoqi@0 1379 #endif // _LP64
aoqi@0 1380 __ bind(no_oop);
aoqi@0 1381 }
aoqi@0 1382
aoqi@0 1383 {
aoqi@0 1384 Label no_reguard;
aoqi@0 1385 __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
aoqi@0 1386 __ jcc(Assembler::notEqual, no_reguard);
aoqi@0 1387
aoqi@0 1388 __ pusha();
aoqi@0 1389 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
aoqi@0 1390 __ popa();
aoqi@0 1391
aoqi@0 1392 __ bind(no_reguard);
aoqi@0 1393 }
aoqi@0 1394
aoqi@0 1395
aoqi@0 1396 // QQQ Seems like for native methods we simply return and the caller will see the pending
aoqi@0 1397 // exception and do the right thing. Certainly the interpreter will, don't know about
aoqi@0 1398 // compiled methods.
aoqi@0 1399 // Seems that the answer to above is no this is wrong. The old code would see the exception
aoqi@0 1400 // and forward it before doing the unlocking and notifying jvmdi that method has exited.
aoqi@0 1401 // This seems wrong need to investigate the spec.
aoqi@0 1402
aoqi@0 1403 // handle exceptions (exception handling will handle unlocking!)
aoqi@0 1404 { Label L;
aoqi@0 1405 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1406 __ jcc(Assembler::zero, L);
aoqi@0 1407 __ bind(pending_exception_present);
aoqi@0 1408
aoqi@0 1409 // There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply
aoqi@0 1410 // return and let caller deal with exception. This skips the unlocking here which
aoqi@0 1411 // seems wrong but seems to be what asm interpreter did. Can't find this in the spec.
aoqi@0 1412 // Note: must preverve method in rbx
aoqi@0 1413 //
aoqi@0 1414
aoqi@0 1415 // remove activation
aoqi@0 1416
aoqi@0 1417 __ movptr(t, STATE(_sender_sp));
aoqi@0 1418 __ leave(); // remove frame anchor
aoqi@0 1419 __ pop(rdi); // get return address
aoqi@0 1420 __ movptr(state, STATE(_prev_link)); // get previous state for return
aoqi@0 1421 __ mov(rsp, t); // set sp to sender sp
aoqi@0 1422 __ push(rdi); // push throwing pc
aoqi@0 1423 // The skips unlocking!! This seems to be what asm interpreter does but seems
aoqi@0 1424 // very wrong. Not clear if this violates the spec.
aoqi@0 1425 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 1426 __ bind(L);
aoqi@0 1427 }
aoqi@0 1428
aoqi@0 1429 // do unlocking if necessary
aoqi@0 1430 { Label L;
aoqi@0 1431 __ movl(t, Address(method, Method::access_flags_offset()));
aoqi@0 1432 __ testl(t, JVM_ACC_SYNCHRONIZED);
aoqi@0 1433 __ jcc(Assembler::zero, L);
aoqi@0 1434 // the code below should be shared with interpreter macro assembler implementation
aoqi@0 1435 { Label unlock;
aoqi@0 1436 const Register monitor = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
aoqi@0 1437 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
aoqi@0 1438 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
aoqi@0 1439 __ movptr(monitor, STATE(_monitor_base));
aoqi@0 1440 __ subptr(monitor, frame::interpreter_frame_monitor_size() * wordSize); // address of initial monitor
aoqi@0 1441
aoqi@0 1442 __ movptr(t, Address(monitor, BasicObjectLock::obj_offset_in_bytes()));
aoqi@0 1443 __ testptr(t, t);
aoqi@0 1444 __ jcc(Assembler::notZero, unlock);
aoqi@0 1445
aoqi@0 1446 // Entry already unlocked, need to throw exception
aoqi@0 1447 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 1448 __ should_not_reach_here();
aoqi@0 1449
aoqi@0 1450 __ bind(unlock);
aoqi@0 1451 __ unlock_object(monitor);
aoqi@0 1452 // unlock can blow rbx so restore it for path that needs it below
aoqi@0 1453 __ movptr(method, STATE(_method));
aoqi@0 1454 }
aoqi@0 1455 __ bind(L);
aoqi@0 1456 }
aoqi@0 1457
aoqi@0 1458 // jvmti support
aoqi@0 1459 // Note: This must happen _after_ handling/throwing any exceptions since
aoqi@0 1460 // the exception handler code notifies the runtime of method exits
aoqi@0 1461 // too. If this happens before, method entry/exit notifications are
aoqi@0 1462 // not properly paired (was bug - gri 11/22/99).
aoqi@0 1463 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
aoqi@0 1464
aoqi@0 1465 // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
aoqi@0 1466 #ifndef _LP64
aoqi@0 1467 __ pop(rdx);
aoqi@0 1468 #endif // _LP64
aoqi@0 1469 __ pop(rax);
aoqi@0 1470 __ movptr(t, STATE(_result_handler)); // get result handler
aoqi@0 1471 __ call(t); // call result handler to convert to tosca form
aoqi@0 1472
aoqi@0 1473 // remove activation
aoqi@0 1474
aoqi@0 1475 __ movptr(t, STATE(_sender_sp));
aoqi@0 1476
aoqi@0 1477 __ leave(); // remove frame anchor
aoqi@0 1478 __ pop(rdi); // get return address
aoqi@0 1479 __ movptr(state, STATE(_prev_link)); // get previous state for return (if c++ interpreter was caller)
aoqi@0 1480 __ mov(rsp, t); // set sp to sender sp
aoqi@0 1481 __ jmp(rdi);
aoqi@0 1482
aoqi@0 1483 // invocation counter overflow
aoqi@0 1484 if (inc_counter) {
aoqi@0 1485 // Handle overflow of counter and compile method
aoqi@0 1486 __ bind(invocation_counter_overflow);
aoqi@0 1487 generate_counter_overflow(&continue_after_compile);
aoqi@0 1488 }
aoqi@0 1489
aoqi@0 1490 return entry_point;
aoqi@0 1491 }
aoqi@0 1492
aoqi@0 1493 // Generate entries that will put a result type index into rcx
aoqi@0 1494 void CppInterpreterGenerator::generate_deopt_handling() {
aoqi@0 1495
aoqi@0 1496 Label return_from_deopt_common;
aoqi@0 1497
aoqi@0 1498 // Generate entries that will put a result type index into rcx
aoqi@0 1499 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1500 deopt_frame_manager_return_atos = __ pc();
aoqi@0 1501
aoqi@0 1502 // rax is live here
aoqi@0 1503 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT)); // Result stub address array index
aoqi@0 1504 __ jmp(return_from_deopt_common);
aoqi@0 1505
aoqi@0 1506
aoqi@0 1507 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1508 deopt_frame_manager_return_btos = __ pc();
aoqi@0 1509
aoqi@0 1510 // rax is live here
aoqi@0 1511 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN)); // Result stub address array index
aoqi@0 1512 __ jmp(return_from_deopt_common);
aoqi@0 1513
aoqi@0 1514 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1515 deopt_frame_manager_return_itos = __ pc();
aoqi@0 1516
aoqi@0 1517 // rax is live here
aoqi@0 1518 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT)); // Result stub address array index
aoqi@0 1519 __ jmp(return_from_deopt_common);
aoqi@0 1520
aoqi@0 1521 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1522
aoqi@0 1523 deopt_frame_manager_return_ltos = __ pc();
aoqi@0 1524 // rax,rdx are live here
aoqi@0 1525 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG)); // Result stub address array index
aoqi@0 1526 __ jmp(return_from_deopt_common);
aoqi@0 1527
aoqi@0 1528 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1529
aoqi@0 1530 deopt_frame_manager_return_ftos = __ pc();
aoqi@0 1531 // st(0) is live here
aoqi@0 1532 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
aoqi@0 1533 __ jmp(return_from_deopt_common);
aoqi@0 1534
aoqi@0 1535 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1536 deopt_frame_manager_return_dtos = __ pc();
aoqi@0 1537
aoqi@0 1538 // st(0) is live here
aoqi@0 1539 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
aoqi@0 1540 __ jmp(return_from_deopt_common);
aoqi@0 1541
aoqi@0 1542 // deopt needs to jump to here to enter the interpreter (return a result)
aoqi@0 1543 deopt_frame_manager_return_vtos = __ pc();
aoqi@0 1544
aoqi@0 1545 __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID));
aoqi@0 1546
aoqi@0 1547 // Deopt return common
aoqi@0 1548 // an index is present in rcx that lets us move any possible result being
aoqi@0 1549 // return to the interpreter's stack
aoqi@0 1550 //
aoqi@0 1551 // Because we have a full sized interpreter frame on the youngest
aoqi@0 1552 // activation the stack is pushed too deep to share the tosca to
aoqi@0 1553 // stack converters directly. We shrink the stack to the desired
aoqi@0 1554 // amount and then push result and then re-extend the stack.
aoqi@0 1555 // We could have the code in size_activation layout a short
aoqi@0 1556 // frame for the top activation but that would look different
aoqi@0 1557 // than say sparc (which needs a full size activation because
aoqi@0 1558 // the windows are in the way. Really it could be short? QQQ
aoqi@0 1559 //
aoqi@0 1560 __ bind(return_from_deopt_common);
aoqi@0 1561
aoqi@0 1562 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1563
aoqi@0 1564 // setup rsp so we can push the "result" as needed.
aoqi@0 1565 __ movptr(rsp, STATE(_stack)); // trim stack (is prepushed)
aoqi@0 1566 __ addptr(rsp, wordSize); // undo prepush
aoqi@0 1567
aoqi@0 1568 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
aoqi@0 1569 // Address index(noreg, rcx, Address::times_ptr);
aoqi@0 1570 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
aoqi@0 1571 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
aoqi@0 1572 __ call(rcx); // call result converter
aoqi@0 1573
aoqi@0 1574 __ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume);
aoqi@0 1575 __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
aoqi@0 1576 __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
aoqi@0 1577 // result if any on stack already )
aoqi@0 1578 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 1579 }
aoqi@0 1580
aoqi@0 1581 // Generate the code to handle a more_monitors message from the c++ interpreter
aoqi@0 1582 void CppInterpreterGenerator::generate_more_monitors() {
aoqi@0 1583
aoqi@0 1584
aoqi@0 1585 Label entry, loop;
aoqi@0 1586 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 1587 // 1. compute new pointers // rsp: old expression stack top
aoqi@0 1588 __ movptr(rdx, STATE(_stack_base)); // rdx: old expression stack bottom
aoqi@0 1589 __ subptr(rsp, entry_size); // move expression stack top limit
aoqi@0 1590 __ subptr(STATE(_stack), entry_size); // update interpreter stack top
aoqi@0 1591 __ subptr(STATE(_stack_limit), entry_size); // inform interpreter
aoqi@0 1592 __ subptr(rdx, entry_size); // move expression stack bottom
aoqi@0 1593 __ movptr(STATE(_stack_base), rdx); // inform interpreter
aoqi@0 1594 __ movptr(rcx, STATE(_stack)); // set start value for copy loop
aoqi@0 1595 __ jmp(entry);
aoqi@0 1596 // 2. move expression stack contents
aoqi@0 1597 __ bind(loop);
aoqi@0 1598 __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location
aoqi@0 1599 __ movptr(Address(rcx, 0), rbx); // and store it at new location
aoqi@0 1600 __ addptr(rcx, wordSize); // advance to next word
aoqi@0 1601 __ bind(entry);
aoqi@0 1602 __ cmpptr(rcx, rdx); // check if bottom reached
aoqi@0 1603 __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word
aoqi@0 1604 // now zero the slot so we can find it.
aoqi@0 1605 __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL_WORD);
aoqi@0 1606 __ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors);
aoqi@0 1607 }
aoqi@0 1608
aoqi@0 1609
aoqi@0 1610 // Initial entry to C++ interpreter from the call_stub.
aoqi@0 1611 // This entry point is called the frame manager since it handles the generation
aoqi@0 1612 // of interpreter activation frames via requests directly from the vm (via call_stub)
aoqi@0 1613 // and via requests from the interpreter. The requests from the call_stub happen
aoqi@0 1614 // directly thru the entry point. Requests from the interpreter happen via returning
aoqi@0 1615 // from the interpreter and examining the message the interpreter has returned to
aoqi@0 1616 // the frame manager. The frame manager can take the following requests:
aoqi@0 1617
aoqi@0 1618 // NO_REQUEST - error, should never happen.
aoqi@0 1619 // MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
aoqi@0 1620 // allocate a new monitor.
aoqi@0 1621 // CALL_METHOD - setup a new activation to call a new method. Very similar to what
aoqi@0 1622 // happens during entry during the entry via the call stub.
aoqi@0 1623 // RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
aoqi@0 1624 //
aoqi@0 1625 // Arguments:
aoqi@0 1626 //
aoqi@0 1627 // rbx: Method*
aoqi@0 1628 // rcx: receiver - unused (retrieved from stack as needed)
aoqi@0 1629 // rsi/r13: previous frame manager state (NULL from the call_stub/c1/c2)
aoqi@0 1630 //
aoqi@0 1631 //
aoqi@0 1632 // Stack layout at entry
aoqi@0 1633 //
aoqi@0 1634 // [ return address ] <--- rsp
aoqi@0 1635 // [ parameter n ]
aoqi@0 1636 // ...
aoqi@0 1637 // [ parameter 1 ]
aoqi@0 1638 // [ expression stack ]
aoqi@0 1639 //
aoqi@0 1640 //
aoqi@0 1641 // We are free to blow any registers we like because the call_stub which brought us here
aoqi@0 1642 // initially has preserved the callee save registers already.
aoqi@0 1643 //
aoqi@0 1644 //
aoqi@0 1645
aoqi@0 1646 static address interpreter_frame_manager = NULL;
aoqi@0 1647
aoqi@0 1648 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
aoqi@0 1649
aoqi@0 1650 // rbx: Method*
aoqi@0 1651 // rsi/r13: sender sp
aoqi@0 1652
aoqi@0 1653 // Because we redispatch "recursive" interpreter entries thru this same entry point
aoqi@0 1654 // the "input" register usage is a little strange and not what you expect coming
aoqi@0 1655 // from the call_stub. From the call stub rsi/rdi (current/previous) interpreter
aoqi@0 1656 // state are NULL but on "recursive" dispatches they are what you'd expect.
aoqi@0 1657 // rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2)
aoqi@0 1658
aoqi@0 1659
aoqi@0 1660 // A single frame manager is plenty as we don't specialize for synchronized. We could and
aoqi@0 1661 // the code is pretty much ready. Would need to change the test below and for good measure
aoqi@0 1662 // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
aoqi@0 1663 // routines. Not clear this is worth it yet.
aoqi@0 1664
aoqi@0 1665 if (interpreter_frame_manager) return interpreter_frame_manager;
aoqi@0 1666
aoqi@0 1667 address entry_point = __ pc();
aoqi@0 1668
aoqi@0 1669 // Fast accessor methods share this entry point.
aoqi@0 1670 // This works because frame manager is in the same codelet
aoqi@0 1671 if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path);
aoqi@0 1672
aoqi@0 1673 Label dispatch_entry_2;
aoqi@0 1674 __ movptr(rcx, sender_sp_on_entry);
aoqi@0 1675 __ movptr(state, (int32_t)NULL_WORD); // no current activation
aoqi@0 1676
aoqi@0 1677 __ jmp(dispatch_entry_2);
aoqi@0 1678
aoqi@0 1679 const Register locals = rdi;
aoqi@0 1680
aoqi@0 1681 Label re_dispatch;
aoqi@0 1682
aoqi@0 1683 __ bind(re_dispatch);
aoqi@0 1684
aoqi@0 1685 // save sender sp (doesn't include return address
aoqi@0 1686 __ lea(rcx, Address(rsp, wordSize));
aoqi@0 1687
aoqi@0 1688 __ bind(dispatch_entry_2);
aoqi@0 1689
aoqi@0 1690 // save sender sp
aoqi@0 1691 __ push(rcx);
aoqi@0 1692
aoqi@0 1693 const Address constMethod (rbx, Method::const_offset());
aoqi@0 1694 const Address access_flags (rbx, Method::access_flags_offset());
aoqi@0 1695 const Address size_of_parameters(rdx, ConstMethod::size_of_parameters_offset());
aoqi@0 1696 const Address size_of_locals (rdx, ConstMethod::size_of_locals_offset());
aoqi@0 1697
aoqi@0 1698 // const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
aoqi@0 1699 // const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
aoqi@0 1700 // const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
aoqi@0 1701
aoqi@0 1702 // get parameter size (always needed)
aoqi@0 1703 __ movptr(rdx, constMethod);
aoqi@0 1704 __ load_unsigned_short(rcx, size_of_parameters);
aoqi@0 1705
aoqi@0 1706 // rbx: Method*
aoqi@0 1707 // rcx: size of parameters
aoqi@0 1708 __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
aoqi@0 1709
aoqi@0 1710 __ subptr(rdx, rcx); // rdx = no. of additional locals
aoqi@0 1711
aoqi@0 1712 // see if we've got enough room on the stack for locals plus overhead.
aoqi@0 1713 generate_stack_overflow_check(); // C++
aoqi@0 1714
aoqi@0 1715 // c++ interpreter does not use stack banging or any implicit exceptions
aoqi@0 1716 // leave for now to verify that check is proper.
aoqi@0 1717 bang_stack_shadow_pages(false);
aoqi@0 1718
aoqi@0 1719
aoqi@0 1720
aoqi@0 1721 // compute beginning of parameters (rdi)
aoqi@0 1722 __ lea(locals, Address(rsp, rcx, Address::times_ptr, wordSize));
aoqi@0 1723
aoqi@0 1724 // save sender's sp
aoqi@0 1725 // __ movl(rcx, rsp);
aoqi@0 1726
aoqi@0 1727 // get sender's sp
aoqi@0 1728 __ pop(rcx);
aoqi@0 1729
aoqi@0 1730 // get return address
aoqi@0 1731 __ pop(rax);
aoqi@0 1732
aoqi@0 1733 // rdx - # of additional locals
aoqi@0 1734 // allocate space for locals
aoqi@0 1735 // explicitly initialize locals
aoqi@0 1736 {
aoqi@0 1737 Label exit, loop;
aoqi@0 1738 __ testl(rdx, rdx); // (32bit ok)
aoqi@0 1739 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
aoqi@0 1740 __ bind(loop);
aoqi@0 1741 __ push((int32_t)NULL_WORD); // initialize local variables
aoqi@0 1742 __ decrement(rdx); // until everything initialized
aoqi@0 1743 __ jcc(Assembler::greater, loop);
aoqi@0 1744 __ bind(exit);
aoqi@0 1745 }
aoqi@0 1746
aoqi@0 1747
aoqi@0 1748 // Assumes rax = return address
aoqi@0 1749
aoqi@0 1750 // allocate and initialize new interpreterState and method expression stack
aoqi@0 1751 // IN(locals) -> locals
aoqi@0 1752 // IN(state) -> any current interpreter activation
aoqi@0 1753 // destroys rax, rcx, rdx, rdi
aoqi@0 1754 // OUT (state) -> new interpreterState
aoqi@0 1755 // OUT(rsp) -> bottom of methods expression stack
aoqi@0 1756
aoqi@0 1757 generate_compute_interpreter_state(state, locals, rcx, false);
aoqi@0 1758
aoqi@0 1759 // Call interpreter
aoqi@0 1760
aoqi@0 1761 Label call_interpreter;
aoqi@0 1762 __ bind(call_interpreter);
aoqi@0 1763
aoqi@0 1764 // c++ interpreter does not use stack banging or any implicit exceptions
aoqi@0 1765 // leave for now to verify that check is proper.
aoqi@0 1766 bang_stack_shadow_pages(false);
aoqi@0 1767
aoqi@0 1768
aoqi@0 1769 // Call interpreter enter here if message is
aoqi@0 1770 // set and we know stack size is valid
aoqi@0 1771
aoqi@0 1772 Label call_interpreter_2;
aoqi@0 1773
aoqi@0 1774 __ bind(call_interpreter_2);
aoqi@0 1775
aoqi@0 1776 {
aoqi@0 1777 const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
aoqi@0 1778
aoqi@0 1779 #ifdef _LP64
aoqi@0 1780 __ mov(c_rarg0, state);
aoqi@0 1781 #else
aoqi@0 1782 __ push(state); // push arg to interpreter
aoqi@0 1783 __ movptr(thread, STATE(_thread));
aoqi@0 1784 #endif // _LP64
aoqi@0 1785
aoqi@0 1786 // We can setup the frame anchor with everything we want at this point
aoqi@0 1787 // as we are thread_in_Java and no safepoints can occur until we go to
aoqi@0 1788 // vm mode. We do have to clear flags on return from vm but that is it
aoqi@0 1789 //
aoqi@0 1790 __ movptr(Address(thread, JavaThread::last_Java_fp_offset()), rbp);
aoqi@0 1791 __ movptr(Address(thread, JavaThread::last_Java_sp_offset()), rsp);
aoqi@0 1792
aoqi@0 1793 // Call the interpreter
aoqi@0 1794
aoqi@0 1795 RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run));
aoqi@0 1796 RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks));
aoqi@0 1797
aoqi@0 1798 __ call(JvmtiExport::can_post_interpreter_events() ? checking : normal);
aoqi@0 1799 NOT_LP64(__ pop(rax);) // discard parameter to run
aoqi@0 1800 //
aoqi@0 1801 // state is preserved since it is callee saved
aoqi@0 1802 //
aoqi@0 1803
aoqi@0 1804 // reset_last_Java_frame
aoqi@0 1805
aoqi@0 1806 NOT_LP64(__ movl(thread, STATE(_thread));)
aoqi@0 1807 __ reset_last_Java_frame(thread, true, true);
aoqi@0 1808 }
aoqi@0 1809
aoqi@0 1810 // examine msg from interpreter to determine next action
aoqi@0 1811
aoqi@0 1812 __ movl(rdx, STATE(_msg)); // Get new message
aoqi@0 1813
aoqi@0 1814 Label call_method;
aoqi@0 1815 Label return_from_interpreted_method;
aoqi@0 1816 Label throw_exception;
aoqi@0 1817 Label bad_msg;
aoqi@0 1818 Label do_OSR;
aoqi@0 1819
aoqi@0 1820 __ cmpl(rdx, (int32_t)BytecodeInterpreter::call_method);
aoqi@0 1821 __ jcc(Assembler::equal, call_method);
aoqi@0 1822 __ cmpl(rdx, (int32_t)BytecodeInterpreter::return_from_method);
aoqi@0 1823 __ jcc(Assembler::equal, return_from_interpreted_method);
aoqi@0 1824 __ cmpl(rdx, (int32_t)BytecodeInterpreter::do_osr);
aoqi@0 1825 __ jcc(Assembler::equal, do_OSR);
aoqi@0 1826 __ cmpl(rdx, (int32_t)BytecodeInterpreter::throwing_exception);
aoqi@0 1827 __ jcc(Assembler::equal, throw_exception);
aoqi@0 1828 __ cmpl(rdx, (int32_t)BytecodeInterpreter::more_monitors);
aoqi@0 1829 __ jcc(Assembler::notEqual, bad_msg);
aoqi@0 1830
aoqi@0 1831 // Allocate more monitor space, shuffle expression stack....
aoqi@0 1832
aoqi@0 1833 generate_more_monitors();
aoqi@0 1834
aoqi@0 1835 __ jmp(call_interpreter);
aoqi@0 1836
aoqi@0 1837 // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
aoqi@0 1838 unctrap_frame_manager_entry = __ pc();
aoqi@0 1839 //
aoqi@0 1840 // Load the registers we need.
aoqi@0 1841 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1842 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 1843 __ jmp(call_interpreter_2);
aoqi@0 1844
aoqi@0 1845
aoqi@0 1846
aoqi@0 1847 //=============================================================================
aoqi@0 1848 // Returning from a compiled method into a deopted method. The bytecode at the
aoqi@0 1849 // bcp has completed. The result of the bytecode is in the native abi (the tosca
aoqi@0 1850 // for the template based interpreter). Any stack space that was used by the
aoqi@0 1851 // bytecode that has completed has been removed (e.g. parameters for an invoke)
aoqi@0 1852 // so all that we have to do is place any pending result on the expression stack
aoqi@0 1853 // and resume execution on the next bytecode.
aoqi@0 1854
aoqi@0 1855
aoqi@0 1856 generate_deopt_handling();
aoqi@0 1857 __ jmp(call_interpreter);
aoqi@0 1858
aoqi@0 1859
aoqi@0 1860 // Current frame has caught an exception we need to dispatch to the
aoqi@0 1861 // handler. We can get here because a native interpreter frame caught
aoqi@0 1862 // an exception in which case there is no handler and we must rethrow
aoqi@0 1863 // If it is a vanilla interpreted frame the we simply drop into the
aoqi@0 1864 // interpreter and let it do the lookup.
aoqi@0 1865
aoqi@0 1866 Interpreter::_rethrow_exception_entry = __ pc();
aoqi@0 1867 // rax: exception
aoqi@0 1868 // rdx: return address/pc that threw exception
aoqi@0 1869
aoqi@0 1870 Label return_with_exception;
aoqi@0 1871 Label unwind_and_forward;
aoqi@0 1872
aoqi@0 1873 // restore state pointer.
aoqi@0 1874 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1875
aoqi@0 1876 __ movptr(rbx, STATE(_method)); // get method
aoqi@0 1877 #ifdef _LP64
aoqi@0 1878 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
aoqi@0 1879 #else
aoqi@0 1880 __ movl(rcx, STATE(_thread)); // get thread
aoqi@0 1881
aoqi@0 1882 // Store exception with interpreter will expect it
aoqi@0 1883 __ movptr(Address(rcx, Thread::pending_exception_offset()), rax);
aoqi@0 1884 #endif // _LP64
aoqi@0 1885
aoqi@0 1886 // is current frame vanilla or native?
aoqi@0 1887
aoqi@0 1888 __ movl(rdx, access_flags);
aoqi@0 1889 __ testl(rdx, JVM_ACC_NATIVE);
aoqi@0 1890 __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly
aoqi@0 1891
aoqi@0 1892 // We drop thru to unwind a native interpreted frame with a pending exception
aoqi@0 1893 // We jump here for the initial interpreter frame with exception pending
aoqi@0 1894 // We unwind the current acivation and forward it to our caller.
aoqi@0 1895
aoqi@0 1896 __ bind(unwind_and_forward);
aoqi@0 1897
aoqi@0 1898 // unwind rbp, return stack to unextended value and re-push return address
aoqi@0 1899
aoqi@0 1900 __ movptr(rcx, STATE(_sender_sp));
aoqi@0 1901 __ leave();
aoqi@0 1902 __ pop(rdx);
aoqi@0 1903 __ mov(rsp, rcx);
aoqi@0 1904 __ push(rdx);
aoqi@0 1905 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 1906
aoqi@0 1907 // Return point from a call which returns a result in the native abi
aoqi@0 1908 // (c1/c2/jni-native). This result must be processed onto the java
aoqi@0 1909 // expression stack.
aoqi@0 1910 //
aoqi@0 1911 // A pending exception may be present in which case there is no result present
aoqi@0 1912
aoqi@0 1913 Label resume_interpreter;
aoqi@0 1914 Label do_float;
aoqi@0 1915 Label do_double;
aoqi@0 1916 Label done_conv;
aoqi@0 1917
aoqi@0 1918 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
aoqi@0 1919 if (UseSSE < 2) {
aoqi@0 1920 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1921 __ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed
aoqi@0 1922 __ movl(rcx, Address(rbx, Method::result_index_offset()));
aoqi@0 1923 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
aoqi@0 1924 __ jcc(Assembler::equal, do_float);
aoqi@0 1925 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
aoqi@0 1926 __ jcc(Assembler::equal, do_double);
aoqi@0 1927 #if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)
aoqi@0 1928 __ empty_FPU_stack();
aoqi@0 1929 #endif // COMPILER2
aoqi@0 1930 __ jmp(done_conv);
aoqi@0 1931
aoqi@0 1932 __ bind(do_float);
aoqi@0 1933 #ifdef COMPILER2
aoqi@0 1934 for (int i = 1; i < 8; i++) {
aoqi@0 1935 __ ffree(i);
aoqi@0 1936 }
aoqi@0 1937 #endif // COMPILER2
aoqi@0 1938 __ jmp(done_conv);
aoqi@0 1939 __ bind(do_double);
aoqi@0 1940 #ifdef COMPILER2
aoqi@0 1941 for (int i = 1; i < 8; i++) {
aoqi@0 1942 __ ffree(i);
aoqi@0 1943 }
aoqi@0 1944 #endif // COMPILER2
aoqi@0 1945 __ jmp(done_conv);
aoqi@0 1946 } else {
aoqi@0 1947 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
aoqi@0 1948 __ jmp(done_conv);
aoqi@0 1949 }
aoqi@0 1950
aoqi@0 1951 // Return point to interpreter from compiled/native method
aoqi@0 1952 InternalAddress return_from_native_method(__ pc());
aoqi@0 1953
aoqi@0 1954 __ bind(done_conv);
aoqi@0 1955
aoqi@0 1956
aoqi@0 1957 // Result if any is in tosca. The java expression stack is in the state that the
aoqi@0 1958 // calling convention left it (i.e. params may or may not be present)
aoqi@0 1959 // Copy the result from tosca and place it on java expression stack.
aoqi@0 1960
aoqi@0 1961 // Restore rsi/r13 as compiled code may not preserve it
aoqi@0 1962
aoqi@0 1963 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
aoqi@0 1964
aoqi@0 1965 // restore stack to what we had when we left (in case i2c extended it)
aoqi@0 1966
aoqi@0 1967 __ movptr(rsp, STATE(_stack));
aoqi@0 1968 __ lea(rsp, Address(rsp, wordSize));
aoqi@0 1969
aoqi@0 1970 // If there is a pending exception then we don't really have a result to process
aoqi@0 1971
aoqi@0 1972 #ifdef _LP64
aoqi@0 1973 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1974 #else
aoqi@0 1975 __ movptr(rcx, STATE(_thread)); // get thread
aoqi@0 1976 __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 1977 #endif // _LP64
aoqi@0 1978 __ jcc(Assembler::notZero, return_with_exception);
aoqi@0 1979
aoqi@0 1980 // get method just executed
aoqi@0 1981 __ movptr(rbx, STATE(_result._to_call._callee));
aoqi@0 1982
aoqi@0 1983 // callee left args on top of expression stack, remove them
aoqi@0 1984 __ movptr(rcx, constMethod);
aoqi@0 1985 __ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));
aoqi@0 1986
aoqi@0 1987 __ lea(rsp, Address(rsp, rcx, Address::times_ptr));
aoqi@0 1988
aoqi@0 1989 __ movl(rcx, Address(rbx, Method::result_index_offset()));
aoqi@0 1990 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
aoqi@0 1991 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 1992 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
aoqi@0 1993 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
aoqi@0 1994 __ call(rcx); // call result converter
aoqi@0 1995 __ jmp(resume_interpreter);
aoqi@0 1996
aoqi@0 1997 // An exception is being caught on return to a vanilla interpreter frame.
aoqi@0 1998 // Empty the stack and resume interpreter
aoqi@0 1999
aoqi@0 2000 __ bind(return_with_exception);
aoqi@0 2001
aoqi@0 2002 // Exception present, empty stack
aoqi@0 2003 __ movptr(rsp, STATE(_stack_base));
aoqi@0 2004 __ jmp(resume_interpreter);
aoqi@0 2005
aoqi@0 2006 // Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
aoqi@0 2007 // interpreter call, or native) and unwind this interpreter activation.
aoqi@0 2008 // All monitors should be unlocked.
aoqi@0 2009
aoqi@0 2010 __ bind(return_from_interpreted_method);
aoqi@0 2011
aoqi@0 2012 Label return_to_initial_caller;
aoqi@0 2013
aoqi@0 2014 __ movptr(rbx, STATE(_method)); // get method just executed
aoqi@0 2015 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
aoqi@0 2016 __ movl(rax, Address(rbx, Method::result_index_offset())); // get result type index
aoqi@0 2017 __ jcc(Assembler::equal, return_to_initial_caller); // back to native code (call_stub/c1/c2)
aoqi@0 2018
aoqi@0 2019 // Copy result to callers java stack
aoqi@0 2020 ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack);
aoqi@0 2021 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 2022
aoqi@0 2023 __ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_ptr)));
aoqi@0 2024 // __ movl(rax, Address(noreg, rax, Address::times_ptr, int(AbstractInterpreter::_stack_to_stack)));
aoqi@0 2025 __ call(rax); // call result converter
aoqi@0 2026
aoqi@0 2027 Label unwind_recursive_activation;
aoqi@0 2028 __ bind(unwind_recursive_activation);
aoqi@0 2029
aoqi@0 2030 // returning to interpreter method from "recursive" interpreter call
aoqi@0 2031 // result converter left rax pointing to top of the java stack for method we are returning
aoqi@0 2032 // to. Now all we must do is unwind the state from the completed call
aoqi@0 2033
aoqi@0 2034 __ movptr(state, STATE(_prev_link)); // unwind state
aoqi@0 2035 __ leave(); // pop the frame
aoqi@0 2036 __ mov(rsp, rax); // unwind stack to remove args
aoqi@0 2037
aoqi@0 2038 // Resume the interpreter. The current frame contains the current interpreter
aoqi@0 2039 // state object.
aoqi@0 2040 //
aoqi@0 2041
aoqi@0 2042 __ bind(resume_interpreter);
aoqi@0 2043
aoqi@0 2044 // state == interpreterState object for method we are resuming
aoqi@0 2045
aoqi@0 2046 __ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume);
aoqi@0 2047 __ lea(rsp, Address(rsp, -wordSize)); // prepush stack (result if any already present)
aoqi@0 2048 __ movptr(STATE(_stack), rsp); // inform interpreter of new stack depth (parameters removed,
aoqi@0 2049 // result if any on stack already )
aoqi@0 2050 __ movptr(rsp, STATE(_stack_limit)); // restore expression stack to full depth
aoqi@0 2051 __ jmp(call_interpreter_2); // No need to bang
aoqi@0 2052
aoqi@0 2053 // interpreter returning to native code (call_stub/c1/c2)
aoqi@0 2054 // convert result and unwind initial activation
aoqi@0 2055 // rax - result index
aoqi@0 2056
aoqi@0 2057 __ bind(return_to_initial_caller);
aoqi@0 2058 ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi);
aoqi@0 2059 // Address index(noreg, rax, Address::times_ptr);
aoqi@0 2060
aoqi@0 2061 __ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_ptr)));
aoqi@0 2062 __ call(rax); // call result converter
aoqi@0 2063
aoqi@0 2064 Label unwind_initial_activation;
aoqi@0 2065 __ bind(unwind_initial_activation);
aoqi@0 2066
aoqi@0 2067 // RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0))
aoqi@0 2068
aoqi@0 2069 /* Current stack picture
aoqi@0 2070
aoqi@0 2071 [ incoming parameters ]
aoqi@0 2072 [ extra locals ]
aoqi@0 2073 [ return address to CALL_STUB/C1/C2]
aoqi@0 2074 fp -> [ CALL_STUB/C1/C2 fp ]
aoqi@0 2075 BytecodeInterpreter object
aoqi@0 2076 expression stack
aoqi@0 2077 sp ->
aoqi@0 2078
aoqi@0 2079 */
aoqi@0 2080
aoqi@0 2081 // return restoring the stack to the original sender_sp value
aoqi@0 2082
aoqi@0 2083 __ movptr(rcx, STATE(_sender_sp));
aoqi@0 2084 __ leave();
aoqi@0 2085 __ pop(rdi); // get return address
aoqi@0 2086 // set stack to sender's sp
aoqi@0 2087 __ mov(rsp, rcx);
aoqi@0 2088 __ jmp(rdi); // return to call_stub
aoqi@0 2089
aoqi@0 2090 // OSR request, adjust return address to make current frame into adapter frame
aoqi@0 2091 // and enter OSR nmethod
aoqi@0 2092
aoqi@0 2093 __ bind(do_OSR);
aoqi@0 2094
aoqi@0 2095 Label remove_initial_frame;
aoqi@0 2096
aoqi@0 2097 // We are going to pop this frame. Is there another interpreter frame underneath
aoqi@0 2098 // it or is it callstub/compiled?
aoqi@0 2099
aoqi@0 2100 // Move buffer to the expected parameter location
aoqi@0 2101 __ movptr(rcx, STATE(_result._osr._osr_buf));
aoqi@0 2102
aoqi@0 2103 __ movptr(rax, STATE(_result._osr._osr_entry));
aoqi@0 2104
aoqi@0 2105 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from "recursive" interpreter call?
aoqi@0 2106 __ jcc(Assembler::equal, remove_initial_frame); // back to native code (call_stub/c1/c2)
aoqi@0 2107
aoqi@0 2108 __ movptr(sender_sp_on_entry, STATE(_sender_sp)); // get sender's sp in expected register
aoqi@0 2109 __ leave(); // pop the frame
aoqi@0 2110 __ mov(rsp, sender_sp_on_entry); // trim any stack expansion
aoqi@0 2111
aoqi@0 2112
aoqi@0 2113 // We know we are calling compiled so push specialized return
aoqi@0 2114 // method uses specialized entry, push a return so we look like call stub setup
aoqi@0 2115 // this path will handle fact that result is returned in registers and not
aoqi@0 2116 // on the java stack.
aoqi@0 2117
aoqi@0 2118 __ pushptr(return_from_native_method.addr());
aoqi@0 2119
aoqi@0 2120 __ jmp(rax);
aoqi@0 2121
aoqi@0 2122 __ bind(remove_initial_frame);
aoqi@0 2123
aoqi@0 2124 __ movptr(rdx, STATE(_sender_sp));
aoqi@0 2125 __ leave();
aoqi@0 2126 // get real return
aoqi@0 2127 __ pop(rsi);
aoqi@0 2128 // set stack to sender's sp
aoqi@0 2129 __ mov(rsp, rdx);
aoqi@0 2130 // repush real return
aoqi@0 2131 __ push(rsi);
aoqi@0 2132 // Enter OSR nmethod
aoqi@0 2133 __ jmp(rax);
aoqi@0 2134
aoqi@0 2135
aoqi@0 2136
aoqi@0 2137
aoqi@0 2138 // Call a new method. All we do is (temporarily) trim the expression stack
aoqi@0 2139 // push a return address to bring us back to here and leap to the new entry.
aoqi@0 2140
aoqi@0 2141 __ bind(call_method);
aoqi@0 2142
aoqi@0 2143 // stack points to next free location and not top element on expression stack
aoqi@0 2144 // method expects sp to be pointing to topmost element
aoqi@0 2145
aoqi@0 2146 __ movptr(rsp, STATE(_stack)); // pop args to c++ interpreter, set sp to java stack top
aoqi@0 2147 __ lea(rsp, Address(rsp, wordSize));
aoqi@0 2148
aoqi@0 2149 __ movptr(rbx, STATE(_result._to_call._callee)); // get method to execute
aoqi@0 2150
aoqi@0 2151 // don't need a return address if reinvoking interpreter
aoqi@0 2152
aoqi@0 2153 // Make it look like call_stub calling conventions
aoqi@0 2154
aoqi@0 2155 // Get (potential) receiver
aoqi@0 2156 // get size of parameters in words
aoqi@0 2157 __ movptr(rcx, constMethod);
aoqi@0 2158 __ load_unsigned_short(rcx, Address(rcx, ConstMethod::size_of_parameters_offset()));
aoqi@0 2159
aoqi@0 2160 ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
aoqi@0 2161 __ pushptr(recursive.addr()); // make it look good in the debugger
aoqi@0 2162
aoqi@0 2163 InternalAddress entry(entry_point);
aoqi@0 2164 __ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter?
aoqi@0 2165 __ jcc(Assembler::equal, re_dispatch); // yes
aoqi@0 2166
aoqi@0 2167 __ pop(rax); // pop dummy address
aoqi@0 2168
aoqi@0 2169
aoqi@0 2170 // get specialized entry
aoqi@0 2171 __ movptr(rax, STATE(_result._to_call._callee_entry_point));
aoqi@0 2172 // set sender SP
aoqi@0 2173 __ mov(sender_sp_on_entry, rsp);
aoqi@0 2174
aoqi@0 2175 // method uses specialized entry, push a return so we look like call stub setup
aoqi@0 2176 // this path will handle fact that result is returned in registers and not
aoqi@0 2177 // on the java stack.
aoqi@0 2178
aoqi@0 2179 __ pushptr(return_from_native_method.addr());
aoqi@0 2180
aoqi@0 2181 __ jmp(rax);
aoqi@0 2182
aoqi@0 2183 __ bind(bad_msg);
aoqi@0 2184 __ stop("Bad message from interpreter");
aoqi@0 2185
aoqi@0 2186 // Interpreted method "returned" with an exception pass it on...
aoqi@0 2187 // Pass result, unwind activation and continue/return to interpreter/call_stub
aoqi@0 2188 // We handle result (if any) differently based on return to interpreter or call_stub
aoqi@0 2189
aoqi@0 2190 Label unwind_initial_with_pending_exception;
aoqi@0 2191
aoqi@0 2192 __ bind(throw_exception);
aoqi@0 2193 __ cmpptr(STATE(_prev_link), (int32_t)NULL_WORD); // returning from recursive interpreter call?
aoqi@0 2194 __ jcc(Assembler::equal, unwind_initial_with_pending_exception); // no, back to native code (call_stub/c1/c2)
aoqi@0 2195 __ movptr(rax, STATE(_locals)); // pop parameters get new stack value
aoqi@0 2196 __ addptr(rax, wordSize); // account for prepush before we return
aoqi@0 2197 __ jmp(unwind_recursive_activation);
aoqi@0 2198
aoqi@0 2199 __ bind(unwind_initial_with_pending_exception);
aoqi@0 2200
aoqi@0 2201 // We will unwind the current (initial) interpreter frame and forward
aoqi@0 2202 // the exception to the caller. We must put the exception in the
aoqi@0 2203 // expected register and clear pending exception and then forward.
aoqi@0 2204
aoqi@0 2205 __ jmp(unwind_and_forward);
aoqi@0 2206
aoqi@0 2207 interpreter_frame_manager = entry_point;
aoqi@0 2208 return entry_point;
aoqi@0 2209 }
aoqi@0 2210
aoqi@0 2211 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
aoqi@0 2212 // determine code generation flags
aoqi@0 2213 bool synchronized = false;
aoqi@0 2214 address entry_point = NULL;
aoqi@0 2215
aoqi@0 2216 switch (kind) {
aoqi@0 2217 case Interpreter::zerolocals : break;
aoqi@0 2218 case Interpreter::zerolocals_synchronized: synchronized = true; break;
aoqi@0 2219 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
aoqi@0 2220 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
aoqi@0 2221 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
aoqi@0 2222 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
aoqi@0 2223 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
aoqi@0 2224 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
aoqi@0 2225
aoqi@0 2226 case Interpreter::java_lang_math_sin : // fall thru
aoqi@0 2227 case Interpreter::java_lang_math_cos : // fall thru
aoqi@0 2228 case Interpreter::java_lang_math_tan : // fall thru
aoqi@0 2229 case Interpreter::java_lang_math_abs : // fall thru
aoqi@0 2230 case Interpreter::java_lang_math_log : // fall thru
aoqi@0 2231 case Interpreter::java_lang_math_log10 : // fall thru
aoqi@0 2232 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
aoqi@0 2233 case Interpreter::java_lang_ref_reference_get
aoqi@0 2234 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
aoqi@0 2235 default : ShouldNotReachHere(); break;
aoqi@0 2236 }
aoqi@0 2237
aoqi@0 2238 if (entry_point) return entry_point;
aoqi@0 2239
aoqi@0 2240 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
aoqi@0 2241
aoqi@0 2242 }
aoqi@0 2243
aoqi@0 2244 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
aoqi@0 2245 : CppInterpreterGenerator(code) {
aoqi@0 2246 generate_all(); // down here so it can be "virtual"
aoqi@0 2247 }
aoqi@0 2248
aoqi@0 2249 // Deoptimization helpers for C++ interpreter
aoqi@0 2250
aoqi@0 2251 // How much stack a method activation needs in words.
aoqi@0 2252 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
aoqi@0 2253
aoqi@0 2254 const int stub_code = 4; // see generate_call_stub
aoqi@0 2255 // Save space for one monitor to get into the interpreted method in case
aoqi@0 2256 // the method is synchronized
aoqi@0 2257 int monitor_size = method->is_synchronized() ?
aoqi@0 2258 1*frame::interpreter_frame_monitor_size() : 0;
aoqi@0 2259
aoqi@0 2260 // total static overhead size. Account for interpreter state object, return
aoqi@0 2261 // address, saved rbp and 2 words for a "static long no_params() method" issue.
aoqi@0 2262
aoqi@0 2263 const int overhead_size = sizeof(BytecodeInterpreter)/wordSize +
aoqi@0 2264 ( frame::sender_sp_offset - frame::link_offset) + 2;
aoqi@0 2265
aoqi@0 2266 const int method_stack = (method->max_locals() + method->max_stack()) *
aoqi@0 2267 Interpreter::stackElementWords;
aoqi@0 2268 return overhead_size + method_stack + stub_code;
aoqi@0 2269 }
aoqi@0 2270
aoqi@0 2271 // returns the activation size.
aoqi@0 2272 static int size_activation_helper(int extra_locals_size, int monitor_size) {
aoqi@0 2273 return (extra_locals_size + // the addition space for locals
aoqi@0 2274 2*BytesPerWord + // return address and saved rbp
aoqi@0 2275 2*BytesPerWord + // "static long no_params() method" issue
aoqi@0 2276 sizeof(BytecodeInterpreter) + // interpreterState
aoqi@0 2277 monitor_size); // monitors
aoqi@0 2278 }
aoqi@0 2279
aoqi@0 2280 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
aoqi@0 2281 frame* caller,
aoqi@0 2282 frame* current,
aoqi@0 2283 Method* method,
aoqi@0 2284 intptr_t* locals,
aoqi@0 2285 intptr_t* stack,
aoqi@0 2286 intptr_t* stack_base,
aoqi@0 2287 intptr_t* monitor_base,
aoqi@0 2288 intptr_t* frame_bottom,
aoqi@0 2289 bool is_top_frame
aoqi@0 2290 )
aoqi@0 2291 {
aoqi@0 2292 // What about any vtable?
aoqi@0 2293 //
aoqi@0 2294 to_fill->_thread = JavaThread::current();
aoqi@0 2295 // This gets filled in later but make it something recognizable for now
aoqi@0 2296 to_fill->_bcp = method->code_base();
aoqi@0 2297 to_fill->_locals = locals;
aoqi@0 2298 to_fill->_constants = method->constants()->cache();
aoqi@0 2299 to_fill->_method = method;
aoqi@0 2300 to_fill->_mdx = NULL;
aoqi@0 2301 to_fill->_stack = stack;
aoqi@0 2302 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {
aoqi@0 2303 to_fill->_msg = deopt_resume2;
aoqi@0 2304 } else {
aoqi@0 2305 to_fill->_msg = method_resume;
aoqi@0 2306 }
aoqi@0 2307 to_fill->_result._to_call._bcp_advance = 0;
aoqi@0 2308 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
aoqi@0 2309 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
aoqi@0 2310 to_fill->_prev_link = NULL;
aoqi@0 2311
aoqi@0 2312 to_fill->_sender_sp = caller->unextended_sp();
aoqi@0 2313
aoqi@0 2314 if (caller->is_interpreted_frame()) {
aoqi@0 2315 interpreterState prev = caller->get_interpreterState();
aoqi@0 2316 to_fill->_prev_link = prev;
aoqi@0 2317 // *current->register_addr(GR_Iprev_state) = (intptr_t) prev;
aoqi@0 2318 // Make the prev callee look proper
aoqi@0 2319 prev->_result._to_call._callee = method;
aoqi@0 2320 if (*prev->_bcp == Bytecodes::_invokeinterface) {
aoqi@0 2321 prev->_result._to_call._bcp_advance = 5;
aoqi@0 2322 } else {
aoqi@0 2323 prev->_result._to_call._bcp_advance = 3;
aoqi@0 2324 }
aoqi@0 2325 }
aoqi@0 2326 to_fill->_oop_temp = NULL;
aoqi@0 2327 to_fill->_stack_base = stack_base;
aoqi@0 2328 // Need +1 here because stack_base points to the word just above the first expr stack entry
aoqi@0 2329 // and stack_limit is supposed to point to the word just below the last expr stack entry.
aoqi@0 2330 // See generate_compute_interpreter_state.
aoqi@0 2331 to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
aoqi@0 2332 to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
aoqi@0 2333
aoqi@0 2334 to_fill->_self_link = to_fill;
aoqi@0 2335 assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
aoqi@0 2336 "Stack top out of range");
aoqi@0 2337 }
aoqi@0 2338
aoqi@0 2339
aoqi@0 2340 static int frame_size_helper(int max_stack,
aoqi@0 2341 int tempcount,
aoqi@0 2342 int moncount,
aoqi@0 2343 int callee_param_count,
aoqi@0 2344 int callee_locals,
aoqi@0 2345 bool is_top_frame,
aoqi@0 2346 int& monitor_size,
aoqi@0 2347 int& full_frame_size) {
aoqi@0 2348 int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
aoqi@0 2349 monitor_size = sizeof(BasicObjectLock) * moncount;
aoqi@0 2350
aoqi@0 2351 // First calculate the frame size without any java expression stack
aoqi@0 2352 int short_frame_size = size_activation_helper(extra_locals_size,
aoqi@0 2353 monitor_size);
aoqi@0 2354
aoqi@0 2355 // Now with full size expression stack
aoqi@0 2356 full_frame_size = short_frame_size + max_stack * BytesPerWord;
aoqi@0 2357
aoqi@0 2358 // and now with only live portion of the expression stack
aoqi@0 2359 short_frame_size = short_frame_size + tempcount * BytesPerWord;
aoqi@0 2360
aoqi@0 2361 // the size the activation is right now. Only top frame is full size
aoqi@0 2362 int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
aoqi@0 2363 return frame_size;
aoqi@0 2364 }
aoqi@0 2365
aoqi@0 2366 int AbstractInterpreter::size_activation(int max_stack,
aoqi@0 2367 int tempcount,
aoqi@0 2368 int extra_args,
aoqi@0 2369 int moncount,
aoqi@0 2370 int callee_param_count,
aoqi@0 2371 int callee_locals,
aoqi@0 2372 bool is_top_frame) {
aoqi@0 2373 assert(extra_args == 0, "FIX ME");
aoqi@0 2374 // NOTE: return size is in words not bytes
aoqi@0 2375
aoqi@0 2376 // Calculate the amount our frame will be adjust by the callee. For top frame
aoqi@0 2377 // this is zero.
aoqi@0 2378
aoqi@0 2379 // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
aoqi@0 2380 // calculates the extra locals based on itself. Not what the callee does
aoqi@0 2381 // to it. So it ignores last_frame_adjust value. Seems suspicious as far
aoqi@0 2382 // as getting sender_sp correct.
aoqi@0 2383
aoqi@0 2384 int unused_monitor_size = 0;
aoqi@0 2385 int unused_full_frame_size = 0;
aoqi@0 2386 return frame_size_helper(max_stack, tempcount, moncount, callee_param_count, callee_locals,
aoqi@0 2387 is_top_frame, unused_monitor_size, unused_full_frame_size)/BytesPerWord;
aoqi@0 2388 }
aoqi@0 2389
aoqi@0 2390 void AbstractInterpreter::layout_activation(Method* method,
aoqi@0 2391 int tempcount, //
aoqi@0 2392 int popframe_extra_args,
aoqi@0 2393 int moncount,
aoqi@0 2394 int caller_actual_parameters,
aoqi@0 2395 int callee_param_count,
aoqi@0 2396 int callee_locals,
aoqi@0 2397 frame* caller,
aoqi@0 2398 frame* interpreter_frame,
aoqi@0 2399 bool is_top_frame,
aoqi@0 2400 bool is_bottom_frame) {
aoqi@0 2401
aoqi@0 2402 assert(popframe_extra_args == 0, "FIX ME");
aoqi@0 2403 // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
aoqi@0 2404 // does as far as allocating an interpreter frame.
aoqi@0 2405 // Set up the method, locals, and monitors.
aoqi@0 2406 // The frame interpreter_frame is guaranteed to be the right size,
aoqi@0 2407 // as determined by a previous call to the size_activation() method.
aoqi@0 2408 // It is also guaranteed to be walkable even though it is in a skeletal state
aoqi@0 2409 // NOTE: tempcount is the current size of the java expression stack. For top most
aoqi@0 2410 // frames we will allocate a full sized expression stack and not the curback
aoqi@0 2411 // version that non-top frames have.
aoqi@0 2412
aoqi@0 2413 int monitor_size = 0;
aoqi@0 2414 int full_frame_size = 0;
aoqi@0 2415 int frame_size = frame_size_helper(method->max_stack(), tempcount, moncount, callee_param_count, callee_locals,
aoqi@0 2416 is_top_frame, monitor_size, full_frame_size);
aoqi@0 2417
aoqi@0 2418 #ifdef ASSERT
aoqi@0 2419 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
aoqi@0 2420 #endif
aoqi@0 2421
aoqi@0 2422 // MUCHO HACK
aoqi@0 2423
aoqi@0 2424 intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
aoqi@0 2425
aoqi@0 2426 /* Now fillin the interpreterState object */
aoqi@0 2427
aoqi@0 2428 // The state object is the first thing on the frame and easily located
aoqi@0 2429
aoqi@0 2430 interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
aoqi@0 2431
aoqi@0 2432
aoqi@0 2433 // Find the locals pointer. This is rather simple on x86 because there is no
aoqi@0 2434 // confusing rounding at the callee to account for. We can trivially locate
aoqi@0 2435 // our locals based on the current fp().
aoqi@0 2436 // Note: the + 2 is for handling the "static long no_params() method" issue.
aoqi@0 2437 // (too bad I don't really remember that issue well...)
aoqi@0 2438
aoqi@0 2439 intptr_t* locals;
aoqi@0 2440 // If the caller is interpreted we need to make sure that locals points to the first
aoqi@0 2441 // argument that the caller passed and not in an area where the stack might have been extended.
aoqi@0 2442 // because the stack to stack to converter needs a proper locals value in order to remove the
aoqi@0 2443 // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
aoqi@0 2444 // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
aoqi@0 2445 // adjust the stack?? HMMM QQQ
aoqi@0 2446 //
aoqi@0 2447 if (caller->is_interpreted_frame()) {
aoqi@0 2448 // locals must agree with the caller because it will be used to set the
aoqi@0 2449 // caller's tos when we return.
aoqi@0 2450 interpreterState prev = caller->get_interpreterState();
aoqi@0 2451 // stack() is prepushed.
aoqi@0 2452 locals = prev->stack() + method->size_of_parameters();
aoqi@0 2453 // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
aoqi@0 2454 if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
aoqi@0 2455 // os::breakpoint();
aoqi@0 2456 }
aoqi@0 2457 } else {
aoqi@0 2458 // this is where a c2i would have placed locals (except for the +2)
aoqi@0 2459 locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
aoqi@0 2460 }
aoqi@0 2461
aoqi@0 2462 intptr_t* monitor_base = (intptr_t*) cur_state;
aoqi@0 2463 intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
aoqi@0 2464 /* +1 because stack is always prepushed */
aoqi@0 2465 intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
aoqi@0 2466
aoqi@0 2467
aoqi@0 2468 BytecodeInterpreter::layout_interpreterState(cur_state,
aoqi@0 2469 caller,
aoqi@0 2470 interpreter_frame,
aoqi@0 2471 method,
aoqi@0 2472 locals,
aoqi@0 2473 stack,
aoqi@0 2474 stack_base,
aoqi@0 2475 monitor_base,
aoqi@0 2476 frame_bottom,
aoqi@0 2477 is_top_frame);
aoqi@0 2478
aoqi@0 2479 // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
aoqi@0 2480 }
aoqi@0 2481
aoqi@0 2482 #endif // CC_INTERP (all)

mercurial