LCOV - code coverage report
Current view: top level - src/wasm - compilation-environment.h (source / functions) Hit Total Coverage
Test: app.info Lines: 6 6 100.0 %
Date: 2019-02-19 Functions: 0 2 0.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_COMPILATION_ENVIRONMENT_H_
       6             : #define V8_WASM_COMPILATION_ENVIRONMENT_H_
       7             : 
       8             : #include <memory>
       9             : 
      10             : #include "src/wasm/wasm-features.h"
      11             : #include "src/wasm/wasm-limits.h"
      12             : #include "src/wasm/wasm-module.h"
      13             : #include "src/wasm/wasm-tier.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18             : class Counters;
      19             : 
      20             : namespace wasm {
      21             : 
      22             : class NativeModule;
      23             : class WasmCode;
      24             : class WasmError;
      25             : 
      26             : enum RuntimeExceptionSupport : bool {
      27             :   kRuntimeExceptionSupport = true,
      28             :   kNoRuntimeExceptionSupport = false
      29             : };
      30             : 
      31             : enum UseTrapHandler : bool { kUseTrapHandler = true, kNoTrapHandler = false };
      32             : 
      33             : enum LowerSimd : bool { kLowerSimd = true, kNoLowerSimd = false };
      34             : 
      35             : // The {CompilationEnv} encapsulates the module data that is used during
      36             : // compilation. CompilationEnvs are shareable across multiple compilations.
      37             : struct CompilationEnv {
      38             :   // A pointer to the decoded module's static representation.
      39             :   const WasmModule* const module;
      40             : 
      41             :   // True if trap handling should be used in compiled code, rather than
      42             :   // compiling in bounds checks for each memory access.
      43             :   const UseTrapHandler use_trap_handler;
      44             : 
      45             :   // If the runtime doesn't support exception propagation,
      46             :   // we won't generate stack checks, and trap handling will also
      47             :   // be generated differently.
      48             :   const RuntimeExceptionSupport runtime_exception_support;
      49             : 
      50             :   // The smallest size of any memory that could be used with this module, in
      51             :   // bytes.
      52             :   const uint64_t min_memory_size;
      53             : 
      54             :   // The largest size of any memory that could be used with this module, in
      55             :   // bytes.
      56             :   const uint64_t max_memory_size;
      57             : 
      58             :   // Features enabled for this compilation.
      59             :   const WasmFeatures enabled_features;
      60             : 
      61             :   const LowerSimd lower_simd;
      62             : 
      63             :   constexpr CompilationEnv(const WasmModule* module,
      64             :                            UseTrapHandler use_trap_handler,
      65             :                            RuntimeExceptionSupport runtime_exception_support,
      66             :                            const WasmFeatures& enabled_features,
      67             :                            LowerSimd lower_simd = kNoLowerSimd)
      68             :       : module(module),
      69             :         use_trap_handler(use_trap_handler),
      70             :         runtime_exception_support(runtime_exception_support),
      71      905223 :         min_memory_size(module ? module->initial_pages * uint64_t{kWasmPageSize}
      72             :                                : 0),
      73      905222 :         max_memory_size((module && module->has_maximum_pages
      74             :                              ? module->maximum_pages
      75      912549 :                              : kV8MaxWasmMemoryPages) *
      76             :                         uint64_t{kWasmPageSize}),
      77             :         enabled_features(enabled_features),
      78     2715665 :         lower_simd(lower_simd) {}
      79             : };
      80             : 
      81             : // The wire bytes are either owned by the StreamingDecoder, or (after streaming)
      82             : // by the NativeModule. This class abstracts over the storage location.
      83     2337608 : class WireBytesStorage {
      84             :  public:
      85     2337608 :   virtual ~WireBytesStorage() = default;
      86             :   virtual Vector<const uint8_t> GetCode(WireBytesRef) const = 0;
      87             : };
      88             : 
      89             : // Callbacks will receive either {kFailedCompilation} or both
      90             : // {kFinishedBaselineCompilation} and {kFinishedTopTierCompilation}, in that
      91             : // order. If tier up is off, both events are delivered right after each other.
      92             : enum class CompilationEvent : uint8_t {
      93             :   kFinishedBaselineCompilation,
      94             :   kFinishedTopTierCompilation,
      95             :   kFailedCompilation,
      96             : 
      97             :   // Marker:
      98             :   // After an event >= kFirstFinalEvent, no further events are generated.
      99             :   kFirstFinalEvent = kFinishedTopTierCompilation
     100             : };
     101             : 
     102             : // The implementation of {CompilationState} lives in module-compiler.cc.
     103             : // This is the PIMPL interface to that private class.
     104             : class CompilationState {
     105             :  public:
     106             :   using callback_t = std::function<void(CompilationEvent)>;
     107             : 
     108             :   ~CompilationState();
     109             : 
     110             :   void AbortCompilation();
     111             : 
     112             :   void SetError(uint32_t func_index, const WasmError& error);
     113             : 
     114             :   void SetWireBytesStorage(std::shared_ptr<WireBytesStorage>);
     115             : 
     116             :   std::shared_ptr<WireBytesStorage> GetWireBytesStorage() const;
     117             : 
     118             :   void AddCallback(callback_t);
     119             : 
     120             :   bool failed() const;
     121             : 
     122             :   void OnFinishedUnit(ExecutionTier, WasmCode*);
     123             : 
     124             :  private:
     125             :   friend class NativeModule;
     126             :   friend class WasmCompilationUnit;
     127             :   CompilationState() = delete;
     128             : 
     129             :   static std::unique_ptr<CompilationState> New(NativeModule*,
     130             :                                                std::shared_ptr<Counters>);
     131             : };
     132             : 
     133             : }  // namespace wasm
     134             : }  // namespace internal
     135             : }  // namespace v8
     136             : 
     137             : #endif  // V8_WASM_COMPILATION_ENVIRONMENT_H_

Generated by: LCOV version 1.10