OSDN Git Service

More efficient stack walk in exception throwing.
authorHiroshi Yamauchi <yamauchi@google.com>
Wed, 13 Aug 2014 18:12:22 +0000 (11:12 -0700)
committerHiroshi Yamauchi <yamauchi@google.com>
Thu, 14 Aug 2014 20:16:08 +0000 (13:16 -0700)
commit2e981cbaa2e869ec3910ebdc5cce9d4ab9edb758
tree74297c37046974e312b7145bbceecbab4467aef9
parentb162bf5af5c2e508c6947471ceffaa98991794f4
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.

(cherry pick commit 649278cec7119cdd1bea3d0b710dbb2aa7c650b6)

Bug: 16800209
Change-Id: Ie815df1e3e8fb9d82e40685d4cc2b8838fd8aa07
runtime/quick_exception_handler.cc
runtime/quick_exception_handler.h
runtime/stack.h