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 "test/heap-unittests/heap-unittest.h"
|
2014-08-20 10:33:03 +00:00
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
#include <limits>
|
2014-08-20 10:33:03 +00:00
|
|
|
|
2014-08-19 10:54:54 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-08-20 10:33:03 +00:00
|
|
|
TEST(EstimateMarkingStepSizeTest, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EstimateMarkingStepSizeTest, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EstimateMarkingStepSizeTest, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EstimateMarkingStepSizeTest, 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
|
|
|
|
|
|
|
TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeInitial) {
|
|
|
|
size_t size = 100 * MB;
|
|
|
|
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0);
|
|
|
|
EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed,
|
|
|
|
time);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeNonZero) {
|
|
|
|
size_t size = 100 * MB;
|
|
|
|
size_t speed = 10 * KB;
|
|
|
|
size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
|
|
|
|
EXPECT_EQ(size / speed, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) {
|
|
|
|
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
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms =
|
|
|
|
static_cast<int>((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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
heap_state.contexts_disposed = 1;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms = static_cast<int>(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;
|
|
|
|
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
|
2014-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms = static_cast<int>(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;
|
|
|
|
int idle_time_ms = 10;
|
|
|
|
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;
|
|
|
|
int idle_time_ms = 10;
|
|
|
|
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-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms = static_cast<int>(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms = static_cast<int>(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);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
|
|
|
|
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
|
|
|
|
int idle_time_ms = 10;
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-08-22 14:12:47 +00:00
|
|
|
int idle_time_ms = static_cast<int>(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);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
// 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();
|
|
|
|
int idle_time_ms = 10;
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
if (action.type == DO_NOTHING) break;
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
handler()->NotifyIdleMarkCompact();
|
|
|
|
}
|
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
// Emulate mutator work.
|
|
|
|
for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
|
|
|
|
handler()->NotifyScavenge();
|
|
|
|
}
|
|
|
|
action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 10:54:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|