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/native/dalvik_system_VMDebug.cc b/src/native/dalvik_system_VMDebug.cc
index dc07a31..992998e 100644
--- a/src/native/dalvik_system_VMDebug.cc
+++ b/src/native/dalvik_system_VMDebug.cc
@@ -18,6 +18,7 @@
 #include <unistd.h>
 
 #include "class_linker.h"
+#include "common_throws.h"
 #include "debugger.h"
 #include "hprof/hprof.h"
 #include "jni_internal.h"
@@ -68,8 +69,9 @@
   int fd = dup(originalFd);
   if (fd < 0) {
     ScopedObjectAccess soa(env);
-    Thread::Current()->ThrowNewExceptionF("Ljava/lang/RuntimeException;",
-                                          "dup(%d) failed: %s", originalFd, strerror(errno));
+    ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow();
+    soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/RuntimeException;",
+                                   "dup(%d) failed: %s", originalFd, strerror(errno));
     return;
   }
 
@@ -90,7 +92,7 @@
 }
 
 static jboolean VMDebug_isMethodTracingActive(JNIEnv*, jclass) {
-  return Runtime::Current()->IsMethodTracingActive();
+  return Trace::IsMethodTracingActive();
 }
 
 static void VMDebug_stopMethodTracing(JNIEnv*, jclass) {
@@ -119,24 +121,26 @@
   return Dbg::LastDebuggerActivity();
 }
 
-static void VMDebug_startInstructionCounting(JNIEnv* env, jclass) {
+static void ThrowUnsupportedOperationException(JNIEnv* env) {
   ScopedObjectAccess soa(env);
-  Thread::Current()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", "");
+  ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow();
+  soa.Self()->ThrowNewException(throw_location, "Ljava/lang/UnsupportedOperationException;", NULL);
+}
+
+static void VMDebug_startInstructionCounting(JNIEnv* env, jclass) {
+  ThrowUnsupportedOperationException(env);
 }
 
 static void VMDebug_stopInstructionCounting(JNIEnv* env, jclass) {
-  ScopedObjectAccess soa(env);
-  Thread::Current()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", "");
+  ThrowUnsupportedOperationException(env);
 }
 
 static void VMDebug_getInstructionCount(JNIEnv* env, jclass, jintArray /*javaCounts*/) {
-  ScopedObjectAccess soa(env);
-  Thread::Current()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", "");
+  ThrowUnsupportedOperationException(env);
 }
 
 static void VMDebug_resetInstructionCount(JNIEnv* env, jclass) {
-  ScopedObjectAccess soa(env);
-  Thread::Current()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", "");
+  ThrowUnsupportedOperationException(env);
 }
 
 static void VMDebug_printLoadedClasses(JNIEnv* env, jclass, jint flags) {
@@ -166,8 +170,7 @@
   // Only one of these may be NULL.
   if (javaFilename == NULL && javaFd == NULL) {
     ScopedObjectAccess soa(env);
-    Thread::Current()->ThrowNewException("Ljava/lang/NullPointerException;",
-                                         "fileName == null && fd == null");
+    ThrowNullPointerException(NULL, "fileName == null && fd == null");
     return;
   }
 
@@ -187,8 +190,7 @@
     fd = jniGetFDFromFileDescriptor(env, javaFd);
     if (fd < 0) {
       ScopedObjectAccess soa(env);
-      Thread::Current()->ThrowNewException("Ljava/lang/RuntimeException;",
-                                           "Invalid file descriptor");
+      ThrowRuntimeException("Invalid file descriptor");
       return;
     }
   }