Add missing Barriers in ReplaceReferences

While replacing references we would incorrectly fail to mark objects
if their references are accessed through the 'VisitRoot' visitor
function. This occurs with DexCache and ClassLoader objects, hitting
the caches and the class table respectively. This could cause problems
if a root was replaced and the reference was not replaced in any of
the other paths. In this case the objects page would not get marked
and the GC would (correctly) throw an error saying it missed a write.

Test: ./tools/parallel_run.py -j80
Test: ./art/test/run-test --host 2001
Bug: 134162467
Change-Id: I9a1ad15fd3986e92dfc39c6f87cebdb031492aab
diff --git a/openjdkjvmti/ti_heap.cc b/openjdkjvmti/ti_heap.cc
index b25b4d1..b645590 100644
--- a/openjdkjvmti/ti_heap.cc
+++ b/openjdkjvmti/ti_heap.cc
@@ -58,6 +58,7 @@
 #include "object_callbacks.h"
 #include "object_tagging.h"
 #include "offsets.h"
+#include "read_barrier.h"
 #include "runtime.h"
 #include "scoped_thread_state_change-inl.h"
 #include "stack.h"
@@ -1625,7 +1626,8 @@
         class ResizeReferenceVisitor {
          public:
           using CompressedObj = art::mirror::CompressedReference<art::mirror::Object>;
-          explicit ResizeReferenceVisitor(const ObjectMap& map) : map_(map) {}
+          explicit ResizeReferenceVisitor(const ObjectMap& map, ObjectPtr ref)
+              : map_(map), ref_(ref) {}
 
           // Ignore class roots.
           void VisitRootIfNonNull(CompressedObj* root) const
@@ -1638,7 +1640,7 @@
             auto it = map_.find(root->AsMirrorPtr());
             if (it != map_.end()) {
               root->Assign(it->second);
-              art::WriteBarrier::ForEveryFieldWrite(it->second);
+              art::WriteBarrier::ForEveryFieldWrite(ref_);
             }
           }
 
@@ -1670,9 +1672,10 @@
 
          private:
           const ObjectMap& map_;
+          ObjectPtr ref_;
         };
 
-        ResizeReferenceVisitor rrv(map);
+        ResizeReferenceVisitor rrv(map, ref);
         if (ref->IsClass()) {
           // Class object native roots are the ArtField and ArtMethod 'declaring_class_' fields
           // which we don't want to be messing with as it would break ref-visitor assumptions about