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