blob: aae78de1b3cf7d6e18fb86dcc95f28938e7bf9ad [file] [log] [blame]
Bill Buzbee3b0b4b92016-02-02 13:45:36 +00001/*
2 * ===========================================================================
3 * Common subroutines and data
4 * ===========================================================================
5 */
6
7
8/*
9 * We've detected a condition that will result in an exception, but the exception
10 * has not yet been thrown. Just bail out to the reference interpreter to deal with it.
11 * TUNING: for consistency, we may want to just go ahead and handle these here.
12 */
Bill Buzbee3b0b4b92016-02-02 13:45:36 +000013common_errDivideByZero:
14 EXPORT_PC
15#if MTERP_LOGGING
16 mov x0, xSELF
17 add x1, xFP, #OFF_FP_SHADOWFRAME
18 bl MterpLogDivideByZeroException
19#endif
20 b MterpCommonFallback
21
22common_errArrayIndex:
23 EXPORT_PC
24#if MTERP_LOGGING
25 mov x0, xSELF
26 add x1, xFP, #OFF_FP_SHADOWFRAME
27 bl MterpLogArrayIndexException
28#endif
29 b MterpCommonFallback
30
31common_errNegativeArraySize:
32 EXPORT_PC
33#if MTERP_LOGGING
34 mov x0, xSELF
35 add x1, xFP, #OFF_FP_SHADOWFRAME
36 bl MterpLogNegativeArraySizeException
37#endif
38 b MterpCommonFallback
39
40common_errNoSuchMethod:
41 EXPORT_PC
42#if MTERP_LOGGING
43 mov x0, xSELF
44 add x1, xFP, #OFF_FP_SHADOWFRAME
45 bl MterpLogNoSuchMethodException
46#endif
47 b MterpCommonFallback
48
49common_errNullObject:
50 EXPORT_PC
51#if MTERP_LOGGING
52 mov x0, xSELF
53 add x1, xFP, #OFF_FP_SHADOWFRAME
54 bl MterpLogNullObjectException
55#endif
56 b MterpCommonFallback
57
58common_exceptionThrown:
59 EXPORT_PC
60#if MTERP_LOGGING
61 mov x0, xSELF
62 add x1, xFP, #OFF_FP_SHADOWFRAME
63 bl MterpLogExceptionThrownException
64#endif
65 b MterpCommonFallback
66
67MterpSuspendFallback:
68 EXPORT_PC
69#if MTERP_LOGGING
70 mov x0, xSELF
71 add x1, xFP, #OFF_FP_SHADOWFRAME
72 ldr x2, [xSELF, #THREAD_FLAGS_OFFSET]
73 bl MterpLogSuspendFallback
74#endif
75 b MterpCommonFallback
76
77/*
78 * If we're here, something is out of the ordinary. If there is a pending
79 * exception, handle it. Otherwise, roll back and retry with the reference
80 * interpreter.
81 */
82MterpPossibleException:
83 ldr x0, [xSELF, #THREAD_EXCEPTION_OFFSET]
84 cbz x0, MterpFallback // If not, fall back to reference interpreter.
85 /* intentional fallthrough - handle pending exception. */
86/*
87 * On return from a runtime helper routine, we've found a pending exception.
88 * Can we handle it here - or need to bail out to caller?
89 *
90 */
91MterpException:
92 mov x0, xSELF
93 add x1, xFP, #OFF_FP_SHADOWFRAME
94 bl MterpHandleException // (self, shadow_frame)
95 cbz w0, MterpExceptionReturn // no local catch, back to caller.
96 ldr x0, [xFP, #OFF_FP_CODE_ITEM]
97 ldr w1, [xFP, #OFF_FP_DEX_PC]
98 ldr xIBASE, [xSELF, #THREAD_CURRENT_IBASE_OFFSET]
99 add xPC, x0, #CODEITEM_INSNS_OFFSET
100 add xPC, xPC, x1, lsl #1 // generate new dex_pc_ptr
Bill Buzbeefd522f92016-02-11 22:37:42 +0000101 /* Do we need to switch interpreters? */
102 bl MterpShouldSwitchInterpreters
103 cbnz w0, MterpFallback
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000104 /* resume execution at catch block */
Bill Buzbeefd522f92016-02-11 22:37:42 +0000105 EXPORT_PC
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000106 FETCH_INST
107 GET_INST_OPCODE ip
108 GOTO_OPCODE ip
109 /* NOTE: no fallthrough */
110
111/*
112 * Check for suspend check request. Assumes wINST already loaded, xPC advanced and
113 * still needs to get the opcode and branch to it, and flags are in lr.
114 */
115MterpCheckSuspendAndContinue:
116 ldr xIBASE, [xSELF, #THREAD_CURRENT_IBASE_OFFSET] // refresh xIBASE
117 ands w7, w7, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
118 b.ne check1
119 GET_INST_OPCODE ip // extract opcode from wINST
120 GOTO_OPCODE ip // jump to next instruction
121check1:
122 EXPORT_PC
123 mov x0, xSELF
124 bl MterpSuspendCheck // (self)
Bill Buzbeefd522f92016-02-11 22:37:42 +0000125 cbnz x0, MterpFallback // Something in the environment changed, switch interpreters
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000126 GET_INST_OPCODE ip // extract opcode from wINST
127 GOTO_OPCODE ip // jump to next instruction
128
129/*
Bill Buzbeefd522f92016-02-11 22:37:42 +0000130 * On-stack replacement has happened, and now we've returned from the compiled method.
131 */
132MterpOnStackReplacement:
133#if MTERP_LOGGING
134 mov x0, xSELF
135 add x1, xFP, #OFF_FP_SHADOWFRAME
136 sbfm x2, xINST, 0, 31
137 bl MterpLogOSR
138#endif
139 mov x0, #1 // Signal normal return
140 b MterpDone
141
142/*
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000143 * Bail out to reference interpreter.
144 */
145MterpFallback:
146 EXPORT_PC
147#if MTERP_LOGGING
148 mov x0, xSELF
149 add x1, xFP, #OFF_FP_SHADOWFRAME
150 bl MterpLogFallback
151#endif
152MterpCommonFallback:
153 mov x0, #0 // signal retry with reference interpreter.
154 b MterpDone
155
156/*
157 * We pushed some registers on the stack in ExecuteMterpImpl, then saved
158 * SP and LR. Here we restore SP, restore the registers, and then restore
159 * LR to PC.
160 *
161 * On entry:
162 * uint32_t* xFP (should still be live, pointer to base of vregs)
163 */
164MterpExceptionReturn:
165 mov x0, #1 // signal return to caller.
166 b MterpDone
167MterpReturn:
168 ldr x2, [xFP, #OFF_FP_RESULT_REGISTER]
169 ldr lr, [xSELF, #THREAD_FLAGS_OFFSET]
170 str x0, [x2]
171 mov x0, xSELF
172 ands lr, lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
173 b.eq check2
174 bl MterpSuspendCheck // (self)
175check2:
176 mov x0, #1 // signal return to caller.
177MterpDone:
178 ldp fp, lr, [sp, #48]
179 ldp xPC, xFP, [sp, #32]
180 ldp xSELF, xINST, [sp, #16]
181 ldp xIBASE, xREFS, [sp], #64
182 ret
183
184 .cfi_endproc
185 .size ExecuteMterpImpl, .-ExecuteMterpImpl
186