2014-08-19 10:54:54 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
#include <limits>
|
2014-08-20 10:33:03 +00:00
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
#include "src/heap/gc-idle-time-handler.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2014-08-19 10:54:54 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class GCIdleTimeHandlerTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
GCIdleTimeHandlerTest() {}
|
|
|
|
virtual ~GCIdleTimeHandlerTest() {}
|
|
|
|
|
|
|
|
GCIdleTimeHandler* handler() { return &handler_; }
|
|
|
|
|
|
|
|
GCIdleTimeHandler::HeapState DefaultHeapState() {
|
|
|
|
GCIdleTimeHandler::HeapState result;
|
|
|
|
result.contexts_disposed = 0;
|
2014-11-07 09:36:49 +00:00
|
|
|
result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate;
|
2014-09-01 09:12:50 +00:00
|
|
|
result.size_of_objects = kSizeOfObjects;
|
|
|
|
result.incremental_marking_stopped = false;
|
|
|
|
result.can_start_incremental_marking = true;
|
|
|
|
result.sweeping_in_progress = false;
|
2015-03-30 10:05:25 +00:00
|
|
|
result.sweeping_completed = false;
|
2014-09-01 09:12:50 +00:00
|
|
|
result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed;
|
|
|
|
result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed;
|
2014-09-16 13:00:05 +00:00
|
|
|
result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed;
|
2014-10-02 07:21:53 +00:00
|
|
|
result.used_new_space_size = 0;
|
2014-09-16 13:00:05 +00:00
|
|
|
result.new_space_capacity = kNewSpaceCapacity;
|
2014-09-18 08:44:46 +00:00
|
|
|
result.new_space_allocation_throughput_in_bytes_per_ms =
|
|
|
|
kNewSpaceAllocationThroughput;
|
2014-09-01 09:12:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const size_t kSizeOfObjects = 100 * MB;
|
2014-09-15 15:15:23 +00:00
|
|
|
static const size_t kMarkCompactSpeed = 200 * KB;
|
|
|
|
static const size_t kMarkingSpeed = 200 * KB;
|
2014-09-16 13:00:05 +00:00
|
|
|
static const size_t kScavengeSpeed = 100 * KB;
|
|
|
|
static const size_t kNewSpaceCapacity = 1 * MB;
|
2014-09-18 08:44:46 +00:00
|
|
|
static const size_t kNewSpaceAllocationThroughput = 10 * KB;
|
2014-09-01 09:12:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
GCIdleTimeHandler handler_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkingStepSizeInitial) {
|
2014-08-20 15:37:43 +00:00
|
|
|
size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0);
|
|
|
|
EXPECT_EQ(
|
|
|
|
static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed *
|
|
|
|
GCIdleTimeHandler::kConservativeTimeRatio),
|
|
|
|
step_size);
|
2014-08-20 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkingStepSizeNonZero) {
|
2014-08-20 15:37:43 +00:00
|
|
|
size_t marking_speed_in_bytes_per_millisecond = 100;
|
|
|
|
size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
|
2014-08-20 10:33:03 +00:00
|
|
|
1, marking_speed_in_bytes_per_millisecond);
|
2014-08-20 15:37:43 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(marking_speed_in_bytes_per_millisecond *
|
|
|
|
GCIdleTimeHandler::kConservativeTimeRatio),
|
2014-08-20 10:33:03 +00:00
|
|
|
step_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow1) {
|
2014-08-20 15:37:43 +00:00
|
|
|
size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
|
|
|
|
10, std::numeric_limits<size_t>::max());
|
|
|
|
EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize),
|
|
|
|
step_size);
|
2014-08-20 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow2) {
|
2014-08-20 15:37:43 +00:00
|
|
|
size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
|
|
|
|
std::numeric_limits<size_t>::max(), 10);
|
|
|
|
EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize),
|
|
|
|
step_size);
|
2014-08-19 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 14:42:22 +00:00
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkCompactTimeInitial) {
|
2014-08-21 14:42:22 +00:00
|
|
|
size_t size = 100 * MB;
|
|
|
|
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0);
|
|
|
|
EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed,
|
|
|
|
time);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkCompactTimeNonZero) {
|
2014-08-21 14:42:22 +00:00
|
|
|
size_t size = 100 * MB;
|
2014-09-15 15:15:23 +00:00
|
|
|
size_t speed = 1 * MB;
|
2014-08-21 14:42:22 +00:00
|
|
|
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
|
|
|
|
EXPECT_EQ(size / speed, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 09:12:50 +00:00
|
|
|
TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) {
|
2014-08-21 14:42:22 +00:00
|
|
|
size_t size = std::numeric_limits<size_t>::max();
|
|
|
|
size_t speed = 1;
|
|
|
|
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
|
|
|
|
EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
|
|
|
|
}
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
|
2014-10-02 07:21:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
int idle_time_in_ms = 16;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge(
|
2014-10-02 07:21:53 +00:00
|
|
|
idle_time_in_ms, heap_state.new_space_capacity,
|
|
|
|
heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
|
|
|
|
heap_state.new_space_allocation_throughput_in_bytes_per_ms));
|
2014-09-16 13:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-02 07:21:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.used_new_space_size = kNewSpaceCapacity;
|
|
|
|
int idle_time_in_ms = 16;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge(
|
2014-10-02 07:21:53 +00:00
|
|
|
idle_time_in_ms, heap_state.new_space_capacity,
|
|
|
|
heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
|
|
|
|
heap_state.new_space_allocation_throughput_in_bytes_per_ms));
|
2014-09-16 13:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-02 07:21:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.used_new_space_size = kNewSpaceCapacity;
|
|
|
|
heap_state.scavenge_speed_in_bytes_per_ms = 0;
|
2015-03-30 11:39:50 +00:00
|
|
|
int idle_time_in_ms = 8;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge(
|
2014-10-02 07:21:53 +00:00
|
|
|
idle_time_in_ms, heap_state.new_space_capacity,
|
|
|
|
heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
|
|
|
|
heap_state.new_space_allocation_throughput_in_bytes_per_ms));
|
2014-09-18 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-02 07:21:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.used_new_space_size = kNewSpaceCapacity;
|
|
|
|
heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB;
|
|
|
|
int idle_time_in_ms = 16;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge(
|
2014-10-02 07:21:53 +00:00
|
|
|
idle_time_in_ms, heap_state.new_space_capacity,
|
|
|
|
heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
|
|
|
|
heap_state.new_space_allocation_throughput_in_bytes_per_ms));
|
2014-09-18 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-02 07:21:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.used_new_space_size = kNewSpaceCapacity;
|
|
|
|
heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity;
|
|
|
|
int idle_time_in_ms = 16;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge(
|
2014-10-02 07:21:53 +00:00
|
|
|
idle_time_in_ms, heap_state.new_space_capacity,
|
|
|
|
heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
|
|
|
|
heap_state.new_space_allocation_throughput_in_bytes_per_ms));
|
2014-09-18 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-13 16:27:55 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ShouldDoMarkCompact) {
|
2015-03-27 08:00:40 +00:00
|
|
|
size_t idle_time_in_ms = GCIdleTimeHandler::kMaxScheduledIdleTime;
|
2014-10-13 16:27:55 +00:00
|
|
|
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoMarkCompact(idle_time_in_ms, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) {
|
|
|
|
size_t idle_time_in_ms = 1;
|
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact(
|
|
|
|
idle_time_in_ms, kSizeOfObjects, kMarkingSpeed));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-27 12:39:41 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ShouldDoFinalIncrementalMarkCompact) {
|
|
|
|
size_t idle_time_in_ms = 16;
|
|
|
|
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact(
|
|
|
|
idle_time_in_ms, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) {
|
|
|
|
size_t idle_time_in_ms = 1;
|
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact(
|
|
|
|
idle_time_in_ms, kSizeOfObjects, kMarkingSpeed));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-07 09:36:49 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 0;
|
2014-11-07 09:36:49 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
|
|
|
heap_state.contexts_disposal_rate =
|
|
|
|
GCIdleTimeHandler::kHighContextDisposalRate - 1;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 0;
|
2014-11-07 09:36:49 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-11-07 13:07:04 +00:00
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
2014-11-07 09:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.contexts_disposal_rate = 1.0;
|
2014-08-22 13:26:29 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.can_start_incremental_marking = false;
|
2014-08-22 13:26:29 +00:00
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>((heap_state.size_of_objects + speed - 1) / speed);
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-21 12:56:52 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.contexts_disposal_rate = 1.0;
|
2014-10-21 12:56:52 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 0;
|
2014-10-21 12:56:52 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.contexts_disposal_rate = 1.0;
|
2014-08-22 13:26:29 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>(heap_state.size_of_objects / speed - 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.contexts_disposal_rate = 1.0;
|
2014-08-22 13:26:29 +00:00
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>(heap_state.size_of_objects / speed - 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
2014-08-22 13:41:29 +00:00
|
|
|
EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
|
|
|
|
static_cast<size_t>(action.parameter));
|
2014-08-22 13:26:29 +00:00
|
|
|
EXPECT_LT(0, action.parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
2014-08-22 13:41:29 +00:00
|
|
|
EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
|
|
|
|
static_cast<size_t>(action.parameter));
|
2014-08-22 13:26:29 +00:00
|
|
|
EXPECT_LT(0, action.parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>(heap_state.size_of_objects / speed - 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-30 10:05:25 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, FinalizeSweeping) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
heap_state.sweeping_in_progress = true;
|
|
|
|
heap_state.sweeping_completed = true;
|
|
|
|
double idle_time_ms = 10.0;
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FINALIZE_SWEEPING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, CannotFinalizeSweeping) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
heap_state.sweeping_in_progress = true;
|
|
|
|
heap_state.sweeping_completed = false;
|
|
|
|
double idle_time_ms = 10.0;
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>(heap_state.size_of_objects / speed + 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-09-16 09:21:09 +00:00
|
|
|
EXPECT_EQ(DONE, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2014-08-22 13:26:29 +00:00
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
2014-09-16 12:48:59 +00:00
|
|
|
// In this case we emulate incremental marking steps that finish with a
|
|
|
|
// full gc.
|
2014-08-22 13:26:29 +00:00
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
2014-09-16 12:48:59 +00:00
|
|
|
heap_state.can_start_incremental_marking = false;
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-09-16 09:21:09 +00:00
|
|
|
EXPECT_EQ(DONE, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms =
|
|
|
|
static_cast<double>(heap_state.size_of_objects / speed + 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-09-16 09:21:09 +00:00
|
|
|
EXPECT_EQ(DONE, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
// Emulate mutator work.
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
|
|
|
|
handler()->NotifyScavenge();
|
|
|
|
}
|
|
|
|
action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_FULL_GC, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2014-08-22 13:26:29 +00:00
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-09-16 09:21:09 +00:00
|
|
|
if (action.type == DONE) break;
|
2014-08-22 13:26:29 +00:00
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
2014-09-16 12:48:59 +00:00
|
|
|
// In this case we try to emulate incremental marking steps the finish with
|
|
|
|
// a full gc.
|
2014-08-22 13:26:29 +00:00
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
2014-09-16 12:48:59 +00:00
|
|
|
heap_state.can_start_incremental_marking = false;
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2014-09-16 09:21:09 +00:00
|
|
|
EXPECT_EQ(DONE, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
// Emulate mutator work.
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
|
|
|
|
handler()->NotifyScavenge();
|
|
|
|
}
|
2014-09-16 12:48:59 +00:00
|
|
|
heap_state.can_start_incremental_marking = true;
|
2014-08-22 13:26:29 +00:00
|
|
|
action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
}
|
|
|
|
|
2014-09-18 08:44:46 +00:00
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, Scavenge) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
int idle_time_ms = 10;
|
2014-10-02 07:21:53 +00:00
|
|
|
heap_state.used_new_space_size =
|
|
|
|
heap_state.new_space_capacity -
|
|
|
|
(kNewSpaceAllocationThroughput * idle_time_ms);
|
2014-11-28 10:59:18 +00:00
|
|
|
GCIdleTimeAction action =
|
|
|
|
handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
|
2014-09-18 08:44:46 +00:00
|
|
|
EXPECT_EQ(DO_SCAVENGE, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
int idle_time_ms = 10;
|
|
|
|
heap_state.can_start_incremental_marking = false;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-10-02 07:21:53 +00:00
|
|
|
heap_state.used_new_space_size =
|
|
|
|
heap_state.new_space_capacity -
|
|
|
|
(kNewSpaceAllocationThroughput * idle_time_ms);
|
2014-11-28 10:59:18 +00:00
|
|
|
GCIdleTimeAction action =
|
|
|
|
handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
|
2014-09-18 08:44:46 +00:00
|
|
|
EXPECT_EQ(DO_SCAVENGE, action.type);
|
2014-10-02 07:21:53 +00:00
|
|
|
heap_state.used_new_space_size = 0;
|
2014-11-28 10:59:18 +00:00
|
|
|
action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
|
2014-09-18 08:44:46 +00:00
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
2014-09-18 13:37:36 +00:00
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 0;
|
2014-09-18 13:37:36 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeDoNothingButStartIdleRound) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2014-09-18 13:37:36 +00:00
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
if (action.type == DONE) break;
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
// In this case we try to emulate incremental marking steps the finish with
|
|
|
|
// a full gc.
|
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
// Emulate mutator work.
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
|
|
|
|
handler()->NotifyScavenge();
|
|
|
|
}
|
|
|
|
action = handler()->Compute(0, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
2014-08-19 10:54:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|