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