ART: Punt to the interpreter for VerifiedMethod errors

In case that the GC map can't be created (because of size restrictions),
do not fail the class. Instead punt to the interpreter.

Bug: 17791183

(cherry picked from commit f535c69f115c61ffadca1bd2706244d0aa30f9aa)

Change-Id: I348bb306dbfc85c235fa93c0c527fba6627551fe
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 051b310..cbb23c2 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2120,8 +2120,12 @@
   } else if ((access_flags & kAccAbstract) != 0) {
     // Abstract methods don't have code.
   } else {
+    bool has_verified_method = verification_results_->GetVerifiedMethod(method_ref) != nullptr;
     bool compile = compilation_enabled &&
-                   verification_results_->IsCandidateForCompilation(method_ref, access_flags);
+                   // Basic checks, e.g., not <clinit>.
+                   verification_results_->IsCandidateForCompilation(method_ref, access_flags) &&
+                   // Did not fail to create VerifiedMethod metadata.
+                   has_verified_method;
     if (compile) {
       // NOTE: if compiler declines to compile this method, it will return nullptr.
       compiled_method = compiler_->Compile(code_item, access_flags, invoke_type, class_def_idx,
@@ -2129,10 +2133,12 @@
     }
     if (compiled_method == nullptr && dex_to_dex_compilation_level != kDontDexToDexCompile) {
       // TODO: add a command-line option to disable DEX-to-DEX compilation ?
+      // Do not optimize if a VerifiedMethod is missing. SafeCast elision, for example, relies on
+      // it.
       (*dex_to_dex_compiler_)(*this, code_item, access_flags,
                               invoke_type, class_def_idx,
                               method_idx, class_loader, dex_file,
-                              dex_to_dex_compilation_level);
+                              has_verified_method ? dex_to_dex_compilation_level : kRequired);
     }
   }
   if (kTimeCompileMethod) {