Warn if a thread attaches without a name and blow up if a thread detaches while running.
Also don't crash if a thread attaches without a name. Doing so is allowed, even
if it's not a good idea.
Change-Id: If5796af689e9221ce21f443023b0d793a8be15b0
diff --git a/src/runtime.cc b/src/runtime.cc
index f6311bb..7e0eab5 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -818,11 +818,15 @@
void Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, Object* thread_group) {
Thread::Attach(thread_name, as_daemon, thread_group);
+ if (thread_name == NULL) {
+ LOG(WARNING) << *Thread::Current() << " attached without supplying a name";
+ }
}
void Runtime::DetachCurrentThread() {
- // TODO: check we're not calling DetachCurrentThread from a call stack that
- // includes managed frames. (It's only valid if the stack is all-native.)
+ if (Thread::Current()->GetTopOfStack().GetSP() != NULL) {
+ LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code";
+ }
thread_list_->Unregister();
}