annotate src/cpu/x86/vm/templateInterpreter_x86_32.cpp @ 748:e5b0439ef4ae

6655638: dynamic languages need method handles Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.) Reviewed-by: kvn, twisti, never
author jrose
date Wed, 08 Apr 2009 10:56:49 -0700
parents 7bb995fbd3c0
children be93aad57795
rev   line source
duke@0 1 /*
xdono@615 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_templateInterpreter_x86_32.cpp.incl"
duke@0 27
duke@0 28 #define __ _masm->
duke@0 29
duke@0 30
duke@0 31 #ifndef CC_INTERP
duke@0 32 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
duke@0 33 const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize;
duke@0 34 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
duke@0 35
duke@0 36 //------------------------------------------------------------------------------------------------------------------------
duke@0 37
duke@0 38 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
duke@0 39 address entry = __ pc();
duke@0 40
duke@0 41 // Note: There should be a minimal interpreter frame set up when stack
duke@0 42 // overflow occurs since we check explicitly for it now.
duke@0 43 //
duke@0 44 #ifdef ASSERT
duke@0 45 { Label L;
never@307 46 __ lea(rax, Address(rbp,
duke@0 47 frame::interpreter_frame_monitor_block_top_offset * wordSize));
never@307 48 __ cmpptr(rax, rsp); // rax, = maximal rsp for current rbp,
duke@0 49 // (stack grows negative)
duke@0 50 __ jcc(Assembler::aboveEqual, L); // check if frame is complete
duke@0 51 __ stop ("interpreter frame not set up");
duke@0 52 __ bind(L);
duke@0 53 }
duke@0 54 #endif // ASSERT
duke@0 55 // Restore bcp under the assumption that the current frame is still
duke@0 56 // interpreted
duke@0 57 __ restore_bcp();
duke@0 58
duke@0 59 // expression stack must be empty before entering the VM if an exception
duke@0 60 // happened
duke@0 61 __ empty_expression_stack();
duke@0 62 __ empty_FPU_stack();
duke@0 63 // throw exception
duke@0 64 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
duke@0 65 return entry;
duke@0 66 }
duke@0 67
duke@0 68 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
duke@0 69 address entry = __ pc();
duke@0 70 // expression stack must be empty before entering the VM if an exception happened
duke@0 71 __ empty_expression_stack();
duke@0 72 __ empty_FPU_stack();
duke@0 73 // setup parameters
duke@0 74 // ??? convention: expect aberrant index in register rbx,
duke@0 75 __ lea(rax, ExternalAddress((address)name));
duke@0 76 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), rax, rbx);
duke@0 77 return entry;
duke@0 78 }
duke@0 79
duke@0 80 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
duke@0 81 address entry = __ pc();
duke@0 82 // object is at TOS
never@307 83 __ pop(rax);
duke@0 84 // expression stack must be empty before entering the VM if an exception
duke@0 85 // happened
duke@0 86 __ empty_expression_stack();
duke@0 87 __ empty_FPU_stack();
duke@0 88 __ call_VM(noreg,
duke@0 89 CAST_FROM_FN_PTR(address,
duke@0 90 InterpreterRuntime::throw_ClassCastException),
duke@0 91 rax);
duke@0 92 return entry;
duke@0 93 }
duke@0 94
jrose@748 95 // Arguments are: required type at TOS+8, failing object (or NULL) at TOS+4.
jrose@748 96 // pc at TOS (just for debugging)
jrose@748 97 address TemplateInterpreterGenerator::generate_WrongMethodType_handler() {
jrose@748 98 address entry = __ pc();
jrose@748 99
jrose@748 100 __ pop(rbx); // actual failing object is at TOS
jrose@748 101 __ pop(rax); // required type is at TOS+4
jrose@748 102
jrose@748 103 __ verify_oop(rbx);
jrose@748 104 __ verify_oop(rax);
jrose@748 105
jrose@748 106 // Various method handle types use interpreter registers as temps.
jrose@748 107 __ restore_bcp();
jrose@748 108 __ restore_locals();
jrose@748 109
jrose@748 110 // Expression stack must be empty before entering the VM for an exception.
jrose@748 111 __ empty_expression_stack();
jrose@748 112 __ empty_FPU_stack();
jrose@748 113 __ call_VM(noreg,
jrose@748 114 CAST_FROM_FN_PTR(address,
jrose@748 115 InterpreterRuntime::throw_WrongMethodTypeException),
jrose@748 116 // pass required type, failing object (or NULL)
jrose@748 117 rax, rbx);
jrose@748 118 return entry;
jrose@748 119 }
jrose@748 120
jrose@748 121
duke@0 122 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
duke@0 123 assert(!pass_oop || message == NULL, "either oop or message but not both");
duke@0 124 address entry = __ pc();
duke@0 125 if (pass_oop) {
duke@0 126 // object is at TOS
never@307 127 __ pop(rbx);
duke@0 128 }
duke@0 129 // expression stack must be empty before entering the VM if an exception happened
duke@0 130 __ empty_expression_stack();
duke@0 131 __ empty_FPU_stack();
duke@0 132 // setup parameters
duke@0 133 __ lea(rax, ExternalAddress((address)name));
duke@0 134 if (pass_oop) {
duke@0 135 __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), rax, rbx);
duke@0 136 } else {
duke@0 137 if (message != NULL) {
duke@0 138 __ lea(rbx, ExternalAddress((address)message));
duke@0 139 } else {
xlu@520 140 __ movptr(rbx, NULL_WORD);
duke@0 141 }
duke@0 142 __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), rax, rbx);
duke@0 143 }
duke@0 144 // throw exception
duke@0 145 __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
duke@0 146 return entry;
duke@0 147 }
duke@0 148
duke@0 149
duke@0 150 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
duke@0 151 address entry = __ pc();
duke@0 152 // NULL last_sp until next java call
xlu@520 153 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 154 __ dispatch_next(state);
duke@0 155 return entry;
duke@0 156 }
duke@0 157
duke@0 158
duke@0 159 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step) {
duke@0 160 Label interpreter_entry;
duke@0 161 address compiled_entry = __ pc();
duke@0 162
duke@0 163 #ifdef COMPILER2
duke@0 164 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
duke@0 165 if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) {
duke@0 166 for (int i = 1; i < 8; i++) {
duke@0 167 __ ffree(i);
duke@0 168 }
duke@0 169 } else if (UseSSE < 2) {
duke@0 170 __ empty_FPU_stack();
duke@0 171 }
duke@0 172 #endif
duke@0 173 if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) {
duke@0 174 __ MacroAssembler::verify_FPU(1, "generate_return_entry_for compiled");
duke@0 175 } else {
duke@0 176 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
duke@0 177 }
duke@0 178
duke@0 179 __ jmp(interpreter_entry, relocInfo::none);
duke@0 180 // emit a sentinel we can test for when converting an interpreter
duke@0 181 // entry point to a compiled entry point.
duke@0 182 __ a_long(Interpreter::return_sentinel);
duke@0 183 __ a_long((int)compiled_entry);
duke@0 184 address entry = __ pc();
duke@0 185 __ bind(interpreter_entry);
duke@0 186
duke@0 187 // In SSE mode, interpreter returns FP results in xmm0 but they need
duke@0 188 // to end up back on the FPU so it can operate on them.
duke@0 189 if (state == ftos && UseSSE >= 1) {
never@307 190 __ subptr(rsp, wordSize);
duke@0 191 __ movflt(Address(rsp, 0), xmm0);
duke@0 192 __ fld_s(Address(rsp, 0));
never@307 193 __ addptr(rsp, wordSize);
duke@0 194 } else if (state == dtos && UseSSE >= 2) {
never@307 195 __ subptr(rsp, 2*wordSize);
duke@0 196 __ movdbl(Address(rsp, 0), xmm0);
duke@0 197 __ fld_d(Address(rsp, 0));
never@307 198 __ addptr(rsp, 2*wordSize);
duke@0 199 }
duke@0 200
duke@0 201 __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_return_entry_for in interpreter");
duke@0 202
duke@0 203 // Restore stack bottom in case i2c adjusted stack
never@307 204 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
duke@0 205 // and NULL it as marker that rsp is now tos until next java call
xlu@520 206 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 207
duke@0 208 __ restore_bcp();
duke@0 209 __ restore_locals();
duke@0 210 __ get_cache_and_index_at_bcp(rbx, rcx, 1);
duke@0 211 __ movl(rbx, Address(rbx, rcx,
never@307 212 Address::times_ptr, constantPoolCacheOopDesc::base_offset() +
duke@0 213 ConstantPoolCacheEntry::flags_offset()));
never@307 214 __ andptr(rbx, 0xFF);
never@307 215 __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));
duke@0 216 __ dispatch_next(state, step);
duke@0 217 return entry;
duke@0 218 }
duke@0 219
duke@0 220
duke@0 221 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
duke@0 222 address entry = __ pc();
duke@0 223
duke@0 224 // In SSE mode, FP results are in xmm0
duke@0 225 if (state == ftos && UseSSE > 0) {
never@307 226 __ subptr(rsp, wordSize);
duke@0 227 __ movflt(Address(rsp, 0), xmm0);
duke@0 228 __ fld_s(Address(rsp, 0));
never@307 229 __ addptr(rsp, wordSize);
duke@0 230 } else if (state == dtos && UseSSE >= 2) {
never@307 231 __ subptr(rsp, 2*wordSize);
duke@0 232 __ movdbl(Address(rsp, 0), xmm0);
duke@0 233 __ fld_d(Address(rsp, 0));
never@307 234 __ addptr(rsp, 2*wordSize);
duke@0 235 }
duke@0 236
duke@0 237 __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_deopt_entry_for in interpreter");
duke@0 238
duke@0 239 // The stack is not extended by deopt but we must NULL last_sp as this
duke@0 240 // entry is like a "return".
xlu@520 241 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 242 __ restore_bcp();
duke@0 243 __ restore_locals();
duke@0 244 // handle exceptions
duke@0 245 { Label L;
duke@0 246 const Register thread = rcx;
duke@0 247 __ get_thread(thread);
never@307 248 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
duke@0 249 __ jcc(Assembler::zero, L);
duke@0 250 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 251 __ should_not_reach_here();
duke@0 252 __ bind(L);
duke@0 253 }
duke@0 254 __ dispatch_next(state, step);
duke@0 255 return entry;
duke@0 256 }
duke@0 257
duke@0 258
duke@0 259 int AbstractInterpreter::BasicType_as_index(BasicType type) {
duke@0 260 int i = 0;
duke@0 261 switch (type) {
duke@0 262 case T_BOOLEAN: i = 0; break;
duke@0 263 case T_CHAR : i = 1; break;
duke@0 264 case T_BYTE : i = 2; break;
duke@0 265 case T_SHORT : i = 3; break;
duke@0 266 case T_INT : // fall through
duke@0 267 case T_LONG : // fall through
duke@0 268 case T_VOID : i = 4; break;
duke@0 269 case T_FLOAT : i = 5; break; // have to treat float and double separately for SSE
duke@0 270 case T_DOUBLE : i = 6; break;
duke@0 271 case T_OBJECT : // fall through
duke@0 272 case T_ARRAY : i = 7; break;
duke@0 273 default : ShouldNotReachHere();
duke@0 274 }
duke@0 275 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
duke@0 276 return i;
duke@0 277 }
duke@0 278
duke@0 279
duke@0 280 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
duke@0 281 address entry = __ pc();
duke@0 282 switch (type) {
duke@0 283 case T_BOOLEAN: __ c2bool(rax); break;
never@307 284 case T_CHAR : __ andptr(rax, 0xFFFF); break;
duke@0 285 case T_BYTE : __ sign_extend_byte (rax); break;
duke@0 286 case T_SHORT : __ sign_extend_short(rax); break;
duke@0 287 case T_INT : /* nothing to do */ break;
duke@0 288 case T_DOUBLE :
duke@0 289 case T_FLOAT :
duke@0 290 { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
never@307 291 __ pop(t); // remove return address first
duke@0 292 __ pop_dtos_to_rsp();
duke@0 293 // Must return a result for interpreter or compiler. In SSE
duke@0 294 // mode, results are returned in xmm0 and the FPU stack must
duke@0 295 // be empty.
duke@0 296 if (type == T_FLOAT && UseSSE >= 1) {
duke@0 297 // Load ST0
duke@0 298 __ fld_d(Address(rsp, 0));
duke@0 299 // Store as float and empty fpu stack
duke@0 300 __ fstp_s(Address(rsp, 0));
duke@0 301 // and reload
duke@0 302 __ movflt(xmm0, Address(rsp, 0));
duke@0 303 } else if (type == T_DOUBLE && UseSSE >= 2 ) {
duke@0 304 __ movdbl(xmm0, Address(rsp, 0));
duke@0 305 } else {
duke@0 306 // restore ST0
duke@0 307 __ fld_d(Address(rsp, 0));
duke@0 308 }
duke@0 309 // and pop the temp
never@307 310 __ addptr(rsp, 2 * wordSize);
never@307 311 __ push(t); // restore return address
duke@0 312 }
duke@0 313 break;
duke@0 314 case T_OBJECT :
duke@0 315 // retrieve result from frame
never@307 316 __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
duke@0 317 // and verify it
duke@0 318 __ verify_oop(rax);
duke@0 319 break;
duke@0 320 default : ShouldNotReachHere();
duke@0 321 }
duke@0 322 __ ret(0); // return from result handler
duke@0 323 return entry;
duke@0 324 }
duke@0 325
duke@0 326 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
duke@0 327 address entry = __ pc();
duke@0 328 __ push(state);
duke@0 329 __ call_VM(noreg, runtime_entry);
duke@0 330 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
duke@0 331 return entry;
duke@0 332 }
duke@0 333
duke@0 334
duke@0 335 // Helpers for commoning out cases in the various type of method entries.
duke@0 336 //
duke@0 337
duke@0 338 // increment invocation count & check for overflow
duke@0 339 //
duke@0 340 // Note: checking for negative value instead of overflow
duke@0 341 // so we have a 'sticky' overflow test
duke@0 342 //
duke@0 343 // rbx,: method
duke@0 344 // rcx: invocation counter
duke@0 345 //
duke@0 346 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
duke@0 347
duke@0 348 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
duke@0 349 const Address backedge_counter (rbx, methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset());
duke@0 350
duke@0 351 if (ProfileInterpreter) { // %%% Merge this into methodDataOop
never@307 352 __ incrementl(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset()));
duke@0 353 }
duke@0 354 // Update standard invocation counters
duke@0 355 __ movl(rax, backedge_counter); // load backedge counter
duke@0 356
never@307 357 __ incrementl(rcx, InvocationCounter::count_increment);
duke@0 358 __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
duke@0 359
duke@0 360 __ movl(invocation_counter, rcx); // save invocation count
duke@0 361 __ addl(rcx, rax); // add both counters
duke@0 362
duke@0 363 // profile_method is non-null only for interpreted method so
duke@0 364 // profile_method != NULL == !native_call
duke@0 365 // BytecodeInterpreter only calls for native so code is elided.
duke@0 366
duke@0 367 if (ProfileInterpreter && profile_method != NULL) {
duke@0 368 // Test to see if we should create a method data oop
duke@0 369 __ cmp32(rcx,
duke@0 370 ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit));
duke@0 371 __ jcc(Assembler::less, *profile_method_continue);
duke@0 372
duke@0 373 // if no method data exists, go to profile_method
duke@0 374 __ test_method_data_pointer(rax, *profile_method);
duke@0 375 }
duke@0 376
duke@0 377 __ cmp32(rcx,
duke@0 378 ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
duke@0 379 __ jcc(Assembler::aboveEqual, *overflow);
duke@0 380
duke@0 381 }
duke@0 382
duke@0 383 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
duke@0 384
duke@0 385 // Asm interpreter on entry
duke@0 386 // rdi - locals
duke@0 387 // rsi - bcp
duke@0 388 // rbx, - method
duke@0 389 // rdx - cpool
duke@0 390 // rbp, - interpreter frame
duke@0 391
duke@0 392 // C++ interpreter on entry
duke@0 393 // rsi - new interpreter state pointer
duke@0 394 // rbp - interpreter frame pointer
duke@0 395 // rbx - method
duke@0 396
duke@0 397 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
duke@0 398 // rbx, - method
duke@0 399 // rcx - rcvr (assuming there is one)
duke@0 400 // top of stack return address of interpreter caller
duke@0 401 // rsp - sender_sp
duke@0 402
duke@0 403 // C++ interpreter only
duke@0 404 // rsi - previous interpreter state pointer
duke@0 405
duke@0 406 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 407
duke@0 408 // InterpreterRuntime::frequency_counter_overflow takes one argument
duke@0 409 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
duke@0 410 // The call returns the address of the verified entry point for the method or NULL
duke@0 411 // if the compilation did not complete (either went background or bailed out).
glewis@522 412 __ movptr(rax, (intptr_t)false);
duke@0 413 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
duke@0 414
never@307 415 __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
duke@0 416
duke@0 417 // Preserve invariant that rsi/rdi contain bcp/locals of sender frame
duke@0 418 // and jump to the interpreted entry.
duke@0 419 __ jmp(*do_continue, relocInfo::none);
duke@0 420
duke@0 421 }
duke@0 422
duke@0 423 void InterpreterGenerator::generate_stack_overflow_check(void) {
duke@0 424 // see if we've got enough room on the stack for locals plus overhead.
duke@0 425 // the expression stack grows down incrementally, so the normal guard
duke@0 426 // page mechanism will work for that.
duke@0 427 //
duke@0 428 // Registers live on entry:
duke@0 429 //
duke@0 430 // Asm interpreter
duke@0 431 // rdx: number of additional locals this frame needs (what we must check)
duke@0 432 // rbx,: methodOop
duke@0 433
duke@0 434 // destroyed on exit
duke@0 435 // rax,
duke@0 436
duke@0 437 // NOTE: since the additional locals are also always pushed (wasn't obvious in
duke@0 438 // generate_method_entry) so the guard should work for them too.
duke@0 439 //
duke@0 440
duke@0 441 // monitor entry size: see picture of stack set (generate_method_entry) and frame_x86.hpp
duke@0 442 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@0 443
duke@0 444 // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
duke@0 445 // be sure to change this if you add/subtract anything to/from the overhead area
duke@0 446 const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize) + entry_size;
duke@0 447
duke@0 448 const int page_size = os::vm_page_size();
duke@0 449
duke@0 450 Label after_frame_check;
duke@0 451
duke@0 452 // see if the frame is greater than one page in size. If so,
duke@0 453 // then we need to verify there is enough stack space remaining
duke@0 454 // for the additional locals.
duke@0 455 __ cmpl(rdx, (page_size - overhead_size)/Interpreter::stackElementSize());
duke@0 456 __ jcc(Assembler::belowEqual, after_frame_check);
duke@0 457
duke@0 458 // compute rsp as if this were going to be the last frame on
duke@0 459 // the stack before the red zone
duke@0 460
duke@0 461 Label after_frame_check_pop;
duke@0 462
never@307 463 __ push(rsi);
duke@0 464
duke@0 465 const Register thread = rsi;
duke@0 466
duke@0 467 __ get_thread(thread);
duke@0 468
duke@0 469 const Address stack_base(thread, Thread::stack_base_offset());
duke@0 470 const Address stack_size(thread, Thread::stack_size_offset());
duke@0 471
duke@0 472 // locals + overhead, in bytes
never@307 473 __ lea(rax, Address(noreg, rdx, Interpreter::stackElementScale(), overhead_size));
duke@0 474
duke@0 475 #ifdef ASSERT
duke@0 476 Label stack_base_okay, stack_size_okay;
duke@0 477 // verify that thread stack base is non-zero
never@307 478 __ cmpptr(stack_base, (int32_t)NULL_WORD);
duke@0 479 __ jcc(Assembler::notEqual, stack_base_okay);
duke@0 480 __ stop("stack base is zero");
duke@0 481 __ bind(stack_base_okay);
duke@0 482 // verify that thread stack size is non-zero
never@307 483 __ cmpptr(stack_size, 0);
duke@0 484 __ jcc(Assembler::notEqual, stack_size_okay);
duke@0 485 __ stop("stack size is zero");
duke@0 486 __ bind(stack_size_okay);
duke@0 487 #endif
duke@0 488
duke@0 489 // Add stack base to locals and subtract stack size
never@307 490 __ addptr(rax, stack_base);
never@307 491 __ subptr(rax, stack_size);
duke@0 492
duke@0 493 // Use the maximum number of pages we might bang.
duke@0 494 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
duke@0 495 (StackRedPages+StackYellowPages);
never@307 496 __ addptr(rax, max_pages * page_size);
duke@0 497
duke@0 498 // check against the current stack bottom
never@307 499 __ cmpptr(rsp, rax);
duke@0 500 __ jcc(Assembler::above, after_frame_check_pop);
duke@0 501
never@307 502 __ pop(rsi); // get saved bcp / (c++ prev state ).
duke@0 503
never@307 504 __ pop(rax); // get return address
duke@0 505 __ jump(ExternalAddress(Interpreter::throw_StackOverflowError_entry()));
duke@0 506
duke@0 507 // all done with frame size check
duke@0 508 __ bind(after_frame_check_pop);
never@307 509 __ pop(rsi);
duke@0 510
duke@0 511 __ bind(after_frame_check);
duke@0 512 }
duke@0 513
duke@0 514 // Allocate monitor and lock method (asm interpreter)
duke@0 515 // rbx, - methodOop
duke@0 516 //
duke@0 517 void InterpreterGenerator::lock_method(void) {
duke@0 518 // synchronize method
duke@0 519 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 520 const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
duke@0 521 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@0 522
duke@0 523 #ifdef ASSERT
duke@0 524 { Label L;
duke@0 525 __ movl(rax, access_flags);
duke@0 526 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 527 __ jcc(Assembler::notZero, L);
duke@0 528 __ stop("method doesn't need synchronization");
duke@0 529 __ bind(L);
duke@0 530 }
duke@0 531 #endif // ASSERT
duke@0 532 // get synchronization object
duke@0 533 { Label done;
duke@0 534 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 535 __ movl(rax, access_flags);
duke@0 536 __ testl(rax, JVM_ACC_STATIC);
never@307 537 __ movptr(rax, Address(rdi, Interpreter::local_offset_in_bytes(0))); // get receiver (assume this is frequent case)
duke@0 538 __ jcc(Assembler::zero, done);
never@307 539 __ movptr(rax, Address(rbx, methodOopDesc::constants_offset()));
never@307 540 __ movptr(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
never@307 541 __ movptr(rax, Address(rax, mirror_offset));
duke@0 542 __ bind(done);
duke@0 543 }
duke@0 544 // add space for monitor & lock
never@307 545 __ subptr(rsp, entry_size); // add space for a monitor entry
never@307 546 __ movptr(monitor_block_top, rsp); // set new monitor block top
never@307 547 __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
never@307 548 __ mov(rdx, rsp); // object address
duke@0 549 __ lock_object(rdx);
duke@0 550 }
duke@0 551
duke@0 552 //
duke@0 553 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
duke@0 554 // and for native methods hence the shared code.
duke@0 555
duke@0 556 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
duke@0 557 // initialize fixed part of activation frame
never@307 558 __ push(rax); // save return address
duke@0 559 __ enter(); // save old & set new rbp,
duke@0 560
duke@0 561
never@307 562 __ push(rsi); // set sender sp
never@307 563 __ push((int32_t)NULL_WORD); // leave last_sp as null
never@307 564 __ movptr(rsi, Address(rbx,methodOopDesc::const_offset())); // get constMethodOop
never@307 565 __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset())); // get codebase
never@307 566 __ push(rbx); // save methodOop
duke@0 567 if (ProfileInterpreter) {
duke@0 568 Label method_data_continue;
never@307 569 __ movptr(rdx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
never@307 570 __ testptr(rdx, rdx);
duke@0 571 __ jcc(Assembler::zero, method_data_continue);
never@307 572 __ addptr(rdx, in_bytes(methodDataOopDesc::data_offset()));
duke@0 573 __ bind(method_data_continue);
never@307 574 __ push(rdx); // set the mdp (method data pointer)
duke@0 575 } else {
never@307 576 __ push(0);
duke@0 577 }
duke@0 578
never@307 579 __ movptr(rdx, Address(rbx, methodOopDesc::constants_offset()));
never@307 580 __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
never@307 581 __ push(rdx); // set constant pool cache
never@307 582 __ push(rdi); // set locals pointer
duke@0 583 if (native_call) {
never@307 584 __ push(0); // no bcp
duke@0 585 } else {
never@307 586 __ push(rsi); // set bcp
duke@0 587 }
never@307 588 __ push(0); // reserve word for pointer to expression stack bottom
never@307 589 __ movptr(Address(rsp, 0), rsp); // set expression stack bottom
duke@0 590 }
duke@0 591
duke@0 592 // End of helpers
duke@0 593
duke@0 594 //
duke@0 595 // Various method entries
duke@0 596 //------------------------------------------------------------------------------------------------------------------------
duke@0 597 //
duke@0 598 //
duke@0 599
duke@0 600 // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
duke@0 601
duke@0 602 address InterpreterGenerator::generate_accessor_entry(void) {
duke@0 603
duke@0 604 // rbx,: methodOop
duke@0 605 // rcx: receiver (preserve for slow entry into asm interpreter)
duke@0 606
duke@0 607 // rsi: senderSP must preserved for slow path, set SP to it on fast path
duke@0 608
duke@0 609 address entry_point = __ pc();
duke@0 610 Label xreturn_path;
duke@0 611
duke@0 612 // do fastpath for resolved accessor methods
duke@0 613 if (UseFastAccessorMethods) {
duke@0 614 Label slow_path;
duke@0 615 // If we need a safepoint check, generate full interpreter entry.
duke@0 616 ExternalAddress state(SafepointSynchronize::address_of_state());
duke@0 617 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
duke@0 618 SafepointSynchronize::_not_synchronized);
duke@0 619
duke@0 620 __ jcc(Assembler::notEqual, slow_path);
duke@0 621 // ASM/C++ Interpreter
duke@0 622 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
duke@0 623 // Note: We can only use this code if the getfield has been resolved
duke@0 624 // and if we don't have a null-pointer exception => check for
duke@0 625 // these conditions first and use slow path if necessary.
duke@0 626 // rbx,: method
duke@0 627 // rcx: receiver
never@307 628 __ movptr(rax, Address(rsp, wordSize));
duke@0 629
duke@0 630 // check if local 0 != NULL and read field
never@307 631 __ testptr(rax, rax);
duke@0 632 __ jcc(Assembler::zero, slow_path);
duke@0 633
never@307 634 __ movptr(rdi, Address(rbx, methodOopDesc::constants_offset()));
duke@0 635 // read first instruction word and extract bytecode @ 1 and index @ 2
never@307 636 __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
duke@0 637 __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
duke@0 638 // Shift codes right to get the index on the right.
duke@0 639 // The bytecode fetched looks like <index><0xb4><0x2a>
duke@0 640 __ shrl(rdx, 2*BitsPerByte);
duke@0 641 __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
never@307 642 __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
duke@0 643
duke@0 644 // rax,: local 0
duke@0 645 // rbx,: method
duke@0 646 // rcx: receiver - do not destroy since it is needed for slow path!
duke@0 647 // rcx: scratch
duke@0 648 // rdx: constant pool cache index
duke@0 649 // rdi: constant pool cache
duke@0 650 // rsi: sender sp
duke@0 651
duke@0 652 // check if getfield has been resolved and read constant pool cache entry
duke@0 653 // check the validity of the cache entry by testing whether _indices field
duke@0 654 // contains Bytecode::_getfield in b1 byte.
duke@0 655 assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
duke@0 656 __ movl(rcx,
duke@0 657 Address(rdi,
duke@0 658 rdx,
never@307 659 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
duke@0 660 __ shrl(rcx, 2*BitsPerByte);
duke@0 661 __ andl(rcx, 0xFF);
duke@0 662 __ cmpl(rcx, Bytecodes::_getfield);
duke@0 663 __ jcc(Assembler::notEqual, slow_path);
duke@0 664
duke@0 665 // Note: constant pool entry is not valid before bytecode is resolved
never@307 666 __ movptr(rcx,
never@307 667 Address(rdi,
never@307 668 rdx,
never@307 669 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset()));
duke@0 670 __ movl(rdx,
duke@0 671 Address(rdi,
duke@0 672 rdx,
never@307 673 Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset()));
duke@0 674
duke@0 675 Label notByte, notShort, notChar;
duke@0 676 const Address field_address (rax, rcx, Address::times_1);
duke@0 677
duke@0 678 // Need to differentiate between igetfield, agetfield, bgetfield etc.
duke@0 679 // because they are different sizes.
duke@0 680 // Use the type from the constant pool cache
duke@0 681 __ shrl(rdx, ConstantPoolCacheEntry::tosBits);
duke@0 682 // Make sure we don't need to mask rdx for tosBits after the above shift
duke@0 683 ConstantPoolCacheEntry::verify_tosBits();
duke@0 684 __ cmpl(rdx, btos);
duke@0 685 __ jcc(Assembler::notEqual, notByte);
duke@0 686 __ load_signed_byte(rax, field_address);
duke@0 687 __ jmp(xreturn_path);
duke@0 688
duke@0 689 __ bind(notByte);
duke@0 690 __ cmpl(rdx, stos);
duke@0 691 __ jcc(Assembler::notEqual, notShort);
jrose@660 692 __ load_signed_short(rax, field_address);
duke@0 693 __ jmp(xreturn_path);
duke@0 694
duke@0 695 __ bind(notShort);
duke@0 696 __ cmpl(rdx, ctos);
duke@0 697 __ jcc(Assembler::notEqual, notChar);
jrose@660 698 __ load_unsigned_short(rax, field_address);
duke@0 699 __ jmp(xreturn_path);
duke@0 700
duke@0 701 __ bind(notChar);
duke@0 702 #ifdef ASSERT
duke@0 703 Label okay;
duke@0 704 __ cmpl(rdx, atos);
duke@0 705 __ jcc(Assembler::equal, okay);
duke@0 706 __ cmpl(rdx, itos);
duke@0 707 __ jcc(Assembler::equal, okay);
duke@0 708 __ stop("what type is this?");
duke@0 709 __ bind(okay);
duke@0 710 #endif // ASSERT
duke@0 711 // All the rest are a 32 bit wordsize
never@307 712 // This is ok for now. Since fast accessors should be going away
never@307 713 __ movptr(rax, field_address);
duke@0 714
duke@0 715 __ bind(xreturn_path);
duke@0 716
duke@0 717 // _ireturn/_areturn
never@307 718 __ pop(rdi); // get return address
never@307 719 __ mov(rsp, rsi); // set sp to sender sp
duke@0 720 __ jmp(rdi);
duke@0 721
duke@0 722 // generate a vanilla interpreter entry as the slow path
duke@0 723 __ bind(slow_path);
duke@0 724
duke@0 725 (void) generate_normal_entry(false);
duke@0 726 return entry_point;
duke@0 727 }
duke@0 728 return NULL;
duke@0 729
duke@0 730 }
duke@0 731
duke@0 732 //
duke@0 733 // Interpreter stub for calling a native method. (asm interpreter)
duke@0 734 // This sets up a somewhat different looking stack for calling the native method
duke@0 735 // than the typical interpreter frame setup.
duke@0 736 //
duke@0 737
duke@0 738 address InterpreterGenerator::generate_native_entry(bool synchronized) {
duke@0 739 // determine code generation flags
duke@0 740 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 741
duke@0 742 // rbx,: methodOop
duke@0 743 // rsi: sender sp
duke@0 744 // rsi: previous interpreter state (C++ interpreter) must preserve
duke@0 745 address entry_point = __ pc();
duke@0 746
duke@0 747
duke@0 748 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 749 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
duke@0 750 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 751
duke@0 752 // get parameter size (always needed)
jrose@660 753 __ load_unsigned_short(rcx, size_of_parameters);
duke@0 754
duke@0 755 // native calls don't need the stack size check since they have no expression stack
duke@0 756 // and the arguments are already on the stack and we only add a handful of words
duke@0 757 // to the stack
duke@0 758
duke@0 759 // rbx,: methodOop
duke@0 760 // rcx: size of parameters
duke@0 761 // rsi: sender sp
duke@0 762
never@307 763 __ pop(rax); // get return address
duke@0 764 // for natives the size of locals is zero
duke@0 765
duke@0 766 // compute beginning of parameters (rdi)
never@307 767 __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
duke@0 768
duke@0 769
duke@0 770 // add 2 zero-initialized slots for native calls
duke@0 771 // NULL result handler
never@307 772 __ push((int32_t)NULL_WORD);
duke@0 773 // NULL oop temp (mirror or jni oop result)
never@307 774 __ push((int32_t)NULL_WORD);
duke@0 775
duke@0 776 if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
duke@0 777 // initialize fixed part of activation frame
duke@0 778
duke@0 779 generate_fixed_frame(true);
duke@0 780
duke@0 781 // make sure method is native & not abstract
duke@0 782 #ifdef ASSERT
duke@0 783 __ movl(rax, access_flags);
duke@0 784 {
duke@0 785 Label L;
duke@0 786 __ testl(rax, JVM_ACC_NATIVE);
duke@0 787 __ jcc(Assembler::notZero, L);
duke@0 788 __ stop("tried to execute non-native method as native");
duke@0 789 __ bind(L);
duke@0 790 }
duke@0 791 { Label L;
duke@0 792 __ testl(rax, JVM_ACC_ABSTRACT);
duke@0 793 __ jcc(Assembler::zero, L);
duke@0 794 __ stop("tried to execute abstract method in interpreter");
duke@0 795 __ bind(L);
duke@0 796 }
duke@0 797 #endif
duke@0 798
duke@0 799 // Since at this point in the method invocation the exception handler
duke@0 800 // would try to exit the monitor of synchronized methods which hasn't
duke@0 801 // been entered yet, we set the thread local variable
duke@0 802 // _do_not_unlock_if_synchronized to true. The remove_activation will
duke@0 803 // check this flag.
duke@0 804
duke@0 805 __ get_thread(rax);
duke@0 806 const Address do_not_unlock_if_synchronized(rax,
duke@0 807 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
duke@0 808 __ movbool(do_not_unlock_if_synchronized, true);
duke@0 809
duke@0 810 // increment invocation count & check for overflow
duke@0 811 Label invocation_counter_overflow;
duke@0 812 if (inc_counter) {
duke@0 813 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
duke@0 814 }
duke@0 815
duke@0 816 Label continue_after_compile;
duke@0 817 __ bind(continue_after_compile);
duke@0 818
duke@0 819 bang_stack_shadow_pages(true);
duke@0 820
duke@0 821 // reset the _do_not_unlock_if_synchronized flag
duke@0 822 __ get_thread(rax);
duke@0 823 __ movbool(do_not_unlock_if_synchronized, false);
duke@0 824
duke@0 825 // check for synchronized methods
duke@0 826 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 827 // so method is not locked if overflows.
duke@0 828 //
duke@0 829 if (synchronized) {
duke@0 830 lock_method();
duke@0 831 } else {
duke@0 832 // no synchronization necessary
duke@0 833 #ifdef ASSERT
duke@0 834 { Label L;
duke@0 835 __ movl(rax, access_flags);
duke@0 836 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 837 __ jcc(Assembler::zero, L);
duke@0 838 __ stop("method needs synchronization");
duke@0 839 __ bind(L);
duke@0 840 }
duke@0 841 #endif
duke@0 842 }
duke@0 843
duke@0 844 // start execution
duke@0 845 #ifdef ASSERT
duke@0 846 { Label L;
duke@0 847 const Address monitor_block_top (rbp,
duke@0 848 frame::interpreter_frame_monitor_block_top_offset * wordSize);
never@307 849 __ movptr(rax, monitor_block_top);
never@307 850 __ cmpptr(rax, rsp);
duke@0 851 __ jcc(Assembler::equal, L);
duke@0 852 __ stop("broken stack frame setup in interpreter");
duke@0 853 __ bind(L);
duke@0 854 }
duke@0 855 #endif
duke@0 856
duke@0 857 // jvmti/dtrace support
duke@0 858 __ notify_method_entry();
duke@0 859
duke@0 860 // work registers
duke@0 861 const Register method = rbx;
duke@0 862 const Register thread = rdi;
duke@0 863 const Register t = rcx;
duke@0 864
duke@0 865 // allocate space for parameters
duke@0 866 __ get_method(method);
duke@0 867 __ verify_oop(method);
jrose@660 868 __ load_unsigned_short(t, Address(method, methodOopDesc::size_of_parameters_offset()));
never@307 869 __ shlptr(t, Interpreter::logStackElementSize());
never@307 870 __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror
never@307 871 __ subptr(rsp, t);
never@307 872 __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
duke@0 873
duke@0 874 // get signature handler
duke@0 875 { Label L;
never@307 876 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
never@307 877 __ testptr(t, t);
duke@0 878 __ jcc(Assembler::notZero, L);
duke@0 879 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
duke@0 880 __ get_method(method);
never@307 881 __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
duke@0 882 __ bind(L);
duke@0 883 }
duke@0 884
duke@0 885 // call signature handler
duke@0 886 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code");
duke@0 887 assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code");
duke@0 888 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t , "adjust this code");
duke@0 889 // The generated handlers do not touch RBX (the method oop).
duke@0 890 // However, large signatures cannot be cached and are generated
duke@0 891 // each time here. The slow-path generator will blow RBX
duke@0 892 // sometime, so we must reload it after the call.
duke@0 893 __ call(t);
duke@0 894 __ get_method(method); // slow path call blows RBX on DevStudio 5.0
duke@0 895
duke@0 896 // result handler is in rax,
duke@0 897 // set result handler
never@307 898 __ movptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize), rax);
duke@0 899
duke@0 900 // pass mirror handle if static call
duke@0 901 { Label L;
duke@0 902 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 903 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
duke@0 904 __ testl(t, JVM_ACC_STATIC);
duke@0 905 __ jcc(Assembler::zero, L);
duke@0 906 // get mirror
never@307 907 __ movptr(t, Address(method, methodOopDesc:: constants_offset()));
never@307 908 __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
never@307 909 __ movptr(t, Address(t, mirror_offset));
duke@0 910 // copy mirror into activation frame
never@307 911 __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize), t);
duke@0 912 // pass handle to mirror
never@307 913 __ lea(t, Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
never@307 914 __ movptr(Address(rsp, wordSize), t);
duke@0 915 __ bind(L);
duke@0 916 }
duke@0 917
duke@0 918 // get native function entry point
duke@0 919 { Label L;
never@307 920 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
duke@0 921 ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
never@307 922 __ cmpptr(rax, unsatisfied.addr());
duke@0 923 __ jcc(Assembler::notEqual, L);
duke@0 924 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
duke@0 925 __ get_method(method);
duke@0 926 __ verify_oop(method);
never@307 927 __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
duke@0 928 __ bind(L);
duke@0 929 }
duke@0 930
duke@0 931 // pass JNIEnv
duke@0 932 __ get_thread(thread);
never@307 933 __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
never@307 934 __ movptr(Address(rsp, 0), t);
duke@0 935
duke@0 936 // set_last_Java_frame_before_call
duke@0 937 // It is enough that the pc()
duke@0 938 // points into the right code segment. It does not have to be the correct return pc.
duke@0 939 __ set_last_Java_frame(thread, noreg, rbp, __ pc());
duke@0 940
duke@0 941 // change thread state
duke@0 942 #ifdef ASSERT
duke@0 943 { Label L;
duke@0 944 __ movl(t, Address(thread, JavaThread::thread_state_offset()));
duke@0 945 __ cmpl(t, _thread_in_Java);
duke@0 946 __ jcc(Assembler::equal, L);
duke@0 947 __ stop("Wrong thread state in native stub");
duke@0 948 __ bind(L);
duke@0 949 }
duke@0 950 #endif
duke@0 951
duke@0 952 // Change state to native
duke@0 953 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
duke@0 954 __ call(rax);
duke@0 955
duke@0 956 // result potentially in rdx:rax or ST0
duke@0 957
duke@0 958 // Either restore the MXCSR register after returning from the JNI Call
duke@0 959 // or verify that it wasn't changed.
duke@0 960 if (VM_Version::supports_sse()) {
duke@0 961 if (RestoreMXCSROnJNICalls) {
duke@0 962 __ ldmxcsr(ExternalAddress(StubRoutines::addr_mxcsr_std()));
duke@0 963 }
duke@0 964 else if (CheckJNICalls ) {
never@307 965 __ call(RuntimeAddress(StubRoutines::x86::verify_mxcsr_entry()));
duke@0 966 }
duke@0 967 }
duke@0 968
duke@0 969 // Either restore the x87 floating pointer control word after returning
duke@0 970 // from the JNI call or verify that it wasn't changed.
duke@0 971 if (CheckJNICalls) {
never@307 972 __ call(RuntimeAddress(StubRoutines::x86::verify_fpu_cntrl_wrd_entry()));
duke@0 973 }
duke@0 974
duke@0 975 // save potential result in ST(0) & rdx:rax
duke@0 976 // (if result handler is the T_FLOAT or T_DOUBLE handler, result must be in ST0 -
duke@0 977 // the check is necessary to avoid potential Intel FPU overflow problems by saving/restoring 'empty' FPU registers)
duke@0 978 // It is safe to do this push because state is _thread_in_native and return address will be found
duke@0 979 // via _last_native_pc and not via _last_jave_sp
duke@0 980
duke@0 981 // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
duke@0 982 // If the order changes or anything else is added to the stack the code in
duke@0 983 // interpreter_frame_result will have to be changed.
duke@0 984
duke@0 985 { Label L;
duke@0 986 Label push_double;
duke@0 987 ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
duke@0 988 ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
duke@0 989 __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
duke@0 990 float_handler.addr());
duke@0 991 __ jcc(Assembler::equal, push_double);
duke@0 992 __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
duke@0 993 double_handler.addr());
duke@0 994 __ jcc(Assembler::notEqual, L);
duke@0 995 __ bind(push_double);
duke@0 996 __ push(dtos);
duke@0 997 __ bind(L);
duke@0 998 }
duke@0 999 __ push(ltos);
duke@0 1000
duke@0 1001 // change thread state
duke@0 1002 __ get_thread(thread);
duke@0 1003 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
duke@0 1004 if(os::is_MP()) {
duke@0 1005 if (UseMembar) {
never@307 1006 // Force this write out before the read below
never@307 1007 __ membar(Assembler::Membar_mask_bits(
never@307 1008 Assembler::LoadLoad | Assembler::LoadStore |
never@307 1009 Assembler::StoreLoad | Assembler::StoreStore));
duke@0 1010 } else {
duke@0 1011 // Write serialization page so VM thread can do a pseudo remote membar.
duke@0 1012 // We use the current thread pointer to calculate a thread specific
duke@0 1013 // offset to write to within the page. This minimizes bus traffic
duke@0 1014 // due to cache line collision.
duke@0 1015 __ serialize_memory(thread, rcx);
duke@0 1016 }
duke@0 1017 }
duke@0 1018
duke@0 1019 if (AlwaysRestoreFPU) {
duke@0 1020 // Make sure the control word is correct.
duke@0 1021 __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
duke@0 1022 }
duke@0 1023
duke@0 1024 // check for safepoint operation in progress and/or pending suspend requests
duke@0 1025 { Label Continue;
duke@0 1026
duke@0 1027 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
duke@0 1028 SafepointSynchronize::_not_synchronized);
duke@0 1029
duke@0 1030 Label L;
duke@0 1031 __ jcc(Assembler::notEqual, L);
duke@0 1032 __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
duke@0 1033 __ jcc(Assembler::equal, Continue);
duke@0 1034 __ bind(L);
duke@0 1035
duke@0 1036 // Don't use call_VM as it will see a possible pending exception and forward it
duke@0 1037 // and never return here preventing us from clearing _last_native_pc down below.
duke@0 1038 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
duke@0 1039 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
duke@0 1040 // by hand.
duke@0 1041 //
never@307 1042 __ push(thread);
duke@0 1043 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
duke@0 1044 JavaThread::check_special_condition_for_native_trans)));
duke@0 1045 __ increment(rsp, wordSize);
duke@0 1046 __ get_thread(thread);
duke@0 1047
duke@0 1048 __ bind(Continue);
duke@0 1049 }
duke@0 1050
duke@0 1051 // change thread state
duke@0 1052 __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
duke@0 1053
duke@0 1054 __ reset_last_Java_frame(thread, true, true);
duke@0 1055
duke@0 1056 // reset handle block
never@307 1057 __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
xlu@520 1058 __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD);
duke@0 1059
duke@0 1060 // If result was an oop then unbox and save it in the frame
duke@0 1061 { Label L;
duke@0 1062 Label no_oop, store_result;
duke@0 1063 ExternalAddress handler(AbstractInterpreter::result_handler(T_OBJECT));
duke@0 1064 __ cmpptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize),
duke@0 1065 handler.addr());
duke@0 1066 __ jcc(Assembler::notEqual, no_oop);
never@307 1067 __ cmpptr(Address(rsp, 0), (int32_t)NULL_WORD);
duke@0 1068 __ pop(ltos);
never@307 1069 __ testptr(rax, rax);
duke@0 1070 __ jcc(Assembler::zero, store_result);
duke@0 1071 // unbox
never@307 1072 __ movptr(rax, Address(rax, 0));
duke@0 1073 __ bind(store_result);
never@307 1074 __ movptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset)*wordSize), rax);
duke@0 1075 // keep stack depth as expected by pushing oop which will eventually be discarded
duke@0 1076 __ push(ltos);
duke@0 1077 __ bind(no_oop);
duke@0 1078 }
duke@0 1079
duke@0 1080 {
duke@0 1081 Label no_reguard;
duke@0 1082 __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
duke@0 1083 __ jcc(Assembler::notEqual, no_reguard);
duke@0 1084
never@307 1085 __ pusha();
duke@0 1086 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
never@307 1087 __ popa();
duke@0 1088
duke@0 1089 __ bind(no_reguard);
duke@0 1090 }
duke@0 1091
duke@0 1092 // restore rsi to have legal interpreter frame,
duke@0 1093 // i.e., bci == 0 <=> rsi == code_base()
duke@0 1094 // Can't call_VM until bcp is within reasonable.
duke@0 1095 __ get_method(method); // method is junk from thread_in_native to now.
duke@0 1096 __ verify_oop(method);
never@307 1097 __ movptr(rsi, Address(method,methodOopDesc::const_offset())); // get constMethodOop
never@307 1098 __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset())); // get codebase
duke@0 1099
duke@0 1100 // handle exceptions (exception handling will handle unlocking!)
duke@0 1101 { Label L;
never@307 1102 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
duke@0 1103 __ jcc(Assembler::zero, L);
duke@0 1104 // Note: At some point we may want to unify this with the code used in call_VM_base();
duke@0 1105 // i.e., we should use the StubRoutines::forward_exception code. For now this
duke@0 1106 // doesn't work here because the rsp is not correctly set at this point.
duke@0 1107 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 1108 __ should_not_reach_here();
duke@0 1109 __ bind(L);
duke@0 1110 }
duke@0 1111
duke@0 1112 // do unlocking if necessary
duke@0 1113 { Label L;
duke@0 1114 __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
duke@0 1115 __ testl(t, JVM_ACC_SYNCHRONIZED);
duke@0 1116 __ jcc(Assembler::zero, L);
duke@0 1117 // the code below should be shared with interpreter macro assembler implementation
duke@0 1118 { Label unlock;
duke@0 1119 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
duke@0 1120 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
duke@0 1121 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
duke@0 1122
never@307 1123 __ lea(rdx, monitor); // address of first monitor
duke@0 1124
never@307 1125 __ movptr(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
never@307 1126 __ testptr(t, t);
duke@0 1127 __ jcc(Assembler::notZero, unlock);
duke@0 1128
duke@0 1129 // Entry already unlocked, need to throw exception
duke@0 1130 __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
duke@0 1131 __ should_not_reach_here();
duke@0 1132
duke@0 1133 __ bind(unlock);
duke@0 1134 __ unlock_object(rdx);
duke@0 1135 }
duke@0 1136 __ bind(L);
duke@0 1137 }
duke@0 1138
duke@0 1139 // jvmti/dtrace support
duke@0 1140 // Note: This must happen _after_ handling/throwing any exceptions since
duke@0 1141 // the exception handler code notifies the runtime of method exits
duke@0 1142 // too. If this happens before, method entry/exit notifications are
duke@0 1143 // not properly paired (was bug - gri 11/22/99).
duke@0 1144 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
duke@0 1145
duke@0 1146 // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
duke@0 1147 __ pop(ltos);
never@307 1148 __ movptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
duke@0 1149 __ call(t);
duke@0 1150
duke@0 1151 // remove activation
never@307 1152 __ movptr(t, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
duke@0 1153 __ leave(); // remove frame anchor
never@307 1154 __ pop(rdi); // get return address
never@307 1155 __ mov(rsp, t); // set sp to sender sp
duke@0 1156 __ jmp(rdi);
duke@0 1157
duke@0 1158 if (inc_counter) {
duke@0 1159 // Handle overflow of counter and compile method
duke@0 1160 __ bind(invocation_counter_overflow);
duke@0 1161 generate_counter_overflow(&continue_after_compile);
duke@0 1162 }
duke@0 1163
duke@0 1164 return entry_point;
duke@0 1165 }
duke@0 1166
duke@0 1167 //
duke@0 1168 // Generic interpreted method entry to (asm) interpreter
duke@0 1169 //
duke@0 1170 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
duke@0 1171 // determine code generation flags
duke@0 1172 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 1173
duke@0 1174 // rbx,: methodOop
duke@0 1175 // rsi: sender sp
duke@0 1176 address entry_point = __ pc();
duke@0 1177
duke@0 1178
duke@0 1179 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
duke@0 1180 const Address size_of_locals (rbx, methodOopDesc::size_of_locals_offset());
duke@0 1181 const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
duke@0 1182 const Address access_flags (rbx, methodOopDesc::access_flags_offset());
duke@0 1183
duke@0 1184 // get parameter size (always needed)
jrose@660 1185 __ load_unsigned_short(rcx, size_of_parameters);
duke@0 1186
duke@0 1187 // rbx,: methodOop
duke@0 1188 // rcx: size of parameters
duke@0 1189
duke@0 1190 // rsi: sender_sp (could differ from sp+wordSize if we were called via c2i )
duke@0 1191
jrose@660 1192 __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
duke@0 1193 __ subl(rdx, rcx); // rdx = no. of additional locals
duke@0 1194
duke@0 1195 // see if we've got enough room on the stack for locals plus overhead.
duke@0 1196 generate_stack_overflow_check();
duke@0 1197
duke@0 1198 // get return address
never@307 1199 __ pop(rax);
duke@0 1200
duke@0 1201 // compute beginning of parameters (rdi)
never@307 1202 __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
duke@0 1203
duke@0 1204 // rdx - # of additional locals
duke@0 1205 // allocate space for locals
duke@0 1206 // explicitly initialize locals
duke@0 1207 {
duke@0 1208 Label exit, loop;
duke@0 1209 __ testl(rdx, rdx);
duke@0 1210 __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
duke@0 1211 __ bind(loop);
never@307 1212 if (TaggedStackInterpreter) {
never@307 1213 __ push((int32_t)NULL_WORD); // push tag
never@307 1214 }
never@307 1215 __ push((int32_t)NULL_WORD); // initialize local variables
duke@0 1216 __ decrement(rdx); // until everything initialized
duke@0 1217 __ jcc(Assembler::greater, loop);
duke@0 1218 __ bind(exit);
duke@0 1219 }
duke@0 1220
duke@0 1221 if (inc_counter) __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
duke@0 1222 // initialize fixed part of activation frame
duke@0 1223 generate_fixed_frame(false);
duke@0 1224
duke@0 1225 // make sure method is not native & not abstract
duke@0 1226 #ifdef ASSERT
duke@0 1227 __ movl(rax, access_flags);
duke@0 1228 {
duke@0 1229 Label L;
duke@0 1230 __ testl(rax, JVM_ACC_NATIVE);
duke@0 1231 __ jcc(Assembler::zero, L);
duke@0 1232 __ stop("tried to execute native method as non-native");
duke@0 1233 __ bind(L);
duke@0 1234 }
duke@0 1235 { Label L;
duke@0 1236 __ testl(rax, JVM_ACC_ABSTRACT);
duke@0 1237 __ jcc(Assembler::zero, L);
duke@0 1238 __ stop("tried to execute abstract method in interpreter");
duke@0 1239 __ bind(L);
duke@0 1240 }
duke@0 1241 #endif
duke@0 1242
duke@0 1243 // Since at this point in the method invocation the exception handler
duke@0 1244 // would try to exit the monitor of synchronized methods which hasn't
duke@0 1245 // been entered yet, we set the thread local variable
duke@0 1246 // _do_not_unlock_if_synchronized to true. The remove_activation will
duke@0 1247 // check this flag.
duke@0 1248
duke@0 1249 __ get_thread(rax);
duke@0 1250 const Address do_not_unlock_if_synchronized(rax,
duke@0 1251 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
duke@0 1252 __ movbool(do_not_unlock_if_synchronized, true);
duke@0 1253
duke@0 1254 // increment invocation count & check for overflow
duke@0 1255 Label invocation_counter_overflow;
duke@0 1256 Label profile_method;
duke@0 1257 Label profile_method_continue;
duke@0 1258 if (inc_counter) {
duke@0 1259 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue);
duke@0 1260 if (ProfileInterpreter) {
duke@0 1261 __ bind(profile_method_continue);
duke@0 1262 }
duke@0 1263 }
duke@0 1264 Label continue_after_compile;
duke@0 1265 __ bind(continue_after_compile);
duke@0 1266
duke@0 1267 bang_stack_shadow_pages(false);
duke@0 1268
duke@0 1269 // reset the _do_not_unlock_if_synchronized flag
duke@0 1270 __ get_thread(rax);
duke@0 1271 __ movbool(do_not_unlock_if_synchronized, false);
duke@0 1272
duke@0 1273 // check for synchronized methods
duke@0 1274 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 1275 // so method is not locked if overflows.
duke@0 1276 //
duke@0 1277 if (synchronized) {
duke@0 1278 // Allocate monitor and lock method
duke@0 1279 lock_method();
duke@0 1280 } else {
duke@0 1281 // no synchronization necessary
duke@0 1282 #ifdef ASSERT
duke@0 1283 { Label L;
duke@0 1284 __ movl(rax, access_flags);
duke@0 1285 __ testl(rax, JVM_ACC_SYNCHRONIZED);
duke@0 1286 __ jcc(Assembler::zero, L);
duke@0 1287 __ stop("method needs synchronization");
duke@0 1288 __ bind(L);
duke@0 1289 }
duke@0 1290 #endif
duke@0 1291 }
duke@0 1292
duke@0 1293 // start execution
duke@0 1294 #ifdef ASSERT
duke@0 1295 { Label L;
duke@0 1296 const Address monitor_block_top (rbp,
duke@0 1297 frame::interpreter_frame_monitor_block_top_offset * wordSize);
never@307 1298 __ movptr(rax, monitor_block_top);
never@307 1299 __ cmpptr(rax, rsp);
duke@0 1300 __ jcc(Assembler::equal, L);
duke@0 1301 __ stop("broken stack frame setup in interpreter");
duke@0 1302 __ bind(L);
duke@0 1303 }
duke@0 1304 #endif
duke@0 1305
duke@0 1306 // jvmti support
duke@0 1307 __ notify_method_entry();
duke@0 1308
duke@0 1309 __ dispatch_next(vtos);
duke@0 1310
duke@0 1311 // invocation counter overflow
duke@0 1312 if (inc_counter) {
duke@0 1313 if (ProfileInterpreter) {
duke@0 1314 // We have decided to profile this method in the interpreter
duke@0 1315 __ bind(profile_method);
duke@0 1316
duke@0 1317 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method), rsi, true);
duke@0 1318
never@307 1319 __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
never@307 1320 __ movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
never@307 1321 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax);
duke@0 1322 __ test_method_data_pointer(rax, profile_method_continue);
never@307 1323 __ addptr(rax, in_bytes(methodDataOopDesc::data_offset()));
never@307 1324 __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax);
duke@0 1325 __ jmp(profile_method_continue);
duke@0 1326 }
duke@0 1327 // Handle overflow of counter and compile method
duke@0 1328 __ bind(invocation_counter_overflow);
duke@0 1329 generate_counter_overflow(&continue_after_compile);
duke@0 1330 }
duke@0 1331
duke@0 1332 return entry_point;
duke@0 1333 }
duke@0 1334
duke@0 1335 //------------------------------------------------------------------------------------------------------------------------
duke@0 1336 // Entry points
duke@0 1337 //
duke@0 1338 // Here we generate the various kind of entries into the interpreter.
duke@0 1339 // The two main entry type are generic bytecode methods and native call method.
duke@0 1340 // These both come in synchronized and non-synchronized versions but the
duke@0 1341 // frame layout they create is very similar. The other method entry
duke@0 1342 // types are really just special purpose entries that are really entry
duke@0 1343 // and interpretation all in one. These are for trivial methods like
duke@0 1344 // accessor, empty, or special math methods.
duke@0 1345 //
duke@0 1346 // When control flow reaches any of the entry types for the interpreter
duke@0 1347 // the following holds ->
duke@0 1348 //
duke@0 1349 // Arguments:
duke@0 1350 //
duke@0 1351 // rbx,: methodOop
duke@0 1352 // rcx: receiver
duke@0 1353 //
duke@0 1354 //
duke@0 1355 // Stack layout immediately at entry
duke@0 1356 //
duke@0 1357 // [ return address ] <--- rsp
duke@0 1358 // [ parameter n ]
duke@0 1359 // ...
duke@0 1360 // [ parameter 1 ]
duke@0 1361 // [ expression stack ] (caller's java expression stack)
duke@0 1362
duke@0 1363 // Assuming that we don't go to one of the trivial specialized
duke@0 1364 // entries the stack will look like below when we are ready to execute
duke@0 1365 // the first bytecode (or call the native routine). The register usage
duke@0 1366 // will be as the template based interpreter expects (see interpreter_x86.hpp).
duke@0 1367 //
duke@0 1368 // local variables follow incoming parameters immediately; i.e.
duke@0 1369 // the return address is moved to the end of the locals).
duke@0 1370 //
duke@0 1371 // [ monitor entry ] <--- rsp
duke@0 1372 // ...
duke@0 1373 // [ monitor entry ]
duke@0 1374 // [ expr. stack bottom ]
duke@0 1375 // [ saved rsi ]
duke@0 1376 // [ current rdi ]
duke@0 1377 // [ methodOop ]
duke@0 1378 // [ saved rbp, ] <--- rbp,
duke@0 1379 // [ return address ]
duke@0 1380 // [ local variable m ]
duke@0 1381 // ...
duke@0 1382 // [ local variable 1 ]
duke@0 1383 // [ parameter n ]
duke@0 1384 // ...
duke@0 1385 // [ parameter 1 ] <--- rdi
duke@0 1386
duke@0 1387 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
duke@0 1388 // determine code generation flags
duke@0 1389 bool synchronized = false;
duke@0 1390 address entry_point = NULL;
duke@0 1391
duke@0 1392 switch (kind) {
duke@0 1393 case Interpreter::zerolocals : break;
duke@0 1394 case Interpreter::zerolocals_synchronized: synchronized = true; break;
duke@0 1395 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
duke@0 1396 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
duke@0 1397 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
duke@0 1398 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
duke@0 1399 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
jrose@748 1400 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
duke@0 1401
duke@0 1402 case Interpreter::java_lang_math_sin : // fall thru
duke@0 1403 case Interpreter::java_lang_math_cos : // fall thru
duke@0 1404 case Interpreter::java_lang_math_tan : // fall thru
duke@0 1405 case Interpreter::java_lang_math_abs : // fall thru
duke@0 1406 case Interpreter::java_lang_math_log : // fall thru
duke@0 1407 case Interpreter::java_lang_math_log10 : // fall thru
duke@0 1408 case Interpreter::java_lang_math_sqrt : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
duke@0 1409 default : ShouldNotReachHere(); break;
duke@0 1410 }
duke@0 1411
duke@0 1412 if (entry_point) return entry_point;
duke@0 1413
duke@0 1414 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
duke@0 1415
duke@0 1416 }
duke@0 1417
duke@0 1418 // How much stack a method activation needs in words.
duke@0 1419 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
duke@0 1420
duke@0 1421 const int stub_code = 4; // see generate_call_stub
duke@0 1422 // Save space for one monitor to get into the interpreted method in case
duke@0 1423 // the method is synchronized
duke@0 1424 int monitor_size = method->is_synchronized() ?
duke@0 1425 1*frame::interpreter_frame_monitor_size() : 0;
duke@0 1426
duke@0 1427 // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
duke@0 1428 // be sure to change this if you add/subtract anything to/from the overhead area
duke@0 1429 const int overhead_size = -frame::interpreter_frame_initial_sp_offset;
duke@0 1430
jrose@748 1431 const int extra_stack = methodOopDesc::extra_stack_entries();
jrose@748 1432 const int method_stack = (method->max_locals() + method->max_stack() + extra_stack) *
duke@0 1433 Interpreter::stackElementWords();
duke@0 1434 return overhead_size + method_stack + stub_code;
duke@0 1435 }
duke@0 1436
duke@0 1437 // asm based interpreter deoptimization helpers
duke@0 1438
duke@0 1439 int AbstractInterpreter::layout_activation(methodOop method,
duke@0 1440 int tempcount,
duke@0 1441 int popframe_extra_args,
duke@0 1442 int moncount,
duke@0 1443 int callee_param_count,
duke@0 1444 int callee_locals,
duke@0 1445 frame* caller,
duke@0 1446 frame* interpreter_frame,
duke@0 1447 bool is_top_frame) {
duke@0 1448 // Note: This calculation must exactly parallel the frame setup
duke@0 1449 // in AbstractInterpreterGenerator::generate_method_entry.
duke@0 1450 // If interpreter_frame!=NULL, set up the method, locals, and monitors.
duke@0 1451 // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
duke@0 1452 // as determined by a previous call to this method.
duke@0 1453 // It is also guaranteed to be walkable even though it is in a skeletal state
duke@0 1454 // NOTE: return size is in words not bytes
duke@0 1455
duke@0 1456 // fixed size of an interpreter frame:
duke@0 1457 int max_locals = method->max_locals() * Interpreter::stackElementWords();
duke@0 1458 int extra_locals = (method->max_locals() - method->size_of_parameters()) *
duke@0 1459 Interpreter::stackElementWords();
duke@0 1460
duke@0 1461 int overhead = frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset;
duke@0 1462
duke@0 1463 // Our locals were accounted for by the caller (or last_frame_adjust on the transistion)
duke@0 1464 // Since the callee parameters already account for the callee's params we only need to account for
duke@0 1465 // the extra locals.
duke@0 1466
duke@0 1467
duke@0 1468 int size = overhead +
duke@0 1469 ((callee_locals - callee_param_count)*Interpreter::stackElementWords()) +
duke@0 1470 (moncount*frame::interpreter_frame_monitor_size()) +
duke@0 1471 tempcount*Interpreter::stackElementWords() + popframe_extra_args;
duke@0 1472
duke@0 1473 if (interpreter_frame != NULL) {
duke@0 1474 #ifdef ASSERT
duke@0 1475 assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
duke@0 1476 assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
duke@0 1477 #endif
duke@0 1478
duke@0 1479 interpreter_frame->interpreter_frame_set_method(method);
duke@0 1480 // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
duke@0 1481 // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
duke@0 1482 // and sender_sp is fp+8
duke@0 1483 intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
duke@0 1484
duke@0 1485 interpreter_frame->interpreter_frame_set_locals(locals);
duke@0 1486 BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
duke@0 1487 BasicObjectLock* monbot = montop - moncount;
duke@0 1488 interpreter_frame->interpreter_frame_set_monitor_end(monbot);
duke@0 1489
duke@0 1490 // Set last_sp
duke@0 1491 intptr_t* rsp = (intptr_t*) monbot -
duke@0 1492 tempcount*Interpreter::stackElementWords() -
duke@0 1493 popframe_extra_args;
duke@0 1494 interpreter_frame->interpreter_frame_set_last_sp(rsp);
duke@0 1495
duke@0 1496 // All frames but the initial (oldest) interpreter frame we fill in have a
duke@0 1497 // value for sender_sp that allows walking the stack but isn't
duke@0 1498 // truly correct. Correct the value here.
duke@0 1499
duke@0 1500 if (extra_locals != 0 &&
duke@0 1501 interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
duke@0 1502 interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
duke@0 1503 }
duke@0 1504 *interpreter_frame->interpreter_frame_cache_addr() =
duke@0 1505 method->constants()->cache();
duke@0 1506 }
duke@0 1507 return size;
duke@0 1508 }
duke@0 1509
duke@0 1510
duke@0 1511 //------------------------------------------------------------------------------------------------------------------------
duke@0 1512 // Exceptions
duke@0 1513
duke@0 1514 void TemplateInterpreterGenerator::generate_throw_exception() {
duke@0 1515 // Entry point in previous activation (i.e., if the caller was interpreted)
duke@0 1516 Interpreter::_rethrow_exception_entry = __ pc();
duke@0 1517
duke@0 1518 // Restore sp to interpreter_frame_last_sp even though we are going
duke@0 1519 // to empty the expression stack for the exception processing.
xlu@520 1520 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 1521 // rax,: exception
duke@0 1522 // rdx: return address/pc that threw exception
duke@0 1523 __ restore_bcp(); // rsi points to call/send
duke@0 1524 __ restore_locals();
duke@0 1525
duke@0 1526 // Entry point for exceptions thrown within interpreter code
duke@0 1527 Interpreter::_throw_exception_entry = __ pc();
duke@0 1528 // expression stack is undefined here
duke@0 1529 // rax,: exception
duke@0 1530 // rsi: exception bcp
duke@0 1531 __ verify_oop(rax);
duke@0 1532
duke@0 1533 // expression stack must be empty before entering the VM in case of an exception
duke@0 1534 __ empty_expression_stack();
duke@0 1535 __ empty_FPU_stack();
duke@0 1536 // find exception handler address and preserve exception oop
duke@0 1537 __ call_VM(rdx, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), rax);
duke@0 1538 // rax,: exception handler entry point
duke@0 1539 // rdx: preserved exception oop
duke@0 1540 // rsi: bcp for exception handler
duke@0 1541 __ push_ptr(rdx); // push exception which is now the only value on the stack
duke@0 1542 __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!)
duke@0 1543
duke@0 1544 // If the exception is not handled in the current frame the frame is removed and
duke@0 1545 // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
duke@0 1546 //
duke@0 1547 // Note: At this point the bci is still the bxi for the instruction which caused
duke@0 1548 // the exception and the expression stack is empty. Thus, for any VM calls
duke@0 1549 // at this point, GC will find a legal oop map (with empty expression stack).
duke@0 1550
duke@0 1551 // In current activation
duke@0 1552 // tos: exception
duke@0 1553 // rsi: exception bcp
duke@0 1554
duke@0 1555 //
duke@0 1556 // JVMTI PopFrame support
duke@0 1557 //
duke@0 1558
duke@0 1559 Interpreter::_remove_activation_preserving_args_entry = __ pc();
duke@0 1560 __ empty_expression_stack();
duke@0 1561 __ empty_FPU_stack();
duke@0 1562 // Set the popframe_processing bit in pending_popframe_condition indicating that we are
duke@0 1563 // currently handling popframe, so that call_VMs that may happen later do not trigger new
duke@0 1564 // popframe handling cycles.
duke@0 1565 __ get_thread(rcx);
duke@0 1566 __ movl(rdx, Address(rcx, JavaThread::popframe_condition_offset()));
duke@0 1567 __ orl(rdx, JavaThread::popframe_processing_bit);
duke@0 1568 __ movl(Address(rcx, JavaThread::popframe_condition_offset()), rdx);
duke@0 1569
duke@0 1570 {
duke@0 1571 // Check to see whether we are returning to a deoptimized frame.
duke@0 1572 // (The PopFrame call ensures that the caller of the popped frame is
duke@0 1573 // either interpreted or compiled and deoptimizes it if compiled.)
duke@0 1574 // In this case, we can't call dispatch_next() after the frame is
duke@0 1575 // popped, but instead must save the incoming arguments and restore
duke@0 1576 // them after deoptimization has occurred.
duke@0 1577 //
duke@0 1578 // Note that we don't compare the return PC against the
duke@0 1579 // deoptimization blob's unpack entry because of the presence of
duke@0 1580 // adapter frames in C2.
duke@0 1581 Label caller_not_deoptimized;
never@307 1582 __ movptr(rdx, Address(rbp, frame::return_addr_offset * wordSize));
duke@0 1583 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), rdx);
duke@0 1584 __ testl(rax, rax);
duke@0 1585 __ jcc(Assembler::notZero, caller_not_deoptimized);
duke@0 1586
duke@0 1587 // Compute size of arguments for saving when returning to deoptimized caller
duke@0 1588 __ get_method(rax);
duke@0 1589 __ verify_oop(rax);
jrose@660 1590 __ load_unsigned_short(rax, Address(rax, in_bytes(methodOopDesc::size_of_parameters_offset())));
never@307 1591 __ shlptr(rax, Interpreter::logStackElementSize());
duke@0 1592 __ restore_locals();
never@307 1593 __ subptr(rdi, rax);
never@307 1594 __ addptr(rdi, wordSize);
duke@0 1595 // Save these arguments
duke@0 1596 __ get_thread(rcx);
duke@0 1597 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), rcx, rax, rdi);
duke@0 1598
duke@0 1599 __ remove_activation(vtos, rdx,
duke@0 1600 /* throw_monitor_exception */ false,
duke@0 1601 /* install_monitor_exception */ false,
duke@0 1602 /* notify_jvmdi */ false);
duke@0 1603
duke@0 1604 // Inform deoptimization that it is responsible for restoring these arguments
duke@0 1605 __ get_thread(rcx);
duke@0 1606 __ movl(Address(rcx, JavaThread::popframe_condition_offset()), JavaThread::popframe_force_deopt_reexecution_bit);
duke@0 1607
duke@0 1608 // Continue in deoptimization handler
duke@0 1609 __ jmp(rdx);
duke@0 1610
duke@0 1611 __ bind(caller_not_deoptimized);
duke@0 1612 }
duke@0 1613
duke@0 1614 __ remove_activation(vtos, rdx,
duke@0 1615 /* throw_monitor_exception */ false,
duke@0 1616 /* install_monitor_exception */ false,
duke@0 1617 /* notify_jvmdi */ false);
duke@0 1618
duke@0 1619 // Finish with popframe handling
duke@0 1620 // A previous I2C followed by a deoptimization might have moved the
duke@0 1621 // outgoing arguments further up the stack. PopFrame expects the
duke@0 1622 // mutations to those outgoing arguments to be preserved and other
duke@0 1623 // constraints basically require this frame to look exactly as
duke@0 1624 // though it had previously invoked an interpreted activation with
duke@0 1625 // no space between the top of the expression stack (current
duke@0 1626 // last_sp) and the top of stack. Rather than force deopt to
duke@0 1627 // maintain this kind of invariant all the time we call a small
duke@0 1628 // fixup routine to move the mutated arguments onto the top of our
duke@0 1629 // expression stack if necessary.
never@307 1630 __ mov(rax, rsp);
never@307 1631 __ movptr(rbx, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
duke@0 1632 __ get_thread(rcx);
duke@0 1633 // PC must point into interpreter here
duke@0 1634 __ set_last_Java_frame(rcx, noreg, rbp, __ pc());
duke@0 1635 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), rcx, rax, rbx);
duke@0 1636 __ get_thread(rcx);
duke@0 1637 __ reset_last_Java_frame(rcx, true, true);
duke@0 1638 // Restore the last_sp and null it out
never@307 1639 __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
xlu@520 1640 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
duke@0 1641
duke@0 1642 __ restore_bcp();
duke@0 1643 __ restore_locals();
duke@0 1644 // The method data pointer was incremented already during
duke@0 1645 // call profiling. We have to restore the mdp for the current bcp.
duke@0 1646 if (ProfileInterpreter) {
duke@0 1647 __ set_method_data_pointer_for_bcp();
duke@0 1648 }
duke@0 1649
duke@0 1650 // Clear the popframe condition flag
duke@0 1651 __ get_thread(rcx);
duke@0 1652 __ movl(Address(rcx, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive);
duke@0 1653
duke@0 1654 __ dispatch_next(vtos);
duke@0 1655 // end of PopFrame support
duke@0 1656
duke@0 1657 Interpreter::_remove_activation_entry = __ pc();
duke@0 1658
duke@0 1659 // preserve exception over this code sequence
duke@0 1660 __ pop_ptr(rax);
duke@0 1661 __ get_thread(rcx);
never@307 1662 __ movptr(Address(rcx, JavaThread::vm_result_offset()), rax);
duke@0 1663 // remove the activation (without doing throws on illegalMonitorExceptions)
duke@0 1664 __ remove_activation(vtos, rdx, false, true, false);
duke@0 1665 // restore exception
duke@0 1666 __ get_thread(rcx);
never@307 1667 __ movptr(rax, Address(rcx, JavaThread::vm_result_offset()));
xlu@520 1668 __ movptr(Address(rcx, JavaThread::vm_result_offset()), NULL_WORD);
duke@0 1669 __ verify_oop(rax);
duke@0 1670
duke@0 1671 // Inbetween activations - previous activation type unknown yet
duke@0 1672 // compute continuation point - the continuation point expects
duke@0 1673 // the following registers set up:
duke@0 1674 //
duke@0 1675 // rax,: exception
duke@0 1676 // rdx: return address/pc that threw exception
duke@0 1677 // rsp: expression stack of caller
duke@0 1678 // rbp,: rbp, of caller
never@307 1679 __ push(rax); // save exception
never@307 1680 __ push(rdx); // save return address
duke@0 1681 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), rdx);
never@307 1682 __ mov(rbx, rax); // save exception handler
never@307 1683 __ pop(rdx); // restore return address
never@307 1684 __ pop(rax); // restore exception
duke@0 1685 // Note that an "issuing PC" is actually the next PC after the call
duke@0 1686 __ jmp(rbx); // jump to exception handler of caller
duke@0 1687 }
duke@0 1688
duke@0 1689
duke@0 1690 //
duke@0 1691 // JVMTI ForceEarlyReturn support
duke@0 1692 //
duke@0 1693 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
duke@0 1694 address entry = __ pc();
duke@0 1695
duke@0 1696 __ restore_bcp();
duke@0 1697 __ restore_locals();
duke@0 1698 __ empty_expression_stack();
duke@0 1699 __ empty_FPU_stack();
duke@0 1700 __ load_earlyret_value(state);
duke@0 1701
duke@0 1702 __ get_thread(rcx);
never@307 1703 __ movptr(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset()));
duke@0 1704 const Address cond_addr(rcx, JvmtiThreadState::earlyret_state_offset());
duke@0 1705
duke@0 1706 // Clear the earlyret state
duke@0 1707 __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
duke@0 1708
duke@0 1709 __ remove_activation(state, rsi,
duke@0 1710 false, /* throw_monitor_exception */
duke@0 1711 false, /* install_monitor_exception */
duke@0 1712 true); /* notify_jvmdi */
duke@0 1713 __ jmp(rsi);
duke@0 1714 return entry;
duke@0 1715 } // end of ForceEarlyReturn support
duke@0 1716
duke@0 1717
duke@0 1718 //------------------------------------------------------------------------------------------------------------------------
duke@0 1719 // Helper for vtos entry point generation
duke@0 1720
duke@0 1721 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
duke@0 1722 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
duke@0 1723 Label L;
duke@0 1724 fep = __ pc(); __ push(ftos); __ jmp(L);
duke@0 1725 dep = __ pc(); __ push(dtos); __ jmp(L);
duke@0 1726 lep = __ pc(); __ push(ltos); __ jmp(L);
duke@0 1727 aep = __ pc(); __ push(atos); __ jmp(L);
duke@0 1728 bep = cep = sep = // fall through
duke@0 1729 iep = __ pc(); __ push(itos); // fall through
duke@0 1730 vep = __ pc(); __ bind(L); // fall through
duke@0 1731 generate_and_dispatch(t);
duke@0 1732 }
duke@0 1733
duke@0 1734 //------------------------------------------------------------------------------------------------------------------------
duke@0 1735 // Generation of individual instructions
duke@0 1736
duke@0 1737 // helpers for generate_and_dispatch
duke@0 1738
duke@0 1739
duke@0 1740
duke@0 1741 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
duke@0 1742 : TemplateInterpreterGenerator(code) {
duke@0 1743 generate_all(); // down here so it can be "virtual"
duke@0 1744 }
duke@0 1745
duke@0 1746 //------------------------------------------------------------------------------------------------------------------------
duke@0 1747
duke@0 1748 // Non-product code
duke@0 1749 #ifndef PRODUCT
duke@0 1750 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
duke@0 1751 address entry = __ pc();
duke@0 1752
duke@0 1753 // prepare expression stack
never@307 1754 __ pop(rcx); // pop return address so expression stack is 'pure'
duke@0 1755 __ push(state); // save tosca
duke@0 1756
duke@0 1757 // pass tosca registers as arguments & call tracer
duke@0 1758 __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), rcx, rax, rdx);
never@307 1759 __ mov(rcx, rax); // make sure return address is not destroyed by pop(state)
duke@0 1760 __ pop(state); // restore tosca
duke@0 1761
duke@0 1762 // return
duke@0 1763 __ jmp(rcx);
duke@0 1764
duke@0 1765 return entry;
duke@0 1766 }
duke@0 1767
duke@0 1768
duke@0 1769 void TemplateInterpreterGenerator::count_bytecode() {
never@307 1770 __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
duke@0 1771 }
duke@0 1772
duke@0 1773
duke@0 1774 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
never@307 1775 __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
duke@0 1776 }
duke@0 1777
duke@0 1778
duke@0 1779 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
duke@0 1780 __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
duke@0 1781 __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
duke@0 1782 __ orl(rbx, ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
duke@0 1783 ExternalAddress table((address) BytecodePairHistogram::_counters);
duke@0 1784 Address index(noreg, rbx, Address::times_4);
never@307 1785 __ incrementl(ArrayAddress(table, index));
duke@0 1786 }
duke@0 1787
duke@0 1788
duke@0 1789 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
duke@0 1790 // Call a little run-time stub to avoid blow-up for each bytecode.
duke@0 1791 // The run-time runtime saves the right registers, depending on
duke@0 1792 // the tosca in-state for the given template.
duke@0 1793 assert(Interpreter::trace_code(t->tos_in()) != NULL,
duke@0 1794 "entry must have been generated");
duke@0 1795 __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
duke@0 1796 }
duke@0 1797
duke@0 1798
duke@0 1799 void TemplateInterpreterGenerator::stop_interpreter_at() {
duke@0 1800 Label L;
duke@0 1801 __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
duke@0 1802 StopInterpreterAt);
duke@0 1803 __ jcc(Assembler::notEqual, L);
duke@0 1804 __ int3();
duke@0 1805 __ bind(L);
duke@0 1806 }
duke@0 1807 #endif // !PRODUCT
duke@0 1808 #endif // CC_INTERP