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

Unified Diff: test/unittests/heap/scavenge-job-unittest.cc

Issue 1352453004: Perform scavenge in idle tasks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 3 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 | « test/unittests/heap/gc-idle-time-handler-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/heap/scavenge-job-unittest.cc
diff --git a/test/unittests/heap/scavenge-job-unittest.cc b/test/unittests/heap/scavenge-job-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dbd463c2d568536e51fa4089c798892a7d301845
--- /dev/null
+++ b/test/unittests/heap/scavenge-job-unittest.cc
@@ -0,0 +1,111 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <limits>
+
+#include "src/globals.h"
+#include "src/heap/scavenge-job.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+const size_t kScavengeSpeedInBytesPerMs = 500 * KB;
+const size_t kNewSpaceCapacity = 8 * MB;
+
+
+TEST(ScavengeJob, AllocationLimitEmptyNewSpace) {
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
+ kScavengeSpeedInBytesPerMs, 0, kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, AllocationLimitFullNewSpace) {
+ EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
+ kScavengeSpeedInBytesPerMs, kNewSpaceCapacity, kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, AllocationLimitUnknownScavengeSpeed) {
+ size_t expected_size = ScavengeJob::kInitialScavengeSpeedInBytesPerMs *
+ ScavengeJob::kAverageIdleTimeMs -
+ ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(0, expected_size - 1,
+ kNewSpaceCapacity));
+ EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(0, expected_size,
+ kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, AllocationLimitLowScavengeSpeed) {
+ size_t scavenge_speed = 1 * KB;
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
+ scavenge_speed, ScavengeJob::kMinAllocationLimit - 1, kNewSpaceCapacity));
+ EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
+ scavenge_speed, ScavengeJob::kMinAllocationLimit, kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, AllocationLimitAverageScavengeSpeed) {
+ size_t expected_size =
+ kScavengeSpeedInBytesPerMs * ScavengeJob::kAverageIdleTimeMs -
+ ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
+ kScavengeSpeedInBytesPerMs, ScavengeJob::kMinAllocationLimit,
+ kNewSpaceCapacity));
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
+ kScavengeSpeedInBytesPerMs, expected_size - 1, kNewSpaceCapacity));
+ EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
+ kScavengeSpeedInBytesPerMs, expected_size, kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, AllocationLimitHighScavengeSpeed) {
+ size_t scavenge_speed = kNewSpaceCapacity;
+ size_t expected_size =
+ static_cast<size_t>(
+ kNewSpaceCapacity *
+ ScavengeJob::kMaxAllocationLimitAsFractionOfNewSpace) -
+ ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
+ EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
+ scavenge_speed, expected_size - 1, kNewSpaceCapacity));
+ EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
+ scavenge_speed, expected_size, kNewSpaceCapacity));
+}
+
+
+TEST(ScavengeJob, EnoughIdleTimeForScavengeUnknownScavengeSpeed) {
+ size_t scavenge_speed = ScavengeJob::kInitialScavengeSpeedInBytesPerMs;
+ size_t new_space_size = 1 * MB;
+ size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
+ EXPECT_TRUE(
+ ScavengeJob::EnoughIdleTimeForScavenge(expected_time, 0, new_space_size));
+ EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(expected_time - 1, 0,
+ new_space_size));
+}
+
+
+TEST(ScavengeJob, EnoughIdleTimeForScavengeLowScavengeSpeed) {
+ size_t scavenge_speed = 1 * KB;
+ size_t new_space_size = 1 * MB;
+ size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
+ EXPECT_TRUE(ScavengeJob::EnoughIdleTimeForScavenge(
+ expected_time, scavenge_speed, new_space_size));
+ EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(
+ expected_time - 1, scavenge_speed, new_space_size));
+}
+
+
+TEST(ScavengeJob, EnoughIdleTimeForScavengeHighScavengeSpeed) {
+ size_t scavenge_speed = kNewSpaceCapacity;
+ size_t new_space_size = 1 * MB;
+ size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
+ EXPECT_TRUE(ScavengeJob::EnoughIdleTimeForScavenge(
+ expected_time, scavenge_speed, new_space_size));
+ EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(
+ expected_time - 1, scavenge_speed, new_space_size));
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/unittests/heap/gc-idle-time-handler-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698