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:
|
2018-09-13 08:48:03 +00:00
|
|
|
GCIdleTimeHandlerTest() = default;
|
2018-09-14 14:02:15 +00:00
|
|
|
~GCIdleTimeHandlerTest() override = default;
|
2014-09-01 09:12:50 +00:00
|
|
|
|
|
|
|
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.incremental_marking_stopped = false;
|
2017-06-30 09:16:26 +00:00
|
|
|
result.size_of_objects = kSizeOfObjects;
|
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;
|
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(
|
2021-06-25 17:08:16 +00:00
|
|
|
10, static_cast<double>(std::numeric_limits<size_t>::max()));
|
2014-08-20 15:37:43 +00:00
|
|
|
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(
|
2021-06-25 17:08:16 +00:00
|
|
|
static_cast<double>(std::numeric_limits<size_t>::max()), 10);
|
2014-08-20 15:37:43 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize),
|
|
|
|
step_size);
|
2014-08-19 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2019-02-21 11:42:14 +00:00
|
|
|
EXPECT_EQ(GCIdleTimeAction::kIncrementalStep,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
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);
|
2019-02-21 11:42:14 +00:00
|
|
|
EXPECT_EQ(GCIdleTimeAction::kDone,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
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;
|
2019-02-21 11:42:14 +00:00
|
|
|
EXPECT_EQ(GCIdleTimeAction::kDone,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
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;
|
2019-02-21 11:42:14 +00:00
|
|
|
EXPECT_EQ(GCIdleTimeAction::kDone,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
2015-07-07 11:37:44 +00:00
|
|
|
heap_state.incremental_marking_stopped = false;
|
2019-02-21 11:42:14 +00:00
|
|
|
EXPECT_EQ(GCIdleTimeAction::kIncrementalStep,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
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;
|
2019-02-21 11:42:14 +00:00
|
|
|
// We should return kDone if we cannot start incremental marking.
|
|
|
|
EXPECT_EQ(GCIdleTimeAction::kDone,
|
|
|
|
handler()->Compute(idle_time_ms, heap_state));
|
2015-05-19 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 10:54:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|