From 58600281e830413bc84a59c30ac11665d4be9008 Mon Sep 17 00:00:00 2001 From: "vegorov@chromium.org" Date: Mon, 21 Feb 2011 16:11:46 +0000 Subject: [PATCH] Heap::gc_count_, last_gc_count, and kGCsBetweenCleanup should be unsigned in order to not be vulnerable to overflow issues. Patch by Mark Lam of Hewlett-Packard Development Company, LP Review URL: http://codereview.chromium.org/5966001 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6870 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap.cc | 8 ++++---- src/heap.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/heap.cc b/src/heap.cc index 87c0f54..90e83d8 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -134,7 +134,7 @@ Heap::HeapState Heap::gc_state_ = NOT_IN_GC; int Heap::mc_count_ = 0; int Heap::ms_count_ = 0; -int Heap::gc_count_ = 0; +unsigned int Heap::gc_count_ = 0; GCTracer* Heap::tracer_ = NULL; @@ -3796,9 +3796,9 @@ bool Heap::IdleNotification() { static const int kIdlesBeforeMarkSweep = 7; static const int kIdlesBeforeMarkCompact = 8; static const int kMaxIdleCount = kIdlesBeforeMarkCompact + 1; - static const int kGCsBetweenCleanup = 4; + static const unsigned int kGCsBetweenCleanup = 4; static int number_idle_notifications = 0; - static int last_gc_count = gc_count_; + static unsigned int last_gc_count = gc_count_; bool uncommit = true; bool finished = false; @@ -3807,7 +3807,7 @@ bool Heap::IdleNotification() { // GCs have taken place. This allows another round of cleanup based // on idle notifications if enough work has been carried out to // provoke a number of garbage collections. - if (gc_count_ < last_gc_count + kGCsBetweenCleanup) { + if (gc_count_ - last_gc_count < kGCsBetweenCleanup) { number_idle_notifications = Min(number_idle_notifications + 1, kMaxIdleCount); } else { diff --git a/src/heap.h b/src/heap.h index f50c3f9..a92770e 100644 --- a/src/heap.h +++ b/src/heap.h @@ -1180,7 +1180,7 @@ class Heap : public AllStatic { static int mc_count_; // how many mark-compact collections happened static int ms_count_; // how many mark-sweep collections happened - static int gc_count_; // how many gc happened + static unsigned int gc_count_; // how many gc happened // Total length of the strings we failed to flatten since the last GC. static int unflattened_strings_length_; @@ -1907,7 +1907,7 @@ class GCTracer BASE_EMBEDDED { void set_collector(GarbageCollector collector) { collector_ = collector; } // Sets the GC count. - void set_gc_count(int count) { gc_count_ = count; } + void set_gc_count(unsigned int count) { gc_count_ = count; } // Sets the full GC count. void set_full_gc_count(int count) { full_gc_count_ = count; } @@ -1950,7 +1950,7 @@ class GCTracer BASE_EMBEDDED { // A count (including this one, eg, the first collection is 1) of the // number of garbage collections. - int gc_count_; + unsigned int gc_count_; // A count (including this one) of the number of full garbage collections. int full_gc_count_; -- 2.7.4