forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytecode-array.h
More file actions
184 lines (139 loc) Β· 7.1 KB
/
bytecode-array.h
File metadata and controls
184 lines (139 loc) Β· 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright 2023 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.
#ifndef V8_OBJECTS_BYTECODE_ARRAY_H_
#define V8_OBJECTS_BYTECODE_ARRAY_H_
#include "src/objects/struct.h"
#include "src/objects/trusted-object.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class BytecodeWrapper;
namespace interpreter {
class Register;
} // namespace interpreter
// TODO(jgruber): These should no longer be included here; instead, all
// TorqueGeneratedFooAsserts should be emitted into a global .cc file.
#include "torque-generated/src/objects/bytecode-array-tq.inc"
// BytecodeArray represents a sequence of interpreter bytecodes.
class BytecodeArray : public ExposedTrustedObject {
public:
// The length of this bytecode array, in bytes.
inline int length() const;
inline int length(AcquireLoadTag tag) const;
inline void set_length(int value);
inline void set_length(int value, ReleaseStoreTag tag);
// The handler table contains offsets of exception handlers.
DECL_PROTECTED_POINTER_ACCESSORS(handler_table, TrustedByteArray)
DECL_PROTECTED_POINTER_ACCESSORS(constant_pool, TrustedFixedArray)
// The BytecodeWrapper for this BytecodeArray. When the sandbox is enabled,
// the BytecodeArray lives in trusted space outside of the sandbox, but the
// wrapper object lives inside the main heap and therefore inside the
// sandbox. As such, the wrapper object can be used in cases where a
// BytecodeArray needs to be referenced alongside other tagged pointer
// references (so for example inside a FixedArray).
DECL_ACCESSORS(wrapper, Tagged<BytecodeWrapper>)
// Source position table. Can contain:
// * Smi::zero() (initial value, or if an error occurred while explicitly
// collecting source positions for pre-existing bytecode).
// * empty_trusted_byte_array (for bytecode generated for functions that will
// never have source positions, e.g. native functions).
// * TrustedByteArray (if source positions were collected for the bytecode)
DECL_RELEASE_ACQUIRE_PROTECTED_POINTER_ACCESSORS(source_position_table,
TrustedByteArray)
DECL_INT32_ACCESSORS(frame_size)
inline int32_t max_frame_size() const;
static constexpr int SizeFor(int length) {
return OBJECT_POINTER_ALIGN(kHeaderSize + length);
}
inline uint8_t get(int index) const;
inline void set(int index, uint8_t value);
inline Address GetFirstBytecodeAddress();
// Note: The register count is derived from frame_size.
inline int register_count() const;
// Note: the parameter count includes the implicit 'this' receiver.
inline uint16_t parameter_count() const;
inline uint16_t parameter_count_without_receiver() const;
inline void set_parameter_count(uint16_t number_of_parameters);
inline uint16_t max_arguments() const;
inline void set_max_arguments(uint16_t max_arguments);
inline interpreter::Register incoming_new_target_or_generator_register()
const;
inline void set_incoming_new_target_or_generator_register(
interpreter::Register incoming_new_target_or_generator_register);
inline bool HasSourcePositionTable() const;
int SourcePosition(int offset) const;
int SourceStatementPosition(int offset) const;
// If source positions have not been collected or an exception has been thrown
// this will return the empty_trusted_byte_array.
DECL_GETTER(SourcePositionTable, Tagged<TrustedByteArray>)
// Raw accessors to access these fields during code cache deserialization.
DECL_GETTER(raw_constant_pool, Tagged<Object>)
DECL_GETTER(raw_handler_table, Tagged<Object>)
// This accessor can also be used when it's not guaranteed that a source
// position table exists, for example because it hasn't been collected. In
// that case, Smi::zero() will be returned.
DECL_ACQUIRE_GETTER(raw_source_position_table, Tagged<Object>)
// Indicates that an attempt was made to collect source positions, but that it
// failed, most likely due to stack exhaustion. When in this state
// |SourcePositionTable| will return an empty byte array.
inline void SetSourcePositionsFailedToCollect();
inline int BytecodeArraySize() const;
// Returns the size of bytecode and its metadata. This includes the size of
// bytecode, constant pool, source position table, and handler table.
DECL_GETTER(SizeIncludingMetadata, int)
DECL_PRINTER(BytecodeArray)
DECL_VERIFIER(BytecodeArray)
V8_EXPORT_PRIVATE void PrintJson(std::ostream& os);
V8_EXPORT_PRIVATE void Disassemble(std::ostream& os);
V8_EXPORT_PRIVATE static void Disassemble(Handle<BytecodeArray> handle,
std::ostream& os);
void CopyBytecodesTo(Tagged<BytecodeArray> to);
// Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic.
inline void clear_padding();
// Maximal memory consumption for a single BytecodeArray.
static const int kMaxSize = 512 * MB;
// Maximal length of a single BytecodeArray.
static const int kMaxLength = kMaxSize - kHeaderSize;
#define FIELD_LIST(V) \
V(kLengthOffset, kTaggedSize) \
V(kWrapperOffset, kTaggedSize) \
V(kSourcePositionTableOffset, kTaggedSize) \
V(kHandlerTableOffset, kTaggedSize) \
V(kConstantPoolOffset, kTaggedSize) \
V(kFrameSizeOffset, kInt32Size) \
V(kParameterSizeOffset, kUInt16Size) \
V(kMaxArgumentsOffset, kUInt16Size) \
V(kIncomingNewTargetOrGeneratorRegisterOffset, kInt32Size) \
V(kOptionalPaddingOffset, 0) \
V(kUnalignedHeaderSize, OBJECT_POINTER_PADDING(kUnalignedHeaderSize)) \
V(kHeaderSize, 0) \
V(kBytesOffset, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(ExposedTrustedObject::kHeaderSize, FIELD_LIST)
#undef FIELD_LIST
class BodyDescriptor;
OBJECT_CONSTRUCTORS(BytecodeArray, ExposedTrustedObject);
};
// A BytecodeWrapper wraps a BytecodeArray but lives inside the sandbox. This
// can be useful for example when a reference to a BytecodeArray needs to be
// stored along other tagged pointers inside an array or similar datastructure.
class BytecodeWrapper : public Struct {
public:
DECL_TRUSTED_POINTER_ACCESSORS(bytecode, BytecodeArray)
DECL_PRINTER(BytecodeWrapper)
DECL_VERIFIER(BytecodeWrapper)
#define FIELD_LIST(V) \
V(kBytecodeOffset, kTrustedPointerSize) \
V(kHeaderSize, 0) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, FIELD_LIST)
#undef FIELD_LIST
class BodyDescriptor;
OBJECT_CONSTRUCTORS(BytecodeWrapper, Struct);
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_BYTECODE_ARRAY_H_