2018-06-07 12:00:16 +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.
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
#include <limits>
|
|
|
|
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "src/objects/objects.h"
|
2018-06-07 12:00:16 +00:00
|
|
|
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles-inl.h"
|
|
|
|
#include "src/handles/handles.h"
|
2018-06-07 12:00:16 +00:00
|
|
|
|
|
|
|
#include "src/heap/heap-controller.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2019-03-29 09:47:48 +00:00
|
|
|
using HeapControllerTest = TestWithIsolate;
|
2018-06-08 15:57:43 +00:00
|
|
|
|
2018-06-07 12:00:16 +00:00
|
|
|
double Round(double x) {
|
|
|
|
// Round to three digits.
|
|
|
|
return floor(x * 1000 + 0.5) / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckEqualRounded(double expected, double actual) {
|
|
|
|
expected = Round(expected);
|
|
|
|
actual = Round(actual);
|
|
|
|
EXPECT_DOUBLE_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-08-09 08:14:12 +00:00
|
|
|
TEST_F(HeapControllerTest, HeapGrowingFactor) {
|
|
|
|
HeapController heap_controller(i_isolate()->heap());
|
2018-09-10 19:05:40 +00:00
|
|
|
double min_factor = heap_controller.min_growing_factor_;
|
|
|
|
double max_factor = heap_controller.max_growing_factor_;
|
2018-08-09 08:14:12 +00:00
|
|
|
|
|
|
|
CheckEqualRounded(max_factor, heap_controller.GrowingFactor(34, 1, 4.0));
|
|
|
|
CheckEqualRounded(3.553, heap_controller.GrowingFactor(45, 1, 4.0));
|
|
|
|
CheckEqualRounded(2.830, heap_controller.GrowingFactor(50, 1, 4.0));
|
|
|
|
CheckEqualRounded(1.478, heap_controller.GrowingFactor(100, 1, 4.0));
|
|
|
|
CheckEqualRounded(1.193, heap_controller.GrowingFactor(200, 1, 4.0));
|
|
|
|
CheckEqualRounded(1.121, heap_controller.GrowingFactor(300, 1, 4.0));
|
|
|
|
CheckEqualRounded(heap_controller.GrowingFactor(300, 1, 4.0),
|
|
|
|
heap_controller.GrowingFactor(600, 2, 4.0));
|
|
|
|
CheckEqualRounded(min_factor, heap_controller.GrowingFactor(400, 1, 4.0));
|
2018-06-07 12:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 08:14:12 +00:00
|
|
|
TEST_F(HeapControllerTest, MaxHeapGrowingFactor) {
|
|
|
|
HeapController heap_controller(i_isolate()->heap());
|
2018-06-07 12:00:16 +00:00
|
|
|
CheckEqualRounded(
|
2018-09-10 19:05:40 +00:00
|
|
|
1.3, heap_controller.MaxGrowingFactor(HeapController::kMinSize * MB));
|
2018-08-09 08:14:12 +00:00
|
|
|
CheckEqualRounded(1.600, heap_controller.MaxGrowingFactor(
|
2018-09-10 19:05:40 +00:00
|
|
|
HeapController::kMaxSize / 2 * MB));
|
2018-08-09 08:14:12 +00:00
|
|
|
CheckEqualRounded(
|
|
|
|
1.999, heap_controller.MaxGrowingFactor(
|
2018-09-10 19:05:40 +00:00
|
|
|
(HeapController::kMaxSize - Heap::kPointerMultiplier) * MB));
|
2018-08-30 13:23:40 +00:00
|
|
|
CheckEqualRounded(4.0,
|
|
|
|
heap_controller.MaxGrowingFactor(
|
2018-09-10 19:05:40 +00:00
|
|
|
static_cast<size_t>(HeapController::kMaxSize) * MB));
|
2018-06-07 12:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 15:57:43 +00:00
|
|
|
TEST_F(HeapControllerTest, OldGenerationAllocationLimit) {
|
|
|
|
Heap* heap = i_isolate()->heap();
|
2018-08-09 08:14:12 +00:00
|
|
|
HeapController heap_controller(heap);
|
2018-06-08 15:57:43 +00:00
|
|
|
size_t old_gen_size = 128 * MB;
|
|
|
|
size_t max_old_generation_size = 512 * MB;
|
|
|
|
double gc_speed = 100;
|
|
|
|
double mutator_speed = 1;
|
|
|
|
size_t new_space_capacity = 16 * MB;
|
|
|
|
|
2018-08-09 08:14:12 +00:00
|
|
|
double max_factor = heap_controller.MaxGrowingFactor(max_old_generation_size);
|
2018-06-08 15:57:43 +00:00
|
|
|
double factor =
|
2018-08-09 08:14:12 +00:00
|
|
|
heap_controller.GrowingFactor(gc_speed, mutator_speed, max_factor);
|
2018-06-08 15:57:43 +00:00
|
|
|
|
2019-05-17 19:35:42 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
|
|
|
|
heap->heap_controller()->CalculateAllocationLimit(
|
|
|
|
old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
|
|
|
|
new_space_capacity, Heap::HeapGrowingMode::kDefault));
|
2018-06-21 07:26:32 +00:00
|
|
|
|
2018-09-10 19:05:40 +00:00
|
|
|
factor = Min(factor, heap_controller.conservative_growing_factor_);
|
2019-05-17 19:35:42 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
|
|
|
|
heap->heap_controller()->CalculateAllocationLimit(
|
|
|
|
old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
|
|
|
|
new_space_capacity, Heap::HeapGrowingMode::kSlow));
|
2018-06-08 15:57:43 +00:00
|
|
|
|
2018-09-10 19:05:40 +00:00
|
|
|
factor = Min(factor, heap_controller.conservative_growing_factor_);
|
2018-08-30 13:23:40 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
|
|
|
|
heap->heap_controller()->CalculateAllocationLimit(
|
2019-05-17 19:35:42 +00:00
|
|
|
old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
|
|
|
|
new_space_capacity, Heap::HeapGrowingMode::kConservative));
|
2018-09-10 19:05:40 +00:00
|
|
|
|
|
|
|
factor = heap_controller.min_growing_factor_;
|
2019-05-17 19:35:42 +00:00
|
|
|
EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
|
|
|
|
heap->heap_controller()->CalculateAllocationLimit(
|
|
|
|
old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
|
|
|
|
new_space_capacity, Heap::HeapGrowingMode::kMinimal));
|
2018-06-08 15:57:43 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 08:14:12 +00:00
|
|
|
TEST_F(HeapControllerTest, MaxOldGenerationSize) {
|
|
|
|
HeapController heap_controller(i_isolate()->heap());
|
2018-06-07 12:00:16 +00:00
|
|
|
uint64_t configurations[][2] = {
|
2018-09-10 19:05:40 +00:00
|
|
|
{0, HeapController::kMinSize},
|
|
|
|
{512, HeapController::kMinSize},
|
2018-06-07 12:00:16 +00:00
|
|
|
{1 * GB, 256 * Heap::kPointerMultiplier},
|
|
|
|
{2 * static_cast<uint64_t>(GB), 512 * Heap::kPointerMultiplier},
|
2018-09-10 19:05:40 +00:00
|
|
|
{4 * static_cast<uint64_t>(GB), HeapController::kMaxSize},
|
|
|
|
{8 * static_cast<uint64_t>(GB), HeapController::kMaxSize}};
|
2018-06-07 12:00:16 +00:00
|
|
|
|
|
|
|
for (auto configuration : configurations) {
|
|
|
|
ASSERT_EQ(configuration[1],
|
|
|
|
static_cast<uint64_t>(
|
|
|
|
Heap::ComputeMaxOldGenerationSize(configuration[0])));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|