From cb3c08fe9c733e477776dcc0d0fa5a3cf0053aa7 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 18 Sep 2014 13:16:38 -0700 Subject: [PATCH] ART: Do a pre-pass for monitor_enter dex pc search In case the method does not have any monitor_enter instructions, it is unnecessary to run the full verifier. Speeds up stack dumps and works around b/17514582. Bug: 17514582 Change-Id: I5201bfbb9fb6cad49596b4c72e71983b58d9f20c --- runtime/verifier/method_verifier.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 467390662..02aea1970 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -379,10 +379,31 @@ void MethodVerifier::FindLocksAtDexPc(mirror::ArtMethod* m, uint32_t dex_pc, verifier.FindLocksAtDexPc(); } +static bool HasMonitorEnterInstructions(const DexFile::CodeItem* const code_item) { + const Instruction* inst = Instruction::At(code_item->insns_); + + uint32_t insns_size = code_item->insns_size_in_code_units_; + for (uint32_t dex_pc = 0; dex_pc < insns_size;) { + if (inst->Opcode() == Instruction::MONITOR_ENTER) { + return true; + } + + dex_pc += inst->SizeInCodeUnits(); + inst = inst->Next(); + } + + return false; +} + void MethodVerifier::FindLocksAtDexPc() { CHECK(monitor_enter_dex_pcs_ != nullptr); CHECK(code_item_ != nullptr); // This only makes sense for methods with code. + // Quick check whether there are any monitor_enter instructions at all. + if (!HasMonitorEnterInstructions(code_item_)) { + return; + } + // Strictly speaking, we ought to be able to get away with doing a subset of the full method // verification. In practice, the phase we want relies on data structures set up by all the // earlier passes, so we just run the full method verification and bail out early when we've -- 2.11.0