v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-import-wrapper-cache.h
Go to the documentation of this file.
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#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <unordered_map>
13
17
18namespace v8::internal::wasm {
19
20class WasmCode;
21class WasmEngine;
22
23// Implements a cache for import wrappers.
25 public:
41
43 public:
44 size_t operator()(const CacheKey& key) const {
45 return base::hash_combine(static_cast<uint8_t>(key.kind),
46 key.type_index.index, key.expected_arity);
47 }
48 };
49
50 // Helper class to modify the cache under a lock.
52 public:
54 : cache_(cache), guard_(&cache->mutex_) {}
55
56 V8_EXPORT_PRIVATE WasmCode* operator[](const CacheKey& key);
57
59 WasmCode::Kind kind, uint64_t signature_hash);
60
61 private:
64 };
65
68
69 void LazyInitialize(Isolate* triggering_isolate);
70
71 void Free(std::vector<WasmCode*>& wrappers);
72
73 // Thread-safe. Returns nullptr if the key doesn't exist in the map.
74 // Adds the returned code to the surrounding WasmCodeRefScope.
76 CanonicalTypeIndex type_index,
77 int expected_arity,
78 Suspend suspend) const;
79
80 WasmCode* Lookup(Address pc) const;
81
82 void LogForIsolate(Isolate* isolate);
83
85
86 // Returns nullptr if {call_target} doesn't belong to a known wrapper.
88
90 const CanonicalSig* sig,
91 CanonicalTypeIndex sig_index,
93 int expected_arity, Suspend suspend);
94
95 private:
96 std::unique_ptr<WasmCodeAllocator> code_allocator_;
98 std::unordered_map<CacheKey, WasmCode*, CacheKeyHash> entry_map_;
99 // Lookup support. The map key is the instruction start address.
100 std::map<Address, WasmCode*> codes_;
101};
102
103} // namespace v8::internal::wasm
104
105#endif // V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_
Builtins::Kind kind
Definition builtins.cc:40
std::unordered_map< CacheKey, WasmCode *, CacheKeyHash > entry_map_
V8_EXPORT_PRIVATE WasmCode * MaybeGet(ImportCallKind kind, CanonicalTypeIndex type_index, int expected_arity, Suspend suspend) const
WasmCode * CompileWasmImportCallWrapper(Isolate *isolate, ImportCallKind kind, const CanonicalSig *sig, CanonicalTypeIndex sig_index, bool source_positions, int expected_arity, Suspend suspend)
void Free(std::vector< WasmCode * > &wrappers)
V8_EXPORT_PRIVATE WasmCode * FindWrapper(WasmCodePointer call_target)
std::unique_ptr< WasmCodeAllocator > code_allocator_
base::Mutex & mutex_
SourcePositionTable * source_positions
ZoneVector< RpoNumber > & result
V8_INLINE size_t hash_combine(size_t seed, size_t hash)
Definition hashing.h:77
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
#define V8_EXPORT_PRIVATE
Definition macros.h:460
bool operator==(const CacheKey &rhs) const =default
CacheKey(ImportCallKind kind, CanonicalTypeIndex type_index, int expected_arity, Suspend suspend)
#define V8_NODISCARD
Definition v8config.h:693
std::unique_ptr< ValueMirror > key