< prev index next >

src/hotspot/cpu/x86/interp_masm_x86.cpp

Print this page

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "compiler/compiler_globals.hpp"
  26 #include "interp_masm_x86.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "interpreter/interpreterRuntime.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/arrayOop.hpp"

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

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

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

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

 565                                                              Register cpool,
 566                                                              Register index) {
 567   assert_different_registers(cpool, index);
 568 
 569   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 570   Register resolved_klasses = cpool;
 571   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
 572   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 573 }
 574 
 575 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 576 // subtype of super_klass.
 577 //
 578 // Args:
 579 //      rax: superklass
 580 //      Rsub_klass: subklass
 581 //
 582 // Kills:
 583 //      rcx, rdi
 584 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 585                                                   Label& ok_is_subtype) {

 586   assert(Rsub_klass != rax, "rax holds superklass");
 587   assert(Rsub_klass != r14, "r14 holds locals");
 588   assert(Rsub_klass != r13, "r13 holds bcp");
 589   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 590   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 591 
 592   // Profile the not-null value's klass.
 593   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi


 594 
 595   // Do the check.
 596   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 597 }
 598 
 599 
 600 // Java Expression Stack
 601 
 602 void InterpreterMacroAssembler::pop_ptr(Register r) {
 603   pop(r);
 604 }
 605 
 606 void InterpreterMacroAssembler::push_ptr(Register r) {
 607   push(r);
 608 }
 609 
 610 void InterpreterMacroAssembler::push_i(Register r) {
 611   push(r);
 612 }
 613 

 867   Label unlocked, unlock, no_unlock;
 868 
 869 #ifdef ASSERT
 870   Label not_preempted;
 871   cmpptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD);
 872   jcc(Assembler::equal, not_preempted);
 873   stop("remove_activation: should not have alternate return address set");
 874   bind(not_preempted);
 875 #endif /* ASSERT */
 876 
 877   const Register rthread = r15_thread;
 878   const Register robj    = c_rarg1;
 879   const Register rmon    = c_rarg1;
 880 
 881   // get the value of _do_not_unlock_if_synchronized into rdx
 882   const Address do_not_unlock_if_synchronized(rthread,
 883     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 884   movbool(rbx, do_not_unlock_if_synchronized);
 885   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 886 
 887  // get method access flags
 888   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 889   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 890   testl(rcx, JVM_ACC_SYNCHRONIZED);
 891   jcc(Assembler::zero, unlocked);
 892 
 893   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 894   // is set.
 895   testbool(rbx);
 896   jcc(Assembler::notZero, no_unlock);
 897 
 898   // unlock monitor
 899   push(state); // save result
 900 
 901   // BasicObjectLock will be first in list, since this is a
 902   // synchronized method. However, need to check that the object has
 903   // not been unlocked by an explicit monitorexit bytecode.
 904   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 905                         wordSize - (int) sizeof(BasicObjectLock));
 906   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 907   // register for unlock_object to pass to VM directly

1006   // the stack, will call InterpreterRuntime::at_unwind.
1007   Label slow_path;
1008   Label fast_path;
1009   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
1010   jmp(fast_path);
1011   bind(slow_path);
1012   push(state);
1013   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
1014   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread);
1015   reset_last_Java_frame(true);
1016   pop(state);
1017   bind(fast_path);
1018 
1019   // JVMTI support. Make sure the safepoint poll test is issued prior.
1020   if (notify_jvmdi) {
1021     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
1022   } else {
1023     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1024   }
1025 
1026   // remove activation
1027   // get sender sp
1028   movptr(rbx,
1029          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1030   if (StackReservedPages > 0) {


1031     // testing if reserved zone needs to be re-enabled
1032     Register rthread = r15_thread;
1033     Label no_reserved_zone_enabling;
1034 
1035     // check if already enabled - if so no re-enabling needed
1036     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
1037     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1038     jcc(Assembler::equal, no_reserved_zone_enabling);
1039 
1040     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1041     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1042 
1043     JFR_ONLY(leave_jfr_critical_section();)
1044 
1045     call_VM_leaf(
1046       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1047     call_VM(noreg, CAST_FROM_FN_PTR(address,
1048                    InterpreterRuntime::throw_delayed_StackOverflowError));
1049     should_not_reach_here();
1050 
1051     bind(no_reserved_zone_enabling);
1052   }
1053 




















































1054   leave();                           // remove frame anchor
1055 
1056   JFR_ONLY(leave_jfr_critical_section();)
1057 
1058   pop(ret_addr);                     // get return address
1059   mov(rsp, rbx);                     // set sp to sender sp
1060   pop_cont_fastpath();
1061 
1062 }
1063 
1064 #if INCLUDE_JFR
1065 void InterpreterMacroAssembler::enter_jfr_critical_section() {
1066   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1067   movbool(sampling_critical_section, true);
1068 }
1069 
1070 void InterpreterMacroAssembler::leave_jfr_critical_section() {
1071   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1072   movbool(sampling_critical_section, false);
1073 }
1074 #endif // INCLUDE_JFR
1075 
1076 void InterpreterMacroAssembler::get_method_counters(Register method,
1077                                                     Register mcs, Label& skip) {
1078   Label has_counters;
1079   movptr(mcs, Address(method, Method::method_counters_offset()));
1080   testptr(mcs, mcs);
1081   jcc(Assembler::notZero, has_counters);
1082   call_VM(noreg, CAST_FROM_FN_PTR(address,
1083           InterpreterRuntime::build_method_counters), method);
1084   movptr(mcs, Address(method,Method::method_counters_offset()));
1085   testptr(mcs, mcs);
1086   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1087   bind(has_counters);
1088 }
1089 

























































































1090 
1091 // Lock object
1092 //
1093 // Args:
1094 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1095 //
1096 // Kills:
1097 //      rax, rbx
1098 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1099   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1100 
1101   Label done, slow_case;
1102 
1103   const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1104   const Register tmp_reg = rbx;
1105   const Register obj_reg = c_rarg3; // Will contain the oop
1106 
1107   // Load object pointer into obj_reg
1108   movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1109 

1322 }
1323 
1324 
1325 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1326   if (ProfileInterpreter) {
1327     Label profile_continue;
1328 
1329     // If no method data exists, go to profile_continue.
1330     test_method_data_pointer(mdp, profile_continue);
1331 
1332     // We are taking a branch.  Increment the taken count.
1333     increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1334 
1335     // The method data pointer needs to be updated to reflect the new target.
1336     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1337     bind(profile_continue);
1338   }
1339 }
1340 
1341 
1342 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1343   if (ProfileInterpreter) {
1344     Label profile_continue;
1345 
1346     // If no method data exists, go to profile_continue.
1347     test_method_data_pointer(mdp, profile_continue);
1348 
1349     // We are not taking a branch.  Increment the not taken count.
1350     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1351 
1352     // The method data pointer needs to be updated to correspond to
1353     // the next bytecode
1354     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1355     bind(profile_continue);
1356   }
1357 }
1358 
1359 void InterpreterMacroAssembler::profile_call(Register mdp) {
1360   if (ProfileInterpreter) {
1361     Label profile_continue;
1362 
1363     // If no method data exists, go to profile_continue.
1364     test_method_data_pointer(mdp, profile_continue);
1365 
1366     // We are making a call.  Increment the count.
1367     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1368 
1369     // The method data pointer needs to be updated to reflect the new target.
1370     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1371     bind(profile_continue);
1372   }
1373 }
1374 

1397                                                      Register reg2,
1398                                                      bool receiver_can_be_null) {
1399   if (ProfileInterpreter) {
1400     Label profile_continue;
1401 
1402     // If no method data exists, go to profile_continue.
1403     test_method_data_pointer(mdp, profile_continue);
1404 
1405     Label skip_receiver_profile;
1406     if (receiver_can_be_null) {
1407       Label not_null;
1408       testptr(receiver, receiver);
1409       jccb(Assembler::notZero, not_null);
1410       // We are making a call.  Increment the count for null receiver.
1411       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1412       jmp(skip_receiver_profile);
1413       bind(not_null);
1414     }
1415 
1416     // Record the receiver type.
1417     record_klass_in_profile(receiver, mdp, reg2, true);
1418     bind(skip_receiver_profile);
1419 
1420     // The method data pointer needs to be updated to reflect the new target.
1421     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1422     bind(profile_continue);
1423   }
1424 }
1425 
1426 // This routine creates a state machine for updating the multi-row
1427 // type profile at a virtual call site (or other type-sensitive bytecode).
1428 // The machine visits each row (of receiver/count) until the receiver type
1429 // is found, or until it runs out of rows.  At the same time, it remembers
1430 // the location of the first empty row.  (An empty row records null for its
1431 // receiver, and can be allocated for a newly-observed receiver type.)
1432 // Because there are two degrees of freedom in the state, a simple linear
1433 // search will not work; it must be a decision tree.  Hence this helper
1434 // function is recursive, to generate the required tree structured code.
1435 // It's the interpreter, so we are trading off code space for speed.
1436 // See below for example code.
1437 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1438                                         Register receiver, Register mdp,
1439                                         Register reg2, int start_row,
1440                                         Label& done, bool is_virtual_call) {
1441   if (TypeProfileWidth == 0) {
1442     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1443   } else {
1444     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1445                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1446   }
1447 }
1448 
1449 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1450                                                               Label& done, int total_rows,
1451                                                               OffsetFunction item_offset_fn,
1452                                                               OffsetFunction item_count_offset_fn) {
1453   int last_row = total_rows - 1;
1454   assert(start_row <= last_row, "must be work left to do");
1455   // Test this row for both the item and for null.
1456   // Take any of three different outcomes:
1457   //   1. found item => increment count and goto done
1458   //   2. found null => keep looking for case 1, maybe allocate this cell
1459   //   3. found something else => keep looking for cases 1 and 2
1460   // Case 3 is handled by a recursive call.

1524 //     // inner copy of decision tree, rooted at row[1]
1525 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1526 //     if (row[1].rec != nullptr) {
1527 //       // degenerate decision tree, rooted at row[2]
1528 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1529 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1530 //       row[2].init(rec); goto done;
1531 //     } else {
1532 //       // remember row[1] is empty
1533 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1534 //       row[1].init(rec); goto done;
1535 //     }
1536 //   } else {
1537 //     // remember row[0] is empty
1538 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1539 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1540 //     row[0].init(rec); goto done;
1541 //   }
1542 //   done:
1543 
1544 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1545                                                         Register mdp, Register reg2,
1546                                                         bool is_virtual_call) {
1547   assert(ProfileInterpreter, "must be profiling");
1548   Label done;
1549 
1550   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1551 
1552   bind (done);
1553 }
1554 
1555 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1556                                             Register mdp) {
1557   if (ProfileInterpreter) {
1558     Label profile_continue;
1559     uint row;
1560 
1561     // If no method data exists, go to profile_continue.
1562     test_method_data_pointer(mdp, profile_continue);
1563 
1564     // Update the total ret count.
1565     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1566 
1567     for (row = 0; row < RetData::row_limit(); row++) {
1568       Label next_test;
1569 
1570       // See if return_bci is equal to bci[n]:

1607     update_mdp_by_constant(mdp, mdp_delta);
1608 
1609     bind(profile_continue);
1610   }
1611 }
1612 
1613 
1614 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1615   if (ProfileInterpreter) {
1616     Label profile_continue;
1617 
1618     // If no method data exists, go to profile_continue.
1619     test_method_data_pointer(mdp, profile_continue);
1620 
1621     // The method data pointer needs to be updated.
1622     int mdp_delta = in_bytes(BitData::bit_data_size());
1623     if (TypeProfileCasts) {
1624       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1625 
1626       // Record the object type.
1627       record_klass_in_profile(klass, mdp, reg2, false);
1628     }
1629     update_mdp_by_constant(mdp, mdp_delta);
1630 
1631     bind(profile_continue);
1632   }
1633 }
1634 
1635 
1636 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1637   if (ProfileInterpreter) {
1638     Label profile_continue;
1639 
1640     // If no method data exists, go to profile_continue.
1641     test_method_data_pointer(mdp, profile_continue);
1642 
1643     // Update the default case count
1644     increment_mdp_data_at(mdp,
1645                           in_bytes(MultiBranchData::default_count_offset()));
1646 
1647     // The method data pointer needs to be updated.

1667     // case_array_offset_in_bytes()
1668     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1669     imulptr(index, reg2); // XXX l ?
1670     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1671 
1672     // Update the case count
1673     increment_mdp_data_at(mdp,
1674                           index,
1675                           in_bytes(MultiBranchData::relative_count_offset()));
1676 
1677     // The method data pointer needs to be updated.
1678     update_mdp_by_offset(mdp,
1679                          index,
1680                          in_bytes(MultiBranchData::
1681                                   relative_displacement_offset()));
1682 
1683     bind(profile_continue);
1684   }
1685 }
1686 


















































































































1687 
1688 
1689 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1690   if (state == atos) {
1691     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1692   }
1693 }
1694 
1695 
1696 // Jump if ((*counter_addr += increment) & mask) == 0
1697 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1698                                                         Register scratch, Label* where) {
1699   // This update is actually not atomic and can lose a number of updates
1700   // under heavy contention, but the alternative of using the (contended)
1701   // atomic update here penalizes profiling paths too much.
1702   movl(scratch, counter_addr);
1703   incrementl(scratch, InvocationCounter::count_increment);
1704   movl(counter_addr, scratch);
1705   andl(scratch, mask);
1706   if (where != nullptr) {

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "compiler/compiler_globals.hpp"
  26 #include "interp_masm_x86.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "interpreter/interpreterRuntime.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/arrayOop.hpp"
  31 #include "oops/constMethodFlags.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/method.hpp"
  35 #include "oops/inlineKlass.hpp"
  36 #include "oops/resolvedFieldEntry.hpp"
  37 #include "oops/resolvedIndyEntry.hpp"
  38 #include "oops/resolvedMethodEntry.hpp"
  39 #include "prims/jvmtiExport.hpp"
  40 #include "prims/jvmtiThreadState.hpp"
  41 #include "runtime/basicLock.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/javaThread.hpp"
  44 #include "runtime/safepointMechanism.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 #include "utilities/powerOfTwo.hpp"
  47 
  48 // Implementation of InterpreterMacroAssembler
  49 
  50 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  51   assert(entry, "Entry must have been generated by now");
  52   jump(RuntimeAddress(entry));
  53 }
  54 
  55 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {

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

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

 567                                                              Register cpool,
 568                                                              Register index) {
 569   assert_different_registers(cpool, index);
 570 
 571   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 572   Register resolved_klasses = cpool;
 573   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
 574   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 575 }
 576 
 577 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 578 // subtype of super_klass.
 579 //
 580 // Args:
 581 //      rax: superklass
 582 //      Rsub_klass: subklass
 583 //
 584 // Kills:
 585 //      rcx, rdi
 586 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 587                                                   Label& ok_is_subtype,
 588                                                   bool profile) {
 589   assert(Rsub_klass != rax, "rax holds superklass");
 590   assert(Rsub_klass != r14, "r14 holds locals");
 591   assert(Rsub_klass != r13, "r13 holds bcp");
 592   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 593   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 594 
 595   // Profile the not-null value's klass.
 596   if (profile) {
 597     profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
 598   }
 599 
 600   // Do the check.
 601   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 602 }
 603 
 604 
 605 // Java Expression Stack
 606 
 607 void InterpreterMacroAssembler::pop_ptr(Register r) {
 608   pop(r);
 609 }
 610 
 611 void InterpreterMacroAssembler::push_ptr(Register r) {
 612   push(r);
 613 }
 614 
 615 void InterpreterMacroAssembler::push_i(Register r) {
 616   push(r);
 617 }
 618 

 872   Label unlocked, unlock, no_unlock;
 873 
 874 #ifdef ASSERT
 875   Label not_preempted;
 876   cmpptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD);
 877   jcc(Assembler::equal, not_preempted);
 878   stop("remove_activation: should not have alternate return address set");
 879   bind(not_preempted);
 880 #endif /* ASSERT */
 881 
 882   const Register rthread = r15_thread;
 883   const Register robj    = c_rarg1;
 884   const Register rmon    = c_rarg1;
 885 
 886   // get the value of _do_not_unlock_if_synchronized into rdx
 887   const Address do_not_unlock_if_synchronized(rthread,
 888     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 889   movbool(rbx, do_not_unlock_if_synchronized);
 890   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 891 
 892   // get method access flags
 893   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 894   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 895   testl(rcx, JVM_ACC_SYNCHRONIZED);
 896   jcc(Assembler::zero, unlocked);
 897 
 898   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 899   // is set.
 900   testbool(rbx);
 901   jcc(Assembler::notZero, no_unlock);
 902 
 903   // unlock monitor
 904   push(state); // save result
 905 
 906   // BasicObjectLock will be first in list, since this is a
 907   // synchronized method. However, need to check that the object has
 908   // not been unlocked by an explicit monitorexit bytecode.
 909   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 910                         wordSize - (int) sizeof(BasicObjectLock));
 911   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 912   // register for unlock_object to pass to VM directly

1011   // the stack, will call InterpreterRuntime::at_unwind.
1012   Label slow_path;
1013   Label fast_path;
1014   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
1015   jmp(fast_path);
1016   bind(slow_path);
1017   push(state);
1018   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
1019   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread);
1020   reset_last_Java_frame(true);
1021   pop(state);
1022   bind(fast_path);
1023 
1024   // JVMTI support. Make sure the safepoint poll test is issued prior.
1025   if (notify_jvmdi) {
1026     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
1027   } else {
1028     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1029   }
1030 




1031   if (StackReservedPages > 0) {
1032     movptr(rbx,
1033                Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1034     // testing if reserved zone needs to be re-enabled
1035     Register rthread = r15_thread;
1036     Label no_reserved_zone_enabling;
1037 
1038     // check if already enabled - if so no re-enabling needed
1039     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
1040     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1041     jcc(Assembler::equal, no_reserved_zone_enabling);
1042 
1043     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1044     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1045 
1046     JFR_ONLY(leave_jfr_critical_section();)
1047 
1048     call_VM_leaf(
1049       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1050     call_VM(noreg, CAST_FROM_FN_PTR(address,
1051                    InterpreterRuntime::throw_delayed_StackOverflowError));
1052     should_not_reach_here();
1053 
1054     bind(no_reserved_zone_enabling);
1055   }
1056 
1057   // remove activation
1058   // get sender sp
1059   movptr(rbx,
1060          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1061 
1062   if (state == atos && InlineTypeReturnedAsFields) {
1063     Label skip;
1064     Label not_null;
1065     testptr(rax, rax);
1066     jcc(Assembler::notZero, not_null);
1067     // Returned value is null, zero all return registers because they may belong to oop fields
1068     xorq(j_rarg1, j_rarg1);
1069     xorq(j_rarg2, j_rarg2);
1070     xorq(j_rarg3, j_rarg3);
1071     xorq(j_rarg4, j_rarg4);
1072     xorq(j_rarg5, j_rarg5);
1073     jmp(skip);
1074     bind(not_null);
1075 
1076     // Check if we are returning an non-null inline type and load its fields into registers
1077     test_oop_is_not_inline_type(rax, rscratch1, skip, /* can_be_null= */ false);
1078 
1079 #ifndef _LP64
1080     super_call_VM_leaf(StubRoutines::load_inline_type_fields_in_regs());
1081 #else
1082     // Load fields from a buffered value with an inline class specific handler
1083     load_klass(rdi, rax, rscratch1);
1084     movptr(rdi, Address(rdi, InstanceKlass::adr_inlineklass_fixed_block_offset()));
1085     movptr(rdi, Address(rdi, InlineKlass::unpack_handler_offset()));
1086     // Unpack handler can be null if inline type is not scalarizable in returns
1087     testptr(rdi, rdi);
1088     jcc(Assembler::zero, skip);
1089     call(rdi);
1090 #endif
1091 #ifdef ASSERT
1092     // TODO 8284443 Enable
1093     if (StressCallingConvention && false) {
1094       Label skip_stress;
1095       movptr(rscratch1, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1096       movl(rscratch1, Address(rscratch1, Method::flags_offset()));
1097       testl(rcx, MethodFlags::has_scalarized_return_flag());
1098       jcc(Assembler::zero, skip_stress);
1099       load_klass(rax, rax, rscratch1);
1100       orptr(rax, 1);
1101       bind(skip_stress);
1102     }
1103 #endif
1104     // call above kills the value in rbx. Reload it.
1105     movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1106     bind(skip);
1107   }
1108 
1109   leave();                           // remove frame anchor
1110 
1111   JFR_ONLY(leave_jfr_critical_section();)
1112 
1113   pop(ret_addr);                     // get return address
1114   mov(rsp, rbx);                     // set sp to sender sp
1115   pop_cont_fastpath();
1116 
1117 }
1118 
1119 #if INCLUDE_JFR
1120 void InterpreterMacroAssembler::enter_jfr_critical_section() {
1121   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1122   movbool(sampling_critical_section, true);
1123 }
1124 
1125 void InterpreterMacroAssembler::leave_jfr_critical_section() {
1126   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1127   movbool(sampling_critical_section, false);
1128 }
1129 #endif // INCLUDE_JFR
1130 
1131 void InterpreterMacroAssembler::get_method_counters(Register method,
1132                                                     Register mcs, Label& skip) {
1133   Label has_counters;
1134   movptr(mcs, Address(method, Method::method_counters_offset()));
1135   testptr(mcs, mcs);
1136   jcc(Assembler::notZero, has_counters);
1137   call_VM(noreg, CAST_FROM_FN_PTR(address,
1138           InterpreterRuntime::build_method_counters), method);
1139   movptr(mcs, Address(method,Method::method_counters_offset()));
1140   testptr(mcs, mcs);
1141   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1142   bind(has_counters);
1143 }
1144 
1145 void InterpreterMacroAssembler::allocate_instance(Register klass, Register new_obj,
1146                                                   Register t1, Register t2,
1147                                                   bool clear_fields, Label& alloc_failed) {
1148   MacroAssembler::allocate_instance(klass, new_obj, t1, t2, clear_fields, alloc_failed);
1149   if (DTraceAllocProbes) {
1150     // Trigger dtrace event for fastpath
1151     push(atos);
1152     call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1153     pop(atos);
1154   }
1155 }
1156 
1157 void InterpreterMacroAssembler::read_flat_field(Register entry, Register tmp1, Register tmp2, Register obj) {
1158   Label alloc_failed, slow_path, done;
1159   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1160   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1161   assert_different_registers(obj, entry, tmp1, tmp2, dst_temp, r8, r9);
1162 
1163   // If the field is nullable, jump to slow path
1164   load_unsigned_byte(tmp1, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
1165   testl(tmp1, 1 << ResolvedFieldEntry::is_null_free_inline_type_shift);
1166   jcc(Assembler::equal, slow_path);
1167 
1168   // Grap the inline field klass
1169   const Register field_klass = tmp1;
1170   load_unsigned_short(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1171 
1172   movptr(tmp1, Address(entry, ResolvedFieldEntry::field_holder_offset()));
1173   get_inline_type_field_klass(tmp1, tmp2, field_klass);
1174 
1175   // allocate buffer
1176   push(obj);  // push object being read from
1177   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1178 
1179   // Have an oop instance buffer, copy into it
1180   load_unsigned_short(r9, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1181   movptr(r8, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1182   inline_layout_info(r8, r9, r8); // holder, index, info => InlineLayoutInfo into r8
1183 
1184   payload_addr(obj, dst_temp, field_klass);
1185   pop(alloc_temp);             // restore object being read from
1186   load_sized_value(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
1187   lea(tmp2, Address(alloc_temp, tmp2));
1188   // call_VM_leaf, clobbers a few regs, save restore new obj
1189   push(obj);
1190   flat_field_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, r8);
1191   pop(obj);
1192   jmp(done);
1193 
1194   bind(alloc_failed);
1195   pop(obj);
1196   bind(slow_path);
1197   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1198           obj, entry);
1199   get_vm_result_oop(obj);
1200   bind(done);
1201 }
1202 
1203 void InterpreterMacroAssembler::write_flat_field(Register entry, Register tmp1, Register tmp2,
1204                                                  Register obj, Register off, Register value) {
1205   assert_different_registers(entry, tmp1, tmp2, obj, off, value);
1206 
1207   Label slow_path, done;
1208 
1209   load_unsigned_byte(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
1210   test_field_is_not_null_free_inline_type(tmp2, tmp1, slow_path);
1211 
1212   null_check(value); // FIXME JDK-8341120
1213 
1214   lea(obj, Address(obj, off, Address::times_1));
1215 
1216   load_klass(tmp2, value, tmp1);
1217   payload_addr(value, value, tmp2);
1218 
1219   Register idx = tmp1;
1220   load_unsigned_short(idx, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1221   movptr(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1222 
1223   Register layout_info = off;
1224   inline_layout_info(tmp2, idx, layout_info);
1225 
1226   flat_field_copy(IN_HEAP, value, obj, layout_info);
1227   jmp(done);
1228 
1229   bind(slow_path);
1230   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_flat_field), obj, value, entry);
1231 
1232   bind(done);
1233 }
1234 
1235 // Lock object
1236 //
1237 // Args:
1238 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1239 //
1240 // Kills:
1241 //      rax, rbx
1242 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1243   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1244 
1245   Label done, slow_case;
1246 
1247   const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1248   const Register tmp_reg = rbx;
1249   const Register obj_reg = c_rarg3; // Will contain the oop
1250 
1251   // Load object pointer into obj_reg
1252   movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1253 

1466 }
1467 
1468 
1469 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1470   if (ProfileInterpreter) {
1471     Label profile_continue;
1472 
1473     // If no method data exists, go to profile_continue.
1474     test_method_data_pointer(mdp, profile_continue);
1475 
1476     // We are taking a branch.  Increment the taken count.
1477     increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1478 
1479     // The method data pointer needs to be updated to reflect the new target.
1480     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1481     bind(profile_continue);
1482   }
1483 }
1484 
1485 
1486 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1487   if (ProfileInterpreter) {
1488     Label profile_continue;
1489 
1490     // If no method data exists, go to profile_continue.
1491     test_method_data_pointer(mdp, profile_continue);
1492 
1493     // We are not taking a branch.  Increment the not taken count.
1494     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1495 
1496     // The method data pointer needs to be updated to correspond to
1497     // the next bytecode
1498     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1499     bind(profile_continue);
1500   }
1501 }
1502 
1503 void InterpreterMacroAssembler::profile_call(Register mdp) {
1504   if (ProfileInterpreter) {
1505     Label profile_continue;
1506 
1507     // If no method data exists, go to profile_continue.
1508     test_method_data_pointer(mdp, profile_continue);
1509 
1510     // We are making a call.  Increment the count.
1511     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1512 
1513     // The method data pointer needs to be updated to reflect the new target.
1514     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1515     bind(profile_continue);
1516   }
1517 }
1518 

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

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

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


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

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

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