xref: /aosp_15_r20/art/runtime/read_barrier-inl.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_READ_BARRIER_INL_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_READ_BARRIER_INL_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include "read_barrier.h"
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker #include "gc/accounting/read_barrier_table.h"
23*795d594fSAndroid Build Coastguard Worker #include "gc/collector/concurrent_copying-inl.h"
24*795d594fSAndroid Build Coastguard Worker #include "gc/collector/mark_compact.h"
25*795d594fSAndroid Build Coastguard Worker #include "gc/heap.h"
26*795d594fSAndroid Build Coastguard Worker #include "mirror/object-readbarrier-inl.h"
27*795d594fSAndroid Build Coastguard Worker #include "mirror/object_reference.h"
28*795d594fSAndroid Build Coastguard Worker #include "mirror/reference.h"
29*795d594fSAndroid Build Coastguard Worker #include "runtime.h"
30*795d594fSAndroid Build Coastguard Worker 
31*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
32*795d594fSAndroid Build Coastguard Worker 
33*795d594fSAndroid Build Coastguard Worker template <typename MirrorType, bool kIsVolatile, ReadBarrierOption kReadBarrierOption,
34*795d594fSAndroid Build Coastguard Worker           bool kAlwaysUpdateField>
Barrier(mirror::Object * obj,MemberOffset offset,mirror::HeapReference<MirrorType> * ref_addr)35*795d594fSAndroid Build Coastguard Worker inline MirrorType* ReadBarrier::Barrier(
36*795d594fSAndroid Build Coastguard Worker     mirror::Object* obj, MemberOffset offset, mirror::HeapReference<MirrorType>* ref_addr) {
37*795d594fSAndroid Build Coastguard Worker   constexpr bool with_read_barrier = kReadBarrierOption == kWithReadBarrier;
38*795d594fSAndroid Build Coastguard Worker   if (gUseReadBarrier && with_read_barrier) {
39*795d594fSAndroid Build Coastguard Worker     if (kCheckDebugDisallowReadBarrierCount) {
40*795d594fSAndroid Build Coastguard Worker       Thread* const self = Thread::Current();
41*795d594fSAndroid Build Coastguard Worker       CHECK(self != nullptr);
42*795d594fSAndroid Build Coastguard Worker       CHECK_EQ(self->GetDebugDisallowReadBarrierCount(), 0u);
43*795d594fSAndroid Build Coastguard Worker     }
44*795d594fSAndroid Build Coastguard Worker     if (kUseBakerReadBarrier) {
45*795d594fSAndroid Build Coastguard Worker       // fake_address_dependency (must be zero) is used to create artificial data dependency from
46*795d594fSAndroid Build Coastguard Worker       // the is_gray load to the ref field (ptr) load to avoid needing a load-load barrier between
47*795d594fSAndroid Build Coastguard Worker       // the two.
48*795d594fSAndroid Build Coastguard Worker       uintptr_t fake_address_dependency;
49*795d594fSAndroid Build Coastguard Worker       bool is_gray = IsGray(obj, &fake_address_dependency);
50*795d594fSAndroid Build Coastguard Worker       if (kEnableReadBarrierInvariantChecks) {
51*795d594fSAndroid Build Coastguard Worker         CHECK_EQ(fake_address_dependency, 0U) << obj << " rb_state=" << obj->GetReadBarrierState();
52*795d594fSAndroid Build Coastguard Worker       }
53*795d594fSAndroid Build Coastguard Worker       ref_addr = reinterpret_cast<mirror::HeapReference<MirrorType>*>(
54*795d594fSAndroid Build Coastguard Worker           fake_address_dependency | reinterpret_cast<uintptr_t>(ref_addr));
55*795d594fSAndroid Build Coastguard Worker       MirrorType* ref = ref_addr->template AsMirrorPtr<kIsVolatile>();
56*795d594fSAndroid Build Coastguard Worker       MirrorType* old_ref = ref;
57*795d594fSAndroid Build Coastguard Worker       if (is_gray) {
58*795d594fSAndroid Build Coastguard Worker         // Slow-path.
59*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(ref));
60*795d594fSAndroid Build Coastguard Worker         // If kAlwaysUpdateField is true, update the field atomically. This may fail if mutator
61*795d594fSAndroid Build Coastguard Worker         // updates before us, but it's OK.
62*795d594fSAndroid Build Coastguard Worker         if (kAlwaysUpdateField && ref != old_ref) {
63*795d594fSAndroid Build Coastguard Worker           obj->CasFieldObjectWithoutWriteBarrier<false, false>(offset,
64*795d594fSAndroid Build Coastguard Worker                                                                old_ref,
65*795d594fSAndroid Build Coastguard Worker                                                                ref,
66*795d594fSAndroid Build Coastguard Worker                                                                CASMode::kStrong,
67*795d594fSAndroid Build Coastguard Worker                                                                std::memory_order_release);
68*795d594fSAndroid Build Coastguard Worker         }
69*795d594fSAndroid Build Coastguard Worker       }
70*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(obj, offset, ref);
71*795d594fSAndroid Build Coastguard Worker       return ref;
72*795d594fSAndroid Build Coastguard Worker     } else if (kUseTableLookupReadBarrier) {
73*795d594fSAndroid Build Coastguard Worker       MirrorType* ref = ref_addr->template AsMirrorPtr<kIsVolatile>();
74*795d594fSAndroid Build Coastguard Worker       MirrorType* old_ref = ref;
75*795d594fSAndroid Build Coastguard Worker       // The heap or the collector can be null at startup. TODO: avoid the need for this null check.
76*795d594fSAndroid Build Coastguard Worker       gc::Heap* heap = Runtime::Current()->GetHeap();
77*795d594fSAndroid Build Coastguard Worker       if (heap != nullptr && heap->GetReadBarrierTable()->IsSet(old_ref)) {
78*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(old_ref));
79*795d594fSAndroid Build Coastguard Worker         // Update the field atomically. This may fail if mutator updates before us, but it's ok.
80*795d594fSAndroid Build Coastguard Worker         if (ref != old_ref) {
81*795d594fSAndroid Build Coastguard Worker           obj->CasFieldObjectWithoutWriteBarrier<false, false>(offset,
82*795d594fSAndroid Build Coastguard Worker                                                                old_ref,
83*795d594fSAndroid Build Coastguard Worker                                                                ref,
84*795d594fSAndroid Build Coastguard Worker                                                                CASMode::kStrong,
85*795d594fSAndroid Build Coastguard Worker                                                                std::memory_order_release);
86*795d594fSAndroid Build Coastguard Worker         }
87*795d594fSAndroid Build Coastguard Worker       }
88*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(obj, offset, ref);
89*795d594fSAndroid Build Coastguard Worker       return ref;
90*795d594fSAndroid Build Coastguard Worker     } else {
91*795d594fSAndroid Build Coastguard Worker       LOG(FATAL) << "Unexpected read barrier type";
92*795d594fSAndroid Build Coastguard Worker       UNREACHABLE();
93*795d594fSAndroid Build Coastguard Worker     }
94*795d594fSAndroid Build Coastguard Worker   } else if (kReadBarrierOption == kWithFromSpaceBarrier) {
95*795d594fSAndroid Build Coastguard Worker     DCHECK(gUseUserfaultfd);
96*795d594fSAndroid Build Coastguard Worker     MirrorType* old = ref_addr->template AsMirrorPtr<kIsVolatile>();
97*795d594fSAndroid Build Coastguard Worker     mirror::Object* ref =
98*795d594fSAndroid Build Coastguard Worker         Runtime::Current()->GetHeap()->MarkCompactCollector()->GetFromSpaceAddrFromBarrier(old);
99*795d594fSAndroid Build Coastguard Worker     return reinterpret_cast<MirrorType*>(ref);
100*795d594fSAndroid Build Coastguard Worker   } else {
101*795d594fSAndroid Build Coastguard Worker     // No read barrier.
102*795d594fSAndroid Build Coastguard Worker     return ref_addr->template AsMirrorPtr<kIsVolatile>();
103*795d594fSAndroid Build Coastguard Worker   }
104*795d594fSAndroid Build Coastguard Worker }
105*795d594fSAndroid Build Coastguard Worker 
106*795d594fSAndroid Build Coastguard Worker template <typename MirrorType, ReadBarrierOption kReadBarrierOption>
BarrierForRoot(MirrorType ** root,GcRootSource * gc_root_source)107*795d594fSAndroid Build Coastguard Worker inline MirrorType* ReadBarrier::BarrierForRoot(MirrorType** root,
108*795d594fSAndroid Build Coastguard Worker                                                GcRootSource* gc_root_source) {
109*795d594fSAndroid Build Coastguard Worker   MirrorType* ref = *root;
110*795d594fSAndroid Build Coastguard Worker   const bool with_read_barrier = kReadBarrierOption == kWithReadBarrier;
111*795d594fSAndroid Build Coastguard Worker   if (gUseReadBarrier && with_read_barrier) {
112*795d594fSAndroid Build Coastguard Worker     if (kCheckDebugDisallowReadBarrierCount) {
113*795d594fSAndroid Build Coastguard Worker       Thread* const self = Thread::Current();
114*795d594fSAndroid Build Coastguard Worker       CHECK(self != nullptr);
115*795d594fSAndroid Build Coastguard Worker       CHECK_EQ(self->GetDebugDisallowReadBarrierCount(), 0u);
116*795d594fSAndroid Build Coastguard Worker     }
117*795d594fSAndroid Build Coastguard Worker     if (kUseBakerReadBarrier) {
118*795d594fSAndroid Build Coastguard Worker       // TODO: separate the read barrier code from the collector code more.
119*795d594fSAndroid Build Coastguard Worker       Thread* self = Thread::Current();
120*795d594fSAndroid Build Coastguard Worker       if (self != nullptr && self->GetIsGcMarking()) {
121*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(ref));
122*795d594fSAndroid Build Coastguard Worker       }
123*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(gc_root_source, ref);
124*795d594fSAndroid Build Coastguard Worker       return ref;
125*795d594fSAndroid Build Coastguard Worker     } else if (kUseTableLookupReadBarrier) {
126*795d594fSAndroid Build Coastguard Worker       Thread* self = Thread::Current();
127*795d594fSAndroid Build Coastguard Worker       if (self != nullptr &&
128*795d594fSAndroid Build Coastguard Worker           self->GetIsGcMarking() &&
129*795d594fSAndroid Build Coastguard Worker           Runtime::Current()->GetHeap()->GetReadBarrierTable()->IsSet(ref)) {
130*795d594fSAndroid Build Coastguard Worker         MirrorType* old_ref = ref;
131*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(old_ref));
132*795d594fSAndroid Build Coastguard Worker         // Update the field atomically. This may fail if mutator updates before us, but it's ok.
133*795d594fSAndroid Build Coastguard Worker         if (ref != old_ref) {
134*795d594fSAndroid Build Coastguard Worker           Atomic<MirrorType*>* atomic_root = reinterpret_cast<Atomic<MirrorType*>*>(root);
135*795d594fSAndroid Build Coastguard Worker           atomic_root->CompareAndSetStrongRelaxed(old_ref, ref);
136*795d594fSAndroid Build Coastguard Worker         }
137*795d594fSAndroid Build Coastguard Worker       }
138*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(gc_root_source, ref);
139*795d594fSAndroid Build Coastguard Worker       return ref;
140*795d594fSAndroid Build Coastguard Worker     } else {
141*795d594fSAndroid Build Coastguard Worker       LOG(FATAL) << "Unexpected read barrier type";
142*795d594fSAndroid Build Coastguard Worker       UNREACHABLE();
143*795d594fSAndroid Build Coastguard Worker     }
144*795d594fSAndroid Build Coastguard Worker   } else if (kReadBarrierOption == kWithFromSpaceBarrier) {
145*795d594fSAndroid Build Coastguard Worker     DCHECK(gUseUserfaultfd);
146*795d594fSAndroid Build Coastguard Worker     mirror::Object* from_ref =
147*795d594fSAndroid Build Coastguard Worker         Runtime::Current()->GetHeap()->MarkCompactCollector()->GetFromSpaceAddrFromBarrier(ref);
148*795d594fSAndroid Build Coastguard Worker     return reinterpret_cast<MirrorType*>(from_ref);
149*795d594fSAndroid Build Coastguard Worker   } else {
150*795d594fSAndroid Build Coastguard Worker     return ref;
151*795d594fSAndroid Build Coastguard Worker   }
152*795d594fSAndroid Build Coastguard Worker }
153*795d594fSAndroid Build Coastguard Worker 
154*795d594fSAndroid Build Coastguard Worker // TODO: Reduce copy paste
155*795d594fSAndroid Build Coastguard Worker template <typename MirrorType, ReadBarrierOption kReadBarrierOption>
BarrierForRoot(mirror::CompressedReference<MirrorType> * root,GcRootSource * gc_root_source)156*795d594fSAndroid Build Coastguard Worker inline MirrorType* ReadBarrier::BarrierForRoot(mirror::CompressedReference<MirrorType>* root,
157*795d594fSAndroid Build Coastguard Worker                                                GcRootSource* gc_root_source) {
158*795d594fSAndroid Build Coastguard Worker   MirrorType* ref = root->AsMirrorPtr();
159*795d594fSAndroid Build Coastguard Worker   const bool with_read_barrier = kReadBarrierOption == kWithReadBarrier;
160*795d594fSAndroid Build Coastguard Worker   if (gUseReadBarrier && with_read_barrier) {
161*795d594fSAndroid Build Coastguard Worker     if (kCheckDebugDisallowReadBarrierCount) {
162*795d594fSAndroid Build Coastguard Worker       Thread* const self = Thread::Current();
163*795d594fSAndroid Build Coastguard Worker       CHECK(self != nullptr);
164*795d594fSAndroid Build Coastguard Worker       CHECK_EQ(self->GetDebugDisallowReadBarrierCount(), 0u);
165*795d594fSAndroid Build Coastguard Worker     }
166*795d594fSAndroid Build Coastguard Worker     if (kUseBakerReadBarrier) {
167*795d594fSAndroid Build Coastguard Worker       // TODO: separate the read barrier code from the collector code more.
168*795d594fSAndroid Build Coastguard Worker       Thread* self = Thread::Current();
169*795d594fSAndroid Build Coastguard Worker       if (self != nullptr && self->GetIsGcMarking()) {
170*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(ref));
171*795d594fSAndroid Build Coastguard Worker       }
172*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(gc_root_source, ref);
173*795d594fSAndroid Build Coastguard Worker       return ref;
174*795d594fSAndroid Build Coastguard Worker     } else if (kUseTableLookupReadBarrier) {
175*795d594fSAndroid Build Coastguard Worker       Thread* self = Thread::Current();
176*795d594fSAndroid Build Coastguard Worker       if (self != nullptr &&
177*795d594fSAndroid Build Coastguard Worker           self->GetIsGcMarking() &&
178*795d594fSAndroid Build Coastguard Worker           Runtime::Current()->GetHeap()->GetReadBarrierTable()->IsSet(ref)) {
179*795d594fSAndroid Build Coastguard Worker         auto old_ref = mirror::CompressedReference<MirrorType>::FromMirrorPtr(ref);
180*795d594fSAndroid Build Coastguard Worker         ref = reinterpret_cast<MirrorType*>(Mark(ref));
181*795d594fSAndroid Build Coastguard Worker         auto new_ref = mirror::CompressedReference<MirrorType>::FromMirrorPtr(ref);
182*795d594fSAndroid Build Coastguard Worker         // Update the field atomically. This may fail if mutator updates before us, but it's ok.
183*795d594fSAndroid Build Coastguard Worker         if (new_ref.AsMirrorPtr() != old_ref.AsMirrorPtr()) {
184*795d594fSAndroid Build Coastguard Worker           auto* atomic_root =
185*795d594fSAndroid Build Coastguard Worker               reinterpret_cast<Atomic<mirror::CompressedReference<MirrorType>>*>(root);
186*795d594fSAndroid Build Coastguard Worker           atomic_root->CompareAndSetStrongRelaxed(old_ref, new_ref);
187*795d594fSAndroid Build Coastguard Worker         }
188*795d594fSAndroid Build Coastguard Worker       }
189*795d594fSAndroid Build Coastguard Worker       AssertToSpaceInvariant(gc_root_source, ref);
190*795d594fSAndroid Build Coastguard Worker       return ref;
191*795d594fSAndroid Build Coastguard Worker     } else {
192*795d594fSAndroid Build Coastguard Worker       LOG(FATAL) << "Unexpected read barrier type";
193*795d594fSAndroid Build Coastguard Worker       UNREACHABLE();
194*795d594fSAndroid Build Coastguard Worker     }
195*795d594fSAndroid Build Coastguard Worker   } else if (kReadBarrierOption == kWithFromSpaceBarrier) {
196*795d594fSAndroid Build Coastguard Worker     DCHECK(gUseUserfaultfd);
197*795d594fSAndroid Build Coastguard Worker     mirror::Object* from_ref =
198*795d594fSAndroid Build Coastguard Worker         Runtime::Current()->GetHeap()->MarkCompactCollector()->GetFromSpaceAddrFromBarrier(ref);
199*795d594fSAndroid Build Coastguard Worker     return reinterpret_cast<MirrorType*>(from_ref);
200*795d594fSAndroid Build Coastguard Worker   } else {
201*795d594fSAndroid Build Coastguard Worker     return ref;
202*795d594fSAndroid Build Coastguard Worker   }
203*795d594fSAndroid Build Coastguard Worker }
204*795d594fSAndroid Build Coastguard Worker 
205*795d594fSAndroid Build Coastguard Worker template <typename MirrorType>
IsMarked(MirrorType * ref)206*795d594fSAndroid Build Coastguard Worker inline MirrorType* ReadBarrier::IsMarked(MirrorType* ref) {
207*795d594fSAndroid Build Coastguard Worker   // Only read-barrier configurations can have mutators run while
208*795d594fSAndroid Build Coastguard Worker   // the GC is marking.
209*795d594fSAndroid Build Coastguard Worker   if (!gUseReadBarrier) {
210*795d594fSAndroid Build Coastguard Worker     return ref;
211*795d594fSAndroid Build Coastguard Worker   }
212*795d594fSAndroid Build Coastguard Worker   // IsMarked does not handle null, so handle it here.
213*795d594fSAndroid Build Coastguard Worker   if (ref == nullptr) {
214*795d594fSAndroid Build Coastguard Worker     return nullptr;
215*795d594fSAndroid Build Coastguard Worker   }
216*795d594fSAndroid Build Coastguard Worker   // IsMarked should only be called when the GC is marking.
217*795d594fSAndroid Build Coastguard Worker   if (!Thread::Current()->GetIsGcMarking()) {
218*795d594fSAndroid Build Coastguard Worker     return ref;
219*795d594fSAndroid Build Coastguard Worker   }
220*795d594fSAndroid Build Coastguard Worker 
221*795d594fSAndroid Build Coastguard Worker   return reinterpret_cast<MirrorType*>(
222*795d594fSAndroid Build Coastguard Worker       Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->IsMarked(ref));
223*795d594fSAndroid Build Coastguard Worker }
224*795d594fSAndroid Build Coastguard Worker 
IsDuringStartup()225*795d594fSAndroid Build Coastguard Worker inline bool ReadBarrier::IsDuringStartup() {
226*795d594fSAndroid Build Coastguard Worker   gc::Heap* heap = Runtime::Current()->GetHeap();
227*795d594fSAndroid Build Coastguard Worker   if (heap == nullptr) {
228*795d594fSAndroid Build Coastguard Worker     // During startup, the heap can be null.
229*795d594fSAndroid Build Coastguard Worker     return true;
230*795d594fSAndroid Build Coastguard Worker   }
231*795d594fSAndroid Build Coastguard Worker   if (heap->CurrentCollectorType() != gc::kCollectorTypeCC) {
232*795d594fSAndroid Build Coastguard Worker     // CC isn't running.
233*795d594fSAndroid Build Coastguard Worker     return true;
234*795d594fSAndroid Build Coastguard Worker   }
235*795d594fSAndroid Build Coastguard Worker   gc::collector::ConcurrentCopying* collector = heap->ConcurrentCopyingCollector();
236*795d594fSAndroid Build Coastguard Worker   if (collector == nullptr) {
237*795d594fSAndroid Build Coastguard Worker     // During startup, the collector can be null.
238*795d594fSAndroid Build Coastguard Worker     return true;
239*795d594fSAndroid Build Coastguard Worker   }
240*795d594fSAndroid Build Coastguard Worker   return false;
241*795d594fSAndroid Build Coastguard Worker }
242*795d594fSAndroid Build Coastguard Worker 
AssertToSpaceInvariant(mirror::Object * obj,MemberOffset offset,mirror::Object * ref)243*795d594fSAndroid Build Coastguard Worker inline void ReadBarrier::AssertToSpaceInvariant(mirror::Object* obj, MemberOffset offset,
244*795d594fSAndroid Build Coastguard Worker                                                 mirror::Object* ref) {
245*795d594fSAndroid Build Coastguard Worker   if (kEnableToSpaceInvariantChecks) {
246*795d594fSAndroid Build Coastguard Worker     if (ref == nullptr || IsDuringStartup()) {
247*795d594fSAndroid Build Coastguard Worker       return;
248*795d594fSAndroid Build Coastguard Worker     }
249*795d594fSAndroid Build Coastguard Worker     Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->
250*795d594fSAndroid Build Coastguard Worker         AssertToSpaceInvariant(obj, offset, ref);
251*795d594fSAndroid Build Coastguard Worker   }
252*795d594fSAndroid Build Coastguard Worker }
253*795d594fSAndroid Build Coastguard Worker 
AssertToSpaceInvariant(GcRootSource * gc_root_source,mirror::Object * ref)254*795d594fSAndroid Build Coastguard Worker inline void ReadBarrier::AssertToSpaceInvariant(GcRootSource* gc_root_source,
255*795d594fSAndroid Build Coastguard Worker                                                 mirror::Object* ref) {
256*795d594fSAndroid Build Coastguard Worker   if (kEnableToSpaceInvariantChecks) {
257*795d594fSAndroid Build Coastguard Worker     if (ref == nullptr || IsDuringStartup()) {
258*795d594fSAndroid Build Coastguard Worker       return;
259*795d594fSAndroid Build Coastguard Worker     }
260*795d594fSAndroid Build Coastguard Worker     Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->
261*795d594fSAndroid Build Coastguard Worker         AssertToSpaceInvariant(gc_root_source, ref);
262*795d594fSAndroid Build Coastguard Worker   }
263*795d594fSAndroid Build Coastguard Worker }
264*795d594fSAndroid Build Coastguard Worker 
Mark(mirror::Object * obj)265*795d594fSAndroid Build Coastguard Worker inline mirror::Object* ReadBarrier::Mark(mirror::Object* obj) {
266*795d594fSAndroid Build Coastguard Worker   return Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->MarkFromReadBarrier(obj);
267*795d594fSAndroid Build Coastguard Worker }
268*795d594fSAndroid Build Coastguard Worker 
IsGray(mirror::Object * obj,uintptr_t * fake_address_dependency)269*795d594fSAndroid Build Coastguard Worker inline bool ReadBarrier::IsGray(mirror::Object* obj, uintptr_t* fake_address_dependency) {
270*795d594fSAndroid Build Coastguard Worker   return obj->GetReadBarrierState(fake_address_dependency) == kGrayState;
271*795d594fSAndroid Build Coastguard Worker }
272*795d594fSAndroid Build Coastguard Worker 
IsGray(mirror::Object * obj)273*795d594fSAndroid Build Coastguard Worker inline bool ReadBarrier::IsGray(mirror::Object* obj) {
274*795d594fSAndroid Build Coastguard Worker   // Use a load-acquire to load the read barrier bit to avoid reordering with the subsequent load.
275*795d594fSAndroid Build Coastguard Worker   // GetReadBarrierStateAcquire() has load-acquire semantics.
276*795d594fSAndroid Build Coastguard Worker   return obj->GetReadBarrierStateAcquire() == kGrayState;
277*795d594fSAndroid Build Coastguard Worker }
278*795d594fSAndroid Build Coastguard Worker 
279*795d594fSAndroid Build Coastguard Worker }  // namespace art
280*795d594fSAndroid Build Coastguard Worker 
281*795d594fSAndroid Build Coastguard Worker #endif  // ART_RUNTIME_READ_BARRIER_INL_H_
282