v8/test/unittests/api/resource-constraints-unittest.cc
Ulan Degenbaev e423f00403 [api] Add a way to specify the max heap size in ResourceConstraints
The new API function is called ConfigureDefaultsFromHeapSize and
accepts two parameters: the initial and the maximum heap size.
Based on the given limits the function computes the default size
for the young and the old generation.

The patch also cleans up the existing functions to make them
consistent in terms of units and heap structure.

Bug: v8:9306
Change-Id: If2200a9cdb45b0b818a373207efe4e6426f7b688
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1631593
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62017}
2019-06-06 10:22:56 +00:00

57 lines
2.3 KiB
C++

// Copyright 2017 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 "testing/gtest/include/gtest/gtest.h"
#include "include/v8-platform.h"
#include "include/v8.h"
#include "src/heap/heap.h"
namespace v8 {
TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeSmall) {
const size_t KB = static_cast<size_t>(i::KB);
const size_t MB = static_cast<size_t>(i::MB);
const size_t pm = i::Heap::kPointerMultiplier;
v8::ResourceConstraints constraints;
constraints.ConfigureDefaultsFromHeapSize(1 * MB, 1 * MB);
ASSERT_EQ(i::Heap::MinOldGenerationSize(),
constraints.max_old_generation_size_in_bytes());
ASSERT_EQ(3 * 512 * pm * KB,
constraints.max_young_generation_size_in_bytes());
ASSERT_EQ(0u, constraints.initial_old_generation_size_in_bytes());
ASSERT_EQ(0u, constraints.initial_young_generation_size_in_bytes());
}
TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeLarge) {
const size_t KB = static_cast<size_t>(i::KB);
const size_t MB = static_cast<size_t>(i::MB);
const size_t pm = i::Heap::kPointerMultiplier;
v8::ResourceConstraints constraints;
constraints.ConfigureDefaultsFromHeapSize(100u * MB, 3000u * MB);
ASSERT_EQ(3000u * MB - 3 * 8192 * pm * KB,
constraints.max_old_generation_size_in_bytes());
ASSERT_EQ(3 * 8192 * pm * KB,
constraints.max_young_generation_size_in_bytes());
ASSERT_EQ(100u * MB - 3 * 512 * pm * KB,
constraints.initial_old_generation_size_in_bytes());
ASSERT_EQ(3 * 512 * pm * KB,
constraints.initial_young_generation_size_in_bytes());
}
TEST(ResourceConstraints, ConfigureDefaults) {
const size_t KB = static_cast<size_t>(i::KB);
const size_t MB = static_cast<size_t>(i::MB);
const size_t pm = i::Heap::kPointerMultiplier;
v8::ResourceConstraints constraints;
constraints.ConfigureDefaults(2048u * MB, 0u);
ASSERT_EQ(512u * pm * MB, constraints.max_old_generation_size_in_bytes());
ASSERT_EQ(3 * 4096 * pm * KB,
constraints.max_young_generation_size_in_bytes());
ASSERT_EQ(0u, constraints.initial_old_generation_size_in_bytes());
ASSERT_EQ(0u, constraints.initial_young_generation_size_in_bytes());
}
} // namespace v8