v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
allocation-site.h
Go to the documentation of this file.
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_OBJECTS_ALLOCATION_SITE_H_
6#define V8_OBJECTS_ALLOCATION_SITE_H_
7
8#include <atomic>
9
10#include "src/objects/objects.h"
11#include "src/objects/struct.h"
12
13// Has to be the last include (doesn't have include guards):
15
16namespace v8 {
17namespace internal {
18
20
21#include "torque-generated/src/objects/allocation-site-tq.inc"
22
24 public:
26 static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024;
27
28 // Values for pretenure decision field.
34 kZombie = 4, // See comment to IsZombie() for documentation.
36 };
37
38 const char* PretenureDecisionName(PretenureDecision decision);
39
41
42 inline Tagged<JSObject> boilerplate() const;
46
47 inline int transition_info() const;
48 inline void set_transition_info(int value);
49
50 // nested_site threads a list of sites that represent nested literals
51 // walked in a particular order. So [[1, 2], 1, 2] will have one
52 // nested_site, but [[1, 2], 3, [4]] will have a list of two.
56
57 // Bitfield containing pretenuring information.
58 inline int32_t pretenure_data(RelaxedLoadTag) const;
59 inline void set_pretenure_data(int32_t value, RelaxedStoreTag);
60
61 inline int32_t pretenure_create_count() const;
62 inline void set_pretenure_create_count(int32_t value);
63
67
68 inline void Initialize();
69
70 // Checks if the allocation site contain weak_next field;
71 inline bool HasWeakNext() const;
72
73 // This method is expensive, it should only be called for reporting.
74 bool IsNested();
75
76 // transition_info bitfields, for constructed array transition info.
79 // Unused bits 7-30.
80
81 // Bitfields for pretenure_data
86
87 // Increments the mementos found counter and returns the new count.
88 inline int IncrementMementoFoundCount(int increment = 1);
89
90 inline void IncrementMementoCreateCount();
91
93
95
97 inline void set_pretenure_decision(PretenureDecision decision);
98
99 inline bool deopt_dependent_code() const;
100 inline void set_deopt_dependent_code(bool deopt);
101
102 inline int memento_found_count() const;
103 inline void set_memento_found_count(int count);
104
105 inline int memento_create_count() const;
106 inline void set_memento_create_count(int count);
107
108 // A "zombie" AllocationSite is one which has no more strong roots to
109 // it, and yet must be maintained until the next GC. The reason is that
110 // it may be that in new space there are AllocationMementos hanging around
111 // which point to the AllocationSite. If we scavenge these AllocationSites
112 // too soon, those AllocationMementos will end up pointing to garbage
113 // addresses. The concrete case happens when evacuating new space in the full
114 // GC which happens after sweeping has been started already. To mitigate this
115 // problem the garbage collector marks such AllocationSites as zombies when it
116 // discovers there are no roots, allowing the subsequent collection pass to
117 // recognize zombies and discard them later.
118 inline bool IsZombie() const;
119
120 inline bool IsMaybeTenure() const;
121
122 inline void MarkZombie();
123
124 inline bool MakePretenureDecision(PretenureDecision current_decision,
125 double ratio, bool maximum_size_scavenge);
126
127 inline bool DigestPretenuringFeedback(bool maximum_size_scavenge);
128
129 inline ElementsKind GetElementsKind() const;
130 inline void SetElementsKind(ElementsKind kind);
131
132 inline bool CanInlineCall() const;
133 inline void SetDoNotInlineCall();
134
135 inline bool PointsToLiteral() const;
136
137 template <AllocationSiteUpdateMode update_or_check =
140 ElementsKind to_kind);
141
144
145 static inline bool ShouldTrack(ElementsKind boilerplate_elements_kind);
146 static bool ShouldTrack(ElementsKind from, ElementsKind to);
147 static inline bool CanTrack(InstanceType type);
148
149 class BodyDescriptor;
150
151 private:
152 inline bool PretenuringDecisionMade() const;
153
154 private:
155 friend class CodeStubAssembler;
158 friend class V8HeapExplorer;
159
160 // Contains either a Smi-encoded bitfield or a boilerplate. If it's a Smi the
161 // AllocationSite is for a constructed Array.
165 std::atomic<int32_t> pretenure_data_;
168
170 public:
171 // heap->allocation_site_list() points to the last AllocationSite which form
172 // a linked list through the weak_next property. The GC might remove elements
173 // from the list by updating weak_next.
175 const;
176 inline void set_weak_next(
179
180 private:
181 friend class CodeStubAssembler;
183 template <typename T>
184 friend struct WeakListVisitor;
185 friend class V8HeapExplorer;
186
189
208
209} // namespace internal
210} // namespace v8
211
213
214#endif // V8_OBJECTS_ALLOCATION_SITE_H_
Builtins::Kind kind
Definition builtins.cc:40
static constexpr U kMax
Definition bit-field.h:44
Tagged< AllocationSite > GetAllocationSite() const
void set_allocation_site(Tagged< AllocationSite > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
friend class TorqueGeneratedAllocationMementoAsserts
TaggedMember< AllocationSite > allocation_site_
void set_weak_next(Tagged< UnionOf< Undefined, AllocationSiteWithWeakNext > > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
TaggedMember< UnionOf< Undefined, AllocationSiteWithWeakNext > > weak_next_
Tagged< UnionOf< Undefined, AllocationSiteWithWeakNext > > weak_next() const
const char * PretenureDecisionName(PretenureDecision decision)
Definition objects.cc:4931
static NEVER_READ_ONLY_SPACE const uint32_t kMaximumArrayBytesToPretransition
TaggedMember< UnionOf< Smi, JSObject > > transition_info_or_boilerplate_
ElementsKind GetElementsKind() const
Tagged< UnionOf< Smi, JSObject > > transition_info_or_boilerplate() const
Tagged< UnionOf< Smi, AllocationSite > > nested_site() const
PretenureDecision pretenure_decision() const
void set_pretenure_decision(PretenureDecision decision)
static bool ShouldTrack(ElementsKind boilerplate_elements_kind)
static bool CanTrack(InstanceType type)
TaggedMember< UnionOf< Smi, AllocationSite > > nested_site_
Tagged< DependentCode > dependent_code() const
void set_pretenure_create_count(int32_t value)
int32_t pretenure_data(RelaxedLoadTag) const
static bool DigestTransitionFeedback(DirectHandle< AllocationSite > site, ElementsKind to_kind)
Tagged< JSObject > boilerplate() const
void set_pretenure_data(int32_t value, RelaxedStoreTag)
bool DigestPretenuringFeedback(bool maximum_size_scavenge)
AllocationType GetAllocationType() const
Definition objects.cc:4906
void set_boilerplate(Tagged< JSObject > value, ReleaseStoreTag, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
TaggedMember< DependentCode > dependent_code_
void set_dependent_code(Tagged< DependentCode > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
bool MakePretenureDecision(PretenureDecision current_decision, double ratio, bool maximum_size_scavenge)
void set_nested_site(Tagged< UnionOf< Smi, AllocationSite > > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
int IncrementMementoFoundCount(int increment=1)
std::atomic< int32_t > pretenure_data_
void SetElementsKind(ElementsKind kind)
double increment
unsigned short uint16_t
Definition unicode.cc:39
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
v8::internal::LoadHandler V8_OBJECT_END
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
AllocationSiteUpdateMode
Definition globals.h:1940
#define DECL_VERIFIER(Name)
#define V8_OBJECT
#define NEVER_READ_ONLY_SPACE
#define DECL_PRINTER(Name)