a1ff298d4f
The WasmCodeManager held a list of all Isolates that use the WasmEngine/WasmCodeManager (those two are 1:1). Since we want to move all isolate-specific tasks (like code logging and compilation callbacks) to the WasmEngine, this CL moves this management from the WasmCodeManager to the WasmEngine. We now have a bidirectional mapping from NativeModules to the Isolates that use them, and from an Isolate to all the NativeModules it uses (n:n). The IsolateData struct will be extended in follow-up CLs to hold things like the ForegroundTaskRunner. The Isolate* in the NativeModule / CompilationState will eventually be removed. R=mstarzinger@chromium.org Bug: v8:8689 Change-Id: Ic2c003c3949f73ce3264dd9dac96884a5c0b9896 Reviewed-on: https://chromium-review.googlesource.com/c/1433793 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#59092}
127 lines
3.8 KiB
C++
127 lines
3.8 KiB
C++
// Copyright 2018 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 "src/compiler/wasm-compiler.h"
|
|
#include "src/wasm/function-compiler.h"
|
|
#include "src/wasm/wasm-code-manager.h"
|
|
#include "src/wasm/wasm-engine.h"
|
|
#include "src/wasm/wasm-import-wrapper-cache-inl.h"
|
|
#include "src/wasm/wasm-module.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
#include "test/common/wasm/test-signatures.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace wasm {
|
|
namespace test_wasm_import_wrapper_cache {
|
|
|
|
std::unique_ptr<NativeModule> NewModule(Isolate* isolate) {
|
|
std::shared_ptr<WasmModule> module(new WasmModule);
|
|
bool can_request_more = false;
|
|
size_t size = 16384;
|
|
auto native_module = isolate->wasm_engine()->NewNativeModule(
|
|
isolate, kAllWasmFeatures, size, can_request_more, std::move(module));
|
|
native_module->SetRuntimeStubs(isolate);
|
|
return native_module;
|
|
}
|
|
|
|
TEST(CacheHit) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
auto module = NewModule(isolate);
|
|
TestSignatures sigs;
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
CHECK_EQ(c1, c2);
|
|
}
|
|
|
|
TEST(CacheMissSig) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
auto module = NewModule(isolate);
|
|
TestSignatures sigs;
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
CHECK_NE(c1, c2);
|
|
}
|
|
|
|
TEST(CacheMissKind) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
auto module = NewModule(isolate);
|
|
TestSignatures sigs;
|
|
|
|
auto kind1 = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
auto kind2 = compiler::WasmImportCallKind::kJSFunctionArityMismatch;
|
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind1, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind2, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
CHECK_NE(c1, c2);
|
|
}
|
|
|
|
TEST(CacheHitMissSig) {
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
auto module = NewModule(isolate);
|
|
TestSignatures sigs;
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
CHECK_NE(c1, c2);
|
|
|
|
WasmCode* c3 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
|
|
|
CHECK_NOT_NULL(c3);
|
|
CHECK_EQ(c1, c3);
|
|
|
|
WasmCode* c4 = module->import_wrapper_cache()->GetOrCompile(
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
|
|
|
CHECK_NOT_NULL(c4);
|
|
CHECK_EQ(c2, c4);
|
|
}
|
|
|
|
} // namespace test_wasm_import_wrapper_cache
|
|
} // namespace wasm
|
|
} // namespace internal
|
|
} // namespace v8
|