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