Add support for profiling when loop optimizations are active
diff --git a/vm/compiler/Frontend.c b/vm/compiler/Frontend.c
index 1144d50..b224614 100644
--- a/vm/compiler/Frontend.c
+++ b/vm/compiler/Frontend.c
@@ -465,9 +465,7 @@
             exitBB->needFallThroughBranch = true;
 
             loopBranch->taken = exitBB;
-#if !defined(WITH_SELF_VERIFICATION)
-            loopBranch->fallThrough = startBB->next;
-#else
+#if defined(WITH_SELF_VERIFICATION)
             BasicBlock *backwardCell =
                 dvmCompilerNewBB(CHAINING_CELL_BACKWARD_BRANCH);
             lastBB->next = backwardCell;
@@ -476,6 +474,21 @@
             backwardCell->startOffset = startBB->startOffset;
             backwardCell->id = numBlocks++;
             loopBranch->fallThrough = backwardCell;
+#elif defined(WITH_JIT_TUNING)
+            if (gDvmJit.profile) {
+                BasicBlock *backwardCell =
+                    dvmCompilerNewBB(CHAINING_CELL_BACKWARD_BRANCH);
+                lastBB->next = backwardCell;
+                lastBB = backwardCell;
+
+                backwardCell->startOffset = startBB->startOffset;
+                backwardCell->id = numBlocks++;
+                loopBranch->fallThrough = backwardCell;
+            } else {
+                loopBranch->fallThrough = startBB->next;
+            }
+#else
+            loopBranch->fallThrough = startBB->next;
 #endif
 
             /* Create the chaining cell as the fallthrough of the exit block */
diff --git a/vm/compiler/codegen/arm/Assemble.c b/vm/compiler/codegen/arm/Assemble.c
index 77cbb4d..6293fb2 100644
--- a/vm/compiler/codegen/arm/Assemble.c
+++ b/vm/compiler/codegen/arm/Assemble.c
@@ -1345,6 +1345,11 @@
                     targetOffset = offsetof(InterpState,
                           jitToInterpEntries.dvmJitToBackwardBranch);
                     break;
+#elif defined(WITH_JIT_TUNING)
+                case CHAINING_CELL_BACKWARD_BRANCH:
+                    targetOffset = offsetof(InterpState,
+                          jitToInterpEntries.dvmJitToInterpNormal);
+                    break;
 #endif
                 default:
                     dvmAbort();
diff --git a/vm/compiler/codegen/arm/Codegen.c b/vm/compiler/codegen/arm/Codegen.c
index a34a1b3..3c28c7b 100644
--- a/vm/compiler/codegen/arm/Codegen.c
+++ b/vm/compiler/codegen/arm/Codegen.c
@@ -3386,13 +3386,18 @@
     addWordData(cUnit, (int) (cUnit->method->insns + offset), true);
 }
 
-#if defined(WITH_SELF_VERIFICATION)
+#if defined(WITH_SELF_VERIFICATION) || defined(WITH_JIT_TUNING)
 /* Chaining cell for branches that branch back into the same basic block */
 static void handleBackwardBranchChainingCell(CompilationUnit *cUnit,
                                              unsigned int offset)
 {
+#if defined(WITH_SELF_VERIFICATION)
     newLIR3(cUnit, THUMB_LDR_RRI5, r0, rGLUE,
         offsetof(InterpState, jitToInterpEntries.dvmJitToBackwardBranch) >> 2);
+#else
+    newLIR3(cUnit, THUMB_LDR_RRI5, r0, rGLUE,
+        offsetof(InterpState, jitToInterpEntries.dvmJitToInterpNormal) >> 2);
+#endif
     newLIR1(cUnit, THUMB_BLX_R, r0);
     addWordData(cUnit, (int) (cUnit->method->insns + offset), true);
 }
@@ -3749,7 +3754,7 @@
                         opReg(cUnit, OP_BLX, r1);
                     }
                     break;
-#if defined(WITH_SELF_VERIFICATION)
+#if defined(WITH_SELF_VERIFICATION) || defined(WITH_JIT_TUNING)
                 case CHAINING_CELL_BACKWARD_BRANCH:
                     labelList[i].opCode =
                         ARM_PSEUDO_CHAINING_CELL_BACKWARD_BRANCH;
@@ -3969,7 +3974,7 @@
                     handleHotChainingCell(cUnit,
                         blockList[blockId]->startOffset);
                     break;
-#if defined(WITH_SELF_VERIFICATION)
+#if defined(WITH_SELF_VERIFICATION) || defined(WITH_JIT_TUNING)
                 case CHAINING_CELL_BACKWARD_BRANCH:
                     handleBackwardBranchChainingCell(cUnit,
                         blockList[blockId]->startOffset);