ART: Cache AoT state in verifier

Cache the runtime-only-instruction flag instead of computing it for
every single instruction.

Bug: 10921004
Test: m test-art-host
Change-Id: I417260ddf73ac714083609b292f036c28227a0b2
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index a77ba6a..bbea474 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -1110,8 +1110,9 @@
   GetInstructionFlags(0).SetCompileTimeInfoPoint();
 
   uint32_t insns_size = code_item_->insns_size_in_code_units_;
+  bool allow_runtime_only_instructions = !Runtime::Current()->IsAotCompiler() || verify_to_dump_;
   for (uint32_t dex_pc = 0; dex_pc < insns_size;) {
-    if (!VerifyInstruction(inst, dex_pc)) {
+    if (!VerifyInstruction(inst, dex_pc, allow_runtime_only_instructions)) {
       DCHECK_NE(failures_.size(), 0U);
       return false;
     }
@@ -1138,7 +1139,9 @@
   return true;
 }
 
-bool MethodVerifier::VerifyInstruction(const Instruction* inst, uint32_t code_offset) {
+bool MethodVerifier::VerifyInstruction(const Instruction* inst,
+                                       uint32_t code_offset,
+                                       bool allow_runtime_only_instructions) {
   if (Instruction::kHaveExperimentalInstructions && UNLIKELY(inst->IsExperimental())) {
     // Experimental instructions don't yet have verifier support implementation.
     // While it is possible to use them by themselves, when we try to use stable instructions
@@ -1247,7 +1250,7 @@
       result = false;
       break;
   }
-  if (inst->GetVerifyIsRuntimeOnly() && Runtime::Current()->IsAotCompiler() && !verify_to_dump_) {
+  if (!allow_runtime_only_instructions && inst->GetVerifyIsRuntimeOnly()) {
     Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "opcode only expected at runtime " << inst->Name();
     result = false;
   }
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index 26dc15e..b34a3af 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -390,7 +390,9 @@
    * - (earlier) for each exception handler, the handler must start at a valid
    *   instruction
    */
-  bool VerifyInstruction(const Instruction* inst, uint32_t code_offset);
+  bool VerifyInstruction(const Instruction* inst,
+                         uint32_t code_offset,
+                         bool allow_runtime_only_instructions);
 
   /* Ensure that the register index is valid for this code item. */
   bool CheckRegisterIndex(uint32_t idx);