annotate src/cpu/x86/vm/cppInterpreter_x86.cpp @ 304:dc7f315e41f7

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