summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/wasm-import-wrapper-cache.h
blob: 91fe1c7b231a730af7b15faf44cfdf102ee0aada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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.

#ifndef V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_
#define V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_

#include "src/base/platform/mutex.h"
#include "src/compiler/wasm-compiler.h"

namespace v8 {
namespace internal {

class Counters;

namespace wasm {

class WasmCode;
class WasmEngine;

using FunctionSig = Signature<ValueType>;

// Implements a cache for import wrappers.
class WasmImportWrapperCache {
 public:
  ~WasmImportWrapperCache();

  V8_EXPORT_PRIVATE WasmCode* GetOrCompile(WasmEngine* wasm_engine,
                                           Counters* counters,
                                           compiler::WasmImportCallKind kind,
                                           FunctionSig* sig);

 private:
  friend class NativeModule;
  using CacheKey = std::pair<uint8_t, FunctionSig>;

  mutable base::Mutex mutex_;
  NativeModule* native_module_;
  std::unordered_map<CacheKey, WasmCode*, base::hash<CacheKey>> entry_map_;

  explicit WasmImportWrapperCache(NativeModule* native_module)
      : native_module_(native_module) {}
};

}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // V8_WASM_WASM_IMPORT_WRAPPER_CACHE_H_