blob: be8eee69c9fcb53853af4216b1b76fe31ebd8077 [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
2 * Copyright (C) 2009 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
17#include "Dalvik.h"
Dan Bornsteindf4daaf2010-12-01 14:23:44 -080018#include "libdex/DexOpcodes.h"
Ben Cheng00603072010-10-28 11:13:58 -070019#include "libdex/DexCatch.h"
Ben Chengba4fc8b2009-06-01 13:00:29 -070020#include "interp/Jit.h"
21#include "CompilerInternals.h"
Ben Cheng7a2697d2010-06-07 13:44:23 -070022#include "Dataflow.h"
Ben Chengba4fc8b2009-06-01 13:00:29 -070023
Ben Cheng00603072010-10-28 11:13:58 -070024static inline bool contentIsInsn(const u2 *codePtr) {
25 u2 instr = *codePtr;
26 Opcode opcode = instr & 0xff;
27
28 /*
29 * Since the low 8-bit in metadata may look like OP_NOP, we need to check
30 * both the low and whole sub-word to determine whether it is code or data.
31 */
32 return (opcode != OP_NOP || instr == 0);
33}
34
Ben Chengba4fc8b2009-06-01 13:00:29 -070035/*
36 * Parse an instruction, return the length of the instruction
37 */
38static inline int parseInsn(const u2 *codePtr, DecodedInstruction *decInsn,
39 bool printMe)
40{
Ben Cheng00603072010-10-28 11:13:58 -070041 // Don't parse instruction data
42 if (!contentIsInsn(codePtr)) {
43 return 0;
44 }
45
Ben Chengba4fc8b2009-06-01 13:00:29 -070046 u2 instr = *codePtr;
Dan Bornstein9a1f8162010-12-01 17:02:26 -080047 Opcode opcode = dexOpcodeFromCodeUnit(instr);
Ben Chengba4fc8b2009-06-01 13:00:29 -070048
Dan Bornstein54322392010-11-17 14:16:56 -080049 dexDecodeInstruction(codePtr, decInsn);
Ben Chengba4fc8b2009-06-01 13:00:29 -070050 if (printMe) {
Ben Cheng7a2697d2010-06-07 13:44:23 -070051 char *decodedString = dvmCompilerGetDalvikDisassembly(decInsn, NULL);
Ben Chengccd6c012009-10-15 14:52:45 -070052 LOGD("%p: %#06x %s\n", codePtr, opcode, decodedString);
Ben Chengba4fc8b2009-06-01 13:00:29 -070053 }
Ben Cheng00603072010-10-28 11:13:58 -070054 return dexGetWidthFromOpcode(opcode);
Ben Chengba4fc8b2009-06-01 13:00:29 -070055}
56
Ben Cheng9c147b82009-10-07 16:41:46 -070057#define UNKNOWN_TARGET 0xffffffff
58
Ben Chengba4fc8b2009-06-01 13:00:29 -070059/*
60 * Identify block-ending instructions and collect supplemental information
61 * regarding the following instructions.
62 */
63static inline bool findBlockBoundary(const Method *caller, MIR *insn,
64 unsigned int curOffset,
65 unsigned int *target, bool *isInvoke,
66 const Method **callee)
67{
Dan Bornstein9a1f8162010-12-01 17:02:26 -080068 switch (insn->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -070069 /* Target is not compile-time constant */
70 case OP_RETURN_VOID:
71 case OP_RETURN:
72 case OP_RETURN_WIDE:
73 case OP_RETURN_OBJECT:
74 case OP_THROW:
Ben Cheng9c147b82009-10-07 16:41:46 -070075 *target = UNKNOWN_TARGET;
76 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -070077 case OP_INVOKE_VIRTUAL:
78 case OP_INVOKE_VIRTUAL_RANGE:
jeffhao71eee1f2011-01-04 14:18:54 -080079 case OP_INVOKE_VIRTUAL_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -070080 case OP_INVOKE_INTERFACE:
81 case OP_INVOKE_INTERFACE_RANGE:
jeffhao71eee1f2011-01-04 14:18:54 -080082 case OP_INVOKE_INTERFACE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -070083 case OP_INVOKE_VIRTUAL_QUICK:
84 case OP_INVOKE_VIRTUAL_QUICK_RANGE:
85 *isInvoke = true;
86 break;
87 case OP_INVOKE_SUPER:
jeffhao71eee1f2011-01-04 14:18:54 -080088 case OP_INVOKE_SUPER_RANGE:
89 case OP_INVOKE_SUPER_JUMBO: {
Ben Chengba4fc8b2009-06-01 13:00:29 -070090 int mIndex = caller->clazz->pDvmDex->
91 pResMethods[insn->dalvikInsn.vB]->methodIndex;
92 const Method *calleeMethod =
93 caller->clazz->super->vtable[mIndex];
94
Ben Cheng8b258bf2009-06-24 17:27:07 -070095 if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -070096 *target = (unsigned int) calleeMethod->insns;
97 }
98 *isInvoke = true;
99 *callee = calleeMethod;
100 break;
101 }
102 case OP_INVOKE_STATIC:
jeffhao71eee1f2011-01-04 14:18:54 -0800103 case OP_INVOKE_STATIC_RANGE:
104 case OP_INVOKE_STATIC_JUMBO: {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700105 const Method *calleeMethod =
106 caller->clazz->pDvmDex->pResMethods[insn->dalvikInsn.vB];
107
Ben Cheng8b258bf2009-06-24 17:27:07 -0700108 if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700109 *target = (unsigned int) calleeMethod->insns;
110 }
111 *isInvoke = true;
112 *callee = calleeMethod;
113 break;
114 }
115 case OP_INVOKE_SUPER_QUICK:
116 case OP_INVOKE_SUPER_QUICK_RANGE: {
117 const Method *calleeMethod =
118 caller->clazz->super->vtable[insn->dalvikInsn.vB];
119
Ben Cheng8b258bf2009-06-24 17:27:07 -0700120 if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700121 *target = (unsigned int) calleeMethod->insns;
122 }
123 *isInvoke = true;
124 *callee = calleeMethod;
125 break;
126 }
127 case OP_INVOKE_DIRECT:
jeffhao71eee1f2011-01-04 14:18:54 -0800128 case OP_INVOKE_DIRECT_RANGE:
129 case OP_INVOKE_DIRECT_JUMBO: {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700130 const Method *calleeMethod =
131 caller->clazz->pDvmDex->pResMethods[insn->dalvikInsn.vB];
Ben Cheng8b258bf2009-06-24 17:27:07 -0700132 if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700133 *target = (unsigned int) calleeMethod->insns;
134 }
135 *isInvoke = true;
136 *callee = calleeMethod;
137 break;
138 }
139 case OP_GOTO:
140 case OP_GOTO_16:
141 case OP_GOTO_32:
142 *target = curOffset + (int) insn->dalvikInsn.vA;
143 break;
144
145 case OP_IF_EQ:
146 case OP_IF_NE:
147 case OP_IF_LT:
148 case OP_IF_GE:
149 case OP_IF_GT:
150 case OP_IF_LE:
151 *target = curOffset + (int) insn->dalvikInsn.vC;
152 break;
153
154 case OP_IF_EQZ:
155 case OP_IF_NEZ:
156 case OP_IF_LTZ:
157 case OP_IF_GEZ:
158 case OP_IF_GTZ:
159 case OP_IF_LEZ:
160 *target = curOffset + (int) insn->dalvikInsn.vB;
161 break;
162
163 default:
164 return false;
Ben Cheng9c147b82009-10-07 16:41:46 -0700165 }
166 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700167}
168
Bill Buzbee324b3ac2009-12-04 13:17:36 -0800169static inline bool isGoto(MIR *insn)
170{
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800171 switch (insn->dalvikInsn.opcode) {
Bill Buzbee324b3ac2009-12-04 13:17:36 -0800172 case OP_GOTO:
173 case OP_GOTO_16:
174 case OP_GOTO_32:
175 return true;
176 default:
177 return false;
178 }
179}
180
Ben Chengba4fc8b2009-06-01 13:00:29 -0700181/*
Bill Buzbee324b3ac2009-12-04 13:17:36 -0800182 * Identify unconditional branch instructions
Ben Chengba4fc8b2009-06-01 13:00:29 -0700183 */
184static inline bool isUnconditionalBranch(MIR *insn)
185{
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800186 switch (insn->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700187 case OP_RETURN_VOID:
188 case OP_RETURN:
189 case OP_RETURN_WIDE:
190 case OP_RETURN_OBJECT:
Ben Chengba4fc8b2009-06-01 13:00:29 -0700191 return true;
192 default:
Bill Buzbee324b3ac2009-12-04 13:17:36 -0800193 return isGoto(insn);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700194 }
195}
196
197/*
Ben Cheng8b258bf2009-06-24 17:27:07 -0700198 * dvmHashTableLookup() callback
199 */
200static int compareMethod(const CompilerMethodStats *m1,
201 const CompilerMethodStats *m2)
202{
203 return (int) m1->method - (int) m2->method;
204}
205
206/*
Ben Cheng7a2697d2010-06-07 13:44:23 -0700207 * Analyze the body of the method to collect high-level information regarding
208 * inlining:
209 * - is empty method?
210 * - is getter/setter?
211 * - can throw exception?
212 *
213 * Currently the inliner only handles getters and setters. When its capability
214 * becomes more sophisticated more information will be retrieved here.
215 */
216static int analyzeInlineTarget(DecodedInstruction *dalvikInsn, int attributes,
217 int offset)
218{
Dan Bornsteine4852762010-12-02 12:45:00 -0800219 int flags = dexGetFlagsFromOpcode(dalvikInsn->opcode);
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800220 int dalvikOpcode = dalvikInsn->opcode;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700221
Dan Bornstein0759f522010-11-30 14:58:53 -0800222 if (flags & kInstrInvoke) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700223 attributes &= ~METHOD_IS_LEAF;
224 }
225
226 if (!(flags & kInstrCanReturn)) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800227 if (!(dvmCompilerDataFlowAttributes[dalvikOpcode] &
Ben Cheng7a2697d2010-06-07 13:44:23 -0700228 DF_IS_GETTER)) {
229 attributes &= ~METHOD_IS_GETTER;
230 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800231 if (!(dvmCompilerDataFlowAttributes[dalvikOpcode] &
Ben Cheng7a2697d2010-06-07 13:44:23 -0700232 DF_IS_SETTER)) {
233 attributes &= ~METHOD_IS_SETTER;
234 }
235 }
236
237 /*
238 * The expected instruction sequence is setter will never return value and
239 * getter will also do. Clear the bits if the behavior is discovered
240 * otherwise.
241 */
242 if (flags & kInstrCanReturn) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800243 if (dalvikOpcode == OP_RETURN_VOID) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700244 attributes &= ~METHOD_IS_GETTER;
245 }
246 else {
247 attributes &= ~METHOD_IS_SETTER;
248 }
249 }
250
251 if (flags & kInstrCanThrow) {
252 attributes &= ~METHOD_IS_THROW_FREE;
253 }
254
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800255 if (offset == 0 && dalvikOpcode == OP_RETURN_VOID) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700256 attributes |= METHOD_IS_EMPTY;
257 }
258
Ben Cheng34dc7962010-08-26 14:56:31 -0700259 /*
260 * Check if this opcode is selected for single stepping.
261 * If so, don't inline the callee as there is no stack frame for the
262 * interpreter to single-step through the instruction.
263 */
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800264 if (SINGLE_STEP_OP(dalvikOpcode)) {
Ben Cheng34dc7962010-08-26 14:56:31 -0700265 attributes &= ~(METHOD_IS_GETTER | METHOD_IS_SETTER);
266 }
267
Ben Cheng7a2697d2010-06-07 13:44:23 -0700268 return attributes;
269}
270
271/*
Ben Cheng8b258bf2009-06-24 17:27:07 -0700272 * Analyze each method whose traces are ever compiled. Collect a variety of
273 * statistics like the ratio of exercised vs overall code and code bloat
Ben Cheng7a2697d2010-06-07 13:44:23 -0700274 * ratios. If isCallee is true, also analyze each instruction in more details
275 * to see if it is suitable for inlining.
Ben Cheng8b258bf2009-06-24 17:27:07 -0700276 */
Ben Cheng7a2697d2010-06-07 13:44:23 -0700277CompilerMethodStats *dvmCompilerAnalyzeMethodBody(const Method *method,
278 bool isCallee)
Ben Cheng8b258bf2009-06-24 17:27:07 -0700279{
280 const DexCode *dexCode = dvmGetMethodCode(method);
281 const u2 *codePtr = dexCode->insns;
282 const u2 *codeEnd = dexCode->insns + dexCode->insnsSize;
283 int insnSize = 0;
284 int hashValue = dvmComputeUtf8Hash(method->name);
285
286 CompilerMethodStats dummyMethodEntry; // For hash table lookup
287 CompilerMethodStats *realMethodEntry; // For hash table storage
288
289 /* For lookup only */
290 dummyMethodEntry.method = method;
Ben Chengcfdeca32011-01-14 11:36:46 -0800291 realMethodEntry = (CompilerMethodStats *)
292 dvmHashTableLookup(gDvmJit.methodStatsTable,
293 hashValue,
294 &dummyMethodEntry,
295 (HashCompareFunc) compareMethod,
296 false);
Ben Cheng8b258bf2009-06-24 17:27:07 -0700297
Ben Cheng7a2697d2010-06-07 13:44:23 -0700298 /* This method has never been analyzed before - create an entry */
299 if (realMethodEntry == NULL) {
300 realMethodEntry =
301 (CompilerMethodStats *) calloc(1, sizeof(CompilerMethodStats));
302 realMethodEntry->method = method;
303
304 dvmHashTableLookup(gDvmJit.methodStatsTable, hashValue,
305 realMethodEntry,
306 (HashCompareFunc) compareMethod,
307 true);
Ben Cheng8b258bf2009-06-24 17:27:07 -0700308 }
309
Ben Cheng7a2697d2010-06-07 13:44:23 -0700310 /* This method is invoked as a callee and has been analyzed - just return */
311 if ((isCallee == true) && (realMethodEntry->attributes & METHOD_IS_CALLEE))
312 return realMethodEntry;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700313
Ben Cheng7a2697d2010-06-07 13:44:23 -0700314 /*
315 * Similarly, return if this method has been compiled before as a hot
316 * method already.
317 */
318 if ((isCallee == false) &&
319 (realMethodEntry->attributes & METHOD_IS_HOT))
320 return realMethodEntry;
321
322 int attributes;
323
324 /* Method hasn't been analyzed for the desired purpose yet */
325 if (isCallee) {
326 /* Aggressively set the attributes until proven otherwise */
327 attributes = METHOD_IS_LEAF | METHOD_IS_THROW_FREE | METHOD_IS_CALLEE |
328 METHOD_IS_GETTER | METHOD_IS_SETTER;
329 } else {
330 attributes = METHOD_IS_HOT;
331 }
Ben Cheng8b258bf2009-06-24 17:27:07 -0700332
333 /* Count the number of instructions */
334 while (codePtr < codeEnd) {
335 DecodedInstruction dalvikInsn;
336 int width = parseInsn(codePtr, &dalvikInsn, false);
337
338 /* Terminate when the data section is seen */
339 if (width == 0)
340 break;
341
Ben Cheng7a2697d2010-06-07 13:44:23 -0700342 if (isCallee) {
343 attributes = analyzeInlineTarget(&dalvikInsn, attributes, insnSize);
344 }
345
Ben Cheng8b258bf2009-06-24 17:27:07 -0700346 insnSize += width;
347 codePtr += width;
348 }
349
Ben Cheng7a2697d2010-06-07 13:44:23 -0700350 /*
351 * Only handle simple getters/setters with one instruction followed by
352 * return
353 */
354 if ((attributes & (METHOD_IS_GETTER | METHOD_IS_SETTER)) &&
355 (insnSize != 3)) {
356 attributes &= ~(METHOD_IS_GETTER | METHOD_IS_SETTER);
357 }
358
Ben Cheng8b258bf2009-06-24 17:27:07 -0700359 realMethodEntry->dalvikSize = insnSize * 2;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700360 realMethodEntry->attributes |= attributes;
361
362#if 0
363 /* Uncomment the following to explore various callee patterns */
364 if (attributes & METHOD_IS_THROW_FREE) {
365 LOGE("%s%s is inlinable%s", method->clazz->descriptor, method->name,
366 (attributes & METHOD_IS_EMPTY) ? " empty" : "");
367 }
368
369 if (attributes & METHOD_IS_LEAF) {
370 LOGE("%s%s is leaf %d%s", method->clazz->descriptor, method->name,
371 insnSize, insnSize < 5 ? " (small)" : "");
372 }
373
374 if (attributes & (METHOD_IS_GETTER | METHOD_IS_SETTER)) {
375 LOGE("%s%s is %s", method->clazz->descriptor, method->name,
376 attributes & METHOD_IS_GETTER ? "getter": "setter");
377 }
378 if (attributes ==
379 (METHOD_IS_LEAF | METHOD_IS_THROW_FREE | METHOD_IS_CALLEE)) {
380 LOGE("%s%s is inlinable non setter/getter", method->clazz->descriptor,
381 method->name);
382 }
383#endif
384
Ben Cheng8b258bf2009-06-24 17:27:07 -0700385 return realMethodEntry;
386}
387
388/*
Ben Cheng33672452010-01-12 14:59:30 -0800389 * Crawl the stack of the thread that requesed compilation to see if any of the
390 * ancestors are on the blacklist.
391 */
Andy McFadden953a0ed2010-09-17 15:48:38 -0700392static bool filterMethodByCallGraph(Thread *thread, const char *curMethodName)
Ben Cheng33672452010-01-12 14:59:30 -0800393{
394 /* Crawl the Dalvik stack frames and compare the method name*/
395 StackSaveArea *ssaPtr = ((StackSaveArea *) thread->curFrame) - 1;
396 while (ssaPtr != ((StackSaveArea *) NULL) - 1) {
397 const Method *method = ssaPtr->method;
398 if (method) {
399 int hashValue = dvmComputeUtf8Hash(method->name);
400 bool found =
401 dvmHashTableLookup(gDvmJit.methodTable, hashValue,
402 (char *) method->name,
403 (HashCompareFunc) strcmp, false) !=
404 NULL;
405 if (found) {
406 LOGD("Method %s (--> %s) found on the JIT %s list",
407 method->name, curMethodName,
408 gDvmJit.includeSelectedMethod ? "white" : "black");
409 return true;
410 }
411
412 }
413 ssaPtr = ((StackSaveArea *) ssaPtr->prevFrame) - 1;
414 };
415 return false;
416}
417
418/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700419 * Main entry point to start trace compilation. Basic blocks are constructed
420 * first and they will be passed to the codegen routines to convert Dalvik
421 * bytecode into machine code.
422 */
Bill Buzbee716f1202009-07-23 13:22:09 -0700423bool dvmCompileTrace(JitTraceDescription *desc, int numMaxInsts,
Ben Cheng4a419582010-08-04 13:23:09 -0700424 JitTranslationInfo *info, jmp_buf *bailPtr,
425 int optHints)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700426{
427 const DexCode *dexCode = dvmGetMethodCode(desc->method);
428 const JitTraceRun* currRun = &desc->trace[0];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700429 unsigned int curOffset = currRun->frag.startOffset;
430 unsigned int numInsts = currRun->frag.numInsts;
431 const u2 *codePtr = dexCode->insns + curOffset;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700432 int traceSize = 0; // # of half-words
Ben Chengba4fc8b2009-06-01 13:00:29 -0700433 const u2 *startCodePtr = codePtr;
Ben Cheng00603072010-10-28 11:13:58 -0700434 BasicBlock *curBB, *entryCodeBB;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700435 int numBlocks = 0;
436 static int compilationId;
437 CompilationUnit cUnit;
Ben Cheng00603072010-10-28 11:13:58 -0700438 GrowableList *blockList;
Ben Cheng1357e942010-02-10 17:21:39 -0800439#if defined(WITH_JIT_TUNING)
Ben Cheng8b258bf2009-06-24 17:27:07 -0700440 CompilerMethodStats *methodStats;
Ben Cheng1357e942010-02-10 17:21:39 -0800441#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -0700442
Bill Buzbee964a7b02010-01-28 12:54:19 -0800443 /* If we've already compiled this trace, just return success */
Ben Chengcfdeca32011-01-14 11:36:46 -0800444 if (dvmJitGetTraceAddr(startCodePtr) && !info->discardResult) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700445 /*
446 * Make sure the codeAddress is NULL so that it won't clobber the
447 * existing entry.
448 */
449 info->codeAddress = NULL;
Bill Buzbee964a7b02010-01-28 12:54:19 -0800450 return true;
451 }
452
buzbee18fba342011-01-19 15:31:15 -0800453 /* If the work order is stale, discard it */
454 if (info->cacheVersion != gDvmJit.cacheVersion) {
455 return false;
456 }
457
Ben Chenge9695e52009-06-16 16:11:47 -0700458 compilationId++;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700459 memset(&cUnit, 0, sizeof(CompilationUnit));
460
Ben Cheng1357e942010-02-10 17:21:39 -0800461#if defined(WITH_JIT_TUNING)
Ben Cheng8b258bf2009-06-24 17:27:07 -0700462 /* Locate the entry to store compilation statistics for this method */
Ben Cheng7a2697d2010-06-07 13:44:23 -0700463 methodStats = dvmCompilerAnalyzeMethodBody(desc->method, false);
Ben Cheng1357e942010-02-10 17:21:39 -0800464#endif
Ben Chenge9695e52009-06-16 16:11:47 -0700465
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800466 /* Set the recover buffer pointer */
467 cUnit.bailPtr = bailPtr;
468
Ben Chengba4fc8b2009-06-01 13:00:29 -0700469 /* Initialize the printMe flag */
470 cUnit.printMe = gDvmJit.printMe;
471
Ben Cheng7a2697d2010-06-07 13:44:23 -0700472 /* Setup the method */
473 cUnit.method = desc->method;
474
475 /* Initialize the PC reconstruction list */
476 dvmInitGrowableList(&cUnit.pcReconstructionList, 8);
477
Ben Cheng00603072010-10-28 11:13:58 -0700478 /* Initialize the basic block list */
479 blockList = &cUnit.blockList;
480 dvmInitGrowableList(blockList, 8);
481
Ben Chengba4fc8b2009-06-01 13:00:29 -0700482 /* Identify traces that we don't want to compile */
483 if (gDvmJit.methodTable) {
484 int len = strlen(desc->method->clazz->descriptor) +
485 strlen(desc->method->name) + 1;
Carl Shapirofc75f3e2010-12-07 11:43:38 -0800486 char *fullSignature = (char *)dvmCompilerNew(len, true);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700487 strcpy(fullSignature, desc->method->clazz->descriptor);
488 strcat(fullSignature, desc->method->name);
489
490 int hashValue = dvmComputeUtf8Hash(fullSignature);
491
492 /*
493 * Doing three levels of screening to see whether we want to skip
494 * compiling this method
495 */
496
497 /* First, check the full "class;method" signature */
498 bool methodFound =
499 dvmHashTableLookup(gDvmJit.methodTable, hashValue,
500 fullSignature, (HashCompareFunc) strcmp,
501 false) !=
502 NULL;
503
504 /* Full signature not found - check the enclosing class */
505 if (methodFound == false) {
506 int hashValue = dvmComputeUtf8Hash(desc->method->clazz->descriptor);
507 methodFound =
508 dvmHashTableLookup(gDvmJit.methodTable, hashValue,
509 (char *) desc->method->clazz->descriptor,
510 (HashCompareFunc) strcmp, false) !=
511 NULL;
512 /* Enclosing class not found - check the method name */
513 if (methodFound == false) {
514 int hashValue = dvmComputeUtf8Hash(desc->method->name);
515 methodFound =
516 dvmHashTableLookup(gDvmJit.methodTable, hashValue,
517 (char *) desc->method->name,
518 (HashCompareFunc) strcmp, false) !=
519 NULL;
Ben Cheng33672452010-01-12 14:59:30 -0800520
521 /*
522 * Debug by call-graph is enabled. Check if the debug list
523 * covers any methods on the VM stack.
524 */
525 if (methodFound == false && gDvmJit.checkCallGraph == true) {
526 methodFound =
527 filterMethodByCallGraph(info->requestingThread,
528 desc->method->name);
529 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700530 }
531 }
532
533 /*
534 * Under the following conditions, the trace will be *conservatively*
535 * compiled by only containing single-step instructions to and from the
536 * interpreter.
537 * 1) If includeSelectedMethod == false, the method matches the full or
538 * partial signature stored in the hash table.
539 *
540 * 2) If includeSelectedMethod == true, the method does not match the
541 * full and partial signature stored in the hash table.
542 */
543 if (gDvmJit.includeSelectedMethod != methodFound) {
544 cUnit.allSingleStep = true;
545 } else {
546 /* Compile the trace as normal */
547
548 /* Print the method we cherry picked */
549 if (gDvmJit.includeSelectedMethod == true) {
550 cUnit.printMe = true;
551 }
552 }
553 }
554
Ben Cheng4238ec22009-08-24 16:32:22 -0700555 /* Allocate the entry block */
Ben Cheng00603072010-10-28 11:13:58 -0700556 curBB = dvmCompilerNewBB(kTraceEntryBlock, numBlocks++);
557 dvmInsertGrowableList(blockList, (intptr_t) curBB);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700558 curBB->startOffset = curOffset;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700559
Ben Cheng00603072010-10-28 11:13:58 -0700560 entryCodeBB = dvmCompilerNewBB(kDalvikByteCode, numBlocks++);
561 dvmInsertGrowableList(blockList, (intptr_t) entryCodeBB);
562 entryCodeBB->startOffset = curOffset;
563 curBB->fallThrough = entryCodeBB;
564 curBB = entryCodeBB;
Ben Cheng4238ec22009-08-24 16:32:22 -0700565
Ben Chengba4fc8b2009-06-01 13:00:29 -0700566 if (cUnit.printMe) {
567 LOGD("--------\nCompiler: Building trace for %s, offset 0x%x\n",
568 desc->method->name, curOffset);
569 }
570
Ben Cheng1efc9c52009-06-08 18:25:27 -0700571 /*
572 * Analyze the trace descriptor and include up to the maximal number
573 * of Dalvik instructions into the IR.
574 */
575 while (1) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700576 MIR *insn;
577 int width;
Carl Shapirofc75f3e2010-12-07 11:43:38 -0800578 insn = (MIR *)dvmCompilerNew(sizeof(MIR), true);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700579 insn->offset = curOffset;
580 width = parseInsn(codePtr, &insn->dalvikInsn, cUnit.printMe);
Ben Cheng8b258bf2009-06-24 17:27:07 -0700581
582 /* The trace should never incude instruction data */
583 assert(width);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700584 insn->width = width;
585 traceSize += width;
586 dvmCompilerAppendMIR(curBB, insn);
Ben Cheng1efc9c52009-06-08 18:25:27 -0700587 cUnit.numInsts++;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700588
Dan Bornsteine4852762010-12-02 12:45:00 -0800589 int flags = dexGetFlagsFromOpcode(insn->dalvikInsn.opcode);
Ben Cheng7a2697d2010-06-07 13:44:23 -0700590
Dan Bornstein0759f522010-11-30 14:58:53 -0800591 if (flags & kInstrInvoke) {
Ben Chengcfdeca32011-01-14 11:36:46 -0800592 const Method *calleeMethod = (const Method *) currRun[2].meta;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700593 assert(numInsts == 1);
594 CallsiteInfo *callsiteInfo =
Carl Shapirofc75f3e2010-12-07 11:43:38 -0800595 (CallsiteInfo *)dvmCompilerNew(sizeof(CallsiteInfo), true);
596 callsiteInfo->clazz = (ClassObject *)currRun[1].meta;
Ben Chengcfdeca32011-01-14 11:36:46 -0800597 callsiteInfo->method = calleeMethod;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700598 insn->meta.callsiteInfo = callsiteInfo;
599 }
600
Ben Cheng1efc9c52009-06-08 18:25:27 -0700601 /* Instruction limit reached - terminate the trace here */
602 if (cUnit.numInsts >= numMaxInsts) {
603 break;
604 }
605 if (--numInsts == 0) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700606 if (currRun->frag.runEnd) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700607 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700608 } else {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700609 /* Advance to the next trace description (ie non-meta info) */
610 do {
611 currRun++;
612 } while (!currRun->frag.isCode);
613
614 /* Dummy end-of-run marker seen */
615 if (currRun->frag.numInsts == 0) {
616 break;
617 }
618
Ben Cheng00603072010-10-28 11:13:58 -0700619 curBB = dvmCompilerNewBB(kDalvikByteCode, numBlocks++);
620 dvmInsertGrowableList(blockList, (intptr_t) curBB);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700621 curOffset = currRun->frag.startOffset;
622 numInsts = currRun->frag.numInsts;
623 curBB->startOffset = curOffset;
624 codePtr = dexCode->insns + curOffset;
625 }
626 } else {
627 curOffset += width;
628 codePtr += width;
629 }
630 }
631
Ben Cheng1357e942010-02-10 17:21:39 -0800632#if defined(WITH_JIT_TUNING)
Ben Cheng8b258bf2009-06-24 17:27:07 -0700633 /* Convert # of half-word to bytes */
634 methodStats->compiledDalvikSize += traceSize * 2;
Ben Cheng1357e942010-02-10 17:21:39 -0800635#endif
Ben Cheng8b258bf2009-06-24 17:27:07 -0700636
Ben Chengba4fc8b2009-06-01 13:00:29 -0700637 /*
638 * Now scan basic blocks containing real code to connect the
639 * taken/fallthrough links. Also create chaining cells for code not included
640 * in the trace.
641 */
Ben Cheng00603072010-10-28 11:13:58 -0700642 size_t blockId;
643 for (blockId = 0; blockId < blockList->numUsed; blockId++) {
644 curBB = (BasicBlock *) dvmGrowableListGetElement(blockList, blockId);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700645 MIR *lastInsn = curBB->lastMIRInsn;
buzbee2e152ba2010-12-15 16:32:35 -0800646 BasicBlock *backwardCell;
Ben Cheng4238ec22009-08-24 16:32:22 -0700647 /* Skip empty blocks */
Ben Chengba4fc8b2009-06-01 13:00:29 -0700648 if (lastInsn == NULL) {
Ben Cheng4238ec22009-08-24 16:32:22 -0700649 continue;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700650 }
651 curOffset = lastInsn->offset;
652 unsigned int targetOffset = curOffset;
653 unsigned int fallThroughOffset = curOffset + lastInsn->width;
654 bool isInvoke = false;
655 const Method *callee = NULL;
656
657 findBlockBoundary(desc->method, curBB->lastMIRInsn, curOffset,
658 &targetOffset, &isInvoke, &callee);
659
660 /* Link the taken and fallthrough blocks */
661 BasicBlock *searchBB;
662
Dan Bornsteine4852762010-12-02 12:45:00 -0800663 int flags = dexGetFlagsFromOpcode(lastInsn->dalvikInsn.opcode);
Ben Cheng7a2697d2010-06-07 13:44:23 -0700664
665 if (flags & kInstrInvoke) {
666 cUnit.hasInvoke = true;
667 }
668
Ben Chengba4fc8b2009-06-01 13:00:29 -0700669 /* No backward branch in the trace - start searching the next BB */
Ben Cheng00603072010-10-28 11:13:58 -0700670 size_t searchBlockId;
671 for (searchBlockId = blockId+1; searchBlockId < blockList->numUsed;
672 searchBlockId++) {
673 searchBB = (BasicBlock *) dvmGrowableListGetElement(blockList,
674 searchBlockId);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700675 if (targetOffset == searchBB->startOffset) {
676 curBB->taken = searchBB;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800677 dvmCompilerSetBit(searchBB->predecessors, curBB->id);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700678 }
679 if (fallThroughOffset == searchBB->startOffset) {
680 curBB->fallThrough = searchBB;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800681 dvmCompilerSetBit(searchBB->predecessors, curBB->id);
Ben Cheng7a2697d2010-06-07 13:44:23 -0700682
683 /*
684 * Fallthrough block of an invoke instruction needs to be
685 * aligned to 4-byte boundary (alignment instruction to be
686 * inserted later.
687 */
688 if (flags & kInstrInvoke) {
689 searchBB->isFallThroughFromInvoke = true;
690 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700691 }
692 }
693
Ben Cheng1efc9c52009-06-08 18:25:27 -0700694 /*
695 * Some blocks are ended by non-control-flow-change instructions,
696 * currently only due to trace length constraint. In this case we need
697 * to generate an explicit branch at the end of the block to jump to
698 * the chaining cell.
699 */
700 curBB->needFallThroughBranch =
Ben Cheng17f15ce2009-07-27 16:21:52 -0700701 ((flags & (kInstrCanBranch | kInstrCanSwitch | kInstrCanReturn |
Dan Bornstein0759f522010-11-30 14:58:53 -0800702 kInstrInvoke)) == 0);
Ben Cheng17f15ce2009-07-27 16:21:52 -0700703
Ben Cheng4a419582010-08-04 13:23:09 -0700704 /* Only form a loop if JIT_OPT_NO_LOOP is not set */
Ben Cheng4238ec22009-08-24 16:32:22 -0700705 if (curBB->taken == NULL &&
706 curBB->fallThrough == NULL &&
707 flags == (kInstrCanBranch | kInstrCanContinue) &&
Ben Cheng00603072010-10-28 11:13:58 -0700708 fallThroughOffset == entryCodeBB->startOffset &&
Ben Cheng4a419582010-08-04 13:23:09 -0700709 JIT_OPT_NO_LOOP != (optHints & JIT_OPT_NO_LOOP)) {
Ben Cheng0fd31e42009-09-03 14:40:16 -0700710 BasicBlock *loopBranch = curBB;
711 BasicBlock *exitBB;
712 BasicBlock *exitChainingCell;
Ben Cheng4238ec22009-08-24 16:32:22 -0700713
714 if (cUnit.printMe) {
715 LOGD("Natural loop detected!");
716 }
Ben Cheng00603072010-10-28 11:13:58 -0700717 exitBB = dvmCompilerNewBB(kTraceExitBlock, numBlocks++);
718 dvmInsertGrowableList(blockList, (intptr_t) exitBB);
Ben Cheng0fd31e42009-09-03 14:40:16 -0700719 exitBB->startOffset = targetOffset;
Ben Cheng0fd31e42009-09-03 14:40:16 -0700720 exitBB->needFallThroughBranch = true;
Ben Cheng4238ec22009-08-24 16:32:22 -0700721
Ben Cheng0fd31e42009-09-03 14:40:16 -0700722 loopBranch->taken = exitBB;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800723 dvmCompilerSetBit(exitBB->predecessors, loopBranch->id);
buzbee2e152ba2010-12-15 16:32:35 -0800724 backwardCell =
Ben Cheng00603072010-10-28 11:13:58 -0700725 dvmCompilerNewBB(kChainingCellBackwardBranch, numBlocks++);
726 dvmInsertGrowableList(blockList, (intptr_t) backwardCell);
727 backwardCell->startOffset = entryCodeBB->startOffset;
Ben Cheng0fd31e42009-09-03 14:40:16 -0700728 loopBranch->fallThrough = backwardCell;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800729 dvmCompilerSetBit(backwardCell->predecessors, loopBranch->id);
Ben Cheng0fd31e42009-09-03 14:40:16 -0700730
731 /* Create the chaining cell as the fallthrough of the exit block */
Ben Cheng00603072010-10-28 11:13:58 -0700732 exitChainingCell = dvmCompilerNewBB(kChainingCellNormal,
733 numBlocks++);
734 dvmInsertGrowableList(blockList, (intptr_t) exitChainingCell);
Ben Cheng0fd31e42009-09-03 14:40:16 -0700735 exitChainingCell->startOffset = targetOffset;
Ben Cheng0fd31e42009-09-03 14:40:16 -0700736
737 exitBB->fallThrough = exitChainingCell;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800738 dvmCompilerSetBit(exitChainingCell->predecessors, exitBB->id);
Ben Cheng0fd31e42009-09-03 14:40:16 -0700739
Ben Cheng4238ec22009-08-24 16:32:22 -0700740 cUnit.hasLoop = true;
741 }
742
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800743 if (lastInsn->dalvikInsn.opcode == OP_PACKED_SWITCH ||
744 lastInsn->dalvikInsn.opcode == OP_SPARSE_SWITCH) {
Ben Cheng6c10a972009-10-29 14:39:18 -0700745 int i;
746 const u2 *switchData = desc->method->insns + lastInsn->offset +
747 lastInsn->dalvikInsn.vB;
748 int size = switchData[1];
749 int maxChains = MIN(size, MAX_CHAINED_SWITCH_CASES);
750
751 /*
752 * Generate the landing pad for cases whose ranks are higher than
753 * MAX_CHAINED_SWITCH_CASES. The code will re-enter the interpreter
754 * through the NoChain point.
755 */
756 if (maxChains != size) {
757 cUnit.switchOverflowPad =
758 desc->method->insns + lastInsn->offset;
759 }
760
761 s4 *targets = (s4 *) (switchData + 2 +
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800762 (lastInsn->dalvikInsn.opcode == OP_PACKED_SWITCH ?
Ben Cheng6c10a972009-10-29 14:39:18 -0700763 2 : size * 2));
764
765 /* One chaining cell for the first MAX_CHAINED_SWITCH_CASES cases */
766 for (i = 0; i < maxChains; i++) {
Ben Cheng00603072010-10-28 11:13:58 -0700767 BasicBlock *caseChain = dvmCompilerNewBB(kChainingCellNormal,
768 numBlocks++);
769 dvmInsertGrowableList(blockList, (intptr_t) caseChain);
Ben Cheng6c10a972009-10-29 14:39:18 -0700770 caseChain->startOffset = lastInsn->offset + targets[i];
Ben Cheng6c10a972009-10-29 14:39:18 -0700771 }
772
773 /* One more chaining cell for the default case */
Ben Cheng00603072010-10-28 11:13:58 -0700774 BasicBlock *caseChain = dvmCompilerNewBB(kChainingCellNormal,
775 numBlocks++);
776 dvmInsertGrowableList(blockList, (intptr_t) caseChain);
Ben Cheng6c10a972009-10-29 14:39:18 -0700777 caseChain->startOffset = lastInsn->offset + lastInsn->width;
Ben Cheng6d576092009-09-01 17:01:58 -0700778 /* Fallthrough block not included in the trace */
Ben Cheng6c10a972009-10-29 14:39:18 -0700779 } else if (!isUnconditionalBranch(lastInsn) &&
780 curBB->fallThrough == NULL) {
Ben Cheng00603072010-10-28 11:13:58 -0700781 BasicBlock *fallThroughBB;
Ben Cheng6d576092009-09-01 17:01:58 -0700782 /*
783 * If the chaining cell is after an invoke or
784 * instruction that cannot change the control flow, request a hot
785 * chaining cell.
786 */
787 if (isInvoke || curBB->needFallThroughBranch) {
Ben Cheng00603072010-10-28 11:13:58 -0700788 fallThroughBB = dvmCompilerNewBB(kChainingCellHot, numBlocks++);
Ben Cheng6d576092009-09-01 17:01:58 -0700789 } else {
Ben Cheng00603072010-10-28 11:13:58 -0700790 fallThroughBB = dvmCompilerNewBB(kChainingCellNormal,
791 numBlocks++);
Ben Cheng6d576092009-09-01 17:01:58 -0700792 }
Ben Cheng00603072010-10-28 11:13:58 -0700793 dvmInsertGrowableList(blockList, (intptr_t) fallThroughBB);
794 fallThroughBB->startOffset = fallThroughOffset;
795 curBB->fallThrough = fallThroughBB;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800796 dvmCompilerSetBit(fallThroughBB->predecessors, curBB->id);
Ben Cheng6d576092009-09-01 17:01:58 -0700797 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700798 /* Target block not included in the trace */
Ben Cheng38329f52009-07-07 14:19:20 -0700799 if (curBB->taken == NULL &&
Bill Buzbee324b3ac2009-12-04 13:17:36 -0800800 (isGoto(lastInsn) || isInvoke ||
801 (targetOffset != UNKNOWN_TARGET && targetOffset != curOffset))) {
Ben Cheng7e2c3c72010-12-22 16:40:46 -0800802 BasicBlock *newBB = NULL;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700803 if (isInvoke) {
Ben Cheng38329f52009-07-07 14:19:20 -0700804 /* Monomorphic callee */
805 if (callee) {
Ben Cheng7e2c3c72010-12-22 16:40:46 -0800806 /* JNI call doesn't need a chaining cell */
807 if (!dvmIsNativeMethod(callee)) {
808 newBB = dvmCompilerNewBB(kChainingCellInvokeSingleton,
809 numBlocks++);
810 newBB->startOffset = 0;
811 newBB->containingMethod = callee;
812 }
Ben Cheng38329f52009-07-07 14:19:20 -0700813 /* Will resolve at runtime */
814 } else {
Ben Cheng00603072010-10-28 11:13:58 -0700815 newBB = dvmCompilerNewBB(kChainingCellInvokePredicted,
816 numBlocks++);
Ben Cheng38329f52009-07-07 14:19:20 -0700817 newBB->startOffset = 0;
818 }
Ben Cheng1efc9c52009-06-08 18:25:27 -0700819 /* For unconditional branches, request a hot chaining cell */
820 } else {
Jeff Hao97319a82009-08-12 16:57:15 -0700821#if !defined(WITH_SELF_VERIFICATION)
Dan Bornsteinc2b486f2010-11-12 16:07:16 -0800822 newBB = dvmCompilerNewBB(dexIsGoto(flags) ?
Bill Buzbee1465db52009-09-23 17:17:35 -0700823 kChainingCellHot :
Ben Cheng00603072010-10-28 11:13:58 -0700824 kChainingCellNormal,
825 numBlocks++);
Ben Cheng38329f52009-07-07 14:19:20 -0700826 newBB->startOffset = targetOffset;
Jeff Hao97319a82009-08-12 16:57:15 -0700827#else
828 /* Handle branches that branch back into the block */
829 if (targetOffset >= curBB->firstMIRInsn->offset &&
830 targetOffset <= curBB->lastMIRInsn->offset) {
Ben Cheng00603072010-10-28 11:13:58 -0700831 newBB = dvmCompilerNewBB(kChainingCellBackwardBranch,
832 numBlocks++);
Jeff Hao97319a82009-08-12 16:57:15 -0700833 } else {
Dan Bornsteinc2b486f2010-11-12 16:07:16 -0800834 newBB = dvmCompilerNewBB(dexIsGoto(flags) ?
Bill Buzbee1465db52009-09-23 17:17:35 -0700835 kChainingCellHot :
Ben Cheng00603072010-10-28 11:13:58 -0700836 kChainingCellNormal,
837 numBlocks++);
Jeff Hao97319a82009-08-12 16:57:15 -0700838 }
839 newBB->startOffset = targetOffset;
840#endif
Ben Cheng1efc9c52009-06-08 18:25:27 -0700841 }
Ben Cheng7e2c3c72010-12-22 16:40:46 -0800842 if (newBB) {
843 curBB->taken = newBB;
Ben Cheng7ab74e12011-02-03 14:02:06 -0800844 dvmCompilerSetBit(newBB->predecessors, curBB->id);
Ben Cheng7e2c3c72010-12-22 16:40:46 -0800845 dvmInsertGrowableList(blockList, (intptr_t) newBB);
846 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700847 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700848 }
849
850 /* Now create a special block to host PC reconstruction code */
Ben Cheng00603072010-10-28 11:13:58 -0700851 curBB = dvmCompilerNewBB(kPCReconstruction, numBlocks++);
852 dvmInsertGrowableList(blockList, (intptr_t) curBB);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700853
854 /* And one final block that publishes the PC and raise the exception */
Ben Cheng00603072010-10-28 11:13:58 -0700855 curBB = dvmCompilerNewBB(kExceptionHandling, numBlocks++);
856 dvmInsertGrowableList(blockList, (intptr_t) curBB);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700857
858 if (cUnit.printMe) {
Ben Cheng00603072010-10-28 11:13:58 -0700859 char* signature =
860 dexProtoCopyMethodDescriptor(&desc->method->prototype);
Elliott Hughescc6fac82010-07-02 13:38:44 -0700861 LOGD("TRACEINFO (%d): 0x%08x %s%s.%s 0x%x %d of %d, %d blocks",
Ben Chenge9695e52009-06-16 16:11:47 -0700862 compilationId,
Ben Chengba4fc8b2009-06-01 13:00:29 -0700863 (intptr_t) desc->method->insns,
864 desc->method->clazz->descriptor,
865 desc->method->name,
Elliott Hughescc6fac82010-07-02 13:38:44 -0700866 signature,
Ben Chengba4fc8b2009-06-01 13:00:29 -0700867 desc->trace[0].frag.startOffset,
868 traceSize,
869 dexCode->insnsSize,
870 numBlocks);
Elliott Hughescc6fac82010-07-02 13:38:44 -0700871 free(signature);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700872 }
873
Ben Chengba4fc8b2009-06-01 13:00:29 -0700874 cUnit.traceDesc = desc;
875 cUnit.numBlocks = numBlocks;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700876
Ben Cheng7a2697d2010-06-07 13:44:23 -0700877 /* Set the instruction set to use (NOTE: later components may change it) */
878 cUnit.instructionSet = dvmCompilerInstructionSet();
879
880 /* Inline transformation @ the MIR level */
881 if (cUnit.hasInvoke && !(gDvmJit.disableOpt & (1 << kMethodInlining))) {
Ben Chengcfdeca32011-01-14 11:36:46 -0800882 dvmCompilerInlineMIR(&cUnit, info);
Ben Cheng7a2697d2010-06-07 13:44:23 -0700883 }
884
Ben Cheng00603072010-10-28 11:13:58 -0700885 cUnit.numDalvikRegisters = cUnit.method->registersSize;
886
Ben Cheng4238ec22009-08-24 16:32:22 -0700887 /* Preparation for SSA conversion */
888 dvmInitializeSSAConversion(&cUnit);
889
890 if (cUnit.hasLoop) {
Ben Cheng4a419582010-08-04 13:23:09 -0700891 /*
892 * Loop is not optimizable (for example lack of a single induction
893 * variable), punt and recompile the trace with loop optimization
894 * disabled.
895 */
896 bool loopOpt = dvmCompilerLoopOpt(&cUnit);
897 if (loopOpt == false) {
898 if (cUnit.printMe) {
899 LOGD("Loop is not optimizable - retry codegen");
900 }
901 /* Reset the compiler resource pool */
902 dvmCompilerArenaReset();
903 return dvmCompileTrace(desc, cUnit.numInsts, info, bailPtr,
904 optHints | JIT_OPT_NO_LOOP);
905 }
Ben Cheng4238ec22009-08-24 16:32:22 -0700906 }
907 else {
908 dvmCompilerNonLoopAnalysis(&cUnit);
909 }
910
Bill Buzbee1465db52009-09-23 17:17:35 -0700911 dvmCompilerInitializeRegAlloc(&cUnit); // Needs to happen after SSA naming
912
Ben Chengba4fc8b2009-06-01 13:00:29 -0700913 if (cUnit.printMe) {
914 dvmCompilerDumpCompilationUnit(&cUnit);
915 }
916
buzbee23d95d02010-12-14 13:16:43 -0800917 /* Allocate Registers using simple local allocation scheme */
918 dvmCompilerLocalRegAlloc(&cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700919
Ben Chengba4fc8b2009-06-01 13:00:29 -0700920 /* Convert MIR to LIR, etc. */
921 dvmCompilerMIR2LIR(&cUnit);
922
buzbeebff121a2010-08-04 15:25:06 -0700923 /* Convert LIR into machine code. Loop for recoverable retries */
924 do {
925 dvmCompilerAssembleLIR(&cUnit, info);
926 cUnit.assemblerRetries++;
927 if (cUnit.printMe && cUnit.assemblerStatus != kSuccess)
928 LOGD("Assembler abort #%d on %d",cUnit.assemblerRetries,
929 cUnit.assemblerStatus);
930 } while (cUnit.assemblerStatus == kRetryAll);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700931
932 if (cUnit.printMe) {
Ben Chengcfdeca32011-01-14 11:36:46 -0800933 LOGD("Trace Dalvik PC: %p", startCodePtr);
buzbeebff121a2010-08-04 15:25:06 -0700934 dvmCompilerCodegenDump(&cUnit);
Ben Cheng1efc9c52009-06-08 18:25:27 -0700935 LOGD("End %s%s, %d Dalvik instructions",
936 desc->method->clazz->descriptor, desc->method->name,
937 cUnit.numInsts);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700938 }
939
940 /* Reset the compiler resource pool */
941 dvmCompilerArenaReset();
942
buzbeebff121a2010-08-04 15:25:06 -0700943 if (cUnit.assemblerStatus == kRetryHalve) {
944 /* Halve the instruction count and start from the top */
Ben Cheng4a419582010-08-04 13:23:09 -0700945 return dvmCompileTrace(desc, cUnit.numInsts / 2, info, bailPtr,
946 optHints);
Ben Cheng1efc9c52009-06-08 18:25:27 -0700947 }
buzbeebff121a2010-08-04 15:25:06 -0700948
949 assert(cUnit.assemblerStatus == kSuccess);
950#if defined(WITH_JIT_TUNING)
951 methodStats->nativeSize += cUnit.totalSize;
952#endif
Ben Cheng00603072010-10-28 11:13:58 -0700953
buzbeebff121a2010-08-04 15:25:06 -0700954 return info->codeAddress != NULL;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700955}
956
957/*
Ben Cheng7a2697d2010-06-07 13:44:23 -0700958 * Since we are including instructions from possibly a cold method into the
959 * current trace, we need to make sure that all the associated information
960 * with the callee is properly initialized. If not, we punt on this inline
961 * target.
962 *
Ben Cheng34dc7962010-08-26 14:56:31 -0700963 * TODO: volatile instructions will be handled later.
Ben Cheng7a2697d2010-06-07 13:44:23 -0700964 */
965bool dvmCompilerCanIncludeThisInstruction(const Method *method,
966 const DecodedInstruction *insn)
967{
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800968 switch (insn->opcode) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700969 case OP_NEW_INSTANCE:
jeffhao71eee1f2011-01-04 14:18:54 -0800970 case OP_NEW_INSTANCE_JUMBO:
971 case OP_CHECK_CAST:
972 case OP_CHECK_CAST_JUMBO: {
Carl Shapirofc75f3e2010-12-07 11:43:38 -0800973 ClassObject *classPtr = (ClassObject *)(void*)
Ben Cheng7a2697d2010-06-07 13:44:23 -0700974 (method->clazz->pDvmDex->pResClasses[insn->vB]);
975
976 /* Class hasn't been initialized yet */
977 if (classPtr == NULL) {
978 return false;
979 }
980 return true;
981 }
Ben Cheng7a2697d2010-06-07 13:44:23 -0700982 case OP_SGET:
jeffhao71eee1f2011-01-04 14:18:54 -0800983 case OP_SGET_JUMBO:
Ben Cheng7a2697d2010-06-07 13:44:23 -0700984 case OP_SGET_WIDE:
jeffhao71eee1f2011-01-04 14:18:54 -0800985 case OP_SGET_WIDE_JUMBO:
986 case OP_SGET_OBJECT:
987 case OP_SGET_OBJECT_JUMBO:
988 case OP_SGET_BOOLEAN:
989 case OP_SGET_BOOLEAN_JUMBO:
990 case OP_SGET_BYTE:
991 case OP_SGET_BYTE_JUMBO:
992 case OP_SGET_CHAR:
993 case OP_SGET_CHAR_JUMBO:
994 case OP_SGET_SHORT:
995 case OP_SGET_SHORT_JUMBO:
Ben Cheng7a2697d2010-06-07 13:44:23 -0700996 case OP_SPUT:
jeffhao71eee1f2011-01-04 14:18:54 -0800997 case OP_SPUT_JUMBO:
998 case OP_SPUT_WIDE:
999 case OP_SPUT_WIDE_JUMBO:
1000 case OP_SPUT_OBJECT:
1001 case OP_SPUT_OBJECT_JUMBO:
1002 case OP_SPUT_BOOLEAN:
1003 case OP_SPUT_BOOLEAN_JUMBO:
1004 case OP_SPUT_BYTE:
1005 case OP_SPUT_BYTE_JUMBO:
1006 case OP_SPUT_CHAR:
1007 case OP_SPUT_CHAR_JUMBO:
1008 case OP_SPUT_SHORT:
1009 case OP_SPUT_SHORT_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001010 void *fieldPtr = (void*)
1011 (method->clazz->pDvmDex->pResFields[insn->vB]);
1012
1013 if (fieldPtr == NULL) {
1014 return false;
1015 }
1016 return true;
1017 }
1018 case OP_INVOKE_SUPER:
jeffhao71eee1f2011-01-04 14:18:54 -08001019 case OP_INVOKE_SUPER_RANGE:
1020 case OP_INVOKE_SUPER_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001021 int mIndex = method->clazz->pDvmDex->
1022 pResMethods[insn->vB]->methodIndex;
1023 const Method *calleeMethod = method->clazz->super->vtable[mIndex];
1024 if (calleeMethod == NULL) {
1025 return false;
1026 }
1027 return true;
1028 }
1029 case OP_INVOKE_SUPER_QUICK:
1030 case OP_INVOKE_SUPER_QUICK_RANGE: {
1031 const Method *calleeMethod = method->clazz->super->vtable[insn->vB];
1032 if (calleeMethod == NULL) {
1033 return false;
1034 }
1035 return true;
1036 }
1037 case OP_INVOKE_STATIC:
1038 case OP_INVOKE_STATIC_RANGE:
jeffhao71eee1f2011-01-04 14:18:54 -08001039 case OP_INVOKE_STATIC_JUMBO:
Ben Cheng7a2697d2010-06-07 13:44:23 -07001040 case OP_INVOKE_DIRECT:
jeffhao71eee1f2011-01-04 14:18:54 -08001041 case OP_INVOKE_DIRECT_RANGE:
1042 case OP_INVOKE_DIRECT_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001043 const Method *calleeMethod =
1044 method->clazz->pDvmDex->pResMethods[insn->vB];
1045 if (calleeMethod == NULL) {
1046 return false;
1047 }
1048 return true;
1049 }
jeffhao71eee1f2011-01-04 14:18:54 -08001050 case OP_CONST_CLASS:
1051 case OP_CONST_CLASS_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001052 void *classPtr = (void*)
1053 (method->clazz->pDvmDex->pResClasses[insn->vB]);
1054
1055 if (classPtr == NULL) {
1056 return false;
1057 }
1058 return true;
1059 }
1060 case OP_CONST_STRING_JUMBO:
1061 case OP_CONST_STRING: {
1062 void *strPtr = (void*)
1063 (method->clazz->pDvmDex->pResStrings[insn->vB]);
1064
1065 if (strPtr == NULL) {
1066 return false;
1067 }
1068 return true;
1069 }
1070 default:
1071 return true;
1072 }
1073}
1074
Ben Cheng00603072010-10-28 11:13:58 -07001075/* Split an existing block from the specified code offset into two */
1076static BasicBlock *splitBlock(CompilationUnit *cUnit,
1077 unsigned int codeOffset,
1078 BasicBlock *origBlock)
1079{
1080 MIR *insn = origBlock->firstMIRInsn;
1081 while (insn) {
1082 if (insn->offset == codeOffset) break;
1083 insn = insn->next;
1084 }
1085 if (insn == NULL) {
1086 LOGE("Break split failed");
1087 dvmAbort();
1088 }
1089 BasicBlock *bottomBlock = dvmCompilerNewBB(kDalvikByteCode,
1090 cUnit->numBlocks++);
1091 dvmInsertGrowableList(&cUnit->blockList, (intptr_t) bottomBlock);
1092
1093 bottomBlock->startOffset = codeOffset;
1094 bottomBlock->firstMIRInsn = insn;
1095 bottomBlock->lastMIRInsn = origBlock->lastMIRInsn;
1096
Ben Cheng00603072010-10-28 11:13:58 -07001097 /* Handle the taken path */
1098 bottomBlock->taken = origBlock->taken;
1099 if (bottomBlock->taken) {
1100 origBlock->taken = NULL;
1101 dvmCompilerClearBit(bottomBlock->taken->predecessors, origBlock->id);
1102 dvmCompilerSetBit(bottomBlock->taken->predecessors, bottomBlock->id);
1103 }
1104
1105 /* Handle the fallthrough path */
1106 bottomBlock->fallThrough = origBlock->fallThrough;
1107 origBlock->fallThrough = bottomBlock;
1108 dvmCompilerSetBit(bottomBlock->predecessors, origBlock->id);
1109 if (bottomBlock->fallThrough) {
1110 dvmCompilerClearBit(bottomBlock->fallThrough->predecessors,
1111 origBlock->id);
1112 dvmCompilerSetBit(bottomBlock->fallThrough->predecessors,
1113 bottomBlock->id);
1114 }
1115
1116 /* Handle the successor list */
1117 if (origBlock->successorBlockList.blockListType != kNotUsed) {
1118 bottomBlock->successorBlockList = origBlock->successorBlockList;
1119 origBlock->successorBlockList.blockListType = kNotUsed;
1120 GrowableListIterator iterator;
1121
1122 dvmGrowableListIteratorInit(&bottomBlock->successorBlockList.blocks,
1123 &iterator);
1124 while (true) {
Ben Cheng7a02cb12010-12-15 14:18:31 -08001125 SuccessorBlockInfo *successorBlockInfo =
1126 (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator);
1127 if (successorBlockInfo == NULL) break;
1128 BasicBlock *bb = successorBlockInfo->block;
Ben Cheng00603072010-10-28 11:13:58 -07001129 dvmCompilerClearBit(bb->predecessors, origBlock->id);
1130 dvmCompilerSetBit(bb->predecessors, bottomBlock->id);
1131 }
1132 }
1133
1134 origBlock->lastMIRInsn = insn->prev;
Ben Cheng00603072010-10-28 11:13:58 -07001135
1136 insn->prev->next = NULL;
1137 insn->prev = NULL;
1138 return bottomBlock;
1139}
1140
1141/*
1142 * Given a code offset, find out the block that starts with it. If the offset
1143 * is in the middle of an existing block, split it into two.
1144 */
1145static BasicBlock *findBlock(CompilationUnit *cUnit,
1146 unsigned int codeOffset,
1147 bool split, bool create)
1148{
1149 GrowableList *blockList = &cUnit->blockList;
1150 BasicBlock *bb;
1151 unsigned int i;
1152
1153 for (i = 0; i < blockList->numUsed; i++) {
1154 bb = (BasicBlock *) blockList->elemList[i];
1155 if (bb->blockType != kDalvikByteCode) continue;
1156 if (bb->startOffset == codeOffset) return bb;
1157 /* Check if a branch jumps into the middle of an existing block */
1158 if ((split == true) && (codeOffset > bb->startOffset) &&
1159 (bb->lastMIRInsn != NULL) &&
1160 (codeOffset <= bb->lastMIRInsn->offset)) {
1161 BasicBlock *newBB = splitBlock(cUnit, codeOffset, bb);
1162 return newBB;
1163 }
1164 }
1165 if (create) {
1166 bb = dvmCompilerNewBB(kDalvikByteCode, cUnit->numBlocks++);
1167 dvmInsertGrowableList(&cUnit->blockList, (intptr_t) bb);
1168 bb->startOffset = codeOffset;
1169 return bb;
1170 }
1171 return NULL;
1172}
1173
1174/* Dump the CFG into a DOT graph */
1175void dumpCFG(CompilationUnit *cUnit, const char *dirPrefix)
1176{
1177 const Method *method = cUnit->method;
1178 FILE *file;
1179 char* signature = dexProtoCopyMethodDescriptor(&method->prototype);
1180 char *fileName = (char *) dvmCompilerNew(
1181 strlen(dirPrefix) +
1182 strlen(method->clazz->descriptor) +
1183 strlen(method->name) +
1184 strlen(signature) +
1185 strlen(".dot") + 1, true);
1186 sprintf(fileName, "%s%s%s%s.dot", dirPrefix,
1187 method->clazz->descriptor, method->name, signature);
1188 free(signature);
1189
1190 /*
1191 * Convert the special characters into a filesystem- and shell-friendly
1192 * format.
1193 */
1194 int i;
1195 for (i = strlen(dirPrefix); fileName[i]; i++) {
1196 if (fileName[i] == '/') {
1197 fileName[i] = '_';
1198 } else if (fileName[i] == ';') {
1199 fileName[i] = '#';
1200 } else if (fileName[i] == '$') {
1201 fileName[i] = '+';
1202 } else if (fileName[i] == '(' || fileName[i] == ')') {
1203 fileName[i] = '@';
1204 } else if (fileName[i] == '<' || fileName[i] == '>') {
1205 fileName[i] = '=';
1206 }
1207 }
1208 file = fopen(fileName, "w");
1209 if (file == NULL) {
1210 return;
1211 }
1212 fprintf(file, "digraph G {\n");
1213
1214 fprintf(file, " rankdir=TB\n");
1215
1216 int numReachableBlocks = cUnit->numReachableBlocks;
1217 int idx;
1218 const GrowableList *blockList = &cUnit->blockList;
1219
1220 for (idx = 0; idx < numReachableBlocks; idx++) {
1221 int blockIdx = cUnit->dfsOrder.elemList[idx];
1222 BasicBlock *bb = (BasicBlock *) dvmGrowableListGetElement(blockList,
1223 blockIdx);
1224 if (bb == NULL) break;
1225 if (bb->blockType == kMethodEntryBlock) {
1226 fprintf(file, " entry [shape=Mdiamond];\n");
1227 } else if (bb->blockType == kMethodExitBlock) {
1228 fprintf(file, " exit [shape=Mdiamond];\n");
1229 } else if (bb->blockType == kDalvikByteCode) {
Ben Cheng7a02cb12010-12-15 14:18:31 -08001230 fprintf(file, " block%04x [shape=record,label = \"{ \\\n",
1231 bb->startOffset);
Ben Cheng00603072010-10-28 11:13:58 -07001232 const MIR *mir;
1233 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
1234 fprintf(file, " {%04x %s\\l}%s\\\n", mir->offset,
1235 dvmCompilerFullDisassembler(cUnit, mir),
1236 mir->next ? " | " : " ");
1237 }
1238 fprintf(file, " }\"];\n\n");
1239 } else if (bb->blockType == kExceptionHandling) {
1240 char blockName[BLOCK_NAME_LEN];
1241
1242 dvmGetBlockName(bb, blockName);
1243 fprintf(file, " %s [shape=invhouse];\n", blockName);
1244 }
1245
1246 char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN];
1247
1248 if (bb->taken) {
1249 dvmGetBlockName(bb, blockName1);
1250 dvmGetBlockName(bb->taken, blockName2);
1251 fprintf(file, " %s:s -> %s:n [style=dotted]\n",
1252 blockName1, blockName2);
1253 }
1254 if (bb->fallThrough) {
1255 dvmGetBlockName(bb, blockName1);
1256 dvmGetBlockName(bb->fallThrough, blockName2);
1257 fprintf(file, " %s:s -> %s:n\n", blockName1, blockName2);
1258 }
1259
1260 if (bb->successorBlockList.blockListType != kNotUsed) {
1261 fprintf(file, " succ%04x [shape=%s,label = \"{ \\\n",
1262 bb->startOffset,
1263 (bb->successorBlockList.blockListType == kCatch) ?
1264 "Mrecord" : "record");
1265 GrowableListIterator iterator;
1266 dvmGrowableListIteratorInit(&bb->successorBlockList.blocks,
1267 &iterator);
Ben Cheng7a02cb12010-12-15 14:18:31 -08001268 SuccessorBlockInfo *successorBlockInfo =
1269 (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator);
Ben Cheng00603072010-10-28 11:13:58 -07001270
1271 int succId = 0;
1272 while (true) {
Ben Cheng7a02cb12010-12-15 14:18:31 -08001273 if (successorBlockInfo == NULL) break;
1274
1275 BasicBlock *destBlock = successorBlockInfo->block;
1276 SuccessorBlockInfo *nextSuccessorBlockInfo =
1277 (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator);
1278
1279 fprintf(file, " {<f%d> %04x: %04x\\l}%s\\\n",
Ben Cheng00603072010-10-28 11:13:58 -07001280 succId++,
Ben Cheng7a02cb12010-12-15 14:18:31 -08001281 successorBlockInfo->key,
Ben Cheng00603072010-10-28 11:13:58 -07001282 destBlock->startOffset,
Ben Cheng7a02cb12010-12-15 14:18:31 -08001283 (nextSuccessorBlockInfo != NULL) ? " | " : " ");
1284
1285 successorBlockInfo = nextSuccessorBlockInfo;
Ben Cheng00603072010-10-28 11:13:58 -07001286 }
1287 fprintf(file, " }\"];\n\n");
1288
1289 dvmGetBlockName(bb, blockName1);
1290 fprintf(file, " %s:s -> succ%04x:n [style=dashed]\n",
1291 blockName1, bb->startOffset);
1292
1293 if (bb->successorBlockList.blockListType == kPackedSwitch ||
1294 bb->successorBlockList.blockListType == kSparseSwitch) {
1295
1296 dvmGrowableListIteratorInit(&bb->successorBlockList.blocks,
1297 &iterator);
1298
1299 succId = 0;
1300 while (true) {
Ben Cheng7a02cb12010-12-15 14:18:31 -08001301 SuccessorBlockInfo *successorBlockInfo =
1302 (SuccessorBlockInfo *)
1303 dvmGrowableListIteratorNext(&iterator);
1304 if (successorBlockInfo == NULL) break;
1305
1306 BasicBlock *destBlock = successorBlockInfo->block;
Ben Cheng00603072010-10-28 11:13:58 -07001307
1308 dvmGetBlockName(destBlock, blockName2);
1309 fprintf(file, " succ%04x:f%d:e -> %s:n\n",
1310 bb->startOffset, succId++,
1311 blockName2);
1312 }
1313 }
1314 }
1315 fprintf(file, "\n");
1316
1317 /*
1318 * If we need to debug the dominator tree, uncomment the following code
1319 */
1320#if 0
1321 dvmGetBlockName(bb, blockName1);
1322 fprintf(file, " cfg%s [label=\"%s\", shape=none];\n",
1323 blockName1, blockName1);
1324 if (bb->iDom) {
1325 dvmGetBlockName(bb->iDom, blockName2);
1326 fprintf(file, " cfg%s:s -> cfg%s:n\n\n",
1327 blockName2, blockName1);
1328 }
1329#endif
1330 }
1331 fprintf(file, "}\n");
1332 fclose(file);
1333}
1334
1335/* Verify if all the successor is connected with all the claimed predecessors */
1336static bool verifyPredInfo(CompilationUnit *cUnit, BasicBlock *bb)
1337{
1338 BitVectorIterator bvIterator;
1339
1340 dvmBitVectorIteratorInit(bb->predecessors, &bvIterator);
1341 while (true) {
1342 int blockIdx = dvmBitVectorIteratorNext(&bvIterator);
1343 if (blockIdx == -1) break;
1344 BasicBlock *predBB = (BasicBlock *)
1345 dvmGrowableListGetElement(&cUnit->blockList, blockIdx);
1346 bool found = false;
1347 if (predBB->taken == bb) {
1348 found = true;
1349 } else if (predBB->fallThrough == bb) {
1350 found = true;
1351 } else if (predBB->successorBlockList.blockListType != kNotUsed) {
1352 GrowableListIterator iterator;
1353 dvmGrowableListIteratorInit(&predBB->successorBlockList.blocks,
1354 &iterator);
1355 while (true) {
Ben Cheng7a02cb12010-12-15 14:18:31 -08001356 SuccessorBlockInfo *successorBlockInfo =
1357 (SuccessorBlockInfo *)
1358 dvmGrowableListIteratorNext(&iterator);
1359 if (successorBlockInfo == NULL) break;
1360 BasicBlock *succBB = successorBlockInfo->block;
Ben Cheng00603072010-10-28 11:13:58 -07001361 if (succBB == bb) {
1362 found = true;
1363 break;
1364 }
1365 }
1366 }
1367 if (found == false) {
1368 char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN];
1369 dvmGetBlockName(bb, blockName1);
1370 dvmGetBlockName(predBB, blockName2);
1371 dumpCFG(cUnit, "/data/tombstones/");
1372 LOGE("Successor %s not found from %s",
1373 blockName1, blockName2);
1374 dvmAbort();
1375 }
1376 }
1377 return true;
1378}
1379
1380/* Identify code range in try blocks and set up the empty catch blocks */
1381static void processTryCatchBlocks(CompilationUnit *cUnit)
1382{
1383 const Method *meth = cUnit->method;
1384 const DexCode *pCode = dvmGetMethodCode(meth);
1385 int triesSize = pCode->triesSize;
1386 int i;
1387 int offset;
1388
1389 if (triesSize == 0) {
1390 return;
1391 }
1392
1393 const DexTry *pTries = dexGetTries(pCode);
1394 BitVector *tryBlockAddr = cUnit->tryBlockAddr;
1395
1396 /* Mark all the insn offsets in Try blocks */
1397 for (i = 0; i < triesSize; i++) {
1398 const DexTry* pTry = &pTries[i];
1399 /* all in 16-bit units */
1400 int startOffset = pTry->startAddr;
1401 int endOffset = startOffset + pTry->insnCount;
1402
1403 for (offset = startOffset; offset < endOffset; offset++) {
1404 dvmCompilerSetBit(tryBlockAddr, offset);
1405 }
1406 }
1407
1408 /* Iterate over each of the handlers to enqueue the empty Catch blocks */
1409 offset = dexGetFirstHandlerOffset(pCode);
1410 int handlersSize = dexGetHandlersSize(pCode);
1411
1412 for (i = 0; i < handlersSize; i++) {
1413 DexCatchIterator iterator;
1414 dexCatchIteratorInit(&iterator, pCode, offset);
1415
1416 for (;;) {
1417 DexCatchHandler* handler = dexCatchIteratorNext(&iterator);
1418
1419 if (handler == NULL) {
1420 break;
1421 }
1422
Ben Cheng7a02cb12010-12-15 14:18:31 -08001423 /*
1424 * Create dummy catch blocks first. Since these are created before
1425 * other blocks are processed, "split" is specified as false.
1426 */
1427 findBlock(cUnit, handler->address,
1428 /* split */
1429 false,
1430 /* create */
1431 true);
Ben Cheng00603072010-10-28 11:13:58 -07001432 }
1433
1434 offset = dexCatchIteratorGetEndOffset(&iterator, pCode);
1435 }
1436}
1437
1438/* Process instructions with the kInstrCanBranch flag */
1439static void processCanBranch(CompilationUnit *cUnit, BasicBlock *curBlock,
1440 MIR *insn, int curOffset, int width, int flags,
1441 const u2* codePtr, const u2* codeEnd)
1442{
1443 int target = curOffset;
1444 switch (insn->dalvikInsn.opcode) {
1445 case OP_GOTO:
1446 case OP_GOTO_16:
1447 case OP_GOTO_32:
1448 target += (int) insn->dalvikInsn.vA;
1449 break;
1450 case OP_IF_EQ:
1451 case OP_IF_NE:
1452 case OP_IF_LT:
1453 case OP_IF_GE:
1454 case OP_IF_GT:
1455 case OP_IF_LE:
1456 target += (int) insn->dalvikInsn.vC;
1457 break;
1458 case OP_IF_EQZ:
1459 case OP_IF_NEZ:
1460 case OP_IF_LTZ:
1461 case OP_IF_GEZ:
1462 case OP_IF_GTZ:
1463 case OP_IF_LEZ:
1464 target += (int) insn->dalvikInsn.vB;
1465 break;
1466 default:
1467 LOGE("Unexpected opcode(%d) with kInstrCanBranch set",
1468 insn->dalvikInsn.opcode);
1469 dvmAbort();
1470 }
1471 BasicBlock *takenBlock = findBlock(cUnit, target,
1472 /* split */
1473 true,
1474 /* create */
1475 true);
1476 curBlock->taken = takenBlock;
1477 dvmCompilerSetBit(takenBlock->predecessors, curBlock->id);
1478
1479 /* Always terminate the current block for conditional branches */
1480 if (flags & kInstrCanContinue) {
1481 BasicBlock *fallthroughBlock = findBlock(cUnit,
1482 curOffset + width,
1483 /* split */
1484 false,
1485 /* create */
1486 true);
1487 curBlock->fallThrough = fallthroughBlock;
1488 dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id);
1489 } else if (codePtr < codeEnd) {
1490 /* Create a fallthrough block for real instructions (incl. OP_NOP) */
1491 if (contentIsInsn(codePtr)) {
1492 findBlock(cUnit, curOffset + width,
1493 /* split */
1494 false,
1495 /* create */
1496 true);
1497 }
1498 }
1499}
1500
1501/* Process instructions with the kInstrCanSwitch flag */
1502static void processCanSwitch(CompilationUnit *cUnit, BasicBlock *curBlock,
1503 MIR *insn, int curOffset, int width, int flags)
1504{
1505 u2 *switchData= (u2 *) (cUnit->method->insns + curOffset +
1506 insn->dalvikInsn.vB);
1507 int size;
Ben Cheng7a02cb12010-12-15 14:18:31 -08001508 int *keyTable;
Ben Cheng00603072010-10-28 11:13:58 -07001509 int *targetTable;
1510 int i;
Ben Cheng7a02cb12010-12-15 14:18:31 -08001511 int firstKey;
Ben Cheng00603072010-10-28 11:13:58 -07001512
1513 /*
1514 * Packed switch data format:
1515 * ushort ident = 0x0100 magic value
1516 * ushort size number of entries in the table
1517 * int first_key first (and lowest) switch case value
1518 * int targets[size] branch targets, relative to switch opcode
1519 *
1520 * Total size is (4+size*2) 16-bit code units.
1521 */
1522 if (insn->dalvikInsn.opcode == OP_PACKED_SWITCH) {
1523 assert(switchData[0] == kPackedSwitchSignature);
1524 size = switchData[1];
Ben Cheng7a02cb12010-12-15 14:18:31 -08001525 firstKey = switchData[2] | (switchData[3] << 16);
Ben Cheng00603072010-10-28 11:13:58 -07001526 targetTable = (int *) &switchData[4];
Ben Cheng7a02cb12010-12-15 14:18:31 -08001527 keyTable = NULL; // Make the compiler happy
Ben Cheng00603072010-10-28 11:13:58 -07001528 /*
1529 * Sparse switch data format:
1530 * ushort ident = 0x0200 magic value
1531 * ushort size number of entries in the table; > 0
1532 * int keys[size] keys, sorted low-to-high; 32-bit aligned
1533 * int targets[size] branch targets, relative to switch opcode
1534 *
1535 * Total size is (2+size*4) 16-bit code units.
1536 */
1537 } else {
1538 assert(switchData[0] == kSparseSwitchSignature);
1539 size = switchData[1];
Ben Cheng7a02cb12010-12-15 14:18:31 -08001540 keyTable = (int *) &switchData[2];
Ben Cheng00603072010-10-28 11:13:58 -07001541 targetTable = (int *) &switchData[2 + size*2];
Ben Cheng7a02cb12010-12-15 14:18:31 -08001542 firstKey = 0; // To make the compiler happy
Ben Cheng00603072010-10-28 11:13:58 -07001543 }
1544
1545 if (curBlock->successorBlockList.blockListType != kNotUsed) {
1546 LOGE("Successor block list already in use: %d",
1547 curBlock->successorBlockList.blockListType);
1548 dvmAbort();
1549 }
1550 curBlock->successorBlockList.blockListType =
1551 (insn->dalvikInsn.opcode == OP_PACKED_SWITCH) ?
1552 kPackedSwitch : kSparseSwitch;
1553 dvmInitGrowableList(&curBlock->successorBlockList.blocks, size);
1554
1555 for (i = 0; i < size; i++) {
1556 BasicBlock *caseBlock = findBlock(cUnit, curOffset + targetTable[i],
1557 /* split */
1558 true,
1559 /* create */
1560 true);
Ben Cheng7a02cb12010-12-15 14:18:31 -08001561 SuccessorBlockInfo *successorBlockInfo =
1562 (SuccessorBlockInfo *) dvmCompilerNew(sizeof(SuccessorBlockInfo),
1563 false);
1564 successorBlockInfo->block = caseBlock;
1565 successorBlockInfo->key = (insn->dalvikInsn.opcode == OP_PACKED_SWITCH)?
1566 firstKey + i : keyTable[i];
Ben Cheng00603072010-10-28 11:13:58 -07001567 dvmInsertGrowableList(&curBlock->successorBlockList.blocks,
Ben Cheng7a02cb12010-12-15 14:18:31 -08001568 (intptr_t) successorBlockInfo);
Ben Cheng00603072010-10-28 11:13:58 -07001569 dvmCompilerSetBit(caseBlock->predecessors, curBlock->id);
1570 }
1571
1572 /* Fall-through case */
1573 BasicBlock *fallthroughBlock = findBlock(cUnit,
1574 curOffset + width,
1575 /* split */
1576 false,
1577 /* create */
1578 true);
1579 curBlock->fallThrough = fallthroughBlock;
1580 dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id);
1581}
1582
1583/* Process instructions with the kInstrCanThrow flag */
1584static void processCanThrow(CompilationUnit *cUnit, BasicBlock *curBlock,
1585 MIR *insn, int curOffset, int width, int flags,
1586 BitVector *tryBlockAddr, const u2 *codePtr,
1587 const u2* codeEnd)
1588{
1589 const Method *method = cUnit->method;
1590 const DexCode *dexCode = dvmGetMethodCode(method);
1591
Ben Cheng00603072010-10-28 11:13:58 -07001592 /* In try block */
1593 if (dvmIsBitSet(tryBlockAddr, curOffset)) {
1594 DexCatchIterator iterator;
1595
1596 if (!dexFindCatchHandler(&iterator, dexCode, curOffset)) {
1597 LOGE("Catch block not found in dexfile for insn %x in %s",
1598 curOffset, method->name);
1599 dvmAbort();
1600
1601 }
1602 if (curBlock->successorBlockList.blockListType != kNotUsed) {
1603 LOGE("Successor block list already in use: %d",
1604 curBlock->successorBlockList.blockListType);
1605 dvmAbort();
1606 }
1607 curBlock->successorBlockList.blockListType = kCatch;
1608 dvmInitGrowableList(&curBlock->successorBlockList.blocks, 2);
1609
1610 for (;;) {
1611 DexCatchHandler* handler = dexCatchIteratorNext(&iterator);
1612
1613 if (handler == NULL) {
1614 break;
1615 }
1616
1617 BasicBlock *catchBlock = findBlock(cUnit, handler->address,
1618 /* split */
1619 false,
1620 /* create */
1621 false);
1622
Ben Cheng7a02cb12010-12-15 14:18:31 -08001623 SuccessorBlockInfo *successorBlockInfo =
1624 (SuccessorBlockInfo *) dvmCompilerNew(sizeof(SuccessorBlockInfo),
1625 false);
1626 successorBlockInfo->block = catchBlock;
1627 successorBlockInfo->key = handler->typeIdx;
Ben Cheng00603072010-10-28 11:13:58 -07001628 dvmInsertGrowableList(&curBlock->successorBlockList.blocks,
Ben Cheng7a02cb12010-12-15 14:18:31 -08001629 (intptr_t) successorBlockInfo);
Ben Cheng00603072010-10-28 11:13:58 -07001630 dvmCompilerSetBit(catchBlock->predecessors, curBlock->id);
1631 }
1632 } else {
1633 BasicBlock *ehBlock = dvmCompilerNewBB(kExceptionHandling,
1634 cUnit->numBlocks++);
1635 curBlock->taken = ehBlock;
1636 dvmInsertGrowableList(&cUnit->blockList, (intptr_t) ehBlock);
1637 ehBlock->startOffset = curOffset;
1638 dvmCompilerSetBit(ehBlock->predecessors, curBlock->id);
1639 }
1640
1641 /*
1642 * Force the current block to terminate.
1643 *
1644 * Data may be present before codeEnd, so we need to parse it to know
1645 * whether it is code or data.
1646 */
1647 if (codePtr < codeEnd) {
1648 /* Create a fallthrough block for real instructions (incl. OP_NOP) */
1649 if (contentIsInsn(codePtr)) {
1650 BasicBlock *fallthroughBlock = findBlock(cUnit,
1651 curOffset + width,
1652 /* split */
1653 false,
1654 /* create */
1655 true);
1656 /*
1657 * OP_THROW and OP_THROW_VERIFICATION_ERROR are unconditional
1658 * branches.
1659 */
1660 if (insn->dalvikInsn.opcode != OP_THROW_VERIFICATION_ERROR &&
1661 insn->dalvikInsn.opcode != OP_THROW) {
1662 curBlock->fallThrough = fallthroughBlock;
1663 dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id);
1664 }
1665 }
1666 }
1667}
1668
Ben Cheng7a2697d2010-06-07 13:44:23 -07001669/*
Ben Chengba4fc8b2009-06-01 13:00:29 -07001670 * Similar to dvmCompileTrace, but the entity processed here is the whole
1671 * method.
1672 *
1673 * TODO: implementation will be revisited when the trace builder can provide
1674 * whole-method traces.
1675 */
Ben Chengcfdeca32011-01-14 11:36:46 -08001676bool dvmCompileMethod(const Method *method, JitTranslationInfo *info)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001677{
Ben Cheng00603072010-10-28 11:13:58 -07001678 CompilationUnit cUnit;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001679 const DexCode *dexCode = dvmGetMethodCode(method);
1680 const u2 *codePtr = dexCode->insns;
1681 const u2 *codeEnd = dexCode->insns + dexCode->insnsSize;
Ben Cheng00603072010-10-28 11:13:58 -07001682 int numBlocks = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001683 unsigned int curOffset = 0;
1684
Ben Chengcfdeca32011-01-14 11:36:46 -08001685 /* Method already compiled */
1686 if (dvmJitGetMethodAddr(codePtr)) {
1687 info->codeAddress = NULL;
1688 return false;
1689 }
1690
Ben Cheng00603072010-10-28 11:13:58 -07001691 memset(&cUnit, 0, sizeof(cUnit));
1692 cUnit.method = method;
Ben Cheng7a2697d2010-06-07 13:44:23 -07001693
Ben Chengcfdeca32011-01-14 11:36:46 -08001694 cUnit.methodJitMode = true;
1695
Ben Cheng00603072010-10-28 11:13:58 -07001696 /* Initialize the block list */
1697 dvmInitGrowableList(&cUnit.blockList, 4);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001698
Ben Chengcfdeca32011-01-14 11:36:46 -08001699 /*
1700 * FIXME - PC reconstruction list won't be needed after the codegen routines
1701 * are enhanced to true method mode.
1702 */
1703 /* Initialize the PC reconstruction list */
1704 dvmInitGrowableList(&cUnit.pcReconstructionList, 8);
1705
Ben Chengba4fc8b2009-06-01 13:00:29 -07001706 /* Allocate the bit-vector to track the beginning of basic blocks */
Ben Cheng00603072010-10-28 11:13:58 -07001707 BitVector *tryBlockAddr = dvmCompilerAllocBitVector(dexCode->insnsSize,
1708 true /* expandable */);
1709 cUnit.tryBlockAddr = tryBlockAddr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001710
Ben Cheng00603072010-10-28 11:13:58 -07001711 /* Create the default entry and exit blocks and enter them to the list */
1712 BasicBlock *entryBlock = dvmCompilerNewBB(kMethodEntryBlock, numBlocks++);
1713 BasicBlock *exitBlock = dvmCompilerNewBB(kMethodExitBlock, numBlocks++);
1714
1715 cUnit.entryBlock = entryBlock;
1716 cUnit.exitBlock = exitBlock;
1717
1718 dvmInsertGrowableList(&cUnit.blockList, (intptr_t) entryBlock);
1719 dvmInsertGrowableList(&cUnit.blockList, (intptr_t) exitBlock);
1720
1721 /* Current block to record parsed instructions */
1722 BasicBlock *curBlock = dvmCompilerNewBB(kDalvikByteCode, numBlocks++);
1723 curBlock->startOffset = 0;
1724 dvmInsertGrowableList(&cUnit.blockList, (intptr_t) curBlock);
1725 entryBlock->fallThrough = curBlock;
1726 dvmCompilerSetBit(curBlock->predecessors, entryBlock->id);
Ben Cheng7a2697d2010-06-07 13:44:23 -07001727
Ben Chengba4fc8b2009-06-01 13:00:29 -07001728 /*
Ben Cheng00603072010-10-28 11:13:58 -07001729 * Store back the number of blocks since new blocks may be created of
1730 * accessing cUnit.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001731 */
Ben Cheng00603072010-10-28 11:13:58 -07001732 cUnit.numBlocks = numBlocks;
1733
1734 /* Identify code range in try blocks and set up the empty catch blocks */
1735 processTryCatchBlocks(&cUnit);
1736
1737 /* Parse all instructions and put them into containing basic blocks */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001738 while (codePtr < codeEnd) {
Ben Cheng00603072010-10-28 11:13:58 -07001739 MIR *insn = (MIR *) dvmCompilerNew(sizeof(MIR), true);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001740 insn->offset = curOffset;
1741 int width = parseInsn(codePtr, &insn->dalvikInsn, false);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001742 insn->width = width;
1743
Ben Cheng8b258bf2009-06-24 17:27:07 -07001744 /* Terminate when the data section is seen */
1745 if (width == 0)
1746 break;
Ben Cheng7a2697d2010-06-07 13:44:23 -07001747
Ben Cheng00603072010-10-28 11:13:58 -07001748 dvmCompilerAppendMIR(curBlock, insn);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001749
1750 codePtr += width;
Ben Cheng00603072010-10-28 11:13:58 -07001751 int flags = dexGetFlagsFromOpcode(insn->dalvikInsn.opcode);
1752
1753 if (flags & kInstrCanBranch) {
1754 processCanBranch(&cUnit, curBlock, insn, curOffset, width, flags,
1755 codePtr, codeEnd);
1756 } else if (flags & kInstrCanReturn) {
1757 curBlock->fallThrough = exitBlock;
1758 dvmCompilerSetBit(exitBlock->predecessors, curBlock->id);
1759 /*
1760 * Terminate the current block if there are instructions
1761 * afterwards.
1762 */
1763 if (codePtr < codeEnd) {
1764 /*
1765 * Create a fallthrough block for real instructions
1766 * (incl. OP_NOP).
1767 */
1768 if (contentIsInsn(codePtr)) {
1769 findBlock(&cUnit, curOffset + width,
1770 /* split */
1771 false,
1772 /* create */
1773 true);
1774 }
1775 }
1776 } else if (flags & kInstrCanThrow) {
1777 processCanThrow(&cUnit, curBlock, insn, curOffset, width, flags,
1778 tryBlockAddr, codePtr, codeEnd);
1779 } else if (flags & kInstrCanSwitch) {
1780 processCanSwitch(&cUnit, curBlock, insn, curOffset, width, flags);
1781 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001782 curOffset += width;
Ben Cheng00603072010-10-28 11:13:58 -07001783 BasicBlock *nextBlock = findBlock(&cUnit, curOffset,
1784 /* split */
1785 false,
1786 /* create */
1787 false);
1788 if (nextBlock) {
1789 /*
1790 * The next instruction could be the target of a previously parsed
1791 * forward branch so a block is already created. If the current
1792 * instruction is not an unconditional branch, connect them through
1793 * the fall-through link.
1794 */
1795 assert(curBlock->fallThrough == NULL ||
1796 curBlock->fallThrough == nextBlock ||
1797 curBlock->fallThrough == exitBlock);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001798
Ben Cheng00603072010-10-28 11:13:58 -07001799 if ((curBlock->fallThrough == NULL) &&
1800 !dexIsGoto(flags) &&
1801 !(flags & kInstrCanReturn)) {
1802 curBlock->fallThrough = nextBlock;
1803 dvmCompilerSetBit(nextBlock->predecessors, curBlock->id);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001804 }
Ben Cheng00603072010-10-28 11:13:58 -07001805 curBlock = nextBlock;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001806 }
1807 }
1808
Ben Chengcfdeca32011-01-14 11:36:46 -08001809 if (cUnit.printMe) {
1810 dvmCompilerDumpCompilationUnit(&cUnit);
1811 }
1812
Ben Cheng00603072010-10-28 11:13:58 -07001813 /* Adjust this value accordingly once inlining is performed */
1814 cUnit.numDalvikRegisters = cUnit.method->registersSize;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001815
Ben Cheng00603072010-10-28 11:13:58 -07001816 /* Verify if all blocks are connected as claimed */
1817 /* FIXME - to be disabled in the future */
1818 dvmCompilerDataFlowAnalysisDispatcher(&cUnit, verifyPredInfo,
1819 kAllNodes,
1820 false /* isIterative */);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001821
Ben Chengba4fc8b2009-06-01 13:00:29 -07001822
Ben Cheng00603072010-10-28 11:13:58 -07001823 /* Perform SSA transformation for the whole method */
1824 dvmCompilerMethodSSATransformation(&cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001825
Ben Chengcfdeca32011-01-14 11:36:46 -08001826 dvmCompilerInitializeRegAlloc(&cUnit); // Needs to happen after SSA naming
Ben Chengba4fc8b2009-06-01 13:00:29 -07001827
Ben Chengcfdeca32011-01-14 11:36:46 -08001828 /* Allocate Registers using simple local allocation scheme */
1829 dvmCompilerLocalRegAlloc(&cUnit);
1830
1831 /* Convert MIR to LIR, etc. */
1832 dvmCompilerMethodMIR2LIR(&cUnit);
1833
1834 // Debugging only
1835 //dumpCFG(&cUnit, "/data/tombstones/");
1836
1837 /* Method is not empty */
1838 if (cUnit.firstLIRInsn) {
1839 /* Convert LIR into machine code. Loop for recoverable retries */
1840 do {
1841 dvmCompilerAssembleLIR(&cUnit, info);
1842 cUnit.assemblerRetries++;
1843 if (cUnit.printMe && cUnit.assemblerStatus != kSuccess)
1844 LOGD("Assembler abort #%d on %d",cUnit.assemblerRetries,
1845 cUnit.assemblerStatus);
1846 } while (cUnit.assemblerStatus == kRetryAll);
1847
1848 if (cUnit.printMe) {
1849 dvmCompilerCodegenDump(&cUnit);
1850 }
1851
1852 if (info->codeAddress) {
1853 dvmJitSetCodeAddr(dexCode->insns, info->codeAddress,
1854 info->instructionSet, true, 0);
1855 /*
1856 * Clear the codeAddress for the enclosing trace to reuse the info
1857 */
1858 info->codeAddress = NULL;
1859 }
1860 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001861
Ben Cheng00603072010-10-28 11:13:58 -07001862 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001863}