summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/gc/heap.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 3b7f0e8383..776695dba9 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1541,7 +1541,10 @@ void Heap::DoPendingCollectorTransition() {
if (collector_type_ == kCollectorTypeCC || collector_type_ == kCollectorTypeCMC) {
// App's allocations (since last GC) more than the threshold then do TransitionGC
// when the app was in background. If not then don't do TransitionGC.
- size_t num_bytes_allocated_since_gc = GetBytesAllocated() - num_bytes_alive_after_gc_;
+ // num_bytes_allocated_since_gc should always be positive even if initially
+ // num_bytes_alive_after_gc_ is coming from Zygote. This gives positive or zero value.
+ size_t num_bytes_allocated_since_gc =
+ UnsignedDifference(GetBytesAllocated(), num_bytes_alive_after_gc_);
if (num_bytes_allocated_since_gc <
(UnsignedDifference(target_footprint_.load(std::memory_order_relaxed),
num_bytes_alive_after_gc_)/4)