< prev index next >

src/hotspot/cpu/x86/interp_masm_x86.cpp

Print this page

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

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

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

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

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

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

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


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

 793 //       no error processing
 794 void InterpreterMacroAssembler::remove_activation(TosState state,
 795                                                   Register ret_addr,
 796                                                   bool throw_monitor_exception,
 797                                                   bool install_monitor_exception,
 798                                                   bool notify_jvmdi) {
 799   // Note: Registers rdx xmm0 may be in use for the
 800   // result check if synchronized method
 801   Label unlocked, unlock, no_unlock;
 802 
 803   const Register rthread = r15_thread;
 804   const Register robj    = c_rarg1;
 805   const Register rmon    = c_rarg1;
 806 
 807   // get the value of _do_not_unlock_if_synchronized into rdx
 808   const Address do_not_unlock_if_synchronized(rthread,
 809     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 810   movbool(rbx, do_not_unlock_if_synchronized);
 811   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 812 
 813  // get method access flags
 814   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 815   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 816   testl(rcx, JVM_ACC_SYNCHRONIZED);
 817   jcc(Assembler::zero, unlocked);
 818 
 819   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 820   // is set.
 821   testbool(rbx);
 822   jcc(Assembler::notZero, no_unlock);
 823 
 824   // unlock monitor
 825   push(state); // save result
 826 
 827   // BasicObjectLock will be first in list, since this is a
 828   // synchronized method. However, need to check that the object has
 829   // not been unlocked by an explicit monitorexit bytecode.
 830   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 831                         wordSize - (int) sizeof(BasicObjectLock));
 832   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 833   // register for unlock_object to pass to VM directly

 932   // the stack, will call InterpreterRuntime::at_unwind.
 933   Label slow_path;
 934   Label fast_path;
 935   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
 936   jmp(fast_path);
 937   bind(slow_path);
 938   push(state);
 939   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
 940   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread);
 941   reset_last_Java_frame(true);
 942   pop(state);
 943   bind(fast_path);
 944 
 945   // JVMTI support. Make sure the safepoint poll test is issued prior.
 946   if (notify_jvmdi) {
 947     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 948   } else {
 949     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 950   }
 951 
 952   // remove activation
 953   // get sender sp
 954   movptr(rbx,
 955          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
 956   if (StackReservedPages > 0) {


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




















































 980   leave();                           // remove frame anchor
 981 
 982   JFR_ONLY(leave_jfr_critical_section();)
 983 
 984   pop(ret_addr);                     // get return address
 985   mov(rsp, rbx);                     // set sp to sender sp
 986   pop_cont_fastpath();
 987 
 988 }
 989 
 990 #if INCLUDE_JFR
 991 void InterpreterMacroAssembler::enter_jfr_critical_section() {
 992   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
 993   movbool(sampling_critical_section, true);
 994 }
 995 
 996 void InterpreterMacroAssembler::leave_jfr_critical_section() {
 997   const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
 998   movbool(sampling_critical_section, false);
 999 }
1000 #endif // INCLUDE_JFR
1001 
1002 void InterpreterMacroAssembler::get_method_counters(Register method,
1003                                                     Register mcs, Label& skip) {
1004   Label has_counters;
1005   movptr(mcs, Address(method, Method::method_counters_offset()));
1006   testptr(mcs, mcs);
1007   jcc(Assembler::notZero, has_counters);
1008   call_VM(noreg, CAST_FROM_FN_PTR(address,
1009           InterpreterRuntime::build_method_counters), method);
1010   movptr(mcs, Address(method,Method::method_counters_offset()));
1011   testptr(mcs, mcs);
1012   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1013   bind(has_counters);
1014 }
1015 






















































1016 
1017 // Lock object
1018 //
1019 // Args:
1020 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1021 //
1022 // Kills:
1023 //      rax, rbx
1024 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1025   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1026 
1027   if (LockingMode == LM_MONITOR) {
1028     call_VM_preemptable(noreg,
1029             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1030             lock_reg);
1031   } else {
1032     Label count_locking, done, slow_case;
1033 
1034     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1035     const Register tmp_reg = rbx;

1041     const int mark_offset = lock_offset +
1042                             BasicLock::displaced_header_offset_in_bytes();
1043 
1044     // Load object pointer into obj_reg
1045     movptr(obj_reg, Address(lock_reg, obj_offset));
1046 
1047     if (LockingMode == LM_LIGHTWEIGHT) {
1048       lightweight_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case);
1049     } else if (LockingMode == LM_LEGACY) {
1050       if (DiagnoseSyncOnValueBasedClasses != 0) {
1051         load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1052         testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1053         jcc(Assembler::notZero, slow_case);
1054       }
1055 
1056       // Load immediate 1 into swap_reg %rax
1057       movl(swap_reg, 1);
1058 
1059       // Load (object->mark() | 1) into swap_reg %rax
1060       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));




1061 
1062       // Save (object->mark() | 1) into BasicLock's displaced header
1063       movptr(Address(lock_reg, mark_offset), swap_reg);
1064 
1065       assert(lock_offset == 0,
1066              "displaced header must be first word in BasicObjectLock");
1067 
1068       lock();
1069       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1070       jcc(Assembler::zero, count_locking);
1071 
1072       const int zero_bits = 7;
1073 
1074       // Fast check for recursive lock.
1075       //
1076       // Can apply the optimization only if this is a stack lock
1077       // allocated in this thread. For efficiency, we can focus on
1078       // recently allocated stack locks (instead of reading the stack
1079       // base and checking whether 'mark' points inside the current
1080       // thread stack):

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

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

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

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

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


















































































































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

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

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

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

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

 798 //       no error processing
 799 void InterpreterMacroAssembler::remove_activation(TosState state,
 800                                                   Register ret_addr,
 801                                                   bool throw_monitor_exception,
 802                                                   bool install_monitor_exception,
 803                                                   bool notify_jvmdi) {
 804   // Note: Registers rdx xmm0 may be in use for the
 805   // result check if synchronized method
 806   Label unlocked, unlock, no_unlock;
 807 
 808   const Register rthread = r15_thread;
 809   const Register robj    = c_rarg1;
 810   const Register rmon    = c_rarg1;
 811 
 812   // get the value of _do_not_unlock_if_synchronized into rdx
 813   const Address do_not_unlock_if_synchronized(rthread,
 814     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 815   movbool(rbx, do_not_unlock_if_synchronized);
 816   movbool(do_not_unlock_if_synchronized, false); // reset the flag
 817 
 818   // get method access flags
 819   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 820   load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
 821   testl(rcx, JVM_ACC_SYNCHRONIZED);
 822   jcc(Assembler::zero, unlocked);
 823 
 824   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 825   // is set.
 826   testbool(rbx);
 827   jcc(Assembler::notZero, no_unlock);
 828 
 829   // unlock monitor
 830   push(state); // save result
 831 
 832   // BasicObjectLock will be first in list, since this is a
 833   // synchronized method. However, need to check that the object has
 834   // not been unlocked by an explicit monitorexit bytecode.
 835   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
 836                         wordSize - (int) sizeof(BasicObjectLock));
 837   // We use c_rarg1/rdx so that if we go slow path it will be the correct
 838   // register for unlock_object to pass to VM directly

 937   // the stack, will call InterpreterRuntime::at_unwind.
 938   Label slow_path;
 939   Label fast_path;
 940   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
 941   jmp(fast_path);
 942   bind(slow_path);
 943   push(state);
 944   set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
 945   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread);
 946   reset_last_Java_frame(true);
 947   pop(state);
 948   bind(fast_path);
 949 
 950   // JVMTI support. Make sure the safepoint poll test is issued prior.
 951   if (notify_jvmdi) {
 952     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 953   } else {
 954     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 955   }
 956 




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

1150     const int mark_offset = lock_offset +
1151                             BasicLock::displaced_header_offset_in_bytes();
1152 
1153     // Load object pointer into obj_reg
1154     movptr(obj_reg, Address(lock_reg, obj_offset));
1155 
1156     if (LockingMode == LM_LIGHTWEIGHT) {
1157       lightweight_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case);
1158     } else if (LockingMode == LM_LEGACY) {
1159       if (DiagnoseSyncOnValueBasedClasses != 0) {
1160         load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1161         testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class);
1162         jcc(Assembler::notZero, slow_case);
1163       }
1164 
1165       // Load immediate 1 into swap_reg %rax
1166       movl(swap_reg, 1);
1167 
1168       // Load (object->mark() | 1) into swap_reg %rax
1169       orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1170       if (EnableValhalla) {
1171         // Mask inline_type bit such that we go to the slow path if object is an inline type
1172         andptr(swap_reg, ~((int) markWord::inline_type_bit_in_place));
1173       }
1174 
1175       // Save (object->mark() | 1) into BasicLock's displaced header
1176       movptr(Address(lock_reg, mark_offset), swap_reg);
1177 
1178       assert(lock_offset == 0,
1179              "displaced header must be first word in BasicObjectLock");
1180 
1181       lock();
1182       cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1183       jcc(Assembler::zero, count_locking);
1184 
1185       const int zero_bits = 7;
1186 
1187       // Fast check for recursive lock.
1188       //
1189       // Can apply the optimization only if this is a stack lock
1190       // allocated in this thread. For efficiency, we can focus on
1191       // recently allocated stack locks (instead of reading the stack
1192       // base and checking whether 'mark' points inside the current
1193       // thread stack):

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

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

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

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


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

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

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