Use thread-local is_gc_marking flags for the CC collector.
The currently global is_marking flag is used to check if the read
barrier slow path needs to be taken for GC roots access. Changing it
to a thread-local flag simplifies the fast path check and makes it
easier to do it in assembly code. It also solves the issue that we
need to avoid accessing the global flag during startup before the heap
or the collector object isn't allocated and initialized.
Bug: 12687968
Change-Id: Ibf0dca12f400bf3490188b12dfe96c7de30583e0
diff --git a/runtime/read_barrier-inl.h b/runtime/read_barrier-inl.h
index 7014813..daae401 100644
--- a/runtime/read_barrier-inl.h
+++ b/runtime/read_barrier-inl.h
@@ -79,13 +79,9 @@
MirrorType* ref = *root;
const bool with_read_barrier = kReadBarrierOption == kWithReadBarrier;
if (with_read_barrier && kUseBakerReadBarrier) {
- if (kMaybeDuringStartup && IsDuringStartup()) {
- // During startup, the heap may not be initialized yet. Just
- // return the given ref.
- return ref;
- }
// TODO: separate the read barrier code from the collector code more.
- if (Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->IsMarking()) {
+ Thread* self = Thread::Current();
+ if (self != nullptr && self->GetIsGcMarking()) {
ref = reinterpret_cast<MirrorType*>(Mark(ref));
}
AssertToSpaceInvariant(gc_root_source, ref);
@@ -120,13 +116,9 @@
MirrorType* ref = root->AsMirrorPtr();
const bool with_read_barrier = kReadBarrierOption == kWithReadBarrier;
if (with_read_barrier && kUseBakerReadBarrier) {
- if (kMaybeDuringStartup && IsDuringStartup()) {
- // During startup, the heap may not be initialized yet. Just
- // return the given ref.
- return ref;
- }
// TODO: separate the read barrier code from the collector code more.
- if (Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->IsMarking()) {
+ Thread* self = Thread::Current();
+ if (self != nullptr && self->GetIsGcMarking()) {
ref = reinterpret_cast<MirrorType*>(Mark(ref));
}
AssertToSpaceInvariant(gc_root_source, ref);