2018-10-10 12:22:19 +00:00
|
|
|
// 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"
|
2019-03-22 12:41:21 +00:00
|
|
|
#include "src/wasm/wasm-import-wrapper-cache.h"
|
2018-10-10 12:22:19 +00:00
|
|
|
#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 {
|
|
|
|
|
2019-03-12 16:10:58 +00:00
|
|
|
std::shared_ptr<NativeModule> NewModule(Isolate* isolate) {
|
2018-10-10 12:22:19 +00:00
|
|
|
std::shared_ptr<WasmModule> module(new WasmModule);
|
|
|
|
bool can_request_more = false;
|
2018-12-21 13:57:28 +00:00
|
|
|
size_t size = 16384;
|
2019-01-25 10:35:37 +00:00
|
|
|
auto native_module = isolate->wasm_engine()->NewNativeModule(
|
2018-10-23 11:43:07 +00:00
|
|
|
isolate, kAllWasmFeatures, size, can_request_more, std::move(module));
|
2018-10-10 12:22:19 +00:00
|
|
|
native_module->SetRuntimeStubs(isolate);
|
|
|
|
return native_module;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CacheHit) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
auto module = NewModule(isolate);
|
|
|
|
TestSignatures sigs;
|
2019-04-02 10:41:00 +00:00
|
|
|
WasmCodeRefScope wasm_code_ref_scope;
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
|
|
CHECK_EQ(c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CacheMissSig) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
auto module = NewModule(isolate);
|
|
|
|
TestSignatures sigs;
|
2019-04-02 10:41:00 +00:00
|
|
|
WasmCodeRefScope wasm_code_ref_scope;
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
|
|
CHECK_NE(c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CacheMissKind) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
auto module = NewModule(isolate);
|
|
|
|
TestSignatures sigs;
|
2019-04-02 10:41:00 +00:00
|
|
|
WasmCodeRefScope wasm_code_ref_scope;
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
auto kind1 = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
auto kind2 = compiler::WasmImportCallKind::kJSFunctionArityMismatch;
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind1, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind2, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
|
|
CHECK_NE(c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CacheHitMissSig) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
auto module = NewModule(isolate);
|
|
|
|
TestSignatures sigs;
|
2019-04-02 10:41:00 +00:00
|
|
|
WasmCodeRefScope wasm_code_ref_scope;
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
auto kind = compiler::WasmImportCallKind::kJSFunctionArityMatch;
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c1 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c1);
|
|
|
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c2 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c2);
|
|
|
|
CHECK_NE(c1, c2);
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c3 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_i());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c3);
|
|
|
|
CHECK_EQ(c1, c3);
|
|
|
|
|
2019-01-11 09:36:39 +00:00
|
|
|
WasmCode* c4 = module->import_wrapper_cache()->GetOrCompile(
|
|
|
|
isolate->wasm_engine(), isolate->counters(), kind, sigs.i_ii());
|
2018-10-10 12:22:19 +00:00
|
|
|
|
|
|
|
CHECK_NOT_NULL(c4);
|
|
|
|
CHECK_EQ(c2, c4);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace test_wasm_import_wrapper_cache
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|