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