Remove mirror::Reference::java_lang_ref_Reference.

And some #include cleanup after previous CLs removing
static GcRoot<>s.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I56b34637f9d793ed7680696a1eeedd07d061ad00
diff --git a/openjdkjvmti/ti_class.cc b/openjdkjvmti/ti_class.cc
index c9d71b4..726e47e 100644
--- a/openjdkjvmti/ti_class.cc
+++ b/openjdkjvmti/ti_class.cc
@@ -63,7 +63,7 @@
 #include "mirror/object-refvisitor-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/object_reference.h"
-#include "mirror/reference.h"
+#include "mirror/reference-inl.h"
 #include "nativehelper/scoped_local_ref.h"
 #include "reflection.h"
 #include "runtime.h"
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 9043866..b276c81 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -130,7 +130,6 @@
         "mirror/method_handles_lookup.cc",
         "mirror/method_type.cc",
         "mirror/object.cc",
-        "mirror/reference.cc",
         "mirror/stack_trace_element.cc",
         "mirror/string.cc",
         "mirror/throwable.cc",
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 5d09321..ea6d7cc 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -510,7 +510,6 @@
   // Setup java.lang.ref.Reference.
   Handle<mirror::Class> java_lang_ref_Reference(hs.NewHandle(
       AllocClass(self, java_lang_Class.Get(), mirror::Reference::ClassSize(image_pointer_size_))));
-  mirror::Reference::SetClass(java_lang_ref_Reference.Get());
   java_lang_ref_Reference->SetObjectSize(mirror::Reference::InstanceSize());
   mirror::Class::SetStatus(java_lang_ref_Reference, ClassStatus::kResolved, self);
 
@@ -1048,7 +1047,6 @@
   mirror::Method::SetClass(GetClassRoot(ClassRoot::kJavaLangReflectMethod, this).Ptr());
   mirror::Method::SetArrayClass(
       GetClassRoot(ClassRoot::kJavaLangReflectMethodArrayClass, this).Ptr());
-  mirror::Reference::SetClass(GetClassRoot(ClassRoot::kJavaLangRefReference, this));
   mirror::Throwable::SetClass(GetClassRoot(ClassRoot::kJavaLangThrowable, this));
   mirror::StackTraceElement::SetClass(GetClassRoot(ClassRoot::kJavaLangStackTraceElement, this));
   mirror::EmulatedStackFrame::SetClass(
@@ -2135,7 +2133,6 @@
   mirror::Constructor::ResetClass();
   mirror::Field::ResetClass();
   mirror::Method::ResetClass();
-  mirror::Reference::ResetClass();
   mirror::StackTraceElement::ResetClass();
   mirror::String::ResetClass();
   mirror::Throwable::ResetClass();
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h
index 5da5470..6b6fe34 100644
--- a/runtime/class_table-inl.h
+++ b/runtime/class_table-inl.h
@@ -20,6 +20,7 @@
 #include "class_table.h"
 
 #include "gc_root-inl.h"
+#include "mirror/class.h"
 #include "oat_file.h"
 
 namespace art {
diff --git a/runtime/gc/reference_processor-inl.h b/runtime/gc/reference_processor-inl.h
deleted file mode 100644
index 0f47d3d..0000000
--- a/runtime/gc/reference_processor-inl.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ART_RUNTIME_GC_REFERENCE_PROCESSOR_INL_H_
-#define ART_RUNTIME_GC_REFERENCE_PROCESSOR_INL_H_
-
-#include "reference_processor.h"
-
-#include "mirror/reference-inl.h"
-
-namespace art {
-namespace gc {
-
-inline bool ReferenceProcessor::SlowPathEnabled() {
-  return mirror::Reference::GetJavaLangRefReference()->GetSlowPathEnabled();
-}
-
-}  // namespace gc
-}  // namespace art
-
-#endif  // ART_RUNTIME_GC_REFERENCE_PROCESSOR_INL_H_
diff --git a/runtime/gc/reference_processor.cc b/runtime/gc/reference_processor.cc
index 5be7b32..fe4124d 100644
--- a/runtime/gc/reference_processor.cc
+++ b/runtime/gc/reference_processor.cc
@@ -16,8 +16,10 @@
 
 #include "reference_processor.h"
 
+#include "art_field-inl.h"
 #include "base/time_utils.h"
 #include "base/utils.h"
+#include "class_root.h"
 #include "collector/garbage_collector.h"
 #include "jni/java_vm_ext.h"
 #include "mirror/class-inl.h"
@@ -25,7 +27,6 @@
 #include "mirror/reference-inl.h"
 #include "nativehelper/scoped_local_ref.h"
 #include "object_callbacks.h"
-#include "reference_processor-inl.h"
 #include "reflection.h"
 #include "scoped_thread_state_change-inl.h"
 #include "task_processor.h"
@@ -47,15 +48,37 @@
       cleared_references_(Locks::reference_queue_cleared_references_lock_) {
 }
 
+static inline MemberOffset GetSlowPathFlagOffset(ObjPtr<mirror::Class> reference_class)
+    REQUIRES_SHARED(Locks::mutator_lock_) {
+  DCHECK(reference_class == GetClassRoot<mirror::Reference>());
+  // Second static field
+  ArtField* field = reference_class->GetStaticField(1);
+  DCHECK_STREQ(field->GetName(), "slowPathEnabled");
+  return field->GetOffset();
+}
+
+static inline void SetSlowPathFlag(bool enabled) REQUIRES_SHARED(Locks::mutator_lock_) {
+  ObjPtr<mirror::Class> reference_class = GetClassRoot<mirror::Reference>();
+  MemberOffset slow_path_offset = GetSlowPathFlagOffset(reference_class);
+  reference_class->SetFieldBoolean</* kTransactionActive */ false, /* kCheckTransaction */ false>(
+      slow_path_offset, enabled ? 1 : 0);
+}
+
 void ReferenceProcessor::EnableSlowPath() {
-  mirror::Reference::GetJavaLangRefReference()->SetSlowPath(true);
+  SetSlowPathFlag(/* enabled */ true);
 }
 
 void ReferenceProcessor::DisableSlowPath(Thread* self) {
-  mirror::Reference::GetJavaLangRefReference()->SetSlowPath(false);
+  SetSlowPathFlag(/* enabled */ false);
   condition_.Broadcast(self);
 }
 
+bool ReferenceProcessor::SlowPathEnabled() {
+  ObjPtr<mirror::Class> reference_class = GetClassRoot<mirror::Reference>();
+  MemberOffset slow_path_offset = GetSlowPathFlagOffset(reference_class);
+  return reference_class->GetFieldBoolean(slow_path_offset);
+}
+
 void ReferenceProcessor::BroadcastForSlowPath(Thread* self) {
   MutexLock mu(self, *Locks::reference_processor_lock_);
   condition_.Broadcast(self);
diff --git a/runtime/image-inl.h b/runtime/image-inl.h
index 935a1b6..3a66a34 100644
--- a/runtime/image-inl.h
+++ b/runtime/image-inl.h
@@ -22,6 +22,7 @@
 #include "art_method.h"
 #include "imt_conflict_table.h"
 #include "imtable.h"
+#include "mirror/object_array-inl.h"
 #include "read_barrier-inl.h"
 
 namespace art {
diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h
index c9c99e8..aeaaf673 100644
--- a/runtime/mirror/array.h
+++ b/runtime/mirror/array.h
@@ -19,7 +19,6 @@
 
 #include "base/enums.h"
 #include "gc/allocator_type.h"
-#include "gc_root.h"
 #include "obj_ptr.h"
 #include "object.h"
 
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index 72b3179..ab50973 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -36,7 +36,6 @@
 #include "object-inl.h"
 #include "object_array.h"
 #include "read_barrier-inl.h"
-#include "reference-inl.h"
 #include "runtime.h"
 #include "string.h"
 
@@ -857,11 +856,6 @@
   return size;
 }
 
-template<ReadBarrierOption kReadBarrierOption>
-inline bool Class::IsReferenceClass() const {
-  return this == Reference::GetJavaLangRefReference<kReadBarrierOption>();
-}
-
 template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption>
 inline bool Class::IsClassClass() {
   ObjPtr<Class> java_lang_Class = GetClass<kVerifyFlags, kReadBarrierOption>()->
@@ -916,30 +910,6 @@
   return GetFieldObject<ObjectArray<ObjectArray<Class>>>(field_offset);
 }
 
-inline MemberOffset Class::GetDisableIntrinsicFlagOffset() {
-  CHECK(IsReferenceClass());
-  // First static field
-  auto* field = GetStaticField(0);
-  DCHECK_STREQ(field->GetName(), "disableIntrinsic");
-  return field->GetOffset();
-}
-
-inline MemberOffset Class::GetSlowPathFlagOffset() {
-  CHECK(IsReferenceClass());
-  // Second static field
-  auto* field = GetStaticField(1);
-  DCHECK_STREQ(field->GetName(), "slowPathEnabled");
-  return field->GetOffset();
-}
-
-inline bool Class::GetSlowPathEnabled() {
-  return GetFieldBoolean(GetSlowPathFlagOffset());
-}
-
-inline void Class::SetSlowPath(bool enabled) {
-  SetFieldBoolean<false, false>(GetSlowPathFlagOffset(), enabled);
-}
-
 inline void Class::InitializeClassVisitor::operator()(ObjPtr<Object> obj,
                                                       size_t usable_size) const {
   DCHECK_LE(class_size_, usable_size);
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 98e25eb..7d5f539 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -437,9 +437,6 @@
 
   bool IsThrowableClass() REQUIRES_SHARED(Locks::mutator_lock_);
 
-  template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  bool IsReferenceClass() const REQUIRES_SHARED(Locks::mutator_lock_);
-
   static MemberOffset ComponentTypeOffset() {
     return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
   }
@@ -1212,12 +1209,6 @@
   // For proxy class only.
   ObjectArray<ObjectArray<Class>>* GetProxyThrows() REQUIRES_SHARED(Locks::mutator_lock_);
 
-  // For reference class only.
-  MemberOffset GetDisableIntrinsicFlagOffset() REQUIRES_SHARED(Locks::mutator_lock_);
-  MemberOffset GetSlowPathFlagOffset() REQUIRES_SHARED(Locks::mutator_lock_);
-  bool GetSlowPathEnabled() REQUIRES_SHARED(Locks::mutator_lock_);
-  void SetSlowPath(bool enabled) REQUIRES_SHARED(Locks::mutator_lock_);
-
   // May cause thread suspension due to EqualParameters.
   ArtMethod* GetDeclaredConstructor(Thread* self,
                                     Handle<ObjectArray<Class>> args,
diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h
index 9aff9ec..bb86004 100644
--- a/runtime/mirror/dex_cache.h
+++ b/runtime/mirror/dex_cache.h
@@ -21,6 +21,7 @@
 #include "base/bit_utils.h"
 #include "base/mutex.h"
 #include "dex/dex_file_types.h"
+#include "gc_root-inl.h"
 #include "object.h"
 #include "object_array.h"
 
diff --git a/runtime/mirror/method_handle_impl.h b/runtime/mirror/method_handle_impl.h
index 4813b3c..030a49e 100644
--- a/runtime/mirror/method_handle_impl.h
+++ b/runtime/mirror/method_handle_impl.h
@@ -20,7 +20,6 @@
 #include "art_field.h"
 #include "art_method.h"
 #include "class.h"
-#include "gc_root.h"
 #include "method_type.h"
 #include "object.h"
 
diff --git a/runtime/mirror/reference-inl.h b/runtime/mirror/reference-inl.h
index 84e5494..c65f740 100644
--- a/runtime/mirror/reference-inl.h
+++ b/runtime/mirror/reference-inl.h
@@ -49,12 +49,6 @@
   return SetFieldObjectVolatile<kTransactionActive>(ZombieOffset(), zombie);
 }
 
-template<ReadBarrierOption kReadBarrierOption>
-inline Class* Reference::GetJavaLangRefReference() {
-  DCHECK(!java_lang_ref_Reference_.IsNull());
-  return java_lang_ref_Reference_.Read<kReadBarrierOption>();
-}
-
 }  // namespace mirror
 }  // namespace art
 
diff --git a/runtime/mirror/reference.cc b/runtime/mirror/reference.cc
deleted file mode 100644
index 1d0b4c5..0000000
--- a/runtime/mirror/reference.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "reference-inl.h"
-
-#include "art_method.h"
-#include "gc_root-inl.h"
-
-namespace art {
-namespace mirror {
-
-GcRoot<Class> Reference::java_lang_ref_Reference_;
-
-void Reference::SetClass(ObjPtr<Class> java_lang_ref_Reference) {
-  CHECK(java_lang_ref_Reference_.IsNull());
-  CHECK(java_lang_ref_Reference != nullptr);
-  java_lang_ref_Reference_ = GcRoot<Class>(java_lang_ref_Reference);
-}
-
-void Reference::ResetClass() {
-  CHECK(!java_lang_ref_Reference_.IsNull());
-  java_lang_ref_Reference_ = GcRoot<Class>(nullptr);
-}
-
-void Reference::VisitRoots(RootVisitor* visitor) {
-  java_lang_ref_Reference_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
-}
-
-}  // namespace mirror
-}  // namespace art
diff --git a/runtime/mirror/reference.h b/runtime/mirror/reference.h
index b10c294..63c5ae5 100644
--- a/runtime/mirror/reference.h
+++ b/runtime/mirror/reference.h
@@ -20,8 +20,6 @@
 #include "base/enums.h"
 #include "base/macros.h"
 #include "base/mutex.h"
-#include "class.h"
-#include "gc_root.h"
 #include "obj_ptr.h"
 #include "object.h"
 #include "read_barrier_option.h"
@@ -98,12 +96,6 @@
     return GetPendingNext<kWithoutReadBarrier>() == nullptr;
   }
 
-  template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  static ALWAYS_INLINE Class* GetJavaLangRefReference() REQUIRES_SHARED(Locks::mutator_lock_);
-  static void SetClass(ObjPtr<Class> klass);
-  static void ResetClass();
-  static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
-
  private:
   // Note: This avoids a read barrier, it should only be used by the GC.
   HeapReference<Object>* GetReferentReferenceAddr() REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -116,8 +108,6 @@
   HeapReference<Reference> queue_next_;
   HeapReference<Object> referent_;  // Note this is Java volatile:
 
-  static GcRoot<Class> java_lang_ref_Reference_;
-
   friend struct art::ReferenceOffsets;  // for verifying offset information
   friend class gc::ReferenceProcessor;
   friend class gc::ReferenceQueue;
diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h
index 545fe93..c45dc49 100644
--- a/runtime/mirror/string.h
+++ b/runtime/mirror/string.h
@@ -18,7 +18,8 @@
 #define ART_RUNTIME_MIRROR_STRING_H_
 
 #include "gc/allocator_type.h"
-#include "gc_root.h"
+#include "gc_root-inl.h"
+#include "class.h"
 #include "object.h"
 
 namespace art {
diff --git a/runtime/mirror/var_handle.h b/runtime/mirror/var_handle.h
index 4fd18c1..9829456 100644
--- a/runtime/mirror/var_handle.h
+++ b/runtime/mirror/var_handle.h
@@ -19,7 +19,6 @@
 
 #include "handle.h"
 #include "interpreter/shadow_frame.h"
-#include "gc_root.h"
 #include "jvalue.h"
 #include "object.h"
 
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index d126fe9..e42bbc2 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1978,7 +1978,6 @@
   // need to be visited once per GC since they never change.
   mirror::Class::VisitRoots(visitor);
   mirror::Constructor::VisitRoots(visitor);
-  mirror::Reference::VisitRoots(visitor);
   mirror::Method::VisitRoots(visitor);
   mirror::StackTraceElement::VisitRoots(visitor);
   mirror::String::VisitRoots(visitor);