wasm-import-wrapper-cache.cc 1.27 KB
Newer Older
1 2 3 4 5 6 7 8
// 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>

9
#include "src/logging/counters.h"
10 11 12 13 14 15
#include "src/wasm/wasm-code-manager.h"

namespace v8 {
namespace internal {
namespace wasm {

16 17 18 19 20
WasmCode*& WasmImportWrapperCache::ModificationScope::operator[](
    const CacheKey& key) {
  return cache_->entry_map_[key];
}

21 22 23 24 25
WasmCode*& WasmImportWrapperCache::operator[](
    const WasmImportWrapperCache::CacheKey& key) {
  return entry_map_[key];
}

26
WasmCode* WasmImportWrapperCache::Get(compiler::WasmImportCallKind kind,
27 28
                                      const FunctionSig* sig,
                                      int expected_arity) const {
29
  base::MutexGuard lock(&mutex_);
30 31

  auto it = entry_map_.find({kind, sig, expected_arity});
32 33 34 35
  DCHECK(it != entry_map_.end());
  return it->second;
}

36 37 38
WasmImportWrapperCache::~WasmImportWrapperCache() {
  std::vector<WasmCode*> ptrs;
  ptrs.reserve(entry_map_.size());
39 40 41 42
  for (auto& e : entry_map_) {
    if (e.second) {
      ptrs.push_back(e.second);
    }
43
  }
44
  WasmCode::DecrementRefCount(VectorOf(ptrs));
45 46 47 48 49
}

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