Add RecordFree to the GarbageCollector interface
RecordFree now calls the Heap::RecordFree as well as updates the
garbage collector's internal bytes freed accounting.
Change-Id: I8cb03748b0768e3c8c50ea709572960e6e4ad219
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index dab668f..4484494 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1143,13 +1143,13 @@
GetLiveBitmap()->Walk(Heap::VerificationCallback, this);
}
-void Heap::RecordFree(ssize_t freed_objects, ssize_t freed_bytes) {
+void Heap::RecordFree(uint64_t freed_objects, int64_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);
+ DCHECK_LE(freed_bytes, static_cast<int64_t>(num_bytes_allocated_.Load()));
+ // Note: This relies on 2s complement for handling negative freed_bytes.
+ num_bytes_allocated_.FetchAndSub(static_cast<ssize_t>(freed_bytes));
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* thread_stats = Thread::Current()->GetStats();
thread_stats->freed_objects += freed_objects;