Merge "Implement ArrayType.NewInstance." into dalvik-dev
diff --git a/src/object.cc b/src/object.cc
index 0b6ad51..8d48250 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -540,7 +540,7 @@
     }
   } else {
     LOG(INFO) << "not invoking " << PrettyMethod(this) << " code=" << (void*) GetCode() << " stub=" << (void*) stub
-        << " started=" << Runtime::Current()->IsStarted();
+              << " started=" << Runtime::Current()->IsStarted();
     if (result != NULL) {
       result->j = 0;
     }
diff --git a/src/thread.cc b/src/thread.cc
index 0a23d46..fdfbf31 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -1252,12 +1252,29 @@
     CHECK(IsExceptionPending());
     return;
   }
+  if (!Runtime::Current()->IsStarted()) {
+    // Something is trying to throw an exception without a started
+    // runtime, which is the common case in the compiler. We won't be
+    // able to invoke the constructor of the exception, so use
+    // AllocObject which will not invoke a constructor.
+    ScopedLocalRef<jthrowable> exception(
+        env, reinterpret_cast<jthrowable>(env->AllocObject(exception_class.get())));
+    if (exception.get() != NULL) {
+      ScopedJniThreadState ts(env);
+      Throwable* t = reinterpret_cast<Throwable*>(ts.Self()->DecodeJObject(exception.get()));
+      ts.Self()->SetException(t);
+    } else {
+      LOG(ERROR) << "Couldn't throw new " << descriptor << " because JNI AllocObject failed: "
+                 << PrettyTypeOf(GetException());
+      CHECK(IsExceptionPending());
+    }
+    return;
+  }
   int rc = env->ThrowNew(exception_class.get(), msg);
   if (rc != JNI_OK) {
     LOG(ERROR) << "Couldn't throw new " << descriptor << " because JNI ThrowNew failed: "
                << PrettyTypeOf(GetException());
     CHECK(IsExceptionPending());
-    return;
   }
 }