< 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   {
1192     SkipIfEqual skip_if(this, &DTraceAllocProbes, 0, rscratch1);
1193     // Trigger dtrace event for fastpath
1194     push(atos);
1195     call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1196     pop(atos);
1197   }
1198 }
1199 
1200 void InterpreterMacroAssembler::read_flat_field(Register entry, Register tmp1, Register tmp2, Register obj) {
1201   Label alloc_failed, empty_value, done;
1202   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1203   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1204   assert_different_registers(obj, entry, tmp1, tmp2, dst_temp, r8, r9);
1205 
1206   // FIXME: code below could be re-written to better use InlineLayoutInfo data structure
1207   // see aarch64 version
1208 
1209   // Grap the inline field klass
1210   const Register field_klass = tmp1;
1211   load_unsigned_short(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1212   movptr(tmp1, Address(entry, ResolvedFieldEntry::field_holder_offset()));
1213   get_inline_type_field_klass(tmp1, tmp2, field_klass);
1214 
1215     //check for empty value klass
1216   test_klass_is_empty_inline_type(field_klass, dst_temp, empty_value);
1217 
1218   // allocate buffer
1219   push(obj);  // push object being read from     // FIXME spilling on stack could probably be avoided by using tmp2
1220   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1221 
1222   // Have an oop instance buffer, copy into it
1223   load_unsigned_short(r9, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1224   movptr(r8, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1225   inline_layout_info(r8, r9, r8); // holder, index, info => InlineLayoutInfo into r8
1226 
1227   data_for_oop(obj, dst_temp, field_klass);
1228   pop(alloc_temp);             // restore object being read from
1229   load_sized_value(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
1230   lea(tmp2, Address(alloc_temp, tmp2));
1231   // call_VM_leaf, clobbers a few regs, save restore new obj
1232   push(obj);
1233   // access_value_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, field_klass);
1234   flat_field_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, r8);
1235   pop(obj);
1236   jmp(done);
1237 
1238   bind(empty_value);
1239   get_empty_inline_type_oop(field_klass, dst_temp, obj);
1240   jmp(done);
1241 
1242   bind(alloc_failed);
1243   pop(obj);
1244   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1245           obj, entry);
1246   get_vm_result(obj, r15_thread);
1247   bind(done);
1248 }
1249 
1250 void InterpreterMacroAssembler::read_flat_element(Register array, Register index,
1251                                                   Register t1, Register t2,
1252                                                   Register obj) {
1253   assert_different_registers(array, index, t1, t2);
1254   Label alloc_failed, empty_value, done;
1255   const Register array_klass = t2;
1256   const Register elem_klass = t1;
1257   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1258   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1259 
1260   // load in array->klass()->element_klass()
1261   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1262   load_klass(array_klass, array, tmp_load_klass);
1263   movptr(elem_klass, Address(array_klass, ArrayKlass::element_klass_offset()));
1264 
1265   //check for empty value klass
1266   test_klass_is_empty_inline_type(elem_klass, dst_temp, empty_value);
1267 
1268   // calc source into "array_klass" and free up some regs
1269   const Register src = array_klass;
1270   push(index); // preserve index reg in case alloc_failed
1271   data_for_value_array_index(array, array_klass, index, src);
1272 
1273   allocate_instance(elem_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1274   // Have an oop instance buffer, copy into it
1275   store_ptr(0, obj); // preserve obj (overwrite index, no longer needed)
1276   data_for_oop(obj, dst_temp, elem_klass);
1277   access_value_copy(IS_DEST_UNINITIALIZED, src, dst_temp, elem_klass);
1278   pop(obj);
1279   jmp(done);
1280 
1281   bind(empty_value);
1282   get_empty_inline_type_oop(elem_klass, dst_temp, obj);
1283   jmp(done);
1284 
1285   bind(alloc_failed);
1286   pop(index);
1287   if (array == c_rarg2) {
1288     mov(elem_klass, array);
1289     array = elem_klass;
1290   }
1291   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::value_array_load), array, index);
1292 
1293   bind(done);
1294 }
1295 
1296 
1297 // Lock object
1298 //
1299 // Args:
1300 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1301 //
1302 // Kills:
1303 //      rax, rbx
1304 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1305   assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1306          "The argument is only for looks. It must be c_rarg1");
1307 
1308   if (LockingMode == LM_MONITOR) {
1309     call_VM(noreg,
1310             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1311             lock_reg);
1312   } else {
1313     Label count_locking, done, slow_case;
1314 
1315     const Register swap_reg = rax; // Must use rax for cmpxchg instruction

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

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

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

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

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


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

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

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