< 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   Label done, slow_case;
1028 
1029   const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1030   const Register tmp_reg = rbx;
1031   const Register obj_reg = c_rarg3; // Will contain the oop
1032 
1033   // Load object pointer into obj_reg
1034   movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1035 

1248 }
1249 
1250 
1251 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1252   if (ProfileInterpreter) {
1253     Label profile_continue;
1254 
1255     // If no method data exists, go to profile_continue.
1256     test_method_data_pointer(mdp, profile_continue);
1257 
1258     // We are taking a branch.  Increment the taken count.
1259     increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1260 
1261     // The method data pointer needs to be updated to reflect the new target.
1262     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1263     bind(profile_continue);
1264   }
1265 }
1266 
1267 
1268 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1269   if (ProfileInterpreter) {
1270     Label profile_continue;
1271 
1272     // If no method data exists, go to profile_continue.
1273     test_method_data_pointer(mdp, profile_continue);
1274 
1275     // We are not taking a branch.  Increment the not taken count.
1276     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1277 
1278     // The method data pointer needs to be updated to correspond to
1279     // the next bytecode
1280     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1281     bind(profile_continue);
1282   }
1283 }
1284 
1285 void InterpreterMacroAssembler::profile_call(Register mdp) {
1286   if (ProfileInterpreter) {
1287     Label profile_continue;
1288 
1289     // If no method data exists, go to profile_continue.
1290     test_method_data_pointer(mdp, profile_continue);
1291 
1292     // We are making a call.  Increment the count.
1293     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1294 
1295     // The method data pointer needs to be updated to reflect the new target.
1296     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1297     bind(profile_continue);
1298   }
1299 }
1300 

1323                                                      Register reg2,
1324                                                      bool receiver_can_be_null) {
1325   if (ProfileInterpreter) {
1326     Label profile_continue;
1327 
1328     // If no method data exists, go to profile_continue.
1329     test_method_data_pointer(mdp, profile_continue);
1330 
1331     Label skip_receiver_profile;
1332     if (receiver_can_be_null) {
1333       Label not_null;
1334       testptr(receiver, receiver);
1335       jccb(Assembler::notZero, not_null);
1336       // We are making a call.  Increment the count for null receiver.
1337       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1338       jmp(skip_receiver_profile);
1339       bind(not_null);
1340     }
1341 
1342     // Record the receiver type.
1343     record_klass_in_profile(receiver, mdp, reg2, true);
1344     bind(skip_receiver_profile);
1345 
1346     // The method data pointer needs to be updated to reflect the new target.
1347     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1348     bind(profile_continue);
1349   }
1350 }
1351 
1352 // This routine creates a state machine for updating the multi-row
1353 // type profile at a virtual call site (or other type-sensitive bytecode).
1354 // The machine visits each row (of receiver/count) until the receiver type
1355 // is found, or until it runs out of rows.  At the same time, it remembers
1356 // the location of the first empty row.  (An empty row records null for its
1357 // receiver, and can be allocated for a newly-observed receiver type.)
1358 // Because there are two degrees of freedom in the state, a simple linear
1359 // search will not work; it must be a decision tree.  Hence this helper
1360 // function is recursive, to generate the required tree structured code.
1361 // It's the interpreter, so we are trading off code space for speed.
1362 // See below for example code.
1363 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1364                                         Register receiver, Register mdp,
1365                                         Register reg2, int start_row,
1366                                         Label& done, bool is_virtual_call) {
1367   if (TypeProfileWidth == 0) {
1368     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1369   } else {
1370     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1371                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1372   }
1373 }
1374 
1375 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1376                                                               Label& done, int total_rows,
1377                                                               OffsetFunction item_offset_fn,
1378                                                               OffsetFunction item_count_offset_fn) {
1379   int last_row = total_rows - 1;
1380   assert(start_row <= last_row, "must be work left to do");
1381   // Test this row for both the item and for null.
1382   // Take any of three different outcomes:
1383   //   1. found item => increment count and goto done
1384   //   2. found null => keep looking for case 1, maybe allocate this cell
1385   //   3. found something else => keep looking for cases 1 and 2
1386   // Case 3 is handled by a recursive call.

1450 //     // inner copy of decision tree, rooted at row[1]
1451 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1452 //     if (row[1].rec != nullptr) {
1453 //       // degenerate decision tree, rooted at row[2]
1454 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1455 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1456 //       row[2].init(rec); goto done;
1457 //     } else {
1458 //       // remember row[1] is empty
1459 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1460 //       row[1].init(rec); goto done;
1461 //     }
1462 //   } else {
1463 //     // remember row[0] is empty
1464 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1465 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1466 //     row[0].init(rec); goto done;
1467 //   }
1468 //   done:
1469 
1470 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1471                                                         Register mdp, Register reg2,
1472                                                         bool is_virtual_call) {
1473   assert(ProfileInterpreter, "must be profiling");
1474   Label done;
1475 
1476   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1477 
1478   bind (done);
1479 }
1480 
1481 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1482                                             Register mdp) {
1483   if (ProfileInterpreter) {
1484     Label profile_continue;
1485     uint row;
1486 
1487     // If no method data exists, go to profile_continue.
1488     test_method_data_pointer(mdp, profile_continue);
1489 
1490     // Update the total ret count.
1491     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1492 
1493     for (row = 0; row < RetData::row_limit(); row++) {
1494       Label next_test;
1495 
1496       // See if return_bci is equal to bci[n]:

1533     update_mdp_by_constant(mdp, mdp_delta);
1534 
1535     bind(profile_continue);
1536   }
1537 }
1538 
1539 
1540 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1541   if (ProfileInterpreter) {
1542     Label profile_continue;
1543 
1544     // If no method data exists, go to profile_continue.
1545     test_method_data_pointer(mdp, profile_continue);
1546 
1547     // The method data pointer needs to be updated.
1548     int mdp_delta = in_bytes(BitData::bit_data_size());
1549     if (TypeProfileCasts) {
1550       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1551 
1552       // Record the object type.
1553       record_klass_in_profile(klass, mdp, reg2, false);
1554     }
1555     update_mdp_by_constant(mdp, mdp_delta);
1556 
1557     bind(profile_continue);
1558   }
1559 }
1560 
1561 
1562 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1563   if (ProfileInterpreter) {
1564     Label profile_continue;
1565 
1566     // If no method data exists, go to profile_continue.
1567     test_method_data_pointer(mdp, profile_continue);
1568 
1569     // Update the default case count
1570     increment_mdp_data_at(mdp,
1571                           in_bytes(MultiBranchData::default_count_offset()));
1572 
1573     // The method data pointer needs to be updated.

1593     // case_array_offset_in_bytes()
1594     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1595     imulptr(index, reg2); // XXX l ?
1596     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1597 
1598     // Update the case count
1599     increment_mdp_data_at(mdp,
1600                           index,
1601                           in_bytes(MultiBranchData::relative_count_offset()));
1602 
1603     // The method data pointer needs to be updated.
1604     update_mdp_by_offset(mdp,
1605                          index,
1606                          in_bytes(MultiBranchData::
1607                                   relative_displacement_offset()));
1608 
1609     bind(profile_continue);
1610   }
1611 }
1612 


















































































































1613 
1614 
1615 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1616   if (state == atos) {
1617     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1618   }
1619 }
1620 
1621 
1622 // Jump if ((*counter_addr += increment) & mask) == 0
1623 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1624                                                         Register scratch, Label* where) {
1625   // This update is actually not atomic and can lose a number of updates
1626   // under heavy contention, but the alternative of using the (contended)
1627   // atomic update here penalizes profiling paths too much.
1628   movl(scratch, counter_addr);
1629   incrementl(scratch, InvocationCounter::count_increment);
1630   movl(counter_addr, scratch);
1631   andl(scratch, mask);
1632   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, slow_path, 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   // If the field is nullable, jump to slow path
1090   load_unsigned_byte(tmp1, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
1091   testl(tmp1, 1 << ResolvedFieldEntry::is_null_free_inline_type_shift);
1092   jcc(Assembler::equal, slow_path);
1093 
1094   // Grap the inline field klass
1095   const Register field_klass = tmp1;
1096   load_unsigned_short(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1097 
1098   movptr(tmp1, Address(entry, ResolvedFieldEntry::field_holder_offset()));
1099   get_inline_type_field_klass(tmp1, tmp2, field_klass);
1100 
1101   // allocate buffer
1102   push(obj);  // push object being read from
1103   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1104 
1105   // Have an oop instance buffer, copy into it
1106   load_unsigned_short(r9, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1107   movptr(r8, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1108   inline_layout_info(r8, r9, r8); // holder, index, info => InlineLayoutInfo into r8
1109 
1110   payload_addr(obj, dst_temp, field_klass);
1111   pop(alloc_temp);             // restore object being read from
1112   load_sized_value(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
1113   lea(tmp2, Address(alloc_temp, tmp2));
1114   // call_VM_leaf, clobbers a few regs, save restore new obj
1115   push(obj);
1116   flat_field_copy(IS_DEST_UNINITIALIZED, tmp2, dst_temp, r8);
1117   pop(obj);
1118   jmp(done);
1119 
1120   bind(alloc_failed);
1121   pop(obj);
1122   bind(slow_path);
1123   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1124           obj, entry);
1125   get_vm_result_oop(obj);
1126   bind(done);
1127 }
1128 
1129 void InterpreterMacroAssembler::write_flat_field(Register entry, Register tmp1, Register tmp2,
1130                                                  Register obj, Register off, Register value) {
1131   assert_different_registers(entry, tmp1, tmp2, obj, off, value);
1132 
1133   Label slow_path, done;
1134 
1135   load_unsigned_byte(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
1136   test_field_is_not_null_free_inline_type(tmp2, tmp1, slow_path);
1137 
1138   null_check(value); // FIXME JDK-8341120
1139 
1140   lea(obj, Address(obj, off, Address::times_1));
1141 
1142   load_klass(tmp2, value, tmp1);
1143   payload_addr(value, value, tmp2);
1144 
1145   Register idx = tmp1;
1146   load_unsigned_short(idx, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1147   movptr(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1148 
1149   Register layout_info = off;
1150   inline_layout_info(tmp2, idx, layout_info);
1151 
1152   flat_field_copy(IN_HEAP, value, obj, layout_info);
1153   jmp(done);
1154 
1155   bind(slow_path);
1156   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_flat_field), obj, value, entry);
1157 
1158   bind(done);
1159 }
1160 
1161 // Lock object
1162 //
1163 // Args:
1164 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1165 //
1166 // Kills:
1167 //      rax, rbx
1168 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1169   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1170 
1171   Label done, slow_case;
1172 
1173   const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1174   const Register tmp_reg = rbx;
1175   const Register obj_reg = c_rarg3; // Will contain the oop
1176 
1177   // Load object pointer into obj_reg
1178   movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1179 

1392 }
1393 
1394 
1395 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1396   if (ProfileInterpreter) {
1397     Label profile_continue;
1398 
1399     // If no method data exists, go to profile_continue.
1400     test_method_data_pointer(mdp, profile_continue);
1401 
1402     // We are taking a branch.  Increment the taken count.
1403     increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1404 
1405     // The method data pointer needs to be updated to reflect the new target.
1406     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1407     bind(profile_continue);
1408   }
1409 }
1410 
1411 
1412 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1413   if (ProfileInterpreter) {
1414     Label profile_continue;
1415 
1416     // If no method data exists, go to profile_continue.
1417     test_method_data_pointer(mdp, profile_continue);
1418 
1419     // We are not taking a branch.  Increment the not taken count.
1420     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1421 
1422     // The method data pointer needs to be updated to correspond to
1423     // the next bytecode
1424     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1425     bind(profile_continue);
1426   }
1427 }
1428 
1429 void InterpreterMacroAssembler::profile_call(Register mdp) {
1430   if (ProfileInterpreter) {
1431     Label profile_continue;
1432 
1433     // If no method data exists, go to profile_continue.
1434     test_method_data_pointer(mdp, profile_continue);
1435 
1436     // We are making a call.  Increment the count.
1437     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1438 
1439     // The method data pointer needs to be updated to reflect the new target.
1440     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1441     bind(profile_continue);
1442   }
1443 }
1444 

1467                                                      Register reg2,
1468                                                      bool receiver_can_be_null) {
1469   if (ProfileInterpreter) {
1470     Label profile_continue;
1471 
1472     // If no method data exists, go to profile_continue.
1473     test_method_data_pointer(mdp, profile_continue);
1474 
1475     Label skip_receiver_profile;
1476     if (receiver_can_be_null) {
1477       Label not_null;
1478       testptr(receiver, receiver);
1479       jccb(Assembler::notZero, not_null);
1480       // We are making a call.  Increment the count for null receiver.
1481       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1482       jmp(skip_receiver_profile);
1483       bind(not_null);
1484     }
1485 
1486     // Record the receiver type.
1487     record_klass_in_profile(receiver, mdp, reg2);
1488     bind(skip_receiver_profile);
1489 
1490     // The method data pointer needs to be updated to reflect the new target.
1491     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1492     bind(profile_continue);
1493   }
1494 }
1495 
1496 // This routine creates a state machine for updating the multi-row
1497 // type profile at a virtual call site (or other type-sensitive bytecode).
1498 // The machine visits each row (of receiver/count) until the receiver type
1499 // is found, or until it runs out of rows.  At the same time, it remembers
1500 // the location of the first empty row.  (An empty row records null for its
1501 // receiver, and can be allocated for a newly-observed receiver type.)
1502 // Because there are two degrees of freedom in the state, a simple linear
1503 // search will not work; it must be a decision tree.  Hence this helper
1504 // function is recursive, to generate the required tree structured code.
1505 // It's the interpreter, so we are trading off code space for speed.
1506 // See below for example code.
1507 void InterpreterMacroAssembler::record_klass_in_profile_helper(Register receiver, Register mdp,
1508                                                                Register reg2, int start_row,
1509                                                                Label& done) {

1510   if (TypeProfileWidth == 0) {
1511     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1512   } else {
1513     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1514                                   &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1515   }
1516 }
1517 
1518 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row,
1519                                                               Label& done, int total_rows,
1520                                                               OffsetFunction item_offset_fn,
1521                                                               OffsetFunction item_count_offset_fn) {
1522   int last_row = total_rows - 1;
1523   assert(start_row <= last_row, "must be work left to do");
1524   // Test this row for both the item and for null.
1525   // Take any of three different outcomes:
1526   //   1. found item => increment count and goto done
1527   //   2. found null => keep looking for case 1, maybe allocate this cell
1528   //   3. found something else => keep looking for cases 1 and 2
1529   // Case 3 is handled by a recursive call.

1593 //     // inner copy of decision tree, rooted at row[1]
1594 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1595 //     if (row[1].rec != nullptr) {
1596 //       // degenerate decision tree, rooted at row[2]
1597 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1598 //       if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1599 //       row[2].init(rec); goto done;
1600 //     } else {
1601 //       // remember row[1] is empty
1602 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1603 //       row[1].init(rec); goto done;
1604 //     }
1605 //   } else {
1606 //     // remember row[0] is empty
1607 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1608 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1609 //     row[0].init(rec); goto done;
1610 //   }
1611 //   done:
1612 
1613 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, Register mdp, Register reg2) {


1614   assert(ProfileInterpreter, "must be profiling");
1615   Label done;
1616 
1617   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1618 
1619   bind (done);
1620 }
1621 
1622 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1623                                             Register mdp) {
1624   if (ProfileInterpreter) {
1625     Label profile_continue;
1626     uint row;
1627 
1628     // If no method data exists, go to profile_continue.
1629     test_method_data_pointer(mdp, profile_continue);
1630 
1631     // Update the total ret count.
1632     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1633 
1634     for (row = 0; row < RetData::row_limit(); row++) {
1635       Label next_test;
1636 
1637       // See if return_bci is equal to bci[n]:

1674     update_mdp_by_constant(mdp, mdp_delta);
1675 
1676     bind(profile_continue);
1677   }
1678 }
1679 
1680 
1681 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1682   if (ProfileInterpreter) {
1683     Label profile_continue;
1684 
1685     // If no method data exists, go to profile_continue.
1686     test_method_data_pointer(mdp, profile_continue);
1687 
1688     // The method data pointer needs to be updated.
1689     int mdp_delta = in_bytes(BitData::bit_data_size());
1690     if (TypeProfileCasts) {
1691       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1692 
1693       // Record the object type.
1694       record_klass_in_profile(klass, mdp, reg2);
1695     }
1696     update_mdp_by_constant(mdp, mdp_delta);
1697 
1698     bind(profile_continue);
1699   }
1700 }
1701 
1702 
1703 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1704   if (ProfileInterpreter) {
1705     Label profile_continue;
1706 
1707     // If no method data exists, go to profile_continue.
1708     test_method_data_pointer(mdp, profile_continue);
1709 
1710     // Update the default case count
1711     increment_mdp_data_at(mdp,
1712                           in_bytes(MultiBranchData::default_count_offset()));
1713 
1714     // The method data pointer needs to be updated.

1734     // case_array_offset_in_bytes()
1735     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1736     imulptr(index, reg2); // XXX l ?
1737     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1738 
1739     // Update the case count
1740     increment_mdp_data_at(mdp,
1741                           index,
1742                           in_bytes(MultiBranchData::relative_count_offset()));
1743 
1744     // The method data pointer needs to be updated.
1745     update_mdp_by_offset(mdp,
1746                          index,
1747                          in_bytes(MultiBranchData::
1748                                   relative_displacement_offset()));
1749 
1750     bind(profile_continue);
1751   }
1752 }
1753 
1754 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
1755                                                                               Register array,
1756                                                                               Register tmp) {
1757   if (ProfileInterpreter) {
1758     Label profile_continue;
1759 
1760     // If no method data exists, go to profile_continue.
1761     test_method_data_pointer(mdp, profile_continue);
1762 
1763     mov(tmp, array);
1764     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
1765 
1766     Label not_flat;
1767     test_non_flat_array_oop(array, tmp, not_flat);
1768 
1769     set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
1770 
1771     bind(not_flat);
1772 
1773     Label not_null_free;
1774     test_non_null_free_array_oop(array, tmp, not_null_free);
1775 
1776     set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
1777 
1778     bind(not_null_free);
1779 
1780     bind(profile_continue);
1781   }
1782 }
1783 
1784 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
1785                                                                            Register array,
1786                                                                            Register tmp);
1787 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
1788                                                                             Register array,
1789                                                                             Register tmp);
1790 
1791 
1792 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
1793   if (ProfileInterpreter) {
1794     Label profile_continue;
1795 
1796     // If no method data exists, go to profile_continue.
1797     test_method_data_pointer(mdp, profile_continue);
1798 
1799     Label done, update;
1800     testptr(element, element);
1801     jccb(Assembler::notZero, update);
1802     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1803     jmp(done);
1804 
1805     bind(update);
1806     load_klass(tmp, element, rscratch1);
1807 
1808     // Record the object type.
1809     record_klass_in_profile(tmp, mdp, tmp2);
1810 
1811     bind(done);
1812 
1813     // The method data pointer needs to be updated.
1814     update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
1815 
1816     bind(profile_continue);
1817   }
1818 }
1819 
1820 void InterpreterMacroAssembler::profile_element_type(Register mdp,
1821                                                      Register element,
1822                                                      Register tmp) {
1823   if (ProfileInterpreter) {
1824     Label profile_continue;
1825 
1826     // If no method data exists, go to profile_continue.
1827     test_method_data_pointer(mdp, profile_continue);
1828 
1829     mov(tmp, element);
1830     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
1831 
1832     // The method data pointer needs to be updated.
1833     update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
1834 
1835     bind(profile_continue);
1836   }
1837 }
1838 
1839 void InterpreterMacroAssembler::profile_acmp(Register mdp,
1840                                              Register left,
1841                                              Register right,
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, left);
1850     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
1851 
1852     Label left_not_inline_type;
1853     test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
1854     set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
1855     bind(left_not_inline_type);
1856 
1857     mov(tmp, right);
1858     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
1859 
1860     Label right_not_inline_type;
1861     test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
1862     set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
1863     bind(right_not_inline_type);
1864 
1865     bind(profile_continue);
1866   }
1867 }
1868 
1869 
1870 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1871   if (state == atos) {
1872     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1873   }
1874 }
1875 
1876 
1877 // Jump if ((*counter_addr += increment) & mask) == 0
1878 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1879                                                         Register scratch, Label* where) {
1880   // This update is actually not atomic and can lose a number of updates
1881   // under heavy contention, but the alternative of using the (contended)
1882   // atomic update here penalizes profiling paths too much.
1883   movl(scratch, counter_addr);
1884   incrementl(scratch, InvocationCounter::count_increment);
1885   movl(counter_addr, scratch);
1886   andl(scratch, mask);
1887   if (where != nullptr) {
< prev index next >