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