Revert^4 "ART: Add StackVisitor accepting a lambda"
This reverts commit ec43a01e0ac948c59d5b1f9c3812f2901b48942a.
Reason for revert: Added missing code.
Bug: 115837065
Test: m test-art-host
Change-Id: Id30ccdf9aa9a6e56a914254793e399f2712c882d
diff --git a/runtime/stack.h b/runtime/stack.h
index 02578d2..9d30115 100644
--- a/runtime/stack.h
+++ b/runtime/stack.h
@@ -143,6 +143,36 @@
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_;
}