1 /*
2 * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "asm/macroAssembler.inline.hpp"
27 #include "compiler/compiler_globals.hpp"
28 #include "gc/shared/barrierSet.hpp"
29 #include "gc/shared/barrierSetAssembler.hpp"
30 #include "interp_masm_aarch64.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/interpreterRuntime.hpp"
33 #include "logging/log.hpp"
34 #include "oops/arrayOop.hpp"
35 #include "oops/markWord.hpp"
36 #include "oops/method.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/resolvedFieldEntry.hpp"
39 #include "oops/resolvedIndyEntry.hpp"
40 #include "oops/resolvedMethodEntry.hpp"
41 #include "prims/jvmtiExport.hpp"
42 #include "prims/jvmtiThreadState.hpp"
43 #include "runtime/basicLock.hpp"
44 #include "runtime/frame.inline.hpp"
45 #include "runtime/javaThread.hpp"
46 #include "runtime/runtimeUpcalls.hpp"
47 #include "runtime/safepointMechanism.hpp"
48 #include "runtime/sharedRuntime.hpp"
49 #include "utilities/powerOfTwo.hpp"
50
51 void InterpreterMacroAssembler::narrow(Register result) {
52
53 // Get method->_constMethod->_result_type
54 ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
55 ldr(rscratch1, Address(rscratch1, Method::const_offset()));
56 ldrb(rscratch1, Address(rscratch1, ConstMethod::result_type_offset()));
57
58 Label done, notBool, notByte, notChar;
59
60 // common case first
61 cmpw(rscratch1, T_INT);
62 br(Assembler::EQ, done);
63
64 // mask integer result to narrower return type.
65 cmpw(rscratch1, T_BOOLEAN);
66 br(Assembler::NE, notBool);
67 andw(result, result, 0x1);
68 b(done);
69
70 bind(notBool);
71 cmpw(rscratch1, T_BYTE);
72 br(Assembler::NE, notByte);
73 sbfx(result, result, 0, 8);
74 b(done);
75
76 bind(notByte);
77 cmpw(rscratch1, T_CHAR);
78 br(Assembler::NE, notChar);
79 ubfx(result, result, 0, 16); // truncate upper 16 bits
80 b(done);
81
82 bind(notChar);
83 sbfx(result, result, 0, 16); // sign-extend short
84
85 // Nothing to do for T_INT
86 bind(done);
87 }
88
89 void InterpreterMacroAssembler::jump_to_entry(address entry) {
90 assert(entry, "Entry must have been generated by now");
91 b(entry);
92 }
93
94 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
95 if (JvmtiExport::can_pop_frame()) {
96 Label L;
97 // Initiate popframe handling only if it is not already being
98 // processed. If the flag has the popframe_processing bit set, it
99 // means that this code is called *during* popframe handling - we
100 // don't want to reenter.
101 // This method is only called just after the call into the vm in
102 // call_VM_base, so the arg registers are available.
103 ldrw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset()));
104 tbz(rscratch1, exact_log2(JavaThread::popframe_pending_bit), L);
105 tbnz(rscratch1, exact_log2(JavaThread::popframe_processing_bit), L);
106 // Call Interpreter::remove_activation_preserving_args_entry() to get the
107 // address of the same-named entrypoint in the generated interpreter code.
108 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
109 br(r0);
110 bind(L);
111 }
112 }
113
114
115 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
116 ldr(r2, Address(rthread, JavaThread::jvmti_thread_state_offset()));
117 const Address tos_addr(r2, JvmtiThreadState::earlyret_tos_offset());
118 const Address oop_addr(r2, JvmtiThreadState::earlyret_oop_offset());
119 const Address val_addr(r2, JvmtiThreadState::earlyret_value_offset());
120 switch (state) {
121 case atos: ldr(r0, oop_addr);
122 str(zr, oop_addr);
123 interp_verify_oop(r0, state); break;
124 case ltos: ldr(r0, val_addr); break;
125 case btos: // fall through
126 case ztos: // fall through
127 case ctos: // fall through
128 case stos: // fall through
129 case itos: ldrw(r0, val_addr); break;
130 case ftos: ldrs(v0, val_addr); break;
131 case dtos: ldrd(v0, val_addr); break;
132 case vtos: /* nothing to do */ break;
133 default : ShouldNotReachHere();
134 }
135 // Clean up tos value in the thread object
136 movw(rscratch1, (int) ilgl);
137 strw(rscratch1, tos_addr);
138 strw(zr, val_addr);
139 }
140
141
142 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
143 if (JvmtiExport::can_force_early_return()) {
144 Label L;
145 ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
146 cbz(rscratch1, L); // if (thread->jvmti_thread_state() == nullptr) exit;
147
148 // Initiate earlyret handling only if it is not already being processed.
149 // If the flag has the earlyret_processing bit set, it means that this code
150 // is called *during* earlyret handling - we don't want to reenter.
151 ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_state_offset()));
152 cmpw(rscratch1, JvmtiThreadState::earlyret_pending);
153 br(Assembler::NE, L);
154
155 // Call Interpreter::remove_activation_early_entry() to get the address of the
156 // same-named entrypoint in the generated interpreter code.
157 ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
158 ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_tos_offset()));
159 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), rscratch1);
160 br(r0);
161 bind(L);
162 }
163 }
164
165 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
166 Register reg,
167 int bcp_offset) {
168 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
169 ldrh(reg, Address(rbcp, bcp_offset));
170 rev16(reg, reg);
171 }
172
173 void InterpreterMacroAssembler::get_dispatch() {
174 uint64_t offset;
175 adrp(rdispatch, ExternalAddress((address)Interpreter::dispatch_table()), offset);
176 // Use add() here after ARDP, rather than lea().
177 // lea() does not generate anything if its offset is zero.
178 // However, relocs expect to find either an ADD or a load/store
179 // insn after an ADRP. add() always generates an ADD insn, even
180 // for add(Rn, Rn, 0).
181 add(rdispatch, rdispatch, offset);
182 }
183
184 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
185 int bcp_offset,
186 size_t index_size) {
187 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
188 if (index_size == sizeof(u2)) {
189 load_unsigned_short(index, Address(rbcp, bcp_offset));
190 } else if (index_size == sizeof(u4)) {
191 // assert(EnableInvokeDynamic, "giant index used only for JSR 292");
192 ldrw(index, Address(rbcp, bcp_offset));
193 } else if (index_size == sizeof(u1)) {
194 load_unsigned_byte(index, Address(rbcp, bcp_offset));
195 } else {
196 ShouldNotReachHere();
197 }
198 }
199
200 void InterpreterMacroAssembler::get_method_counters(Register method,
201 Register mcs, Label& skip) {
202 Label has_counters;
203 ldr(mcs, Address(method, Method::method_counters_offset()));
204 cbnz(mcs, has_counters);
205 call_VM(noreg, CAST_FROM_FN_PTR(address,
206 InterpreterRuntime::build_method_counters), method);
207 ldr(mcs, Address(method, Method::method_counters_offset()));
208 cbz(mcs, skip); // No MethodCounters allocated, OutOfMemory
209 bind(has_counters);
210 }
211
212 // Load object from cpool->resolved_references(index)
213 void InterpreterMacroAssembler::load_resolved_reference_at_index(
214 Register result, Register index, Register tmp) {
215 assert_different_registers(result, index);
216
217 get_constant_pool(result);
218 // load pointer for resolved_references[] objArray
219 ldr(result, Address(result, ConstantPool::cache_offset()));
220 ldr(result, Address(result, ConstantPoolCache::resolved_references_offset()));
221 resolve_oop_handle(result, tmp, rscratch2);
222 // Add in the index
223 add(index, index, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
224 load_heap_oop(result, Address(result, index, Address::uxtw(LogBytesPerHeapOop)), tmp, rscratch2);
225 }
226
227 void InterpreterMacroAssembler::load_resolved_klass_at_offset(
228 Register cpool, Register index, Register klass, Register temp) {
229 add(temp, cpool, index, LSL, LogBytesPerWord);
230 ldrh(temp, Address(temp, sizeof(ConstantPool))); // temp = resolved_klass_index
231 ldr(klass, Address(cpool, ConstantPool::resolved_klasses_offset())); // klass = cpool->_resolved_klasses
232 add(klass, klass, temp, LSL, LogBytesPerWord);
233 ldr(klass, Address(klass, Array<Klass*>::base_offset_in_bytes()));
234 }
235
236 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
237 // subtype of super_klass.
238 //
239 // Args:
240 // r0: superklass
241 // Rsub_klass: subklass
242 //
243 // Kills:
244 // r2, r5
245 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
246 Label& ok_is_subtype) {
247 assert(Rsub_klass != r0, "r0 holds superklass");
248 assert(Rsub_klass != r2, "r2 holds 2ndary super array length");
249 assert(Rsub_klass != r5, "r5 holds 2ndary super array scan ptr");
250
251 // Profile the not-null value's klass.
252 profile_typecheck(r2, Rsub_klass, r5); // blows r2, reloads r5
253
254 // Do the check.
255 check_klass_subtype(Rsub_klass, r0, r2, ok_is_subtype); // blows r2
256 }
257
258 // Java Expression Stack
259
260 void InterpreterMacroAssembler::pop_ptr(Register r) {
261 ldr(r, post(esp, wordSize));
262 }
263
264 void InterpreterMacroAssembler::pop_i(Register r) {
265 ldrw(r, post(esp, wordSize));
266 }
267
268 void InterpreterMacroAssembler::pop_l(Register r) {
269 ldr(r, post(esp, 2 * Interpreter::stackElementSize));
270 }
271
272 void InterpreterMacroAssembler::push_ptr(Register r) {
273 str(r, pre(esp, -wordSize));
274 }
275
276 void InterpreterMacroAssembler::push_i(Register r) {
277 str(r, pre(esp, -wordSize));
278 }
279
280 void InterpreterMacroAssembler::push_l(Register r) {
281 str(zr, pre(esp, -wordSize));
282 str(r, pre(esp, - wordSize));
283 }
284
285 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
286 ldrs(r, post(esp, wordSize));
287 }
288
289 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
290 ldrd(r, post(esp, 2 * Interpreter::stackElementSize));
291 }
292
293 void InterpreterMacroAssembler::push_f(FloatRegister r) {
294 strs(r, pre(esp, -wordSize));
295 }
296
297 void InterpreterMacroAssembler::push_d(FloatRegister r) {
298 strd(r, pre(esp, 2* -wordSize));
299 }
300
301 void InterpreterMacroAssembler::pop(TosState state) {
302 switch (state) {
303 case atos: pop_ptr(); break;
304 case btos:
305 case ztos:
306 case ctos:
307 case stos:
308 case itos: pop_i(); break;
309 case ltos: pop_l(); break;
310 case ftos: pop_f(); break;
311 case dtos: pop_d(); break;
312 case vtos: /* nothing to do */ break;
313 default: ShouldNotReachHere();
314 }
315 interp_verify_oop(r0, state);
316 }
317
318 void InterpreterMacroAssembler::push(TosState state) {
319 interp_verify_oop(r0, state);
320 switch (state) {
321 case atos: push_ptr(); break;
322 case btos:
323 case ztos:
324 case ctos:
325 case stos:
326 case itos: push_i(); break;
327 case ltos: push_l(); break;
328 case ftos: push_f(); break;
329 case dtos: push_d(); break;
330 case vtos: /* nothing to do */ break;
331 default : ShouldNotReachHere();
332 }
333 }
334
335 // Helpers for swap and dup
336 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
337 ldr(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
338 }
339
340 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
341 str(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
342 }
343
344 void InterpreterMacroAssembler::load_float(Address src) {
345 ldrs(v0, src);
346 }
347
348 void InterpreterMacroAssembler::load_double(Address src) {
349 ldrd(v0, src);
350 }
351
352 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
353 // set sender sp
354 mov(r19_sender_sp, sp);
355 // record last_sp
356 sub(rscratch1, esp, rfp);
357 asr(rscratch1, rscratch1, Interpreter::logStackElementSize);
358 str(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
359 }
360
361 // Jump to from_interpreted entry of a call unless single stepping is possible
362 // in this thread in which case we must call the i2i entry
363 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
364 prepare_to_jump_from_interpreted();
365
366 if (JvmtiExport::can_post_interpreter_events()) {
367 Label run_compiled_code;
368 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
369 // compiled code in threads for which the event is enabled. Check here for
370 // interp_only_mode if these events CAN be enabled.
371 ldrw(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset()));
372 cbzw(rscratch1, run_compiled_code);
373 ldr(rscratch1, Address(method, Method::interpreter_entry_offset()));
374 br(rscratch1);
375 bind(run_compiled_code);
376 }
377
378 ldr(rscratch1, Address(method, Method::from_interpreted_offset()));
379 br(rscratch1);
380 }
381
382 // The following two routines provide a hook so that an implementation
383 // can schedule the dispatch in two parts. amd64 does not do this.
384 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
385 }
386
387 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
388 dispatch_next(state, step);
389 }
390
391 void InterpreterMacroAssembler::dispatch_base(TosState state,
392 address* table,
393 bool verifyoop,
394 bool generate_poll) {
395 if (VerifyActivationFrameSize) {
396 Label L;
397 sub(rscratch2, rfp, esp);
398 int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
399 subs(rscratch2, rscratch2, min_frame_size);
400 br(Assembler::GE, L);
401 stop("broken stack frame");
402 bind(L);
403 }
404 if (verifyoop) {
405 interp_verify_oop(r0, state);
406 }
407
408 Label safepoint;
409 address* const safepoint_table = Interpreter::safept_table(state);
410 bool needs_thread_local_poll = generate_poll && table != safepoint_table;
411
412 if (needs_thread_local_poll) {
413 NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
414 ldr(rscratch2, Address(rthread, JavaThread::polling_word_offset()));
415 tbnz(rscratch2, exact_log2(SafepointMechanism::poll_bit()), safepoint);
416 }
417
418 if (table == Interpreter::dispatch_table(state)) {
419 addw(rscratch2, rscratch1, Interpreter::distance_from_dispatch_table(state));
420 ldr(rscratch2, Address(rdispatch, rscratch2, Address::uxtw(3)));
421 } else {
422 mov(rscratch2, (address)table);
423 ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
424 }
425 br(rscratch2);
426
427 if (needs_thread_local_poll) {
428 bind(safepoint);
429 lea(rscratch2, ExternalAddress((address)safepoint_table));
430 ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
431 br(rscratch2);
432 }
433 }
434
435 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {
436 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
437 }
438
439 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
440 dispatch_base(state, Interpreter::normal_table(state));
441 }
442
443 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
444 dispatch_base(state, Interpreter::normal_table(state), false);
445 }
446
447
448 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) {
449 // load next bytecode
450 ldrb(rscratch1, Address(pre(rbcp, step)));
451 dispatch_base(state, Interpreter::dispatch_table(state), /*verifyoop*/true, generate_poll);
452 }
453
454 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
455 // load current bytecode
456 ldrb(rscratch1, Address(rbcp, 0));
457 dispatch_base(state, table);
458 }
459
460 // remove activation
461 //
462 // Unlock the receiver if this is a synchronized method.
463 // Unlock any Java monitors from synchronized blocks.
464 // Apply stack watermark barrier.
465 // Notify JVMTI.
466 // Remove the activation from the stack.
467 //
468 // If there are locked Java monitors
469 // If throw_monitor_exception
470 // throws IllegalMonitorStateException
471 // Else if install_monitor_exception
472 // installs IllegalMonitorStateException
473 // Else
474 // no error processing
475 void InterpreterMacroAssembler::remove_activation(TosState state,
476 bool throw_monitor_exception,
477 bool install_monitor_exception,
478 bool notify_jvmdi) {
479 // Note: Registers r3 xmm0 may be in use for the
480 // result check if synchronized method
481 Label unlocked, unlock, no_unlock;
482
483 #ifdef ASSERT
484 Label not_preempted;
485 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
486 cbz(rscratch1, not_preempted);
487 stop("remove_activation: should not have alternate return address set");
488 bind(not_preempted);
489 #endif /* ASSERT */
490
491 // get the value of _do_not_unlock_if_synchronized into r3
492 const Address do_not_unlock_if_synchronized(rthread,
493 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
494 ldrb(r3, do_not_unlock_if_synchronized);
495 strb(zr, do_not_unlock_if_synchronized); // reset the flag
496
497 // get method access flags
498 ldr(r1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
499 ldrh(r2, Address(r1, Method::access_flags_offset()));
500 tbz(r2, exact_log2(JVM_ACC_SYNCHRONIZED), unlocked);
501
502 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
503 // is set.
504 cbnz(r3, no_unlock);
505
506 // unlock monitor
507 push(state); // save result
508
509 // BasicObjectLock will be first in list, since this is a
510 // synchronized method. However, need to check that the object has
511 // not been unlocked by an explicit monitorexit bytecode.
512 const Address monitor(rfp, frame::interpreter_frame_initial_sp_offset *
513 wordSize - (int) sizeof(BasicObjectLock));
514 // We use c_rarg1 so that if we go slow path it will be the correct
515 // register for unlock_object to pass to VM directly
516 lea(c_rarg1, monitor); // address of first monitor
517
518 ldr(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
519 cbnz(r0, unlock);
520
521 pop(state);
522 if (throw_monitor_exception) {
523 // Entry already unlocked, need to throw exception
524 call_VM(noreg, CAST_FROM_FN_PTR(address,
525 InterpreterRuntime::throw_illegal_monitor_state_exception));
526 should_not_reach_here();
527 } else {
528 // Monitor already unlocked during a stack unroll. If requested,
529 // install an illegal_monitor_state_exception. Continue with
530 // stack unrolling.
531 if (install_monitor_exception) {
532 call_VM(noreg, CAST_FROM_FN_PTR(address,
533 InterpreterRuntime::new_illegal_monitor_state_exception));
534 }
535 b(unlocked);
536 }
537
538 bind(unlock);
539 unlock_object(c_rarg1);
540 pop(state);
541
542 // Check that for block-structured locking (i.e., that all locked
543 // objects has been unlocked)
544 bind(unlocked);
545
546 // r0: Might contain return value
547
548 // Check that all monitors are unlocked
549 {
550 Label loop, exception, entry, restart;
551 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
552 const Address monitor_block_top(
553 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
554 const Address monitor_block_bot(
555 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
556
557 bind(restart);
558 // We use c_rarg1 so that if we go slow path it will be the correct
559 // register for unlock_object to pass to VM directly
560 ldr(c_rarg1, monitor_block_top); // derelativize pointer
561 lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
562 // c_rarg1 points to current entry, starting with top-most entry
563
564 lea(r19, monitor_block_bot); // points to word before bottom of
565 // monitor block
566 b(entry);
567
568 // Entry already locked, need to throw exception
569 bind(exception);
570
571 if (throw_monitor_exception) {
572 // Throw exception
573 MacroAssembler::call_VM(noreg,
574 CAST_FROM_FN_PTR(address, InterpreterRuntime::
575 throw_illegal_monitor_state_exception));
576 should_not_reach_here();
577 } else {
578 // Stack unrolling. Unlock object and install illegal_monitor_exception.
579 // Unlock does not block, so don't have to worry about the frame.
580 // We don't have to preserve c_rarg1 since we are going to throw an exception.
581
582 push(state);
583 unlock_object(c_rarg1);
584 pop(state);
585
586 if (install_monitor_exception) {
587 call_VM(noreg, CAST_FROM_FN_PTR(address,
588 InterpreterRuntime::
589 new_illegal_monitor_state_exception));
590 }
591
592 b(restart);
593 }
594
595 bind(loop);
596 // check if current entry is used
597 ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset()));
598 cbnz(rscratch1, exception);
599
600 add(c_rarg1, c_rarg1, entry_size); // otherwise advance to next entry
601 bind(entry);
602 cmp(c_rarg1, r19); // check if bottom reached
603 br(Assembler::NE, loop); // if not at bottom then check this entry
604 }
605
606 bind(no_unlock);
607
608 JFR_ONLY(enter_jfr_critical_section();)
609
610 // The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
611 // that would normally not be safe to use. Such bad returns into unsafe territory of
612 // the stack, will call InterpreterRuntime::at_unwind.
613 Label slow_path;
614 Label fast_path;
615 safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
616 br(Assembler::AL, fast_path);
617 bind(slow_path);
618 push(state);
619 set_last_Java_frame(esp, rfp, pc(), rscratch1);
620 super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
621 reset_last_Java_frame(true);
622 pop(state);
623 bind(fast_path);
624
625 // JVMTI support. Make sure the safepoint poll test is issued prior.
626 if (notify_jvmdi) {
627 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
628 } else {
629 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
630 }
631
632 // remove activation
633 // get sender esp
634 ldr(rscratch2,
635 Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
636 if (StackReservedPages > 0) {
637 // testing if reserved zone needs to be re-enabled
638 Label no_reserved_zone_enabling;
639
640 // check if already enabled - if so no re-enabling needed
641 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
642 ldrw(rscratch1, Address(rthread, JavaThread::stack_guard_state_offset()));
643 cmpw(rscratch1, (u1)StackOverflow::stack_guard_enabled);
644 br(Assembler::EQ, no_reserved_zone_enabling);
645
646 // look for an overflow into the stack reserved zone, i.e.
647 // interpreter_frame_sender_sp <= JavaThread::reserved_stack_activation
648 ldr(rscratch1, Address(rthread, JavaThread::reserved_stack_activation_offset()));
649 cmp(rscratch2, rscratch1);
650 br(Assembler::LS, no_reserved_zone_enabling);
651
652 JFR_ONLY(leave_jfr_critical_section();)
653
654 call_VM_leaf(
655 CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
656 call_VM(noreg, CAST_FROM_FN_PTR(address,
657 InterpreterRuntime::throw_delayed_StackOverflowError));
658 should_not_reach_here();
659
660 bind(no_reserved_zone_enabling);
661 }
662
663 // remove frame anchor
664 leave();
665
666 JFR_ONLY(leave_jfr_critical_section();)
667
668 // restore sender esp
669 mov(esp, rscratch2);
670
671 // If we're returning to interpreted code we will shortly be
672 // adjusting SP to allow some space for ESP. If we're returning to
673 // compiled code the saved sender SP was saved in sender_sp, so this
674 // restores it.
675 andr(sp, esp, -16);
676 }
677
678 #if INCLUDE_JFR
679 void InterpreterMacroAssembler::enter_jfr_critical_section() {
680 const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
681 mov(rscratch1, true);
682 strb(rscratch1, sampling_critical_section);
683 }
684
685 void InterpreterMacroAssembler::leave_jfr_critical_section() {
686 const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
687 strb(zr, sampling_critical_section);
688 }
689 #endif // INCLUDE_JFR
690
691 // Lock object
692 //
693 // Args:
694 // c_rarg1: BasicObjectLock to be used for locking
695 //
696 // Kills:
697 // r0
698 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, .. (param regs)
699 // rscratch1, rscratch2 (scratch regs)
700 void InterpreterMacroAssembler::lock_object(Register lock_reg)
701 {
702 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
703
704 const Register tmp = c_rarg2;
705 const Register obj_reg = c_rarg3; // Will contain the oop
706 const Register tmp2 = c_rarg4;
707 const Register tmp3 = c_rarg5;
708
709 // Load object pointer into obj_reg %c_rarg3
710 ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
711
712 Label slow_case, done;
713 fast_lock(lock_reg, obj_reg, tmp, tmp2, tmp3, slow_case);
714 b(done);
715
716 bind(slow_case);
717
718 // Call the runtime routine for slow case
719 call_VM_preemptable(noreg,
720 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
721 lock_reg);
722
723 bind(done);
724 }
725
726
727 // Unlocks an object. Used in monitorexit bytecode and
728 // remove_activation. Throws an IllegalMonitorException if object is
729 // not locked by current thread.
730 //
731 // Args:
732 // c_rarg1: BasicObjectLock for lock
733 //
734 // Kills:
735 // r0
736 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
737 // rscratch1, rscratch2 (scratch regs)
738 void InterpreterMacroAssembler::unlock_object(Register lock_reg)
739 {
740 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
741
742 const Register swap_reg = r0;
743 const Register header_reg = c_rarg2; // Will contain the old oopMark
744 const Register obj_reg = c_rarg3; // Will contain the oop
745 const Register tmp_reg = c_rarg4; // Temporary used by fast_unlock
746
747 save_bcp(); // Save in case of exception
748
749 // Load oop into obj_reg(%c_rarg3)
750 ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
751
752 // Free entry
753 str(zr, Address(lock_reg, BasicObjectLock::obj_offset()));
754
755 Label slow_case, done;
756 fast_unlock(obj_reg, header_reg, swap_reg, tmp_reg, slow_case);
757 b(done);
758
759 bind(slow_case);
760 // Call the runtime routine for slow case.
761 str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); // restore obj
762 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
763 bind(done);
764 restore_bcp();
765 }
766
767 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
768 Label& zero_continue) {
769 assert(ProfileInterpreter, "must be profiling interpreter");
770 ldr(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
771 cbz(mdp, zero_continue);
772 }
773
774 // Set the method data pointer for the current bcp.
775 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
776 assert(ProfileInterpreter, "must be profiling interpreter");
777 Label set_mdp;
778 stp(r0, r1, Address(pre(sp, -2 * wordSize)));
779
780 // Test MDO to avoid the call if it is null.
781 ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset())));
782 cbz(r0, set_mdp);
783 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp);
784 // r0: mdi
785 // mdo is guaranteed to be non-zero here, we checked for it before the call.
786 ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
787 lea(r1, Address(r1, in_bytes(MethodData::data_offset())));
788 add(r0, r1, r0);
789 str(r0, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
790 bind(set_mdp);
791 ldp(r0, r1, Address(post(sp, 2 * wordSize)));
792 }
793
794 void InterpreterMacroAssembler::verify_method_data_pointer() {
795 assert(ProfileInterpreter, "must be profiling interpreter");
796 #ifdef ASSERT
797 Label verify_continue;
798 stp(r0, r1, Address(pre(sp, -2 * wordSize)));
799 stp(r2, r3, Address(pre(sp, -2 * wordSize)));
800 test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue
801 get_method(r1);
802
803 // If the mdp is valid, it will point to a DataLayout header which is
804 // consistent with the bcp. The converse is highly probable also.
805 ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset())));
806 ldr(rscratch1, Address(r1, Method::const_offset()));
807 add(r2, r2, rscratch1, Assembler::LSL);
808 lea(r2, Address(r2, ConstMethod::codes_offset()));
809 cmp(r2, rbcp);
810 br(Assembler::EQ, verify_continue);
811 // r1: method
812 // rbcp: bcp // rbcp == 22
813 // r3: mdp
814 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
815 r1, rbcp, r3);
816 bind(verify_continue);
817 ldp(r2, r3, Address(post(sp, 2 * wordSize)));
818 ldp(r0, r1, Address(post(sp, 2 * wordSize)));
819 #endif // ASSERT
820 }
821
822
823 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
824 int constant,
825 Register value) {
826 assert(ProfileInterpreter, "must be profiling interpreter");
827 Address data(mdp_in, constant);
828 str(value, data);
829 }
830
831
832 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
833 int constant) {
834 increment_mdp_data_at(mdp_in, noreg, constant);
835 }
836
837 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
838 Register index,
839 int constant) {
840 assert(ProfileInterpreter, "must be profiling interpreter");
841
842 assert_different_registers(rscratch2, rscratch1, mdp_in, index);
843
844 Address addr1(mdp_in, constant);
845 Address addr2(rscratch2, index, Address::lsl(0));
846 Address &addr = addr1;
847 if (index != noreg) {
848 lea(rscratch2, addr1);
849 addr = addr2;
850 }
851
852 increment(addr, DataLayout::counter_increment);
853 }
854
855 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
856 int flag_byte_constant) {
857 assert(ProfileInterpreter, "must be profiling interpreter");
858 int flags_offset = in_bytes(DataLayout::flags_offset());
859 // Set the flag
860 ldrb(rscratch1, Address(mdp_in, flags_offset));
861 orr(rscratch1, rscratch1, flag_byte_constant);
862 strb(rscratch1, Address(mdp_in, flags_offset));
863 }
864
865
866 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
867 int offset,
868 Register value,
869 Register test_value_out,
870 Label& not_equal_continue) {
871 assert(ProfileInterpreter, "must be profiling interpreter");
872 if (test_value_out == noreg) {
873 ldr(rscratch1, Address(mdp_in, offset));
874 cmp(value, rscratch1);
875 } else {
876 // Put the test value into a register, so caller can use it:
877 ldr(test_value_out, Address(mdp_in, offset));
878 cmp(value, test_value_out);
879 }
880 br(Assembler::NE, not_equal_continue);
881 }
882
883
884 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
885 int offset_of_disp) {
886 assert(ProfileInterpreter, "must be profiling interpreter");
887 ldr(rscratch1, Address(mdp_in, offset_of_disp));
888 add(mdp_in, mdp_in, rscratch1, LSL);
889 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
890 }
891
892
893 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
894 Register reg,
895 int offset_of_disp) {
896 assert(ProfileInterpreter, "must be profiling interpreter");
897 lea(rscratch1, Address(mdp_in, offset_of_disp));
898 ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0)));
899 add(mdp_in, mdp_in, rscratch1, LSL);
900 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
901 }
902
903
904 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
905 int constant) {
906 assert(ProfileInterpreter, "must be profiling interpreter");
907 add(mdp_in, mdp_in, (unsigned)constant);
908 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
909 }
910
911
912 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
913 assert(ProfileInterpreter, "must be profiling interpreter");
914 // save/restore across call_VM
915 stp(zr, return_bci, Address(pre(sp, -2 * wordSize)));
916 call_VM(noreg,
917 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
918 return_bci);
919 ldp(zr, return_bci, Address(post(sp, 2 * wordSize)));
920 }
921
922
923 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
924 if (ProfileInterpreter) {
925 Label profile_continue;
926
927 // If no method data exists, go to profile_continue.
928 test_method_data_pointer(mdp, profile_continue);
929
930 // We are taking a branch. Increment the taken count.
931 increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
932
933 // The method data pointer needs to be updated to reflect the new target.
934 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
935 bind(profile_continue);
936 }
937 }
938
939
940 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
941 if (ProfileInterpreter) {
942 Label profile_continue;
943
944 // If no method data exists, go to profile_continue.
945 test_method_data_pointer(mdp, profile_continue);
946
947 // We are not taking a branch. Increment the not taken count.
948 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
949
950 // The method data pointer needs to be updated to correspond to
951 // the next bytecode
952 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
953 bind(profile_continue);
954 }
955 }
956
957
958 void InterpreterMacroAssembler::profile_call(Register mdp) {
959 if (ProfileInterpreter) {
960 Label profile_continue;
961
962 // If no method data exists, go to profile_continue.
963 test_method_data_pointer(mdp, profile_continue);
964
965 // We are making a call. Increment the count.
966 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
967
968 // The method data pointer needs to be updated to reflect the new target.
969 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
970 bind(profile_continue);
971 }
972 }
973
974 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
975 if (ProfileInterpreter) {
976 Label profile_continue;
977
978 // If no method data exists, go to profile_continue.
979 test_method_data_pointer(mdp, profile_continue);
980
981 // We are making a call. Increment the count.
982 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
983
984 // The method data pointer needs to be updated to reflect the new target.
985 update_mdp_by_constant(mdp,
986 in_bytes(VirtualCallData::
987 virtual_call_data_size()));
988 bind(profile_continue);
989 }
990 }
991
992
993 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
994 Register mdp,
995 Register reg2,
996 bool receiver_can_be_null) {
997 if (ProfileInterpreter) {
998 Label profile_continue;
999
1000 // If no method data exists, go to profile_continue.
1001 test_method_data_pointer(mdp, profile_continue);
1002
1003 Label skip_receiver_profile;
1004 if (receiver_can_be_null) {
1005 Label not_null;
1006 // We are making a call. Increment the count for null receiver.
1007 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1008 b(skip_receiver_profile);
1009 bind(not_null);
1010 }
1011
1012 // Record the receiver type.
1013 record_klass_in_profile(receiver, mdp, reg2);
1014 bind(skip_receiver_profile);
1015
1016 // The method data pointer needs to be updated to reflect the new target.
1017 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1018 bind(profile_continue);
1019 }
1020 }
1021
1022 // This routine creates a state machine for updating the multi-row
1023 // type profile at a virtual call site (or other type-sensitive bytecode).
1024 // The machine visits each row (of receiver/count) until the receiver type
1025 // is found, or until it runs out of rows. At the same time, it remembers
1026 // the location of the first empty row. (An empty row records null for its
1027 // receiver, and can be allocated for a newly-observed receiver type.)
1028 // Because there are two degrees of freedom in the state, a simple linear
1029 // search will not work; it must be a decision tree. Hence this helper
1030 // function is recursive, to generate the required tree structured code.
1031 // It's the interpreter, so we are trading off code space for speed.
1032 // See below for example code.
1033 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1034 Register receiver, Register mdp,
1035 Register reg2, int start_row,
1036 Label& done) {
1037 if (TypeProfileWidth == 0) {
1038 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1039 } else {
1040 record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1041 &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset);
1042 }
1043 }
1044
1045 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp,
1046 Register reg2, int start_row, Label& done, int total_rows,
1047 OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn) {
1048 int last_row = total_rows - 1;
1049 assert(start_row <= last_row, "must be work left to do");
1050 // Test this row for both the item and for null.
1051 // Take any of three different outcomes:
1052 // 1. found item => increment count and goto done
1053 // 2. found null => keep looking for case 1, maybe allocate this cell
1054 // 3. found something else => keep looking for cases 1 and 2
1055 // Case 3 is handled by a recursive call.
1056 for (int row = start_row; row <= last_row; row++) {
1057 Label next_test;
1058 bool test_for_null_also = (row == start_row);
1059
1060 // See if the item is item[n].
1061 int item_offset = in_bytes(item_offset_fn(row));
1062 test_mdp_data_at(mdp, item_offset, item,
1063 (test_for_null_also ? reg2 : noreg),
1064 next_test);
1065 // (Reg2 now contains the item from the CallData.)
1066
1067 // The item is item[n]. Increment count[n].
1068 int count_offset = in_bytes(item_count_offset_fn(row));
1069 increment_mdp_data_at(mdp, count_offset);
1070 b(done);
1071 bind(next_test);
1072
1073 if (test_for_null_also) {
1074 Label found_null;
1075 // Failed the equality check on item[n]... Test for null.
1076 if (start_row == last_row) {
1077 // The only thing left to do is handle the null case.
1078 cbz(reg2, found_null);
1079 // Item did not match any saved item and there is no empty row for it.
1080 // Increment total counter to indicate polymorphic case.
1081 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1082 b(done);
1083 bind(found_null);
1084 break;
1085 }
1086 // Since null is rare, make it be the branch-taken case.
1087 cbz(reg2, found_null);
1088
1089 // Put all the "Case 3" tests here.
1090 record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows,
1091 item_offset_fn, item_count_offset_fn);
1092
1093 // Found a null. Keep searching for a matching item,
1094 // but remember that this is an empty (unused) slot.
1095 bind(found_null);
1096 }
1097 }
1098
1099 // In the fall-through case, we found no matching item, but we
1100 // observed the item[start_row] is null.
1101
1102 // Fill in the item field and increment the count.
1103 int item_offset = in_bytes(item_offset_fn(start_row));
1104 set_mdp_data_at(mdp, item_offset, item);
1105 int count_offset = in_bytes(item_count_offset_fn(start_row));
1106 mov(reg2, DataLayout::counter_increment);
1107 set_mdp_data_at(mdp, count_offset, reg2);
1108 if (start_row > 0) {
1109 b(done);
1110 }
1111 }
1112
1113 // Example state machine code for three profile rows:
1114 // // main copy of decision tree, rooted at row[1]
1115 // if (row[0].rec == rec) { row[0].incr(); goto done; }
1116 // if (row[0].rec != nullptr) {
1117 // // inner copy of decision tree, rooted at row[1]
1118 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1119 // if (row[1].rec != nullptr) {
1120 // // degenerate decision tree, rooted at row[2]
1121 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1122 // if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow
1123 // row[2].init(rec); goto done;
1124 // } else {
1125 // // remember row[1] is empty
1126 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1127 // row[1].init(rec); goto done;
1128 // }
1129 // } else {
1130 // // remember row[0] is empty
1131 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1132 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1133 // row[0].init(rec); goto done;
1134 // }
1135 // done:
1136
1137 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1138 Register mdp, Register reg2) {
1139 assert(ProfileInterpreter, "must be profiling");
1140 Label done;
1141
1142 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
1143
1144 bind (done);
1145 }
1146
1147 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1148 Register mdp) {
1149 if (ProfileInterpreter) {
1150 Label profile_continue;
1151 uint row;
1152
1153 // If no method data exists, go to profile_continue.
1154 test_method_data_pointer(mdp, profile_continue);
1155
1156 // Update the total ret count.
1157 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1158
1159 for (row = 0; row < RetData::row_limit(); row++) {
1160 Label next_test;
1161
1162 // See if return_bci is equal to bci[n]:
1163 test_mdp_data_at(mdp,
1164 in_bytes(RetData::bci_offset(row)),
1165 return_bci, noreg,
1166 next_test);
1167
1168 // return_bci is equal to bci[n]. Increment the count.
1169 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1170
1171 // The method data pointer needs to be updated to reflect the new target.
1172 update_mdp_by_offset(mdp,
1173 in_bytes(RetData::bci_displacement_offset(row)));
1174 b(profile_continue);
1175 bind(next_test);
1176 }
1177
1178 update_mdp_for_ret(return_bci);
1179
1180 bind(profile_continue);
1181 }
1182 }
1183
1184 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1185 if (ProfileInterpreter) {
1186 Label profile_continue;
1187
1188 // If no method data exists, go to profile_continue.
1189 test_method_data_pointer(mdp, profile_continue);
1190
1191 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1192
1193 // The method data pointer needs to be updated.
1194 int mdp_delta = in_bytes(BitData::bit_data_size());
1195 if (TypeProfileCasts) {
1196 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1197 }
1198 update_mdp_by_constant(mdp, mdp_delta);
1199
1200 bind(profile_continue);
1201 }
1202 }
1203
1204 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1205 if (ProfileInterpreter) {
1206 Label profile_continue;
1207
1208 // If no method data exists, go to profile_continue.
1209 test_method_data_pointer(mdp, profile_continue);
1210
1211 // The method data pointer needs to be updated.
1212 int mdp_delta = in_bytes(BitData::bit_data_size());
1213 if (TypeProfileCasts) {
1214 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1215
1216 // Record the object type.
1217 record_klass_in_profile(klass, mdp, reg2);
1218 }
1219 update_mdp_by_constant(mdp, mdp_delta);
1220
1221 bind(profile_continue);
1222 }
1223 }
1224
1225 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1226 if (ProfileInterpreter) {
1227 Label profile_continue;
1228
1229 // If no method data exists, go to profile_continue.
1230 test_method_data_pointer(mdp, profile_continue);
1231
1232 // Update the default case count
1233 increment_mdp_data_at(mdp,
1234 in_bytes(MultiBranchData::default_count_offset()));
1235
1236 // The method data pointer needs to be updated.
1237 update_mdp_by_offset(mdp,
1238 in_bytes(MultiBranchData::
1239 default_displacement_offset()));
1240
1241 bind(profile_continue);
1242 }
1243 }
1244
1245 void InterpreterMacroAssembler::profile_switch_case(Register index,
1246 Register mdp,
1247 Register reg2) {
1248 if (ProfileInterpreter) {
1249 Label profile_continue;
1250
1251 // If no method data exists, go to profile_continue.
1252 test_method_data_pointer(mdp, profile_continue);
1253
1254 // Build the base (index * per_case_size_in_bytes()) +
1255 // case_array_offset_in_bytes()
1256 movw(reg2, in_bytes(MultiBranchData::per_case_size()));
1257 movw(rscratch1, in_bytes(MultiBranchData::case_array_offset()));
1258 Assembler::maddw(index, index, reg2, rscratch1);
1259
1260 // Update the case count
1261 increment_mdp_data_at(mdp,
1262 index,
1263 in_bytes(MultiBranchData::relative_count_offset()));
1264
1265 // The method data pointer needs to be updated.
1266 update_mdp_by_offset(mdp,
1267 index,
1268 in_bytes(MultiBranchData::
1269 relative_displacement_offset()));
1270
1271 bind(profile_continue);
1272 }
1273 }
1274
1275 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1276 if (state == atos) {
1277 MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1278 }
1279 }
1280
1281 void InterpreterMacroAssembler::generate_runtime_upcalls_on_method_entry()
1282 {
1283 address upcall = RuntimeUpcalls::on_method_entry_upcall_address();
1284 if (RuntimeUpcalls::does_upcall_need_method_parameter(upcall)) {
1285 get_method(c_rarg1);
1286 call_VM(noreg,upcall, c_rarg1);
1287 } else {
1288 call_VM(noreg,upcall);
1289 }
1290 }
1291
1292 void InterpreterMacroAssembler::notify_method_entry() {
1293 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1294 // track stack depth. If it is possible to enter interp_only_mode we add
1295 // the code to check if the event should be sent.
1296 if (JvmtiExport::can_post_interpreter_events()) {
1297 Label L;
1298 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1299 cbzw(r3, L);
1300 call_VM(noreg, CAST_FROM_FN_PTR(address,
1301 InterpreterRuntime::post_method_entry));
1302 bind(L);
1303 }
1304
1305 if (DTraceMethodProbes) {
1306 get_method(c_rarg1);
1307 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1308 rthread, c_rarg1);
1309 }
1310
1311 // RedefineClasses() tracing support for obsolete method entry
1312 if (log_is_enabled(Trace, redefine, class, obsolete) ||
1313 log_is_enabled(Trace, interpreter, bytecode)) {
1314 get_method(c_rarg1);
1315 call_VM_leaf(
1316 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1317 rthread, c_rarg1);
1318 }
1319
1320 }
1321
1322
1323 void InterpreterMacroAssembler::notify_method_exit(
1324 TosState state, NotifyMethodExitMode mode) {
1325 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1326 // track stack depth. If it is possible to enter interp_only_mode we add
1327 // the code to check if the event should be sent.
1328 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1329 Label L;
1330 // Note: frame::interpreter_frame_result has a dependency on how the
1331 // method result is saved across the call to post_method_exit. If this
1332 // is changed then the interpreter_frame_result implementation will
1333 // need to be updated too.
1334
1335 // template interpreter will leave the result on the top of the stack.
1336 push(state);
1337 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1338 cbz(r3, L);
1339 call_VM(noreg,
1340 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1341 bind(L);
1342 pop(state);
1343 }
1344
1345 if (DTraceMethodProbes) {
1346 push(state);
1347 get_method(c_rarg1);
1348 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1349 rthread, c_rarg1);
1350 pop(state);
1351 }
1352 }
1353
1354
1355 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1356 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1357 int increment, Address mask,
1358 Register scratch, Register scratch2,
1359 bool preloaded, Condition cond,
1360 Label* where) {
1361 if (!preloaded) {
1362 ldrw(scratch, counter_addr);
1363 }
1364 add(scratch, scratch, increment);
1365 strw(scratch, counter_addr);
1366 ldrw(scratch2, mask);
1367 ands(scratch, scratch, scratch2);
1368 br(cond, *where);
1369 }
1370
1371 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
1372 int number_of_arguments) {
1373 // interpreter specific
1374 //
1375 // Note: No need to save/restore rbcp & rlocals pointer since these
1376 // are callee saved registers and no blocking/ GC can happen
1377 // in leaf calls.
1378 #ifdef ASSERT
1379 {
1380 Label L;
1381 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1382 cbz(rscratch1, L);
1383 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1384 " last_sp != nullptr");
1385 bind(L);
1386 }
1387 #endif /* ASSERT */
1388 // super call
1389 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
1390 }
1391
1392 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
1393 Register java_thread,
1394 Register last_java_sp,
1395 Label* return_pc,
1396 address entry_point,
1397 int number_of_arguments,
1398 bool check_exceptions) {
1399 // interpreter specific
1400 //
1401 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
1402 // really make a difference for these runtime calls, since they are
1403 // slow anyway. Btw., bcp must be saved/restored since it may change
1404 // due to GC.
1405 // assert(java_thread == noreg , "not expecting a precomputed java thread");
1406 save_bcp();
1407 #ifdef ASSERT
1408 {
1409 Label L;
1410 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1411 cbz(rscratch1, L);
1412 stop("InterpreterMacroAssembler::call_VM_base:"
1413 " last_sp != nullptr");
1414 bind(L);
1415 }
1416 #endif /* ASSERT */
1417 // super call
1418 MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
1419 return_pc, entry_point,
1420 number_of_arguments, check_exceptions);
1421 // interpreter specific
1422 restore_bcp();
1423 restore_locals();
1424 }
1425
1426 void InterpreterMacroAssembler::call_VM_preemptable_helper(Register oop_result,
1427 address entry_point,
1428 int number_of_arguments,
1429 bool check_exceptions) {
1430 assert(InterpreterRuntime::is_preemptable_call(entry_point), "VM call not preemptable, should use call_VM()");
1431 Label resume_pc, not_preempted;
1432
1433 #ifdef ASSERT
1434 {
1435 Label L1, L2;
1436 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1437 cbz(rscratch1, L1);
1438 stop("call_VM_preemptable_helper: Should not have alternate return address set");
1439 bind(L1);
1440 // We check this counter in patch_return_pc_with_preempt_stub() during freeze.
1441 incrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1442 ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1443 cmpw(rscratch1, 0);
1444 br(Assembler::GT, L2);
1445 stop("call_VM_preemptable_helper: should be > 0");
1446 bind(L2);
1447 }
1448 #endif /* ASSERT */
1449
1450 // Force freeze slow path.
1451 push_cont_fastpath();
1452
1453 // Make VM call. In case of preemption set last_pc to the one we want to resume to.
1454 // Note: call_VM_base will use resume_pc label to set last_Java_pc.
1455 call_VM_base(noreg, noreg, noreg, &resume_pc, entry_point, number_of_arguments, false /*check_exceptions*/);
1456
1457 pop_cont_fastpath();
1458
1459 #ifdef ASSERT
1460 {
1461 Label L;
1462 decrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1463 ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1464 cmpw(rscratch1, 0);
1465 br(Assembler::GE, L);
1466 stop("call_VM_preemptable_helper: should be >= 0");
1467 bind(L);
1468 }
1469 #endif /* ASSERT */
1470
1471 // Check if preempted.
1472 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1473 cbz(rscratch1, not_preempted);
1474 str(zr, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1475 br(rscratch1);
1476
1477 // In case of preemption, this is where we will resume once we finally acquire the monitor.
1478 bind(resume_pc);
1479 restore_after_resume(false /* is_native */);
1480
1481 bind(not_preempted);
1482 if (check_exceptions) {
1483 // check for pending exceptions
1484 ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset())));
1485 Label ok;
1486 cbz(rscratch1, ok);
1487 lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry()));
1488 br(rscratch1);
1489 bind(ok);
1490 }
1491
1492 // get oop result if there is one and reset the value in the thread
1493 if (oop_result->is_valid()) {
1494 get_vm_result_oop(oop_result, rthread);
1495 }
1496 }
1497
1498 static void pass_arg1(MacroAssembler* masm, Register arg) {
1499 if (c_rarg1 != arg ) {
1500 masm->mov(c_rarg1, arg);
1501 }
1502 }
1503
1504 static void pass_arg2(MacroAssembler* masm, Register arg) {
1505 if (c_rarg2 != arg ) {
1506 masm->mov(c_rarg2, arg);
1507 }
1508 }
1509
1510 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1511 address entry_point,
1512 Register arg_1,
1513 bool check_exceptions) {
1514 pass_arg1(this, arg_1);
1515 call_VM_preemptable_helper(oop_result, entry_point, 1, check_exceptions);
1516 }
1517
1518 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1519 address entry_point,
1520 Register arg_1,
1521 Register arg_2,
1522 bool check_exceptions) {
1523 LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
1524 pass_arg2(this, arg_2);
1525 pass_arg1(this, arg_1);
1526 call_VM_preemptable_helper(oop_result, entry_point, 2, check_exceptions);
1527 }
1528
1529 void InterpreterMacroAssembler::restore_after_resume(bool is_native) {
1530 lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter()));
1531 blr(rscratch1);
1532 if (is_native) {
1533 // On resume we need to set up stack as expected
1534 push(dtos);
1535 push(ltos);
1536 }
1537 }
1538
1539 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1540 assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index());
1541 Label update, next, none;
1542
1543 verify_oop(obj);
1544
1545 cbnz(obj, update);
1546 orptr(mdo_addr, TypeEntries::null_seen);
1547 b(next);
1548
1549 bind(update);
1550 load_klass(obj, obj);
1551
1552 ldr(rscratch1, mdo_addr);
1553 eor(obj, obj, rscratch1);
1554 tst(obj, TypeEntries::type_klass_mask);
1555 br(Assembler::EQ, next); // klass seen before, nothing to
1556 // do. The unknown bit may have been
1557 // set already but no need to check.
1558
1559 tbnz(obj, exact_log2(TypeEntries::type_unknown), next);
1560 // already unknown. Nothing to do anymore.
1561
1562 cbz(rscratch1, none);
1563 cmp(rscratch1, (u1)TypeEntries::null_seen);
1564 br(Assembler::EQ, none);
1565 // There is a chance that the checks above
1566 // fail if another thread has just set the
1567 // profiling to this obj's klass
1568 eor(obj, obj, rscratch1); // get back original value before XOR
1569 ldr(rscratch1, mdo_addr);
1570 eor(obj, obj, rscratch1);
1571 tst(obj, TypeEntries::type_klass_mask);
1572 br(Assembler::EQ, next);
1573
1574 // different than before. Cannot keep accurate profile.
1575 orptr(mdo_addr, TypeEntries::type_unknown);
1576 b(next);
1577
1578 bind(none);
1579 // first time here. Set profile type.
1580 str(obj, mdo_addr);
1581 #ifdef ASSERT
1582 andr(obj, obj, TypeEntries::type_mask);
1583 verify_klass_ptr(obj);
1584 #endif
1585
1586 bind(next);
1587 }
1588
1589 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1590 if (!ProfileInterpreter) {
1591 return;
1592 }
1593
1594 if (MethodData::profile_arguments() || MethodData::profile_return()) {
1595 Label profile_continue;
1596
1597 test_method_data_pointer(mdp, profile_continue);
1598
1599 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1600
1601 ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start));
1602 cmp(rscratch1, u1(is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag));
1603 br(Assembler::NE, profile_continue);
1604
1605 if (MethodData::profile_arguments()) {
1606 Label done;
1607 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1608
1609 for (int i = 0; i < TypeProfileArgsLimit; i++) {
1610 if (i > 0 || MethodData::profile_return()) {
1611 // If return value type is profiled we may have no argument to profile
1612 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1613 sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count());
1614 cmp(tmp, (u1)TypeStackSlotEntries::per_arg_count());
1615 add(rscratch1, mdp, off_to_args);
1616 br(Assembler::LT, done);
1617 }
1618 ldr(tmp, Address(callee, Method::const_offset()));
1619 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
1620 // stack offset o (zero based) from the start of the argument
1621 // list, for n arguments translates into offset n - o - 1 from
1622 // the end of the argument list
1623 ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))));
1624 sub(tmp, tmp, rscratch1);
1625 sub(tmp, tmp, 1);
1626 Address arg_addr = argument_address(tmp);
1627 ldr(tmp, arg_addr);
1628
1629 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i)));
1630 profile_obj_type(tmp, mdo_arg_addr);
1631
1632 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1633 off_to_args += to_add;
1634 }
1635
1636 if (MethodData::profile_return()) {
1637 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1638 sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1639 }
1640
1641 add(rscratch1, mdp, off_to_args);
1642 bind(done);
1643 mov(mdp, rscratch1);
1644
1645 if (MethodData::profile_return()) {
1646 // We're right after the type profile for the last
1647 // argument. tmp is the number of cells left in the
1648 // CallTypeData/VirtualCallTypeData to reach its end. Non null
1649 // if there's a return to profile.
1650 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1651 add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size));
1652 }
1653 str(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
1654 } else {
1655 assert(MethodData::profile_return(), "either profile call args or call ret");
1656 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1657 }
1658
1659 // mdp points right after the end of the
1660 // CallTypeData/VirtualCallTypeData, right after the cells for the
1661 // return value type if there's one
1662
1663 bind(profile_continue);
1664 }
1665 }
1666
1667 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1668 assert_different_registers(mdp, ret, tmp, rbcp);
1669 if (ProfileInterpreter && MethodData::profile_return()) {
1670 Label profile_continue, done;
1671
1672 test_method_data_pointer(mdp, profile_continue);
1673
1674 if (MethodData::profile_return_jsr292_only()) {
1675 assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
1676
1677 // If we don't profile all invoke bytecodes we must make sure
1678 // it's a bytecode we indeed profile. We can't go back to the
1679 // beginning of the ProfileData we intend to update to check its
1680 // type because we're right after it and we don't known its
1681 // length
1682 Label do_profile;
1683 ldrb(rscratch1, Address(rbcp, 0));
1684 cmp(rscratch1, (u1)Bytecodes::_invokedynamic);
1685 br(Assembler::EQ, do_profile);
1686 cmp(rscratch1, (u1)Bytecodes::_invokehandle);
1687 br(Assembler::EQ, do_profile);
1688 get_method(tmp);
1689 ldrh(rscratch1, Address(tmp, Method::intrinsic_id_offset()));
1690 subs(zr, rscratch1, static_cast<int>(vmIntrinsics::_compiledLambdaForm));
1691 br(Assembler::NE, profile_continue);
1692
1693 bind(do_profile);
1694 }
1695
1696 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
1697 mov(tmp, ret);
1698 profile_obj_type(tmp, mdo_ret_addr);
1699
1700 bind(profile_continue);
1701 }
1702 }
1703
1704 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1705 assert_different_registers(rscratch1, rscratch2, mdp, tmp1, tmp2);
1706 if (ProfileInterpreter && MethodData::profile_parameters()) {
1707 Label profile_continue, done;
1708
1709 test_method_data_pointer(mdp, profile_continue);
1710
1711 // Load the offset of the area within the MDO used for
1712 // parameters. If it's negative we're not profiling any parameters
1713 ldrw(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
1714 tbnz(tmp1, 31, profile_continue); // i.e. sign bit set
1715
1716 // Compute a pointer to the area for parameters from the offset
1717 // and move the pointer to the slot for the last
1718 // parameters. Collect profiling from last parameter down.
1719 // mdo start + parameters offset + array length - 1
1720 add(mdp, mdp, tmp1);
1721 ldr(tmp1, Address(mdp, ArrayData::array_len_offset()));
1722 sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1723
1724 Label loop;
1725 bind(loop);
1726
1727 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1728 int type_base = in_bytes(ParametersTypeData::type_offset(0));
1729 int per_arg_scale = exact_log2(DataLayout::cell_size);
1730 add(rscratch1, mdp, off_base);
1731 add(rscratch2, mdp, type_base);
1732
1733 Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale));
1734 Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale));
1735
1736 // load offset on the stack from the slot for this parameter
1737 ldr(tmp2, arg_off);
1738 neg(tmp2, tmp2);
1739 // read the parameter from the local area
1740 ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize)));
1741
1742 // profile the parameter
1743 profile_obj_type(tmp2, arg_type);
1744
1745 // go to next parameter
1746 subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1747 br(Assembler::GE, loop);
1748
1749 bind(profile_continue);
1750 }
1751 }
1752
1753 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
1754 // Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp
1755 get_cache_index_at_bcp(index, 1, sizeof(u4));
1756 // Get address of invokedynamic array
1757 ldr(cache, Address(rcpool, in_bytes(ConstantPoolCache::invokedynamic_entries_offset())));
1758 // Scale the index to be the entry index * sizeof(ResolvedIndyEntry)
1759 lsl(index, index, log2i_exact(sizeof(ResolvedIndyEntry)));
1760 add(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes());
1761 lea(cache, Address(cache, index));
1762 }
1763
1764 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) {
1765 // Get index out of bytecode pointer
1766 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1767 // Take shortcut if the size is a power of 2
1768 if (is_power_of_2(sizeof(ResolvedFieldEntry))) {
1769 lsl(index, index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2
1770 } else {
1771 mov(cache, sizeof(ResolvedFieldEntry));
1772 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry)
1773 }
1774 // Get address of field entries array
1775 ldr(cache, Address(rcpool, ConstantPoolCache::field_entries_offset()));
1776 add(cache, cache, Array<ResolvedFieldEntry>::base_offset_in_bytes());
1777 lea(cache, Address(cache, index));
1778 // Prevents stale data from being read after the bytecode is patched to the fast bytecode
1779 membar(MacroAssembler::LoadLoad);
1780 }
1781
1782 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) {
1783 // Get index out of bytecode pointer
1784 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1785 mov(cache, sizeof(ResolvedMethodEntry));
1786 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry)
1787
1788 // Get address of field entries array
1789 ldr(cache, Address(rcpool, ConstantPoolCache::method_entries_offset()));
1790 add(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes());
1791 lea(cache, Address(cache, index));
1792 }
1793
1794 #ifdef ASSERT
1795 void InterpreterMacroAssembler::verify_field_offset(Register reg) {
1796 // Verify the field offset is not in the header, implicitly checks for 0
1797 Label L;
1798 subs(zr, reg, oopDesc::base_offset_in_bytes());
1799 br(Assembler::GE, L);
1800 stop("bad field offset");
1801 bind(L);
1802 }
1803 #endif