src/cpu/x86/vm/cppInterpreter_x86.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 739
dc7f315e41f7
permissions
-rw-r--r--

Initial load

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

mercurial