/
templateTable_aarch64.cpp
4017 lines (3484 loc) · 119 KB
/
templateTable_aarch64.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "asm/macroAssembler.inline.hpp"
#include "gc/shared/barrierSetAssembler.hpp"
#include "gc/shared/tlab_globals.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "interpreter/interp_masm.hpp"
#include "interpreter/templateTable.hpp"
#include "memory/universe.hpp"
#include "oops/methodData.hpp"
#include "oops/method.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "utilities/powerOfTwo.hpp"
#define __ _masm->
// Address computation: local variables
static inline Address iaddress(int n) {
return Address(rlocals, Interpreter::local_offset_in_bytes(n));
}
static inline Address laddress(int n) {
return iaddress(n + 1);
}
static inline Address faddress(int n) {
return iaddress(n);
}
static inline Address daddress(int n) {
return laddress(n);
}
static inline Address aaddress(int n) {
return iaddress(n);
}
static inline Address iaddress(Register r) {
return Address(rlocals, r, Address::lsl(3));
}
static inline Address laddress(Register r, Register scratch,
InterpreterMacroAssembler* _masm) {
__ lea(scratch, Address(rlocals, r, Address::lsl(3)));
return Address(scratch, Interpreter::local_offset_in_bytes(1));
}
static inline Address faddress(Register r) {
return iaddress(r);
}
static inline Address daddress(Register r, Register scratch,
InterpreterMacroAssembler* _masm) {
return laddress(r, scratch, _masm);
}
static inline Address aaddress(Register r) {
return iaddress(r);
}
static inline Address at_rsp() {
return Address(esp, 0);
}
// At top of Java expression stack which may be different than esp(). It
// isn't for category 1 objects.
static inline Address at_tos () {
return Address(esp, Interpreter::expr_offset_in_bytes(0));
}
static inline Address at_tos_p1() {
return Address(esp, Interpreter::expr_offset_in_bytes(1));
}
static inline Address at_tos_p2() {
return Address(esp, Interpreter::expr_offset_in_bytes(2));
}
static inline Address at_tos_p3() {
return Address(esp, Interpreter::expr_offset_in_bytes(3));
}
static inline Address at_tos_p4() {
return Address(esp, Interpreter::expr_offset_in_bytes(4));
}
static inline Address at_tos_p5() {
return Address(esp, Interpreter::expr_offset_in_bytes(5));
}
// Condition conversion
static Assembler::Condition j_not(TemplateTable::Condition cc) {
switch (cc) {
case TemplateTable::equal : return Assembler::NE;
case TemplateTable::not_equal : return Assembler::EQ;
case TemplateTable::less : return Assembler::GE;
case TemplateTable::less_equal : return Assembler::GT;
case TemplateTable::greater : return Assembler::LE;
case TemplateTable::greater_equal: return Assembler::LT;
}
ShouldNotReachHere();
return Assembler::EQ;
}
// Miscelaneous helper routines
// Store an oop (or NULL) at the Address described by obj.
// If val == noreg this means store a NULL
static void do_oop_store(InterpreterMacroAssembler* _masm,
Address dst,
Register val,
DecoratorSet decorators) {
assert(val == noreg || val == r0, "parameter is just for looks");
__ store_heap_oop(dst, val, r10, r1, decorators);
}
static void do_oop_load(InterpreterMacroAssembler* _masm,
Address src,
Register dst,
DecoratorSet decorators) {
__ load_heap_oop(dst, src, r10, r1, decorators);
}
Address TemplateTable::at_bcp(int offset) {
assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
return Address(rbcp, offset);
}
void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
int byte_no)
{
if (!RewriteBytecodes) return;
Label L_patch_done;
switch (bc) {
case Bytecodes::_fast_aputfield:
case Bytecodes::_fast_bputfield:
case Bytecodes::_fast_zputfield:
case Bytecodes::_fast_cputfield:
case Bytecodes::_fast_dputfield:
case Bytecodes::_fast_fputfield:
case Bytecodes::_fast_iputfield:
case Bytecodes::_fast_lputfield:
case Bytecodes::_fast_sputfield:
{
// We skip bytecode quickening for putfield instructions when
// the put_code written to the constant pool cache is zero.
// This is required so that every execution of this instruction
// calls out to InterpreterRuntime::resolve_get_put to do
// additional, required work.
assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
assert(load_bc_into_bc_reg, "we use bc_reg as temp");
__ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1);
__ movw(bc_reg, bc);
__ cbzw(temp_reg, L_patch_done); // don't patch
}
break;
default:
assert(byte_no == -1, "sanity");
// the pair bytecodes have already done the load.
if (load_bc_into_bc_reg) {
__ movw(bc_reg, bc);
}
}
if (JvmtiExport::can_post_breakpoint()) {
Label L_fast_patch;
// if a breakpoint is present we can't rewrite the stream directly
__ load_unsigned_byte(temp_reg, at_bcp(0));
__ cmpw(temp_reg, Bytecodes::_breakpoint);
__ br(Assembler::NE, L_fast_patch);
// Let breakpoint table handling rewrite to quicker bytecode
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), rmethod, rbcp, bc_reg);
__ b(L_patch_done);
__ bind(L_fast_patch);
}
#ifdef ASSERT
Label L_okay;
__ load_unsigned_byte(temp_reg, at_bcp(0));
__ cmpw(temp_reg, (int) Bytecodes::java_code(bc));
__ br(Assembler::EQ, L_okay);
__ cmpw(temp_reg, bc_reg);
__ br(Assembler::EQ, L_okay);
__ stop("patching the wrong bytecode");
__ bind(L_okay);
#endif
// patch bytecode
__ strb(bc_reg, at_bcp(0));
__ bind(L_patch_done);
}
// Individual instructions
void TemplateTable::nop() {
transition(vtos, vtos);
// nothing to do
}
void TemplateTable::shouldnotreachhere() {
transition(vtos, vtos);
__ stop("shouldnotreachhere bytecode");
}
void TemplateTable::aconst_null()
{
transition(vtos, atos);
__ mov(r0, 0);
}
void TemplateTable::iconst(int value)
{
transition(vtos, itos);
__ mov(r0, value);
}
void TemplateTable::lconst(int value)
{
__ mov(r0, value);
}
void TemplateTable::fconst(int value)
{
transition(vtos, ftos);
switch (value) {
case 0:
__ fmovs(v0, zr);
break;
case 1:
__ fmovs(v0, 1.0);
break;
case 2:
__ fmovs(v0, 2.0);
break;
default:
ShouldNotReachHere();
break;
}
}
void TemplateTable::dconst(int value)
{
transition(vtos, dtos);
switch (value) {
case 0:
__ fmovd(v0, zr);
break;
case 1:
__ fmovd(v0, 1.0);
break;
case 2:
__ fmovd(v0, 2.0);
break;
default:
ShouldNotReachHere();
break;
}
}
void TemplateTable::bipush()
{
transition(vtos, itos);
__ load_signed_byte32(r0, at_bcp(1));
}
void TemplateTable::sipush()
{
transition(vtos, itos);
__ load_unsigned_short(r0, at_bcp(1));
__ revw(r0, r0);
__ asrw(r0, r0, 16);
}
void TemplateTable::ldc(bool wide)
{
transition(vtos, vtos);
Label call_ldc, notFloat, notClass, notInt, Done;
if (wide) {
__ get_unsigned_2_byte_index_at_bcp(r1, 1);
} else {
__ load_unsigned_byte(r1, at_bcp(1));
}
__ get_cpool_and_tags(r2, r0);
const int base_offset = ConstantPool::header_size() * wordSize;
const int tags_offset = Array<u1>::base_offset_in_bytes();
// get type
__ add(r3, r1, tags_offset);
__ lea(r3, Address(r0, r3));
__ ldarb(r3, r3);
// unresolved class - get the resolved class
__ cmp(r3, (u1)JVM_CONSTANT_UnresolvedClass);
__ br(Assembler::EQ, call_ldc);
// unresolved class in error state - call into runtime to throw the error
// from the first resolution attempt
__ cmp(r3, (u1)JVM_CONSTANT_UnresolvedClassInError);
__ br(Assembler::EQ, call_ldc);
// resolved class - need to call vm to get java mirror of the class
__ cmp(r3, (u1)JVM_CONSTANT_Class);
__ br(Assembler::NE, notClass);
__ bind(call_ldc);
__ mov(c_rarg1, wide);
call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), c_rarg1);
__ push_ptr(r0);
__ verify_oop(r0);
__ b(Done);
__ bind(notClass);
__ cmp(r3, (u1)JVM_CONSTANT_Float);
__ br(Assembler::NE, notFloat);
// ftos
__ adds(r1, r2, r1, Assembler::LSL, 3);
__ ldrs(v0, Address(r1, base_offset));
__ push_f();
__ b(Done);
__ bind(notFloat);
__ cmp(r3, (u1)JVM_CONSTANT_Integer);
__ br(Assembler::NE, notInt);
// itos
__ adds(r1, r2, r1, Assembler::LSL, 3);
__ ldrw(r0, Address(r1, base_offset));
__ push_i(r0);
__ b(Done);
__ bind(notInt);
condy_helper(Done);
__ bind(Done);
}
// Fast path for caching oop constants.
void TemplateTable::fast_aldc(bool wide)
{
transition(vtos, atos);
Register result = r0;
Register tmp = r1;
Register rarg = r2;
int index_size = wide ? sizeof(u2) : sizeof(u1);
Label resolved;
// We are resolved if the resolved reference cache entry contains a
// non-null object (String, MethodType, etc.)
assert_different_registers(result, tmp);
__ get_cache_index_at_bcp(tmp, 1, index_size);
__ load_resolved_reference_at_index(result, tmp);
__ cbnz(result, resolved);
address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
// first time invocation - must resolve first
__ mov(rarg, (int)bytecode());
__ call_VM(result, entry, rarg);
__ bind(resolved);
{ // Check for the null sentinel.
// If we just called the VM, it already did the mapping for us,
// but it's harmless to retry.
Label notNull;
// Stash null_sentinel address to get its value later
__ movptr(rarg, (uintptr_t)Universe::the_null_sentinel_addr());
__ ldr(tmp, Address(rarg));
__ resolve_oop_handle(tmp);
__ cmpoop(result, tmp);
__ br(Assembler::NE, notNull);
__ mov(result, 0); // NULL object reference
__ bind(notNull);
}
if (VerifyOops) {
// Safe to call with 0 result
__ verify_oop(result);
}
}
void TemplateTable::ldc2_w()
{
transition(vtos, vtos);
Label notDouble, notLong, Done;
__ get_unsigned_2_byte_index_at_bcp(r0, 1);
__ get_cpool_and_tags(r1, r2);
const int base_offset = ConstantPool::header_size() * wordSize;
const int tags_offset = Array<u1>::base_offset_in_bytes();
// get type
__ lea(r2, Address(r2, r0, Address::lsl(0)));
__ load_unsigned_byte(r2, Address(r2, tags_offset));
__ cmpw(r2, (int)JVM_CONSTANT_Double);
__ br(Assembler::NE, notDouble);
// dtos
__ lea (r2, Address(r1, r0, Address::lsl(3)));
__ ldrd(v0, Address(r2, base_offset));
__ push_d();
__ b(Done);
__ bind(notDouble);
__ cmpw(r2, (int)JVM_CONSTANT_Long);
__ br(Assembler::NE, notLong);
// ltos
__ lea(r0, Address(r1, r0, Address::lsl(3)));
__ ldr(r0, Address(r0, base_offset));
__ push_l();
__ b(Done);
__ bind(notLong);
condy_helper(Done);
__ bind(Done);
}
void TemplateTable::condy_helper(Label& Done)
{
Register obj = r0;
Register rarg = r1;
Register flags = r2;
Register off = r3;
address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
__ mov(rarg, (int) bytecode());
__ call_VM(obj, entry, rarg);
__ get_vm_result_2(flags, rthread);
// VMr = obj = base address to find primitive value to push
// VMr2 = flags = (tos, off) using format of CPCE::_flags
__ mov(off, flags);
__ andw(off, off, ConstantPoolCacheEntry::field_index_mask);
const Address field(obj, off);
// What sort of thing are we loading?
// x86 uses a shift and mask or wings it with a shift plus assert
// the mask is not needed. aarch64 just uses bitfield extract
__ ubfxw(flags, flags, ConstantPoolCacheEntry::tos_state_shift,
ConstantPoolCacheEntry::tos_state_bits);
switch (bytecode()) {
case Bytecodes::_ldc:
case Bytecodes::_ldc_w:
{
// tos in (itos, ftos, stos, btos, ctos, ztos)
Label notInt, notFloat, notShort, notByte, notChar, notBool;
__ cmpw(flags, itos);
__ br(Assembler::NE, notInt);
// itos
__ ldrw(r0, field);
__ push(itos);
__ b(Done);
__ bind(notInt);
__ cmpw(flags, ftos);
__ br(Assembler::NE, notFloat);
// ftos
__ load_float(field);
__ push(ftos);
__ b(Done);
__ bind(notFloat);
__ cmpw(flags, stos);
__ br(Assembler::NE, notShort);
// stos
__ load_signed_short(r0, field);
__ push(stos);
__ b(Done);
__ bind(notShort);
__ cmpw(flags, btos);
__ br(Assembler::NE, notByte);
// btos
__ load_signed_byte(r0, field);
__ push(btos);
__ b(Done);
__ bind(notByte);
__ cmpw(flags, ctos);
__ br(Assembler::NE, notChar);
// ctos
__ load_unsigned_short(r0, field);
__ push(ctos);
__ b(Done);
__ bind(notChar);
__ cmpw(flags, ztos);
__ br(Assembler::NE, notBool);
// ztos
__ load_signed_byte(r0, field);
__ push(ztos);
__ b(Done);
__ bind(notBool);
break;
}
case Bytecodes::_ldc2_w:
{
Label notLong, notDouble;
__ cmpw(flags, ltos);
__ br(Assembler::NE, notLong);
// ltos
__ ldr(r0, field);
__ push(ltos);
__ b(Done);
__ bind(notLong);
__ cmpw(flags, dtos);
__ br(Assembler::NE, notDouble);
// dtos
__ load_double(field);
__ push(dtos);
__ b(Done);
__ bind(notDouble);
break;
}
default:
ShouldNotReachHere();
}
__ stop("bad ldc/condy");
}
void TemplateTable::locals_index(Register reg, int offset)
{
__ ldrb(reg, at_bcp(offset));
__ neg(reg, reg);
}
void TemplateTable::iload() {
iload_internal();
}
void TemplateTable::nofast_iload() {
iload_internal(may_not_rewrite);
}
void TemplateTable::iload_internal(RewriteControl rc) {
transition(vtos, itos);
if (RewriteFrequentPairs && rc == may_rewrite) {
Label rewrite, done;
Register bc = r4;
// get next bytecode
__ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
// if _iload, wait to rewrite to iload2. We only want to rewrite the
// last two iloads in a pair. Comparing against fast_iload means that
// the next bytecode is neither an iload or a caload, and therefore
// an iload pair.
__ cmpw(r1, Bytecodes::_iload);
__ br(Assembler::EQ, done);
// if _fast_iload rewrite to _fast_iload2
__ cmpw(r1, Bytecodes::_fast_iload);
__ movw(bc, Bytecodes::_fast_iload2);
__ br(Assembler::EQ, rewrite);
// if _caload rewrite to _fast_icaload
__ cmpw(r1, Bytecodes::_caload);
__ movw(bc, Bytecodes::_fast_icaload);
__ br(Assembler::EQ, rewrite);
// else rewrite to _fast_iload
__ movw(bc, Bytecodes::_fast_iload);
// rewrite
// bc: new bytecode
__ bind(rewrite);
patch_bytecode(Bytecodes::_iload, bc, r1, false);
__ bind(done);
}
// do iload, get the local value into tos
locals_index(r1);
__ ldr(r0, iaddress(r1));
}
void TemplateTable::fast_iload2()
{
transition(vtos, itos);
locals_index(r1);
__ ldr(r0, iaddress(r1));
__ push(itos);
locals_index(r1, 3);
__ ldr(r0, iaddress(r1));
}
void TemplateTable::fast_iload()
{
transition(vtos, itos);
locals_index(r1);
__ ldr(r0, iaddress(r1));
}
void TemplateTable::lload()
{
transition(vtos, ltos);
__ ldrb(r1, at_bcp(1));
__ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
__ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
}
void TemplateTable::fload()
{
transition(vtos, ftos);
locals_index(r1);
// n.b. we use ldrd here because this is a 64 bit slot
// this is comparable to the iload case
__ ldrd(v0, faddress(r1));
}
void TemplateTable::dload()
{
transition(vtos, dtos);
__ ldrb(r1, at_bcp(1));
__ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
__ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
}
void TemplateTable::aload()
{
transition(vtos, atos);
locals_index(r1);
__ ldr(r0, iaddress(r1));
}
void TemplateTable::locals_index_wide(Register reg) {
__ ldrh(reg, at_bcp(2));
__ rev16w(reg, reg);
__ neg(reg, reg);
}
void TemplateTable::wide_iload() {
transition(vtos, itos);
locals_index_wide(r1);
__ ldr(r0, iaddress(r1));
}
void TemplateTable::wide_lload()
{
transition(vtos, ltos);
__ ldrh(r1, at_bcp(2));
__ rev16w(r1, r1);
__ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
__ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
}
void TemplateTable::wide_fload()
{
transition(vtos, ftos);
locals_index_wide(r1);
// n.b. we use ldrd here because this is a 64 bit slot
// this is comparable to the iload case
__ ldrd(v0, faddress(r1));
}
void TemplateTable::wide_dload()
{
transition(vtos, dtos);
__ ldrh(r1, at_bcp(2));
__ rev16w(r1, r1);
__ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
__ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
}
void TemplateTable::wide_aload()
{
transition(vtos, atos);
locals_index_wide(r1);
__ ldr(r0, aaddress(r1));
}
void TemplateTable::index_check(Register array, Register index)
{
// destroys r1, rscratch1
// check array
__ null_check(array, arrayOopDesc::length_offset_in_bytes());
// sign extend index for use by indexed load
// __ movl2ptr(index, index);
// check index
Register length = rscratch1;
__ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
__ cmpw(index, length);
if (index != r1) {
// ??? convention: move aberrant index into r1 for exception message
assert(r1 != array, "different registers");
__ mov(r1, index);
}
Label ok;
__ br(Assembler::LO, ok);
// ??? convention: move array into r3 for exception message
__ mov(r3, array);
__ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
__ br(rscratch1);
__ bind(ok);
}
void TemplateTable::iaload()
{
transition(itos, itos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
__ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
}
void TemplateTable::laload()
{
transition(itos, ltos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_LONG) >> 3);
__ access_load_at(T_LONG, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
}
void TemplateTable::faload()
{
transition(itos, ftos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
__ access_load_at(T_FLOAT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
}
void TemplateTable::daload()
{
transition(itos, dtos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
__ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
}
void TemplateTable::aaload()
{
transition(itos, atos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
do_oop_load(_masm,
Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)),
r0,
IS_ARRAY);
}
void TemplateTable::baload()
{
transition(itos, itos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
__ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
}
void TemplateTable::caload()
{
transition(itos, itos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_CHAR) >> 1);
__ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
}
// iload followed by caload frequent pair
void TemplateTable::fast_icaload()
{
transition(vtos, itos);
// load index out of locals
locals_index(r2);
__ ldr(r1, iaddress(r2));
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_CHAR) >> 1);
__ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
}
void TemplateTable::saload()
{
transition(itos, itos);
__ mov(r1, r0);
__ pop_ptr(r0);
// r0: array
// r1: index
index_check(r0, r1); // leaves index in r1, kills rscratch1
__ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_SHORT) >> 1);
__ access_load_at(T_SHORT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(1)), noreg, noreg);
}
void TemplateTable::iload(int n)
{
transition(vtos, itos);
__ ldr(r0, iaddress(n));
}
void TemplateTable::lload(int n)
{
transition(vtos, ltos);
__ ldr(r0, laddress(n));
}
void TemplateTable::fload(int n)
{
transition(vtos, ftos);
__ ldrs(v0, faddress(n));
}
void TemplateTable::dload(int n)
{
transition(vtos, dtos);
__ ldrd(v0, daddress(n));
}
void TemplateTable::aload(int n)
{
transition(vtos, atos);
__ ldr(r0, iaddress(n));
}
void TemplateTable::aload_0() {
aload_0_internal();
}
void TemplateTable::nofast_aload_0() {
aload_0_internal(may_not_rewrite);
}
void TemplateTable::aload_0_internal(RewriteControl rc) {
// According to bytecode histograms, the pairs:
//
// _aload_0, _fast_igetfield
// _aload_0, _fast_agetfield
// _aload_0, _fast_fgetfield
//
// occur frequently. If RewriteFrequentPairs is set, the (slow)
// _aload_0 bytecode checks if the next bytecode is either
// _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
// rewrites the current bytecode into a pair bytecode; otherwise it
// rewrites the current bytecode into _fast_aload_0 that doesn't do
// the pair check anymore.
//
// Note: If the next bytecode is _getfield, the rewrite must be
// delayed, otherwise we may miss an opportunity for a pair.
//
// Also rewrite frequent pairs
// aload_0, aload_1
// aload_0, iload_1
// These bytecodes with a small amount of code are most profitable
// to rewrite
if (RewriteFrequentPairs && rc == may_rewrite) {
Label rewrite, done;
const Register bc = r4;
// get next bytecode
__ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
// if _getfield then wait with rewrite
__ cmpw(r1, Bytecodes::Bytecodes::_getfield);
__ br(Assembler::EQ, done);
// if _igetfield then rewrite to _fast_iaccess_0
assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
__ cmpw(r1, Bytecodes::_fast_igetfield);
__ movw(bc, Bytecodes::_fast_iaccess_0);
__ br(Assembler::EQ, rewrite);
// if _agetfield then rewrite to _fast_aaccess_0
assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
__ cmpw(r1, Bytecodes::_fast_agetfield);
__ movw(bc, Bytecodes::_fast_aaccess_0);
__ br(Assembler::EQ, rewrite);
// if _fgetfield then rewrite to _fast_faccess_0
assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
__ cmpw(r1, Bytecodes::_fast_fgetfield);
__ movw(bc, Bytecodes::_fast_faccess_0);
__ br(Assembler::EQ, rewrite);
// else rewrite to _fast_aload0
assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
__ movw(bc, Bytecodes::Bytecodes::_fast_aload_0);
// rewrite
// bc: new bytecode
__ bind(rewrite);
patch_bytecode(Bytecodes::_aload_0, bc, r1, false);
__ bind(done);
}
// Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop).
aload(0);
}
void TemplateTable::istore()
{
transition(itos, vtos);
locals_index(r1);
// FIXME: We're being very pernickerty here storing a jint in a
// local with strw, which costs an extra instruction over what we'd
// be able to do with a simple str. We should just store the whole
// word.
__ lea(rscratch1, iaddress(r1));
__ strw(r0, Address(rscratch1));
}
void TemplateTable::lstore()
{
transition(ltos, vtos);
locals_index(r1);
__ str(r0, laddress(r1, rscratch1, _masm));
}
void TemplateTable::fstore() {
transition(ftos, vtos);
locals_index(r1);
__ lea(rscratch1, iaddress(r1));
__ strs(v0, Address(rscratch1));
}
void TemplateTable::dstore() {