1 /* 2 * Copyright (c) 2003, 2023, 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(StubRoutines::throw_StackOverflowError_entry() != nullptr, "stub not yet generated"); 762 __ far_jump(RuntimeAddress(StubRoutines::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 address unsatisfied = (SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); 1347 __ mov(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 // We need an acquire here to ensure that any subsequent load of the 1423 // global SafepointSynchronize::_state flag is ordered after this load 1424 // of the thread-local polling word. We don't want this poll to 1425 // return false (i.e. not safepointing) and a later poll of the global 1426 // SafepointSynchronize::_state spuriously to return true. 1427 // 1428 // This is to avoid a race when we're in a native->Java transition 1429 // racing the code which wakes up from a safepoint. 1430 __ safepoint_poll(L, true /* at_return */, true /* acquire */, false /* in_nmethod */); 1431 __ ldrw(rscratch2, Address(rthread, JavaThread::suspend_flags_offset())); 1432 __ cbz(rscratch2, Continue); 1433 __ bind(L); 1434 1435 // Don't use call_VM as it will see a possible pending exception 1436 // and forward it and never return here preventing us from 1437 // clearing _last_native_pc down below. So we do a runtime call by 1438 // hand. 1439 // 1440 __ mov(c_rarg0, rthread); 1441 __ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)); 1442 __ blr(rscratch2); 1443 __ get_method(rmethod); 1444 __ reinit_heapbase(); 1445 __ bind(Continue); 1446 } 1447 1448 // change thread state 1449 __ mov(rscratch1, _thread_in_Java); 1450 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1451 __ stlrw(rscratch1, rscratch2); 1452 1453 // reset_last_Java_frame 1454 __ reset_last_Java_frame(true); 1455 1456 if (CheckJNICalls) { 1457 // clear_pending_jni_exception_check 1458 __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset())); 1459 } 1460 1461 // reset handle block 1462 __ ldr(t, Address(rthread, JavaThread::active_handles_offset())); 1463 __ str(zr, Address(t, JNIHandleBlock::top_offset())); 1464 1465 // If result is an oop unbox and store it in frame where gc will see it 1466 // and result handler will pick it up 1467 1468 { 1469 Label no_oop; 1470 __ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT))); 1471 __ cmp(t, result_handler); 1472 __ br(Assembler::NE, no_oop); 1473 // Unbox oop result, e.g. JNIHandles::resolve result. 1474 __ pop(ltos); 1475 __ resolve_jobject(r0, t, rscratch2); 1476 __ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize)); 1477 // keep stack depth as expected by pushing oop which will eventually be discarded 1478 __ push(ltos); 1479 __ bind(no_oop); 1480 } 1481 1482 { 1483 Label no_reguard; 1484 __ lea(rscratch1, Address(rthread, in_bytes(JavaThread::stack_guard_state_offset()))); 1485 __ ldrw(rscratch1, Address(rscratch1)); 1486 __ cmp(rscratch1, (u1)StackOverflow::stack_guard_yellow_reserved_disabled); 1487 __ br(Assembler::NE, no_reguard); 1488 1489 __ push_call_clobbered_registers(); 1490 __ mov(c_rarg0, rthread); 1491 __ mov(rscratch2, CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)); 1492 __ blr(rscratch2); 1493 __ pop_call_clobbered_registers(); 1494 1495 __ bind(no_reguard); 1496 } 1497 1498 // The method register is junk from after the thread_in_native transition 1499 // until here. Also can't call_VM until the bcp has been 1500 // restored. Need bcp for throwing exception below so get it now. 1501 __ get_method(rmethod); 1502 1503 // restore bcp to have legal interpreter frame, i.e., bci == 0 <=> 1504 // rbcp == code_base() 1505 __ ldr(rbcp, Address(rmethod, Method::const_offset())); // get ConstMethod* 1506 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); // get codebase 1507 // handle exceptions (exception handling will handle unlocking!) 1508 { 1509 Label L; 1510 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 1511 __ cbz(rscratch1, L); 1512 // Note: At some point we may want to unify this with the code 1513 // used in call_VM_base(); i.e., we should use the 1514 // StubRoutines::forward_exception code. For now this doesn't work 1515 // here because the rsp is not correctly set at this point. 1516 __ MacroAssembler::call_VM(noreg, 1517 CAST_FROM_FN_PTR(address, 1518 InterpreterRuntime::throw_pending_exception)); 1519 __ should_not_reach_here(); 1520 __ bind(L); 1521 } 1522 1523 // do unlocking if necessary 1524 { 1525 Label L; 1526 __ ldrw(t, Address(rmethod, Method::access_flags_offset())); 1527 __ tbz(t, exact_log2(JVM_ACC_SYNCHRONIZED), L); 1528 // the code below should be shared with interpreter macro 1529 // assembler implementation 1530 { 1531 Label unlock; 1532 // BasicObjectLock will be first in list, since this is a 1533 // synchronized method. However, need to check that the object 1534 // has not been unlocked by an explicit monitorexit bytecode. 1535 1536 // monitor expect in c_rarg1 for slow unlock path 1537 __ lea (c_rarg1, Address(rfp, // address of first monitor 1538 (intptr_t)(frame::interpreter_frame_initial_sp_offset * 1539 wordSize - sizeof(BasicObjectLock)))); 1540 1541 __ ldr(t, Address(c_rarg1, BasicObjectLock::obj_offset())); 1542 __ cbnz(t, unlock); 1543 1544 // Entry already unlocked, need to throw exception 1545 __ MacroAssembler::call_VM(noreg, 1546 CAST_FROM_FN_PTR(address, 1547 InterpreterRuntime::throw_illegal_monitor_state_exception)); 1548 __ should_not_reach_here(); 1549 1550 __ bind(unlock); 1551 __ unlock_object(c_rarg1); 1552 } 1553 __ bind(L); 1554 } 1555 1556 // jvmti support 1557 // Note: This must happen _after_ handling/throwing any exceptions since 1558 // the exception handler code notifies the runtime of method exits 1559 // too. If this happens before, method entry/exit notifications are 1560 // not properly paired (was bug - gri 11/22/99). 1561 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); 1562 1563 // restore potential result in r0:d0, call result handler to 1564 // restore potential result in ST0 & handle result 1565 1566 __ pop(ltos); 1567 __ pop(dtos); 1568 1569 __ blr(result_handler); 1570 1571 // remove activation 1572 __ ldr(esp, Address(rfp, 1573 frame::interpreter_frame_sender_sp_offset * 1574 wordSize)); // get sender sp 1575 // remove frame anchor 1576 __ leave(); 1577 1578 // restore sender sp 1579 __ mov(sp, esp); 1580 1581 __ ret(lr); 1582 1583 if (inc_counter) { 1584 // Handle overflow of counter and compile method 1585 __ bind(invocation_counter_overflow); 1586 generate_counter_overflow(continue_after_compile); 1587 } 1588 1589 return entry_point; 1590 } 1591 1592 // 1593 // Generic interpreted method entry to (asm) interpreter 1594 // 1595 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { 1596 // determine code generation flags 1597 bool inc_counter = UseCompiler || CountCompiledCalls; 1598 1599 // rscratch1: sender sp 1600 address entry_point = __ pc(); 1601 1602 const Address constMethod(rmethod, Method::const_offset()); 1603 const Address access_flags(rmethod, Method::access_flags_offset()); 1604 const Address size_of_parameters(r3, 1605 ConstMethod::size_of_parameters_offset()); 1606 const Address size_of_locals(r3, ConstMethod::size_of_locals_offset()); 1607 1608 // get parameter size (always needed) 1609 // need to load the const method first 1610 __ ldr(r3, constMethod); 1611 __ load_unsigned_short(r2, size_of_parameters); 1612 1613 // r2: size of parameters 1614 1615 __ load_unsigned_short(r3, size_of_locals); // get size of locals in words 1616 __ sub(r3, r3, r2); // r3 = no. of additional locals 1617 1618 // see if we've got enough room on the stack for locals plus overhead. 1619 generate_stack_overflow_check(); 1620 1621 // compute beginning of parameters (rlocals) 1622 __ add(rlocals, esp, r2, ext::uxtx, 3); 1623 __ sub(rlocals, rlocals, wordSize); 1624 1625 __ mov(rscratch1, esp); 1626 1627 // r3 - # of additional locals 1628 // allocate space for locals 1629 // explicitly initialize locals 1630 // Initializing memory allocated for locals in the same direction as 1631 // the stack grows to ensure page initialization order according 1632 // to windows-aarch64 stack page growth requirement (see 1633 // https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160#stack) 1634 { 1635 Label exit, loop; 1636 __ ands(zr, r3, r3); 1637 __ br(Assembler::LE, exit); // do nothing if r3 <= 0 1638 __ bind(loop); 1639 __ str(zr, Address(__ pre(rscratch1, -wordSize))); 1640 __ sub(r3, r3, 1); // until everything initialized 1641 __ cbnz(r3, loop); 1642 __ bind(exit); 1643 } 1644 1645 // Padding between locals and fixed part of activation frame to ensure 1646 // SP is always 16-byte aligned. 1647 __ andr(sp, rscratch1, -16); 1648 1649 // And the base dispatch table 1650 __ get_dispatch(); 1651 1652 // initialize fixed part of activation frame 1653 generate_fixed_frame(false); 1654 1655 // make sure method is not native & not abstract 1656 #ifdef ASSERT 1657 __ ldrw(r0, access_flags); 1658 { 1659 Label L; 1660 __ tst(r0, JVM_ACC_NATIVE); 1661 __ br(Assembler::EQ, L); 1662 __ stop("tried to execute native method as non-native"); 1663 __ bind(L); 1664 } 1665 { 1666 Label L; 1667 __ tst(r0, JVM_ACC_ABSTRACT); 1668 __ br(Assembler::EQ, L); 1669 __ stop("tried to execute abstract method in interpreter"); 1670 __ bind(L); 1671 } 1672 #endif 1673 1674 // Since at this point in the method invocation the exception 1675 // handler would try to exit the monitor of synchronized methods 1676 // which hasn't been entered yet, we set the thread local variable 1677 // _do_not_unlock_if_synchronized to true. The remove_activation 1678 // will check this flag. 1679 1680 const Address do_not_unlock_if_synchronized(rthread, 1681 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1682 __ mov(rscratch2, true); 1683 __ strb(rscratch2, do_not_unlock_if_synchronized); 1684 1685 Register mdp = r3; 1686 __ profile_parameters_type(mdp, r1, r2); 1687 1688 // increment invocation count & check for overflow 1689 Label invocation_counter_overflow; 1690 if (inc_counter) { 1691 generate_counter_incr(&invocation_counter_overflow); 1692 } 1693 1694 Label continue_after_compile; 1695 __ bind(continue_after_compile); 1696 1697 bang_stack_shadow_pages(false); 1698 1699 // reset the _do_not_unlock_if_synchronized flag 1700 __ strb(zr, do_not_unlock_if_synchronized); 1701 1702 // check for synchronized methods 1703 // Must happen AFTER invocation_counter check and stack overflow check, 1704 // so method is not locked if overflows. 1705 if (synchronized) { 1706 // Allocate monitor and lock method 1707 lock_method(); 1708 } else { 1709 // no synchronization necessary 1710 #ifdef ASSERT 1711 { 1712 Label L; 1713 __ ldrw(r0, access_flags); 1714 __ tst(r0, JVM_ACC_SYNCHRONIZED); 1715 __ br(Assembler::EQ, L); 1716 __ stop("method needs synchronization"); 1717 __ bind(L); 1718 } 1719 #endif 1720 } 1721 1722 // start execution 1723 #ifdef ASSERT 1724 { 1725 Label L; 1726 const Address monitor_block_top (rfp, 1727 frame::interpreter_frame_monitor_block_top_offset * wordSize); 1728 __ ldr(rscratch1, monitor_block_top); 1729 __ lea(rscratch1, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 1730 __ cmp(esp, rscratch1); 1731 __ br(Assembler::EQ, L); 1732 __ stop("broken stack frame setup in interpreter 2"); 1733 __ bind(L); 1734 } 1735 #endif 1736 1737 // jvmti support 1738 __ notify_method_entry(); 1739 1740 __ dispatch_next(vtos); 1741 1742 // invocation counter overflow 1743 if (inc_counter) { 1744 // Handle overflow of counter and compile method 1745 __ bind(invocation_counter_overflow); 1746 generate_counter_overflow(continue_after_compile); 1747 } 1748 1749 return entry_point; 1750 } 1751 1752 // Method entry for java.lang.Thread.currentThread 1753 address TemplateInterpreterGenerator::generate_currentThread() { 1754 address entry_point = __ pc(); 1755 1756 __ ldr(r0, Address(rthread, JavaThread::vthread_offset())); 1757 __ resolve_oop_handle(r0, rscratch1, rscratch2); 1758 __ ret(lr); 1759 1760 return entry_point; 1761 } 1762 1763 // Not supported 1764 address TemplateInterpreterGenerator::generate_Float_intBitsToFloat_entry() { return nullptr; } 1765 address TemplateInterpreterGenerator::generate_Float_floatToRawIntBits_entry() { return nullptr; } 1766 address TemplateInterpreterGenerator::generate_Double_longBitsToDouble_entry() { return nullptr; } 1767 address TemplateInterpreterGenerator::generate_Double_doubleToRawLongBits_entry() { return nullptr; } 1768 1769 //----------------------------------------------------------------------------- 1770 // Exceptions 1771 1772 void TemplateInterpreterGenerator::generate_throw_exception() { 1773 // Entry point in previous activation (i.e., if the caller was 1774 // interpreted) 1775 Interpreter::_rethrow_exception_entry = __ pc(); 1776 // Restore sp to interpreter_frame_last_sp even though we are going 1777 // to empty the expression stack for the exception processing. 1778 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1779 // r0: exception 1780 // r3: return address/pc that threw exception 1781 __ restore_bcp(); // rbcp points to call/send 1782 __ restore_locals(); 1783 __ restore_constant_pool_cache(); 1784 __ reinit_heapbase(); // restore rheapbase as heapbase. 1785 __ get_dispatch(); 1786 1787 // Entry point for exceptions thrown within interpreter code 1788 Interpreter::_throw_exception_entry = __ pc(); 1789 // If we came here via a NullPointerException on the receiver of a 1790 // method, rmethod may be corrupt. 1791 __ get_method(rmethod); 1792 // expression stack is undefined here 1793 // r0: exception 1794 // rbcp: exception bcp 1795 __ verify_oop(r0); 1796 __ mov(c_rarg1, r0); 1797 1798 // expression stack must be empty before entering the VM in case of 1799 // an exception 1800 __ empty_expression_stack(); 1801 // find exception handler address and preserve exception oop 1802 __ call_VM(r3, 1803 CAST_FROM_FN_PTR(address, 1804 InterpreterRuntime::exception_handler_for_exception), 1805 c_rarg1); 1806 1807 // Restore machine SP 1808 __ restore_sp_after_call(); 1809 1810 // r0: exception handler entry point 1811 // r3: preserved exception oop 1812 // rbcp: bcp for exception handler 1813 __ push_ptr(r3); // push exception which is now the only value on the stack 1814 __ br(r0); // jump to exception handler (may be _remove_activation_entry!) 1815 1816 // If the exception is not handled in the current frame the frame is 1817 // removed and the exception is rethrown (i.e. exception 1818 // continuation is _rethrow_exception). 1819 // 1820 // Note: At this point the bci is still the bxi for the instruction 1821 // which caused the exception and the expression stack is 1822 // empty. Thus, for any VM calls at this point, GC will find a legal 1823 // oop map (with empty expression stack). 1824 1825 // 1826 // JVMTI PopFrame support 1827 // 1828 1829 Interpreter::_remove_activation_preserving_args_entry = __ pc(); 1830 __ empty_expression_stack(); 1831 // Set the popframe_processing bit in pending_popframe_condition 1832 // indicating that we are currently handling popframe, so that 1833 // call_VMs that may happen later do not trigger new popframe 1834 // handling cycles. 1835 __ ldrw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1836 __ orr(r3, r3, JavaThread::popframe_processing_bit); 1837 __ strw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1838 1839 { 1840 // Check to see whether we are returning to a deoptimized frame. 1841 // (The PopFrame call ensures that the caller of the popped frame is 1842 // either interpreted or compiled and deoptimizes it if compiled.) 1843 // In this case, we can't call dispatch_next() after the frame is 1844 // popped, but instead must save the incoming arguments and restore 1845 // them after deoptimization has occurred. 1846 // 1847 // Note that we don't compare the return PC against the 1848 // deoptimization blob's unpack entry because of the presence of 1849 // adapter frames in C2. 1850 Label caller_not_deoptimized; 1851 __ ldr(c_rarg1, Address(rfp, frame::return_addr_offset * wordSize)); 1852 // This is a return address, so requires authenticating for PAC. 1853 __ authenticate_return_address(c_rarg1); 1854 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1855 InterpreterRuntime::interpreter_contains), c_rarg1); 1856 __ cbnz(r0, caller_not_deoptimized); 1857 1858 // Compute size of arguments for saving when returning to 1859 // deoptimized caller 1860 __ get_method(r0); 1861 __ ldr(r0, Address(r0, Method::const_offset())); 1862 __ load_unsigned_short(r0, Address(r0, in_bytes(ConstMethod:: 1863 size_of_parameters_offset()))); 1864 __ lsl(r0, r0, Interpreter::logStackElementSize); 1865 __ restore_locals(); // XXX do we need this? 1866 __ sub(rlocals, rlocals, r0); 1867 __ add(rlocals, rlocals, wordSize); 1868 // Save these arguments 1869 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1870 Deoptimization:: 1871 popframe_preserve_args), 1872 rthread, r0, rlocals); 1873 1874 __ remove_activation(vtos, 1875 /* throw_monitor_exception */ false, 1876 /* install_monitor_exception */ false, 1877 /* notify_jvmdi */ false); 1878 1879 // Inform deoptimization that it is responsible for restoring 1880 // these arguments 1881 __ mov(rscratch1, JavaThread::popframe_force_deopt_reexecution_bit); 1882 __ strw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset())); 1883 1884 // Continue in deoptimization handler 1885 __ ret(lr); 1886 1887 __ bind(caller_not_deoptimized); 1888 } 1889 1890 __ remove_activation(vtos, 1891 /* throw_monitor_exception */ false, 1892 /* install_monitor_exception */ false, 1893 /* notify_jvmdi */ false); 1894 1895 // Restore the last_sp and null it out 1896 __ ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1897 __ lea(esp, Address(rfp, rscratch1, Address::lsl(Interpreter::logStackElementSize))); 1898 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1899 1900 __ restore_bcp(); 1901 __ restore_locals(); 1902 __ restore_constant_pool_cache(); 1903 __ get_method(rmethod); 1904 __ get_dispatch(); 1905 1906 // The method data pointer was incremented already during 1907 // call profiling. We have to restore the mdp for the current bcp. 1908 if (ProfileInterpreter) { 1909 __ set_method_data_pointer_for_bcp(); 1910 } 1911 1912 // Clear the popframe condition flag 1913 __ strw(zr, Address(rthread, JavaThread::popframe_condition_offset())); 1914 assert(JavaThread::popframe_inactive == 0, "fix popframe_inactive"); 1915 1916 #if INCLUDE_JVMTI 1917 { 1918 Label L_done; 1919 1920 __ ldrb(rscratch1, Address(rbcp, 0)); 1921 __ cmpw(rscratch1, Bytecodes::_invokestatic); 1922 __ br(Assembler::NE, L_done); 1923 1924 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. 1925 // Detect such a case in the InterpreterRuntime function and return the member name argument, or null. 1926 1927 __ ldr(c_rarg0, Address(rlocals, 0)); 1928 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), c_rarg0, rmethod, rbcp); 1929 1930 __ cbz(r0, L_done); 1931 1932 __ str(r0, Address(esp, 0)); 1933 __ bind(L_done); 1934 } 1935 #endif // INCLUDE_JVMTI 1936 1937 // Restore machine SP 1938 __ restore_sp_after_call(); 1939 1940 __ dispatch_next(vtos); 1941 // end of PopFrame support 1942 1943 Interpreter::_remove_activation_entry = __ pc(); 1944 1945 // preserve exception over this code sequence 1946 __ pop_ptr(r0); 1947 __ str(r0, Address(rthread, JavaThread::vm_result_offset())); 1948 // remove the activation (without doing throws on illegalMonitorExceptions) 1949 __ remove_activation(vtos, false, true, false); 1950 // restore exception 1951 __ get_vm_result(r0, rthread); 1952 1953 // In between activations - previous activation type unknown yet 1954 // compute continuation point - the continuation point expects the 1955 // following registers set up: 1956 // 1957 // r0: exception 1958 // lr: return address/pc that threw exception 1959 // esp: expression stack of caller 1960 // rfp: fp of caller 1961 __ stp(r0, lr, Address(__ pre(sp, -2 * wordSize))); // save exception & return address 1962 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1963 SharedRuntime::exception_handler_for_return_address), 1964 rthread, lr); 1965 __ mov(r1, r0); // save exception handler 1966 __ ldp(r0, lr, Address(__ post(sp, 2 * wordSize))); // restore exception & return address 1967 // We might be returning to a deopt handler that expects r3 to 1968 // contain the exception pc 1969 __ mov(r3, lr); 1970 // Note that an "issuing PC" is actually the next PC after the call 1971 __ br(r1); // jump to exception 1972 // handler of caller 1973 } 1974 1975 1976 // 1977 // JVMTI ForceEarlyReturn support 1978 // 1979 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { 1980 address entry = __ pc(); 1981 1982 __ restore_bcp(); 1983 __ restore_locals(); 1984 __ empty_expression_stack(); 1985 __ load_earlyret_value(state); 1986 1987 __ ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset())); 1988 Address cond_addr(rscratch1, JvmtiThreadState::earlyret_state_offset()); 1989 1990 // Clear the earlyret state 1991 assert(JvmtiThreadState::earlyret_inactive == 0, "should be"); 1992 __ str(zr, cond_addr); 1993 1994 __ remove_activation(state, 1995 false, /* throw_monitor_exception */ 1996 false, /* install_monitor_exception */ 1997 true); /* notify_jvmdi */ 1998 __ ret(lr); 1999 2000 return entry; 2001 } // end of ForceEarlyReturn support 2002 2003 2004 2005 //----------------------------------------------------------------------------- 2006 // Helper for vtos entry point generation 2007 2008 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, 2009 address& bep, 2010 address& cep, 2011 address& sep, 2012 address& aep, 2013 address& iep, 2014 address& lep, 2015 address& fep, 2016 address& dep, 2017 address& vep) { 2018 assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 2019 Label L; 2020 aep = __ pc(); __ push_ptr(); __ b(L); 2021 fep = __ pc(); __ push_f(); __ b(L); 2022 dep = __ pc(); __ push_d(); __ b(L); 2023 lep = __ pc(); __ push_l(); __ b(L); 2024 bep = cep = sep = 2025 iep = __ pc(); __ push_i(); 2026 vep = __ pc(); 2027 __ bind(L); 2028 generate_and_dispatch(t); 2029 } 2030 2031 //----------------------------------------------------------------------------- 2032 2033 // Non-product code 2034 #ifndef PRODUCT 2035 address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 2036 address entry = __ pc(); 2037 2038 __ protect_return_address(); 2039 __ push(lr); 2040 __ push(state); 2041 __ push(RegSet::range(r0, r15), sp); 2042 __ mov(c_rarg2, r0); // Pass itos 2043 __ call_VM(noreg, 2044 CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), 2045 c_rarg1, c_rarg2, c_rarg3); 2046 __ pop(RegSet::range(r0, r15), sp); 2047 __ pop(state); 2048 __ pop(lr); 2049 __ authenticate_return_address(); 2050 __ ret(lr); // return from result handler 2051 2052 return entry; 2053 } 2054 2055 void TemplateInterpreterGenerator::count_bytecode() { 2056 __ mov(r10, (address) &BytecodeCounter::_counter_value); 2057 __ atomic_addw(noreg, 1, r10); 2058 } 2059 2060 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { 2061 __ mov(r10, (address) &BytecodeHistogram::_counters[t->bytecode()]); 2062 __ atomic_addw(noreg, 1, r10); 2063 } 2064 2065 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { 2066 // Calculate new index for counter: 2067 // _index = (_index >> log2_number_of_codes) | 2068 // (bytecode << log2_number_of_codes); 2069 Register index_addr = rscratch1; 2070 Register index = rscratch2; 2071 __ mov(index_addr, (address) &BytecodePairHistogram::_index); 2072 __ ldrw(index, index_addr); 2073 __ mov(r10, 2074 ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes); 2075 __ orrw(index, r10, index, Assembler::LSR, 2076 BytecodePairHistogram::log2_number_of_codes); 2077 __ strw(index, index_addr); 2078 2079 // Bump bucket contents: 2080 // _counters[_index] ++; 2081 Register counter_addr = rscratch1; 2082 __ mov(r10, (address) &BytecodePairHistogram::_counters); 2083 __ lea(counter_addr, Address(r10, index, Address::lsl(LogBytesPerInt))); 2084 __ atomic_addw(noreg, 1, counter_addr); 2085 } 2086 2087 void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 2088 // Call a little run-time stub to avoid blow-up for each bytecode. 2089 // The run-time runtime saves the right registers, depending on 2090 // the tosca in-state for the given template. 2091 2092 assert(Interpreter::trace_code(t->tos_in()) != nullptr, 2093 "entry must have been generated"); 2094 __ bl(Interpreter::trace_code(t->tos_in())); 2095 __ reinit_heapbase(); 2096 } 2097 2098 2099 void TemplateInterpreterGenerator::stop_interpreter_at() { 2100 Label L; 2101 __ push(rscratch1); 2102 __ mov(rscratch1, (address) &BytecodeCounter::_counter_value); 2103 __ ldr(rscratch1, Address(rscratch1)); 2104 __ mov(rscratch2, StopInterpreterAt); 2105 __ cmpw(rscratch1, rscratch2); 2106 __ br(Assembler::NE, L); 2107 __ brk(0); 2108 __ bind(L); 2109 __ pop(rscratch1); 2110 } 2111 2112 #endif // !PRODUCT