diff options
author | Jeff Hao <jeffhao@google.com> | 2014-04-22 13:54:32 -0700 |
---|---|---|
committer | Jeff Hao <jeffhao@google.com> | 2014-04-22 17:03:21 -0700 |
commit | aa961918da5142220029da2809287e0dd537a5d7 (patch) | |
tree | 93cdad41650f353e1c7d82aaa8894037b12bb2a0 | |
parent | 82b1a81890970a8b07f9132aeae537a6c43df6b0 (diff) | |
download | art-aa961918da5142220029da2809287e0dd537a5d7.zip art-aa961918da5142220029da2809287e0dd537a5d7.tar.gz art-aa961918da5142220029da2809287e0dd537a5d7.tar.bz2 |
Fix FindCatchBlock to work in -Xverify:none mode.
FindCatchBlock now uses ResolveType to get the exception type,
since it might not be able to find it in the dex cache.
Bug: 13948502
Change-Id: Ia6f1c7dc743206ae1c8551bf6239f48ee4d3a784
-rw-r--r-- | runtime/catch_block_stack_visitor.cc | 4 | ||||
-rw-r--r-- | runtime/catch_block_stack_visitor.h | 2 | ||||
-rw-r--r-- | runtime/interpreter/interpreter_common.h | 3 | ||||
-rw-r--r-- | runtime/mirror/art_method.cc | 21 | ||||
-rw-r--r-- | runtime/mirror/art_method.h | 3 |
5 files changed, 23 insertions, 10 deletions
diff --git a/runtime/catch_block_stack_visitor.cc b/runtime/catch_block_stack_visitor.cc index f9acffb..410fff9 100644 --- a/runtime/catch_block_stack_visitor.cc +++ b/runtime/catch_block_stack_visitor.cc @@ -53,7 +53,9 @@ bool CatchBlockStackVisitor::HandleTryItems(mirror::ArtMethod* method) { } if (dex_pc != DexFile::kDexNoIndex) { bool clear_exception = false; - uint32_t found_dex_pc = method->FindCatchBlock(to_find_, dex_pc, &clear_exception); + SirtRef<mirror::Class> sirt_method_to_find(Thread::Current(), to_find_); + uint32_t found_dex_pc = method->FindCatchBlock(sirt_method_to_find, dex_pc, &clear_exception); + to_find_ = sirt_method_to_find.get(); catch_finder_->SetClearException(clear_exception); if (found_dex_pc != DexFile::kDexNoIndex) { catch_finder_->SetHandlerDexPc(found_dex_pc); diff --git a/runtime/catch_block_stack_visitor.h b/runtime/catch_block_stack_visitor.h index 175ad7d..ce67e27 100644 --- a/runtime/catch_block_stack_visitor.h +++ b/runtime/catch_block_stack_visitor.h @@ -45,7 +45,7 @@ class CatchBlockStackVisitor : public StackVisitor { Thread* const self_; const bool is_deoptimization_; // The type of the exception catch block to find. - mirror::Class* const to_find_; + mirror::Class* to_find_; CatchFinder* const catch_finder_; // Number of native methods passed in crawl (equates to number of SIRTs to pop) uint32_t native_method_count_; diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index 21eeafa..65bdf0e 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -498,7 +498,8 @@ static inline uint32_t FindNextInstructionFollowingException(Thread* self, ThrowLocation throw_location; mirror::Throwable* exception = self->GetException(&throw_location); bool clear_exception = false; - uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception->GetClass(), dex_pc, + SirtRef<mirror::Class> exception_class(self, exception->GetClass()); + uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc, &clear_exception); if (found_dex_pc == DexFile::kDexNoIndex) { instrumentation->MethodUnwindEvent(self, this_object, diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc index ee5a0a4..2151fc7 100644 --- a/runtime/mirror/art_method.cc +++ b/runtime/mirror/art_method.cc @@ -230,10 +230,15 @@ uintptr_t ArtMethod::ToNativePc(const uint32_t dex_pc) { return 0; } -uint32_t ArtMethod::FindCatchBlock(Class* exception_type, uint32_t dex_pc, +uint32_t ArtMethod::FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, bool* has_no_move_exception) { MethodHelper mh(this); const DexFile::CodeItem* code_item = mh.GetCodeItem(); + // Set aside the exception while we resolve its type. + Thread* self = Thread::Current(); + ThrowLocation throw_location; + SirtRef<mirror::Throwable> exception(self, self->GetException(&throw_location)); + self->ClearException(); // Default to handler not found. uint32_t found_dex_pc = DexFile::kDexNoIndex; // Iterate over the catch handlers associated with dex_pc. @@ -245,21 +250,25 @@ uint32_t ArtMethod::FindCatchBlock(Class* exception_type, uint32_t dex_pc, break; } // Does this catch exception type apply? - Class* iter_exception_type = mh.GetDexCacheResolvedType(iter_type_idx); - if (iter_exception_type == NULL) { - // The verifier should take care of resolving all exception classes early + Class* iter_exception_type = mh.GetClassFromTypeIdx(iter_type_idx); + if (exception_type.get() == nullptr) { + self->ClearException(); LOG(WARNING) << "Unresolved exception class when finding catch block: " << mh.GetTypeDescriptorFromTypeIdx(iter_type_idx); - } else if (iter_exception_type->IsAssignableFrom(exception_type)) { + } else if (iter_exception_type->IsAssignableFrom(exception_type.get())) { found_dex_pc = it.GetHandlerAddress(); break; } } if (found_dex_pc != DexFile::kDexNoIndex) { const Instruction* first_catch_instr = - Instruction::At(&mh.GetCodeItem()->insns_[found_dex_pc]); + Instruction::At(&code_item->insns_[found_dex_pc]); *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); } + // Put the exception back. + if (exception.get() != nullptr) { + self->SetException(throw_location, exception.get()); + } return found_dex_pc; } diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h index fd5ac19..38e44be 100644 --- a/runtime/mirror/art_method.h +++ b/runtime/mirror/art_method.h @@ -418,7 +418,8 @@ class MANAGED ArtMethod : public Object { // Find the catch block for the given exception type and dex_pc. When a catch block is found, // indicates whether the found catch block is responsible for clearing the exception or whether // a move-exception instruction is present. - uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception) + uint32_t FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, + bool* has_no_move_exception) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static void SetClass(Class* java_lang_reflect_ArtMethod); |