v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-array.h
Go to the documentation of this file.
1// Copyright 2023 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_OBJECTS_BYTECODE_ARRAY_H_
6#define V8_OBJECTS_BYTECODE_ARRAY_H_
7
10
11// Has to be the last include (doesn't have include guards):
13
14namespace v8 {
15namespace internal {
16
17class BytecodeWrapper;
18
19namespace interpreter {
20class Register;
21} // namespace interpreter
22
23// TODO(jgruber): These should no longer be included here; instead, all
24// TorqueGeneratedFooAsserts should be emitted into a global .cc file.
25#include "torque-generated/src/objects/bytecode-array-tq.inc"
26
27// BytecodeArray represents a sequence of interpreter bytecodes.
29 public:
30 // The length of this bytecode array, in bytes.
31 inline int length() const;
32 inline int length(AcquireLoadTag tag) const;
33 inline void set_length(int value);
34 inline void set_length(int value, ReleaseStoreTag tag);
35
36 // The handler table contains offsets of exception handlers.
38
40
41 // The BytecodeWrapper for this BytecodeArray. When the sandbox is enabled,
42 // the BytecodeArray lives in trusted space outside of the sandbox, but the
43 // wrapper object lives inside the main heap and therefore inside the
44 // sandbox. As such, the wrapper object can be used in cases where a
45 // BytecodeArray needs to be referenced alongside other tagged pointer
46 // references (so for example inside a FixedArray).
48
49 // Source position table. Can contain:
50 // * Smi::zero() (initial value, or if an error occurred while explicitly
51 // collecting source positions for pre-existing bytecode).
52 // * empty_trusted_byte_array (for bytecode generated for functions that will
53 // never have source positions, e.g. native functions).
54 // * TrustedByteArray (if source positions were collected for the bytecode)
57
58 DECL_INT32_ACCESSORS(frame_size)
59
60 inline int32_t max_frame_size() const;
61
62 static constexpr int SizeFor(int length) {
63 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
64 }
65
66 inline uint8_t get(int index) const;
67 inline void set(int index, uint8_t value);
68
70
71 // Note: The register count is derived from frame_size.
72 inline int register_count() const;
73
74 // Note: the parameter count includes the implicit 'this' receiver.
75 inline uint16_t parameter_count() const;
76 inline uint16_t parameter_count_without_receiver() const;
77 inline void set_parameter_count(uint16_t number_of_parameters);
78 inline uint16_t max_arguments() const;
79 inline void set_max_arguments(uint16_t max_arguments);
80
82 const;
85
86 inline bool HasSourcePositionTable() const;
87 int SourcePosition(int offset) const;
88 int SourceStatementPosition(int offset) const;
89
90 // If source positions have not been collected or an exception has been thrown
91 // this will return the empty_trusted_byte_array.
93
94 // Raw accessors to access these fields during code cache deserialization.
95 DECL_GETTER(raw_constant_pool, Tagged<Object>)
96 DECL_GETTER(raw_handler_table, Tagged<Object>)
97 // This accessor can also be used when it's not guaranteed that a source
98 // position table exists, for example because it hasn't been collected. In
99 // that case, Smi::zero() will be returned.
100 DECL_ACQUIRE_GETTER(raw_source_position_table, Tagged<Object>)
101
102 // Indicates that an attempt was made to collect source positions, but that it
103 // failed, most likely due to stack exhaustion. When in this state
104 // |SourcePositionTable| will return an empty byte array.
106
107 inline int BytecodeArraySize() const;
108
109 // Returns the size of bytecode and its metadata. This includes the size of
110 // bytecode, constant pool, source position table, and handler table.
111 DECL_GETTER(SizeIncludingMetadata, int)
112
115
116 V8_EXPORT_PRIVATE void PrintJson(std::ostream& os);
117 V8_EXPORT_PRIVATE void Disassemble(std::ostream& os);
118
120 std::ostream& os);
121
123
124 // Clear uninitialized padding space. This ensures that the snapshot content
125 // is deterministic.
126 inline void clear_padding();
127
128 // Maximal memory consumption for a single BytecodeArray.
129 static const int kMaxSize = 512 * MB;
130 // Maximal length of a single BytecodeArray.
131 static const int kMaxLength = kMaxSize - kHeaderSize;
132
133#define FIELD_LIST(V) \
134 V(kLengthOffset, kTaggedSize) \
135 V(kWrapperOffset, kTaggedSize) \
136 V(kSourcePositionTableOffset, kTaggedSize) \
137 V(kHandlerTableOffset, kTaggedSize) \
138 V(kConstantPoolOffset, kTaggedSize) \
139 V(kFrameSizeOffset, kInt32Size) \
140 V(kParameterSizeOffset, kUInt16Size) \
141 V(kMaxArgumentsOffset, kUInt16Size) \
142 V(kIncomingNewTargetOrGeneratorRegisterOffset, kInt32Size) \
143 V(kOptionalPaddingOffset, 0) \
144 V(kUnalignedHeaderSize, OBJECT_POINTER_PADDING(kUnalignedHeaderSize)) \
145 V(kHeaderSize, 0) \
146 V(kBytesOffset, 0)
147
149#undef FIELD_LIST
150
151 class BodyDescriptor;
152
154};
155
156// A BytecodeWrapper wraps a BytecodeArray but lives inside the sandbox. This
157// can be useful for example when a reference to a BytecodeArray needs to be
158// stored along other tagged pointers inside an array or similar datastructure.
159class BytecodeWrapper : public Struct {
160 public:
162
165
166#define FIELD_LIST(V) \
167 V(kBytecodeOffset, kTrustedPointerSize) \
168 V(kHeaderSize, 0) \
169 V(kSize, 0)
170
171 DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, FIELD_LIST)
172#undef FIELD_LIST
173
174 class BodyDescriptor;
175
177};
178
179} // namespace internal
180} // namespace v8
181
183
184#endif // V8_OBJECTS_BYTECODE_ARRAY_H_
void set_length(int value, ReleaseStoreTag tag)
uint16_t parameter_count_without_receiver() const
interpreter::Register incoming_new_target_or_generator_register() const
void set(int index, uint8_t value)
int SourceStatementPosition(int offset) const
int SourcePosition(int offset) const
void set_max_arguments(uint16_t max_arguments)
OBJECT_CONSTRUCTORS(BytecodeArray, ExposedTrustedObject)
void CopyBytecodesTo(Tagged< BytecodeArray > to)
void set_length(int value)
void set_incoming_new_target_or_generator_register(interpreter::Register incoming_new_target_or_generator_register)
V8_EXPORT_PRIVATE void Disassemble(std::ostream &os)
uint8_t get(int index) const
int length(AcquireLoadTag tag) const
V8_EXPORT_PRIVATE void PrintJson(std::ostream &os)
void set_parameter_count(uint16_t number_of_parameters)
static constexpr int SizeFor(int length)
OBJECT_CONSTRUCTORS(BytecodeWrapper, Struct)
#define OBJECT_POINTER_ALIGN(value)
Definition globals.h:1783
int32_t offset
#define FIELD_LIST(V)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage * MB
Definition flags.cc:2197
#define DECL_ACCESSORS(name,...)
#define DECL_GETTER(name,...)
#define DECL_ACQUIRE_GETTER(name,...)
#define DECL_RELEASE_ACQUIRE_PROTECTED_POINTER_ACCESSORS(name, type)
#define DECL_TRUSTED_POINTER_ACCESSORS(name, type)
#define DECL_VERIFIER(Name)
#define DECL_PROTECTED_POINTER_ACCESSORS(name, type)
#define DECL_PRINTER(Name)
#define DECL_INT32_ACCESSORS(name)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define DEFINE_FIELD_OFFSET_CONSTANTS(StartOffset, LIST_MACRO)
Definition utils.h:242