Interpreter entries and instrumentation as a listener.

Make the instrumentation responsible for whether we want method entry/exit
stubs, and allow it to use interpreter entry stubs when instruction by
instruction instrumentation is required. Improve deoptimization so more JDWP
test cases are passing.

Refactor exception debug posting, in particular improve reporting in the
interpreter. Improve class linker exception throwing so that broken dex files
are more likely to be reported. Fixes the performance issue Bug: 8410519.

Fix some error reporting lock level errors for the large object space. Make
fast object verification faster.

Add some debug mode robustness to finding dex PCs in GC maps.

Add printf attributes to JniAbortF and fix errors.

Expand run-test 044 to test return behaviors and fix issues with not throwing
appropriate exceptions for proxies.

Ensure causes are reported with a class linker NoClassDefFoundError and JNI
NoSuchFieldError.

Remove unused debugMe and updateDebuggerFromCode.

There's a minor sizing tweak to the arg array builder, and an extra reference
array check in the interpreter.

Some clean-up of trace code.

Fix reg type cache destructor if it is called after the reg type cache is
shutdown (as is the case in oatdump).

Change-Id: I6519c7b35df77f978d011999354c864f4918e8ce
diff --git a/src/runtime.cc b/src/runtime.cc
index 3e9cd8e..23a7309 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -43,6 +43,7 @@
 #include "jni_internal.h"
 #include "mirror/abstract_method-inl.h"
 #include "mirror/array.h"
+#include "mirror/class-inl.h"
 #include "mirror/class_loader.h"
 #include "mirror/field.h"
 #include "mirror/field-inl.h"
@@ -97,7 +98,7 @@
       stats_enabled_(false),
       method_trace_(0),
       method_trace_file_size_(0),
-      instrumentation_(NULL),
+      instrumentation_(),
       use_compile_time_class_path_(false),
       main_thread_group_(NULL),
       system_thread_group_(NULL) {
@@ -119,11 +120,7 @@
     }
     shutting_down_ = true;
   }
-
-  if (IsMethodTracingActive()) {
-    Trace::Shutdown();
-  }
-  delete instrumentation_;
+  Trace::Shutdown();
 
   // Make sure to let the GC complete if it is running.
   heap_->WaitForConcurrentGcToComplete(self);
@@ -171,8 +168,11 @@
       os << "Aborting thread:\n";
       self->Dump(os);
       if (self->IsExceptionPending()) {
-        os << "Pending " << PrettyTypeOf(self->GetException()) << " on thread:\n"
-           << self->GetException()->Dump();
+        ThrowLocation throw_location;
+        mirror::Throwable* exception = self->GetException(&throw_location);
+        os << "Pending exception " << PrettyTypeOf(exception)
+            << " thrown by '" << throw_location.Dump() << "\n"
+            << exception->Dump();
       }
     }
     DumpAllThreads(os, self);
@@ -652,9 +652,9 @@
 
   // Pre-allocate an OutOfMemoryError for the double-OOME case.
   Thread* self = Thread::Current();
-  self->ThrowNewException("Ljava/lang/OutOfMemoryError;",
+  self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;",
                           "OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available");
-  pre_allocated_OutOfMemoryError_ = self->GetException();
+  pre_allocated_OutOfMemoryError_ = self->GetException(NULL);
   self->ClearException();
 
   // Restore main thread state to kNative as expected by native code.
@@ -794,7 +794,6 @@
 
   is_compiler_ = options->is_compiler_;
   is_zygote_ = options->is_zygote_;
-  interpreter_only_ = options->interpreter_only_;
   is_concurrent_gc_enabled_ = options->is_concurrent_gc_enabled_;
 
   vfprintf_ = options->hook_vfprintf_;
@@ -809,6 +808,10 @@
   intern_table_ = new InternTable;
 
 
+  if (options->interpreter_only_) {
+    GetInstrumentation()->ForceInterpretOnly();
+  }
+
   heap_ = new Heap(options->heap_initial_size_,
                    options->heap_growth_limit_,
                    options->heap_min_free_,
@@ -1196,28 +1199,6 @@
   callee_save_methods_[type] = method;
 }
 
-void Runtime::EnableMethodTracing(Trace* trace) {
-  CHECK(!IsMethodTracingActive());
-  if (instrumentation_ == NULL) {
-    instrumentation_ = new Instrumentation();
-  }
-  instrumentation_->SetTrace(trace);
-}
-
-void Runtime::DisableMethodTracing() {
-  CHECK(IsMethodTracingActive());
-  instrumentation_->RemoveTrace();
-}
-
-bool Runtime::IsMethodTracingActive() const {
-  return instrumentation_ != NULL && instrumentation_->GetTrace() != NULL;
-}
-
-Instrumentation* Runtime::GetInstrumentation() const {
-  CHECK(IsMethodTracingActive());
-  return instrumentation_;
-}
-
 const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject class_loader) {
   if (class_loader == NULL) {
     return GetClassLinker()->GetBootClassPath();