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