summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/heap/heap-controller-unittest.cc
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-09-07 17:07:13 +0200
committerMichaël Zasso <targos@protonmail.com>2018-09-07 20:59:13 +0200
commit586db2414a338e1bf6eaf6e672a3adc7ce309f6a (patch)
tree139fa972aef648481ddee22a3a85b99707d28df5 /deps/v8/test/unittests/heap/heap-controller-unittest.cc
parent12ed7c94e5160aa6d38e3d2cb2a73dae0a6f9342 (diff)
downloadnode-new-586db2414a338e1bf6eaf6e672a3adc7ce309f6a.tar.gz
deps: update V8 to 6.9.427.22
PR-URL: https://github.com/nodejs/node/pull/21983 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'deps/v8/test/unittests/heap/heap-controller-unittest.cc')
-rw-r--r--deps/v8/test/unittests/heap/heap-controller-unittest.cc118
1 files changed, 118 insertions, 0 deletions
diff --git a/deps/v8/test/unittests/heap/heap-controller-unittest.cc b/deps/v8/test/unittests/heap/heap-controller-unittest.cc
new file mode 100644
index 0000000000..dc75820f64
--- /dev/null
+++ b/deps/v8/test/unittests/heap/heap-controller-unittest.cc
@@ -0,0 +1,118 @@
+// 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>
+
+#include "src/objects-inl.h"
+#include "src/objects.h"
+
+#include "src/handles-inl.h"
+#include "src/handles.h"
+
+#include "src/heap/heap-controller.h"
+#include "test/unittests/test-utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+typedef TestWithIsolate HeapControllerTest;
+
+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);
+}
+
+TEST(HeapController, HeapGrowingFactor) {
+ CheckEqualRounded(HeapController::kMaxHeapGrowingFactor,
+ HeapController::HeapGrowingFactor(34, 1, 4.0));
+ CheckEqualRounded(3.553, HeapController::HeapGrowingFactor(45, 1, 4.0));
+ CheckEqualRounded(2.830, HeapController::HeapGrowingFactor(50, 1, 4.0));
+ CheckEqualRounded(1.478, HeapController::HeapGrowingFactor(100, 1, 4.0));
+ CheckEqualRounded(1.193, HeapController::HeapGrowingFactor(200, 1, 4.0));
+ CheckEqualRounded(1.121, HeapController::HeapGrowingFactor(300, 1, 4.0));
+ CheckEqualRounded(HeapController::HeapGrowingFactor(300, 1, 4.0),
+ HeapController::HeapGrowingFactor(600, 2, 4.0));
+ CheckEqualRounded(HeapController::kMinHeapGrowingFactor,
+ HeapController::HeapGrowingFactor(400, 1, 4.0));
+}
+
+TEST(HeapController, MaxHeapGrowingFactor) {
+ CheckEqualRounded(1.3, HeapController::MaxHeapGrowingFactor(
+ HeapController::kMinOldGenerationSize * MB));
+ CheckEqualRounded(1.600, HeapController::MaxHeapGrowingFactor(
+ HeapController::kMaxOldGenerationSize / 2 * MB));
+ CheckEqualRounded(1.999, HeapController::MaxHeapGrowingFactor(
+ (HeapController::kMaxOldGenerationSize -
+ Heap::kPointerMultiplier) *
+ MB));
+ CheckEqualRounded(
+ 4.0,
+ HeapController::MaxHeapGrowingFactor(
+ static_cast<size_t>(HeapController::kMaxOldGenerationSize) * MB));
+}
+
+TEST_F(HeapControllerTest, OldGenerationAllocationLimit) {
+ Heap* heap = i_isolate()->heap();
+ 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;
+
+ double max_factor =
+ HeapController::MaxHeapGrowingFactor(max_old_generation_size);
+ double factor =
+ HeapController::HeapGrowingFactor(gc_speed, mutator_speed, max_factor);
+
+ EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
+ heap->heap_controller()->CalculateOldGenerationAllocationLimit(
+ old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
+ new_space_capacity, Heap::HeapGrowingMode::kDefault));
+
+ factor = Min(factor, HeapController::kConservativeHeapGrowingFactor);
+ EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
+ heap->heap_controller()->CalculateOldGenerationAllocationLimit(
+ old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
+ new_space_capacity, Heap::HeapGrowingMode::kSlow));
+
+ factor = Min(factor, HeapController::kConservativeHeapGrowingFactor);
+ EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
+ heap->heap_controller()->CalculateOldGenerationAllocationLimit(
+ old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
+ new_space_capacity, Heap::HeapGrowingMode::kConservative));
+
+ factor = HeapController::kMinHeapGrowingFactor;
+ EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity),
+ heap->heap_controller()->CalculateOldGenerationAllocationLimit(
+ old_gen_size, max_old_generation_size, gc_speed, mutator_speed,
+ new_space_capacity, Heap::HeapGrowingMode::kMinimal));
+}
+
+TEST(HeapController, MaxOldGenerationSize) {
+ uint64_t configurations[][2] = {
+ {0, HeapController::kMinOldGenerationSize},
+ {512, HeapController::kMinOldGenerationSize},
+ {1 * GB, 256 * Heap::kPointerMultiplier},
+ {2 * static_cast<uint64_t>(GB), 512 * Heap::kPointerMultiplier},
+ {4 * static_cast<uint64_t>(GB), HeapController::kMaxOldGenerationSize},
+ {8 * static_cast<uint64_t>(GB), HeapController::kMaxOldGenerationSize}};
+
+ for (auto configuration : configurations) {
+ ASSERT_EQ(configuration[1],
+ static_cast<uint64_t>(
+ Heap::ComputeMaxOldGenerationSize(configuration[0])));
+ }
+}
+
+} // namespace internal
+} // namespace v8