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