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
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*! \file LowerGetPut.cpp
\brief This file lowers the following bytecodes: XGET|PUT_XXX
*/
#include "libdex/DexOpcodes.h"
#include "libdex/DexFile.h"
#include "Lower.h"
#include "NcgAot.h"
#include "enc_wrapper.h"
#define P_GPR_1 PhysicalReg_EBX
#define P_GPR_2 PhysicalReg_ECX
#define P_GPR_3 PhysicalReg_ESI
#define P_GPR_4 PhysicalReg_EDX
//! LOWER bytecode AGET without usage of helper function
//! It has null check and length check
int aget_common_nohelper(int flag, u2 vA, u2 vref, u2 vindex) {
////////////////////////////
// Request VR free delays before register allocation for the temporaries
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK))
requestVRFreeDelay(vref,VRDELAY_NULLCHECK);
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
requestVRFreeDelay(vref,VRDELAY_BOUNDCHECK);
requestVRFreeDelay(vindex,VRDELAY_BOUNDCHECK);
}
get_virtual_reg(vref, OpndSize_32, 1, false); //array
get_virtual_reg(vindex, OpndSize_32, 2, false); //index
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
//last argument is the exception number for this bytecode
nullCheck(1, false, 1, vref); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vref,VRDELAY_NULLCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
}
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
boundCheck(vref, 1, false,
vindex, 2, false,
2);
cancelVRFreeDelayRequest(vref,VRDELAY_BOUNDCHECK);
cancelVRFreeDelayRequest(vindex,VRDELAY_BOUNDCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
updateRefCount2(2, LowOpndRegType_gp, false); //update reference count for tmp2
}
if(flag == AGET) {
move_mem_disp_scale_to_reg(OpndSize_32, 1, false, offArrayObject_contents, 2, false, 4, 4, false);
}
else if(flag == AGET_WIDE) {
move_mem_disp_scale_to_reg(OpndSize_64, 1, false, offArrayObject_contents, 2, false, 8, 1, false);
}
else if(flag == AGET_CHAR) {
movez_mem_disp_scale_to_reg(OpndSize_16, 1, false, offArrayObject_contents, 2, false, 2, 4, false);
}
else if(flag == AGET_SHORT) {
moves_mem_disp_scale_to_reg(OpndSize_16, 1, false, offArrayObject_contents, 2, false, 2, 4, false);
}
else if(flag == AGET_BOOLEAN) {
movez_mem_disp_scale_to_reg(OpndSize_8, 1, false, offArrayObject_contents, 2, false, 1, 4, false);
}
else if(flag == AGET_BYTE) {
moves_mem_disp_scale_to_reg(OpndSize_8, 1, false, offArrayObject_contents, 2, false, 1, 4, false);
}
if(flag == AGET_WIDE) {
set_virtual_reg(vA, OpndSize_64, 1, false);
}
else {
set_virtual_reg(vA, OpndSize_32, 4, false);
}
//////////////////////////////////
return 0;
}
//! wrapper to call either aget_common_helper or aget_common_nohelper
//!
int aget_common(int flag, u2 vA, u2 vref, u2 vindex) {
return aget_common_nohelper(flag, vA, vref, vindex);
}
#undef P_GPR_1
#undef P_GPR_2
#undef P_GPR_3
#undef P_GPR_4
//! lower bytecode AGET by calling aget_common
//!
int op_aget() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode AGET_WIDE by calling aget_common
//!
int op_aget_wide() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET_WIDE, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode AGET_OBJECT by calling aget_common
//!
int op_aget_object() {
return op_aget();
}
//! lower bytecode BOOLEAN by calling aget_common
//!
int op_aget_boolean() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET_BOOLEAN, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode AGET_BYTE by calling aget_common
//!
int op_aget_byte() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET_BYTE, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode AGET_CHAR by calling aget_common
//!
int op_aget_char() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET_CHAR, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode AGET_SHORT by calling aget_common
//!
int op_aget_short() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aget_common(AGET_SHORT, vA, vref, vindex);
rPC += 2;
return retval;
}
#define P_GPR_1 PhysicalReg_EBX
#define P_GPR_2 PhysicalReg_ECX
#define P_GPR_3 PhysicalReg_ESI
#define P_GPR_4 PhysicalReg_EDX
//! LOWER bytecode APUT without usage of helper function
//! It has null check and length check
int aput_common_nohelper(int flag, u2 vA, u2 vref, u2 vindex) {
//////////////////////////////////////
// Request VR free delays before register allocation for the temporaries.
// No need to request delay for vA since it will be transferred to temporary
// after the null check and bound check.
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK))
requestVRFreeDelay(vref,VRDELAY_NULLCHECK);
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
requestVRFreeDelay(vref,VRDELAY_BOUNDCHECK);
requestVRFreeDelay(vindex,VRDELAY_BOUNDCHECK);
}
get_virtual_reg(vref, OpndSize_32, 1, false); //array
get_virtual_reg(vindex, OpndSize_32, 2, false); //index
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
//last argument is the exception number for this bytecode
nullCheck(1, false, 1, vref); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vref,VRDELAY_NULLCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
}
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
boundCheck(vref, 1, false,
vindex, 2, false,
2);
cancelVRFreeDelayRequest(vref,VRDELAY_BOUNDCHECK);
cancelVRFreeDelayRequest(vindex,VRDELAY_BOUNDCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
updateRefCount2(2, LowOpndRegType_gp, false); //update reference count for tmp2
}
if(flag == APUT_WIDE) {
get_virtual_reg(vA, OpndSize_64, 1, false);
}
else {
get_virtual_reg(vA, OpndSize_32, 4, false);
}
if(flag == APUT)
move_reg_to_mem_disp_scale(OpndSize_32, 4, false, 1, false, offArrayObject_contents, 2, false, 4);
else if(flag == APUT_WIDE)
move_reg_to_mem_disp_scale(OpndSize_64, 1, false, 1, false, offArrayObject_contents, 2, false, 8);
else if(flag == APUT_CHAR || flag == APUT_SHORT)
move_reg_to_mem_disp_scale(OpndSize_16, 4, false, 1, false, offArrayObject_contents, 2, false, 2);
else if(flag == APUT_BOOLEAN || flag == APUT_BYTE)
move_reg_to_mem_disp_scale(OpndSize_8, 4, false, 1, false, offArrayObject_contents, 2, false, 1);
//////////////////////////////////
return 0;
}
//! wrapper to call either aput_common_helper or aput_common_nohelper
//!
int aput_common(int flag, u2 vA, u2 vref, u2 vindex) {
return aput_common_nohelper(flag, vA, vref, vindex);
}
#undef P_GPR_1
#undef P_GPR_2
#undef P_GPR_3
#undef P_GPR_4
//! lower bytecode APUT by calling aput_common
//!
int op_aput() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode APUT_WIDE by calling aput_common
//!
int op_aput_wide() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT_WIDE, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode APUT_BOOLEAN by calling aput_common
//!
int op_aput_boolean() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT_BOOLEAN, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode APUT_BYTE by calling aput_common
//!
int op_aput_byte() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT_BYTE, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode APUT_CHAR by calling aput_common
//!
int op_aput_char() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT_CHAR, vA, vref, vindex);
rPC += 2;
return retval;
}
//! lower bytecode APUT_SHORT by calling aput_common
//!
int op_aput_short() {
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
int retval = aput_common(APUT_SHORT, vA, vref, vindex);
rPC += 2;
return retval;
}
#define P_GPR_1 PhysicalReg_EBX //callee-saved valid after CanPutArray
#define P_GPR_2 PhysicalReg_ECX
#define P_GPR_3 PhysicalReg_ESI //callee-saved
#define P_SCRATCH_1 PhysicalReg_EDX
#define P_SCRATCH_2 PhysicalReg_EAX
#define P_SCRATCH_3 PhysicalReg_EDX
void markCard_notNull(int tgtAddrReg, int scratchReg, bool isPhysical);
//! lower bytecode APUT_OBJECT
//! Lower the bytecode using helper function ".aput_obj_helper" if helper switch is on
int op_aput_object() { //type checking
u2 vA = INST_AA(inst);
u2 vref = FETCH(1) & 0xff;
u2 vindex = FETCH(1) >> 8;
///////////////////////////
// Request VR free delays before register allocation for the temporaries
// No need to request delay for vA since it will be transferred to temporary
// after the null check and bound check.
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK))
requestVRFreeDelay(vref,VRDELAY_NULLCHECK);
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
requestVRFreeDelay(vref,VRDELAY_BOUNDCHECK);
requestVRFreeDelay(vindex,VRDELAY_BOUNDCHECK);
}
get_virtual_reg(vref, OpndSize_32, 1, false); //array
export_pc(); //use %edx
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
compare_imm_reg(OpndSize_32, 0, 1, false);
conditional_jump_global_API(Condition_E, "common_errNullObject", false);
cancelVRFreeDelayRequest(vref,VRDELAY_NULLCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
}
get_virtual_reg(vindex, OpndSize_32, 2, false); //index
if(!(traceCurrentMIR->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
compare_mem_reg(OpndSize_32, offArrayObject_length, 1, false, 2, false);
conditional_jump_global_API(Condition_NC, "common_errArrayIndex", false);
cancelVRFreeDelayRequest(vref,VRDELAY_BOUNDCHECK);
cancelVRFreeDelayRequest(vindex,VRDELAY_BOUNDCHECK);
} else {
updateRefCount2(1, LowOpndRegType_gp, false); //update reference count for tmp1
updateRefCount2(2, LowOpndRegType_gp, false); //update reference count for tmp2
}
get_virtual_reg(vA, OpndSize_32, 4, false);
compare_imm_reg(OpndSize_32, 0, 4, false);
conditional_jump(Condition_E, ".aput_object_skip_check", true);
rememberState(1);
move_mem_to_reg(OpndSize_32, offObject_clazz, 4, false, 5, false);
load_effective_addr(-12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
move_reg_to_mem(OpndSize_32, 5, false, 0, PhysicalReg_ESP, true);
move_mem_to_reg(OpndSize_32, offObject_clazz, 1, false, 6, false);
move_reg_to_mem(OpndSize_32, 6, false, 4, PhysicalReg_ESP, true);
scratchRegs[0] = PhysicalReg_SCRATCH_1;
call_dvmCanPutArrayElement(); //scratch??
load_effective_addr(12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
compare_imm_reg(OpndSize_32, 0, PhysicalReg_EAX, true);
conditional_jump_global_API(Condition_E, "common_errArrayStore", false);
//NOTE: "2, false" is live through function call
move_reg_to_mem_disp_scale(OpndSize_32, 4, false, 1, false, offArrayObject_contents, 2, false, 4);
markCard_notNull(1, 11, false);
rememberState(2);
////TODO NCG O1 + code cache
unconditional_jump(".aput_object_after_check", true);
insertLabel(".aput_object_skip_check", true);
goToState(1);
//NOTE: "2, false" is live through function call
move_reg_to_mem_disp_scale(OpndSize_32, 4, false, 1, false, offArrayObject_contents, 2, false, 4);
transferToState(2);
insertLabel(".aput_object_after_check", true);
///////////////////////////////
rPC += 2;
return 0;
}
#undef P_GPR_1
#undef P_GPR_2
#undef P_GPR_3
#undef P_SCRATCH_1
#undef P_SCRATCH_2
#undef P_SCRATCH_3
//////////////////////////////////////////
#define P_GPR_1 PhysicalReg_ECX
#define P_GPR_2 PhysicalReg_EBX //should be callee-saved to avoid overwritten by inst_field_resolve
#define P_GPR_3 PhysicalReg_ESI
#define P_SCRATCH_1 PhysicalReg_EDX
/*
movl offThread_cardTable(self), scratchReg
compare_imm_reg 0, valReg (testl valReg, valReg)
je .markCard_skip
shrl $GC_CARD_SHIFT, tgtAddrReg
movb %, (scratchReg, tgtAddrReg)
NOTE: scratchReg can be accessed with the corresponding byte
tgtAddrReg will be updated
for O1, update the corresponding reference count
*/
void markCard(int valReg, int tgtAddrReg, bool targetPhysical, int scratchReg, bool isPhysical) {
get_self_pointer(PhysicalReg_SCRATCH_6, isScratchPhysical);
move_mem_to_reg(OpndSize_32, offsetof(Thread, cardTable), PhysicalReg_SCRATCH_6, isScratchPhysical, scratchReg, isPhysical);
compare_imm_reg(OpndSize_32, 0, valReg, isPhysical);
conditional_jump(Condition_E, ".markCard_skip", true);
alu_binary_imm_reg(OpndSize_32, shr_opc, GC_CARD_SHIFT, tgtAddrReg, targetPhysical);
move_reg_to_mem_disp_scale(OpndSize_8, scratchReg, isPhysical, scratchReg, isPhysical, 0, tgtAddrReg, targetPhysical, 1);
insertLabel(".markCard_skip", true);
}
void markCard_notNull(int tgtAddrReg, int scratchReg, bool isPhysical) {
get_self_pointer(PhysicalReg_SCRATCH_2, isScratchPhysical);
move_mem_to_reg(OpndSize_32, offsetof(Thread, cardTable), PhysicalReg_SCRATCH_2, isScratchPhysical, scratchReg, isPhysical);
alu_binary_imm_reg(OpndSize_32, shr_opc, GC_CARD_SHIFT, tgtAddrReg, isPhysical);
move_reg_to_mem_disp_scale(OpndSize_8, scratchReg, isPhysical, scratchReg, isPhysical, 0, tgtAddrReg, isPhysical, 1);
}
void markCard_filled(int tgtAddrReg, bool isTgtPhysical, int scratchReg, bool isScratchPhysical) {
get_self_pointer(PhysicalReg_SCRATCH_2, false/*isPhysical*/);
move_mem_to_reg(OpndSize_32, offsetof(Thread, cardTable), PhysicalReg_SCRATCH_2, isScratchPhysical, scratchReg, isScratchPhysical);
alu_binary_imm_reg(OpndSize_32, shr_opc, GC_CARD_SHIFT, tgtAddrReg, isTgtPhysical);
move_reg_to_mem_disp_scale(OpndSize_8, scratchReg, isScratchPhysical, scratchReg, isScratchPhysical, 0, tgtAddrReg, isTgtPhysical, 1);
}
//! LOWER bytecode IGET,IPUT without usage of helper function
//! It has null check and calls assembly function inst_field_resolve
int iget_iput_common_nohelper(int tmp, int flag, u2 vA, u2 vB, int isObj, bool isVolatile) {
#ifdef WITH_JIT_INLINING
const Method *method = (traceCurrentMIR->OptimizationFlags & MIR_CALLEE) ?
traceCurrentMIR->meta.calleeMethod : currentMethod;
InstField *pInstField = (InstField *)
method->clazz->pDvmDex->pResFields[tmp];
#else
InstField *pInstField = (InstField *)
currentMethod->clazz->pDvmDex->pResFields[tmp];
#endif
int fieldOffset;
assert(pInstField != NULL);
fieldOffset = pInstField->byteOffset;
move_imm_to_reg(OpndSize_32, fieldOffset, 8, false);
// Request VR delay before transfer to temporary. Only vB needs delay.
// vA will have non-zero reference count since transfer to temporary for
// it happens after null check, thus no delay is needed.
requestVRFreeDelay(vB,VRDELAY_NULLCHECK);
get_virtual_reg(vB, OpndSize_32, 7, false);
nullCheck(7, false, 2, vB); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vB,VRDELAY_NULLCHECK);
if(flag == IGET) {
move_mem_scale_to_reg(OpndSize_32, 7, false, 8, false, 1, 9, false);
set_virtual_reg(vA, OpndSize_32, 9, false);
#ifdef DEBUG_IGET_OBJ
if(isObj > 0) {
pushAllRegs();
load_effective_addr(-16, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
move_reg_to_mem(OpndSize_32, 9, false, 12, PhysicalReg_ESP, true); //field
move_reg_to_mem(OpndSize_32, 7, false, 8, PhysicalReg_ESP, true); //object
move_imm_to_mem(OpndSize_32, tmp, 4, PhysicalReg_ESP, true); //field
move_imm_to_mem(OpndSize_32, 0, 0, PhysicalReg_ESP, true); //iget
call_dvmDebugIgetIput();
load_effective_addr(16, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
popAllRegs();
}
#endif
} else if(flag == IGET_WIDE) {
if(isVolatile) {
/* call dvmQuasiAtomicRead64(addr) */
load_effective_addr(fieldOffset, 7, false, 9, false);
move_reg_to_mem(OpndSize_32, 9, false, -4, PhysicalReg_ESP, true); //1st argument
load_effective_addr(-4, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
nextVersionOfHardReg(PhysicalReg_EAX, 2);
nextVersionOfHardReg(PhysicalReg_EDX, 2);
scratchRegs[0] = PhysicalReg_SCRATCH_3;
call_dvmQuasiAtomicRead64();
load_effective_addr(4, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
//memory content in %edx, %eax
set_virtual_reg(vA, OpndSize_32, PhysicalReg_EAX, true);
set_virtual_reg(vA+1, OpndSize_32, PhysicalReg_EDX, true);
} else {
move_mem_scale_to_reg(OpndSize_64, 7, false, 8, false, 1, 1, false); //access field
set_virtual_reg(vA, OpndSize_64, 1, false);
}
} else if(flag == IPUT) {
get_virtual_reg(vA, OpndSize_32, 9, false);
move_reg_to_mem_scale(OpndSize_32, 9, false, 7, false, 8, false, 1); //access field
if(isObj) {
markCard(9, 7, false, 11, false);
}
} else if(flag == IPUT_WIDE) {
get_virtual_reg(vA, OpndSize_64, 1, false);
if(isVolatile) {
/* call dvmQuasiAtomicSwap64(val, addr) */
load_effective_addr(fieldOffset, 7, false, 9, false);
move_reg_to_mem(OpndSize_32, 9, false, -4, PhysicalReg_ESP, true); //2nd argument
move_reg_to_mem(OpndSize_64, 1, false, -12, PhysicalReg_ESP, true); //1st argument
load_effective_addr(-12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
scratchRegs[0] = PhysicalReg_SCRATCH_3;
call_dvmQuasiAtomicSwap64();
load_effective_addr(12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
}
else {
move_reg_to_mem_scale(OpndSize_64, 1, false, 7, false, 8, false, 1);
}
}
///////////////////////////
return 0;
}
//! wrapper to call either iget_iput_common_helper or iget_iput_common_nohelper
//!
int iget_iput_common(int tmp, int flag, u2 vA, u2 vB, int isObj, bool isVolatile) {
return iget_iput_common_nohelper(tmp, flag, vA, vB, isObj, isVolatile);
}
#undef P_GPR_1
#undef P_GPR_2
#undef P_GPR_3
#undef P_SCRATCH_1
//! lower bytecode IGET by calling iget_iput_common
//!
int op_iget() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IGET, vA, vB, 0, false);
rPC += 2;
return retval;
}
//! lower bytecode IGET_WIDE by calling iget_iput_common
//!
int op_iget_wide(bool isVolatile) {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IGET_WIDE, vA, vB, 0, isVolatile);
rPC += 2;
return retval;
}
//! lower bytecode IGET_OBJECT by calling iget_iput_common
//!
int op_iget_object() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IGET, vA, vB, 1, false);
rPC += 2;
return retval;
}
//! lower bytecode IGET_BOOLEAN by calling iget_iput_common
//!
int op_iget_boolean() {
return op_iget();
}
//! lower bytecode IGET_BYTE by calling iget_iput_common
//!
int op_iget_byte() {
return op_iget();
}
//! lower bytecode IGET_CHAR by calling iget_iput_common
//!
int op_iget_char() {
return op_iget();
}
//! lower bytecode IGET_SHORT by calling iget_iput_common
//!
int op_iget_short() {
return op_iget();
}
//! lower bytecode IPUT by calling iget_iput_common
//!
int op_iput() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IPUT, vA, vB, 0, false);
rPC += 2;
return retval;
}
//! lower bytecode IPUT_WIDE by calling iget_iput_common
//!
int op_iput_wide(bool isVolatile) {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IPUT_WIDE, vA, vB, 0, isVolatile);
rPC += 2;
return retval;
}
//! lower bytecode IPUT_OBJECT by calling iget_iput_common
//!
int op_iput_object() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst);
u2 tmp = FETCH(1);
int retval = iget_iput_common(tmp, IPUT, vA, vB, 1, false);
rPC += 2;
return retval;
}
//! lower bytecode IPUT_BOOLEAN by calling iget_iput_common
//!
int op_iput_boolean() {
return op_iput();
}
//! lower bytecode IPUT_BYTE by calling iget_iput_common
//!
int op_iput_byte() {
return op_iput();
}
//! lower bytecode IPUT_CHAR by calling iget_iput_common
//!
int op_iput_char() {
return op_iput();
}
//! lower bytecode IPUT_SHORT by calling iget_iput_common
//!
int op_iput_short() {
return op_iput();
}
#define P_GPR_1 PhysicalReg_EBX
#define P_GPR_2 PhysicalReg_ECX
#define P_GPR_3 PhysicalReg_EDX //used by helper only
//! common section to lower IGET & IPUT
//! It will use helper function sget_helper if the switch is on
int sget_sput_common(int flag, u2 vA, u2 tmp, bool isObj, bool isVolatile) {
//call assembly static_field_resolve
//no exception
//glue: get_res_fields
//hard-coded: eax (one version?)
//////////////////////////////////////////
#ifdef WITH_JIT_INLINING
const Method *method = (traceCurrentMIR->OptimizationFlags & MIR_CALLEE) ? traceCurrentMIR->meta.calleeMethod : currentMethod;
void *fieldPtr = (void*)
(method->clazz->pDvmDex->pResFields[tmp]);
#else
void *fieldPtr = (void*)
(currentMethod->clazz->pDvmDex->pResFields[tmp]);
#endif
/* Usually, fieldPtr should not be null. The interpreter should resolve
* it before we come here, or not allow this opcode in a trace. However,
* we can be in a loop trace and this opcode might have been picked up
* by exhaustTrace. Sending a -1 here will terminate the loop formation
* and fall back to normal trace, which will not have this opcode.
*/
if (!fieldPtr) {
return -1;
}
move_imm_to_reg(OpndSize_32, (int)fieldPtr, PhysicalReg_EAX, true);
if(flag == SGET) {
move_mem_to_reg(OpndSize_32, offStaticField_value, PhysicalReg_EAX, true, 7, false); //access field
set_virtual_reg(vA, OpndSize_32, 7, false);
} else if(flag == SGET_WIDE) {
if(isVolatile) {
/* call dvmQuasiAtomicRead64(addr) */
load_effective_addr(offStaticField_value, PhysicalReg_EAX, true, 9, false);
move_reg_to_mem(OpndSize_32, 9, false, -4, PhysicalReg_ESP, true); //1st argument
load_effective_addr(-4, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
nextVersionOfHardReg(PhysicalReg_EAX, 2);
nextVersionOfHardReg(PhysicalReg_EDX, 2);
scratchRegs[0] = PhysicalReg_SCRATCH_3;
call_dvmQuasiAtomicRead64();
load_effective_addr(4, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
//memory content in %edx, %eax
set_virtual_reg(vA, OpndSize_32, PhysicalReg_EAX, true);
set_virtual_reg(vA+1, OpndSize_32, PhysicalReg_EDX, true);
}
else {
move_mem_to_reg(OpndSize_64, offStaticField_value, PhysicalReg_EAX, true, 1, false); //access field
set_virtual_reg(vA, OpndSize_64, 1, false);
}
} else if(flag == SPUT) {
get_virtual_reg(vA, OpndSize_32, 7, false);
move_reg_to_mem(OpndSize_32, 7, false, offStaticField_value, PhysicalReg_EAX, true); //access field
if(isObj) {
/* get clazz object, then use clazz object to mark card */
move_mem_to_reg(OpndSize_32, offField_clazz, PhysicalReg_EAX, true, 12, false);
markCard(7/*valReg*/, 12, false, 11, false);
}
} else if(flag == SPUT_WIDE) {
get_virtual_reg(vA, OpndSize_64, 1, false);
if(isVolatile) {
/* call dvmQuasiAtomicSwap64(val, addr) */
load_effective_addr(offStaticField_value, PhysicalReg_EAX, true, 9, false);
move_reg_to_mem(OpndSize_32, 9, false, -4, PhysicalReg_ESP, true); //2nd argument
move_reg_to_mem(OpndSize_64, 1, false, -12, PhysicalReg_ESP, true); //1st argument
load_effective_addr(-12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
scratchRegs[0] = PhysicalReg_SCRATCH_3;
call_dvmQuasiAtomicSwap64();
load_effective_addr(12, PhysicalReg_ESP, true, PhysicalReg_ESP, true);
}
else {
move_reg_to_mem(OpndSize_64, 1, false, offStaticField_value, PhysicalReg_EAX, true); //access field
}
}
//////////////////////////////////////////////
return 0;
}
#undef P_GPR_1
#undef P_GPR_2
#undef P_GPR_3
//! lower bytecode SGET by calling sget_sput_common
//!
int op_sget() {
u2 vA = INST_AA(inst);
u2 tmp = FETCH(1);
int retval = sget_sput_common(SGET, vA, tmp, false, false);
rPC += 2;
return retval;
}
//! lower bytecode SGET_WIDE by calling sget_sput_common
//!
int op_sget_wide(bool isVolatile) {
u2 vA = INST_AA(inst);
u2 tmp = FETCH(1);
int retval = sget_sput_common(SGET_WIDE, vA, tmp, false, isVolatile);
rPC += 2;
return retval;
}
//! lower bytecode SGET_OBJECT by calling sget_sput_common
//!
int op_sget_object() {
return op_sget();
}
//! lower bytecode SGET_BOOLEAN by calling sget_sput_common
//!
int op_sget_boolean() {
return op_sget();
}
//! lower bytecode SGET_BYTE by calling sget_sput_common
//!
int op_sget_byte() {
return op_sget();
}
//! lower bytecode SGET_CHAR by calling sget_sput_common
//!
int op_sget_char() {
return op_sget();
}
//! lower bytecode SGET_SHORT by calling sget_sput_common
//!
int op_sget_short() {
return op_sget();
}
//! lower bytecode SPUT by calling sget_sput_common
//!
int op_sput(bool isObj) {
u2 vA = INST_AA(inst);
u2 tmp = FETCH(1);
int retval = sget_sput_common(SPUT, vA, tmp, isObj, false);
rPC += 2;
return retval;
}
//! lower bytecode SPUT_WIDE by calling sget_sput_common
//!
int op_sput_wide(bool isVolatile) {
u2 vA = INST_AA(inst);
u2 tmp = FETCH(1);
int retval = sget_sput_common(SPUT_WIDE, vA, tmp, false, isVolatile);
rPC += 2;
return retval;
}
//! lower bytecode SPUT_OBJECT by calling sget_sput_common
//!
int op_sput_object() {
return op_sput(true);
}
//! lower bytecode SPUT_OBJECT by calling sget_sput_common
//!
int op_sput_boolean() {
return op_sput(false);
}
//! lower bytecode SPUT_BOOLEAN by calling sget_sput_common
//!
int op_sput_byte() {
return op_sput(false);
}
//! lower bytecode SPUT_BYTE by calling sget_sput_common
//!
int op_sput_char() {
return op_sput(false);
}
//! lower bytecode SPUT_SHORT by calling sget_sput_common
//!
int op_sput_short() {
return op_sput(false);
}
#define P_GPR_1 PhysicalReg_EBX
#define P_GPR_2 PhysicalReg_ECX
//! lower bytecode IGET_QUICK
//!
int op_iget_quick() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst); //object
u2 tmp = FETCH(1);
requestVRFreeDelay(vB,VRDELAY_NULLCHECK); // Request VR delay before transfer to temporary
get_virtual_reg(vB, OpndSize_32, 1, false);
nullCheck(1, false, 1, vB); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vB,VRDELAY_NULLCHECK);
move_mem_to_reg(OpndSize_32, tmp, 1, false, 2, false);
set_virtual_reg(vA, OpndSize_32, 2, false);
rPC += 2;
return 0;
}
#undef P_GPR_1
#undef P_GPR_2
#define P_GPR_1 PhysicalReg_EBX
//! lower bytecode IGET_WIDE_QUICK
//!
int op_iget_wide_quick() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst); //object
u2 tmp = FETCH(1);
requestVRFreeDelay(vB,VRDELAY_NULLCHECK); // Request VR delay before transfer to temporary
get_virtual_reg(vB, OpndSize_32, 1, false);
nullCheck(1, false, 1, vB); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vB,VRDELAY_NULLCHECK);
move_mem_to_reg(OpndSize_64, tmp, 1, false, 1, false);
set_virtual_reg(vA, OpndSize_64, 1, false);
rPC += 2;
return 0;
}
#undef P_GPR_1
//! lower bytecode IGET_OBJECT_QUICK
//!
int op_iget_object_quick() {
return op_iget_quick();
}
#define P_GPR_1 PhysicalReg_EBX
#define P_GPR_2 PhysicalReg_ECX
//! lower bytecode IPUT_QUICK
//!
int iput_quick_common(bool isObj) {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst); //object
u2 tmp = FETCH(1);
// Request VR delay before transfer to temporary. Only vB needs delay.
// vA will have non-zero reference count since transfer to temporary for
// it happens after null check, thus no delay is needed.
requestVRFreeDelay(vB,VRDELAY_NULLCHECK);
get_virtual_reg(vB, OpndSize_32, 1, false);
nullCheck(1, false, 1, vB); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vB,VRDELAY_NULLCHECK);
get_virtual_reg(vA, OpndSize_32, 2, false);
move_reg_to_mem(OpndSize_32, 2, false, tmp, 1, false);
if(isObj) {
markCard(2/*valReg*/, 1, false, 11, false);
}
rPC += 2;
return 0;
}
int op_iput_quick() {
return iput_quick_common(false);
}
#undef P_GPR_1
#undef P_GPR_2
#define P_GPR_1 PhysicalReg_EBX
//! lower bytecode IPUT_WIDE_QUICK
//!
int op_iput_wide_quick() {
u2 vA = INST_A(inst);
u2 vB = INST_B(inst); //object
u2 tmp = FETCH(1); //byte offset
// Request VR delay before transfer to temporary. Only vB needs delay.
// vA will have non-zero reference count since transfer to temporary for
// it happens after null check, thus no delay is needed.
requestVRFreeDelay(vB,VRDELAY_NULLCHECK);
get_virtual_reg(vB, OpndSize_32, 1, false);
nullCheck(1, false, 1, vB); //maybe optimized away, if not, call
cancelVRFreeDelayRequest(vB,VRDELAY_NULLCHECK);
get_virtual_reg(vA, OpndSize_64, 1, false);
move_reg_to_mem(OpndSize_64, 1, false, tmp, 1, false);
rPC += 2;
return 0;
}
#undef P_GPR_1
//! lower bytecode IPUT_OBJECT_QUICK
//!
int op_iput_object_quick() {
return iput_quick_common(true);
}
|