Address some GC comments
Follow-up from:
https://android-review.googlesource.com/#/c/159650/
Change-Id: Id14f29b4ce5b70b63fcb3e74f8503ae60a3ae444
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 93156ac..eed5cf2 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -78,6 +78,7 @@
// no other threads which can trigger read barriers on the same referent during reference
// processing.
from_ref->Assign(Mark(from_ref->AsMirrorPtr()));
+ DCHECK(!from_ref->IsNull());
}
ConcurrentCopying::~ConcurrentCopying() {
diff --git a/runtime/gc/collector/concurrent_copying.h b/runtime/gc/collector/concurrent_copying.h
index 4f92ea0..f1317b8 100644
--- a/runtime/gc/collector/concurrent_copying.h
+++ b/runtime/gc/collector/concurrent_copying.h
@@ -121,7 +121,7 @@
void VerifyNoFromSpaceReferences() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
accounting::ObjectStack* GetAllocationStack();
accounting::ObjectStack* GetLiveStack();
- void ProcessMarkStack() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ virtual void ProcessMarkStack() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
bool ProcessMarkStackOnce() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
void ProcessMarkStackRef(mirror::Object* to_ref) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
size_t ProcessThreadLocalMarkStacks(bool disable_weak_ref_access)
diff --git a/runtime/gc/collector/garbage_collector.h b/runtime/gc/collector/garbage_collector.h
index e10bef4..cfc4f96 100644
--- a/runtime/gc/collector/garbage_collector.h
+++ b/runtime/gc/collector/garbage_collector.h
@@ -181,8 +181,8 @@
void RecordFreeLOS(const ObjectBytePair& freed);
void DumpPerformanceInfo(std::ostream& os) LOCKS_EXCLUDED(pause_histogram_lock_);
- // Helper functions for querying if objects are marked at compile time. These are used for
- // reading system weaks, processing references.
+ // Helper functions for querying if objects are marked. These are used for processing references,
+ // and will be used for reading system weaks while the GC is running.
virtual mirror::Object* IsMarked(mirror::Object* obj)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
virtual bool IsMarkedHeapReference(mirror::HeapReference<mirror::Object>* obj)
diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc
index 65e6b40..0623fd4 100644
--- a/runtime/gc/collector/mark_compact.cc
+++ b/runtime/gc/collector/mark_compact.cc
@@ -142,7 +142,7 @@
inline mirror::Object* MarkCompact::MarkObject(mirror::Object* obj) {
if (obj == nullptr) {
- return obj;
+ return nullptr;
}
if (kUseBakerOrBrooksReadBarrier) {
// Verify all the objects have the correct forward pointer installed.
diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc
index e0d6d6b..42bca84 100644
--- a/runtime/gc/collector/mark_sweep.cc
+++ b/runtime/gc/collector/mark_sweep.cc
@@ -498,11 +498,6 @@
return !mark_bitmap_->AtomicTestAndSet(obj, visitor);
}
-mirror::Object* MarkSweep::MarkObject(mirror::Object* obj) {
- MarkObject(obj, nullptr, MemberOffset(0));
- return obj;
-}
-
void MarkSweep::MarkHeapReference(mirror::HeapReference<mirror::Object>* ref) {
MarkObject(ref->AsMirrorPtr(), nullptr, MemberOffset(0));
}
diff --git a/runtime/gc/collector/mark_sweep.h b/runtime/gc/collector/mark_sweep.h
index c13755c..1dac342 100644
--- a/runtime/gc/collector/mark_sweep.h
+++ b/runtime/gc/collector/mark_sweep.h
@@ -188,7 +188,10 @@
// Marks an object.
virtual mirror::Object* MarkObject(mirror::Object* obj) OVERRIDE
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
- EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
+ EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) {
+ MarkObject(obj, nullptr, MemberOffset(0));
+ return obj;
+ }
void MarkObject(mirror::Object* obj, mirror::Object* holder, MemberOffset offset)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
@@ -205,7 +208,7 @@
SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_);
protected:
- // Returns true if the object has its bit set in the mark bitmap.
+ // Returns object if the object is marked in the heap bitmap, otherwise null.
virtual mirror::Object* IsMarked(mirror::Object* object) OVERRIDE
SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
diff --git a/runtime/gc/reference_processor.cc b/runtime/gc/reference_processor.cc
index 256cdd2..39ba743 100644
--- a/runtime/gc/reference_processor.cc
+++ b/runtime/gc/reference_processor.cc
@@ -138,7 +138,8 @@
if (concurrent) {
StartPreservingReferences(self);
}
- // TODO: Add smarter logic for preserving soft references.
+ // TODO: Add smarter logic for preserving soft references. The behavior should be a conditional
+ // mark if the SoftReference is supposed to be preserved.
soft_reference_queue_.ForwardSoftReferences(collector);
collector->ProcessMarkStack();
if (concurrent) {