v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-graph.cc
Go to the documentation of this file.
1// Copyright 2014 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
6
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16#define GET_CACHED_FIELD(ptr, expr) (*(ptr)) ? *(ptr) : (*(ptr) = (expr))
17
18#define DEFINE_GETTER(name, Type, expr) \
19 TNode<Type> JSGraph::name() { \
20 return TNode<Type>::UncheckedCast(GET_CACHED_FIELD(&name##_, expr)); \
21 }
22
23Node* JSGraph::CEntryStubConstant(int result_size, ArgvMode argv_mode,
24 bool builtin_exit_frame) {
25 if (argv_mode == ArgvMode::kStack) {
26 DCHECK(result_size >= 1 && result_size <= 3);
27 if (!builtin_exit_frame) {
28 Node** ptr = nullptr;
29 if (result_size == 1) {
30 ptr = &CEntryStub1Constant_;
31 } else if (result_size == 2) {
32 ptr = &CEntryStub2Constant_;
33 } else {
34 DCHECK_EQ(3, result_size);
35 ptr = &CEntryStub3Constant_;
36 }
37 return GET_CACHED_FIELD(
39 isolate(), result_size, argv_mode, builtin_exit_frame)));
40 }
41 Node** ptr = builtin_exit_frame ? &CEntryStub1WithBuiltinExitFrameConstant_
42 : &CEntryStub1Constant_;
43 return GET_CACHED_FIELD(
45 isolate(), result_size, argv_mode, builtin_exit_frame)));
46 }
48 argv_mode, builtin_exit_frame));
49}
50
52 // This CHECK is security critical, we should never observe a hole
53 // here. Please do not remove this! (crbug.com/1486789)
54 CHECK(ref.IsSmi() || ref.IsHeapNumber() ||
55 ref.AsHeapObject().GetHeapObjectType(broker).hole_type() ==
57 if (IsThinString(*ref.object())) {
59 Cast<ThinString>(*ref.object())->actual());
60 }
61 return Constant(ref, broker);
62}
63
65 return Constant(ref, broker);
66}
67
69 if (ref.IsSmi()) return ConstantMaybeHole(ref.AsSmi());
70 if (ref.IsHeapNumber()) {
71 return ConstantMaybeHole(ref.AsHeapNumber().value());
72 }
73
74 switch (ref.AsHeapObject().GetHeapObjectType(broker).hole_type()) {
75 case HoleType::kNone:
76 break;
78 return TheHoleConstant();
79 case HoleType::kPropertyCellHole:
80 return PropertyCellHoleConstant();
81 case HoleType::kHashTableHole:
82 return HashTableHoleConstant();
83 case HoleType::kPromiseHole:
84 return PromiseHoleConstant();
85 case HoleType::kOptimizedOut:
86 return OptimizedOutConstant();
87 case HoleType::kStaleRegister:
88 return StaleRegisterConstant();
89 case HoleType::kUninitialized:
90 return UninitializedConstant();
91 case HoleType::kException:
92 case HoleType::kTerminationException:
93 case HoleType::kArgumentsMarker:
94 case HoleType::kSelfReferenceMarker:
95 case HoleType::kBasicBlockCountersMarker:
97 }
98
99 OddballType oddball_type =
100 ref.AsHeapObject().GetHeapObjectType(broker).oddball_type();
101 ReadOnlyRoots roots(isolate());
102 if (oddball_type == OddballType::kUndefined) {
103 DCHECK(IsUndefined(*ref.object(), roots));
104 return UndefinedConstant();
105 } else if (oddball_type == OddballType::kNull) {
106 DCHECK(IsNull(*ref.object(), roots));
107 return NullConstant();
108 } else if (oddball_type == OddballType::kBoolean) {
109 if (IsTrue(*ref.object(), roots)) {
110 return TrueConstant();
111 } else {
112 DCHECK(IsFalse(*ref.object(), roots));
113 return FalseConstant();
114 }
115 } else {
116 return HeapConstantNoHole(ref.AsHeapObject().object());
117 }
118}
119
124
129
132 return ZeroConstant();
134 return OneConstant();
135 return NumberConstant(value);
136}
137
139 Node** loc = cache_.FindNumberConstant(value);
140 if (*loc == nullptr) {
141 *loc = graph()->NewNode(common()->NumberConstant(value));
142 }
143 return *loc;
144}
145
147 CHECK(!IsAnyHole(*value));
148 Node** loc = cache_.FindHeapConstant(value);
149 if (*loc == nullptr) {
150 *loc = graph()->NewNode(common()->HeapConstant(value));
151 }
152 return *loc;
153}
154
156 Node** loc = cache_.FindHeapConstant(value);
157 if (*loc == nullptr) {
158 *loc = graph()->NewNode(common()->HeapConstant(value));
159 }
160 return *loc;
161}
162
164 DCHECK(IsAnyHole(*value));
165 Node** loc = cache_.FindHeapConstant(value);
166 if (*loc == nullptr) {
167 *loc = graph()->NewNode(common()->HeapConstant(value));
168 }
169 return *loc;
170}
171
173 DCHECK(IsTrustedObject(*value));
174 // TODO(pthier): Consider also caching trusted constants. Right now they are
175 // only used for RegExp data as part of RegExp literals and it should be
176 // uncommon for the same literal to appear multiple times.
177 return graph()->NewNode(common()->TrustedHeapConstant(value));
178}
179
181 cache_.GetCachedNodes(nodes);
182#define DO_CACHED_FIELD(name, ...) \
183 if (name##_) nodes->push_back(name##_);
184
187#undef DO_CACHED_FIELD
188}
189
190DEFINE_GETTER(AllocateInYoungGenerationStubConstant, Code,
192 AllocateInYoungGeneration)))
193
194DEFINE_GETTER(AllocateInOldGenerationStubConstant, Code,
196 AllocateInOldGeneration)))
197
198#if V8_ENABLE_WEBASSEMBLY
199DEFINE_GETTER(WasmAllocateInYoungGenerationStubConstant, Code,
201 WasmAllocateInYoungGeneration)))
202
203DEFINE_GETTER(WasmAllocateInOldGenerationStubConstant, Code,
205 WasmAllocateInOldGeneration)))
206#endif
207
208DEFINE_GETTER(ArrayConstructorStubConstant, Code,
209 HeapConstantNoHole(BUILTIN_CODE(isolate(), ArrayConstructorImpl)))
210
211DEFINE_GETTER(BigIntMapConstant, Map,
212 HeapConstantNoHole(factory()->bigint_map()))
213
214DEFINE_GETTER(BooleanMapConstant, Map,
215 HeapConstantNoHole(factory()->boolean_map()))
216
217DEFINE_GETTER(ToNumberBuiltinConstant, Code,
219
220DEFINE_GETTER(PlainPrimitiveToNumberBuiltinConstant, Code,
222 PlainPrimitiveToNumber)))
223
224DEFINE_GETTER(EmptyFixedArrayConstant, FixedArray,
225 HeapConstantNoHole(factory()->empty_fixed_array()))
226
227DEFINE_GETTER(EmptyStringConstant, String,
228 HeapConstantNoHole(factory()->empty_string()))
229
230DEFINE_GETTER(FixedArrayMapConstant, Map,
231 HeapConstantNoHole(factory()->fixed_array_map()))
232
233DEFINE_GETTER(PropertyArrayMapConstant, Map,
234 HeapConstantNoHole(factory()->property_array_map()))
235
236DEFINE_GETTER(FixedDoubleArrayMapConstant, Map,
237 HeapConstantNoHole(factory()->fixed_double_array_map()))
238
239DEFINE_GETTER(WeakFixedArrayMapConstant, Map,
240 HeapConstantNoHole(factory()->weak_fixed_array_map()))
241
242DEFINE_GETTER(HeapNumberMapConstant, Map,
243 HeapConstantNoHole(factory()->heap_number_map()))
244
245DEFINE_GETTER(UndefinedConstant, Undefined,
246 HeapConstantNoHole(factory()->undefined_value()))
247
248DEFINE_GETTER(TheHoleConstant, Hole,
249 HeapConstantHole(factory()->the_hole_value()))
250
251DEFINE_GETTER(PropertyCellHoleConstant, Hole,
252 HeapConstantHole(factory()->property_cell_hole_value()))
253
254DEFINE_GETTER(HashTableHoleConstant, Hole,
255 HeapConstantHole(factory()->hash_table_hole_value()))
256
257DEFINE_GETTER(PromiseHoleConstant, Hole,
258 HeapConstantHole(factory()->promise_hole_value()))
259
260DEFINE_GETTER(UninitializedConstant, Hole,
261 HeapConstantHole(factory()->uninitialized_value()))
262
263DEFINE_GETTER(OptimizedOutConstant, Hole,
264 HeapConstantHole(factory()->optimized_out()))
265
266DEFINE_GETTER(StaleRegisterConstant, Hole,
267 HeapConstantHole(factory()->stale_register()))
268
269DEFINE_GETTER(TrueConstant, True, HeapConstantNoHole(factory()->true_value()))
270
271DEFINE_GETTER(FalseConstant, False,
272 HeapConstantNoHole(factory()->false_value()))
273
274DEFINE_GETTER(NullConstant, Null, HeapConstantNoHole(factory()->null_value()))
275
276DEFINE_GETTER(ZeroConstant, Number, NumberConstant(0.0))
277
278DEFINE_GETTER(MinusZeroConstant, Number, NumberConstant(-0.0))
279
280DEFINE_GETTER(OneConstant, Number, NumberConstant(1.0))
281
282DEFINE_GETTER(MinusOneConstant, Number, NumberConstant(-1.0))
283
285 NumberConstant(std::numeric_limits<double>::quiet_NaN()))
286
287DEFINE_GETTER(EmptyStateValues, UntaggedT,
288 graph()->NewNode(common()->StateValues(0,
289 SparseInputMask::Dense())))
290
292 SingleDeadTypedStateValues, UntaggedT,
293 graph()->NewNode(common()->TypedStateValues(
294 graph()->zone()->New<ZoneVector<MachineType>>(0, graph()->zone()),
296
297DEFINE_GETTER(ExternalObjectMapConstant, Map,
298 HeapConstantNoHole(factory()->external_map()))
299
300#undef DEFINE_GETTER
301#undef GET_CACHED_FIELD
302
303} // namespace compiler
304} // namespace internal
305} // namespace v8
#define BUILTIN_CODE(isolate, name)
Definition builtins.h:45
static Handle< Code > CEntry(Isolate *isolate, int result_size=1, ArgvMode argv_mode=ArgvMode::kStack, bool builtin_exit_frame=false, bool switch_to_central_stack=false)
void GetCachedNodes(ZoneVector< Node * > *nodes)
Node ** FindHeapConstant(Handle< HeapObject > value)
IndirectHandle< HeapNumber > object() const
Node * ConstantMaybeHole(ObjectRef ref, JSHeapBroker *broker)
Definition js-graph.cc:64
Node * Constant(ObjectRef value, JSHeapBroker *broker)
Definition js-graph.cc:68
void GetCachedNodes(NodeVector *nodes)
Definition js-graph.cc:180
Node * HeapConstantHole(Handle< HeapObject > value)
Definition js-graph.cc:163
Node * HeapConstantNoHole(Handle< HeapObject > value)
Definition js-graph.cc:146
Node * NumberConstant(double value)
Definition js-graph.cc:138
Node * CEntryStubConstant(int result_size, ArgvMode argv_mode=ArgvMode::kStack, bool builtin_exit_frame=false)
Definition js-graph.cc:23
Isolate * isolate() const
Definition js-graph.h:106
Node * ConstantMutableHeapNumber(HeapNumberRef ref, JSHeapBroker *broker)
Definition js-graph.cc:120
Node * HeapConstantMaybeHole(Handle< HeapObject > value)
Definition js-graph.cc:155
Node * ConstantNoHole(ObjectRef ref, JSHeapBroker *broker)
Definition js-graph.cc:51
Node * TrustedHeapConstant(Handle< HeapObject > value)
Definition js-graph.cc:172
CommonOperatorBuilder * common() const
Node * NewNode(const Operator *op, int input_count, Node *const *inputs, bool incomplete=false)
Isolate * isolate
JSHeapBroker * broker
#define DEFINE_GETTER(Name, HighBit, LowBit, Func)
#define DO_CACHED_FIELD(name,...)
#define GET_CACHED_FIELD(ptr, expr)
Definition js-graph.cc:16
#define CACHED_GLOBAL_LIST(V)
Definition js-graph.h:113
#define CACHED_CENTRY_LIST(V)
Definition js-graph.h:160
STL namespace.
V8_INLINE Dest bit_cast(Source const &source)
Definition macros.h:95
HeapConstantHole(factory() ->the_hole_value())) DEFINE_GETTER(PropertyCellHoleConstant
NumberConstant(std::numeric_limits< double >::quiet_NaN())) DEFINE_GETTER(EmptyStateValues
ref_traits< T >::ref_type MakeRefAssumeMemoryFence(JSHeapBroker *broker, Tagged< T > object)
HeapConstantNoHole(BUILTIN_CODE(isolate(), AllocateInOldGeneration))) DEFINE_GETTER(ArrayConstructorStubConstant
bool IsAnyHole(Tagged< Object > obj, PtrComprCageBase cage_base)
constexpr uint64_t kHoleNanInt64
Definition globals.h:1960
int ToNumber(Register reg)
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Definition map-inl.h:70
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
static const base::uc32 kEndMarker
#define CHECK(condition)
Definition logging.h:124
#define CHECK_NE(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485