summaryrefslogtreecommitdiff
path: root/runtime/quick_exception_handler.cc
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2014-08-13 11:12:22 -0700
committerHiroshi Yamauchi <yamauchi@google.com>2014-08-13 20:46:10 -0700
commit649278cec7119cdd1bea3d0b710dbb2aa7c650b6 (patch)
tree6b5e08abee97e8af1ee5635488e6476d3fb3dc15 /runtime/quick_exception_handler.cc
parent99c251bbd225dd97d0deece29559a430b12a0b66 (diff)
More efficient stack walk in exception throwing.
In the exception handling code, we currently walk down the stack twice, once to get the stack height which we use to compute frame IDs (the bottom frame is zero), and once more to find the catch block to jump to. For a deep stack, this could result in very slow exception handling. That is, if have a lot of finally or catch blocks that we end up jumping to in a deep stack, we need to do a lot of catch/rethrow chains. Since we'd need to walk down to the bottom each time to compute frames IDs in each catch/rethrow, we'd need to walk down O(N^2) frames at the worst case. Instead of frames IDs ((the bottom frame is zero), we will use the frame depth (the top frame is zero) and no longer need to walk down the stack just to get the stack height. We walk down O(N) frames. This was what was happening with code.google.gson.functional.CircularReferenceTest. With this change, the test run time went from ~120s down to ~3s on N5 and it no longer crashes due to the thread suspension timeout. Bug: 16800209 Change-Id: Ie815df1e3e8fb9d82e40685d4cc2b8838fd8aa07
Diffstat (limited to 'runtime/quick_exception_handler.cc')
-rw-r--r--runtime/quick_exception_handler.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index 41d69894d5..98eeda7263 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -29,14 +29,14 @@
namespace art {
static constexpr bool kDebugExceptionDelivery = false;
-static constexpr size_t kInvalidFrameId = 0xffffffff;
+static constexpr size_t kInvalidFrameDepth = 0xffffffff;
QuickExceptionHandler::QuickExceptionHandler(Thread* self, bool is_deoptimization)
: self_(self), context_(self->GetLongJumpContext()), is_deoptimization_(is_deoptimization),
method_tracing_active_(is_deoptimization ||
Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled()),
handler_quick_frame_(nullptr), handler_quick_frame_pc_(0), handler_method_(nullptr),
- handler_dex_pc_(0), clear_exception_(false), handler_frame_id_(kInvalidFrameId) {
+ handler_dex_pc_(0), clear_exception_(false), handler_frame_depth_(kInvalidFrameDepth) {
}
// Finds catch handler or prepares for deoptimization.
@@ -51,7 +51,7 @@ class CatchBlockStackVisitor FINAL : public StackVisitor {
bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
mirror::ArtMethod* method = GetMethod();
- exception_handler_->SetHandlerFrameId(GetFrameId());
+ exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
if (method == nullptr) {
// This is the upcall, we remember the frame and last pc so that we may long jump to them.
exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
@@ -177,7 +177,7 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor {
}
bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- exception_handler_->SetHandlerFrameId(GetFrameId());
+ exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
mirror::ArtMethod* method = GetMethod();
if (method == nullptr) {
// This is the upcall, we remember the frame and last pc so that we may long jump to them.
@@ -295,17 +295,17 @@ void QuickExceptionHandler::DeoptimizeStack() {
// Unwinds all instrumentation stack frame prior to catch handler or upcall.
class InstrumentationStackVisitor : public StackVisitor {
public:
- InstrumentationStackVisitor(Thread* self, bool is_deoptimization, size_t frame_id)
+ InstrumentationStackVisitor(Thread* self, bool is_deoptimization, size_t frame_depth)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
: StackVisitor(self, nullptr),
- self_(self), frame_id_(frame_id),
+ self_(self), frame_depth_(frame_depth),
instrumentation_frames_to_pop_(0) {
- CHECK_NE(frame_id_, kInvalidFrameId);
+ CHECK_NE(frame_depth_, kInvalidFrameDepth);
}
bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- size_t current_frame_id = GetFrameId();
- if (current_frame_id > frame_id_) {
+ size_t current_frame_depth = GetFrameDepth();
+ if (current_frame_depth < frame_depth_) {
CHECK(GetMethod() != nullptr);
if (UNLIKELY(GetQuickInstrumentationExitPc() == GetReturnPc())) {
++instrumentation_frames_to_pop_;
@@ -323,7 +323,7 @@ class InstrumentationStackVisitor : public StackVisitor {
private:
Thread* const self_;
- const size_t frame_id_;
+ const size_t frame_depth_;
size_t instrumentation_frames_to_pop_;
DISALLOW_COPY_AND_ASSIGN(InstrumentationStackVisitor);
@@ -331,7 +331,7 @@ class InstrumentationStackVisitor : public StackVisitor {
void QuickExceptionHandler::UpdateInstrumentationStack() {
if (method_tracing_active_) {
- InstrumentationStackVisitor visitor(self_, is_deoptimization_, handler_frame_id_);
+ InstrumentationStackVisitor visitor(self_, is_deoptimization_, handler_frame_depth_);
visitor.WalkStack(true);
size_t instrumentation_frames_to_pop = visitor.GetInstrumentationFramesToPop();