2017-09-16 05:22:38 +00:00
|
|
|
// 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 "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
|
|
|
2018-04-24 13:10:51 +00:00
|
|
|
#include "src/wasm/function-compiler.h"
|
2018-06-19 09:47:17 +00:00
|
|
|
#include "src/wasm/jump-table-assembler.h"
|
2017-12-05 01:47:59 +00:00
|
|
|
#include "src/wasm/wasm-code-manager.h"
|
2018-09-18 13:05:45 +00:00
|
|
|
#include "src/wasm/wasm-memory.h"
|
2017-09-16 05:22:38 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-28 17:55:52 +00:00
|
|
|
namespace wasm_heap_unittest {
|
2017-09-16 05:22:38 +00:00
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
class DisjointAllocationPoolTest : public ::testing::Test {
|
2017-09-16 05:22:38 +00:00
|
|
|
public:
|
2018-04-13 22:28:05 +00:00
|
|
|
Address A(size_t n) { return static_cast<Address>(n); }
|
2017-09-16 05:22:38 +00:00
|
|
|
void CheckLooksLike(const DisjointAllocationPool& mem,
|
|
|
|
std::vector<std::pair<size_t, size_t>> expectation);
|
2018-06-08 11:05:58 +00:00
|
|
|
void CheckLooksLike(AddressRange range,
|
|
|
|
std::pair<size_t, size_t> expectation);
|
2017-09-16 05:22:38 +00:00
|
|
|
DisjointAllocationPool Make(std::vector<std::pair<size_t, size_t>> model);
|
|
|
|
};
|
|
|
|
|
|
|
|
void DisjointAllocationPoolTest::CheckLooksLike(
|
|
|
|
const DisjointAllocationPool& mem,
|
|
|
|
std::vector<std::pair<size_t, size_t>> expectation) {
|
|
|
|
const auto& ranges = mem.ranges();
|
|
|
|
CHECK_EQ(ranges.size(), expectation.size());
|
|
|
|
auto iter = expectation.begin();
|
|
|
|
for (auto it = ranges.begin(), e = ranges.end(); it != e; ++it, ++iter) {
|
2018-06-08 11:05:58 +00:00
|
|
|
CheckLooksLike(*it, *iter);
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-08 11:05:58 +00:00
|
|
|
void DisjointAllocationPoolTest::CheckLooksLike(
|
|
|
|
AddressRange range, std::pair<size_t, size_t> expectation) {
|
|
|
|
CHECK_EQ(range.start, A(expectation.first));
|
|
|
|
CHECK_EQ(range.end, A(expectation.second));
|
|
|
|
}
|
|
|
|
|
2017-09-16 05:22:38 +00:00
|
|
|
DisjointAllocationPool DisjointAllocationPoolTest::Make(
|
|
|
|
std::vector<std::pair<size_t, size_t>> model) {
|
|
|
|
DisjointAllocationPool ret;
|
|
|
|
for (auto& pair : model) {
|
2018-06-08 11:05:58 +00:00
|
|
|
ret.Merge({A(pair.first), A(pair.second)});
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-08 11:05:58 +00:00
|
|
|
TEST_F(DisjointAllocationPoolTest, ConstructEmpty) {
|
2017-09-16 05:22:38 +00:00
|
|
|
DisjointAllocationPool a;
|
|
|
|
CHECK(a.IsEmpty());
|
2018-06-08 11:05:58 +00:00
|
|
|
CheckLooksLike(a, {});
|
|
|
|
a.Merge({1, 5});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, ConstructWithRange) {
|
|
|
|
DisjointAllocationPool a({1, 5});
|
|
|
|
CHECK(!a.IsEmpty());
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, SimpleExtract) {
|
|
|
|
DisjointAllocationPool a = Make({{1, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
AddressRange b = a.Allocate(2);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{3, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
CheckLooksLike(b, {1, 3});
|
|
|
|
a.Merge(b);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
|
|
|
CHECK_EQ(a.ranges().size(), 1);
|
2018-06-08 11:05:58 +00:00
|
|
|
CHECK_EQ(a.ranges().front().start, A(1));
|
|
|
|
CHECK_EQ(a.ranges().front().end, A(5));
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, ExtractAll) {
|
2018-06-08 11:05:58 +00:00
|
|
|
DisjointAllocationPool a({A(1), A(5)});
|
|
|
|
AddressRange b = a.Allocate(4);
|
|
|
|
CheckLooksLike(b, {1, 5});
|
2017-09-16 05:22:38 +00:00
|
|
|
CHECK(a.IsEmpty());
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge(b);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, FailToExtract) {
|
|
|
|
DisjointAllocationPool a = Make({{1, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
AddressRange b = a.Allocate(5);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
CHECK(b.is_empty());
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, FailToExtractExact) {
|
|
|
|
DisjointAllocationPool a = Make({{1, 5}, {10, 14}});
|
2018-06-08 11:05:58 +00:00
|
|
|
AddressRange b = a.Allocate(5);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}, {10, 14}});
|
2018-06-08 11:05:58 +00:00
|
|
|
CHECK(b.is_empty());
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, ExtractExact) {
|
|
|
|
DisjointAllocationPool a = Make({{1, 5}, {10, 15}});
|
2018-06-08 11:05:58 +00:00
|
|
|
AddressRange b = a.Allocate(5);
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{1, 5}});
|
2018-06-08 11:05:58 +00:00
|
|
|
CheckLooksLike(b, {10, 15});
|
2017-09-16 05:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, Merging) {
|
|
|
|
DisjointAllocationPool a = Make({{10, 15}, {20, 25}});
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge({15, 20});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{10, 25}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, MergingMore) {
|
|
|
|
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge({15, 20});
|
|
|
|
a.Merge({25, 30});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{10, 35}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, MergingSkip) {
|
|
|
|
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge({25, 30});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{10, 15}, {20, 35}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrc) {
|
|
|
|
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge({25, 30});
|
|
|
|
a.Merge({35, 40});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{10, 15}, {20, 40}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrcWithGap) {
|
|
|
|
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
|
2018-06-08 11:05:58 +00:00
|
|
|
a.Merge({25, 30});
|
|
|
|
a.Merge({36, 40});
|
2017-09-16 05:22:38 +00:00
|
|
|
CheckLooksLike(a, {{10, 15}, {20, 35}, {36, 40}});
|
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
enum ModuleStyle : int { Fixed = 0, Growable = 1 };
|
|
|
|
|
2018-06-20 11:19:45 +00:00
|
|
|
std::string PrintWasmCodeManageTestParam(
|
|
|
|
::testing::TestParamInfo<ModuleStyle> info) {
|
|
|
|
switch (info.param) {
|
|
|
|
case Fixed:
|
|
|
|
return "Fixed";
|
|
|
|
case Growable:
|
|
|
|
return "Growable";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
class WasmCodeManagerTest : public TestWithContext,
|
|
|
|
public ::testing::WithParamInterface<ModuleStyle> {
|
2017-11-20 21:34:04 +00:00
|
|
|
public:
|
2018-06-19 09:47:17 +00:00
|
|
|
static constexpr uint32_t kNumFunctions = 10;
|
|
|
|
static constexpr uint32_t kJumpTableSize = RoundUp<kCodeAlignment>(
|
2018-08-07 10:33:50 +00:00
|
|
|
JumpTableAssembler::SizeForNumberOfSlots(kNumFunctions));
|
2018-06-19 09:47:17 +00:00
|
|
|
|
2017-11-20 21:34:04 +00:00
|
|
|
using NativeModulePtr = std::unique_ptr<NativeModule>;
|
|
|
|
|
|
|
|
NativeModulePtr AllocModule(WasmCodeManager* manager, size_t size,
|
|
|
|
ModuleStyle style) {
|
2018-06-28 13:23:24 +00:00
|
|
|
std::shared_ptr<WasmModule> module(new WasmModule);
|
|
|
|
module->num_declared_functions = kNumFunctions;
|
2018-06-12 16:43:02 +00:00
|
|
|
bool can_request_more = style == Growable;
|
2018-08-02 09:50:08 +00:00
|
|
|
ModuleEnv env(module.get(), UseTrapHandler::kNoTrapHandler,
|
|
|
|
RuntimeExceptionSupport::kNoRuntimeExceptionSupport);
|
2018-08-08 14:54:44 +00:00
|
|
|
return manager->NewNativeModule(i_isolate(), kAllWasmFeatures, size,
|
|
|
|
can_request_more, std::move(module), env);
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WasmCode* AddCode(NativeModule* native_module, uint32_t index, size_t size) {
|
|
|
|
CodeDesc desc;
|
|
|
|
memset(reinterpret_cast<void*>(&desc), 0, sizeof(CodeDesc));
|
|
|
|
std::unique_ptr<byte[]> exec_buff(new byte[size]);
|
|
|
|
desc.buffer = exec_buff.get();
|
|
|
|
desc.instr_size = static_cast<int>(size);
|
2018-06-28 09:45:22 +00:00
|
|
|
return native_module->AddCode(index, desc, 0, 0, 0, {}, OwnedVector<byte>(),
|
2018-03-23 11:30:26 +00:00
|
|
|
WasmCode::kOther);
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 17:59:57 +00:00
|
|
|
size_t page() const { return AllocatePageSize(); }
|
2018-09-18 13:05:45 +00:00
|
|
|
|
|
|
|
WasmMemoryTracker* memory_tracker() { return &memory_tracker_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
WasmMemoryTracker memory_tracker_;
|
2017-11-20 21:34:04 +00:00
|
|
|
};
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(Parameterized, WasmCodeManagerTest,
|
2018-06-20 11:19:45 +00:00
|
|
|
::testing::Values(Fixed, Growable),
|
|
|
|
PrintWasmCodeManageTestParam);
|
2018-03-19 12:34:59 +00:00
|
|
|
|
|
|
|
TEST_P(WasmCodeManagerTest, EmptyCase) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 0 * page());
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(0, manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
2018-06-19 09:47:17 +00:00
|
|
|
ASSERT_DEATH_IF_SUPPORTED(AllocModule(&manager, 1 * page(), GetParam()),
|
2018-03-19 12:34:59 +00:00
|
|
|
"OOM in NativeModule::AddOwnedCode");
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, AllocateAndGoOverLimit) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 1 * page());
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(1 * page(), manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
NativeModulePtr native_module = AllocModule(&manager, 1 * page(), GetParam());
|
|
|
|
CHECK(native_module);
|
2018-06-19 09:47:17 +00:00
|
|
|
CHECK_EQ(0, manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
uint32_t index = 0;
|
|
|
|
WasmCode* code = AddCode(native_module.get(), index++, 1 * kCodeAlignment);
|
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(0, manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
|
|
|
code = AddCode(native_module.get(), index++, 3 * kCodeAlignment);
|
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(0, manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
2018-06-19 09:47:17 +00:00
|
|
|
code = AddCode(native_module.get(), index++,
|
|
|
|
page() - 4 * kCodeAlignment - kJumpTableSize);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(0, manager.remaining_uncommitted_code_space());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
|
|
|
ASSERT_DEATH_IF_SUPPORTED(
|
|
|
|
AddCode(native_module.get(), index++, 1 * kCodeAlignment),
|
|
|
|
"OOM in NativeModule::AddOwnedCode");
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, TotalLimitIrrespectiveOfModuleCount) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 3 * page());
|
2018-06-19 09:47:17 +00:00
|
|
|
NativeModulePtr nm1 = AllocModule(&manager, 2 * page(), GetParam());
|
|
|
|
NativeModulePtr nm2 = AllocModule(&manager, 2 * page(), GetParam());
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK(nm1);
|
|
|
|
CHECK(nm2);
|
2018-06-19 09:47:17 +00:00
|
|
|
WasmCode* code = AddCode(nm1.get(), 0, 2 * page() - kJumpTableSize);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_NOT_NULL(code);
|
2018-06-19 09:47:17 +00:00
|
|
|
ASSERT_DEATH_IF_SUPPORTED(AddCode(nm2.get(), 0, 2 * page() - kJumpTableSize),
|
2018-03-19 12:34:59 +00:00
|
|
|
"OOM in NativeModule::AddOwnedCode");
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, DifferentHeapsApplyLimitsIndependently) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager1(memory_tracker(), 1 * page());
|
|
|
|
WasmCodeManager manager2(memory_tracker(), 2 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
NativeModulePtr nm1 = AllocModule(&manager1, 1 * page(), GetParam());
|
|
|
|
NativeModulePtr nm2 = AllocModule(&manager2, 1 * page(), GetParam());
|
|
|
|
CHECK(nm1);
|
|
|
|
CHECK(nm2);
|
2018-06-19 09:47:17 +00:00
|
|
|
WasmCode* code = AddCode(nm1.get(), 0, 1 * page() - kJumpTableSize);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(0, manager1.remaining_uncommitted_code_space());
|
2018-06-19 09:47:17 +00:00
|
|
|
code = AddCode(nm2.get(), 0, 1 * page() - kJumpTableSize);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_NOT_NULL(code);
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, GrowingVsFixedModule) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 3 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
NativeModulePtr nm = AllocModule(&manager, 1 * page(), GetParam());
|
2018-06-20 11:19:45 +00:00
|
|
|
size_t module_size = GetParam() == Fixed ? kMaxWasmCodeMemory : 1 * page();
|
|
|
|
size_t remaining_space_in_module = module_size - kJumpTableSize;
|
2018-03-19 12:34:59 +00:00
|
|
|
if (GetParam() == Fixed) {
|
2018-06-20 11:19:45 +00:00
|
|
|
// Requesting more than the remaining space fails because the module cannot
|
|
|
|
// grow.
|
|
|
|
ASSERT_DEATH_IF_SUPPORTED(
|
|
|
|
AddCode(nm.get(), 0, remaining_space_in_module + kCodeAlignment),
|
|
|
|
"OOM in NativeModule::AddOwnedCode");
|
2018-03-19 12:34:59 +00:00
|
|
|
} else {
|
2018-06-20 11:19:45 +00:00
|
|
|
// The module grows by one page. One page remains uncommitted.
|
|
|
|
CHECK_NOT_NULL(
|
|
|
|
AddCode(nm.get(), 0, remaining_space_in_module + kCodeAlignment));
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(manager.remaining_uncommitted_code_space(), 1 * page());
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, CommitIncrements) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 10 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
NativeModulePtr nm = AllocModule(&manager, 3 * page(), GetParam());
|
|
|
|
WasmCode* code = AddCode(nm.get(), 0, kCodeAlignment);
|
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(manager.remaining_uncommitted_code_space(), 9 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
code = AddCode(nm.get(), 1, 2 * page());
|
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(manager.remaining_uncommitted_code_space(), 7 * page());
|
2018-06-19 09:47:17 +00:00
|
|
|
code = AddCode(nm.get(), 2, page() - kCodeAlignment - kJumpTableSize);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_NOT_NULL(code);
|
2018-05-16 12:05:49 +00:00
|
|
|
CHECK_EQ(manager.remaining_uncommitted_code_space(), 7 * page());
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, Lookup) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 2 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
|
|
|
NativeModulePtr nm1 = AllocModule(&manager, 1 * page(), GetParam());
|
|
|
|
NativeModulePtr nm2 = AllocModule(&manager, 1 * page(), GetParam());
|
|
|
|
WasmCode* code1_0 = AddCode(nm1.get(), 0, kCodeAlignment);
|
|
|
|
CHECK_EQ(nm1.get(), code1_0->native_module());
|
|
|
|
WasmCode* code1_1 = AddCode(nm1.get(), 1, kCodeAlignment);
|
|
|
|
WasmCode* code2_0 = AddCode(nm2.get(), 0, kCodeAlignment);
|
|
|
|
WasmCode* code2_1 = AddCode(nm2.get(), 1, kCodeAlignment);
|
|
|
|
CHECK_EQ(nm2.get(), code2_1->native_module());
|
|
|
|
|
|
|
|
CHECK_EQ(0, code1_0->index());
|
|
|
|
CHECK_EQ(1, code1_1->index());
|
|
|
|
CHECK_EQ(0, code2_0->index());
|
|
|
|
CHECK_EQ(1, code2_1->index());
|
|
|
|
|
|
|
|
// we know the manager object is allocated here, so we shouldn't
|
|
|
|
// find any WasmCode* associated with that ptr.
|
|
|
|
WasmCode* not_found = manager.LookupCode(reinterpret_cast<Address>(&manager));
|
|
|
|
CHECK_NULL(not_found);
|
2018-04-13 22:28:05 +00:00
|
|
|
WasmCode* found = manager.LookupCode(code1_0->instruction_start());
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_EQ(found, code1_0);
|
2018-04-13 22:28:05 +00:00
|
|
|
found = manager.LookupCode(code2_1->instruction_start() +
|
2018-03-19 12:34:59 +00:00
|
|
|
(code2_1->instructions().size() / 2));
|
|
|
|
CHECK_EQ(found, code2_1);
|
2018-04-13 22:28:05 +00:00
|
|
|
found = manager.LookupCode(code2_1->instruction_start() +
|
2018-03-19 12:34:59 +00:00
|
|
|
code2_1->instructions().size() - 1);
|
|
|
|
CHECK_EQ(found, code2_1);
|
2018-04-13 22:28:05 +00:00
|
|
|
found = manager.LookupCode(code2_1->instruction_start() +
|
2018-03-19 12:34:59 +00:00
|
|
|
code2_1->instructions().size());
|
|
|
|
CHECK_NULL(found);
|
|
|
|
Address mid_code1_1 =
|
2018-04-13 22:28:05 +00:00
|
|
|
code1_1->instruction_start() + (code1_1->instructions().size() / 2);
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_EQ(code1_1, manager.LookupCode(mid_code1_1));
|
|
|
|
nm1.reset();
|
|
|
|
CHECK_NULL(manager.LookupCode(mid_code1_1));
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, MultiManagerLookup) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager1(memory_tracker(), 2 * page());
|
|
|
|
WasmCodeManager manager2(memory_tracker(), 2 * page());
|
2017-11-20 21:34:04 +00:00
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
NativeModulePtr nm1 = AllocModule(&manager1, 1 * page(), GetParam());
|
|
|
|
NativeModulePtr nm2 = AllocModule(&manager2, 1 * page(), GetParam());
|
2017-11-20 21:34:04 +00:00
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
WasmCode* code1_0 = AddCode(nm1.get(), 0, kCodeAlignment);
|
|
|
|
CHECK_EQ(nm1.get(), code1_0->native_module());
|
|
|
|
WasmCode* code1_1 = AddCode(nm1.get(), 1, kCodeAlignment);
|
|
|
|
WasmCode* code2_0 = AddCode(nm2.get(), 0, kCodeAlignment);
|
|
|
|
WasmCode* code2_1 = AddCode(nm2.get(), 1, kCodeAlignment);
|
|
|
|
CHECK_EQ(nm2.get(), code2_1->native_module());
|
2017-11-20 21:34:04 +00:00
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
CHECK_EQ(0, code1_0->index());
|
|
|
|
CHECK_EQ(1, code1_1->index());
|
|
|
|
CHECK_EQ(0, code2_0->index());
|
|
|
|
CHECK_EQ(1, code2_1->index());
|
2017-11-20 21:34:04 +00:00
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
CHECK_EQ(code1_0, manager1.LookupCode(code1_0->instruction_start()));
|
|
|
|
CHECK_NULL(manager2.LookupCode(code1_0->instruction_start()));
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 12:34:59 +00:00
|
|
|
TEST_P(WasmCodeManagerTest, LookupWorksAfterRewrite) {
|
2018-09-18 13:05:45 +00:00
|
|
|
WasmCodeManager manager(memory_tracker(), 2 * page());
|
2018-03-19 12:34:59 +00:00
|
|
|
|
|
|
|
NativeModulePtr nm1 = AllocModule(&manager, 1 * page(), GetParam());
|
|
|
|
|
|
|
|
WasmCode* code0 = AddCode(nm1.get(), 0, kCodeAlignment);
|
|
|
|
WasmCode* code1 = AddCode(nm1.get(), 1, kCodeAlignment);
|
|
|
|
CHECK_EQ(0, code0->index());
|
|
|
|
CHECK_EQ(1, code1->index());
|
2018-04-13 22:28:05 +00:00
|
|
|
CHECK_EQ(code1, manager.LookupCode(code1->instruction_start()));
|
2018-03-19 12:34:59 +00:00
|
|
|
WasmCode* code1_1 = AddCode(nm1.get(), 1, kCodeAlignment);
|
|
|
|
CHECK_EQ(1, code1_1->index());
|
2018-04-13 22:28:05 +00:00
|
|
|
CHECK_EQ(code1, manager.LookupCode(code1->instruction_start()));
|
|
|
|
CHECK_EQ(code1_1, manager.LookupCode(code1_1->instruction_start()));
|
2017-11-20 21:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
} // namespace wasm_heap_unittest
|
2017-09-16 05:22:38 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|