Clean up `ObjectReference<>` use with vreg values. am: 970291ce79

Original change: https://android-review.googlesource.com/c/platform/art/+/2388217

Change-Id: I927166572b67201cc5e75353daf7d6a4ba0d15fe
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/runtime/gc/collector/mark_compact.h b/runtime/gc/collector/mark_compact.h
index f97c0d7..2a10bcd 100644
--- a/runtime/gc/collector/mark_compact.h
+++ b/runtime/gc/collector/mark_compact.h
@@ -159,7 +159,7 @@
   };
 
  private:
-  using ObjReference = mirror::ObjectReference</*kPoisonReferences*/ false, mirror::Object>;
+  using ObjReference = mirror::CompressedReference<mirror::Object>;
   // Number of bits (live-words) covered by a single chunk-info (below)
   // entry/word.
   // TODO: Since popcount is performed usomg SIMD instructions, we should
diff --git a/runtime/gc_root-inl.h b/runtime/gc_root-inl.h
index 7795c66..e561d29 100644
--- a/runtime/gc_root-inl.h
+++ b/runtime/gc_root-inl.h
@@ -34,8 +34,12 @@
 }
 
 template<class MirrorType>
+inline GcRoot<MirrorType>::GcRoot(mirror::CompressedReference<mirror::Object> ref)
+    : root_(ref) { }
+
+template<class MirrorType>
 inline GcRoot<MirrorType>::GcRoot(MirrorType* ref)
-    : root_(mirror::CompressedReference<mirror::Object>::FromMirrorPtr(ref)) { }
+    : GcRoot(mirror::CompressedReference<mirror::Object>::FromMirrorPtr(ref)) { }
 
 template<class MirrorType>
 inline GcRoot<MirrorType>::GcRoot(ObjPtr<MirrorType> ref)
diff --git a/runtime/gc_root.h b/runtime/gc_root.h
index 553f3d6..3f207ec 100644
--- a/runtime/gc_root.h
+++ b/runtime/gc_root.h
@@ -215,6 +215,8 @@
   }
 
   ALWAYS_INLINE GcRoot() {}
+  explicit ALWAYS_INLINE GcRoot(mirror::CompressedReference<mirror::Object> ref)
+      REQUIRES_SHARED(Locks::mutator_lock_);
   explicit ALWAYS_INLINE GcRoot(MirrorType* ref)
       REQUIRES_SHARED(Locks::mutator_lock_);
   explicit ALWAYS_INLINE GcRoot(ObjPtr<MirrorType> ref)
diff --git a/runtime/mirror/object_reference.h b/runtime/mirror/object_reference.h
index 4c3a5dc..ce123fa 100644
--- a/runtime/mirror/object_reference.h
+++ b/runtime/mirror/object_reference.h
@@ -21,6 +21,7 @@
 #include <string_view>
 
 #include "base/atomic.h"
+#include "base/casts.h"
 #include "base/locks.h"  // For Locks::mutator_lock_.
 #include "heap_poisoning.h"
 #include "obj_ptr.h"
@@ -95,14 +96,14 @@
  public:
   // Compress reference to its bit representation.
   static uint32_t Compress(MirrorType* mirror_ptr) {
-    uintptr_t as_bits = reinterpret_cast<uintptr_t>(mirror_ptr);
-    return static_cast<uint32_t>(kPoisonReferences ? -as_bits : as_bits);
+    uint32_t as_bits = reinterpret_cast32<uint32_t>(mirror_ptr);
+    return kPoisonReferences ? -as_bits : as_bits;
   }
 
   // Uncompress an encoded reference from its bit representation.
   static MirrorType* Decompress(uint32_t ref) {
-    uintptr_t as_bits = kPoisonReferences ? -ref : ref;
-    return reinterpret_cast<MirrorType*>(as_bits);
+    uint32_t as_bits = kPoisonReferences ? -ref : ref;
+    return reinterpret_cast32<MirrorType*>(as_bits);
   }
 
   // Convert an ObjPtr to a compressed reference.
@@ -144,10 +145,6 @@
     return reference_ == 0;
   }
 
-  uint32_t AsVRegValue() const {
-    return reference_;
-  }
-
   static ObjectReference<kPoisonReferences, MirrorType> FromMirrorPtr(MirrorType* mirror_ptr)
       REQUIRES_SHARED(Locks::mutator_lock_) {
     return ObjectReference<kPoisonReferences, MirrorType>(mirror_ptr);
@@ -230,9 +227,19 @@
     return CompressedReference<MirrorType>(p);
   }
 
+  static CompressedReference<MirrorType> FromVRegValue(uint32_t vreg_value) {
+    CompressedReference<MirrorType> result(nullptr);
+    result.reference_ = vreg_value;
+    return result;
+  }
+
+  uint32_t AsVRegValue() const {
+    return this->reference_;
+  }
+
  private:
   explicit CompressedReference(MirrorType* p) REQUIRES_SHARED(Locks::mutator_lock_)
-      : mirror::ObjectReference<false, MirrorType>(p) {}
+      : ObjectReference<false, MirrorType>(p) {}
 };
 
 }  // namespace mirror