Fix oatdump and valgrind.

Bug: 11531382
Move allocation instrumentation out of runtime into instrumentation. Don't
attempt to suspend threads in unstarted runtimes.
Make indentation support sputc returning eof, on which it will sync and try
again. A further failure likely means the disk is full.
Move the dump-oat output directory to be art as now there's too much output to
fit all the dump-oat data in our standard /tmp.

Change-Id: I8ea848ace318552c180e2efa46570288ff1ca62c
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 8316bc5..4070324 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -39,6 +39,9 @@
 #include "thread_list.h"
 
 namespace art {
+
+extern void SetQuickAllocEntryPointsInstrumented(bool instrumented);
+
 namespace instrumentation {
 
 // Do we want to deoptimize for method entry and exit listeners or just try to intercept
@@ -391,6 +394,55 @@
   }
 }
 
+static void ResetQuickAllocEntryPointsForThread(Thread* thread, void* arg) {
+  thread->ResetQuickAllocEntryPointsForThread();
+}
+
+void Instrumentation::InstrumentQuickAllocEntryPoints() {
+  // TODO: the read of quick_alloc_entry_points_instrumentation_counter_ is racey and this code
+  //       should be guarded by a lock.
+  DCHECK_GE(quick_alloc_entry_points_instrumentation_counter_, 0U);
+  bool enable_instrumentation = (quick_alloc_entry_points_instrumentation_counter_ == 0);
+  quick_alloc_entry_points_instrumentation_counter_++;
+  if (enable_instrumentation) {
+    // Instrumentation wasn't enabled so enable it.
+    SetQuickAllocEntryPointsInstrumented(true);
+    Runtime* runtime = Runtime::Current();
+    if (runtime->IsStarted()) {
+      ThreadList* tl = runtime->GetThreadList();
+      Thread* self = Thread::Current();
+      tl->SuspendAll();
+      {
+        MutexLock mu(self, *Locks::thread_list_lock_);
+        tl->ForEach(ResetQuickAllocEntryPointsForThread, NULL);
+      }
+      tl->ResumeAll();
+    }
+  }
+}
+
+void Instrumentation::UninstrumentQuickAllocEntryPoints() {
+  // TODO: the read of quick_alloc_entry_points_instrumentation_counter_ is racey and this code
+  //       should be guarded by a lock.
+  DCHECK_GT(quick_alloc_entry_points_instrumentation_counter_, 0U);
+  quick_alloc_entry_points_instrumentation_counter_--;
+  bool disable_instrumentation = (quick_alloc_entry_points_instrumentation_counter_ == 0);
+  if (disable_instrumentation) {
+    SetQuickAllocEntryPointsInstrumented(false);
+    Runtime* runtime = Runtime::Current();
+    if (runtime->IsStarted()) {
+      ThreadList* tl = Runtime::Current()->GetThreadList();
+      Thread* self = Thread::Current();
+      tl->SuspendAll();
+      {
+        MutexLock mu(self, *Locks::thread_list_lock_);
+        tl->ForEach(ResetQuickAllocEntryPointsForThread, NULL);
+      }
+      tl->ResumeAll();
+    }
+  }
+}
+
 void Instrumentation::UpdateMethodsCode(mirror::ArtMethod* method, const void* code) const {
   if (LIKELY(!instrumentation_stubs_installed_)) {
     method->SetEntryPointFromCompiledCode(code);