From 14691c5e786e8c2c5734f687e4c96217340771be Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Thu, 5 Mar 2015 10:40:17 +0000 Subject: Compute the right catch location for the debugger. Also remove tls ThrowLocation, it is not needed anymore. Change-Id: I78fddf09ce968ca475e39c17fa76d699c589c8d9 --- runtime/interpreter/interpreter_common.cc | 84 ++-------------------- runtime/interpreter/interpreter_goto_table_impl.cc | 4 +- runtime/interpreter/interpreter_switch_impl.cc | 4 +- 3 files changed, 9 insertions(+), 83 deletions(-) (limited to 'runtime/interpreter') diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index 754602f943..3f09bd3e59 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -413,90 +413,16 @@ EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-objec #undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL #undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL -/** - * Finds the location where this exception will be caught. We search until we reach either the top - * frame or a native frame, in which cases this exception is considered uncaught. - */ -class CatchLocationFinder : public StackVisitor { - public: - explicit CatchLocationFinder(Thread* self, Handle* exception) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) - : StackVisitor(self, nullptr), self_(self), handle_scope_(self), exception_(exception), - catch_method_(handle_scope_.NewHandle(nullptr)), - catch_dex_pc_(DexFile::kDexNoIndex), clear_exception_(false) { - } - - bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - mirror::ArtMethod* method = GetMethod(); - if (method == nullptr) { - return true; - } - if (method->IsRuntimeMethod()) { - // Ignore callee save method. - DCHECK(method->IsCalleeSaveMethod()); - return true; - } - if (method->IsNative()) { - return false; // End stack walk. - } - DCHECK(!method->IsNative()); - uint32_t dex_pc = GetDexPc(); - if (dex_pc != DexFile::kDexNoIndex) { - uint32_t found_dex_pc; - { - StackHandleScope<3> hs(self_); - Handle exception_class(hs.NewHandle((*exception_)->GetClass())); - Handle h_method(hs.NewHandle(method)); - found_dex_pc = mirror::ArtMethod::FindCatchBlock(h_method, exception_class, dex_pc, - &clear_exception_); - } - if (found_dex_pc != DexFile::kDexNoIndex) { - catch_method_.Assign(method); - catch_dex_pc_ = found_dex_pc; - return false; // End stack walk. - } - } - return true; // Continue stack walk. - } - - ArtMethod* GetCatchMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return catch_method_.Get(); - } - - uint32_t GetCatchDexPc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return catch_dex_pc_; - } - - bool NeedClearException() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return clear_exception_; - } - - private: - Thread* const self_; - StackHandleScope<1> handle_scope_; - Handle* exception_; - MutableHandle catch_method_; - uint32_t catch_dex_pc_; - bool clear_exception_; - - - DISALLOW_COPY_AND_ASSIGN(CatchLocationFinder); -}; - uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame, uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation) { self->VerifyStack(); - ThrowLocation throw_location; StackHandleScope<3> hs(self); - Handle exception(hs.NewHandle(self->GetException(&throw_location))); + Handle exception(hs.NewHandle(self->GetException())); if (instrumentation->HasExceptionCaughtListeners() && self->IsExceptionThrownByCurrentMethod(exception.Get())) { - CatchLocationFinder clf(self, &exception); - clf.WalkStack(false); - instrumentation->ExceptionCaughtEvent(self, throw_location, clf.GetCatchMethod(), - clf.GetCatchDexPc(), exception.Get()); + instrumentation->ExceptionCaughtEvent(self, exception.Get()); } bool clear_exception = false; uint32_t found_dex_pc; @@ -848,7 +774,7 @@ static void CheckExceptionGenerateClassNotFound(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { if (self->IsExceptionPending()) { // If it is not an InternalError, wrap it. - std::string type(PrettyTypeOf(self->GetException(nullptr))); + std::string type(PrettyTypeOf(self->GetException())); if (type != "java.lang.InternalError") { self->ThrowNewWrappedException(self->GetCurrentLocationForThrow(), "Ljava/lang/ClassNotFoundException;", @@ -903,7 +829,7 @@ static void UnstartedRuntimeInvoke(Thread* self, const DexFile::CodeItem* code_ // This might have an error pending. But semantics are to just return null. if (self->IsExceptionPending()) { // If it is an InternalError, keep it. See CheckExceptionGenerateClassNotFound. - std::string type(PrettyTypeOf(self->GetException(nullptr))); + std::string type(PrettyTypeOf(self->GetException())); if (type != "java.lang.InternalError") { self->ClearException(); } @@ -936,7 +862,7 @@ static void UnstartedRuntimeInvoke(Thread* self, const DexFile::CodeItem* code_ if (!ok) { std::string error_msg = StringPrintf("Failed in Class.newInstance for '%s' with %s", PrettyClass(h_klass.Get()).c_str(), - PrettyTypeOf(self->GetException(nullptr)).c_str()); + PrettyTypeOf(self->GetException()).c_str()); self->ThrowNewWrappedException(self->GetCurrentLocationForThrow(), "Ljava/lang/InternalError;", error_msg.c_str()); diff --git a/runtime/interpreter/interpreter_goto_table_impl.cc b/runtime/interpreter/interpreter_goto_table_impl.cc index 37324eac82..f1ab7477ef 100644 --- a/runtime/interpreter/interpreter_goto_table_impl.cc +++ b/runtime/interpreter/interpreter_goto_table_impl.cc @@ -244,7 +244,7 @@ JValue ExecuteGotoImpl(Thread* self, const DexFile::CodeItem* code_item, ShadowF HANDLE_INSTRUCTION_END(); HANDLE_INSTRUCTION_START(MOVE_EXCEPTION) { - Throwable* exception = self->GetException(nullptr); + Throwable* exception = self->GetException(); DCHECK(exception != nullptr) << "No pending exception on MOVE_EXCEPTION instruction"; shadow_frame.SetVRegReference(inst->VRegA_11x(inst_data), exception); self->ClearException(); @@ -605,7 +605,7 @@ JValue ExecuteGotoImpl(Thread* self, const DexFile::CodeItem* code_item, ShadowF "Throwing '%s' that is not instance of Throwable", exception->GetClass()->GetDescriptor(&temp)); } else { - self->SetException(shadow_frame.GetCurrentLocationForThrow(), exception->AsThrowable()); + self->SetException(exception->AsThrowable()); } HANDLE_PENDING_EXCEPTION(); } diff --git a/runtime/interpreter/interpreter_switch_impl.cc b/runtime/interpreter/interpreter_switch_impl.cc index 2f85587604..dceed47169 100644 --- a/runtime/interpreter/interpreter_switch_impl.cc +++ b/runtime/interpreter/interpreter_switch_impl.cc @@ -163,7 +163,7 @@ JValue ExecuteSwitchImpl(Thread* self, const DexFile::CodeItem* code_item, break; case Instruction::MOVE_EXCEPTION: { PREAMBLE(); - Throwable* exception = self->GetException(nullptr); + Throwable* exception = self->GetException(); DCHECK(exception != nullptr) << "No pending exception on MOVE_EXCEPTION instruction"; shadow_frame.SetVRegReference(inst->VRegA_11x(inst_data), exception); self->ClearException(); @@ -515,7 +515,7 @@ JValue ExecuteSwitchImpl(Thread* self, const DexFile::CodeItem* code_item, "Throwing '%s' that is not instance of Throwable", exception->GetClass()->GetDescriptor(&temp)); } else { - self->SetException(shadow_frame.GetCurrentLocationForThrow(), exception->AsThrowable()); + self->SetException(exception->AsThrowable()); } HANDLE_PENDING_EXCEPTION(); break; -- cgit v1.2.3