1 /*
2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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) {
56 Label update, next, none;
57
58 assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index());
59
60 interp_verify_oop(obj, atos);
61
62 testptr(obj, obj);
63 jccb(Assembler::notZero, update);
64 testptr(mdo_addr, TypeEntries::null_seen);
65 jccb(Assembler::notZero, next); // null already seen. Nothing to do anymore.
66 // atomic update to prevent overwriting Klass* with 0
67 lock();
68 orptr(mdo_addr, TypeEntries::null_seen);
69 jmpb(next);
70
71 bind(update);
72 load_klass(obj, obj, rscratch1);
73 mov(rscratch1, obj);
74
75 xorptr(obj, mdo_addr);
76 testptr(obj, TypeEntries::type_klass_mask);
77 jccb(Assembler::zero, next); // klass seen before, nothing to
78 // do. The unknown bit may have been
79 // set already but no need to check.
80
81 testptr(obj, TypeEntries::type_unknown);
82 jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
83
84 cmpptr(mdo_addr, 0);
85 jccb(Assembler::equal, none);
86 cmpptr(mdo_addr, TypeEntries::null_seen);
87 jccb(Assembler::equal, none);
88
89 // There is a chance that the checks above (re-reading profiling
90 // data from memory) fail if another thread has just set the
91 // profiling to this obj's klass
92 mov(obj, rscratch1);
93 xorptr(obj, mdo_addr);
94 testptr(obj, TypeEntries::type_klass_mask);
95 jccb(Assembler::zero, next);
96
97 // different than before. Cannot keep accurate profile.
98 orptr(mdo_addr, TypeEntries::type_unknown);
99 jmpb(next);
100
101 bind(none);
102 // first time here. Set profile type.
103 movptr(mdo_addr, obj);
104 #ifdef ASSERT
105 andptr(obj, TypeEntries::type_klass_mask);
106 verify_klass_ptr(obj);
107 #endif
108
109 bind(next);
110 }
111
112 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
113 if (!ProfileInterpreter) {
114 return;
115 }
116
117 if (MethodData::profile_arguments() || MethodData::profile_return()) {
118 Label profile_continue;
119
120 test_method_data_pointer(mdp, profile_continue);
121
122 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
123
124 cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
125 jcc(Assembler::notEqual, profile_continue);
126
127 if (MethodData::profile_arguments()) {
128 Label done;
129 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
130 addptr(mdp, off_to_args);
131
132 for (int i = 0; i < TypeProfileArgsLimit; i++) {
133 if (i > 0 || MethodData::profile_return()) {
134 // If return value type is profiled we may have no argument to profile
135 movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
136 subl(tmp, i*TypeStackSlotEntries::per_arg_count());
137 cmpl(tmp, TypeStackSlotEntries::per_arg_count());
138 jcc(Assembler::less, done);
139 }
140 movptr(tmp, Address(callee, Method::const_offset()));
141 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
142 // stack offset o (zero based) from the start of the argument
143 // list, for n arguments translates into offset n - o - 1 from
144 // the end of the argument list
145 subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
146 subl(tmp, 1);
147 Address arg_addr = argument_address(tmp);
148 movptr(tmp, arg_addr);
149
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()) {
191 Label profile_continue;
192
193 test_method_data_pointer(mdp, profile_continue);
194
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
236 // and move the pointer to the slot for the last
237 // parameters. Collect profiling from last parameter down.
238 // mdo start + parameters offset + array length - 1
239 addptr(mdp, tmp1);
240 movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
241 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
242
243 Label loop;
244 bind(loop);
245
246 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
247 int type_base = in_bytes(ParametersTypeData::type_offset(0));
248 Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
249 Address arg_off(mdp, tmp1, per_arg_scale, off_base);
250 Address arg_type(mdp, tmp1, per_arg_scale, type_base);
251
252 // load offset on the stack from the slot for this parameter
253 movptr(tmp2, arg_off);
254 negptr(tmp2);
255 // read the parameter from the local area
256 movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
257
258 // profile the parameter
259 profile_obj_type(tmp2, arg_type);
260
261 // go to next parameter
262 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
263 jcc(Assembler::positive, loop);
264
265 bind(profile_continue);
266 }
267 }
268
269 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
270 int number_of_arguments) {
271 // interpreter specific
272 //
273 // Note: No need to save/restore bcp & locals registers
274 // since these are callee saved registers and no blocking/
275 // GC can happen in leaf calls.
276 // Further Note: DO NOT save/restore bcp/locals. If a caller has
277 // already saved them so that it can use rsi/rdi as temporaries
278 // then a save/restore here will DESTROY the copy the caller
279 // saved! There used to be a save_bcp() that only happened in
280 // the ASSERT path (no restore_bcp). Which caused bizarre failures
281 // when jvm built with ASSERTs.
282 #ifdef ASSERT
283 {
284 Label L;
285 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
286 jcc(Assembler::equal, L);
287 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
288 " last_sp != null");
289 bind(L);
290 }
291 #endif
292 // super call
293 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
294 // interpreter specific
295 // LP64: Used to ASSERT that r13/r14 were equal to frame's bcp/locals
296 // but since they may not have been saved (and we don't want to
297 // save them here (see note above) the assert is invalid.
298 }
299
300 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
301 Register last_java_sp,
302 address entry_point,
303 int number_of_arguments,
304 bool check_exceptions) {
305 // interpreter specific
306 //
307 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
308 // really make a difference for these runtime calls, since they are
309 // slow anyway. Btw., bcp must be saved/restored since it may change
310 // due to GC.
311 save_bcp();
312 #ifdef ASSERT
313 {
314 Label L;
315 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
316 jcc(Assembler::equal, L);
317 stop("InterpreterMacroAssembler::call_VM_base:"
318 " last_sp isn't null");
319 bind(L);
320 }
321 #endif /* ASSERT */
322 // super call
323 MacroAssembler::call_VM_base(oop_result, last_java_sp,
324 entry_point, number_of_arguments,
325 check_exceptions);
326 // interpreter specific
327 restore_bcp();
328 restore_locals();
329 }
330
331 void InterpreterMacroAssembler::call_VM_preemptable_helper(Register oop_result,
332 address entry_point,
333 int number_of_arguments,
334 bool check_exceptions) {
335 assert(InterpreterRuntime::is_preemptable_call(entry_point), "VM call not preemptable, should use call_VM()");
336 Label resume_pc, not_preempted;
337
338 #ifdef ASSERT
339 {
340 Label L1, L2;
341 cmpptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD);
342 jcc(Assembler::equal, L1);
343 stop("call_VM_preemptable_helper: should not have alternate return address set");
344 bind(L1);
345 // We check this counter in patch_return_pc_with_preempt_stub() during freeze.
346 incrementl(Address(r15_thread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
347 cmpl(Address(r15_thread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()), 0);
348 jcc(Assembler::greater, L2);
349 stop("call_VM_preemptable_helper: should be > 0");
350 bind(L2);
351 }
352 #endif /* ASSERT */
353
354 // Force freeze slow path.
355 push_cont_fastpath();
356
357 // Make VM call. In case of preemption set last_pc to the one we want to resume to.
358 lea(rscratch1, resume_pc);
359 push(rscratch1);
360 lea(rax, Address(rsp, wordSize));
361 call_VM_base(noreg, rax, entry_point, number_of_arguments, false);
362 pop(rscratch1);
363
364 pop_cont_fastpath();
365
366 #ifdef ASSERT
367 {
368 Label L;
369 decrementl(Address(r15_thread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
370 cmpl(Address(r15_thread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()), 0);
371 jcc(Assembler::greaterEqual, L);
372 stop("call_VM_preemptable_helper: should be >= 0");
373 bind(L);
374 }
375 #endif /* ASSERT */
376
377 // Check if preempted.
378 movptr(rscratch1, Address(r15_thread, JavaThread::preempt_alternate_return_offset()));
379 cmpptr(rscratch1, NULL_WORD);
380 jccb(Assembler::zero, not_preempted);
381 movptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD);
382 jmp(rscratch1);
383
384 // In case of preemption, this is where we will resume once we finally acquire the monitor.
385 bind(resume_pc);
386 restore_after_resume(false /* is_native */);
387
388 bind(not_preempted);
389 if (check_exceptions) {
390 // check for pending exceptions
391 cmpptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD);
392 Label ok;
393 jcc(Assembler::equal, ok);
394 // Exception stub expects return pc to be at top of stack. We only need
395 // it to check Interpreter::contains(return_address) so anything will do.
396 lea(rscratch1, resume_pc);
397 push(rscratch1);
398 jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
399 bind(ok);
400 }
401
402 // get oop result if there is one and reset the value in the thread
403 if (oop_result->is_valid()) {
404 get_vm_result_oop(oop_result);
405 }
406 }
407
408 static void pass_arg1(MacroAssembler* masm, Register arg) {
409 if (c_rarg1 != arg ) {
410 masm->mov(c_rarg1, arg);
411 }
412 }
413
414 static void pass_arg2(MacroAssembler* masm, Register arg) {
415 if (c_rarg2 != arg ) {
416 masm->mov(c_rarg2, arg);
417 }
418 }
419
420 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
421 address entry_point,
422 Register arg_1,
423 bool check_exceptions) {
424 pass_arg1(this, arg_1);
425 call_VM_preemptable_helper(oop_result, entry_point, 1, check_exceptions);
426 }
427
428 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
429 address entry_point,
430 Register arg_1,
431 Register arg_2,
432 bool check_exceptions) {
433 LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
434 pass_arg2(this, arg_2);
435 pass_arg1(this, arg_1);
436 call_VM_preemptable_helper(oop_result, entry_point, 2, check_exceptions);
437 }
438
439 void InterpreterMacroAssembler::restore_after_resume(bool is_native) {
440 lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter()));
441 call(rscratch1);
442 if (is_native) {
443 // On resume we need to set up stack as expected.
444 push(dtos);
445 push(ltos);
446 }
447 }
448
449 void InterpreterMacroAssembler::check_and_handle_popframe() {
450 if (JvmtiExport::can_pop_frame()) {
451 Label L;
452 // Initiate popframe handling only if it is not already being
453 // processed. If the flag has the popframe_processing bit set, it
454 // means that this code is called *during* popframe handling - we
455 // don't want to reenter.
456 // This method is only called just after the call into the vm in
457 // call_VM_base, so the arg registers are available.
458 Register pop_cond = c_rarg0;
459 movl(pop_cond, Address(r15_thread, JavaThread::popframe_condition_offset()));
460 testl(pop_cond, JavaThread::popframe_pending_bit);
461 jcc(Assembler::zero, L);
462 testl(pop_cond, JavaThread::popframe_processing_bit);
463 jcc(Assembler::notZero, L);
464 // Call Interpreter::remove_activation_preserving_args_entry() to get the
465 // address of the same-named entrypoint in the generated interpreter code.
466 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
467 jmp(rax);
468 bind(L);
469 }
470 }
471
472 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
473 movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
474 const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
475 const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
476 const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
477
478 switch (state) {
479 case atos: movptr(rax, oop_addr);
480 movptr(oop_addr, NULL_WORD);
481 interp_verify_oop(rax, state); break;
482 case ltos: movptr(rax, val_addr); break;
483 case btos: // fall through
484 case ztos: // fall through
485 case ctos: // fall through
486 case stos: // fall through
487 case itos: movl(rax, val_addr); break;
488 case ftos: movflt(xmm0, val_addr); break;
489 case dtos: movdbl(xmm0, val_addr); break;
490 case vtos: /* nothing to do */ break;
491 default : ShouldNotReachHere();
492 }
493
494 // Clean up tos value in the thread object
495 movl(tos_addr, ilgl);
496 movptr(val_addr, NULL_WORD);
497 }
498
499
500 void InterpreterMacroAssembler::check_and_handle_earlyret() {
501 if (JvmtiExport::can_force_early_return()) {
502 Label L;
503 Register tmp = c_rarg0;
504 Register rthread = r15_thread;
505
506 movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
507 testptr(tmp, tmp);
508 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == nullptr) exit;
509
510 // Initiate earlyret handling only if it is not already being processed.
511 // If the flag has the earlyret_processing bit set, it means that this code
512 // is called *during* earlyret handling - we don't want to reenter.
513 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
514 cmpl(tmp, JvmtiThreadState::earlyret_pending);
515 jcc(Assembler::notEqual, L);
516
517 // Call Interpreter::remove_activation_early_entry() to get the address of the
518 // same-named entrypoint in the generated interpreter code.
519 movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
520 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
521 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), tmp);
522 jmp(rax);
523 bind(L);
524 }
525 }
526
527 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
528 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
529 load_unsigned_short(reg, Address(_bcp_register, bcp_offset));
530 bswapl(reg);
531 shrl(reg, 16);
532 }
533
534 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
535 int bcp_offset,
536 size_t index_size) {
537 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
538 if (index_size == sizeof(u2)) {
539 load_unsigned_short(index, Address(_bcp_register, bcp_offset));
540 } else if (index_size == sizeof(u4)) {
541 movl(index, Address(_bcp_register, bcp_offset));
542 } else if (index_size == sizeof(u1)) {
543 load_unsigned_byte(index, Address(_bcp_register, bcp_offset));
544 } else {
545 ShouldNotReachHere();
546 }
547 }
548
549 // Load object from cpool->resolved_references(index)
550 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result,
551 Register index,
552 Register tmp) {
553 assert_different_registers(result, index);
554
555 get_constant_pool(result);
556 // load pointer for resolved_references[] objArray
557 movptr(result, Address(result, ConstantPool::cache_offset()));
558 movptr(result, Address(result, ConstantPoolCache::resolved_references_offset()));
559 resolve_oop_handle(result, tmp);
560 load_heap_oop(result, Address(result, index,
561 UseCompressedOops ? Address::times_4 : Address::times_ptr,
562 arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp);
563 }
564
565 // load cpool->resolved_klass_at(index)
566 void InterpreterMacroAssembler::load_resolved_klass_at_index(Register klass,
567 Register cpool,
568 Register index) {
569 assert_different_registers(cpool, index);
570
571 movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
572 Register resolved_klasses = cpool;
573 movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset()));
574 movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
575 }
576
577 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
578 // subtype of super_klass.
579 //
580 // Args:
581 // rax: superklass
582 // Rsub_klass: subklass
583 //
584 // Kills:
585 // rcx
586 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
587 Label& ok_is_subtype,
588 bool profile) {
589 assert(Rsub_klass != rax, "rax holds superklass");
590 assert(Rsub_klass != r14, "r14 holds locals");
591 assert(Rsub_klass != r13, "r13 holds bcp");
592 assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
593
594 // Profile the not-null value's klass.
595 if (profile) {
596 profile_typecheck(rcx, Rsub_klass); // blows rcx
597 }
598 // Do the check.
599 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
600 }
601
602
603 // Java Expression Stack
604
605 void InterpreterMacroAssembler::pop_ptr(Register r) {
606 pop(r);
607 }
608
609 void InterpreterMacroAssembler::push_ptr(Register r) {
610 push(r);
611 }
612
613 void InterpreterMacroAssembler::push_i(Register r) {
614 push(r);
615 }
616
617 void InterpreterMacroAssembler::push_i_or_ptr(Register r) {
618 push(r);
619 }
620
621 void InterpreterMacroAssembler::push_f(XMMRegister r) {
622 subptr(rsp, wordSize);
623 movflt(Address(rsp, 0), r);
624 }
625
626 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
627 movflt(r, Address(rsp, 0));
628 addptr(rsp, wordSize);
629 }
630
631 void InterpreterMacroAssembler::push_d(XMMRegister r) {
632 subptr(rsp, 2 * wordSize);
633 movdbl(Address(rsp, 0), r);
634 }
635
636 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
637 movdbl(r, Address(rsp, 0));
638 addptr(rsp, 2 * Interpreter::stackElementSize);
639 }
640
641 void InterpreterMacroAssembler::pop_i(Register r) {
642 // XXX can't use pop currently, upper half non clean
643 movl(r, Address(rsp, 0));
644 addptr(rsp, wordSize);
645 }
646
647 void InterpreterMacroAssembler::pop_l(Register r) {
648 movq(r, Address(rsp, 0));
649 addptr(rsp, 2 * Interpreter::stackElementSize);
650 }
651
652 void InterpreterMacroAssembler::push_l(Register r) {
653 subptr(rsp, 2 * wordSize);
654 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(0)), r );
655 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(1)), NULL_WORD );
656 }
657
658 void InterpreterMacroAssembler::pop(TosState state) {
659 switch (state) {
660 case atos: pop_ptr(); break;
661 case btos:
662 case ztos:
663 case ctos:
664 case stos:
665 case itos: pop_i(); break;
666 case ltos: pop_l(); break;
667 case ftos: pop_f(xmm0); break;
668 case dtos: pop_d(xmm0); break;
669 case vtos: /* nothing to do */ break;
670 default: ShouldNotReachHere();
671 }
672 interp_verify_oop(rax, state);
673 }
674
675 void InterpreterMacroAssembler::push(TosState state) {
676 interp_verify_oop(rax, state);
677 switch (state) {
678 case atos: push_ptr(); break;
679 case btos:
680 case ztos:
681 case ctos:
682 case stos:
683 case itos: push_i(); break;
684 case ltos: push_l(); break;
685 case ftos: push_f(xmm0); break;
686 case dtos: push_d(xmm0); break;
687 case vtos: /* nothing to do */ break;
688 default : ShouldNotReachHere();
689 }
690 }
691
692 // Helpers for swap and dup
693 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
694 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
695 }
696
697 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
698 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
699 }
700
701
702 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
703 // set sender sp
704 lea(_bcp_register, Address(rsp, wordSize));
705 // record last_sp
706 mov(rcx, _bcp_register);
707 subptr(rcx, rbp);
708 sarptr(rcx, LogBytesPerWord);
709 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rcx);
710 }
711
712
713 // Jump to from_interpreted entry of a call unless single stepping is possible
714 // in this thread in which case we must call the i2i entry
715 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
716 prepare_to_jump_from_interpreted();
717
718 if (JvmtiExport::can_post_interpreter_events()) {
719 Label run_compiled_code;
720 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
721 // compiled code in threads for which the event is enabled. Check here for
722 // interp_only_mode if these events CAN be enabled.
723 // interp_only is an int, on little endian it is sufficient to test the byte only
724 // Is a cmpl faster?
725 cmpb(Address(r15_thread, JavaThread::interp_only_mode_offset()), 0);
726 jccb(Assembler::zero, run_compiled_code);
727 jmp(Address(method, Method::interpreter_entry_offset()));
728 bind(run_compiled_code);
729 }
730
731 jmp(Address(method, Method::from_interpreted_offset()));
732 }
733
734 // The following two routines provide a hook so that an implementation
735 // can schedule the dispatch in two parts. x86 does not do this.
736 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
737 // Nothing x86 specific to be done here
738 }
739
740 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
741 dispatch_next(state, step);
742 }
743
744 void InterpreterMacroAssembler::dispatch_base(TosState state,
745 address* table,
746 bool verifyoop,
747 bool generate_poll) {
748 if (VerifyActivationFrameSize) {
749 Label L;
750 mov(rcx, rbp);
751 subptr(rcx, rsp);
752 int32_t min_frame_size =
753 (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
754 wordSize;
755 cmpptr(rcx, min_frame_size);
756 jcc(Assembler::greaterEqual, L);
757 stop("broken stack frame");
758 bind(L);
759 }
760 if (verifyoop) {
761 interp_verify_oop(rax, state);
762 }
763
764 address* const safepoint_table = Interpreter::safept_table(state);
765 Label no_safepoint, dispatch;
766 if (table != safepoint_table && generate_poll) {
767 NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
768 testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
769
770 jccb(Assembler::zero, no_safepoint);
771 lea(rscratch1, ExternalAddress((address)safepoint_table));
772 jmpb(dispatch);
773 }
774
775 bind(no_safepoint);
776 lea(rscratch1, ExternalAddress((address)table));
777 bind(dispatch);
778 jmp(Address(rscratch1, rbx, Address::times_8));
779 }
780
781 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {
782 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
783 }
784
785 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
786 dispatch_base(state, Interpreter::normal_table(state));
787 }
788
789 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
790 dispatch_base(state, Interpreter::normal_table(state), false);
791 }
792
793
794 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) {
795 // load next bytecode (load before advancing _bcp_register to prevent AGI)
796 load_unsigned_byte(rbx, Address(_bcp_register, step));
797 // advance _bcp_register
798 increment(_bcp_register, step);
799 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
800 }
801
802 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
803 // load current bytecode
804 load_unsigned_byte(rbx, Address(_bcp_register, 0));
805 dispatch_base(state, table);
806 }
807
808 void InterpreterMacroAssembler::narrow(Register result) {
809
810 // Get method->_constMethod->_result_type
811 movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
812 movptr(rcx, Address(rcx, Method::const_offset()));
813 load_unsigned_byte(rcx, Address(rcx, ConstMethod::result_type_offset()));
814
815 Label done, notBool, notByte, notChar;
816
817 // common case first
818 cmpl(rcx, T_INT);
819 jcc(Assembler::equal, done);
820
821 // mask integer result to narrower return type.
822 cmpl(rcx, T_BOOLEAN);
823 jcc(Assembler::notEqual, notBool);
824 andl(result, 0x1);
825 jmp(done);
826
827 bind(notBool);
828 cmpl(rcx, T_BYTE);
829 jcc(Assembler::notEqual, notByte);
830 movsbl(result, result);
831 jmp(done);
832
833 bind(notByte);
834 cmpl(rcx, T_CHAR);
835 jcc(Assembler::notEqual, notChar);
836 movzwl(result, result);
837 jmp(done);
838
839 bind(notChar);
840 // cmpl(rcx, T_SHORT); // all that's left
841 // jcc(Assembler::notEqual, done);
842 movswl(result, result);
843
844 // Nothing to do for T_INT
845 bind(done);
846 }
847
848 // remove activation
849 //
850 // Unlock the receiver if this is a synchronized method.
851 // Unlock any Java monitors from synchronized blocks.
852 // Apply stack watermark barrier.
853 // Notify JVMTI.
854 // Remove the activation from the stack.
855 //
856 // If there are locked Java monitors
857 // If throw_monitor_exception
858 // throws IllegalMonitorStateException
859 // Else if install_monitor_exception
860 // installs IllegalMonitorStateException
861 // Else
862 // no error processing
863 void InterpreterMacroAssembler::remove_activation(TosState state,
864 Register ret_addr,
865 bool throw_monitor_exception,
866 bool install_monitor_exception,
867 bool notify_jvmdi) {
868 // Note: Registers rdx xmm0 may be in use for the
869 // result check if synchronized method
870 Label unlocked, unlock, no_unlock;
871
872 #ifdef ASSERT
873 Label not_preempted;
874 cmpptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD);
875 jcc(Assembler::equal, not_preempted);
876 stop("remove_activation: should not have alternate return address set");
877 bind(not_preempted);
878 #endif /* ASSERT */
879
880 const Register rthread = r15_thread;
881 const Register robj = c_rarg1;
882 const Register rmon = c_rarg1;
883
884 // get the value of _do_not_unlock_if_synchronized into rdx
885 const Address do_not_unlock_if_synchronized(rthread,
886 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
887 movbool(rbx, do_not_unlock_if_synchronized);
888 movbool(do_not_unlock_if_synchronized, false); // reset the flag
889
890 // get method access flags
891 movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
892 load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset()));
893 testl(rcx, JVM_ACC_SYNCHRONIZED);
894 jcc(Assembler::zero, unlocked);
895
896 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
897 // is set.
898 testbool(rbx);
899 jcc(Assembler::notZero, no_unlock);
900
901 // unlock monitor
902 push(state); // save result
903
904 // BasicObjectLock will be first in list, since this is a
905 // synchronized method. However, need to check that the object has
906 // not been unlocked by an explicit monitorexit bytecode.
907 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
908 wordSize - (int) sizeof(BasicObjectLock));
909 // We use c_rarg1/rdx so that if we go slow path it will be the correct
910 // register for unlock_object to pass to VM directly
911 lea(robj, monitor); // address of first monitor
912
913 movptr(rax, Address(robj, BasicObjectLock::obj_offset()));
914 testptr(rax, rax);
915 jcc(Assembler::notZero, unlock);
916
917 pop(state);
918 if (throw_monitor_exception) {
919 // Entry already unlocked, need to throw exception
920 call_VM(noreg, CAST_FROM_FN_PTR(address,
921 InterpreterRuntime::throw_illegal_monitor_state_exception));
922 should_not_reach_here();
923 } else {
924 // Monitor already unlocked during a stack unroll. If requested,
925 // install an illegal_monitor_state_exception. Continue with
926 // stack unrolling.
927 if (install_monitor_exception) {
928 call_VM(noreg, CAST_FROM_FN_PTR(address,
929 InterpreterRuntime::new_illegal_monitor_state_exception));
930 }
931 jmp(unlocked);
932 }
933
934 bind(unlock);
935 unlock_object(robj);
936 pop(state);
937
938 // Check that for block-structured locking (i.e., that all locked
939 // objects has been unlocked)
940 bind(unlocked);
941
942 // rax, rdx: Might contain return value
943
944 // Check that all monitors are unlocked
945 {
946 Label loop, exception, entry, restart;
947 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
948 const Address monitor_block_top(
949 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
950 const Address monitor_block_bot(
951 rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
952
953 bind(restart);
954 // We use c_rarg1 so that if we go slow path it will be the correct
955 // register for unlock_object to pass to VM directly
956 movptr(rmon, monitor_block_top); // derelativize pointer
957 lea(rmon, Address(rbp, rmon, Address::times_ptr));
958 // c_rarg1 points to current entry, starting with top-most entry
959
960 lea(rbx, monitor_block_bot); // points to word before bottom of
961 // monitor block
962 jmp(entry);
963
964 // Entry already locked, need to throw exception
965 bind(exception);
966
967 if (throw_monitor_exception) {
968 // Throw exception
969 MacroAssembler::call_VM(noreg,
970 CAST_FROM_FN_PTR(address, InterpreterRuntime::
971 throw_illegal_monitor_state_exception));
972 should_not_reach_here();
973 } else {
974 // Stack unrolling. Unlock object and install illegal_monitor_exception.
975 // Unlock does not block, so don't have to worry about the frame.
976 // We don't have to preserve c_rarg1 since we are going to throw an exception.
977
978 push(state);
979 mov(robj, rmon); // nop if robj and rmon are the same
980 unlock_object(robj);
981 pop(state);
982
983 if (install_monitor_exception) {
984 call_VM(noreg, CAST_FROM_FN_PTR(address,
985 InterpreterRuntime::
986 new_illegal_monitor_state_exception));
987 }
988
989 jmp(restart);
990 }
991
992 bind(loop);
993 // check if current entry is used
994 cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD);
995 jcc(Assembler::notEqual, exception);
996
997 addptr(rmon, entry_size); // otherwise advance to next entry
998 bind(entry);
999 cmpptr(rmon, rbx); // check if bottom reached
1000 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
1001 }
1002
1003 bind(no_unlock);
1004
1005 JFR_ONLY(enter_jfr_critical_section();)
1006
1007 // The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
1008 // that would normally not be safe to use. Such bad returns into unsafe territory of
1009 // the stack, will call InterpreterRuntime::at_unwind.
1010 Label slow_path;
1011 Label fast_path;
1012 safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
1013 jmp(fast_path);
1014 bind(slow_path);
1015 push(state);
1016 set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1);
1017 super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread);
1018 reset_last_Java_frame(true);
1019 pop(state);
1020 bind(fast_path);
1021
1022 // JVMTI support. Make sure the safepoint poll test is issued prior.
1023 if (notify_jvmdi) {
1024 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
1025 } else {
1026 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1027 }
1028
1029 if (StackReservedPages > 0) {
1030 movptr(rbx,
1031 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1032 // testing if reserved zone needs to be re-enabled
1033 Register rthread = r15_thread;
1034 Label no_reserved_zone_enabling;
1035
1036 // check if already enabled - if so no re-enabling needed
1037 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
1038 cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1039 jcc(Assembler::equal, no_reserved_zone_enabling);
1040
1041 cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1042 jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1043
1044 JFR_ONLY(leave_jfr_critical_section();)
1045
1046 call_VM_leaf(
1047 CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1048 call_VM(noreg, CAST_FROM_FN_PTR(address,
1049 InterpreterRuntime::throw_delayed_StackOverflowError));
1050 should_not_reach_here();
1051
1052 bind(no_reserved_zone_enabling);
1053 }
1054
1055 // remove activation
1056 // get sender sp
1057 movptr(rbx,
1058 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1059
1060 if (state == atos && InlineTypeReturnedAsFields) {
1061 Label skip;
1062 Label not_null;
1063 testptr(rax, rax);
1064 jcc(Assembler::notZero, not_null);
1065 // Returned value is null, zero all return registers because they may belong to oop fields
1066 xorq(j_rarg1, j_rarg1);
1067 xorq(j_rarg2, j_rarg2);
1068 xorq(j_rarg3, j_rarg3);
1069 xorq(j_rarg4, j_rarg4);
1070 xorq(j_rarg5, j_rarg5);
1071 jmp(skip);
1072 bind(not_null);
1073
1074 // Check if we are returning an non-null inline type and load its fields into registers
1075 test_oop_is_not_inline_type(rax, rscratch1, skip, /* can_be_null= */ false);
1076
1077 #ifndef _LP64
1078 super_call_VM_leaf(StubRoutines::load_inline_type_fields_in_regs());
1079 #else
1080 // Load fields from a buffered value with an inline class specific handler
1081 load_klass(rdi, rax, rscratch1);
1082 movptr(rdi, Address(rdi, InlineKlass::adr_members_offset()));
1083 movptr(rdi, Address(rdi, InlineKlass::unpack_handler_offset()));
1084 // Unpack handler can be null if inline type is not scalarizable in returns
1085 testptr(rdi, rdi);
1086 jcc(Assembler::zero, skip);
1087 call(rdi);
1088 #endif
1089 #ifdef ASSERT
1090 // TODO 8284443 Enable
1091 if (StressCallingConvention && false) {
1092 Label skip_stress;
1093 movptr(rscratch1, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1094 movl(rscratch1, Address(rscratch1, Method::flags_offset()));
1095 testl(rcx, MethodFlags::has_scalarized_return_flag());
1096 jcc(Assembler::zero, skip_stress);
1097 load_klass(rax, rax, rscratch1);
1098 orptr(rax, 1);
1099 bind(skip_stress);
1100 }
1101 #endif
1102 // call above kills the value in rbx. Reload it.
1103 movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1104 bind(skip);
1105 }
1106
1107 leave(); // remove frame anchor
1108
1109 JFR_ONLY(leave_jfr_critical_section();)
1110
1111 pop(ret_addr); // get return address
1112 mov(rsp, rbx); // set sp to sender sp
1113 pop_cont_fastpath();
1114
1115 }
1116
1117 #if INCLUDE_JFR
1118 void InterpreterMacroAssembler::enter_jfr_critical_section() {
1119 const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1120 movbool(sampling_critical_section, true);
1121 }
1122
1123 void InterpreterMacroAssembler::leave_jfr_critical_section() {
1124 const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
1125 movbool(sampling_critical_section, false);
1126 }
1127 #endif // INCLUDE_JFR
1128
1129 void InterpreterMacroAssembler::get_method_counters(Register method,
1130 Register mcs, Label& skip) {
1131 Label has_counters;
1132 movptr(mcs, Address(method, Method::method_counters_offset()));
1133 testptr(mcs, mcs);
1134 jcc(Assembler::notZero, has_counters);
1135 call_VM(noreg, CAST_FROM_FN_PTR(address,
1136 InterpreterRuntime::build_method_counters), method);
1137 movptr(mcs, Address(method,Method::method_counters_offset()));
1138 testptr(mcs, mcs);
1139 jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1140 bind(has_counters);
1141 }
1142
1143 void InterpreterMacroAssembler::allocate_instance(Register klass, Register new_obj,
1144 Register t1, Register t2,
1145 bool clear_fields, Label& alloc_failed) {
1146 MacroAssembler::allocate_instance(klass, new_obj, t1, t2, clear_fields, alloc_failed);
1147 if (DTraceAllocProbes) {
1148 // Trigger dtrace event for fastpath
1149 push(atos);
1150 call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1151 pop(atos);
1152 }
1153 }
1154
1155 void InterpreterMacroAssembler::read_flat_field(Register entry, Register obj) {
1156 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field),
1157 obj, entry);
1158 get_vm_result_oop(obj);
1159 }
1160
1161 void InterpreterMacroAssembler::write_flat_field(Register entry, Register tmp1, Register tmp2,
1162 Register obj, Register off, Register value) {
1163 assert_different_registers(entry, tmp1, tmp2, obj, off, value);
1164
1165 Label slow_path, done;
1166
1167 load_unsigned_byte(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
1168 test_field_is_not_null_free_inline_type(tmp2, tmp1, slow_path);
1169
1170 null_check(value); // FIXME JDK-8341120
1171
1172 lea(obj, Address(obj, off, Address::times_1));
1173
1174 load_klass(tmp2, value, tmp1);
1175 payload_addr(value, value, tmp2);
1176
1177 Register idx = tmp1;
1178 load_unsigned_short(idx, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
1179 movptr(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
1180
1181 Register layout_info = off;
1182 inline_layout_info(tmp2, idx, layout_info);
1183
1184 flat_field_copy(IN_HEAP, value, obj, layout_info);
1185 jmp(done);
1186
1187 bind(slow_path);
1188 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_flat_field), obj, value, entry);
1189
1190 bind(done);
1191 }
1192
1193 // Lock object
1194 //
1195 // Args:
1196 // rdx, c_rarg1: BasicObjectLock to be used for locking
1197 //
1198 // Kills:
1199 // rax, rbx
1200 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1201 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1202
1203 Label done, slow_case;
1204
1205 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1206 const Register tmp_reg = rbx;
1207 const Register obj_reg = c_rarg3; // Will contain the oop
1208
1209 // Load object pointer into obj_reg
1210 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1211
1212 fast_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case);
1213 jmp(done);
1214
1215 bind(slow_case);
1216
1217 // Call the runtime routine for slow case
1218 call_VM_preemptable(noreg,
1219 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1220 lock_reg);
1221 bind(done);
1222 }
1223
1224
1225 // Unlocks an object. Used in monitorexit bytecode and
1226 // remove_activation. Throws an IllegalMonitorException if object is
1227 // not locked by current thread.
1228 //
1229 // Args:
1230 // rdx, c_rarg1: BasicObjectLock for lock
1231 //
1232 // Kills:
1233 // rax
1234 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
1235 // rscratch1 (scratch reg)
1236 // rax, rbx, rcx, rdx
1237 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
1238 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
1239
1240 Label done, slow_case;
1241
1242 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1243 const Register header_reg = c_rarg2; // Will contain the old oopMark
1244 const Register obj_reg = c_rarg3; // Will contain the oop
1245
1246 save_bcp(); // Save in case of exception
1247
1248 // Load oop into obj_reg(%c_rarg3)
1249 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
1250
1251 // Free entry
1252 movptr(Address(lock_reg, BasicObjectLock::obj_offset()), NULL_WORD);
1253
1254 fast_unlock(obj_reg, swap_reg, header_reg, slow_case);
1255 jmp(done);
1256
1257 bind(slow_case);
1258 // Call the runtime routine for slow case.
1259 movptr(Address(lock_reg, BasicObjectLock::obj_offset()), obj_reg); // restore obj
1260 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
1261
1262 bind(done);
1263
1264 restore_bcp();
1265 }
1266
1267 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
1268 Label& zero_continue) {
1269 assert(ProfileInterpreter, "must be profiling interpreter");
1270 movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize));
1271 testptr(mdp, mdp);
1272 jcc(Assembler::zero, zero_continue);
1273 }
1274
1275
1276 // Set the method data pointer for the current bcp.
1277 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
1278 assert(ProfileInterpreter, "must be profiling interpreter");
1279 Label set_mdp;
1280 push(rax);
1281 push(rbx);
1282
1283 get_method(rbx);
1284 // Test MDO to avoid the call if it is null.
1285 movptr(rax, Address(rbx, in_bytes(Method::method_data_offset())));
1286 testptr(rax, rax);
1287 jcc(Assembler::zero, set_mdp);
1288 // rbx: method
1289 // _bcp_register: bcp
1290 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, _bcp_register);
1291 // rax: mdi
1292 // mdo is guaranteed to be non-zero here, we checked for it before the call.
1293 movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset())));
1294 addptr(rbx, in_bytes(MethodData::data_offset()));
1295 addptr(rax, rbx);
1296 bind(set_mdp);
1297 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax);
1298 pop(rbx);
1299 pop(rax);
1300 }
1301
1302 void InterpreterMacroAssembler::verify_method_data_pointer() {
1303 assert(ProfileInterpreter, "must be profiling interpreter");
1304 #ifdef ASSERT
1305 Label verify_continue;
1306 push(rax);
1307 push(rbx);
1308 Register arg3_reg = c_rarg3;
1309 Register arg2_reg = c_rarg2;
1310 push(arg3_reg);
1311 push(arg2_reg);
1312 test_method_data_pointer(arg3_reg, verify_continue); // If mdp is zero, continue
1313 get_method(rbx);
1314
1315 // If the mdp is valid, it will point to a DataLayout header which is
1316 // consistent with the bcp. The converse is highly probable also.
1317 load_unsigned_short(arg2_reg,
1318 Address(arg3_reg, in_bytes(DataLayout::bci_offset())));
1319 addptr(arg2_reg, Address(rbx, Method::const_offset()));
1320 lea(arg2_reg, Address(arg2_reg, ConstMethod::codes_offset()));
1321 cmpptr(arg2_reg, _bcp_register);
1322 jcc(Assembler::equal, verify_continue);
1323 // rbx: method
1324 // _bcp_register: bcp
1325 // c_rarg3: mdp
1326 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
1327 rbx, _bcp_register, arg3_reg);
1328 bind(verify_continue);
1329 pop(arg2_reg);
1330 pop(arg3_reg);
1331 pop(rbx);
1332 pop(rax);
1333 #endif // ASSERT
1334 }
1335
1336
1337 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1338 int constant,
1339 Register value) {
1340 assert(ProfileInterpreter, "must be profiling interpreter");
1341 Address data(mdp_in, constant);
1342 movptr(data, value);
1343 }
1344
1345
1346 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1347 int constant) {
1348 assert(ProfileInterpreter, "must be profiling interpreter");
1349 Address data(mdp_in, constant);
1350 addptr(data, DataLayout::counter_increment);
1351 }
1352
1353
1354 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1355 Register index,
1356 int constant) {
1357 assert(ProfileInterpreter, "must be profiling interpreter");
1358 Address data(mdp_in, index, Address::times_1, constant);
1359 addptr(data, DataLayout::counter_increment);
1360 }
1361
1362 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1363 int flag_byte_constant) {
1364 assert(ProfileInterpreter, "must be profiling interpreter");
1365 int header_offset = in_bytes(DataLayout::flags_offset());
1366 int header_bits = flag_byte_constant;
1367 // Set the flag
1368 orb(Address(mdp_in, header_offset), header_bits);
1369 }
1370
1371
1372
1373 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1374 int offset,
1375 Register value,
1376 Register test_value_out,
1377 Label& not_equal_continue) {
1378 assert(ProfileInterpreter, "must be profiling interpreter");
1379 if (test_value_out == noreg) {
1380 cmpptr(value, Address(mdp_in, offset));
1381 } else {
1382 // Put the test value into a register, so caller can use it:
1383 movptr(test_value_out, Address(mdp_in, offset));
1384 cmpptr(test_value_out, value);
1385 }
1386 jcc(Assembler::notEqual, not_equal_continue);
1387 }
1388
1389
1390 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1391 int offset_of_disp) {
1392 assert(ProfileInterpreter, "must be profiling interpreter");
1393 Address disp_address(mdp_in, offset_of_disp);
1394 addptr(mdp_in, disp_address);
1395 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1396 }
1397
1398
1399 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1400 Register reg,
1401 int offset_of_disp) {
1402 assert(ProfileInterpreter, "must be profiling interpreter");
1403 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1404 addptr(mdp_in, disp_address);
1405 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1406 }
1407
1408
1409 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1410 int constant) {
1411 assert(ProfileInterpreter, "must be profiling interpreter");
1412 addptr(mdp_in, constant);
1413 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1414 }
1415
1416
1417 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1418 assert(ProfileInterpreter, "must be profiling interpreter");
1419 push(return_bci); // save/restore across call_VM
1420 call_VM(noreg,
1421 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1422 return_bci);
1423 pop(return_bci);
1424 }
1425
1426
1427 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1428 if (ProfileInterpreter) {
1429 Label profile_continue;
1430
1431 // If no method data exists, go to profile_continue.
1432 test_method_data_pointer(mdp, profile_continue);
1433
1434 // We are taking a branch. Increment the taken count.
1435 increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1436
1437 // The method data pointer needs to be updated to reflect the new target.
1438 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1439 bind(profile_continue);
1440 }
1441 }
1442
1443
1444 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1445 if (ProfileInterpreter) {
1446 Label profile_continue;
1447
1448 // If no method data exists, go to profile_continue.
1449 test_method_data_pointer(mdp, profile_continue);
1450
1451 // We are not taking a branch. Increment the not taken count.
1452 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1453
1454 // The method data pointer needs to be updated to correspond to
1455 // the next bytecode
1456 update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1457 bind(profile_continue);
1458 }
1459 }
1460
1461 void InterpreterMacroAssembler::profile_call(Register mdp) {
1462 if (ProfileInterpreter) {
1463 Label profile_continue;
1464
1465 // If no method data exists, go to profile_continue.
1466 test_method_data_pointer(mdp, profile_continue);
1467
1468 // We are making a call. Increment the count.
1469 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1470
1471 // The method data pointer needs to be updated to reflect the new target.
1472 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1473 bind(profile_continue);
1474 }
1475 }
1476
1477
1478 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1479 if (ProfileInterpreter) {
1480 Label profile_continue;
1481
1482 // If no method data exists, go to profile_continue.
1483 test_method_data_pointer(mdp, profile_continue);
1484
1485 // We are making a call. Increment the count.
1486 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1487
1488 // The method data pointer needs to be updated to reflect the new target.
1489 update_mdp_by_constant(mdp,
1490 in_bytes(VirtualCallData::
1491 virtual_call_data_size()));
1492 bind(profile_continue);
1493 }
1494 }
1495
1496
1497 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1498 Register mdp,
1499 bool receiver_can_be_null) {
1500 if (ProfileInterpreter) {
1501 Label profile_continue;
1502
1503 // If no method data exists, go to profile_continue.
1504 test_method_data_pointer(mdp, profile_continue);
1505
1506 Label skip_receiver_profile;
1507 if (receiver_can_be_null) {
1508 Label not_null;
1509 testptr(receiver, receiver);
1510 jccb(Assembler::notZero, not_null);
1511 // We are making a call. Increment the count for null receiver.
1512 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1513 jmp(skip_receiver_profile);
1514 bind(not_null);
1515 }
1516
1517 // Record the receiver type.
1518 profile_receiver_type(receiver, mdp, 0);
1519 bind(skip_receiver_profile);
1520
1521 // The method data pointer needs to be updated to reflect the new target.
1522 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1523 bind(profile_continue);
1524 }
1525 }
1526
1527 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1528 Register mdp) {
1529 if (ProfileInterpreter) {
1530 Label profile_continue;
1531 uint row;
1532
1533 // If no method data exists, go to profile_continue.
1534 test_method_data_pointer(mdp, profile_continue);
1535
1536 // Update the total ret count.
1537 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1538
1539 for (row = 0; row < RetData::row_limit(); row++) {
1540 Label next_test;
1541
1542 // See if return_bci is equal to bci[n]:
1543 test_mdp_data_at(mdp,
1544 in_bytes(RetData::bci_offset(row)),
1545 return_bci, noreg,
1546 next_test);
1547
1548 // return_bci is equal to bci[n]. Increment the count.
1549 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1550
1551 // The method data pointer needs to be updated to reflect the new target.
1552 update_mdp_by_offset(mdp,
1553 in_bytes(RetData::bci_displacement_offset(row)));
1554 jmp(profile_continue);
1555 bind(next_test);
1556 }
1557
1558 update_mdp_for_ret(return_bci);
1559
1560 bind(profile_continue);
1561 }
1562 }
1563
1564
1565 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1566 if (ProfileInterpreter) {
1567 Label profile_continue;
1568
1569 // If no method data exists, go to profile_continue.
1570 test_method_data_pointer(mdp, profile_continue);
1571
1572 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1573
1574 // The method data pointer needs to be updated.
1575 int mdp_delta = in_bytes(BitData::bit_data_size());
1576 if (TypeProfileCasts) {
1577 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1578 }
1579 update_mdp_by_constant(mdp, mdp_delta);
1580
1581 bind(profile_continue);
1582 }
1583 }
1584
1585
1586 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass) {
1587 if (ProfileInterpreter) {
1588 Label profile_continue;
1589
1590 // If no method data exists, go to profile_continue.
1591 test_method_data_pointer(mdp, profile_continue);
1592
1593 // The method data pointer needs to be updated.
1594 int mdp_delta = in_bytes(BitData::bit_data_size());
1595 if (TypeProfileCasts) {
1596 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1597
1598 // Record the object type.
1599 profile_receiver_type(klass, mdp, 0);
1600 }
1601 update_mdp_by_constant(mdp, mdp_delta);
1602
1603 bind(profile_continue);
1604 }
1605 }
1606
1607
1608 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1609 if (ProfileInterpreter) {
1610 Label profile_continue;
1611
1612 // If no method data exists, go to profile_continue.
1613 test_method_data_pointer(mdp, profile_continue);
1614
1615 // Update the default case count
1616 increment_mdp_data_at(mdp,
1617 in_bytes(MultiBranchData::default_count_offset()));
1618
1619 // The method data pointer needs to be updated.
1620 update_mdp_by_offset(mdp,
1621 in_bytes(MultiBranchData::
1622 default_displacement_offset()));
1623
1624 bind(profile_continue);
1625 }
1626 }
1627
1628
1629 void InterpreterMacroAssembler::profile_switch_case(Register index,
1630 Register mdp,
1631 Register reg2) {
1632 if (ProfileInterpreter) {
1633 Label profile_continue;
1634
1635 // If no method data exists, go to profile_continue.
1636 test_method_data_pointer(mdp, profile_continue);
1637
1638 // Build the base (index * per_case_size_in_bytes()) +
1639 // case_array_offset_in_bytes()
1640 movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1641 imulptr(index, reg2); // XXX l ?
1642 addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1643
1644 // Update the case count
1645 increment_mdp_data_at(mdp,
1646 index,
1647 in_bytes(MultiBranchData::relative_count_offset()));
1648
1649 // The method data pointer needs to be updated.
1650 update_mdp_by_offset(mdp,
1651 index,
1652 in_bytes(MultiBranchData::
1653 relative_displacement_offset()));
1654
1655 bind(profile_continue);
1656 }
1657 }
1658
1659 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
1660 Register array,
1661 Register tmp) {
1662 if (ProfileInterpreter) {
1663 Label profile_continue;
1664
1665 // If no method data exists, go to profile_continue.
1666 test_method_data_pointer(mdp, profile_continue);
1667
1668 mov(tmp, array);
1669 profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
1670
1671 Label not_flat;
1672 test_non_flat_array_oop(array, tmp, not_flat);
1673
1674 set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
1675
1676 bind(not_flat);
1677
1678 Label not_null_free;
1679 test_non_null_free_array_oop(array, tmp, not_null_free);
1680
1681 set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
1682
1683 bind(not_null_free);
1684
1685 bind(profile_continue);
1686 }
1687 }
1688
1689 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
1690 Register array,
1691 Register tmp);
1692 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
1693 Register array,
1694 Register tmp);
1695
1696
1697 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
1698 if (ProfileInterpreter) {
1699 Label profile_continue;
1700
1701 // If no method data exists, go to profile_continue.
1702 test_method_data_pointer(mdp, profile_continue);
1703
1704 Label done, update;
1705 testptr(element, element);
1706 jccb(Assembler::notZero, update);
1707 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1708 jmp(done);
1709
1710 bind(update);
1711 load_klass(tmp, element, rscratch1);
1712
1713 // Record the object type.
1714 profile_receiver_type(tmp, mdp, 0);
1715
1716 bind(done);
1717
1718 // The method data pointer needs to be updated.
1719 update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
1720
1721 bind(profile_continue);
1722 }
1723 }
1724
1725 void InterpreterMacroAssembler::profile_element_type(Register mdp,
1726 Register element,
1727 Register tmp) {
1728 if (ProfileInterpreter) {
1729 Label profile_continue;
1730
1731 // If no method data exists, go to profile_continue.
1732 test_method_data_pointer(mdp, profile_continue);
1733
1734 mov(tmp, element);
1735 profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
1736
1737 // The method data pointer needs to be updated.
1738 update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
1739
1740 bind(profile_continue);
1741 }
1742 }
1743
1744 void InterpreterMacroAssembler::profile_acmp(Register mdp,
1745 Register left,
1746 Register right,
1747 Register tmp) {
1748 if (ProfileInterpreter) {
1749 Label profile_continue;
1750
1751 // If no method data exists, go to profile_continue.
1752 test_method_data_pointer(mdp, profile_continue);
1753
1754 mov(tmp, left);
1755 profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
1756
1757 Label left_not_inline_type;
1758 test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
1759 set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
1760 bind(left_not_inline_type);
1761
1762 mov(tmp, right);
1763 profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
1764
1765 Label right_not_inline_type;
1766 test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
1767 set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
1768 bind(right_not_inline_type);
1769
1770 bind(profile_continue);
1771 }
1772 }
1773
1774
1775 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1776 if (state == atos) {
1777 MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1778 }
1779 }
1780
1781
1782 // Jump if ((*counter_addr += increment) & mask) == 0
1783 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
1784 Register scratch, Label* where) {
1785 // This update is actually not atomic and can lose a number of updates
1786 // under heavy contention, but the alternative of using the (contended)
1787 // atomic update here penalizes profiling paths too much.
1788 movl(scratch, counter_addr);
1789 incrementl(scratch, InvocationCounter::count_increment);
1790 movl(counter_addr, scratch);
1791 andl(scratch, mask);
1792 if (where != nullptr) {
1793 jcc(Assembler::zero, *where);
1794 }
1795 }
1796
1797 void InterpreterMacroAssembler::notify_method_entry() {
1798 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1799 // track stack depth. If it is possible to enter interp_only_mode we add
1800 // the code to check if the event should be sent.
1801 Register rthread = r15_thread;
1802 Register rarg = c_rarg1;
1803 if (JvmtiExport::can_post_interpreter_events()) {
1804 Label L;
1805 movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
1806 testl(rdx, rdx);
1807 jcc(Assembler::zero, L);
1808 call_VM(noreg, CAST_FROM_FN_PTR(address,
1809 InterpreterRuntime::post_method_entry));
1810 bind(L);
1811 }
1812
1813 if (DTraceMethodProbes) {
1814 get_method(rarg);
1815 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1816 rthread, rarg);
1817 }
1818
1819 // RedefineClasses() tracing support for obsolete method entry
1820 if (log_is_enabled(Trace, redefine, class, obsolete)) {
1821 get_method(rarg);
1822 call_VM_leaf(
1823 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1824 rthread, rarg);
1825 }
1826 }
1827
1828
1829 void InterpreterMacroAssembler::notify_method_exit(
1830 TosState state, NotifyMethodExitMode mode) {
1831 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1832 // track stack depth. If it is possible to enter interp_only_mode we add
1833 // the code to check if the event should be sent.
1834 Register rthread = r15_thread;
1835 Register rarg = c_rarg1;
1836 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1837 Label L;
1838 // Note: frame::interpreter_frame_result has a dependency on how the
1839 // method result is saved across the call to post_method_exit. If this
1840 // is changed then the interpreter_frame_result implementation will
1841 // need to be updated too.
1842
1843 // template interpreter will leave the result on the top of the stack.
1844 push(state);
1845 movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
1846 testl(rdx, rdx);
1847 jcc(Assembler::zero, L);
1848 call_VM(noreg,
1849 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1850 bind(L);
1851 pop(state);
1852 }
1853
1854 if (DTraceMethodProbes) {
1855 push(state);
1856 get_method(rarg);
1857 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1858 rthread, rarg);
1859 pop(state);
1860 }
1861 }
1862
1863 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
1864 // Get index out of bytecode pointer
1865 get_cache_index_at_bcp(index, 1, sizeof(u4));
1866 // Get address of invokedynamic array
1867 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
1868 movptr(cache, Address(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset())));
1869 if (is_power_of_2(sizeof(ResolvedIndyEntry))) {
1870 shll(index, log2i_exact(sizeof(ResolvedIndyEntry))); // Scale index by power of 2
1871 } else {
1872 imull(index, index, sizeof(ResolvedIndyEntry)); // Scale the index to be the entry index * sizeof(ResolvedIndyEntry)
1873 }
1874 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedIndyEntry>::base_offset_in_bytes()));
1875 }
1876
1877 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) {
1878 // Get index out of bytecode pointer
1879 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
1880 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1881
1882 movptr(cache, Address(cache, ConstantPoolCache::field_entries_offset()));
1883 // Take shortcut if the size is a power of 2
1884 if (is_power_of_2(sizeof(ResolvedFieldEntry))) {
1885 shll(index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2
1886 } else {
1887 imull(index, index, sizeof(ResolvedFieldEntry)); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry)
1888 }
1889 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedFieldEntry>::base_offset_in_bytes()));
1890 }
1891
1892 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) {
1893 // Get index out of bytecode pointer
1894 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
1895 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1896
1897 movptr(cache, Address(cache, ConstantPoolCache::method_entries_offset()));
1898 imull(index, index, sizeof(ResolvedMethodEntry)); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry)
1899 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedMethodEntry>::base_offset_in_bytes()));
1900 }