Revert "Revert^2 "ART: Add StackVisitor accepting a lambda""
This reverts commit 3d477f3a3eea757a49ca621cc579f711f22fccdd.
Bug: 115837065
Reason for revert: Breaks jdwp tests.
Change-Id: I09249331798970751a20c6b41675c3efef72adfb
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 7729838..1701ca8 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -18,8 +18,7 @@
#include <sstream>
-#include <android-base/logging.h>
-#include <android-base/unique_fd.h>
+#include "android-base/unique_fd.h"
#include "arch/context.h"
#include "art_method-inl.h"
@@ -1273,6 +1272,31 @@
}
}
+class MarkCodeVisitor final : public StackVisitor {
+ public:
+ MarkCodeVisitor(Thread* thread_in, JitCodeCache* code_cache_in, CodeCacheBitmap* bitmap)
+ : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kSkipInlinedFrames),
+ code_cache_(code_cache_in),
+ bitmap_(bitmap) {}
+
+ bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
+ const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
+ if (method_header == nullptr) {
+ return true;
+ }
+ const void* code = method_header->GetCode();
+ if (code_cache_->ContainsPc(code)) {
+ // Use the atomic set version, as multiple threads are executing this code.
+ bitmap_->AtomicTestAndSet(FromCodeToAllocation(code));
+ }
+ return true;
+ }
+
+ private:
+ JitCodeCache* const code_cache_;
+ CodeCacheBitmap* const bitmap_;
+};
+
class MarkCodeClosure final : public Closure {
public:
MarkCodeClosure(JitCodeCache* code_cache, CodeCacheBitmap* bitmap, Barrier* barrier)
@@ -1281,24 +1305,8 @@
void Run(Thread* thread) override REQUIRES_SHARED(Locks::mutator_lock_) {
ScopedTrace trace(__PRETTY_FUNCTION__);
DCHECK(thread == Thread::Current() || thread->IsSuspended());
- StackVisitor::WalkStack(
- [&](const art::StackVisitor* stack_visitor) {
- const OatQuickMethodHeader* method_header =
- stack_visitor->GetCurrentOatQuickMethodHeader();
- if (method_header == nullptr) {
- return true;
- }
- const void* code = method_header->GetCode();
- if (code_cache_->ContainsPc(code)) {
- // Use the atomic set version, as multiple threads are executing this code.
- bitmap_->AtomicTestAndSet(FromCodeToAllocation(code));
- }
- return true;
- },
- thread,
- /* context= */ nullptr,
- art::StackVisitor::StackWalkKind::kSkipInlinedFrames);
-
+ MarkCodeVisitor visitor(thread, code_cache_, bitmap_);
+ visitor.WalkStack();
if (kIsDebugBuild) {
// The stack walking code queries the side instrumentation stack if it
// sees an instrumentation exit pc, so the JIT code of methods in that stack