1 /* 2 * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "compiler/compiler_globals.hpp" 29 #include "gc/shared/barrierSet.hpp" 30 #include "gc/shared/barrierSetAssembler.hpp" 31 #include "interp_masm_aarch64.hpp" 32 #include "interpreter/interpreter.hpp" 33 #include "interpreter/interpreterRuntime.hpp" 34 #include "logging/log.hpp" 35 #include "oops/arrayOop.hpp" 36 #include "oops/markWord.hpp" 37 #include "oops/method.hpp" 38 #include "oops/methodData.hpp" 39 #include "oops/resolvedFieldEntry.hpp" 40 #include "oops/resolvedIndyEntry.hpp" 41 #include "oops/resolvedMethodEntry.hpp" 42 #include "prims/jvmtiExport.hpp" 43 #include "prims/jvmtiThreadState.hpp" 44 #include "runtime/basicLock.hpp" 45 #include "runtime/frame.inline.hpp" 46 #include "runtime/javaThread.hpp" 47 #include "runtime/runtimeUpcalls.hpp" 48 #include "runtime/safepointMechanism.hpp" 49 #include "runtime/sharedRuntime.hpp" 50 #include "utilities/powerOfTwo.hpp" 51 52 void InterpreterMacroAssembler::narrow(Register result) { 53 54 // Get method->_constMethod->_result_type 55 ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize)); 56 ldr(rscratch1, Address(rscratch1, Method::const_offset())); 57 ldrb(rscratch1, Address(rscratch1, ConstMethod::result_type_offset())); 58 59 Label done, notBool, notByte, notChar; 60 61 // common case first 62 cmpw(rscratch1, T_INT); 63 br(Assembler::EQ, done); 64 65 // mask integer result to narrower return type. 66 cmpw(rscratch1, T_BOOLEAN); 67 br(Assembler::NE, notBool); 68 andw(result, result, 0x1); 69 b(done); 70 71 bind(notBool); 72 cmpw(rscratch1, T_BYTE); 73 br(Assembler::NE, notByte); 74 sbfx(result, result, 0, 8); 75 b(done); 76 77 bind(notByte); 78 cmpw(rscratch1, T_CHAR); 79 br(Assembler::NE, notChar); 80 ubfx(result, result, 0, 16); // truncate upper 16 bits 81 b(done); 82 83 bind(notChar); 84 sbfx(result, result, 0, 16); // sign-extend short 85 86 // Nothing to do for T_INT 87 bind(done); 88 } 89 90 void InterpreterMacroAssembler::jump_to_entry(address entry) { 91 assert(entry, "Entry must have been generated by now"); 92 b(entry); 93 } 94 95 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { 96 if (JvmtiExport::can_pop_frame()) { 97 Label L; 98 // Initiate popframe handling only if it is not already being 99 // processed. If the flag has the popframe_processing bit set, it 100 // means that this code is called *during* popframe handling - we 101 // don't want to reenter. 102 // This method is only called just after the call into the vm in 103 // call_VM_base, so the arg registers are available. 104 ldrw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset())); 105 tbz(rscratch1, exact_log2(JavaThread::popframe_pending_bit), L); 106 tbnz(rscratch1, exact_log2(JavaThread::popframe_processing_bit), L); 107 // Call Interpreter::remove_activation_preserving_args_entry() to get the 108 // address of the same-named entrypoint in the generated interpreter code. 109 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); 110 br(r0); 111 bind(L); 112 } 113 } 114 115 116 void InterpreterMacroAssembler::load_earlyret_value(TosState state) { 117 ldr(r2, Address(rthread, JavaThread::jvmti_thread_state_offset())); 118 const Address tos_addr(r2, JvmtiThreadState::earlyret_tos_offset()); 119 const Address oop_addr(r2, JvmtiThreadState::earlyret_oop_offset()); 120 const Address val_addr(r2, JvmtiThreadState::earlyret_value_offset()); 121 switch (state) { 122 case atos: ldr(r0, oop_addr); 123 str(zr, oop_addr); 124 interp_verify_oop(r0, state); break; 125 case ltos: ldr(r0, val_addr); break; 126 case btos: // fall through 127 case ztos: // fall through 128 case ctos: // fall through 129 case stos: // fall through 130 case itos: ldrw(r0, val_addr); break; 131 case ftos: ldrs(v0, val_addr); break; 132 case dtos: ldrd(v0, val_addr); break; 133 case vtos: /* nothing to do */ break; 134 default : ShouldNotReachHere(); 135 } 136 // Clean up tos value in the thread object 137 movw(rscratch1, (int) ilgl); 138 strw(rscratch1, tos_addr); 139 strw(zr, val_addr); 140 } 141 142 143 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { 144 if (JvmtiExport::can_force_early_return()) { 145 Label L; 146 ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset())); 147 cbz(rscratch1, L); // if (thread->jvmti_thread_state() == nullptr) exit; 148 149 // Initiate earlyret handling only if it is not already being processed. 150 // If the flag has the earlyret_processing bit set, it means that this code 151 // is called *during* earlyret handling - we don't want to reenter. 152 ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_state_offset())); 153 cmpw(rscratch1, JvmtiThreadState::earlyret_pending); 154 br(Assembler::NE, L); 155 156 // Call Interpreter::remove_activation_early_entry() to get the address of the 157 // same-named entrypoint in the generated interpreter code. 158 ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset())); 159 ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_tos_offset())); 160 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), rscratch1); 161 br(r0); 162 bind(L); 163 } 164 } 165 166 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp( 167 Register reg, 168 int bcp_offset) { 169 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); 170 ldrh(reg, Address(rbcp, bcp_offset)); 171 rev16(reg, reg); 172 } 173 174 void InterpreterMacroAssembler::get_dispatch() { 175 uint64_t offset; 176 adrp(rdispatch, ExternalAddress((address)Interpreter::dispatch_table()), offset); 177 // Use add() here after ARDP, rather than lea(). 178 // lea() does not generate anything if its offset is zero. 179 // However, relocs expect to find either an ADD or a load/store 180 // insn after an ADRP. add() always generates an ADD insn, even 181 // for add(Rn, Rn, 0). 182 add(rdispatch, rdispatch, offset); 183 } 184 185 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, 186 int bcp_offset, 187 size_t index_size) { 188 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 189 if (index_size == sizeof(u2)) { 190 load_unsigned_short(index, Address(rbcp, bcp_offset)); 191 } else if (index_size == sizeof(u4)) { 192 // assert(EnableInvokeDynamic, "giant index used only for JSR 292"); 193 ldrw(index, Address(rbcp, bcp_offset)); 194 } else if (index_size == sizeof(u1)) { 195 load_unsigned_byte(index, Address(rbcp, bcp_offset)); 196 } else { 197 ShouldNotReachHere(); 198 } 199 } 200 201 void InterpreterMacroAssembler::get_method_counters(Register method, 202 Register mcs, Label& skip) { 203 Label has_counters; 204 ldr(mcs, Address(method, Method::method_counters_offset())); 205 cbnz(mcs, has_counters); 206 call_VM(noreg, CAST_FROM_FN_PTR(address, 207 InterpreterRuntime::build_method_counters), method); 208 ldr(mcs, Address(method, Method::method_counters_offset())); 209 cbz(mcs, skip); // No MethodCounters allocated, OutOfMemory 210 bind(has_counters); 211 } 212 213 // Load object from cpool->resolved_references(index) 214 void InterpreterMacroAssembler::load_resolved_reference_at_index( 215 Register result, Register index, Register tmp) { 216 assert_different_registers(result, index); 217 218 get_constant_pool(result); 219 // load pointer for resolved_references[] objArray 220 ldr(result, Address(result, ConstantPool::cache_offset())); 221 ldr(result, Address(result, ConstantPoolCache::resolved_references_offset())); 222 resolve_oop_handle(result, tmp, rscratch2); 223 // Add in the index 224 add(index, index, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop); 225 load_heap_oop(result, Address(result, index, Address::uxtw(LogBytesPerHeapOop)), tmp, rscratch2); 226 } 227 228 void InterpreterMacroAssembler::load_resolved_klass_at_offset( 229 Register cpool, Register index, Register klass, Register temp) { 230 add(temp, cpool, index, LSL, LogBytesPerWord); 231 ldrh(temp, Address(temp, sizeof(ConstantPool))); // temp = resolved_klass_index 232 ldr(klass, Address(cpool, ConstantPool::resolved_klasses_offset())); // klass = cpool->_resolved_klasses 233 add(klass, klass, temp, LSL, LogBytesPerWord); 234 ldr(klass, Address(klass, Array<Klass*>::base_offset_in_bytes())); 235 } 236 237 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a 238 // subtype of super_klass. 239 // 240 // Args: 241 // r0: superklass 242 // Rsub_klass: subklass 243 // 244 // Kills: 245 // r2, r5 246 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, 247 Label& ok_is_subtype) { 248 assert(Rsub_klass != r0, "r0 holds superklass"); 249 assert(Rsub_klass != r2, "r2 holds 2ndary super array length"); 250 assert(Rsub_klass != r5, "r5 holds 2ndary super array scan ptr"); 251 252 // Profile the not-null value's klass. 253 profile_typecheck(r2, Rsub_klass, r5); // blows r2, reloads r5 254 255 // Do the check. 256 check_klass_subtype(Rsub_klass, r0, r2, ok_is_subtype); // blows r2 257 } 258 259 // Java Expression Stack 260 261 void InterpreterMacroAssembler::pop_ptr(Register r) { 262 ldr(r, post(esp, wordSize)); 263 } 264 265 void InterpreterMacroAssembler::pop_i(Register r) { 266 ldrw(r, post(esp, wordSize)); 267 } 268 269 void InterpreterMacroAssembler::pop_l(Register r) { 270 ldr(r, post(esp, 2 * Interpreter::stackElementSize)); 271 } 272 273 void InterpreterMacroAssembler::push_ptr(Register r) { 274 str(r, pre(esp, -wordSize)); 275 } 276 277 void InterpreterMacroAssembler::push_i(Register r) { 278 str(r, pre(esp, -wordSize)); 279 } 280 281 void InterpreterMacroAssembler::push_l(Register r) { 282 str(zr, pre(esp, -wordSize)); 283 str(r, pre(esp, - wordSize)); 284 } 285 286 void InterpreterMacroAssembler::pop_f(FloatRegister r) { 287 ldrs(r, post(esp, wordSize)); 288 } 289 290 void InterpreterMacroAssembler::pop_d(FloatRegister r) { 291 ldrd(r, post(esp, 2 * Interpreter::stackElementSize)); 292 } 293 294 void InterpreterMacroAssembler::push_f(FloatRegister r) { 295 strs(r, pre(esp, -wordSize)); 296 } 297 298 void InterpreterMacroAssembler::push_d(FloatRegister r) { 299 strd(r, pre(esp, 2* -wordSize)); 300 } 301 302 void InterpreterMacroAssembler::pop(TosState state) { 303 switch (state) { 304 case atos: pop_ptr(); break; 305 case btos: 306 case ztos: 307 case ctos: 308 case stos: 309 case itos: pop_i(); break; 310 case ltos: pop_l(); break; 311 case ftos: pop_f(); break; 312 case dtos: pop_d(); break; 313 case vtos: /* nothing to do */ break; 314 default: ShouldNotReachHere(); 315 } 316 interp_verify_oop(r0, state); 317 } 318 319 void InterpreterMacroAssembler::push(TosState state) { 320 interp_verify_oop(r0, state); 321 switch (state) { 322 case atos: push_ptr(); break; 323 case btos: 324 case ztos: 325 case ctos: 326 case stos: 327 case itos: push_i(); break; 328 case ltos: push_l(); break; 329 case ftos: push_f(); break; 330 case dtos: push_d(); break; 331 case vtos: /* nothing to do */ break; 332 default : ShouldNotReachHere(); 333 } 334 } 335 336 // Helpers for swap and dup 337 void InterpreterMacroAssembler::load_ptr(int n, Register val) { 338 ldr(val, Address(esp, Interpreter::expr_offset_in_bytes(n))); 339 } 340 341 void InterpreterMacroAssembler::store_ptr(int n, Register val) { 342 str(val, Address(esp, Interpreter::expr_offset_in_bytes(n))); 343 } 344 345 void InterpreterMacroAssembler::load_float(Address src) { 346 ldrs(v0, src); 347 } 348 349 void InterpreterMacroAssembler::load_double(Address src) { 350 ldrd(v0, src); 351 } 352 353 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { 354 // set sender sp 355 mov(r19_sender_sp, sp); 356 // record last_sp 357 sub(rscratch1, esp, rfp); 358 asr(rscratch1, rscratch1, Interpreter::logStackElementSize); 359 str(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 360 } 361 362 // Jump to from_interpreted entry of a call unless single stepping is possible 363 // in this thread in which case we must call the i2i entry 364 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { 365 prepare_to_jump_from_interpreted(); 366 367 if (JvmtiExport::can_post_interpreter_events()) { 368 Label run_compiled_code; 369 // JVMTI events, such as single-stepping, are implemented partly by avoiding running 370 // compiled code in threads for which the event is enabled. Check here for 371 // interp_only_mode if these events CAN be enabled. 372 ldrw(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset())); 373 cbzw(rscratch1, run_compiled_code); 374 ldr(rscratch1, Address(method, Method::interpreter_entry_offset())); 375 br(rscratch1); 376 bind(run_compiled_code); 377 } 378 379 ldr(rscratch1, Address(method, Method::from_interpreted_offset())); 380 br(rscratch1); 381 } 382 383 // The following two routines provide a hook so that an implementation 384 // can schedule the dispatch in two parts. amd64 does not do this. 385 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { 386 } 387 388 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { 389 dispatch_next(state, step); 390 } 391 392 void InterpreterMacroAssembler::dispatch_base(TosState state, 393 address* table, 394 bool verifyoop, 395 bool generate_poll) { 396 if (VerifyActivationFrameSize) { 397 Unimplemented(); 398 } 399 if (verifyoop) { 400 interp_verify_oop(r0, state); 401 } 402 403 Label safepoint; 404 address* const safepoint_table = Interpreter::safept_table(state); 405 bool needs_thread_local_poll = generate_poll && table != safepoint_table; 406 407 if (needs_thread_local_poll) { 408 NOT_PRODUCT(block_comment("Thread-local Safepoint poll")); 409 ldr(rscratch2, Address(rthread, JavaThread::polling_word_offset())); 410 tbnz(rscratch2, exact_log2(SafepointMechanism::poll_bit()), safepoint); 411 } 412 413 if (table == Interpreter::dispatch_table(state)) { 414 addw(rscratch2, rscratch1, Interpreter::distance_from_dispatch_table(state)); 415 ldr(rscratch2, Address(rdispatch, rscratch2, Address::uxtw(3))); 416 } else { 417 mov(rscratch2, (address)table); 418 ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3))); 419 } 420 br(rscratch2); 421 422 if (needs_thread_local_poll) { 423 bind(safepoint); 424 lea(rscratch2, ExternalAddress((address)safepoint_table)); 425 ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3))); 426 br(rscratch2); 427 } 428 } 429 430 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) { 431 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll); 432 } 433 434 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { 435 dispatch_base(state, Interpreter::normal_table(state)); 436 } 437 438 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { 439 dispatch_base(state, Interpreter::normal_table(state), false); 440 } 441 442 443 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) { 444 // load next bytecode 445 ldrb(rscratch1, Address(pre(rbcp, step))); 446 dispatch_base(state, Interpreter::dispatch_table(state), /*verifyoop*/true, generate_poll); 447 } 448 449 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { 450 // load current bytecode 451 ldrb(rscratch1, Address(rbcp, 0)); 452 dispatch_base(state, table); 453 } 454 455 // remove activation 456 // 457 // Apply stack watermark barrier. 458 // Unlock the receiver if this is a synchronized method. 459 // Unlock any Java monitors from synchronized blocks. 460 // Remove the activation from the stack. 461 // 462 // If there are locked Java monitors 463 // If throw_monitor_exception 464 // throws IllegalMonitorStateException 465 // Else if install_monitor_exception 466 // installs IllegalMonitorStateException 467 // Else 468 // no error processing 469 void InterpreterMacroAssembler::remove_activation( 470 TosState state, 471 bool throw_monitor_exception, 472 bool install_monitor_exception, 473 bool notify_jvmdi) { 474 // Note: Registers r3 xmm0 may be in use for the 475 // result check if synchronized method 476 Label unlocked, unlock, no_unlock; 477 478 // The below poll is for the stack watermark barrier. It allows fixing up frames lazily, 479 // that would normally not be safe to use. Such bad returns into unsafe territory of 480 // the stack, will call InterpreterRuntime::at_unwind. 481 Label slow_path; 482 Label fast_path; 483 safepoint_poll(slow_path, true /* at_return */, false /* acquire */, false /* in_nmethod */); 484 br(Assembler::AL, fast_path); 485 bind(slow_path); 486 push(state); 487 set_last_Java_frame(esp, rfp, (address)pc(), rscratch1); 488 super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread); 489 reset_last_Java_frame(true); 490 pop(state); 491 bind(fast_path); 492 493 // get the value of _do_not_unlock_if_synchronized into r3 494 const Address do_not_unlock_if_synchronized(rthread, 495 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 496 ldrb(r3, do_not_unlock_if_synchronized); 497 strb(zr, do_not_unlock_if_synchronized); // reset the flag 498 499 // get method access flags 500 ldr(r1, Address(rfp, frame::interpreter_frame_method_offset * wordSize)); 501 ldr(r2, Address(r1, Method::access_flags_offset())); 502 tbz(r2, exact_log2(JVM_ACC_SYNCHRONIZED), unlocked); 503 504 // Don't unlock anything if the _do_not_unlock_if_synchronized flag 505 // is set. 506 cbnz(r3, no_unlock); 507 508 // unlock monitor 509 push(state); // save result 510 511 // BasicObjectLock will be first in list, since this is a 512 // synchronized method. However, need to check that the object has 513 // not been unlocked by an explicit monitorexit bytecode. 514 const Address monitor(rfp, frame::interpreter_frame_initial_sp_offset * 515 wordSize - (int) sizeof(BasicObjectLock)); 516 // We use c_rarg1 so that if we go slow path it will be the correct 517 // register for unlock_object to pass to VM directly 518 lea(c_rarg1, monitor); // address of first monitor 519 520 ldr(r0, Address(c_rarg1, BasicObjectLock::obj_offset())); 521 cbnz(r0, unlock); 522 523 pop(state); 524 if (throw_monitor_exception) { 525 // Entry already unlocked, need to throw exception 526 call_VM(noreg, CAST_FROM_FN_PTR(address, 527 InterpreterRuntime::throw_illegal_monitor_state_exception)); 528 should_not_reach_here(); 529 } else { 530 // Monitor already unlocked during a stack unroll. If requested, 531 // install an illegal_monitor_state_exception. Continue with 532 // stack unrolling. 533 if (install_monitor_exception) { 534 call_VM(noreg, CAST_FROM_FN_PTR(address, 535 InterpreterRuntime::new_illegal_monitor_state_exception)); 536 } 537 b(unlocked); 538 } 539 540 bind(unlock); 541 unlock_object(c_rarg1); 542 pop(state); 543 544 // Check that for block-structured locking (i.e., that all locked 545 // objects has been unlocked) 546 bind(unlocked); 547 548 // r0: Might contain return value 549 550 // Check that all monitors are unlocked 551 { 552 Label loop, exception, entry, restart; 553 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes(); 554 const Address monitor_block_top( 555 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 556 const Address monitor_block_bot( 557 rfp, frame::interpreter_frame_initial_sp_offset * wordSize); 558 559 bind(restart); 560 // We use c_rarg1 so that if we go slow path it will be the correct 561 // register for unlock_object to pass to VM directly 562 ldr(c_rarg1, monitor_block_top); // derelativize pointer 563 lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize))); 564 // c_rarg1 points to current entry, starting with top-most entry 565 566 lea(r19, monitor_block_bot); // points to word before bottom of 567 // monitor block 568 b(entry); 569 570 // Entry already locked, need to throw exception 571 bind(exception); 572 573 if (throw_monitor_exception) { 574 // Throw exception 575 MacroAssembler::call_VM(noreg, 576 CAST_FROM_FN_PTR(address, InterpreterRuntime:: 577 throw_illegal_monitor_state_exception)); 578 should_not_reach_here(); 579 } else { 580 // Stack unrolling. Unlock object and install illegal_monitor_exception. 581 // Unlock does not block, so don't have to worry about the frame. 582 // We don't have to preserve c_rarg1 since we are going to throw an exception. 583 584 push(state); 585 unlock_object(c_rarg1); 586 pop(state); 587 588 if (install_monitor_exception) { 589 call_VM(noreg, CAST_FROM_FN_PTR(address, 590 InterpreterRuntime:: 591 new_illegal_monitor_state_exception)); 592 } 593 594 b(restart); 595 } 596 597 bind(loop); 598 // check if current entry is used 599 ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset())); 600 cbnz(rscratch1, exception); 601 602 add(c_rarg1, c_rarg1, entry_size); // otherwise advance to next entry 603 bind(entry); 604 cmp(c_rarg1, r19); // check if bottom reached 605 br(Assembler::NE, loop); // if not at bottom then check this entry 606 } 607 608 bind(no_unlock); 609 610 // jvmti support 611 if (notify_jvmdi) { 612 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA 613 } else { 614 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA 615 } 616 617 // remove activation 618 // get sender esp 619 ldr(rscratch2, 620 Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize)); 621 if (StackReservedPages > 0) { 622 // testing if reserved zone needs to be re-enabled 623 Label no_reserved_zone_enabling; 624 625 // check if already enabled - if so no re-enabling needed 626 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size"); 627 ldrw(rscratch1, Address(rthread, JavaThread::stack_guard_state_offset())); 628 cmpw(rscratch1, (u1)StackOverflow::stack_guard_enabled); 629 br(Assembler::EQ, no_reserved_zone_enabling); 630 631 // look for an overflow into the stack reserved zone, i.e. 632 // interpreter_frame_sender_sp <= JavaThread::reserved_stack_activation 633 ldr(rscratch1, Address(rthread, JavaThread::reserved_stack_activation_offset())); 634 cmp(rscratch2, rscratch1); 635 br(Assembler::LS, no_reserved_zone_enabling); 636 637 call_VM_leaf( 638 CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread); 639 call_VM(noreg, CAST_FROM_FN_PTR(address, 640 InterpreterRuntime::throw_delayed_StackOverflowError)); 641 should_not_reach_here(); 642 643 bind(no_reserved_zone_enabling); 644 } 645 646 // restore sender esp 647 mov(esp, rscratch2); 648 // remove frame anchor 649 leave(); 650 // If we're returning to interpreted code we will shortly be 651 // adjusting SP to allow some space for ESP. If we're returning to 652 // compiled code the saved sender SP was saved in sender_sp, so this 653 // restores it. 654 andr(sp, esp, -16); 655 } 656 657 // Lock object 658 // 659 // Args: 660 // c_rarg1: BasicObjectLock to be used for locking 661 // 662 // Kills: 663 // r0 664 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, .. (param regs) 665 // rscratch1, rscratch2 (scratch regs) 666 void InterpreterMacroAssembler::lock_object(Register lock_reg) 667 { 668 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1"); 669 if (LockingMode == LM_MONITOR) { 670 call_VM_preemptable(noreg, 671 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 672 lock_reg); 673 } else { 674 Label count, done; 675 676 const Register swap_reg = r0; 677 const Register tmp = c_rarg2; 678 const Register obj_reg = c_rarg3; // Will contain the oop 679 const Register tmp2 = c_rarg4; 680 const Register tmp3 = c_rarg5; 681 682 const int obj_offset = in_bytes(BasicObjectLock::obj_offset()); 683 const int lock_offset = in_bytes(BasicObjectLock::lock_offset()); 684 const int mark_offset = lock_offset + 685 BasicLock::displaced_header_offset_in_bytes(); 686 687 Label slow_case; 688 689 // Load object pointer into obj_reg %c_rarg3 690 ldr(obj_reg, Address(lock_reg, obj_offset)); 691 692 if (DiagnoseSyncOnValueBasedClasses != 0) { 693 load_klass(tmp, obj_reg); 694 ldrb(tmp, Address(tmp, Klass::misc_flags_offset())); 695 tst(tmp, KlassFlags::_misc_is_value_based_class); 696 br(Assembler::NE, slow_case); 697 } 698 699 if (LockingMode == LM_LIGHTWEIGHT) { 700 lightweight_lock(lock_reg, obj_reg, tmp, tmp2, tmp3, slow_case); 701 b(done); 702 } else if (LockingMode == LM_LEGACY) { 703 // Load (object->mark() | 1) into swap_reg 704 ldr(rscratch1, Address(obj_reg, oopDesc::mark_offset_in_bytes())); 705 orr(swap_reg, rscratch1, 1); 706 707 // Save (object->mark() | 1) into BasicLock's displaced header 708 str(swap_reg, Address(lock_reg, mark_offset)); 709 710 assert(lock_offset == 0, 711 "displached header must be first word in BasicObjectLock"); 712 713 Label fail; 714 cmpxchg_obj_header(swap_reg, lock_reg, obj_reg, rscratch1, count, /*fallthrough*/nullptr); 715 716 // Fast check for recursive lock. 717 // 718 // Can apply the optimization only if this is a stack lock 719 // allocated in this thread. For efficiency, we can focus on 720 // recently allocated stack locks (instead of reading the stack 721 // base and checking whether 'mark' points inside the current 722 // thread stack): 723 // 1) (mark & 7) == 0, and 724 // 2) sp <= mark < mark + os::pagesize() 725 // 726 // Warning: sp + os::pagesize can overflow the stack base. We must 727 // neither apply the optimization for an inflated lock allocated 728 // just above the thread stack (this is why condition 1 matters) 729 // nor apply the optimization if the stack lock is inside the stack 730 // of another thread. The latter is avoided even in case of overflow 731 // because we have guard pages at the end of all stacks. Hence, if 732 // we go over the stack base and hit the stack of another thread, 733 // this should not be in a writeable area that could contain a 734 // stack lock allocated by that thread. As a consequence, a stack 735 // lock less than page size away from sp is guaranteed to be 736 // owned by the current thread. 737 // 738 // These 3 tests can be done by evaluating the following 739 // expression: ((mark - sp) & (7 - os::vm_page_size())), 740 // assuming both stack pointer and pagesize have their 741 // least significant 3 bits clear. 742 // NOTE: the mark is in swap_reg %r0 as the result of cmpxchg 743 // NOTE2: aarch64 does not like to subtract sp from rn so take a 744 // copy 745 mov(rscratch1, sp); 746 sub(swap_reg, swap_reg, rscratch1); 747 ands(swap_reg, swap_reg, (uint64_t)(7 - (int)os::vm_page_size())); 748 749 // Save the test result, for recursive case, the result is zero 750 str(swap_reg, Address(lock_reg, mark_offset)); 751 br(Assembler::NE, slow_case); 752 753 bind(count); 754 inc_held_monitor_count(rscratch1); 755 b(done); 756 } 757 bind(slow_case); 758 759 // Call the runtime routine for slow case 760 call_VM_preemptable(noreg, 761 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 762 lock_reg); 763 764 bind(done); 765 } 766 } 767 768 769 // Unlocks an object. Used in monitorexit bytecode and 770 // remove_activation. Throws an IllegalMonitorException if object is 771 // not locked by current thread. 772 // 773 // Args: 774 // c_rarg1: BasicObjectLock for lock 775 // 776 // Kills: 777 // r0 778 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs) 779 // rscratch1, rscratch2 (scratch regs) 780 void InterpreterMacroAssembler::unlock_object(Register lock_reg) 781 { 782 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1"); 783 784 if (LockingMode == LM_MONITOR) { 785 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 786 } else { 787 Label count, done; 788 789 const Register swap_reg = r0; 790 const Register header_reg = c_rarg2; // Will contain the old oopMark 791 const Register obj_reg = c_rarg3; // Will contain the oop 792 const Register tmp_reg = c_rarg4; // Temporary used by lightweight_unlock 793 794 save_bcp(); // Save in case of exception 795 796 if (LockingMode != LM_LIGHTWEIGHT) { 797 // Convert from BasicObjectLock structure to object and BasicLock 798 // structure Store the BasicLock address into %r0 799 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset())); 800 } 801 802 // Load oop into obj_reg(%c_rarg3) 803 ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); 804 805 // Free entry 806 str(zr, Address(lock_reg, BasicObjectLock::obj_offset())); 807 808 Label slow_case; 809 if (LockingMode == LM_LIGHTWEIGHT) { 810 lightweight_unlock(obj_reg, header_reg, swap_reg, tmp_reg, slow_case); 811 b(done); 812 } else if (LockingMode == LM_LEGACY) { 813 // Load the old header from BasicLock structure 814 ldr(header_reg, Address(swap_reg, 815 BasicLock::displaced_header_offset_in_bytes())); 816 817 // Test for recursion 818 cbz(header_reg, count); 819 820 // Atomic swap back the old header 821 cmpxchg_obj_header(swap_reg, header_reg, obj_reg, rscratch1, count, &slow_case); 822 823 bind(count); 824 dec_held_monitor_count(rscratch1); 825 b(done); 826 } 827 828 bind(slow_case); 829 // Call the runtime routine for slow case. 830 str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); // restore obj 831 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 832 bind(done); 833 restore_bcp(); 834 } 835 } 836 837 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, 838 Label& zero_continue) { 839 assert(ProfileInterpreter, "must be profiling interpreter"); 840 ldr(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 841 cbz(mdp, zero_continue); 842 } 843 844 // Set the method data pointer for the current bcp. 845 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { 846 assert(ProfileInterpreter, "must be profiling interpreter"); 847 Label set_mdp; 848 stp(r0, r1, Address(pre(sp, -2 * wordSize))); 849 850 // Test MDO to avoid the call if it is null. 851 ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset()))); 852 cbz(r0, set_mdp); 853 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp); 854 // r0: mdi 855 // mdo is guaranteed to be non-zero here, we checked for it before the call. 856 ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset()))); 857 lea(r1, Address(r1, in_bytes(MethodData::data_offset()))); 858 add(r0, r1, r0); 859 str(r0, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 860 bind(set_mdp); 861 ldp(r0, r1, Address(post(sp, 2 * wordSize))); 862 } 863 864 void InterpreterMacroAssembler::verify_method_data_pointer() { 865 assert(ProfileInterpreter, "must be profiling interpreter"); 866 #ifdef ASSERT 867 Label verify_continue; 868 stp(r0, r1, Address(pre(sp, -2 * wordSize))); 869 stp(r2, r3, Address(pre(sp, -2 * wordSize))); 870 test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue 871 get_method(r1); 872 873 // If the mdp is valid, it will point to a DataLayout header which is 874 // consistent with the bcp. The converse is highly probable also. 875 ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset()))); 876 ldr(rscratch1, Address(r1, Method::const_offset())); 877 add(r2, r2, rscratch1, Assembler::LSL); 878 lea(r2, Address(r2, ConstMethod::codes_offset())); 879 cmp(r2, rbcp); 880 br(Assembler::EQ, verify_continue); 881 // r1: method 882 // rbcp: bcp // rbcp == 22 883 // r3: mdp 884 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), 885 r1, rbcp, r3); 886 bind(verify_continue); 887 ldp(r2, r3, Address(post(sp, 2 * wordSize))); 888 ldp(r0, r1, Address(post(sp, 2 * wordSize))); 889 #endif // ASSERT 890 } 891 892 893 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, 894 int constant, 895 Register value) { 896 assert(ProfileInterpreter, "must be profiling interpreter"); 897 Address data(mdp_in, constant); 898 str(value, data); 899 } 900 901 902 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 903 int constant, 904 bool decrement) { 905 increment_mdp_data_at(mdp_in, noreg, constant, decrement); 906 } 907 908 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 909 Register reg, 910 int constant, 911 bool decrement) { 912 assert(ProfileInterpreter, "must be profiling interpreter"); 913 // %%% this does 64bit counters at best it is wasting space 914 // at worst it is a rare bug when counters overflow 915 916 assert_different_registers(rscratch2, rscratch1, mdp_in, reg); 917 918 Address addr1(mdp_in, constant); 919 Address addr2(rscratch2, reg, Address::lsl(0)); 920 Address &addr = addr1; 921 if (reg != noreg) { 922 lea(rscratch2, addr1); 923 addr = addr2; 924 } 925 926 if (decrement) { 927 // Decrement the register. Set condition codes. 928 // Intel does this 929 // addptr(data, (int32_t) -DataLayout::counter_increment); 930 // If the decrement causes the counter to overflow, stay negative 931 // Label L; 932 // jcc(Assembler::negative, L); 933 // addptr(data, (int32_t) DataLayout::counter_increment); 934 // so we do this 935 ldr(rscratch1, addr); 936 subs(rscratch1, rscratch1, (unsigned)DataLayout::counter_increment); 937 Label L; 938 br(Assembler::LO, L); // skip store if counter underflow 939 str(rscratch1, addr); 940 bind(L); 941 } else { 942 assert(DataLayout::counter_increment == 1, 943 "flow-free idiom only works with 1"); 944 // Intel does this 945 // Increment the register. Set carry flag. 946 // addptr(data, DataLayout::counter_increment); 947 // If the increment causes the counter to overflow, pull back by 1. 948 // sbbptr(data, (int32_t)0); 949 // so we do this 950 ldr(rscratch1, addr); 951 adds(rscratch1, rscratch1, DataLayout::counter_increment); 952 Label L; 953 br(Assembler::CS, L); // skip store if counter overflow 954 str(rscratch1, addr); 955 bind(L); 956 } 957 } 958 959 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, 960 int flag_byte_constant) { 961 assert(ProfileInterpreter, "must be profiling interpreter"); 962 int flags_offset = in_bytes(DataLayout::flags_offset()); 963 // Set the flag 964 ldrb(rscratch1, Address(mdp_in, flags_offset)); 965 orr(rscratch1, rscratch1, flag_byte_constant); 966 strb(rscratch1, Address(mdp_in, flags_offset)); 967 } 968 969 970 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, 971 int offset, 972 Register value, 973 Register test_value_out, 974 Label& not_equal_continue) { 975 assert(ProfileInterpreter, "must be profiling interpreter"); 976 if (test_value_out == noreg) { 977 ldr(rscratch1, Address(mdp_in, offset)); 978 cmp(value, rscratch1); 979 } else { 980 // Put the test value into a register, so caller can use it: 981 ldr(test_value_out, Address(mdp_in, offset)); 982 cmp(value, test_value_out); 983 } 984 br(Assembler::NE, not_equal_continue); 985 } 986 987 988 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, 989 int offset_of_disp) { 990 assert(ProfileInterpreter, "must be profiling interpreter"); 991 ldr(rscratch1, Address(mdp_in, offset_of_disp)); 992 add(mdp_in, mdp_in, rscratch1, LSL); 993 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 994 } 995 996 997 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, 998 Register reg, 999 int offset_of_disp) { 1000 assert(ProfileInterpreter, "must be profiling interpreter"); 1001 lea(rscratch1, Address(mdp_in, offset_of_disp)); 1002 ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0))); 1003 add(mdp_in, mdp_in, rscratch1, LSL); 1004 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 1005 } 1006 1007 1008 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, 1009 int constant) { 1010 assert(ProfileInterpreter, "must be profiling interpreter"); 1011 add(mdp_in, mdp_in, (unsigned)constant); 1012 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 1013 } 1014 1015 1016 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { 1017 assert(ProfileInterpreter, "must be profiling interpreter"); 1018 // save/restore across call_VM 1019 stp(zr, return_bci, Address(pre(sp, -2 * wordSize))); 1020 call_VM(noreg, 1021 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), 1022 return_bci); 1023 ldp(zr, return_bci, Address(post(sp, 2 * wordSize))); 1024 } 1025 1026 1027 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, 1028 Register bumped_count) { 1029 if (ProfileInterpreter) { 1030 Label profile_continue; 1031 1032 // If no method data exists, go to profile_continue. 1033 // Otherwise, assign to mdp 1034 test_method_data_pointer(mdp, profile_continue); 1035 1036 // We are taking a branch. Increment the taken count. 1037 // We inline increment_mdp_data_at to return bumped_count in a register 1038 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); 1039 Address data(mdp, in_bytes(JumpData::taken_offset())); 1040 ldr(bumped_count, data); 1041 assert(DataLayout::counter_increment == 1, 1042 "flow-free idiom only works with 1"); 1043 // Intel does this to catch overflow 1044 // addptr(bumped_count, DataLayout::counter_increment); 1045 // sbbptr(bumped_count, 0); 1046 // so we do this 1047 adds(bumped_count, bumped_count, DataLayout::counter_increment); 1048 Label L; 1049 br(Assembler::CS, L); // skip store if counter overflow 1050 str(bumped_count, data); 1051 bind(L); 1052 // The method data pointer needs to be updated to reflect the new target. 1053 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); 1054 bind(profile_continue); 1055 } 1056 } 1057 1058 1059 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { 1060 if (ProfileInterpreter) { 1061 Label profile_continue; 1062 1063 // If no method data exists, go to profile_continue. 1064 test_method_data_pointer(mdp, profile_continue); 1065 1066 // We are taking a branch. Increment the not taken count. 1067 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); 1068 1069 // The method data pointer needs to be updated to correspond to 1070 // the next bytecode 1071 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); 1072 bind(profile_continue); 1073 } 1074 } 1075 1076 1077 void InterpreterMacroAssembler::profile_call(Register mdp) { 1078 if (ProfileInterpreter) { 1079 Label profile_continue; 1080 1081 // If no method data exists, go to profile_continue. 1082 test_method_data_pointer(mdp, profile_continue); 1083 1084 // We are making a call. Increment the count. 1085 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1086 1087 // The method data pointer needs to be updated to reflect the new target. 1088 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); 1089 bind(profile_continue); 1090 } 1091 } 1092 1093 void InterpreterMacroAssembler::profile_final_call(Register mdp) { 1094 if (ProfileInterpreter) { 1095 Label profile_continue; 1096 1097 // If no method data exists, go to profile_continue. 1098 test_method_data_pointer(mdp, profile_continue); 1099 1100 // We are making a call. Increment the count. 1101 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1102 1103 // The method data pointer needs to be updated to reflect the new target. 1104 update_mdp_by_constant(mdp, 1105 in_bytes(VirtualCallData:: 1106 virtual_call_data_size())); 1107 bind(profile_continue); 1108 } 1109 } 1110 1111 1112 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, 1113 Register mdp, 1114 Register reg2, 1115 bool receiver_can_be_null) { 1116 if (ProfileInterpreter) { 1117 Label profile_continue; 1118 1119 // If no method data exists, go to profile_continue. 1120 test_method_data_pointer(mdp, profile_continue); 1121 1122 Label skip_receiver_profile; 1123 if (receiver_can_be_null) { 1124 Label not_null; 1125 // We are making a call. Increment the count for null receiver. 1126 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1127 b(skip_receiver_profile); 1128 bind(not_null); 1129 } 1130 1131 // Record the receiver type. 1132 record_klass_in_profile(receiver, mdp, reg2); 1133 bind(skip_receiver_profile); 1134 1135 // The method data pointer needs to be updated to reflect the new target. 1136 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); 1137 bind(profile_continue); 1138 } 1139 } 1140 1141 // This routine creates a state machine for updating the multi-row 1142 // type profile at a virtual call site (or other type-sensitive bytecode). 1143 // The machine visits each row (of receiver/count) until the receiver type 1144 // is found, or until it runs out of rows. At the same time, it remembers 1145 // the location of the first empty row. (An empty row records null for its 1146 // receiver, and can be allocated for a newly-observed receiver type.) 1147 // Because there are two degrees of freedom in the state, a simple linear 1148 // search will not work; it must be a decision tree. Hence this helper 1149 // function is recursive, to generate the required tree structured code. 1150 // It's the interpreter, so we are trading off code space for speed. 1151 // See below for example code. 1152 void InterpreterMacroAssembler::record_klass_in_profile_helper( 1153 Register receiver, Register mdp, 1154 Register reg2, int start_row, 1155 Label& done) { 1156 if (TypeProfileWidth == 0) { 1157 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1158 } else { 1159 record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth, 1160 &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset); 1161 } 1162 } 1163 1164 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, 1165 Register reg2, int start_row, Label& done, int total_rows, 1166 OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn) { 1167 int last_row = total_rows - 1; 1168 assert(start_row <= last_row, "must be work left to do"); 1169 // Test this row for both the item and for null. 1170 // Take any of three different outcomes: 1171 // 1. found item => increment count and goto done 1172 // 2. found null => keep looking for case 1, maybe allocate this cell 1173 // 3. found something else => keep looking for cases 1 and 2 1174 // Case 3 is handled by a recursive call. 1175 for (int row = start_row; row <= last_row; row++) { 1176 Label next_test; 1177 bool test_for_null_also = (row == start_row); 1178 1179 // See if the item is item[n]. 1180 int item_offset = in_bytes(item_offset_fn(row)); 1181 test_mdp_data_at(mdp, item_offset, item, 1182 (test_for_null_also ? reg2 : noreg), 1183 next_test); 1184 // (Reg2 now contains the item from the CallData.) 1185 1186 // The item is item[n]. Increment count[n]. 1187 int count_offset = in_bytes(item_count_offset_fn(row)); 1188 increment_mdp_data_at(mdp, count_offset); 1189 b(done); 1190 bind(next_test); 1191 1192 if (test_for_null_also) { 1193 Label found_null; 1194 // Failed the equality check on item[n]... Test for null. 1195 if (start_row == last_row) { 1196 // The only thing left to do is handle the null case. 1197 cbz(reg2, found_null); 1198 // Item did not match any saved item and there is no empty row for it. 1199 // Increment total counter to indicate polymorphic case. 1200 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1201 b(done); 1202 bind(found_null); 1203 break; 1204 } 1205 // Since null is rare, make it be the branch-taken case. 1206 cbz(reg2, found_null); 1207 1208 // Put all the "Case 3" tests here. 1209 record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows, 1210 item_offset_fn, item_count_offset_fn); 1211 1212 // Found a null. Keep searching for a matching item, 1213 // but remember that this is an empty (unused) slot. 1214 bind(found_null); 1215 } 1216 } 1217 1218 // In the fall-through case, we found no matching item, but we 1219 // observed the item[start_row] is null. 1220 1221 // Fill in the item field and increment the count. 1222 int item_offset = in_bytes(item_offset_fn(start_row)); 1223 set_mdp_data_at(mdp, item_offset, item); 1224 int count_offset = in_bytes(item_count_offset_fn(start_row)); 1225 mov(reg2, DataLayout::counter_increment); 1226 set_mdp_data_at(mdp, count_offset, reg2); 1227 if (start_row > 0) { 1228 b(done); 1229 } 1230 } 1231 1232 // Example state machine code for three profile rows: 1233 // // main copy of decision tree, rooted at row[1] 1234 // if (row[0].rec == rec) { row[0].incr(); goto done; } 1235 // if (row[0].rec != nullptr) { 1236 // // inner copy of decision tree, rooted at row[1] 1237 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1238 // if (row[1].rec != nullptr) { 1239 // // degenerate decision tree, rooted at row[2] 1240 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1241 // if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow 1242 // row[2].init(rec); goto done; 1243 // } else { 1244 // // remember row[1] is empty 1245 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1246 // row[1].init(rec); goto done; 1247 // } 1248 // } else { 1249 // // remember row[0] is empty 1250 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1251 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1252 // row[0].init(rec); goto done; 1253 // } 1254 // done: 1255 1256 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, 1257 Register mdp, Register reg2) { 1258 assert(ProfileInterpreter, "must be profiling"); 1259 Label done; 1260 1261 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done); 1262 1263 bind (done); 1264 } 1265 1266 void InterpreterMacroAssembler::profile_ret(Register return_bci, 1267 Register mdp) { 1268 if (ProfileInterpreter) { 1269 Label profile_continue; 1270 uint row; 1271 1272 // If no method data exists, go to profile_continue. 1273 test_method_data_pointer(mdp, profile_continue); 1274 1275 // Update the total ret count. 1276 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1277 1278 for (row = 0; row < RetData::row_limit(); row++) { 1279 Label next_test; 1280 1281 // See if return_bci is equal to bci[n]: 1282 test_mdp_data_at(mdp, 1283 in_bytes(RetData::bci_offset(row)), 1284 return_bci, noreg, 1285 next_test); 1286 1287 // return_bci is equal to bci[n]. Increment the count. 1288 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); 1289 1290 // The method data pointer needs to be updated to reflect the new target. 1291 update_mdp_by_offset(mdp, 1292 in_bytes(RetData::bci_displacement_offset(row))); 1293 b(profile_continue); 1294 bind(next_test); 1295 } 1296 1297 update_mdp_for_ret(return_bci); 1298 1299 bind(profile_continue); 1300 } 1301 } 1302 1303 void InterpreterMacroAssembler::profile_null_seen(Register mdp) { 1304 if (ProfileInterpreter) { 1305 Label profile_continue; 1306 1307 // If no method data exists, go to profile_continue. 1308 test_method_data_pointer(mdp, profile_continue); 1309 1310 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); 1311 1312 // The method data pointer needs to be updated. 1313 int mdp_delta = in_bytes(BitData::bit_data_size()); 1314 if (TypeProfileCasts) { 1315 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1316 } 1317 update_mdp_by_constant(mdp, mdp_delta); 1318 1319 bind(profile_continue); 1320 } 1321 } 1322 1323 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { 1324 if (ProfileInterpreter) { 1325 Label profile_continue; 1326 1327 // If no method data exists, go to profile_continue. 1328 test_method_data_pointer(mdp, profile_continue); 1329 1330 // The method data pointer needs to be updated. 1331 int mdp_delta = in_bytes(BitData::bit_data_size()); 1332 if (TypeProfileCasts) { 1333 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1334 1335 // Record the object type. 1336 record_klass_in_profile(klass, mdp, reg2); 1337 } 1338 update_mdp_by_constant(mdp, mdp_delta); 1339 1340 bind(profile_continue); 1341 } 1342 } 1343 1344 void InterpreterMacroAssembler::profile_switch_default(Register mdp) { 1345 if (ProfileInterpreter) { 1346 Label profile_continue; 1347 1348 // If no method data exists, go to profile_continue. 1349 test_method_data_pointer(mdp, profile_continue); 1350 1351 // Update the default case count 1352 increment_mdp_data_at(mdp, 1353 in_bytes(MultiBranchData::default_count_offset())); 1354 1355 // The method data pointer needs to be updated. 1356 update_mdp_by_offset(mdp, 1357 in_bytes(MultiBranchData:: 1358 default_displacement_offset())); 1359 1360 bind(profile_continue); 1361 } 1362 } 1363 1364 void InterpreterMacroAssembler::profile_switch_case(Register index, 1365 Register mdp, 1366 Register reg2) { 1367 if (ProfileInterpreter) { 1368 Label profile_continue; 1369 1370 // If no method data exists, go to profile_continue. 1371 test_method_data_pointer(mdp, profile_continue); 1372 1373 // Build the base (index * per_case_size_in_bytes()) + 1374 // case_array_offset_in_bytes() 1375 movw(reg2, in_bytes(MultiBranchData::per_case_size())); 1376 movw(rscratch1, in_bytes(MultiBranchData::case_array_offset())); 1377 Assembler::maddw(index, index, reg2, rscratch1); 1378 1379 // Update the case count 1380 increment_mdp_data_at(mdp, 1381 index, 1382 in_bytes(MultiBranchData::relative_count_offset())); 1383 1384 // The method data pointer needs to be updated. 1385 update_mdp_by_offset(mdp, 1386 index, 1387 in_bytes(MultiBranchData:: 1388 relative_displacement_offset())); 1389 1390 bind(profile_continue); 1391 } 1392 } 1393 1394 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) { 1395 if (state == atos) { 1396 MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line); 1397 } 1398 } 1399 1400 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { ; } 1401 1402 void InterpreterMacroAssembler::generate_runtime_upcalls_on_method_entry() 1403 { 1404 address upcall = RuntimeUpcalls::on_method_entry_upcall_address(); 1405 if (RuntimeUpcalls::does_upcall_need_method_parameter(upcall)) { 1406 get_method(c_rarg1); 1407 call_VM(noreg,upcall, c_rarg1); 1408 } else { 1409 call_VM(noreg,upcall); 1410 } 1411 } 1412 1413 void InterpreterMacroAssembler::notify_method_entry() { 1414 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1415 // track stack depth. If it is possible to enter interp_only_mode we add 1416 // the code to check if the event should be sent. 1417 if (JvmtiExport::can_post_interpreter_events()) { 1418 Label L; 1419 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset())); 1420 cbzw(r3, L); 1421 call_VM(noreg, CAST_FROM_FN_PTR(address, 1422 InterpreterRuntime::post_method_entry)); 1423 bind(L); 1424 } 1425 1426 if (DTraceMethodProbes) { 1427 get_method(c_rarg1); 1428 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), 1429 rthread, c_rarg1); 1430 } 1431 1432 // RedefineClasses() tracing support for obsolete method entry 1433 if (log_is_enabled(Trace, redefine, class, obsolete) || 1434 log_is_enabled(Trace, interpreter, bytecode)) { 1435 get_method(c_rarg1); 1436 call_VM_leaf( 1437 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), 1438 rthread, c_rarg1); 1439 } 1440 1441 } 1442 1443 1444 void InterpreterMacroAssembler::notify_method_exit( 1445 TosState state, NotifyMethodExitMode mode) { 1446 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1447 // track stack depth. If it is possible to enter interp_only_mode we add 1448 // the code to check if the event should be sent. 1449 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 1450 Label L; 1451 // Note: frame::interpreter_frame_result has a dependency on how the 1452 // method result is saved across the call to post_method_exit. If this 1453 // is changed then the interpreter_frame_result implementation will 1454 // need to be updated too. 1455 1456 // template interpreter will leave the result on the top of the stack. 1457 push(state); 1458 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset())); 1459 cbz(r3, L); 1460 call_VM(noreg, 1461 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); 1462 bind(L); 1463 pop(state); 1464 } 1465 1466 if (DTraceMethodProbes) { 1467 push(state); 1468 get_method(c_rarg1); 1469 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), 1470 rthread, c_rarg1); 1471 pop(state); 1472 } 1473 } 1474 1475 1476 // Jump if ((*counter_addr += increment) & mask) satisfies the condition. 1477 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, 1478 int increment, Address mask, 1479 Register scratch, Register scratch2, 1480 bool preloaded, Condition cond, 1481 Label* where) { 1482 if (!preloaded) { 1483 ldrw(scratch, counter_addr); 1484 } 1485 add(scratch, scratch, increment); 1486 strw(scratch, counter_addr); 1487 ldrw(scratch2, mask); 1488 ands(scratch, scratch, scratch2); 1489 br(cond, *where); 1490 } 1491 1492 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, 1493 int number_of_arguments) { 1494 // interpreter specific 1495 // 1496 // Note: No need to save/restore rbcp & rlocals pointer since these 1497 // are callee saved registers and no blocking/ GC can happen 1498 // in leaf calls. 1499 #ifdef ASSERT 1500 { 1501 Label L; 1502 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1503 cbz(rscratch1, L); 1504 stop("InterpreterMacroAssembler::call_VM_leaf_base:" 1505 " last_sp != nullptr"); 1506 bind(L); 1507 } 1508 #endif /* ASSERT */ 1509 // super call 1510 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); 1511 } 1512 1513 void InterpreterMacroAssembler::call_VM_base(Register oop_result, 1514 Register java_thread, 1515 Register last_java_sp, 1516 address entry_point, 1517 int number_of_arguments, 1518 bool check_exceptions) { 1519 // interpreter specific 1520 // 1521 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't 1522 // really make a difference for these runtime calls, since they are 1523 // slow anyway. Btw., bcp must be saved/restored since it may change 1524 // due to GC. 1525 // assert(java_thread == noreg , "not expecting a precomputed java thread"); 1526 save_bcp(); 1527 #ifdef ASSERT 1528 { 1529 Label L; 1530 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1531 cbz(rscratch1, L); 1532 stop("InterpreterMacroAssembler::call_VM_base:" 1533 " last_sp != nullptr"); 1534 bind(L); 1535 } 1536 #endif /* ASSERT */ 1537 // super call 1538 MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp, 1539 entry_point, number_of_arguments, 1540 check_exceptions); 1541 // interpreter specific 1542 restore_bcp(); 1543 restore_locals(); 1544 } 1545 1546 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result, 1547 address entry_point, 1548 Register arg_1) { 1549 assert(arg_1 == c_rarg1, ""); 1550 Label resume_pc, not_preempted; 1551 1552 #ifdef ASSERT 1553 { 1554 Label L; 1555 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset())); 1556 cbz(rscratch1, L); 1557 stop("Should not have alternate return address set"); 1558 bind(L); 1559 } 1560 #endif /* ASSERT */ 1561 1562 // Force freeze slow path. 1563 push_cont_fastpath(); 1564 1565 // Make VM call. In case of preemption set last_pc to the one we want to resume to. 1566 adr(rscratch1, resume_pc); 1567 str(rscratch1, Address(rthread, JavaThread::last_Java_pc_offset())); 1568 call_VM_base(oop_result, noreg, noreg, entry_point, 1, false /*check_exceptions*/); 1569 1570 pop_cont_fastpath(); 1571 1572 // Check if preempted. 1573 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset())); 1574 cbz(rscratch1, not_preempted); 1575 str(zr, Address(rthread, JavaThread::preempt_alternate_return_offset())); 1576 br(rscratch1); 1577 1578 // In case of preemption, this is where we will resume once we finally acquire the monitor. 1579 bind(resume_pc); 1580 restore_after_resume(false /* is_native */); 1581 1582 bind(not_preempted); 1583 } 1584 1585 void InterpreterMacroAssembler::restore_after_resume(bool is_native) { 1586 lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter())); 1587 blr(rscratch1); 1588 if (is_native) { 1589 // On resume we need to set up stack as expected 1590 push(dtos); 1591 push(ltos); 1592 } 1593 } 1594 1595 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) { 1596 assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index()); 1597 Label update, next, none; 1598 1599 verify_oop(obj); 1600 1601 cbnz(obj, update); 1602 orptr(mdo_addr, TypeEntries::null_seen); 1603 b(next); 1604 1605 bind(update); 1606 load_klass(obj, obj); 1607 1608 ldr(rscratch1, mdo_addr); 1609 eor(obj, obj, rscratch1); 1610 tst(obj, TypeEntries::type_klass_mask); 1611 br(Assembler::EQ, next); // klass seen before, nothing to 1612 // do. The unknown bit may have been 1613 // set already but no need to check. 1614 1615 tbnz(obj, exact_log2(TypeEntries::type_unknown), next); 1616 // already unknown. Nothing to do anymore. 1617 1618 cbz(rscratch1, none); 1619 cmp(rscratch1, (u1)TypeEntries::null_seen); 1620 br(Assembler::EQ, none); 1621 // There is a chance that the checks above 1622 // fail if another thread has just set the 1623 // profiling to this obj's klass 1624 eor(obj, obj, rscratch1); // get back original value before XOR 1625 ldr(rscratch1, mdo_addr); 1626 eor(obj, obj, rscratch1); 1627 tst(obj, TypeEntries::type_klass_mask); 1628 br(Assembler::EQ, next); 1629 1630 // different than before. Cannot keep accurate profile. 1631 orptr(mdo_addr, TypeEntries::type_unknown); 1632 b(next); 1633 1634 bind(none); 1635 // first time here. Set profile type. 1636 str(obj, mdo_addr); 1637 #ifdef ASSERT 1638 andr(obj, obj, TypeEntries::type_mask); 1639 verify_klass_ptr(obj); 1640 #endif 1641 1642 bind(next); 1643 } 1644 1645 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) { 1646 if (!ProfileInterpreter) { 1647 return; 1648 } 1649 1650 if (MethodData::profile_arguments() || MethodData::profile_return()) { 1651 Label profile_continue; 1652 1653 test_method_data_pointer(mdp, profile_continue); 1654 1655 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size()); 1656 1657 ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start)); 1658 cmp(rscratch1, u1(is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag)); 1659 br(Assembler::NE, profile_continue); 1660 1661 if (MethodData::profile_arguments()) { 1662 Label done; 1663 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset()); 1664 1665 for (int i = 0; i < TypeProfileArgsLimit; i++) { 1666 if (i > 0 || MethodData::profile_return()) { 1667 // If return value type is profiled we may have no argument to profile 1668 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset()))); 1669 sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count()); 1670 cmp(tmp, (u1)TypeStackSlotEntries::per_arg_count()); 1671 add(rscratch1, mdp, off_to_args); 1672 br(Assembler::LT, done); 1673 } 1674 ldr(tmp, Address(callee, Method::const_offset())); 1675 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset())); 1676 // stack offset o (zero based) from the start of the argument 1677 // list, for n arguments translates into offset n - o - 1 from 1678 // the end of the argument list 1679 ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i)))); 1680 sub(tmp, tmp, rscratch1); 1681 sub(tmp, tmp, 1); 1682 Address arg_addr = argument_address(tmp); 1683 ldr(tmp, arg_addr); 1684 1685 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))); 1686 profile_obj_type(tmp, mdo_arg_addr); 1687 1688 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size()); 1689 off_to_args += to_add; 1690 } 1691 1692 if (MethodData::profile_return()) { 1693 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset()))); 1694 sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count()); 1695 } 1696 1697 add(rscratch1, mdp, off_to_args); 1698 bind(done); 1699 mov(mdp, rscratch1); 1700 1701 if (MethodData::profile_return()) { 1702 // We're right after the type profile for the last 1703 // argument. tmp is the number of cells left in the 1704 // CallTypeData/VirtualCallTypeData to reach its end. Non null 1705 // if there's a return to profile. 1706 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type"); 1707 add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size)); 1708 } 1709 str(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize)); 1710 } else { 1711 assert(MethodData::profile_return(), "either profile call args or call ret"); 1712 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size())); 1713 } 1714 1715 // mdp points right after the end of the 1716 // CallTypeData/VirtualCallTypeData, right after the cells for the 1717 // return value type if there's one 1718 1719 bind(profile_continue); 1720 } 1721 } 1722 1723 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) { 1724 assert_different_registers(mdp, ret, tmp, rbcp); 1725 if (ProfileInterpreter && MethodData::profile_return()) { 1726 Label profile_continue, done; 1727 1728 test_method_data_pointer(mdp, profile_continue); 1729 1730 if (MethodData::profile_return_jsr292_only()) { 1731 assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2"); 1732 1733 // If we don't profile all invoke bytecodes we must make sure 1734 // it's a bytecode we indeed profile. We can't go back to the 1735 // beginning of the ProfileData we intend to update to check its 1736 // type because we're right after it and we don't known its 1737 // length 1738 Label do_profile; 1739 ldrb(rscratch1, Address(rbcp, 0)); 1740 cmp(rscratch1, (u1)Bytecodes::_invokedynamic); 1741 br(Assembler::EQ, do_profile); 1742 cmp(rscratch1, (u1)Bytecodes::_invokehandle); 1743 br(Assembler::EQ, do_profile); 1744 get_method(tmp); 1745 ldrh(rscratch1, Address(tmp, Method::intrinsic_id_offset())); 1746 subs(zr, rscratch1, static_cast<int>(vmIntrinsics::_compiledLambdaForm)); 1747 br(Assembler::NE, profile_continue); 1748 1749 bind(do_profile); 1750 } 1751 1752 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size())); 1753 mov(tmp, ret); 1754 profile_obj_type(tmp, mdo_ret_addr); 1755 1756 bind(profile_continue); 1757 } 1758 } 1759 1760 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) { 1761 assert_different_registers(rscratch1, rscratch2, mdp, tmp1, tmp2); 1762 if (ProfileInterpreter && MethodData::profile_parameters()) { 1763 Label profile_continue, done; 1764 1765 test_method_data_pointer(mdp, profile_continue); 1766 1767 // Load the offset of the area within the MDO used for 1768 // parameters. If it's negative we're not profiling any parameters 1769 ldrw(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()))); 1770 tbnz(tmp1, 31, profile_continue); // i.e. sign bit set 1771 1772 // Compute a pointer to the area for parameters from the offset 1773 // and move the pointer to the slot for the last 1774 // parameters. Collect profiling from last parameter down. 1775 // mdo start + parameters offset + array length - 1 1776 add(mdp, mdp, tmp1); 1777 ldr(tmp1, Address(mdp, ArrayData::array_len_offset())); 1778 sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count()); 1779 1780 Label loop; 1781 bind(loop); 1782 1783 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0)); 1784 int type_base = in_bytes(ParametersTypeData::type_offset(0)); 1785 int per_arg_scale = exact_log2(DataLayout::cell_size); 1786 add(rscratch1, mdp, off_base); 1787 add(rscratch2, mdp, type_base); 1788 1789 Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale)); 1790 Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale)); 1791 1792 // load offset on the stack from the slot for this parameter 1793 ldr(tmp2, arg_off); 1794 neg(tmp2, tmp2); 1795 // read the parameter from the local area 1796 ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize))); 1797 1798 // profile the parameter 1799 profile_obj_type(tmp2, arg_type); 1800 1801 // go to next parameter 1802 subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count()); 1803 br(Assembler::GE, loop); 1804 1805 bind(profile_continue); 1806 } 1807 } 1808 1809 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) { 1810 // Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp 1811 get_cache_index_at_bcp(index, 1, sizeof(u4)); 1812 // Get address of invokedynamic array 1813 ldr(cache, Address(rcpool, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()))); 1814 // Scale the index to be the entry index * sizeof(ResolvedIndyEntry) 1815 lsl(index, index, log2i_exact(sizeof(ResolvedIndyEntry))); 1816 add(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes()); 1817 lea(cache, Address(cache, index)); 1818 } 1819 1820 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) { 1821 // Get index out of bytecode pointer 1822 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 1823 // Take shortcut if the size is a power of 2 1824 if (is_power_of_2(sizeof(ResolvedFieldEntry))) { 1825 lsl(index, index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2 1826 } else { 1827 mov(cache, sizeof(ResolvedFieldEntry)); 1828 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry) 1829 } 1830 // Get address of field entries array 1831 ldr(cache, Address(rcpool, ConstantPoolCache::field_entries_offset())); 1832 add(cache, cache, Array<ResolvedFieldEntry>::base_offset_in_bytes()); 1833 lea(cache, Address(cache, index)); 1834 // Prevents stale data from being read after the bytecode is patched to the fast bytecode 1835 membar(MacroAssembler::LoadLoad); 1836 } 1837 1838 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) { 1839 // Get index out of bytecode pointer 1840 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 1841 mov(cache, sizeof(ResolvedMethodEntry)); 1842 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry) 1843 1844 // Get address of field entries array 1845 ldr(cache, Address(rcpool, ConstantPoolCache::method_entries_offset())); 1846 add(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes()); 1847 lea(cache, Address(cache, index)); 1848 }