Commit 38ce72ae authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove test-only method

The {remaining_uncommitted_code_space} method is only used for testing.
This CL removes it, and replaces all uses by {committed_code_space}.

R=mstarzinger@chromium.org

Bug: v8:8217
Change-Id: Icb50471da3564a5cd114b15836c8b346b932a108
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1559735
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60704}
parent 1a7d847c
......@@ -552,11 +552,6 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
size_t committed_code_space() const {
return total_committed_code_space_.load();
}
size_t remaining_uncommitted_code_space() const {
size_t committed = committed_code_space();
DCHECK_GE(max_committed_code_space_, committed);
return max_committed_code_space_ - committed;
}
void SetMaxCommittedMemoryForTesting(size_t limit);
......
......@@ -158,6 +158,12 @@ class WasmCodeManagerTest : public TestWithContext,
static constexpr uint32_t kNumFunctions = 10;
static constexpr uint32_t kJumpTableSize = RoundUp<kCodeAlignment>(
JumpTableAssembler::SizeForNumberOfSlots(kNumFunctions));
static size_t page_size;
WasmCodeManagerTest() {
if (page_size == 0) page_size = AllocatePageSize();
DCHECK_NE(0, page_size);
}
using NativeModulePtr = std::shared_ptr<NativeModule>;
......@@ -180,8 +186,6 @@ class WasmCodeManagerTest : public TestWithContext,
return native_module->PublishCode(std::move(code));
}
size_t page() const { return AllocatePageSize(); }
WasmEngine* engine() { return i_isolate()->wasm_engine(); }
WasmCodeManager* manager() { return engine()->code_manager(); }
......@@ -191,38 +195,41 @@ class WasmCodeManagerTest : public TestWithContext,
}
};
// static
size_t WasmCodeManagerTest::page_size = 0;
INSTANTIATE_TEST_SUITE_P(Parameterized, WasmCodeManagerTest,
::testing::Values(Fixed, Growable),
PrintWasmCodeManageTestParam);
TEST_P(WasmCodeManagerTest, EmptyCase) {
SetMaxCommittedMemory(0 * page());
CHECK_EQ(0, manager()->remaining_uncommitted_code_space());
SetMaxCommittedMemory(0);
CHECK_EQ(0, manager()->committed_code_space());
ASSERT_DEATH_IF_SUPPORTED(AllocModule(1 * page(), GetParam()),
ASSERT_DEATH_IF_SUPPORTED(AllocModule(page_size, GetParam()),
"OOM in NativeModule::AllocateForCode commit");
}
TEST_P(WasmCodeManagerTest, AllocateAndGoOverLimit) {
SetMaxCommittedMemory(1 * page());
CHECK_EQ(1 * page(), manager()->remaining_uncommitted_code_space());
NativeModulePtr native_module = AllocModule(1 * page(), GetParam());
SetMaxCommittedMemory(page_size);
CHECK_EQ(0, manager()->committed_code_space());
NativeModulePtr native_module = AllocModule(page_size, GetParam());
CHECK(native_module);
CHECK_EQ(0, manager()->remaining_uncommitted_code_space());
CHECK_EQ(page_size, manager()->committed_code_space());
WasmCodeRefScope code_ref_scope;
uint32_t index = 0;
WasmCode* code = AddCode(native_module.get(), index++, 1 * kCodeAlignment);
CHECK_NOT_NULL(code);
CHECK_EQ(0, manager()->remaining_uncommitted_code_space());
CHECK_EQ(page_size, manager()->committed_code_space());
code = AddCode(native_module.get(), index++, 3 * kCodeAlignment);
CHECK_NOT_NULL(code);
CHECK_EQ(0, manager()->remaining_uncommitted_code_space());
CHECK_EQ(page_size, manager()->committed_code_space());
code = AddCode(native_module.get(), index++,
page() - 4 * kCodeAlignment - kJumpTableSize);
page_size - 4 * kCodeAlignment - kJumpTableSize);
CHECK_NOT_NULL(code);
CHECK_EQ(0, manager()->remaining_uncommitted_code_space());
CHECK_EQ(page_size, manager()->committed_code_space());
// This fails in "reservation" if we cannot extend the code space, or in
// "commit" it we can (since we hit the allocation limit in the
......@@ -233,22 +240,23 @@ TEST_P(WasmCodeManagerTest, AllocateAndGoOverLimit) {
}
TEST_P(WasmCodeManagerTest, TotalLimitIrrespectiveOfModuleCount) {
SetMaxCommittedMemory(3 * page());
NativeModulePtr nm1 = AllocModule(2 * page(), GetParam());
NativeModulePtr nm2 = AllocModule(2 * page(), GetParam());
SetMaxCommittedMemory(3 * page_size);
NativeModulePtr nm1 = AllocModule(2 * page_size, GetParam());
NativeModulePtr nm2 = AllocModule(2 * page_size, GetParam());
CHECK(nm1);
CHECK(nm2);
WasmCodeRefScope code_ref_scope;
WasmCode* code = AddCode(nm1.get(), 0, 2 * page() - kJumpTableSize);
WasmCode* code = AddCode(nm1.get(), 0, 2 * page_size - kJumpTableSize);
CHECK_NOT_NULL(code);
ASSERT_DEATH_IF_SUPPORTED(AddCode(nm2.get(), 0, 2 * page() - kJumpTableSize),
ASSERT_DEATH_IF_SUPPORTED(
AddCode(nm2.get(), 0, 2 * page_size - kJumpTableSize),
"OOM in NativeModule::AllocateForCode commit");
}
TEST_P(WasmCodeManagerTest, GrowingVsFixedModule) {
SetMaxCommittedMemory(3 * page());
NativeModulePtr nm = AllocModule(1 * page(), GetParam());
size_t module_size = GetParam() == Fixed ? kMaxWasmCodeMemory : 1 * page();
SetMaxCommittedMemory(3 * page_size);
NativeModulePtr nm = AllocModule(page_size, GetParam());
size_t module_size = GetParam() == Fixed ? kMaxWasmCodeMemory : page_size;
size_t remaining_space_in_module = module_size - kJumpTableSize;
if (GetParam() == Fixed) {
// Requesting more than the remaining space fails because the module cannot
......@@ -261,30 +269,30 @@ TEST_P(WasmCodeManagerTest, GrowingVsFixedModule) {
WasmCodeRefScope code_ref_scope;
CHECK_NOT_NULL(
AddCode(nm.get(), 0, remaining_space_in_module + kCodeAlignment));
CHECK_EQ(manager()->remaining_uncommitted_code_space(), 1 * page());
CHECK_EQ(2 * page_size, manager()->committed_code_space());
}
}
TEST_P(WasmCodeManagerTest, CommitIncrements) {
SetMaxCommittedMemory(10 * page());
NativeModulePtr nm = AllocModule(3 * page(), GetParam());
SetMaxCommittedMemory(10 * page_size);
NativeModulePtr nm = AllocModule(3 * page_size, GetParam());
WasmCodeRefScope code_ref_scope;
WasmCode* code = AddCode(nm.get(), 0, kCodeAlignment);
CHECK_NOT_NULL(code);
CHECK_EQ(manager()->remaining_uncommitted_code_space(), 9 * page());
code = AddCode(nm.get(), 1, 2 * page());
CHECK_EQ(page_size, manager()->committed_code_space());
code = AddCode(nm.get(), 1, 2 * page_size);
CHECK_NOT_NULL(code);
CHECK_EQ(manager()->remaining_uncommitted_code_space(), 7 * page());
code = AddCode(nm.get(), 2, page() - kCodeAlignment - kJumpTableSize);
CHECK_EQ(3 * page_size, manager()->committed_code_space());
code = AddCode(nm.get(), 2, page_size - kCodeAlignment - kJumpTableSize);
CHECK_NOT_NULL(code);
CHECK_EQ(manager()->remaining_uncommitted_code_space(), 7 * page());
CHECK_EQ(3 * page_size, manager()->committed_code_space());
}
TEST_P(WasmCodeManagerTest, Lookup) {
SetMaxCommittedMemory(2 * page());
SetMaxCommittedMemory(2 * page_size);
NativeModulePtr nm1 = AllocModule(1 * page(), GetParam());
NativeModulePtr nm2 = AllocModule(1 * page(), GetParam());
NativeModulePtr nm1 = AllocModule(page_size, GetParam());
NativeModulePtr nm2 = AllocModule(page_size, GetParam());
Address mid_code1_1;
{
// The {WasmCodeRefScope} needs to die before {nm1} dies.
......@@ -326,9 +334,9 @@ TEST_P(WasmCodeManagerTest, Lookup) {
}
TEST_P(WasmCodeManagerTest, LookupWorksAfterRewrite) {
SetMaxCommittedMemory(2 * page());
SetMaxCommittedMemory(2 * page_size);
NativeModulePtr nm1 = AllocModule(1 * page(), GetParam());
NativeModulePtr nm1 = AllocModule(page_size, GetParam());
WasmCodeRefScope code_ref_scope;
WasmCode* code0 = AddCode(nm1.get(), 0, kCodeAlignment);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment