From 168293591111a381b26491407c3ccd16b800a168 Mon Sep 17 00:00:00 2001 From: hpayer Date: Thu, 19 Nov 2015 07:55:14 -0800 Subject: [PATCH] [heap] Enforce size checks in allocation stats. This CL should be reverted after investigating the size chrasher. BUG=chromium:556912 LOG=n Review URL: https://codereview.chromium.org/1455273003 Cr-Commit-Position: refs/heads/master@{#32119} --- src/heap/spaces.cc | 3 ++- src/heap/spaces.h | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc index 6db43fb47d..d2e908bb00 100644 --- a/src/heap/spaces.cc +++ b/src/heap/spaces.cc @@ -2707,7 +2707,8 @@ void PagedSpace::PrepareForMarkCompact() { intptr_t PagedSpace::SizeOfObjects() { const intptr_t size = Size() - (limit() - top()); - DCHECK_GE(size, 0); + CHECK_GE(limit(), top()); + CHECK_GE(size, 0); USE(size); return size; } diff --git a/src/heap/spaces.h b/src/heap/spaces.h index 018f0650ab..e2680b4419 100644 --- a/src/heap/spaces.h +++ b/src/heap/spaces.h @@ -1541,7 +1541,10 @@ class AllocationStats BASE_EMBEDDED { // Accessors for the allocation statistics. intptr_t Capacity() { return capacity_; } intptr_t MaxCapacity() { return max_capacity_; } - intptr_t Size() { return size_; } + intptr_t Size() { + CHECK_GE(size_, 0); + return size_; + } // Grow the space by adding available bytes. They are initially marked as // being in use (part of the size), but will normally be immediately freed, @@ -1552,7 +1555,7 @@ class AllocationStats BASE_EMBEDDED { if (capacity_ > max_capacity_) { max_capacity_ = capacity_; } - DCHECK(size_ >= 0); + CHECK(size_ >= 0); } // Shrink the space by removing available bytes. Since shrinking is done @@ -1561,19 +1564,19 @@ class AllocationStats BASE_EMBEDDED { void ShrinkSpace(int size_in_bytes) { capacity_ -= size_in_bytes; size_ -= size_in_bytes; - DCHECK(size_ >= 0); + CHECK(size_ >= 0); } // Allocate from available bytes (available -> size). void AllocateBytes(intptr_t size_in_bytes) { size_ += size_in_bytes; - DCHECK(size_ >= 0); + CHECK(size_ >= 0); } // Free allocated bytes, making them available (size -> available). void DeallocateBytes(intptr_t size_in_bytes) { size_ -= size_in_bytes; - DCHECK_GE(size_, 0); + CHECK_GE(size_, 0); } // Merge {other} into {this}. @@ -1583,12 +1586,13 @@ class AllocationStats BASE_EMBEDDED { if (other.max_capacity_ > max_capacity_) { max_capacity_ = other.max_capacity_; } + CHECK_GE(size_, 0); } void DecreaseCapacity(intptr_t size_in_bytes) { capacity_ -= size_in_bytes; - DCHECK_GE(capacity_, 0); - DCHECK_GE(capacity_, size_); + CHECK_GE(capacity_, 0); + CHECK_GE(capacity_, size_); } void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; }