/
interp_masm_ppc_64.cpp
2446 lines (2056 loc) · 89.6 KB
/
interp_masm_ppc_64.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, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020 SAP SE. 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/barrierSet.hpp"
#include "gc/shared/barrierSetAssembler.hpp"
#include "interp_masm_ppc.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "oops/methodData.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"
// Implementation of InterpreterMacroAssembler.
// This file specializes the assembler with interpreter-specific macros.
#ifdef PRODUCT
#define BLOCK_COMMENT(str) // nothing
#else
#define BLOCK_COMMENT(str) block_comment(str)
#endif
void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) {
address exception_entry = Interpreter::throw_NullPointerException_entry();
MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);
}
void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) {
assert(entry, "Entry must have been generated by now");
if (is_within_range_of_b(entry, pc())) {
b(entry);
} else {
load_const_optimized(Rscratch, entry, R0);
mtctr(Rscratch);
bctr();
}
}
void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {
Register bytecode = R12_scratch2;
if (bcp_incr != 0) {
lbzu(bytecode, bcp_incr, R14_bcp);
} else {
lbz(bytecode, 0, R14_bcp);
}
dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state), generate_poll);
}
void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
// Load current bytecode.
Register bytecode = R12_scratch2;
lbz(bytecode, 0, R14_bcp);
dispatch_Lbyte_code(state, bytecode, table);
}
// Dispatch code executed in the prolog of a bytecode which does not do it's
// own dispatch. The dispatch address is computed and placed in R24_dispatch_addr.
void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {
Register bytecode = R12_scratch2;
lbz(bytecode, bcp_incr, R14_bcp);
load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state));
sldi(bytecode, bytecode, LogBytesPerWord);
ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode);
}
// Dispatch code executed in the epilog of a bytecode which does not do it's
// own dispatch. The dispatch address in R24_dispatch_addr is used for the
// dispatch.
void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {
if (bcp_incr) { addi(R14_bcp, R14_bcp, bcp_incr); }
mtctr(R24_dispatch_addr);
bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
}
void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {
assert(scratch_reg != R0, "can't use R0 as scratch_reg here");
if (JvmtiExport::can_pop_frame()) {
Label L;
// Check the "pending popframe condition" flag in the current thread.
lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
// Initiate popframe handling only if it is not already being
// processed. If the flag has the popframe_processing bit set, it
// means that this code is called *during* popframe handling - we
// don't want to reenter.
andi_(R0, scratch_reg, JavaThread::popframe_pending_bit);
beq(CCR0, L);
andi_(R0, scratch_reg, JavaThread::popframe_processing_bit);
bne(CCR0, L);
// Call the Interpreter::remove_activation_preserving_args_entry()
// func to get the address of the same-named entrypoint in the
// generated interpreter code.
#if defined(ABI_ELFv2)
call_c(CAST_FROM_FN_PTR(address,
Interpreter::remove_activation_preserving_args_entry),
relocInfo::none);
#else
call_c(CAST_FROM_FN_PTR(FunctionDescriptor*,
Interpreter::remove_activation_preserving_args_entry),
relocInfo::none);
#endif
// Jump to Interpreter::_remove_activation_preserving_args_entry.
mtctr(R3_RET);
bctr();
align(32, 12);
bind(L);
}
}
void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {
const Register Rthr_state_addr = scratch_reg;
if (JvmtiExport::can_force_early_return()) {
Label Lno_early_ret;
ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
cmpdi(CCR0, Rthr_state_addr, 0);
beq(CCR0, Lno_early_ret);
lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr);
cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending);
bne(CCR0, Lno_early_ret);
// Jump to Interpreter::_earlyret_entry.
lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr);
call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry));
mtlr(R3_RET);
blr();
align(32, 12);
bind(Lno_early_ret);
}
}
void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) {
const Register RjvmtiState = Rscratch1;
const Register Rscratch2 = R0;
ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
li(Rscratch2, 0);
switch (state) {
case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
break;
case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
break;
case btos: // fall through
case ztos: // fall through
case ctos: // fall through
case stos: // fall through
case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
break;
case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
break;
case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
break;
case vtos: break;
default : ShouldNotReachHere();
}
// Clean up tos value in the jvmti thread state.
std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
// Set tos state field to illegal value.
li(Rscratch2, ilgl);
stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState);
}
// Common code to dispatch and dispatch_only.
// Dispatch value in Lbyte_code and increment Lbcp.
void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) {
address table_base = (address)Interpreter::dispatch_table((TosState)0);
intptr_t table_offs = (intptr_t)table - (intptr_t)table_base;
if (is_simm16(table_offs)) {
addi(dst, R25_templateTableBase, (int)table_offs);
} else {
load_const_optimized(dst, table, R0);
}
}
void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode,
address* table, bool generate_poll) {
assert_different_registers(bytecode, R11_scratch1);
// Calc dispatch table address.
load_dispatch_table(R11_scratch1, table);
if (generate_poll) {
address *sfpt_tbl = Interpreter::safept_table(state);
if (table != sfpt_tbl) {
Label dispatch;
ld(R0, in_bytes(Thread::polling_word_offset()), R16_thread);
// Armed page has poll_bit set, if poll bit is cleared just continue.
andi_(R0, R0, SafepointMechanism::poll_bit());
beq(CCR0, dispatch);
load_dispatch_table(R11_scratch1, sfpt_tbl);
align(32, 16);
bind(dispatch);
}
}
sldi(R12_scratch2, bytecode, LogBytesPerWord);
ldx(R11_scratch1, R11_scratch1, R12_scratch2);
// Jump off!
mtctr(R11_scratch1);
bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
}
void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) {
sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize);
ldx(Rrecv_dst, Rrecv_dst, R15_esp);
}
// helpers for expression stack
void InterpreterMacroAssembler::pop_i(Register r) {
lwzu(r, Interpreter::stackElementSize, R15_esp);
}
void InterpreterMacroAssembler::pop_ptr(Register r) {
ldu(r, Interpreter::stackElementSize, R15_esp);
}
void InterpreterMacroAssembler::pop_l(Register r) {
ld(r, Interpreter::stackElementSize, R15_esp);
addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
}
void InterpreterMacroAssembler::pop_f(FloatRegister f) {
lfsu(f, Interpreter::stackElementSize, R15_esp);
}
void InterpreterMacroAssembler::pop_d(FloatRegister f) {
lfd(f, Interpreter::stackElementSize, R15_esp);
addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
}
void InterpreterMacroAssembler::push_i(Register r) {
stw(r, 0, R15_esp);
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::push_ptr(Register r) {
std(r, 0, R15_esp);
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::push_l(Register r) {
// Clear unused slot.
load_const_optimized(R0, 0L);
std(R0, 0, R15_esp);
std(r, - Interpreter::stackElementSize, R15_esp);
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::push_f(FloatRegister f) {
stfs(f, 0, R15_esp);
addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::push_d(FloatRegister f) {
stfd(f, - Interpreter::stackElementSize, R15_esp);
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) {
std(first, 0, R15_esp);
std(second, -Interpreter::stackElementSize, R15_esp);
addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
}
void InterpreterMacroAssembler::move_l_to_d(Register l, FloatRegister d) {
if (VM_Version::has_mtfprd()) {
mtfprd(d, l);
} else {
std(l, 0, R15_esp);
lfd(d, 0, R15_esp);
}
}
void InterpreterMacroAssembler::move_d_to_l(FloatRegister d, Register l) {
if (VM_Version::has_mtfprd()) {
mffprd(l, d);
} else {
stfd(d, 0, R15_esp);
ld(l, 0, R15_esp);
}
}
void InterpreterMacroAssembler::push(TosState state) {
switch (state) {
case atos: push_ptr(); break;
case btos:
case ztos:
case ctos:
case stos:
case itos: push_i(); break;
case ltos: push_l(); break;
case ftos: push_f(); break;
case dtos: push_d(); break;
case vtos: /* nothing to do */ break;
default : ShouldNotReachHere();
}
}
void InterpreterMacroAssembler::pop(TosState state) {
switch (state) {
case atos: pop_ptr(); break;
case btos:
case ztos:
case ctos:
case stos:
case itos: pop_i(); break;
case ltos: pop_l(); break;
case ftos: pop_f(); break;
case dtos: pop_d(); break;
case vtos: /* nothing to do */ break;
default : ShouldNotReachHere();
}
verify_oop(R17_tos, state);
}
void InterpreterMacroAssembler::empty_expression_stack() {
addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
}
void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int bcp_offset,
Register Rdst,
signedOrNot is_signed) {
#if defined(VM_LITTLE_ENDIAN)
if (bcp_offset) {
load_const_optimized(Rdst, bcp_offset);
lhbrx(Rdst, R14_bcp, Rdst);
} else {
lhbrx(Rdst, R14_bcp);
}
if (is_signed == Signed) {
extsh(Rdst, Rdst);
}
#else
// Read Java big endian format.
if (is_signed == Signed) {
lha(Rdst, bcp_offset, R14_bcp);
} else {
lhz(Rdst, bcp_offset, R14_bcp);
}
#endif
}
void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int bcp_offset,
Register Rdst,
signedOrNot is_signed) {
#if defined(VM_LITTLE_ENDIAN)
if (bcp_offset) {
load_const_optimized(Rdst, bcp_offset);
lwbrx(Rdst, R14_bcp, Rdst);
} else {
lwbrx(Rdst, R14_bcp);
}
if (is_signed == Signed) {
extsw(Rdst, Rdst);
}
#else
// Read Java big endian format.
if (bcp_offset & 3) { // Offset unaligned?
load_const_optimized(Rdst, bcp_offset);
if (is_signed == Signed) {
lwax(Rdst, R14_bcp, Rdst);
} else {
lwzx(Rdst, R14_bcp, Rdst);
}
} else {
if (is_signed == Signed) {
lwa(Rdst, bcp_offset, R14_bcp);
} else {
lwz(Rdst, bcp_offset, R14_bcp);
}
}
#endif
}
// Load the constant pool cache index from the bytecode stream.
//
// Kills / writes:
// - Rdst, Rscratch
void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset,
size_t index_size) {
assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
// Cache index is always in the native format, courtesy of Rewriter.
if (index_size == sizeof(u2)) {
lhz(Rdst, bcp_offset, R14_bcp);
} else if (index_size == sizeof(u4)) {
if (bcp_offset & 3) {
load_const_optimized(Rdst, bcp_offset);
lwax(Rdst, R14_bcp, Rdst);
} else {
lwa(Rdst, bcp_offset, R14_bcp);
}
assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
nand(Rdst, Rdst, Rdst); // convert to plain index
} else if (index_size == sizeof(u1)) {
lbz(Rdst, bcp_offset, R14_bcp);
} else {
ShouldNotReachHere();
}
// Rdst now contains cp cache index.
}
void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset,
size_t index_size) {
get_cache_index_at_bcp(cache, bcp_offset, index_size);
sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));
add(cache, R27_constPoolCache, cache);
}
// Load 4-byte signed or unsigned integer in Java format (that is, big-endian format)
// from (Rsrc)+offset.
void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset,
signedOrNot is_signed) {
#if defined(VM_LITTLE_ENDIAN)
if (offset) {
load_const_optimized(Rdst, offset);
lwbrx(Rdst, Rdst, Rsrc);
} else {
lwbrx(Rdst, Rsrc);
}
if (is_signed == Signed) {
extsw(Rdst, Rdst);
}
#else
if (is_signed == Signed) {
lwa(Rdst, offset, Rsrc);
} else {
lwz(Rdst, offset, Rsrc);
}
#endif
}
// Load object from cpool->resolved_references(index).
void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index, Label *L_handle_null) {
assert_different_registers(result, index);
get_constant_pool(result);
// Convert from field index to resolved_references() index and from
// word index to byte offset. Since this is a java object, it can be compressed.
Register tmp = index; // reuse
sldi(tmp, index, LogBytesPerHeapOop);
// Load pointer for resolved_references[] objArray.
ld(result, ConstantPool::cache_offset_in_bytes(), result);
ld(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
resolve_oop_handle(result);
#ifdef ASSERT
Label index_ok;
lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);
sldi(R0, R0, LogBytesPerHeapOop);
cmpd(CCR0, tmp, R0);
blt(CCR0, index_ok);
stop("resolved reference index out of bounds");
bind(index_ok);
#endif
// Add in the index.
add(result, tmp, result);
load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result, tmp, R0, false, 0, L_handle_null);
}
// load cpool->resolved_klass_at(index)
void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass) {
// int value = *(Rcpool->int_at_addr(which));
// int resolved_klass_index = extract_low_short_from_int(value);
add(Roffset, Rcpool, Roffset);
#if defined(VM_LITTLE_ENDIAN)
lhz(Roffset, sizeof(ConstantPool), Roffset); // Roffset = resolved_klass_index
#else
lhz(Roffset, sizeof(ConstantPool) + 2, Roffset); // Roffset = resolved_klass_index
#endif
ld(Rklass, ConstantPool::resolved_klasses_offset_in_bytes(), Rcpool); // Rklass = Rcpool->_resolved_klasses
sldi(Roffset, Roffset, LogBytesPerWord);
addi(Roffset, Roffset, Array<Klass*>::base_offset_in_bytes());
isync(); // Order load of instance Klass wrt. tags.
ldx(Rklass, Rklass, Roffset);
}
void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,
Register cache,
Register method) {
const int method_offset = in_bytes(
ConstantPoolCache::base_offset() +
((byte_no == TemplateTable::f2_byte)
? ConstantPoolCacheEntry::f2_offset()
: ConstantPoolCacheEntry::f1_offset()));
ld(method, method_offset, cache); // get f1 Method*
}
// Generate a subtype check: branch to ok_is_subtype if sub_klass is
// a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2.
void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1,
Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) {
// Profile the not-null value's klass.
profile_typecheck(Rsub_klass, Rtmp1, Rtmp2);
check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);
profile_typecheck_failed(Rtmp1, Rtmp2);
}
// Separate these two to allow for delay slot in middle.
// These are used to do a test and full jump to exception-throwing code.
// Check that index is in range for array, then shift index by index_shift,
// and put arrayOop + shifted_index into res.
// Note: res is still shy of address by array offset into object.
void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex,
int index_shift, Register Rtmp, Register Rres) {
// Check that index is in range for array, then shift index by index_shift,
// and put arrayOop + shifted_index into res.
// Note: res is still shy of address by array offset into object.
// Kills:
// - Rindex
// Writes:
// - Rres: Address that corresponds to the array index if check was successful.
verify_oop(Rarray);
const Register Rlength = R0;
const Register RsxtIndex = Rtmp;
Label LisNull, LnotOOR;
// Array nullcheck
if (!ImplicitNullChecks) {
cmpdi(CCR0, Rarray, 0);
beq(CCR0, LisNull);
} else {
null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex);
}
// Rindex might contain garbage in upper bits (remember that we don't sign extend
// during integer arithmetic operations). So kill them and put value into same register
// where ArrayIndexOutOfBounds would expect the index in.
rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit
// Index check
lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray);
cmplw(CCR0, Rindex, Rlength);
sldi(RsxtIndex, RsxtIndex, index_shift);
blt(CCR0, LnotOOR);
// Index should be in R17_tos, array should be in R4_ARG2.
mr_if_needed(R17_tos, Rindex);
mr_if_needed(R4_ARG2, Rarray);
load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
mtctr(Rtmp);
bctr();
if (!ImplicitNullChecks) {
bind(LisNull);
load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry);
mtctr(Rtmp);
bctr();
}
align(32, 16);
bind(LnotOOR);
// Calc address
add(Rres, RsxtIndex, Rarray);
}
void InterpreterMacroAssembler::index_check(Register array, Register index,
int index_shift, Register tmp, Register res) {
// pop array
pop_ptr(array);
// check array
index_check_without_pop(array, index, index_shift, tmp, res);
}
void InterpreterMacroAssembler::get_const(Register Rdst) {
ld(Rdst, in_bytes(Method::const_offset()), R19_method);
}
void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {
get_const(Rdst);
ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);
}
void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {
get_constant_pool(Rdst);
ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);
}
void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {
get_constant_pool(Rcpool);
ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool);
}
// Unlock if synchronized method.
//
// Unlock the receiver if this is a synchronized method.
// Unlock any Java monitors from synchronized blocks.
//
// If there are locked Java monitors
// If throw_monitor_exception
// throws IllegalMonitorStateException
// Else if install_monitor_exception
// installs IllegalMonitorStateException
// Else
// no error processing
void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
bool throw_monitor_exception,
bool install_monitor_exception) {
Label Lunlocked, Lno_unlock;
{
Register Rdo_not_unlock_flag = R11_scratch1;
Register Raccess_flags = R12_scratch2;
// Check if synchronized method or unlocking prevented by
// JavaThread::do_not_unlock_if_synchronized flag.
lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method);
li(R0, 0);
stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag
push(state);
// Skip if we don't have to unlock.
rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0.
beq(CCR0, Lunlocked);
cmpwi(CCR0, Rdo_not_unlock_flag, 0);
bne(CCR0, Lno_unlock);
}
// Unlock
{
Register Rmonitor_base = R11_scratch1;
Label Lunlock;
// If it's still locked, everything is ok, unlock it.
ld(Rmonitor_base, 0, R1_SP);
addi(Rmonitor_base, Rmonitor_base,
-(frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base
ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base);
cmpdi(CCR0, R0, 0);
bne(CCR0, Lunlock);
// If it's already unlocked, throw exception.
if (throw_monitor_exception) {
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
should_not_reach_here();
} else {
if (install_monitor_exception) {
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
b(Lunlocked);
}
}
bind(Lunlock);
unlock_object(Rmonitor_base);
}
// Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not.
bind(Lunlocked);
{
Label Lexception, Lrestart;
Register Rcurrent_obj_addr = R11_scratch1;
const int delta = frame::interpreter_frame_monitor_size_in_bytes();
assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords");
bind(Lrestart);
// Set up search loop: Calc num of iterations.
{
Register Riterations = R12_scratch2;
Register Rmonitor_base = Rcurrent_obj_addr;
ld(Rmonitor_base, 0, R1_SP);
addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size); // Monitor base
subf_(Riterations, R26_monitor, Rmonitor_base);
ble(CCR0, Lno_unlock);
addi(Rcurrent_obj_addr, Rmonitor_base,
BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes());
// Check if any monitor is on stack, bail out if not
srdi(Riterations, Riterations, exact_log2(delta));
mtctr(Riterations);
}
// The search loop: Look for locked monitors.
{
const Register Rcurrent_obj = R0;
Label Lloop;
ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
bind(Lloop);
// Check if current entry is used.
cmpdi(CCR0, Rcurrent_obj, 0);
bne(CCR0, Lexception);
// Preload next iteration's compare value.
ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
bdnz(Lloop);
}
// Fell through: Everything's unlocked => finish.
b(Lno_unlock);
// An object is still locked => need to throw exception.
bind(Lexception);
if (throw_monitor_exception) {
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
should_not_reach_here();
} else {
// Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.
// Unlock does not block, so don't have to worry about the frame.
Register Rmonitor_addr = R11_scratch1;
addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta);
unlock_object(Rmonitor_addr);
if (install_monitor_exception) {
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
}
b(Lrestart);
}
}
align(32, 12);
bind(Lno_unlock);
pop(state);
}
// Support function for remove_activation & Co.
void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc,
Register Rscratch1, Register Rscratch2) {
// Pop interpreter frame.
ld(Rscratch1, 0, R1_SP); // *SP
ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp
ld(Rscratch2, 0, Rscratch1); // **SP
if (return_pc!=noreg) {
ld(return_pc, _abi0(lr), Rscratch1); // LR
}
// Merge top frames.
subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP
stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP
}
void InterpreterMacroAssembler::narrow(Register result) {
Register ret_type = R11_scratch1;
ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
lbz(ret_type, in_bytes(ConstMethod::result_type_offset()), R11_scratch1);
Label notBool, notByte, notChar, done;
// common case first
cmpwi(CCR0, ret_type, T_INT);
beq(CCR0, done);
cmpwi(CCR0, ret_type, T_BOOLEAN);
bne(CCR0, notBool);
andi(result, result, 0x1);
b(done);
bind(notBool);
cmpwi(CCR0, ret_type, T_BYTE);
bne(CCR0, notByte);
extsb(result, result);
b(done);
bind(notByte);
cmpwi(CCR0, ret_type, T_CHAR);
bne(CCR0, notChar);
andi(result, result, 0xffff);
b(done);
bind(notChar);
// cmpwi(CCR0, ret_type, T_SHORT); // all that's left
// bne(CCR0, done);
extsh(result, result);
// Nothing to do for T_INT
bind(done);
}
// Remove activation.
//
// Unlock the receiver if this is a synchronized method.
// Unlock any Java monitors from synchronized blocks.
// Remove the activation from the stack.
//
// If there are locked Java monitors
// If throw_monitor_exception
// throws IllegalMonitorStateException
// Else if install_monitor_exception
// installs IllegalMonitorStateException
// Else
// no error processing
void InterpreterMacroAssembler::remove_activation(TosState state,
bool throw_monitor_exception,
bool install_monitor_exception) {
BLOCK_COMMENT("remove_activation {");
unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);
// Save result (push state before jvmti call and pop it afterwards) and notify jvmti.
notify_method_exit(false, state, NotifyJVMTI, true);
BLOCK_COMMENT("reserved_stack_check:");
if (StackReservedPages > 0) {
// Test if reserved zone needs to be enabled.
Label no_reserved_zone_enabling;
// Compare frame pointers. There is no good stack pointer, as with stack
// frame compression we can get different SPs when we do calls. A subsequent
// call could have a smaller SP, so that this compare succeeds for an
// inner call of the method annotated with ReservedStack.
ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);
ld_ptr(R11_scratch1, _abi0(callers_sp), R1_SP); // Load frame pointer.
cmpld(CCR0, R11_scratch1, R0);
blt_predict_taken(CCR0, no_reserved_zone_enabling);
// Enable reserved zone again, throw stack overflow exception.
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));
should_not_reach_here();
bind(no_reserved_zone_enabling);
}
verify_oop(R17_tos, state);
verify_thread();
merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
mtlr(R0);
BLOCK_COMMENT("} remove_activation");
}
// Lock object
//
// Registers alive
// monitor - Address of the BasicObjectLock to be used for locking,
// which must be initialized with the object to lock.
// object - Address of the object to be locked.
//
void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
if (UseHeavyMonitors) {
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
} else {
// template code:
//
// markWord displaced_header = obj->mark().set_unlocked();
// monitor->lock()->set_displaced_header(displaced_header);
// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
// // We stored the monitor address into the object's mark word.
// } else if (THREAD->is_lock_owned((address)displaced_header))
// // Simple recursive case.
// monitor->lock()->set_displaced_header(NULL);
// } else {
// // Slow path.
// InterpreterRuntime::monitorenter(THREAD, monitor);
// }
const Register displaced_header = R7_ARG5;
const Register object_mark_addr = R8_ARG6;
const Register current_header = R9_ARG7;
const Register tmp = R10_ARG8;
Label done;
Label cas_failed, slow_case;
assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);
// markWord displaced_header = obj->mark().set_unlocked();
// Load markWord from object into displaced_header.
ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
load_klass(tmp, object);
lwz(tmp, in_bytes(Klass::access_flags_offset()), tmp);
testbitdi(CCR0, R0, tmp, exact_log2(JVM_ACC_IS_BOX_CLASS));
bne(CCR0, slow_case);
}
if (UseBiasedLocking) {
biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);
}
// Set displaced_header to be (markWord of object | UNLOCK_VALUE).
ori(displaced_header, displaced_header, markWord::unlocked_value);
// monitor->lock()->set_displaced_header(displaced_header);
// Initialize the box (Must happen before we update the object mark!).
std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
BasicLock::displaced_header_offset_in_bytes(), monitor);
// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
// Store stack address of the BasicObjectLock (this is monitor) into object.
addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
// Must fence, otherwise, preceding store(s) may float below cmpxchg.
// CmpxchgX sets CCR0 to cmpX(current, displaced).
cmpxchgd(/*flag=*/CCR0,
/*current_value=*/current_header,
/*compare_value=*/displaced_header, /*exchange_value=*/monitor,
/*where=*/object_mark_addr,
MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq,
MacroAssembler::cmpxchgx_hint_acquire_lock(),
noreg,
&cas_failed,
/*check without membar and ldarx first*/true);
// If the compare-and-exchange succeeded, then we found an unlocked
// object and we have now locked it.
b(done);
bind(cas_failed);
// } else if (THREAD->is_lock_owned((address)displaced_header))
// // Simple recursive case.
// monitor->lock()->set_displaced_header(NULL);
// We did not see an unlocked object so try the fast recursive case.
// Check if owner is self by comparing the value in the markWord of object
// (current_header) with the stack pointer.
sub(current_header, current_header, R1_SP);
assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");
load_const_optimized(tmp, ~(os::vm_page_size()-1) | markWord::lock_mask_in_place);
and_(R0/*==0?*/, current_header, tmp);
// If condition is true we are done and hence we can store 0 in the displaced
// header indicating it is a recursive lock.
bne(CCR0, slow_case);
std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +
BasicLock::displaced_header_offset_in_bytes(), monitor);
b(done);
// } else {
// // Slow path.
// InterpreterRuntime::monitorenter(THREAD, monitor);
// None of the above fast optimizations worked so we have to get into the
// slow case of monitor enter.
bind(slow_case);
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
// }
align(32, 12);
bind(done);
}
}
// Unlocks an object. Used in monitorexit bytecode and remove_activation.
//
// Registers alive
// monitor - Address of the BasicObjectLock to be used for locking,
// which must be initialized with the object to lock.
//
// Throw IllegalMonitorException if object is not locked by current thread.
void InterpreterMacroAssembler::unlock_object(Register monitor) {
if (UseHeavyMonitors) {
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
} else {