| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Bornstein | df4daaf | 2010-12-01 14:23:44 -0800 | [diff] [blame] | 18 | #include "libdex/DexOpcodes.h" |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 19 | #include "libdex/DexCatch.h" |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 20 | #include "interp/Jit.h" |
| 21 | #include "CompilerInternals.h" |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 22 | #include "Dataflow.h" |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 23 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 24 | static 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 Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Parse an instruction, return the length of the instruction |
| 37 | */ |
| 38 | static inline int parseInsn(const u2 *codePtr, DecodedInstruction *decInsn, |
| 39 | bool printMe) |
| 40 | { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 41 | // Don't parse instruction data |
| 42 | if (!contentIsInsn(codePtr)) { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 46 | u2 instr = *codePtr; |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 47 | Opcode opcode = dexOpcodeFromCodeUnit(instr); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 48 | |
| Dan Bornstein | 5432239 | 2010-11-17 14:16:56 -0800 | [diff] [blame] | 49 | dexDecodeInstruction(codePtr, decInsn); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 50 | if (printMe) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 51 | char *decodedString = dvmCompilerGetDalvikDisassembly(decInsn, NULL); |
| Ben Cheng | ccd6c01 | 2009-10-15 14:52:45 -0700 | [diff] [blame] | 52 | LOGD("%p: %#06x %s\n", codePtr, opcode, decodedString); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 53 | } |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 54 | return dexGetWidthFromOpcode(opcode); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| Ben Cheng | 9c147b8 | 2009-10-07 16:41:46 -0700 | [diff] [blame] | 57 | #define UNKNOWN_TARGET 0xffffffff |
| 58 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 59 | /* |
| 60 | * Identify block-ending instructions and collect supplemental information |
| 61 | * regarding the following instructions. |
| 62 | */ |
| 63 | static inline bool findBlockBoundary(const Method *caller, MIR *insn, |
| 64 | unsigned int curOffset, |
| 65 | unsigned int *target, bool *isInvoke, |
| 66 | const Method **callee) |
| 67 | { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 68 | switch (insn->dalvikInsn.opcode) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 69 | /* 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 Cheng | 9c147b8 | 2009-10-07 16:41:46 -0700 | [diff] [blame] | 75 | *target = UNKNOWN_TARGET; |
| 76 | break; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 77 | case OP_INVOKE_VIRTUAL: |
| 78 | case OP_INVOKE_VIRTUAL_RANGE: |
| 79 | case OP_INVOKE_INTERFACE: |
| 80 | case OP_INVOKE_INTERFACE_RANGE: |
| 81 | case OP_INVOKE_VIRTUAL_QUICK: |
| 82 | case OP_INVOKE_VIRTUAL_QUICK_RANGE: |
| 83 | *isInvoke = true; |
| 84 | break; |
| 85 | case OP_INVOKE_SUPER: |
| 86 | case OP_INVOKE_SUPER_RANGE: { |
| 87 | int mIndex = caller->clazz->pDvmDex-> |
| 88 | pResMethods[insn->dalvikInsn.vB]->methodIndex; |
| 89 | const Method *calleeMethod = |
| 90 | caller->clazz->super->vtable[mIndex]; |
| 91 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 92 | if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 93 | *target = (unsigned int) calleeMethod->insns; |
| 94 | } |
| 95 | *isInvoke = true; |
| 96 | *callee = calleeMethod; |
| 97 | break; |
| 98 | } |
| 99 | case OP_INVOKE_STATIC: |
| 100 | case OP_INVOKE_STATIC_RANGE: { |
| 101 | const Method *calleeMethod = |
| 102 | caller->clazz->pDvmDex->pResMethods[insn->dalvikInsn.vB]; |
| 103 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 104 | if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 105 | *target = (unsigned int) calleeMethod->insns; |
| 106 | } |
| 107 | *isInvoke = true; |
| 108 | *callee = calleeMethod; |
| 109 | break; |
| 110 | } |
| 111 | case OP_INVOKE_SUPER_QUICK: |
| 112 | case OP_INVOKE_SUPER_QUICK_RANGE: { |
| 113 | const Method *calleeMethod = |
| 114 | caller->clazz->super->vtable[insn->dalvikInsn.vB]; |
| 115 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 116 | if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 117 | *target = (unsigned int) calleeMethod->insns; |
| 118 | } |
| 119 | *isInvoke = true; |
| 120 | *callee = calleeMethod; |
| 121 | break; |
| 122 | } |
| 123 | case OP_INVOKE_DIRECT: |
| 124 | case OP_INVOKE_DIRECT_RANGE: { |
| 125 | const Method *calleeMethod = |
| 126 | caller->clazz->pDvmDex->pResMethods[insn->dalvikInsn.vB]; |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 127 | if (calleeMethod && !dvmIsNativeMethod(calleeMethod)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 128 | *target = (unsigned int) calleeMethod->insns; |
| 129 | } |
| 130 | *isInvoke = true; |
| 131 | *callee = calleeMethod; |
| 132 | break; |
| 133 | } |
| 134 | case OP_GOTO: |
| 135 | case OP_GOTO_16: |
| 136 | case OP_GOTO_32: |
| 137 | *target = curOffset + (int) insn->dalvikInsn.vA; |
| 138 | break; |
| 139 | |
| 140 | case OP_IF_EQ: |
| 141 | case OP_IF_NE: |
| 142 | case OP_IF_LT: |
| 143 | case OP_IF_GE: |
| 144 | case OP_IF_GT: |
| 145 | case OP_IF_LE: |
| 146 | *target = curOffset + (int) insn->dalvikInsn.vC; |
| 147 | break; |
| 148 | |
| 149 | case OP_IF_EQZ: |
| 150 | case OP_IF_NEZ: |
| 151 | case OP_IF_LTZ: |
| 152 | case OP_IF_GEZ: |
| 153 | case OP_IF_GTZ: |
| 154 | case OP_IF_LEZ: |
| 155 | *target = curOffset + (int) insn->dalvikInsn.vB; |
| 156 | break; |
| 157 | |
| 158 | default: |
| 159 | return false; |
| Ben Cheng | 9c147b8 | 2009-10-07 16:41:46 -0700 | [diff] [blame] | 160 | } |
| 161 | return true; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| Bill Buzbee | 324b3ac | 2009-12-04 13:17:36 -0800 | [diff] [blame] | 164 | static inline bool isGoto(MIR *insn) |
| 165 | { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 166 | switch (insn->dalvikInsn.opcode) { |
| Bill Buzbee | 324b3ac | 2009-12-04 13:17:36 -0800 | [diff] [blame] | 167 | case OP_GOTO: |
| 168 | case OP_GOTO_16: |
| 169 | case OP_GOTO_32: |
| 170 | return true; |
| 171 | default: |
| 172 | return false; |
| 173 | } |
| 174 | } |
| 175 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 176 | /* |
| Bill Buzbee | 324b3ac | 2009-12-04 13:17:36 -0800 | [diff] [blame] | 177 | * Identify unconditional branch instructions |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 178 | */ |
| 179 | static inline bool isUnconditionalBranch(MIR *insn) |
| 180 | { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 181 | switch (insn->dalvikInsn.opcode) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 182 | case OP_RETURN_VOID: |
| 183 | case OP_RETURN: |
| 184 | case OP_RETURN_WIDE: |
| 185 | case OP_RETURN_OBJECT: |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 186 | return true; |
| 187 | default: |
| Bill Buzbee | 324b3ac | 2009-12-04 13:17:36 -0800 | [diff] [blame] | 188 | return isGoto(insn); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | /* |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 193 | * dvmHashTableLookup() callback |
| 194 | */ |
| 195 | static int compareMethod(const CompilerMethodStats *m1, |
| 196 | const CompilerMethodStats *m2) |
| 197 | { |
| 198 | return (int) m1->method - (int) m2->method; |
| 199 | } |
| 200 | |
| 201 | /* |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 202 | * Analyze the body of the method to collect high-level information regarding |
| 203 | * inlining: |
| 204 | * - is empty method? |
| 205 | * - is getter/setter? |
| 206 | * - can throw exception? |
| 207 | * |
| 208 | * Currently the inliner only handles getters and setters. When its capability |
| 209 | * becomes more sophisticated more information will be retrieved here. |
| 210 | */ |
| 211 | static int analyzeInlineTarget(DecodedInstruction *dalvikInsn, int attributes, |
| 212 | int offset) |
| 213 | { |
| Dan Bornstein | e485276 | 2010-12-02 12:45:00 -0800 | [diff] [blame] | 214 | int flags = dexGetFlagsFromOpcode(dalvikInsn->opcode); |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 215 | int dalvikOpcode = dalvikInsn->opcode; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 216 | |
| Dan Bornstein | 0759f52 | 2010-11-30 14:58:53 -0800 | [diff] [blame] | 217 | if (flags & kInstrInvoke) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 218 | attributes &= ~METHOD_IS_LEAF; |
| 219 | } |
| 220 | |
| 221 | if (!(flags & kInstrCanReturn)) { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 222 | if (!(dvmCompilerDataFlowAttributes[dalvikOpcode] & |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 223 | DF_IS_GETTER)) { |
| 224 | attributes &= ~METHOD_IS_GETTER; |
| 225 | } |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 226 | if (!(dvmCompilerDataFlowAttributes[dalvikOpcode] & |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 227 | DF_IS_SETTER)) { |
| 228 | attributes &= ~METHOD_IS_SETTER; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * The expected instruction sequence is setter will never return value and |
| 234 | * getter will also do. Clear the bits if the behavior is discovered |
| 235 | * otherwise. |
| 236 | */ |
| 237 | if (flags & kInstrCanReturn) { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 238 | if (dalvikOpcode == OP_RETURN_VOID) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 239 | attributes &= ~METHOD_IS_GETTER; |
| 240 | } |
| 241 | else { |
| 242 | attributes &= ~METHOD_IS_SETTER; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if (flags & kInstrCanThrow) { |
| 247 | attributes &= ~METHOD_IS_THROW_FREE; |
| 248 | } |
| 249 | |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 250 | if (offset == 0 && dalvikOpcode == OP_RETURN_VOID) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 251 | attributes |= METHOD_IS_EMPTY; |
| 252 | } |
| 253 | |
| Ben Cheng | 34dc796 | 2010-08-26 14:56:31 -0700 | [diff] [blame] | 254 | /* |
| 255 | * Check if this opcode is selected for single stepping. |
| 256 | * If so, don't inline the callee as there is no stack frame for the |
| 257 | * interpreter to single-step through the instruction. |
| 258 | */ |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 259 | if (SINGLE_STEP_OP(dalvikOpcode)) { |
| Ben Cheng | 34dc796 | 2010-08-26 14:56:31 -0700 | [diff] [blame] | 260 | attributes &= ~(METHOD_IS_GETTER | METHOD_IS_SETTER); |
| 261 | } |
| 262 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 263 | return attributes; |
| 264 | } |
| 265 | |
| 266 | /* |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 267 | * Analyze each method whose traces are ever compiled. Collect a variety of |
| 268 | * statistics like the ratio of exercised vs overall code and code bloat |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 269 | * ratios. If isCallee is true, also analyze each instruction in more details |
| 270 | * to see if it is suitable for inlining. |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 271 | */ |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 272 | CompilerMethodStats *dvmCompilerAnalyzeMethodBody(const Method *method, |
| 273 | bool isCallee) |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 274 | { |
| 275 | const DexCode *dexCode = dvmGetMethodCode(method); |
| 276 | const u2 *codePtr = dexCode->insns; |
| 277 | const u2 *codeEnd = dexCode->insns + dexCode->insnsSize; |
| 278 | int insnSize = 0; |
| 279 | int hashValue = dvmComputeUtf8Hash(method->name); |
| 280 | |
| 281 | CompilerMethodStats dummyMethodEntry; // For hash table lookup |
| 282 | CompilerMethodStats *realMethodEntry; // For hash table storage |
| 283 | |
| 284 | /* For lookup only */ |
| 285 | dummyMethodEntry.method = method; |
| Carl Shapiro | fc75f3e | 2010-12-07 11:43:38 -0800 | [diff] [blame] | 286 | realMethodEntry = |
| 287 | (CompilerMethodStats *) dvmHashTableLookup(gDvmJit.methodStatsTable, hashValue, |
| 288 | &dummyMethodEntry, |
| 289 | (HashCompareFunc) compareMethod, |
| 290 | false); |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 291 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 292 | /* This method has never been analyzed before - create an entry */ |
| 293 | if (realMethodEntry == NULL) { |
| 294 | realMethodEntry = |
| 295 | (CompilerMethodStats *) calloc(1, sizeof(CompilerMethodStats)); |
| 296 | realMethodEntry->method = method; |
| 297 | |
| 298 | dvmHashTableLookup(gDvmJit.methodStatsTable, hashValue, |
| 299 | realMethodEntry, |
| 300 | (HashCompareFunc) compareMethod, |
| 301 | true); |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 304 | /* This method is invoked as a callee and has been analyzed - just return */ |
| 305 | if ((isCallee == true) && (realMethodEntry->attributes & METHOD_IS_CALLEE)) |
| 306 | return realMethodEntry; |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 307 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 308 | /* |
| 309 | * Similarly, return if this method has been compiled before as a hot |
| 310 | * method already. |
| 311 | */ |
| 312 | if ((isCallee == false) && |
| 313 | (realMethodEntry->attributes & METHOD_IS_HOT)) |
| 314 | return realMethodEntry; |
| 315 | |
| 316 | int attributes; |
| 317 | |
| 318 | /* Method hasn't been analyzed for the desired purpose yet */ |
| 319 | if (isCallee) { |
| 320 | /* Aggressively set the attributes until proven otherwise */ |
| 321 | attributes = METHOD_IS_LEAF | METHOD_IS_THROW_FREE | METHOD_IS_CALLEE | |
| 322 | METHOD_IS_GETTER | METHOD_IS_SETTER; |
| 323 | } else { |
| 324 | attributes = METHOD_IS_HOT; |
| 325 | } |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 326 | |
| 327 | /* Count the number of instructions */ |
| 328 | while (codePtr < codeEnd) { |
| 329 | DecodedInstruction dalvikInsn; |
| 330 | int width = parseInsn(codePtr, &dalvikInsn, false); |
| 331 | |
| 332 | /* Terminate when the data section is seen */ |
| 333 | if (width == 0) |
| 334 | break; |
| 335 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 336 | if (isCallee) { |
| 337 | attributes = analyzeInlineTarget(&dalvikInsn, attributes, insnSize); |
| 338 | } |
| 339 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 340 | insnSize += width; |
| 341 | codePtr += width; |
| 342 | } |
| 343 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 344 | /* |
| 345 | * Only handle simple getters/setters with one instruction followed by |
| 346 | * return |
| 347 | */ |
| 348 | if ((attributes & (METHOD_IS_GETTER | METHOD_IS_SETTER)) && |
| 349 | (insnSize != 3)) { |
| 350 | attributes &= ~(METHOD_IS_GETTER | METHOD_IS_SETTER); |
| 351 | } |
| 352 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 353 | realMethodEntry->dalvikSize = insnSize * 2; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 354 | realMethodEntry->attributes |= attributes; |
| 355 | |
| 356 | #if 0 |
| 357 | /* Uncomment the following to explore various callee patterns */ |
| 358 | if (attributes & METHOD_IS_THROW_FREE) { |
| 359 | LOGE("%s%s is inlinable%s", method->clazz->descriptor, method->name, |
| 360 | (attributes & METHOD_IS_EMPTY) ? " empty" : ""); |
| 361 | } |
| 362 | |
| 363 | if (attributes & METHOD_IS_LEAF) { |
| 364 | LOGE("%s%s is leaf %d%s", method->clazz->descriptor, method->name, |
| 365 | insnSize, insnSize < 5 ? " (small)" : ""); |
| 366 | } |
| 367 | |
| 368 | if (attributes & (METHOD_IS_GETTER | METHOD_IS_SETTER)) { |
| 369 | LOGE("%s%s is %s", method->clazz->descriptor, method->name, |
| 370 | attributes & METHOD_IS_GETTER ? "getter": "setter"); |
| 371 | } |
| 372 | if (attributes == |
| 373 | (METHOD_IS_LEAF | METHOD_IS_THROW_FREE | METHOD_IS_CALLEE)) { |
| 374 | LOGE("%s%s is inlinable non setter/getter", method->clazz->descriptor, |
| 375 | method->name); |
| 376 | } |
| 377 | #endif |
| 378 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 379 | return realMethodEntry; |
| 380 | } |
| 381 | |
| 382 | /* |
| Ben Cheng | 3367245 | 2010-01-12 14:59:30 -0800 | [diff] [blame] | 383 | * Crawl the stack of the thread that requesed compilation to see if any of the |
| 384 | * ancestors are on the blacklist. |
| 385 | */ |
| Andy McFadden | 953a0ed | 2010-09-17 15:48:38 -0700 | [diff] [blame] | 386 | static bool filterMethodByCallGraph(Thread *thread, const char *curMethodName) |
| Ben Cheng | 3367245 | 2010-01-12 14:59:30 -0800 | [diff] [blame] | 387 | { |
| 388 | /* Crawl the Dalvik stack frames and compare the method name*/ |
| 389 | StackSaveArea *ssaPtr = ((StackSaveArea *) thread->curFrame) - 1; |
| 390 | while (ssaPtr != ((StackSaveArea *) NULL) - 1) { |
| 391 | const Method *method = ssaPtr->method; |
| 392 | if (method) { |
| 393 | int hashValue = dvmComputeUtf8Hash(method->name); |
| 394 | bool found = |
| 395 | dvmHashTableLookup(gDvmJit.methodTable, hashValue, |
| 396 | (char *) method->name, |
| 397 | (HashCompareFunc) strcmp, false) != |
| 398 | NULL; |
| 399 | if (found) { |
| 400 | LOGD("Method %s (--> %s) found on the JIT %s list", |
| 401 | method->name, curMethodName, |
| 402 | gDvmJit.includeSelectedMethod ? "white" : "black"); |
| 403 | return true; |
| 404 | } |
| 405 | |
| 406 | } |
| 407 | ssaPtr = ((StackSaveArea *) ssaPtr->prevFrame) - 1; |
| 408 | }; |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | /* |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 413 | * Main entry point to start trace compilation. Basic blocks are constructed |
| 414 | * first and they will be passed to the codegen routines to convert Dalvik |
| 415 | * bytecode into machine code. |
| 416 | */ |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 417 | bool dvmCompileTrace(JitTraceDescription *desc, int numMaxInsts, |
| Ben Cheng | 4a41958 | 2010-08-04 13:23:09 -0700 | [diff] [blame] | 418 | JitTranslationInfo *info, jmp_buf *bailPtr, |
| 419 | int optHints) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 420 | { |
| 421 | const DexCode *dexCode = dvmGetMethodCode(desc->method); |
| 422 | const JitTraceRun* currRun = &desc->trace[0]; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 423 | unsigned int curOffset = currRun->frag.startOffset; |
| 424 | unsigned int numInsts = currRun->frag.numInsts; |
| 425 | const u2 *codePtr = dexCode->insns + curOffset; |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 426 | int traceSize = 0; // # of half-words |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 427 | const u2 *startCodePtr = codePtr; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 428 | BasicBlock *curBB, *entryCodeBB; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 429 | int numBlocks = 0; |
| 430 | static int compilationId; |
| 431 | CompilationUnit cUnit; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 432 | GrowableList *blockList; |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 433 | #if defined(WITH_JIT_TUNING) |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 434 | CompilerMethodStats *methodStats; |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 435 | #endif |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 436 | |
| Bill Buzbee | 964a7b0 | 2010-01-28 12:54:19 -0800 | [diff] [blame] | 437 | /* If we've already compiled this trace, just return success */ |
| jeffhao | 9e45c0b | 2010-02-03 10:24:05 -0800 | [diff] [blame] | 438 | if (dvmJitGetCodeAddr(startCodePtr) && !info->discardResult) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 439 | /* |
| 440 | * Make sure the codeAddress is NULL so that it won't clobber the |
| 441 | * existing entry. |
| 442 | */ |
| 443 | info->codeAddress = NULL; |
| Bill Buzbee | 964a7b0 | 2010-01-28 12:54:19 -0800 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 447 | compilationId++; |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 448 | memset(&cUnit, 0, sizeof(CompilationUnit)); |
| 449 | |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 450 | #if defined(WITH_JIT_TUNING) |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 451 | /* Locate the entry to store compilation statistics for this method */ |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 452 | methodStats = dvmCompilerAnalyzeMethodBody(desc->method, false); |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 453 | #endif |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 454 | |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 455 | /* Set the recover buffer pointer */ |
| 456 | cUnit.bailPtr = bailPtr; |
| 457 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 458 | /* Initialize the printMe flag */ |
| 459 | cUnit.printMe = gDvmJit.printMe; |
| 460 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 461 | /* Setup the method */ |
| 462 | cUnit.method = desc->method; |
| 463 | |
| 464 | /* Initialize the PC reconstruction list */ |
| 465 | dvmInitGrowableList(&cUnit.pcReconstructionList, 8); |
| 466 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 467 | /* Initialize the basic block list */ |
| 468 | blockList = &cUnit.blockList; |
| 469 | dvmInitGrowableList(blockList, 8); |
| 470 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 471 | /* Identify traces that we don't want to compile */ |
| 472 | if (gDvmJit.methodTable) { |
| 473 | int len = strlen(desc->method->clazz->descriptor) + |
| 474 | strlen(desc->method->name) + 1; |
| Carl Shapiro | fc75f3e | 2010-12-07 11:43:38 -0800 | [diff] [blame] | 475 | char *fullSignature = (char *)dvmCompilerNew(len, true); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 476 | strcpy(fullSignature, desc->method->clazz->descriptor); |
| 477 | strcat(fullSignature, desc->method->name); |
| 478 | |
| 479 | int hashValue = dvmComputeUtf8Hash(fullSignature); |
| 480 | |
| 481 | /* |
| 482 | * Doing three levels of screening to see whether we want to skip |
| 483 | * compiling this method |
| 484 | */ |
| 485 | |
| 486 | /* First, check the full "class;method" signature */ |
| 487 | bool methodFound = |
| 488 | dvmHashTableLookup(gDvmJit.methodTable, hashValue, |
| 489 | fullSignature, (HashCompareFunc) strcmp, |
| 490 | false) != |
| 491 | NULL; |
| 492 | |
| 493 | /* Full signature not found - check the enclosing class */ |
| 494 | if (methodFound == false) { |
| 495 | int hashValue = dvmComputeUtf8Hash(desc->method->clazz->descriptor); |
| 496 | methodFound = |
| 497 | dvmHashTableLookup(gDvmJit.methodTable, hashValue, |
| 498 | (char *) desc->method->clazz->descriptor, |
| 499 | (HashCompareFunc) strcmp, false) != |
| 500 | NULL; |
| 501 | /* Enclosing class not found - check the method name */ |
| 502 | if (methodFound == false) { |
| 503 | int hashValue = dvmComputeUtf8Hash(desc->method->name); |
| 504 | methodFound = |
| 505 | dvmHashTableLookup(gDvmJit.methodTable, hashValue, |
| 506 | (char *) desc->method->name, |
| 507 | (HashCompareFunc) strcmp, false) != |
| 508 | NULL; |
| Ben Cheng | 3367245 | 2010-01-12 14:59:30 -0800 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * Debug by call-graph is enabled. Check if the debug list |
| 512 | * covers any methods on the VM stack. |
| 513 | */ |
| 514 | if (methodFound == false && gDvmJit.checkCallGraph == true) { |
| 515 | methodFound = |
| 516 | filterMethodByCallGraph(info->requestingThread, |
| 517 | desc->method->name); |
| 518 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Under the following conditions, the trace will be *conservatively* |
| 524 | * compiled by only containing single-step instructions to and from the |
| 525 | * interpreter. |
| 526 | * 1) If includeSelectedMethod == false, the method matches the full or |
| 527 | * partial signature stored in the hash table. |
| 528 | * |
| 529 | * 2) If includeSelectedMethod == true, the method does not match the |
| 530 | * full and partial signature stored in the hash table. |
| 531 | */ |
| 532 | if (gDvmJit.includeSelectedMethod != methodFound) { |
| 533 | cUnit.allSingleStep = true; |
| 534 | } else { |
| 535 | /* Compile the trace as normal */ |
| 536 | |
| 537 | /* Print the method we cherry picked */ |
| 538 | if (gDvmJit.includeSelectedMethod == true) { |
| 539 | cUnit.printMe = true; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 544 | /* Allocate the entry block */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 545 | curBB = dvmCompilerNewBB(kTraceEntryBlock, numBlocks++); |
| 546 | dvmInsertGrowableList(blockList, (intptr_t) curBB); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 547 | curBB->startOffset = curOffset; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 548 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 549 | entryCodeBB = dvmCompilerNewBB(kDalvikByteCode, numBlocks++); |
| 550 | dvmInsertGrowableList(blockList, (intptr_t) entryCodeBB); |
| 551 | entryCodeBB->startOffset = curOffset; |
| 552 | curBB->fallThrough = entryCodeBB; |
| 553 | curBB = entryCodeBB; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 554 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 555 | if (cUnit.printMe) { |
| 556 | LOGD("--------\nCompiler: Building trace for %s, offset 0x%x\n", |
| 557 | desc->method->name, curOffset); |
| 558 | } |
| 559 | |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 560 | /* |
| 561 | * Analyze the trace descriptor and include up to the maximal number |
| 562 | * of Dalvik instructions into the IR. |
| 563 | */ |
| 564 | while (1) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 565 | MIR *insn; |
| 566 | int width; |
| Carl Shapiro | fc75f3e | 2010-12-07 11:43:38 -0800 | [diff] [blame] | 567 | insn = (MIR *)dvmCompilerNew(sizeof(MIR), true); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 568 | insn->offset = curOffset; |
| 569 | width = parseInsn(codePtr, &insn->dalvikInsn, cUnit.printMe); |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 570 | |
| 571 | /* The trace should never incude instruction data */ |
| 572 | assert(width); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 573 | insn->width = width; |
| 574 | traceSize += width; |
| 575 | dvmCompilerAppendMIR(curBB, insn); |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 576 | cUnit.numInsts++; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 577 | |
| Dan Bornstein | e485276 | 2010-12-02 12:45:00 -0800 | [diff] [blame] | 578 | int flags = dexGetFlagsFromOpcode(insn->dalvikInsn.opcode); |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 579 | |
| Dan Bornstein | 0759f52 | 2010-11-30 14:58:53 -0800 | [diff] [blame] | 580 | if (flags & kInstrInvoke) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 581 | assert(numInsts == 1); |
| 582 | CallsiteInfo *callsiteInfo = |
| Carl Shapiro | fc75f3e | 2010-12-07 11:43:38 -0800 | [diff] [blame] | 583 | (CallsiteInfo *)dvmCompilerNew(sizeof(CallsiteInfo), true); |
| 584 | callsiteInfo->clazz = (ClassObject *)currRun[1].meta; |
| 585 | callsiteInfo->method = (Method *)currRun[2].meta; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 586 | insn->meta.callsiteInfo = callsiteInfo; |
| 587 | } |
| 588 | |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 589 | /* Instruction limit reached - terminate the trace here */ |
| 590 | if (cUnit.numInsts >= numMaxInsts) { |
| 591 | break; |
| 592 | } |
| 593 | if (--numInsts == 0) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 594 | if (currRun->frag.runEnd) { |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 595 | break; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 596 | } else { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 597 | /* Advance to the next trace description (ie non-meta info) */ |
| 598 | do { |
| 599 | currRun++; |
| 600 | } while (!currRun->frag.isCode); |
| 601 | |
| 602 | /* Dummy end-of-run marker seen */ |
| 603 | if (currRun->frag.numInsts == 0) { |
| 604 | break; |
| 605 | } |
| 606 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 607 | curBB = dvmCompilerNewBB(kDalvikByteCode, numBlocks++); |
| 608 | dvmInsertGrowableList(blockList, (intptr_t) curBB); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 609 | curOffset = currRun->frag.startOffset; |
| 610 | numInsts = currRun->frag.numInsts; |
| 611 | curBB->startOffset = curOffset; |
| 612 | codePtr = dexCode->insns + curOffset; |
| 613 | } |
| 614 | } else { |
| 615 | curOffset += width; |
| 616 | codePtr += width; |
| 617 | } |
| 618 | } |
| 619 | |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 620 | #if defined(WITH_JIT_TUNING) |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 621 | /* Convert # of half-word to bytes */ |
| 622 | methodStats->compiledDalvikSize += traceSize * 2; |
| Ben Cheng | 1357e94 | 2010-02-10 17:21:39 -0800 | [diff] [blame] | 623 | #endif |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 624 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 625 | /* |
| 626 | * Now scan basic blocks containing real code to connect the |
| 627 | * taken/fallthrough links. Also create chaining cells for code not included |
| 628 | * in the trace. |
| 629 | */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 630 | size_t blockId; |
| 631 | for (blockId = 0; blockId < blockList->numUsed; blockId++) { |
| 632 | curBB = (BasicBlock *) dvmGrowableListGetElement(blockList, blockId); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 633 | MIR *lastInsn = curBB->lastMIRInsn; |
| buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame^] | 634 | BasicBlock *backwardCell; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 635 | /* Skip empty blocks */ |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 636 | if (lastInsn == NULL) { |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 637 | continue; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 638 | } |
| 639 | curOffset = lastInsn->offset; |
| 640 | unsigned int targetOffset = curOffset; |
| 641 | unsigned int fallThroughOffset = curOffset + lastInsn->width; |
| 642 | bool isInvoke = false; |
| 643 | const Method *callee = NULL; |
| 644 | |
| 645 | findBlockBoundary(desc->method, curBB->lastMIRInsn, curOffset, |
| 646 | &targetOffset, &isInvoke, &callee); |
| 647 | |
| 648 | /* Link the taken and fallthrough blocks */ |
| 649 | BasicBlock *searchBB; |
| 650 | |
| Dan Bornstein | e485276 | 2010-12-02 12:45:00 -0800 | [diff] [blame] | 651 | int flags = dexGetFlagsFromOpcode(lastInsn->dalvikInsn.opcode); |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 652 | |
| 653 | if (flags & kInstrInvoke) { |
| 654 | cUnit.hasInvoke = true; |
| 655 | } |
| 656 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 657 | /* No backward branch in the trace - start searching the next BB */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 658 | size_t searchBlockId; |
| 659 | for (searchBlockId = blockId+1; searchBlockId < blockList->numUsed; |
| 660 | searchBlockId++) { |
| 661 | searchBB = (BasicBlock *) dvmGrowableListGetElement(blockList, |
| 662 | searchBlockId); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 663 | if (targetOffset == searchBB->startOffset) { |
| 664 | curBB->taken = searchBB; |
| 665 | } |
| 666 | if (fallThroughOffset == searchBB->startOffset) { |
| 667 | curBB->fallThrough = searchBB; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * Fallthrough block of an invoke instruction needs to be |
| 671 | * aligned to 4-byte boundary (alignment instruction to be |
| 672 | * inserted later. |
| 673 | */ |
| 674 | if (flags & kInstrInvoke) { |
| 675 | searchBB->isFallThroughFromInvoke = true; |
| 676 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 680 | /* |
| 681 | * Some blocks are ended by non-control-flow-change instructions, |
| 682 | * currently only due to trace length constraint. In this case we need |
| 683 | * to generate an explicit branch at the end of the block to jump to |
| 684 | * the chaining cell. |
| 685 | */ |
| 686 | curBB->needFallThroughBranch = |
| Ben Cheng | 17f15ce | 2009-07-27 16:21:52 -0700 | [diff] [blame] | 687 | ((flags & (kInstrCanBranch | kInstrCanSwitch | kInstrCanReturn | |
| Dan Bornstein | 0759f52 | 2010-11-30 14:58:53 -0800 | [diff] [blame] | 688 | kInstrInvoke)) == 0); |
| Ben Cheng | 17f15ce | 2009-07-27 16:21:52 -0700 | [diff] [blame] | 689 | |
| Ben Cheng | 4a41958 | 2010-08-04 13:23:09 -0700 | [diff] [blame] | 690 | /* Only form a loop if JIT_OPT_NO_LOOP is not set */ |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 691 | if (curBB->taken == NULL && |
| 692 | curBB->fallThrough == NULL && |
| 693 | flags == (kInstrCanBranch | kInstrCanContinue) && |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 694 | fallThroughOffset == entryCodeBB->startOffset && |
| Ben Cheng | 4a41958 | 2010-08-04 13:23:09 -0700 | [diff] [blame] | 695 | JIT_OPT_NO_LOOP != (optHints & JIT_OPT_NO_LOOP)) { |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 696 | BasicBlock *loopBranch = curBB; |
| 697 | BasicBlock *exitBB; |
| 698 | BasicBlock *exitChainingCell; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 699 | |
| 700 | if (cUnit.printMe) { |
| 701 | LOGD("Natural loop detected!"); |
| 702 | } |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 703 | exitBB = dvmCompilerNewBB(kTraceExitBlock, numBlocks++); |
| 704 | dvmInsertGrowableList(blockList, (intptr_t) exitBB); |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 705 | exitBB->startOffset = targetOffset; |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 706 | exitBB->needFallThroughBranch = true; |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 707 | |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 708 | loopBranch->taken = exitBB; |
| buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame^] | 709 | backwardCell = |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 710 | dvmCompilerNewBB(kChainingCellBackwardBranch, numBlocks++); |
| 711 | dvmInsertGrowableList(blockList, (intptr_t) backwardCell); |
| 712 | backwardCell->startOffset = entryCodeBB->startOffset; |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 713 | loopBranch->fallThrough = backwardCell; |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 714 | |
| 715 | /* Create the chaining cell as the fallthrough of the exit block */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 716 | exitChainingCell = dvmCompilerNewBB(kChainingCellNormal, |
| 717 | numBlocks++); |
| 718 | dvmInsertGrowableList(blockList, (intptr_t) exitChainingCell); |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 719 | exitChainingCell->startOffset = targetOffset; |
| Ben Cheng | 0fd31e4 | 2009-09-03 14:40:16 -0700 | [diff] [blame] | 720 | |
| 721 | exitBB->fallThrough = exitChainingCell; |
| 722 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 723 | cUnit.hasLoop = true; |
| 724 | } |
| 725 | |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 726 | if (lastInsn->dalvikInsn.opcode == OP_PACKED_SWITCH || |
| 727 | lastInsn->dalvikInsn.opcode == OP_SPARSE_SWITCH) { |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 728 | int i; |
| 729 | const u2 *switchData = desc->method->insns + lastInsn->offset + |
| 730 | lastInsn->dalvikInsn.vB; |
| 731 | int size = switchData[1]; |
| 732 | int maxChains = MIN(size, MAX_CHAINED_SWITCH_CASES); |
| 733 | |
| 734 | /* |
| 735 | * Generate the landing pad for cases whose ranks are higher than |
| 736 | * MAX_CHAINED_SWITCH_CASES. The code will re-enter the interpreter |
| 737 | * through the NoChain point. |
| 738 | */ |
| 739 | if (maxChains != size) { |
| 740 | cUnit.switchOverflowPad = |
| 741 | desc->method->insns + lastInsn->offset; |
| 742 | } |
| 743 | |
| 744 | s4 *targets = (s4 *) (switchData + 2 + |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 745 | (lastInsn->dalvikInsn.opcode == OP_PACKED_SWITCH ? |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 746 | 2 : size * 2)); |
| 747 | |
| 748 | /* One chaining cell for the first MAX_CHAINED_SWITCH_CASES cases */ |
| 749 | for (i = 0; i < maxChains; i++) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 750 | BasicBlock *caseChain = dvmCompilerNewBB(kChainingCellNormal, |
| 751 | numBlocks++); |
| 752 | dvmInsertGrowableList(blockList, (intptr_t) caseChain); |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 753 | caseChain->startOffset = lastInsn->offset + targets[i]; |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /* One more chaining cell for the default case */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 757 | BasicBlock *caseChain = dvmCompilerNewBB(kChainingCellNormal, |
| 758 | numBlocks++); |
| 759 | dvmInsertGrowableList(blockList, (intptr_t) caseChain); |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 760 | caseChain->startOffset = lastInsn->offset + lastInsn->width; |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame] | 761 | /* Fallthrough block not included in the trace */ |
| Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 762 | } else if (!isUnconditionalBranch(lastInsn) && |
| 763 | curBB->fallThrough == NULL) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 764 | BasicBlock *fallThroughBB; |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame] | 765 | /* |
| 766 | * If the chaining cell is after an invoke or |
| 767 | * instruction that cannot change the control flow, request a hot |
| 768 | * chaining cell. |
| 769 | */ |
| 770 | if (isInvoke || curBB->needFallThroughBranch) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 771 | fallThroughBB = dvmCompilerNewBB(kChainingCellHot, numBlocks++); |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame] | 772 | } else { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 773 | fallThroughBB = dvmCompilerNewBB(kChainingCellNormal, |
| 774 | numBlocks++); |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame] | 775 | } |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 776 | dvmInsertGrowableList(blockList, (intptr_t) fallThroughBB); |
| 777 | fallThroughBB->startOffset = fallThroughOffset; |
| 778 | curBB->fallThrough = fallThroughBB; |
| Ben Cheng | 6d57609 | 2009-09-01 17:01:58 -0700 | [diff] [blame] | 779 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 780 | /* Target block not included in the trace */ |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 781 | if (curBB->taken == NULL && |
| Bill Buzbee | 324b3ac | 2009-12-04 13:17:36 -0800 | [diff] [blame] | 782 | (isGoto(lastInsn) || isInvoke || |
| 783 | (targetOffset != UNKNOWN_TARGET && targetOffset != curOffset))) { |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 784 | BasicBlock *newBB; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 785 | if (isInvoke) { |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 786 | /* Monomorphic callee */ |
| 787 | if (callee) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 788 | newBB = dvmCompilerNewBB(kChainingCellInvokeSingleton, |
| 789 | numBlocks++); |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 790 | newBB->startOffset = 0; |
| 791 | newBB->containingMethod = callee; |
| 792 | /* Will resolve at runtime */ |
| 793 | } else { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 794 | newBB = dvmCompilerNewBB(kChainingCellInvokePredicted, |
| 795 | numBlocks++); |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 796 | newBB->startOffset = 0; |
| 797 | } |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 798 | /* For unconditional branches, request a hot chaining cell */ |
| 799 | } else { |
| Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame] | 800 | #if !defined(WITH_SELF_VERIFICATION) |
| Dan Bornstein | c2b486f | 2010-11-12 16:07:16 -0800 | [diff] [blame] | 801 | newBB = dvmCompilerNewBB(dexIsGoto(flags) ? |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 802 | kChainingCellHot : |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 803 | kChainingCellNormal, |
| 804 | numBlocks++); |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 805 | newBB->startOffset = targetOffset; |
| Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame] | 806 | #else |
| 807 | /* Handle branches that branch back into the block */ |
| 808 | if (targetOffset >= curBB->firstMIRInsn->offset && |
| 809 | targetOffset <= curBB->lastMIRInsn->offset) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 810 | newBB = dvmCompilerNewBB(kChainingCellBackwardBranch, |
| 811 | numBlocks++); |
| Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame] | 812 | } else { |
| Dan Bornstein | c2b486f | 2010-11-12 16:07:16 -0800 | [diff] [blame] | 813 | newBB = dvmCompilerNewBB(dexIsGoto(flags) ? |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 814 | kChainingCellHot : |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 815 | kChainingCellNormal, |
| 816 | numBlocks++); |
| Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame] | 817 | } |
| 818 | newBB->startOffset = targetOffset; |
| 819 | #endif |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 820 | } |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 821 | curBB->taken = newBB; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 822 | dvmInsertGrowableList(blockList, (intptr_t) newBB); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 823 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /* Now create a special block to host PC reconstruction code */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 827 | curBB = dvmCompilerNewBB(kPCReconstruction, numBlocks++); |
| 828 | dvmInsertGrowableList(blockList, (intptr_t) curBB); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 829 | |
| 830 | /* And one final block that publishes the PC and raise the exception */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 831 | curBB = dvmCompilerNewBB(kExceptionHandling, numBlocks++); |
| 832 | dvmInsertGrowableList(blockList, (intptr_t) curBB); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 833 | |
| 834 | if (cUnit.printMe) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 835 | char* signature = |
| 836 | dexProtoCopyMethodDescriptor(&desc->method->prototype); |
| Elliott Hughes | cc6fac8 | 2010-07-02 13:38:44 -0700 | [diff] [blame] | 837 | LOGD("TRACEINFO (%d): 0x%08x %s%s.%s 0x%x %d of %d, %d blocks", |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 838 | compilationId, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 839 | (intptr_t) desc->method->insns, |
| 840 | desc->method->clazz->descriptor, |
| 841 | desc->method->name, |
| Elliott Hughes | cc6fac8 | 2010-07-02 13:38:44 -0700 | [diff] [blame] | 842 | signature, |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 843 | desc->trace[0].frag.startOffset, |
| 844 | traceSize, |
| 845 | dexCode->insnsSize, |
| 846 | numBlocks); |
| Elliott Hughes | cc6fac8 | 2010-07-02 13:38:44 -0700 | [diff] [blame] | 847 | free(signature); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 850 | cUnit.traceDesc = desc; |
| 851 | cUnit.numBlocks = numBlocks; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 852 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 853 | /* Set the instruction set to use (NOTE: later components may change it) */ |
| 854 | cUnit.instructionSet = dvmCompilerInstructionSet(); |
| 855 | |
| 856 | /* Inline transformation @ the MIR level */ |
| 857 | if (cUnit.hasInvoke && !(gDvmJit.disableOpt & (1 << kMethodInlining))) { |
| 858 | dvmCompilerInlineMIR(&cUnit); |
| 859 | } |
| 860 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 861 | cUnit.numDalvikRegisters = cUnit.method->registersSize; |
| 862 | |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 863 | /* Preparation for SSA conversion */ |
| 864 | dvmInitializeSSAConversion(&cUnit); |
| 865 | |
| 866 | if (cUnit.hasLoop) { |
| Ben Cheng | 4a41958 | 2010-08-04 13:23:09 -0700 | [diff] [blame] | 867 | /* |
| 868 | * Loop is not optimizable (for example lack of a single induction |
| 869 | * variable), punt and recompile the trace with loop optimization |
| 870 | * disabled. |
| 871 | */ |
| 872 | bool loopOpt = dvmCompilerLoopOpt(&cUnit); |
| 873 | if (loopOpt == false) { |
| 874 | if (cUnit.printMe) { |
| 875 | LOGD("Loop is not optimizable - retry codegen"); |
| 876 | } |
| 877 | /* Reset the compiler resource pool */ |
| 878 | dvmCompilerArenaReset(); |
| 879 | return dvmCompileTrace(desc, cUnit.numInsts, info, bailPtr, |
| 880 | optHints | JIT_OPT_NO_LOOP); |
| 881 | } |
| Ben Cheng | 4238ec2 | 2009-08-24 16:32:22 -0700 | [diff] [blame] | 882 | } |
| 883 | else { |
| 884 | dvmCompilerNonLoopAnalysis(&cUnit); |
| 885 | } |
| 886 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 887 | dvmCompilerInitializeRegAlloc(&cUnit); // Needs to happen after SSA naming |
| 888 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 889 | if (cUnit.printMe) { |
| 890 | dvmCompilerDumpCompilationUnit(&cUnit); |
| 891 | } |
| 892 | |
| buzbee | 23d95d0 | 2010-12-14 13:16:43 -0800 | [diff] [blame] | 893 | /* Allocate Registers using simple local allocation scheme */ |
| 894 | dvmCompilerLocalRegAlloc(&cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 895 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 896 | /* Convert MIR to LIR, etc. */ |
| 897 | dvmCompilerMIR2LIR(&cUnit); |
| 898 | |
| buzbee | bff121a | 2010-08-04 15:25:06 -0700 | [diff] [blame] | 899 | /* Convert LIR into machine code. Loop for recoverable retries */ |
| 900 | do { |
| 901 | dvmCompilerAssembleLIR(&cUnit, info); |
| 902 | cUnit.assemblerRetries++; |
| 903 | if (cUnit.printMe && cUnit.assemblerStatus != kSuccess) |
| 904 | LOGD("Assembler abort #%d on %d",cUnit.assemblerRetries, |
| 905 | cUnit.assemblerStatus); |
| 906 | } while (cUnit.assemblerStatus == kRetryAll); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 907 | |
| 908 | if (cUnit.printMe) { |
| buzbee | bff121a | 2010-08-04 15:25:06 -0700 | [diff] [blame] | 909 | dvmCompilerCodegenDump(&cUnit); |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 910 | LOGD("End %s%s, %d Dalvik instructions", |
| 911 | desc->method->clazz->descriptor, desc->method->name, |
| 912 | cUnit.numInsts); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* Reset the compiler resource pool */ |
| 916 | dvmCompilerArenaReset(); |
| 917 | |
| buzbee | bff121a | 2010-08-04 15:25:06 -0700 | [diff] [blame] | 918 | if (cUnit.assemblerStatus == kRetryHalve) { |
| 919 | /* Halve the instruction count and start from the top */ |
| Ben Cheng | 4a41958 | 2010-08-04 13:23:09 -0700 | [diff] [blame] | 920 | return dvmCompileTrace(desc, cUnit.numInsts / 2, info, bailPtr, |
| 921 | optHints); |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 922 | } |
| buzbee | bff121a | 2010-08-04 15:25:06 -0700 | [diff] [blame] | 923 | |
| 924 | assert(cUnit.assemblerStatus == kSuccess); |
| 925 | #if defined(WITH_JIT_TUNING) |
| 926 | methodStats->nativeSize += cUnit.totalSize; |
| 927 | #endif |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 928 | |
| 929 | /* FIXME - to exercise the method parser, uncomment the following code */ |
| 930 | #if 0 |
| 931 | bool dvmCompileMethod(const Method *method); |
| 932 | if (desc->trace[0].frag.startOffset == 0) { |
| 933 | dvmCompileMethod(desc->method); |
| 934 | } |
| 935 | #endif |
| 936 | |
| buzbee | bff121a | 2010-08-04 15:25:06 -0700 | [diff] [blame] | 937 | return info->codeAddress != NULL; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 941 | * Since we are including instructions from possibly a cold method into the |
| 942 | * current trace, we need to make sure that all the associated information |
| 943 | * with the callee is properly initialized. If not, we punt on this inline |
| 944 | * target. |
| 945 | * |
| Ben Cheng | 34dc796 | 2010-08-26 14:56:31 -0700 | [diff] [blame] | 946 | * TODO: volatile instructions will be handled later. |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 947 | */ |
| 948 | bool dvmCompilerCanIncludeThisInstruction(const Method *method, |
| 949 | const DecodedInstruction *insn) |
| 950 | { |
| Dan Bornstein | 9a1f816 | 2010-12-01 17:02:26 -0800 | [diff] [blame] | 951 | switch (insn->opcode) { |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 952 | case OP_NEW_INSTANCE: |
| 953 | case OP_CHECK_CAST: { |
| Carl Shapiro | fc75f3e | 2010-12-07 11:43:38 -0800 | [diff] [blame] | 954 | ClassObject *classPtr = (ClassObject *)(void*) |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 955 | (method->clazz->pDvmDex->pResClasses[insn->vB]); |
| 956 | |
| 957 | /* Class hasn't been initialized yet */ |
| 958 | if (classPtr == NULL) { |
| 959 | return false; |
| 960 | } |
| 961 | return true; |
| 962 | } |
| 963 | case OP_SGET_OBJECT: |
| 964 | case OP_SGET_BOOLEAN: |
| 965 | case OP_SGET_CHAR: |
| 966 | case OP_SGET_BYTE: |
| 967 | case OP_SGET_SHORT: |
| 968 | case OP_SGET: |
| 969 | case OP_SGET_WIDE: |
| 970 | case OP_SPUT_OBJECT: |
| 971 | case OP_SPUT_BOOLEAN: |
| 972 | case OP_SPUT_CHAR: |
| 973 | case OP_SPUT_BYTE: |
| 974 | case OP_SPUT_SHORT: |
| 975 | case OP_SPUT: |
| 976 | case OP_SPUT_WIDE: { |
| 977 | void *fieldPtr = (void*) |
| 978 | (method->clazz->pDvmDex->pResFields[insn->vB]); |
| 979 | |
| 980 | if (fieldPtr == NULL) { |
| 981 | return false; |
| 982 | } |
| 983 | return true; |
| 984 | } |
| 985 | case OP_INVOKE_SUPER: |
| 986 | case OP_INVOKE_SUPER_RANGE: { |
| 987 | int mIndex = method->clazz->pDvmDex-> |
| 988 | pResMethods[insn->vB]->methodIndex; |
| 989 | const Method *calleeMethod = method->clazz->super->vtable[mIndex]; |
| 990 | if (calleeMethod == NULL) { |
| 991 | return false; |
| 992 | } |
| 993 | return true; |
| 994 | } |
| 995 | case OP_INVOKE_SUPER_QUICK: |
| 996 | case OP_INVOKE_SUPER_QUICK_RANGE: { |
| 997 | const Method *calleeMethod = method->clazz->super->vtable[insn->vB]; |
| 998 | if (calleeMethod == NULL) { |
| 999 | return false; |
| 1000 | } |
| 1001 | return true; |
| 1002 | } |
| 1003 | case OP_INVOKE_STATIC: |
| 1004 | case OP_INVOKE_STATIC_RANGE: |
| 1005 | case OP_INVOKE_DIRECT: |
| 1006 | case OP_INVOKE_DIRECT_RANGE: { |
| 1007 | const Method *calleeMethod = |
| 1008 | method->clazz->pDvmDex->pResMethods[insn->vB]; |
| 1009 | if (calleeMethod == NULL) { |
| 1010 | return false; |
| 1011 | } |
| 1012 | return true; |
| 1013 | } |
| 1014 | case OP_CONST_CLASS: { |
| 1015 | void *classPtr = (void*) |
| 1016 | (method->clazz->pDvmDex->pResClasses[insn->vB]); |
| 1017 | |
| 1018 | if (classPtr == NULL) { |
| 1019 | return false; |
| 1020 | } |
| 1021 | return true; |
| 1022 | } |
| 1023 | case OP_CONST_STRING_JUMBO: |
| 1024 | case OP_CONST_STRING: { |
| 1025 | void *strPtr = (void*) |
| 1026 | (method->clazz->pDvmDex->pResStrings[insn->vB]); |
| 1027 | |
| 1028 | if (strPtr == NULL) { |
| 1029 | return false; |
| 1030 | } |
| 1031 | return true; |
| 1032 | } |
| 1033 | default: |
| 1034 | return true; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1038 | /* Split an existing block from the specified code offset into two */ |
| 1039 | static BasicBlock *splitBlock(CompilationUnit *cUnit, |
| 1040 | unsigned int codeOffset, |
| 1041 | BasicBlock *origBlock) |
| 1042 | { |
| 1043 | MIR *insn = origBlock->firstMIRInsn; |
| 1044 | while (insn) { |
| 1045 | if (insn->offset == codeOffset) break; |
| 1046 | insn = insn->next; |
| 1047 | } |
| 1048 | if (insn == NULL) { |
| 1049 | LOGE("Break split failed"); |
| 1050 | dvmAbort(); |
| 1051 | } |
| 1052 | BasicBlock *bottomBlock = dvmCompilerNewBB(kDalvikByteCode, |
| 1053 | cUnit->numBlocks++); |
| 1054 | dvmInsertGrowableList(&cUnit->blockList, (intptr_t) bottomBlock); |
| 1055 | |
| 1056 | bottomBlock->startOffset = codeOffset; |
| 1057 | bottomBlock->firstMIRInsn = insn; |
| 1058 | bottomBlock->lastMIRInsn = origBlock->lastMIRInsn; |
| 1059 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1060 | /* Handle the taken path */ |
| 1061 | bottomBlock->taken = origBlock->taken; |
| 1062 | if (bottomBlock->taken) { |
| 1063 | origBlock->taken = NULL; |
| 1064 | dvmCompilerClearBit(bottomBlock->taken->predecessors, origBlock->id); |
| 1065 | dvmCompilerSetBit(bottomBlock->taken->predecessors, bottomBlock->id); |
| 1066 | } |
| 1067 | |
| 1068 | /* Handle the fallthrough path */ |
| 1069 | bottomBlock->fallThrough = origBlock->fallThrough; |
| 1070 | origBlock->fallThrough = bottomBlock; |
| 1071 | dvmCompilerSetBit(bottomBlock->predecessors, origBlock->id); |
| 1072 | if (bottomBlock->fallThrough) { |
| 1073 | dvmCompilerClearBit(bottomBlock->fallThrough->predecessors, |
| 1074 | origBlock->id); |
| 1075 | dvmCompilerSetBit(bottomBlock->fallThrough->predecessors, |
| 1076 | bottomBlock->id); |
| 1077 | } |
| 1078 | |
| 1079 | /* Handle the successor list */ |
| 1080 | if (origBlock->successorBlockList.blockListType != kNotUsed) { |
| 1081 | bottomBlock->successorBlockList = origBlock->successorBlockList; |
| 1082 | origBlock->successorBlockList.blockListType = kNotUsed; |
| 1083 | GrowableListIterator iterator; |
| 1084 | |
| 1085 | dvmGrowableListIteratorInit(&bottomBlock->successorBlockList.blocks, |
| 1086 | &iterator); |
| 1087 | while (true) { |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1088 | SuccessorBlockInfo *successorBlockInfo = |
| 1089 | (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator); |
| 1090 | if (successorBlockInfo == NULL) break; |
| 1091 | BasicBlock *bb = successorBlockInfo->block; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1092 | dvmCompilerClearBit(bb->predecessors, origBlock->id); |
| 1093 | dvmCompilerSetBit(bb->predecessors, bottomBlock->id); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | origBlock->lastMIRInsn = insn->prev; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1098 | |
| 1099 | insn->prev->next = NULL; |
| 1100 | insn->prev = NULL; |
| 1101 | return bottomBlock; |
| 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * Given a code offset, find out the block that starts with it. If the offset |
| 1106 | * is in the middle of an existing block, split it into two. |
| 1107 | */ |
| 1108 | static BasicBlock *findBlock(CompilationUnit *cUnit, |
| 1109 | unsigned int codeOffset, |
| 1110 | bool split, bool create) |
| 1111 | { |
| 1112 | GrowableList *blockList = &cUnit->blockList; |
| 1113 | BasicBlock *bb; |
| 1114 | unsigned int i; |
| 1115 | |
| 1116 | for (i = 0; i < blockList->numUsed; i++) { |
| 1117 | bb = (BasicBlock *) blockList->elemList[i]; |
| 1118 | if (bb->blockType != kDalvikByteCode) continue; |
| 1119 | if (bb->startOffset == codeOffset) return bb; |
| 1120 | /* Check if a branch jumps into the middle of an existing block */ |
| 1121 | if ((split == true) && (codeOffset > bb->startOffset) && |
| 1122 | (bb->lastMIRInsn != NULL) && |
| 1123 | (codeOffset <= bb->lastMIRInsn->offset)) { |
| 1124 | BasicBlock *newBB = splitBlock(cUnit, codeOffset, bb); |
| 1125 | return newBB; |
| 1126 | } |
| 1127 | } |
| 1128 | if (create) { |
| 1129 | bb = dvmCompilerNewBB(kDalvikByteCode, cUnit->numBlocks++); |
| 1130 | dvmInsertGrowableList(&cUnit->blockList, (intptr_t) bb); |
| 1131 | bb->startOffset = codeOffset; |
| 1132 | return bb; |
| 1133 | } |
| 1134 | return NULL; |
| 1135 | } |
| 1136 | |
| 1137 | /* Dump the CFG into a DOT graph */ |
| 1138 | void dumpCFG(CompilationUnit *cUnit, const char *dirPrefix) |
| 1139 | { |
| 1140 | const Method *method = cUnit->method; |
| 1141 | FILE *file; |
| 1142 | char* signature = dexProtoCopyMethodDescriptor(&method->prototype); |
| 1143 | char *fileName = (char *) dvmCompilerNew( |
| 1144 | strlen(dirPrefix) + |
| 1145 | strlen(method->clazz->descriptor) + |
| 1146 | strlen(method->name) + |
| 1147 | strlen(signature) + |
| 1148 | strlen(".dot") + 1, true); |
| 1149 | sprintf(fileName, "%s%s%s%s.dot", dirPrefix, |
| 1150 | method->clazz->descriptor, method->name, signature); |
| 1151 | free(signature); |
| 1152 | |
| 1153 | /* |
| 1154 | * Convert the special characters into a filesystem- and shell-friendly |
| 1155 | * format. |
| 1156 | */ |
| 1157 | int i; |
| 1158 | for (i = strlen(dirPrefix); fileName[i]; i++) { |
| 1159 | if (fileName[i] == '/') { |
| 1160 | fileName[i] = '_'; |
| 1161 | } else if (fileName[i] == ';') { |
| 1162 | fileName[i] = '#'; |
| 1163 | } else if (fileName[i] == '$') { |
| 1164 | fileName[i] = '+'; |
| 1165 | } else if (fileName[i] == '(' || fileName[i] == ')') { |
| 1166 | fileName[i] = '@'; |
| 1167 | } else if (fileName[i] == '<' || fileName[i] == '>') { |
| 1168 | fileName[i] = '='; |
| 1169 | } |
| 1170 | } |
| 1171 | file = fopen(fileName, "w"); |
| 1172 | if (file == NULL) { |
| 1173 | return; |
| 1174 | } |
| 1175 | fprintf(file, "digraph G {\n"); |
| 1176 | |
| 1177 | fprintf(file, " rankdir=TB\n"); |
| 1178 | |
| 1179 | int numReachableBlocks = cUnit->numReachableBlocks; |
| 1180 | int idx; |
| 1181 | const GrowableList *blockList = &cUnit->blockList; |
| 1182 | |
| 1183 | for (idx = 0; idx < numReachableBlocks; idx++) { |
| 1184 | int blockIdx = cUnit->dfsOrder.elemList[idx]; |
| 1185 | BasicBlock *bb = (BasicBlock *) dvmGrowableListGetElement(blockList, |
| 1186 | blockIdx); |
| 1187 | if (bb == NULL) break; |
| 1188 | if (bb->blockType == kMethodEntryBlock) { |
| 1189 | fprintf(file, " entry [shape=Mdiamond];\n"); |
| 1190 | } else if (bb->blockType == kMethodExitBlock) { |
| 1191 | fprintf(file, " exit [shape=Mdiamond];\n"); |
| 1192 | } else if (bb->blockType == kDalvikByteCode) { |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1193 | fprintf(file, " block%04x [shape=record,label = \"{ \\\n", |
| 1194 | bb->startOffset); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1195 | const MIR *mir; |
| 1196 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 1197 | fprintf(file, " {%04x %s\\l}%s\\\n", mir->offset, |
| 1198 | dvmCompilerFullDisassembler(cUnit, mir), |
| 1199 | mir->next ? " | " : " "); |
| 1200 | } |
| 1201 | fprintf(file, " }\"];\n\n"); |
| 1202 | } else if (bb->blockType == kExceptionHandling) { |
| 1203 | char blockName[BLOCK_NAME_LEN]; |
| 1204 | |
| 1205 | dvmGetBlockName(bb, blockName); |
| 1206 | fprintf(file, " %s [shape=invhouse];\n", blockName); |
| 1207 | } |
| 1208 | |
| 1209 | char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN]; |
| 1210 | |
| 1211 | if (bb->taken) { |
| 1212 | dvmGetBlockName(bb, blockName1); |
| 1213 | dvmGetBlockName(bb->taken, blockName2); |
| 1214 | fprintf(file, " %s:s -> %s:n [style=dotted]\n", |
| 1215 | blockName1, blockName2); |
| 1216 | } |
| 1217 | if (bb->fallThrough) { |
| 1218 | dvmGetBlockName(bb, blockName1); |
| 1219 | dvmGetBlockName(bb->fallThrough, blockName2); |
| 1220 | fprintf(file, " %s:s -> %s:n\n", blockName1, blockName2); |
| 1221 | } |
| 1222 | |
| 1223 | if (bb->successorBlockList.blockListType != kNotUsed) { |
| 1224 | fprintf(file, " succ%04x [shape=%s,label = \"{ \\\n", |
| 1225 | bb->startOffset, |
| 1226 | (bb->successorBlockList.blockListType == kCatch) ? |
| 1227 | "Mrecord" : "record"); |
| 1228 | GrowableListIterator iterator; |
| 1229 | dvmGrowableListIteratorInit(&bb->successorBlockList.blocks, |
| 1230 | &iterator); |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1231 | SuccessorBlockInfo *successorBlockInfo = |
| 1232 | (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1233 | |
| 1234 | int succId = 0; |
| 1235 | while (true) { |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1236 | if (successorBlockInfo == NULL) break; |
| 1237 | |
| 1238 | BasicBlock *destBlock = successorBlockInfo->block; |
| 1239 | SuccessorBlockInfo *nextSuccessorBlockInfo = |
| 1240 | (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator); |
| 1241 | |
| 1242 | fprintf(file, " {<f%d> %04x: %04x\\l}%s\\\n", |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1243 | succId++, |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1244 | successorBlockInfo->key, |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1245 | destBlock->startOffset, |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1246 | (nextSuccessorBlockInfo != NULL) ? " | " : " "); |
| 1247 | |
| 1248 | successorBlockInfo = nextSuccessorBlockInfo; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1249 | } |
| 1250 | fprintf(file, " }\"];\n\n"); |
| 1251 | |
| 1252 | dvmGetBlockName(bb, blockName1); |
| 1253 | fprintf(file, " %s:s -> succ%04x:n [style=dashed]\n", |
| 1254 | blockName1, bb->startOffset); |
| 1255 | |
| 1256 | if (bb->successorBlockList.blockListType == kPackedSwitch || |
| 1257 | bb->successorBlockList.blockListType == kSparseSwitch) { |
| 1258 | |
| 1259 | dvmGrowableListIteratorInit(&bb->successorBlockList.blocks, |
| 1260 | &iterator); |
| 1261 | |
| 1262 | succId = 0; |
| 1263 | while (true) { |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1264 | SuccessorBlockInfo *successorBlockInfo = |
| 1265 | (SuccessorBlockInfo *) |
| 1266 | dvmGrowableListIteratorNext(&iterator); |
| 1267 | if (successorBlockInfo == NULL) break; |
| 1268 | |
| 1269 | BasicBlock *destBlock = successorBlockInfo->block; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1270 | |
| 1271 | dvmGetBlockName(destBlock, blockName2); |
| 1272 | fprintf(file, " succ%04x:f%d:e -> %s:n\n", |
| 1273 | bb->startOffset, succId++, |
| 1274 | blockName2); |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | fprintf(file, "\n"); |
| 1279 | |
| 1280 | /* |
| 1281 | * If we need to debug the dominator tree, uncomment the following code |
| 1282 | */ |
| 1283 | #if 0 |
| 1284 | dvmGetBlockName(bb, blockName1); |
| 1285 | fprintf(file, " cfg%s [label=\"%s\", shape=none];\n", |
| 1286 | blockName1, blockName1); |
| 1287 | if (bb->iDom) { |
| 1288 | dvmGetBlockName(bb->iDom, blockName2); |
| 1289 | fprintf(file, " cfg%s:s -> cfg%s:n\n\n", |
| 1290 | blockName2, blockName1); |
| 1291 | } |
| 1292 | #endif |
| 1293 | } |
| 1294 | fprintf(file, "}\n"); |
| 1295 | fclose(file); |
| 1296 | } |
| 1297 | |
| 1298 | /* Verify if all the successor is connected with all the claimed predecessors */ |
| 1299 | static bool verifyPredInfo(CompilationUnit *cUnit, BasicBlock *bb) |
| 1300 | { |
| 1301 | BitVectorIterator bvIterator; |
| 1302 | |
| 1303 | dvmBitVectorIteratorInit(bb->predecessors, &bvIterator); |
| 1304 | while (true) { |
| 1305 | int blockIdx = dvmBitVectorIteratorNext(&bvIterator); |
| 1306 | if (blockIdx == -1) break; |
| 1307 | BasicBlock *predBB = (BasicBlock *) |
| 1308 | dvmGrowableListGetElement(&cUnit->blockList, blockIdx); |
| 1309 | bool found = false; |
| 1310 | if (predBB->taken == bb) { |
| 1311 | found = true; |
| 1312 | } else if (predBB->fallThrough == bb) { |
| 1313 | found = true; |
| 1314 | } else if (predBB->successorBlockList.blockListType != kNotUsed) { |
| 1315 | GrowableListIterator iterator; |
| 1316 | dvmGrowableListIteratorInit(&predBB->successorBlockList.blocks, |
| 1317 | &iterator); |
| 1318 | while (true) { |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1319 | SuccessorBlockInfo *successorBlockInfo = |
| 1320 | (SuccessorBlockInfo *) |
| 1321 | dvmGrowableListIteratorNext(&iterator); |
| 1322 | if (successorBlockInfo == NULL) break; |
| 1323 | BasicBlock *succBB = successorBlockInfo->block; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1324 | if (succBB == bb) { |
| 1325 | found = true; |
| 1326 | break; |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | if (found == false) { |
| 1331 | char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN]; |
| 1332 | dvmGetBlockName(bb, blockName1); |
| 1333 | dvmGetBlockName(predBB, blockName2); |
| 1334 | dumpCFG(cUnit, "/data/tombstones/"); |
| 1335 | LOGE("Successor %s not found from %s", |
| 1336 | blockName1, blockName2); |
| 1337 | dvmAbort(); |
| 1338 | } |
| 1339 | } |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | /* Identify code range in try blocks and set up the empty catch blocks */ |
| 1344 | static void processTryCatchBlocks(CompilationUnit *cUnit) |
| 1345 | { |
| 1346 | const Method *meth = cUnit->method; |
| 1347 | const DexCode *pCode = dvmGetMethodCode(meth); |
| 1348 | int triesSize = pCode->triesSize; |
| 1349 | int i; |
| 1350 | int offset; |
| 1351 | |
| 1352 | if (triesSize == 0) { |
| 1353 | return; |
| 1354 | } |
| 1355 | |
| 1356 | const DexTry *pTries = dexGetTries(pCode); |
| 1357 | BitVector *tryBlockAddr = cUnit->tryBlockAddr; |
| 1358 | |
| 1359 | /* Mark all the insn offsets in Try blocks */ |
| 1360 | for (i = 0; i < triesSize; i++) { |
| 1361 | const DexTry* pTry = &pTries[i]; |
| 1362 | /* all in 16-bit units */ |
| 1363 | int startOffset = pTry->startAddr; |
| 1364 | int endOffset = startOffset + pTry->insnCount; |
| 1365 | |
| 1366 | for (offset = startOffset; offset < endOffset; offset++) { |
| 1367 | dvmCompilerSetBit(tryBlockAddr, offset); |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /* Iterate over each of the handlers to enqueue the empty Catch blocks */ |
| 1372 | offset = dexGetFirstHandlerOffset(pCode); |
| 1373 | int handlersSize = dexGetHandlersSize(pCode); |
| 1374 | |
| 1375 | for (i = 0; i < handlersSize; i++) { |
| 1376 | DexCatchIterator iterator; |
| 1377 | dexCatchIteratorInit(&iterator, pCode, offset); |
| 1378 | |
| 1379 | for (;;) { |
| 1380 | DexCatchHandler* handler = dexCatchIteratorNext(&iterator); |
| 1381 | |
| 1382 | if (handler == NULL) { |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1386 | /* |
| 1387 | * Create dummy catch blocks first. Since these are created before |
| 1388 | * other blocks are processed, "split" is specified as false. |
| 1389 | */ |
| 1390 | findBlock(cUnit, handler->address, |
| 1391 | /* split */ |
| 1392 | false, |
| 1393 | /* create */ |
| 1394 | true); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | offset = dexCatchIteratorGetEndOffset(&iterator, pCode); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | /* Process instructions with the kInstrCanBranch flag */ |
| 1402 | static void processCanBranch(CompilationUnit *cUnit, BasicBlock *curBlock, |
| 1403 | MIR *insn, int curOffset, int width, int flags, |
| 1404 | const u2* codePtr, const u2* codeEnd) |
| 1405 | { |
| 1406 | int target = curOffset; |
| 1407 | switch (insn->dalvikInsn.opcode) { |
| 1408 | case OP_GOTO: |
| 1409 | case OP_GOTO_16: |
| 1410 | case OP_GOTO_32: |
| 1411 | target += (int) insn->dalvikInsn.vA; |
| 1412 | break; |
| 1413 | case OP_IF_EQ: |
| 1414 | case OP_IF_NE: |
| 1415 | case OP_IF_LT: |
| 1416 | case OP_IF_GE: |
| 1417 | case OP_IF_GT: |
| 1418 | case OP_IF_LE: |
| 1419 | target += (int) insn->dalvikInsn.vC; |
| 1420 | break; |
| 1421 | case OP_IF_EQZ: |
| 1422 | case OP_IF_NEZ: |
| 1423 | case OP_IF_LTZ: |
| 1424 | case OP_IF_GEZ: |
| 1425 | case OP_IF_GTZ: |
| 1426 | case OP_IF_LEZ: |
| 1427 | target += (int) insn->dalvikInsn.vB; |
| 1428 | break; |
| 1429 | default: |
| 1430 | LOGE("Unexpected opcode(%d) with kInstrCanBranch set", |
| 1431 | insn->dalvikInsn.opcode); |
| 1432 | dvmAbort(); |
| 1433 | } |
| 1434 | BasicBlock *takenBlock = findBlock(cUnit, target, |
| 1435 | /* split */ |
| 1436 | true, |
| 1437 | /* create */ |
| 1438 | true); |
| 1439 | curBlock->taken = takenBlock; |
| 1440 | dvmCompilerSetBit(takenBlock->predecessors, curBlock->id); |
| 1441 | |
| 1442 | /* Always terminate the current block for conditional branches */ |
| 1443 | if (flags & kInstrCanContinue) { |
| 1444 | BasicBlock *fallthroughBlock = findBlock(cUnit, |
| 1445 | curOffset + width, |
| 1446 | /* split */ |
| 1447 | false, |
| 1448 | /* create */ |
| 1449 | true); |
| 1450 | curBlock->fallThrough = fallthroughBlock; |
| 1451 | dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id); |
| 1452 | } else if (codePtr < codeEnd) { |
| 1453 | /* Create a fallthrough block for real instructions (incl. OP_NOP) */ |
| 1454 | if (contentIsInsn(codePtr)) { |
| 1455 | findBlock(cUnit, curOffset + width, |
| 1456 | /* split */ |
| 1457 | false, |
| 1458 | /* create */ |
| 1459 | true); |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | /* Process instructions with the kInstrCanSwitch flag */ |
| 1465 | static void processCanSwitch(CompilationUnit *cUnit, BasicBlock *curBlock, |
| 1466 | MIR *insn, int curOffset, int width, int flags) |
| 1467 | { |
| 1468 | u2 *switchData= (u2 *) (cUnit->method->insns + curOffset + |
| 1469 | insn->dalvikInsn.vB); |
| 1470 | int size; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1471 | int *keyTable; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1472 | int *targetTable; |
| 1473 | int i; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1474 | int firstKey; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1475 | |
| 1476 | /* |
| 1477 | * Packed switch data format: |
| 1478 | * ushort ident = 0x0100 magic value |
| 1479 | * ushort size number of entries in the table |
| 1480 | * int first_key first (and lowest) switch case value |
| 1481 | * int targets[size] branch targets, relative to switch opcode |
| 1482 | * |
| 1483 | * Total size is (4+size*2) 16-bit code units. |
| 1484 | */ |
| 1485 | if (insn->dalvikInsn.opcode == OP_PACKED_SWITCH) { |
| 1486 | assert(switchData[0] == kPackedSwitchSignature); |
| 1487 | size = switchData[1]; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1488 | firstKey = switchData[2] | (switchData[3] << 16); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1489 | targetTable = (int *) &switchData[4]; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1490 | keyTable = NULL; // Make the compiler happy |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1491 | /* |
| 1492 | * Sparse switch data format: |
| 1493 | * ushort ident = 0x0200 magic value |
| 1494 | * ushort size number of entries in the table; > 0 |
| 1495 | * int keys[size] keys, sorted low-to-high; 32-bit aligned |
| 1496 | * int targets[size] branch targets, relative to switch opcode |
| 1497 | * |
| 1498 | * Total size is (2+size*4) 16-bit code units. |
| 1499 | */ |
| 1500 | } else { |
| 1501 | assert(switchData[0] == kSparseSwitchSignature); |
| 1502 | size = switchData[1]; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1503 | keyTable = (int *) &switchData[2]; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1504 | targetTable = (int *) &switchData[2 + size*2]; |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1505 | firstKey = 0; // To make the compiler happy |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | if (curBlock->successorBlockList.blockListType != kNotUsed) { |
| 1509 | LOGE("Successor block list already in use: %d", |
| 1510 | curBlock->successorBlockList.blockListType); |
| 1511 | dvmAbort(); |
| 1512 | } |
| 1513 | curBlock->successorBlockList.blockListType = |
| 1514 | (insn->dalvikInsn.opcode == OP_PACKED_SWITCH) ? |
| 1515 | kPackedSwitch : kSparseSwitch; |
| 1516 | dvmInitGrowableList(&curBlock->successorBlockList.blocks, size); |
| 1517 | |
| 1518 | for (i = 0; i < size; i++) { |
| 1519 | BasicBlock *caseBlock = findBlock(cUnit, curOffset + targetTable[i], |
| 1520 | /* split */ |
| 1521 | true, |
| 1522 | /* create */ |
| 1523 | true); |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1524 | SuccessorBlockInfo *successorBlockInfo = |
| 1525 | (SuccessorBlockInfo *) dvmCompilerNew(sizeof(SuccessorBlockInfo), |
| 1526 | false); |
| 1527 | successorBlockInfo->block = caseBlock; |
| 1528 | successorBlockInfo->key = (insn->dalvikInsn.opcode == OP_PACKED_SWITCH)? |
| 1529 | firstKey + i : keyTable[i]; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1530 | dvmInsertGrowableList(&curBlock->successorBlockList.blocks, |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1531 | (intptr_t) successorBlockInfo); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1532 | dvmCompilerSetBit(caseBlock->predecessors, curBlock->id); |
| 1533 | } |
| 1534 | |
| 1535 | /* Fall-through case */ |
| 1536 | BasicBlock *fallthroughBlock = findBlock(cUnit, |
| 1537 | curOffset + width, |
| 1538 | /* split */ |
| 1539 | false, |
| 1540 | /* create */ |
| 1541 | true); |
| 1542 | curBlock->fallThrough = fallthroughBlock; |
| 1543 | dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id); |
| 1544 | } |
| 1545 | |
| 1546 | /* Process instructions with the kInstrCanThrow flag */ |
| 1547 | static void processCanThrow(CompilationUnit *cUnit, BasicBlock *curBlock, |
| 1548 | MIR *insn, int curOffset, int width, int flags, |
| 1549 | BitVector *tryBlockAddr, const u2 *codePtr, |
| 1550 | const u2* codeEnd) |
| 1551 | { |
| 1552 | const Method *method = cUnit->method; |
| 1553 | const DexCode *dexCode = dvmGetMethodCode(method); |
| 1554 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1555 | /* In try block */ |
| 1556 | if (dvmIsBitSet(tryBlockAddr, curOffset)) { |
| 1557 | DexCatchIterator iterator; |
| 1558 | |
| 1559 | if (!dexFindCatchHandler(&iterator, dexCode, curOffset)) { |
| 1560 | LOGE("Catch block not found in dexfile for insn %x in %s", |
| 1561 | curOffset, method->name); |
| 1562 | dvmAbort(); |
| 1563 | |
| 1564 | } |
| 1565 | if (curBlock->successorBlockList.blockListType != kNotUsed) { |
| 1566 | LOGE("Successor block list already in use: %d", |
| 1567 | curBlock->successorBlockList.blockListType); |
| 1568 | dvmAbort(); |
| 1569 | } |
| 1570 | curBlock->successorBlockList.blockListType = kCatch; |
| 1571 | dvmInitGrowableList(&curBlock->successorBlockList.blocks, 2); |
| 1572 | |
| 1573 | for (;;) { |
| 1574 | DexCatchHandler* handler = dexCatchIteratorNext(&iterator); |
| 1575 | |
| 1576 | if (handler == NULL) { |
| 1577 | break; |
| 1578 | } |
| 1579 | |
| 1580 | BasicBlock *catchBlock = findBlock(cUnit, handler->address, |
| 1581 | /* split */ |
| 1582 | false, |
| 1583 | /* create */ |
| 1584 | false); |
| 1585 | |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1586 | SuccessorBlockInfo *successorBlockInfo = |
| 1587 | (SuccessorBlockInfo *) dvmCompilerNew(sizeof(SuccessorBlockInfo), |
| 1588 | false); |
| 1589 | successorBlockInfo->block = catchBlock; |
| 1590 | successorBlockInfo->key = handler->typeIdx; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1591 | dvmInsertGrowableList(&curBlock->successorBlockList.blocks, |
| Ben Cheng | 7a02cb1 | 2010-12-15 14:18:31 -0800 | [diff] [blame] | 1592 | (intptr_t) successorBlockInfo); |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1593 | dvmCompilerSetBit(catchBlock->predecessors, curBlock->id); |
| 1594 | } |
| 1595 | } else { |
| 1596 | BasicBlock *ehBlock = dvmCompilerNewBB(kExceptionHandling, |
| 1597 | cUnit->numBlocks++); |
| 1598 | curBlock->taken = ehBlock; |
| 1599 | dvmInsertGrowableList(&cUnit->blockList, (intptr_t) ehBlock); |
| 1600 | ehBlock->startOffset = curOffset; |
| 1601 | dvmCompilerSetBit(ehBlock->predecessors, curBlock->id); |
| 1602 | } |
| 1603 | |
| 1604 | /* |
| 1605 | * Force the current block to terminate. |
| 1606 | * |
| 1607 | * Data may be present before codeEnd, so we need to parse it to know |
| 1608 | * whether it is code or data. |
| 1609 | */ |
| 1610 | if (codePtr < codeEnd) { |
| 1611 | /* Create a fallthrough block for real instructions (incl. OP_NOP) */ |
| 1612 | if (contentIsInsn(codePtr)) { |
| 1613 | BasicBlock *fallthroughBlock = findBlock(cUnit, |
| 1614 | curOffset + width, |
| 1615 | /* split */ |
| 1616 | false, |
| 1617 | /* create */ |
| 1618 | true); |
| 1619 | /* |
| 1620 | * OP_THROW and OP_THROW_VERIFICATION_ERROR are unconditional |
| 1621 | * branches. |
| 1622 | */ |
| 1623 | if (insn->dalvikInsn.opcode != OP_THROW_VERIFICATION_ERROR && |
| 1624 | insn->dalvikInsn.opcode != OP_THROW) { |
| 1625 | curBlock->fallThrough = fallthroughBlock; |
| 1626 | dvmCompilerSetBit(fallthroughBlock->predecessors, curBlock->id); |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 1632 | /* |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1633 | * Similar to dvmCompileTrace, but the entity processed here is the whole |
| 1634 | * method. |
| 1635 | * |
| 1636 | * TODO: implementation will be revisited when the trace builder can provide |
| 1637 | * whole-method traces. |
| 1638 | */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1639 | bool dvmCompileMethod(const Method *method) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1640 | { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1641 | CompilationUnit cUnit; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1642 | const DexCode *dexCode = dvmGetMethodCode(method); |
| 1643 | const u2 *codePtr = dexCode->insns; |
| 1644 | const u2 *codeEnd = dexCode->insns + dexCode->insnsSize; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1645 | int numBlocks = 0; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1646 | unsigned int curOffset = 0; |
| 1647 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1648 | memset(&cUnit, 0, sizeof(cUnit)); |
| 1649 | cUnit.method = method; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 1650 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1651 | /* Initialize the block list */ |
| 1652 | dvmInitGrowableList(&cUnit.blockList, 4); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1653 | |
| 1654 | /* Allocate the bit-vector to track the beginning of basic blocks */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1655 | BitVector *tryBlockAddr = dvmCompilerAllocBitVector(dexCode->insnsSize, |
| 1656 | true /* expandable */); |
| 1657 | cUnit.tryBlockAddr = tryBlockAddr; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1658 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1659 | /* Create the default entry and exit blocks and enter them to the list */ |
| 1660 | BasicBlock *entryBlock = dvmCompilerNewBB(kMethodEntryBlock, numBlocks++); |
| 1661 | BasicBlock *exitBlock = dvmCompilerNewBB(kMethodExitBlock, numBlocks++); |
| 1662 | |
| 1663 | cUnit.entryBlock = entryBlock; |
| 1664 | cUnit.exitBlock = exitBlock; |
| 1665 | |
| 1666 | dvmInsertGrowableList(&cUnit.blockList, (intptr_t) entryBlock); |
| 1667 | dvmInsertGrowableList(&cUnit.blockList, (intptr_t) exitBlock); |
| 1668 | |
| 1669 | /* Current block to record parsed instructions */ |
| 1670 | BasicBlock *curBlock = dvmCompilerNewBB(kDalvikByteCode, numBlocks++); |
| 1671 | curBlock->startOffset = 0; |
| 1672 | dvmInsertGrowableList(&cUnit.blockList, (intptr_t) curBlock); |
| 1673 | entryBlock->fallThrough = curBlock; |
| 1674 | dvmCompilerSetBit(curBlock->predecessors, entryBlock->id); |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 1675 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1676 | /* |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1677 | * Store back the number of blocks since new blocks may be created of |
| 1678 | * accessing cUnit. |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1679 | */ |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1680 | cUnit.numBlocks = numBlocks; |
| 1681 | |
| 1682 | /* Identify code range in try blocks and set up the empty catch blocks */ |
| 1683 | processTryCatchBlocks(&cUnit); |
| 1684 | |
| 1685 | /* Parse all instructions and put them into containing basic blocks */ |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1686 | while (codePtr < codeEnd) { |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1687 | MIR *insn = (MIR *) dvmCompilerNew(sizeof(MIR), true); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1688 | insn->offset = curOffset; |
| 1689 | int width = parseInsn(codePtr, &insn->dalvikInsn, false); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1690 | insn->width = width; |
| 1691 | |
| Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 1692 | /* Terminate when the data section is seen */ |
| 1693 | if (width == 0) |
| 1694 | break; |
| Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 1695 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1696 | dvmCompilerAppendMIR(curBlock, insn); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1697 | |
| 1698 | codePtr += width; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1699 | int flags = dexGetFlagsFromOpcode(insn->dalvikInsn.opcode); |
| 1700 | |
| 1701 | if (flags & kInstrCanBranch) { |
| 1702 | processCanBranch(&cUnit, curBlock, insn, curOffset, width, flags, |
| 1703 | codePtr, codeEnd); |
| 1704 | } else if (flags & kInstrCanReturn) { |
| 1705 | curBlock->fallThrough = exitBlock; |
| 1706 | dvmCompilerSetBit(exitBlock->predecessors, curBlock->id); |
| 1707 | /* |
| 1708 | * Terminate the current block if there are instructions |
| 1709 | * afterwards. |
| 1710 | */ |
| 1711 | if (codePtr < codeEnd) { |
| 1712 | /* |
| 1713 | * Create a fallthrough block for real instructions |
| 1714 | * (incl. OP_NOP). |
| 1715 | */ |
| 1716 | if (contentIsInsn(codePtr)) { |
| 1717 | findBlock(&cUnit, curOffset + width, |
| 1718 | /* split */ |
| 1719 | false, |
| 1720 | /* create */ |
| 1721 | true); |
| 1722 | } |
| 1723 | } |
| 1724 | } else if (flags & kInstrCanThrow) { |
| 1725 | processCanThrow(&cUnit, curBlock, insn, curOffset, width, flags, |
| 1726 | tryBlockAddr, codePtr, codeEnd); |
| 1727 | } else if (flags & kInstrCanSwitch) { |
| 1728 | processCanSwitch(&cUnit, curBlock, insn, curOffset, width, flags); |
| 1729 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1730 | curOffset += width; |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1731 | BasicBlock *nextBlock = findBlock(&cUnit, curOffset, |
| 1732 | /* split */ |
| 1733 | false, |
| 1734 | /* create */ |
| 1735 | false); |
| 1736 | if (nextBlock) { |
| 1737 | /* |
| 1738 | * The next instruction could be the target of a previously parsed |
| 1739 | * forward branch so a block is already created. If the current |
| 1740 | * instruction is not an unconditional branch, connect them through |
| 1741 | * the fall-through link. |
| 1742 | */ |
| 1743 | assert(curBlock->fallThrough == NULL || |
| 1744 | curBlock->fallThrough == nextBlock || |
| 1745 | curBlock->fallThrough == exitBlock); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1746 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1747 | if ((curBlock->fallThrough == NULL) && |
| 1748 | !dexIsGoto(flags) && |
| 1749 | !(flags & kInstrCanReturn)) { |
| 1750 | curBlock->fallThrough = nextBlock; |
| 1751 | dvmCompilerSetBit(nextBlock->predecessors, curBlock->id); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1752 | } |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1753 | curBlock = nextBlock; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1757 | /* Adjust this value accordingly once inlining is performed */ |
| 1758 | cUnit.numDalvikRegisters = cUnit.method->registersSize; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1759 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1760 | /* Verify if all blocks are connected as claimed */ |
| 1761 | /* FIXME - to be disabled in the future */ |
| 1762 | dvmCompilerDataFlowAnalysisDispatcher(&cUnit, verifyPredInfo, |
| 1763 | kAllNodes, |
| 1764 | false /* isIterative */); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1765 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1766 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1767 | /* Perform SSA transformation for the whole method */ |
| 1768 | dvmCompilerMethodSSATransformation(&cUnit); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1769 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1770 | if (cUnit.printMe) dumpCFG(&cUnit, "/data/tombstones/"); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1771 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1772 | /* Reset the compiler resource pool */ |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1773 | dvmCompilerArenaReset(); |
| 1774 | |
| Ben Cheng | 0060307 | 2010-10-28 11:13:58 -0700 | [diff] [blame] | 1775 | return false; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1776 | } |