src/cpu/x86/vm/cppInterpreter_x86.cpp

Wed, 17 Jun 2015 17:48:25 -0700

author
ascarpino
date
Wed, 17 Jun 2015 17:48:25 -0700
changeset 9788
44ef77ad417c
parent 8368
32b682649973
child 8604
04d83ba48607
permissions
-rw-r--r--

8073108: Use x86 and SPARC CPU instructions for GHASH acceleration
Reviewed-by: kvn, jrose, phh

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

mercurial