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