1 /*
2 * Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, 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/disassembler.hpp"
28 #include "compiler/compilerDefinitions.inline.hpp"
29 #include "gc/shared/barrierSetAssembler.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/tlab_globals.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "interpreter/interpreterRuntime.hpp"
34 #include "interpreter/interp_masm.hpp"
35 #include "interpreter/templateTable.hpp"
36 #include "memory/universe.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/method.inline.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/resolvedFieldEntry.hpp"
42 #include "oops/resolvedIndyEntry.hpp"
43 #include "oops/resolvedMethodEntry.hpp"
44 #include "prims/jvmtiExport.hpp"
45 #include "prims/methodHandles.hpp"
46 #include "runtime/arguments.hpp"
47 #include "runtime/frame.inline.hpp"
48 #include "runtime/sharedRuntime.hpp"
49 #include "runtime/stubRoutines.hpp"
50 #include "runtime/synchronizer.hpp"
51 #include "utilities/powerOfTwo.hpp"
52
53 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
54
55 // Address computation: local variables
56
57 static inline Address iaddress(int n) {
58 return Address(rlocals, Interpreter::local_offset_in_bytes(n));
59 }
60
61 static inline Address laddress(int n) {
62 return iaddress(n + 1);
63 }
64
65 static inline Address faddress(int n) {
66 return iaddress(n);
67 }
68
69 static inline Address daddress(int n) {
70 return laddress(n);
71 }
72
73 static inline Address aaddress(int n) {
74 return iaddress(n);
75 }
76
77 static inline Address iaddress(Register r) {
78 return Address(rlocals, r, Address::lsl(3));
79 }
80
81 static inline Address laddress(Register r, Register scratch,
82 InterpreterMacroAssembler* _masm) {
83 __ lea(scratch, Address(rlocals, r, Address::lsl(3)));
84 return Address(scratch, Interpreter::local_offset_in_bytes(1));
85 }
86
87 static inline Address faddress(Register r) {
88 return iaddress(r);
89 }
90
91 static inline Address daddress(Register r, Register scratch,
92 InterpreterMacroAssembler* _masm) {
93 return laddress(r, scratch, _masm);
94 }
95
96 static inline Address aaddress(Register r) {
97 return iaddress(r);
98 }
99
100 static inline Address at_rsp() {
101 return Address(esp, 0);
102 }
103
104 // At top of Java expression stack which may be different than esp(). It
105 // isn't for category 1 objects.
106 static inline Address at_tos () {
107 return Address(esp, Interpreter::expr_offset_in_bytes(0));
108 }
109
110 static inline Address at_tos_p1() {
111 return Address(esp, Interpreter::expr_offset_in_bytes(1));
112 }
113
114 static inline Address at_tos_p2() {
115 return Address(esp, Interpreter::expr_offset_in_bytes(2));
116 }
117
118 static inline Address at_tos_p3() {
119 return Address(esp, Interpreter::expr_offset_in_bytes(3));
120 }
121
122 static inline Address at_tos_p4() {
123 return Address(esp, Interpreter::expr_offset_in_bytes(4));
124 }
125
126 static inline Address at_tos_p5() {
127 return Address(esp, Interpreter::expr_offset_in_bytes(5));
128 }
129
130 // Condition conversion
131 static Assembler::Condition j_not(TemplateTable::Condition cc) {
132 switch (cc) {
133 case TemplateTable::equal : return Assembler::NE;
134 case TemplateTable::not_equal : return Assembler::EQ;
135 case TemplateTable::less : return Assembler::GE;
136 case TemplateTable::less_equal : return Assembler::GT;
137 case TemplateTable::greater : return Assembler::LE;
138 case TemplateTable::greater_equal: return Assembler::LT;
139 }
140 ShouldNotReachHere();
141 return Assembler::EQ;
142 }
143
144
145 // Miscellaneous helper routines
146 // Store an oop (or null) at the Address described by obj.
147 // If val == noreg this means store a null
148 static void do_oop_store(InterpreterMacroAssembler* _masm,
149 Address dst,
150 Register val,
151 DecoratorSet decorators) {
152 assert(val == noreg || val == r0, "parameter is just for looks");
153 __ store_heap_oop(dst, val, r10, r11, r3, decorators);
154 }
155
156 static void do_oop_load(InterpreterMacroAssembler* _masm,
157 Address src,
158 Register dst,
159 DecoratorSet decorators) {
160 __ load_heap_oop(dst, src, r10, r11, decorators);
161 }
162
163 Address TemplateTable::at_bcp(int offset) {
164 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
165 return Address(rbcp, offset);
166 }
167
168 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
169 Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
170 int byte_no)
171 {
172 assert_different_registers(bc_reg, temp_reg);
173 if (!RewriteBytecodes) return;
174 Label L_patch_done;
175
176 switch (bc) {
177 case Bytecodes::_fast_vputfield:
178 case Bytecodes::_fast_aputfield:
179 case Bytecodes::_fast_bputfield:
180 case Bytecodes::_fast_zputfield:
181 case Bytecodes::_fast_cputfield:
182 case Bytecodes::_fast_dputfield:
183 case Bytecodes::_fast_fputfield:
184 case Bytecodes::_fast_iputfield:
185 case Bytecodes::_fast_lputfield:
186 case Bytecodes::_fast_sputfield:
187 {
188 // We skip bytecode quickening for putfield instructions when
189 // the put_code written to the constant pool cache is zero.
190 // This is required so that every execution of this instruction
191 // calls out to InterpreterRuntime::resolve_get_put to do
192 // additional, required work.
193 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
194 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
195 __ load_field_entry(temp_reg, bc_reg);
196 if (byte_no == f1_byte) {
197 __ lea(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
198 } else {
199 __ lea(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::put_code_offset())));
200 }
201 // Load-acquire the bytecode to match store-release in ResolvedFieldEntry::fill_in()
202 __ ldarb(temp_reg, temp_reg);
203 __ movw(bc_reg, bc);
204 __ cbzw(temp_reg, L_patch_done); // don't patch
205 }
206 break;
207 default:
208 assert(byte_no == -1, "sanity");
209 // the pair bytecodes have already done the load.
210 if (load_bc_into_bc_reg) {
211 __ movw(bc_reg, bc);
212 }
213 }
214
215 if (JvmtiExport::can_post_breakpoint()) {
216 Label L_fast_patch;
217 // if a breakpoint is present we can't rewrite the stream directly
218 __ load_unsigned_byte(temp_reg, at_bcp(0));
219 __ cmpw(temp_reg, Bytecodes::_breakpoint);
220 __ br(Assembler::NE, L_fast_patch);
221 // Let breakpoint table handling rewrite to quicker bytecode
222 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), rmethod, rbcp, bc_reg);
223 __ b(L_patch_done);
224 __ bind(L_fast_patch);
225 }
226
227 #ifdef ASSERT
228 Label L_okay;
229 __ load_unsigned_byte(temp_reg, at_bcp(0));
230 __ cmpw(temp_reg, (int) Bytecodes::java_code(bc));
231 __ br(Assembler::EQ, L_okay);
232 __ cmpw(temp_reg, bc_reg);
233 __ br(Assembler::EQ, L_okay);
234 __ stop("patching the wrong bytecode");
235 __ bind(L_okay);
236 #endif
237 // Patch bytecode with release store to coordinate with ResolvedFieldEntry loads
238 // in fast bytecode codelets. load_field_entry has a memory barrier that gains
239 // the needed ordering, together with control dependency on entering the fast codelet
240 // itself.
241 __ lea(temp_reg, at_bcp(0));
242 __ stlrb(bc_reg, temp_reg);
243 __ bind(L_patch_done);
244 }
245
246
247 // Individual instructions
248
249 void TemplateTable::nop() {
250 transition(vtos, vtos);
251 // nothing to do
252 }
253
254 void TemplateTable::shouldnotreachhere() {
255 transition(vtos, vtos);
256 __ stop("shouldnotreachhere bytecode");
257 }
258
259 void TemplateTable::aconst_null()
260 {
261 transition(vtos, atos);
262 __ mov(r0, 0);
263 }
264
265 void TemplateTable::iconst(int value)
266 {
267 transition(vtos, itos);
268 __ mov(r0, value);
269 }
270
271 void TemplateTable::lconst(int value)
272 {
273 __ mov(r0, value);
274 }
275
276 void TemplateTable::fconst(int value)
277 {
278 transition(vtos, ftos);
279 switch (value) {
280 case 0:
281 __ fmovs(v0, 0.0);
282 break;
283 case 1:
284 __ fmovs(v0, 1.0);
285 break;
286 case 2:
287 __ fmovs(v0, 2.0);
288 break;
289 default:
290 ShouldNotReachHere();
291 break;
292 }
293 }
294
295 void TemplateTable::dconst(int value)
296 {
297 transition(vtos, dtos);
298 switch (value) {
299 case 0:
300 __ fmovd(v0, 0.0);
301 break;
302 case 1:
303 __ fmovd(v0, 1.0);
304 break;
305 case 2:
306 __ fmovd(v0, 2.0);
307 break;
308 default:
309 ShouldNotReachHere();
310 break;
311 }
312 }
313
314 void TemplateTable::bipush()
315 {
316 transition(vtos, itos);
317 __ load_signed_byte32(r0, at_bcp(1));
318 }
319
320 void TemplateTable::sipush()
321 {
322 transition(vtos, itos);
323 __ load_unsigned_short(r0, at_bcp(1));
324 __ revw(r0, r0);
325 __ asrw(r0, r0, 16);
326 }
327
328 void TemplateTable::ldc(LdcType type)
329 {
330 transition(vtos, vtos);
331 Label call_ldc, notFloat, notClass, notInt, Done;
332
333 if (is_ldc_wide(type)) {
334 __ get_unsigned_2_byte_index_at_bcp(r1, 1);
335 } else {
336 __ load_unsigned_byte(r1, at_bcp(1));
337 }
338 __ get_cpool_and_tags(r2, r0);
339
340 const int base_offset = ConstantPool::header_size() * wordSize;
341 const int tags_offset = Array<u1>::base_offset_in_bytes();
342
343 // get type
344 __ add(r3, r1, tags_offset);
345 __ lea(r3, Address(r0, r3));
346 __ ldarb(r3, r3);
347
348 // unresolved class - get the resolved class
349 __ cmp(r3, (u1)JVM_CONSTANT_UnresolvedClass);
350 __ br(Assembler::EQ, call_ldc);
351
352 // unresolved class in error state - call into runtime to throw the error
353 // from the first resolution attempt
354 __ cmp(r3, (u1)JVM_CONSTANT_UnresolvedClassInError);
355 __ br(Assembler::EQ, call_ldc);
356
357 // resolved class - need to call vm to get java mirror of the class
358 __ cmp(r3, (u1)JVM_CONSTANT_Class);
359 __ br(Assembler::NE, notClass);
360
361 __ bind(call_ldc);
362 __ mov(c_rarg1, is_ldc_wide(type) ? 1 : 0);
363 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), c_rarg1);
364 __ push_ptr(r0);
365 __ verify_oop(r0);
366 __ b(Done);
367
368 __ bind(notClass);
369 __ cmp(r3, (u1)JVM_CONSTANT_Float);
370 __ br(Assembler::NE, notFloat);
371 // ftos
372 __ adds(r1, r2, r1, Assembler::LSL, 3);
373 __ ldrs(v0, Address(r1, base_offset));
374 __ push_f();
375 __ b(Done);
376
377 __ bind(notFloat);
378
379 __ cmp(r3, (u1)JVM_CONSTANT_Integer);
380 __ br(Assembler::NE, notInt);
381
382 // itos
383 __ adds(r1, r2, r1, Assembler::LSL, 3);
384 __ ldrw(r0, Address(r1, base_offset));
385 __ push_i(r0);
386 __ b(Done);
387
388 __ bind(notInt);
389 condy_helper(Done);
390
391 __ bind(Done);
392 }
393
394 // Fast path for caching oop constants.
395 void TemplateTable::fast_aldc(LdcType type)
396 {
397 transition(vtos, atos);
398
399 Register result = r0;
400 Register tmp = r1;
401 Register rarg = r2;
402
403 int index_size = is_ldc_wide(type) ? sizeof(u2) : sizeof(u1);
404
405 Label resolved;
406
407 // We are resolved if the resolved reference cache entry contains a
408 // non-null object (String, MethodType, etc.)
409 assert_different_registers(result, tmp);
410 __ get_cache_index_at_bcp(tmp, 1, index_size);
411 __ load_resolved_reference_at_index(result, tmp);
412 __ cbnz(result, resolved);
413
414 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
415
416 // first time invocation - must resolve first
417 __ mov(rarg, (int)bytecode());
418 __ call_VM(result, entry, rarg);
419
420 __ bind(resolved);
421
422 { // Check for the null sentinel.
423 // If we just called the VM, it already did the mapping for us,
424 // but it's harmless to retry.
425 Label notNull;
426
427 // Stash null_sentinel address to get its value later
428 __ movptr(rarg, (uintptr_t)Universe::the_null_sentinel_addr());
429 __ ldr(tmp, Address(rarg));
430 __ resolve_oop_handle(tmp, r5, rscratch2);
431 __ cmpoop(result, tmp);
432 __ br(Assembler::NE, notNull);
433 __ mov(result, 0); // null object reference
434 __ bind(notNull);
435 }
436
437 if (VerifyOops) {
438 // Safe to call with 0 result
439 __ verify_oop(result);
440 }
441 }
442
443 void TemplateTable::ldc2_w()
444 {
445 transition(vtos, vtos);
446 Label notDouble, notLong, Done;
447 __ get_unsigned_2_byte_index_at_bcp(r0, 1);
448
449 __ get_cpool_and_tags(r1, r2);
450 const int base_offset = ConstantPool::header_size() * wordSize;
451 const int tags_offset = Array<u1>::base_offset_in_bytes();
452
453 // get type
454 __ lea(r2, Address(r2, r0, Address::lsl(0)));
455 __ load_unsigned_byte(r2, Address(r2, tags_offset));
456 __ cmpw(r2, (int)JVM_CONSTANT_Double);
457 __ br(Assembler::NE, notDouble);
458
459 // dtos
460 __ lea (r2, Address(r1, r0, Address::lsl(3)));
461 __ ldrd(v0, Address(r2, base_offset));
462 __ push_d();
463 __ b(Done);
464
465 __ bind(notDouble);
466 __ cmpw(r2, (int)JVM_CONSTANT_Long);
467 __ br(Assembler::NE, notLong);
468
469 // ltos
470 __ lea(r0, Address(r1, r0, Address::lsl(3)));
471 __ ldr(r0, Address(r0, base_offset));
472 __ push_l();
473 __ b(Done);
474
475 __ bind(notLong);
476 condy_helper(Done);
477
478 __ bind(Done);
479 }
480
481 void TemplateTable::condy_helper(Label& Done)
482 {
483 Register obj = r0;
484 Register rarg = r1;
485 Register flags = r2;
486 Register off = r3;
487
488 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
489
490 __ mov(rarg, (int) bytecode());
491 __ call_VM(obj, entry, rarg);
492
493 __ get_vm_result_metadata(flags, rthread);
494
495 // VMr = obj = base address to find primitive value to push
496 // VMr2 = flags = (tos, off) using format of CPCE::_flags
497 __ mov(off, flags);
498 __ andw(off, off, ConstantPoolCache::field_index_mask);
499
500 const Address field(obj, off);
501
502 // What sort of thing are we loading?
503 // x86 uses a shift and mask or wings it with a shift plus assert
504 // the mask is not needed. aarch64 just uses bitfield extract
505 __ ubfxw(flags, flags, ConstantPoolCache::tos_state_shift,
506 ConstantPoolCache::tos_state_bits);
507
508 switch (bytecode()) {
509 case Bytecodes::_ldc:
510 case Bytecodes::_ldc_w:
511 {
512 // tos in (itos, ftos, stos, btos, ctos, ztos)
513 Label notInt, notFloat, notShort, notByte, notChar, notBool;
514 __ cmpw(flags, itos);
515 __ br(Assembler::NE, notInt);
516 // itos
517 __ ldrw(r0, field);
518 __ push(itos);
519 __ b(Done);
520
521 __ bind(notInt);
522 __ cmpw(flags, ftos);
523 __ br(Assembler::NE, notFloat);
524 // ftos
525 __ load_float(field);
526 __ push(ftos);
527 __ b(Done);
528
529 __ bind(notFloat);
530 __ cmpw(flags, stos);
531 __ br(Assembler::NE, notShort);
532 // stos
533 __ load_signed_short(r0, field);
534 __ push(stos);
535 __ b(Done);
536
537 __ bind(notShort);
538 __ cmpw(flags, btos);
539 __ br(Assembler::NE, notByte);
540 // btos
541 __ load_signed_byte(r0, field);
542 __ push(btos);
543 __ b(Done);
544
545 __ bind(notByte);
546 __ cmpw(flags, ctos);
547 __ br(Assembler::NE, notChar);
548 // ctos
549 __ load_unsigned_short(r0, field);
550 __ push(ctos);
551 __ b(Done);
552
553 __ bind(notChar);
554 __ cmpw(flags, ztos);
555 __ br(Assembler::NE, notBool);
556 // ztos
557 __ load_signed_byte(r0, field);
558 __ push(ztos);
559 __ b(Done);
560
561 __ bind(notBool);
562 break;
563 }
564
565 case Bytecodes::_ldc2_w:
566 {
567 Label notLong, notDouble;
568 __ cmpw(flags, ltos);
569 __ br(Assembler::NE, notLong);
570 // ltos
571 __ ldr(r0, field);
572 __ push(ltos);
573 __ b(Done);
574
575 __ bind(notLong);
576 __ cmpw(flags, dtos);
577 __ br(Assembler::NE, notDouble);
578 // dtos
579 __ load_double(field);
580 __ push(dtos);
581 __ b(Done);
582
583 __ bind(notDouble);
584 break;
585 }
586
587 default:
588 ShouldNotReachHere();
589 }
590
591 __ stop("bad ldc/condy");
592 }
593
594 void TemplateTable::locals_index(Register reg, int offset)
595 {
596 __ ldrb(reg, at_bcp(offset));
597 __ neg(reg, reg);
598 }
599
600 void TemplateTable::iload() {
601 iload_internal();
602 }
603
604 void TemplateTable::nofast_iload() {
605 iload_internal(may_not_rewrite);
606 }
607
608 void TemplateTable::iload_internal(RewriteControl rc) {
609 transition(vtos, itos);
610 if (RewriteFrequentPairs && rc == may_rewrite) {
611 Label rewrite, done;
612 Register bc = r4;
613
614 // get next bytecode
615 __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
616
617 // if _iload, wait to rewrite to iload2. We only want to rewrite the
618 // last two iloads in a pair. Comparing against fast_iload means that
619 // the next bytecode is neither an iload or a caload, and therefore
620 // an iload pair.
621 __ cmpw(r1, Bytecodes::_iload);
622 __ br(Assembler::EQ, done);
623
624 // if _fast_iload rewrite to _fast_iload2
625 __ cmpw(r1, Bytecodes::_fast_iload);
626 __ movw(bc, Bytecodes::_fast_iload2);
627 __ br(Assembler::EQ, rewrite);
628
629 // if _caload rewrite to _fast_icaload
630 __ cmpw(r1, Bytecodes::_caload);
631 __ movw(bc, Bytecodes::_fast_icaload);
632 __ br(Assembler::EQ, rewrite);
633
634 // else rewrite to _fast_iload
635 __ movw(bc, Bytecodes::_fast_iload);
636
637 // rewrite
638 // bc: new bytecode
639 __ bind(rewrite);
640 patch_bytecode(Bytecodes::_iload, bc, r1, false);
641 __ bind(done);
642
643 }
644
645 // do iload, get the local value into tos
646 locals_index(r1);
647 __ ldr(r0, iaddress(r1));
648
649 }
650
651 void TemplateTable::fast_iload2()
652 {
653 transition(vtos, itos);
654 locals_index(r1);
655 __ ldr(r0, iaddress(r1));
656 __ push(itos);
657 locals_index(r1, 3);
658 __ ldr(r0, iaddress(r1));
659 }
660
661 void TemplateTable::fast_iload()
662 {
663 transition(vtos, itos);
664 locals_index(r1);
665 __ ldr(r0, iaddress(r1));
666 }
667
668 void TemplateTable::lload()
669 {
670 transition(vtos, ltos);
671 __ ldrb(r1, at_bcp(1));
672 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
673 __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
674 }
675
676 void TemplateTable::fload()
677 {
678 transition(vtos, ftos);
679 locals_index(r1);
680 // n.b. we use ldrd here because this is a 64 bit slot
681 // this is comparable to the iload case
682 __ ldrd(v0, faddress(r1));
683 }
684
685 void TemplateTable::dload()
686 {
687 transition(vtos, dtos);
688 __ ldrb(r1, at_bcp(1));
689 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
690 __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
691 }
692
693 void TemplateTable::aload()
694 {
695 transition(vtos, atos);
696 locals_index(r1);
697 __ ldr(r0, iaddress(r1));
698 }
699
700 void TemplateTable::locals_index_wide(Register reg) {
701 __ ldrh(reg, at_bcp(2));
702 __ rev16w(reg, reg);
703 __ neg(reg, reg);
704 }
705
706 void TemplateTable::wide_iload() {
707 transition(vtos, itos);
708 locals_index_wide(r1);
709 __ ldr(r0, iaddress(r1));
710 }
711
712 void TemplateTable::wide_lload()
713 {
714 transition(vtos, ltos);
715 __ ldrh(r1, at_bcp(2));
716 __ rev16w(r1, r1);
717 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
718 __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
719 }
720
721 void TemplateTable::wide_fload()
722 {
723 transition(vtos, ftos);
724 locals_index_wide(r1);
725 // n.b. we use ldrd here because this is a 64 bit slot
726 // this is comparable to the iload case
727 __ ldrd(v0, faddress(r1));
728 }
729
730 void TemplateTable::wide_dload()
731 {
732 transition(vtos, dtos);
733 __ ldrh(r1, at_bcp(2));
734 __ rev16w(r1, r1);
735 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
736 __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
737 }
738
739 void TemplateTable::wide_aload()
740 {
741 transition(vtos, atos);
742 locals_index_wide(r1);
743 __ ldr(r0, aaddress(r1));
744 }
745
746 void TemplateTable::index_check(Register array, Register index)
747 {
748 // destroys r1, rscratch1
749 // sign extend index for use by indexed load
750 // __ movl2ptr(index, index);
751 // check index
752 Register length = rscratch1;
753 __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
754 __ cmpw(index, length);
755 if (index != r1) {
756 // ??? convention: move aberrant index into r1 for exception message
757 assert(r1 != array, "different registers");
758 __ mov(r1, index);
759 }
760 Label ok;
761 __ br(Assembler::LO, ok);
762 // ??? convention: move array into r3 for exception message
763 __ mov(r3, array);
764 __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
765 __ br(rscratch1);
766 __ bind(ok);
767 }
768
769 void TemplateTable::iaload()
770 {
771 transition(itos, itos);
772 __ mov(r1, r0);
773 __ pop_ptr(r0);
774 // r0: array
775 // r1: index
776 index_check(r0, r1); // leaves index in r1, kills rscratch1
777 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
778 __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
779 }
780
781 void TemplateTable::laload()
782 {
783 transition(itos, ltos);
784 __ mov(r1, r0);
785 __ pop_ptr(r0);
786 // r0: array
787 // r1: index
788 index_check(r0, r1); // leaves index in r1, kills rscratch1
789 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_LONG) >> 3);
790 __ access_load_at(T_LONG, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
791 }
792
793 void TemplateTable::faload()
794 {
795 transition(itos, ftos);
796 __ mov(r1, r0);
797 __ pop_ptr(r0);
798 // r0: array
799 // r1: index
800 index_check(r0, r1); // leaves index in r1, kills rscratch1
801 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
802 __ access_load_at(T_FLOAT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
803 }
804
805 void TemplateTable::daload()
806 {
807 transition(itos, dtos);
808 __ mov(r1, r0);
809 __ pop_ptr(r0);
810 // r0: array
811 // r1: index
812 index_check(r0, r1); // leaves index in r1, kills rscratch1
813 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
814 __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
815 }
816
817 void TemplateTable::aaload()
818 {
819 transition(itos, atos);
820 __ mov(r1, r0);
821 __ pop_ptr(r0);
822 // r0: array
823 // r1: index
824 index_check(r0, r1); // leaves index in r1, kills rscratch1
825 __ profile_array_type<ArrayLoadData>(r2, r0, r4);
826 if (UseArrayFlattening) {
827 Label is_flat_array, done;
828
829 __ test_flat_array_oop(r0, rscratch1 /*temp*/, is_flat_array);
830 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
831 do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
832
833 __ b(done);
834 __ bind(is_flat_array);
835 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_load), r0, r1);
836 // Ensure the stores to copy the inline field contents are visible
837 // before any subsequent store that publishes this reference.
838 __ membar(Assembler::StoreStore);
839 __ bind(done);
840 } else {
841 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
842 do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
843 }
844 __ profile_element_type(r2, r0, r4);
845 }
846
847 void TemplateTable::baload()
848 {
849 transition(itos, itos);
850 __ mov(r1, r0);
851 __ pop_ptr(r0);
852 // r0: array
853 // r1: index
854 index_check(r0, r1); // leaves index in r1, kills rscratch1
855 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
856 __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
857 }
858
859 void TemplateTable::caload()
860 {
861 transition(itos, itos);
862 __ mov(r1, r0);
863 __ pop_ptr(r0);
864 // r0: array
865 // r1: index
866 index_check(r0, r1); // leaves index in r1, kills rscratch1
867 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_CHAR) >> 1);
868 __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
869 }
870
871 // iload followed by caload frequent pair
872 void TemplateTable::fast_icaload()
873 {
874 transition(vtos, itos);
875 // load index out of locals
876 locals_index(r2);
877 __ ldr(r1, iaddress(r2));
878
879 __ pop_ptr(r0);
880
881 // r0: array
882 // r1: index
883 index_check(r0, r1); // leaves index in r1, kills rscratch1
884 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_CHAR) >> 1);
885 __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
886 }
887
888 void TemplateTable::saload()
889 {
890 transition(itos, itos);
891 __ mov(r1, r0);
892 __ pop_ptr(r0);
893 // r0: array
894 // r1: index
895 index_check(r0, r1); // leaves index in r1, kills rscratch1
896 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_SHORT) >> 1);
897 __ access_load_at(T_SHORT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
898 }
899
900 void TemplateTable::iload(int n)
901 {
902 transition(vtos, itos);
903 __ ldr(r0, iaddress(n));
904 }
905
906 void TemplateTable::lload(int n)
907 {
908 transition(vtos, ltos);
909 __ ldr(r0, laddress(n));
910 }
911
912 void TemplateTable::fload(int n)
913 {
914 transition(vtos, ftos);
915 __ ldrs(v0, faddress(n));
916 }
917
918 void TemplateTable::dload(int n)
919 {
920 transition(vtos, dtos);
921 __ ldrd(v0, daddress(n));
922 }
923
924 void TemplateTable::aload(int n)
925 {
926 transition(vtos, atos);
927 __ ldr(r0, iaddress(n));
928 }
929
930 void TemplateTable::aload_0() {
931 aload_0_internal();
932 }
933
934 void TemplateTable::nofast_aload_0() {
935 aload_0_internal(may_not_rewrite);
936 }
937
938 void TemplateTable::aload_0_internal(RewriteControl rc) {
939 // According to bytecode histograms, the pairs:
940 //
941 // _aload_0, _fast_igetfield
942 // _aload_0, _fast_agetfield
943 // _aload_0, _fast_fgetfield
944 //
945 // occur frequently. If RewriteFrequentPairs is set, the (slow)
946 // _aload_0 bytecode checks if the next bytecode is either
947 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
948 // rewrites the current bytecode into a pair bytecode; otherwise it
949 // rewrites the current bytecode into _fast_aload_0 that doesn't do
950 // the pair check anymore.
951 //
952 // Note: If the next bytecode is _getfield, the rewrite must be
953 // delayed, otherwise we may miss an opportunity for a pair.
954 //
955 // Also rewrite frequent pairs
956 // aload_0, aload_1
957 // aload_0, iload_1
958 // These bytecodes with a small amount of code are most profitable
959 // to rewrite
960 if (RewriteFrequentPairs && rc == may_rewrite) {
961 Label rewrite, done;
962 const Register bc = r4;
963
964 // get next bytecode
965 __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
966
967 // if _getfield then wait with rewrite
968 __ cmpw(r1, Bytecodes::Bytecodes::_getfield);
969 __ br(Assembler::EQ, done);
970
971 // if _igetfield then rewrite to _fast_iaccess_0
972 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
973 __ cmpw(r1, Bytecodes::_fast_igetfield);
974 __ movw(bc, Bytecodes::_fast_iaccess_0);
975 __ br(Assembler::EQ, rewrite);
976
977 // if _agetfield then rewrite to _fast_aaccess_0
978 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
979 __ cmpw(r1, Bytecodes::_fast_agetfield);
980 __ movw(bc, Bytecodes::_fast_aaccess_0);
981 __ br(Assembler::EQ, rewrite);
982
983 // if _fgetfield then rewrite to _fast_faccess_0
984 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
985 __ cmpw(r1, Bytecodes::_fast_fgetfield);
986 __ movw(bc, Bytecodes::_fast_faccess_0);
987 __ br(Assembler::EQ, rewrite);
988
989 // else rewrite to _fast_aload0
990 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
991 __ movw(bc, Bytecodes::Bytecodes::_fast_aload_0);
992
993 // rewrite
994 // bc: new bytecode
995 __ bind(rewrite);
996 patch_bytecode(Bytecodes::_aload_0, bc, r1, false);
997
998 __ bind(done);
999 }
1000
1001 // Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop).
1002 aload(0);
1003 }
1004
1005 void TemplateTable::istore()
1006 {
1007 transition(itos, vtos);
1008 locals_index(r1);
1009 // FIXME: We're being very pernickerty here storing a jint in a
1010 // local with strw, which costs an extra instruction over what we'd
1011 // be able to do with a simple str. We should just store the whole
1012 // word.
1013 __ lea(rscratch1, iaddress(r1));
1014 __ strw(r0, Address(rscratch1));
1015 }
1016
1017 void TemplateTable::lstore()
1018 {
1019 transition(ltos, vtos);
1020 locals_index(r1);
1021 __ str(r0, laddress(r1, rscratch1, _masm));
1022 }
1023
1024 void TemplateTable::fstore() {
1025 transition(ftos, vtos);
1026 locals_index(r1);
1027 __ lea(rscratch1, iaddress(r1));
1028 __ strs(v0, Address(rscratch1));
1029 }
1030
1031 void TemplateTable::dstore() {
1032 transition(dtos, vtos);
1033 locals_index(r1);
1034 __ strd(v0, daddress(r1, rscratch1, _masm));
1035 }
1036
1037 void TemplateTable::astore()
1038 {
1039 transition(vtos, vtos);
1040 __ pop_ptr(r0);
1041 locals_index(r1);
1042 __ str(r0, aaddress(r1));
1043 }
1044
1045 void TemplateTable::wide_istore() {
1046 transition(vtos, vtos);
1047 __ pop_i();
1048 locals_index_wide(r1);
1049 __ lea(rscratch1, iaddress(r1));
1050 __ strw(r0, Address(rscratch1));
1051 }
1052
1053 void TemplateTable::wide_lstore() {
1054 transition(vtos, vtos);
1055 __ pop_l();
1056 locals_index_wide(r1);
1057 __ str(r0, laddress(r1, rscratch1, _masm));
1058 }
1059
1060 void TemplateTable::wide_fstore() {
1061 transition(vtos, vtos);
1062 __ pop_f();
1063 locals_index_wide(r1);
1064 __ lea(rscratch1, faddress(r1));
1065 __ strs(v0, rscratch1);
1066 }
1067
1068 void TemplateTable::wide_dstore() {
1069 transition(vtos, vtos);
1070 __ pop_d();
1071 locals_index_wide(r1);
1072 __ strd(v0, daddress(r1, rscratch1, _masm));
1073 }
1074
1075 void TemplateTable::wide_astore() {
1076 transition(vtos, vtos);
1077 __ pop_ptr(r0);
1078 locals_index_wide(r1);
1079 __ str(r0, aaddress(r1));
1080 }
1081
1082 void TemplateTable::iastore() {
1083 transition(itos, vtos);
1084 __ pop_i(r1);
1085 __ pop_ptr(r3);
1086 // r0: value
1087 // r1: index
1088 // r3: array
1089 index_check(r3, r1); // prefer index in r1
1090 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
1091 __ access_store_at(T_INT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), r0, noreg, noreg, noreg);
1092 }
1093
1094 void TemplateTable::lastore() {
1095 transition(ltos, vtos);
1096 __ pop_i(r1);
1097 __ pop_ptr(r3);
1098 // r0: value
1099 // r1: index
1100 // r3: array
1101 index_check(r3, r1); // prefer index in r1
1102 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_LONG) >> 3);
1103 __ access_store_at(T_LONG, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), r0, noreg, noreg, noreg);
1104 }
1105
1106 void TemplateTable::fastore() {
1107 transition(ftos, vtos);
1108 __ pop_i(r1);
1109 __ pop_ptr(r3);
1110 // v0: value
1111 // r1: index
1112 // r3: array
1113 index_check(r3, r1); // prefer index in r1
1114 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1115 __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), noreg /* ftos */, noreg, noreg, noreg);
1116 }
1117
1118 void TemplateTable::dastore() {
1119 transition(dtos, vtos);
1120 __ pop_i(r1);
1121 __ pop_ptr(r3);
1122 // v0: value
1123 // r1: index
1124 // r3: array
1125 index_check(r3, r1); // prefer index in r1
1126 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1127 __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), noreg /* dtos */, noreg, noreg, noreg);
1128 }
1129
1130 void TemplateTable::aastore() {
1131 Label is_null, is_flat_array, ok_is_subtype, done;
1132 transition(vtos, vtos);
1133 // stack: ..., array, index, value
1134 __ ldr(r0, at_tos()); // value
1135 __ ldr(r2, at_tos_p1()); // index
1136 __ ldr(r3, at_tos_p2()); // array
1137
1138 index_check(r3, r2); // kills r1
1139
1140 __ profile_array_type<ArrayStoreData>(r4, r3, r5);
1141 __ profile_multiple_element_types(r4, r0, r5, r6);
1142
1143 __ add(r4, r2, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1144 Address element_address(r3, r4, Address::uxtw(LogBytesPerHeapOop));
1145 // Be careful not to clobber r4 below
1146
1147 // do array store check - check for null value first
1148 __ cbz(r0, is_null);
1149
1150 // Move array class to r5
1151 __ load_klass(r5, r3);
1152
1153 if (UseArrayFlattening) {
1154 __ ldrw(r6, Address(r5, Klass::layout_helper_offset()));
1155 __ test_flat_array_layout(r6, is_flat_array);
1156 }
1157
1158 // Move subklass into r1
1159 __ load_klass(r1, r0);
1160
1161 // Move array element superklass into r0
1162 __ ldr(r0, Address(r5, ObjArrayKlass::element_klass_offset()));
1163 // Compress array + index*oopSize + 12 into a single register. Frees r2.
1164
1165 // Generate subtype check. Blows r2, r5
1166 // Superklass in r0. Subklass in r1.
1167
1168 // is "r1 <: r0" ? (value subclass <: array element superclass)
1169 __ gen_subtype_check(r1, ok_is_subtype, false);
1170
1171 // Come here on failure
1172 // object is at TOS
1173 __ b(Interpreter::_throw_ArrayStoreException_entry);
1174
1175 // Come here on success
1176 __ bind(ok_is_subtype);
1177
1178 // Get the value we will store
1179 __ ldr(r0, at_tos());
1180 // Now store using the appropriate barrier
1181 // Clobbers: r10, r11, r3
1182 do_oop_store(_masm, element_address, r0, IS_ARRAY);
1183 __ b(done);
1184
1185 // Have a null in r0, r3=array, r2=index. Store null at ary[idx]
1186 __ bind(is_null);
1187 if (Arguments::is_valhalla_enabled()) {
1188 Label is_null_into_value_array_npe, store_null;
1189
1190 if (UseArrayFlattening) {
1191 __ test_flat_array_oop(r3, rscratch1, is_flat_array);
1192 }
1193
1194 // No way to store null in a null-free array
1195 __ test_null_free_array_oop(r3, rscratch1, is_null_into_value_array_npe);
1196 __ b(store_null);
1197
1198 __ bind(is_null_into_value_array_npe);
1199 __ b(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1200
1201 __ bind(store_null);
1202 }
1203
1204 // Store a null
1205 // Clobbers: r10, r11, r3
1206 do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1207 __ b(done);
1208
1209 if (UseArrayFlattening) {
1210 Label is_type_ok;
1211 __ bind(is_flat_array); // Store non-null value to flat
1212
1213 __ ldr(r0, at_tos()); // value
1214 __ ldr(r3, at_tos_p1()); // index
1215 __ ldr(r2, at_tos_p2()); // array
1216 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), r0, r2, r3);
1217 }
1218
1219 // Pop stack arguments
1220 __ bind(done);
1221 __ add(esp, esp, 3 * Interpreter::stackElementSize);
1222 }
1223
1224 void TemplateTable::bastore()
1225 {
1226 transition(itos, vtos);
1227 __ pop_i(r1);
1228 __ pop_ptr(r3);
1229 // r0: value
1230 // r1: index
1231 // r3: array
1232 index_check(r3, r1); // prefer index in r1
1233
1234 // Need to check whether array is boolean or byte
1235 // since both types share the bastore bytecode.
1236 __ load_klass(r2, r3);
1237 __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));
1238 int diffbit_index = exact_log2(Klass::layout_helper_boolean_diffbit());
1239 Label L_skip;
1240 __ tbz(r2, diffbit_index, L_skip);
1241 __ andw(r0, r0, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1
1242 __ bind(L_skip);
1243
1244 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
1245 __ access_store_at(T_BYTE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(0)), r0, noreg, noreg, noreg);
1246 }
1247
1248 void TemplateTable::castore()
1249 {
1250 transition(itos, vtos);
1251 __ pop_i(r1);
1252 __ pop_ptr(r3);
1253 // r0: value
1254 // r1: index
1255 // r3: array
1256 index_check(r3, r1); // prefer index in r1
1257 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_CHAR) >> 1);
1258 __ access_store_at(T_CHAR, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(1)), r0, noreg, noreg, noreg);
1259 }
1260
1261 void TemplateTable::sastore()
1262 {
1263 castore();
1264 }
1265
1266 void TemplateTable::istore(int n)
1267 {
1268 transition(itos, vtos);
1269 __ str(r0, iaddress(n));
1270 }
1271
1272 void TemplateTable::lstore(int n)
1273 {
1274 transition(ltos, vtos);
1275 __ str(r0, laddress(n));
1276 }
1277
1278 void TemplateTable::fstore(int n)
1279 {
1280 transition(ftos, vtos);
1281 __ strs(v0, faddress(n));
1282 }
1283
1284 void TemplateTable::dstore(int n)
1285 {
1286 transition(dtos, vtos);
1287 __ strd(v0, daddress(n));
1288 }
1289
1290 void TemplateTable::astore(int n)
1291 {
1292 transition(vtos, vtos);
1293 __ pop_ptr(r0);
1294 __ str(r0, iaddress(n));
1295 }
1296
1297 void TemplateTable::pop()
1298 {
1299 transition(vtos, vtos);
1300 __ add(esp, esp, Interpreter::stackElementSize);
1301 }
1302
1303 void TemplateTable::pop2()
1304 {
1305 transition(vtos, vtos);
1306 __ add(esp, esp, 2 * Interpreter::stackElementSize);
1307 }
1308
1309 void TemplateTable::dup()
1310 {
1311 transition(vtos, vtos);
1312 __ ldr(r0, Address(esp, 0));
1313 __ push(r0);
1314 // stack: ..., a, a
1315 }
1316
1317 void TemplateTable::dup_x1()
1318 {
1319 transition(vtos, vtos);
1320 // stack: ..., a, b
1321 __ ldr(r0, at_tos()); // load b
1322 __ ldr(r2, at_tos_p1()); // load a
1323 __ str(r0, at_tos_p1()); // store b
1324 __ str(r2, at_tos()); // store a
1325 __ push(r0); // push b
1326 // stack: ..., b, a, b
1327 }
1328
1329 void TemplateTable::dup_x2()
1330 {
1331 transition(vtos, vtos);
1332 // stack: ..., a, b, c
1333 __ ldr(r0, at_tos()); // load c
1334 __ ldr(r2, at_tos_p2()); // load a
1335 __ str(r0, at_tos_p2()); // store c in a
1336 __ push(r0); // push c
1337 // stack: ..., c, b, c, c
1338 __ ldr(r0, at_tos_p2()); // load b
1339 __ str(r2, at_tos_p2()); // store a in b
1340 // stack: ..., c, a, c, c
1341 __ str(r0, at_tos_p1()); // store b in c
1342 // stack: ..., c, a, b, c
1343 }
1344
1345 void TemplateTable::dup2()
1346 {
1347 transition(vtos, vtos);
1348 // stack: ..., a, b
1349 __ ldr(r0, at_tos_p1()); // load a
1350 __ push(r0); // push a
1351 __ ldr(r0, at_tos_p1()); // load b
1352 __ push(r0); // push b
1353 // stack: ..., a, b, a, b
1354 }
1355
1356 void TemplateTable::dup2_x1()
1357 {
1358 transition(vtos, vtos);
1359 // stack: ..., a, b, c
1360 __ ldr(r2, at_tos()); // load c
1361 __ ldr(r0, at_tos_p1()); // load b
1362 __ push(r0); // push b
1363 __ push(r2); // push c
1364 // stack: ..., a, b, c, b, c
1365 __ str(r2, at_tos_p3()); // store c in b
1366 // stack: ..., a, c, c, b, c
1367 __ ldr(r2, at_tos_p4()); // load a
1368 __ str(r2, at_tos_p2()); // store a in 2nd c
1369 // stack: ..., a, c, a, b, c
1370 __ str(r0, at_tos_p4()); // store b in a
1371 // stack: ..., b, c, a, b, c
1372 }
1373
1374 void TemplateTable::dup2_x2()
1375 {
1376 transition(vtos, vtos);
1377 // stack: ..., a, b, c, d
1378 __ ldr(r2, at_tos()); // load d
1379 __ ldr(r0, at_tos_p1()); // load c
1380 __ push(r0) ; // push c
1381 __ push(r2); // push d
1382 // stack: ..., a, b, c, d, c, d
1383 __ ldr(r0, at_tos_p4()); // load b
1384 __ str(r0, at_tos_p2()); // store b in d
1385 __ str(r2, at_tos_p4()); // store d in b
1386 // stack: ..., a, d, c, b, c, d
1387 __ ldr(r2, at_tos_p5()); // load a
1388 __ ldr(r0, at_tos_p3()); // load c
1389 __ str(r2, at_tos_p3()); // store a in c
1390 __ str(r0, at_tos_p5()); // store c in a
1391 // stack: ..., c, d, a, b, c, d
1392 }
1393
1394 void TemplateTable::swap()
1395 {
1396 transition(vtos, vtos);
1397 // stack: ..., a, b
1398 __ ldr(r2, at_tos_p1()); // load a
1399 __ ldr(r0, at_tos()); // load b
1400 __ str(r2, at_tos()); // store a in b
1401 __ str(r0, at_tos_p1()); // store b in a
1402 // stack: ..., b, a
1403 }
1404
1405 void TemplateTable::iop2(Operation op)
1406 {
1407 transition(itos, itos);
1408 // r0 <== r1 op r0
1409 __ pop_i(r1);
1410 switch (op) {
1411 case add : __ addw(r0, r1, r0); break;
1412 case sub : __ subw(r0, r1, r0); break;
1413 case mul : __ mulw(r0, r1, r0); break;
1414 case _and : __ andw(r0, r1, r0); break;
1415 case _or : __ orrw(r0, r1, r0); break;
1416 case _xor : __ eorw(r0, r1, r0); break;
1417 case shl : __ lslvw(r0, r1, r0); break;
1418 case shr : __ asrvw(r0, r1, r0); break;
1419 case ushr : __ lsrvw(r0, r1, r0);break;
1420 default : ShouldNotReachHere();
1421 }
1422 }
1423
1424 void TemplateTable::lop2(Operation op)
1425 {
1426 transition(ltos, ltos);
1427 // r0 <== r1 op r0
1428 __ pop_l(r1);
1429 switch (op) {
1430 case add : __ add(r0, r1, r0); break;
1431 case sub : __ sub(r0, r1, r0); break;
1432 case mul : __ mul(r0, r1, r0); break;
1433 case _and : __ andr(r0, r1, r0); break;
1434 case _or : __ orr(r0, r1, r0); break;
1435 case _xor : __ eor(r0, r1, r0); break;
1436 default : ShouldNotReachHere();
1437 }
1438 }
1439
1440 void TemplateTable::idiv()
1441 {
1442 transition(itos, itos);
1443 // explicitly check for div0
1444 Label no_div0;
1445 __ cbnzw(r0, no_div0);
1446 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1447 __ br(rscratch1);
1448 __ bind(no_div0);
1449 __ pop_i(r1);
1450 // r0 <== r1 idiv r0
1451 __ corrected_idivl(r0, r1, r0, /* want_remainder */ false);
1452 }
1453
1454 void TemplateTable::irem()
1455 {
1456 transition(itos, itos);
1457 // explicitly check for div0
1458 Label no_div0;
1459 __ cbnzw(r0, no_div0);
1460 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1461 __ br(rscratch1);
1462 __ bind(no_div0);
1463 __ pop_i(r1);
1464 // r0 <== r1 irem r0
1465 __ corrected_idivl(r0, r1, r0, /* want_remainder */ true);
1466 }
1467
1468 void TemplateTable::lmul()
1469 {
1470 transition(ltos, ltos);
1471 __ pop_l(r1);
1472 __ mul(r0, r0, r1);
1473 }
1474
1475 void TemplateTable::ldiv()
1476 {
1477 transition(ltos, ltos);
1478 // explicitly check for div0
1479 Label no_div0;
1480 __ cbnz(r0, no_div0);
1481 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1482 __ br(rscratch1);
1483 __ bind(no_div0);
1484 __ pop_l(r1);
1485 // r0 <== r1 ldiv r0
1486 __ corrected_idivq(r0, r1, r0, /* want_remainder */ false);
1487 }
1488
1489 void TemplateTable::lrem()
1490 {
1491 transition(ltos, ltos);
1492 // explicitly check for div0
1493 Label no_div0;
1494 __ cbnz(r0, no_div0);
1495 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1496 __ br(rscratch1);
1497 __ bind(no_div0);
1498 __ pop_l(r1);
1499 // r0 <== r1 lrem r0
1500 __ corrected_idivq(r0, r1, r0, /* want_remainder */ true);
1501 }
1502
1503 void TemplateTable::lshl()
1504 {
1505 transition(itos, ltos);
1506 // shift count is in r0
1507 __ pop_l(r1);
1508 __ lslv(r0, r1, r0);
1509 }
1510
1511 void TemplateTable::lshr()
1512 {
1513 transition(itos, ltos);
1514 // shift count is in r0
1515 __ pop_l(r1);
1516 __ asrv(r0, r1, r0);
1517 }
1518
1519 void TemplateTable::lushr()
1520 {
1521 transition(itos, ltos);
1522 // shift count is in r0
1523 __ pop_l(r1);
1524 __ lsrv(r0, r1, r0);
1525 }
1526
1527 void TemplateTable::fop2(Operation op)
1528 {
1529 transition(ftos, ftos);
1530 switch (op) {
1531 case add:
1532 // n.b. use ldrd because this is a 64 bit slot
1533 __ pop_f(v1);
1534 __ fadds(v0, v1, v0);
1535 break;
1536 case sub:
1537 __ pop_f(v1);
1538 __ fsubs(v0, v1, v0);
1539 break;
1540 case mul:
1541 __ pop_f(v1);
1542 __ fmuls(v0, v1, v0);
1543 break;
1544 case div:
1545 __ pop_f(v1);
1546 __ fdivs(v0, v1, v0);
1547 break;
1548 case rem:
1549 __ fmovs(v1, v0);
1550 __ pop_f(v0);
1551 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem));
1552 break;
1553 default:
1554 ShouldNotReachHere();
1555 break;
1556 }
1557 }
1558
1559 void TemplateTable::dop2(Operation op)
1560 {
1561 transition(dtos, dtos);
1562 switch (op) {
1563 case add:
1564 // n.b. use ldrd because this is a 64 bit slot
1565 __ pop_d(v1);
1566 __ faddd(v0, v1, v0);
1567 break;
1568 case sub:
1569 __ pop_d(v1);
1570 __ fsubd(v0, v1, v0);
1571 break;
1572 case mul:
1573 __ pop_d(v1);
1574 __ fmuld(v0, v1, v0);
1575 break;
1576 case div:
1577 __ pop_d(v1);
1578 __ fdivd(v0, v1, v0);
1579 break;
1580 case rem:
1581 __ fmovd(v1, v0);
1582 __ pop_d(v0);
1583 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem));
1584 break;
1585 default:
1586 ShouldNotReachHere();
1587 break;
1588 }
1589 }
1590
1591 void TemplateTable::ineg()
1592 {
1593 transition(itos, itos);
1594 __ negw(r0, r0);
1595
1596 }
1597
1598 void TemplateTable::lneg()
1599 {
1600 transition(ltos, ltos);
1601 __ neg(r0, r0);
1602 }
1603
1604 void TemplateTable::fneg()
1605 {
1606 transition(ftos, ftos);
1607 __ fnegs(v0, v0);
1608 }
1609
1610 void TemplateTable::dneg()
1611 {
1612 transition(dtos, dtos);
1613 __ fnegd(v0, v0);
1614 }
1615
1616 void TemplateTable::iinc()
1617 {
1618 transition(vtos, vtos);
1619 __ load_signed_byte(r1, at_bcp(2)); // get constant
1620 locals_index(r2);
1621 __ ldr(r0, iaddress(r2));
1622 __ addw(r0, r0, r1);
1623 __ str(r0, iaddress(r2));
1624 }
1625
1626 void TemplateTable::wide_iinc()
1627 {
1628 transition(vtos, vtos);
1629 // __ mov(r1, zr);
1630 __ ldrw(r1, at_bcp(2)); // get constant and index
1631 __ rev16(r1, r1);
1632 __ ubfx(r2, r1, 0, 16);
1633 __ neg(r2, r2);
1634 __ sbfx(r1, r1, 16, 16);
1635 __ ldr(r0, iaddress(r2));
1636 __ addw(r0, r0, r1);
1637 __ str(r0, iaddress(r2));
1638 }
1639
1640 void TemplateTable::convert()
1641 {
1642 // Checking
1643 #ifdef ASSERT
1644 {
1645 TosState tos_in = ilgl;
1646 TosState tos_out = ilgl;
1647 switch (bytecode()) {
1648 case Bytecodes::_i2l: // fall through
1649 case Bytecodes::_i2f: // fall through
1650 case Bytecodes::_i2d: // fall through
1651 case Bytecodes::_i2b: // fall through
1652 case Bytecodes::_i2c: // fall through
1653 case Bytecodes::_i2s: tos_in = itos; break;
1654 case Bytecodes::_l2i: // fall through
1655 case Bytecodes::_l2f: // fall through
1656 case Bytecodes::_l2d: tos_in = ltos; break;
1657 case Bytecodes::_f2i: // fall through
1658 case Bytecodes::_f2l: // fall through
1659 case Bytecodes::_f2d: tos_in = ftos; break;
1660 case Bytecodes::_d2i: // fall through
1661 case Bytecodes::_d2l: // fall through
1662 case Bytecodes::_d2f: tos_in = dtos; break;
1663 default : ShouldNotReachHere();
1664 }
1665 switch (bytecode()) {
1666 case Bytecodes::_l2i: // fall through
1667 case Bytecodes::_f2i: // fall through
1668 case Bytecodes::_d2i: // fall through
1669 case Bytecodes::_i2b: // fall through
1670 case Bytecodes::_i2c: // fall through
1671 case Bytecodes::_i2s: tos_out = itos; break;
1672 case Bytecodes::_i2l: // fall through
1673 case Bytecodes::_f2l: // fall through
1674 case Bytecodes::_d2l: tos_out = ltos; break;
1675 case Bytecodes::_i2f: // fall through
1676 case Bytecodes::_l2f: // fall through
1677 case Bytecodes::_d2f: tos_out = ftos; break;
1678 case Bytecodes::_i2d: // fall through
1679 case Bytecodes::_l2d: // fall through
1680 case Bytecodes::_f2d: tos_out = dtos; break;
1681 default : ShouldNotReachHere();
1682 }
1683 transition(tos_in, tos_out);
1684 }
1685 #endif // ASSERT
1686 // static const int64_t is_nan = 0x8000000000000000L;
1687
1688 // Conversion
1689 switch (bytecode()) {
1690 case Bytecodes::_i2l:
1691 __ sxtw(r0, r0);
1692 break;
1693 case Bytecodes::_i2f:
1694 __ scvtfws(v0, r0);
1695 break;
1696 case Bytecodes::_i2d:
1697 __ scvtfwd(v0, r0);
1698 break;
1699 case Bytecodes::_i2b:
1700 __ sxtbw(r0, r0);
1701 break;
1702 case Bytecodes::_i2c:
1703 __ uxthw(r0, r0);
1704 break;
1705 case Bytecodes::_i2s:
1706 __ sxthw(r0, r0);
1707 break;
1708 case Bytecodes::_l2i:
1709 __ uxtw(r0, r0);
1710 break;
1711 case Bytecodes::_l2f:
1712 __ scvtfs(v0, r0);
1713 break;
1714 case Bytecodes::_l2d:
1715 __ scvtfd(v0, r0);
1716 break;
1717 case Bytecodes::_f2i:
1718 {
1719 Label L_Okay;
1720 __ clear_fpsr();
1721 __ fcvtzsw(r0, v0);
1722 __ get_fpsr(r1);
1723 __ cbzw(r1, L_Okay);
1724 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i));
1725 __ bind(L_Okay);
1726 }
1727 break;
1728 case Bytecodes::_f2l:
1729 {
1730 Label L_Okay;
1731 __ clear_fpsr();
1732 __ fcvtzs(r0, v0);
1733 __ get_fpsr(r1);
1734 __ cbzw(r1, L_Okay);
1735 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l));
1736 __ bind(L_Okay);
1737 }
1738 break;
1739 case Bytecodes::_f2d:
1740 __ fcvts(v0, v0);
1741 break;
1742 case Bytecodes::_d2i:
1743 {
1744 Label L_Okay;
1745 __ clear_fpsr();
1746 __ fcvtzdw(r0, v0);
1747 __ get_fpsr(r1);
1748 __ cbzw(r1, L_Okay);
1749 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i));
1750 __ bind(L_Okay);
1751 }
1752 break;
1753 case Bytecodes::_d2l:
1754 {
1755 Label L_Okay;
1756 __ clear_fpsr();
1757 __ fcvtzd(r0, v0);
1758 __ get_fpsr(r1);
1759 __ cbzw(r1, L_Okay);
1760 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l));
1761 __ bind(L_Okay);
1762 }
1763 break;
1764 case Bytecodes::_d2f:
1765 __ fcvtd(v0, v0);
1766 break;
1767 default:
1768 ShouldNotReachHere();
1769 }
1770 }
1771
1772 void TemplateTable::lcmp()
1773 {
1774 transition(ltos, itos);
1775 Label done;
1776 __ pop_l(r1);
1777 __ cmp(r1, r0);
1778 __ mov(r0, (uint64_t)-1L);
1779 __ br(Assembler::LT, done);
1780 // __ mov(r0, 1UL);
1781 // __ csel(r0, r0, zr, Assembler::NE);
1782 // and here is a faster way
1783 __ csinc(r0, zr, zr, Assembler::EQ);
1784 __ bind(done);
1785 }
1786
1787 void TemplateTable::float_cmp(bool is_float, int unordered_result)
1788 {
1789 Label done;
1790 if (is_float) {
1791 // XXX get rid of pop here, use ... reg, mem32
1792 __ pop_f(v1);
1793 __ fcmps(v1, v0);
1794 } else {
1795 // XXX get rid of pop here, use ... reg, mem64
1796 __ pop_d(v1);
1797 __ fcmpd(v1, v0);
1798 }
1799 if (unordered_result < 0) {
1800 // we want -1 for unordered or less than, 0 for equal and 1 for
1801 // greater than.
1802 __ mov(r0, (uint64_t)-1L);
1803 // for FP LT tests less than or unordered
1804 __ br(Assembler::LT, done);
1805 // install 0 for EQ otherwise 1
1806 __ csinc(r0, zr, zr, Assembler::EQ);
1807 } else {
1808 // we want -1 for less than, 0 for equal and 1 for unordered or
1809 // greater than.
1810 __ mov(r0, 1L);
1811 // for FP HI tests greater than or unordered
1812 __ br(Assembler::HI, done);
1813 // install 0 for EQ otherwise ~0
1814 __ csinv(r0, zr, zr, Assembler::EQ);
1815
1816 }
1817 __ bind(done);
1818 }
1819
1820 void TemplateTable::branch(bool is_jsr, bool is_wide)
1821 {
1822 __ profile_taken_branch(r0);
1823 const ByteSize be_offset = MethodCounters::backedge_counter_offset() +
1824 InvocationCounter::counter_offset();
1825 const ByteSize inv_offset = MethodCounters::invocation_counter_offset() +
1826 InvocationCounter::counter_offset();
1827
1828 // load branch displacement
1829 if (!is_wide) {
1830 __ ldrh(r2, at_bcp(1));
1831 __ rev16(r2, r2);
1832 // sign extend the 16 bit value in r2
1833 __ sbfm(r2, r2, 0, 15);
1834 } else {
1835 __ ldrw(r2, at_bcp(1));
1836 __ revw(r2, r2);
1837 // sign extend the 32 bit value in r2
1838 __ sbfm(r2, r2, 0, 31);
1839 }
1840
1841 // Handle all the JSR stuff here, then exit.
1842 // It's much shorter and cleaner than intermingling with the non-JSR
1843 // normal-branch stuff occurring below.
1844
1845 if (is_jsr) {
1846 // Pre-load the next target bytecode into rscratch1
1847 __ load_unsigned_byte(rscratch1, Address(rbcp, r2));
1848 // compute return address as bci
1849 __ ldr(rscratch2, Address(rmethod, Method::const_offset()));
1850 __ add(rscratch2, rscratch2,
1851 in_bytes(ConstMethod::codes_offset()) - (is_wide ? 5 : 3));
1852 __ sub(r1, rbcp, rscratch2);
1853 __ push_i(r1);
1854 // Adjust the bcp by the 16-bit displacement in r2
1855 __ add(rbcp, rbcp, r2);
1856 __ dispatch_only(vtos, /*generate_poll*/true);
1857 return;
1858 }
1859
1860 // Normal (non-jsr) branch handling
1861
1862 // Adjust the bcp by the displacement in r2
1863 __ add(rbcp, rbcp, r2);
1864
1865 assert(UseLoopCounter || !UseOnStackReplacement,
1866 "on-stack-replacement requires loop counters");
1867 Label backedge_counter_overflow;
1868 Label dispatch;
1869 if (UseLoopCounter) {
1870 // increment backedge counter for backward branches
1871 // r0: MDO
1872 // r2: target offset
1873 __ cmp(r2, zr);
1874 __ br(Assembler::GT, dispatch); // count only if backward branch
1875
1876 // ECN: FIXME: This code smells
1877 // check if MethodCounters exists
1878 Label has_counters;
1879 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1880 __ cbnz(rscratch1, has_counters);
1881 __ push(r0);
1882 __ push(r2);
1883 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
1884 InterpreterRuntime::build_method_counters), rmethod);
1885 __ pop(r2);
1886 __ pop(r0);
1887 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1888 __ cbz(rscratch1, dispatch); // No MethodCounters allocated, OutOfMemory
1889 __ bind(has_counters);
1890
1891 Label no_mdo;
1892 int increment = InvocationCounter::count_increment;
1893 if (ProfileInterpreter) {
1894 // Are we profiling?
1895 __ ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
1896 __ cbz(r1, no_mdo);
1897 // Increment the MDO backedge counter
1898 const Address mdo_backedge_counter(r1, in_bytes(MethodData::backedge_counter_offset()) +
1899 in_bytes(InvocationCounter::counter_offset()));
1900 const Address mask(r1, in_bytes(MethodData::backedge_mask_offset()));
1901 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
1902 r0, rscratch1, false, Assembler::EQ,
1903 UseOnStackReplacement ? &backedge_counter_overflow : &dispatch);
1904 __ b(dispatch);
1905 }
1906 __ bind(no_mdo);
1907 // Increment backedge counter in MethodCounters*
1908 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1909 const Address mask(rscratch1, in_bytes(MethodCounters::backedge_mask_offset()));
1910 __ increment_mask_and_jump(Address(rscratch1, be_offset), increment, mask,
1911 r0, rscratch2, false, Assembler::EQ,
1912 UseOnStackReplacement ? &backedge_counter_overflow : &dispatch);
1913 __ bind(dispatch);
1914 }
1915
1916 // Pre-load the next target bytecode into rscratch1
1917 __ load_unsigned_byte(rscratch1, Address(rbcp, 0));
1918
1919 // continue with the bytecode @ target
1920 // rscratch1: target bytecode
1921 // rbcp: target bcp
1922 __ dispatch_only(vtos, /*generate_poll*/true);
1923
1924 if (UseLoopCounter && UseOnStackReplacement) {
1925 // invocation counter overflow
1926 __ bind(backedge_counter_overflow);
1927 __ neg(r2, r2);
1928 __ add(r2, r2, rbcp); // branch bcp
1929 // IcoResult frequency_counter_overflow([JavaThread*], address branch_bcp)
1930 __ call_VM(noreg,
1931 CAST_FROM_FN_PTR(address,
1932 InterpreterRuntime::frequency_counter_overflow),
1933 r2);
1934 __ load_unsigned_byte(r1, Address(rbcp, 0)); // restore target bytecode
1935
1936 // r0: osr nmethod (osr ok) or null (osr not possible)
1937 // w1: target bytecode
1938 // r2: scratch
1939 __ cbz(r0, dispatch); // test result -- no osr if null
1940 // nmethod may have been invalidated (VM may block upon call_VM return)
1941 __ ldrb(r2, Address(r0, nmethod::state_offset()));
1942 if (nmethod::in_use != 0)
1943 __ sub(r2, r2, nmethod::in_use);
1944 __ cbnz(r2, dispatch);
1945
1946 // We have the address of an on stack replacement routine in r0
1947 // We need to prepare to execute the OSR method. First we must
1948 // migrate the locals and monitors off of the stack.
1949
1950 __ mov(r19, r0); // save the nmethod
1951
1952 JFR_ONLY(__ enter_jfr_critical_section();)
1953
1954 call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
1955
1956 // r0 is OSR buffer, move it to expected parameter location
1957 __ mov(j_rarg0, r0);
1958
1959 // remove activation
1960 // get sender esp
1961 __ ldr(esp,
1962 Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
1963 // remove frame anchor
1964 __ leave();
1965
1966 JFR_ONLY(__ leave_jfr_critical_section();)
1967
1968 // Ensure compiled code always sees stack at proper alignment
1969 __ andr(sp, esp, -16);
1970
1971 // and begin the OSR nmethod
1972 __ ldr(rscratch1, Address(r19, nmethod::osr_entry_point_offset()));
1973 __ br(rscratch1);
1974 }
1975 }
1976
1977
1978 void TemplateTable::if_0cmp(Condition cc)
1979 {
1980 transition(itos, vtos);
1981 // assume branch is more often taken than not (loops use backward branches)
1982 Label not_taken;
1983 if (cc == equal)
1984 __ cbnzw(r0, not_taken);
1985 else if (cc == not_equal)
1986 __ cbzw(r0, not_taken);
1987 else {
1988 __ andsw(zr, r0, r0);
1989 __ br(j_not(cc), not_taken);
1990 }
1991
1992 branch(false, false);
1993 __ bind(not_taken);
1994 __ profile_not_taken_branch(r0);
1995 }
1996
1997 void TemplateTable::if_icmp(Condition cc)
1998 {
1999 transition(itos, vtos);
2000 // assume branch is more often taken than not (loops use backward branches)
2001 Label not_taken;
2002 __ pop_i(r1);
2003 __ cmpw(r1, r0, Assembler::LSL);
2004 __ br(j_not(cc), not_taken);
2005 branch(false, false);
2006 __ bind(not_taken);
2007 __ profile_not_taken_branch(r0);
2008 }
2009
2010 void TemplateTable::if_nullcmp(Condition cc)
2011 {
2012 transition(atos, vtos);
2013 // assume branch is more often taken than not (loops use backward branches)
2014 Label not_taken;
2015 if (cc == equal)
2016 __ cbnz(r0, not_taken);
2017 else
2018 __ cbz(r0, not_taken);
2019 branch(false, false);
2020 __ bind(not_taken);
2021 __ profile_not_taken_branch(r0);
2022 }
2023
2024 void TemplateTable::if_acmp(Condition cc) {
2025 transition(atos, vtos);
2026 // assume branch is more often taken than not (loops use backward branches)
2027 Label taken, not_taken;
2028 __ pop_ptr(r1);
2029
2030 __ profile_acmp(r2, r1, r0, r4);
2031
2032 Register is_inline_type_mask = rscratch1;
2033 __ mov(is_inline_type_mask, markWord::inline_type_pattern);
2034
2035 if (Arguments::is_valhalla_enabled()) {
2036 __ cmp(r1, r0);
2037 __ br(Assembler::EQ, (cc == equal) ? taken : not_taken);
2038
2039 // might be substitutable, test if either r0 or r1 is null
2040 __ andr(r2, r0, r1);
2041 __ cbz(r2, (cc == equal) ? not_taken : taken);
2042
2043 // and both are values ?
2044 __ ldr(r2, Address(r1, oopDesc::mark_offset_in_bytes()));
2045 __ andr(r2, r2, is_inline_type_mask);
2046 __ ldr(r4, Address(r0, oopDesc::mark_offset_in_bytes()));
2047 __ andr(r4, r4, is_inline_type_mask);
2048 __ andr(r2, r2, r4);
2049 __ cmp(r2, is_inline_type_mask);
2050 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2051
2052 // same value klass ?
2053 __ load_metadata(r2, r1);
2054 __ load_metadata(r4, r0);
2055 __ cmp(r2, r4);
2056 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2057
2058 // Know both are the same type, let's test for substitutability...
2059 if (cc == equal) {
2060 invoke_is_substitutable(r0, r1, taken, not_taken);
2061 } else {
2062 invoke_is_substitutable(r0, r1, not_taken, taken);
2063 }
2064 __ stop("Not reachable");
2065 }
2066
2067 __ cmpoop(r1, r0);
2068 __ br(j_not(cc), not_taken);
2069 __ bind(taken);
2070 branch(false, false);
2071 __ bind(not_taken);
2072 __ profile_not_taken_branch(r0, true);
2073 }
2074
2075 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2076 Label& is_subst, Label& not_subst) {
2077
2078 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2079 // Restored... r0 answer, jmp to outcome...
2080 __ cbz(r0, not_subst);
2081 __ b(is_subst);
2082 }
2083
2084
2085 void TemplateTable::ret() {
2086 transition(vtos, vtos);
2087 locals_index(r1);
2088 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2089 __ profile_ret(r1, r2);
2090 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2091 __ lea(rbcp, Address(rbcp, r1));
2092 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2093 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2094 }
2095
2096 void TemplateTable::wide_ret() {
2097 transition(vtos, vtos);
2098 locals_index_wide(r1);
2099 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2100 __ profile_ret(r1, r2);
2101 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2102 __ lea(rbcp, Address(rbcp, r1));
2103 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2104 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2105 }
2106
2107
2108 void TemplateTable::tableswitch() {
2109 Label default_case, continue_execution;
2110 transition(itos, vtos);
2111 // align rbcp
2112 __ lea(r1, at_bcp(BytesPerInt));
2113 __ andr(r1, r1, -BytesPerInt);
2114 // load lo & hi
2115 __ ldrw(r2, Address(r1, BytesPerInt));
2116 __ ldrw(r3, Address(r1, 2 * BytesPerInt));
2117 __ rev32(r2, r2);
2118 __ rev32(r3, r3);
2119 // check against lo & hi
2120 __ cmpw(r0, r2);
2121 __ br(Assembler::LT, default_case);
2122 __ cmpw(r0, r3);
2123 __ br(Assembler::GT, default_case);
2124 // lookup dispatch offset
2125 __ subw(r0, r0, r2);
2126 __ lea(r3, Address(r1, r0, Address::uxtw(2)));
2127 __ ldrw(r3, Address(r3, 3 * BytesPerInt));
2128 __ profile_switch_case(r0, r1, r2);
2129 // continue execution
2130 __ bind(continue_execution);
2131 __ rev32(r3, r3);
2132 __ load_unsigned_byte(rscratch1, Address(rbcp, r3, Address::sxtw(0)));
2133 __ add(rbcp, rbcp, r3, ext::sxtw);
2134 __ dispatch_only(vtos, /*generate_poll*/true);
2135 // handle default
2136 __ bind(default_case);
2137 __ profile_switch_default(r0);
2138 __ ldrw(r3, Address(r1, 0));
2139 __ b(continue_execution);
2140 }
2141
2142 void TemplateTable::lookupswitch() {
2143 transition(itos, itos);
2144 __ stop("lookupswitch bytecode should have been rewritten");
2145 }
2146
2147 void TemplateTable::fast_linearswitch() {
2148 transition(itos, vtos);
2149 Label loop_entry, loop, found, continue_execution;
2150 // bswap r0 so we can avoid bswapping the table entries
2151 __ rev32(r0, r0);
2152 // align rbcp
2153 __ lea(r19, at_bcp(BytesPerInt)); // btw: should be able to get rid of
2154 // this instruction (change offsets
2155 // below)
2156 __ andr(r19, r19, -BytesPerInt);
2157 // set counter
2158 __ ldrw(r1, Address(r19, BytesPerInt));
2159 __ rev32(r1, r1);
2160 __ b(loop_entry);
2161 // table search
2162 __ bind(loop);
2163 __ lea(rscratch1, Address(r19, r1, Address::lsl(3)));
2164 __ ldrw(rscratch1, Address(rscratch1, 2 * BytesPerInt));
2165 __ cmpw(r0, rscratch1);
2166 __ br(Assembler::EQ, found);
2167 __ bind(loop_entry);
2168 __ subs(r1, r1, 1);
2169 __ br(Assembler::PL, loop);
2170 // default case
2171 __ profile_switch_default(r0);
2172 __ ldrw(r3, Address(r19, 0));
2173 __ b(continue_execution);
2174 // entry found -> get offset
2175 __ bind(found);
2176 __ lea(rscratch1, Address(r19, r1, Address::lsl(3)));
2177 __ ldrw(r3, Address(rscratch1, 3 * BytesPerInt));
2178 __ profile_switch_case(r1, r0, r19);
2179 // continue execution
2180 __ bind(continue_execution);
2181 __ rev32(r3, r3);
2182 __ add(rbcp, rbcp, r3, ext::sxtw);
2183 __ ldrb(rscratch1, Address(rbcp, 0));
2184 __ dispatch_only(vtos, /*generate_poll*/true);
2185 }
2186
2187 void TemplateTable::fast_binaryswitch() {
2188 transition(itos, vtos);
2189 // Implementation using the following core algorithm:
2190 //
2191 // int binary_search(int key, LookupswitchPair* array, int n) {
2192 // // Binary search according to "Methodik des Programmierens" by
2193 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
2194 // int i = 0;
2195 // int j = n;
2196 // while (i+1 < j) {
2197 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
2198 // // with Q: for all i: 0 <= i < n: key < a[i]
2199 // // where a stands for the array and assuming that the (inexisting)
2200 // // element a[n] is infinitely big.
2201 // int h = (i + j) >> 1;
2202 // // i < h < j
2203 // if (key < array[h].fast_match()) {
2204 // j = h;
2205 // } else {
2206 // i = h;
2207 // }
2208 // }
2209 // // R: a[i] <= key < a[i+1] or Q
2210 // // (i.e., if key is within array, i is the correct index)
2211 // return i;
2212 // }
2213
2214 // Register allocation
2215 const Register key = r0; // already set (tosca)
2216 const Register array = r1;
2217 const Register i = r2;
2218 const Register j = r3;
2219 const Register h = rscratch1;
2220 const Register temp = rscratch2;
2221
2222 // Find array start
2223 __ lea(array, at_bcp(3 * BytesPerInt)); // btw: should be able to
2224 // get rid of this
2225 // instruction (change
2226 // offsets below)
2227 __ andr(array, array, -BytesPerInt);
2228
2229 // Initialize i & j
2230 __ mov(i, 0); // i = 0;
2231 __ ldrw(j, Address(array, -BytesPerInt)); // j = length(array);
2232
2233 // Convert j into native byteordering
2234 __ rev32(j, j);
2235
2236 // And start
2237 Label entry;
2238 __ b(entry);
2239
2240 // binary search loop
2241 {
2242 Label loop;
2243 __ bind(loop);
2244 // int h = (i + j) >> 1;
2245 __ addw(h, i, j); // h = i + j;
2246 __ lsrw(h, h, 1); // h = (i + j) >> 1;
2247 // if (key < array[h].fast_match()) {
2248 // j = h;
2249 // } else {
2250 // i = h;
2251 // }
2252 // Convert array[h].match to native byte-ordering before compare
2253 __ ldr(temp, Address(array, h, Address::lsl(3)));
2254 __ rev32(temp, temp);
2255 __ cmpw(key, temp);
2256 // j = h if (key < array[h].fast_match())
2257 __ csel(j, h, j, Assembler::LT);
2258 // i = h if (key >= array[h].fast_match())
2259 __ csel(i, h, i, Assembler::GE);
2260 // while (i+1 < j)
2261 __ bind(entry);
2262 __ addw(h, i, 1); // i+1
2263 __ cmpw(h, j); // i+1 < j
2264 __ br(Assembler::LT, loop);
2265 }
2266
2267 // end of binary search, result index is i (must check again!)
2268 Label default_case;
2269 // Convert array[i].match to native byte-ordering before compare
2270 __ ldr(temp, Address(array, i, Address::lsl(3)));
2271 __ rev32(temp, temp);
2272 __ cmpw(key, temp);
2273 __ br(Assembler::NE, default_case);
2274
2275 // entry found -> j = offset
2276 __ add(j, array, i, ext::uxtx, 3);
2277 __ ldrw(j, Address(j, BytesPerInt));
2278 __ profile_switch_case(i, key, array);
2279 __ rev32(j, j);
2280 __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0)));
2281 __ lea(rbcp, Address(rbcp, j, Address::sxtw(0)));
2282 __ dispatch_only(vtos, /*generate_poll*/true);
2283
2284 // default case -> j = default offset
2285 __ bind(default_case);
2286 __ profile_switch_default(i);
2287 __ ldrw(j, Address(array, -2 * BytesPerInt));
2288 __ rev32(j, j);
2289 __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0)));
2290 __ lea(rbcp, Address(rbcp, j, Address::sxtw(0)));
2291 __ dispatch_only(vtos, /*generate_poll*/true);
2292 }
2293
2294
2295 void TemplateTable::_return(TosState state)
2296 {
2297 transition(state, state);
2298 assert(_desc->calls_vm(),
2299 "inconsistent calls_vm information"); // call in remove_activation
2300
2301 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2302 assert(state == vtos, "only valid state");
2303
2304 __ ldr(c_rarg1, aaddress(0));
2305 __ load_klass(r3, c_rarg1);
2306 __ ldrb(r3, Address(r3, Klass::misc_flags_offset()));
2307 Label skip_register_finalizer;
2308 __ tbz(r3, exact_log2(KlassFlags::_misc_has_finalizer), skip_register_finalizer);
2309
2310 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), c_rarg1);
2311
2312 __ bind(skip_register_finalizer);
2313 }
2314
2315 // Issue a StoreStore barrier after all stores but before return
2316 // from any constructor for any class with a final field. We don't
2317 // know if this is a finalizer, so we always do so.
2318 if (_desc->bytecode() == Bytecodes::_return
2319 || _desc->bytecode() == Bytecodes::_return_register_finalizer)
2320 __ membar(MacroAssembler::StoreStore);
2321
2322 if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2323 Label no_safepoint;
2324 __ ldr(rscratch1, Address(rthread, JavaThread::polling_word_offset()));
2325 __ tbz(rscratch1, log2i_exact(SafepointMechanism::poll_bit()), no_safepoint);
2326 __ push(state);
2327 __ push_cont_fastpath(rthread);
2328 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint));
2329 __ pop_cont_fastpath(rthread);
2330 __ pop(state);
2331 __ bind(no_safepoint);
2332 }
2333
2334 // Narrow result if state is itos but result type is smaller.
2335 // Need to narrow in the return bytecode rather than in generate_return_entry
2336 // since compiled code callers expect the result to already be narrowed.
2337 if (state == itos) {
2338 __ narrow(r0);
2339 }
2340
2341 __ remove_activation(state);
2342 __ ret(lr);
2343 }
2344
2345 // ----------------------------------------------------------------------------
2346 // Volatile variables demand their effects be made known to all CPU's
2347 // in order. Store buffers on most chips allow reads & writes to
2348 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2349 // without some kind of memory barrier (i.e., it's not sufficient that
2350 // the interpreter does not reorder volatile references, the hardware
2351 // also must not reorder them).
2352 //
2353 // According to the new Java Memory Model (JMM):
2354 // (1) All volatiles are serialized wrt to each other. ALSO reads &
2355 // writes act as acquire & release, so:
2356 // (2) A read cannot let unrelated NON-volatile memory refs that
2357 // happen after the read float up to before the read. It's OK for
2358 // non-volatile memory refs that happen before the volatile read to
2359 // float down below it.
2360 // (3) Similar a volatile write cannot let unrelated NON-volatile
2361 // memory refs that happen BEFORE the write float down to after the
2362 // write. It's OK for non-volatile memory refs that happen after the
2363 // volatile write to float up before it.
2364 //
2365 // We only put in barriers around volatile refs (they are expensive),
2366 // not _between_ memory refs (that would require us to track the
2367 // flavor of the previous memory refs). Requirements (2) and (3)
2368 // require some barriers before volatile stores and after volatile
2369 // loads. These nearly cover requirement (1) but miss the
2370 // volatile-store-volatile-load case. This final case is placed after
2371 // volatile-stores although it could just as well go before
2372 // volatile-loads.
2373
2374 void TemplateTable::resolve_cache_and_index_for_method(int byte_no,
2375 Register Rcache,
2376 Register index) {
2377 const Register temp = r19;
2378 assert_different_registers(Rcache, index, temp);
2379 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2380
2381 Label L_clinit_barrier_slow, L_done;
2382
2383 Bytecodes::Code code = bytecode();
2384 __ load_method_entry(Rcache, index);
2385 switch(byte_no) {
2386 case f1_byte:
2387 __ lea(temp, Address(Rcache, in_bytes(ResolvedMethodEntry::bytecode1_offset())));
2388 break;
2389 case f2_byte:
2390 __ lea(temp, Address(Rcache, in_bytes(ResolvedMethodEntry::bytecode2_offset())));
2391 break;
2392 }
2393 // Load-acquire the bytecode to match store-release in InterpreterRuntime
2394 __ ldarb(temp, temp);
2395 __ subs(zr, temp, (int) code); // have we resolved this bytecode?
2396
2397 // Class initialization barrier for static methods
2398 if (bytecode() == Bytecodes::_invokestatic) {
2399 assert(VM_Version::supports_fast_class_init_checks(), "sanity");
2400 __ br(Assembler::NE, L_clinit_barrier_slow);
2401 __ ldr(temp, Address(Rcache, in_bytes(ResolvedMethodEntry::method_offset())));
2402 __ load_method_holder(temp, temp);
2403 __ clinit_barrier(temp, rscratch1, &L_done, /*L_slow_path*/ nullptr);
2404 __ bind(L_clinit_barrier_slow);
2405 } else {
2406 __ br(Assembler::EQ, L_done);
2407 }
2408
2409 // resolve first time through
2410 // Class initialization barrier slow path lands here as well.
2411 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2412 __ mov(temp, (int) code);
2413 __ call_VM_preemptable(noreg, entry, temp);
2414
2415 // Update registers with resolved info
2416 __ load_method_entry(Rcache, index);
2417 // n.b. unlike x86 Rcache is now rcpool plus the indexed offset
2418 // so all clients ofthis method must be modified accordingly
2419 __ bind(L_done);
2420 }
2421
2422 void TemplateTable::resolve_cache_and_index_for_field(int byte_no,
2423 Register Rcache,
2424 Register index) {
2425 const Register temp = r19;
2426 assert_different_registers(Rcache, index, temp);
2427
2428 Label L_clinit_barrier_slow, L_done;
2429
2430 Bytecodes::Code code = bytecode();
2431 switch (code) {
2432 case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break;
2433 case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break;
2434 default: break;
2435 }
2436
2437 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2438 __ load_field_entry(Rcache, index);
2439 if (byte_no == f1_byte) {
2440 __ lea(temp, Address(Rcache, in_bytes(ResolvedFieldEntry::get_code_offset())));
2441 } else {
2442 __ lea(temp, Address(Rcache, in_bytes(ResolvedFieldEntry::put_code_offset())));
2443 }
2444 // Load-acquire the bytecode to match store-release in ResolvedFieldEntry::fill_in()
2445 __ ldarb(temp, temp);
2446 __ subs(zr, temp, (int) code); // have we resolved this bytecode?
2447
2448 // Class initialization barrier for static fields
2449 if (bytecode() == Bytecodes::_getstatic || bytecode() == Bytecodes::_putstatic) {
2450 assert(VM_Version::supports_fast_class_init_checks(), "sanity");
2451 const Register field_holder = temp;
2452
2453 __ br(Assembler::NE, L_clinit_barrier_slow);
2454 __ ldr(field_holder, Address(Rcache, in_bytes(ResolvedFieldEntry::field_holder_offset())));
2455 __ clinit_barrier(field_holder, rscratch1, &L_done, /*L_slow_path*/ nullptr);
2456 __ bind(L_clinit_barrier_slow);
2457 } else {
2458 __ br(Assembler::EQ, L_done);
2459 }
2460
2461 // resolve first time through
2462 // Class initialization barrier slow path lands here as well.
2463 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2464 __ mov(temp, (int) code);
2465 __ call_VM_preemptable(noreg, entry, temp);
2466
2467 // Update registers with resolved info
2468 __ load_field_entry(Rcache, index);
2469 __ bind(L_done);
2470 }
2471
2472 void TemplateTable::load_resolved_field_entry(Register obj,
2473 Register cache,
2474 Register tos_state,
2475 Register offset,
2476 Register flags,
2477 bool is_static = false) {
2478 assert_different_registers(cache, tos_state, flags, offset);
2479
2480 // Field offset
2481 __ load_sized_value(offset, Address(cache, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
2482
2483 // Flags
2484 __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedFieldEntry::flags_offset())));
2485
2486 // TOS state
2487 if (tos_state != noreg) {
2488 __ load_unsigned_byte(tos_state, Address(cache, in_bytes(ResolvedFieldEntry::type_offset())));
2489 }
2490
2491 // Klass overwrite register
2492 if (is_static) {
2493 __ ldr(obj, Address(cache, ResolvedFieldEntry::field_holder_offset()));
2494 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
2495 __ ldr(obj, Address(obj, mirror_offset));
2496 __ resolve_oop_handle(obj, r5, rscratch2);
2497 }
2498 }
2499
2500 void TemplateTable::load_resolved_method_entry_special_or_static(Register cache,
2501 Register method,
2502 Register flags) {
2503
2504 // setup registers
2505 const Register index = flags;
2506 assert_different_registers(method, cache, flags);
2507
2508 // determine constant pool cache field offsets
2509 resolve_cache_and_index_for_method(f1_byte, cache, index);
2510 __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2511 __ ldr(method, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2512 }
2513
2514 void TemplateTable::load_resolved_method_entry_handle(Register cache,
2515 Register method,
2516 Register ref_index,
2517 Register flags) {
2518 // setup registers
2519 const Register index = ref_index;
2520 assert_different_registers(method, flags);
2521 assert_different_registers(method, cache, index);
2522
2523 // determine constant pool cache field offsets
2524 resolve_cache_and_index_for_method(f1_byte, cache, index);
2525 __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2526
2527 // maybe push appendix to arguments (just before return address)
2528 Label L_no_push;
2529 __ tbz(flags, ResolvedMethodEntry::has_appendix_shift, L_no_push);
2530 // invokehandle uses an index into the resolved references array
2531 __ load_unsigned_short(ref_index, Address(cache, in_bytes(ResolvedMethodEntry::resolved_references_index_offset())));
2532 // Push the appendix as a trailing parameter.
2533 // This must be done before we get the receiver,
2534 // since the parameter_size includes it.
2535 Register appendix = method;
2536 __ load_resolved_reference_at_index(appendix, ref_index);
2537 __ push(appendix); // push appendix (MethodType, CallSite, etc.)
2538 __ bind(L_no_push);
2539
2540 __ ldr(method, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2541 }
2542
2543 void TemplateTable::load_resolved_method_entry_interface(Register cache,
2544 Register klass,
2545 Register method_or_table_index,
2546 Register flags) {
2547 // setup registers
2548 const Register index = method_or_table_index;
2549 assert_different_registers(method_or_table_index, cache, flags);
2550
2551 // determine constant pool cache field offsets
2552 resolve_cache_and_index_for_method(f1_byte, cache, index);
2553 __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2554
2555 // Invokeinterface can behave in different ways:
2556 // If calling a method from java.lang.Object, the forced virtual flag is true so the invocation will
2557 // behave like an invokevirtual call. The state of the virtual final flag will determine whether a method or
2558 // vtable index is placed in the register.
2559 // Otherwise, the registers will be populated with the klass and method.
2560
2561 Label NotVirtual; Label NotVFinal; Label Done;
2562 __ tbz(flags, ResolvedMethodEntry::is_forced_virtual_shift, NotVirtual);
2563 __ tbz(flags, ResolvedMethodEntry::is_vfinal_shift, NotVFinal);
2564 __ ldr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2565 __ b(Done);
2566
2567 __ bind(NotVFinal);
2568 __ load_unsigned_short(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::table_index_offset())));
2569 __ b(Done);
2570
2571 __ bind(NotVirtual);
2572 __ ldr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2573 __ ldr(klass, Address(cache, in_bytes(ResolvedMethodEntry::klass_offset())));
2574 __ bind(Done);
2575 }
2576
2577 void TemplateTable::load_resolved_method_entry_virtual(Register cache,
2578 Register method_or_table_index,
2579 Register flags) {
2580 // setup registers
2581 const Register index = flags;
2582 assert_different_registers(method_or_table_index, cache, flags);
2583
2584 // determine constant pool cache field offsets
2585 resolve_cache_and_index_for_method(f2_byte, cache, index);
2586 __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2587
2588 // method_or_table_index can either be an itable index or a method depending on the virtual final flag
2589 Label NotVFinal; Label Done;
2590 __ tbz(flags, ResolvedMethodEntry::is_vfinal_shift, NotVFinal);
2591 __ ldr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2592 __ b(Done);
2593
2594 __ bind(NotVFinal);
2595 __ load_unsigned_short(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::table_index_offset())));
2596 __ bind(Done);
2597 }
2598
2599 // The rmethod register is input and overwritten to be the adapter method for the
2600 // indy call. Link Register (lr) is set to the return address for the adapter and
2601 // an appendix may be pushed to the stack. Registers r0-r3 are clobbered
2602 void TemplateTable::load_invokedynamic_entry(Register method) {
2603 // setup registers
2604 const Register appendix = r0;
2605 const Register cache = r2;
2606 const Register index = r3;
2607 assert_different_registers(method, appendix, cache, index, rcpool);
2608
2609 __ save_bcp();
2610
2611 Label resolved;
2612
2613 __ load_resolved_indy_entry(cache, index);
2614 // Load-acquire the adapter method to match store-release in ResolvedIndyEntry::fill_in()
2615 __ lea(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2616 __ ldar(method, method);
2617
2618 // Compare the method to zero
2619 __ cbnz(method, resolved);
2620
2621 Bytecodes::Code code = bytecode();
2622
2623 // Call to the interpreter runtime to resolve invokedynamic
2624 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2625 __ mov(method, code); // this is essentially Bytecodes::_invokedynamic
2626 __ call_VM(noreg, entry, method);
2627 // Update registers with resolved info
2628 __ load_resolved_indy_entry(cache, index);
2629 // Load-acquire the adapter method to match store-release in ResolvedIndyEntry::fill_in()
2630 __ lea(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2631 __ ldar(method, method);
2632
2633 #ifdef ASSERT
2634 __ cbnz(method, resolved);
2635 __ stop("Should be resolved by now");
2636 #endif // ASSERT
2637 __ bind(resolved);
2638
2639 Label L_no_push;
2640 // Check if there is an appendix
2641 __ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::flags_offset())));
2642 __ tbz(index, ResolvedIndyEntry::has_appendix_shift, L_no_push);
2643
2644 // Get appendix
2645 __ load_unsigned_short(index, Address(cache, in_bytes(ResolvedIndyEntry::resolved_references_index_offset())));
2646 // Push the appendix as a trailing parameter
2647 // since the parameter_size includes it.
2648 __ push(method);
2649 __ mov(method, index);
2650 __ load_resolved_reference_at_index(appendix, method);
2651 __ verify_oop(appendix);
2652 __ pop(method);
2653 __ push(appendix); // push appendix (MethodType, CallSite, etc.)
2654 __ bind(L_no_push);
2655
2656 // compute return type
2657 __ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::result_type_offset())));
2658 // load return address
2659 // Return address is loaded into link register(lr) and not pushed to the stack
2660 // like x86
2661 {
2662 const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
2663 __ mov(rscratch1, table_addr);
2664 __ ldr(lr, Address(rscratch1, index, Address::lsl(3)));
2665 }
2666 }
2667
2668 // The registers cache and index expected to be set before call.
2669 // Correct values of the cache and index registers are preserved.
2670 void TemplateTable::jvmti_post_field_access(Register cache, Register index,
2671 bool is_static, bool has_tos) {
2672 // do the JVMTI work here to avoid disturbing the register state below
2673 // We use c_rarg registers here because we want to use the register used in
2674 // the call to the VM
2675 if (JvmtiExport::can_post_field_access()) {
2676 // Check to see if a field access watch has been set before we
2677 // take the time to call into the VM.
2678 Label L1;
2679 assert_different_registers(cache, index, r0);
2680 __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
2681 __ ldrw(r0, Address(rscratch1));
2682 __ cbzw(r0, L1);
2683
2684 __ load_field_entry(c_rarg2, index);
2685
2686 if (is_static) {
2687 __ mov(c_rarg1, zr); // null object reference
2688 } else {
2689 __ ldr(c_rarg1, at_tos()); // get object pointer without popping it
2690 __ verify_oop(c_rarg1);
2691 }
2692 // c_rarg1: object pointer or null
2693 // c_rarg2: cache entry pointer
2694 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2695 InterpreterRuntime::post_field_access),
2696 c_rarg1, c_rarg2);
2697 __ load_field_entry(cache, index);
2698 __ bind(L1);
2699 }
2700 }
2701
2702 void TemplateTable::pop_and_check_object(Register r)
2703 {
2704 __ pop_ptr(r);
2705 __ null_check(r); // for field access must check obj.
2706 __ verify_oop(r);
2707 }
2708
2709 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2710 {
2711 const Register cache = r2;
2712 const Register obj = r4;
2713 const Register index = r3;
2714 const Register tos_state = r3;
2715 const Register off = r19;
2716 const Register flags = r6;
2717 const Register bc = r4; // uses same reg as obj, so don't mix them
2718
2719 resolve_cache_and_index_for_field(byte_no, cache, index);
2720 jvmti_post_field_access(cache, index, is_static, false);
2721
2722 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2723
2724 if (!is_static) {
2725 // obj is on the stack
2726 pop_and_check_object(obj);
2727 }
2728
2729 // 8179954: We need to make sure that the code generated for
2730 // volatile accesses forms a sequentially-consistent set of
2731 // operations when combined with STLR and LDAR. Without a leading
2732 // membar it's possible for a simple Dekker test to fail if loads
2733 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
2734 // the stores in one method and we interpret the loads in another.
2735 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2736 Label notVolatile;
2737 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2738 __ membar(MacroAssembler::AnyAny);
2739 __ bind(notVolatile);
2740 }
2741
2742 const Address field(obj, off);
2743
2744 Label Done, notByte, notBool, notInt, notShort, notChar,
2745 notLong, notFloat, notObj, notDouble;
2746
2747 assert(btos == 0, "change code, btos != 0");
2748 __ cbnz(tos_state, notByte);
2749
2750 // Don't rewrite getstatic, only getfield
2751 if (is_static) rc = may_not_rewrite;
2752
2753 // btos
2754 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
2755 __ push(btos);
2756 // Rewrite bytecode to be faster
2757 if (rc == may_rewrite) {
2758 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2759 }
2760 __ b(Done);
2761
2762 __ bind(notByte);
2763 __ cmp(tos_state, (u1)ztos);
2764 __ br(Assembler::NE, notBool);
2765
2766 // ztos (same code as btos)
2767 __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2768 __ push(ztos);
2769 // Rewrite bytecode to be faster
2770 if (rc == may_rewrite) {
2771 // use btos rewriting, no truncating to t/f bit is needed for getfield.
2772 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2773 }
2774 __ b(Done);
2775
2776 __ bind(notBool);
2777 __ cmp(tos_state, (u1)atos);
2778 __ br(Assembler::NE, notObj);
2779 // atos
2780 if (!Arguments::is_valhalla_enabled()) {
2781 do_oop_load(_masm, field, r0, IN_HEAP);
2782 __ push(atos);
2783 if (rc == may_rewrite) {
2784 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2785 }
2786 __ b(Done);
2787 } else { // Valhalla
2788 if (is_static) {
2789 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2790 __ push(atos);
2791 __ b(Done);
2792 } else {
2793 Label is_flat;
2794 __ test_field_is_flat(flags, noreg /* temp */, is_flat);
2795 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2796 __ push(atos);
2797 if (rc == may_rewrite) {
2798 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2799 }
2800 __ b(Done);
2801 __ bind(is_flat);
2802 // field is flat (null-free or nullable with a null-marker)
2803 __ mov(r0, obj);
2804 __ read_flat_field(cache, r0);
2805 __ verify_oop(r0);
2806 __ push(atos);
2807 if (rc == may_rewrite) {
2808 patch_bytecode(Bytecodes::_fast_vgetfield, bc, r1);
2809 }
2810 __ b(Done);
2811 }
2812 }
2813
2814 __ bind(notObj);
2815 __ cmp(tos_state, (u1)itos);
2816 __ br(Assembler::NE, notInt);
2817 // itos
2818 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2819 __ push(itos);
2820 // Rewrite bytecode to be faster
2821 if (rc == may_rewrite) {
2822 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2823 }
2824 __ b(Done);
2825
2826 __ bind(notInt);
2827 __ cmp(tos_state, (u1)ctos);
2828 __ br(Assembler::NE, notChar);
2829 // ctos
2830 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2831 __ push(ctos);
2832 // Rewrite bytecode to be faster
2833 if (rc == may_rewrite) {
2834 patch_bytecode(Bytecodes::_fast_cgetfield, bc, r1);
2835 }
2836 __ b(Done);
2837
2838 __ bind(notChar);
2839 __ cmp(tos_state, (u1)stos);
2840 __ br(Assembler::NE, notShort);
2841 // stos
2842 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
2843 __ push(stos);
2844 // Rewrite bytecode to be faster
2845 if (rc == may_rewrite) {
2846 patch_bytecode(Bytecodes::_fast_sgetfield, bc, r1);
2847 }
2848 __ b(Done);
2849
2850 __ bind(notShort);
2851 __ cmp(tos_state, (u1)ltos);
2852 __ br(Assembler::NE, notLong);
2853 // ltos
2854 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
2855 __ push(ltos);
2856 // Rewrite bytecode to be faster
2857 if (rc == may_rewrite) {
2858 patch_bytecode(Bytecodes::_fast_lgetfield, bc, r1);
2859 }
2860 __ b(Done);
2861
2862 __ bind(notLong);
2863 __ cmp(tos_state, (u1)ftos);
2864 __ br(Assembler::NE, notFloat);
2865 // ftos
2866 __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
2867 __ push(ftos);
2868 // Rewrite bytecode to be faster
2869 if (rc == may_rewrite) {
2870 patch_bytecode(Bytecodes::_fast_fgetfield, bc, r1);
2871 }
2872 __ b(Done);
2873
2874 __ bind(notFloat);
2875 #ifdef ASSERT
2876 __ cmp(tos_state, (u1)dtos);
2877 __ br(Assembler::NE, notDouble);
2878 #endif
2879 // dtos
2880 __ access_load_at(T_DOUBLE, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
2881 __ push(dtos);
2882 // Rewrite bytecode to be faster
2883 if (rc == may_rewrite) {
2884 patch_bytecode(Bytecodes::_fast_dgetfield, bc, r1);
2885 }
2886 #ifdef ASSERT
2887 __ b(Done);
2888
2889 __ bind(notDouble);
2890 __ stop("Bad state");
2891 #endif
2892
2893 __ bind(Done);
2894
2895 Label notVolatile;
2896 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2897 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
2898 __ bind(notVolatile);
2899 }
2900
2901
2902 void TemplateTable::getfield(int byte_no)
2903 {
2904 getfield_or_static(byte_no, false);
2905 }
2906
2907 void TemplateTable::nofast_getfield(int byte_no) {
2908 getfield_or_static(byte_no, false, may_not_rewrite);
2909 }
2910
2911 void TemplateTable::getstatic(int byte_no)
2912 {
2913 getfield_or_static(byte_no, true);
2914 }
2915
2916 // The registers cache and index expected to be set before call.
2917 // The function may destroy various registers, just not the cache and index registers.
2918 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2919 transition(vtos, vtos);
2920
2921 if (JvmtiExport::can_post_field_modification()) {
2922 // Check to see if a field modification watch has been set before
2923 // we take the time to call into the VM.
2924 Label L1;
2925 assert_different_registers(cache, index, r0);
2926 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2927 __ ldrw(r0, Address(rscratch1));
2928 __ cbz(r0, L1);
2929
2930 __ mov(c_rarg2, cache);
2931
2932 if (is_static) {
2933 // Life is simple. Null out the object pointer.
2934 __ mov(c_rarg1, zr);
2935 } else {
2936 // Life is harder. The stack holds the value on top, followed by
2937 // the object. We don't know the size of the value, though; it
2938 // could be one or two words depending on its type. As a result,
2939 // we must find the type to determine where the object is.
2940 __ load_unsigned_byte(c_rarg3, Address(c_rarg2, in_bytes(ResolvedFieldEntry::type_offset())));
2941 Label nope2, done, ok;
2942 __ ldr(c_rarg1, at_tos_p1()); // initially assume a one word jvalue
2943 __ cmpw(c_rarg3, ltos);
2944 __ br(Assembler::EQ, ok);
2945 __ cmpw(c_rarg3, dtos);
2946 __ br(Assembler::NE, nope2);
2947 __ bind(ok);
2948 __ ldr(c_rarg1, at_tos_p2()); // ltos (two word jvalue)
2949 __ bind(nope2);
2950 }
2951 // object (tos)
2952 __ mov(c_rarg3, esp);
2953 // c_rarg1: object pointer set up above (null if static)
2954 // c_rarg2: cache entry pointer
2955 // c_rarg3: jvalue object on the stack
2956 __ call_VM(noreg,
2957 CAST_FROM_FN_PTR(address,
2958 InterpreterRuntime::post_field_modification),
2959 c_rarg1, c_rarg2, c_rarg3);
2960 __ load_field_entry(cache, index);
2961 __ bind(L1);
2962 }
2963 }
2964
2965 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2966 transition(vtos, vtos);
2967
2968 const Register cache = r2;
2969 const Register index = r3;
2970 const Register tos_state = r3;
2971 const Register obj = r2;
2972 const Register off = r19;
2973 const Register flags = r6;
2974 const Register bc = r4;
2975
2976 resolve_cache_and_index_for_field(byte_no, cache, index);
2977 jvmti_post_field_mod(cache, index, is_static);
2978 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2979
2980 Label Done;
2981 {
2982 Label notVolatile;
2983 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2984 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2985 __ bind(notVolatile);
2986 }
2987
2988 // field address
2989 const Address field(obj, off);
2990
2991 Label notByte, notBool, notInt, notShort, notChar,
2992 notLong, notFloat, notObj, notDouble;
2993
2994 assert(btos == 0, "change code, btos != 0");
2995 __ cbnz(tos_state, notByte);
2996
2997 // Don't rewrite putstatic, only putfield
2998 if (is_static) rc = may_not_rewrite;
2999
3000 // btos
3001 {
3002 __ pop(btos);
3003 if (!is_static) pop_and_check_object(obj);
3004 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3005 if (rc == may_rewrite) {
3006 patch_bytecode(Bytecodes::_fast_bputfield, bc, r1, true, byte_no);
3007 }
3008 __ b(Done);
3009 }
3010
3011 __ bind(notByte);
3012 __ cmp(tos_state, (u1)ztos);
3013 __ br(Assembler::NE, notBool);
3014
3015 // ztos
3016 {
3017 __ pop(ztos);
3018 if (!is_static) pop_and_check_object(obj);
3019 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3020 if (rc == may_rewrite) {
3021 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
3022 }
3023 __ b(Done);
3024 }
3025
3026 __ bind(notBool);
3027 __ cmp(tos_state, (u1)atos);
3028 __ br(Assembler::NE, notObj);
3029
3030 // atos
3031 {
3032 if (!Arguments::is_valhalla_enabled()) {
3033 __ pop(atos);
3034 if (!is_static) pop_and_check_object(obj);
3035 // Store into the field
3036 // Clobbers: r10, r11, r3
3037 do_oop_store(_masm, field, r0, IN_HEAP);
3038 if (rc == may_rewrite) {
3039 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
3040 }
3041 __ b(Done);
3042 } else { // Valhalla
3043 __ pop(atos);
3044 if (is_static) {
3045 Label is_nullable;
3046 __ test_field_is_not_null_free_inline_type(flags, noreg /* temp */, is_nullable);
3047 __ null_check(r0); // FIXME JDK-8341120
3048 __ bind(is_nullable);
3049 do_oop_store(_masm, field, r0, IN_HEAP);
3050 __ b(Done);
3051 } else {
3052 Label null_free_reference, is_flat, rewrite_inline;
3053 __ test_field_is_flat(flags, noreg /* temp */, is_flat);
3054 __ test_field_is_null_free_inline_type(flags, noreg /* temp */, null_free_reference);
3055 pop_and_check_object(obj);
3056 // Store into the field
3057 // Clobbers: r10, r11, r3
3058 do_oop_store(_masm, field, r0, IN_HEAP);
3059 if (rc == may_rewrite) {
3060 patch_bytecode(Bytecodes::_fast_aputfield, bc, r19, true, byte_no);
3061 }
3062 __ b(Done);
3063 // Implementation of the inline type semantic
3064 __ bind(null_free_reference);
3065 __ null_check(r0); // FIXME JDK-8341120
3066 pop_and_check_object(obj);
3067 // Store into the field
3068 // Clobbers: r10, r11, r3
3069 do_oop_store(_masm, field, r0, IN_HEAP);
3070 __ b(rewrite_inline);
3071 __ bind(is_flat);
3072 pop_and_check_object(r7);
3073 __ write_flat_field(cache, off, index, flags, r7);
3074 __ bind(rewrite_inline);
3075 if (rc == may_rewrite) {
3076 patch_bytecode(Bytecodes::_fast_vputfield, bc, r19, true, byte_no);
3077 }
3078 __ b(Done);
3079 }
3080 } // Valhalla
3081 }
3082
3083 __ bind(notObj);
3084 __ cmp(tos_state, (u1)itos);
3085 __ br(Assembler::NE, notInt);
3086
3087 // itos
3088 {
3089 __ pop(itos);
3090 if (!is_static) pop_and_check_object(obj);
3091 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3092 if (rc == may_rewrite) {
3093 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
3094 }
3095 __ b(Done);
3096 }
3097
3098 __ bind(notInt);
3099 __ cmp(tos_state, (u1)ctos);
3100 __ br(Assembler::NE, notChar);
3101
3102 // ctos
3103 {
3104 __ pop(ctos);
3105 if (!is_static) pop_and_check_object(obj);
3106 __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);
3107 if (rc == may_rewrite) {
3108 patch_bytecode(Bytecodes::_fast_cputfield, bc, r1, true, byte_no);
3109 }
3110 __ b(Done);
3111 }
3112
3113 __ bind(notChar);
3114 __ cmp(tos_state, (u1)stos);
3115 __ br(Assembler::NE, notShort);
3116
3117 // stos
3118 {
3119 __ pop(stos);
3120 if (!is_static) pop_and_check_object(obj);
3121 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3122 if (rc == may_rewrite) {
3123 patch_bytecode(Bytecodes::_fast_sputfield, bc, r1, true, byte_no);
3124 }
3125 __ b(Done);
3126 }
3127
3128 __ bind(notShort);
3129 __ cmp(tos_state, (u1)ltos);
3130 __ br(Assembler::NE, notLong);
3131
3132 // ltos
3133 {
3134 __ pop(ltos);
3135 if (!is_static) pop_and_check_object(obj);
3136 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3137 if (rc == may_rewrite) {
3138 patch_bytecode(Bytecodes::_fast_lputfield, bc, r1, true, byte_no);
3139 }
3140 __ b(Done);
3141 }
3142
3143 __ bind(notLong);
3144 __ cmp(tos_state, (u1)ftos);
3145 __ br(Assembler::NE, notFloat);
3146
3147 // ftos
3148 {
3149 __ pop(ftos);
3150 if (!is_static) pop_and_check_object(obj);
3151 __ access_store_at(T_FLOAT, IN_HEAP, field, noreg /* ftos */, noreg, noreg, noreg);
3152 if (rc == may_rewrite) {
3153 patch_bytecode(Bytecodes::_fast_fputfield, bc, r1, true, byte_no);
3154 }
3155 __ b(Done);
3156 }
3157
3158 __ bind(notFloat);
3159 #ifdef ASSERT
3160 __ cmp(tos_state, (u1)dtos);
3161 __ br(Assembler::NE, notDouble);
3162 #endif
3163
3164 // dtos
3165 {
3166 __ pop(dtos);
3167 if (!is_static) pop_and_check_object(obj);
3168 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3169 if (rc == may_rewrite) {
3170 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
3171 }
3172 }
3173
3174 #ifdef ASSERT
3175 __ b(Done);
3176
3177 __ bind(notDouble);
3178 __ stop("Bad state");
3179 #endif
3180
3181 __ bind(Done);
3182
3183 {
3184 Label notVolatile;
3185 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3186 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3187 __ bind(notVolatile);
3188 }
3189 }
3190
3191 void TemplateTable::putfield(int byte_no)
3192 {
3193 putfield_or_static(byte_no, false);
3194 }
3195
3196 void TemplateTable::nofast_putfield(int byte_no) {
3197 putfield_or_static(byte_no, false, may_not_rewrite);
3198 }
3199
3200 void TemplateTable::putstatic(int byte_no) {
3201 putfield_or_static(byte_no, true);
3202 }
3203
3204 void TemplateTable::jvmti_post_fast_field_mod() {
3205 if (JvmtiExport::can_post_field_modification()) {
3206 // Check to see if a field modification watch has been set before
3207 // we take the time to call into the VM.
3208 Label L2;
3209 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3210 __ ldrw(c_rarg3, Address(rscratch1));
3211 __ cbzw(c_rarg3, L2);
3212 __ pop_ptr(r19); // copy the object pointer from tos
3213 __ verify_oop(r19);
3214 __ push_ptr(r19); // put the object pointer back on tos
3215 // Save tos values before call_VM() clobbers them. Since we have
3216 // to do it for every data type, we use the saved values as the
3217 // jvalue object.
3218 switch (bytecode()) { // load values into the jvalue object
3219 case Bytecodes::_fast_vputfield: // fall through
3220 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3221 case Bytecodes::_fast_bputfield: // fall through
3222 case Bytecodes::_fast_zputfield: // fall through
3223 case Bytecodes::_fast_sputfield: // fall through
3224 case Bytecodes::_fast_cputfield: // fall through
3225 case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3226 case Bytecodes::_fast_dputfield: __ push_d(); break;
3227 case Bytecodes::_fast_fputfield: __ push_f(); break;
3228 case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3229
3230 default:
3231 ShouldNotReachHere();
3232 }
3233 __ mov(c_rarg3, esp); // points to jvalue on the stack
3234 // access constant pool cache entry
3235 __ load_field_entry(c_rarg2, r0);
3236 __ verify_oop(r19);
3237 // r19: object pointer copied above
3238 // c_rarg2: cache entry pointer
3239 // c_rarg3: jvalue object on the stack
3240 __ call_VM(noreg,
3241 CAST_FROM_FN_PTR(address,
3242 InterpreterRuntime::post_field_modification),
3243 r19, c_rarg2, c_rarg3);
3244
3245 switch (bytecode()) { // restore tos values
3246 case Bytecodes::_fast_vputfield: // fall through
3247 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3248 case Bytecodes::_fast_bputfield: // fall through
3249 case Bytecodes::_fast_zputfield: // fall through
3250 case Bytecodes::_fast_sputfield: // fall through
3251 case Bytecodes::_fast_cputfield: // fall through
3252 case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3253 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3254 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3255 case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3256 default: break;
3257 }
3258 __ bind(L2);
3259 }
3260 }
3261
3262 void TemplateTable::fast_storefield(TosState state)
3263 {
3264 transition(state, vtos);
3265
3266 ByteSize base = ConstantPoolCache::base_offset();
3267
3268 jvmti_post_fast_field_mod();
3269
3270 // access constant pool cache
3271 __ load_field_entry(r2, r1);
3272
3273 // R1: field offset, R2: field holder, R5: flags
3274 load_resolved_field_entry(r2, r2, noreg, r1, r5);
3275 __ verify_field_offset(r1);
3276
3277 {
3278 Label notVolatile;
3279 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3280 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3281 __ bind(notVolatile);
3282 }
3283
3284 Label notVolatile;
3285
3286 // Get object from stack
3287 pop_and_check_object(r2);
3288
3289 // field address
3290 const Address field(r2, r1);
3291
3292 // access field
3293 switch (bytecode()) {
3294 case Bytecodes::_fast_vputfield:
3295 {
3296 Label is_flat, done;
3297 __ test_field_is_flat(r5, noreg /* temp */, is_flat);
3298 __ null_check(r0);
3299 do_oop_store(_masm, field, r0, IN_HEAP);
3300 __ b(done);
3301 __ bind(is_flat);
3302 __ load_field_entry(r4, r5);
3303 // Re-shuffle registers because of VM calls calling convention
3304 __ mov(r19, r1);
3305 __ mov(r7, r2);
3306 __ write_flat_field(r4, r19, r6, r8, r7);
3307 __ bind(done);
3308 }
3309 break;
3310 case Bytecodes::_fast_aputfield:
3311 // Clobbers: r10, r11, r3
3312 do_oop_store(_masm, field, r0, IN_HEAP);
3313 break;
3314 case Bytecodes::_fast_lputfield:
3315 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3316 break;
3317 case Bytecodes::_fast_iputfield:
3318 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3319 break;
3320 case Bytecodes::_fast_zputfield:
3321 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3322 break;
3323 case Bytecodes::_fast_bputfield:
3324 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3325 break;
3326 case Bytecodes::_fast_sputfield:
3327 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3328 break;
3329 case Bytecodes::_fast_cputfield:
3330 __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);
3331 break;
3332 case Bytecodes::_fast_fputfield:
3333 __ access_store_at(T_FLOAT, IN_HEAP, field, noreg /* ftos */, noreg, noreg, noreg);
3334 break;
3335 case Bytecodes::_fast_dputfield:
3336 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3337 break;
3338 default:
3339 ShouldNotReachHere();
3340 }
3341
3342 {
3343 Label notVolatile;
3344 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3345 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3346 __ bind(notVolatile);
3347 }
3348 }
3349
3350
3351 void TemplateTable::fast_accessfield(TosState state)
3352 {
3353 transition(atos, state);
3354 // Do the JVMTI work here to avoid disturbing the register state below
3355 if (JvmtiExport::can_post_field_access()) {
3356 // Check to see if a field access watch has been set before we
3357 // take the time to call into the VM.
3358 Label L1;
3359 __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
3360 __ ldrw(r2, Address(rscratch1));
3361 __ cbzw(r2, L1);
3362 // access constant pool cache entry
3363 __ load_field_entry(c_rarg2, rscratch2);
3364 __ verify_oop(r0);
3365 __ push_ptr(r0); // save object pointer before call_VM() clobbers it
3366 __ mov(c_rarg1, r0);
3367 // c_rarg1: object pointer copied above
3368 // c_rarg2: cache entry pointer
3369 __ call_VM(noreg,
3370 CAST_FROM_FN_PTR(address,
3371 InterpreterRuntime::post_field_access),
3372 c_rarg1, c_rarg2);
3373 __ pop_ptr(r0); // restore object pointer
3374 __ bind(L1);
3375 }
3376
3377 // access constant pool cache
3378 __ load_field_entry(r2, r1);
3379
3380 __ load_sized_value(r1, Address(r2, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3381 __ verify_field_offset(r1);
3382
3383 __ load_unsigned_byte(r3, Address(r2, in_bytes(ResolvedFieldEntry::flags_offset())));
3384
3385 // r0: object
3386 __ verify_oop(r0);
3387 __ null_check(r0);
3388 const Address field(r0, r1);
3389
3390 // 8179954: We need to make sure that the code generated for
3391 // volatile accesses forms a sequentially-consistent set of
3392 // operations when combined with STLR and LDAR. Without a leading
3393 // membar it's possible for a simple Dekker test to fail if loads
3394 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3395 // the stores in one method and we interpret the loads in another.
3396 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3397 Label notVolatile;
3398 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3399 __ membar(MacroAssembler::AnyAny);
3400 __ bind(notVolatile);
3401 }
3402
3403 // access field
3404 switch (bytecode()) {
3405 case Bytecodes::_fast_vgetfield:
3406 {
3407 // field is flat
3408 __ read_flat_field(r2, r0);
3409 __ verify_oop(r0);
3410 }
3411 break;
3412 case Bytecodes::_fast_agetfield:
3413 do_oop_load(_masm, field, r0, IN_HEAP);
3414 __ verify_oop(r0);
3415 break;
3416 case Bytecodes::_fast_lgetfield:
3417 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3418 break;
3419 case Bytecodes::_fast_igetfield:
3420 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3421 break;
3422 case Bytecodes::_fast_bgetfield:
3423 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3424 break;
3425 case Bytecodes::_fast_sgetfield:
3426 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3427 break;
3428 case Bytecodes::_fast_cgetfield:
3429 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3430 break;
3431 case Bytecodes::_fast_fgetfield:
3432 __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
3433 break;
3434 case Bytecodes::_fast_dgetfield:
3435 __ access_load_at(T_DOUBLE, IN_HEAP, noreg /* dtos */, field, noreg, noreg);
3436 break;
3437 default:
3438 ShouldNotReachHere();
3439 }
3440 {
3441 Label notVolatile;
3442 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3443 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3444 __ bind(notVolatile);
3445 }
3446 }
3447
3448 void TemplateTable::fast_xaccess(TosState state)
3449 {
3450 transition(vtos, state);
3451
3452 // get receiver
3453 __ ldr(r0, aaddress(0));
3454 // access constant pool cache
3455 __ load_field_entry(r2, r3, 2);
3456
3457 __ load_sized_value(r1, Address(r2, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3458 __ verify_field_offset(r1);
3459
3460 // 8179954: We need to make sure that the code generated for
3461 // volatile accesses forms a sequentially-consistent set of
3462 // operations when combined with STLR and LDAR. Without a leading
3463 // membar it's possible for a simple Dekker test to fail if loads
3464 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3465 // the stores in one method and we interpret the loads in another.
3466 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3467 Label notVolatile;
3468 __ load_unsigned_byte(r3, Address(r2, in_bytes(ResolvedFieldEntry::flags_offset())));
3469 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3470 __ membar(MacroAssembler::AnyAny);
3471 __ bind(notVolatile);
3472 }
3473
3474 // make sure exception is reported in correct bcp range (getfield is
3475 // next instruction)
3476 __ increment(rbcp);
3477 __ null_check(r0);
3478 switch (state) {
3479 case itos:
3480 __ access_load_at(T_INT, IN_HEAP, r0, Address(r0, r1, Address::lsl(0)), noreg, noreg);
3481 break;
3482 case atos:
3483 do_oop_load(_masm, Address(r0, r1, Address::lsl(0)), r0, IN_HEAP);
3484 __ verify_oop(r0);
3485 break;
3486 case ftos:
3487 __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, Address(r0, r1, Address::lsl(0)), noreg, noreg);
3488 break;
3489 default:
3490 ShouldNotReachHere();
3491 }
3492
3493 {
3494 Label notVolatile;
3495 __ load_unsigned_byte(r3, Address(r2, in_bytes(ResolvedFieldEntry::flags_offset())));
3496 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3497 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3498 __ bind(notVolatile);
3499 }
3500
3501 __ decrement(rbcp);
3502 }
3503
3504
3505
3506 //-----------------------------------------------------------------------------
3507 // Calls
3508
3509 void TemplateTable::prepare_invoke(Register cache, Register recv) {
3510
3511 Bytecodes::Code code = bytecode();
3512 const bool load_receiver = (code != Bytecodes::_invokestatic) && (code != Bytecodes::_invokedynamic);
3513
3514 // save 'interpreter return address'
3515 __ save_bcp();
3516
3517 // Load TOS state for later
3518 __ load_unsigned_byte(rscratch2, Address(cache, in_bytes(ResolvedMethodEntry::type_offset())));
3519
3520 // load receiver if needed (note: no return address pushed yet)
3521 if (load_receiver) {
3522 __ load_unsigned_short(recv, Address(cache, in_bytes(ResolvedMethodEntry::num_parameters_offset())));
3523 __ add(rscratch1, esp, recv, ext::uxtx, 3);
3524 __ ldr(recv, Address(rscratch1, -Interpreter::expr_offset_in_bytes(1)));
3525 __ verify_oop(recv);
3526 }
3527
3528 // load return address
3529 {
3530 const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
3531 __ mov(rscratch1, table_addr);
3532 __ ldr(lr, Address(rscratch1, rscratch2, Address::lsl(3)));
3533 }
3534 }
3535
3536
3537 void TemplateTable::invokevirtual_helper(Register index,
3538 Register recv,
3539 Register flags)
3540 {
3541 // Uses temporary registers r0, r3
3542 assert_different_registers(index, recv, r0, r3);
3543 // Test for an invoke of a final method
3544 Label notFinal;
3545 __ tbz(flags, ResolvedMethodEntry::is_vfinal_shift, notFinal);
3546
3547 const Register method = index; // method must be rmethod
3548 assert(method == rmethod,
3549 "Method must be rmethod for interpreter calling convention");
3550
3551 // do the call - the index is actually the method to call
3552 // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method*
3553
3554 // It's final, need a null check here!
3555 __ null_check(recv);
3556
3557 // profile this call
3558 __ profile_final_call(r0);
3559 __ profile_arguments_type(r0, method, r4, true);
3560
3561 __ jump_from_interpreted(method, r0);
3562
3563 __ bind(notFinal);
3564
3565 // get receiver klass
3566 __ load_klass(r0, recv);
3567
3568 // profile this call
3569 __ profile_virtual_call(r0, rlocals, r3);
3570
3571 // get target Method & entry point
3572 __ lookup_virtual_method(r0, index, method);
3573 __ profile_arguments_type(r3, method, r4, true);
3574 // FIXME -- this looks completely redundant. is it?
3575 // __ ldr(r3, Address(method, Method::interpreter_entry_offset()));
3576 __ jump_from_interpreted(method, r3);
3577 }
3578
3579 void TemplateTable::invokevirtual(int byte_no)
3580 {
3581 transition(vtos, vtos);
3582 assert(byte_no == f2_byte, "use this argument");
3583
3584 load_resolved_method_entry_virtual(r2, // ResolvedMethodEntry*
3585 rmethod, // Method* or itable index
3586 r3); // flags
3587 prepare_invoke(r2, r2); // recv
3588
3589 // rmethod: index (actually a Method*)
3590 // r2: receiver
3591 // r3: flags
3592
3593 invokevirtual_helper(rmethod, r2, r3);
3594 }
3595
3596 void TemplateTable::invokespecial(int byte_no)
3597 {
3598 transition(vtos, vtos);
3599 assert(byte_no == f1_byte, "use this argument");
3600
3601 load_resolved_method_entry_special_or_static(r2, // ResolvedMethodEntry*
3602 rmethod, // Method*
3603 r3); // flags
3604 prepare_invoke(r2, r2); // get receiver also for null check
3605 __ verify_oop(r2);
3606 __ null_check(r2);
3607 // do the call
3608 __ profile_call(r0);
3609 __ profile_arguments_type(r0, rmethod, rbcp, false);
3610 __ jump_from_interpreted(rmethod, r0);
3611 }
3612
3613 void TemplateTable::invokestatic(int byte_no)
3614 {
3615 transition(vtos, vtos);
3616 assert(byte_no == f1_byte, "use this argument");
3617
3618 load_resolved_method_entry_special_or_static(r2, // ResolvedMethodEntry*
3619 rmethod, // Method*
3620 r3); // flags
3621 prepare_invoke(r2, r2); // get receiver also for null check
3622
3623 // do the call
3624 __ profile_call(r0);
3625 __ profile_arguments_type(r0, rmethod, r4, false);
3626 __ jump_from_interpreted(rmethod, r0);
3627 }
3628
3629 void TemplateTable::fast_invokevfinal(int byte_no)
3630 {
3631 __ call_Unimplemented();
3632 }
3633
3634 void TemplateTable::invokeinterface(int byte_no) {
3635 transition(vtos, vtos);
3636 assert(byte_no == f1_byte, "use this argument");
3637
3638 load_resolved_method_entry_interface(r2, // ResolvedMethodEntry*
3639 r0, // Klass*
3640 rmethod, // Method* or itable/vtable index
3641 r3); // flags
3642 prepare_invoke(r2, r2); // receiver
3643
3644 // r0: interface klass (from f1)
3645 // rmethod: method (from f2)
3646 // r2: receiver
3647 // r3: flags
3648
3649 // First check for Object case, then private interface method,
3650 // then regular interface method.
3651
3652 // Special case of invokeinterface called for virtual method of
3653 // java.lang.Object. See cpCache.cpp for details.
3654 Label notObjectMethod;
3655 __ tbz(r3, ResolvedMethodEntry::is_forced_virtual_shift, notObjectMethod);
3656
3657 invokevirtual_helper(rmethod, r2, r3);
3658 __ bind(notObjectMethod);
3659
3660 Label no_such_interface;
3661
3662 // Check for private method invocation - indicated by vfinal
3663 Label notVFinal;
3664 __ tbz(r3, ResolvedMethodEntry::is_vfinal_shift, notVFinal);
3665
3666 // Get receiver klass into r3
3667 __ load_klass(r3, r2);
3668
3669 Label subtype;
3670 __ check_klass_subtype(r3, r0, r4, subtype);
3671 // If we get here the typecheck failed
3672 __ b(no_such_interface);
3673 __ bind(subtype);
3674
3675 __ profile_final_call(r0);
3676 __ profile_arguments_type(r0, rmethod, r4, true);
3677 __ jump_from_interpreted(rmethod, r0);
3678
3679 __ bind(notVFinal);
3680
3681 // Get receiver klass into r3
3682 __ restore_locals();
3683 __ load_klass(r3, r2);
3684
3685 Label no_such_method;
3686
3687 // Preserve method for throw_AbstractMethodErrorVerbose.
3688 __ mov(r16, rmethod);
3689 // Receiver subtype check against REFC.
3690 // Superklass in r0. Subklass in r3. Blows rscratch2, r13
3691 __ lookup_interface_method(// inputs: rec. class, interface, itable index
3692 r3, r0, noreg,
3693 // outputs: scan temp. reg, scan temp. reg
3694 rscratch2, r13,
3695 no_such_interface,
3696 /*return_method=*/false);
3697
3698 // profile this call
3699 __ profile_virtual_call(r3, r13, r19);
3700
3701 // Get declaring interface class from method, and itable index
3702
3703 __ load_method_holder(r0, rmethod);
3704 __ ldrw(rmethod, Address(rmethod, Method::itable_index_offset()));
3705 __ subw(rmethod, rmethod, Method::itable_index_max);
3706 __ negw(rmethod, rmethod);
3707
3708 // Preserve recvKlass for throw_AbstractMethodErrorVerbose.
3709 __ mov(rlocals, r3);
3710 __ lookup_interface_method(// inputs: rec. class, interface, itable index
3711 rlocals, r0, rmethod,
3712 // outputs: method, scan temp. reg
3713 rmethod, r13,
3714 no_such_interface);
3715
3716 // rmethod,: Method to call
3717 // r2: receiver
3718 // Check for abstract method error
3719 // Note: This should be done more efficiently via a throw_abstract_method_error
3720 // interpreter entry point and a conditional jump to it in case of a null
3721 // method.
3722 __ cbz(rmethod, no_such_method);
3723
3724 __ profile_arguments_type(r3, rmethod, r13, true);
3725
3726 // do the call
3727 // r2: receiver
3728 // rmethod,: Method
3729 __ jump_from_interpreted(rmethod, r3);
3730 __ should_not_reach_here();
3731
3732 // exception handling code follows...
3733 // note: must restore interpreter registers to canonical
3734 // state for exception handling to work correctly!
3735
3736 __ bind(no_such_method);
3737 // throw exception
3738 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed)
3739 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
3740 // Pass arguments for generating a verbose error message.
3741 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodErrorVerbose), r3, r16);
3742 // the call_VM checks for exception, so we should never return here.
3743 __ should_not_reach_here();
3744
3745 __ bind(no_such_interface);
3746 // throw exception
3747 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed)
3748 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
3749 // Pass arguments for generating a verbose error message.
3750 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3751 InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose), r3, r0);
3752 // the call_VM checks for exception, so we should never return here.
3753 __ should_not_reach_here();
3754 return;
3755 }
3756
3757 void TemplateTable::invokehandle(int byte_no) {
3758 transition(vtos, vtos);
3759 assert(byte_no == f1_byte, "use this argument");
3760
3761 load_resolved_method_entry_handle(r2, // ResolvedMethodEntry*
3762 rmethod, // Method*
3763 r0, // Resolved reference
3764 r3); // flags
3765 prepare_invoke(r2, r2);
3766
3767 __ verify_method_ptr(r2);
3768 __ verify_oop(r2);
3769 __ null_check(r2);
3770
3771 // FIXME: profile the LambdaForm also
3772
3773 // r13 is safe to use here as a scratch reg because it is about to
3774 // be clobbered by jump_from_interpreted().
3775 __ profile_final_call(r13);
3776 __ profile_arguments_type(r13, rmethod, r4, true);
3777
3778 __ jump_from_interpreted(rmethod, r0);
3779 }
3780
3781 void TemplateTable::invokedynamic(int byte_no) {
3782 transition(vtos, vtos);
3783 assert(byte_no == f1_byte, "use this argument");
3784
3785 load_invokedynamic_entry(rmethod);
3786
3787 // r0: CallSite object (from cpool->resolved_references[])
3788 // rmethod: MH.linkToCallSite method
3789
3790 // Note: r0_callsite is already pushed
3791
3792 // %%% should make a type profile for any invokedynamic that takes a ref argument
3793 // profile this call
3794 __ profile_call(rbcp);
3795 __ profile_arguments_type(r3, rmethod, r13, false);
3796
3797 __ verify_oop(r0);
3798
3799 __ jump_from_interpreted(rmethod, r0);
3800 }
3801
3802
3803 //-----------------------------------------------------------------------------
3804 // Allocation
3805
3806 void TemplateTable::_new() {
3807 transition(vtos, atos);
3808
3809 __ get_unsigned_2_byte_index_at_bcp(r3, 1);
3810 Label slow_case;
3811 Label done;
3812 Label initialize_header;
3813
3814 __ get_cpool_and_tags(r4, r0);
3815 // Make sure the class we're about to instantiate has been resolved.
3816 // This is done before loading InstanceKlass to be consistent with the order
3817 // how Constant Pool is updated (see ConstantPool::klass_at_put)
3818 const int tags_offset = Array<u1>::base_offset_in_bytes();
3819 __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3820 __ lea(rscratch1, Address(rscratch1, tags_offset));
3821 __ ldarb(rscratch1, rscratch1);
3822 __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3823 __ br(Assembler::NE, slow_case);
3824
3825 // get InstanceKlass
3826 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3827
3828 // make sure klass is initialized
3829 assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3830 __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3831
3832 __ allocate_instance(r4, r0, r3, r1, true, slow_case);
3833 __ b(done);
3834
3835 // slow case
3836 __ bind(slow_case);
3837 __ get_constant_pool(c_rarg1);
3838 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3839 __ call_VM_preemptable(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3840 __ verify_oop(r0);
3841
3842 // continue
3843 __ bind(done);
3844 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3845 __ membar(Assembler::StoreStore);
3846 }
3847
3848 void TemplateTable::newarray() {
3849 transition(itos, atos);
3850 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3851 __ mov(c_rarg2, r0);
3852 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3853 c_rarg1, c_rarg2);
3854 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3855 __ membar(Assembler::StoreStore);
3856 }
3857
3858 void TemplateTable::anewarray() {
3859 transition(itos, atos);
3860 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3861 __ get_constant_pool(c_rarg1);
3862 __ mov(c_rarg3, r0);
3863 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
3864 c_rarg1, c_rarg2, c_rarg3);
3865 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3866 __ membar(Assembler::StoreStore);
3867 }
3868
3869 void TemplateTable::arraylength() {
3870 transition(atos, itos);
3871 __ ldrw(r0, Address(r0, arrayOopDesc::length_offset_in_bytes()));
3872 }
3873
3874 void TemplateTable::checkcast()
3875 {
3876 transition(atos, atos);
3877 Label done, is_null, ok_is_subtype, quicked, resolved;
3878 __ cbz(r0, is_null);
3879
3880 // Get cpool & tags index
3881 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3882 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3883 // See if bytecode has already been quicked
3884 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3885 __ lea(r1, Address(rscratch1, r19));
3886 __ ldarb(r1, r1);
3887 __ cmp(r1, (u1)JVM_CONSTANT_Class);
3888 __ br(Assembler::EQ, quicked);
3889
3890 __ push(atos); // save receiver for result, and for GC
3891 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3892 __ get_vm_result_metadata(r0, rthread);
3893 __ pop(r3); // restore receiver
3894 __ b(resolved);
3895
3896 // Get superklass in r0 and subklass in r3
3897 __ bind(quicked);
3898 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3899 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3900
3901 __ bind(resolved);
3902 __ load_klass(r19, r3);
3903
3904 // Generate subtype check. Blows r2, r5. Object in r3.
3905 // Superklass in r0. Subklass in r19.
3906 __ gen_subtype_check(r19, ok_is_subtype);
3907
3908 // Come here on failure
3909 __ push(r3);
3910 // object is at TOS
3911 __ b(Interpreter::_throw_ClassCastException_entry);
3912
3913 // Come here on success
3914 __ bind(ok_is_subtype);
3915 __ mov(r0, r3); // Restore object in r3
3916
3917 __ b(done);
3918 __ bind(is_null);
3919
3920 // Collect counts on whether this test sees nulls a lot or not.
3921 if (ProfileInterpreter) {
3922 __ profile_null_seen(r2);
3923 }
3924
3925 __ bind(done);
3926 }
3927
3928 void TemplateTable::instanceof() {
3929 transition(atos, itos);
3930 Label done, is_null, ok_is_subtype, quicked, resolved;
3931 __ cbz(r0, is_null);
3932
3933 // Get cpool & tags index
3934 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3935 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3936 // See if bytecode has already been quicked
3937 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3938 __ lea(r1, Address(rscratch1, r19));
3939 __ ldarb(r1, r1);
3940 __ cmp(r1, (u1)JVM_CONSTANT_Class);
3941 __ br(Assembler::EQ, quicked);
3942
3943 __ push(atos); // save receiver for result, and for GC
3944 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3945 __ get_vm_result_metadata(r0, rthread);
3946 __ pop(r3); // restore receiver
3947 __ verify_oop(r3);
3948 __ load_klass(r3, r3);
3949 __ b(resolved);
3950
3951 // Get superklass in r0 and subklass in r3
3952 __ bind(quicked);
3953 __ load_klass(r3, r0);
3954 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1);
3955
3956 __ bind(resolved);
3957
3958 // Generate subtype check. Blows r2, r5
3959 // Superklass in r0. Subklass in r3.
3960 __ gen_subtype_check(r3, ok_is_subtype);
3961
3962 // Come here on failure
3963 __ mov(r0, 0);
3964 __ b(done);
3965 // Come here on success
3966 __ bind(ok_is_subtype);
3967 __ mov(r0, 1);
3968
3969 // Collect counts on whether this test sees nulls a lot or not.
3970 if (ProfileInterpreter) {
3971 __ b(done);
3972 __ bind(is_null);
3973 __ profile_null_seen(r2);
3974 } else {
3975 __ bind(is_null); // same as 'done'
3976 }
3977 __ bind(done);
3978 // r0 = 0: obj == nullptr or obj is not an instanceof the specified klass
3979 // r0 = 1: obj != nullptr and obj is an instanceof the specified klass
3980 }
3981
3982 //-----------------------------------------------------------------------------
3983 // Breakpoints
3984 void TemplateTable::_breakpoint() {
3985 // Note: We get here even if we are single stepping..
3986 // jbug inists on setting breakpoints at every bytecode
3987 // even if we are in single step mode.
3988
3989 transition(vtos, vtos);
3990
3991 // get the unpatched byte code
3992 __ get_method(c_rarg1);
3993 __ call_VM(noreg,
3994 CAST_FROM_FN_PTR(address,
3995 InterpreterRuntime::get_original_bytecode_at),
3996 c_rarg1, rbcp);
3997 __ mov(r19, r0);
3998
3999 // post the breakpoint event
4000 __ call_VM(noreg,
4001 CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint),
4002 rmethod, rbcp);
4003
4004 // complete the execution of original bytecode
4005 __ mov(rscratch1, r19);
4006 __ dispatch_only_normal(vtos);
4007 }
4008
4009 //-----------------------------------------------------------------------------
4010 // Exceptions
4011
4012 void TemplateTable::athrow() {
4013 transition(atos, vtos);
4014 __ null_check(r0);
4015 __ b(Interpreter::throw_exception_entry());
4016 }
4017
4018 //-----------------------------------------------------------------------------
4019 // Synchronization
4020 //
4021 // Note: monitorenter & exit are symmetric routines; which is reflected
4022 // in the assembly code structure as well
4023 //
4024 // Stack layout:
4025 //
4026 // [expressions ] <--- esp = expression stack top
4027 // ..
4028 // [expressions ]
4029 // [monitor entry] <--- monitor block top = expression stack bot
4030 // ..
4031 // [monitor entry]
4032 // [frame data ] <--- monitor block bot
4033 // ...
4034 // [saved rfp ] <--- rfp
4035 void TemplateTable::monitorenter()
4036 {
4037 transition(atos, vtos);
4038
4039 // check for null object
4040 __ null_check(r0);
4041
4042 Label is_inline_type;
4043 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4044 __ test_markword_is_inline_type(rscratch1, is_inline_type);
4045
4046 const Address monitor_block_top(
4047 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4048 const Address monitor_block_bot(
4049 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4050 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4051
4052 Label allocated;
4053
4054 // initialize entry pointer
4055 __ mov(c_rarg1, zr); // points to free slot or null
4056
4057 // find a free slot in the monitor block (result in c_rarg1)
4058 {
4059 Label entry, loop, exit;
4060 __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
4061 __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
4062 // c_rarg3 points to current entry, starting with top-most entry
4063
4064 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4065
4066 __ b(entry);
4067
4068 __ bind(loop);
4069 // check if current entry is used
4070 // if not used then remember entry in c_rarg1
4071 __ ldr(rscratch1, Address(c_rarg3, BasicObjectLock::obj_offset()));
4072 __ cmp(zr, rscratch1);
4073 __ csel(c_rarg1, c_rarg3, c_rarg1, Assembler::EQ);
4074 // check if current entry is for same object
4075 __ cmp(r0, rscratch1);
4076 // if same object then stop searching
4077 __ br(Assembler::EQ, exit);
4078 // otherwise advance to next entry
4079 __ add(c_rarg3, c_rarg3, entry_size);
4080 __ bind(entry);
4081 // check if bottom reached
4082 __ cmp(c_rarg3, c_rarg2);
4083 // if not at bottom then check this entry
4084 __ br(Assembler::NE, loop);
4085 __ bind(exit);
4086 }
4087
4088 __ cbnz(c_rarg1, allocated); // check if a slot has been found and
4089 // if found, continue with that on
4090
4091 // allocate one if there's no free slot
4092 {
4093 Label entry, loop;
4094 // 1. compute new pointers // rsp: old expression stack top
4095
4096 __ check_extended_sp();
4097 __ sub(sp, sp, entry_size); // make room for the monitor
4098 __ sub(rscratch1, sp, rfp);
4099 __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize);
4100 __ str(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize));
4101
4102 __ ldr(c_rarg1, monitor_block_bot); // derelativize pointer
4103 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4104 // c_rarg1 points to the old expression stack bottom
4105
4106 __ sub(esp, esp, entry_size); // move expression stack top
4107 __ sub(c_rarg1, c_rarg1, entry_size); // move expression stack bottom
4108 __ mov(c_rarg3, esp); // set start value for copy loop
4109 __ sub(rscratch1, c_rarg1, rfp); // relativize pointer
4110 __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize);
4111 __ str(rscratch1, monitor_block_bot); // set new monitor block bottom
4112
4113 __ b(entry);
4114 // 2. move expression stack contents
4115 __ bind(loop);
4116 __ ldr(c_rarg2, Address(c_rarg3, entry_size)); // load expression stack
4117 // word from old location
4118 __ str(c_rarg2, Address(c_rarg3, 0)); // and store it at new location
4119 __ add(c_rarg3, c_rarg3, wordSize); // advance to next word
4120 __ bind(entry);
4121 __ cmp(c_rarg3, c_rarg1); // check if bottom reached
4122 __ br(Assembler::NE, loop); // if not at bottom then
4123 // copy next word
4124 }
4125
4126 // call run-time routine
4127 // c_rarg1: points to monitor entry
4128 __ bind(allocated);
4129
4130 // Increment bcp to point to the next bytecode, so exception
4131 // handling for async. exceptions work correctly.
4132 // The object has already been popped from the stack, so the
4133 // expression stack looks correct.
4134 __ increment(rbcp);
4135
4136 // store object
4137 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
4138 __ lock_object(c_rarg1);
4139
4140 // check to make sure this monitor doesn't cause stack overflow after locking
4141 __ save_bcp(); // in case of exception
4142 __ generate_stack_overflow_check(0);
4143
4144 // The bcp has already been incremented. Just need to dispatch to
4145 // next instruction.
4146 __ dispatch_next(vtos);
4147
4148 __ bind(is_inline_type);
4149 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4150 InterpreterRuntime::throw_identity_exception), r0);
4151 __ should_not_reach_here();
4152 }
4153
4154
4155 void TemplateTable::monitorexit()
4156 {
4157 transition(atos, vtos);
4158
4159 // check for null object
4160 __ null_check(r0);
4161
4162 const int is_inline_type_mask = markWord::inline_type_pattern;
4163 Label has_identity;
4164 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4165 __ mov(rscratch2, is_inline_type_mask);
4166 __ andr(rscratch1, rscratch1, rscratch2);
4167 __ cmp(rscratch1, rscratch2);
4168 __ br(Assembler::NE, has_identity);
4169 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4170 InterpreterRuntime::throw_illegal_monitor_state_exception));
4171 __ should_not_reach_here();
4172 __ bind(has_identity);
4173
4174 const Address monitor_block_top(
4175 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4176 const Address monitor_block_bot(
4177 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4178 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4179
4180 Label found;
4181
4182 // find matching slot
4183 {
4184 Label entry, loop;
4185 __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4186 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4187 // c_rarg1 points to current entry, starting with top-most entry
4188
4189 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4190 // of monitor block
4191 __ b(entry);
4192
4193 __ bind(loop);
4194 // check if current entry is for same object
4195 __ ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset()));
4196 __ cmp(r0, rscratch1);
4197 // if same object then stop searching
4198 __ br(Assembler::EQ, found);
4199 // otherwise advance to next entry
4200 __ add(c_rarg1, c_rarg1, entry_size);
4201 __ bind(entry);
4202 // check if bottom reached
4203 __ cmp(c_rarg1, c_rarg2);
4204 // if not at bottom then check this entry
4205 __ br(Assembler::NE, loop);
4206 }
4207
4208 // error handling. Unlocking was not block-structured
4209 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4210 InterpreterRuntime::throw_illegal_monitor_state_exception));
4211 __ should_not_reach_here();
4212
4213 // call run-time routine
4214 __ bind(found);
4215 __ push_ptr(r0); // make sure object is on stack (contract with oopMaps)
4216 __ unlock_object(c_rarg1);
4217 __ pop_ptr(r0); // discard object
4218 }
4219
4220
4221 // Wide instructions
4222 void TemplateTable::wide()
4223 {
4224 __ load_unsigned_byte(r19, at_bcp(1));
4225 __ mov(rscratch1, (address)Interpreter::_wentry_point);
4226 __ ldr(rscratch1, Address(rscratch1, r19, Address::uxtw(3)));
4227 __ br(rscratch1);
4228 }
4229
4230
4231 // Multi arrays
4232 void TemplateTable::multianewarray() {
4233 transition(vtos, atos);
4234 __ load_unsigned_byte(r0, at_bcp(3)); // get number of dimensions
4235 // last dim is on top of stack; we want address of first one:
4236 // first_addr = last_addr + (ndims - 1) * wordSize
4237 __ lea(c_rarg1, Address(esp, r0, Address::uxtw(3)));
4238 __ sub(c_rarg1, c_rarg1, wordSize);
4239 call_VM(r0,
4240 CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray),
4241 c_rarg1);
4242 __ load_unsigned_byte(r1, at_bcp(3));
4243 __ lea(esp, Address(esp, r1, Address::uxtw(3)));
4244 }