V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
allocation-site.h
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 "src/objects.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 enum InstanceType : uint16_t;
17 
19  public:
20  static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024;
21  static const double kPretenureRatio;
22  static const int kPretenureMinimumCreated = 100;
23 
24  // Values for pretenure decision field.
25  enum PretenureDecision {
26  kUndecided = 0,
27  kDontTenure = 1,
28  kMaybeTenure = 2,
29  kTenure = 3,
30  kZombie = 4,
31  kLastPretenureDecisionValue = kZombie
32  };
33 
34  const char* PretenureDecisionName(PretenureDecision decision);
35 
36  // Contains either a Smi-encoded bitfield or a boilerplate. If it's a Smi the
37  // AllocationSite is for a constructed Array.
38  DECL_ACCESSORS(transition_info_or_boilerplate, Object)
39  DECL_ACCESSORS(boilerplate, JSObject)
40  DECL_INT_ACCESSORS(transition_info)
41 
42  // nested_site threads a list of sites that represent nested literals
43  // walked in a particular order. So [[1, 2], 1, 2] will have one
44  // nested_site, but [[1, 2], 3, [4]] will have a list of two.
45  DECL_ACCESSORS(nested_site, Object)
46 
47  // Bitfield containing pretenuring information.
48  DECL_INT32_ACCESSORS(pretenure_data)
49 
50  DECL_INT32_ACCESSORS(pretenure_create_count)
51  DECL_ACCESSORS(dependent_code, DependentCode)
52 
53  // heap->allocation_site_list() points to the last AllocationSite which form
54  // a linked list through the weak_next property. The GC might remove elements
55  // from the list by updateing weak_next.
56  DECL_ACCESSORS(weak_next, Object)
57 
58  inline void Initialize();
59 
60  // Checks if the allocation site contain weak_next field;
61  inline bool HasWeakNext() const;
62 
63  // This method is expensive, it should only be called for reporting.
64  bool IsNested();
65 
66  // transition_info bitfields, for constructed array transition info.
67  class ElementsKindBits : public BitField<ElementsKind, 0, 5> {};
68  class DoNotInlineBit : public BitField<bool, 5, 1> {};
69  // Unused bits 6-30.
70 
71  // Bitfields for pretenure_data
72  class MementoFoundCountBits : public BitField<int, 0, 26> {};
73  class PretenureDecisionBits : public BitField<PretenureDecision, 26, 3> {};
74  class DeoptDependentCodeBit : public BitField<bool, 29, 1> {};
75  STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
76 
77  // Increments the mementos found counter and returns true when the first
78  // memento was found for a given allocation site.
79  inline bool IncrementMementoFoundCount(int increment = 1);
80 
81  inline void IncrementMementoCreateCount();
82 
83  PretenureFlag GetPretenureMode() const;
84 
85  void ResetPretenureDecision();
86 
87  inline PretenureDecision pretenure_decision() const;
88  inline void set_pretenure_decision(PretenureDecision decision);
89 
90  inline bool deopt_dependent_code() const;
91  inline void set_deopt_dependent_code(bool deopt);
92 
93  inline int memento_found_count() const;
94  inline void set_memento_found_count(int count);
95 
96  inline int memento_create_count() const;
97  inline void set_memento_create_count(int count);
98 
99  // The pretenuring decision is made during gc, and the zombie state allows
100  // us to recognize when an allocation site is just being kept alive because
101  // a later traversal of new space may discover AllocationMementos that point
102  // to this AllocationSite.
103  inline bool IsZombie() const;
104 
105  inline bool IsMaybeTenure() const;
106 
107  inline void MarkZombie();
108 
109  inline bool MakePretenureDecision(PretenureDecision current_decision,
110  double ratio, bool maximum_size_scavenge);
111 
112  inline bool DigestPretenuringFeedback(bool maximum_size_scavenge);
113 
114  inline ElementsKind GetElementsKind() const;
115  inline void SetElementsKind(ElementsKind kind);
116 
117  inline bool CanInlineCall() const;
118  inline void SetDoNotInlineCall();
119 
120  inline bool PointsToLiteral() const;
121 
122  template <AllocationSiteUpdateMode update_or_check =
123  AllocationSiteUpdateMode::kUpdate>
124  static bool DigestTransitionFeedback(Handle<AllocationSite> site,
125  ElementsKind to_kind);
126 
127  DECL_PRINTER(AllocationSite)
128  DECL_VERIFIER(AllocationSite)
129 
130  DECL_CAST(AllocationSite)
131  static inline bool ShouldTrack(ElementsKind boilerplate_elements_kind);
132  static bool ShouldTrack(ElementsKind from, ElementsKind to);
133  static inline bool CanTrack(InstanceType type);
134 
135 // Layout description.
136 // AllocationSite has to start with TransitionInfoOrboilerPlateOffset
137 // and end with WeakNext field.
138 #define ALLOCATION_SITE_FIELDS(V) \
139  V(kStartOffset, 0) \
140  V(kTransitionInfoOrBoilerplateOffset, kTaggedSize) \
141  V(kNestedSiteOffset, kTaggedSize) \
142  V(kDependentCodeOffset, kTaggedSize) \
143  V(kCommonPointerFieldEndOffset, 0) \
144  V(kPretenureDataOffset, kInt32Size) \
145  V(kPretenureCreateCountOffset, kInt32Size) \
146  /* Size of AllocationSite without WeakNext field */ \
147  V(kSizeWithoutWeakNext, 0) \
148  V(kWeakNextOffset, kTaggedSize) \
149  /* Size of AllocationSite with WeakNext field */ \
150  V(kSizeWithWeakNext, 0)
151 
152  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ALLOCATION_SITE_FIELDS)
153 #undef ALLOCATION_SITE_FIELDS
154 
155  class BodyDescriptor;
156 
157  private:
158  inline bool PretenuringDecisionMade() const;
159 
160  DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite);
161 };
162 
163 class AllocationMemento : public Struct {
164  public:
165 // Layout description.
166 #define ALLOCATION_MEMENTO_FIELDS(V) \
167  V(kAllocationSiteOffset, kTaggedSize) \
168  V(kSize, 0)
169 
170  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
171  ALLOCATION_MEMENTO_FIELDS)
172 #undef ALLOCATION_MEMENTO_FIELDS
173 
174  DECL_ACCESSORS(allocation_site, Object)
175 
176  inline bool IsValid() const;
177  inline AllocationSite* GetAllocationSite() const;
178  inline Address GetAllocationSiteUnchecked() const;
179 
180  DECL_PRINTER(AllocationMemento)
181  DECL_VERIFIER(AllocationMemento)
182 
183  DECL_CAST(AllocationMemento)
184 
185  private:
186  DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento);
187 };
188 
189 } // namespace internal
190 } // namespace v8
191 
192 #include "src/objects/object-macros-undef.h"
193 
194 #endif // V8_OBJECTS_ALLOCATION_SITE_H_
Definition: libplatform.h:13