v8/test/unittests/heap/scavenge-job-unittest.cc
Yang Guo f9a88acbc9 Move remaining files in src/
TBR=mvstanton@chromium.org,neis@chromium.org,ahaas@chromium.org

Bug: v8:9247
Change-Id: I5433c863a54f3412d73df0d38aba3fdbcfac7ebe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1627973
Commit-Queue: Yang Guo <yangguo@chromium.org>
Auto-Submit: Yang Guo <yangguo@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61830}
2019-05-24 18:24:36 +00:00

115 lines
4.3 KiB
C++

// 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/common/globals.h"
#include "src/heap/scavenge-job.h"
#include "src/utils/utils.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;
expected_size = Max(expected_size, ScavengeJob::kMinAllocationLimit);
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 + 1, 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