diff options
Diffstat (limited to 'runtime/stack.h')
-rw-r--r-- | runtime/stack.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/runtime/stack.h b/runtime/stack.h index 02578d25b7..1f305d2625 100644 --- a/runtime/stack.h +++ b/runtime/stack.h @@ -20,8 +20,8 @@ #include <stdint.h> #include <string> +#include "base/locks.h" #include "base/macros.h" -#include "base/mutex.h" #include "quick/quick_method_frame_info.h" #include "stack_map.h" @@ -143,6 +143,36 @@ class StackVisitor { template <CountTransitions kCount = CountTransitions::kYes> void WalkStack(bool include_transitions = false) REQUIRES_SHARED(Locks::mutator_lock_); + // Convenience helper function to walk the stack with a lambda as a visitor. + template <CountTransitions kCountTransitions = CountTransitions::kYes, + typename T> + ALWAYS_INLINE static void WalkStack(const T& fn, + Thread* thread, + Context* context, + StackWalkKind walk_kind, + bool check_suspended = true, + bool include_transitions = false) + REQUIRES_SHARED(Locks::mutator_lock_) { + class LambdaStackVisitor : public StackVisitor { + public: + LambdaStackVisitor(const T& fn, + Thread* thread, + Context* context, + StackWalkKind walk_kind, + bool check_suspended = true) + : StackVisitor(thread, context, walk_kind, check_suspended), fn_(fn) {} + + bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { + return fn_(this); + } + + private: + T fn_; + }; + LambdaStackVisitor visitor(fn, thread, context, walk_kind, check_suspended); + visitor.template WalkStack<kCountTransitions>(include_transitions); + } + Thread* GetThread() const { return thread_; } @@ -312,6 +342,7 @@ class StackVisitor { size_t cur_depth_; // Current inlined frames of the method we are currently at. // We keep poping frames from the end as we visit the frames. + CodeInfo current_code_info_; BitTableRange<InlineInfo> current_inline_frames_; protected: |