ART: Use templates for VerifyInstruction
Use a template parameter instead of an explicit one.
Bug: 10921004
Test: m test-art-host
Change-Id: If0c21a8b902428456e445728afd443f0c88588df
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 7490611..c8f6623 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -883,10 +883,13 @@
InstructionFlags());
// Run through the instructions and see if the width checks out.
bool result = ComputeWidthsAndCountOps();
+ bool allow_runtime_only_instructions = !Runtime::Current()->IsAotCompiler() || verify_to_dump_;
// Flag instructions guarded by a "try" block and check exception handlers.
result = result && ScanTryCatchBlocks();
// Perform static instruction verification.
- result = result && VerifyInstructions();
+ result = result && (allow_runtime_only_instructions
+ ? VerifyInstructions<true>()
+ : VerifyInstructions<false>());
// Perform code-flow analysis and return.
result = result && VerifyCodeFlow();
@@ -1102,6 +1105,7 @@
return true;
}
+template <bool kAllowRuntimeOnlyInstructions>
bool MethodVerifier::VerifyInstructions() {
const Instruction* inst = Instruction::At(code_item_->insns_);
@@ -1110,9 +1114,8 @@
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, allow_runtime_only_instructions)) {
+ if (!VerifyInstruction<kAllowRuntimeOnlyInstructions>(inst, dex_pc)) {
DCHECK_NE(failures_.size(), 0U);
return false;
}
@@ -1139,9 +1142,8 @@
return true;
}
-bool MethodVerifier::VerifyInstruction(const Instruction* inst,
- uint32_t code_offset,
- bool allow_runtime_only_instructions) {
+template <bool kAllowRuntimeOnlyInstructions>
+bool MethodVerifier::VerifyInstruction(const Instruction* inst, uint32_t code_offset) {
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
@@ -1250,7 +1252,7 @@
result = false;
break;
}
- if (!allow_runtime_only_instructions && inst->GetVerifyIsRuntimeOnly()) {
+ if (!kAllowRuntimeOnlyInstructions && 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 b34a3af..d878b2a 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -355,6 +355,7 @@
*
* Walks through instructions in a method calling VerifyInstruction on each.
*/
+ template <bool kAllowRuntimeOnlyInstructions>
bool VerifyInstructions();
/*
@@ -390,9 +391,8 @@
* - (earlier) for each exception handler, the handler must start at a valid
* instruction
*/
- bool VerifyInstruction(const Instruction* inst,
- uint32_t code_offset,
- bool allow_runtime_only_instructions);
+ template <bool kAllowRuntimeOnlyInstructions>
+ bool VerifyInstruction(const Instruction* inst, uint32_t code_offset);
/* Ensure that the register index is valid for this code item. */
bool CheckRegisterIndex(uint32_t idx);