Callers of SuspendAll should be in the kRunnable state

Change-Id: I37996164a5fd56251134683f717e6e00541cab22
diff --git a/src/heap.cc b/src/heap.cc
index bd6d009..bef71ae 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -369,7 +369,7 @@
     //       utilization slop for the new allocation.
     if (is_verbose_gc_) {
       LOG(INFO) << "Grow heap (frag case) to " << new_footprint / MB
-                << "for " << size << "-byte allocation";
+                << " for " << size << "-byte allocation";
     }
     return ptr;
   }
diff --git a/src/runtime.cc b/src/runtime.cc
index 7595ed8..8672d29 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -393,6 +393,9 @@
 
   CHECK(host_prefix_.empty()) << host_prefix_;
 
+  // Restore main thread state to kNative as expected by native code
+  Thread::Current()->SetState(Thread::kNative);
+
   InitNativeMethods();
 
   Thread::FinishStartup();
@@ -511,6 +514,9 @@
   // without creating objects.
   Thread::Attach(this, "main", false);
 
+  // Set us to runnable so tools using a runtime can allocate and GC by default
+  Thread::Current()->SetState(Thread::kRunnable);
+
   CHECK_GE(Heap::GetSpaces().size(), 1U);
   class_linker_ = ((Heap::GetSpaces()[0]->IsImageSpace())
                    ? ClassLinker::Create(intern_table_)
diff --git a/src/signal_catcher.cc b/src/signal_catcher.cc
index 41d0fe4..4e8628d 100644
--- a/src/signal_catcher.cc
+++ b/src/signal_catcher.cc
@@ -159,6 +159,7 @@
 
   Runtime* runtime = Runtime::Current();
   runtime->AttachCurrentThread("Signal Catcher", true);
+  Thread::Current()->SetState(Thread::kRunnable);
 
   {
     MutexLock mu(signal_catcher->lock_);
diff --git a/src/thread.cc b/src/thread.cc
index e45da0d..9f54c36 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -498,7 +498,9 @@
       os << "(Native method)";
     } else {
       int line_number = dex_file.GetLineNumFromPC(m, m->ToDexPC(pc));
-      os << "(" << c->GetSourceFile()->ToModifiedUtf8() << ":" << line_number << ")";
+      SirtRef<String> source_file(c->GetSourceFile());
+      os << "(" << (source_file.get() != NULL ? source_file->ToModifiedUtf8() : "unavailable")
+         << ":" << line_number << ")";
     }
     os << "\n";
 
diff --git a/src/thread_list.cc b/src/thread_list.cc
index 26faede..0512186 100644
--- a/src/thread_list.cc
+++ b/src/thread_list.cc
@@ -118,12 +118,11 @@
 void ThreadList::SuspendAll(bool for_debugger) {
   Thread* self = Thread::Current();
 
-  // TODO: add another thread_suspend_lock_ to avoid GC/debugger races.
-
   if (verbose_) {
     LOG(INFO) << *self << " SuspendAll starting..." << (for_debugger ? " (debugger)" : "");
   }
 
+  CHECK_EQ(self->GetState(), Thread::kRunnable);
   ThreadListLocker locker(this);
   Thread* debug_thread = Dbg::GetDebugThread();