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