Add flock(2)ing on dex-cache files to prevent races

Bug: 9071417
Change-Id: I1ee9ff281867f90fba7a8ed8bbf06b33ac29d511
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 7e3afb5..48e595f 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2218,11 +2218,13 @@
 
 // Set the stack end to that to be used during a stack overflow
 void Thread::SetStackEndForStackOverflow() {
-  // During stack overflow we allow use of the full stack
+  // During stack overflow we allow use of the full stack.
   if (stack_end_ == stack_begin_) {
-    DumpStack(std::cerr);
-    LOG(FATAL) << "Need to increase kStackOverflowReservedBytes (currently "
-               << kStackOverflowReservedBytes << ")";
+    // However, we seem to have already extended to use the full stack.
+    LOG(ERROR) << "Need to increase kStackOverflowReservedBytes (currently "
+               << kStackOverflowReservedBytes << ")?";
+    DumpStack(LOG(ERROR));
+    LOG(FATAL) << "Recursive stack overflow.";
   }
 
   stack_end_ = stack_begin_;