forked from openjdk/jdk
/
templateInterpreterGenerator_arm.cpp
1645 lines (1350 loc) · 53.3 KB
/
templateInterpreterGenerator_arm.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) 2008, 2021, Oracle and/or its affiliates. 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/assembler.hpp"
#include "asm/macroAssembler.inline.hpp"
#include "classfile/javaClasses.hpp"
#include "interpreter/bytecodeHistogram.hpp"
#include "interpreter/interp_masm.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "interpreter/templateInterpreterGenerator.hpp"
#include "interpreter/templateTable.hpp"
#include "oops/arrayOop.hpp"
#include "oops/methodData.hpp"
#include "oops/method.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/arguments.hpp"
#include "runtime/deoptimization.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/jniHandles.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/timer.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/align.hpp"
#include "utilities/debug.hpp"
#include "utilities/macros.hpp"
// Size of interpreter code. Increase if too small. Interpreter will
// fail with a guarantee ("not enough space for interpreter generation");
// if too small.
// Run with +PrintInterpreter to get the VM to print out the size.
// Max size with JVMTI
int TemplateInterpreter::InterpreterCodeSize = 180 * 1024;
#define __ _masm->
//------------------------------------------------------------------------------------------------------------------------
address TemplateInterpreterGenerator::generate_slow_signature_handler() {
address entry = __ pc();
// callee-save register for saving LR, shared with generate_native_entry
const Register Rsaved_ret_addr = Rtmp_save0;
__ mov(Rsaved_ret_addr, LR);
__ mov(R1, Rmethod);
__ mov(R2, Rlocals);
__ mov(R3, SP);
// Safer to save R9 (when scratched) since callers may have been
// written assuming R9 survives. This is suboptimal but
// probably not important for this slow case call site.
// Note for R9 saving: slow_signature_handler may copy register
// arguments above the current SP (passed as R3). It is safe for
// call_VM to use push and pop to protect additional values on the
// stack if needed.
__ call_VM(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), true /* save R9 if needed*/);
__ add(SP, SP, wordSize); // Skip R0
__ pop(RegisterSet(R1, R3)); // Load arguments passed in registers
#ifdef __ABI_HARD__
// Few alternatives to an always-load-FP-registers approach:
// - parse method signature to detect FP arguments
// - keep a counter/flag on a stack indicationg number of FP arguments in the method.
// The later has been originally implemented and tested but a conditional path could
// eliminate any gain imposed by avoiding 8 double word loads.
__ fldmiad(SP, FloatRegisterSet(D0, 8), writeback);
#endif // __ABI_HARD__
__ ret(Rsaved_ret_addr);
return entry;
}
//
// Various method entries (that c++ and asm interpreter agree upon)
//------------------------------------------------------------------------------------------------------------------------
//
//
// Abstract method entry
// Attempt to execute abstract method. Throw exception
address TemplateInterpreterGenerator::generate_abstract_entry(void) {
address entry_point = __ pc();
__ empty_expression_stack();
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
DEBUG_ONLY(STOP("generate_abstract_entry");) // Should not reach here
return entry_point;
}
address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
address entry_point = NULL;
Register continuation = LR;
bool use_runtime_function = false;
switch (kind) {
case Interpreter::java_lang_math_abs:
entry_point = __ pc();
#ifdef __SOFTFP__
use_runtime_function = true;
__ ldrd(R0, Address(SP));
#else // !__SOFTFP__
__ ldr_double(D0, Address(SP));
__ abs_double(D0, D0);
#endif // __SOFTFP__
break;
case Interpreter::java_lang_math_sqrt:
entry_point = __ pc();
#ifdef __SOFTFP__
use_runtime_function = true;
__ ldrd(R0, Address(SP));
#else // !__SOFTFP__
__ ldr_double(D0, Address(SP));
__ sqrt_double(D0, D0);
#endif // __SOFTFP__
break;
case Interpreter::java_lang_math_sin:
case Interpreter::java_lang_math_cos:
case Interpreter::java_lang_math_tan:
case Interpreter::java_lang_math_log:
case Interpreter::java_lang_math_log10:
case Interpreter::java_lang_math_exp:
entry_point = __ pc();
use_runtime_function = true;
#ifdef __SOFTFP__
__ ldrd(R0, Address(SP));
#else // !__SOFTFP__
__ ldr_double(D0, Address(SP));
#endif // __SOFTFP__
break;
case Interpreter::java_lang_math_pow:
entry_point = __ pc();
use_runtime_function = true;
#ifdef __SOFTFP__
__ ldrd(R0, Address(SP, 2 * Interpreter::stackElementSize));
__ ldrd(R2, Address(SP));
#else // !__SOFTFP__
__ ldr_double(D0, Address(SP, 2 * Interpreter::stackElementSize));
__ ldr_double(D1, Address(SP));
#endif // __SOFTFP__
break;
case Interpreter::java_lang_math_fmaD:
case Interpreter::java_lang_math_fmaF:
// TODO: Implement intrinsic
break;
default:
ShouldNotReachHere();
}
if (entry_point != NULL) {
__ mov(SP, Rsender_sp);
if (use_runtime_function) {
__ mov(Rtmp_save0, LR);
continuation = Rtmp_save0;
generate_math_runtime_call(kind);
}
__ ret(continuation);
}
return entry_point;
}
void TemplateInterpreterGenerator::generate_math_runtime_call(AbstractInterpreter::MethodKind kind) {
address fn;
switch (kind) {
#ifdef __SOFTFP__
case Interpreter::java_lang_math_abs:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dabs);
break;
case Interpreter::java_lang_math_sqrt:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt);
break;
#endif // __SOFTFP__
case Interpreter::java_lang_math_sin:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
break;
case Interpreter::java_lang_math_cos:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
break;
case Interpreter::java_lang_math_tan:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
break;
case Interpreter::java_lang_math_log:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
break;
case Interpreter::java_lang_math_log10:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
break;
case Interpreter::java_lang_math_exp:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
break;
case Interpreter::java_lang_math_pow:
fn = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
break;
default:
ShouldNotReachHere();
fn = NULL; // silence "maybe uninitialized" compiler warnings
}
__ call_VM_leaf(fn);
}
address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
address entry = __ pc();
// Note: There should be a minimal interpreter frame set up when stack
// overflow occurs since we check explicitly for it now.
//
#ifdef ASSERT
{ Label L;
__ sub(Rtemp, FP, - frame::interpreter_frame_monitor_block_top_offset * wordSize);
__ cmp(SP, Rtemp); // Rtemp = maximal SP for current FP,
// (stack grows negative)
__ b(L, ls); // check if frame is complete
__ stop ("interpreter frame not set up");
__ bind(L);
}
#endif // ASSERT
// Restore bcp under the assumption that the current frame is still
// interpreted
__ restore_bcp();
// expression stack must be empty before entering the VM if an exception
// happened
__ empty_expression_stack();
// throw exception
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
__ should_not_reach_here();
return entry;
}
address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler() {
address entry = __ pc();
// index is in R4_ArrayIndexOutOfBounds_index
// expression stack must be empty before entering the VM if an exception happened
__ empty_expression_stack();
// setup parameters
// Array expected in R1.
__ mov(R2, R4_ArrayIndexOutOfBounds_index);
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), R1, R2);
__ nop(); // to avoid filling CPU pipeline with invalid instructions
__ nop();
__ should_not_reach_here();
return entry;
}
address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
address entry = __ pc();
// object is in R2_ClassCastException_obj
// expression stack must be empty before entering the VM if an exception
// happened
__ empty_expression_stack();
__ mov(R1, R2_ClassCastException_obj);
__ call_VM(noreg,
CAST_FROM_FN_PTR(address,
InterpreterRuntime::throw_ClassCastException),
R1);
__ should_not_reach_here();
return entry;
}
address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
assert(!pass_oop || message == NULL, "either oop or message but not both");
address entry = __ pc();
InlinedString Lname(name);
InlinedString Lmessage(message);
if (pass_oop) {
// object is at TOS
__ pop_ptr(R2);
}
// expression stack must be empty before entering the VM if an exception happened
__ empty_expression_stack();
// setup parameters
__ ldr_literal(R1, Lname);
if (pass_oop) {
__ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), R1, R2);
} else {
if (message != NULL) {
__ ldr_literal(R2, Lmessage);
} else {
__ mov(R2, 0);
}
__ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), R1, R2);
}
// throw exception
__ b(Interpreter::throw_exception_entry());
__ nop(); // to avoid filling CPU pipeline with invalid instructions
__ nop();
__ bind_literal(Lname);
if (!pass_oop && (message != NULL)) {
__ bind_literal(Lmessage);
}
return entry;
}
address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
address entry = __ pc();
__ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
// Restore stack bottom in case i2c adjusted stack
__ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
// and NULL it as marker that SP is now tos until next java call
__ mov(Rtemp, (int)NULL_WORD);
__ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
__ restore_method();
__ restore_bcp();
__ restore_dispatch();
__ restore_locals();
const Register Rcache = R2_tmp;
const Register Rindex = R3_tmp;
__ get_cache_and_index_at_bcp(Rcache, Rindex, 1, index_size);
__ add(Rtemp, Rcache, AsmOperand(Rindex, lsl, LogBytesPerWord));
__ ldrb(Rtemp, Address(Rtemp, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
__ check_stack_top();
__ add(Rstack_top, Rstack_top, AsmOperand(Rtemp, lsl, Interpreter::logStackElementSize));
__ convert_retval_to_tos(state);
__ check_and_handle_popframe();
__ check_and_handle_earlyret();
__ dispatch_next(state, step);
return entry;
}
address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) {
address entry = __ pc();
__ interp_verify_oop(R0_tos, state, __FILE__, __LINE__);
// The stack is not extended by deopt but we must NULL last_sp as this
// entry is like a "return".
__ mov(Rtemp, 0);
__ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
__ restore_method();
__ restore_bcp();
__ restore_dispatch();
__ restore_locals();
// handle exceptions
{ Label L;
__ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset()));
__ cbz(Rtemp, L);
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
__ should_not_reach_here();
__ bind(L);
}
if (continuation == NULL) {
__ dispatch_next(state, step);
} else {
__ jump_to_entry(continuation);
}
return entry;
}
address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
address entry = __ pc();
switch (type) {
case T_CHAR : /* Nothing to do */ break;
case T_BYTE : /* Nothing to do */ break;
case T_SHORT : /* Nothing to do */ break;
case T_INT : /* Nothing to do */ break;
case T_LONG : /* Nothing to do */ break;
case T_VOID : /* Nothing to do */ break;
case T_DOUBLE : /* Nothing to do */ break;
case T_FLOAT : /* Nothing to do */ break;
case T_BOOLEAN : __ c2bool(R0); break;
case T_OBJECT :
__ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize));
__ verify_oop(R0);
break;
default : __ should_not_reach_here(); break;
}
__ ret();
return entry;
}
address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
address entry = __ pc();
__ push(state);
__ call_VM(noreg, runtime_entry);
// load current bytecode
__ ldrb(R3_bytecode, Address(Rbcp));
__ dispatch_only_normal(vtos);
return entry;
}
// Helpers for commoning out cases in the various type of method entries.
//
// increment invocation count & check for overflow
//
// Note: checking for negative value instead of overflow
// so we have a 'sticky' overflow test
//
// In: Rmethod.
//
// Uses R0, R1, Rtemp.
//
void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow) {
Label done;
const Register Rcounters = Rtemp;
const Address invocation_counter(Rcounters,
MethodCounters::invocation_counter_offset() +
InvocationCounter::counter_offset());
// Note: In tiered we increment either counters in MethodCounters* or
// in MDO depending if we're profiling or not.
int increment = InvocationCounter::count_increment;
Label no_mdo;
if (ProfileInterpreter) {
// Are we profiling?
__ ldr(R1_tmp, Address(Rmethod, Method::method_data_offset()));
__ cbz(R1_tmp, no_mdo);
// Increment counter in the MDO
const Address mdo_invocation_counter(R1_tmp,
in_bytes(MethodData::invocation_counter_offset()) +
in_bytes(InvocationCounter::counter_offset()));
const Address mask(R1_tmp, in_bytes(MethodData::invoke_mask_offset()));
__ increment_mask_and_jump(mdo_invocation_counter, increment, mask, R0_tmp, Rtemp, eq, overflow);
__ b(done);
}
__ bind(no_mdo);
__ get_method_counters(Rmethod, Rcounters, done);
const Address mask(Rcounters, in_bytes(MethodCounters::invoke_mask_offset()));
__ increment_mask_and_jump(invocation_counter, increment, mask, R0_tmp, R1_tmp, eq, overflow);
__ bind(done);
}
void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) {
// InterpreterRuntime::frequency_counter_overflow takes one argument
// indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
// The call returns the address of the verified entry point for the method or NULL
// if the compilation did not complete (either went background or bailed out).
__ mov(R1, (int)false);
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R1);
// jump to the interpreted entry.
__ b(do_continue);
}
void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
// Check if we've got enough room on the stack for
// - overhead;
// - locals;
// - expression stack.
//
// Registers on entry:
//
// R3 = number of additional locals
// Rthread
// Rmethod
// Registers used: R0, R1, R2, Rtemp.
const Register Radditional_locals = R3;
const Register RmaxStack = R2;
// monitor entry size
const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
// total overhead size: entry_size + (saved registers, thru expr stack bottom).
// be sure to change this if you add/subtract anything to/from the overhead area
const int overhead_size = (frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset)*wordSize + entry_size;
// Pages reserved for VM runtime calls and subsequent Java calls.
const int reserved_pages = StackOverflow::stack_shadow_zone_size();
// Thread::stack_size() includes guard pages, and they should not be touched.
const int guard_pages = StackOverflow::stack_guard_zone_size();
__ ldr(R0, Address(Rthread, Thread::stack_base_offset()));
__ ldr(R1, Address(Rthread, Thread::stack_size_offset()));
__ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
__ ldrh(RmaxStack, Address(Rtemp, ConstMethod::max_stack_offset()));
__ sub_slow(Rtemp, SP, overhead_size + reserved_pages + guard_pages + Method::extra_stack_words());
// reserve space for additional locals
__ sub(Rtemp, Rtemp, AsmOperand(Radditional_locals, lsl, Interpreter::logStackElementSize));
// stack size
__ sub(R0, R0, R1);
// reserve space for expression stack
__ sub(Rtemp, Rtemp, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize));
__ cmp(Rtemp, R0);
__ mov(SP, Rsender_sp, ls); // restore SP
__ b(StubRoutines::throw_StackOverflowError_entry(), ls);
}
// Allocate monitor and lock method (asm interpreter)
//
void TemplateInterpreterGenerator::lock_method() {
// synchronize method
const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
assert ((entry_size % StackAlignmentInBytes) == 0, "should keep stack alignment");
#ifdef ASSERT
{ Label L;
__ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
__ tbnz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L);
__ stop("method doesn't need synchronization");
__ bind(L);
}
#endif // ASSERT
// get synchronization object
{ Label done;
__ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
__ tst(Rtemp, JVM_ACC_STATIC);
__ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0)), eq); // get receiver (assume this is frequent case)
__ b(done, eq);
__ load_mirror(R0, Rmethod, Rtemp);
__ bind(done);
}
// add space for monitor & lock
__ sub(Rstack_top, Rstack_top, entry_size);
__ check_stack_top_on_expansion();
// add space for a monitor entry
__ str(Rstack_top, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize));
// set new monitor block top
__ str(R0, Address(Rstack_top, BasicObjectLock::obj_offset_in_bytes()));
// store object
__ mov(R1, Rstack_top); // monitor entry address
__ lock_object(R1);
}
//
// Generate a fixed interpreter frame. This is identical setup for interpreted methods
// and for native methods hence the shared code.
void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
// Generates the following stack layout:
//
// [ expr. stack bottom ]
// [ saved Rbcp ]
// [ current Rlocals ]
// [ cache ]
// [ mdx ]
// [ Method* ]
// [ last_sp ]
// [ sender_sp ]
// [ saved FP ] <--- FP
// [ saved LR ]
// initialize fixed part of activation frame
__ push(LR); // save return address
__ push(FP); // save FP
__ mov(FP, SP); // establish new FP
__ push(Rsender_sp);
__ mov(R0, 0);
__ push(R0); // leave last_sp as null
// setup Rbcp
if (native_call) {
__ mov(Rbcp, 0); // bcp = 0 for native calls
} else {
__ ldr(Rtemp, Address(Rmethod, Method::const_offset())); // get ConstMethod*
__ add(Rbcp, Rtemp, ConstMethod::codes_offset()); // get codebase
}
__ push(Rmethod); // save Method*
// Get mirror and store it in the frame as GC root for this Method*
__ load_mirror(Rtemp, Rmethod, Rtemp);
__ push(Rtemp);
if (ProfileInterpreter) {
__ ldr(Rtemp, Address(Rmethod, Method::method_data_offset()));
__ tst(Rtemp, Rtemp);
__ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset()), ne);
__ push(Rtemp); // set the mdp (method data pointer)
} else {
__ push(R0);
}
__ ldr(Rtemp, Address(Rmethod, Method::const_offset()));
__ ldr(Rtemp, Address(Rtemp, ConstMethod::constants_offset()));
__ ldr(Rtemp, Address(Rtemp, ConstantPool::cache_offset_in_bytes()));
__ push(Rtemp); // set constant pool cache
__ push(Rlocals); // set locals pointer
__ push(Rbcp); // set bcp
__ push(R0); // reserve word for pointer to expression stack bottom
__ str(SP, Address(SP, 0)); // set expression stack bottom
}
// End of helpers
//------------------------------------------------------------------------------------------------------------------------
// Entry points
//
// Here we generate the various kind of entries into the interpreter.
// The two main entry type are generic bytecode methods and native call method.
// These both come in synchronized and non-synchronized versions but the
// frame layout they create is very similar. The other method entry
// types are really just special purpose entries that are really entry
// and interpretation all in one. These are for trivial methods like
// accessor, empty, or special math methods.
//
// When control flow reaches any of the entry types for the interpreter
// the following holds ->
//
// Arguments:
//
// Rmethod: Method*
// Rthread: thread
// Rsender_sp: sender sp
// Rparams (SP on 32-bit ARM): pointer to method parameters
//
// LR: return address
//
// Stack layout immediately at entry
//
// [ parameter n ] <--- Rparams (SP on 32-bit ARM)
// ...
// [ parameter 1 ]
// [ expression stack ] (caller's java expression stack)
// Assuming that we don't go to one of the trivial specialized
// entries the stack will look like below when we are ready to execute
// the first bytecode (or call the native routine). The register usage
// will be as the template based interpreter expects.
//
// local variables follow incoming parameters immediately; i.e.
// the return address is saved at the end of the locals.
//
// [ expr. stack ] <--- Rstack_top (SP on 32-bit ARM)
// [ monitor entry ]
// ...
// [ monitor entry ]
// [ expr. stack bottom ]
// [ saved Rbcp ]
// [ current Rlocals ]
// [ cache ]
// [ mdx ]
// [ mirror ]
// [ Method* ]
//
// 32-bit ARM:
// [ last_sp ]
//
// [ sender_sp ]
// [ saved FP ] <--- FP
// [ saved LR ]
// [ optional padding(*)]
// [ local variable m ]
// ...
// [ local variable 1 ]
// [ parameter n ]
// ...
// [ parameter 1 ] <--- Rlocals
//
address TemplateInterpreterGenerator::generate_Reference_get_entry(void) {
// Code: _aload_0, _getfield, _areturn
// parameter size = 1
//
// The code that gets generated by this routine is split into 2 parts:
// 1. The "intrinsified" code performing an ON_WEAK_OOP_REF load,
// 2. The slow path - which is an expansion of the regular method entry.
//
// Notes:-
// * An intrinsic is always executed, where an ON_WEAK_OOP_REF load is performed.
// * We may jump to the slow path iff the receiver is null. If the
// Reference object is null then we no longer perform an ON_WEAK_OOP_REF load
// Thus we can use the regular method entry code to generate the NPE.
//
// Rmethod: Method*
// Rthread: thread
// Rsender_sp: sender sp, must be preserved for slow path, set SP to it on fast path
// Rparams: parameters
address entry = __ pc();
Label slow_path;
const Register Rthis = R0;
const Register Rret_addr = Rtmp_save1;
assert_different_registers(Rthis, Rret_addr, Rsender_sp);
const int referent_offset = java_lang_ref_Reference::referent_offset();
// Check if local 0 != NULL
// If the receiver is null then it is OK to jump to the slow path.
__ ldr(Rthis, Address(Rparams));
__ cbz(Rthis, slow_path);
// Preserve LR
__ mov(Rret_addr, LR);
// Load the value of the referent field.
const Address field_address(Rthis, referent_offset);
__ load_heap_oop(R0, field_address, Rtemp, R1_tmp, R2_tmp, ON_WEAK_OOP_REF);
// _areturn
__ mov(SP, Rsender_sp);
__ ret(Rret_addr);
// generate a vanilla interpreter entry as the slow path
__ bind(slow_path);
__ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals));
return entry;
}
// Not supported
address TemplateInterpreterGenerator::generate_CRC32_update_entry() { return NULL; }
address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { return NULL; }
address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { return NULL; }
//
// Interpreter stub for calling a native method. (asm interpreter)
// This sets up a somewhat different looking stack for calling the native method
// than the typical interpreter frame setup.
//
address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
// determine code generation flags
bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods;
// Incoming registers:
//
// Rmethod: Method*
// Rthread: thread
// Rsender_sp: sender sp
// Rparams: parameters
address entry_point = __ pc();
// Register allocation
const Register Rsize_of_params = R6;
const Register Rsig_handler = Rtmp_save0; // R4
const Register Rnative_code = Rtmp_save1; // R5
const Register Rresult_handler = R6;
const Register Rsaved_result_lo = Rtmp_save0; // R4
const Register Rsaved_result_hi = Rtmp_save1; // R5
FloatRegister saved_result_fp;
__ ldr(Rsize_of_params, Address(Rmethod, Method::const_offset()));
__ ldrh(Rsize_of_params, Address(Rsize_of_params, ConstMethod::size_of_parameters_offset()));
// native calls don't need the stack size check since they have no expression stack
// and the arguments are already on the stack and we only add a handful of words
// to the stack
// compute beginning of parameters (Rlocals)
__ sub(Rlocals, Rparams, wordSize);
__ add(Rlocals, Rlocals, AsmOperand(Rsize_of_params, lsl, Interpreter::logStackElementSize));
// reserve stack space for oop_temp
__ mov(R0, 0);
__ push(R0);
generate_fixed_frame(true); // Note: R9 is now saved in the frame
// make sure method is native & not abstract
#ifdef ASSERT
__ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
{
Label L;
__ tbnz(Rtemp, JVM_ACC_NATIVE_BIT, L);
__ stop("tried to execute non-native method as native");
__ bind(L);
}
{ Label L;
__ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L);
__ stop("tried to execute abstract method in interpreter");
__ bind(L);
}
#endif
// increment invocation count & check for overflow
Label invocation_counter_overflow;
if (inc_counter) {
if (synchronized) {
// Avoid unlocking method's monitor in case of exception, as it has not
// been locked yet.
__ set_do_not_unlock_if_synchronized(true, Rtemp);
}
generate_counter_incr(&invocation_counter_overflow);
}
Label continue_after_compile;
__ bind(continue_after_compile);
if (inc_counter && synchronized) {
__ set_do_not_unlock_if_synchronized(false, Rtemp);
}
// check for synchronized methods
// Must happen AFTER invocation_counter check and stack overflow check,
// so method is not locked if overflows.
//
if (synchronized) {
lock_method();
} else {
// no synchronization necessary
#ifdef ASSERT
{ Label L;
__ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
__ tbz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L);
__ stop("method needs synchronization");
__ bind(L);
}
#endif
}
// start execution
#ifdef ASSERT
{ Label L;
__ ldr(Rtemp, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize));
__ cmp(Rtemp, Rstack_top);
__ b(L, eq);
__ stop("broken stack frame setup in interpreter");
__ bind(L);
}
#endif
__ check_extended_sp(Rtemp);
// jvmti/dtrace support
__ notify_method_entry();
#if R9_IS_SCRATCHED
__ restore_method();
#endif
{
Label L;
__ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
__ cbnz(Rsig_handler, L);
__ mov(R1, Rmethod);
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1, true);
__ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset()));
__ bind(L);
}
{
Label L;
__ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
__ cbnz(Rnative_code, L);
__ mov(R1, Rmethod);
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1);
__ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset()));
__ bind(L);
}
// Allocate stack space for arguments
// C functions need aligned stack
__ bic(SP, SP, StackAlignmentInBytes - 1);
// Multiply by BytesPerLong instead of BytesPerWord, because calling convention
// may require empty slots due to long alignment, e.g. func(int, jlong, int, jlong)
__ sub(SP, SP, AsmOperand(Rsize_of_params, lsl, LogBytesPerLong));
#ifdef __ABI_HARD__
// Allocate more stack space to accomodate all GP as well as FP registers:
// 4 * wordSize
// 8 * BytesPerLong
int reg_arguments = align_up((4*wordSize) + (8*BytesPerLong), StackAlignmentInBytes);
#else
// Reserve at least 4 words on the stack for loading
// of parameters passed on registers (R0-R3).
// See generate_slow_signature_handler().
// It is also used for JNIEnv & class additional parameters.
int reg_arguments = 4 * wordSize;
#endif // __ABI_HARD__
__ sub(SP, SP, reg_arguments);
// Note: signature handler blows R4 besides all scratch registers.
// See AbstractInterpreterGenerator::generate_slow_signature_handler().
__ call(Rsig_handler);
#if R9_IS_SCRATCHED
__ restore_method();
#endif
__ mov(Rresult_handler, R0);
// Pass JNIEnv and mirror for static methods
{
Label L;
__ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset()));
__ add(R0, Rthread, in_bytes(JavaThread::jni_environment_offset()));
__ tbz(Rtemp, JVM_ACC_STATIC_BIT, L);
__ load_mirror(Rtemp, Rmethod, Rtemp);
__ add(R1, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
__ str(Rtemp, Address(R1, 0));
__ bind(L);
}
__ set_last_Java_frame(SP, FP, true, Rtemp);
// Changing state to _thread_in_native must be the last thing to do
// before the jump to native code. At this moment stack must be
// safepoint-safe and completely prepared for stack walking.
#ifdef ASSERT
{
Label L;
__ ldr_u32(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
__ cmp_32(Rtemp, _thread_in_Java);
__ b(L, eq);
__ stop("invalid thread state");
__ bind(L);
}
#endif
// Force all preceding writes to be observed prior to thread state change
__ membar(MacroAssembler::StoreStore, Rtemp);
__ mov(Rtemp, _thread_in_native);
__ str(Rtemp, Address(Rthread, JavaThread::thread_state_offset()));
__ call(Rnative_code);
#if R9_IS_SCRATCHED
__ restore_method();
#endif
// Set FPSCR/FPCR to a known state
if (AlwaysRestoreFPU) {
__ restore_default_fp_mode();
}
// Do safepoint check
__ mov(Rtemp, _thread_in_native_trans);