< prev index next >

src/hotspot/cpu/x86/interp_masm_x86.cpp

Print this page

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

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

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

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

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

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

 512   assert(Rsub_klass != rax, "rax holds superklass");
 513   LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
 514   LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
 515   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 516   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 517 
 518   // Profile the not-null value's klass.
 519   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi


 520 
 521   // Do the check.
 522   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 523 }
 524 
 525 
 526 #ifndef _LP64
 527 void InterpreterMacroAssembler::f2ieee() {
 528   if (IEEEPrecision) {
 529     fstp_s(Address(rsp, 0));
 530     fld_s(Address(rsp, 0));
 531   }
 532 }
 533 
 534 
 535 void InterpreterMacroAssembler::d2ieee() {
 536   if (IEEEPrecision) {
 537     fstp_d(Address(rsp, 0));
 538     fld_d(Address(rsp, 0));
 539   }

 951   // the stack, will call InterpreterRuntime::at_unwind.
 952   Label slow_path;
 953   Label fast_path;
 954   safepoint_poll(slow_path, rthread, true /* at_return */, false /* in_nmethod */);
 955   jmp(fast_path);
 956   bind(slow_path);
 957   push(state);
 958   set_last_Java_frame(rthread, noreg, rbp, (address)pc(), rscratch1);
 959   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
 960   NOT_LP64(get_thread(rthread);) // call_VM clobbered it, restore
 961   reset_last_Java_frame(rthread, true);
 962   pop(state);
 963   bind(fast_path);
 964 
 965   // get the value of _do_not_unlock_if_synchronized into rdx
 966   const Address do_not_unlock_if_synchronized(rthread,
 967     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 968   movbool(rbx, do_not_unlock_if_synchronized);
 969   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 970 
 971  // get method access flags
 972   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 973   movl(rcx, Address(rcx, Method::access_flags_offset()));
 974   testl(rcx, JVM_ACC_SYNCHRONIZED);
 975   jcc(Assembler::zero, unlocked);
 976 
 977   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 978   // is set.
 979   testbool(rbx);
 980   jcc(Assembler::notZero, no_unlock);
 981 
 982   // unlock monitor
 983   push(state); // save result
 984 
 985   // BasicObjectLock will be first in list, since this is a
 986   // synchronized method. However, need to check that the object has
 987   // not been unlocked by an explicit monitorexit bytecode.
 988   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 989                         wordSize - (int) sizeof(BasicObjectLock));
 990   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 991   // register for unlock_object to pass to VM directly

1077     bind(loop);
1078     // check if current entry is used
1079     cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD);
1080     jcc(Assembler::notEqual, exception);
1081 
1082     addptr(rmon, entry_size); // otherwise advance to next entry
1083     bind(entry);
1084     cmpptr(rmon, rbx); // check if bottom reached
1085     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
1086   }
1087 
1088   bind(no_unlock);
1089 
1090   // jvmti support
1091   if (notify_jvmdi) {
1092     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
1093   } else {
1094     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1095   }
1096 
1097   // remove activation
1098   // get sender sp
1099   movptr(rbx,
1100          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1101   if (StackReservedPages > 0) {


1102     // testing if reserved zone needs to be re-enabled
1103     Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
1104     Label no_reserved_zone_enabling;
1105 
1106     NOT_LP64(get_thread(rthread);)
1107 
1108     // check if already enabled - if so no re-enabling needed
1109     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
1110     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1111     jcc(Assembler::equal, no_reserved_zone_enabling);
1112 
1113     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1114     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1115 
1116     call_VM_leaf(
1117       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1118     call_VM(noreg, CAST_FROM_FN_PTR(address,
1119                    InterpreterRuntime::throw_delayed_StackOverflowError));
1120     should_not_reach_here();
1121 
1122     bind(no_reserved_zone_enabling);
1123   }








































1124   leave();                           // remove frame anchor
1125   pop(ret_addr);                     // get return address
1126   mov(rsp, rbx);                     // set sp to sender sp
1127   pop_cont_fastpath();
1128 }
1129 
1130 void InterpreterMacroAssembler::get_method_counters(Register method,
1131                                                     Register mcs, Label& skip) {
1132   Label has_counters;
1133   movptr(mcs, Address(method, Method::method_counters_offset()));
1134   testptr(mcs, mcs);
1135   jcc(Assembler::notZero, has_counters);
1136   call_VM(noreg, CAST_FROM_FN_PTR(address,
1137           InterpreterRuntime::build_method_counters), method);
1138   movptr(mcs, Address(method,Method::method_counters_offset()));
1139   testptr(mcs, mcs);
1140   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1141   bind(has_counters);
1142 }
1143 












































































































1144 
1145 // Lock object
1146 //
1147 // Args:
1148 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1149 //
1150 // Kills:
1151 //      rax, rbx
1152 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1153   assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1154          "The argument is only for looks. It must be c_rarg1");
1155 
1156   if (LockingMode == LM_MONITOR) {
1157     call_VM(noreg,
1158             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1159             lock_reg);
1160   } else {
1161     Label count_locking, done, slow_case;
1162 
1163     const Register swap_reg = rax; // Must use rax for cmpxchg instruction

1176     if (DiagnoseSyncOnValueBasedClasses != 0) {
1177       load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1178       testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1179       jcc(Assembler::notZero, slow_case);
1180     }
1181 
1182     if (LockingMode == LM_LIGHTWEIGHT) {
1183 #ifdef _LP64
1184       const Register thread = r15_thread;
1185       lightweight_lock(lock_reg, obj_reg, swap_reg, thread, tmp_reg, slow_case);
1186 #else
1187       // Lacking registers and thread on x86_32. Always take slow path.
1188       jmp(slow_case);
1189 #endif
1190     } else if (LockingMode == LM_LEGACY) {
1191       // Load immediate 1 into swap_reg %rax
1192       movl(swap_reg, 1);
1193 
1194       // Load (object->mark() | 1) into swap_reg %rax
1195       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));




1196 
1197       // Save (object->mark() | 1) into BasicLock's displaced header
1198       movptr(Address(lock_reg, mark_offset), swap_reg);
1199 
1200       assert(lock_offset == 0,
1201              "displaced header must be first word in BasicObjectLock");
1202 
1203       lock();
1204       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1205       jcc(Assembler::zero, count_locking);
1206 
1207       const int zero_bits = LP64_ONLY(7) NOT_LP64(3);
1208 
1209       // Fast check for recursive lock.
1210       //
1211       // Can apply the optimization only if this is a stack lock
1212       // allocated in this thread. For efficiency, we can focus on
1213       // recently allocated stack locks (instead of reading the stack
1214       // base and checking whether 'mark' points inside the current
1215       // thread stack):

1533     test_method_data_pointer(mdp, profile_continue);
1534 
1535     // We are taking a branch.  Increment the taken count.
1536     // We inline increment_mdp_data_at to return bumped_count in a register
1537     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1538     Address data(mdp, in_bytes(JumpData::taken_offset()));
1539     movptr(bumped_count, data);
1540     assert(DataLayout::counter_increment == 1,
1541             "flow-free idiom only works with 1");
1542     addptr(bumped_count, DataLayout::counter_increment);
1543     sbbptr(bumped_count, 0);
1544     movptr(data, bumped_count); // Store back out
1545 
1546     // The method data pointer needs to be updated to reflect the new target.
1547     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1548     bind(profile_continue);
1549   }
1550 }
1551 
1552 
1553 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1554   if (ProfileInterpreter) {
1555     Label profile_continue;
1556 
1557     // If no method data exists, go to profile_continue.
1558     test_method_data_pointer(mdp, profile_continue);
1559 
1560     // We are taking a branch.  Increment the not taken count.
1561     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1562 
1563     // The method data pointer needs to be updated to correspond to
1564     // the next bytecode
1565     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1566     bind(profile_continue);
1567   }
1568 }
1569 
1570 void InterpreterMacroAssembler::profile_call(Register mdp) {
1571   if (ProfileInterpreter) {
1572     Label profile_continue;
1573 
1574     // If no method data exists, go to profile_continue.
1575     test_method_data_pointer(mdp, profile_continue);
1576 
1577     // We are making a call.  Increment the count.
1578     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1579 
1580     // The method data pointer needs to be updated to reflect the new target.
1581     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1582     bind(profile_continue);
1583   }
1584 }
1585 

1608                                                      Register reg2,
1609                                                      bool receiver_can_be_null) {
1610   if (ProfileInterpreter) {
1611     Label profile_continue;
1612 
1613     // If no method data exists, go to profile_continue.
1614     test_method_data_pointer(mdp, profile_continue);
1615 
1616     Label skip_receiver_profile;
1617     if (receiver_can_be_null) {
1618       Label not_null;
1619       testptr(receiver, receiver);
1620       jccb(Assembler::notZero, not_null);
1621       // We are making a call.  Increment the count for null receiver.
1622       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1623       jmp(skip_receiver_profile);
1624       bind(not_null);
1625     }
1626 
1627     // Record the receiver type.
1628     record_klass_in_profile(receiver, mdp, reg2, true);
1629     bind(skip_receiver_profile);
1630 
1631     // The method data pointer needs to be updated to reflect the new target.
1632     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1633     bind(profile_continue);
1634   }
1635 }
1636 
1637 // This routine creates a state machine for updating the multi-row
1638 // type profile at a virtual call site (or other type-sensitive bytecode).
1639 // The machine visits each row (of receiver/count) until the receiver type
1640 // is found, or until it runs out of rows.  At the same time, it remembers
1641 // the location of the first empty row.  (An empty row records null for its
1642 // receiver, and can be allocated for a newly-observed receiver type.)
1643 // Because there are two degrees of freedom in the state, a simple linear
1644 // search will not work; it must be a decision tree.  Hence this helper
1645 // function is recursive, to generate the required tree structured code.
1646 // It's the interpreter, so we are trading off code space for speed.
1647 // See below for example code.
1648 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1649                                         Register receiver, Register mdp,
1650                                         Register reg2, int start_row,
1651                                         Label& done, bool is_virtual_call) {
1652   if (TypeProfileWidth == 0) {
1653     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1654   } else {
1655     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1656                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1657   }
1658 }
1659 
1660 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1661                                                               Label& done, int total_rows,
1662                                                               OffsetFunction item_offset_fn,
1663                                                               OffsetFunction item_count_offset_fn) {
1664   int last_row = total_rows - 1;
1665   assert(start_row <= last_row, "must be work left to do");
1666   // Test this row for both the item and for null.
1667   // Take any of three different outcomes:
1668   //   1. found item => increment count and goto done
1669   //   2. found null => keep looking for case 1, maybe allocate this cell
1670   //   3. found something else => keep looking for cases 1 and 2
1671   // Case 3 is handled by a recursive call.

1735 //     // inner copy of decision tree, rooted at row[1]
1736 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1737 //     if (row[1].rec != nullptr) {
1738 //       // degenerate decision tree, rooted at row[2]
1739 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1740 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1741 //       row[2].init(rec); goto done;
1742 //     } else {
1743 //       // remember row[1] is empty
1744 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1745 //       row[1].init(rec); goto done;
1746 //     }
1747 //   } else {
1748 //     // remember row[0] is empty
1749 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1750 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1751 //     row[0].init(rec); goto done;
1752 //   }
1753 //   done:
1754 
1755 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1756                                                         Register mdp, Register reg2,
1757                                                         bool is_virtual_call) {
1758   assert(ProfileInterpreter, "must be profiling");
1759   Label done;
1760 
1761   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1762 
1763   bind (done);
1764 }
1765 
1766 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1767                                             Register mdp) {
1768   if (ProfileInterpreter) {
1769     Label profile_continue;
1770     uint row;
1771 
1772     // If no method data exists, go to profile_continue.
1773     test_method_data_pointer(mdp, profile_continue);
1774 
1775     // Update the total ret count.
1776     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1777 
1778     for (row = 0; row < RetData::row_limit(); row++) {
1779       Label next_test;
1780 
1781       // See if return_bci is equal to bci[n]:

1818     update_mdp_by_constant(mdp, mdp_delta);
1819 
1820     bind(profile_continue);
1821   }
1822 }
1823 
1824 
1825 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1826   if (ProfileInterpreter) {
1827     Label profile_continue;
1828 
1829     // If no method data exists, go to profile_continue.
1830     test_method_data_pointer(mdp, profile_continue);
1831 
1832     // The method data pointer needs to be updated.
1833     int mdp_delta = in_bytes(BitData::bit_data_size());
1834     if (TypeProfileCasts) {
1835       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1836 
1837       // Record the object type.
1838       record_klass_in_profile(klass, mdp, reg2, false);
1839       NOT_LP64(assert(reg2 == rdi, "we know how to fix this blown reg");)
1840       NOT_LP64(restore_locals();)         // Restore EDI
1841     }
1842     update_mdp_by_constant(mdp, mdp_delta);
1843 
1844     bind(profile_continue);
1845   }
1846 }
1847 
1848 
1849 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1850   if (ProfileInterpreter) {
1851     Label profile_continue;
1852 
1853     // If no method data exists, go to profile_continue.
1854     test_method_data_pointer(mdp, profile_continue);
1855 
1856     // Update the default case count
1857     increment_mdp_data_at(mdp,
1858                           in_bytes(MultiBranchData::default_count_offset()));

1880     // case_array_offset_in_bytes()
1881     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1882     imulptr(index, reg2); // XXX l ?
1883     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1884 
1885     // Update the case count
1886     increment_mdp_data_at(mdp,
1887                           index,
1888                           in_bytes(MultiBranchData::relative_count_offset()));
1889 
1890     // The method data pointer needs to be updated.
1891     update_mdp_by_offset(mdp,
1892                          index,
1893                          in_bytes(MultiBranchData::
1894                                   relative_displacement_offset()));
1895 
1896     bind(profile_continue);
1897   }
1898 }
1899 


















































































































1900 
1901 
1902 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1903   if (state == atos) {
1904     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1905   }
1906 }
1907 
1908 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1909 #ifndef _LP64
1910   if ((state == ftos && UseSSE < 1) ||
1911       (state == dtos && UseSSE < 2)) {
1912     MacroAssembler::verify_FPU(stack_depth);
1913   }
1914 #endif
1915 }
1916 
1917 // Jump if ((*counter_addr += increment) & mask) == 0
1918 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1919                                                         Register scratch, Label* where) {

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

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

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

 493                                                              Register cpool,
 494                                                              Register index) {
 495   assert_different_registers(cpool, index);
 496 
 497   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 498   Register resolved_klasses = cpool;
 499   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
 500   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 501 }
 502 
 503 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 504 // subtype of super_klass.
 505 //
 506 // Args:
 507 //      rax: superklass
 508 //      Rsub_klass: subklass
 509 //
 510 // Kills:
 511 //      rcx, rdi
 512 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 513                                                   Label& ok_is_subtype,
 514                                                   bool profile) {
 515   assert(Rsub_klass != rax, "rax holds superklass");
 516   LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
 517   LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
 518   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 519   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 520 
 521   // Profile the not-null value's klass.
 522   if (profile) {
 523     profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
 524   }
 525 
 526   // Do the check.
 527   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 528 }
 529 
 530 
 531 #ifndef _LP64
 532 void InterpreterMacroAssembler::f2ieee() {
 533   if (IEEEPrecision) {
 534     fstp_s(Address(rsp, 0));
 535     fld_s(Address(rsp, 0));
 536   }
 537 }
 538 
 539 
 540 void InterpreterMacroAssembler::d2ieee() {
 541   if (IEEEPrecision) {
 542     fstp_d(Address(rsp, 0));
 543     fld_d(Address(rsp, 0));
 544   }

 956   // the stack, will call InterpreterRuntime::at_unwind.
 957   Label slow_path;
 958   Label fast_path;
 959   safepoint_poll(slow_path, rthread, true /* at_return */, false /* in_nmethod */);
 960   jmp(fast_path);
 961   bind(slow_path);
 962   push(state);
 963   set_last_Java_frame(rthread, noreg, rbp, (address)pc(), rscratch1);
 964   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
 965   NOT_LP64(get_thread(rthread);) // call_VM clobbered it, restore
 966   reset_last_Java_frame(rthread, true);
 967   pop(state);
 968   bind(fast_path);
 969 
 970   // get the value of _do_not_unlock_if_synchronized into rdx
 971   const Address do_not_unlock_if_synchronized(rthread,
 972     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 973   movbool(rbx, do_not_unlock_if_synchronized);
 974   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 975 
 976   // get method access flags
 977   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 978   movl(rcx, Address(rcx, Method::access_flags_offset()));
 979   testl(rcx, JVM_ACC_SYNCHRONIZED);
 980   jcc(Assembler::zero, unlocked);
 981 
 982   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 983   // is set.
 984   testbool(rbx);
 985   jcc(Assembler::notZero, no_unlock);
 986 
 987   // unlock monitor
 988   push(state); // save result
 989 
 990   // BasicObjectLock will be first in list, since this is a
 991   // synchronized method. However, need to check that the object has
 992   // not been unlocked by an explicit monitorexit bytecode.
 993   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 994                         wordSize - (int) sizeof(BasicObjectLock));
 995   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 996   // register for unlock_object to pass to VM directly

1082     bind(loop);
1083     // check if current entry is used
1084     cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD);
1085     jcc(Assembler::notEqual, exception);
1086 
1087     addptr(rmon, entry_size); // otherwise advance to next entry
1088     bind(entry);
1089     cmpptr(rmon, rbx); // check if bottom reached
1090     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
1091   }
1092 
1093   bind(no_unlock);
1094 
1095   // jvmti support
1096   if (notify_jvmdi) {
1097     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
1098   } else {
1099     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1100   }
1101 




1102   if (StackReservedPages > 0) {
1103     movptr(rbx,
1104                Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1105     // testing if reserved zone needs to be re-enabled
1106     Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
1107     Label no_reserved_zone_enabling;
1108 
1109     NOT_LP64(get_thread(rthread);)
1110 
1111     // check if already enabled - if so no re-enabling needed
1112     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
1113     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1114     jcc(Assembler::equal, no_reserved_zone_enabling);
1115 
1116     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1117     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1118 
1119     call_VM_leaf(
1120       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1121     call_VM(noreg, CAST_FROM_FN_PTR(address,
1122                    InterpreterRuntime::throw_delayed_StackOverflowError));
1123     should_not_reach_here();
1124 
1125     bind(no_reserved_zone_enabling);
1126   }
1127 
1128   // remove activation
1129   // get sender sp
1130   movptr(rbx,
1131          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1132 
1133   if (state == atos && InlineTypeReturnedAsFields) {
1134     // Check if we are returning an non-null inline type and load its fields into registers
1135     Label skip;
1136     test_oop_is_not_inline_type(rax, rscratch1, skip);
1137 
1138 #ifndef _LP64
1139     super_call_VM_leaf(StubRoutines::load_inline_type_fields_in_regs());
1140 #else
1141     // Load fields from a buffered value with an inline class specific handler
1142     load_klass(rdi, rax, rscratch1);
1143     movptr(rdi, Address(rdi, InstanceKlass::adr_inlineklass_fixed_block_offset()));
1144     movptr(rdi, Address(rdi, InlineKlass::unpack_handler_offset()));
1145     // Unpack handler can be null if inline type is not scalarizable in returns
1146     testptr(rdi, rdi);
1147     jcc(Assembler::zero, skip);
1148     call(rdi);
1149 #endif
1150 #ifdef ASSERT
1151     // TODO 8284443 Enable
1152     if (StressCallingConvention && false) {
1153       Label skip_stress;
1154       movptr(rscratch1, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1155       movl(rscratch1, Address(rscratch1, Method::flags_offset()));
1156       testl(rcx, MethodFlags::has_scalarized_return_flag());
1157       jcc(Assembler::zero, skip_stress);
1158       load_klass(rax, rax, rscratch1);
1159       orptr(rax, 1);
1160       bind(skip_stress);
1161     }
1162 #endif
1163     // call above kills the value in rbx. Reload it.
1164     movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1165     bind(skip);
1166   }
1167   leave();                           // remove frame anchor
1168   pop(ret_addr);                     // get return address
1169   mov(rsp, rbx);                     // set sp to sender sp
1170   pop_cont_fastpath();
1171 }
1172 
1173 void InterpreterMacroAssembler::get_method_counters(Register method,
1174                                                     Register mcs, Label& skip) {
1175   Label has_counters;
1176   movptr(mcs, Address(method, Method::method_counters_offset()));
1177   testptr(mcs, mcs);
1178   jcc(Assembler::notZero, has_counters);
1179   call_VM(noreg, CAST_FROM_FN_PTR(address,
1180           InterpreterRuntime::build_method_counters), method);
1181   movptr(mcs, Address(method,Method::method_counters_offset()));
1182   testptr(mcs, mcs);
1183   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1184   bind(has_counters);
1185 }
1186 
1187 void InterpreterMacroAssembler::allocate_instance(Register klass, Register new_obj,
1188                                                   Register t1, Register t2,
1189                                                   bool clear_fields, Label& alloc_failed) {
1190   MacroAssembler::allocate_instance(klass, new_obj, t1, t2, clear_fields, alloc_failed);
1191   if (DTraceMethodProbes) {
1192     // Trigger dtrace event for fastpath
1193     push(atos);
1194     call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1195     pop(atos);
1196   }
1197 }
1198 
1199 void InterpreterMacroAssembler::read_flat_field(Register entry, Register tmp1, Register tmp2, Register obj) {
1200   Label alloc_failed, empty_value, done;
1201   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1202   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1203   assert_different_registers(obj, entry, tmp1, tmp2, dst_temp, r8, r9);
1204 
1205   // FIXME: code below could be re-written to better use InlineLayoutInfo data structure
1206   // see aarch64 version
1207 
1208   // Grap the inline field klass
1209   const Register field_klass = tmp1;
1210   load_unsigned_short(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1211   movptr(tmp1, Address(entry, ResolvedFieldEntry::field_holder_offset()));
1212   get_inline_type_field_klass(tmp1, tmp2, field_klass);
1213 
1214     //check for empty value klass
1215   test_klass_is_empty_inline_type(field_klass, dst_temp, empty_value);
1216 
1217   // allocate buffer
1218   push(obj);  // push object being read from     // FIXME spilling on stack could probably be avoided by using tmp2
1219   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1220 
1221   // Have an oop instance buffer, copy into it
1222   load_unsigned_short(r9, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1223   movptr(r8, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1224   inline_layout_info(r8, r9, r8); // holder, index, info => InlineLayoutInfo into r8
1225 
1226   data_for_oop(obj, dst_temp, field_klass);
1227   pop(alloc_temp);             // restore object being read from
1228   load_sized_value(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
1229   lea(tmp2, Address(alloc_temp, tmp2));
1230   // call_VM_leaf, clobbers a few regs, save restore new obj
1231   push(obj);
1232   // access_value_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, field_klass);
1233   flat_field_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, r8);
1234   pop(obj);
1235   jmp(done);
1236 
1237   bind(empty_value);
1238   get_empty_inline_type_oop(field_klass, dst_temp, obj);
1239   jmp(done);
1240 
1241   bind(alloc_failed);
1242   pop(obj);
1243   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1244           obj, entry);
1245   get_vm_result(obj, r15_thread);
1246   bind(done);
1247 }
1248 
1249 void InterpreterMacroAssembler::read_flat_element(Register array, Register index,
1250                                                   Register t1, Register t2,
1251                                                   Register obj) {
1252   assert_different_registers(array, index, t1, t2);
1253   Label alloc_failed, empty_value, done;
1254   const Register array_klass = t2;
1255   const Register elem_klass = t1;
1256   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1257   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1258 
1259   // load in array->klass()->element_klass()
1260   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1261   load_klass(array_klass, array, tmp_load_klass);
1262   movptr(elem_klass, Address(array_klass, ArrayKlass::element_klass_offset()));
1263 
1264   //check for empty value klass
1265   test_klass_is_empty_inline_type(elem_klass, dst_temp, empty_value);
1266 
1267   // calc source into "array_klass" and free up some regs
1268   const Register src = array_klass;
1269   push(index); // preserve index reg in case alloc_failed
1270   data_for_value_array_index(array, array_klass, index, src);
1271 
1272   allocate_instance(elem_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1273   // Have an oop instance buffer, copy into it
1274   store_ptr(0, obj); // preserve obj (overwrite index, no longer needed)
1275   data_for_oop(obj, dst_temp, elem_klass);
1276   access_value_copy(IS_DEST_UNINITIALIZED, src, dst_temp, elem_klass);
1277   pop(obj);
1278   jmp(done);
1279 
1280   bind(empty_value);
1281   get_empty_inline_type_oop(elem_klass, dst_temp, obj);
1282   jmp(done);
1283 
1284   bind(alloc_failed);
1285   pop(index);
1286   if (array == c_rarg2) {
1287     mov(elem_klass, array);
1288     array = elem_klass;
1289   }
1290   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::value_array_load), array, index);
1291 
1292   bind(done);
1293 }
1294 
1295 
1296 // Lock object
1297 //
1298 // Args:
1299 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1300 //
1301 // Kills:
1302 //      rax, rbx
1303 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1304   assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1305          "The argument is only for looks. It must be c_rarg1");
1306 
1307   if (LockingMode == LM_MONITOR) {
1308     call_VM(noreg,
1309             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1310             lock_reg);
1311   } else {
1312     Label count_locking, done, slow_case;
1313 
1314     const Register swap_reg = rax; // Must use rax for cmpxchg instruction

1327     if (DiagnoseSyncOnValueBasedClasses != 0) {
1328       load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1329       testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1330       jcc(Assembler::notZero, slow_case);
1331     }
1332 
1333     if (LockingMode == LM_LIGHTWEIGHT) {
1334 #ifdef _LP64
1335       const Register thread = r15_thread;
1336       lightweight_lock(lock_reg, obj_reg, swap_reg, thread, tmp_reg, slow_case);
1337 #else
1338       // Lacking registers and thread on x86_32. Always take slow path.
1339       jmp(slow_case);
1340 #endif
1341     } else if (LockingMode == LM_LEGACY) {
1342       // Load immediate 1 into swap_reg %rax
1343       movl(swap_reg, 1);
1344 
1345       // Load (object->mark() | 1) into swap_reg %rax
1346       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1347       if (EnableValhalla) {
1348         // Mask inline_type bit such that we go to the slow path if object is an inline type
1349         andptr(swap_reg, ~((int) markWord::inline_type_bit_in_place));
1350       }
1351 
1352       // Save (object->mark() | 1) into BasicLock's displaced header
1353       movptr(Address(lock_reg, mark_offset), swap_reg);
1354 
1355       assert(lock_offset == 0,
1356              "displaced header must be first word in BasicObjectLock");
1357 
1358       lock();
1359       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1360       jcc(Assembler::zero, count_locking);
1361 
1362       const int zero_bits = LP64_ONLY(7) NOT_LP64(3);
1363 
1364       // Fast check for recursive lock.
1365       //
1366       // Can apply the optimization only if this is a stack lock
1367       // allocated in this thread. For efficiency, we can focus on
1368       // recently allocated stack locks (instead of reading the stack
1369       // base and checking whether 'mark' points inside the current
1370       // thread stack):

1688     test_method_data_pointer(mdp, profile_continue);
1689 
1690     // We are taking a branch.  Increment the taken count.
1691     // We inline increment_mdp_data_at to return bumped_count in a register
1692     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1693     Address data(mdp, in_bytes(JumpData::taken_offset()));
1694     movptr(bumped_count, data);
1695     assert(DataLayout::counter_increment == 1,
1696             "flow-free idiom only works with 1");
1697     addptr(bumped_count, DataLayout::counter_increment);
1698     sbbptr(bumped_count, 0);
1699     movptr(data, bumped_count); // Store back out
1700 
1701     // The method data pointer needs to be updated to reflect the new target.
1702     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1703     bind(profile_continue);
1704   }
1705 }
1706 
1707 
1708 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1709   if (ProfileInterpreter) {
1710     Label profile_continue;
1711 
1712     // If no method data exists, go to profile_continue.
1713     test_method_data_pointer(mdp, profile_continue);
1714 
1715     // We are taking a branch.  Increment the not taken count.
1716     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1717 
1718     // The method data pointer needs to be updated to correspond to
1719     // the next bytecode
1720     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1721     bind(profile_continue);
1722   }
1723 }
1724 
1725 void InterpreterMacroAssembler::profile_call(Register mdp) {
1726   if (ProfileInterpreter) {
1727     Label profile_continue;
1728 
1729     // If no method data exists, go to profile_continue.
1730     test_method_data_pointer(mdp, profile_continue);
1731 
1732     // We are making a call.  Increment the count.
1733     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1734 
1735     // The method data pointer needs to be updated to reflect the new target.
1736     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1737     bind(profile_continue);
1738   }
1739 }
1740 

1763                                                      Register reg2,
1764                                                      bool receiver_can_be_null) {
1765   if (ProfileInterpreter) {
1766     Label profile_continue;
1767 
1768     // If no method data exists, go to profile_continue.
1769     test_method_data_pointer(mdp, profile_continue);
1770 
1771     Label skip_receiver_profile;
1772     if (receiver_can_be_null) {
1773       Label not_null;
1774       testptr(receiver, receiver);
1775       jccb(Assembler::notZero, not_null);
1776       // We are making a call.  Increment the count for null receiver.
1777       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1778       jmp(skip_receiver_profile);
1779       bind(not_null);
1780     }
1781 
1782     // Record the receiver type.
1783     record_klass_in_profile(receiver, mdp, reg2);
1784     bind(skip_receiver_profile);
1785 
1786     // The method data pointer needs to be updated to reflect the new target.
1787     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1788     bind(profile_continue);
1789   }
1790 }
1791 
1792 // This routine creates a state machine for updating the multi-row
1793 // type profile at a virtual call site (or other type-sensitive bytecode).
1794 // The machine visits each row (of receiver/count) until the receiver type
1795 // is found, or until it runs out of rows.  At the same time, it remembers
1796 // the location of the first empty row.  (An empty row records null for its
1797 // receiver, and can be allocated for a newly-observed receiver type.)
1798 // Because there are two degrees of freedom in the state, a simple linear
1799 // search will not work; it must be a decision tree.  Hence this helper
1800 // function is recursive, to generate the required tree structured code.
1801 // It's the interpreter, so we are trading off code space for speed.
1802 // See below for example code.
1803 void InterpreterMacroAssembler::record_klass_in_profile_helper(Register receiver, Register mdp,
1804                                                                Register reg2, int start_row,
1805                                                                Label& done) {

1806   if (TypeProfileWidth == 0) {
1807     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1808   } else {
1809     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1810                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1811   }
1812 }
1813 
1814 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1815                                                               Label& done, int total_rows,
1816                                                               OffsetFunction item_offset_fn,
1817                                                               OffsetFunction item_count_offset_fn) {
1818   int last_row = total_rows - 1;
1819   assert(start_row <= last_row, "must be work left to do");
1820   // Test this row for both the item and for null.
1821   // Take any of three different outcomes:
1822   //   1. found item => increment count and goto done
1823   //   2. found null => keep looking for case 1, maybe allocate this cell
1824   //   3. found something else => keep looking for cases 1 and 2
1825   // Case 3 is handled by a recursive call.

1889 //     // inner copy of decision tree, rooted at row[1]
1890 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1891 //     if (row[1].rec != nullptr) {
1892 //       // degenerate decision tree, rooted at row[2]
1893 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1894 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1895 //       row[2].init(rec); goto done;
1896 //     } else {
1897 //       // remember row[1] is empty
1898 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1899 //       row[1].init(rec); goto done;
1900 //     }
1901 //   } else {
1902 //     // remember row[0] is empty
1903 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1904 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1905 //     row[0].init(rec); goto done;
1906 //   }
1907 //   done:
1908 
1909 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, Register mdp, Register reg2) {


1910   assert(ProfileInterpreter, "must be profiling");
1911   Label done;
1912 
1913   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1914 
1915   bind (done);
1916 }
1917 
1918 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1919                                             Register mdp) {
1920   if (ProfileInterpreter) {
1921     Label profile_continue;
1922     uint row;
1923 
1924     // If no method data exists, go to profile_continue.
1925     test_method_data_pointer(mdp, profile_continue);
1926 
1927     // Update the total ret count.
1928     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1929 
1930     for (row = 0; row < RetData::row_limit(); row++) {
1931       Label next_test;
1932 
1933       // See if return_bci is equal to bci[n]:

1970     update_mdp_by_constant(mdp, mdp_delta);
1971 
1972     bind(profile_continue);
1973   }
1974 }
1975 
1976 
1977 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1978   if (ProfileInterpreter) {
1979     Label profile_continue;
1980 
1981     // If no method data exists, go to profile_continue.
1982     test_method_data_pointer(mdp, profile_continue);
1983 
1984     // The method data pointer needs to be updated.
1985     int mdp_delta = in_bytes(BitData::bit_data_size());
1986     if (TypeProfileCasts) {
1987       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1988 
1989       // Record the object type.
1990       record_klass_in_profile(klass, mdp, reg2);
1991       NOT_LP64(assert(reg2 == rdi, "we know how to fix this blown reg");)
1992       NOT_LP64(restore_locals();)         // Restore EDI
1993     }
1994     update_mdp_by_constant(mdp, mdp_delta);
1995 
1996     bind(profile_continue);
1997   }
1998 }
1999 
2000 
2001 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
2002   if (ProfileInterpreter) {
2003     Label profile_continue;
2004 
2005     // If no method data exists, go to profile_continue.
2006     test_method_data_pointer(mdp, profile_continue);
2007 
2008     // Update the default case count
2009     increment_mdp_data_at(mdp,
2010                           in_bytes(MultiBranchData::default_count_offset()));

2032     // case_array_offset_in_bytes()
2033     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
2034     imulptr(index, reg2); // XXX l ?
2035     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
2036 
2037     // Update the case count
2038     increment_mdp_data_at(mdp,
2039                           index,
2040                           in_bytes(MultiBranchData::relative_count_offset()));
2041 
2042     // The method data pointer needs to be updated.
2043     update_mdp_by_offset(mdp,
2044                          index,
2045                          in_bytes(MultiBranchData::
2046                                   relative_displacement_offset()));
2047 
2048     bind(profile_continue);
2049   }
2050 }
2051 
2052 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
2053                                                                               Register array,
2054                                                                               Register tmp) {
2055   if (ProfileInterpreter) {
2056     Label profile_continue;
2057 
2058     // If no method data exists, go to profile_continue.
2059     test_method_data_pointer(mdp, profile_continue);
2060 
2061     mov(tmp, array);
2062     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
2063 
2064     Label not_flat;
2065     test_non_flat_array_oop(array, tmp, not_flat);
2066 
2067     set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
2068 
2069     bind(not_flat);
2070 
2071     Label not_null_free;
2072     test_non_null_free_array_oop(array, tmp, not_null_free);
2073 
2074     set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
2075 
2076     bind(not_null_free);
2077 
2078     bind(profile_continue);
2079   }
2080 }
2081 
2082 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
2083                                                                            Register array,
2084                                                                            Register tmp);
2085 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
2086                                                                             Register array,
2087                                                                             Register tmp);
2088 
2089 
2090 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
2091   if (ProfileInterpreter) {
2092     Label profile_continue;
2093 
2094     // If no method data exists, go to profile_continue.
2095     test_method_data_pointer(mdp, profile_continue);
2096 
2097     Label done, update;
2098     testptr(element, element);
2099     jccb(Assembler::notZero, update);
2100     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
2101     jmp(done);
2102 
2103     bind(update);
2104     load_klass(tmp, element, rscratch1);
2105 
2106     // Record the object type.
2107     record_klass_in_profile(tmp, mdp, tmp2);
2108 
2109     bind(done);
2110 
2111     // The method data pointer needs to be updated.
2112     update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
2113 
2114     bind(profile_continue);
2115   }
2116 }
2117 
2118 void InterpreterMacroAssembler::profile_element_type(Register mdp,
2119                                                      Register element,
2120                                                      Register tmp) {
2121   if (ProfileInterpreter) {
2122     Label profile_continue;
2123 
2124     // If no method data exists, go to profile_continue.
2125     test_method_data_pointer(mdp, profile_continue);
2126 
2127     mov(tmp, element);
2128     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
2129 
2130     // The method data pointer needs to be updated.
2131     update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
2132 
2133     bind(profile_continue);
2134   }
2135 }
2136 
2137 void InterpreterMacroAssembler::profile_acmp(Register mdp,
2138                                              Register left,
2139                                              Register right,
2140                                              Register tmp) {
2141   if (ProfileInterpreter) {
2142     Label profile_continue;
2143 
2144     // If no method data exists, go to profile_continue.
2145     test_method_data_pointer(mdp, profile_continue);
2146 
2147     mov(tmp, left);
2148     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
2149 
2150     Label left_not_inline_type;
2151     test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
2152     set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
2153     bind(left_not_inline_type);
2154 
2155     mov(tmp, right);
2156     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
2157 
2158     Label right_not_inline_type;
2159     test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
2160     set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
2161     bind(right_not_inline_type);
2162 
2163     bind(profile_continue);
2164   }
2165 }
2166 
2167 
2168 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
2169   if (state == atos) {
2170     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
2171   }
2172 }
2173 
2174 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2175 #ifndef _LP64
2176   if ((state == ftos && UseSSE < 1) ||
2177       (state == dtos && UseSSE < 2)) {
2178     MacroAssembler::verify_FPU(stack_depth);
2179   }
2180 #endif
2181 }
2182 
2183 // Jump if ((*counter_addr += increment) & mask) == 0
2184 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
2185                                                         Register scratch, Label* where) {
< prev index next >