Remove the useless "suspend count already zero" message for new threads.

We can actually detect the expected case of this warning ourselves, and
not emit it. Then we can upgrade the WARNING to a FATAL.

I also tripped over the fact that the operator<< for Thread::State was out
of date, so I've moved the Thread enums up to namespace scope so the script
can automatically generate correct operator<< implementations for us. (All
the high-numbered thread states have been off by one for a couple of weeks.)

Change-Id: I5de573d33d641e5a3cba87b370e9620c8c66e633
diff --git a/src/thread_list.cc b/src/thread_list.cc
index 2526fc2..1a342da 100644
--- a/src/thread_list.cc
+++ b/src/thread_list.cc
@@ -74,8 +74,10 @@
   DCHECK_GE(thread->suspend_count_, thread->debug_suspend_count_) << *thread;
 #endif
   if (delta == -1 && thread->suspend_count_ <= 0) {
-    // This can happen if you attach a thread during a GC.
-    LOG(WARNING) << *thread << " suspend count already zero";
+    // This is expected if you attach a thread during a GC.
+    if (thread->GetState() != kStarting) {
+      LOG(FATAL) << *thread << " suspend count already zero";
+    }
     return;
   }
   thread->suspend_count_ += delta;
@@ -95,7 +97,7 @@
 
   VLOG(threads) << *thread << " self-suspending";
   {
-    ScopedThreadStateChange tsc(thread, Thread::kSuspended);
+    ScopedThreadStateChange tsc(thread, kSuspended);
     while (thread->suspend_count_ != 0) {
       /*
        * Wait for wakeup signal, releasing lock.  The act of releasing
@@ -114,7 +116,7 @@
 
   VLOG(threads) << *self << " SuspendAll starting..." << (for_debugger ? " (debugger)" : "");
 
-  CHECK_EQ(self->GetState(), Thread::kRunnable);
+  CHECK_EQ(self->GetState(), kRunnable);
   ScopedThreadListLock thread_list_lock;
   Thread* debug_thread = Dbg::GetDebugThread();
 
@@ -195,7 +197,7 @@
 
   // Suspend ourselves.
   CHECK_GT(self->suspend_count_, 0);
-  self->SetState(Thread::kSuspended);
+  self->SetState(kSuspended);
   VLOG(threads) << *self << " self-suspending (debugger)";
 
   // Tell JDWP that we've completed suspension. The JDWP thread can't
@@ -215,7 +217,7 @@
     }
   }
   CHECK_EQ(self->suspend_count_, 0);
-  self->SetState(Thread::kRunnable);
+  self->SetState(kRunnable);
   VLOG(threads) << *self << " self-reviving (debugger)";
 }
 
@@ -387,19 +389,19 @@
     VLOG(threads) << *self << " waiting for child " << *child << " to be in thread list...";
 
     // We wait for the child to tell us that it's in the thread list.
-    while (child->GetState() != Thread::kStarting) {
+    while (child->GetState() != kStarting) {
       thread_start_cond_.Wait(thread_list_lock_);
     }
   }
 
   // If we switch out of runnable and then back in, we know there's no pending suspend.
-  self->SetState(Thread::kVmWait);
-  self->SetState(Thread::kRunnable);
+  self->SetState(kVmWait);
+  self->SetState(kRunnable);
 
   // Tell the child that it's safe: it will see any future suspend request.
   ScopedThreadListLock thread_list_lock;
   VLOG(threads) << *self << " telling child " << *child << " it's safe to proceed...";
-  child->SetState(Thread::kVmWait);
+  child->SetState(kVmWait);
   thread_start_cond_.Broadcast();
 }
 
@@ -412,13 +414,13 @@
 
     // Tell our parent that we're in the thread list.
     VLOG(threads) << *self << " telling parent that we're now in thread list...";
-    self->SetState(Thread::kStarting);
+    self->SetState(kStarting);
     thread_start_cond_.Broadcast();
 
     // Wait until our parent tells us there's no suspend still pending
     // from before we were on the thread list.
     VLOG(threads) << *self << " waiting for parent's go-ahead...";
-    while (self->GetState() != Thread::kVmWait) {
+    while (self->GetState() != kVmWait) {
       thread_start_cond_.Wait(thread_list_lock_);
     }
   }
@@ -432,7 +434,7 @@
   {
     ScopedHeapLock heap_lock;
   }
-  self->SetState(Thread::kRunnable);
+  self->SetState(kRunnable);
 }
 
 bool ThreadList::AllOtherThreadsAreDaemons() {
@@ -475,7 +477,7 @@
     bool all_suspended = true;
     for (It it = list_.begin(), end = list_.end(); it != end; ++it) {
       Thread* thread = *it;
-      if (thread != Thread::Current() && thread->GetState() == Thread::kRunnable) {
+      if (thread != Thread::Current() && thread->GetState() == kRunnable) {
         if (!have_complained) {
           LOG(WARNING) << "daemon thread not yet suspended: " << *thread;
           have_complained = true;