Implement LogLineLowStack() properly.

Avoid stack-based buffers used by the log formatting in
__android_log_print().

Move the VLOG(threads) in Thread::InitStackHwm() after the
low stack check as it's not safe to actually log before
that; even the StringPrintf() is using a stack-based buffer.

Bug: 18830897
Change-Id: I13b2166438e871c52ab91dabfe98f2200fd7c1cf
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 4a7103b..5ff7490 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -515,12 +515,6 @@
   size_t read_guard_size;
   GetThreadStack(tlsPtr_.pthread_self, &read_stack_base, &read_stack_size, &read_guard_size);
 
-  // This is included in the SIGQUIT output, but it's useful here for thread debugging.
-  VLOG(threads) << StringPrintf("Native stack is at %p (%s with %s guard)",
-                                read_stack_base,
-                                PrettySize(read_stack_size).c_str(),
-                                PrettySize(read_guard_size).c_str());
-
   tlsPtr_.stack_begin = reinterpret_cast<uint8_t*>(read_stack_base);
   tlsPtr_.stack_size = read_stack_size;
 
@@ -537,6 +531,12 @@
     return false;
   }
 
+  // This is included in the SIGQUIT output, but it's useful here for thread debugging.
+  VLOG(threads) << StringPrintf("Native stack is at %p (%s with %s guard)",
+                                read_stack_base,
+                                PrettySize(read_stack_size).c_str(),
+                                PrettySize(read_guard_size).c_str());
+
   // Set stack_end_ to the bottom of the stack saving space of stack overflows
 
   Runtime* runtime = Runtime::Current();