LCOV - code coverage report
Current view: top level - src/wasm - wasm-import-wrapper-cache-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 11 11 100.0 %
Date: 2019-01-20 Functions: 3 3 100.0 %

          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_INL_H_
       6             : #define V8_WASM_WASM_IMPORT_WRAPPER_CACHE_INL_H_
       7             : 
       8             : #include "src/compiler/wasm-compiler.h"
       9             : #include "src/counters.h"
      10             : #include "src/wasm/value-type.h"
      11             : #include "src/wasm/wasm-code-manager.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : namespace wasm {
      16             : 
      17             : // Implements a cache for import wrappers.
      18     3061180 : class WasmImportWrapperCache {
      19             :  public:
      20       13726 :   WasmCode* GetOrCompile(WasmEngine* wasm_engine, Counters* counters,
      21             :                          compiler::WasmImportCallKind kind, FunctionSig* sig) {
      22       13726 :     base::MutexGuard lock(&mutex_);
      23             :     CacheKey key(static_cast<uint8_t>(kind), *sig);
      24             :     WasmCode*& cached = entry_map_[key];
      25       13726 :     if (cached == nullptr) {
      26             :       // TODO(wasm): no need to hold the lock while compiling an import wrapper.
      27       14678 :       bool source_positions = native_module_->module()->origin == kAsmJsOrigin;
      28             :       cached = compiler::CompileWasmImportCallWrapper(
      29        7339 :           wasm_engine, native_module_, kind, sig, source_positions);
      30             :       counters->wasm_generated_code_size()->Increment(
      31        7339 :           cached->instructions().length());
      32       14678 :       counters->wasm_reloc_size()->Increment(cached->reloc_info().length());
      33             :     }
      34       27452 :     return cached;
      35             :   }
      36             : 
      37             :  private:
      38             :   friend class NativeModule;
      39             :   mutable base::Mutex mutex_;
      40             :   NativeModule* native_module_;
      41             :   using CacheKey = std::pair<uint8_t, FunctionSig>;
      42             :   std::unordered_map<CacheKey, WasmCode*, base::hash<CacheKey>> entry_map_;
      43             : 
      44     1530590 :   explicit WasmImportWrapperCache(NativeModule* native_module)
      45     3061180 :       : native_module_(native_module) {}
      46             : };
      47             : 
      48             : }  // namespace wasm
      49             : }  // namespace internal
      50             : }  // namespace v8
      51             : 
      52             : #endif  // V8_WASM_WASM_IMPORT_WRAPPER_CACHE_INL_H_

Generated by: LCOV version 1.10