Fix RecordFree to take signed parameters.
RecordFree can get negative bytes allocated when background
compaction foreground transitions occur. This caused a DCHECK to
fail on debug builds. Also did some refactoring in
PreProcessReferences.
Bug: 13568814
Change-Id: I57543f1c78544a94f1d241459698b736dba8cfa8
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index a763e37..79417a6 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1101,8 +1101,12 @@
GetLiveBitmap()->Walk(Heap::VerificationCallback, this);
}
-void Heap::RecordFree(size_t freed_objects, size_t freed_bytes) {
- DCHECK_LE(freed_bytes, num_bytes_allocated_.Load());
+void Heap::RecordFree(ssize_t freed_objects, ssize_t freed_bytes) {
+ // Use signed comparison since freed bytes can be negative when background compaction foreground
+ // transitions occurs. This is caused by the moving objects from a bump pointer space to a
+ // free list backed space typically increasing memory footprint due to padding and binning.
+ DCHECK_LE(freed_bytes, static_cast<ssize_t>(num_bytes_allocated_.Load()));
+ DCHECK_GE(freed_objects, 0);
num_bytes_allocated_.FetchAndSub(freed_bytes);
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* thread_stats = Thread::Current()->GetStats();