Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_
6 : #define V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_
7 :
8 : #include "src/base/platform/mutex.h"
9 : #include "src/compiler/wasm-compiler.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 : class Counters;
15 :
16 : namespace wasm {
17 :
18 : class WasmCode;
19 : class WasmEngine;
20 :
21 : using FunctionSig = Signature<ValueType>;
22 :
23 : // Implements a cache for import wrappers.
24 : class WasmImportWrapperCache {
25 : public:
26 : ~WasmImportWrapperCache();
27 :
28 : V8_EXPORT_PRIVATE WasmCode* GetOrCompile(WasmEngine* wasm_engine,
29 : Counters* counters,
30 : compiler::WasmImportCallKind kind,
31 : FunctionSig* sig);
32 :
33 : private:
34 : friend class NativeModule;
35 : using CacheKey = std::pair<uint8_t, FunctionSig>;
36 :
37 : mutable base::Mutex mutex_;
38 : NativeModule* native_module_;
39 : std::unordered_map<CacheKey, WasmCode*, base::hash<CacheKey>> entry_map_;
40 :
41 : explicit WasmImportWrapperCache(NativeModule* native_module)
42 1242981 : : native_module_(native_module) {}
43 : };
44 :
45 : } // namespace wasm
46 : } // namespace internal
47 : } // namespace v8
48 :
49 : #endif // V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_
|