1 /* 2 * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved. 4 * Copyright (c) 2021, Azul Systems, Inc. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 * 25 */ 26 27 #include "precompiled.hpp" 28 #include "asm/macroAssembler.hpp" 29 #include "asm/macroAssembler.inline.hpp" 30 #include "code/codeCache.hpp" 31 #include "code/compiledIC.hpp" 32 #include "code/debugInfoRec.hpp" 33 #include "code/vtableStubs.hpp" 34 #include "compiler/oopMap.hpp" 35 #include "gc/shared/barrierSetAssembler.hpp" 36 #include "interpreter/interpreter.hpp" 37 #include "interpreter/interp_masm.hpp" 38 #include "logging/log.hpp" 39 #include "memory/resourceArea.hpp" 40 #include "nativeInst_aarch64.hpp" 41 #include "oops/klass.inline.hpp" 42 #include "oops/method.inline.hpp" 43 #include "prims/methodHandles.hpp" 44 #include "runtime/continuation.hpp" 45 #include "runtime/continuationEntry.inline.hpp" 46 #include "runtime/globals.hpp" 47 #include "runtime/jniHandles.hpp" 48 #include "runtime/safepointMechanism.hpp" 49 #include "runtime/sharedRuntime.hpp" 50 #include "runtime/signature.hpp" 51 #include "runtime/stubRoutines.hpp" 52 #include "runtime/vframeArray.hpp" 53 #include "utilities/align.hpp" 54 #include "utilities/formatBuffer.hpp" 55 #include "vmreg_aarch64.inline.hpp" 56 #ifdef COMPILER1 57 #include "c1/c1_Runtime1.hpp" 58 #endif 59 #ifdef COMPILER2 60 #include "adfiles/ad_aarch64.hpp" 61 #include "opto/runtime.hpp" 62 #endif 63 #if INCLUDE_JVMCI 64 #include "jvmci/jvmciJavaClasses.hpp" 65 #endif 66 67 #define __ masm-> 68 69 #ifdef PRODUCT 70 #define BLOCK_COMMENT(str) /* nothing */ 71 #else 72 #define BLOCK_COMMENT(str) __ block_comment(str) 73 #endif 74 75 const int StackAlignmentInSlots = StackAlignmentInBytes / VMRegImpl::stack_slot_size; 76 77 // FIXME -- this is used by C1 78 class RegisterSaver { 79 const bool _save_vectors; 80 public: 81 RegisterSaver(bool save_vectors) : _save_vectors(save_vectors) {} 82 83 OopMap* save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words); 84 void restore_live_registers(MacroAssembler* masm); 85 86 // Offsets into the register save area 87 // Used by deoptimization when it is managing result register 88 // values on its own 89 90 int reg_offset_in_bytes(Register r); 91 int r0_offset_in_bytes() { return reg_offset_in_bytes(r0); } 92 int rscratch1_offset_in_bytes() { return reg_offset_in_bytes(rscratch1); } 93 int v0_offset_in_bytes(); 94 95 // Total stack size in bytes for saving sve predicate registers. 96 int total_sve_predicate_in_bytes(); 97 98 // Capture info about frame layout 99 // Note this is only correct when not saving full vectors. 100 enum layout { 101 fpu_state_off = 0, 102 fpu_state_end = fpu_state_off + FPUStateSizeInWords - 1, 103 // The frame sender code expects that rfp will be in 104 // the "natural" place and will override any oopMap 105 // setting for it. We must therefore force the layout 106 // so that it agrees with the frame sender code. 107 r0_off = fpu_state_off + FPUStateSizeInWords, 108 rfp_off = r0_off + (Register::number_of_registers - 2) * Register::max_slots_per_register, 109 return_off = rfp_off + Register::max_slots_per_register, // slot for return address 110 reg_save_size = return_off + Register::max_slots_per_register}; 111 112 }; 113 114 int RegisterSaver::reg_offset_in_bytes(Register r) { 115 // The integer registers are located above the floating point 116 // registers in the stack frame pushed by save_live_registers() so the 117 // offset depends on whether we are saving full vectors, and whether 118 // those vectors are NEON or SVE. 119 120 int slots_per_vect = FloatRegister::save_slots_per_register; 121 122 #if COMPILER2_OR_JVMCI 123 if (_save_vectors) { 124 slots_per_vect = FloatRegister::slots_per_neon_register; 125 126 #ifdef COMPILER2 127 if (Matcher::supports_scalable_vector()) { 128 slots_per_vect = Matcher::scalable_vector_reg_size(T_FLOAT); 129 } 130 #endif 131 } 132 #endif 133 134 int r0_offset = v0_offset_in_bytes() + (slots_per_vect * FloatRegister::number_of_registers) * BytesPerInt; 135 return r0_offset + r->encoding() * wordSize; 136 } 137 138 int RegisterSaver::v0_offset_in_bytes() { 139 // The floating point registers are located above the predicate registers if 140 // they are present in the stack frame pushed by save_live_registers(). So the 141 // offset depends on the saved total predicate vectors in the stack frame. 142 return (total_sve_predicate_in_bytes() / VMRegImpl::stack_slot_size) * BytesPerInt; 143 } 144 145 int RegisterSaver::total_sve_predicate_in_bytes() { 146 #ifdef COMPILER2 147 if (_save_vectors && Matcher::supports_scalable_vector()) { 148 return (Matcher::scalable_vector_reg_size(T_BYTE) >> LogBitsPerByte) * 149 PRegister::number_of_registers; 150 } 151 #endif 152 return 0; 153 } 154 155 OopMap* RegisterSaver::save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words) { 156 bool use_sve = false; 157 int sve_vector_size_in_bytes = 0; 158 int sve_vector_size_in_slots = 0; 159 int sve_predicate_size_in_slots = 0; 160 int total_predicate_in_bytes = total_sve_predicate_in_bytes(); 161 int total_predicate_in_slots = total_predicate_in_bytes / VMRegImpl::stack_slot_size; 162 163 #ifdef COMPILER2 164 use_sve = Matcher::supports_scalable_vector(); 165 if (use_sve) { 166 sve_vector_size_in_bytes = Matcher::scalable_vector_reg_size(T_BYTE); 167 sve_vector_size_in_slots = Matcher::scalable_vector_reg_size(T_FLOAT); 168 sve_predicate_size_in_slots = Matcher::scalable_predicate_reg_slots(); 169 } 170 #endif 171 172 #if COMPILER2_OR_JVMCI 173 if (_save_vectors) { 174 int extra_save_slots_per_register = 0; 175 // Save upper half of vector registers 176 if (use_sve) { 177 extra_save_slots_per_register = sve_vector_size_in_slots - FloatRegister::save_slots_per_register; 178 } else { 179 extra_save_slots_per_register = FloatRegister::extra_save_slots_per_neon_register; 180 } 181 int extra_vector_bytes = extra_save_slots_per_register * 182 VMRegImpl::stack_slot_size * 183 FloatRegister::number_of_registers; 184 additional_frame_words += ((extra_vector_bytes + total_predicate_in_bytes) / wordSize); 185 } 186 #else 187 assert(!_save_vectors, "vectors are generated only by C2 and JVMCI"); 188 #endif 189 190 int frame_size_in_bytes = align_up(additional_frame_words * wordSize + 191 reg_save_size * BytesPerInt, 16); 192 // OopMap frame size is in compiler stack slots (jint's) not bytes or words 193 int frame_size_in_slots = frame_size_in_bytes / BytesPerInt; 194 // The caller will allocate additional_frame_words 195 int additional_frame_slots = additional_frame_words * wordSize / BytesPerInt; 196 // CodeBlob frame size is in words. 197 int frame_size_in_words = frame_size_in_bytes / wordSize; 198 *total_frame_words = frame_size_in_words; 199 200 // Save Integer and Float registers. 201 __ enter(); 202 __ push_CPU_state(_save_vectors, use_sve, sve_vector_size_in_bytes, total_predicate_in_bytes); 203 204 // Set an oopmap for the call site. This oopmap will map all 205 // oop-registers and debug-info registers as callee-saved. This 206 // will allow deoptimization at this safepoint to find all possible 207 // debug-info recordings, as well as let GC find all oops. 208 209 OopMapSet *oop_maps = new OopMapSet(); 210 OopMap* oop_map = new OopMap(frame_size_in_slots, 0); 211 212 for (int i = 0; i < Register::number_of_registers; i++) { 213 Register r = as_Register(i); 214 if (i <= rfp->encoding() && r != rscratch1 && r != rscratch2) { 215 // SP offsets are in 4-byte words. 216 // Register slots are 8 bytes wide, 32 floating-point registers. 217 int sp_offset = Register::max_slots_per_register * i + 218 FloatRegister::save_slots_per_register * FloatRegister::number_of_registers; 219 oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset + additional_frame_slots), r->as_VMReg()); 220 } 221 } 222 223 for (int i = 0; i < FloatRegister::number_of_registers; i++) { 224 FloatRegister r = as_FloatRegister(i); 225 int sp_offset = 0; 226 if (_save_vectors) { 227 sp_offset = use_sve ? (total_predicate_in_slots + sve_vector_size_in_slots * i) : 228 (FloatRegister::slots_per_neon_register * i); 229 } else { 230 sp_offset = FloatRegister::save_slots_per_register * i; 231 } 232 oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset), r->as_VMReg()); 233 } 234 235 return oop_map; 236 } 237 238 void RegisterSaver::restore_live_registers(MacroAssembler* masm) { 239 #ifdef COMPILER2 240 __ pop_CPU_state(_save_vectors, Matcher::supports_scalable_vector(), 241 Matcher::scalable_vector_reg_size(T_BYTE), total_sve_predicate_in_bytes()); 242 #else 243 #if !INCLUDE_JVMCI 244 assert(!_save_vectors, "vectors are generated only by C2 and JVMCI"); 245 #endif 246 __ pop_CPU_state(_save_vectors); 247 #endif 248 __ ldp(rfp, lr, Address(__ post(sp, 2 * wordSize))); 249 __ authenticate_return_address(); 250 } 251 252 // Is vector's size (in bytes) bigger than a size saved by default? 253 // 8 bytes vector registers are saved by default on AArch64. 254 // The SVE supported min vector size is 8 bytes and we need to save 255 // predicate registers when the vector size is 8 bytes as well. 256 bool SharedRuntime::is_wide_vector(int size) { 257 return size > 8 || (UseSVE > 0 && size >= 8); 258 } 259 260 // --------------------------------------------------------------------------- 261 // Read the array of BasicTypes from a signature, and compute where the 262 // arguments should go. Values in the VMRegPair regs array refer to 4-byte 263 // quantities. Values less than VMRegImpl::stack0 are registers, those above 264 // refer to 4-byte stack slots. All stack slots are based off of the stack pointer 265 // as framesizes are fixed. 266 // VMRegImpl::stack0 refers to the first slot 0(sp). 267 // and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. 268 // Register up to Register::number_of_registers are the 64-bit 269 // integer registers. 270 271 // Note: the INPUTS in sig_bt are in units of Java argument words, 272 // which are 64-bit. The OUTPUTS are in 32-bit units. 273 274 // The Java calling convention is a "shifted" version of the C ABI. 275 // By skipping the first C ABI register we can call non-static jni 276 // methods with small numbers of arguments without having to shuffle 277 // the arguments at all. Since we control the java ABI we ought to at 278 // least get some advantage out of it. 279 280 int SharedRuntime::java_calling_convention(const BasicType *sig_bt, 281 VMRegPair *regs, 282 int total_args_passed) { 283 284 // Create the mapping between argument positions and 285 // registers. 286 static const Register INT_ArgReg[Argument::n_int_register_parameters_j] = { 287 j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5, j_rarg6, j_rarg7 288 }; 289 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters_j] = { 290 j_farg0, j_farg1, j_farg2, j_farg3, 291 j_farg4, j_farg5, j_farg6, j_farg7 292 }; 293 294 295 uint int_args = 0; 296 uint fp_args = 0; 297 uint stk_args = 0; 298 299 for (int i = 0; i < total_args_passed; i++) { 300 switch (sig_bt[i]) { 301 case T_BOOLEAN: 302 case T_CHAR: 303 case T_BYTE: 304 case T_SHORT: 305 case T_INT: 306 if (int_args < Argument::n_int_register_parameters_j) { 307 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg()); 308 } else { 309 stk_args = align_up(stk_args, 2); 310 regs[i].set1(VMRegImpl::stack2reg(stk_args)); 311 stk_args += 1; 312 } 313 break; 314 case T_VOID: 315 // halves of T_LONG or T_DOUBLE 316 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half"); 317 regs[i].set_bad(); 318 break; 319 case T_LONG: 320 assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half"); 321 // fall through 322 case T_OBJECT: 323 case T_ARRAY: 324 case T_ADDRESS: 325 if (int_args < Argument::n_int_register_parameters_j) { 326 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg()); 327 } else { 328 stk_args = align_up(stk_args, 2); 329 regs[i].set2(VMRegImpl::stack2reg(stk_args)); 330 stk_args += 2; 331 } 332 break; 333 case T_FLOAT: 334 if (fp_args < Argument::n_float_register_parameters_j) { 335 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg()); 336 } else { 337 stk_args = align_up(stk_args, 2); 338 regs[i].set1(VMRegImpl::stack2reg(stk_args)); 339 stk_args += 1; 340 } 341 break; 342 case T_DOUBLE: 343 assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half"); 344 if (fp_args < Argument::n_float_register_parameters_j) { 345 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg()); 346 } else { 347 stk_args = align_up(stk_args, 2); 348 regs[i].set2(VMRegImpl::stack2reg(stk_args)); 349 stk_args += 2; 350 } 351 break; 352 default: 353 ShouldNotReachHere(); 354 break; 355 } 356 } 357 358 return stk_args; 359 } 360 361 // Patch the callers callsite with entry to compiled code if it exists. 362 static void patch_callers_callsite(MacroAssembler *masm) { 363 Label L; 364 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::code_offset()))); 365 __ cbz(rscratch1, L); 366 367 __ enter(); 368 __ push_CPU_state(); 369 370 // VM needs caller's callsite 371 // VM needs target method 372 // This needs to be a long call since we will relocate this adapter to 373 // the codeBuffer and it may not reach 374 375 #ifndef PRODUCT 376 assert(frame::arg_reg_save_area_bytes == 0, "not expecting frame reg save area"); 377 #endif 378 379 __ mov(c_rarg0, rmethod); 380 __ mov(c_rarg1, lr); 381 __ authenticate_return_address(c_rarg1); 382 __ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite))); 383 __ blr(rscratch1); 384 385 // Explicit isb required because fixup_callers_callsite may change the code 386 // stream. 387 __ safepoint_isb(); 388 389 __ pop_CPU_state(); 390 // restore sp 391 __ leave(); 392 __ bind(L); 393 } 394 395 static void gen_c2i_adapter(MacroAssembler *masm, 396 int total_args_passed, 397 int comp_args_on_stack, 398 const BasicType *sig_bt, 399 const VMRegPair *regs, 400 Label& skip_fixup) { 401 // Before we get into the guts of the C2I adapter, see if we should be here 402 // at all. We've come from compiled code and are attempting to jump to the 403 // interpreter, which means the caller made a static call to get here 404 // (vcalls always get a compiled target if there is one). Check for a 405 // compiled target. If there is one, we need to patch the caller's call. 406 patch_callers_callsite(masm); 407 408 __ bind(skip_fixup); 409 410 int words_pushed = 0; 411 412 // Since all args are passed on the stack, total_args_passed * 413 // Interpreter::stackElementSize is the space we need. 414 415 int extraspace = total_args_passed * Interpreter::stackElementSize; 416 417 __ mov(r19_sender_sp, sp); 418 419 // stack is aligned, keep it that way 420 extraspace = align_up(extraspace, 2*wordSize); 421 422 if (extraspace) 423 __ sub(sp, sp, extraspace); 424 425 // Now write the args into the outgoing interpreter space 426 for (int i = 0; i < total_args_passed; i++) { 427 if (sig_bt[i] == T_VOID) { 428 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half"); 429 continue; 430 } 431 432 // offset to start parameters 433 int st_off = (total_args_passed - i - 1) * Interpreter::stackElementSize; 434 int next_off = st_off - Interpreter::stackElementSize; 435 436 // Say 4 args: 437 // i st_off 438 // 0 32 T_LONG 439 // 1 24 T_VOID 440 // 2 16 T_OBJECT 441 // 3 8 T_BOOL 442 // - 0 return address 443 // 444 // However to make thing extra confusing. Because we can fit a Java long/double in 445 // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter 446 // leaves one slot empty and only stores to a single slot. In this case the 447 // slot that is occupied is the T_VOID slot. See I said it was confusing. 448 449 VMReg r_1 = regs[i].first(); 450 VMReg r_2 = regs[i].second(); 451 if (!r_1->is_valid()) { 452 assert(!r_2->is_valid(), ""); 453 continue; 454 } 455 if (r_1->is_stack()) { 456 // memory to memory use rscratch1 457 int ld_off = (r_1->reg2stack() * VMRegImpl::stack_slot_size 458 + extraspace 459 + words_pushed * wordSize); 460 if (!r_2->is_valid()) { 461 // sign extend?? 462 __ ldrw(rscratch1, Address(sp, ld_off)); 463 __ str(rscratch1, Address(sp, st_off)); 464 465 } else { 466 467 __ ldr(rscratch1, Address(sp, ld_off)); 468 469 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG 470 // T_DOUBLE and T_LONG use two slots in the interpreter 471 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { 472 // ld_off == LSW, ld_off+wordSize == MSW 473 // st_off == MSW, next_off == LSW 474 __ str(rscratch1, Address(sp, next_off)); 475 #ifdef ASSERT 476 // Overwrite the unused slot with known junk 477 __ mov(rscratch1, (uint64_t)0xdeadffffdeadaaaaull); 478 __ str(rscratch1, Address(sp, st_off)); 479 #endif /* ASSERT */ 480 } else { 481 __ str(rscratch1, Address(sp, st_off)); 482 } 483 } 484 } else if (r_1->is_Register()) { 485 Register r = r_1->as_Register(); 486 if (!r_2->is_valid()) { 487 // must be only an int (or less ) so move only 32bits to slot 488 // why not sign extend?? 489 __ str(r, Address(sp, st_off)); 490 } else { 491 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG 492 // T_DOUBLE and T_LONG use two slots in the interpreter 493 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { 494 // jlong/double in gpr 495 #ifdef ASSERT 496 // Overwrite the unused slot with known junk 497 __ mov(rscratch1, (uint64_t)0xdeadffffdeadaaabull); 498 __ str(rscratch1, Address(sp, st_off)); 499 #endif /* ASSERT */ 500 __ str(r, Address(sp, next_off)); 501 } else { 502 __ str(r, Address(sp, st_off)); 503 } 504 } 505 } else { 506 assert(r_1->is_FloatRegister(), ""); 507 if (!r_2->is_valid()) { 508 // only a float use just part of the slot 509 __ strs(r_1->as_FloatRegister(), Address(sp, st_off)); 510 } else { 511 #ifdef ASSERT 512 // Overwrite the unused slot with known junk 513 __ mov(rscratch1, (uint64_t)0xdeadffffdeadaaacull); 514 __ str(rscratch1, Address(sp, st_off)); 515 #endif /* ASSERT */ 516 __ strd(r_1->as_FloatRegister(), Address(sp, next_off)); 517 } 518 } 519 } 520 521 __ mov(esp, sp); // Interp expects args on caller's expression stack 522 523 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::interpreter_entry_offset()))); 524 __ br(rscratch1); 525 } 526 527 528 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm, 529 int total_args_passed, 530 int comp_args_on_stack, 531 const BasicType *sig_bt, 532 const VMRegPair *regs) { 533 534 // Note: r19_sender_sp contains the senderSP on entry. We must 535 // preserve it since we may do a i2c -> c2i transition if we lose a 536 // race where compiled code goes non-entrant while we get args 537 // ready. 538 539 // Adapters are frameless. 540 541 // An i2c adapter is frameless because the *caller* frame, which is 542 // interpreted, routinely repairs its own esp (from 543 // interpreter_frame_last_sp), even if a callee has modified the 544 // stack pointer. It also recalculates and aligns sp. 545 546 // A c2i adapter is frameless because the *callee* frame, which is 547 // interpreted, routinely repairs its caller's sp (from sender_sp, 548 // which is set up via the senderSP register). 549 550 // In other words, if *either* the caller or callee is interpreted, we can 551 // get the stack pointer repaired after a call. 552 553 // This is why c2i and i2c adapters cannot be indefinitely composed. 554 // In particular, if a c2i adapter were to somehow call an i2c adapter, 555 // both caller and callee would be compiled methods, and neither would 556 // clean up the stack pointer changes performed by the two adapters. 557 // If this happens, control eventually transfers back to the compiled 558 // caller, but with an uncorrected stack, causing delayed havoc. 559 560 if (VerifyAdapterCalls && 561 (Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) { 562 #if 0 563 // So, let's test for cascading c2i/i2c adapters right now. 564 // assert(Interpreter::contains($return_addr) || 565 // StubRoutines::contains($return_addr), 566 // "i2c adapter must return to an interpreter frame"); 567 __ block_comment("verify_i2c { "); 568 Label L_ok; 569 if (Interpreter::code() != nullptr) { 570 range_check(masm, rax, r11, 571 Interpreter::code()->code_start(), Interpreter::code()->code_end(), 572 L_ok); 573 } 574 if (StubRoutines::initial_stubs_code() != nullptr) { 575 range_check(masm, rax, r11, 576 StubRoutines::initial_stubs_code()->code_begin(), 577 StubRoutines::initial_stubs_code()->code_end(), 578 L_ok); 579 } 580 if (StubRoutines::final_stubs_code() != nullptr) { 581 range_check(masm, rax, r11, 582 StubRoutines::final_stubs_code()->code_begin(), 583 StubRoutines::final_stubs_code()->code_end(), 584 L_ok); 585 } 586 const char* msg = "i2c adapter must return to an interpreter frame"; 587 __ block_comment(msg); 588 __ stop(msg); 589 __ bind(L_ok); 590 __ block_comment("} verify_i2ce "); 591 #endif 592 } 593 594 // Cut-out for having no stack args. 595 int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord; 596 if (comp_args_on_stack) { 597 __ sub(rscratch1, sp, comp_words_on_stack * wordSize); 598 __ andr(sp, rscratch1, -16); 599 } 600 601 // Will jump to the compiled code just as if compiled code was doing it. 602 // Pre-load the register-jump target early, to schedule it better. 603 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::from_compiled_offset()))); 604 605 #if INCLUDE_JVMCI 606 if (EnableJVMCI) { 607 // check if this call should be routed towards a specific entry point 608 __ ldr(rscratch2, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset()))); 609 Label no_alternative_target; 610 __ cbz(rscratch2, no_alternative_target); 611 __ mov(rscratch1, rscratch2); 612 __ str(zr, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset()))); 613 __ bind(no_alternative_target); 614 } 615 #endif // INCLUDE_JVMCI 616 617 // Now generate the shuffle code. 618 for (int i = 0; i < total_args_passed; i++) { 619 if (sig_bt[i] == T_VOID) { 620 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half"); 621 continue; 622 } 623 624 // Pick up 0, 1 or 2 words from SP+offset. 625 626 assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(), 627 "scrambled load targets?"); 628 // Load in argument order going down. 629 int ld_off = (total_args_passed - i - 1)*Interpreter::stackElementSize; 630 // Point to interpreter value (vs. tag) 631 int next_off = ld_off - Interpreter::stackElementSize; 632 // 633 // 634 // 635 VMReg r_1 = regs[i].first(); 636 VMReg r_2 = regs[i].second(); 637 if (!r_1->is_valid()) { 638 assert(!r_2->is_valid(), ""); 639 continue; 640 } 641 if (r_1->is_stack()) { 642 // Convert stack slot to an SP offset (+ wordSize to account for return address ) 643 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size; 644 if (!r_2->is_valid()) { 645 // sign extend??? 646 __ ldrsw(rscratch2, Address(esp, ld_off)); 647 __ str(rscratch2, Address(sp, st_off)); 648 } else { 649 // 650 // We are using two optoregs. This can be either T_OBJECT, 651 // T_ADDRESS, T_LONG, or T_DOUBLE the interpreter allocates 652 // two slots but only uses one for thr T_LONG or T_DOUBLE case 653 // So we must adjust where to pick up the data to match the 654 // interpreter. 655 // 656 // Interpreter local[n] == MSW, local[n+1] == LSW however locals 657 // are accessed as negative so LSW is at LOW address 658 659 // ld_off is MSW so get LSW 660 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)? 661 next_off : ld_off; 662 __ ldr(rscratch2, Address(esp, offset)); 663 // st_off is LSW (i.e. reg.first()) 664 __ str(rscratch2, Address(sp, st_off)); 665 } 666 } else if (r_1->is_Register()) { // Register argument 667 Register r = r_1->as_Register(); 668 if (r_2->is_valid()) { 669 // 670 // We are using two VMRegs. This can be either T_OBJECT, 671 // T_ADDRESS, T_LONG, or T_DOUBLE the interpreter allocates 672 // two slots but only uses one for thr T_LONG or T_DOUBLE case 673 // So we must adjust where to pick up the data to match the 674 // interpreter. 675 676 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)? 677 next_off : ld_off; 678 679 // this can be a misaligned move 680 __ ldr(r, Address(esp, offset)); 681 } else { 682 // sign extend and use a full word? 683 __ ldrw(r, Address(esp, ld_off)); 684 } 685 } else { 686 if (!r_2->is_valid()) { 687 __ ldrs(r_1->as_FloatRegister(), Address(esp, ld_off)); 688 } else { 689 __ ldrd(r_1->as_FloatRegister(), Address(esp, next_off)); 690 } 691 } 692 } 693 694 __ mov(rscratch2, rscratch1); 695 __ push_cont_fastpath(rthread); // Set JavaThread::_cont_fastpath to the sp of the oldest interpreted frame we know about; kills rscratch1 696 __ mov(rscratch1, rscratch2); 697 698 // 6243940 We might end up in handle_wrong_method if 699 // the callee is deoptimized as we race thru here. If that 700 // happens we don't want to take a safepoint because the 701 // caller frame will look interpreted and arguments are now 702 // "compiled" so it is much better to make this transition 703 // invisible to the stack walking code. Unfortunately if 704 // we try and find the callee by normal means a safepoint 705 // is possible. So we stash the desired callee in the thread 706 // and the vm will find there should this case occur. 707 708 __ str(rmethod, Address(rthread, JavaThread::callee_target_offset())); 709 710 __ br(rscratch1); 711 } 712 713 // --------------------------------------------------------------- 714 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm, 715 int total_args_passed, 716 int comp_args_on_stack, 717 const BasicType *sig_bt, 718 const VMRegPair *regs, 719 AdapterFingerPrint* fingerprint) { 720 address i2c_entry = __ pc(); 721 722 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs); 723 724 address c2i_unverified_entry = __ pc(); 725 Label skip_fixup; 726 727 Register data = rscratch2; 728 Register receiver = j_rarg0; 729 Register tmp = r10; // A call-clobbered register not used for arg passing 730 731 // ------------------------------------------------------------------------- 732 // Generate a C2I adapter. On entry we know rmethod holds the Method* during calls 733 // to the interpreter. The args start out packed in the compiled layout. They 734 // need to be unpacked into the interpreter layout. This will almost always 735 // require some stack space. We grow the current (compiled) stack, then repack 736 // the args. We finally end in a jump to the generic interpreter entry point. 737 // On exit from the interpreter, the interpreter will restore our SP (lest the 738 // compiled code, which relies solely on SP and not FP, get sick). 739 740 { 741 __ block_comment("c2i_unverified_entry {"); 742 // Method might have been compiled since the call site was patched to 743 // interpreted; if that is the case treat it as a miss so we can get 744 // the call site corrected. 745 __ ic_check(1 /* end_alignment */); 746 __ ldr(rmethod, Address(data, CompiledICData::speculated_method_offset())); 747 748 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::code_offset()))); 749 __ cbz(rscratch1, skip_fixup); 750 __ far_jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub())); 751 __ block_comment("} c2i_unverified_entry"); 752 } 753 754 address c2i_entry = __ pc(); 755 756 // Class initialization barrier for static methods 757 address c2i_no_clinit_check_entry = nullptr; 758 if (VM_Version::supports_fast_class_init_checks()) { 759 Label L_skip_barrier; 760 761 { // Bypass the barrier for non-static methods 762 __ ldrw(rscratch1, Address(rmethod, Method::access_flags_offset())); 763 __ andsw(zr, rscratch1, JVM_ACC_STATIC); 764 __ br(Assembler::EQ, L_skip_barrier); // non-static 765 } 766 767 __ load_method_holder(rscratch2, rmethod); 768 __ clinit_barrier(rscratch2, rscratch1, &L_skip_barrier); 769 __ far_jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); 770 771 __ bind(L_skip_barrier); 772 c2i_no_clinit_check_entry = __ pc(); 773 } 774 775 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler(); 776 bs->c2i_entry_barrier(masm); 777 778 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup); 779 780 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry); 781 } 782 783 static int c_calling_convention_priv(const BasicType *sig_bt, 784 VMRegPair *regs, 785 int total_args_passed) { 786 787 // We return the amount of VMRegImpl stack slots we need to reserve for all 788 // the arguments NOT counting out_preserve_stack_slots. 789 790 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = { 791 c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5, c_rarg6, c_rarg7 792 }; 793 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters_c] = { 794 c_farg0, c_farg1, c_farg2, c_farg3, 795 c_farg4, c_farg5, c_farg6, c_farg7 796 }; 797 798 uint int_args = 0; 799 uint fp_args = 0; 800 uint stk_args = 0; // inc by 2 each time 801 802 for (int i = 0; i < total_args_passed; i++) { 803 switch (sig_bt[i]) { 804 case T_BOOLEAN: 805 case T_CHAR: 806 case T_BYTE: 807 case T_SHORT: 808 case T_INT: 809 if (int_args < Argument::n_int_register_parameters_c) { 810 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg()); 811 } else { 812 #ifdef __APPLE__ 813 // Less-than word types are stored one after another. 814 // The code is unable to handle this so bailout. 815 return -1; 816 #endif 817 regs[i].set1(VMRegImpl::stack2reg(stk_args)); 818 stk_args += 2; 819 } 820 break; 821 case T_LONG: 822 assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half"); 823 // fall through 824 case T_OBJECT: 825 case T_ARRAY: 826 case T_ADDRESS: 827 case T_METADATA: 828 if (int_args < Argument::n_int_register_parameters_c) { 829 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg()); 830 } else { 831 regs[i].set2(VMRegImpl::stack2reg(stk_args)); 832 stk_args += 2; 833 } 834 break; 835 case T_FLOAT: 836 if (fp_args < Argument::n_float_register_parameters_c) { 837 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg()); 838 } else { 839 #ifdef __APPLE__ 840 // Less-than word types are stored one after another. 841 // The code is unable to handle this so bailout. 842 return -1; 843 #endif 844 regs[i].set1(VMRegImpl::stack2reg(stk_args)); 845 stk_args += 2; 846 } 847 break; 848 case T_DOUBLE: 849 assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half"); 850 if (fp_args < Argument::n_float_register_parameters_c) { 851 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg()); 852 } else { 853 regs[i].set2(VMRegImpl::stack2reg(stk_args)); 854 stk_args += 2; 855 } 856 break; 857 case T_VOID: // Halves of longs and doubles 858 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half"); 859 regs[i].set_bad(); 860 break; 861 default: 862 ShouldNotReachHere(); 863 break; 864 } 865 } 866 867 return stk_args; 868 } 869 870 int SharedRuntime::vector_calling_convention(VMRegPair *regs, 871 uint num_bits, 872 uint total_args_passed) { 873 Unimplemented(); 874 return 0; 875 } 876 877 int SharedRuntime::c_calling_convention(const BasicType *sig_bt, 878 VMRegPair *regs, 879 int total_args_passed) 880 { 881 int result = c_calling_convention_priv(sig_bt, regs, total_args_passed); 882 guarantee(result >= 0, "Unsupported arguments configuration"); 883 return result; 884 } 885 886 887 void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { 888 // We always ignore the frame_slots arg and just use the space just below frame pointer 889 // which by this time is free to use 890 switch (ret_type) { 891 case T_FLOAT: 892 __ strs(v0, Address(rfp, -wordSize)); 893 break; 894 case T_DOUBLE: 895 __ strd(v0, Address(rfp, -wordSize)); 896 break; 897 case T_VOID: break; 898 default: { 899 __ str(r0, Address(rfp, -wordSize)); 900 } 901 } 902 } 903 904 void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { 905 // We always ignore the frame_slots arg and just use the space just below frame pointer 906 // which by this time is free to use 907 switch (ret_type) { 908 case T_FLOAT: 909 __ ldrs(v0, Address(rfp, -wordSize)); 910 break; 911 case T_DOUBLE: 912 __ ldrd(v0, Address(rfp, -wordSize)); 913 break; 914 case T_VOID: break; 915 default: { 916 __ ldr(r0, Address(rfp, -wordSize)); 917 } 918 } 919 } 920 static void save_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) { 921 RegSet x; 922 for ( int i = first_arg ; i < arg_count ; i++ ) { 923 if (args[i].first()->is_Register()) { 924 x = x + args[i].first()->as_Register(); 925 } else if (args[i].first()->is_FloatRegister()) { 926 __ strd(args[i].first()->as_FloatRegister(), Address(__ pre(sp, -2 * wordSize))); 927 } 928 } 929 __ push(x, sp); 930 } 931 932 static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) { 933 RegSet x; 934 for ( int i = first_arg ; i < arg_count ; i++ ) { 935 if (args[i].first()->is_Register()) { 936 x = x + args[i].first()->as_Register(); 937 } else { 938 ; 939 } 940 } 941 __ pop(x, sp); 942 for ( int i = arg_count - 1 ; i >= first_arg ; i-- ) { 943 if (args[i].first()->is_Register()) { 944 ; 945 } else if (args[i].first()->is_FloatRegister()) { 946 __ ldrd(args[i].first()->as_FloatRegister(), Address(__ post(sp, 2 * wordSize))); 947 } 948 } 949 } 950 951 static void verify_oop_args(MacroAssembler* masm, 952 const methodHandle& method, 953 const BasicType* sig_bt, 954 const VMRegPair* regs) { 955 Register temp_reg = r19; // not part of any compiled calling seq 956 if (VerifyOops) { 957 for (int i = 0; i < method->size_of_parameters(); i++) { 958 if (sig_bt[i] == T_OBJECT || 959 sig_bt[i] == T_ARRAY) { 960 VMReg r = regs[i].first(); 961 assert(r->is_valid(), "bad oop arg"); 962 if (r->is_stack()) { 963 __ ldr(temp_reg, Address(sp, r->reg2stack() * VMRegImpl::stack_slot_size)); 964 __ verify_oop(temp_reg); 965 } else { 966 __ verify_oop(r->as_Register()); 967 } 968 } 969 } 970 } 971 } 972 973 // on exit, sp points to the ContinuationEntry 974 static OopMap* continuation_enter_setup(MacroAssembler* masm, int& stack_slots) { 975 assert(ContinuationEntry::size() % VMRegImpl::stack_slot_size == 0, ""); 976 assert(in_bytes(ContinuationEntry::cont_offset()) % VMRegImpl::stack_slot_size == 0, ""); 977 assert(in_bytes(ContinuationEntry::chunk_offset()) % VMRegImpl::stack_slot_size == 0, ""); 978 979 stack_slots += (int)ContinuationEntry::size()/wordSize; 980 __ sub(sp, sp, (int)ContinuationEntry::size()); // place Continuation metadata 981 982 OopMap* map = new OopMap(((int)ContinuationEntry::size() + wordSize)/ VMRegImpl::stack_slot_size, 0 /* arg_slots*/); 983 984 __ ldr(rscratch1, Address(rthread, JavaThread::cont_entry_offset())); 985 __ str(rscratch1, Address(sp, ContinuationEntry::parent_offset())); 986 __ mov(rscratch1, sp); // we can't use sp as the source in str 987 __ str(rscratch1, Address(rthread, JavaThread::cont_entry_offset())); 988 989 return map; 990 } 991 992 // on entry c_rarg1 points to the continuation 993 // sp points to ContinuationEntry 994 // c_rarg3 -- isVirtualThread 995 static void fill_continuation_entry(MacroAssembler* masm) { 996 #ifdef ASSERT 997 __ movw(rscratch1, ContinuationEntry::cookie_value()); 998 __ strw(rscratch1, Address(sp, ContinuationEntry::cookie_offset())); 999 #endif 1000 1001 __ str (c_rarg1, Address(sp, ContinuationEntry::cont_offset())); 1002 __ strw(c_rarg3, Address(sp, ContinuationEntry::flags_offset())); 1003 __ str (zr, Address(sp, ContinuationEntry::chunk_offset())); 1004 __ strw(zr, Address(sp, ContinuationEntry::argsize_offset())); 1005 __ strw(zr, Address(sp, ContinuationEntry::pin_count_offset())); 1006 1007 __ ldr(rscratch1, Address(rthread, JavaThread::cont_fastpath_offset())); 1008 __ str(rscratch1, Address(sp, ContinuationEntry::parent_cont_fastpath_offset())); 1009 __ ldr(rscratch1, Address(rthread, JavaThread::held_monitor_count_offset())); 1010 __ str(rscratch1, Address(sp, ContinuationEntry::parent_held_monitor_count_offset())); 1011 1012 __ str(zr, Address(rthread, JavaThread::cont_fastpath_offset())); 1013 __ str(zr, Address(rthread, JavaThread::held_monitor_count_offset())); 1014 } 1015 1016 // on entry, sp points to the ContinuationEntry 1017 // on exit, rfp points to the spilled rfp in the entry frame 1018 static void continuation_enter_cleanup(MacroAssembler* masm) { 1019 #ifndef PRODUCT 1020 Label OK; 1021 __ ldr(rscratch1, Address(rthread, JavaThread::cont_entry_offset())); 1022 __ cmp(sp, rscratch1); 1023 __ br(Assembler::EQ, OK); 1024 __ stop("incorrect sp1"); 1025 __ bind(OK); 1026 #endif 1027 __ ldr(rscratch1, Address(sp, ContinuationEntry::parent_cont_fastpath_offset())); 1028 __ str(rscratch1, Address(rthread, JavaThread::cont_fastpath_offset())); 1029 1030 if (CheckJNICalls) { 1031 // Check if this is a virtual thread continuation 1032 Label L_skip_vthread_code; 1033 __ ldrw(rscratch1, Address(sp, ContinuationEntry::flags_offset())); 1034 __ cbzw(rscratch1, L_skip_vthread_code); 1035 1036 // If the held monitor count is > 0 and this vthread is terminating then 1037 // it failed to release a JNI monitor. So we issue the same log message 1038 // that JavaThread::exit does. 1039 __ ldr(rscratch1, Address(rthread, JavaThread::jni_monitor_count_offset())); 1040 __ cbz(rscratch1, L_skip_vthread_code); 1041 1042 // Save return value potentially containing the exception oop in callee-saved R19. 1043 __ mov(r19, r0); 1044 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::log_jni_monitor_still_held)); 1045 // Restore potential return value. 1046 __ mov(r0, r19); 1047 1048 // For vthreads we have to explicitly zero the JNI monitor count of the carrier 1049 // on termination. The held count is implicitly zeroed below when we restore from 1050 // the parent held count (which has to be zero). 1051 __ str(zr, Address(rthread, JavaThread::jni_monitor_count_offset())); 1052 1053 __ bind(L_skip_vthread_code); 1054 } 1055 #ifdef ASSERT 1056 else { 1057 // Check if this is a virtual thread continuation 1058 Label L_skip_vthread_code; 1059 __ ldrw(rscratch1, Address(sp, ContinuationEntry::flags_offset())); 1060 __ cbzw(rscratch1, L_skip_vthread_code); 1061 1062 // See comment just above. If not checking JNI calls the JNI count is only 1063 // needed for assertion checking. 1064 __ str(zr, Address(rthread, JavaThread::jni_monitor_count_offset())); 1065 1066 __ bind(L_skip_vthread_code); 1067 } 1068 #endif 1069 1070 __ ldr(rscratch1, Address(sp, ContinuationEntry::parent_held_monitor_count_offset())); 1071 __ str(rscratch1, Address(rthread, JavaThread::held_monitor_count_offset())); 1072 1073 __ ldr(rscratch2, Address(sp, ContinuationEntry::parent_offset())); 1074 __ str(rscratch2, Address(rthread, JavaThread::cont_entry_offset())); 1075 __ add(rfp, sp, (int)ContinuationEntry::size()); 1076 } 1077 1078 // enterSpecial(Continuation c, boolean isContinue, boolean isVirtualThread) 1079 // On entry: c_rarg1 -- the continuation object 1080 // c_rarg2 -- isContinue 1081 // c_rarg3 -- isVirtualThread 1082 static void gen_continuation_enter(MacroAssembler* masm, 1083 const methodHandle& method, 1084 const BasicType* sig_bt, 1085 const VMRegPair* regs, 1086 int& exception_offset, 1087 OopMapSet*oop_maps, 1088 int& frame_complete, 1089 int& stack_slots, 1090 int& interpreted_entry_offset, 1091 int& compiled_entry_offset) { 1092 //verify_oop_args(masm, method, sig_bt, regs); 1093 Address resolve(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type); 1094 1095 address start = __ pc(); 1096 1097 Label call_thaw, exit; 1098 1099 // i2i entry used at interp_only_mode only 1100 interpreted_entry_offset = __ pc() - start; 1101 { 1102 1103 #ifdef ASSERT 1104 Label is_interp_only; 1105 __ ldrw(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset())); 1106 __ cbnzw(rscratch1, is_interp_only); 1107 __ stop("enterSpecial interpreter entry called when not in interp_only_mode"); 1108 __ bind(is_interp_only); 1109 #endif 1110 1111 // Read interpreter arguments into registers (this is an ad-hoc i2c adapter) 1112 __ ldr(c_rarg1, Address(esp, Interpreter::stackElementSize*2)); 1113 __ ldr(c_rarg2, Address(esp, Interpreter::stackElementSize*1)); 1114 __ ldr(c_rarg3, Address(esp, Interpreter::stackElementSize*0)); 1115 __ push_cont_fastpath(rthread); 1116 1117 __ enter(); 1118 stack_slots = 2; // will be adjusted in setup 1119 OopMap* map = continuation_enter_setup(masm, stack_slots); 1120 // The frame is complete here, but we only record it for the compiled entry, so the frame would appear unsafe, 1121 // but that's okay because at the very worst we'll miss an async sample, but we're in interp_only_mode anyway. 1122 1123 fill_continuation_entry(masm); 1124 1125 __ cbnz(c_rarg2, call_thaw); 1126 1127 const address tr_call = __ trampoline_call(resolve); 1128 if (tr_call == nullptr) { 1129 fatal("CodeCache is full at gen_continuation_enter"); 1130 } 1131 1132 oop_maps->add_gc_map(__ pc() - start, map); 1133 __ post_call_nop(); 1134 1135 __ b(exit); 1136 1137 address stub = CompiledDirectCall::emit_to_interp_stub(masm, tr_call); 1138 if (stub == nullptr) { 1139 fatal("CodeCache is full at gen_continuation_enter"); 1140 } 1141 } 1142 1143 // compiled entry 1144 __ align(CodeEntryAlignment); 1145 compiled_entry_offset = __ pc() - start; 1146 1147 __ enter(); 1148 stack_slots = 2; // will be adjusted in setup 1149 OopMap* map = continuation_enter_setup(masm, stack_slots); 1150 frame_complete = __ pc() - start; 1151 1152 fill_continuation_entry(masm); 1153 1154 __ cbnz(c_rarg2, call_thaw); 1155 1156 const address tr_call = __ trampoline_call(resolve); 1157 if (tr_call == nullptr) { 1158 fatal("CodeCache is full at gen_continuation_enter"); 1159 } 1160 1161 oop_maps->add_gc_map(__ pc() - start, map); 1162 __ post_call_nop(); 1163 1164 __ b(exit); 1165 1166 __ bind(call_thaw); 1167 1168 __ rt_call(CAST_FROM_FN_PTR(address, StubRoutines::cont_thaw())); 1169 oop_maps->add_gc_map(__ pc() - start, map->deep_copy()); 1170 ContinuationEntry::_return_pc_offset = __ pc() - start; 1171 __ post_call_nop(); 1172 1173 __ bind(exit); 1174 continuation_enter_cleanup(masm); 1175 __ leave(); 1176 __ ret(lr); 1177 1178 /// exception handling 1179 1180 exception_offset = __ pc() - start; 1181 { 1182 __ mov(r19, r0); // save return value contaning the exception oop in callee-saved R19 1183 1184 continuation_enter_cleanup(masm); 1185 1186 __ ldr(c_rarg1, Address(rfp, wordSize)); // return address 1187 __ authenticate_return_address(c_rarg1); 1188 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), rthread, c_rarg1); 1189 1190 // see OptoRuntime::generate_exception_blob: r0 -- exception oop, r3 -- exception pc 1191 1192 __ mov(r1, r0); // the exception handler 1193 __ mov(r0, r19); // restore return value contaning the exception oop 1194 __ verify_oop(r0); 1195 1196 __ leave(); 1197 __ mov(r3, lr); 1198 __ br(r1); // the exception handler 1199 } 1200 1201 address stub = CompiledDirectCall::emit_to_interp_stub(masm, tr_call); 1202 if (stub == nullptr) { 1203 fatal("CodeCache is full at gen_continuation_enter"); 1204 } 1205 } 1206 1207 static void gen_continuation_yield(MacroAssembler* masm, 1208 const methodHandle& method, 1209 const BasicType* sig_bt, 1210 const VMRegPair* regs, 1211 OopMapSet* oop_maps, 1212 int& frame_complete, 1213 int& stack_slots, 1214 int& compiled_entry_offset) { 1215 enum layout { 1216 rfp_off1, 1217 rfp_off2, 1218 lr_off, 1219 lr_off2, 1220 framesize // inclusive of return address 1221 }; 1222 // assert(is_even(framesize/2), "sp not 16-byte aligned"); 1223 stack_slots = framesize / VMRegImpl::slots_per_word; 1224 assert(stack_slots == 2, "recheck layout"); 1225 1226 address start = __ pc(); 1227 1228 compiled_entry_offset = __ pc() - start; 1229 __ enter(); 1230 1231 __ mov(c_rarg1, sp); 1232 1233 frame_complete = __ pc() - start; 1234 address the_pc = __ pc(); 1235 1236 __ post_call_nop(); // this must be exactly after the pc value that is pushed into the frame info, we use this nop for fast CodeBlob lookup 1237 1238 __ mov(c_rarg0, rthread); 1239 __ set_last_Java_frame(sp, rfp, the_pc, rscratch1); 1240 __ call_VM_leaf(Continuation::freeze_entry(), 2); 1241 __ reset_last_Java_frame(true); 1242 1243 Label pinned; 1244 1245 __ cbnz(r0, pinned); 1246 1247 // We've succeeded, set sp to the ContinuationEntry 1248 __ ldr(rscratch1, Address(rthread, JavaThread::cont_entry_offset())); 1249 __ mov(sp, rscratch1); 1250 continuation_enter_cleanup(masm); 1251 1252 __ bind(pinned); // pinned -- return to caller 1253 1254 // handle pending exception thrown by freeze 1255 __ ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 1256 Label ok; 1257 __ cbz(rscratch1, ok); 1258 __ leave(); 1259 __ lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry())); 1260 __ br(rscratch1); 1261 __ bind(ok); 1262 1263 __ leave(); 1264 __ ret(lr); 1265 1266 OopMap* map = new OopMap(framesize, 1); 1267 oop_maps->add_gc_map(the_pc - start, map); 1268 } 1269 1270 static void gen_special_dispatch(MacroAssembler* masm, 1271 const methodHandle& method, 1272 const BasicType* sig_bt, 1273 const VMRegPair* regs) { 1274 verify_oop_args(masm, method, sig_bt, regs); 1275 vmIntrinsics::ID iid = method->intrinsic_id(); 1276 1277 // Now write the args into the outgoing interpreter space 1278 bool has_receiver = false; 1279 Register receiver_reg = noreg; 1280 int member_arg_pos = -1; 1281 Register member_reg = noreg; 1282 int ref_kind = MethodHandles::signature_polymorphic_intrinsic_ref_kind(iid); 1283 if (ref_kind != 0) { 1284 member_arg_pos = method->size_of_parameters() - 1; // trailing MemberName argument 1285 member_reg = r19; // known to be free at this point 1286 has_receiver = MethodHandles::ref_kind_has_receiver(ref_kind); 1287 } else if (iid == vmIntrinsics::_invokeBasic) { 1288 has_receiver = true; 1289 } else if (iid == vmIntrinsics::_linkToNative) { 1290 member_arg_pos = method->size_of_parameters() - 1; // trailing NativeEntryPoint argument 1291 member_reg = r19; // known to be free at this point 1292 } else { 1293 fatal("unexpected intrinsic id %d", vmIntrinsics::as_int(iid)); 1294 } 1295 1296 if (member_reg != noreg) { 1297 // Load the member_arg into register, if necessary. 1298 SharedRuntime::check_member_name_argument_is_last_argument(method, sig_bt, regs); 1299 VMReg r = regs[member_arg_pos].first(); 1300 if (r->is_stack()) { 1301 __ ldr(member_reg, Address(sp, r->reg2stack() * VMRegImpl::stack_slot_size)); 1302 } else { 1303 // no data motion is needed 1304 member_reg = r->as_Register(); 1305 } 1306 } 1307 1308 if (has_receiver) { 1309 // Make sure the receiver is loaded into a register. 1310 assert(method->size_of_parameters() > 0, "oob"); 1311 assert(sig_bt[0] == T_OBJECT, "receiver argument must be an object"); 1312 VMReg r = regs[0].first(); 1313 assert(r->is_valid(), "bad receiver arg"); 1314 if (r->is_stack()) { 1315 // Porting note: This assumes that compiled calling conventions always 1316 // pass the receiver oop in a register. If this is not true on some 1317 // platform, pick a temp and load the receiver from stack. 1318 fatal("receiver always in a register"); 1319 receiver_reg = r2; // known to be free at this point 1320 __ ldr(receiver_reg, Address(sp, r->reg2stack() * VMRegImpl::stack_slot_size)); 1321 } else { 1322 // no data motion is needed 1323 receiver_reg = r->as_Register(); 1324 } 1325 } 1326 1327 // Figure out which address we are really jumping to: 1328 MethodHandles::generate_method_handle_dispatch(masm, iid, 1329 receiver_reg, member_reg, /*for_compiler_entry:*/ true); 1330 } 1331 1332 // --------------------------------------------------------------------------- 1333 // Generate a native wrapper for a given method. The method takes arguments 1334 // in the Java compiled code convention, marshals them to the native 1335 // convention (handlizes oops, etc), transitions to native, makes the call, 1336 // returns to java state (possibly blocking), unhandlizes any result and 1337 // returns. 1338 // 1339 // Critical native functions are a shorthand for the use of 1340 // GetPrimtiveArrayCritical and disallow the use of any other JNI 1341 // functions. The wrapper is expected to unpack the arguments before 1342 // passing them to the callee. Critical native functions leave the state _in_Java, 1343 // since they block out GC. 1344 // Some other parts of JNI setup are skipped like the tear down of the JNI handle 1345 // block and the check for pending exceptions it's impossible for them 1346 // to be thrown. 1347 // 1348 nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm, 1349 const methodHandle& method, 1350 int compile_id, 1351 BasicType* in_sig_bt, 1352 VMRegPair* in_regs, 1353 BasicType ret_type) { 1354 if (method->is_continuation_native_intrinsic()) { 1355 int exception_offset = -1; 1356 OopMapSet* oop_maps = new OopMapSet(); 1357 int frame_complete = -1; 1358 int stack_slots = -1; 1359 int interpreted_entry_offset = -1; 1360 int vep_offset = -1; 1361 if (method->is_continuation_enter_intrinsic()) { 1362 gen_continuation_enter(masm, 1363 method, 1364 in_sig_bt, 1365 in_regs, 1366 exception_offset, 1367 oop_maps, 1368 frame_complete, 1369 stack_slots, 1370 interpreted_entry_offset, 1371 vep_offset); 1372 } else if (method->is_continuation_yield_intrinsic()) { 1373 gen_continuation_yield(masm, 1374 method, 1375 in_sig_bt, 1376 in_regs, 1377 oop_maps, 1378 frame_complete, 1379 stack_slots, 1380 vep_offset); 1381 } else { 1382 guarantee(false, "Unknown Continuation native intrinsic"); 1383 } 1384 1385 #ifdef ASSERT 1386 if (method->is_continuation_enter_intrinsic()) { 1387 assert(interpreted_entry_offset != -1, "Must be set"); 1388 assert(exception_offset != -1, "Must be set"); 1389 } else { 1390 assert(interpreted_entry_offset == -1, "Must be unset"); 1391 assert(exception_offset == -1, "Must be unset"); 1392 } 1393 assert(frame_complete != -1, "Must be set"); 1394 assert(stack_slots != -1, "Must be set"); 1395 assert(vep_offset != -1, "Must be set"); 1396 #endif 1397 1398 __ flush(); 1399 nmethod* nm = nmethod::new_native_nmethod(method, 1400 compile_id, 1401 masm->code(), 1402 vep_offset, 1403 frame_complete, 1404 stack_slots, 1405 in_ByteSize(-1), 1406 in_ByteSize(-1), 1407 oop_maps, 1408 exception_offset); 1409 if (nm == nullptr) return nm; 1410 if (method->is_continuation_enter_intrinsic()) { 1411 ContinuationEntry::set_enter_code(nm, interpreted_entry_offset); 1412 } else if (method->is_continuation_yield_intrinsic()) { 1413 _cont_doYield_stub = nm; 1414 } else { 1415 guarantee(false, "Unknown Continuation native intrinsic"); 1416 } 1417 return nm; 1418 } 1419 1420 if (method->is_method_handle_intrinsic()) { 1421 vmIntrinsics::ID iid = method->intrinsic_id(); 1422 intptr_t start = (intptr_t)__ pc(); 1423 int vep_offset = ((intptr_t)__ pc()) - start; 1424 1425 // First instruction must be a nop as it may need to be patched on deoptimisation 1426 __ nop(); 1427 gen_special_dispatch(masm, 1428 method, 1429 in_sig_bt, 1430 in_regs); 1431 int frame_complete = ((intptr_t)__ pc()) - start; // not complete, period 1432 __ flush(); 1433 int stack_slots = SharedRuntime::out_preserve_stack_slots(); // no out slots at all, actually 1434 return nmethod::new_native_nmethod(method, 1435 compile_id, 1436 masm->code(), 1437 vep_offset, 1438 frame_complete, 1439 stack_slots / VMRegImpl::slots_per_word, 1440 in_ByteSize(-1), 1441 in_ByteSize(-1), 1442 nullptr); 1443 } 1444 address native_func = method->native_function(); 1445 assert(native_func != nullptr, "must have function"); 1446 1447 // An OopMap for lock (and class if static) 1448 OopMapSet *oop_maps = new OopMapSet(); 1449 intptr_t start = (intptr_t)__ pc(); 1450 1451 // We have received a description of where all the java arg are located 1452 // on entry to the wrapper. We need to convert these args to where 1453 // the jni function will expect them. To figure out where they go 1454 // we convert the java signature to a C signature by inserting 1455 // the hidden arguments as arg[0] and possibly arg[1] (static method) 1456 1457 const int total_in_args = method->size_of_parameters(); 1458 int total_c_args = total_in_args + (method->is_static() ? 2 : 1); 1459 1460 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args); 1461 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args); 1462 BasicType* in_elem_bt = nullptr; 1463 1464 int argc = 0; 1465 out_sig_bt[argc++] = T_ADDRESS; 1466 if (method->is_static()) { 1467 out_sig_bt[argc++] = T_OBJECT; 1468 } 1469 1470 for (int i = 0; i < total_in_args ; i++ ) { 1471 out_sig_bt[argc++] = in_sig_bt[i]; 1472 } 1473 1474 // Now figure out where the args must be stored and how much stack space 1475 // they require. 1476 int out_arg_slots; 1477 out_arg_slots = c_calling_convention_priv(out_sig_bt, out_regs, total_c_args); 1478 1479 if (out_arg_slots < 0) { 1480 return nullptr; 1481 } 1482 1483 // Compute framesize for the wrapper. We need to handlize all oops in 1484 // incoming registers 1485 1486 // Calculate the total number of stack slots we will need. 1487 1488 // First count the abi requirement plus all of the outgoing args 1489 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots; 1490 1491 // Now the space for the inbound oop handle area 1492 int total_save_slots = 8 * VMRegImpl::slots_per_word; // 8 arguments passed in registers 1493 1494 int oop_handle_offset = stack_slots; 1495 stack_slots += total_save_slots; 1496 1497 // Now any space we need for handlizing a klass if static method 1498 1499 int klass_slot_offset = 0; 1500 int klass_offset = -1; 1501 int lock_slot_offset = 0; 1502 bool is_static = false; 1503 1504 if (method->is_static()) { 1505 klass_slot_offset = stack_slots; 1506 stack_slots += VMRegImpl::slots_per_word; 1507 klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size; 1508 is_static = true; 1509 } 1510 1511 // Plus a lock if needed 1512 1513 if (method->is_synchronized()) { 1514 lock_slot_offset = stack_slots; 1515 stack_slots += VMRegImpl::slots_per_word; 1516 } 1517 1518 // Now a place (+2) to save return values or temp during shuffling 1519 // + 4 for return address (which we own) and saved rfp 1520 stack_slots += 6; 1521 1522 // Ok The space we have allocated will look like: 1523 // 1524 // 1525 // FP-> | | 1526 // |---------------------| 1527 // | 2 slots for moves | 1528 // |---------------------| 1529 // | lock box (if sync) | 1530 // |---------------------| <- lock_slot_offset 1531 // | klass (if static) | 1532 // |---------------------| <- klass_slot_offset 1533 // | oopHandle area | 1534 // |---------------------| <- oop_handle_offset (8 java arg registers) 1535 // | outbound memory | 1536 // | based arguments | 1537 // | | 1538 // |---------------------| 1539 // | | 1540 // SP-> | out_preserved_slots | 1541 // 1542 // 1543 1544 1545 // Now compute actual number of stack words we need rounding to make 1546 // stack properly aligned. 1547 stack_slots = align_up(stack_slots, StackAlignmentInSlots); 1548 1549 int stack_size = stack_slots * VMRegImpl::stack_slot_size; 1550 1551 // First thing make an ic check to see if we should even be here 1552 1553 // We are free to use all registers as temps without saving them and 1554 // restoring them except rfp. rfp is the only callee save register 1555 // as far as the interpreter and the compiler(s) are concerned. 1556 1557 const Register receiver = j_rarg0; 1558 1559 Label exception_pending; 1560 1561 assert_different_registers(receiver, rscratch1); 1562 __ verify_oop(receiver); 1563 __ ic_check(8 /* end_alignment */); 1564 1565 // Verified entry point must be aligned 1566 int vep_offset = ((intptr_t)__ pc()) - start; 1567 1568 // If we have to make this method not-entrant we'll overwrite its 1569 // first instruction with a jump. For this action to be legal we 1570 // must ensure that this first instruction is a B, BL, NOP, BKPT, 1571 // SVC, HVC, or SMC. Make it a NOP. 1572 __ nop(); 1573 1574 if (VM_Version::supports_fast_class_init_checks() && method->needs_clinit_barrier()) { 1575 Label L_skip_barrier; 1576 __ mov_metadata(rscratch2, method->method_holder()); // InstanceKlass* 1577 __ clinit_barrier(rscratch2, rscratch1, &L_skip_barrier); 1578 __ far_jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); 1579 1580 __ bind(L_skip_barrier); 1581 } 1582 1583 // Generate stack overflow check 1584 __ bang_stack_with_offset(checked_cast<int>(StackOverflow::stack_shadow_zone_size())); 1585 1586 // Generate a new frame for the wrapper. 1587 __ enter(); 1588 // -2 because return address is already present and so is saved rfp 1589 __ sub(sp, sp, stack_size - 2*wordSize); 1590 1591 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler(); 1592 bs->nmethod_entry_barrier(masm, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */); 1593 1594 // Frame is now completed as far as size and linkage. 1595 int frame_complete = ((intptr_t)__ pc()) - start; 1596 1597 // We use r20 as the oop handle for the receiver/klass 1598 // It is callee save so it survives the call to native 1599 1600 const Register oop_handle_reg = r20; 1601 1602 // 1603 // We immediately shuffle the arguments so that any vm call we have to 1604 // make from here on out (sync slow path, jvmti, etc.) we will have 1605 // captured the oops from our caller and have a valid oopMap for 1606 // them. 1607 1608 // ----------------- 1609 // The Grand Shuffle 1610 1611 // The Java calling convention is either equal (linux) or denser (win64) than the 1612 // c calling convention. However the because of the jni_env argument the c calling 1613 // convention always has at least one more (and two for static) arguments than Java. 1614 // Therefore if we move the args from java -> c backwards then we will never have 1615 // a register->register conflict and we don't have to build a dependency graph 1616 // and figure out how to break any cycles. 1617 // 1618 1619 // Record esp-based slot for receiver on stack for non-static methods 1620 int receiver_offset = -1; 1621 1622 // This is a trick. We double the stack slots so we can claim 1623 // the oops in the caller's frame. Since we are sure to have 1624 // more args than the caller doubling is enough to make 1625 // sure we can capture all the incoming oop args from the 1626 // caller. 1627 // 1628 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); 1629 1630 // Mark location of rfp (someday) 1631 // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, vmreg(rfp)); 1632 1633 1634 int float_args = 0; 1635 int int_args = 0; 1636 1637 #ifdef ASSERT 1638 bool reg_destroyed[Register::number_of_registers]; 1639 bool freg_destroyed[FloatRegister::number_of_registers]; 1640 for ( int r = 0 ; r < Register::number_of_registers ; r++ ) { 1641 reg_destroyed[r] = false; 1642 } 1643 for ( int f = 0 ; f < FloatRegister::number_of_registers ; f++ ) { 1644 freg_destroyed[f] = false; 1645 } 1646 1647 #endif /* ASSERT */ 1648 1649 // For JNI natives the incoming and outgoing registers are offset upwards. 1650 GrowableArray<int> arg_order(2 * total_in_args); 1651 VMRegPair tmp_vmreg; 1652 tmp_vmreg.set2(r19->as_VMReg()); 1653 1654 for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) { 1655 arg_order.push(i); 1656 arg_order.push(c_arg); 1657 } 1658 1659 int temploc = -1; 1660 for (int ai = 0; ai < arg_order.length(); ai += 2) { 1661 int i = arg_order.at(ai); 1662 int c_arg = arg_order.at(ai + 1); 1663 __ block_comment(err_msg("move %d -> %d", i, c_arg)); 1664 assert(c_arg != -1 && i != -1, "wrong order"); 1665 #ifdef ASSERT 1666 if (in_regs[i].first()->is_Register()) { 1667 assert(!reg_destroyed[in_regs[i].first()->as_Register()->encoding()], "destroyed reg!"); 1668 } else if (in_regs[i].first()->is_FloatRegister()) { 1669 assert(!freg_destroyed[in_regs[i].first()->as_FloatRegister()->encoding()], "destroyed reg!"); 1670 } 1671 if (out_regs[c_arg].first()->is_Register()) { 1672 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true; 1673 } else if (out_regs[c_arg].first()->is_FloatRegister()) { 1674 freg_destroyed[out_regs[c_arg].first()->as_FloatRegister()->encoding()] = true; 1675 } 1676 #endif /* ASSERT */ 1677 switch (in_sig_bt[i]) { 1678 case T_ARRAY: 1679 case T_OBJECT: 1680 __ object_move(map, oop_handle_offset, stack_slots, in_regs[i], out_regs[c_arg], 1681 ((i == 0) && (!is_static)), 1682 &receiver_offset); 1683 int_args++; 1684 break; 1685 case T_VOID: 1686 break; 1687 1688 case T_FLOAT: 1689 __ float_move(in_regs[i], out_regs[c_arg]); 1690 float_args++; 1691 break; 1692 1693 case T_DOUBLE: 1694 assert( i + 1 < total_in_args && 1695 in_sig_bt[i + 1] == T_VOID && 1696 out_sig_bt[c_arg+1] == T_VOID, "bad arg list"); 1697 __ double_move(in_regs[i], out_regs[c_arg]); 1698 float_args++; 1699 break; 1700 1701 case T_LONG : 1702 __ long_move(in_regs[i], out_regs[c_arg]); 1703 int_args++; 1704 break; 1705 1706 case T_ADDRESS: assert(false, "found T_ADDRESS in java args"); 1707 1708 default: 1709 __ move32_64(in_regs[i], out_regs[c_arg]); 1710 int_args++; 1711 } 1712 } 1713 1714 // point c_arg at the first arg that is already loaded in case we 1715 // need to spill before we call out 1716 int c_arg = total_c_args - total_in_args; 1717 1718 // Pre-load a static method's oop into c_rarg1. 1719 if (method->is_static()) { 1720 1721 // load oop into a register 1722 __ movoop(c_rarg1, 1723 JNIHandles::make_local(method->method_holder()->java_mirror())); 1724 1725 // Now handlize the static class mirror it's known not-null. 1726 __ str(c_rarg1, Address(sp, klass_offset)); 1727 map->set_oop(VMRegImpl::stack2reg(klass_slot_offset)); 1728 1729 // Now get the handle 1730 __ lea(c_rarg1, Address(sp, klass_offset)); 1731 // and protect the arg if we must spill 1732 c_arg--; 1733 } 1734 1735 // Change state to native (we save the return address in the thread, since it might not 1736 // be pushed on the stack when we do a stack traversal). 1737 // We use the same pc/oopMap repeatedly when we call out 1738 1739 Label native_return; 1740 __ set_last_Java_frame(sp, noreg, native_return, rscratch1); 1741 1742 Label dtrace_method_entry, dtrace_method_entry_done; 1743 if (DTraceMethodProbes) { 1744 __ b(dtrace_method_entry); 1745 __ bind(dtrace_method_entry_done); 1746 } 1747 1748 // RedefineClasses() tracing support for obsolete method entry 1749 if (log_is_enabled(Trace, redefine, class, obsolete)) { 1750 // protect the args we've loaded 1751 save_args(masm, total_c_args, c_arg, out_regs); 1752 __ mov_metadata(c_rarg1, method()); 1753 __ call_VM_leaf( 1754 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), 1755 rthread, c_rarg1); 1756 restore_args(masm, total_c_args, c_arg, out_regs); 1757 } 1758 1759 // Lock a synchronized method 1760 1761 // Register definitions used by locking and unlocking 1762 1763 const Register swap_reg = r0; 1764 const Register obj_reg = r19; // Will contain the oop 1765 const Register lock_reg = r13; // Address of compiler lock object (BasicLock) 1766 const Register old_hdr = r13; // value of old header at unlock time 1767 const Register lock_tmp = r14; // Temporary used by lightweight_lock/unlock 1768 const Register tmp = lr; 1769 1770 Label slow_path_lock; 1771 Label lock_done; 1772 1773 if (method->is_synchronized()) { 1774 Label count; 1775 const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes(); 1776 1777 // Get the handle (the 2nd argument) 1778 __ mov(oop_handle_reg, c_rarg1); 1779 1780 // Get address of the box 1781 1782 __ lea(lock_reg, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size)); 1783 1784 // Load the oop from the handle 1785 __ ldr(obj_reg, Address(oop_handle_reg, 0)); 1786 1787 if (LockingMode == LM_MONITOR) { 1788 __ b(slow_path_lock); 1789 } else if (LockingMode == LM_LEGACY) { 1790 // Load (object->mark() | 1) into swap_reg %r0 1791 __ ldr(rscratch1, Address(obj_reg, oopDesc::mark_offset_in_bytes())); 1792 __ orr(swap_reg, rscratch1, 1); 1793 1794 // Save (object->mark() | 1) into BasicLock's displaced header 1795 __ str(swap_reg, Address(lock_reg, mark_word_offset)); 1796 1797 // src -> dest iff dest == r0 else r0 <- dest 1798 __ cmpxchg_obj_header(r0, lock_reg, obj_reg, rscratch1, count, /*fallthrough*/nullptr); 1799 1800 // Hmm should this move to the slow path code area??? 1801 1802 // Test if the oopMark is an obvious stack pointer, i.e., 1803 // 1) (mark & 3) == 0, and 1804 // 2) sp <= mark < mark + os::pagesize() 1805 // These 3 tests can be done by evaluating the following 1806 // expression: ((mark - sp) & (3 - os::vm_page_size())), 1807 // assuming both stack pointer and pagesize have their 1808 // least significant 2 bits clear. 1809 // NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg 1810 1811 __ sub(swap_reg, sp, swap_reg); 1812 __ neg(swap_reg, swap_reg); 1813 __ ands(swap_reg, swap_reg, 3 - (int)os::vm_page_size()); 1814 1815 // Save the test result, for recursive case, the result is zero 1816 __ str(swap_reg, Address(lock_reg, mark_word_offset)); 1817 __ br(Assembler::NE, slow_path_lock); 1818 } else { 1819 assert(LockingMode == LM_LIGHTWEIGHT, "must be"); 1820 __ lightweight_lock(lock_reg, obj_reg, swap_reg, tmp, lock_tmp, slow_path_lock); 1821 } 1822 __ bind(count); 1823 __ increment(Address(rthread, JavaThread::held_monitor_count_offset())); 1824 1825 // Slow path will re-enter here 1826 __ bind(lock_done); 1827 } 1828 1829 1830 // Finally just about ready to make the JNI call 1831 1832 // get JNIEnv* which is first argument to native 1833 __ lea(c_rarg0, Address(rthread, in_bytes(JavaThread::jni_environment_offset()))); 1834 1835 // Now set thread in native 1836 __ mov(rscratch1, _thread_in_native); 1837 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1838 __ stlrw(rscratch1, rscratch2); 1839 1840 __ rt_call(native_func); 1841 1842 __ bind(native_return); 1843 1844 intptr_t return_pc = (intptr_t) __ pc(); 1845 oop_maps->add_gc_map(return_pc - start, map); 1846 1847 // Verify or restore cpu control state after JNI call 1848 __ restore_cpu_control_state_after_jni(rscratch1, rscratch2); 1849 1850 // Unpack native results. 1851 switch (ret_type) { 1852 case T_BOOLEAN: __ c2bool(r0); break; 1853 case T_CHAR : __ ubfx(r0, r0, 0, 16); break; 1854 case T_BYTE : __ sbfx(r0, r0, 0, 8); break; 1855 case T_SHORT : __ sbfx(r0, r0, 0, 16); break; 1856 case T_INT : __ sbfx(r0, r0, 0, 32); break; 1857 case T_DOUBLE : 1858 case T_FLOAT : 1859 // Result is in v0 we'll save as needed 1860 break; 1861 case T_ARRAY: // Really a handle 1862 case T_OBJECT: // Really a handle 1863 break; // can't de-handlize until after safepoint check 1864 case T_VOID: break; 1865 case T_LONG: break; 1866 default : ShouldNotReachHere(); 1867 } 1868 1869 Label safepoint_in_progress, safepoint_in_progress_done; 1870 Label after_transition; 1871 1872 // Switch thread to "native transition" state before reading the synchronization state. 1873 // This additional state is necessary because reading and testing the synchronization 1874 // state is not atomic w.r.t. GC, as this scenario demonstrates: 1875 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted. 1876 // VM thread changes sync state to synchronizing and suspends threads for GC. 1877 // Thread A is resumed to finish this native method, but doesn't block here since it 1878 // didn't see any synchronization is progress, and escapes. 1879 __ mov(rscratch1, _thread_in_native_trans); 1880 1881 __ strw(rscratch1, Address(rthread, JavaThread::thread_state_offset())); 1882 1883 // Force this write out before the read below 1884 if (!UseSystemMemoryBarrier) { 1885 __ dmb(Assembler::ISH); 1886 } 1887 1888 __ verify_sve_vector_length(); 1889 1890 // Check for safepoint operation in progress and/or pending suspend requests. 1891 { 1892 // No need for acquire as Java threads always disarm themselves. 1893 __ safepoint_poll(safepoint_in_progress, true /* at_return */, false /* acquire */, false /* in_nmethod */); 1894 __ ldrw(rscratch1, Address(rthread, JavaThread::suspend_flags_offset())); 1895 __ cbnzw(rscratch1, safepoint_in_progress); 1896 __ bind(safepoint_in_progress_done); 1897 } 1898 1899 // change thread state 1900 __ mov(rscratch1, _thread_in_Java); 1901 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1902 __ stlrw(rscratch1, rscratch2); 1903 __ bind(after_transition); 1904 1905 Label reguard; 1906 Label reguard_done; 1907 __ ldrb(rscratch1, Address(rthread, JavaThread::stack_guard_state_offset())); 1908 __ cmpw(rscratch1, StackOverflow::stack_guard_yellow_reserved_disabled); 1909 __ br(Assembler::EQ, reguard); 1910 __ bind(reguard_done); 1911 1912 // native result if any is live 1913 1914 // Unlock 1915 Label unlock_done; 1916 Label slow_path_unlock; 1917 if (method->is_synchronized()) { 1918 1919 // Get locked oop from the handle we passed to jni 1920 __ ldr(obj_reg, Address(oop_handle_reg, 0)); 1921 1922 Label done, not_recursive; 1923 1924 if (LockingMode == LM_LEGACY) { 1925 // Simple recursive lock? 1926 __ ldr(rscratch1, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size)); 1927 __ cbnz(rscratch1, not_recursive); 1928 __ decrement(Address(rthread, JavaThread::held_monitor_count_offset())); 1929 __ b(done); 1930 } 1931 1932 __ bind(not_recursive); 1933 1934 // Must save r0 if if it is live now because cmpxchg must use it 1935 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) { 1936 save_native_result(masm, ret_type, stack_slots); 1937 } 1938 1939 if (LockingMode == LM_MONITOR) { 1940 __ b(slow_path_unlock); 1941 } else if (LockingMode == LM_LEGACY) { 1942 // get address of the stack lock 1943 __ lea(r0, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size)); 1944 // get old displaced header 1945 __ ldr(old_hdr, Address(r0, 0)); 1946 1947 // Atomic swap old header if oop still contains the stack lock 1948 Label count; 1949 __ cmpxchg_obj_header(r0, old_hdr, obj_reg, rscratch1, count, &slow_path_unlock); 1950 __ bind(count); 1951 __ decrement(Address(rthread, JavaThread::held_monitor_count_offset())); 1952 } else { 1953 assert(LockingMode == LM_LIGHTWEIGHT, ""); 1954 __ lightweight_unlock(obj_reg, old_hdr, swap_reg, lock_tmp, slow_path_unlock); 1955 __ decrement(Address(rthread, JavaThread::held_monitor_count_offset())); 1956 } 1957 1958 // slow path re-enters here 1959 __ bind(unlock_done); 1960 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) { 1961 restore_native_result(masm, ret_type, stack_slots); 1962 } 1963 1964 __ bind(done); 1965 } 1966 1967 Label dtrace_method_exit, dtrace_method_exit_done; 1968 if (DTraceMethodProbes) { 1969 __ b(dtrace_method_exit); 1970 __ bind(dtrace_method_exit_done); 1971 } 1972 1973 __ reset_last_Java_frame(false); 1974 1975 // Unbox oop result, e.g. JNIHandles::resolve result. 1976 if (is_reference_type(ret_type)) { 1977 __ resolve_jobject(r0, r1, r2); 1978 } 1979 1980 if (CheckJNICalls) { 1981 // clear_pending_jni_exception_check 1982 __ str(zr, Address(rthread, JavaThread::pending_jni_exception_check_fn_offset())); 1983 } 1984 1985 // reset handle block 1986 __ ldr(r2, Address(rthread, JavaThread::active_handles_offset())); 1987 __ str(zr, Address(r2, JNIHandleBlock::top_offset())); 1988 1989 __ leave(); 1990 1991 // Any exception pending? 1992 __ ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 1993 __ cbnz(rscratch1, exception_pending); 1994 1995 // We're done 1996 __ ret(lr); 1997 1998 // Unexpected paths are out of line and go here 1999 2000 // forward the exception 2001 __ bind(exception_pending); 2002 2003 // and forward the exception 2004 __ far_jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 2005 2006 // Slow path locking & unlocking 2007 if (method->is_synchronized()) { 2008 2009 __ block_comment("Slow path lock {"); 2010 __ bind(slow_path_lock); 2011 2012 // has last_Java_frame setup. No exceptions so do vanilla call not call_VM 2013 // args are (oop obj, BasicLock* lock, JavaThread* thread) 2014 2015 // protect the args we've loaded 2016 save_args(masm, total_c_args, c_arg, out_regs); 2017 2018 __ mov(c_rarg0, obj_reg); 2019 __ mov(c_rarg1, lock_reg); 2020 __ mov(c_rarg2, rthread); 2021 2022 // Not a leaf but we have last_Java_frame setup as we want 2023 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), 3); 2024 restore_args(masm, total_c_args, c_arg, out_regs); 2025 2026 #ifdef ASSERT 2027 { Label L; 2028 __ ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 2029 __ cbz(rscratch1, L); 2030 __ stop("no pending exception allowed on exit from monitorenter"); 2031 __ bind(L); 2032 } 2033 #endif 2034 __ b(lock_done); 2035 2036 __ block_comment("} Slow path lock"); 2037 2038 __ block_comment("Slow path unlock {"); 2039 __ bind(slow_path_unlock); 2040 2041 // If we haven't already saved the native result we must save it now as xmm registers 2042 // are still exposed. 2043 2044 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) { 2045 save_native_result(masm, ret_type, stack_slots); 2046 } 2047 2048 __ mov(c_rarg2, rthread); 2049 __ lea(c_rarg1, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size)); 2050 __ mov(c_rarg0, obj_reg); 2051 2052 // Save pending exception around call to VM (which contains an EXCEPTION_MARK) 2053 // NOTE that obj_reg == r19 currently 2054 __ ldr(r19, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 2055 __ str(zr, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 2056 2057 __ rt_call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C)); 2058 2059 #ifdef ASSERT 2060 { 2061 Label L; 2062 __ ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 2063 __ cbz(rscratch1, L); 2064 __ stop("no pending exception allowed on exit complete_monitor_unlocking_C"); 2065 __ bind(L); 2066 } 2067 #endif /* ASSERT */ 2068 2069 __ str(r19, Address(rthread, in_bytes(Thread::pending_exception_offset()))); 2070 2071 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) { 2072 restore_native_result(masm, ret_type, stack_slots); 2073 } 2074 __ b(unlock_done); 2075 2076 __ block_comment("} Slow path unlock"); 2077 2078 } // synchronized 2079 2080 // SLOW PATH Reguard the stack if needed 2081 2082 __ bind(reguard); 2083 save_native_result(masm, ret_type, stack_slots); 2084 __ rt_call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)); 2085 restore_native_result(masm, ret_type, stack_slots); 2086 // and continue 2087 __ b(reguard_done); 2088 2089 // SLOW PATH safepoint 2090 { 2091 __ block_comment("safepoint {"); 2092 __ bind(safepoint_in_progress); 2093 2094 // Don't use call_VM as it will see a possible pending exception and forward it 2095 // and never return here preventing us from clearing _last_native_pc down below. 2096 // 2097 save_native_result(masm, ret_type, stack_slots); 2098 __ mov(c_rarg0, rthread); 2099 #ifndef PRODUCT 2100 assert(frame::arg_reg_save_area_bytes == 0, "not expecting frame reg save area"); 2101 #endif 2102 __ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans))); 2103 __ blr(rscratch1); 2104 2105 // Restore any method result value 2106 restore_native_result(masm, ret_type, stack_slots); 2107 2108 __ b(safepoint_in_progress_done); 2109 __ block_comment("} safepoint"); 2110 } 2111 2112 // SLOW PATH dtrace support 2113 if (DTraceMethodProbes) { 2114 { 2115 __ block_comment("dtrace entry {"); 2116 __ bind(dtrace_method_entry); 2117 2118 // We have all of the arguments setup at this point. We must not touch any register 2119 // argument registers at this point (what if we save/restore them there are no oop? 2120 2121 save_args(masm, total_c_args, c_arg, out_regs); 2122 __ mov_metadata(c_rarg1, method()); 2123 __ call_VM_leaf( 2124 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), 2125 rthread, c_rarg1); 2126 restore_args(masm, total_c_args, c_arg, out_regs); 2127 __ b(dtrace_method_entry_done); 2128 __ block_comment("} dtrace entry"); 2129 } 2130 2131 { 2132 __ block_comment("dtrace exit {"); 2133 __ bind(dtrace_method_exit); 2134 save_native_result(masm, ret_type, stack_slots); 2135 __ mov_metadata(c_rarg1, method()); 2136 __ call_VM_leaf( 2137 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), 2138 rthread, c_rarg1); 2139 restore_native_result(masm, ret_type, stack_slots); 2140 __ b(dtrace_method_exit_done); 2141 __ block_comment("} dtrace exit"); 2142 } 2143 } 2144 2145 __ flush(); 2146 2147 nmethod *nm = nmethod::new_native_nmethod(method, 2148 compile_id, 2149 masm->code(), 2150 vep_offset, 2151 frame_complete, 2152 stack_slots / VMRegImpl::slots_per_word, 2153 (is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)), 2154 in_ByteSize(lock_slot_offset*VMRegImpl::stack_slot_size), 2155 oop_maps); 2156 2157 return nm; 2158 } 2159 2160 // this function returns the adjust size (in number of words) to a c2i adapter 2161 // activation for use during deoptimization 2162 int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals) { 2163 assert(callee_locals >= callee_parameters, 2164 "test and remove; got more parms than locals"); 2165 if (callee_locals < callee_parameters) 2166 return 0; // No adjustment for negative locals 2167 int diff = (callee_locals - callee_parameters) * Interpreter::stackElementWords; 2168 // diff is counted in stack words 2169 return align_up(diff, 2); 2170 } 2171 2172 2173 //------------------------------generate_deopt_blob---------------------------- 2174 void SharedRuntime::generate_deopt_blob() { 2175 // Allocate space for the code 2176 ResourceMark rm; 2177 // Setup code generation tools 2178 int pad = 0; 2179 #if INCLUDE_JVMCI 2180 if (EnableJVMCI) { 2181 pad += 512; // Increase the buffer size when compiling for JVMCI 2182 } 2183 #endif 2184 CodeBuffer buffer("deopt_blob", 2048+pad, 1024); 2185 MacroAssembler* masm = new MacroAssembler(&buffer); 2186 int frame_size_in_words; 2187 OopMap* map = nullptr; 2188 OopMapSet *oop_maps = new OopMapSet(); 2189 RegisterSaver reg_save(COMPILER2_OR_JVMCI != 0); 2190 2191 // ------------- 2192 // This code enters when returning to a de-optimized nmethod. A return 2193 // address has been pushed on the stack, and return values are in 2194 // registers. 2195 // If we are doing a normal deopt then we were called from the patched 2196 // nmethod from the point we returned to the nmethod. So the return 2197 // address on the stack is wrong by NativeCall::instruction_size 2198 // We will adjust the value so it looks like we have the original return 2199 // address on the stack (like when we eagerly deoptimized). 2200 // In the case of an exception pending when deoptimizing, we enter 2201 // with a return address on the stack that points after the call we patched 2202 // into the exception handler. We have the following register state from, 2203 // e.g., the forward exception stub (see stubGenerator_x86_64.cpp). 2204 // r0: exception oop 2205 // r19: exception handler 2206 // r3: throwing pc 2207 // So in this case we simply jam r3 into the useless return address and 2208 // the stack looks just like we want. 2209 // 2210 // At this point we need to de-opt. We save the argument return 2211 // registers. We call the first C routine, fetch_unroll_info(). This 2212 // routine captures the return values and returns a structure which 2213 // describes the current frame size and the sizes of all replacement frames. 2214 // The current frame is compiled code and may contain many inlined 2215 // functions, each with their own JVM state. We pop the current frame, then 2216 // push all the new frames. Then we call the C routine unpack_frames() to 2217 // populate these frames. Finally unpack_frames() returns us the new target 2218 // address. Notice that callee-save registers are BLOWN here; they have 2219 // already been captured in the vframeArray at the time the return PC was 2220 // patched. 2221 address start = __ pc(); 2222 Label cont; 2223 2224 // Prolog for non exception case! 2225 2226 // Save everything in sight. 2227 map = reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2228 2229 // Normal deoptimization. Save exec mode for unpack_frames. 2230 __ movw(rcpool, Deoptimization::Unpack_deopt); // callee-saved 2231 __ b(cont); 2232 2233 int reexecute_offset = __ pc() - start; 2234 #if INCLUDE_JVMCI && !defined(COMPILER1) 2235 if (EnableJVMCI && UseJVMCICompiler) { 2236 // JVMCI does not use this kind of deoptimization 2237 __ should_not_reach_here(); 2238 } 2239 #endif 2240 2241 // Reexecute case 2242 // return address is the pc describes what bci to do re-execute at 2243 2244 // No need to update map as each call to save_live_registers will produce identical oopmap 2245 (void) reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2246 2247 __ movw(rcpool, Deoptimization::Unpack_reexecute); // callee-saved 2248 __ b(cont); 2249 2250 #if INCLUDE_JVMCI 2251 Label after_fetch_unroll_info_call; 2252 int implicit_exception_uncommon_trap_offset = 0; 2253 int uncommon_trap_offset = 0; 2254 2255 if (EnableJVMCI) { 2256 implicit_exception_uncommon_trap_offset = __ pc() - start; 2257 2258 __ ldr(lr, Address(rthread, in_bytes(JavaThread::jvmci_implicit_exception_pc_offset()))); 2259 __ str(zr, Address(rthread, in_bytes(JavaThread::jvmci_implicit_exception_pc_offset()))); 2260 2261 uncommon_trap_offset = __ pc() - start; 2262 2263 // Save everything in sight. 2264 reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2265 // fetch_unroll_info needs to call last_java_frame() 2266 Label retaddr; 2267 __ set_last_Java_frame(sp, noreg, retaddr, rscratch1); 2268 2269 __ ldrw(c_rarg1, Address(rthread, in_bytes(JavaThread::pending_deoptimization_offset()))); 2270 __ movw(rscratch1, -1); 2271 __ strw(rscratch1, Address(rthread, in_bytes(JavaThread::pending_deoptimization_offset()))); 2272 2273 __ movw(rcpool, (int32_t)Deoptimization::Unpack_reexecute); 2274 __ mov(c_rarg0, rthread); 2275 __ movw(c_rarg2, rcpool); // exec mode 2276 __ lea(rscratch1, 2277 RuntimeAddress(CAST_FROM_FN_PTR(address, 2278 Deoptimization::uncommon_trap))); 2279 __ blr(rscratch1); 2280 __ bind(retaddr); 2281 oop_maps->add_gc_map( __ pc()-start, map->deep_copy()); 2282 2283 __ reset_last_Java_frame(false); 2284 2285 __ b(after_fetch_unroll_info_call); 2286 } // EnableJVMCI 2287 #endif // INCLUDE_JVMCI 2288 2289 int exception_offset = __ pc() - start; 2290 2291 // Prolog for exception case 2292 2293 // all registers are dead at this entry point, except for r0, and 2294 // r3 which contain the exception oop and exception pc 2295 // respectively. Set them in TLS and fall thru to the 2296 // unpack_with_exception_in_tls entry point. 2297 2298 __ str(r3, Address(rthread, JavaThread::exception_pc_offset())); 2299 __ str(r0, Address(rthread, JavaThread::exception_oop_offset())); 2300 2301 int exception_in_tls_offset = __ pc() - start; 2302 2303 // new implementation because exception oop is now passed in JavaThread 2304 2305 // Prolog for exception case 2306 // All registers must be preserved because they might be used by LinearScan 2307 // Exceptiop oop and throwing PC are passed in JavaThread 2308 // tos: stack at point of call to method that threw the exception (i.e. only 2309 // args are on the stack, no return address) 2310 2311 // The return address pushed by save_live_registers will be patched 2312 // later with the throwing pc. The correct value is not available 2313 // now because loading it from memory would destroy registers. 2314 2315 // NB: The SP at this point must be the SP of the method that is 2316 // being deoptimized. Deoptimization assumes that the frame created 2317 // here by save_live_registers is immediately below the method's SP. 2318 // This is a somewhat fragile mechanism. 2319 2320 // Save everything in sight. 2321 map = reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2322 2323 // Now it is safe to overwrite any register 2324 2325 // Deopt during an exception. Save exec mode for unpack_frames. 2326 __ mov(rcpool, Deoptimization::Unpack_exception); // callee-saved 2327 2328 // load throwing pc from JavaThread and patch it as the return address 2329 // of the current frame. Then clear the field in JavaThread 2330 __ ldr(r3, Address(rthread, JavaThread::exception_pc_offset())); 2331 __ protect_return_address(r3); 2332 __ str(r3, Address(rfp, wordSize)); 2333 __ str(zr, Address(rthread, JavaThread::exception_pc_offset())); 2334 2335 #ifdef ASSERT 2336 // verify that there is really an exception oop in JavaThread 2337 __ ldr(r0, Address(rthread, JavaThread::exception_oop_offset())); 2338 __ verify_oop(r0); 2339 2340 // verify that there is no pending exception 2341 Label no_pending_exception; 2342 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 2343 __ cbz(rscratch1, no_pending_exception); 2344 __ stop("must not have pending exception here"); 2345 __ bind(no_pending_exception); 2346 #endif 2347 2348 __ bind(cont); 2349 2350 // Call C code. Need thread and this frame, but NOT official VM entry 2351 // crud. We cannot block on this call, no GC can happen. 2352 // 2353 // UnrollBlock* fetch_unroll_info(JavaThread* thread) 2354 2355 // fetch_unroll_info needs to call last_java_frame(). 2356 2357 Label retaddr; 2358 __ set_last_Java_frame(sp, noreg, retaddr, rscratch1); 2359 #ifdef ASSERT 2360 { Label L; 2361 __ ldr(rscratch1, Address(rthread, JavaThread::last_Java_fp_offset())); 2362 __ cbz(rscratch1, L); 2363 __ stop("SharedRuntime::generate_deopt_blob: last_Java_fp not cleared"); 2364 __ bind(L); 2365 } 2366 #endif // ASSERT 2367 __ mov(c_rarg0, rthread); 2368 __ mov(c_rarg1, rcpool); 2369 __ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info))); 2370 __ blr(rscratch1); 2371 __ bind(retaddr); 2372 2373 // Need to have an oopmap that tells fetch_unroll_info where to 2374 // find any register it might need. 2375 oop_maps->add_gc_map(__ pc() - start, map); 2376 2377 __ reset_last_Java_frame(false); 2378 2379 #if INCLUDE_JVMCI 2380 if (EnableJVMCI) { 2381 __ bind(after_fetch_unroll_info_call); 2382 } 2383 #endif 2384 2385 // Load UnrollBlock* into r5 2386 __ mov(r5, r0); 2387 2388 __ ldrw(rcpool, Address(r5, Deoptimization::UnrollBlock::unpack_kind_offset())); 2389 Label noException; 2390 __ cmpw(rcpool, Deoptimization::Unpack_exception); // Was exception pending? 2391 __ br(Assembler::NE, noException); 2392 __ ldr(r0, Address(rthread, JavaThread::exception_oop_offset())); 2393 // QQQ this is useless it was null above 2394 __ ldr(r3, Address(rthread, JavaThread::exception_pc_offset())); 2395 __ str(zr, Address(rthread, JavaThread::exception_oop_offset())); 2396 __ str(zr, Address(rthread, JavaThread::exception_pc_offset())); 2397 2398 __ verify_oop(r0); 2399 2400 // Overwrite the result registers with the exception results. 2401 __ str(r0, Address(sp, reg_save.r0_offset_in_bytes())); 2402 // I think this is useless 2403 // __ str(r3, Address(sp, RegisterSaver::r3_offset_in_bytes())); 2404 2405 __ bind(noException); 2406 2407 // Only register save data is on the stack. 2408 // Now restore the result registers. Everything else is either dead 2409 // or captured in the vframeArray. 2410 2411 // Restore fp result register 2412 __ ldrd(v0, Address(sp, reg_save.v0_offset_in_bytes())); 2413 // Restore integer result register 2414 __ ldr(r0, Address(sp, reg_save.r0_offset_in_bytes())); 2415 2416 // Pop all of the register save area off the stack 2417 __ add(sp, sp, frame_size_in_words * wordSize); 2418 2419 // All of the register save area has been popped of the stack. Only the 2420 // return address remains. 2421 2422 // Pop all the frames we must move/replace. 2423 // 2424 // Frame picture (youngest to oldest) 2425 // 1: self-frame (no frame link) 2426 // 2: deopting frame (no frame link) 2427 // 3: caller of deopting frame (could be compiled/interpreted). 2428 // 2429 // Note: by leaving the return address of self-frame on the stack 2430 // and using the size of frame 2 to adjust the stack 2431 // when we are done the return to frame 3 will still be on the stack. 2432 2433 // Pop deoptimized frame 2434 __ ldrw(r2, Address(r5, Deoptimization::UnrollBlock::size_of_deoptimized_frame_offset())); 2435 __ sub(r2, r2, 2 * wordSize); 2436 __ add(sp, sp, r2); 2437 __ ldp(rfp, zr, __ post(sp, 2 * wordSize)); 2438 2439 #ifdef ASSERT 2440 // Compilers generate code that bang the stack by as much as the 2441 // interpreter would need. So this stack banging should never 2442 // trigger a fault. Verify that it does not on non product builds. 2443 __ ldrw(r19, Address(r5, Deoptimization::UnrollBlock::total_frame_sizes_offset())); 2444 __ bang_stack_size(r19, r2); 2445 #endif 2446 // Load address of array of frame pcs into r2 2447 __ ldr(r2, Address(r5, Deoptimization::UnrollBlock::frame_pcs_offset())); 2448 2449 // Trash the old pc 2450 // __ addptr(sp, wordSize); FIXME ???? 2451 2452 // Load address of array of frame sizes into r4 2453 __ ldr(r4, Address(r5, Deoptimization::UnrollBlock::frame_sizes_offset())); 2454 2455 // Load counter into r3 2456 __ ldrw(r3, Address(r5, Deoptimization::UnrollBlock::number_of_frames_offset())); 2457 2458 // Now adjust the caller's stack to make up for the extra locals 2459 // but record the original sp so that we can save it in the skeletal interpreter 2460 // frame and the stack walking of interpreter_sender will get the unextended sp 2461 // value and not the "real" sp value. 2462 2463 const Register sender_sp = r6; 2464 2465 __ mov(sender_sp, sp); 2466 __ ldrw(r19, Address(r5, 2467 Deoptimization::UnrollBlock:: 2468 caller_adjustment_offset())); 2469 __ sub(sp, sp, r19); 2470 2471 // Push interpreter frames in a loop 2472 __ mov(rscratch1, (uint64_t)0xDEADDEAD); // Make a recognizable pattern 2473 __ mov(rscratch2, rscratch1); 2474 Label loop; 2475 __ bind(loop); 2476 __ ldr(r19, Address(__ post(r4, wordSize))); // Load frame size 2477 __ sub(r19, r19, 2*wordSize); // We'll push pc and fp by hand 2478 __ ldr(lr, Address(__ post(r2, wordSize))); // Load pc 2479 __ enter(); // Save old & set new fp 2480 __ sub(sp, sp, r19); // Prolog 2481 // This value is corrected by layout_activation_impl 2482 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 2483 __ str(sender_sp, Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize)); // Make it walkable 2484 __ mov(sender_sp, sp); // Pass sender_sp to next frame 2485 __ sub(r3, r3, 1); // Decrement counter 2486 __ cbnz(r3, loop); 2487 2488 // Re-push self-frame 2489 __ ldr(lr, Address(r2)); 2490 __ enter(); 2491 2492 // Allocate a full sized register save area. We subtract 2 because 2493 // enter() just pushed 2 words 2494 __ sub(sp, sp, (frame_size_in_words - 2) * wordSize); 2495 2496 // Restore frame locals after moving the frame 2497 __ strd(v0, Address(sp, reg_save.v0_offset_in_bytes())); 2498 __ str(r0, Address(sp, reg_save.r0_offset_in_bytes())); 2499 2500 // Call C code. Need thread but NOT official VM entry 2501 // crud. We cannot block on this call, no GC can happen. Call should 2502 // restore return values to their stack-slots with the new SP. 2503 // 2504 // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode) 2505 2506 // Use rfp because the frames look interpreted now 2507 // Don't need the precise return PC here, just precise enough to point into this code blob. 2508 address the_pc = __ pc(); 2509 __ set_last_Java_frame(sp, rfp, the_pc, rscratch1); 2510 2511 __ mov(c_rarg0, rthread); 2512 __ movw(c_rarg1, rcpool); // second arg: exec_mode 2513 __ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames))); 2514 __ blr(rscratch1); 2515 2516 // Set an oopmap for the call site 2517 // Use the same PC we used for the last java frame 2518 oop_maps->add_gc_map(the_pc - start, 2519 new OopMap( frame_size_in_words, 0 )); 2520 2521 // Clear fp AND pc 2522 __ reset_last_Java_frame(true); 2523 2524 // Collect return values 2525 __ ldrd(v0, Address(sp, reg_save.v0_offset_in_bytes())); 2526 __ ldr(r0, Address(sp, reg_save.r0_offset_in_bytes())); 2527 // I think this is useless (throwing pc?) 2528 // __ ldr(r3, Address(sp, RegisterSaver::r3_offset_in_bytes())); 2529 2530 // Pop self-frame. 2531 __ leave(); // Epilog 2532 2533 // Jump to interpreter 2534 __ ret(lr); 2535 2536 // Make sure all code is generated 2537 masm->flush(); 2538 2539 _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_in_words); 2540 _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset); 2541 #if INCLUDE_JVMCI 2542 if (EnableJVMCI) { 2543 _deopt_blob->set_uncommon_trap_offset(uncommon_trap_offset); 2544 _deopt_blob->set_implicit_exception_uncommon_trap_offset(implicit_exception_uncommon_trap_offset); 2545 } 2546 #endif 2547 } 2548 2549 // Number of stack slots between incoming argument block and the start of 2550 // a new frame. The PROLOG must add this many slots to the stack. The 2551 // EPILOG must remove this many slots. aarch64 needs two slots for 2552 // return address and fp. 2553 // TODO think this is correct but check 2554 uint SharedRuntime::in_preserve_stack_slots() { 2555 return 4; 2556 } 2557 2558 uint SharedRuntime::out_preserve_stack_slots() { 2559 return 0; 2560 } 2561 2562 2563 //------------------------------generate_handler_blob------ 2564 // 2565 // Generate a special Compile2Runtime blob that saves all registers, 2566 // and setup oopmap. 2567 // 2568 SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_type) { 2569 ResourceMark rm; 2570 OopMapSet *oop_maps = new OopMapSet(); 2571 OopMap* map; 2572 2573 // Allocate space for the code. Setup code generation tools. 2574 CodeBuffer buffer("handler_blob", 2048, 1024); 2575 MacroAssembler* masm = new MacroAssembler(&buffer); 2576 2577 address start = __ pc(); 2578 address call_pc = nullptr; 2579 int frame_size_in_words; 2580 bool cause_return = (poll_type == POLL_AT_RETURN); 2581 RegisterSaver reg_save(poll_type == POLL_AT_VECTOR_LOOP /* save_vectors */); 2582 2583 // When the signal occurred, the LR was either signed and stored on the stack (in which 2584 // case it will be restored from the stack before being used) or unsigned and not stored 2585 // on the stack. Stipping ensures we get the right value. 2586 __ strip_return_address(); 2587 2588 // Save Integer and Float registers. 2589 map = reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2590 2591 // The following is basically a call_VM. However, we need the precise 2592 // address of the call in order to generate an oopmap. Hence, we do all the 2593 // work ourselves. 2594 2595 Label retaddr; 2596 __ set_last_Java_frame(sp, noreg, retaddr, rscratch1); 2597 2598 // The return address must always be correct so that frame constructor never 2599 // sees an invalid pc. 2600 2601 if (!cause_return) { 2602 // overwrite the return address pushed by save_live_registers 2603 // Additionally, r20 is a callee-saved register so we can look at 2604 // it later to determine if someone changed the return address for 2605 // us! 2606 __ ldr(r20, Address(rthread, JavaThread::saved_exception_pc_offset())); 2607 __ protect_return_address(r20); 2608 __ str(r20, Address(rfp, wordSize)); 2609 } 2610 2611 // Do the call 2612 __ mov(c_rarg0, rthread); 2613 __ lea(rscratch1, RuntimeAddress(call_ptr)); 2614 __ blr(rscratch1); 2615 __ bind(retaddr); 2616 2617 // Set an oopmap for the call site. This oopmap will map all 2618 // oop-registers and debug-info registers as callee-saved. This 2619 // will allow deoptimization at this safepoint to find all possible 2620 // debug-info recordings, as well as let GC find all oops. 2621 2622 oop_maps->add_gc_map( __ pc() - start, map); 2623 2624 Label noException; 2625 2626 __ reset_last_Java_frame(false); 2627 2628 __ membar(Assembler::LoadLoad | Assembler::LoadStore); 2629 2630 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 2631 __ cbz(rscratch1, noException); 2632 2633 // Exception pending 2634 2635 reg_save.restore_live_registers(masm); 2636 2637 __ far_jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 2638 2639 // No exception case 2640 __ bind(noException); 2641 2642 Label no_adjust, bail; 2643 if (!cause_return) { 2644 // If our stashed return pc was modified by the runtime we avoid touching it 2645 __ ldr(rscratch1, Address(rfp, wordSize)); 2646 __ cmp(r20, rscratch1); 2647 __ br(Assembler::NE, no_adjust); 2648 __ authenticate_return_address(r20); 2649 2650 #ifdef ASSERT 2651 // Verify the correct encoding of the poll we're about to skip. 2652 // See NativeInstruction::is_ldrw_to_zr() 2653 __ ldrw(rscratch1, Address(r20)); 2654 __ ubfx(rscratch2, rscratch1, 22, 10); 2655 __ cmpw(rscratch2, 0b1011100101); 2656 __ br(Assembler::NE, bail); 2657 __ ubfx(rscratch2, rscratch1, 0, 5); 2658 __ cmpw(rscratch2, 0b11111); 2659 __ br(Assembler::NE, bail); 2660 #endif 2661 // Adjust return pc forward to step over the safepoint poll instruction 2662 __ add(r20, r20, NativeInstruction::instruction_size); 2663 __ protect_return_address(r20); 2664 __ str(r20, Address(rfp, wordSize)); 2665 } 2666 2667 __ bind(no_adjust); 2668 // Normal exit, restore registers and exit. 2669 reg_save.restore_live_registers(masm); 2670 2671 __ ret(lr); 2672 2673 #ifdef ASSERT 2674 __ bind(bail); 2675 __ stop("Attempting to adjust pc to skip safepoint poll but the return point is not what we expected"); 2676 #endif 2677 2678 // Make sure all code is generated 2679 masm->flush(); 2680 2681 // Fill-out other meta info 2682 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words); 2683 } 2684 2685 // 2686 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss 2687 // 2688 // Generate a stub that calls into vm to find out the proper destination 2689 // of a java call. All the argument registers are live at this point 2690 // but since this is generic code we don't know what they are and the caller 2691 // must do any gc of the args. 2692 // 2693 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) { 2694 assert (StubRoutines::forward_exception_entry() != nullptr, "must be generated before"); 2695 2696 // allocate space for the code 2697 ResourceMark rm; 2698 2699 CodeBuffer buffer(name, 1000, 512); 2700 MacroAssembler* masm = new MacroAssembler(&buffer); 2701 2702 int frame_size_in_words; 2703 RegisterSaver reg_save(false /* save_vectors */); 2704 2705 OopMapSet *oop_maps = new OopMapSet(); 2706 OopMap* map = nullptr; 2707 2708 int start = __ offset(); 2709 2710 map = reg_save.save_live_registers(masm, 0, &frame_size_in_words); 2711 2712 int frame_complete = __ offset(); 2713 2714 { 2715 Label retaddr; 2716 __ set_last_Java_frame(sp, noreg, retaddr, rscratch1); 2717 2718 __ mov(c_rarg0, rthread); 2719 __ lea(rscratch1, RuntimeAddress(destination)); 2720 2721 __ blr(rscratch1); 2722 __ bind(retaddr); 2723 } 2724 2725 // Set an oopmap for the call site. 2726 // We need this not only for callee-saved registers, but also for volatile 2727 // registers that the compiler might be keeping live across a safepoint. 2728 2729 oop_maps->add_gc_map( __ offset() - start, map); 2730 2731 // r0 contains the address we are going to jump to assuming no exception got installed 2732 2733 // clear last_Java_sp 2734 __ reset_last_Java_frame(false); 2735 // check for pending exceptions 2736 Label pending; 2737 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 2738 __ cbnz(rscratch1, pending); 2739 2740 // get the returned Method* 2741 __ get_vm_result_2(rmethod, rthread); 2742 __ str(rmethod, Address(sp, reg_save.reg_offset_in_bytes(rmethod))); 2743 2744 // r0 is where we want to jump, overwrite rscratch1 which is saved and scratch 2745 __ str(r0, Address(sp, reg_save.rscratch1_offset_in_bytes())); 2746 reg_save.restore_live_registers(masm); 2747 2748 // We are back to the original state on entry and ready to go. 2749 2750 __ br(rscratch1); 2751 2752 // Pending exception after the safepoint 2753 2754 __ bind(pending); 2755 2756 reg_save.restore_live_registers(masm); 2757 2758 // exception pending => remove activation and forward to exception handler 2759 2760 __ str(zr, Address(rthread, JavaThread::vm_result_offset())); 2761 2762 __ ldr(r0, Address(rthread, Thread::pending_exception_offset())); 2763 __ far_jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 2764 2765 // ------------- 2766 // make sure all code is generated 2767 masm->flush(); 2768 2769 // return the blob 2770 // frame_size_words or bytes?? 2771 return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, true); 2772 } 2773 2774 // Continuation point for throwing of implicit exceptions that are 2775 // not handled in the current activation. Fabricates an exception 2776 // oop and initiates normal exception dispatching in this 2777 // frame. Since we need to preserve callee-saved values (currently 2778 // only for C2, but done for C1 as well) we need a callee-saved oop 2779 // map and therefore have to make these stubs into RuntimeStubs 2780 // rather than BufferBlobs. If the compiler needs all registers to 2781 // be preserved between the fault point and the exception handler 2782 // then it must assume responsibility for that in 2783 // AbstractCompiler::continuation_for_implicit_null_exception or 2784 // continuation_for_implicit_division_by_zero_exception. All other 2785 // implicit exceptions (e.g., NullPointerException or 2786 // AbstractMethodError on entry) are either at call sites or 2787 // otherwise assume that stack unwinding will be initiated, so 2788 // caller saved registers were assumed volatile in the compiler. 2789 2790 RuntimeStub* SharedRuntime::generate_throw_exception(const char* name, address runtime_entry) { 2791 // Information about frame layout at time of blocking runtime call. 2792 // Note that we only have to preserve callee-saved registers since 2793 // the compilers are responsible for supplying a continuation point 2794 // if they expect all registers to be preserved. 2795 // n.b. aarch64 asserts that frame::arg_reg_save_area_bytes == 0 2796 enum layout { 2797 rfp_off = 0, 2798 rfp_off2, 2799 return_off, 2800 return_off2, 2801 framesize // inclusive of return address 2802 }; 2803 2804 int insts_size = 512; 2805 int locs_size = 64; 2806 2807 ResourceMark rm; 2808 const char* timer_msg = "SharedRuntime generate_throw_exception"; 2809 TraceTime timer(timer_msg, TRACETIME_LOG(Info, startuptime)); 2810 2811 CodeBuffer code(name, insts_size, locs_size); 2812 OopMapSet* oop_maps = new OopMapSet(); 2813 MacroAssembler* masm = new MacroAssembler(&code); 2814 2815 address start = __ pc(); 2816 2817 // This is an inlined and slightly modified version of call_VM 2818 // which has the ability to fetch the return PC out of 2819 // thread-local storage and also sets up last_Java_sp slightly 2820 // differently than the real call_VM 2821 2822 __ enter(); // Save FP and LR before call 2823 2824 assert(is_even(framesize/2), "sp not 16-byte aligned"); 2825 2826 // lr and fp are already in place 2827 __ sub(sp, rfp, ((uint64_t)framesize-4) << LogBytesPerInt); // prolog 2828 2829 int frame_complete = __ pc() - start; 2830 2831 // Set up last_Java_sp and last_Java_fp 2832 address the_pc = __ pc(); 2833 __ set_last_Java_frame(sp, rfp, the_pc, rscratch1); 2834 2835 __ mov(c_rarg0, rthread); 2836 BLOCK_COMMENT("call runtime_entry"); 2837 __ mov(rscratch1, runtime_entry); 2838 __ blr(rscratch1); 2839 2840 // Generate oop map 2841 OopMap* map = new OopMap(framesize, 0); 2842 2843 oop_maps->add_gc_map(the_pc - start, map); 2844 2845 __ reset_last_Java_frame(true); 2846 2847 // Reinitialize the ptrue predicate register, in case the external runtime 2848 // call clobbers ptrue reg, as we may return to SVE compiled code. 2849 __ reinitialize_ptrue(); 2850 2851 __ leave(); 2852 2853 // check for pending exceptions 2854 #ifdef ASSERT 2855 Label L; 2856 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 2857 __ cbnz(rscratch1, L); 2858 __ should_not_reach_here(); 2859 __ bind(L); 2860 #endif // ASSERT 2861 __ far_jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 2862 2863 // codeBlob framesize is in words (not VMRegImpl::slot_size) 2864 RuntimeStub* stub = 2865 RuntimeStub::new_runtime_stub(name, 2866 &code, 2867 frame_complete, 2868 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 2869 oop_maps, false); 2870 return stub; 2871 } 2872 2873 #if INCLUDE_JFR 2874 2875 static void jfr_prologue(address the_pc, MacroAssembler* masm, Register thread) { 2876 __ set_last_Java_frame(sp, rfp, the_pc, rscratch1); 2877 __ mov(c_rarg0, thread); 2878 } 2879 2880 // The handle is dereferenced through a load barrier. 2881 static void jfr_epilogue(MacroAssembler* masm) { 2882 __ reset_last_Java_frame(true); 2883 } 2884 2885 // For c2: c_rarg0 is junk, call to runtime to write a checkpoint. 2886 // It returns a jobject handle to the event writer. 2887 // The handle is dereferenced and the return value is the event writer oop. 2888 RuntimeStub* SharedRuntime::generate_jfr_write_checkpoint() { 2889 enum layout { 2890 rbp_off, 2891 rbpH_off, 2892 return_off, 2893 return_off2, 2894 framesize // inclusive of return address 2895 }; 2896 2897 int insts_size = 1024; 2898 int locs_size = 64; 2899 CodeBuffer code("jfr_write_checkpoint", insts_size, locs_size); 2900 OopMapSet* oop_maps = new OopMapSet(); 2901 MacroAssembler* masm = new MacroAssembler(&code); 2902 2903 address start = __ pc(); 2904 __ enter(); 2905 int frame_complete = __ pc() - start; 2906 address the_pc = __ pc(); 2907 jfr_prologue(the_pc, masm, rthread); 2908 __ call_VM_leaf(CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::write_checkpoint), 1); 2909 jfr_epilogue(masm); 2910 __ resolve_global_jobject(r0, rscratch1, rscratch2); 2911 __ leave(); 2912 __ ret(lr); 2913 2914 OopMap* map = new OopMap(framesize, 1); // rfp 2915 oop_maps->add_gc_map(the_pc - start, map); 2916 2917 RuntimeStub* stub = // codeBlob framesize is in words (not VMRegImpl::slot_size) 2918 RuntimeStub::new_runtime_stub("jfr_write_checkpoint", &code, frame_complete, 2919 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 2920 oop_maps, false); 2921 return stub; 2922 } 2923 2924 // For c2: call to return a leased buffer. 2925 RuntimeStub* SharedRuntime::generate_jfr_return_lease() { 2926 enum layout { 2927 rbp_off, 2928 rbpH_off, 2929 return_off, 2930 return_off2, 2931 framesize // inclusive of return address 2932 }; 2933 2934 int insts_size = 1024; 2935 int locs_size = 64; 2936 2937 CodeBuffer code("jfr_return_lease", insts_size, locs_size); 2938 OopMapSet* oop_maps = new OopMapSet(); 2939 MacroAssembler* masm = new MacroAssembler(&code); 2940 2941 address start = __ pc(); 2942 __ enter(); 2943 int frame_complete = __ pc() - start; 2944 address the_pc = __ pc(); 2945 jfr_prologue(the_pc, masm, rthread); 2946 __ call_VM_leaf(CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::return_lease), 1); 2947 jfr_epilogue(masm); 2948 2949 __ leave(); 2950 __ ret(lr); 2951 2952 OopMap* map = new OopMap(framesize, 1); // rfp 2953 oop_maps->add_gc_map(the_pc - start, map); 2954 2955 RuntimeStub* stub = // codeBlob framesize is in words (not VMRegImpl::slot_size) 2956 RuntimeStub::new_runtime_stub("jfr_return_lease", &code, frame_complete, 2957 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 2958 oop_maps, false); 2959 return stub; 2960 } 2961 2962 #endif // INCLUDE_JFR --- EOF ---