Make attached threads visible to the GC sooner

Threads that are created outside the VM and then attached were
allocating objects (Thread, VMThread, a String for the name) before
they were on the internal thread list.  This made for some awkward
moments and required the use of an ALLOC_NO_GC flag.

With this change we now add the thread to the list first, and perform
the object creation afterward.  This is saner from the perspective
of the GC, and may allow us to eliminate ALLOC_NO_GC.

As it happens, the places that would care about a null threadObj
(thread dump, get thread name, debugger request for thread list)
already check for it, making this pretty straightforward.

While I was in here I also took some steps to ensure that threadObj
doesn't get rewritten by the copying collector while something is in
the process of examining it.  This involved a bit of paranoia in the
thread dump.

For bug 2603988.

Change-Id: Ibf2fdb917618277e75a79df113180f1d7f616e14
2 files changed