Fix how the ProfileSaver thread attaches to the runtime.
If the runtime is shutting down we can't attach new threads. In this
case it is expected that Runtime::Attach returns nullptr.
Also, lower the serverity of the log to warning so that it does not
show up in the run-tests.
Bug: 28435649
(cherry picked from commit e55fda1373abad5ace4409453c51aeb0daaf99ef)
Change-Id: I96464d76a275d155a90a1bc3bb99fbb9d914cf20
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index 99b8dfc..6af0c1a 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -247,12 +247,17 @@
void* ProfileSaver::RunProfileSaverThread(void* arg) {
Runtime* runtime = Runtime::Current();
- ProfileSaver* profile_saver = reinterpret_cast<ProfileSaver*>(arg);
- CHECK(runtime->AttachCurrentThread("Profile Saver",
- /*as_daemon*/true,
- runtime->GetSystemThreadGroup(),
- /*create_peer*/true));
+ bool attached = runtime->AttachCurrentThread("Profile Saver",
+ /*as_daemon*/true,
+ runtime->GetSystemThreadGroup(),
+ /*create_peer*/true);
+ if (!attached) {
+ CHECK(runtime->IsShuttingDown(Thread::Current()));
+ return nullptr;
+ }
+
+ ProfileSaver* profile_saver = reinterpret_cast<ProfileSaver*>(arg);
profile_saver->Run();
runtime->DetachCurrentThread();
diff --git a/runtime/thread.cc b/runtime/thread.cc
index e3feda6..fb24828 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -740,7 +740,7 @@
{
MutexLock mu(nullptr, *Locks::runtime_shutdown_lock_);
if (runtime->IsShuttingDownLocked()) {
- LOG(ERROR) << "Thread attaching while runtime is shutting down: " << thread_name;
+ LOG(WARNING) << "Thread attaching while runtime is shutting down: " << thread_name;
return nullptr;
} else {
Runtime::Current()->StartThreadBirth();