Add even more sanity checks to ti_redefine.cc and skips

Add some additional sanity checks so its more obvious if b/147207934
occurs on any other gcs. The issue is that VisitObjects was missing
some objects causing assumptions to be broken.

Also add blanket skips for all structural redefinition tests to CMS
runs. Since VisitObjects is not reliable on CMS we cannot really use
the structural redefinition feature there.

Test: ./test.py --host
Bug: 147207934
Change-Id: I52aa4f3defb352e988f18b5ab494c9f3a028f0e2
diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc
index e18538e..eea158f 100644
--- a/openjdkjvmti/ti_redefine.cc
+++ b/openjdkjvmti/ti_redefine.cc
@@ -1711,6 +1711,7 @@
   art::Handle<art::mirror::ObjectArray<art::mirror::Class>> new_classes_arr(
       hs.NewHandle(cur_data->GetNewClasses()));
   DCHECK_EQ(old_classes_arr->GetLength(), new_classes_arr->GetLength());
+  DCHECK_GT(old_classes_arr->GetLength(), 0);
   art::Handle<art::mirror::Class> obj_array_class(
       hs.NewHandle(art::GetClassRoot<art::mirror::ObjectArray<art::mirror::Object>>(
           driver_->runtime_->GetClassLinker())));
@@ -1742,12 +1743,15 @@
     int32_t i = pair.second;
     auto iterator = art::ZipLeft(old_classes_arr.Iterate<art::mirror::Class>(),
                                  new_classes_arr.Iterate<art::mirror::Class>());
-    auto [_, new_type] =
-        *(std::find_if(iterator.begin(),
-                       iterator.end(),
-                       [&](auto class_pair) REQUIRES_SHARED(art::Locks::mutator_lock_) {
-                         return class_pair.first == hinstance->GetClass();
-                       }));
+    auto it = std::find_if(iterator.begin(),
+                           iterator.end(),
+                           [&](auto class_pair) REQUIRES_SHARED(art::Locks::mutator_lock_) {
+                             return class_pair.first == hinstance->GetClass();
+                           });
+    DCHECK(it != iterator.end()) << "Unable to find class pair for "
+                                 << hinstance->GetClass()->PrettyClass() << " (instance " << i
+                                 << ")";
+    auto [_, new_type] = *it;
     // Make sure when allocating the new instance we don't add it's finalizer since we will directly
     // replace the old object in the finalizer reference. If we added it here to we would call
     // finalize twice.
@@ -1875,6 +1879,7 @@
         old_types.push_back(hs.NewHandle(obj->AsClass()));
       }
     });
+    DCHECK_GT(old_types.size(), 0u) << "Expected to find at least old_klass!";
     VLOG(plugin) << "Found " << old_types.size() << " types that are/are subtypes of "
                 << old_klass->PrettyClass();
   }
@@ -1903,9 +1908,11 @@
               });
   }
   for (uint32_t i = 0; i < old_types.size(); ++i) {
+    DCHECK(!old_types[i].IsNull()) << i;
     old_classes_arr->Set(i, old_types[i].Get());
   }
   cur_data->SetOldClasses(old_classes_arr.Get());
+  DCHECK_GT(old_classes_arr->GetLength(), 0);
 
   art::Handle<art::mirror::ObjectArray<art::mirror::Class>> new_classes_arr(
       hs.NewHandle(art::mirror::ObjectArray<art::mirror::Class>::Alloc(
diff --git a/test/knownfailures.json b/test/knownfailures.json
index d94cfbd..3574698 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -1109,6 +1109,48 @@
         "description": ["Failing on RI. Needs further investigating. Some of these use smali."]
     },
     {
+      "tests": [
+                  "1974-resize-array",
+                  "1975-hello-structural-transformation",
+                  "1976-hello-structural-static-methods",
+                  "1977-hello-structural-obsolescence",
+                  "1978-regular-obsolete-then-structural-obsolescence",
+                  "1979-threaded-structural-transformation",
+                  "1980-obsolete-object-cleared",
+                  "1981-structural-redef-private-method-handles",
+                  "1982-no-virtuals-structural-redefinition",
+                  "1983-structural-redefinition-failures",
+                  "1984-structural-redefine-field-trace",
+                  "1985-structural-redefine-stack-scope",
+                  "1986-structural-redefine-multi-thread-stack-scope",
+                  "1987-structural-redefine-recursive-stack-scope",
+                  "1988-multi-structural-redefine",
+                  "1989-transform-bad-monitor",
+                  "1990-structural-bad-verify",
+                  "1991-hello-structural-retransform",
+                  "1992-retransform-no-such-field",
+                  "1993-fallback-non-structural",
+                  "1994-final-virtual-structural",
+                  "1995-final-virtual-structural-multithread",
+                  "1996-final-override-virtual-structural",
+                  "1997-structural-shadow-method",
+                  "1998-structural-shadow-field",
+                  "1999-virtual-structural",
+                  "2000-virtual-list-structural",
+                  "2001-virtual-structural-multithread",
+                  "2002-virtual-structural-initializing",
+                  "2003-double-virtual-structural",
+                  "2004-double-virtual-structural-abstract",
+                  "2005-pause-all-redefine-multithreaded",
+                  "2006-virtual-structural-finalizing",
+                  "2007-virtual-structural-finalizable"
+                ],
+        "env_vars": {"ART_USE_READ_BARRIER": "false"},
+        "description": ["Relies on the accuracy of the Heap::VisitObjects function which is broken",
+                        " when READ_BARRIER==false (I.e. On CMS collector)."],
+        "bug": "b/147207934"
+    },
+    {
         "tests": ["530-checker-peel-unroll",
                   "616-cha-unloading",
                   "674-hiddenapi",
@@ -1157,7 +1199,12 @@
                   "1999-virtual-structural",
                   "2000-virtual-list-structural",
                   "2001-virtual-structural-multithread",
-                  "2002-virtual-structural-initializing"
+                  "2002-virtual-structural-initializing",
+                  "2003-double-virtual-structural",
+                  "2004-double-virtual-structural-abstract",
+                  "2005-pause-all-redefine-multithreaded",
+                  "2006-virtual-structural-finalizing",
+                  "2007-virtual-structural-finalizable"
                 ],
         "variant": "jvm",
         "description": ["Doesn't run on RI."]