Don't do a recursive call when there are CHA guards.

Otherwise we would continue execute the method with invalid inlining
optimizations.

Test: 832-cha-recursive
Bug: 19381779
Change-Id: I57d73828d2a9c30f429cf32906f94244346c1310
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index d6b3726..94eae4d 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -4939,7 +4939,18 @@
   }
 
   MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; }
-  CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; }
+  CodePtrLocation GetCodePtrLocation() const {
+    // We do CHA analysis after sharpening. When a method has CHA inlining, it
+    // cannot call itself, as if the CHA optmization is invalid we want to make
+    // sure the method is never executed again. So, while sharpening can return
+    // kCallSelf, we bypass it here if there is a CHA optimization.
+    if (dispatch_info_.code_ptr_location == CodePtrLocation::kCallSelf &&
+        GetBlock()->GetGraph()->HasShouldDeoptimizeFlag()) {
+      return CodePtrLocation::kCallArtMethod;
+    } else {
+      return dispatch_info_.code_ptr_location;
+    }
+  }
   bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; }
   bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; }
   bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; }