< prev index next >

src/hotspot/cpu/x86/interp_masm_x86.cpp

Print this page

  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 "compiler/compiler_globals.hpp"
  26 #include "interp_masm_x86.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "interpreter/interpreterRuntime.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/arrayOop.hpp"

  31 #include "oops/markWord.hpp"
  32 #include "oops/methodData.hpp"
  33 #include "oops/method.hpp"

  34 #include "oops/resolvedFieldEntry.hpp"
  35 #include "oops/resolvedIndyEntry.hpp"
  36 #include "oops/resolvedMethodEntry.hpp"
  37 #include "prims/jvmtiExport.hpp"
  38 #include "prims/jvmtiThreadState.hpp"
  39 #include "runtime/basicLock.hpp"
  40 #include "runtime/frame.inline.hpp"
  41 #include "runtime/javaThread.hpp"
  42 #include "runtime/safepointMechanism.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "utilities/powerOfTwo.hpp"
  45 
  46 // Implementation of InterpreterMacroAssembler
  47 
  48 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  49   assert(entry, "Entry must have been generated by now");
  50   jump(RuntimeAddress(entry));
  51 }
  52 
  53 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {

 148         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
 149         profile_obj_type(tmp, mdo_arg_addr);
 150 
 151         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
 152         addptr(mdp, to_add);
 153         off_to_args += to_add;
 154       }
 155 
 156       if (MethodData::profile_return()) {
 157         movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
 158         subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
 159       }
 160 
 161       bind(done);
 162 
 163       if (MethodData::profile_return()) {
 164         // We're right after the type profile for the last
 165         // argument. tmp is the number of cells left in the
 166         // CallTypeData/VirtualCallTypeData to reach its end. Non null
 167         // if there's a return to profile.
 168         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
 169         shll(tmp, log2i_exact((int)DataLayout::cell_size));
 170         addptr(mdp, tmp);
 171       }
 172       movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp);
 173     } else {
 174       assert(MethodData::profile_return(), "either profile call args or call ret");
 175       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
 176     }
 177 
 178     // mdp points right after the end of the
 179     // CallTypeData/VirtualCallTypeData, right after the cells for the
 180     // return value type if there's one
 181 
 182     bind(profile_continue);
 183   }
 184 }
 185 
 186 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
 187   assert_different_registers(mdp, ret, tmp, _bcp_register);
 188   if (ProfileInterpreter && MethodData::profile_return()) {

 193     if (MethodData::profile_return_jsr292_only()) {
 194       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
 195 
 196       // If we don't profile all invoke bytecodes we must make sure
 197       // it's a bytecode we indeed profile. We can't go back to the
 198       // beginning of the ProfileData we intend to update to check its
 199       // type because we're right after it and we don't known its
 200       // length
 201       Label do_profile;
 202       cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
 203       jcc(Assembler::equal, do_profile);
 204       cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
 205       jcc(Assembler::equal, do_profile);
 206       get_method(tmp);
 207       cmpw(Address(tmp, Method::intrinsic_id_offset()), static_cast<int>(vmIntrinsics::_compiledLambdaForm));
 208       jcc(Assembler::notEqual, profile_continue);
 209 
 210       bind(do_profile);
 211     }
 212 
 213     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
 214     mov(tmp, ret);
 215     profile_obj_type(tmp, mdo_ret_addr);
 216 
 217     bind(profile_continue);
 218   }
 219 }
 220 
 221 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
 222   if (ProfileInterpreter && MethodData::profile_parameters()) {
 223     Label profile_continue;
 224 
 225     test_method_data_pointer(mdp, profile_continue);
 226 
 227     // Load the offset of the area within the MDO used for
 228     // parameters. If it's negative we're not profiling any parameters
 229     movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
 230     testl(tmp1, tmp1);
 231     jcc(Assembler::negative, profile_continue);
 232 
 233     // Compute a pointer to the area for parameters from the offset

 499                                                              Register cpool,
 500                                                              Register index) {
 501   assert_different_registers(cpool, index);
 502 
 503   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 504   Register resolved_klasses = cpool;
 505   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
 506   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 507 }
 508 
 509 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 510 // subtype of super_klass.
 511 //
 512 // Args:
 513 //      rax: superklass
 514 //      Rsub_klass: subklass
 515 //
 516 // Kills:
 517 //      rcx, rdi
 518 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 519                                                   Label& ok_is_subtype) {

 520   assert(Rsub_klass != rax, "rax holds superklass");
 521   LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
 522   LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
 523   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 524   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 525 
 526   // Profile the not-null value's klass.
 527   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi


 528 
 529   // Do the check.
 530   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 531 }
 532 
 533 
 534 // Java Expression Stack
 535 
 536 void InterpreterMacroAssembler::pop_ptr(Register r) {
 537   pop(r);
 538 }
 539 
 540 void InterpreterMacroAssembler::push_ptr(Register r) {
 541   push(r);
 542 }
 543 
 544 void InterpreterMacroAssembler::push_i(Register r) {
 545   push(r);
 546 }
 547 

 808   // that would normally not be safe to use. Such bad returns into unsafe territory of
 809   // the stack, will call InterpreterRuntime::at_unwind.
 810   Label slow_path;
 811   Label fast_path;
 812   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
 813   jmp(fast_path);
 814   bind(slow_path);
 815   push(state);
 816   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
 817   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
 818   reset_last_Java_frame(true);
 819   pop(state);
 820   bind(fast_path);
 821 
 822   // get the value of _do_not_unlock_if_synchronized into rdx
 823   const Address do_not_unlock_if_synchronized(rthread,
 824     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 825   movbool(rbx, do_not_unlock_if_synchronized);
 826   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 827 
 828  // get method access flags
 829   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 830   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 831   testl(rcx, JVM_ACC_SYNCHRONIZED);
 832   jcc(Assembler::zero, unlocked);
 833 
 834   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 835   // is set.
 836   testbool(rbx);
 837   jcc(Assembler::notZero, no_unlock);
 838 
 839   // unlock monitor
 840   push(state); // save result
 841 
 842   // BasicObjectLock will be first in list, since this is a
 843   // synchronized method. However, need to check that the object has
 844   // not been unlocked by an explicit monitorexit bytecode.
 845   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 846                         wordSize - (int) sizeof(BasicObjectLock));
 847   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 848   // register for unlock_object to pass to VM directly

 930     bind(loop);
 931     // check if current entry is used
 932     cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD);
 933     jcc(Assembler::notEqual, exception);
 934 
 935     addptr(rmon, entry_size); // otherwise advance to next entry
 936     bind(entry);
 937     cmpptr(rmon, rbx); // check if bottom reached
 938     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
 939   }
 940 
 941   bind(no_unlock);
 942 
 943   // jvmti support
 944   if (notify_jvmdi) {
 945     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 946   } else {
 947     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 948   }
 949 
 950   // remove activation
 951   // get sender sp
 952   movptr(rbx,
 953          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
 954   if (StackReservedPages > 0) {


 955     // testing if reserved zone needs to be re-enabled
 956     Register rthread = r15_thread;
 957     Label no_reserved_zone_enabling;
 958 
 959     // check if already enabled - if so no re-enabling needed
 960     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
 961     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
 962     jcc(Assembler::equal, no_reserved_zone_enabling);
 963 
 964     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
 965     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
 966 
 967     call_VM_leaf(
 968       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
 969     call_VM(noreg, CAST_FROM_FN_PTR(address,
 970                    InterpreterRuntime::throw_delayed_StackOverflowError));
 971     should_not_reach_here();
 972 
 973     bind(no_reserved_zone_enabling);
 974   }








































 975   leave();                           // remove frame anchor
 976   pop(ret_addr);                     // get return address
 977   mov(rsp, rbx);                     // set sp to sender sp
 978   pop_cont_fastpath();
 979 }
 980 
 981 void InterpreterMacroAssembler::get_method_counters(Register method,
 982                                                     Register mcs, Label& skip) {
 983   Label has_counters;
 984   movptr(mcs, Address(method, Method::method_counters_offset()));
 985   testptr(mcs, mcs);
 986   jcc(Assembler::notZero, has_counters);
 987   call_VM(noreg, CAST_FROM_FN_PTR(address,
 988           InterpreterRuntime::build_method_counters), method);
 989   movptr(mcs, Address(method,Method::method_counters_offset()));
 990   testptr(mcs, mcs);
 991   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
 992   bind(has_counters);
 993 }
 994 






















































 995 
 996 // Lock object
 997 //
 998 // Args:
 999 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1000 //
1001 // Kills:
1002 //      rax, rbx
1003 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1004   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1005 
1006   if (LockingMode == LM_MONITOR) {
1007     call_VM_preemptable(noreg,
1008             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1009             lock_reg);
1010   } else {
1011     Label count_locking, done, slow_case;
1012 
1013     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1014     const Register tmp_reg = rbx;

1020     const int mark_offset = lock_offset +
1021                             BasicLock::displaced_header_offset_in_bytes();
1022 
1023     // Load object pointer into obj_reg
1024     movptr(obj_reg, Address(lock_reg, obj_offset));
1025 
1026     if (DiagnoseSyncOnValueBasedClasses != 0) {
1027       load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1028       testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1029       jcc(Assembler::notZero, slow_case);
1030     }
1031 
1032     if (LockingMode == LM_LIGHTWEIGHT) {
1033       lightweight_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case);
1034     } else if (LockingMode == LM_LEGACY) {
1035       // Load immediate 1 into swap_reg %rax
1036       movl(swap_reg, 1);
1037 
1038       // Load (object->mark() | 1) into swap_reg %rax
1039       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));




1040 
1041       // Save (object->mark() | 1) into BasicLock's displaced header
1042       movptr(Address(lock_reg, mark_offset), swap_reg);
1043 
1044       assert(lock_offset == 0,
1045              "displaced header must be first word in BasicObjectLock");
1046 
1047       lock();
1048       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1049       jcc(Assembler::zero, count_locking);
1050 
1051       const int zero_bits = 7;
1052 
1053       // Fast check for recursive lock.
1054       //
1055       // Can apply the optimization only if this is a stack lock
1056       // allocated in this thread. For efficiency, we can focus on
1057       // recently allocated stack locks (instead of reading the stack
1058       // base and checking whether 'mark' points inside the current
1059       // thread stack):

1371     test_method_data_pointer(mdp, profile_continue);
1372 
1373     // We are taking a branch.  Increment the taken count.
1374     // We inline increment_mdp_data_at to return bumped_count in a register
1375     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1376     Address data(mdp, in_bytes(JumpData::taken_offset()));
1377     movptr(bumped_count, data);
1378     assert(DataLayout::counter_increment == 1,
1379             "flow-free idiom only works with 1");
1380     addptr(bumped_count, DataLayout::counter_increment);
1381     sbbptr(bumped_count, 0);
1382     movptr(data, bumped_count); // Store back out
1383 
1384     // The method data pointer needs to be updated to reflect the new target.
1385     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1386     bind(profile_continue);
1387   }
1388 }
1389 
1390 
1391 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1392   if (ProfileInterpreter) {
1393     Label profile_continue;
1394 
1395     // If no method data exists, go to profile_continue.
1396     test_method_data_pointer(mdp, profile_continue);
1397 
1398     // We are taking a branch.  Increment the not taken count.
1399     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1400 
1401     // The method data pointer needs to be updated to correspond to
1402     // the next bytecode
1403     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1404     bind(profile_continue);
1405   }
1406 }
1407 
1408 void InterpreterMacroAssembler::profile_call(Register mdp) {
1409   if (ProfileInterpreter) {
1410     Label profile_continue;
1411 
1412     // If no method data exists, go to profile_continue.
1413     test_method_data_pointer(mdp, profile_continue);
1414 
1415     // We are making a call.  Increment the count.
1416     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1417 
1418     // The method data pointer needs to be updated to reflect the new target.
1419     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1420     bind(profile_continue);
1421   }
1422 }
1423 

1446                                                      Register reg2,
1447                                                      bool receiver_can_be_null) {
1448   if (ProfileInterpreter) {
1449     Label profile_continue;
1450 
1451     // If no method data exists, go to profile_continue.
1452     test_method_data_pointer(mdp, profile_continue);
1453 
1454     Label skip_receiver_profile;
1455     if (receiver_can_be_null) {
1456       Label not_null;
1457       testptr(receiver, receiver);
1458       jccb(Assembler::notZero, not_null);
1459       // We are making a call.  Increment the count for null receiver.
1460       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1461       jmp(skip_receiver_profile);
1462       bind(not_null);
1463     }
1464 
1465     // Record the receiver type.
1466     record_klass_in_profile(receiver, mdp, reg2, true);
1467     bind(skip_receiver_profile);
1468 
1469     // The method data pointer needs to be updated to reflect the new target.
1470     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1471     bind(profile_continue);
1472   }
1473 }
1474 
1475 // This routine creates a state machine for updating the multi-row
1476 // type profile at a virtual call site (or other type-sensitive bytecode).
1477 // The machine visits each row (of receiver/count) until the receiver type
1478 // is found, or until it runs out of rows.  At the same time, it remembers
1479 // the location of the first empty row.  (An empty row records null for its
1480 // receiver, and can be allocated for a newly-observed receiver type.)
1481 // Because there are two degrees of freedom in the state, a simple linear
1482 // search will not work; it must be a decision tree.  Hence this helper
1483 // function is recursive, to generate the required tree structured code.
1484 // It's the interpreter, so we are trading off code space for speed.
1485 // See below for example code.
1486 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1487                                         Register receiver, Register mdp,
1488                                         Register reg2, int start_row,
1489                                         Label& done, bool is_virtual_call) {
1490   if (TypeProfileWidth == 0) {
1491     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1492   } else {
1493     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1494                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1495   }
1496 }
1497 
1498 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1499                                                               Label& done, int total_rows,
1500                                                               OffsetFunction item_offset_fn,
1501                                                               OffsetFunction item_count_offset_fn) {
1502   int last_row = total_rows - 1;
1503   assert(start_row <= last_row, "must be work left to do");
1504   // Test this row for both the item and for null.
1505   // Take any of three different outcomes:
1506   //   1. found item => increment count and goto done
1507   //   2. found null => keep looking for case 1, maybe allocate this cell
1508   //   3. found something else => keep looking for cases 1 and 2
1509   // Case 3 is handled by a recursive call.

1573 //     // inner copy of decision tree, rooted at row[1]
1574 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1575 //     if (row[1].rec != nullptr) {
1576 //       // degenerate decision tree, rooted at row[2]
1577 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1578 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1579 //       row[2].init(rec); goto done;
1580 //     } else {
1581 //       // remember row[1] is empty
1582 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1583 //       row[1].init(rec); goto done;
1584 //     }
1585 //   } else {
1586 //     // remember row[0] is empty
1587 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1588 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1589 //     row[0].init(rec); goto done;
1590 //   }
1591 //   done:
1592 
1593 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1594                                                         Register mdp, Register reg2,
1595                                                         bool is_virtual_call) {
1596   assert(ProfileInterpreter, "must be profiling");
1597   Label done;
1598 
1599   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1600 
1601   bind (done);
1602 }
1603 
1604 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1605                                             Register mdp) {
1606   if (ProfileInterpreter) {
1607     Label profile_continue;
1608     uint row;
1609 
1610     // If no method data exists, go to profile_continue.
1611     test_method_data_pointer(mdp, profile_continue);
1612 
1613     // Update the total ret count.
1614     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1615 
1616     for (row = 0; row < RetData::row_limit(); row++) {
1617       Label next_test;
1618 
1619       // See if return_bci is equal to bci[n]:

1656     update_mdp_by_constant(mdp, mdp_delta);
1657 
1658     bind(profile_continue);
1659   }
1660 }
1661 
1662 
1663 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1664   if (ProfileInterpreter) {
1665     Label profile_continue;
1666 
1667     // If no method data exists, go to profile_continue.
1668     test_method_data_pointer(mdp, profile_continue);
1669 
1670     // The method data pointer needs to be updated.
1671     int mdp_delta = in_bytes(BitData::bit_data_size());
1672     if (TypeProfileCasts) {
1673       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1674 
1675       // Record the object type.
1676       record_klass_in_profile(klass, mdp, reg2, false);
1677     }
1678     update_mdp_by_constant(mdp, mdp_delta);
1679 
1680     bind(profile_continue);
1681   }
1682 }
1683 
1684 
1685 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1686   if (ProfileInterpreter) {
1687     Label profile_continue;
1688 
1689     // If no method data exists, go to profile_continue.
1690     test_method_data_pointer(mdp, profile_continue);
1691 
1692     // Update the default case count
1693     increment_mdp_data_at(mdp,
1694                           in_bytes(MultiBranchData::default_count_offset()));
1695 
1696     // The method data pointer needs to be updated.

1716     // case_array_offset_in_bytes()
1717     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1718     imulptr(index, reg2); // XXX l ?
1719     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1720 
1721     // Update the case count
1722     increment_mdp_data_at(mdp,
1723                           index,
1724                           in_bytes(MultiBranchData::relative_count_offset()));
1725 
1726     // The method data pointer needs to be updated.
1727     update_mdp_by_offset(mdp,
1728                          index,
1729                          in_bytes(MultiBranchData::
1730                                   relative_displacement_offset()));
1731 
1732     bind(profile_continue);
1733   }
1734 }
1735 


















































































































1736 
1737 
1738 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1739   if (state == atos) {
1740     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1741   }
1742 }
1743 
1744 
1745 // Jump if ((*counter_addr += increment) & mask) == 0
1746 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1747                                                         Register scratch, Label* where) {
1748   // This update is actually not atomic and can lose a number of updates
1749   // under heavy contention, but the alternative of using the (contended)
1750   // atomic update here penalizes profiling paths too much.
1751   movl(scratch, counter_addr);
1752   incrementl(scratch, InvocationCounter::count_increment);
1753   movl(counter_addr, scratch);
1754   andl(scratch, mask);
1755   if (where != nullptr) {

  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 "compiler/compiler_globals.hpp"
  26 #include "interp_masm_x86.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "interpreter/interpreterRuntime.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/arrayOop.hpp"
  31 #include "oops/constMethodFlags.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/method.hpp"
  35 #include "oops/inlineKlass.hpp"
  36 #include "oops/resolvedFieldEntry.hpp"
  37 #include "oops/resolvedIndyEntry.hpp"
  38 #include "oops/resolvedMethodEntry.hpp"
  39 #include "prims/jvmtiExport.hpp"
  40 #include "prims/jvmtiThreadState.hpp"
  41 #include "runtime/basicLock.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/javaThread.hpp"
  44 #include "runtime/safepointMechanism.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 #include "utilities/powerOfTwo.hpp"
  47 
  48 // Implementation of InterpreterMacroAssembler
  49 
  50 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  51   assert(entry, "Entry must have been generated by now");
  52   jump(RuntimeAddress(entry));
  53 }
  54 
  55 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {

 150         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
 151         profile_obj_type(tmp, mdo_arg_addr);
 152 
 153         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
 154         addptr(mdp, to_add);
 155         off_to_args += to_add;
 156       }
 157 
 158       if (MethodData::profile_return()) {
 159         movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
 160         subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
 161       }
 162 
 163       bind(done);
 164 
 165       if (MethodData::profile_return()) {
 166         // We're right after the type profile for the last
 167         // argument. tmp is the number of cells left in the
 168         // CallTypeData/VirtualCallTypeData to reach its end. Non null
 169         // if there's a return to profile.
 170         assert(SingleTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
 171         shll(tmp, log2i_exact((int)DataLayout::cell_size));
 172         addptr(mdp, tmp);
 173       }
 174       movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp);
 175     } else {
 176       assert(MethodData::profile_return(), "either profile call args or call ret");
 177       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
 178     }
 179 
 180     // mdp points right after the end of the
 181     // CallTypeData/VirtualCallTypeData, right after the cells for the
 182     // return value type if there's one
 183 
 184     bind(profile_continue);
 185   }
 186 }
 187 
 188 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
 189   assert_different_registers(mdp, ret, tmp, _bcp_register);
 190   if (ProfileInterpreter && MethodData::profile_return()) {

 195     if (MethodData::profile_return_jsr292_only()) {
 196       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
 197 
 198       // If we don't profile all invoke bytecodes we must make sure
 199       // it's a bytecode we indeed profile. We can't go back to the
 200       // beginning of the ProfileData we intend to update to check its
 201       // type because we're right after it and we don't known its
 202       // length
 203       Label do_profile;
 204       cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
 205       jcc(Assembler::equal, do_profile);
 206       cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
 207       jcc(Assembler::equal, do_profile);
 208       get_method(tmp);
 209       cmpw(Address(tmp, Method::intrinsic_id_offset()), static_cast<int>(vmIntrinsics::_compiledLambdaForm));
 210       jcc(Assembler::notEqual, profile_continue);
 211 
 212       bind(do_profile);
 213     }
 214 
 215     Address mdo_ret_addr(mdp, -in_bytes(SingleTypeEntry::size()));
 216     mov(tmp, ret);
 217     profile_obj_type(tmp, mdo_ret_addr);
 218 
 219     bind(profile_continue);
 220   }
 221 }
 222 
 223 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
 224   if (ProfileInterpreter && MethodData::profile_parameters()) {
 225     Label profile_continue;
 226 
 227     test_method_data_pointer(mdp, profile_continue);
 228 
 229     // Load the offset of the area within the MDO used for
 230     // parameters. If it's negative we're not profiling any parameters
 231     movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
 232     testl(tmp1, tmp1);
 233     jcc(Assembler::negative, profile_continue);
 234 
 235     // Compute a pointer to the area for parameters from the offset

 501                                                              Register cpool,
 502                                                              Register index) {
 503   assert_different_registers(cpool, index);
 504 
 505   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 506   Register resolved_klasses = cpool;
 507   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
 508   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 509 }
 510 
 511 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 512 // subtype of super_klass.
 513 //
 514 // Args:
 515 //      rax: superklass
 516 //      Rsub_klass: subklass
 517 //
 518 // Kills:
 519 //      rcx, rdi
 520 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 521                                                   Label& ok_is_subtype,
 522                                                   bool profile) {
 523   assert(Rsub_klass != rax, "rax holds superklass");
 524   LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
 525   LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
 526   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 527   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 528 
 529   // Profile the not-null value's klass.
 530   if (profile) {
 531     profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
 532   }
 533 
 534   // Do the check.
 535   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 536 }
 537 
 538 
 539 // Java Expression Stack
 540 
 541 void InterpreterMacroAssembler::pop_ptr(Register r) {
 542   pop(r);
 543 }
 544 
 545 void InterpreterMacroAssembler::push_ptr(Register r) {
 546   push(r);
 547 }
 548 
 549 void InterpreterMacroAssembler::push_i(Register r) {
 550   push(r);
 551 }
 552 

 813   // that would normally not be safe to use. Such bad returns into unsafe territory of
 814   // the stack, will call InterpreterRuntime::at_unwind.
 815   Label slow_path;
 816   Label fast_path;
 817   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
 818   jmp(fast_path);
 819   bind(slow_path);
 820   push(state);
 821   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
 822   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
 823   reset_last_Java_frame(true);
 824   pop(state);
 825   bind(fast_path);
 826 
 827   // get the value of _do_not_unlock_if_synchronized into rdx
 828   const Address do_not_unlock_if_synchronized(rthread,
 829     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 830   movbool(rbx, do_not_unlock_if_synchronized);
 831   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 832 
 833   // get method access flags
 834   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 835   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 836   testl(rcx, JVM_ACC_SYNCHRONIZED);
 837   jcc(Assembler::zero, unlocked);
 838 
 839   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 840   // is set.
 841   testbool(rbx);
 842   jcc(Assembler::notZero, no_unlock);
 843 
 844   // unlock monitor
 845   push(state); // save result
 846 
 847   // BasicObjectLock will be first in list, since this is a
 848   // synchronized method. However, need to check that the object has
 849   // not been unlocked by an explicit monitorexit bytecode.
 850   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 851                         wordSize - (int) sizeof(BasicObjectLock));
 852   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 853   // register for unlock_object to pass to VM directly

 935     bind(loop);
 936     // check if current entry is used
 937     cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD);
 938     jcc(Assembler::notEqual, exception);
 939 
 940     addptr(rmon, entry_size); // otherwise advance to next entry
 941     bind(entry);
 942     cmpptr(rmon, rbx); // check if bottom reached
 943     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
 944   }
 945 
 946   bind(no_unlock);
 947 
 948   // jvmti support
 949   if (notify_jvmdi) {
 950     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 951   } else {
 952     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 953   }
 954 




 955   if (StackReservedPages > 0) {
 956     movptr(rbx,
 957                Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
 958     // testing if reserved zone needs to be re-enabled
 959     Register rthread = r15_thread;
 960     Label no_reserved_zone_enabling;
 961 
 962     // check if already enabled - if so no re-enabling needed
 963     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
 964     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
 965     jcc(Assembler::equal, no_reserved_zone_enabling);
 966 
 967     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
 968     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
 969 
 970     call_VM_leaf(
 971       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
 972     call_VM(noreg, CAST_FROM_FN_PTR(address,
 973                    InterpreterRuntime::throw_delayed_StackOverflowError));
 974     should_not_reach_here();
 975 
 976     bind(no_reserved_zone_enabling);
 977   }
 978 
 979   // remove activation
 980   // get sender sp
 981   movptr(rbx,
 982          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
 983 
 984   if (state == atos && InlineTypeReturnedAsFields) {
 985     // Check if we are returning an non-null inline type and load its fields into registers
 986     Label skip;
 987     test_oop_is_not_inline_type(rax, rscratch1, skip);
 988 
 989 #ifndef _LP64
 990     super_call_VM_leaf(StubRoutines::load_inline_type_fields_in_regs());
 991 #else
 992     // Load fields from a buffered value with an inline class specific handler
 993     load_klass(rdi, rax, rscratch1);
 994     movptr(rdi, Address(rdi, InstanceKlass::adr_inlineklass_fixed_block_offset()));
 995     movptr(rdi, Address(rdi, InlineKlass::unpack_handler_offset()));
 996     // Unpack handler can be null if inline type is not scalarizable in returns
 997     testptr(rdi, rdi);
 998     jcc(Assembler::zero, skip);
 999     call(rdi);
1000 #endif
1001 #ifdef ASSERT
1002     // TODO 8284443 Enable
1003     if (StressCallingConvention && false) {
1004       Label skip_stress;
1005       movptr(rscratch1, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1006       movl(rscratch1, Address(rscratch1, Method::flags_offset()));
1007       testl(rcx, MethodFlags::has_scalarized_return_flag());
1008       jcc(Assembler::zero, skip_stress);
1009       load_klass(rax, rax, rscratch1);
1010       orptr(rax, 1);
1011       bind(skip_stress);
1012     }
1013 #endif
1014     // call above kills the value in rbx. Reload it.
1015     movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1016     bind(skip);
1017   }
1018   leave();                           // remove frame anchor
1019   pop(ret_addr);                     // get return address
1020   mov(rsp, rbx);                     // set sp to sender sp
1021   pop_cont_fastpath();
1022 }
1023 
1024 void InterpreterMacroAssembler::get_method_counters(Register method,
1025                                                     Register mcs, Label& skip) {
1026   Label has_counters;
1027   movptr(mcs, Address(method, Method::method_counters_offset()));
1028   testptr(mcs, mcs);
1029   jcc(Assembler::notZero, has_counters);
1030   call_VM(noreg, CAST_FROM_FN_PTR(address,
1031           InterpreterRuntime::build_method_counters), method);
1032   movptr(mcs, Address(method,Method::method_counters_offset()));
1033   testptr(mcs, mcs);
1034   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1035   bind(has_counters);
1036 }
1037 
1038 void InterpreterMacroAssembler::allocate_instance(Register klass, Register new_obj,
1039                                                   Register t1, Register t2,
1040                                                   bool clear_fields, Label& alloc_failed) {
1041   MacroAssembler::allocate_instance(klass, new_obj, t1, t2, clear_fields, alloc_failed);
1042   if (DTraceMethodProbes) {
1043     // Trigger dtrace event for fastpath
1044     push(atos);
1045     call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1046     pop(atos);
1047   }
1048 }
1049 
1050 void InterpreterMacroAssembler::read_flat_field(Register entry, Register tmp1, Register tmp2, Register obj) {
1051   Label alloc_failed, done;
1052   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1053   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1054   assert_different_registers(obj, entry, tmp1, tmp2, dst_temp, r8, r9);
1055 
1056   // FIXME: code below could be re-written to better use InlineLayoutInfo data structure
1057   // see aarch64 version
1058 
1059   // Grap the inline field klass
1060   const Register field_klass = tmp1;
1061   load_unsigned_short(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1062   movptr(tmp1, Address(entry, ResolvedFieldEntry::field_holder_offset()));
1063   get_inline_type_field_klass(tmp1, tmp2, field_klass);
1064 
1065   // allocate buffer
1066   push(obj);  // push object being read from     // FIXME spilling on stack could probably be avoided by using tmp2
1067   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1068 
1069   // Have an oop instance buffer, copy into it
1070   load_unsigned_short(r9, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1071   movptr(r8, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1072   inline_layout_info(r8, r9, r8); // holder, index, info => InlineLayoutInfo into r8
1073 
1074   payload_addr(obj, dst_temp, field_klass);
1075   pop(alloc_temp);             // restore object being read from
1076   load_sized_value(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
1077   lea(tmp2, Address(alloc_temp, tmp2));
1078   // call_VM_leaf, clobbers a few regs, save restore new obj
1079   push(obj);
1080   // access_value_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, field_klass);
1081   flat_field_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, r8);
1082   pop(obj);
1083   jmp(done);
1084 
1085   bind(alloc_failed);
1086   pop(obj);
1087   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1088           obj, entry);
1089   get_vm_result(obj);
1090   bind(done);
1091 }
1092 
1093 // Lock object
1094 //
1095 // Args:
1096 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1097 //
1098 // Kills:
1099 //      rax, rbx
1100 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1101   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1102 
1103   if (LockingMode == LM_MONITOR) {
1104     call_VM_preemptable(noreg,
1105             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1106             lock_reg);
1107   } else {
1108     Label count_locking, done, slow_case;
1109 
1110     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1111     const Register tmp_reg = rbx;

1117     const int mark_offset = lock_offset +
1118                             BasicLock::displaced_header_offset_in_bytes();
1119 
1120     // Load object pointer into obj_reg
1121     movptr(obj_reg, Address(lock_reg, obj_offset));
1122 
1123     if (DiagnoseSyncOnValueBasedClasses != 0) {
1124       load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1125       testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1126       jcc(Assembler::notZero, slow_case);
1127     }
1128 
1129     if (LockingMode == LM_LIGHTWEIGHT) {
1130       lightweight_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case);
1131     } else if (LockingMode == LM_LEGACY) {
1132       // Load immediate 1 into swap_reg %rax
1133       movl(swap_reg, 1);
1134 
1135       // Load (object->mark() | 1) into swap_reg %rax
1136       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1137       if (EnableValhalla) {
1138         // Mask inline_type bit such that we go to the slow path if object is an inline type
1139         andptr(swap_reg, ~((int) markWord::inline_type_bit_in_place));
1140       }
1141 
1142       // Save (object->mark() | 1) into BasicLock's displaced header
1143       movptr(Address(lock_reg, mark_offset), swap_reg);
1144 
1145       assert(lock_offset == 0,
1146              "displaced header must be first word in BasicObjectLock");
1147 
1148       lock();
1149       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1150       jcc(Assembler::zero, count_locking);
1151 
1152       const int zero_bits = 7;
1153 
1154       // Fast check for recursive lock.
1155       //
1156       // Can apply the optimization only if this is a stack lock
1157       // allocated in this thread. For efficiency, we can focus on
1158       // recently allocated stack locks (instead of reading the stack
1159       // base and checking whether 'mark' points inside the current
1160       // thread stack):

1472     test_method_data_pointer(mdp, profile_continue);
1473 
1474     // We are taking a branch.  Increment the taken count.
1475     // We inline increment_mdp_data_at to return bumped_count in a register
1476     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1477     Address data(mdp, in_bytes(JumpData::taken_offset()));
1478     movptr(bumped_count, data);
1479     assert(DataLayout::counter_increment == 1,
1480             "flow-free idiom only works with 1");
1481     addptr(bumped_count, DataLayout::counter_increment);
1482     sbbptr(bumped_count, 0);
1483     movptr(data, bumped_count); // Store back out
1484 
1485     // The method data pointer needs to be updated to reflect the new target.
1486     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1487     bind(profile_continue);
1488   }
1489 }
1490 
1491 
1492 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1493   if (ProfileInterpreter) {
1494     Label profile_continue;
1495 
1496     // If no method data exists, go to profile_continue.
1497     test_method_data_pointer(mdp, profile_continue);
1498 
1499     // We are taking a branch.  Increment the not taken count.
1500     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1501 
1502     // The method data pointer needs to be updated to correspond to
1503     // the next bytecode
1504     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1505     bind(profile_continue);
1506   }
1507 }
1508 
1509 void InterpreterMacroAssembler::profile_call(Register mdp) {
1510   if (ProfileInterpreter) {
1511     Label profile_continue;
1512 
1513     // If no method data exists, go to profile_continue.
1514     test_method_data_pointer(mdp, profile_continue);
1515 
1516     // We are making a call.  Increment the count.
1517     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1518 
1519     // The method data pointer needs to be updated to reflect the new target.
1520     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1521     bind(profile_continue);
1522   }
1523 }
1524 

1547                                                      Register reg2,
1548                                                      bool receiver_can_be_null) {
1549   if (ProfileInterpreter) {
1550     Label profile_continue;
1551 
1552     // If no method data exists, go to profile_continue.
1553     test_method_data_pointer(mdp, profile_continue);
1554 
1555     Label skip_receiver_profile;
1556     if (receiver_can_be_null) {
1557       Label not_null;
1558       testptr(receiver, receiver);
1559       jccb(Assembler::notZero, not_null);
1560       // We are making a call.  Increment the count for null receiver.
1561       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1562       jmp(skip_receiver_profile);
1563       bind(not_null);
1564     }
1565 
1566     // Record the receiver type.
1567     record_klass_in_profile(receiver, mdp, reg2);
1568     bind(skip_receiver_profile);
1569 
1570     // The method data pointer needs to be updated to reflect the new target.
1571     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1572     bind(profile_continue);
1573   }
1574 }
1575 
1576 // This routine creates a state machine for updating the multi-row
1577 // type profile at a virtual call site (or other type-sensitive bytecode).
1578 // The machine visits each row (of receiver/count) until the receiver type
1579 // is found, or until it runs out of rows.  At the same time, it remembers
1580 // the location of the first empty row.  (An empty row records null for its
1581 // receiver, and can be allocated for a newly-observed receiver type.)
1582 // Because there are two degrees of freedom in the state, a simple linear
1583 // search will not work; it must be a decision tree.  Hence this helper
1584 // function is recursive, to generate the required tree structured code.
1585 // It's the interpreter, so we are trading off code space for speed.
1586 // See below for example code.
1587 void InterpreterMacroAssembler::record_klass_in_profile_helper(Register receiver, Register mdp,
1588                                                                Register reg2, int start_row,
1589                                                                Label& done) {

1590   if (TypeProfileWidth == 0) {
1591     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1592   } else {
1593     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1594                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1595   }
1596 }
1597 
1598 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1599                                                               Label& done, int total_rows,
1600                                                               OffsetFunction item_offset_fn,
1601                                                               OffsetFunction item_count_offset_fn) {
1602   int last_row = total_rows - 1;
1603   assert(start_row <= last_row, "must be work left to do");
1604   // Test this row for both the item and for null.
1605   // Take any of three different outcomes:
1606   //   1. found item => increment count and goto done
1607   //   2. found null => keep looking for case 1, maybe allocate this cell
1608   //   3. found something else => keep looking for cases 1 and 2
1609   // Case 3 is handled by a recursive call.

1673 //     // inner copy of decision tree, rooted at row[1]
1674 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1675 //     if (row[1].rec != nullptr) {
1676 //       // degenerate decision tree, rooted at row[2]
1677 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1678 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1679 //       row[2].init(rec); goto done;
1680 //     } else {
1681 //       // remember row[1] is empty
1682 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1683 //       row[1].init(rec); goto done;
1684 //     }
1685 //   } else {
1686 //     // remember row[0] is empty
1687 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1688 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1689 //     row[0].init(rec); goto done;
1690 //   }
1691 //   done:
1692 
1693 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, Register mdp, Register reg2) {


1694   assert(ProfileInterpreter, "must be profiling");
1695   Label done;
1696 
1697   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1698 
1699   bind (done);
1700 }
1701 
1702 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1703                                             Register mdp) {
1704   if (ProfileInterpreter) {
1705     Label profile_continue;
1706     uint row;
1707 
1708     // If no method data exists, go to profile_continue.
1709     test_method_data_pointer(mdp, profile_continue);
1710 
1711     // Update the total ret count.
1712     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1713 
1714     for (row = 0; row < RetData::row_limit(); row++) {
1715       Label next_test;
1716 
1717       // See if return_bci is equal to bci[n]:

1754     update_mdp_by_constant(mdp, mdp_delta);
1755 
1756     bind(profile_continue);
1757   }
1758 }
1759 
1760 
1761 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1762   if (ProfileInterpreter) {
1763     Label profile_continue;
1764 
1765     // If no method data exists, go to profile_continue.
1766     test_method_data_pointer(mdp, profile_continue);
1767 
1768     // The method data pointer needs to be updated.
1769     int mdp_delta = in_bytes(BitData::bit_data_size());
1770     if (TypeProfileCasts) {
1771       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1772 
1773       // Record the object type.
1774       record_klass_in_profile(klass, mdp, reg2);
1775     }
1776     update_mdp_by_constant(mdp, mdp_delta);
1777 
1778     bind(profile_continue);
1779   }
1780 }
1781 
1782 
1783 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1784   if (ProfileInterpreter) {
1785     Label profile_continue;
1786 
1787     // If no method data exists, go to profile_continue.
1788     test_method_data_pointer(mdp, profile_continue);
1789 
1790     // Update the default case count
1791     increment_mdp_data_at(mdp,
1792                           in_bytes(MultiBranchData::default_count_offset()));
1793 
1794     // The method data pointer needs to be updated.

1814     // case_array_offset_in_bytes()
1815     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1816     imulptr(index, reg2); // XXX l ?
1817     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1818 
1819     // Update the case count
1820     increment_mdp_data_at(mdp,
1821                           index,
1822                           in_bytes(MultiBranchData::relative_count_offset()));
1823 
1824     // The method data pointer needs to be updated.
1825     update_mdp_by_offset(mdp,
1826                          index,
1827                          in_bytes(MultiBranchData::
1828                                   relative_displacement_offset()));
1829 
1830     bind(profile_continue);
1831   }
1832 }
1833 
1834 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
1835                                                                               Register array,
1836                                                                               Register tmp) {
1837   if (ProfileInterpreter) {
1838     Label profile_continue;
1839 
1840     // If no method data exists, go to profile_continue.
1841     test_method_data_pointer(mdp, profile_continue);
1842 
1843     mov(tmp, array);
1844     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
1845 
1846     Label not_flat;
1847     test_non_flat_array_oop(array, tmp, not_flat);
1848 
1849     set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
1850 
1851     bind(not_flat);
1852 
1853     Label not_null_free;
1854     test_non_null_free_array_oop(array, tmp, not_null_free);
1855 
1856     set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
1857 
1858     bind(not_null_free);
1859 
1860     bind(profile_continue);
1861   }
1862 }
1863 
1864 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
1865                                                                            Register array,
1866                                                                            Register tmp);
1867 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
1868                                                                             Register array,
1869                                                                             Register tmp);
1870 
1871 
1872 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
1873   if (ProfileInterpreter) {
1874     Label profile_continue;
1875 
1876     // If no method data exists, go to profile_continue.
1877     test_method_data_pointer(mdp, profile_continue);
1878 
1879     Label done, update;
1880     testptr(element, element);
1881     jccb(Assembler::notZero, update);
1882     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1883     jmp(done);
1884 
1885     bind(update);
1886     load_klass(tmp, element, rscratch1);
1887 
1888     // Record the object type.
1889     record_klass_in_profile(tmp, mdp, tmp2);
1890 
1891     bind(done);
1892 
1893     // The method data pointer needs to be updated.
1894     update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
1895 
1896     bind(profile_continue);
1897   }
1898 }
1899 
1900 void InterpreterMacroAssembler::profile_element_type(Register mdp,
1901                                                      Register element,
1902                                                      Register tmp) {
1903   if (ProfileInterpreter) {
1904     Label profile_continue;
1905 
1906     // If no method data exists, go to profile_continue.
1907     test_method_data_pointer(mdp, profile_continue);
1908 
1909     mov(tmp, element);
1910     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
1911 
1912     // The method data pointer needs to be updated.
1913     update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
1914 
1915     bind(profile_continue);
1916   }
1917 }
1918 
1919 void InterpreterMacroAssembler::profile_acmp(Register mdp,
1920                                              Register left,
1921                                              Register right,
1922                                              Register tmp) {
1923   if (ProfileInterpreter) {
1924     Label profile_continue;
1925 
1926     // If no method data exists, go to profile_continue.
1927     test_method_data_pointer(mdp, profile_continue);
1928 
1929     mov(tmp, left);
1930     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
1931 
1932     Label left_not_inline_type;
1933     test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
1934     set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
1935     bind(left_not_inline_type);
1936 
1937     mov(tmp, right);
1938     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
1939 
1940     Label right_not_inline_type;
1941     test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
1942     set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
1943     bind(right_not_inline_type);
1944 
1945     bind(profile_continue);
1946   }
1947 }
1948 
1949 
1950 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1951   if (state == atos) {
1952     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1953   }
1954 }
1955 
1956 
1957 // Jump if ((*counter_addr += increment) & mask) == 0
1958 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1959                                                         Register scratch, Label* where) {
1960   // This update is actually not atomic and can lose a number of updates
1961   // under heavy contention, but the alternative of using the (contended)
1962   // atomic update here penalizes profiling paths too much.
1963   movl(scratch, counter_addr);
1964   incrementl(scratch, InvocationCounter::count_increment);
1965   movl(counter_addr, scratch);
1966   andl(scratch, mask);
1967   if (where != nullptr) {
< prev index next >