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/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 #ifdef ASSERT
738 // TODO 8284443 Enable
739 if (StressCallingConvention && false) {
740 Label skip_stress;
741 ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
742 ldrw(rscratch1, Address(rscratch1, Method::flags_offset()));
743 tstw(rscratch1, MethodFlags::has_scalarized_return_flag());
744 br(Assembler::EQ, skip_stress);
745 load_klass(r0, r0);
746 orr(r0, r0, 1);
747 bind(skip_stress);
748 }
749 #endif
750 bind(skip);
751 // Check above kills sender esp in rscratch2. Reload it.
752 ldr(rscratch2, Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
753 }
754
755 // remove frame anchor
756 leave();
757
758 JFR_ONLY(leave_jfr_critical_section();)
759
760 // restore sender esp
761 mov(esp, rscratch2);
762
763 // If we're returning to interpreted code we will shortly be
764 // adjusting SP to allow some space for ESP. If we're returning to
765 // compiled code the saved sender SP was saved in sender_sp, so this
766 // restores it.
767 andr(sp, esp, -16);
768 }
769
770 #if INCLUDE_JFR
771 void InterpreterMacroAssembler::enter_jfr_critical_section() {
772 const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
773 mov(rscratch1, true);
774 strb(rscratch1, sampling_critical_section);
775 }
776
777 void InterpreterMacroAssembler::leave_jfr_critical_section() {
778 const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
779 strb(zr, sampling_critical_section);
780 }
781 #endif // INCLUDE_JFR
782
783 // Lock object
784 //
785 // Args:
786 // c_rarg1: BasicObjectLock to be used for locking
787 //
788 // Kills:
789 // r0
790 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, .. (param regs)
791 // rscratch1, rscratch2 (scratch regs)
792 void InterpreterMacroAssembler::lock_object(Register lock_reg)
793 {
794 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
795
796 const Register tmp = c_rarg2;
797 const Register obj_reg = c_rarg3; // Will contain the oop
798 const Register tmp2 = c_rarg4;
799 const Register tmp3 = c_rarg5;
800
801 // Load object pointer into obj_reg %c_rarg3
802 ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
803
804 Label slow_case, done;
805 fast_lock(lock_reg, obj_reg, tmp, tmp2, tmp3, slow_case);
806 b(done);
807
808 bind(slow_case);
809
810 // Call the runtime routine for slow case
811 call_VM_preemptable(noreg,
812 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
813 lock_reg);
814
815 bind(done);
816 }
817
818
819 // Unlocks an object. Used in monitorexit bytecode and
820 // remove_activation. Throws an IllegalMonitorException if object is
821 // not locked by current thread.
822 //
823 // Args:
824 // c_rarg1: BasicObjectLock for lock
825 //
826 // Kills:
827 // r0
828 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
829 // rscratch1, rscratch2 (scratch regs)
830 void InterpreterMacroAssembler::unlock_object(Register lock_reg)
831 {
832 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
833
834 const Register swap_reg = r0;
835 const Register header_reg = c_rarg2; // Will contain the old oopMark
836 const Register obj_reg = c_rarg3; // Will contain the oop
837 const Register tmp_reg = c_rarg4; // Temporary used by fast_unlock
838
839 save_bcp(); // Save in case of exception
840
841 // Load oop into obj_reg(%c_rarg3)
842 ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
843
844 // Free entry
845 str(zr, Address(lock_reg, BasicObjectLock::obj_offset()));
846
847 Label slow_case, done;
848 fast_unlock(obj_reg, header_reg, swap_reg, tmp_reg, slow_case);
849 b(done);
850
851 bind(slow_case);
852 // Call the runtime routine for slow case.
853 str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); // restore obj
854 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
855 bind(done);
856 restore_bcp();
857 }
858
859 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
860 Label& zero_continue) {
861 assert(ProfileInterpreter, "must be profiling interpreter");
862 ldr(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
863 cbz(mdp, zero_continue);
864 }
865
866 // Set the method data pointer for the current bcp.
867 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
868 assert(ProfileInterpreter, "must be profiling interpreter");
869 Label set_mdp;
870 stp(r0, r1, Address(pre(sp, -2 * wordSize)));
871
872 // Test MDO to avoid the call if it is null.
873 ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset())));
874 cbz(r0, set_mdp);
875 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp);
876 // r0: mdi
877 // mdo is guaranteed to be non-zero here, we checked for it before the call.
878 ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
879 lea(r1, Address(r1, in_bytes(MethodData::data_offset())));
880 add(r0, r1, r0);
881 str(r0, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
882 bind(set_mdp);
883 ldp(r0, r1, Address(post(sp, 2 * wordSize)));
884 }
885
886 void InterpreterMacroAssembler::verify_method_data_pointer() {
887 assert(ProfileInterpreter, "must be profiling interpreter");
888 #ifdef ASSERT
889 Label verify_continue;
890 stp(r0, r1, Address(pre(sp, -2 * wordSize)));
891 stp(r2, r3, Address(pre(sp, -2 * wordSize)));
892 test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue
893 get_method(r1);
894
895 // If the mdp is valid, it will point to a DataLayout header which is
896 // consistent with the bcp. The converse is highly probable also.
897 ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset())));
898 ldr(rscratch1, Address(r1, Method::const_offset()));
899 add(r2, r2, rscratch1, Assembler::LSL);
900 lea(r2, Address(r2, ConstMethod::codes_offset()));
901 cmp(r2, rbcp);
902 br(Assembler::EQ, verify_continue);
903 // r1: method
904 // rbcp: bcp // rbcp == 22
905 // r3: mdp
906 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
907 r1, rbcp, r3);
908 bind(verify_continue);
909 ldp(r2, r3, Address(post(sp, 2 * wordSize)));
910 ldp(r0, r1, Address(post(sp, 2 * wordSize)));
911 #endif // ASSERT
912 }
913
914
915 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
916 int constant,
917 Register value) {
918 assert(ProfileInterpreter, "must be profiling interpreter");
919 Address data(mdp_in, constant);
920 str(value, data);
921 }
922
923
924 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
925 int constant) {
926 increment_mdp_data_at(mdp_in, noreg, constant);
927 }
928
929 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
930 Register index,
931 int constant) {
932 assert(ProfileInterpreter, "must be profiling interpreter");
933
934 assert_different_registers(rscratch2, rscratch1, mdp_in, index);
935
936 Address addr1(mdp_in, constant);
937 Address addr2(rscratch2, index, Address::lsl(0));
938 Address &addr = addr1;
939 if (index != noreg) {
940 lea(rscratch2, addr1);
941 addr = addr2;
942 }
943
944 increment(addr, DataLayout::counter_increment);
945 }
946
947 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
948 int flag_byte_constant) {
949 assert(ProfileInterpreter, "must be profiling interpreter");
950 int flags_offset = in_bytes(DataLayout::flags_offset());
951 // Set the flag
952 ldrb(rscratch1, Address(mdp_in, flags_offset));
953 orr(rscratch1, rscratch1, flag_byte_constant);
954 strb(rscratch1, Address(mdp_in, flags_offset));
955 }
956
957
958 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
959 int offset,
960 Register value,
961 Register test_value_out,
962 Label& not_equal_continue) {
963 assert(ProfileInterpreter, "must be profiling interpreter");
964 if (test_value_out == noreg) {
965 ldr(rscratch1, Address(mdp_in, offset));
966 cmp(value, rscratch1);
967 } else {
968 // Put the test value into a register, so caller can use it:
969 ldr(test_value_out, Address(mdp_in, offset));
970 cmp(value, test_value_out);
971 }
972 br(Assembler::NE, not_equal_continue);
973 }
974
975
976 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
977 int offset_of_disp) {
978 assert(ProfileInterpreter, "must be profiling interpreter");
979 ldr(rscratch1, Address(mdp_in, offset_of_disp));
980 add(mdp_in, mdp_in, rscratch1, LSL);
981 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
982 }
983
984
985 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
986 Register reg,
987 int offset_of_disp) {
988 assert(ProfileInterpreter, "must be profiling interpreter");
989 lea(rscratch1, Address(mdp_in, offset_of_disp));
990 ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0)));
991 add(mdp_in, mdp_in, rscratch1, LSL);
992 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
993 }
994
995
996 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
997 int constant) {
998 assert(ProfileInterpreter, "must be profiling interpreter");
999 add(mdp_in, mdp_in, (unsigned)constant);
1000 str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
1001 }
1002
1003
1004 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1005 assert(ProfileInterpreter, "must be profiling interpreter");
1006 // save/restore across call_VM
1007 stp(zr, return_bci, Address(pre(sp, -2 * wordSize)));
1008 call_VM(noreg,
1009 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1010 return_bci);
1011 ldp(zr, return_bci, Address(post(sp, 2 * wordSize)));
1012 }
1013
1014
1015 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
1016 if (ProfileInterpreter) {
1017 Label profile_continue;
1018
1019 // If no method data exists, go to profile_continue.
1020 test_method_data_pointer(mdp, profile_continue);
1021
1022 // We are taking a branch. Increment the taken count.
1023 increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1024
1025 // The method data pointer needs to be updated to reflect the new target.
1026 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1027 bind(profile_continue);
1028 }
1029 }
1030
1031
1032 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1033 if (ProfileInterpreter) {
1034 Label profile_continue;
1035
1036 // If no method data exists, go to profile_continue.
1037 test_method_data_pointer(mdp, profile_continue);
1038
1039 // We are not taking a branch. Increment the not taken count.
1040 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1041
1042 // The method data pointer needs to be updated to correspond to
1043 // the next bytecode
1044 update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()) : in_bytes(BranchData::branch_data_size()));
1045 bind(profile_continue);
1046 }
1047 }
1048
1049
1050 void InterpreterMacroAssembler::profile_call(Register mdp) {
1051 if (ProfileInterpreter) {
1052 Label profile_continue;
1053
1054 // If no method data exists, go to profile_continue.
1055 test_method_data_pointer(mdp, profile_continue);
1056
1057 // We are making a call. Increment the count.
1058 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1059
1060 // The method data pointer needs to be updated to reflect the new target.
1061 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1062 bind(profile_continue);
1063 }
1064 }
1065
1066 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1067 if (ProfileInterpreter) {
1068 Label profile_continue;
1069
1070 // If no method data exists, go to profile_continue.
1071 test_method_data_pointer(mdp, profile_continue);
1072
1073 // We are making a call. Increment the count.
1074 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1075
1076 // The method data pointer needs to be updated to reflect the new target.
1077 update_mdp_by_constant(mdp,
1078 in_bytes(VirtualCallData::
1079 virtual_call_data_size()));
1080 bind(profile_continue);
1081 }
1082 }
1083
1084
1085 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1086 Register mdp,
1087 bool receiver_can_be_null) {
1088 if (ProfileInterpreter) {
1089 Label profile_continue;
1090
1091 // If no method data exists, go to profile_continue.
1092 test_method_data_pointer(mdp, profile_continue);
1093
1094 Label skip_receiver_profile;
1095 if (receiver_can_be_null) {
1096 Label not_null;
1097 // We are making a call. Increment the count for null receiver.
1098 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1099 b(skip_receiver_profile);
1100 bind(not_null);
1101 }
1102
1103 // Record the receiver type.
1104 profile_receiver_type(receiver, mdp, 0);
1105 bind(skip_receiver_profile);
1106
1107 // The method data pointer needs to be updated to reflect the new target.
1108 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1109 bind(profile_continue);
1110 }
1111 }
1112
1113 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1114 Register mdp) {
1115 if (ProfileInterpreter) {
1116 Label profile_continue;
1117 uint row;
1118
1119 // If no method data exists, go to profile_continue.
1120 test_method_data_pointer(mdp, profile_continue);
1121
1122 // Update the total ret count.
1123 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1124
1125 for (row = 0; row < RetData::row_limit(); row++) {
1126 Label next_test;
1127
1128 // See if return_bci is equal to bci[n]:
1129 test_mdp_data_at(mdp,
1130 in_bytes(RetData::bci_offset(row)),
1131 return_bci, noreg,
1132 next_test);
1133
1134 // return_bci is equal to bci[n]. Increment the count.
1135 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1136
1137 // The method data pointer needs to be updated to reflect the new target.
1138 update_mdp_by_offset(mdp,
1139 in_bytes(RetData::bci_displacement_offset(row)));
1140 b(profile_continue);
1141 bind(next_test);
1142 }
1143
1144 update_mdp_for_ret(return_bci);
1145
1146 bind(profile_continue);
1147 }
1148 }
1149
1150 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1151 if (ProfileInterpreter) {
1152 Label profile_continue;
1153
1154 // If no method data exists, go to profile_continue.
1155 test_method_data_pointer(mdp, profile_continue);
1156
1157 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1158
1159 // The method data pointer needs to be updated.
1160 int mdp_delta = in_bytes(BitData::bit_data_size());
1161 if (TypeProfileCasts) {
1162 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1163 }
1164 update_mdp_by_constant(mdp, mdp_delta);
1165
1166 bind(profile_continue);
1167 }
1168 }
1169
1170 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass) {
1171 if (ProfileInterpreter) {
1172 Label profile_continue;
1173
1174 // If no method data exists, go to profile_continue.
1175 test_method_data_pointer(mdp, profile_continue);
1176
1177 // The method data pointer needs to be updated.
1178 int mdp_delta = in_bytes(BitData::bit_data_size());
1179 if (TypeProfileCasts) {
1180 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1181
1182 // Record the object type.
1183 profile_receiver_type(klass, mdp, 0);
1184 }
1185 update_mdp_by_constant(mdp, mdp_delta);
1186
1187 bind(profile_continue);
1188 }
1189 }
1190
1191 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1192 if (ProfileInterpreter) {
1193 Label profile_continue;
1194
1195 // If no method data exists, go to profile_continue.
1196 test_method_data_pointer(mdp, profile_continue);
1197
1198 // Update the default case count
1199 increment_mdp_data_at(mdp,
1200 in_bytes(MultiBranchData::default_count_offset()));
1201
1202 // The method data pointer needs to be updated.
1203 update_mdp_by_offset(mdp,
1204 in_bytes(MultiBranchData::
1205 default_displacement_offset()));
1206
1207 bind(profile_continue);
1208 }
1209 }
1210
1211 void InterpreterMacroAssembler::profile_switch_case(Register index,
1212 Register mdp,
1213 Register reg2) {
1214 if (ProfileInterpreter) {
1215 Label profile_continue;
1216
1217 // If no method data exists, go to profile_continue.
1218 test_method_data_pointer(mdp, profile_continue);
1219
1220 // Build the base (index * per_case_size_in_bytes()) +
1221 // case_array_offset_in_bytes()
1222 movw(reg2, in_bytes(MultiBranchData::per_case_size()));
1223 movw(rscratch1, in_bytes(MultiBranchData::case_array_offset()));
1224 Assembler::maddw(index, index, reg2, rscratch1);
1225
1226 // Update the case count
1227 increment_mdp_data_at(mdp,
1228 index,
1229 in_bytes(MultiBranchData::relative_count_offset()));
1230
1231 // The method data pointer needs to be updated.
1232 update_mdp_by_offset(mdp,
1233 index,
1234 in_bytes(MultiBranchData::
1235 relative_displacement_offset()));
1236
1237 bind(profile_continue);
1238 }
1239 }
1240
1241 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
1242 Register array,
1243 Register tmp) {
1244 if (ProfileInterpreter) {
1245 Label profile_continue;
1246
1247 // If no method data exists, go to profile_continue.
1248 test_method_data_pointer(mdp, profile_continue);
1249
1250 mov(tmp, array);
1251 profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
1252
1253 Label not_flat;
1254 test_non_flat_array_oop(array, tmp, not_flat);
1255
1256 set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
1257
1258 bind(not_flat);
1259
1260 Label not_null_free;
1261 test_non_null_free_array_oop(array, tmp, not_null_free);
1262
1263 set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
1264
1265 bind(not_null_free);
1266
1267 bind(profile_continue);
1268 }
1269 }
1270
1271 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
1272 Register array,
1273 Register tmp);
1274 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
1275 Register array,
1276 Register tmp);
1277
1278 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
1279 if (ProfileInterpreter) {
1280 Label profile_continue;
1281
1282 // If no method data exists, go to profile_continue.
1283 test_method_data_pointer(mdp, profile_continue);
1284
1285 Label done, update;
1286 cbnz(element, update);
1287 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1288 b(done);
1289
1290 bind(update);
1291 load_klass(tmp, element);
1292
1293 // Record the object type.
1294 profile_receiver_type(tmp, mdp, 0);
1295
1296 bind(done);
1297
1298 // The method data pointer needs to be updated.
1299 update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
1300
1301 bind(profile_continue);
1302 }
1303 }
1304
1305
1306 void InterpreterMacroAssembler::profile_element_type(Register mdp,
1307 Register element,
1308 Register tmp) {
1309 if (ProfileInterpreter) {
1310 Label profile_continue;
1311
1312 // If no method data exists, go to profile_continue.
1313 test_method_data_pointer(mdp, profile_continue);
1314
1315 mov(tmp, element);
1316 profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
1317
1318 // The method data pointer needs to be updated.
1319 update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
1320
1321 bind(profile_continue);
1322 }
1323 }
1324
1325 void InterpreterMacroAssembler::profile_acmp(Register mdp,
1326 Register left,
1327 Register right,
1328 Register tmp) {
1329 if (ProfileInterpreter) {
1330 Label profile_continue;
1331
1332 // If no method data exists, go to profile_continue.
1333 test_method_data_pointer(mdp, profile_continue);
1334
1335 mov(tmp, left);
1336 profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
1337
1338 Label left_not_inline_type;
1339 test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
1340 set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
1341 bind(left_not_inline_type);
1342
1343 mov(tmp, right);
1344 profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
1345
1346 Label right_not_inline_type;
1347 test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
1348 set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
1349 bind(right_not_inline_type);
1350
1351 bind(profile_continue);
1352 }
1353 }
1354
1355 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1356 if (state == atos) {
1357 MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1358 }
1359 }
1360
1361 void InterpreterMacroAssembler::notify_method_entry() {
1362 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1363 // track stack depth. If it is possible to enter interp_only_mode we add
1364 // the code to check if the event should be sent.
1365 if (JvmtiExport::can_post_interpreter_events()) {
1366 Label L;
1367 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1368 cbzw(r3, L);
1369 call_VM(noreg, CAST_FROM_FN_PTR(address,
1370 InterpreterRuntime::post_method_entry));
1371 bind(L);
1372 }
1373
1374 if (DTraceMethodProbes) {
1375 get_method(c_rarg1);
1376 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1377 rthread, c_rarg1);
1378 }
1379
1380 // RedefineClasses() tracing support for obsolete method entry
1381 if (log_is_enabled(Trace, redefine, class, obsolete)) {
1382 get_method(c_rarg1);
1383 call_VM_leaf(
1384 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1385 rthread, c_rarg1);
1386 }
1387
1388 }
1389
1390
1391 void InterpreterMacroAssembler::notify_method_exit(
1392 TosState state, NotifyMethodExitMode mode) {
1393 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1394 // track stack depth. If it is possible to enter interp_only_mode we add
1395 // the code to check if the event should be sent.
1396 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1397 Label L;
1398 // Note: frame::interpreter_frame_result has a dependency on how the
1399 // method result is saved across the call to post_method_exit. If this
1400 // is changed then the interpreter_frame_result implementation will
1401 // need to be updated too.
1402
1403 // template interpreter will leave the result on the top of the stack.
1404 push(state);
1405 ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1406 cbz(r3, L);
1407 call_VM(noreg,
1408 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1409 bind(L);
1410 pop(state);
1411 }
1412
1413 if (DTraceMethodProbes) {
1414 push(state);
1415 get_method(c_rarg1);
1416 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1417 rthread, c_rarg1);
1418 pop(state);
1419 }
1420 }
1421
1422
1423 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1424 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1425 int increment, Address mask,
1426 Register scratch, Register scratch2,
1427 bool preloaded, Condition cond,
1428 Label* where) {
1429 if (!preloaded) {
1430 ldrw(scratch, counter_addr);
1431 }
1432 add(scratch, scratch, increment);
1433 strw(scratch, counter_addr);
1434 ldrw(scratch2, mask);
1435 ands(scratch, scratch, scratch2);
1436 br(cond, *where);
1437 }
1438
1439 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
1440 int number_of_arguments) {
1441 // interpreter specific
1442 //
1443 // Note: No need to save/restore rbcp & rlocals pointer since these
1444 // are callee saved registers and no blocking/ GC can happen
1445 // in leaf calls.
1446 #ifdef ASSERT
1447 {
1448 Label L;
1449 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1450 cbz(rscratch1, L);
1451 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1452 " last_sp != nullptr");
1453 bind(L);
1454 }
1455 #endif /* ASSERT */
1456 // super call
1457 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
1458 }
1459
1460 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
1461 Register java_thread,
1462 Register last_java_sp,
1463 Label* return_pc,
1464 address entry_point,
1465 int number_of_arguments,
1466 bool check_exceptions) {
1467 // interpreter specific
1468 //
1469 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
1470 // really make a difference for these runtime calls, since they are
1471 // slow anyway. Btw., bcp must be saved/restored since it may change
1472 // due to GC.
1473 // assert(java_thread == noreg , "not expecting a precomputed java thread");
1474 save_bcp();
1475 #ifdef ASSERT
1476 {
1477 Label L;
1478 ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1479 cbz(rscratch1, L);
1480 stop("InterpreterMacroAssembler::call_VM_base:"
1481 " last_sp != nullptr");
1482 bind(L);
1483 }
1484 #endif /* ASSERT */
1485 // super call
1486 MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
1487 return_pc, entry_point,
1488 number_of_arguments, check_exceptions);
1489 // interpreter specific
1490 restore_bcp();
1491 restore_locals();
1492 }
1493
1494 void InterpreterMacroAssembler::call_VM_preemptable_helper(Register oop_result,
1495 address entry_point,
1496 int number_of_arguments,
1497 bool check_exceptions) {
1498 assert(InterpreterRuntime::is_preemptable_call(entry_point), "VM call not preemptable, should use call_VM()");
1499 Label resume_pc, not_preempted;
1500
1501 #ifdef ASSERT
1502 {
1503 Label L1, L2;
1504 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1505 cbz(rscratch1, L1);
1506 stop("call_VM_preemptable_helper: Should not have alternate return address set");
1507 bind(L1);
1508 // We check this counter in patch_return_pc_with_preempt_stub() during freeze.
1509 incrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1510 ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1511 cmpw(rscratch1, 0);
1512 br(Assembler::GT, L2);
1513 stop("call_VM_preemptable_helper: should be > 0");
1514 bind(L2);
1515 }
1516 #endif /* ASSERT */
1517
1518 // Force freeze slow path.
1519 push_cont_fastpath();
1520
1521 // Make VM call. In case of preemption set last_pc to the one we want to resume to.
1522 // Note: call_VM_base will use resume_pc label to set last_Java_pc.
1523 call_VM_base(noreg, noreg, noreg, &resume_pc, entry_point, number_of_arguments, false /*check_exceptions*/);
1524
1525 pop_cont_fastpath();
1526
1527 #ifdef ASSERT
1528 {
1529 Label L;
1530 decrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1531 ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1532 cmpw(rscratch1, 0);
1533 br(Assembler::GE, L);
1534 stop("call_VM_preemptable_helper: should be >= 0");
1535 bind(L);
1536 }
1537 #endif /* ASSERT */
1538
1539 // Check if preempted.
1540 ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1541 cbz(rscratch1, not_preempted);
1542 str(zr, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1543 br(rscratch1);
1544
1545 // In case of preemption, this is where we will resume once we finally acquire the monitor.
1546 bind(resume_pc);
1547 restore_after_resume(false /* is_native */);
1548
1549 bind(not_preempted);
1550 if (check_exceptions) {
1551 // check for pending exceptions
1552 ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset())));
1553 Label ok;
1554 cbz(rscratch1, ok);
1555 lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry()));
1556 br(rscratch1);
1557 bind(ok);
1558 }
1559
1560 // get oop result if there is one and reset the value in the thread
1561 if (oop_result->is_valid()) {
1562 get_vm_result_oop(oop_result, rthread);
1563 }
1564 }
1565
1566 static void pass_arg1(MacroAssembler* masm, Register arg) {
1567 if (c_rarg1 != arg ) {
1568 masm->mov(c_rarg1, arg);
1569 }
1570 }
1571
1572 static void pass_arg2(MacroAssembler* masm, Register arg) {
1573 if (c_rarg2 != arg ) {
1574 masm->mov(c_rarg2, arg);
1575 }
1576 }
1577
1578 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1579 address entry_point,
1580 Register arg_1,
1581 bool check_exceptions) {
1582 pass_arg1(this, arg_1);
1583 call_VM_preemptable_helper(oop_result, entry_point, 1, check_exceptions);
1584 }
1585
1586 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1587 address entry_point,
1588 Register arg_1,
1589 Register arg_2,
1590 bool check_exceptions) {
1591 LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
1592 pass_arg2(this, arg_2);
1593 pass_arg1(this, arg_1);
1594 call_VM_preemptable_helper(oop_result, entry_point, 2, check_exceptions);
1595 }
1596
1597 void InterpreterMacroAssembler::restore_after_resume(bool is_native) {
1598 lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter()));
1599 blr(rscratch1);
1600 if (is_native) {
1601 // On resume we need to set up stack as expected
1602 push(dtos);
1603 push(ltos);
1604 }
1605 }
1606
1607 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1608 assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index());
1609 Label update, next, none;
1610
1611 verify_oop(obj);
1612
1613 cbnz(obj, update);
1614 orptr(mdo_addr, TypeEntries::null_seen);
1615 b(next);
1616
1617 bind(update);
1618 load_klass(obj, obj);
1619
1620 ldr(rscratch1, mdo_addr);
1621 eor(obj, obj, rscratch1);
1622 tst(obj, TypeEntries::type_klass_mask);
1623 br(Assembler::EQ, next); // klass seen before, nothing to
1624 // do. The unknown bit may have been
1625 // set already but no need to check.
1626
1627 tbnz(obj, exact_log2(TypeEntries::type_unknown), next);
1628 // already unknown. Nothing to do anymore.
1629
1630 cbz(rscratch1, none);
1631 cmp(rscratch1, (u1)TypeEntries::null_seen);
1632 br(Assembler::EQ, none);
1633 // There is a chance that the checks above
1634 // fail if another thread has just set the
1635 // profiling to this obj's klass
1636 eor(obj, obj, rscratch1); // get back original value before XOR
1637 ldr(rscratch1, mdo_addr);
1638 eor(obj, obj, rscratch1);
1639 tst(obj, TypeEntries::type_klass_mask);
1640 br(Assembler::EQ, next);
1641
1642 // different than before. Cannot keep accurate profile.
1643 orptr(mdo_addr, TypeEntries::type_unknown);
1644 b(next);
1645
1646 bind(none);
1647 // first time here. Set profile type.
1648 str(obj, mdo_addr);
1649 #ifdef ASSERT
1650 andr(obj, obj, TypeEntries::type_mask);
1651 verify_klass_ptr(obj);
1652 #endif
1653
1654 bind(next);
1655 }
1656
1657 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1658 if (!ProfileInterpreter) {
1659 return;
1660 }
1661
1662 if (MethodData::profile_arguments() || MethodData::profile_return()) {
1663 Label profile_continue;
1664
1665 test_method_data_pointer(mdp, profile_continue);
1666
1667 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1668
1669 ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start));
1670 cmp(rscratch1, u1(is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag));
1671 br(Assembler::NE, profile_continue);
1672
1673 if (MethodData::profile_arguments()) {
1674 Label done;
1675 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1676
1677 for (int i = 0; i < TypeProfileArgsLimit; i++) {
1678 if (i > 0 || MethodData::profile_return()) {
1679 // If return value type is profiled we may have no argument to profile
1680 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1681 sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count());
1682 cmp(tmp, (u1)TypeStackSlotEntries::per_arg_count());
1683 add(rscratch1, mdp, off_to_args);
1684 br(Assembler::LT, done);
1685 }
1686 ldr(tmp, Address(callee, Method::const_offset()));
1687 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
1688 // stack offset o (zero based) from the start of the argument
1689 // list, for n arguments translates into offset n - o - 1 from
1690 // the end of the argument list
1691 ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))));
1692 sub(tmp, tmp, rscratch1);
1693 sub(tmp, tmp, 1);
1694 Address arg_addr = argument_address(tmp);
1695 ldr(tmp, arg_addr);
1696
1697 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i)));
1698 profile_obj_type(tmp, mdo_arg_addr);
1699
1700 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1701 off_to_args += to_add;
1702 }
1703
1704 if (MethodData::profile_return()) {
1705 ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1706 sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1707 }
1708
1709 add(rscratch1, mdp, off_to_args);
1710 bind(done);
1711 mov(mdp, rscratch1);
1712
1713 if (MethodData::profile_return()) {
1714 // We're right after the type profile for the last
1715 // argument. tmp is the number of cells left in the
1716 // CallTypeData/VirtualCallTypeData to reach its end. Non null
1717 // if there's a return to profile.
1718 assert(SingleTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1719 add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size));
1720 }
1721 str(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
1722 } else {
1723 assert(MethodData::profile_return(), "either profile call args or call ret");
1724 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1725 }
1726
1727 // mdp points right after the end of the
1728 // CallTypeData/VirtualCallTypeData, right after the cells for the
1729 // return value type if there's one
1730
1731 bind(profile_continue);
1732 }
1733 }
1734
1735 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1736 assert_different_registers(mdp, ret, tmp, rbcp);
1737 if (ProfileInterpreter && MethodData::profile_return()) {
1738 Label profile_continue, done;
1739
1740 test_method_data_pointer(mdp, profile_continue);
1741
1742 if (MethodData::profile_return_jsr292_only()) {
1743 assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
1744
1745 // If we don't profile all invoke bytecodes we must make sure
1746 // it's a bytecode we indeed profile. We can't go back to the
1747 // beginning of the ProfileData we intend to update to check its
1748 // type because we're right after it and we don't known its
1749 // length
1750 Label do_profile;
1751 ldrb(rscratch1, Address(rbcp, 0));
1752 cmp(rscratch1, (u1)Bytecodes::_invokedynamic);
1753 br(Assembler::EQ, do_profile);
1754 cmp(rscratch1, (u1)Bytecodes::_invokehandle);
1755 br(Assembler::EQ, do_profile);
1756 get_method(tmp);
1757 ldrh(rscratch1, Address(tmp, Method::intrinsic_id_offset()));
1758 subs(zr, rscratch1, static_cast<int>(vmIntrinsics::_compiledLambdaForm));
1759 br(Assembler::NE, profile_continue);
1760
1761 bind(do_profile);
1762 }
1763
1764 Address mdo_ret_addr(mdp, -in_bytes(SingleTypeEntry::size()));
1765 mov(tmp, ret);
1766 profile_obj_type(tmp, mdo_ret_addr);
1767
1768 bind(profile_continue);
1769 }
1770 }
1771
1772 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1773 assert_different_registers(rscratch1, rscratch2, mdp, tmp1, tmp2);
1774 if (ProfileInterpreter && MethodData::profile_parameters()) {
1775 Label profile_continue, done;
1776
1777 test_method_data_pointer(mdp, profile_continue);
1778
1779 // Load the offset of the area within the MDO used for
1780 // parameters. If it's negative we're not profiling any parameters
1781 ldrw(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
1782 tbnz(tmp1, 31, profile_continue); // i.e. sign bit set
1783
1784 // Compute a pointer to the area for parameters from the offset
1785 // and move the pointer to the slot for the last
1786 // parameters. Collect profiling from last parameter down.
1787 // mdo start + parameters offset + array length - 1
1788 add(mdp, mdp, tmp1);
1789 ldr(tmp1, Address(mdp, ArrayData::array_len_offset()));
1790 sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1791
1792 Label loop;
1793 bind(loop);
1794
1795 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1796 int type_base = in_bytes(ParametersTypeData::type_offset(0));
1797 int per_arg_scale = exact_log2(DataLayout::cell_size);
1798 add(rscratch1, mdp, off_base);
1799 add(rscratch2, mdp, type_base);
1800
1801 Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale));
1802 Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale));
1803
1804 // load offset on the stack from the slot for this parameter
1805 ldr(tmp2, arg_off);
1806 neg(tmp2, tmp2);
1807 // read the parameter from the local area
1808 ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize)));
1809
1810 // profile the parameter
1811 profile_obj_type(tmp2, arg_type);
1812
1813 // go to next parameter
1814 subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1815 br(Assembler::GE, loop);
1816
1817 bind(profile_continue);
1818 }
1819 }
1820
1821 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
1822 // Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp
1823 get_cache_index_at_bcp(index, 1, sizeof(u4));
1824 // Get address of invokedynamic array
1825 ldr(cache, Address(rcpool, in_bytes(ConstantPoolCache::invokedynamic_entries_offset())));
1826 // Scale the index to be the entry index * sizeof(ResolvedIndyEntry)
1827 lsl(index, index, log2i_exact(sizeof(ResolvedIndyEntry)));
1828 add(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes());
1829 lea(cache, Address(cache, index));
1830 }
1831
1832 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) {
1833 // Get index out of bytecode pointer
1834 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1835 // Take shortcut if the size is a power of 2
1836 if (is_power_of_2(sizeof(ResolvedFieldEntry))) {
1837 lsl(index, index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2
1838 } else {
1839 mov(cache, sizeof(ResolvedFieldEntry));
1840 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry)
1841 }
1842 // Get address of field entries array
1843 ldr(cache, Address(rcpool, ConstantPoolCache::field_entries_offset()));
1844 add(cache, cache, Array<ResolvedFieldEntry>::base_offset_in_bytes());
1845 lea(cache, Address(cache, index));
1846 // Prevents stale data from being read after the bytecode is patched to the fast bytecode
1847 membar(MacroAssembler::LoadLoad);
1848 }
1849
1850 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) {
1851 // Get index out of bytecode pointer
1852 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1853 mov(cache, sizeof(ResolvedMethodEntry));
1854 mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry)
1855
1856 // Get address of field entries array
1857 ldr(cache, Address(rcpool, ConstantPoolCache::method_entries_offset()));
1858 add(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes());
1859 lea(cache, Address(cache, index));
1860 }
1861
1862 #ifdef ASSERT
1863 void InterpreterMacroAssembler::verify_field_offset(Register reg) {
1864 // Verify the field offset is not in the header, implicitly checks for 0
1865 Label L;
1866 subs(zr, reg, oopDesc::base_offset_in_bytes());
1867 br(Assembler::GE, L);
1868 stop("bad field offset");
1869 bind(L);
1870 }
1871 #endif