v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-deopt-data.h
Go to the documentation of this file.
1// Copyright 2024 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_DEOPT_DATA_H_
6#define V8_WASM_WASM_DEOPT_DATA_H_
7#if !V8_ENABLE_WEBASSEMBLY
8#error This header should only be included if WebAssembly is enabled.
9#endif // !V8_ENABLE_WEBASSEMBLY
10
11#include "src/base/memory.h"
12#include "src/utils/utils.h"
15
16namespace v8::internal {
17class DeoptimizationLiteral;
18}
19
20namespace v8::internal::wasm {
21
22// The "header" of the full deopt data for an optimized wasm function containing
23// overall counts used to access the unerlying translated values, literals etc.
25 uint32_t entry_count = 0; // Count of deopt points.
27 uint32_t deopt_literals_size = 0;
28 // The offset inside the code to the first deopt builtin call instruction.
29 // This is used to map a pc back to a the "deopt index".
31 // The count of eager deopt points.
33};
34
36 // The wire bytes offset of the deopt point. This is used to map a deopt entry
37 // to a liftoff deopt point.
39 // The index inside the translations array at which this deopt entry starts.
40 // (The translations array is shared for all deopt points of a function.)
42};
43
44// A view to access the deopt data stored in the WasmCode's metadata as raw
45// bytes.
47 public:
49 : deopt_data_(deopt_data) {
50 if (!deopt_data.empty()) {
51 static_assert(std::is_trivially_copy_assignable_v<WasmDeoptData>);
52 DCHECK_GE(deopt_data_.size(), sizeof(WasmDeoptData));
53 std::memcpy(&base_data_, deopt_data_.begin(), sizeof(base_data_));
54 }
55 }
56
57 bool HasDeoptData() const { return !deopt_data_.empty(); }
58
59 const WasmDeoptData& GetDeoptData() const {
61 return base_data_;
62 }
63
69
70 WasmDeoptEntry GetDeoptEntry(uint32_t deopt_index) const {
72 DCHECK(deopt_index < base_data_.entry_count);
73 const uint8_t* begin = deopt_data_.begin() + sizeof(base_data_) +
76 begin + sizeof(WasmDeoptEntry) * deopt_index));
77 }
78
79 std::vector<DeoptimizationLiteral> BuildDeoptimizationLiteralArray();
80
81 private:
84};
85
87 public:
89 int deopt_exit_start_offset, int eager_deopt_count,
90 base::Vector<const uint8_t> translation_array,
92 const ZoneDeque<DeoptimizationLiteral>& deopt_literals);
93};
94
95// All the information needed by the deoptimizer to know what the Liftoff frame
96// has to look like.
98 uint32_t wire_bytes_offset = 0;
99 uint32_t pc_offset = 0;
100#ifdef V8_ENABLE_CET_SHADOW_STACK
101 uint32_t adapt_shadow_stack_pc_offset = 0;
102#endif // V8_ENABLE_CET_SHADOW_STACK
103 std::vector<LiftoffVarState> var_state = {};
104 // If the trusted_instance is cached in a register additionally to the stack
105 // slot, this register needs to be updated as well.
108};
109
110} // namespace v8::internal::wasm
111#endif // V8_WASM_WASM_DEOPT_DATA_H_
constexpr bool empty() const
Definition vector.h:73
constexpr T * begin() const
Definition vector.h:96
static constexpr BytecodeOffset None()
Definition utils.h:675
static base::OwnedVector< uint8_t > Serialize(int deopt_exit_start_offset, int eager_deopt_count, base::Vector< const uint8_t > translation_array, base::Vector< wasm::WasmDeoptEntry > deopt_entries, const ZoneDeque< DeoptimizationLiteral > &deopt_literals)
WasmDeoptView(base::Vector< const uint8_t > deopt_data)
std::vector< DeoptimizationLiteral > BuildDeoptimizationLiteralArray()
WasmDeoptEntry GetDeoptEntry(uint32_t deopt_index) const
base::Vector< const uint8_t > GetTranslationsArray() const
base::Vector< const uint8_t > deopt_data_
const WasmDeoptData & GetDeoptData() const
static V ReadUnalignedValue(Address p)
Definition memory.h:28
constexpr Register no_reg
#define DCHECK(condition)
Definition logging.h:482