blob: fbab59f118f28332bb99132f2ad099ca7c3d1cf0 [file] [log] [blame]
buzbee31a4a6f2012-02-28 15:36:15 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogers57b86d42012-03-27 16:05:41 -070017#include "oat/runtime/oat_support_entrypoints.h"
18
buzbee31a4a6f2012-02-28 15:36:15 -080019namespace art {
20
21/*
22 * This source files contains "gen" codegen routines that should
23 * be applicable to most targets. Only mid-level support utilities
24 * and "op" calls may be used here.
25 */
26
buzbee31a4a6f2012-02-28 15:36:15 -080027/*
28 * If there are any ins passed in registers that have not been promoted
29 * to a callee-save register, flush them to the frame. Perform intial
30 * assignment of promoted arguments.
buzbeead8f15e2012-06-18 14:49:45 -070031 *
32 * argLocs is an array of location records describing the incoming arguments
33 * with one location record per word of argument.
buzbee31a4a6f2012-02-28 15:36:15 -080034 */
buzbeead8f15e2012-06-18 14:49:45 -070035void flushIns(CompilationUnit* cUnit, RegLocation* argLocs, RegLocation rlMethod)
buzbee31a4a6f2012-02-28 15:36:15 -080036{
Bill Buzbeea114add2012-05-03 15:00:40 -070037 /*
38 * Dummy up a RegLocation for the incoming Method*
buzbeef0504cd2012-11-13 16:31:10 -080039 * It will attempt to keep kArg0 live (or copy it to home location
Bill Buzbeea114add2012-05-03 15:00:40 -070040 * if promoted).
41 */
buzbeead8f15e2012-06-18 14:49:45 -070042 RegLocation rlSrc = rlMethod;
Bill Buzbeea114add2012-05-03 15:00:40 -070043 rlSrc.location = kLocPhysReg;
buzbeef0504cd2012-11-13 16:31:10 -080044 rlSrc.lowReg = targetReg(kArg0);
Bill Buzbeea114add2012-05-03 15:00:40 -070045 rlSrc.home = false;
46 oatMarkLive(cUnit, rlSrc.lowReg, rlSrc.sRegLow);
47 storeValue(cUnit, rlMethod, rlSrc);
48 // If Method* has been promoted, explicitly flush
49 if (rlMethod.location == kLocPhysReg) {
buzbeef0504cd2012-11-13 16:31:10 -080050 storeWordDisp(cUnit, targetReg(kSp), 0, targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -070051 }
buzbee9c044ce2012-03-18 13:24:07 -070052
Bill Buzbeea114add2012-05-03 15:00:40 -070053 if (cUnit->numIns == 0)
54 return;
55 const int numArgRegs = 3;
buzbeef0504cd2012-11-13 16:31:10 -080056 static SpecialTargetRegister argRegs[] = {kArg1, kArg2, kArg3};
Bill Buzbeea114add2012-05-03 15:00:40 -070057 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
58 /*
59 * Copy incoming arguments to their proper home locations.
60 * NOTE: an older version of dx had an issue in which
61 * it would reuse static method argument registers.
62 * This could result in the same Dalvik virtual register
63 * being promoted to both core and fp regs. To account for this,
64 * we only copy to the corresponding promoted physical register
65 * if it matches the type of the SSA name for the incoming
66 * argument. It is also possible that long and double arguments
67 * end up half-promoted. In those cases, we must flush the promoted
68 * half to memory as well.
69 */
70 for (int i = 0; i < cUnit->numIns; i++) {
71 PromotionMap* vMap = &cUnit->promotionMap[startVReg + i];
72 if (i < numArgRegs) {
73 // If arriving in register
74 bool needFlush = true;
buzbeead8f15e2012-06-18 14:49:45 -070075 RegLocation* tLoc = &argLocs[i];
Bill Buzbeea114add2012-05-03 15:00:40 -070076 if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) {
buzbeef0504cd2012-11-13 16:31:10 -080077 opRegCopy(cUnit, vMap->coreReg, targetReg(argRegs[i]));
Bill Buzbeea114add2012-05-03 15:00:40 -070078 needFlush = false;
79 } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) {
buzbeef0504cd2012-11-13 16:31:10 -080080 opRegCopy(cUnit, vMap->fpReg, targetReg(argRegs[i]));
Bill Buzbeea114add2012-05-03 15:00:40 -070081 needFlush = false;
82 } else {
83 needFlush = true;
84 }
buzbee86a4bce2012-03-06 18:15:00 -080085
Bill Buzbeea114add2012-05-03 15:00:40 -070086 // For wide args, force flush if only half is promoted
87 if (tLoc->wide) {
88 PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1);
89 needFlush |= (pMap->coreLocation != vMap->coreLocation) ||
90 (pMap->fpLocation != vMap->fpLocation);
91 }
92 if (needFlush) {
buzbeef0504cd2012-11-13 16:31:10 -080093 storeBaseDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, startVReg + i),
94 targetReg(argRegs[i]), kWord);
Bill Buzbeea114add2012-05-03 15:00:40 -070095 }
96 } else {
97 // If arriving in frame & promoted
98 if (vMap->coreLocation == kLocPhysReg) {
buzbeef0504cd2012-11-13 16:31:10 -080099 loadWordDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, startVReg + i),
Bill Buzbeea114add2012-05-03 15:00:40 -0700100 vMap->coreReg);
101 }
102 if (vMap->fpLocation == kLocPhysReg) {
buzbeef0504cd2012-11-13 16:31:10 -0800103 loadWordDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, startVReg + i),
Bill Buzbeea114add2012-05-03 15:00:40 -0700104 vMap->fpReg);
105 }
buzbee31a4a6f2012-02-28 15:36:15 -0800106 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700107 }
buzbee31a4a6f2012-02-28 15:36:15 -0800108}
109
buzbeeeaf09bc2012-11-15 14:51:41 -0800110void scanMethodLiteralPool(CompilationUnit* cUnit, LIR** methodTarget, LIR** codeTarget,
111 const DexFile* dexFile, uint32_t dexMethodIdx)
Ian Rogers3fa13792012-03-18 15:53:45 -0700112{
Bill Buzbeea114add2012-05-03 15:00:40 -0700113 LIR* curTarget = cUnit->methodLiteralList;
114 LIR* nextTarget = curTarget != NULL ? curTarget->next : NULL;
115 while (curTarget != NULL && nextTarget != NULL) {
buzbeecbd6d442012-11-17 14:11:25 -0800116 if (curTarget->operands[0] == reinterpret_cast<intptr_t>(dexFile) &&
117 nextTarget->operands[0] == static_cast<int>(dexMethodIdx)) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700118 *codeTarget = curTarget;
119 *methodTarget = nextTarget;
120 DCHECK((*codeTarget)->next == *methodTarget);
buzbeecbd6d442012-11-17 14:11:25 -0800121 DCHECK_EQ((*codeTarget)->operands[0], reinterpret_cast<intptr_t>(dexFile));
122 DCHECK_EQ((*methodTarget)->operands[0], static_cast<int>(dexMethodIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -0700123 break;
Ian Rogers3fa13792012-03-18 15:53:45 -0700124 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700125 curTarget = nextTarget->next;
126 nextTarget = curTarget != NULL ? curTarget->next : NULL;
127 }
Ian Rogers3fa13792012-03-18 15:53:45 -0700128}
129
buzbee31a4a6f2012-02-28 15:36:15 -0800130/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700131 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800132 * emit the next instruction in static & direct invoke sequences.
133 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700134int nextSDCallInsn(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700135 int state, uint32_t dexIdx, uint32_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700136 uintptr_t directCode, uintptr_t directMethod,
137 InvokeType type)
buzbee31a4a6f2012-02-28 15:36:15 -0800138{
buzbeeb046e162012-10-30 15:48:42 -0700139 if (cUnit->instructionSet != kThumb2) {
140 // Disable sharpening
141 directCode = 0;
142 directMethod = 0;
143 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700144 if (directCode != 0 && directMethod != 0) {
145 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800146 case 0: // Get the current Method* [sets kArg0]
buzbeecbd6d442012-11-17 14:11:25 -0800147 if (directCode != static_cast<unsigned int>(-1)) {
buzbeef0504cd2012-11-13 16:31:10 -0800148 loadConstant(cUnit, targetReg(kInvokeTgt), directCode);
Bill Buzbeea114add2012-05-03 15:00:40 -0700149 } else {
150 LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0);
151 if (dataTarget == NULL) {
152 dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx);
153 dataTarget->operands[1] = type;
Ian Rogers2ed3b952012-03-17 11:49:39 -0700154 }
buzbeef0504cd2012-11-13 16:31:10 -0800155 LIR* loadPcRel = opPcRelLoad(cUnit, targetReg(kInvokeTgt), dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700156 oatAppendLIR(cUnit, loadPcRel);
buzbeecbd6d442012-11-17 14:11:25 -0800157 DCHECK_EQ(cUnit->instructionSet, kThumb2) << reinterpret_cast<void*>(dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700158 }
buzbeecbd6d442012-11-17 14:11:25 -0800159 if (directMethod != static_cast<unsigned int>(-1)) {
buzbeef0504cd2012-11-13 16:31:10 -0800160 loadConstant(cUnit, targetReg(kArg0), directMethod);
Bill Buzbeea114add2012-05-03 15:00:40 -0700161 } else {
162 LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0);
163 if (dataTarget == NULL) {
164 dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx);
165 dataTarget->operands[1] = type;
166 }
buzbeef0504cd2012-11-13 16:31:10 -0800167 LIR* loadPcRel = opPcRelLoad(cUnit, targetReg(kArg0), dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700168 oatAppendLIR(cUnit, loadPcRel);
buzbeecbd6d442012-11-17 14:11:25 -0800169 DCHECK_EQ(cUnit->instructionSet, kThumb2) << reinterpret_cast<void*>(dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700170 }
171 break;
172 default:
173 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800174 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700175 } else {
176 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800177 case 0: // Get the current Method* [sets kArg0]
Ian Rogers137e88f2012-10-08 17:46:47 -0700178 // TUNING: we can save a reg copy if Method* has been promoted.
buzbeef0504cd2012-11-13 16:31:10 -0800179 loadCurrMethodDirect(cUnit, targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700180 break;
181 case 1: // Get method->dex_cache_resolved_methods_
buzbeef0504cd2012-11-13 16:31:10 -0800182 loadWordDisp(cUnit, targetReg(kArg0),
183 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(), targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700184 // Set up direct code if known.
185 if (directCode != 0) {
buzbeecbd6d442012-11-17 14:11:25 -0800186 if (directCode != static_cast<unsigned int>(-1)) {
buzbeef0504cd2012-11-13 16:31:10 -0800187 loadConstant(cUnit, targetReg(kInvokeTgt), directCode);
Bill Buzbeea114add2012-05-03 15:00:40 -0700188 } else {
189 LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0);
190 if (dataTarget == NULL) {
191 dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx);
192 dataTarget->operands[1] = type;
193 }
buzbeef0504cd2012-11-13 16:31:10 -0800194 LIR* loadPcRel = opPcRelLoad(cUnit, targetReg(kInvokeTgt), dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700195 oatAppendLIR(cUnit, loadPcRel);
buzbeecbd6d442012-11-17 14:11:25 -0800196 DCHECK_EQ(cUnit->instructionSet, kThumb2) << reinterpret_cast<void*>(dataTarget);
Bill Buzbeea114add2012-05-03 15:00:40 -0700197 }
198 }
199 break;
200 case 2: // Grab target method*
buzbeef0504cd2012-11-13 16:31:10 -0800201 loadWordDisp(cUnit, targetReg(kArg0),
202 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4, targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700203 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700204 case 3: // Grab the code from the method*
buzbeeb046e162012-10-30 15:48:42 -0700205 if (cUnit->instructionSet != kX86) {
206 if (directCode == 0) {
buzbeef0504cd2012-11-13 16:31:10 -0800207 loadWordDisp(cUnit, targetReg(kArg0), AbstractMethod::GetCodeOffset().Int32Value(),
208 targetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700209 }
210 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700211 }
buzbeeb046e162012-10-30 15:48:42 -0700212 // Intentional fallthrough for x86
Bill Buzbeea114add2012-05-03 15:00:40 -0700213 default:
214 return -1;
215 }
216 }
217 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800218}
219
220/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700221 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800222 * emit the next instruction in a virtual invoke sequence.
buzbeef0504cd2012-11-13 16:31:10 -0800223 * We can use kLr as a temp prior to target address loading
buzbee31a4a6f2012-02-28 15:36:15 -0800224 * Note also that we'll load the first argument ("this") into
buzbeef0504cd2012-11-13 16:31:10 -0800225 * kArg1 here rather than the standard loadArgRegs.
buzbee31a4a6f2012-02-28 15:36:15 -0800226 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700227int nextVCallInsn(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700228 int state, uint32_t dexIdx, uint32_t methodIdx,
Brian Carlstromf5822582012-03-19 22:34:31 -0700229 uintptr_t unused, uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800230{
Bill Buzbeea114add2012-05-03 15:00:40 -0700231 /*
232 * This is the fast path in which the target virtual method is
233 * fully resolved at compile time.
234 */
235 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800236 case 0: { // Get "this" [set kArg1]
Ian Rogers137e88f2012-10-08 17:46:47 -0700237 RegLocation rlArg = info->args[0];
buzbeef0504cd2012-11-13 16:31:10 -0800238 loadValueDirectFixed(cUnit, rlArg, targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700239 break;
Ian Rogers137e88f2012-10-08 17:46:47 -0700240 }
buzbeef0504cd2012-11-13 16:31:10 -0800241 case 1: // Is "this" null? [use kArg1]
242 genNullCheck(cUnit, info->args[0].sRegLow, targetReg(kArg1), info->optFlags);
243 // get this->klass_ [use kArg1, set kInvokeTgt]
244 loadWordDisp(cUnit, targetReg(kArg1), Object::ClassOffset().Int32Value(),
245 targetReg(kInvokeTgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700246 break;
buzbeef0504cd2012-11-13 16:31:10 -0800247 case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt]
248 loadWordDisp(cUnit, targetReg(kInvokeTgt), Class::VTableOffset().Int32Value(),
249 targetReg(kInvokeTgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700250 break;
buzbeef0504cd2012-11-13 16:31:10 -0800251 case 3: // Get target method [use kInvokeTgt, set kArg0]
252 loadWordDisp(cUnit, targetReg(kInvokeTgt), (methodIdx * 4) +
253 Array::DataOffset(sizeof(Object*)).Int32Value(), targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700254 break;
buzbeef0504cd2012-11-13 16:31:10 -0800255 case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt]
buzbeeb046e162012-10-30 15:48:42 -0700256 if (cUnit->instructionSet != kX86) {
buzbeef0504cd2012-11-13 16:31:10 -0800257 loadWordDisp(cUnit, targetReg(kArg0), AbstractMethod::GetCodeOffset().Int32Value(),
258 targetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700259 break;
260 }
261 // Intentional fallthrough for X86
Bill Buzbeea114add2012-05-03 15:00:40 -0700262 default:
263 return -1;
264 }
265 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800266}
267
Ian Rogers137e88f2012-10-08 17:46:47 -0700268/*
269 * All invoke-interface calls bounce off of art_invoke_interface_trampoline,
270 * which will locate the target and continue on via a tail call.
271 */
272int nextInterfaceCallInsn(CompilationUnit* cUnit, CallInfo* info, int state,
273 uint32_t dexIdx, uint32_t unused, uintptr_t unused2,
274 uintptr_t directMethod, InvokeType unused4)
275{
buzbeeb046e162012-10-30 15:48:42 -0700276 if (cUnit->instructionSet != kThumb2) {
277 // Disable sharpening
278 directMethod = 0;
279 }
280 int trampoline = (cUnit->instructionSet == kX86) ? 0
281 : ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline);
Ian Rogers137e88f2012-10-08 17:46:47 -0700282
283 if (directMethod != 0) {
284 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800285 case 0: // Load the trampoline target [sets kInvokeTgt].
buzbeeb046e162012-10-30 15:48:42 -0700286 if (cUnit->instructionSet != kX86) {
buzbeef0504cd2012-11-13 16:31:10 -0800287 loadWordDisp(cUnit, targetReg(kSelf), trampoline, targetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700288 }
buzbeef0504cd2012-11-13 16:31:10 -0800289 // Get the interface Method* [sets kArg0]
buzbeecbd6d442012-11-17 14:11:25 -0800290 if (directMethod != static_cast<unsigned int>(-1)) {
buzbeef0504cd2012-11-13 16:31:10 -0800291 loadConstant(cUnit, targetReg(kArg0), directMethod);
Ian Rogers137e88f2012-10-08 17:46:47 -0700292 } else {
293 LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0);
294 if (dataTarget == NULL) {
295 dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx);
296 dataTarget->operands[1] = kInterface;
297 }
buzbeef0504cd2012-11-13 16:31:10 -0800298 LIR* loadPcRel = opPcRelLoad(cUnit, targetReg(kArg0), dataTarget);
Ian Rogers137e88f2012-10-08 17:46:47 -0700299 oatAppendLIR(cUnit, loadPcRel);
buzbeecbd6d442012-11-17 14:11:25 -0800300 DCHECK_EQ(cUnit->instructionSet, kThumb2) << reinterpret_cast<void*>(dataTarget);
Ian Rogers137e88f2012-10-08 17:46:47 -0700301 }
302 break;
303 default:
304 return -1;
305 }
306 } else {
307 switch (state) {
308 case 0:
buzbeef0504cd2012-11-13 16:31:10 -0800309 // Get the current Method* [sets kArg0] - TUNING: remove copy of method if it is promoted.
310 loadCurrMethodDirect(cUnit, targetReg(kArg0));
311 // Load the trampoline target [sets kInvokeTgt].
buzbeeb046e162012-10-30 15:48:42 -0700312 if (cUnit->instructionSet != kX86) {
buzbeef0504cd2012-11-13 16:31:10 -0800313 loadWordDisp(cUnit, targetReg(kSelf), trampoline, targetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700314 }
Ian Rogers137e88f2012-10-08 17:46:47 -0700315 break;
buzbeef0504cd2012-11-13 16:31:10 -0800316 case 1: // Get method->dex_cache_resolved_methods_ [set/use kArg0]
317 loadWordDisp(cUnit, targetReg(kArg0),
Ian Rogers137e88f2012-10-08 17:46:47 -0700318 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(),
buzbeef0504cd2012-11-13 16:31:10 -0800319 targetReg(kArg0));
Ian Rogers137e88f2012-10-08 17:46:47 -0700320 break;
buzbeef0504cd2012-11-13 16:31:10 -0800321 case 2: // Grab target method* [set/use kArg0]
322 loadWordDisp(cUnit, targetReg(kArg0),
Ian Rogers137e88f2012-10-08 17:46:47 -0700323 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4,
buzbeef0504cd2012-11-13 16:31:10 -0800324 targetReg(kArg0));
Ian Rogers137e88f2012-10-08 17:46:47 -0700325 break;
326 default:
327 return -1;
328 }
329 }
330 return state + 1;
331}
332
buzbee3b3dbdd2012-06-13 13:39:34 -0700333int nextInvokeInsnSP(CompilationUnit* cUnit, CallInfo* info, int trampoline,
buzbee31a4a6f2012-02-28 15:36:15 -0800334 int state, uint32_t dexIdx, uint32_t methodIdx)
335{
Bill Buzbeea114add2012-05-03 15:00:40 -0700336 /*
337 * This handles the case in which the base method is not fully
338 * resolved at compile time, we bail to a runtime helper.
339 */
340 if (state == 0) {
buzbeeb046e162012-10-30 15:48:42 -0700341 if (cUnit->instructionSet != kX86) {
342 // Load trampoline target
buzbeef0504cd2012-11-13 16:31:10 -0800343 loadWordDisp(cUnit, targetReg(kSelf), trampoline, targetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700344 }
buzbeef0504cd2012-11-13 16:31:10 -0800345 // Load kArg0 with method index
346 loadConstant(cUnit, targetReg(kArg0), dexIdx);
Bill Buzbeea114add2012-05-03 15:00:40 -0700347 return 1;
348 }
349 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800350}
351
buzbee3b3dbdd2012-06-13 13:39:34 -0700352int nextStaticCallInsnSP(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700353 int state, uint32_t dexIdx, uint32_t methodIdx,
Brian Carlstromf5822582012-03-19 22:34:31 -0700354 uintptr_t unused, uintptr_t unused2,
355 InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800356{
Ian Rogers57b86d42012-03-27 16:05:41 -0700357 int trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700358 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800359}
360
buzbee3b3dbdd2012-06-13 13:39:34 -0700361int nextDirectCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700362 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700363 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800364{
Ian Rogers57b86d42012-03-27 16:05:41 -0700365 int trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700366 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800367}
368
buzbee3b3dbdd2012-06-13 13:39:34 -0700369int nextSuperCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700370 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700371 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800372{
Ian Rogers57b86d42012-03-27 16:05:41 -0700373 int trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700374 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800375}
376
buzbee3b3dbdd2012-06-13 13:39:34 -0700377int nextVCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700378 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700379 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800380{
Ian Rogers57b86d42012-03-27 16:05:41 -0700381 int trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700382 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800383}
384
buzbee15bf9802012-06-12 17:49:27 -0700385int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit,
buzbee3b3dbdd2012-06-13 13:39:34 -0700386 CallInfo* info, int state,
buzbee15bf9802012-06-12 17:49:27 -0700387 uint32_t dexIdx, uint32_t unused,
388 uintptr_t unused2, uintptr_t unused3,
389 InvokeType unused4)
buzbee31a4a6f2012-02-28 15:36:15 -0800390{
Ian Rogers57b86d42012-03-27 16:05:41 -0700391 int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700392 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800393}
394
buzbee3b3dbdd2012-06-13 13:39:34 -0700395int loadArgRegs(CompilationUnit* cUnit, CallInfo* info, int callState,
buzbee15bf9802012-06-12 17:49:27 -0700396 NextCallInsn nextCallInsn, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700397 uint32_t methodIdx, uintptr_t directCode,
Brian Carlstromf5822582012-03-19 22:34:31 -0700398 uintptr_t directMethod, InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800399{
buzbeef0504cd2012-11-13 16:31:10 -0800400 int lastArgReg = targetReg(kArg3);
401 int nextReg = targetReg(kArg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700402 int nextArg = 0;
403 if (skipThis) {
404 nextReg++;
405 nextArg++;
406 }
buzbee15bf9802012-06-12 17:49:27 -0700407 for (; (nextReg <= lastArgReg) && (nextArg < info->numArgWords); nextReg++) {
408 RegLocation rlArg = info->args[nextArg++];
Bill Buzbeea114add2012-05-03 15:00:40 -0700409 rlArg = oatUpdateRawLoc(cUnit, rlArg);
buzbeef0504cd2012-11-13 16:31:10 -0800410 if (rlArg.wide && (nextReg <= targetReg(kArg2))) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700411 loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1);
412 nextReg++;
413 nextArg++;
414 } else {
415 rlArg.wide = false;
416 loadValueDirectFixed(cUnit, rlArg, nextReg);
buzbee31a4a6f2012-02-28 15:36:15 -0800417 }
buzbee15bf9802012-06-12 17:49:27 -0700418 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700419 directCode, directMethod, type);
420 }
421 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800422}
423
424/*
425 * Load up to 5 arguments, the first three of which will be in
buzbeef0504cd2012-11-13 16:31:10 -0800426 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
buzbee31a4a6f2012-02-28 15:36:15 -0800427 * and as part of the load sequence, it must be replaced with
428 * the target method pointer. Note, this may also be called
429 * for "range" variants if the number of arguments is 5 or fewer.
430 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700431int genDalvikArgsNoRange(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700432 int callState,
buzbee31a4a6f2012-02-28 15:36:15 -0800433 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700434 uint32_t dexIdx, uint32_t methodIdx,
435 uintptr_t directCode, uintptr_t directMethod,
Brian Carlstromf5822582012-03-19 22:34:31 -0700436 InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800437{
Bill Buzbeea114add2012-05-03 15:00:40 -0700438 RegLocation rlArg;
buzbee31a4a6f2012-02-28 15:36:15 -0800439
Bill Buzbeea114add2012-05-03 15:00:40 -0700440 /* If no arguments, just return */
buzbee15bf9802012-06-12 17:49:27 -0700441 if (info->numArgWords == 0)
buzbee31a4a6f2012-02-28 15:36:15 -0800442 return callState;
Bill Buzbeea114add2012-05-03 15:00:40 -0700443
buzbee15bf9802012-06-12 17:49:27 -0700444 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700445 directCode, directMethod, type);
446
buzbee15bf9802012-06-12 17:49:27 -0700447 DCHECK_LE(info->numArgWords, 5);
448 if (info->numArgWords > 3) {
449 int32_t nextUse = 3;
Bill Buzbeea114add2012-05-03 15:00:40 -0700450 //Detect special case of wide arg spanning arg3/arg4
buzbee15bf9802012-06-12 17:49:27 -0700451 RegLocation rlUse0 = info->args[0];
452 RegLocation rlUse1 = info->args[1];
453 RegLocation rlUse2 = info->args[2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700454 if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) &&
455 rlUse2.wide) {
456 int reg = -1;
457 // Wide spans, we need the 2nd half of uses[2].
458 rlArg = oatUpdateLocWide(cUnit, rlUse2);
459 if (rlArg.location == kLocPhysReg) {
460 reg = rlArg.highReg;
461 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800462 // kArg2 & rArg3 can safely be used here
463 reg = targetReg(kArg3);
464 loadWordDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg);
buzbee15bf9802012-06-12 17:49:27 -0700465 callState = nextCallInsn(cUnit, info, callState, dexIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700466 methodIdx, directCode, directMethod, type);
467 }
buzbeef0504cd2012-11-13 16:31:10 -0800468 storeBaseDisp(cUnit, targetReg(kSp), (nextUse + 1) * 4, reg, kWord);
469 storeBaseDisp(cUnit, targetReg(kSp), 16 /* (3+1)*4 */, reg, kWord);
buzbee15bf9802012-06-12 17:49:27 -0700470 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700471 directCode, directMethod, type);
472 nextUse++;
473 }
474 // Loop through the rest
buzbee15bf9802012-06-12 17:49:27 -0700475 while (nextUse < info->numArgWords) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700476 int lowReg;
477 int highReg = -1;
buzbee15bf9802012-06-12 17:49:27 -0700478 rlArg = info->args[nextUse];
Bill Buzbeea114add2012-05-03 15:00:40 -0700479 rlArg = oatUpdateRawLoc(cUnit, rlArg);
480 if (rlArg.location == kLocPhysReg) {
481 lowReg = rlArg.lowReg;
482 highReg = rlArg.highReg;
483 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800484 lowReg = targetReg(kArg2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700485 if (rlArg.wide) {
buzbeef0504cd2012-11-13 16:31:10 -0800486 highReg = targetReg(kArg3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700487 loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg);
488 } else {
489 loadValueDirectFixed(cUnit, rlArg, lowReg);
490 }
buzbee15bf9802012-06-12 17:49:27 -0700491 callState = nextCallInsn(cUnit, info, callState, dexIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700492 methodIdx, directCode, directMethod, type);
493 }
494 int outsOffset = (nextUse + 1) * 4;
495 if (rlArg.wide) {
buzbeef0504cd2012-11-13 16:31:10 -0800496 storeBaseDispWide(cUnit, targetReg(kSp), outsOffset, lowReg, highReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700497 nextUse += 2;
498 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800499 storeWordDisp(cUnit, targetReg(kSp), outsOffset, lowReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700500 nextUse++;
501 }
buzbee15bf9802012-06-12 17:49:27 -0700502 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700503 directCode, directMethod, type);
504 }
505 }
506
buzbee15bf9802012-06-12 17:49:27 -0700507 callState = loadArgRegs(cUnit, info, callState, nextCallInsn,
Bill Buzbeea114add2012-05-03 15:00:40 -0700508 dexIdx, methodIdx, directCode, directMethod,
509 type, skipThis);
510
511 if (pcrLabel) {
buzbeecbd6d442012-11-17 14:11:25 -0800512 *pcrLabel = genNullCheck(cUnit, info->args[0].sRegLow, targetReg(kArg1), info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700513 }
514 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800515}
516
517/*
518 * May have 0+ arguments (also used for jumbo). Note that
519 * source virtual registers may be in physical registers, so may
520 * need to be flushed to home location before copying. This
521 * applies to arg3 and above (see below).
522 *
523 * Two general strategies:
524 * If < 20 arguments
525 * Pass args 3-18 using vldm/vstm block copy
buzbeef0504cd2012-11-13 16:31:10 -0800526 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800527 * If 20+ arguments
528 * Pass args arg19+ using memcpy block copy
buzbeef0504cd2012-11-13 16:31:10 -0800529 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800530 *
531 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700532int genDalvikArgsRange(CompilationUnit* cUnit, CallInfo* info, int callState,
buzbee31a4a6f2012-02-28 15:36:15 -0800533 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700534 uint32_t dexIdx, uint32_t methodIdx,
535 uintptr_t directCode, uintptr_t directMethod,
Brian Carlstromf5822582012-03-19 22:34:31 -0700536 InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800537{
buzbee31a4a6f2012-02-28 15:36:15 -0800538
Bill Buzbeea114add2012-05-03 15:00:40 -0700539 // If we can treat it as non-range (Jumbo ops will use range form)
buzbee15bf9802012-06-12 17:49:27 -0700540 if (info->numArgWords <= 5)
541 return genDalvikArgsNoRange(cUnit, info, callState, pcrLabel,
Bill Buzbeea114add2012-05-03 15:00:40 -0700542 nextCallInsn, dexIdx, methodIdx,
543 directCode, directMethod, type, skipThis);
544 /*
Bill Buzbeea114add2012-05-03 15:00:40 -0700545 * First load the non-register arguments. Both forms expect all
546 * of the source arguments to be in their home frame location, so
547 * scan the sReg names and flush any that have been promoted to
548 * frame backing storage.
549 */
550 // Scan the rest of the args - if in physReg flush to memory
buzbee15bf9802012-06-12 17:49:27 -0700551 for (int nextArg = 0; nextArg < info->numArgWords;) {
552 RegLocation loc = info->args[nextArg];
Bill Buzbeea114add2012-05-03 15:00:40 -0700553 if (loc.wide) {
554 loc = oatUpdateLocWide(cUnit, loc);
555 if ((nextArg >= 2) && (loc.location == kLocPhysReg)) {
buzbeef0504cd2012-11-13 16:31:10 -0800556 storeBaseDispWide(cUnit, targetReg(kSp), oatSRegOffset(cUnit, loc.sRegLow),
Bill Buzbeea114add2012-05-03 15:00:40 -0700557 loc.lowReg, loc.highReg);
558 }
559 nextArg += 2;
560 } else {
561 loc = oatUpdateLoc(cUnit, loc);
562 if ((nextArg >= 3) && (loc.location == kLocPhysReg)) {
buzbeef0504cd2012-11-13 16:31:10 -0800563 storeBaseDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, loc.sRegLow),
Bill Buzbeea114add2012-05-03 15:00:40 -0700564 loc.lowReg, kWord);
565 }
566 nextArg++;
buzbee31a4a6f2012-02-28 15:36:15 -0800567 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700568 }
buzbee31a4a6f2012-02-28 15:36:15 -0800569
buzbee15bf9802012-06-12 17:49:27 -0700570 int startOffset = oatSRegOffset(cUnit, info->args[3].sRegLow);
Bill Buzbeea114add2012-05-03 15:00:40 -0700571 int outsOffset = 4 /* Method* */ + (3 * 4);
buzbeeb046e162012-10-30 15:48:42 -0700572 if (cUnit->instructionSet != kThumb2) {
buzbee31a4a6f2012-02-28 15:36:15 -0800573 // Generate memcpy
buzbeef0504cd2012-11-13 16:31:10 -0800574 opRegRegImm(cUnit, kOpAdd, targetReg(kArg0), targetReg(kSp), outsOffset);
575 opRegRegImm(cUnit, kOpAdd, targetReg(kArg1), targetReg(kSp), startOffset);
576 callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy), targetReg(kArg0),
577 targetReg(kArg1), (info->numArgWords - 3) * 4, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700578 } else {
buzbeeb046e162012-10-30 15:48:42 -0700579 if (info->numArgWords >= 20) {
580 // Generate memcpy
buzbeef0504cd2012-11-13 16:31:10 -0800581 opRegRegImm(cUnit, kOpAdd, targetReg(kArg0), targetReg(kSp), outsOffset);
582 opRegRegImm(cUnit, kOpAdd, targetReg(kArg1), targetReg(kSp), startOffset);
583 callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy), targetReg(kArg0),
584 targetReg(kArg1), (info->numArgWords - 3) * 4, false);
buzbeeb046e162012-10-30 15:48:42 -0700585 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800586 // Use vldm/vstm pair using kArg3 as a temp
buzbeeb046e162012-10-30 15:48:42 -0700587 int regsLeft = std::min(info->numArgWords - 3, 16);
588 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
589 directCode, directMethod, type);
buzbeef0504cd2012-11-13 16:31:10 -0800590 opRegRegImm(cUnit, kOpAdd, targetReg(kArg3), targetReg(kSp), startOffset);
591 LIR* ld = opVldm(cUnit, targetReg(kArg3), regsLeft);
buzbeeb046e162012-10-30 15:48:42 -0700592 //TUNING: loosen barrier
593 ld->defMask = ENCODE_ALL;
594 setMemRefType(ld, true /* isLoad */, kDalvikReg);
595 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
596 directCode, directMethod, type);
buzbeef0504cd2012-11-13 16:31:10 -0800597 opRegRegImm(cUnit, kOpAdd, targetReg(kArg3), targetReg(kSp), 4 /* Method* */ + (3 * 4));
buzbeeb046e162012-10-30 15:48:42 -0700598 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
599 directCode, directMethod, type);
buzbeef0504cd2012-11-13 16:31:10 -0800600 LIR* st = opVstm(cUnit, targetReg(kArg3), regsLeft);
buzbeeb046e162012-10-30 15:48:42 -0700601 setMemRefType(st, false /* isLoad */, kDalvikReg);
602 st->defMask = ENCODE_ALL;
603 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
604 directCode, directMethod, type);
605 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700606 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700607
buzbee15bf9802012-06-12 17:49:27 -0700608 callState = loadArgRegs(cUnit, info, callState, nextCallInsn,
Bill Buzbeea114add2012-05-03 15:00:40 -0700609 dexIdx, methodIdx, directCode, directMethod,
610 type, skipThis);
611
buzbee15bf9802012-06-12 17:49:27 -0700612 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700613 directCode, directMethod, type);
614 if (pcrLabel) {
buzbeef0504cd2012-11-13 16:31:10 -0800615 *pcrLabel = genNullCheck(cUnit, info->args[0].sRegLow, targetReg(kArg1),
buzbee15bf9802012-06-12 17:49:27 -0700616 info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700617 }
618 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800619}
620
buzbee3b3dbdd2012-06-13 13:39:34 -0700621RegLocation inlineTarget(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700622{
Bill Buzbeea114add2012-05-03 15:00:40 -0700623 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700624 if (info->result.location == kLocInvalid) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700625 res = oatGetReturn(cUnit, false);
626 } else {
buzbee15bf9802012-06-12 17:49:27 -0700627 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700628 }
629 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700630}
631
buzbee3b3dbdd2012-06-13 13:39:34 -0700632RegLocation inlineTargetWide(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700633{
Bill Buzbeea114add2012-05-03 15:00:40 -0700634 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700635 if (info->result.location == kLocInvalid) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700636 res = oatGetReturnWide(cUnit, false);
637 } else {
buzbee15bf9802012-06-12 17:49:27 -0700638 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700639 }
640 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700641}
642
buzbee3b3dbdd2012-06-13 13:39:34 -0700643bool genInlinedCharAt(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700644{
buzbeeb046e162012-10-30 15:48:42 -0700645 if (cUnit->instructionSet == kMips) {
646 // TODO - add Mips implementation
647 return false;
648 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700649 // Location of reference to data array
650 int valueOffset = String::ValueOffset().Int32Value();
651 // Location of count
652 int countOffset = String::CountOffset().Int32Value();
653 // Starting offset within data array
654 int offsetOffset = String::OffsetOffset().Int32Value();
655 // Start of char data with array_
656 int dataOffset = Array::DataOffset(sizeof(uint16_t)).Int32Value();
buzbeefc9e6fa2012-03-23 15:14:29 -0700657
buzbee15bf9802012-06-12 17:49:27 -0700658 RegLocation rlObj = info->args[0];
659 RegLocation rlIdx = info->args[1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700660 rlObj = loadValue(cUnit, rlObj, kCoreReg);
661 rlIdx = loadValue(cUnit, rlIdx, kCoreReg);
662 int regMax;
buzbee15bf9802012-06-12 17:49:27 -0700663 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, info->optFlags);
664 bool rangeCheck = (!(info->optFlags & MIR_IGNORE_RANGE_CHECK));
jeffhao634ea282012-08-10 13:04:01 -0700665 LIR* launchPad = NULL;
buzbeeb046e162012-10-30 15:48:42 -0700666 int regOff = INVALID_REG;
667 int regPtr = INVALID_REG;
668 if (cUnit->instructionSet != kX86) {
669 regOff = oatAllocTemp(cUnit);
670 regPtr = oatAllocTemp(cUnit);
671 if (rangeCheck) {
672 regMax = oatAllocTemp(cUnit);
673 loadWordDisp(cUnit, rlObj.lowReg, countOffset, regMax);
674 }
675 loadWordDisp(cUnit, rlObj.lowReg, offsetOffset, regOff);
676 loadWordDisp(cUnit, rlObj.lowReg, valueOffset, regPtr);
677 if (rangeCheck) {
678 // Set up a launch pad to allow retry in case of bounds violation */
buzbeecbd6d442012-11-17 14:11:25 -0800679 launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
buzbeeb046e162012-10-30 15:48:42 -0700680 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
buzbeecbd6d442012-11-17 14:11:25 -0800681 reinterpret_cast<uintptr_t>(launchPad));
buzbeeb046e162012-10-30 15:48:42 -0700682 opRegReg(cUnit, kOpCmp, rlIdx.lowReg, regMax);
683 oatFreeTemp(cUnit, regMax);
684 opCondBranch(cUnit, kCondCs, launchPad);
685 }
686 } else {
687 if (rangeCheck) {
688 regMax = oatAllocTemp(cUnit);
689 loadWordDisp(cUnit, rlObj.lowReg, countOffset, regMax);
690 // Set up a launch pad to allow retry in case of bounds violation */
buzbeecbd6d442012-11-17 14:11:25 -0800691 launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
buzbeeb046e162012-10-30 15:48:42 -0700692 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
buzbeecbd6d442012-11-17 14:11:25 -0800693 reinterpret_cast<uintptr_t>(launchPad));
buzbeeb046e162012-10-30 15:48:42 -0700694 opRegReg(cUnit, kOpCmp, rlIdx.lowReg, regMax);
695 oatFreeTemp(cUnit, regMax);
696 opCondBranch(cUnit, kCondCc, launchPad);
697 }
698 regOff = oatAllocTemp(cUnit);
699 regPtr = oatAllocTemp(cUnit);
700 loadWordDisp(cUnit, rlObj.lowReg, offsetOffset, regOff);
701 loadWordDisp(cUnit, rlObj.lowReg, valueOffset, regPtr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700702 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700703 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
704 opRegReg(cUnit, kOpAdd, regOff, rlIdx.lowReg);
jeffhao634ea282012-08-10 13:04:01 -0700705 oatFreeTemp(cUnit, rlObj.lowReg);
706 oatFreeTemp(cUnit, rlIdx.lowReg);
buzbee15bf9802012-06-12 17:49:27 -0700707 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700708 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
709 loadBaseIndexed(cUnit, regPtr, regOff, rlResult.lowReg, 1, kUnsignedHalf);
710 oatFreeTemp(cUnit, regOff);
711 oatFreeTemp(cUnit, regPtr);
712 storeValue(cUnit, rlDest, rlResult);
713 if (rangeCheck) {
Elliott Hughes60234562012-06-01 12:25:59 -0700714 launchPad->operands[2] = 0; // no resumption
Bill Buzbeea114add2012-05-03 15:00:40 -0700715 }
716 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700717 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
Bill Buzbeea114add2012-05-03 15:00:40 -0700718 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700719}
720
721// Generates an inlined String.isEmpty or String.length.
buzbee3b3dbdd2012-06-13 13:39:34 -0700722bool genInlinedStringIsEmptyOrLength(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700723 bool isEmpty)
buzbeefc9e6fa2012-03-23 15:14:29 -0700724{
buzbeeb046e162012-10-30 15:48:42 -0700725 if (cUnit->instructionSet == kMips) {
726 // TODO - add Mips implementation
727 return false;
728 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700729 // dst = src.length();
buzbee15bf9802012-06-12 17:49:27 -0700730 RegLocation rlObj = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700731 rlObj = loadValue(cUnit, rlObj, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700732 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700733 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
buzbee15bf9802012-06-12 17:49:27 -0700734 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700735 loadWordDisp(cUnit, rlObj.lowReg, String::CountOffset().Int32Value(),
736 rlResult.lowReg);
737 if (isEmpty) {
738 // dst = (dst == 0);
buzbeeb046e162012-10-30 15:48:42 -0700739 if (cUnit->instructionSet == kThumb2) {
740 int tReg = oatAllocTemp(cUnit);
741 opRegReg(cUnit, kOpNeg, tReg, rlResult.lowReg);
742 opRegRegReg(cUnit, kOpAdc, rlResult.lowReg, rlResult.lowReg, tReg);
743 } else {
744 DCHECK_EQ(cUnit->instructionSet, kX86);
745 opRegImm(cUnit, kOpSub, rlResult.lowReg, 1);
746 opRegImm(cUnit, kOpLsr, rlResult.lowReg, 31);
747 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700748 }
749 storeValue(cUnit, rlDest, rlResult);
750 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700751}
752
buzbee3b3dbdd2012-06-13 13:39:34 -0700753bool genInlinedAbsInt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700754{
buzbeeb046e162012-10-30 15:48:42 -0700755 if (cUnit->instructionSet == kMips) {
756 // TODO - add Mips implementation
757 return false;
758 }
buzbee15bf9802012-06-12 17:49:27 -0700759 RegLocation rlSrc = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700760 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700761 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700762 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
763 int signReg = oatAllocTemp(cUnit);
764 // abs(x) = y<=x>>31, (x+y)^y.
765 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.lowReg, 31);
766 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
767 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
768 storeValue(cUnit, rlDest, rlResult);
769 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700770}
771
buzbee3b3dbdd2012-06-13 13:39:34 -0700772bool genInlinedAbsLong(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700773{
buzbeeb046e162012-10-30 15:48:42 -0700774 if (cUnit->instructionSet == kMips) {
775 // TODO - add Mips implementation
776 return false;
777 }
778 if (cUnit->instructionSet == kThumb2) {
779 RegLocation rlSrc = info->args[0];
780 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
781 RegLocation rlDest = inlineTargetWide(cUnit, info);
782 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
783 int signReg = oatAllocTemp(cUnit);
784 // abs(x) = y<=x>>31, (x+y)^y.
785 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.highReg, 31);
786 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
787 opRegRegReg(cUnit, kOpAdc, rlResult.highReg, rlSrc.highReg, signReg);
788 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
789 opRegReg(cUnit, kOpXor, rlResult.highReg, signReg);
790 storeValueWide(cUnit, rlDest, rlResult);
791 return true;
792 } else {
793 DCHECK_EQ(cUnit->instructionSet, kX86);
794 // Reuse source registers to avoid running out of temps
795 RegLocation rlSrc = info->args[0];
796 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
797 RegLocation rlDest = inlineTargetWide(cUnit, info);
798 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
799 opRegCopyWide(cUnit, rlResult.lowReg, rlResult.highReg, rlSrc.lowReg, rlSrc.highReg);
800 oatFreeTemp(cUnit, rlSrc.lowReg);
801 oatFreeTemp(cUnit, rlSrc.highReg);
802 int signReg = oatAllocTemp(cUnit);
803 // abs(x) = y<=x>>31, (x+y)^y.
804 opRegRegImm(cUnit, kOpAsr, signReg, rlResult.highReg, 31);
805 opRegReg(cUnit, kOpAdd, rlResult.lowReg, signReg);
806 opRegReg(cUnit, kOpAdc, rlResult.highReg, signReg);
807 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
808 opRegReg(cUnit, kOpXor, rlResult.highReg, signReg);
809 storeValueWide(cUnit, rlDest, rlResult);
810 return true;
811 }
buzbeefc9e6fa2012-03-23 15:14:29 -0700812}
813
buzbee3b3dbdd2012-06-13 13:39:34 -0700814bool genInlinedFloatCvt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700815{
buzbeeb046e162012-10-30 15:48:42 -0700816 if (cUnit->instructionSet == kMips) {
817 // TODO - add Mips implementation
818 return false;
819 }
buzbee15bf9802012-06-12 17:49:27 -0700820 RegLocation rlSrc = info->args[0];
821 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700822 storeValue(cUnit, rlDest, rlSrc);
823 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700824}
825
buzbee3b3dbdd2012-06-13 13:39:34 -0700826bool genInlinedDoubleCvt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700827{
buzbeeb046e162012-10-30 15:48:42 -0700828 if (cUnit->instructionSet == kMips) {
829 // TODO - add Mips implementation
830 return false;
831 }
buzbee15bf9802012-06-12 17:49:27 -0700832 RegLocation rlSrc = info->args[0];
833 RegLocation rlDest = inlineTargetWide(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700834 storeValueWide(cUnit, rlDest, rlSrc);
835 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700836}
837
838/*
839 * Fast string.indexOf(I) & (II). Tests for simple case of char <= 0xffff,
840 * otherwise bails to standard library code.
841 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700842bool genInlinedIndexOf(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700843 bool zeroBased)
buzbeefc9e6fa2012-03-23 15:14:29 -0700844{
buzbeeb046e162012-10-30 15:48:42 -0700845 if (cUnit->instructionSet == kMips) {
846 // TODO - add Mips implementation
847 return false;
848 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700849 oatClobberCalleeSave(cUnit);
850 oatLockCallTemps(cUnit); // Using fixed registers
buzbeef0504cd2012-11-13 16:31:10 -0800851 int regPtr = targetReg(kArg0);
852 int regChar = targetReg(kArg1);
853 int regStart = targetReg(kArg2);
buzbeefc9e6fa2012-03-23 15:14:29 -0700854
buzbee15bf9802012-06-12 17:49:27 -0700855 RegLocation rlObj = info->args[0];
856 RegLocation rlChar = info->args[1];
857 RegLocation rlStart = info->args[2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700858 loadValueDirectFixed(cUnit, rlObj, regPtr);
859 loadValueDirectFixed(cUnit, rlChar, regChar);
860 if (zeroBased) {
861 loadConstant(cUnit, regStart, 0);
862 } else {
863 loadValueDirectFixed(cUnit, rlStart, regStart);
864 }
buzbeeb046e162012-10-30 15:48:42 -0700865 int rTgt = (cUnit->instructionSet != kX86) ? loadHelper(cUnit, ENTRYPOINT_OFFSET(pIndexOf)) : 0;
buzbee15bf9802012-06-12 17:49:27 -0700866 genNullCheck(cUnit, rlObj.sRegLow, regPtr, info->optFlags);
buzbeecbd6d442012-11-17 14:11:25 -0800867 LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
868 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads, reinterpret_cast<uintptr_t>(launchPad));
Bill Buzbeea114add2012-05-03 15:00:40 -0700869 opCmpImmBranch(cUnit, kCondGt, regChar, 0xFFFF, launchPad);
buzbee8320f382012-09-11 16:29:42 -0700870 // NOTE: not a safepoint
buzbeeb046e162012-10-30 15:48:42 -0700871 if (cUnit->instructionSet != kX86) {
872 opReg(cUnit, kOpBlx, rTgt);
873 } else {
874 opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pIndexOf));
875 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700876 LIR* resumeTgt = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -0800877 launchPad->operands[2] = reinterpret_cast<uintptr_t>(resumeTgt);
Bill Buzbeea114add2012-05-03 15:00:40 -0700878 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700879 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
880 RegLocation rlReturn = oatGetReturn(cUnit, false);
881 RegLocation rlDest = inlineTarget(cUnit, info);
882 storeValue(cUnit, rlDest, rlReturn);
Bill Buzbeea114add2012-05-03 15:00:40 -0700883 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700884}
885
886/* Fast string.compareTo(Ljava/lang/string;)I. */
buzbee3b3dbdd2012-06-13 13:39:34 -0700887bool genInlinedStringCompareTo(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700888{
buzbeeb046e162012-10-30 15:48:42 -0700889 if (cUnit->instructionSet == kMips) {
890 // TODO - add Mips implementation
891 return false;
892 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700893 oatClobberCalleeSave(cUnit);
894 oatLockCallTemps(cUnit); // Using fixed registers
buzbeef0504cd2012-11-13 16:31:10 -0800895 int regThis = targetReg(kArg0);
896 int regCmp = targetReg(kArg1);
buzbeefc9e6fa2012-03-23 15:14:29 -0700897
buzbee15bf9802012-06-12 17:49:27 -0700898 RegLocation rlThis = info->args[0];
899 RegLocation rlCmp = info->args[1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700900 loadValueDirectFixed(cUnit, rlThis, regThis);
901 loadValueDirectFixed(cUnit, rlCmp, regCmp);
buzbeeb046e162012-10-30 15:48:42 -0700902 int rTgt = (cUnit->instructionSet != kX86) ?
903 loadHelper(cUnit, ENTRYPOINT_OFFSET(pStringCompareTo)) : 0;
buzbee15bf9802012-06-12 17:49:27 -0700904 genNullCheck(cUnit, rlThis.sRegLow, regThis, info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700905 //TUNING: check if rlCmp.sRegLow is already null checked
buzbeecbd6d442012-11-17 14:11:25 -0800906 LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
907 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads, reinterpret_cast<uintptr_t>(launchPad));
Bill Buzbeea114add2012-05-03 15:00:40 -0700908 opCmpImmBranch(cUnit, kCondEq, regCmp, 0, launchPad);
buzbee8320f382012-09-11 16:29:42 -0700909 // NOTE: not a safepoint
buzbeeb046e162012-10-30 15:48:42 -0700910 if (cUnit->instructionSet != kX86) {
911 opReg(cUnit, kOpBlx, rTgt);
912 } else {
913 opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pStringCompareTo));
914 }
Elliott Hughes60234562012-06-01 12:25:59 -0700915 launchPad->operands[2] = 0; // No return possible
Bill Buzbeea114add2012-05-03 15:00:40 -0700916 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700917 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
918 RegLocation rlReturn = oatGetReturn(cUnit, false);
919 RegLocation rlDest = inlineTarget(cUnit, info);
920 storeValue(cUnit, rlDest, rlReturn);
Bill Buzbeea114add2012-05-03 15:00:40 -0700921 return true;
Ian Rogers0183dd72012-09-17 23:06:51 -0700922}
923
buzbee3b3dbdd2012-06-13 13:39:34 -0700924bool genIntrinsic(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700925{
Ian Rogerse13eafa2012-09-07 11:24:27 -0700926 if (info->optFlags & MIR_INLINED) {
buzbeefc9e6fa2012-03-23 15:14:29 -0700927 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -0700928 }
929 /*
930 * TODO: move these to a target-specific structured constant array
931 * and use a generic match function. The list of intrinsics may be
932 * slightly different depending on target.
933 * TODO: Fold this into a matching function that runs during
934 * basic block building. This should be part of the action for
935 * small method inlining and recognition of the special object init
936 * method. By doing this during basic block construction, we can also
937 * take advantage of/generate new useful dataflow info.
938 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700939 std::string tgtMethod(PrettyMethod(info->index, *cUnit->dex_file));
Ian Rogers0183dd72012-09-17 23:06:51 -0700940 if (tgtMethod.find(" java.lang") != std::string::npos) {
941 if (tgtMethod == "long java.lang.Double.doubleToRawLongBits(double)") {
942 return genInlinedDoubleCvt(cUnit, info);
943 }
944 if (tgtMethod == "double java.lang.Double.longBitsToDouble(long)") {
945 return genInlinedDoubleCvt(cUnit, info);
946 }
947 if (tgtMethod == "int java.lang.Float.floatToRawIntBits(float)") {
948 return genInlinedFloatCvt(cUnit, info);
949 }
950 if (tgtMethod == "float java.lang.Float.intBitsToFloat(int)") {
951 return genInlinedFloatCvt(cUnit, info);
952 }
953 if (tgtMethod == "int java.lang.Math.abs(int)" ||
954 tgtMethod == "int java.lang.StrictMath.abs(int)") {
955 return genInlinedAbsInt(cUnit, info);
956 }
957 if (tgtMethod == "long java.lang.Math.abs(long)" ||
958 tgtMethod == "long java.lang.StrictMath.abs(long)") {
959 return genInlinedAbsLong(cUnit, info);
960 }
961 if (tgtMethod == "int java.lang.Math.max(int, int)" ||
962 tgtMethod == "int java.lang.StrictMath.max(int, int)") {
963 return genInlinedMinMaxInt(cUnit, info, false /* isMin */);
964 }
965 if (tgtMethod == "int java.lang.Math.min(int, int)" ||
966 tgtMethod == "int java.lang.StrictMath.min(int, int)") {
967 return genInlinedMinMaxInt(cUnit, info, true /* isMin */);
968 }
969 if (tgtMethod == "double java.lang.Math.sqrt(double)" ||
970 tgtMethod == "double java.lang.StrictMath.sqrt(double)") {
971 return genInlinedSqrt(cUnit, info);
972 }
973 if (tgtMethod == "char java.lang.String.charAt(int)") {
974 return genInlinedCharAt(cUnit, info);
975 }
976 if (tgtMethod == "int java.lang.String.compareTo(java.lang.String)") {
977 return genInlinedStringCompareTo(cUnit, info);
978 }
979 if (tgtMethod == "boolean java.lang.String.isEmpty()") {
980 return genInlinedStringIsEmptyOrLength(cUnit, info, true /* isEmpty */);
981 }
982 if (tgtMethod == "int java.lang.String.indexOf(int, int)") {
983 return genInlinedIndexOf(cUnit, info, false /* base 0 */);
984 }
985 if (tgtMethod == "int java.lang.String.indexOf(int)") {
986 return genInlinedIndexOf(cUnit, info, true /* base 0 */);
987 }
988 if (tgtMethod == "int java.lang.String.length()") {
989 return genInlinedStringIsEmptyOrLength(cUnit, info, false /* isEmpty */);
990 }
991 } else if (tgtMethod.find("boolean sun.misc.Unsafe.compareAndSwap") != std::string::npos) {
992 if (tgtMethod == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
993 return genInlinedCas32(cUnit, info, false);
994 }
995 if (tgtMethod == "boolean sun.misc.Unsafe.compareAndSwapObject(java.lang.Object, long, java.lang.Object, java.lang.Object)") {
996 return genInlinedCas32(cUnit, info, true);
997 }
Ian Rogerse13eafa2012-09-07 11:24:27 -0700998 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700999 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -07001000}
1001
1002
buzbee31a4a6f2012-02-28 15:36:15 -08001003} // namespace art