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