Fix suspension assumptions in perfetto plugin.
Make sure the tread suspending all threads is already suspended.
Test: test.py
Bug: 265638087
Change-Id: I7aab1964ed2d81bf3352111a46793e01deb541a8
diff --git a/perfetto_hprof/perfetto_hprof.cc b/perfetto_hprof/perfetto_hprof.cc
index b13e5e1..318b890 100644
--- a/perfetto_hprof/perfetto_hprof.cc
+++ b/perfetto_hprof/perfetto_hprof.cc
@@ -913,6 +913,7 @@
std::optional<art::gc::ScopedGCCriticalSection> gcs(std::in_place, self, art::gc::kGcCauseHprof,
art::gc::kCollectorTypeHprof);
+ DCHECK(self->IsSuspended());
std::optional<art::ScopedSuspendAll> ssa(std::in_place, __FUNCTION__, /* long_suspend=*/ true);
pid_t pid = fork();
@@ -1033,7 +1034,7 @@
});
}
-void DumpPerfettoOutOfMemory() {
+void DumpPerfettoOutOfMemory() REQUIRES_SHARED(art::Locks::mutator_lock_) {
art::Thread* self = art::Thread::Current();
if (!self) {
LOG(FATAL_WITHOUT_ABORT) << "no thread in DumpPerfettoOutOfMemory";
@@ -1048,6 +1049,8 @@
}
g_oome_triggered = true;
}
+
+ art::ScopedThreadSuspension sts(self, art::ThreadState::kSuspended);
// If we fork & resume the original process execution it will most likely exit
// ~immediately due to the OOME error thrown. When the system detects that
// that, it will cleanup by killing all processes in the cgroup (including