blob: bbe3a480e17fb8c286aa216640424129bbf72185 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2019 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/wasm/wasm-import-wrapper-cache.h"
#include <vector>
#include "src/wasm/wasm-code-manager.h"
namespace v8 {
namespace internal {
namespace wasm {
WasmCode*& WasmImportWrapperCache::ModificationScope::operator[](
const CacheKey& key) {
return cache_->entry_map_[key];
}
WasmCode*& WasmImportWrapperCache::operator[](
const WasmImportWrapperCache::CacheKey& key) {
return entry_map_[key];
}
WasmCode* WasmImportWrapperCache::Get(compiler::WasmImportCallKind kind,
uint32_t canonical_type_index,
int expected_arity,
Suspend suspend) const {
base::MutexGuard lock(&mutex_);
auto it =
entry_map_.find({kind, canonical_type_index, expected_arity, suspend});
DCHECK(it != entry_map_.end());
return it->second;
}
WasmCode* WasmImportWrapperCache::MaybeGet(compiler::WasmImportCallKind kind,
uint32_t canonical_type_index,
int expected_arity,
Suspend suspend) const {
base::MutexGuard lock(&mutex_);
auto it =
entry_map_.find({kind, canonical_type_index, expected_arity, suspend});
if (it == entry_map_.end()) return nullptr;
return it->second;
}
WasmImportWrapperCache::~WasmImportWrapperCache() {
std::vector<WasmCode*> ptrs;
ptrs.reserve(entry_map_.size());
for (auto& e : entry_map_) {
if (e.second) {
ptrs.push_back(e.second);
}
}
WasmCode::DecrementRefCount(base::VectorOf(ptrs));
}
} // namespace wasm
} // namespace internal
} // namespace v8
|