1 /* 2 * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "classfile/javaClasses.hpp" 29 #include "compiler/compiler_globals.hpp" 30 #include "gc/shared/barrierSetAssembler.hpp" 31 #include "interpreter/bytecodeHistogram.hpp" 32 #include "interpreter/interpreter.hpp" 33 #include "interpreter/interpreterRuntime.hpp" 34 #include "interpreter/interp_masm.hpp" 35 #include "interpreter/templateInterpreterGenerator.hpp" 36 #include "interpreter/templateTable.hpp" 37 #include "interpreter/bytecodeTracer.hpp" 38 #include "memory/resourceArea.hpp" 39 #include "oops/arrayOop.hpp" 40 #include "oops/method.hpp" 41 #include "oops/methodCounters.hpp" 42 #include "oops/methodData.hpp" 43 #include "oops/oop.inline.hpp" 44 #include "oops/inlineKlass.hpp" 45 #include "oops/resolvedIndyEntry.hpp" 46 #include "oops/resolvedMethodEntry.hpp" 47 #include "prims/jvmtiExport.hpp" 48 #include "prims/jvmtiThreadState.hpp" 49 #include "runtime/arguments.hpp" 50 #include "runtime/deoptimization.hpp" 51 #include "runtime/frame.inline.hpp" 52 #include "runtime/globals.hpp" 53 #include "runtime/jniHandles.hpp" 54 #include "runtime/sharedRuntime.hpp" 55 #include "runtime/stubRoutines.hpp" 56 #include "runtime/synchronizer.hpp" 57 #include "runtime/timer.hpp" 58 #include "runtime/vframeArray.hpp" 59 #include "utilities/checkedCast.hpp" 60 #include "utilities/debug.hpp" 61 #include "utilities/powerOfTwo.hpp" 62 #include <sys/types.h> 63 64 // Size of interpreter code. Increase if too small. Interpreter will 65 // fail with a guarantee ("not enough space for interpreter generation"); 66 // if too small. 67 // Run with +PrintInterpreter to get the VM to print out the size. 68 // Max size with JVMTI 69 int TemplateInterpreter::InterpreterCodeSize = 200 * 1024; 70 71 #define __ _masm-> 72 73 //----------------------------------------------------------------------------- 74 75 extern "C" void entry(CodeBuffer*); 76 77 //----------------------------------------------------------------------------- 78 79 address TemplateInterpreterGenerator::generate_slow_signature_handler() { 80 address entry = __ pc(); 81 82 __ andr(esp, esp, -16); 83 __ mov(c_rarg3, esp); 84 // rmethod 85 // rlocals 86 // c_rarg3: first stack arg - wordSize 87 88 // adjust sp 89 __ sub(sp, c_rarg3, 18 * wordSize); 90 __ str(lr, Address(__ pre(sp, -2 * wordSize))); 91 __ call_VM(noreg, 92 CAST_FROM_FN_PTR(address, 93 InterpreterRuntime::slow_signature_handler), 94 rmethod, rlocals, c_rarg3); 95 96 // r0: result handler 97 98 // Stack layout: 99 // rsp: return address <- sp 100 // 1 garbage 101 // 8 integer args (if static first is unused) 102 // 1 float/double identifiers 103 // 8 double args 104 // stack args <- esp 105 // garbage 106 // expression stack bottom 107 // bcp (null) 108 // ... 109 110 // Restore LR 111 __ ldr(lr, Address(__ post(sp, 2 * wordSize))); 112 113 // Do FP first so we can use c_rarg3 as temp 114 __ ldrw(c_rarg3, Address(sp, 9 * wordSize)); // float/double identifiers 115 116 for (int i = 0; i < Argument::n_float_register_parameters_c; i++) { 117 const FloatRegister r = as_FloatRegister(i); 118 119 Label d, done; 120 121 __ tbnz(c_rarg3, i, d); 122 __ ldrs(r, Address(sp, (10 + i) * wordSize)); 123 __ b(done); 124 __ bind(d); 125 __ ldrd(r, Address(sp, (10 + i) * wordSize)); 126 __ bind(done); 127 } 128 129 // c_rarg0 contains the result from the call of 130 // InterpreterRuntime::slow_signature_handler so we don't touch it 131 // here. It will be loaded with the JNIEnv* later. 132 __ ldr(c_rarg1, Address(sp, 1 * wordSize)); 133 for (int i = c_rarg2->encoding(); i <= c_rarg7->encoding(); i += 2) { 134 Register rm = as_Register(i), rn = as_Register(i+1); 135 __ ldp(rm, rn, Address(sp, i * wordSize)); 136 } 137 138 __ add(sp, sp, 18 * wordSize); 139 __ ret(lr); 140 141 return entry; 142 } 143 144 145 // 146 // Various method entries 147 // 148 149 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 150 // rmethod: Method* 151 // r19_sender_sp: sender sp 152 // esp: args 153 154 // These don't need a safepoint check because they aren't virtually 155 // callable. We won't enter these intrinsics from compiled code. 156 // If in the future we added an intrinsic which was virtually callable 157 // we'd have to worry about how to safepoint so that this code is used. 158 159 // mathematical functions inlined by compiler 160 // (interpreter must provide identical implementation 161 // in order to avoid monotonicity bugs when switching 162 // from interpreter to compiler in the middle of some 163 // computation) 164 // 165 // stack: 166 // [ arg ] <-- esp 167 // [ arg ] 168 // retaddr in lr 169 170 address entry_point = nullptr; 171 Register continuation = lr; 172 switch (kind) { 173 case Interpreter::java_lang_math_abs: 174 entry_point = __ pc(); 175 __ ldrd(v0, Address(esp)); 176 __ fabsd(v0, v0); 177 __ mov(sp, r19_sender_sp); // Restore caller's SP 178 break; 179 case Interpreter::java_lang_math_sqrt: 180 entry_point = __ pc(); 181 __ ldrd(v0, Address(esp)); 182 __ fsqrtd(v0, v0); 183 __ mov(sp, r19_sender_sp); 184 break; 185 case Interpreter::java_lang_math_sin : 186 case Interpreter::java_lang_math_cos : 187 case Interpreter::java_lang_math_tan : 188 case Interpreter::java_lang_math_log : 189 case Interpreter::java_lang_math_log10 : 190 case Interpreter::java_lang_math_exp : 191 entry_point = __ pc(); 192 __ ldrd(v0, Address(esp)); 193 __ mov(sp, r19_sender_sp); 194 __ mov(r23, lr); 195 continuation = r23; // The first free callee-saved register 196 generate_transcendental_entry(kind, 1); 197 break; 198 case Interpreter::java_lang_math_pow : 199 entry_point = __ pc(); 200 __ mov(r23, lr); 201 continuation = r23; 202 __ ldrd(v0, Address(esp, 2 * Interpreter::stackElementSize)); 203 __ ldrd(v1, Address(esp)); 204 __ mov(sp, r19_sender_sp); 205 generate_transcendental_entry(kind, 2); 206 break; 207 case Interpreter::java_lang_math_fmaD : 208 if (UseFMA) { 209 entry_point = __ pc(); 210 __ ldrd(v0, Address(esp, 4 * Interpreter::stackElementSize)); 211 __ ldrd(v1, Address(esp, 2 * Interpreter::stackElementSize)); 212 __ ldrd(v2, Address(esp)); 213 __ fmaddd(v0, v0, v1, v2); 214 __ mov(sp, r19_sender_sp); // Restore caller's SP 215 } 216 break; 217 case Interpreter::java_lang_math_fmaF : 218 if (UseFMA) { 219 entry_point = __ pc(); 220 __ ldrs(v0, Address(esp, 2 * Interpreter::stackElementSize)); 221 __ ldrs(v1, Address(esp, Interpreter::stackElementSize)); 222 __ ldrs(v2, Address(esp)); 223 __ fmadds(v0, v0, v1, v2); 224 __ mov(sp, r19_sender_sp); // Restore caller's SP 225 } 226 break; 227 default: 228 ; 229 } 230 if (entry_point) { 231 __ br(continuation); 232 } 233 234 return entry_point; 235 } 236 237 // double trigonometrics and transcendentals 238 // static jdouble dsin(jdouble x); 239 // static jdouble dcos(jdouble x); 240 // static jdouble dtan(jdouble x); 241 // static jdouble dlog(jdouble x); 242 // static jdouble dlog10(jdouble x); 243 // static jdouble dexp(jdouble x); 244 // static jdouble dpow(jdouble x, jdouble y); 245 246 void TemplateInterpreterGenerator::generate_transcendental_entry(AbstractInterpreter::MethodKind kind, int fpargs) { 247 address fn; 248 switch (kind) { 249 case Interpreter::java_lang_math_sin : 250 if (StubRoutines::dsin() == nullptr) { 251 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); 252 } else { 253 fn = CAST_FROM_FN_PTR(address, StubRoutines::dsin()); 254 } 255 break; 256 case Interpreter::java_lang_math_cos : 257 if (StubRoutines::dcos() == nullptr) { 258 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); 259 } else { 260 fn = CAST_FROM_FN_PTR(address, StubRoutines::dcos()); 261 } 262 break; 263 case Interpreter::java_lang_math_tan : 264 if (StubRoutines::dtan() == nullptr) { 265 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); 266 } else { 267 fn = CAST_FROM_FN_PTR(address, StubRoutines::dtan()); 268 } 269 break; 270 case Interpreter::java_lang_math_log : 271 if (StubRoutines::dlog() == nullptr) { 272 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); 273 } else { 274 fn = CAST_FROM_FN_PTR(address, StubRoutines::dlog()); 275 } 276 break; 277 case Interpreter::java_lang_math_log10 : 278 if (StubRoutines::dlog10() == nullptr) { 279 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); 280 } else { 281 fn = CAST_FROM_FN_PTR(address, StubRoutines::dlog10()); 282 } 283 break; 284 case Interpreter::java_lang_math_exp : 285 if (StubRoutines::dexp() == nullptr) { 286 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); 287 } else { 288 fn = CAST_FROM_FN_PTR(address, StubRoutines::dexp()); 289 } 290 break; 291 case Interpreter::java_lang_math_pow : 292 if (StubRoutines::dpow() == nullptr) { 293 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 294 } else { 295 fn = CAST_FROM_FN_PTR(address, StubRoutines::dpow()); 296 } 297 break; 298 default: 299 ShouldNotReachHere(); 300 fn = nullptr; // unreachable 301 } 302 __ mov(rscratch1, fn); 303 __ blr(rscratch1); 304 } 305 306 address TemplateInterpreterGenerator::generate_Float_float16ToFloat_entry() { 307 assert(VM_Version::supports_float16(), "this intrinsic is not supported"); 308 // r19_sender_sp: sender sp 309 // stack: 310 // [ arg ] <-- esp 311 // [ arg ] 312 // retaddr in lr 313 // result in v0 314 315 address entry_point = __ pc(); 316 __ ldrw(c_rarg0, Address(esp)); 317 __ flt16_to_flt(v0, c_rarg0, v1); 318 __ mov(sp, r19_sender_sp); // Restore caller's SP 319 __ br(lr); 320 return entry_point; 321 } 322 323 address TemplateInterpreterGenerator::generate_Float_floatToFloat16_entry() { 324 assert(VM_Version::supports_float16(), "this intrinsic is not supported"); 325 // r19_sender_sp: sender sp 326 // stack: 327 // [ arg ] <-- esp 328 // [ arg ] 329 // retaddr in lr 330 // result in c_rarg0 331 332 address entry_point = __ pc(); 333 __ ldrs(v0, Address(esp)); 334 __ flt_to_flt16(c_rarg0, v0, v1); 335 __ mov(sp, r19_sender_sp); // Restore caller's SP 336 __ br(lr); 337 return entry_point; 338 } 339 340 // Abstract method entry 341 // Attempt to execute abstract method. Throw exception 342 address TemplateInterpreterGenerator::generate_abstract_entry(void) { 343 // rmethod: Method* 344 // r19_sender_sp: sender SP 345 346 address entry_point = __ pc(); 347 348 // abstract method entry 349 350 // pop return address, reset last_sp to null 351 __ empty_expression_stack(); 352 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed) 353 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 354 355 // throw exception 356 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 357 InterpreterRuntime::throw_AbstractMethodErrorWithMethod), 358 rmethod); 359 // the call_VM checks for exception, so we should never return here. 360 __ should_not_reach_here(); 361 362 return entry_point; 363 } 364 365 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 366 address entry = __ pc(); 367 368 #ifdef ASSERT 369 { 370 Label L; 371 __ ldr(rscratch1, Address(rfp, 372 frame::interpreter_frame_monitor_block_top_offset * 373 wordSize)); 374 __ lea(rscratch1, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 375 __ mov(rscratch2, sp); 376 __ cmp(rscratch1, rscratch2); // maximal rsp for current rfp (stack 377 // grows negative) 378 __ br(Assembler::HS, L); // check if frame is complete 379 __ stop ("interpreter frame not set up"); 380 __ bind(L); 381 } 382 #endif // ASSERT 383 // Restore bcp under the assumption that the current frame is still 384 // interpreted 385 __ restore_bcp(); 386 387 // expression stack must be empty before entering the VM if an 388 // exception happened 389 __ empty_expression_stack(); 390 // throw exception 391 __ call_VM(noreg, 392 CAST_FROM_FN_PTR(address, 393 InterpreterRuntime::throw_StackOverflowError)); 394 return entry; 395 } 396 397 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler() { 398 address entry = __ pc(); 399 // expression stack must be empty before entering the VM if an 400 // exception happened 401 __ empty_expression_stack(); 402 // setup parameters 403 404 // ??? convention: expect aberrant index in register r1 405 __ movw(c_rarg2, r1); 406 // ??? convention: expect array in register r3 407 __ mov(c_rarg1, r3); 408 __ call_VM(noreg, 409 CAST_FROM_FN_PTR(address, 410 InterpreterRuntime:: 411 throw_ArrayIndexOutOfBoundsException), 412 c_rarg1, c_rarg2); 413 return entry; 414 } 415 416 address TemplateInterpreterGenerator::generate_ClassCastException_handler() { 417 address entry = __ pc(); 418 419 // object is at TOS 420 __ pop(c_rarg1); 421 422 // expression stack must be empty before entering the VM if an 423 // exception happened 424 __ empty_expression_stack(); 425 426 __ call_VM(noreg, 427 CAST_FROM_FN_PTR(address, 428 InterpreterRuntime:: 429 throw_ClassCastException), 430 c_rarg1); 431 return entry; 432 } 433 434 address TemplateInterpreterGenerator::generate_exception_handler_common( 435 const char* name, const char* message, bool pass_oop) { 436 assert(!pass_oop || message == nullptr, "either oop or message but not both"); 437 address entry = __ pc(); 438 if (pass_oop) { 439 // object is at TOS 440 __ pop(c_rarg2); 441 } 442 // expression stack must be empty before entering the VM if an 443 // exception happened 444 __ empty_expression_stack(); 445 // setup parameters 446 __ lea(c_rarg1, Address((address)name)); 447 if (pass_oop) { 448 __ call_VM(r0, CAST_FROM_FN_PTR(address, 449 InterpreterRuntime:: 450 create_klass_exception), 451 c_rarg1, c_rarg2); 452 } else { 453 // kind of lame ExternalAddress can't take null because 454 // external_word_Relocation will assert. 455 if (message != nullptr) { 456 __ lea(c_rarg2, Address((address)message)); 457 } else { 458 __ mov(c_rarg2, NULL_WORD); 459 } 460 __ call_VM(r0, 461 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), 462 c_rarg1, c_rarg2); 463 } 464 // throw exception 465 __ b(address(Interpreter::throw_exception_entry())); 466 return entry; 467 } 468 469 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) { 470 address entry = __ pc(); 471 472 // Restore stack bottom in case i2c adjusted stack 473 __ ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 474 __ lea(esp, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 475 // and null it as marker that esp is now tos until next java call 476 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 477 478 if (state == atos && InlineTypeReturnedAsFields) { 479 __ store_inline_type_fields_to_buf(nullptr, true); 480 } 481 482 __ restore_bcp(); 483 __ restore_locals(); 484 __ restore_constant_pool_cache(); 485 __ get_method(rmethod); 486 487 if (state == atos) { 488 Register obj = r0; 489 Register mdp = r1; 490 Register tmp = r2; 491 __ profile_return_type(mdp, obj, tmp); 492 } 493 494 const Register cache = r1; 495 const Register index = r2; 496 497 if (index_size == sizeof(u4)) { 498 __ load_resolved_indy_entry(cache, index); 499 __ load_unsigned_short(cache, Address(cache, in_bytes(ResolvedIndyEntry::num_parameters_offset()))); 500 __ add(esp, esp, cache, Assembler::LSL, 3); 501 } else { 502 // Pop N words from the stack 503 assert(index_size == sizeof(u2), "Can only be u2"); 504 __ load_method_entry(cache, index); 505 __ load_unsigned_short(cache, Address(cache, in_bytes(ResolvedMethodEntry::num_parameters_offset()))); 506 __ add(esp, esp, cache, Assembler::LSL, 3); 507 } 508 509 // Restore machine SP 510 __ restore_sp_after_call(); 511 512 __ check_and_handle_popframe(rthread); 513 __ check_and_handle_earlyret(rthread); 514 515 __ get_dispatch(); 516 __ dispatch_next(state, step); 517 518 return entry; 519 } 520 521 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, 522 int step, 523 address continuation) { 524 address entry = __ pc(); 525 __ restore_bcp(); 526 __ restore_locals(); 527 __ restore_constant_pool_cache(); 528 __ get_method(rmethod); 529 __ get_dispatch(); 530 531 __ restore_sp_after_call(); // Restore SP to extended SP 532 533 // Restore expression stack pointer 534 __ ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 535 __ lea(esp, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 536 // null last_sp until next java call 537 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 538 539 #if INCLUDE_JVMCI 540 // Check if we need to take lock at entry of synchronized method. This can 541 // only occur on method entry so emit it only for vtos with step 0. 542 if (EnableJVMCI && state == vtos && step == 0) { 543 Label L; 544 __ ldrb(rscratch1, Address(rthread, JavaThread::pending_monitorenter_offset())); 545 __ cbz(rscratch1, L); 546 // Clear flag. 547 __ strb(zr, Address(rthread, JavaThread::pending_monitorenter_offset())); 548 // Take lock. 549 lock_method(); 550 __ bind(L); 551 } else { 552 #ifdef ASSERT 553 if (EnableJVMCI) { 554 Label L; 555 __ ldrb(rscratch1, Address(rthread, JavaThread::pending_monitorenter_offset())); 556 __ cbz(rscratch1, L); 557 __ stop("unexpected pending monitor in deopt entry"); 558 __ bind(L); 559 } 560 #endif 561 } 562 #endif 563 // handle exceptions 564 { 565 Label L; 566 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 567 __ cbz(rscratch1, L); 568 __ call_VM(noreg, 569 CAST_FROM_FN_PTR(address, 570 InterpreterRuntime::throw_pending_exception)); 571 __ should_not_reach_here(); 572 __ bind(L); 573 } 574 575 if (continuation == nullptr) { 576 __ dispatch_next(state, step); 577 } else { 578 __ jump_to_entry(continuation); 579 } 580 return entry; 581 } 582 583 address TemplateInterpreterGenerator::generate_result_handler_for( 584 BasicType type) { 585 address entry = __ pc(); 586 switch (type) { 587 case T_BOOLEAN: __ c2bool(r0); break; 588 case T_CHAR : __ uxth(r0, r0); break; 589 case T_BYTE : __ sxtb(r0, r0); break; 590 case T_SHORT : __ sxth(r0, r0); break; 591 case T_INT : __ uxtw(r0, r0); break; // FIXME: We almost certainly don't need this 592 case T_LONG : /* nothing to do */ break; 593 case T_VOID : /* nothing to do */ break; 594 case T_FLOAT : /* nothing to do */ break; 595 case T_DOUBLE : /* nothing to do */ break; 596 case T_OBJECT : 597 // retrieve result from frame 598 __ ldr(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize)); 599 // and verify it 600 __ verify_oop(r0); 601 break; 602 default : ShouldNotReachHere(); 603 } 604 __ ret(lr); // return from result handler 605 return entry; 606 } 607 608 address TemplateInterpreterGenerator::generate_safept_entry_for( 609 TosState state, 610 address runtime_entry) { 611 address entry = __ pc(); 612 __ push(state); 613 __ push_cont_fastpath(rthread); 614 __ call_VM(noreg, runtime_entry); 615 __ pop_cont_fastpath(rthread); 616 __ membar(Assembler::AnyAny); 617 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos)); 618 return entry; 619 } 620 621 // Helpers for commoning out cases in the various type of method entries. 622 // 623 624 625 // increment invocation count & check for overflow 626 // 627 // Note: checking for negative value instead of overflow 628 // so we have a 'sticky' overflow test 629 // 630 // rmethod: method 631 // 632 void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow) { 633 Label done; 634 // Note: In tiered we increment either counters in Method* or in MDO depending if we're profiling or not. 635 int increment = InvocationCounter::count_increment; 636 Label no_mdo; 637 if (ProfileInterpreter) { 638 // Are we profiling? 639 __ ldr(r0, Address(rmethod, Method::method_data_offset())); 640 __ cbz(r0, no_mdo); 641 // Increment counter in the MDO 642 const Address mdo_invocation_counter(r0, in_bytes(MethodData::invocation_counter_offset()) + 643 in_bytes(InvocationCounter::counter_offset())); 644 const Address mask(r0, in_bytes(MethodData::invoke_mask_offset())); 645 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rscratch1, rscratch2, false, Assembler::EQ, overflow); 646 __ b(done); 647 } 648 __ bind(no_mdo); 649 // Increment counter in MethodCounters 650 const Address invocation_counter(rscratch2, 651 MethodCounters::invocation_counter_offset() + 652 InvocationCounter::counter_offset()); 653 __ get_method_counters(rmethod, rscratch2, done); 654 const Address mask(rscratch2, in_bytes(MethodCounters::invoke_mask_offset())); 655 __ increment_mask_and_jump(invocation_counter, increment, mask, rscratch1, r1, false, Assembler::EQ, overflow); 656 __ bind(done); 657 } 658 659 void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) { 660 661 // Asm interpreter on entry 662 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] 663 // Everything as it was on entry 664 665 // InterpreterRuntime::frequency_counter_overflow takes two 666 // arguments, the first (thread) is passed by call_VM, the second 667 // indicates if the counter overflow occurs at a backwards branch 668 // (null bcp). We pass zero for it. The call returns the address 669 // of the verified entry point for the method or null if the 670 // compilation did not complete (either went background or bailed 671 // out). 672 __ mov(c_rarg1, 0); 673 __ call_VM(noreg, 674 CAST_FROM_FN_PTR(address, 675 InterpreterRuntime::frequency_counter_overflow), 676 c_rarg1); 677 678 __ b(do_continue); 679 } 680 681 // See if we've got enough room on the stack for locals plus overhead 682 // below JavaThread::stack_overflow_limit(). If not, throw a StackOverflowError 683 // without going through the signal handler, i.e., reserved and yellow zones 684 // will not be made usable. The shadow zone must suffice to handle the 685 // overflow. 686 // The expression stack grows down incrementally, so the normal guard 687 // page mechanism will work for that. 688 // 689 // NOTE: Since the additional locals are also always pushed (wasn't 690 // obvious in generate_method_entry) so the guard should work for them 691 // too. 692 // 693 // Args: 694 // r3: number of additional locals this frame needs (what we must check) 695 // rmethod: Method* 696 // 697 // Kills: 698 // r0 699 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) { 700 701 // monitor entry size: see picture of stack set 702 // (generate_method_entry) and frame_amd64.hpp 703 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes(); 704 705 // total overhead size: entry_size + (saved rbp through expr stack 706 // bottom). be sure to change this if you add/subtract anything 707 // to/from the overhead area 708 const int overhead_size = 709 -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size; 710 711 const size_t page_size = os::vm_page_size(); 712 713 Label after_frame_check; 714 715 // see if the frame is greater than one page in size. If so, 716 // then we need to verify there is enough stack space remaining 717 // for the additional locals. 718 // 719 // Note that we use SUBS rather than CMP here because the immediate 720 // field of this instruction may overflow. SUBS can cope with this 721 // because it is a macro that will expand to some number of MOV 722 // instructions and a register operation. 723 __ subs(rscratch1, r3, (page_size - overhead_size) / Interpreter::stackElementSize); 724 __ br(Assembler::LS, after_frame_check); 725 726 // compute rsp as if this were going to be the last frame on 727 // the stack before the red zone 728 729 // locals + overhead, in bytes 730 __ mov(r0, overhead_size); 731 __ add(r0, r0, r3, Assembler::LSL, Interpreter::logStackElementSize); // 2 slots per parameter. 732 733 const Address stack_limit(rthread, JavaThread::stack_overflow_limit_offset()); 734 __ ldr(rscratch1, stack_limit); 735 736 #ifdef ASSERT 737 Label limit_okay; 738 // Verify that thread stack limit is non-zero. 739 __ cbnz(rscratch1, limit_okay); 740 __ stop("stack overflow limit is zero"); 741 __ bind(limit_okay); 742 #endif 743 744 // Add stack limit to locals. 745 __ add(r0, r0, rscratch1); 746 747 // Check against the current stack bottom. 748 __ cmp(sp, r0); 749 __ br(Assembler::HI, after_frame_check); 750 751 // Remove the incoming args, peeling the machine SP back to where it 752 // was in the caller. This is not strictly necessary, but unless we 753 // do so the stack frame may have a garbage FP; this ensures a 754 // correct call stack that we can always unwind. The ANDR should be 755 // unnecessary because the sender SP in r19 is always aligned, but 756 // it doesn't hurt. 757 __ andr(sp, r19_sender_sp, -16); 758 759 // Note: the restored frame is not necessarily interpreted. 760 // Use the shared runtime version of the StackOverflowError. 761 assert(SharedRuntime::throw_StackOverflowError_entry() != nullptr, "stub not yet generated"); 762 __ far_jump(RuntimeAddress(SharedRuntime::throw_StackOverflowError_entry())); 763 764 // all done with frame size check 765 __ bind(after_frame_check); 766 } 767 768 // Allocate monitor and lock method (asm interpreter) 769 // 770 // Args: 771 // rmethod: Method* 772 // rlocals: locals 773 // 774 // Kills: 775 // r0 776 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs) 777 // rscratch1, rscratch2 (scratch regs) 778 void TemplateInterpreterGenerator::lock_method() { 779 // synchronize method 780 const Address access_flags(rmethod, Method::access_flags_offset()); 781 const Address monitor_block_top( 782 rfp, 783 frame::interpreter_frame_monitor_block_top_offset * wordSize); 784 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes(); 785 786 #ifdef ASSERT 787 { 788 Label L; 789 __ ldrw(r0, access_flags); 790 __ tst(r0, JVM_ACC_SYNCHRONIZED); 791 __ br(Assembler::NE, L); 792 __ stop("method doesn't need synchronization"); 793 __ bind(L); 794 } 795 #endif // ASSERT 796 797 // get synchronization object 798 { 799 Label done; 800 __ ldrw(r0, access_flags); 801 __ tst(r0, JVM_ACC_STATIC); 802 // get receiver (assume this is frequent case) 803 __ ldr(r0, Address(rlocals, Interpreter::local_offset_in_bytes(0))); 804 __ br(Assembler::EQ, done); 805 __ load_mirror(r0, rmethod, r5, rscratch2); 806 807 #ifdef ASSERT 808 { 809 Label L; 810 __ cbnz(r0, L); 811 __ stop("synchronization object is null"); 812 __ bind(L); 813 } 814 #endif // ASSERT 815 816 __ bind(done); 817 } 818 819 // add space for monitor & lock 820 __ check_extended_sp(); 821 __ sub(sp, sp, entry_size); // add space for a monitor entry 822 __ sub(esp, esp, entry_size); 823 __ sub(rscratch1, sp, rfp); 824 __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize); 825 __ str(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize)); 826 __ sub(rscratch1, esp, rfp); 827 __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize); 828 __ str(rscratch1, monitor_block_top); // set new monitor block top 829 830 // store object 831 __ str(r0, Address(esp, BasicObjectLock::obj_offset())); 832 __ mov(c_rarg1, esp); // object address 833 __ lock_object(c_rarg1); 834 } 835 836 // Generate a fixed interpreter frame. This is identical setup for 837 // interpreted methods and for native methods hence the shared code. 838 // 839 // Args: 840 // lr: return address 841 // rmethod: Method* 842 // rlocals: pointer to locals 843 // rcpool: cp cache 844 // stack_pointer: previous sp 845 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 846 // initialize fixed part of activation frame 847 if (native_call) { 848 __ sub(esp, sp, 14 * wordSize); 849 __ mov(rbcp, zr); 850 __ mov(rscratch1, frame::interpreter_frame_initial_sp_offset); 851 __ stp(rscratch1, zr, Address(__ pre(sp, -14 * wordSize))); 852 // add 2 zero-initialized slots for native calls 853 __ stp(zr, zr, Address(sp, 12 * wordSize)); 854 } else { 855 __ sub(esp, sp, 12 * wordSize); 856 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); // get ConstMethod 857 __ add(rbcp, rscratch1, in_bytes(ConstMethod::codes_offset())); // get codebase 858 __ mov(rscratch1, frame::interpreter_frame_initial_sp_offset); 859 __ stp(rscratch1, rbcp, Address(__ pre(sp, -12 * wordSize))); 860 } 861 862 if (ProfileInterpreter) { 863 Label method_data_continue; 864 __ ldr(rscratch1, Address(rmethod, Method::method_data_offset())); 865 __ cbz(rscratch1, method_data_continue); 866 __ lea(rscratch1, Address(rscratch1, in_bytes(MethodData::data_offset()))); 867 __ bind(method_data_continue); 868 __ stp(rscratch1, rmethod, Address(sp, 6 * wordSize)); // save Method* and mdp (method data pointer) 869 } else { 870 __ stp(zr, rmethod, Address(sp, 6 * wordSize)); // save Method* (no mdp) 871 } 872 873 __ protect_return_address(); 874 __ stp(rfp, lr, Address(sp, 10 * wordSize)); 875 __ lea(rfp, Address(sp, 10 * wordSize)); 876 877 __ ldr(rcpool, Address(rmethod, Method::const_offset())); 878 __ ldr(rcpool, Address(rcpool, ConstMethod::constants_offset())); 879 __ ldr(rcpool, Address(rcpool, ConstantPool::cache_offset())); 880 __ sub(rscratch1, rlocals, rfp); 881 __ lsr(rscratch1, rscratch1, Interpreter::logStackElementSize); // rscratch1 = rlocals - fp(); 882 // Store relativized rlocals, see frame::interpreter_frame_locals(). 883 __ stp(rscratch1, rcpool, Address(sp, 2 * wordSize)); 884 885 // set sender sp 886 // leave last_sp as null 887 __ stp(zr, r19_sender_sp, Address(sp, 8 * wordSize)); 888 889 // Get mirror 890 __ load_mirror(r10, rmethod, r5, rscratch2); 891 if (! native_call) { 892 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 893 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 894 __ add(rscratch1, rscratch1, MAX2(3, Method::extra_stack_entries())); 895 __ sub(rscratch1, sp, rscratch1, ext::uxtw, 3); 896 __ andr(rscratch1, rscratch1, -16); 897 __ sub(rscratch2, rscratch1, rfp); 898 __ asr(rscratch2, rscratch2, Interpreter::logStackElementSize); 899 // Store extended SP and mirror 900 __ stp(r10, rscratch2, Address(sp, 4 * wordSize)); 901 // Move SP out of the way 902 __ mov(sp, rscratch1); 903 } else { 904 // Make sure there is room for the exception oop pushed in case method throws 905 // an exception (see TemplateInterpreterGenerator::generate_throw_exception()) 906 __ sub(rscratch1, sp, 2 * wordSize); 907 __ sub(rscratch2, rscratch1, rfp); 908 __ asr(rscratch2, rscratch2, Interpreter::logStackElementSize); 909 __ stp(r10, rscratch2, Address(sp, 4 * wordSize)); 910 __ mov(sp, rscratch1); 911 } 912 } 913 914 // End of helpers 915 916 // Various method entries 917 //------------------------------------------------------------------------------------------------------------------------ 918 // 919 // 920 921 // Method entry for java.lang.ref.Reference.get. 922 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) { 923 // Code: _aload_0, _getfield, _areturn 924 // parameter size = 1 925 // 926 // The code that gets generated by this routine is split into 2 parts: 927 // 1. The "intrinsified" code for G1 (or any SATB based GC), 928 // 2. The slow path - which is an expansion of the regular method entry. 929 // 930 // Notes:- 931 // * In the G1 code we do not check whether we need to block for 932 // a safepoint. If G1 is enabled then we must execute the specialized 933 // code for Reference.get (except when the Reference object is null) 934 // so that we can log the value in the referent field with an SATB 935 // update buffer. 936 // If the code for the getfield template is modified so that the 937 // G1 pre-barrier code is executed when the current method is 938 // Reference.get() then going through the normal method entry 939 // will be fine. 940 // * The G1 code can, however, check the receiver object (the instance 941 // of java.lang.Reference) and jump to the slow path if null. If the 942 // Reference object is null then we obviously cannot fetch the referent 943 // and so we don't need to call the G1 pre-barrier. Thus we can use the 944 // regular method entry code to generate the NPE. 945 // 946 // This code is based on generate_accessor_entry. 947 // 948 // rmethod: Method* 949 // r19_sender_sp: senderSP must preserve for slow path, set SP to it on fast path 950 951 // LR is live. It must be saved around calls. 952 953 address entry = __ pc(); 954 955 const int referent_offset = java_lang_ref_Reference::referent_offset(); 956 957 Label slow_path; 958 const Register local_0 = c_rarg0; 959 // Check if local 0 != null 960 // If the receiver is null then it is OK to jump to the slow path. 961 __ ldr(local_0, Address(esp, 0)); 962 __ cbz(local_0, slow_path); 963 964 // Load the value of the referent field. 965 const Address field_address(local_0, referent_offset); 966 BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler(); 967 bs->load_at(_masm, IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT, local_0, field_address, /*tmp1*/ rscratch1, /*tmp2*/ rscratch2); 968 969 // areturn 970 __ andr(sp, r19_sender_sp, -16); // done with stack 971 __ ret(lr); 972 973 // generate a vanilla interpreter entry as the slow path 974 __ bind(slow_path); 975 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals)); 976 return entry; 977 978 } 979 980 /** 981 * Method entry for static native methods: 982 * int java.util.zip.CRC32.update(int crc, int b) 983 */ 984 address TemplateInterpreterGenerator::generate_CRC32_update_entry() { 985 assert(UseCRC32Intrinsics, "this intrinsic is not supported"); 986 address entry = __ pc(); 987 988 // rmethod: Method* 989 // r19_sender_sp: senderSP must preserved for slow path 990 // esp: args 991 992 Label slow_path; 993 // If we need a safepoint check, generate full interpreter entry. 994 __ safepoint_poll(slow_path, false /* at_return */, false /* acquire */, false /* in_nmethod */); 995 996 // We don't generate local frame and don't align stack because 997 // we call stub code and there is no safepoint on this path. 998 999 // Load parameters 1000 const Register crc = c_rarg0; // crc 1001 const Register val = c_rarg1; // source java byte value 1002 const Register tbl = c_rarg2; // scratch 1003 1004 // Arguments are reversed on java expression stack 1005 __ ldrw(val, Address(esp, 0)); // byte value 1006 __ ldrw(crc, Address(esp, wordSize)); // Initial CRC 1007 1008 uint64_t offset; 1009 __ adrp(tbl, ExternalAddress(StubRoutines::crc_table_addr()), offset); 1010 __ add(tbl, tbl, offset); 1011 1012 __ mvnw(crc, crc); // ~crc 1013 __ update_byte_crc32(crc, val, tbl); 1014 __ mvnw(crc, crc); // ~crc 1015 1016 // result in c_rarg0 1017 1018 __ andr(sp, r19_sender_sp, -16); 1019 __ ret(lr); 1020 1021 // generate a vanilla native entry as the slow path 1022 __ bind(slow_path); 1023 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native)); 1024 return entry; 1025 } 1026 1027 /** 1028 * Method entry for static native methods: 1029 * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) 1030 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 1031 */ 1032 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 1033 assert(UseCRC32Intrinsics, "this intrinsic is not supported"); 1034 address entry = __ pc(); 1035 1036 // rmethod,: Method* 1037 // r19_sender_sp: senderSP must preserved for slow path 1038 1039 Label slow_path; 1040 // If we need a safepoint check, generate full interpreter entry. 1041 __ safepoint_poll(slow_path, false /* at_return */, false /* acquire */, false /* in_nmethod */); 1042 1043 // We don't generate local frame and don't align stack because 1044 // we call stub code and there is no safepoint on this path. 1045 1046 // Load parameters 1047 const Register crc = c_rarg0; // crc 1048 const Register buf = c_rarg1; // source java byte array address 1049 const Register len = c_rarg2; // length 1050 const Register off = len; // offset (never overlaps with 'len') 1051 1052 // Arguments are reversed on java expression stack 1053 // Calculate address of start element 1054 if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { 1055 __ ldr(buf, Address(esp, 2*wordSize)); // long buf 1056 __ ldrw(off, Address(esp, wordSize)); // offset 1057 __ add(buf, buf, off); // + offset 1058 __ ldrw(crc, Address(esp, 4*wordSize)); // Initial CRC 1059 } else { 1060 __ ldr(buf, Address(esp, 2*wordSize)); // byte[] array 1061 __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size 1062 __ ldrw(off, Address(esp, wordSize)); // offset 1063 __ add(buf, buf, off); // + offset 1064 __ ldrw(crc, Address(esp, 3*wordSize)); // Initial CRC 1065 } 1066 // Can now load 'len' since we're finished with 'off' 1067 __ ldrw(len, Address(esp, 0x0)); // Length 1068 1069 __ andr(sp, r19_sender_sp, -16); // Restore the caller's SP 1070 1071 // We are frameless so we can just jump to the stub. 1072 __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32())); 1073 1074 // generate a vanilla native entry as the slow path 1075 __ bind(slow_path); 1076 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native)); 1077 return entry; 1078 } 1079 1080 /** 1081 * Method entry for intrinsic-candidate (non-native) methods: 1082 * int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int end) 1083 * int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end) 1084 * Unlike CRC32, CRC32C does not have any methods marked as native 1085 * CRC32C also uses an "end" variable instead of the length variable CRC32 uses 1086 */ 1087 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 1088 assert(UseCRC32CIntrinsics, "this intrinsic is not supported"); 1089 address entry = __ pc(); 1090 1091 // Prepare jump to stub using parameters from the stack 1092 const Register crc = c_rarg0; // initial crc 1093 const Register buf = c_rarg1; // source java byte array address 1094 const Register len = c_rarg2; // len argument to the kernel 1095 1096 const Register end = len; // index of last element to process 1097 const Register off = crc; // offset 1098 1099 __ ldrw(end, Address(esp)); // int end 1100 __ ldrw(off, Address(esp, wordSize)); // int offset 1101 __ sub(len, end, off); 1102 __ ldr(buf, Address(esp, 2*wordSize)); // byte[] buf | long buf 1103 __ add(buf, buf, off); // + offset 1104 if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) { 1105 __ ldrw(crc, Address(esp, 4*wordSize)); // long crc 1106 } else { 1107 __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size 1108 __ ldrw(crc, Address(esp, 3*wordSize)); // long crc 1109 } 1110 1111 __ andr(sp, r19_sender_sp, -16); // Restore the caller's SP 1112 1113 // Jump to the stub. 1114 __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32C())); 1115 1116 return entry; 1117 } 1118 1119 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 1120 // See more discussion in stackOverflow.hpp. 1121 1122 const int shadow_zone_size = checked_cast<int>(StackOverflow::stack_shadow_zone_size()); 1123 const int page_size = (int)os::vm_page_size(); 1124 const int n_shadow_pages = shadow_zone_size / page_size; 1125 1126 #ifdef ASSERT 1127 Label L_good_limit; 1128 __ ldr(rscratch1, Address(rthread, JavaThread::shadow_zone_safe_limit())); 1129 __ cbnz(rscratch1, L_good_limit); 1130 __ stop("shadow zone safe limit is not initialized"); 1131 __ bind(L_good_limit); 1132 1133 Label L_good_watermark; 1134 __ ldr(rscratch1, Address(rthread, JavaThread::shadow_zone_growth_watermark())); 1135 __ cbnz(rscratch1, L_good_watermark); 1136 __ stop("shadow zone growth watermark is not initialized"); 1137 __ bind(L_good_watermark); 1138 #endif 1139 1140 Label L_done; 1141 1142 __ ldr(rscratch1, Address(rthread, JavaThread::shadow_zone_growth_watermark())); 1143 __ cmp(sp, rscratch1); 1144 __ br(Assembler::HI, L_done); 1145 1146 for (int p = 1; p <= n_shadow_pages; p++) { 1147 __ sub(rscratch2, sp, p*page_size); 1148 __ str(zr, Address(rscratch2)); 1149 } 1150 1151 // Record the new watermark, but only if the update is above the safe limit. 1152 // Otherwise, the next time around the check above would pass the safe limit. 1153 __ ldr(rscratch1, Address(rthread, JavaThread::shadow_zone_safe_limit())); 1154 __ cmp(sp, rscratch1); 1155 __ br(Assembler::LS, L_done); 1156 __ mov(rscratch1, sp); 1157 __ str(rscratch1, Address(rthread, JavaThread::shadow_zone_growth_watermark())); 1158 1159 __ bind(L_done); 1160 } 1161 1162 // Interpreter stub for calling a native method. (asm interpreter) 1163 // This sets up a somewhat different looking stack for calling the 1164 // native method than the typical interpreter frame setup. 1165 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) { 1166 // determine code generation flags 1167 bool inc_counter = UseCompiler || CountCompiledCalls; 1168 1169 // r1: Method* 1170 // rscratch1: sender sp 1171 1172 address entry_point = __ pc(); 1173 1174 const Address constMethod (rmethod, Method::const_offset()); 1175 const Address access_flags (rmethod, Method::access_flags_offset()); 1176 const Address size_of_parameters(r2, ConstMethod:: 1177 size_of_parameters_offset()); 1178 1179 // get parameter size (always needed) 1180 __ ldr(r2, constMethod); 1181 __ load_unsigned_short(r2, size_of_parameters); 1182 1183 // Native calls don't need the stack size check since they have no 1184 // expression stack and the arguments are already on the stack and 1185 // we only add a handful of words to the stack. 1186 1187 // rmethod: Method* 1188 // r2: size of parameters 1189 // rscratch1: sender sp 1190 1191 // for natives the size of locals is zero 1192 1193 // compute beginning of parameters (rlocals) 1194 __ add(rlocals, esp, r2, ext::uxtx, 3); 1195 __ add(rlocals, rlocals, -wordSize); 1196 1197 // Pull SP back to minimum size: this avoids holes in the stack 1198 __ andr(sp, esp, -16); 1199 1200 // initialize fixed part of activation frame 1201 generate_fixed_frame(true); 1202 1203 // make sure method is native & not abstract 1204 #ifdef ASSERT 1205 __ ldrw(r0, access_flags); 1206 { 1207 Label L; 1208 __ tst(r0, JVM_ACC_NATIVE); 1209 __ br(Assembler::NE, L); 1210 __ stop("tried to execute non-native method as native"); 1211 __ bind(L); 1212 } 1213 { 1214 Label L; 1215 __ tst(r0, JVM_ACC_ABSTRACT); 1216 __ br(Assembler::EQ, L); 1217 __ stop("tried to execute abstract method in interpreter"); 1218 __ bind(L); 1219 } 1220 #endif 1221 1222 // Since at this point in the method invocation the exception 1223 // handler would try to exit the monitor of synchronized methods 1224 // which hasn't been entered yet, we set the thread local variable 1225 // _do_not_unlock_if_synchronized to true. The remove_activation 1226 // will check this flag. 1227 1228 const Address do_not_unlock_if_synchronized(rthread, 1229 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1230 __ mov(rscratch2, true); 1231 __ strb(rscratch2, do_not_unlock_if_synchronized); 1232 1233 // increment invocation count & check for overflow 1234 Label invocation_counter_overflow; 1235 if (inc_counter) { 1236 generate_counter_incr(&invocation_counter_overflow); 1237 } 1238 1239 Label continue_after_compile; 1240 __ bind(continue_after_compile); 1241 1242 bang_stack_shadow_pages(true); 1243 1244 // reset the _do_not_unlock_if_synchronized flag 1245 __ strb(zr, do_not_unlock_if_synchronized); 1246 1247 // check for synchronized methods 1248 // Must happen AFTER invocation_counter check and stack overflow check, 1249 // so method is not locked if overflows. 1250 if (synchronized) { 1251 lock_method(); 1252 } else { 1253 // no synchronization necessary 1254 #ifdef ASSERT 1255 { 1256 Label L; 1257 __ ldrw(r0, access_flags); 1258 __ tst(r0, JVM_ACC_SYNCHRONIZED); 1259 __ br(Assembler::EQ, L); 1260 __ stop("method needs synchronization"); 1261 __ bind(L); 1262 } 1263 #endif 1264 } 1265 1266 // start execution 1267 #ifdef ASSERT 1268 { 1269 Label L; 1270 const Address monitor_block_top(rfp, 1271 frame::interpreter_frame_monitor_block_top_offset * wordSize); 1272 __ ldr(rscratch1, monitor_block_top); 1273 __ lea(rscratch1, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 1274 __ cmp(esp, rscratch1); 1275 __ br(Assembler::EQ, L); 1276 __ stop("broken stack frame setup in interpreter 1"); 1277 __ bind(L); 1278 } 1279 #endif 1280 1281 // jvmti support 1282 __ notify_method_entry(); 1283 1284 // work registers 1285 const Register t = r17; 1286 const Register result_handler = r19; 1287 1288 // allocate space for parameters 1289 __ ldr(t, Address(rmethod, Method::const_offset())); 1290 __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset())); 1291 1292 __ sub(rscratch1, esp, t, ext::uxtx, Interpreter::logStackElementSize); 1293 __ andr(sp, rscratch1, -16); 1294 __ mov(esp, rscratch1); 1295 1296 // get signature handler 1297 { 1298 Label L; 1299 __ ldr(t, Address(rmethod, Method::signature_handler_offset())); 1300 __ cbnz(t, L); 1301 __ call_VM(noreg, 1302 CAST_FROM_FN_PTR(address, 1303 InterpreterRuntime::prepare_native_call), 1304 rmethod); 1305 __ ldr(t, Address(rmethod, Method::signature_handler_offset())); 1306 __ bind(L); 1307 } 1308 1309 // call signature handler 1310 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rlocals, 1311 "adjust this code"); 1312 assert(InterpreterRuntime::SignatureHandlerGenerator::to() == sp, 1313 "adjust this code"); 1314 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1, 1315 "adjust this code"); 1316 1317 // The generated handlers do not touch rmethod (the method). 1318 // However, large signatures cannot be cached and are generated 1319 // each time here. The slow-path generator can do a GC on return, 1320 // so we must reload it after the call. 1321 __ blr(t); 1322 __ get_method(rmethod); // slow path can do a GC, reload rmethod 1323 1324 1325 // result handler is in r0 1326 // set result handler 1327 __ mov(result_handler, r0); 1328 // pass mirror handle if static call 1329 { 1330 Label L; 1331 __ ldrw(t, Address(rmethod, Method::access_flags_offset())); 1332 __ tbz(t, exact_log2(JVM_ACC_STATIC), L); 1333 // get mirror 1334 __ load_mirror(t, rmethod, r10, rscratch2); 1335 // copy mirror into activation frame 1336 __ str(t, Address(rfp, frame::interpreter_frame_oop_temp_offset * wordSize)); 1337 // pass handle to mirror 1338 __ add(c_rarg1, rfp, frame::interpreter_frame_oop_temp_offset * wordSize); 1339 __ bind(L); 1340 } 1341 1342 // get native function entry point in r10 1343 { 1344 Label L; 1345 __ ldr(r10, Address(rmethod, Method::native_function_offset())); 1346 ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); 1347 __ lea(rscratch2, unsatisfied); 1348 __ ldr(rscratch2, rscratch2); 1349 __ cmp(r10, rscratch2); 1350 __ br(Assembler::NE, L); 1351 __ call_VM(noreg, 1352 CAST_FROM_FN_PTR(address, 1353 InterpreterRuntime::prepare_native_call), 1354 rmethod); 1355 __ get_method(rmethod); 1356 __ ldr(r10, Address(rmethod, Method::native_function_offset())); 1357 __ bind(L); 1358 } 1359 1360 // pass JNIEnv 1361 __ add(c_rarg0, rthread, in_bytes(JavaThread::jni_environment_offset())); 1362 1363 // Set the last Java PC in the frame anchor to be the return address from 1364 // the call to the native method: this will allow the debugger to 1365 // generate an accurate stack trace. 1366 Label native_return; 1367 __ set_last_Java_frame(esp, rfp, native_return, rscratch1); 1368 1369 // change thread state 1370 #ifdef ASSERT 1371 { 1372 Label L; 1373 __ ldrw(t, Address(rthread, JavaThread::thread_state_offset())); 1374 __ cmp(t, (u1)_thread_in_Java); 1375 __ br(Assembler::EQ, L); 1376 __ stop("Wrong thread state in native stub"); 1377 __ bind(L); 1378 } 1379 #endif 1380 1381 // Change state to native 1382 __ mov(rscratch1, _thread_in_native); 1383 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1384 __ stlrw(rscratch1, rscratch2); 1385 1386 // Call the native method. 1387 __ blr(r10); 1388 __ bind(native_return); 1389 __ get_method(rmethod); 1390 // result potentially in r0 or v0 1391 1392 // Restore cpu control state after JNI call 1393 __ restore_cpu_control_state_after_jni(rscratch1, rscratch2); 1394 1395 // make room for the pushes we're about to do 1396 __ sub(rscratch1, esp, 4 * wordSize); 1397 __ andr(sp, rscratch1, -16); 1398 1399 // NOTE: The order of these pushes is known to frame::interpreter_frame_result 1400 // in order to extract the result of a method call. If the order of these 1401 // pushes change or anything else is added to the stack then the code in 1402 // interpreter_frame_result must also change. 1403 __ push(dtos); 1404 __ push(ltos); 1405 1406 __ verify_sve_vector_length(); 1407 1408 // change thread state 1409 __ mov(rscratch1, _thread_in_native_trans); 1410 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1411 __ stlrw(rscratch1, rscratch2); 1412 1413 // Force this write out before the read below 1414 if (!UseSystemMemoryBarrier) { 1415 __ dmb(Assembler::ISH); 1416 } 1417 1418 // check for safepoint operation in progress and/or pending suspend requests 1419 { 1420 Label L, Continue; 1421 1422 // No need for acquire as Java threads always disarm themselves. 1423 __ safepoint_poll(L, true /* at_return */, false /* acquire */, false /* in_nmethod */); 1424 __ ldrw(rscratch2, Address(rthread, JavaThread::suspend_flags_offset())); 1425 __ cbz(rscratch2, Continue); 1426 __ bind(L); 1427 1428 // Don't use call_VM as it will see a possible pending exception 1429 // and forward it and never return here preventing us from 1430 // clearing _last_native_pc down below. So we do a runtime call by 1431 // hand. 1432 // 1433 __ mov(c_rarg0, rthread); 1434 __ lea(rscratch2, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans))); 1435 __ blr(rscratch2); 1436 __ get_method(rmethod); 1437 __ reinit_heapbase(); 1438 __ bind(Continue); 1439 } 1440 1441 // change thread state 1442 __ mov(rscratch1, _thread_in_Java); 1443 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1444 __ stlrw(rscratch1, rscratch2); 1445 1446 // reset_last_Java_frame 1447 __ reset_last_Java_frame(true); 1448 1449 if (CheckJNICalls) { 1450 // clear_pending_jni_exception_check 1451 __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset())); 1452 } 1453 1454 // reset handle block 1455 __ ldr(t, Address(rthread, JavaThread::active_handles_offset())); 1456 __ str(zr, Address(t, JNIHandleBlock::top_offset())); 1457 1458 // If result is an oop unbox and store it in frame where gc will see it 1459 // and result handler will pick it up 1460 1461 { 1462 Label no_oop; 1463 __ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT))); 1464 __ cmp(t, result_handler); 1465 __ br(Assembler::NE, no_oop); 1466 // Unbox oop result, e.g. JNIHandles::resolve result. 1467 __ pop(ltos); 1468 __ resolve_jobject(r0, t, rscratch2); 1469 __ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize)); 1470 // keep stack depth as expected by pushing oop which will eventually be discarded 1471 __ push(ltos); 1472 __ bind(no_oop); 1473 } 1474 1475 { 1476 Label no_reguard; 1477 __ lea(rscratch1, Address(rthread, in_bytes(JavaThread::stack_guard_state_offset()))); 1478 __ ldrw(rscratch1, Address(rscratch1)); 1479 __ cmp(rscratch1, (u1)StackOverflow::stack_guard_yellow_reserved_disabled); 1480 __ br(Assembler::NE, no_reguard); 1481 1482 __ push_call_clobbered_registers(); 1483 __ mov(c_rarg0, rthread); 1484 __ lea(rscratch2, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages))); 1485 __ blr(rscratch2); 1486 __ pop_call_clobbered_registers(); 1487 1488 __ bind(no_reguard); 1489 } 1490 1491 // The method register is junk from after the thread_in_native transition 1492 // until here. Also can't call_VM until the bcp has been 1493 // restored. Need bcp for throwing exception below so get it now. 1494 __ get_method(rmethod); 1495 1496 // restore bcp to have legal interpreter frame, i.e., bci == 0 <=> 1497 // rbcp == code_base() 1498 __ ldr(rbcp, Address(rmethod, Method::const_offset())); // get ConstMethod* 1499 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); // get codebase 1500 // handle exceptions (exception handling will handle unlocking!) 1501 { 1502 Label L; 1503 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 1504 __ cbz(rscratch1, L); 1505 // Note: At some point we may want to unify this with the code 1506 // used in call_VM_base(); i.e., we should use the 1507 // StubRoutines::forward_exception code. For now this doesn't work 1508 // here because the rsp is not correctly set at this point. 1509 __ MacroAssembler::call_VM(noreg, 1510 CAST_FROM_FN_PTR(address, 1511 InterpreterRuntime::throw_pending_exception)); 1512 __ should_not_reach_here(); 1513 __ bind(L); 1514 } 1515 1516 // do unlocking if necessary 1517 { 1518 Label L; 1519 __ ldrw(t, Address(rmethod, Method::access_flags_offset())); 1520 __ tbz(t, exact_log2(JVM_ACC_SYNCHRONIZED), L); 1521 // the code below should be shared with interpreter macro 1522 // assembler implementation 1523 { 1524 Label unlock; 1525 // BasicObjectLock will be first in list, since this is a 1526 // synchronized method. However, need to check that the object 1527 // has not been unlocked by an explicit monitorexit bytecode. 1528 1529 // monitor expect in c_rarg1 for slow unlock path 1530 __ lea (c_rarg1, Address(rfp, // address of first monitor 1531 (intptr_t)(frame::interpreter_frame_initial_sp_offset * 1532 wordSize - sizeof(BasicObjectLock)))); 1533 1534 __ ldr(t, Address(c_rarg1, BasicObjectLock::obj_offset())); 1535 __ cbnz(t, unlock); 1536 1537 // Entry already unlocked, need to throw exception 1538 __ MacroAssembler::call_VM(noreg, 1539 CAST_FROM_FN_PTR(address, 1540 InterpreterRuntime::throw_illegal_monitor_state_exception)); 1541 __ should_not_reach_here(); 1542 1543 __ bind(unlock); 1544 __ unlock_object(c_rarg1); 1545 } 1546 __ bind(L); 1547 } 1548 1549 // jvmti support 1550 // Note: This must happen _after_ handling/throwing any exceptions since 1551 // the exception handler code notifies the runtime of method exits 1552 // too. If this happens before, method entry/exit notifications are 1553 // not properly paired (was bug - gri 11/22/99). 1554 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); 1555 1556 // restore potential result in r0:d0, call result handler to 1557 // restore potential result in ST0 & handle result 1558 1559 __ pop(ltos); 1560 __ pop(dtos); 1561 1562 __ blr(result_handler); 1563 1564 // remove activation 1565 __ ldr(esp, Address(rfp, 1566 frame::interpreter_frame_sender_sp_offset * 1567 wordSize)); // get sender sp 1568 // remove frame anchor 1569 __ leave(); 1570 1571 // restore sender sp 1572 __ mov(sp, esp); 1573 1574 __ ret(lr); 1575 1576 if (inc_counter) { 1577 // Handle overflow of counter and compile method 1578 __ bind(invocation_counter_overflow); 1579 generate_counter_overflow(continue_after_compile); 1580 } 1581 1582 return entry_point; 1583 } 1584 1585 // 1586 // Generic interpreted method entry to (asm) interpreter 1587 // 1588 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { 1589 // determine code generation flags 1590 bool inc_counter = UseCompiler || CountCompiledCalls; 1591 1592 // rscratch1: sender sp 1593 address entry_point = __ pc(); 1594 1595 const Address constMethod(rmethod, Method::const_offset()); 1596 const Address access_flags(rmethod, Method::access_flags_offset()); 1597 const Address size_of_parameters(r3, 1598 ConstMethod::size_of_parameters_offset()); 1599 const Address size_of_locals(r3, ConstMethod::size_of_locals_offset()); 1600 1601 // get parameter size (always needed) 1602 // need to load the const method first 1603 __ ldr(r3, constMethod); 1604 __ load_unsigned_short(r2, size_of_parameters); 1605 1606 // r2: size of parameters 1607 1608 __ load_unsigned_short(r3, size_of_locals); // get size of locals in words 1609 __ sub(r3, r3, r2); // r3 = no. of additional locals 1610 1611 // see if we've got enough room on the stack for locals plus overhead. 1612 generate_stack_overflow_check(); 1613 1614 // compute beginning of parameters (rlocals) 1615 __ add(rlocals, esp, r2, ext::uxtx, 3); 1616 __ sub(rlocals, rlocals, wordSize); 1617 1618 __ mov(rscratch1, esp); 1619 1620 // r3 - # of additional locals 1621 // allocate space for locals 1622 // explicitly initialize locals 1623 // Initializing memory allocated for locals in the same direction as 1624 // the stack grows to ensure page initialization order according 1625 // to windows-aarch64 stack page growth requirement (see 1626 // https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160#stack) 1627 { 1628 Label exit, loop; 1629 __ ands(zr, r3, r3); 1630 __ br(Assembler::LE, exit); // do nothing if r3 <= 0 1631 __ bind(loop); 1632 __ str(zr, Address(__ pre(rscratch1, -wordSize))); 1633 __ sub(r3, r3, 1); // until everything initialized 1634 __ cbnz(r3, loop); 1635 __ bind(exit); 1636 } 1637 1638 // Padding between locals and fixed part of activation frame to ensure 1639 // SP is always 16-byte aligned. 1640 __ andr(sp, rscratch1, -16); 1641 1642 // And the base dispatch table 1643 __ get_dispatch(); 1644 1645 // initialize fixed part of activation frame 1646 generate_fixed_frame(false); 1647 1648 // make sure method is not native & not abstract 1649 #ifdef ASSERT 1650 __ ldrw(r0, access_flags); 1651 { 1652 Label L; 1653 __ tst(r0, JVM_ACC_NATIVE); 1654 __ br(Assembler::EQ, L); 1655 __ stop("tried to execute native method as non-native"); 1656 __ bind(L); 1657 } 1658 { 1659 Label L; 1660 __ tst(r0, JVM_ACC_ABSTRACT); 1661 __ br(Assembler::EQ, L); 1662 __ stop("tried to execute abstract method in interpreter"); 1663 __ bind(L); 1664 } 1665 #endif 1666 1667 // Since at this point in the method invocation the exception 1668 // handler would try to exit the monitor of synchronized methods 1669 // which hasn't been entered yet, we set the thread local variable 1670 // _do_not_unlock_if_synchronized to true. The remove_activation 1671 // will check this flag. 1672 1673 const Address do_not_unlock_if_synchronized(rthread, 1674 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1675 __ mov(rscratch2, true); 1676 __ strb(rscratch2, do_not_unlock_if_synchronized); 1677 1678 Register mdp = r3; 1679 __ profile_parameters_type(mdp, r1, r2); 1680 1681 // increment invocation count & check for overflow 1682 Label invocation_counter_overflow; 1683 if (inc_counter) { 1684 generate_counter_incr(&invocation_counter_overflow); 1685 } 1686 1687 Label continue_after_compile; 1688 __ bind(continue_after_compile); 1689 1690 bang_stack_shadow_pages(false); 1691 1692 // reset the _do_not_unlock_if_synchronized flag 1693 __ strb(zr, do_not_unlock_if_synchronized); 1694 1695 // check for synchronized methods 1696 // Must happen AFTER invocation_counter check and stack overflow check, 1697 // so method is not locked if overflows. 1698 if (synchronized) { 1699 // Allocate monitor and lock method 1700 lock_method(); 1701 } else { 1702 // no synchronization necessary 1703 #ifdef ASSERT 1704 { 1705 Label L; 1706 __ ldrw(r0, access_flags); 1707 __ tst(r0, JVM_ACC_SYNCHRONIZED); 1708 __ br(Assembler::EQ, L); 1709 __ stop("method needs synchronization"); 1710 __ bind(L); 1711 } 1712 #endif 1713 } 1714 1715 // start execution 1716 #ifdef ASSERT 1717 { 1718 Label L; 1719 const Address monitor_block_top (rfp, 1720 frame::interpreter_frame_monitor_block_top_offset * wordSize); 1721 __ ldr(rscratch1, monitor_block_top); 1722 __ lea(rscratch1, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 1723 __ cmp(esp, rscratch1); 1724 __ br(Assembler::EQ, L); 1725 __ stop("broken stack frame setup in interpreter 2"); 1726 __ bind(L); 1727 } 1728 #endif 1729 1730 // jvmti support 1731 __ notify_method_entry(); 1732 1733 __ dispatch_next(vtos); 1734 1735 // invocation counter overflow 1736 if (inc_counter) { 1737 // Handle overflow of counter and compile method 1738 __ bind(invocation_counter_overflow); 1739 generate_counter_overflow(continue_after_compile); 1740 } 1741 1742 return entry_point; 1743 } 1744 1745 // Method entry for java.lang.Thread.currentThread 1746 address TemplateInterpreterGenerator::generate_currentThread() { 1747 address entry_point = __ pc(); 1748 1749 __ ldr(r0, Address(rthread, JavaThread::vthread_offset())); 1750 __ resolve_oop_handle(r0, rscratch1, rscratch2); 1751 __ ret(lr); 1752 1753 return entry_point; 1754 } 1755 1756 // Not supported 1757 address TemplateInterpreterGenerator::generate_Float_intBitsToFloat_entry() { return nullptr; } 1758 address TemplateInterpreterGenerator::generate_Float_floatToRawIntBits_entry() { return nullptr; } 1759 address TemplateInterpreterGenerator::generate_Double_longBitsToDouble_entry() { return nullptr; } 1760 address TemplateInterpreterGenerator::generate_Double_doubleToRawLongBits_entry() { return nullptr; } 1761 1762 //----------------------------------------------------------------------------- 1763 // Exceptions 1764 1765 void TemplateInterpreterGenerator::generate_throw_exception() { 1766 // Entry point in previous activation (i.e., if the caller was 1767 // interpreted) 1768 Interpreter::_rethrow_exception_entry = __ pc(); 1769 // Restore sp to interpreter_frame_last_sp even though we are going 1770 // to empty the expression stack for the exception processing. 1771 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1772 // r0: exception 1773 // r3: return address/pc that threw exception 1774 __ restore_bcp(); // rbcp points to call/send 1775 __ restore_locals(); 1776 __ restore_constant_pool_cache(); 1777 __ reinit_heapbase(); // restore rheapbase as heapbase. 1778 __ get_dispatch(); 1779 1780 // Entry point for exceptions thrown within interpreter code 1781 Interpreter::_throw_exception_entry = __ pc(); 1782 // If we came here via a NullPointerException on the receiver of a 1783 // method, rmethod may be corrupt. 1784 __ get_method(rmethod); 1785 // expression stack is undefined here 1786 // r0: exception 1787 // rbcp: exception bcp 1788 __ verify_oop(r0); 1789 __ mov(c_rarg1, r0); 1790 1791 // expression stack must be empty before entering the VM in case of 1792 // an exception 1793 __ empty_expression_stack(); 1794 // find exception handler address and preserve exception oop 1795 __ call_VM(r3, 1796 CAST_FROM_FN_PTR(address, 1797 InterpreterRuntime::exception_handler_for_exception), 1798 c_rarg1); 1799 1800 // Restore machine SP 1801 __ restore_sp_after_call(); 1802 1803 // r0: exception handler entry point 1804 // r3: preserved exception oop 1805 // rbcp: bcp for exception handler 1806 __ push_ptr(r3); // push exception which is now the only value on the stack 1807 __ br(r0); // jump to exception handler (may be _remove_activation_entry!) 1808 1809 // If the exception is not handled in the current frame the frame is 1810 // removed and the exception is rethrown (i.e. exception 1811 // continuation is _rethrow_exception). 1812 // 1813 // Note: At this point the bci is still the bxi for the instruction 1814 // which caused the exception and the expression stack is 1815 // empty. Thus, for any VM calls at this point, GC will find a legal 1816 // oop map (with empty expression stack). 1817 1818 // 1819 // JVMTI PopFrame support 1820 // 1821 1822 Interpreter::_remove_activation_preserving_args_entry = __ pc(); 1823 __ empty_expression_stack(); 1824 // Set the popframe_processing bit in pending_popframe_condition 1825 // indicating that we are currently handling popframe, so that 1826 // call_VMs that may happen later do not trigger new popframe 1827 // handling cycles. 1828 __ ldrw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1829 __ orr(r3, r3, JavaThread::popframe_processing_bit); 1830 __ strw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1831 1832 { 1833 // Check to see whether we are returning to a deoptimized frame. 1834 // (The PopFrame call ensures that the caller of the popped frame is 1835 // either interpreted or compiled and deoptimizes it if compiled.) 1836 // In this case, we can't call dispatch_next() after the frame is 1837 // popped, but instead must save the incoming arguments and restore 1838 // them after deoptimization has occurred. 1839 // 1840 // Note that we don't compare the return PC against the 1841 // deoptimization blob's unpack entry because of the presence of 1842 // adapter frames in C2. 1843 Label caller_not_deoptimized; 1844 __ ldr(c_rarg1, Address(rfp, frame::return_addr_offset * wordSize)); 1845 // This is a return address, so requires authenticating for PAC. 1846 __ authenticate_return_address(c_rarg1); 1847 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1848 InterpreterRuntime::interpreter_contains), c_rarg1); 1849 __ cbnz(r0, caller_not_deoptimized); 1850 1851 // Compute size of arguments for saving when returning to 1852 // deoptimized caller 1853 __ get_method(r0); 1854 __ ldr(r0, Address(r0, Method::const_offset())); 1855 __ load_unsigned_short(r0, Address(r0, in_bytes(ConstMethod:: 1856 size_of_parameters_offset()))); 1857 __ lsl(r0, r0, Interpreter::logStackElementSize); 1858 __ restore_locals(); // XXX do we need this? 1859 __ sub(rlocals, rlocals, r0); 1860 __ add(rlocals, rlocals, wordSize); 1861 // Save these arguments 1862 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1863 Deoptimization:: 1864 popframe_preserve_args), 1865 rthread, r0, rlocals); 1866 1867 __ remove_activation(vtos, 1868 /* throw_monitor_exception */ false, 1869 /* install_monitor_exception */ false, 1870 /* notify_jvmdi */ false); 1871 1872 // Inform deoptimization that it is responsible for restoring 1873 // these arguments 1874 __ mov(rscratch1, JavaThread::popframe_force_deopt_reexecution_bit); 1875 __ strw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset())); 1876 1877 // Continue in deoptimization handler 1878 __ ret(lr); 1879 1880 __ bind(caller_not_deoptimized); 1881 } 1882 1883 __ remove_activation(vtos, 1884 /* throw_monitor_exception */ false, 1885 /* install_monitor_exception */ false, 1886 /* notify_jvmdi */ false); 1887 1888 // Restore the last_sp and null it out 1889 __ ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1890 __ lea(esp, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 1891 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1892 1893 __ restore_bcp(); 1894 __ restore_locals(); 1895 __ restore_constant_pool_cache(); 1896 __ get_method(rmethod); 1897 __ get_dispatch(); 1898 1899 // The method data pointer was incremented already during 1900 // call profiling. We have to restore the mdp for the current bcp. 1901 if (ProfileInterpreter) { 1902 __ set_method_data_pointer_for_bcp(); 1903 } 1904 1905 // Clear the popframe condition flag 1906 __ strw(zr, Address(rthread, JavaThread::popframe_condition_offset())); 1907 assert(JavaThread::popframe_inactive == 0, "fix popframe_inactive"); 1908 1909 #if INCLUDE_JVMTI 1910 { 1911 Label L_done; 1912 1913 __ ldrb(rscratch1, Address(rbcp, 0)); 1914 __ cmpw(rscratch1, Bytecodes::_invokestatic); 1915 __ br(Assembler::NE, L_done); 1916 1917 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. 1918 // Detect such a case in the InterpreterRuntime function and return the member name argument, or null. 1919 1920 __ ldr(c_rarg0, Address(rlocals, 0)); 1921 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), c_rarg0, rmethod, rbcp); 1922 1923 __ cbz(r0, L_done); 1924 1925 __ str(r0, Address(esp, 0)); 1926 __ bind(L_done); 1927 } 1928 #endif // INCLUDE_JVMTI 1929 1930 // Restore machine SP 1931 __ restore_sp_after_call(); 1932 1933 __ dispatch_next(vtos); 1934 // end of PopFrame support 1935 1936 Interpreter::_remove_activation_entry = __ pc(); 1937 1938 // preserve exception over this code sequence 1939 __ pop_ptr(r0); 1940 __ str(r0, Address(rthread, JavaThread::vm_result_offset())); 1941 // remove the activation (without doing throws on illegalMonitorExceptions) 1942 __ remove_activation(vtos, false, true, false); 1943 // restore exception 1944 __ get_vm_result(r0, rthread); 1945 1946 // In between activations - previous activation type unknown yet 1947 // compute continuation point - the continuation point expects the 1948 // following registers set up: 1949 // 1950 // r0: exception 1951 // lr: return address/pc that threw exception 1952 // esp: expression stack of caller 1953 // rfp: fp of caller 1954 __ stp(r0, lr, Address(__ pre(sp, -2 * wordSize))); // save exception & return address 1955 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1956 SharedRuntime::exception_handler_for_return_address), 1957 rthread, lr); 1958 __ mov(r1, r0); // save exception handler 1959 __ ldp(r0, lr, Address(__ post(sp, 2 * wordSize))); // restore exception & return address 1960 // We might be returning to a deopt handler that expects r3 to 1961 // contain the exception pc 1962 __ mov(r3, lr); 1963 // Note that an "issuing PC" is actually the next PC after the call 1964 __ br(r1); // jump to exception 1965 // handler of caller 1966 } 1967 1968 1969 // 1970 // JVMTI ForceEarlyReturn support 1971 // 1972 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { 1973 address entry = __ pc(); 1974 1975 __ restore_bcp(); 1976 __ restore_locals(); 1977 __ empty_expression_stack(); 1978 __ load_earlyret_value(state); 1979 1980 __ ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset())); 1981 Address cond_addr(rscratch1, JvmtiThreadState::earlyret_state_offset()); 1982 1983 // Clear the earlyret state 1984 assert(JvmtiThreadState::earlyret_inactive == 0, "should be"); 1985 __ str(zr, cond_addr); 1986 1987 __ remove_activation(state, 1988 false, /* throw_monitor_exception */ 1989 false, /* install_monitor_exception */ 1990 true); /* notify_jvmdi */ 1991 __ ret(lr); 1992 1993 return entry; 1994 } // end of ForceEarlyReturn support 1995 1996 1997 1998 //----------------------------------------------------------------------------- 1999 // Helper for vtos entry point generation 2000 2001 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, 2002 address& bep, 2003 address& cep, 2004 address& sep, 2005 address& aep, 2006 address& iep, 2007 address& lep, 2008 address& fep, 2009 address& dep, 2010 address& vep) { 2011 assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 2012 Label L; 2013 aep = __ pc(); __ push_ptr(); __ b(L); 2014 fep = __ pc(); __ push_f(); __ b(L); 2015 dep = __ pc(); __ push_d(); __ b(L); 2016 lep = __ pc(); __ push_l(); __ b(L); 2017 bep = cep = sep = 2018 iep = __ pc(); __ push_i(); 2019 vep = __ pc(); 2020 __ bind(L); 2021 generate_and_dispatch(t); 2022 } 2023 2024 //----------------------------------------------------------------------------- 2025 2026 // Non-product code 2027 #ifndef PRODUCT 2028 address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 2029 address entry = __ pc(); 2030 2031 __ protect_return_address(); 2032 __ push(lr); 2033 __ push(state); 2034 __ push(RegSet::range(r0, r15), sp); 2035 __ mov(c_rarg2, r0); // Pass itos 2036 __ call_VM(noreg, 2037 CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), 2038 c_rarg1, c_rarg2, c_rarg3); 2039 __ pop(RegSet::range(r0, r15), sp); 2040 __ pop(state); 2041 __ pop(lr); 2042 __ authenticate_return_address(); 2043 __ ret(lr); // return from result handler 2044 2045 return entry; 2046 } 2047 2048 void TemplateInterpreterGenerator::count_bytecode() { 2049 __ mov(r10, (address) &BytecodeCounter::_counter_value); 2050 __ atomic_addw(noreg, 1, r10); 2051 } 2052 2053 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { 2054 __ mov(r10, (address) &BytecodeHistogram::_counters[t->bytecode()]); 2055 __ atomic_addw(noreg, 1, r10); 2056 } 2057 2058 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { 2059 // Calculate new index for counter: 2060 // _index = (_index >> log2_number_of_codes) | 2061 // (bytecode << log2_number_of_codes); 2062 Register index_addr = rscratch1; 2063 Register index = rscratch2; 2064 __ mov(index_addr, (address) &BytecodePairHistogram::_index); 2065 __ ldrw(index, index_addr); 2066 __ mov(r10, 2067 ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes); 2068 __ orrw(index, r10, index, Assembler::LSR, 2069 BytecodePairHistogram::log2_number_of_codes); 2070 __ strw(index, index_addr); 2071 2072 // Bump bucket contents: 2073 // _counters[_index] ++; 2074 Register counter_addr = rscratch1; 2075 __ mov(r10, (address) &BytecodePairHistogram::_counters); 2076 __ lea(counter_addr, Address(r10, index, Address::lsl(LogBytesPerInt))); 2077 __ atomic_addw(noreg, 1, counter_addr); 2078 } 2079 2080 void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 2081 // Call a little run-time stub to avoid blow-up for each bytecode. 2082 // The run-time runtime saves the right registers, depending on 2083 // the tosca in-state for the given template. 2084 2085 assert(Interpreter::trace_code(t->tos_in()) != nullptr, 2086 "entry must have been generated"); 2087 __ bl(RuntimeAddress(Interpreter::trace_code(t->tos_in()))); 2088 __ reinit_heapbase(); 2089 } 2090 2091 2092 void TemplateInterpreterGenerator::stop_interpreter_at() { 2093 Label L; 2094 __ push(rscratch1); 2095 __ mov(rscratch1, (address) &BytecodeCounter::_counter_value); 2096 __ ldr(rscratch1, Address(rscratch1)); 2097 __ mov(rscratch2, StopInterpreterAt); 2098 __ cmpw(rscratch1, rscratch2); 2099 __ br(Assembler::NE, L); 2100 __ brk(0); 2101 __ bind(L); 2102 __ pop(rscratch1); 2103 } 2104 2105 #endif // !PRODUCT