Revert "Revert "Add basic checks for redefinition.""

This reverts commit f9d41c1d269f3031c0a89e34fc4a04303e186958.

Reason for revert: Fixed issue of missing target skip.

Test: mma -j40 test-art-host
Change-Id: Ibe632e1f3063373950fb873e1716d0439c561297
diff --git a/test/ti-agent/common_helper.cc b/test/ti-agent/common_helper.cc
index ebf1e46..01b6c98 100644
--- a/test/ti-agent/common_helper.cc
+++ b/test/ti-agent/common_helper.cc
@@ -17,6 +17,7 @@
 #include "ti-agent/common_helper.h"
 
 #include <stdio.h>
+#include <sstream>
 
 #include "art_method.h"
 #include "jni.h"
@@ -41,8 +42,24 @@
 
 namespace common_redefine {
 
+static void throwRedefinitionError(jvmtiEnv* jvmti, JNIEnv* env, jclass target, jvmtiError res) {
+  std::stringstream err;
+  char* signature = nullptr;
+  char* generic = nullptr;
+  jvmti->GetClassSignature(target, &signature, &generic);
+  char* error = nullptr;
+  jvmti->GetErrorName(res, &error);
+  err << "Failed to redefine class <" << signature << "> due to " << error;
+  std::string message = err.str();
+  jvmti->Deallocate(reinterpret_cast<unsigned char*>(signature));
+  jvmti->Deallocate(reinterpret_cast<unsigned char*>(generic));
+  jvmti->Deallocate(reinterpret_cast<unsigned char*>(error));
+  env->ThrowNew(env->FindClass("java/lang/Exception"), message.c_str());
+}
+
 using RedefineDirectFunction = jvmtiError (*)(jvmtiEnv*, jclass, jint, const unsigned char*);
-static void DoClassTransformation(jvmtiEnv* jvmti_env, JNIEnv* env,
+static void DoClassTransformation(jvmtiEnv* jvmti_env,
+                                  JNIEnv* env,
                                   jclass target,
                                   jbyteArray class_file_bytes,
                                   jbyteArray dex_file_bytes) {
@@ -63,7 +80,7 @@
     res = f(jvmti_env, target, len, redef_bytes);
   }
   if (res != JVMTI_ERROR_NONE) {
-    printf("Redefinition failed!");
+    throwRedefinitionError(jvmti_env, env, target, res);
   }
 }