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_; }
|
|
|
|
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState DefaultHeapState() {
|
|
|
|
GCIdleTimeHeapState result;
|
2014-09-01 09:12:50 +00:00
|
|
|
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.incremental_marking_stopped = false;
|
|
|
|
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;
|
2015-07-07 11:37:44 +00:00
|
|
|
static const int kMaxNotifications = 100;
|
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-11-27 12:39:41 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ShouldDoFinalIncrementalMarkCompact) {
|
2015-05-07 14:41:53 +00:00
|
|
|
size_t idle_time_ms = 16;
|
2014-11-27 12:39:41 +00:00
|
|
|
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact(
|
2015-05-07 14:41:53 +00:00
|
|
|
idle_time_ms, 0, 0));
|
2014-11-27 12:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) {
|
2015-05-07 14:41:53 +00:00
|
|
|
size_t idle_time_ms = 1;
|
2014-11-27 12:39:41 +00:00
|
|
|
EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact(
|
2015-05-07 14:41:53 +00:00
|
|
|
idle_time_ms, kSizeOfObjects, kMarkingSpeed));
|
2014-11-27 12:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-07 09:36:49 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-11-07 09:36:49 +00:00
|
|
|
heap_state.contexts_disposed = 1;
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 0;
|
2015-07-07 11:37:44 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
2014-11-07 09:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-11-07 09:36:49 +00:00
|
|
|
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;
|
2015-07-07 11:37:44 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-21 12:56:52 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-10-21 12:56:52 +00:00
|
|
|
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;
|
2015-07-07 11:37:44 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 13:26:29 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-08-22 13:26:29 +00:00
|
|
|
heap_state.contexts_disposed = 1;
|
2015-05-15 07:48:16 +00:00
|
|
|
heap_state.contexts_disposal_rate =
|
|
|
|
GCIdleTimeHandler::kHighContextDisposalRate;
|
2015-10-02 12:58:21 +00:00
|
|
|
size_t speed = kMarkCompactSpeed;
|
2015-09-08 15:54:24 +00:00
|
|
|
double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1);
|
2015-07-07 11:37:44 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2015-09-08 15:54:24 +00:00
|
|
|
EXPECT_EQ(DO_INCREMENTAL_STEP, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-08-22 13:26:29 +00:00
|
|
|
heap_state.contexts_disposed = 1;
|
2015-05-15 07:48:16 +00:00
|
|
|
heap_state.contexts_disposal_rate =
|
|
|
|
GCIdleTimeHandler::kHighContextDisposalRate;
|
2015-10-02 12:58:21 +00:00
|
|
|
size_t speed = kMarkCompactSpeed;
|
2015-09-08 15:54:24 +00:00
|
|
|
double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1);
|
2015-07-07 11:37:44 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2015-09-08 15:54:24 +00:00
|
|
|
EXPECT_EQ(DO_INCREMENTAL_STEP, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-11-28 10:59:18 +00:00
|
|
|
double idle_time_ms = 10;
|
2015-07-07 11:37:44 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2015-09-08 15:54:24 +00:00
|
|
|
EXPECT_EQ(DO_INCREMENTAL_STEP, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-08-22 13:26:29 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2015-10-02 12:58:21 +00:00
|
|
|
size_t speed = kMarkCompactSpeed;
|
2015-09-08 15:54:24 +00:00
|
|
|
double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1);
|
2014-08-22 13:26:29 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
2015-07-07 11:37:44 +00:00
|
|
|
EXPECT_EQ(DONE, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-07 11:37:44 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2015-05-07 14:41:53 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2015-07-07 11:37:44 +00:00
|
|
|
double idle_time_ms = 10.0;
|
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);
|
2015-07-05 18:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-07 11:37:44 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2015-07-05 18:18:45 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2015-07-07 11:37:44 +00:00
|
|
|
double idle_time_ms = 10.0;
|
2015-07-05 18:18:45 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DONE, action.type);
|
2015-07-07 11:37:44 +00:00
|
|
|
heap_state.incremental_marking_stopped = false;
|
2014-08-22 13:26:29 +00:00
|
|
|
action = handler()->Compute(idle_time_ms, heap_state);
|
2015-09-08 15:54:24 +00:00
|
|
|
EXPECT_EQ(DO_INCREMENTAL_STEP, action.type);
|
2014-08-22 13:26:29 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 08:44:46 +00:00
|
|
|
|
2015-05-07 14:41:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2015-05-07 14:41:53 +00:00
|
|
|
for (int i = 0; i < kMaxNotifications; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(0, heap_state);
|
|
|
|
EXPECT_EQ(DO_NOTHING, action.type);
|
|
|
|
}
|
2014-09-18 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-07 14:41:53 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2014-09-18 08:44:46 +00:00
|
|
|
heap_state.incremental_marking_stopped = true;
|
2015-05-07 14:41:53 +00:00
|
|
|
for (int i = 0; i < kMaxNotifications; i++) {
|
|
|
|
GCIdleTimeAction action = handler()->Compute(10, heap_state);
|
2015-05-19 18:12:18 +00:00
|
|
|
EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
|
2015-05-07 14:41:53 +00:00
|
|
|
}
|
2014-09-18 13:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-19 18:12:18 +00:00
|
|
|
TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!handler()->Enabled()) return;
|
|
|
|
|
2015-05-19 18:12:18 +00:00
|
|
|
// Regression test for crbug.com/489323.
|
2015-09-25 13:55:11 +00:00
|
|
|
GCIdleTimeHeapState heap_state = DefaultHeapState();
|
2015-05-19 18:12:18 +00:00
|
|
|
|
|
|
|
// Simulate incremental marking stopped and not eligible to start.
|
|
|
|
heap_state.incremental_marking_stopped = true;
|
|
|
|
double idle_time_ms = 10.0;
|
2015-07-07 11:37:44 +00:00
|
|
|
// We should return DONE if we cannot start incremental marking.
|
2015-05-19 18:12:18 +00:00
|
|
|
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
|
|
|
|
EXPECT_EQ(DONE, action.type);
|
|
|
|
}
|
|
|
|
|
2014-08-19 10:54:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|