Reviewers: ulan,
Description:
Fix overflow in allocation throughput calculation.
BUG=chromium:492021
LOG=n
Please review this at https://codereview.chromium.org/1148953009/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+22, -22 lines):
M src/heap/gc-tracer.h
M src/heap/gc-tracer.cc
M test/cctest/test-heap.cc
Index: src/heap/gc-tracer.cc
diff --git a/src/heap/gc-tracer.cc b/src/heap/gc-tracer.cc
index
4395ac55a485cbaf560e82352cbe5c161e605ea3..9ccdd2198c41321ec4e8c9624c2688a85ad245fe
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_;
@@ -629,18 +630,16 @@ 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);
+ printf("%d %d %d, %f, %d\n", new_space_allocation_in_bytes_since_gc_,
+ old_generation_allocation_in_bytes_since_gc_, bytes, durations,
+ static_cast<size_t>(bytes / durations + 0.5));
+ 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);
}
Index: src/heap/gc-tracer.h
diff --git a/src/heap/gc-tracer.h b/src/heap/gc-tracer.h
index
e16f5d5f83c0bae591cb2a9e22197b23fb863763..5d5500c44daa4eb28c1833a260a8455dc0ce1888
100644
--- a/src/heap/gc-tracer.h
+++ b/src/heap/gc-tracer.h
@@ -386,9 +386,10 @@ class GCTracer {
// Returns 0 if no allocation events have been recorded.
size_t NewSpaceAllocationThroughputInBytesPerMillisecond() const;
- // Bytes allocated in heap in the specified time.
+ // Allocation throughput in heap in bytes/millisecond in the last time_ms
+ // milliseconds.
// Returns 0 if no allocation events have been recorded.
- size_t AllocatedBytesInLast(double time_ms) const;
+ size_t AllocationThroughputInBytesPerMillisecond(double time_ms) const;
// Allocation throughput in heap in bytes/milliseconds in
// the last five seconds.
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index
deb9a4922183c7309f386c9181b55ee69392e3ab..c99019f89e8032d8457e915e468829c3cc8d3e62
100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -5549,13 +5549,13 @@ TEST(NewSpaceAllocationThroughput2) {
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, counter2, 0);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(10000, bytes);
+ size_t throughput =
tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, counter3, 0);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput);
}
@@ -5612,13 +5612,13 @@ TEST(OldGenerationAllocationThroughput) {
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, 0, counter2);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(10000, bytes);
+ size_t throughput =
tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, 0, counter3);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput);
}
@@ -5634,11 +5634,11 @@ TEST(AllocationThroughput) {
int time2 = 200;
size_t counter2 = 2000;
tracer->SampleAllocation(time2, counter2, counter2);
- size_t bytes = tracer->AllocatedBytesInLast(1000);
- CHECK_EQ(20000, bytes);
+ size_t throughput =
tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput);
int time3 = 1000;
size_t counter3 = 30000;
tracer->SampleAllocation(time3, counter3, counter3);
- bytes = tracer->AllocatedBytesInLast(100);
- CHECK_EQ(2 * (counter3 - counter1) * 100 / (time3 - time1), bytes);
+ throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
+ CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput);
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.