blob: 3456a7559b43ed481ce696ded8275ebf1c9be0b4 [file] [log] [blame]
buzbee1452bee2015-03-06 14:43:04 -08001/*
2 * ===========================================================================
3 * Common subroutines and data
4 * ===========================================================================
5 */
6
7 .text
8 .align 2
9
10/*
11 * We've detected a condition that will result in an exception, but the exception
12 * has not yet been thrown. Just bail out to the reference interpreter to deal with it.
13 * TUNING: for consistency, we may want to just go ahead and handle these here.
14 */
buzbee1452bee2015-03-06 14:43:04 -080015common_errDivideByZero:
16 EXPORT_PC
17#if MTERP_LOGGING
18 mov r0, rSELF
19 add r1, rFP, #OFF_FP_SHADOWFRAME
20 bl MterpLogDivideByZeroException
21#endif
22 b MterpCommonFallback
23
24common_errArrayIndex:
25 EXPORT_PC
26#if MTERP_LOGGING
27 mov r0, rSELF
28 add r1, rFP, #OFF_FP_SHADOWFRAME
29 bl MterpLogArrayIndexException
30#endif
31 b MterpCommonFallback
32
33common_errNegativeArraySize:
34 EXPORT_PC
35#if MTERP_LOGGING
36 mov r0, rSELF
37 add r1, rFP, #OFF_FP_SHADOWFRAME
38 bl MterpLogNegativeArraySizeException
39#endif
40 b MterpCommonFallback
41
42common_errNoSuchMethod:
43 EXPORT_PC
44#if MTERP_LOGGING
45 mov r0, rSELF
46 add r1, rFP, #OFF_FP_SHADOWFRAME
47 bl MterpLogNoSuchMethodException
48#endif
49 b MterpCommonFallback
50
51common_errNullObject:
52 EXPORT_PC
53#if MTERP_LOGGING
54 mov r0, rSELF
55 add r1, rFP, #OFF_FP_SHADOWFRAME
56 bl MterpLogNullObjectException
57#endif
58 b MterpCommonFallback
59
60common_exceptionThrown:
61 EXPORT_PC
62#if MTERP_LOGGING
63 mov r0, rSELF
64 add r1, rFP, #OFF_FP_SHADOWFRAME
65 bl MterpLogExceptionThrownException
66#endif
67 b MterpCommonFallback
68
69MterpSuspendFallback:
70 EXPORT_PC
71#if MTERP_LOGGING
72 mov r0, rSELF
73 add r1, rFP, #OFF_FP_SHADOWFRAME
74 ldr r2, [rSELF, #THREAD_FLAGS_OFFSET]
75 bl MterpLogSuspendFallback
76#endif
77 b MterpCommonFallback
78
79/*
80 * If we're here, something is out of the ordinary. If there is a pending
81 * exception, handle it. Otherwise, roll back and retry with the reference
82 * interpreter.
83 */
84MterpPossibleException:
85 ldr r0, [rSELF, #THREAD_EXCEPTION_OFFSET]
86 cmp r0, #0 @ Exception pending?
87 beq MterpFallback @ If not, fall back to reference interpreter.
88 /* intentional fallthrough - handle pending exception. */
89/*
90 * On return from a runtime helper routine, we've found a pending exception.
91 * Can we handle it here - or need to bail out to caller?
92 *
93 */
94MterpException:
95 mov r0, rSELF
96 add r1, rFP, #OFF_FP_SHADOWFRAME
97 bl MterpHandleException @ (self, shadow_frame)
98 cmp r0, #0
99 beq MterpExceptionReturn @ no local catch, back to caller.
100 ldr r0, [rFP, #OFF_FP_CODE_ITEM]
101 ldr r1, [rFP, #OFF_FP_DEX_PC]
102 ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET]
103 add rPC, r0, #CODEITEM_INSNS_OFFSET
104 add rPC, rPC, r1, lsl #1 @ generate new dex_pc_ptr
Bill Buzbeefd522f92016-02-11 22:37:42 +0000105 /* Do we need to switch interpreters? */
106 bl MterpShouldSwitchInterpreters
107 cmp r0, #0
108 bne MterpFallback
buzbee1452bee2015-03-06 14:43:04 -0800109 /* resume execution at catch block */
Bill Buzbeefd522f92016-02-11 22:37:42 +0000110 EXPORT_PC
buzbee1452bee2015-03-06 14:43:04 -0800111 FETCH_INST
112 GET_INST_OPCODE ip
113 GOTO_OPCODE ip
114 /* NOTE: no fallthrough */
115
116/*
117 * Check for suspend check request. Assumes rINST already loaded, rPC advanced and
118 * still needs to get the opcode and branch to it, and flags are in lr.
119 */
120MterpCheckSuspendAndContinue:
121 ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] @ refresh rIBASE
buzbee1452bee2015-03-06 14:43:04 -0800122 ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
Bill Buzbeefd522f92016-02-11 22:37:42 +0000123 bne 1f
buzbee1452bee2015-03-06 14:43:04 -0800124 GET_INST_OPCODE ip @ extract opcode from rINST
125 GOTO_OPCODE ip @ jump to next instruction
Bill Buzbeefd522f92016-02-11 22:37:42 +00001261:
127 EXPORT_PC
128 mov r0, rSELF
129 bl MterpSuspendCheck @ (self)
130 cmp r0, #0
131 bne MterpFallback
132 GET_INST_OPCODE ip @ extract opcode from rINST
133 GOTO_OPCODE ip @ jump to next instruction
134
135/*
136 * On-stack replacement has happened, and now we've returned from the compiled method.
137 */
138MterpOnStackReplacement:
139#if MTERP_LOGGING
140 mov r0, rSELF
141 add r1, rFP, #OFF_FP_SHADOWFRAME
142 mov r2, rINST
143 bl MterpLogOSR
144#endif
145 mov r0, #1 @ Signal normal return
146 b MterpDone
buzbee1452bee2015-03-06 14:43:04 -0800147
148/*
149 * Bail out to reference interpreter.
150 */
151MterpFallback:
152 EXPORT_PC
buzbee76833da2016-01-13 13:06:22 -0800153#if MTERP_LOGGING
buzbee1452bee2015-03-06 14:43:04 -0800154 mov r0, rSELF
155 add r1, rFP, #OFF_FP_SHADOWFRAME
156 bl MterpLogFallback
buzbee76833da2016-01-13 13:06:22 -0800157#endif
buzbee1452bee2015-03-06 14:43:04 -0800158MterpCommonFallback:
159 mov r0, #0 @ signal retry with reference interpreter.
160 b MterpDone
161
162/*
163 * We pushed some registers on the stack in ExecuteMterpImpl, then saved
164 * SP and LR. Here we restore SP, restore the registers, and then restore
165 * LR to PC.
166 *
167 * On entry:
168 * uint32_t* rFP (should still be live, pointer to base of vregs)
169 */
170MterpExceptionReturn:
buzbee1452bee2015-03-06 14:43:04 -0800171 mov r0, #1 @ signal return to caller.
172 b MterpDone
173MterpReturn:
174 ldr r2, [rFP, #OFF_FP_RESULT_REGISTER]
buzbee1452bee2015-03-06 14:43:04 -0800175 str r0, [r2]
176 str r1, [r2, #4]
buzbee1452bee2015-03-06 14:43:04 -0800177 mov r0, #1 @ signal return to caller.
178MterpDone:
179 add sp, sp, #4 @ un-align 64
180 ldmfd sp!, {r4-r10,fp,pc} @ restore 9 regs and return
181
182
183 .fnend
184 .size ExecuteMterpImpl, .-ExecuteMterpImpl
185