diff options
-rw-r--r-- | runtime/gc/heap.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index a34cd3871d..6d70a38765 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -417,7 +417,10 @@ class Heap { // Implements java.lang.Runtime.freeMemory. size_t GetFreeMemory() const { - return max_allowed_footprint_ - num_bytes_allocated_.LoadSequentiallyConsistent(); + size_t byte_allocated = num_bytes_allocated_.LoadSequentiallyConsistent(); + // Make sure we don't get a negative number since the max allowed footprint is only updated + // after the GC. But we can still allocate even if bytes_allocated > max_allowed_footprint_. + return std::max(max_allowed_footprint_, byte_allocated) - byte_allocated; } // get the space that corresponds to an object's address. Current implementation searches all |