Check IsModifiableClass earlier in redefineClasses and retransformClasses

We were not checking this until we actually tried to install the
definition. This meant that we could send dex file data to agents even
if there is no chance of it being used. We would also try to get the
dex file name for non-existant dex files causing crashes.

Bug: 31455788
Test: ./test/testrunner/testrunner.py --host -t 921-hello-failure
Change-Id: I647a057fe916861d555ae142a2961f449f1bc3a5
diff --git a/runtime/openjdkjvmti/transform.cc b/runtime/openjdkjvmti/transform.cc
index 36421b9..bd52cbb 100644
--- a/runtime/openjdkjvmti/transform.cc
+++ b/runtime/openjdkjvmti/transform.cc
@@ -109,6 +109,13 @@
   std::vector<ArtClassDefinition> definitions;
   jvmtiError res = OK;
   for (jint i = 0; i < class_count; i++) {
+    jboolean is_modifiable = JNI_FALSE;
+    res = env->IsModifiableClass(classes[i], &is_modifiable);
+    if (res != OK) {
+      return res;
+    } else if (!is_modifiable) {
+      return ERR(UNMODIFIABLE_CLASS);
+    }
     ArtClassDefinition def;
     res = FillInTransformationData(env, classes[i], &def);
     if (res != OK) {