Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: src/heap/gc-tracer.cc

Issue 1148953009: Fix overflow in allocation throughput calculation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap/gc-tracer.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/gc-tracer.cc
diff --git a/src/heap/gc-tracer.cc b/src/heap/gc-tracer.cc
index 4395ac55a485cbaf560e82352cbe5c161e605ea3..11453b9d34317e29ede5a7b50a559e827b74e847 100644
--- a/src/heap/gc-tracer.cc
+++ b/src/heap/gc-tracer.cc
@@ -615,7 +615,8 @@ size_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const {
}
-size_t GCTracer::AllocatedBytesInLast(double time_ms) const {
+size_t GCTracer::AllocationThroughputInBytesPerMillisecond(
+ double time_ms) const {
size_t bytes = new_space_allocation_in_bytes_since_gc_ +
old_generation_allocation_in_bytes_since_gc_;
double durations = allocation_duration_since_gc_;
@@ -630,17 +631,13 @@ size_t GCTracer::AllocatedBytesInLast(double time_ms) const {
if (durations == 0.0) return 0;
- bytes = static_cast<size_t>(bytes * (time_ms / durations) + 0.5);
- // Return at least 1 since 0 means "no data".
- return std::max<size_t>(bytes, 1);
+ return static_cast<size_t>(bytes / durations + 0.5);
}
size_t GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const {
static const double kThroughputTimeFrame = 5000;
- size_t allocated_bytes = AllocatedBytesInLast(kThroughputTimeFrame);
- if (allocated_bytes == 0) return 0;
- return static_cast<size_t>((allocated_bytes / kThroughputTimeFrame) + 1);
+ return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrame);
}
« no previous file with comments | « src/heap/gc-tracer.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698