ART: Ensure correct thread state for stack trace collection
As the closure needs the mutator lock, the calling thread must hold
the mutator lock. Ensure that that is the case.
Test: m test-art-host
Test: art/test/testrunner/testrunner.py -b --host --trace --interpreter 911
Change-Id: I47d36abba83a0f38b398b9e3ef6f485b5e735622
diff --git a/openjdkjvmti/ti_stack.cc b/openjdkjvmti/ti_stack.cc
index eee8108..318d98d 100644
--- a/openjdkjvmti/ti_stack.cc
+++ b/openjdkjvmti/ti_stack.cc
@@ -322,7 +322,9 @@
};
template <typename Data>
-static void RunCheckpointAndWait(Data* data, size_t max_frame_count) {
+static void RunCheckpointAndWait(Data* data, size_t max_frame_count)
+ REQUIRES_SHARED(art::Locks::mutator_lock_) {
+ // Note: requires the mutator lock as the checkpoint requires the mutator lock.
GetAllStackTracesVectorClosure<Data> closure(max_frame_count, data);
size_t barrier_count = art::Runtime::Current()->GetThreadList()->RunCheckpoint(&closure, nullptr);
if (barrier_count == 0) {
@@ -380,9 +382,11 @@
};
AllStackTracesData data;
- RunCheckpointAndWait(&data, static_cast<size_t>(max_frame_count));
-
art::Thread* current = art::Thread::Current();
+ {
+ art::ScopedObjectAccess soa(current);
+ RunCheckpointAndWait(&data, static_cast<size_t>(max_frame_count));
+ }
// Convert the data into our output format.