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