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